Reimplenting Linux Kernel in Python

Bengt Richter bokr at oz.net
Thu Oct 14 22:07:52 EDT 2004


On Fri, 15 Oct 2004 00:37:39 -0000, mike at hobbshouse.org (Michael Hobbs) wrote:

>Mike Meyer <mwm at mired.org> wrote:
>> mike at hobbshouse.org (Michael Hobbs) writes:
>>> I had once given serious thought to what it would take to write an OS 
>>> only in a high-level language. (Standard ML was my language of choice
>>> at the time.) The short answer is, no, it can't be done with Python as
>>> it currently stands. 
>> But it can be done. It *has* been done.
>> [snip]
>> Actually, you don't need those modifications to Python. What you need
>> is a module written in something other than Python that lets you do
>> all those things.
>
>Sorry, I should have emphasized the word *only*. I'm talking about writing
>an OS *only* with Python. No C, no assembly, just Python. Writing an OS 
>without assembly would be impossible unless the compiler can somehow map
>required processor opcodes to a function or statement in the higher-level
>language. Python does not currently have a proper compiler, much less
>functions or statements that would, say, put the processor into protected
>mode.
>
OTOH, it's a bootstrapping process. You can start by putting together
a python string that contains an image of the boot block on a bootable floppy,
and with suitable permissions you can write it to an actual floppy.

Next you can create a python string that is the image of a boot loader, that
the boot block will know where to find and read into memory using BIOS, if you
put it in a certain place on the floppy. And then you can get the loader to load
your OS image, which is a big bunch of bytes. You might want to structure the floppy
info for access as a primitive (non-patent-infringing ;-/) file system.
Maybe you will want to do a bootable CD instead ;-)

Anyway, CPU instructions are just bytes. As a start, it might be interesting to try to build
a dll extension in an mmap array and import it (be prepared for lots of crashes ;-).

Obviously mmap etc depend on the OS, but if you had prepared a suitable bootable OS
with a primitive file system and mmap functionality, and a userland python VM, ... well,
it's involved, but you can get there. I'd bet pypy will eventually be at the center of
something like that, with maybe a monolithic boot image in flash, and BIOS to boot it.
At some point, on a suitable platform, it will be able to self-host its own development, I'd bet.

Regards,
Bengt Richter



More information about the Python-list mailing list