jart / cosmopolitan

build-once run-anywhere c library
ISC License
17.9k stars 614 forks source link

Bare Metal walkthrough/example #130

Closed microspino closed 3 years ago

microspino commented 3 years ago

Hi this thing is super cool. Super super cool! I've read it could run ALSO on bare metal. It's not clear how. I know you guys are busy making this thing better and better but if you ever find some spare time, would you mind adding an example of running it, maybe on a bare metal x86? I have a few thin clients, mostly by 10Zig and I've been dreaming about running with something like redbean. I know you completed integrating Lua and that Janet is not far away therefore i think i could use them on the server side as well...Maybe... I will be more than happy to test this configuration and report feedback. Feel free to close this issue if you think I'm out of my mind.

jart commented 3 years ago

Bare metal is currently less developed than the support that exists for userspace. Our support on metal is currently limited to read() / write() to serial uart and mmap() / malloc() are supported too. I'd like to have e1000 and virtio at some point too so we can run redbean on metal in the cloud without needing linux as a dependency.

The closest thing we have to a walkthrough at the moment is this: https://justine.lol/cosmopolitan/deathstar.html which shows how to get a demo from rosetta code to boot in qemu. It's also possible to run any of the programs in this repository inside the blinkenlights emulator too. For example:

make -j8 o//tool/build/blinkenlights.com o//examples/hello.com
o//tool/build/blinkenlights.com -rt o//examples/hello.com

Let me know what you think!

The main blocker at the moment in terms of developing this support further is simply my lack of experience in operating system development. It's something I've been gradually learning for fun and that's been a slow process, which could easily be sped up if we could attract some seasoned kernel devs to the project.

piranna commented 3 years ago

What about UEFI? It's mostly seen as an operating system itself, and provides "protocols" to access to the hardware, including graphics and networking. Think of them like standarized BIOS calls on esteroids :-) This way it could be possible to run on real hardware too without needing to write (too much) drivers, not just only emulators... A different topic would be the quality of these drivers, or the lack of hardware acceleration...

https://edk2-docs.gitbook.io/edk-ii-uefi-driver-writer-s-guide/3_foundation/36_protocols_and_handles https://archive.fosdem.org/2018/schedule/event/hwenablement_uefi_for_dummies/attachments/slides/2381/export/events/attachments/hwenablement_uefi_for_dummies/slides/2381/Programming_UEFI_For_Dummies.pdf

https://wiki.osdev.org/UEFI#Developing_with_POSIX-UEFI https://edk2-docs.gitbook.io/edk-ii-uefi-driver-writer-s-guide/examples

microspino commented 3 years ago

@piranna as far as i know It has ben already explored succesfully in #12 as an alternative to windows support. It would be nice to see an example of it with readbean. It's above my head but, maybe, UEFI has more juice than BIOS for a webserver.

piranna commented 3 years ago

It's above my head but, maybe, UEFI has more juice than BIOS for a webserver.

Yes, it have, starting from the networking support :-) There are in fact some Rust crates that allow to create HTTP servers and other things using standard tools :-)

microspino commented 3 years ago

I understand also that Libreboot comes with ROM images built for QEMU. That could be another way to explore. I will dig more about it in my spare time.

microspino commented 3 years ago

As soon as I have time I will try with UEFI. I think closing this would help focus all the efforts on other cosmopolitan issues.