Cleanup printing, enhance cmd_mem

print.s:
        removed some unused macros, and ones used in only one place.
        Merge PRINTLNS_ with PRINTLN_.

        add sprint_size_, taking bl argument; enhance sprint_fixedpoint_32_32$,
        using flag indicating whether or not to print the suffix (.000) if it
        is zero (for aligned pritning).

        merge PRINT_START and PRINT_START_; PRINT_START pushes ax and
        calls PRINT_START_, similar to PRINT_END/PRINT_END_.

        merge PRINTCHAR with PRINTCHAR_ (similar to above).

fs.s:
        rename PRINTLNS_ to PRINTLN

gfx.x:
        store fonts in SECTION_DATA_FONTS.

kernel.s:
        declare SECTION_DATA_FONTS

        define INCLUDE macro that creates code_XXX_(start|end) labels
        around each include.

        use INCLUDE macro instead of .include

        add code_kernel_(start|end).

mem.s:
        define cmd_mem option constants.

        add suboption -c to -s to print code sizes for various subsystems
        (the includes from the kernel). All code sizes are accounted for.

shell.s:
        rename xcmdline_* back to cmdline_* (shell objectify stage 6 amend)
Add virtual consoles. Add TLS.

Add 10 virtual consoles (replacing the default console with console0).

Major rework on printing and keyboard. Old code can be generated
by disabling VIRTUAL_CONSOLES.
Interrupt-driven printing (such as 'netdump') will still only print to
the default console.

TLS support: a global dword is updated on every task switch; if the
task changes the value, it will be remembered for next time.

print.s:
	add SCREEN_BUFFER_FIRST; when defined, printing is done in the
	screen buffer, and then copied to the screen, instead of the
	other way around.

		Add method: screen_buf_flush

	Add VIRTUAL_CONSOLES; update all references to [screen_*] fields
	with an array reference.
	The virtual console data is organized in such a way that the
	first virtual console correlates with the static screen_*
	fields, so that the realmode and pmode-switching code (before
	kmain) do not need to know about virtual consoles.

		Changed macros:

			PUSHCOLOR, POPCOLOR, COLOR,
			PUSH_SCREENPOS, POP_SCREENPOS, add SET_SCREENPOS,
			PRINT_START, PRINT_END

	remove unused: SCREEN_INIT, __newline, __println

	update macro PRINT, PRINTLN, PRINTc_ to support esi as arg.

	update macro PRINTc and PRINTLNc, as PUSHCOLOR/POPCOLOR have
	high overhead when VIRTUAL_CONSOLES are enabled, and in a few places
	the 'loop' instruction won't work. Instead, now _s_printc is called,
	taking the string/color arguments on the stack. This saves
	a lot of push/popping and should reduce kernel size.

	enable, update (rtl args) _s_printc/_s_printcharc; add _s_printlnc.

	update cls method: use the SET_SCREENPOS instead of manipulating edi
	directly, as edi may point somewhere within a screen buffer.

	update method newline: take VIRTUAL_CONSOLES and SCREEN_BUFFER_FIRST
	into consideration.

	Data movement: move SCREEN_BUFFER data to beginning;
	add screen_buf0 bss buffer; update [screen_buf] to a pointer;
	move screen_buf*/scroll_lines together with screen_pos etc
	for vconsole struct lineup.

	update __scroll method: take into account SCREEN_BUFFER_FIRST
	and VIRTUAL_CONSOLES.

	add screen_get_scroll_lines.

keyboard.s:
	if scheduler is running, let the scheduled kb_task store the
	key in the buffer if it is not a special key (scroll, ^C,
	alt-digit (select console)).

	buf_err$: update printing error message to current standards.

	add KB_LOCK/UNLOCK (MUTEX_[UN]LOCK KB) calls in the keyboard
	function (k_get etc). Without this, anything typed will be
	(most of the time) picked up by all virtual consoles simultaneously.

console.s:
	This is the start of an attempt to consolidate console functionality
	in one place. For now, there still is VIRTUAL_CONSOLE dependent
	code in keyboard.s and print.s. I had wanted to keep all keyboard
	functionality in one place, and, when VIRTUAL_CONSOLES is disabled,
	this is still true, except for the kb_task (which is not used
	unless scheduling is enabled).

	moved kb_task and scroll to console.s.

	kb_task:
		remove call to KB_PEEK.
		add suspend_task, console_set, continue_task calls.
		use console screen buffer if VIRTUAL_CONSOLES enabled.

	add console_set: allocates screen buffer for console if it
	doesn't have one, updates the [console_cur_ptr], and copies
	the console buffer to the screen.

	add cmd_consoles (consoles shell command), printing active
	console info (debug).

schedule.s:
	add TASK_FLAG_SUSPENDED (and according implementation).
	add suspend_task, continue_task (which just update the flag).

	add TLS (Thread Local Storage) support: remember a global [tls]
	dword for each task, which gets written on task activation,
	and it's value copied on task deactivation.
	Use of TLS will be implemented elsewhere, i.e., have it be a malloced
	buffer. For the kernel for now it seems there should be a shared struct
	possibly defined in tls.s.

	scheduler_get_task: add debug to show whether kb or net is running
	in the ticker-tape.

	update task_queue_empty handler: int 3

	update schedule_isr/_TEST: add [tls] support

	update schedule_task: allow multiple instances of a task (but still
	restrict jobs as they are meant to be unique).
	also, mask out all flag bits except TASK_FLAG_TASK.

	add task_get_by_pid;
	add suspend_task;
	add continue_task;

	update sched_print_graph: do not manipulate edi/screen_pos directly.

macros.s:
	add .tdata/.tdata end macros: they define .struct _TLS_SIZE,
	and update _TLS_SIZE to reflect the total size of the TLS so far.
	kernel.s defines tls_default in SECTION_DATA_TLS near the end,
	as any code can define tls fields. The tls_default cannot be
	initialized with values due to the macro structure, and so this
	is done in kmain. (alternative approach: define a macro with varargs
	that declares the struct entry aswell as the data, such as:
		.tls tls_field .long somevalue
	)

shell.s:
	record cmd_consoles.

	Consider: adding a DATA_SECTION_SHELL_COMMANDS. Shell command
	definitions can be easily grepped.

	cursor_toggle: do not manipulate edi/screen_pos directly.

	update prompt to show console name (task label).

	fix commandline screen overflow printing.

idt.s:
	print pid

	update reference to screen_pos, screen_scroll_lines.

ata.s:
	change reference to [screen_pos] with macro.
	change PRINT_START/reference to __println/PRINT_END with macro.

debug.s:
	cleanup MORE macro.

debugger.s:
	add compiletime switch for SCREEN_BUFFER.

	update reference to screen_scroll_lines.

	dont change [mutex].

Makefile.s:
	record console.s

kernel.s:
	record console.s

	add SECTION_DATA_SEMAPHORES; seems nice to have a single
	area of memory to observe for the entire lock-relationships
	within the kernel.

	remove the duplicate (disabled) signature code, and define
	signature to be one section after BSS, for easy change when BSS
	is no longer stored in the image.

	replace reference to static screen_buf with [screen_buf] pointer
	on initially copying the screen (up to kernel start) to
	screen buffer.

	add call to console_set to initialize virtual consoles. At current
	this call does nothing.

partition.s:
	remove argument to popcolor (old vim 'yyp4spush' ;)).
mem.s:
	idem;

	update reference to screen_pos.

	cmd_mem -s -c: add console; mem -s: order signature/bss.

cmos.s:
	change reference to screen_pos

mutex.s:
	store mutex in SECTION_DATA_SEMAPHORES.

	add nolocklabel argument to MUTEX_LOCK macro.

pit.s:
	also set es to SEL_compatDS on pit_isr: when SCREEN_BUFFER_FIRST
	is set, es is expected to be equal to ds on printing.

.tcshrc:
	add bkp alias to tgz changed files.
Enable network queue.

net.s:
	minor fixes in the network queue; is stable, so enabled (no more
	dropped packets).

	re-use semi-closed tcp connections after 30 seconds of inactivity.
	(FIN rx & tx, FIN ACK tx; no ACK rx).

	fix tcp service port scan - yielded false positives due to scan size
	being negative, resulting in a null handler.

shell.s:
	disable use of screen mutex

mutex.s:
	comment out screen mutex to make sure it isnt used.

	add MUTEX_SPINLOCK macro.
debug.s:
	allow DEBUG_WORD to specify label
Minor cosmetic improvements and print fixes.

util/stabs.pl:
	make sure source filenames are stored only once.

	implement parsing generated .stabs file.

idt.s:
	fix printing source line in debug_print_stack$.

kernel.s:
	add SECTION_DATA_SHELL_CMDS.

shell.s:
	store shell command structures in SECTION_DATA_SHELL_CMDS.
	Due to the size of the structure being calculated in shell.s,
	and due to the SHELL_COMMAND macro being defined in shell.s,
	commands can as yet not be declared before or after including
	shell.s.

	Add cmd_sline (stabs source line), and cmd_sym (debug symbol name).

schedule.s:
	add alternative format for printing the task list: source line + symbol.

	remove debug output in printing the task list.
Add identity paging.

Enable paging, and add a command paging_show_usage to show which pages are used.

Makefile:
	register paging.s

kernel.s:
	register paging.s
	add SECTION_DATA_SHELL_CMDS

shell.s:
	add cmd_cr to display control registers

	add paging_show_usage reference to show pages who's accessed flags
	are set.

	update cmd_exe to load A.ELF from boot drive.

mem.s:
	calculate physical memory size on init (for paging)

	cmd_mem:
		print SECTION_DATA_SHELL_CMDS usage
		print PAGING usage

paging.s:
	enable identity paging: map first 4 MB as 4kb pages.

DOC/Paging.txt:
	some observations.
Cosmetic changes and minor debugger fix.

debugger.s:
	update scrolling code - the scroll method is an event handler,
	and does not keep control while scrolling is enabled.

gdt.s:
	add GDT_taskCS/DS: for use in task switching.

	move some macros to macros.s.
	add macro GDT_GET_FLAGS
	add macro GDT_SET_BASE
	add macro GDT_SET_LIMIT
	update macro GDT_GET_LIMIT

	update stack calculation: align with physical 4kb page for paging.
	The paging structures (directory, tables) follow the stack immediately.

macros.s:
	receive macros from gdt.s and print.s: GET_INDEX, R8H, R8L, R16,
	REG_GET_FREE, IS_REG8, IS_SEGREG, IS_REG32, GET_REG32.

print.s:
	move macros GET_INDEX and IS_REG8 to macros.s

	update macro PRINT: allow esi as argument, and use stack-based
	_s_printc (which changes all PRINT invocations from
	push esi; mov esi, offset _txt; call print_; pop esi    to
	push offset _txt; call print_.).

	add method _s_print, taking the string from the stack;
	calling convention: callee cleanup.
Implement DNS server proxy. Add UDP socket.

net.s:
	add net_tcp_port_get - for tcp sockets (unused).

	don't print dns packet as default action

	expand DNS documentation

	implement DNS RR compressed names.

	implement proper dns packet printing

	add dns_resolve_name using UDP socket to read response;
	partly uses socket: uses the port.

	deliver UDP packets to sockets

	generalize socket_deliver from socket_deliver_icmp; skip IP
	match check for sockets with 0 or -1 as ip.
Minor code16 overflow fix.

Some bios-proxy code (not used) overflowed due to not putting 16 bit code
in .text16. Fixed.
Exception handler & debugger improvements.

idt.s:
	When exceptions are raised while executing CPL3, ss:esp of the CPL3
	code is also pushed on stack.

	Update printing stack to also print ss, esp labels if appropriate;
	print the CPL3 ('user') stack aswell if a privilege change has
	occurred.

	Have debug_print_stack$ take ebx as the stack segment.

	Improve page fault printing.

	When IP is beyond limit, print the limit.

	Invoke debugger on invalid TSS and page fault.

	Print some TSS values - temporary - to inspect tss stack values.

debugger.s:
	save and pass along ebx to debug_print_stack$.
Print caller source/debug on malloc/mfree errors.
Minor updates/fixes.

macros.s:
	remove compile-time debug statements.

paging.s:
	set PDE_FLAG_U and PTE_FLAG_U (user accessible) for CPL3 access.

print.s:
	don't call 'cli' on PRINT_START.

	add _s_printhex8. *NOTE* this is a companion to 2 commits ago (idt.s).

shell.s:
	fix calculating A.ELF boot drive path (each successive invocation
	would increment the drive).

	cmd_exe: call exe_elf, so that the file handle can be closed after.
Implement Ring 3 ELF execution.

elf.s:
	SEL_task(CS|DS) have the same base as SEL_compat(CS|DS) so they
	share the virtual address space and ring3 tasks can call the kernel.

	Create a separate stack at the end of the elf image - required
	due to privilege level switching through the call gate to access
	kernel.

	Update relocation to add the elf image base.

	Add retf to CPL3, and a call to re-enter kernel mode after return.

gdt.s:
	Add a call gate accessible from CPL3.

	Remove compile-time debug printing.

	fix granularity in GDT_SET_LIMIT macro.

	fix GDT_READ_LIMIT macro: mask DPL.

	Register call gate dynamically due to GAS limitation of doing
	pointer arithmetic (*.text* and *ABS* don't mix, even with << and & )

	Add kernel_callgate method: enters CPL0 (by virtue of the call gate
	descriptor), does some stack wizardy, calls the caller, and intercepts
	it's method return. To get ring0 acccess from ring3, simply
	call SEL_kernelCall, and proceed as normal.
	TODO: make secure by using an index argument and a method lookup table.

libc.s:
	most any method now calls the kernel call gate due to needing to
	write to the screen, which uses the SEL_vid_txt when the screen buffer
	is flushed, which is CPL0.

	Improved simplicity of the _c_exit method - the two level leave was
	wrong.

The result of this and the last few previous commits is that simple ELF
executables can now be run in CPL3 (from the CPL0 shell), having kernel-api
access.