Page 1 of 1

exporting kernel functions

Posted: Tue Jul 03, 2007 1:01 am
by spectrum
hello all,

i'm at the beginning of a little os, and i need some help about the right way to export basic kernel functions, as for example the function that print the output on the screen. I've that function inside the kernel now, and i would that it ca be available to an external libc, so that user programs can at the end make use of that.

My cose is asm for the boot, but the rest is plain C.

Thanks, angelo

Posted: Tue Jul 03, 2007 1:11 am
by AJ
Hi,

Do you want any kind of protection for your kernel? The usual answer is 'yes' - if you have user tasks that are able to access kernel functions directly, they can also overwrite kernel data, which is considered a Bad Thing.

The more normal way to do it, is to have user tasks running in CPL3, kernel code running in CPL0, and have an interrupt handler setup (in Linux, this is int 0x80 and I believe windows uses 0x20, for example). When your user code wants to access a kernel function, it loads EAX with the function numbers and then calls your interrupt. Let's say you had a function 0x0001, which prints directly to the console from ESI:

Code: Select all

my_user_function:
   MOV  EAX,  0x0001
   MOV  ESI, [MY_STRING_ADDRESS]
   INT   0x20      ;or whatever your kernel uses
ret
Of course, that's only a brief outline.

Cheers,
Adam

Posted: Tue Jul 03, 2007 1:29 am
by spectrum
ok, many thanks, that's what i need for now.

angelo