PetrOS Native Kernel API

All calls are currently through 
	int 0x20

unless specified, all strings are short pascal strings

	struct
		len	db ?
		value	db 255 (?)
	ends


For all functions,

	eax = function number
		bits 16:31	major function
		bits 0:15	minor function
			0:	get subsystem name
				returns 
					@params.p1 = subsystem name


for some functions	
	edx = pointer to a parameter block.

		struct
			p1	dd ?
			p2	dd ?
			p3	dd ?
			p4	dd ?
			p5	dd ?
			p6	dd ?
			p7	dd ?
			p8	dd ?
		ends


major: (eax >> 16)
	minor: (eax & 0xFFFF)




1:	Filesystem
		ax = minor function
		edx = parameter block
	returns
		eax = result

	(see filesystem section)

2:	Console I/O
	ax	= minor function


	1:	write char
			dl = char


	2:	key pressed
		returns
			eax = 0		no key pressed
			eax = 1		key pressed


	3:	read key
		returns
			eax = character  (if 0 then extended scancode follows)


	4:	write string
			edx = pointer to string
			ecx = length of string


	5:	set cursor (0,0 = top left)
			ecx = x posn
			edx = y posn


	6:	get cursor (0,0 = top left)
			ecx = dword ptr
			edx = dword ptr
		returns
			@ecx = x posn
			@edx = y posn


	7:	set screen attr
			ebx = attr (0:3 = foreground, 4:7 = background)


	8:	get screen attr
		returns
			eax = attr


	9:	get screen number of lines
		returns
			eax = number of lines


	10:	get screen frame buffer base
		returns
			eax = text buffer address (usually 0xb0018000)


	11:	vesa set screen mode
			ebx = screen mode (0-$FF = VGA, $0100-$FFFF = vesa)


	12:	vesa set bank
			ebx = bank


	13:	vesa get mode info
			ebx = mode
			ecx = ptr to vesa info
		returns
			@ecx filled in


	14:	read keyboard scan code
		returns
			eax = scan code


	15:	read keyboard scan code extended
		returns
			eax = extended scan code


3:	Multitasking


	1:	kill current process (hard kill - does not call user epilogue)


	2:	exit process (calls user epilogue)


	3:	exec process
			edx = executable name (pascal string)
			ecx = command line (pascal string)
		returns
			eax = process primary thread id
			waits for termination, or subprocess detach


	4:	exec detached process
			edx = executable name (pascal string)
			ecx = command line (pascal string)
		returns
			eax = process primary thread id
			does not wait


	5:	create thread in current process
			ebx = address of thread procedure
			ecx = thread exit procedure
			edx = initial stack ptr
			esi = thread parameter
			edi = thread info ptr (housekeeping)
		returns
			eax = thread id, or 0 if failure


	6:	sleep
			edx = msecs


	7:	get thread info ptr
		returns
			eax = thread info ptr


	8:	get thread/process command line
			edx = ptr to string
		returns
			@edx = command line


	9:	exec process with debugger
			edx = executable name (pascal string)
			ecx = command line (pascal string)
		returns
			eax = process primary thread id
			waits for termination, or subprocess detach


	10:	get thread name
			edx = ptr to string
		returns
			@edx = thread name


	11:	set exit procedure for process
			ebx = address of exit procedure


	12:	get exit procedure for process
		returns
			eax = address of current exit procedure


	13:	detach current process


	14:	signal thread
			ebx = thread id
			ecx = signal number (0-31)


	15:	set fault handler
			ebx = new fault handler
		returns
			eax = old fault handler


	16:	enter v86 mode
			ebx = new stack frame


	17:	set i/o port access (SECURITY HOLE *************)
			edx =	0	disable access
				1	screen access 
					  (3b4,3b5,3D4,3d5,3d8,3da,3c0-3cf)
					timer access
					  (42)
					speaker
					  (61,62)
				2	all access (000-FFF), IOPL=0
				3	all access (000-FFF), IOPL=3


	18:	get environment
			ebx = environment buffer
			ecx = size of environment buffer
		returns
			eax = size of environment
			      -size if buffer too small


	19:	set environment
			ebx = new environment buffer
		returns
			eax = size of environment
			      -size if system buffer too small


	20:	map meg zero (SECURITY HOLE ************)
			edx = page zero PTE
		returns
			eax = old page zero


	21: 	set v86 timer rate
			ebx = period of timer


	22:	get environment string
			ebx = null terminated name of env string
			ecx = buffer
			edx = length of buffer
		returns
			@ecx = null terminated env value


	23:	set environment string
			ebx = null terminated name of env string
			ecx = null terminated string value
		returns
			eax = 1 success 
			      0 failure


	100:	extended exec process
			edx = parameter block
				p1 = program name
				p2 = program command line
				p3 = flags (detached = 1, debug = 4)
				p4 = stdin
				p5 = stdout
				p6 = stderr
		returns
			eax = primary thread id


	4096:	process/thread status
			ecx = thread id
			edx = ptr to thread status
		returns
			eax = 1 success
			      2 failure


	4097:	dump free


	4098:	dumppagelist


4:	Commio	(obsolete)


5:	Clock


	1:	get millisecond clock
		returns
			eax = milliseconds since system start


	2:
		get 64 bit absolute time (NT style, 100nsec resolution)
		returns
			eax = systime.lo
			edx = systime.hi


	3:	get system clock ticks (usually 10 msec ticks)
		returns
			eax = ticks


6:	Reserved


7:	Socket services
		ax = minor function
		edx = parameter block

8:	Virtual memory control
		ax = minor function
		edx = parameter block


9:	Device driver services
		ax = minor function
		edx = parameter block


10:	stdin/stdout services


	1:	write char to stdout
			edx = ptr to char


	2:	char avail on stdin (keypressed)
		returns
			eax = 1 avail
			      0 not avail


	3:	read char from stdin
		returns
			eax = char


	4:	write string to stdout
			edx = ptr to string
			ecx = length of string


11:	Reserved


12:	Floppy disk i/o (testing only)
		ax = minor function
		edx = parameter block


13:	Mouse i/o


	1:	mouse on


	2:	mouse off


	3:	get mouse state
			ebx = dword ptr to mouse x
			ecx = dword ptr to mouse y
			edx = dword ptr to mouse buttons
		returns
			@ebx = mouse x
			@ecx = mouse y
			@edx = mouse buttons


	4:	set mouse position
			ebx = mouse x
			ecx = mouse y


	5:	get mouse delta
			ebx = dword ptr to mouse delta x
			ecx = dword ptr to mouse delta y
			edx = dowrd ptr to mouse buttons
		returns
			@ebx = mouse delta x
			@ecx = mouse delta y
			@edx = mouse buttons
			delta x & y reset to 0


	6:
		set mouse delta
			ebx = mouse delta x
			ecx = mouse delta y
			edx = mouse buttons


14: 	LDT management


	1:	create LDT
			ebx = size of LDT


	2:	free LDT


	3:	resize LDT (unimplemented)
			ebx = new size of LDT


	4:	new LDT desc
			ebx = base
			ecx = limit
			edx = 0 data, 1 code
		returns
			eax = selector


	5:	free LDT
			ebx = selector


	6:	get base
			ebx = selector
		returns
			eax = base


	7:	get limit
			ebx = selector
		returns
			eax = limit


	8:	get LDT descriptor
			ebx = selector
		returns
			ecx = desc.long0
			edx = desc.long1


	9:	set LDT descriptor (checked)
			ebx = selector
			ecx = desc.long0
			edx = desc.long1


FileSystem functions

all io results returned in eax


0:	get subsystem name
	returns
		@p1 = 'FILEIO'


1:	open file
		@p1 = handle
		p2 = name of file
		p3 = how:(fm_open = 1, fm_create = 2)


2:	close file
		p1 = handle


3:	read file
		p1 = handle
		p2 = buffer
		p3 = length
		@p4 = bytes read


4:	write file
		p1 = handle
		p2 = buffer
		p3 = length
		@p4 = bytes written


5:	seek file
		p1 = handle
		p2 = offset
		@p3 = new posn


6:	getsize
		p1 = handle
		@p2 = size


7:	getposn
		p1 = handle
		@p2 = posn


8:	iocontrol
		p1 = handle
		p2 = ioctl
		@p3 = param


9:	get file time
		p1 = handle
		@p2 = dos file time


10:	get file attr
		p1 = handle
		@p2 = dos file attr


11:	set file time
		p1 = handle
		p2 = dos file time


100:	dir open
		@p1 = handle
		p2 = search path


101:	dir read
		p1 = handle
		p2 = dir info buffer
		p3 = buffer length
		@p4 = bytes transferred


102:	dir close
		p1 = handle


103:	expand path name
		@p1 = path


200:	chdir
		p1 = name of dir


201:	getdir
		@p1 = name of dir


202:	mkdir
		p1 = name of dir


203:	rmdir
		p1 = name of dir


204:	delete file
		p1 = name of file


205:	rename file/dir
		p1 = old name
		p2 = new name


206:	get system dir
		@p1 = name of dir


300:	get std handle
		@p1 = handle
		p2 = type of handle


301:	set std handle
		p1 = handle
		p2 = type of handle


302:	readkey from std in
		@p1 = char


303:	keypressed from std in
		@p1 = boolean key pressed


304:	is console
		@p1 = boolean is console


305:	dup handle
		@p1 = new handle
		p2 = handle


306:	write std out
		p1 = buffer
		p2 = length


350:	create pipe
		@p1 = handle read pipe
		@p2 = handle write pipe


401:	open comm port
		@p1 = handle
		@p2 = comm file name


800:	open mutex
		@p1 = handle
		p2 = mutex name
		p3 = can create
		p4 = initial owner


801:	open semaphore/event
		@p1 = handle
		p2 = semaphore name
		p3 = can create
		p4 = init count
		p5 = max count


900:	open drive
		@p1 = handle
		p2 = drive name


901:	open node
		@p1 = handle
		p2 = drive
		p3 = node address (cluster start)


Virtual memory services


0:	get subsystem name
		@p1 = 'VMEM'


1:	virtual alloc
		p1 = address
		p2 = size
		p3 = allocation type
		p4 = protection


2:	virtual free
		p1 = address
		p2 = size
		p3 = freetype (ignored)


3:	global memory status
		@p1 = memory status block


0x101:	virtalloc
		p1 = base
		p2 = size
		p3 = flags


0x102:	virtfree
		p1 = base
		p2 = size


0x103:	virtfindfree
		p1 = start
		p2 = end
		p3 = size


0x104:	virtavail
		p1 = base
		p2 = size


0x105:	map real memory 0xA0000 to user space for 0x60000


0x106:	create file mapping
		p1 = rva
		p2 = virtual size
		p3 = file handle
		p4 = offset of file segment
		p5 = size of file segment


0x107:	map real memory 0x00000 to 0x100000 for 0x1000