Split mem_handles.s from mem.s
Minor mem fixes.

kernel/mem.s:
	mem -ha also prints free handles as it prints all handles
	referring to nonzero memory blocks.

kernel/mem_handle.s:
	remove redundant flag setting for old handles_handle.
	don't mfree the first time.
Fix debugger print schedule.

It uses cmd_tasks which expects to be called as a shell command, i.e., esi
pointing to an array of stringpointers.
Control, alt, shift maintain scroll mode.

When the console is in scroll mode (page up), any key not belonging to the
class of keys to manipulate the scrolling will exit scroll mode.
This commit maintains scroll mode when control, shift, or alt is pressed,
especially useful for focus shifting to and from the virtual machine.
ARP update.

kernel/net/arp.s:
	Implement ARP according to RFC 826.

		The main difference is that in the previous implementation,
		the ARP table was only updated on reception of a response
		in answer to a locally originated request.

		This commit changes that, so that whenever a valid ARP packet
		is received, the ARP table is updated IF the remote IP is
		already present in the table. If it is not present, it will
		be added IF the packet is targeted to a local NIC's address.
		This implementation is potentially insecure, as third parties
		can send ARP packets to update the ARP table for IP's other
		than their own. However, it conforms to the RFC.

		The benefit of this approach is that when a handler called
		by the netqueue task sends an IP response, the IP will already
		be known, IF the remote party first sent an ARP request before
		sending an IP packet.

	Implement generic ARP table.

		A compilation flag ARP_TABLE_GENERIC determines whether IPV4
		optimized, or a generic ARP table implementation is used.

		The generic implementation allows for different software
		protocol addresses (IPV4, IPV6 at current) to be stored in
		the ARP table. The hardware addresses are not flexible, as only
		Ethernet is implemented.

		The ARP_TABLE_GENERIC flag must be enabled to support IPV6.

kernel/net/ipv6.s:
	Mostly a placeholder file.

	Implement net_print_ipv6 and net_print_ipv6_smart, the latter untested,
	which attempts to print the address with the largest sequence of 0
	collapsed.

kernel/net/net.s:
	include ipv6.s.

	add label 'net_packet_print' for 'net_print_protocol' (which will be
	removed).

	add debug label 'net_rx_pkt' in net_rx_packet after the mdup call,
	for printing the callers in 'mem -ha'.

	add (disabled) debug.

kernel/nic.s:
	add nic_get_by_ipv6 dummy implementation, which is referenced if
	ARP_TABLE_GENERIC is 1.
kernel/dev.s:
	add dev_pci_subvendor and dev_pci_subdevice fields in dev struct.

kernel/pci.s:
	add DEV_PCI_CLASS_* constants for storage, multimedia, and bridge.

	fix loop bug for when device class API is empty.

	Store the subsystem vendor and device id's in the dev struct.

	Print capabilities if the capability pointer
Fix TSS stack bug.

The TSS used [realsegflat] as the stack top which is the physical start address
of the kernel image. SS is based on this same address, and therefore ESP
pointed to offset [realsegflat] in the kernel image, which happened to be
somewhere in the code. Whenever a RING elevation occurred, code would be
overwritten (general protection faults where the bytecode did not match
the image).

Changed this so that the init_gdt_16, which sets up the kernel stack,
also allocates a stack for the TSS.

kernel/gdt.s:
	move call to init_tss_16 after setting up the kernel_(tss0_)stack_top.

kernel/pmode.s:
	declare kernel_tss0_stack_top.

kernel/tss.s:
	use [kernel_tss0_stack_top] instead of [realsegflat] for tss_ESP0.
PCI updates.

Summary:
	Print PCI device Capabilities list if present.
	Implement PCI Configuration Area layout for header type 1: Bridges.
	Declare null drivers for currently observed PCI devices in VMWare.

kernel/cmos.s:
kernel/print.s:
	move macro PRINTIF to print.s

kernel/pci.s:
	Fix PCI_STATUS_ flags according to the PCI specs. Turned out

	Declare DEV_PCI_CLASS_BRIDGE_ISA.

	Print capabilities list:
		fix preservation of command&status flag containing
		PCI_STATUS_CAPABILITIES_LIST;

		document and print the known capabilities.

	Implement parsing the PCI-to-PCI Bridge header type configuration
	space layout and allow drivers to be matched for it.
	(pci_list_pcibridge$)

	Extract pci_list_bar$ and pci_list_caps$.

	Fix PIIX4 ISA host bridge PCI class in driver declaration.

	Declare PCI (null) drivers for VMWare devices.
Proper mem caller registration; minor fixes.

	Summary

	The mem functions (malloc etc), aswell as some other core buffer and
	array functions now register the caller properly, by setting up ebp
	to point to the caller return stack. There are two versions of most
	of these functions, one meant for internal use, to preserve the caller
	of the 'library' function so that the proper place of allocation
	is traceable (i.e., having mem blocks registered by 'buf_new' is
	undesirable). The other version of the function is meant as a public
	API, which will take it's caller's address and propagate it to the
	registration code.

kernel/cmos.s:
	move PRINTBITS8 macro to print.s as PRINTBITSb.

kernel/print.s:
	add PRINTBITSb from cmos.s.
	add PRINTBITSw, PRINTBITb, PRINTBITw,
	and _PRINTBITSHEX internal utility.

	[the PRINTBIT(b|w) is used in uncommitted code].

kernel/fs.s:
	add CF check for array_new call.
	preserve edx in fs_new_handle while calling FS API close, just in case.

kernel/mem.s:
	add '_' suffixed versions for public mem functions: malloc_, mrealloc_,
	mallocz_, mreallocz_, malloc_aligned_. These expect [ebp] to point to
	the caller to be registered in the allocations, rather than stack
	trickery to find out the call depth.
	The unsuffixed functions (i.e. malloc) set up ebp and call the suffixed
	version (which is the original function).o

	Update cmd_mem$: register code sections for string, vid and usb.

kernel/hash.s:
	call the '_' suffixed mem functions (mallocz_, mreallocz_ etc.).
	rename buf_new to buf_new_ and buf_resize to buf_resize_ for calls
	from hash.s itself,
	and add buf_new and buf_resize, setting up ebp.

	For example, array_new as an 'exported function' sets up ebp,
	calls buf_new_, which calls mallocz_. Thus, the handle will contain
	the caller to array_new, rather than the caller to mallocz.

kernel/string.s:
	update strdup, strdupn, strndup to call malloc_.

kernel/usb.s:
	remove debug print of IRQ.

kernel/vmware/svga2.s:
	remove debug print of IRQ.

	enable the startup check (going in and out of gfx mode).
	Record the textmode WxHxBpp.
	Do not use SVGA_CAP_TRACES unless the capability is present. It is not
	present in QEmu 1.3's vmware SVGA II device.
Shell: add 'int', extend 'pic'

kernel/shell.s:
	add cmd_int, to trigger an interrupt given in hex.

	update cmd_pic: print the IRQ numbers and original names,
	and print their handlers if IRQ_PROXIES is enabled.
Minor: fix print schedule caller on disabled

kernel/schedule.s:
	When scheduling is disabled, a call to schedule_near
	will print an error message referring to the caller, properly.

	Set the 'sched.debug' environment variable after scheduling
	is enabled so that mfree
	(called by buf_resize called by the env var setting),
	which uses a mem spinlock, doesn't generate the printing of the error.
Minor: mem debug fixes.

kernel/mem_handle.s:
	make debugging optional and turn it off.
ISo9660: print errors on mount fail.
Fix PRINT macro (GAS oddity)

kernel/print.s:
	When issuing:  print "foo '", the print macro:

	.macro PRINT msg=esi
		.ifnc esi,\msg
		PUSH_TXT "\msg"
		call	_s_print
		.else
		call	print
	.endm

	generates the code:

		call	_s_print

	which ends with 'ret 4'.

	Somehow the ' prevents or distorts the macro call.

	Fixed by replacing .ifnc esi,\msg with .ifnes "esi","\msg".
Major DEV/PCI OO Overhaul.

SUMMARY
-------
	o DEV/PCI OO Overhaul: implement OO.G
	o fix PCI scan for multiple-function devices.
	o add PIIX4 IDE BM driver (experimental).
	o fix am79c971 very rarely not working: dword aligned buffer.

CHANGES
-------

TODO:
	Notes on IDE busmastering;
	Notes on reworking pci/devices to OO.
	Notes on am79c.

kernel/Makefile:
	add '--MD kernel.dep' to generate source-dependency file
	for use in (uncommitted) doc.pl.

	Register oo.s.

	register Intel device drivers: i440.s, ipiix4.s.

kernel/i440.s:	(NEW)
	Add dummy driver for the Intel 440 BX/ZX/DC Host/AGP Bridge.
	Contains a schematic of the motherboard, busses and such.

kernel/ipiix4.s:	(NEW)
	Add Intel PIIX4 drivers:
		fn 0: ISA Host Bridge - dummy.
		fn 1: Busmaster IDE Driver - experimental.
		[fn 2: USB (not implemented/present in vmware)]
		[fn 3: APM (not implemented/present in vmware)]

kernel/defines.s:
	record SECTION_DATA_PCI_CLASSES and SECTION_DATA_PCI_CLASS_METHODS.
	(and renumber SECTION_DATA_PCI_DRIVERINFO).

kernel/kernel.s:
	Record .data SECTION_DATA_CLASSES and SECTION_DATA_CLASS_METHODS.

	Include oo.s.
	Include i440.s.
	Include ipiix4.s

	add optional MEM_TEST, and consequently a SCHEDULE_EARLY compile
	flag, which enables scheduling right after mem_init is called
	(so that mfree doesn't print mutex/yield/schedule errors).

	Add example of how and where to set a breakpoint when mem overwrites
	are apparent.

kernel/oo.s:	(NEW)
	Object Orientation.

	This code replaces most of what dev.s and pci.s's DECLARE_PCI_DRIVER
	used to do.

	Declare macro's:
		DECLARE_CLASS_BEGIN classname, supername
			Begins a .struct at the size of class_\supername.
		# field declarations
		DECLARE_CLASS_METHOD apiname, codeoffset[, OVERRIDE]
			Registers a method in SECTION_DATA_CLASS_METHODS,
			and declares a label in the struct (unless OVERRIDE).
		DECLARE_CLASS_END classname
			Completes the struct and registers the class
			in SECTION_DATA_CLASSES, under label class_\classname,
			with object size, a pointer to the method array,
			number of methods, number of overrides,
			and a super-class pointer (or 0).
			[NOTE: classname cannot be remembered from the _BEGIN
			macro because it is a string - GAS limitation]

	add class_newinstance, which allocates the proper size for the object,
	and fills in the vptr table (method pointers); Has some checks.
	The object is registered in a ptr_array class_instances.
	Methods can be overridden, and due to the subclass->superclass
	progression, preserving filled in methods, both implementing
	abstract classes aswell as overriding existing method implementations
	are possible.

	Implement cmd_classes, which prints all registered classes,
	their hierarchy, and their methods (and code/source address).

kernel/hash.s:
	add field obj_class to the OBJ struct. This 'class' is the
	top level Object class.

kernel/shell.s:
	register cmd_classes as "classes".

kernel/fs.s:
	disable the code that lists the devices in /dev.

kernel/pci.s:
	Main changes:
		- PCI addr is now a dword, not a word: the 3rd byte is
		the PCI Function.
		- Multiple-function devices are supported.
		- Using the OO code.

	Specifics:

	device name prefixes:
		add br, mmaudio/video/phone
		rename ipi/eipic to pic.

	PCI Driver struct:
	rename pci_driver_class/subclass to pci_driver_pci_*, add _pci_func.
	add pci_driver_class to refer to the oo class definition.

	Change the DECLARE_PCI_DRIVER macro: remove the init,
	and the obj_init/init/api/api_size data.

	pci_list_drivers: when bl (pci class) is -1, list all drivers.
	(not called from anywhere yet).

	pci_find_driver: reworked. The old implementation expected ebx
	to be a dev object pointer, but this code is called before
	object instantiation. Thus it takes the pci class and vendor info
	in registers. The code when a driver was found is removed.

	pci_list_devices: support scanning multi-function devices. PCI-to-PCI
	bridges are only instantiated and listed for Fn 0, since they
	all have 8 functions (for successive busses).
	call pci_instantiate_dev$ instead of dev_get/newinstance.
	Add checks around dev_api_constructor call after all PCI info
	has been filled in: the first check is to see whether the
	device has already been initialized (a new dev_state field).
	[at current this has no effect since running lspci will create
	a second instance for each device).
	The second check is whether the dev_api_constructor is defined (!NULL).
	If not, debug mode is entered (int 3) - press 'c' to continue.

	Add pci_print_bus_architecture, which prints all devices on all
	busses, slots and functions, including the bridges. The idea was
	to have a hierarchy, but it is very evident without a tree-printing.

	add pci_instantiate_dev$ to make the pci_list_devices cleaner.
	It replaces the dev_newinstnace stuff. It searches for a pci
	driver, if found, uses the class to call class_newinstance,
	(and otherwise uses the dev_pci abstract class),
	and then fills in the vendor, pci addr, pci class,
	and generates a device name.

	pci_list_pcibridge$: reworked printing.

	At the bottom some DECLARE_PCI_DRIVER calls for newfound devices
	in VMWare and Qemu. Also the nulldev init code has been merged.

kernel/dev.s:
	DECLARE_CLASS dev; add dev_state to record whether the init is
	called, so future lspci's don't re-initialize the device.
	[this worked, until the OO reworking].

	Removed the class_ class, class_get_info, and the device_classes
	constructs (dev_init$, dev_newentry, dev_relocate,
	dev_get_class_info, dev_newinstance, dev_getinstnace, [devices])
	in favour of the new OO implementation.
	Same goes for the _pre_constructor kludge.
	dev_pci_constructor's useful bits are copied into pci.s'
	pci_instantiate_dev$.

	The dev_pci_* proxies are updated to use the dword pci addr.

	cmd_dev_list is disabled for now.

	DECLARE_CLASS vid, from vmware/svga2.s.

Device drivers:
---------------

kernel/nic.s:
	create the nic struct using DECLARE_CLASS_*.

	reimplement nic_init to scan the class_instances for class_nic.
	changed ABI: ebx no longer yields [devices], as objects
	in class_instances use 'absolute' pointers.

	nic_getobject, nic_get_by_network, nic_get_by_ipv4, nic_get_by_mac:
	updated to handle the changed semantic of ebx. Code is left as is,
	except for zeroing ebx, in case object pointers will become relative.

	remove nic_constructor, nic_obj_init, and obsolete/disabled code.

	remove nic_name from nic struct, and use dev_drivername_short.

kernel/ata.s:
	Update ata_list_drive to use class_newinstance instead of
	dev_get/newinstance.

	declare ATAPI_DRQ_CMDIN.
	Add some comments on LBA for DMA_READ_EXT.
	declare ATAPI_COMMAND_SRST.

	rework ata_isr1/ata_isr2 - add some disabled status code,
	left-overs from the BM IDE integration.

	add ata_print_drq_reason$.

kernel/am79c971.s:
	DECLARE_CLASS nic_am79c instead of a struct.
	Made the register read/write debug more compact.

	Update the init: add a check for CSR_MODE after IDON,
	which reads as 0xf instead of PORTSEL0 on error.
	FIX BUG: Make sure the init_block is dword aligned.

	Debug tweaks.

kernel/i8254.s:
kernel/rtl8139.s:
	use dev_drivername_short instead of nic_name.

	DECLARE_CLASS instead of struct.

kernel/vmware/svga2.s:
	moved the vid struct to dev.s as a proper DECLARE_CLASS.
	removed the object/find pci driver init code (vid_obj_init,
	vid_constructor).

	DECLARE_CLASS vmsvga2 instead of a vid struct. Also renamed
	all fields from vid_ to vmsvga2_.

kernel/usb.s:
	DECLARE_CLASS ...

	added some spaces in flag printing.

.tcshrc:
	add qemu-vmware alias for qemu 1.3.50 using the vid-vmware driver.
	At current the drivers are incompatible as it corrupts the font
	after switching to/from gfx mode.