Tumbled Logic

Jan 16 2010

Fun Things I Wrote A Long Time Ago

Once upon a time, about 2002ish, I think, I was doing a lot of work with x86-based embedded systems. Set-top boxes, that sort of thing.

One weekend, I sat down and ported NetBSD’s ELF ld.so to be a standalone Multiboot-compliant executable.

It worked like this: in GRUB’s menu.lst, you’d specify this port of ld.so as the “kernel”, and then the actual operating system kernel as the first “module”. The ported ld.so had basic memory management and console I/O facilities, and instead of loading and mapping files using syscalls, would deal with whatever the Multiboot structure passed to it by GRUB told it was already there.

This meant the real kernel could be dynamically-linked. The side-effect of this was that a lot of the system-dependent code could be moved into a shared library. Because the ported ld.so didn’t actually care about the shared library dependencies listed in the executable (it couldn’t actually load any files, after all), it meant the real kernel could be an executable which ran in user-space on some ELF-supporting operating system with a different shared library. In my case, I used Linux, but it could have just as easily been one of the BSDs, or Solaris, or whatever.

In other words, the kernel was just a program: all of the nasty low-level stuff was kept in a .so (which I called the hardware abstraction layer, or “HAL”, as it performed a similar function to Windows NT’s HAL) which was only ever loaded by GRUB, and was emulated by a second .so which the actual kernel was linked with. Thus, I could have a hal-i586.so which GRUB loaded, and a hal-linux-i586.so which Linux would load if I ran the kernel as a user-space program.

Sadly, I never actually did anything with this. Business priorities shifted and I ended up working on a lot of Windows CE stuff for a while (the pinnacle of this was replacing a very broken vendor-supplied NIC driver with a port of one from FreeBSD; that was fun, let me tell you).


blog comments powered by Disqus
Page 1 of 1