[haiku-development] Re: undertanding syscall

  • From: romain.haiku@xxxxxxxxxxx
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Sun, 30 Nov 2008 23:02:29 +0100 (CET)

From: "JiSheng Zhang" <jszhang3@xxxxxxxxx>:

>> "_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" ?
>
>Dunno.
>
>Hope it helps!

Sure! I will look at all this. Thanks a lot for this detailed answer.

Romain.



Other related posts: