Subject: Re: misc kern questions
To: Travis H. <>
From: Hubert Feyrer <>
List: tech-kern
Date: 08/25/2006 12:15:26
On Thu, 24 Aug 2006, Travis H. wrote:
> Can anyone describe succinctly how, say, Linux binary emulation works?
> URLs welcome.  Calls to RTFM just as welcome.  I'm hoping for
> something very low-level, like explaining that int 0x80 maps does
> this-or-that, whereas NetBSD natively uses int 0x81, or whatever.

NetBSD doesn't use BIOS interrupts (usually), it calls its own device 

As for how things happen, look at the list that I posted yesterday 
( The kernel knows under what emulation (native, 
linux, ...) a binary runs as it looked at the exact ELF type when starting 
the binary, and remembered that one, and then chooses a system call table 
appropriate for that binary. The idea of the native syscall table should 
be obvious. The 'emul' syscall tables either map emulated syscalls 
directly to native ones, or to "wrapper" functions that adjust semantical 
differences between the systems (before usually calling native syscalls 
again). See src/sys/compat/linux/arch/i386/syscalls.master for an example 
- you will see calls to many linux_*() functions, but also to some native 
ones like sys_read(). The implementation of those linux_*() functions is 
in the same directory and in src/sys/compat/linux/common.

Different register handling between NetBSD and Linux is handled by things 
like linux_syscall_plain() in src/sys/arch/i386/i386/linux_syscall.c.
(I'm actually not sure how this hooks into the overall syscall framework, 
but I guess that can be found out :)

Some URLs to read - the majority are not specific to i386, but go into 
much detail and give an in-depth overview of how things work:

Implementing Linux emulation on NetBSD:

Linux compatibility on BSD for the PPC platform (5 parts):

Irix binary compatibility (6 parts):

> Do the Linux syscalls actually implement the entire syscall, or do
> they rearrange arguments and call the native syscall?

See above.

> Does NetBSD use
> any Linux code?

This is prohibited by the Linux license - NetBSD doesn't allow GPL in the 

> IIRC Linux keeps most of the args in registers, and
> BSD copies them off the stack; how do we support both, just
> __asmlinkage__ the Linux syscalls and not the native?
> I assume that emulating Linux LKMs is not possible; does VMWare run
> natively?  How about Xen?