[haiku-development] Re: undertanding syscall

  • From: "JiSheng Zhang" <jszhang3@xxxxxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Mon, 1 Dec 2008 04:14:27 +0800

hi romain,

2008/12/1  <romain.haiku@xxxxxxxxxxx>:

> "_kern_is_computer_on". However I could not find where/how is defined the
> latter one. I suppose that it is generated by some tool since I can find
> it in the generated "libroot.so".
_kern_xx is declared in headers/private/system/syscalls.h and defined
in generated/objects/haiku/x86/common/system/libroot/os/syscalls.S.inc
which is generated by gensyscalls
> So basically I am missing 2 parts of the chain:
> - Where is the "_kern_xxx" code for all userland calls to syscalls ?

well, look at the syscalls.S.inc, there are many SYSCALLX(_kern_xxx,
x) lines. And SYSCALLX is defined in src/system/libroot/os/arch/x86(or
other arch)/syscalls.inc. They are all most the same just save the x
in register %eax and then jump to specific address in a common page.
The page is exported to userland by kernel during kernel booting. The
kernel will test the cpu to see if it supports sysenter instruction.
If so, the specific address will rewritten with
_user_syscall_sysenter, otherwise with _user_syscall_int. The two
_user_syscall_xxx are defined in src/system/kernel/arch/x86/syscall.S.

Let's say the cpu doesn't support sysenter,  so _user_syscall_int will
be used. The code just trigger "99" interrupt. The ISR will be
initialized with "trap99" defined in
src/system/kernel/arch/x86/arch_interrupts.S. After doing some
preparation it will call handle_syscall. it will check syscall number,
copy parameters etc. then will call the corresponding function of a
struct syscall_info in kSyscallInfos. The function is just _user_xxx.
The kSyscallinfos symbol is defined in
generated/objects/haiku/x86/common/system/kernel/syscall_table.h which
is auto generated by gensyscallinfos.

Secondly, if the cpu support sysenter, _user_syscall_sysenter will be
used and the x86_sysenter(defined in
src/system/kernel/arch/x86/arch_interrupts.S) will be written into MSR
EIP register. After sysenter instruction x86_sysenter will be carried
out. Please refer the Intel Architecture Software Developer's Manual
for details. x86_sysenter will also call handle_syscall after some
preparation. Then everything is OK.

> - Where is the link between the interrupt that is generated and the call
> to the corresponding "_user_xxx" ?

Look above

> Btw why does the code in the kernel is prefixed "_user", and the code in
> user is prefixed "_kernel" ?


Hope it helps!


Other related posts: