Subject: Re: Emulations as LKMs
To: Jarommr Dolecek <dolecek@ibis.cz>
From: Bill Studenmund <wrstuden@zembu.com>
List: tech-kern
Date: 11/06/2000 15:45:53
On Mon, 6 Nov 2000, Jarommr Dolecek wrote:

> Hi,
> it's getting unpleasant that the emulation code is not loadable
> via LKM. Developing new code, testing and debugging is quite
> difficult - having to compile new kernel and to reboot is very
> time consuming. Currently, it makes me think it would actually
> safe me quite some time to implement better emulation LKM logic
> than to continue working the traditional way.

Cool!

> There is some LM_EXEC-related code in sys/kern/kern_lkm.c, but that doesn't
> seem to be working ATM and would probably need some more work to glue
> the emulation properly into running system.

I haven't dived into this, but from skimming our lkm documentation (such
tat it is), the LM_EXEC stuff was designed to load a new execution format
in. Loading an emulation is something different (though related).

As an example to show the difference, the LM_EXEC stuff would be most
directly targeted at say developing ELF support for the m68k arch.

I.e. I think you want to be adding "LM_EMUL".

> What I think needs to be done (in no particular order):
> - split binary format and emulation so that we can have single emulation
>   structure for all supported binary formats of that particular emulation
> - add some functions to make it possible to add/remove emulations dynamically
>   as well as having them compiled in
> - add refcnt to emulation and binary format structures, so that it's possible
>   to find out if it's safe to unload it

All sounds good.

> - add an easy way to check for type of process emulation;
>   current practice of
> 
> #ifdef COMPAT_FOO_OS
>   if (0
> #ifdef EXEC_AOUT
>   || p->emul == &emul_FOO_OS_aout)
> #endif
> #ifdef EXEC_ELF32
>   || p->emul == &emul_FOO_OS_elf32)
> #endif
>   ) { do_stuff; }
> #endif /* COMPAT_FOO_OS */
> 
>   .. should die and become something like:
> #if defined(COMPAT_LINUX) || defined(LKM)
>   if (emul_is_equal(p->emul, EMUL_LINUX) {
> 	do_stuff;
>   }
> #endif

That should be fine.

>   (would be good to find out how FreeBSD folks solved this)
> 
> - there are probably more - feel free to comment :)

Go for it!

Take care,

Bill