Python without an operating system
lwn.net
lwn.net
(also, everytime I see an LWN article here, I keep meaning to subscribe, but I mostly read HN at work, and I usually forget by the time I get home... I feel really bad about that)
If you work anywhere even remotely related to Open Source, I'd recommend getting your employer to get a corporate subscription. It's one of the single most valuable news sources I read; it summarizes LKML and numerous other first-hand sources, as well as many conferences, summits, and other in-person events.
http://uuu.cvs.sourceforge.net/viewvc/uuu/
Edit: http://dl.sourceforge.net/project/uuu/Existence/2003-09-21/e... should boot with qemu-system-i386
If you were to build a Python OS, you'd probably start by writing PID 1 in Python. It would be a Python init, starting services written in Python, running gettys written in Python, and you'd log into a shell written in Python.
Hmm... I can actually see myself writing an init system in Python... (hell, I did exactly that at my last company.... I'd have to rewrite it from scratch, but that's no big deal...)
Great, I think I've found a new rabbit hole.
Incidentally, I also came across [2] -- which I wasn't aware of.
[2] https://www.python.org/dev/peps/pep-3143/ https://pypi.python.org/pypi/python-daemon
FFI to the kernel on Linux, NetBSD Rump kernels and even bare on Xen.
Send yourself email reminders.
I also made a thing to suck all the Github repos you star into Wunderlist with their descriptions, since I always want to find something I starred in the past, and I've found Github's search lacking in this regard: https://github.com/ip2k/wunder-star
$ at 8pm <<END
> echo "Don't forget to subscribe to lwn!" \
> | mail -s "LWN reminder" personal-mail@example.com
> END
[1] http://debian-handbook.info/browse/stable/sect.task-scheduli...$3 with free shipping
Alternatively, the article mentions: > Environments like Mirage OS (and other "just enough operating systems") could also add Python using the BITS code without too much difficulty, he said.
You could therefore probably add this code to iPXE [2] without too much trouble to get python on your BootROM, though I'm unsure how much of the C standard library you would need to borrow or reimplement. By the looks of it, iPXE doesn't have threads or local storage support, so you would be pretty limited in usability without a lot of work.
[1] http://networkboot.org/fundamentals/ [2] http://ipxe.org
Just pointing out as the OP that I'm not the author of the project. I just came across the article on r/python
So maybe you can answer me this, how is memory management done in this environment? Are you free (heh) to do malloc and free or did you have to provide your own implementation? Is GRUB2 already in protected mode or there were some hacks needed on that area?
In the BIOS version, GRUB2 is entered in 16-bit real mode, and it transitions to 32-bit protected mode; it then has its own memory map. In the 32-bit and 64-bit EFI versions, the firmware transitions to 32-bit or 64-bit protected mode before calling GRUB2. (In all cases, there's no actual protection and the segment bases are all 0, though 64-bit mode does actually require a page table.)
However, GRUB2 normally only runs on the boot CPU ("BSP", bootstrap processor). We have to initialize the non-boot CPUs ("APs", application processors) ourselves. To do that, we allocate an aligned region of low memory, copy some bootstrap code and data into that memory, and send each processor an INIT (to reset them) and a startup inter-processor interrupt (SIPI) that forces them to jump to that address in low memory. We then transition them from 16-bit real mode to either 32-bit or 64-bit protected mode ourselves. (In the case of 64-bit protected mode, we set up paging by using the same page-table address that the firmware set up on the BSP, so that they all have the same memory map.) With that done, the AP can then run C code. Then we put the AP to sleep using mwait, waiting for work to do. When we want them to do something, we hand them a function pointer and a pointer-sized parameter.
We have a very tiny Python pci module, which contains a brute-force bus-walk to find devices with a specific class; we're using that to find PCI-attached USB host controllers so that we can force them to "hand off" to the OS, which then causes the BIOS to stop polling them, which often causes the BIOS to stop doing frequent SMIs. (That allows us to tell if a BIOS's out-of-spec use of long-running SMI handlers is caused by USB handling.)
Simple PCI enumeration, though, is effectively just "walk every possible device, read the first four bytes of configuration space from function 0, if they're not 0xffffffff then they're vendor and product IDs, and then read the same from functions 1-7".
>The presentation and demos were all done in the BITS environment, so, in reality, the whole presentation was a demo, he said to a round of applause
Pretty impressive!
My first programming environment was C under DOS, where you could create a pointer to video memory at 0xA0000000 or 0xC0000000 and start scribbling on the screen. I learned from a book ( http://smile.amazon.com/Microsoft-C-Programming-Robert-Lafor... ) which had an appendix showing how to draw the Mandelbrot set directly to video memory, so this was really nostalgic for me.
It is used for embedded systems but can work on a larger system too I suppose.
Basically it is just a kernel (for drivers) and on top (init) is Erlang VM.
The interesting aspect is an Erlang process is similar to a modern OS process -- has an isolated heap. So it kind of maps elegantly to an safe embedded multi-process OS.
Find the Erlang Factory talk by Frank Hunleth for more details.
Turn your question around, why would logging in and then starting Python be more educational than just booting directly into Python?
Because it takes longer to reboot than it does to restart a Python interpereter.
Because you can learn more than Python with it.
So if you want a comfortable Python environment with more services and the ability to use the full power of Linux, you would want to boot to Linux and run Python (possibly with some extra modules); if you want raw access to hardware and firmware, but without any OS (with all the advantages and disadvantages that implies), you want BITS.
A small rugged laptop, booting Linux as the kernel, and a UI built entirely out of Python that the kids could modify at whim.
We have direct access to video memory in graphics mode. Have fun.
GRUB's own scripting language is mostly up to the task of enumerating OSes and displaying boot options, though.