9 ms·
x86 Bare Metal Examples
- cyrusmg 8y agoWhat is the use-case in real life ? Is it to run special lab/factory equipment ? Anyone here who develops for bare metal - can you share any details?
- choeger 8y agoThe use case is to break some layers of abstraction. If no one would write such a guide, who would create the next OS? We would all be dammed to copy existing codes and pray they work. I applaude the author for the effort, in particular using images that can be booted should make it feasible to use these techniques for teaching!!
- z3t4 8y agoA dream I've had for a long time is to make an application that you boot into, which is the only application on the computer, for maximum optimization. Upgrades would be easy, just reboot the computer and load the new software. Wouln't write everything in assembly though.
- cirosantilli 8y agoYes, the ASM overkill was a mistake of my youth :-) https://github.com/cirosantilli/x86-bare-metal-examples/tree/85931f4e4a9551470a712f15421c69ee5204cfdc#to-c-or-not-to-c https://github.com/cirosantilli/x86-bare-metal-examples/tree...
- teddyh 8y agoWhat you describe used to be very common: https://en.wikipedia.org/wiki/PC_booter https://en.wikipedia.org/wiki/PC_booter
- adrianN 8y agoSo a Unikernel with your program?
- rramadass 8y agoThis is standard "embedded" system programming for lower-end MCUs. "Unikernels" use the same concept to create standalone bootable binaries(linked with reqd. OS modules) to run directly either on HW or on a VM Hypervisor. See "IncludeOS" for one representative example.
- Taniwha 8y agoyou're describing any number of embedded systems, including the Arduino runtime - load up an Arduino app and you have your dream come true :-)
- OskarS 8y agoThe problem comes when you need to use any kind of hardware, all the drivers would have to be part of your app. The "unikernel" concept however does some version of this: loads a kernel which only supports the minimal amount of functionality and drivers needed and with only a single address space for a single app.
- 0xcde4c3db 8y agoHistorically this was more tractable because driver code was much simpler and there was a lot of cloning/emulation of "legacy" hardware interfaces (a lot of this is still present on PC, despite vendors' desire to get rid of it). Typically either the hardware capabilities were fundamentally narrower in scope than modern hardware or the hardware had its own controller (sometimes with more raw power than the host CPU...) that implemented an abstract interface. A bare-metal VGA driver for a single mode is no more than a few dozen lines of code, whereas a modern GPU driver stack literally has an optimizing compiler built into it.
- pjmlp 8y agoBesides what everyone is commenting on, this is how Amiga, Atari ST and most console games used to be done.
- cirosantilli 8y agoThis repo is mostly just educative as a helper to understand Linux kernel x86 / Linux kernel drivers In e.g. ARM, baremetal is potentially more useful due to embedded. But even in ARM you should just use Linux kernel / some RTOS if you can get away with it :-)
- emourkai 8y agoI'm kind of curious who's behind this Ciro Santili guy. He(?) seems to be doing a ton of interesting github repos, a great deal of informative stackoverflow answers and who knows what else. Also, some anti-CCP stuff in the profile?
- cirosantilli 8y agoIf you have any specific questions, fire away :-) Homepage + social media links from there should give a good idea of who I am: http://www.cirosantilli.com http://www.cirosantilli.com
- rurban 8y agoI'm curious. Why did you learn Chinese, but not Rust or Haskell yet? And yes, I agree with https://github.com/cirosantilli/china-dictatorship https://github.com/cirosantilli/china-dictatorship And that speaking Chinese is much simpler than reading or writing in it. One of the simplest languages actually.
- cirosantilli 8y agoAlas, I'm married to a Chinese woman, and not Graydon Hoare :-)
- 188201 8y agoInteresting. I have to admit I have stereotype and prejudice, any westerner married to Chinese woman is pro-China. I see you have some sensitive Chinese word in username in different community, so I thought it is a Chinese guy in Western country behind it.
- cirosantilli 8y agoWhen your wife does Falun Gong, and her father spent a decade + in semi-prison during the cultural revolution, that tends to not bring out the brightest side of the Chinese Communist Party ;-)
- cerebrum 8y agohttp://menuetos.net/ http://menuetos.net/
- baybal2 8y agoYou can use efi text mode or framebuffer these days.
- cirosantilli 8y agoI wanted to do a proper UEFI example, but got lazy, sketch at: https://github.com/cirosantilli/x86-bare-metal-examples/tree/28598672c95fc519a296132200cbcce9012fa7d3#uefi-example https://github.com/cirosantilli/x86-bare-metal-examples/tree... Links to minimal runnable working examples / patches welcome.
- self_awareness 8y agoUsing BIOS calls doesn't seem to be really "bare metal". One could use bios interrupt to read data from a disk, or also one could use memory mapping with a target device to write a device driver that could request the file. I find the second case a "bare metal" approach. Fortunately most of the bios examples are using bios_* filenames. Rest of the files are very nice.
- cirosantilli 8y agoYes, here we go again: https://news.ycombinator.com/item?id=18532102 https://news.ycombinator.com/item?id=18532102 :-) I wonder how much lower level you can go with QEMU / how much it can match real hardware. Pull requests / links welcome ;-)
- deleted 8y ago[deleted]
- pm215 8y agoQEMU runs the 'seabios' bios image in the guest, so you could certainly run a 'bare metal' custom image instead of the default BIOS blob if you wanted. At the basic level of "prod the UART, prod the timers" we should be a reasonable match to real hardware. Running on real hardware without the BIOS would be trickier as you start to need to do things like set up memory controllers, which you can get away without on QEMU.
- self_awareness 8y agoOkay I've sent you a pull request with a bare metal hello world example ;)
- snaky 8y agoOne could follow this "toward the bare metal" way as long as he wish. E.g. in Silego GreenPAK chips a CPU is considered unneeded abstraction and you program the raw state machine.
- oldsklgdfth 8y agoLooking at the skills section on his webpage: http://www.cirosantilli.com/skills/ http://www.cirosantilli.com/skills/ This seems like the most honest self-assessment I have seen of one's skills.
- zymhan 8y agoWow, that is how I've wanted to answer the "on a scale of 1-10, how would you rate your XYZ skills". I really wish more people had some benchmark for the numbers they throw out there.
- tracker1 8y agoSimilarly, if I see more than one or two 9-10 on self-assessed skills, I feel that's an invitation to "sock it to me" on knowledge questions when interviewing someone. When people are 4-6 I'm a lot more reasonable.
- cirosantilli 8y agoThat was copied from failed Google interview BTW :-) To me the main problem is that I'm always afraid to put a 5, who can not check manuals? ;-) I'm also more and more of the opinion that (impact of projects) is more important than (current skills).
- oldsklgdfth 8y agoI find this interesting because grade inflation is real. There are so many straight A students that it loses it's value as a measure. But if you can do something without looking it up I would agree that is proficient. A good team member is a larger force multiplier than a single rockstar.
- ddingus 8y agoI have found inverting this kind of question helps. Rate your interest in the following: Item A Item B People tend to express high interest where they want to grow, or have need.
- _chiliconcarne 8y agoI'll drop a question since I see Ciro Santilli is around. I want to start learning low level programming. Yet, I feel awfully overwhelmed every single time I try. Any recommendations you might have?
- cirosantilli 8y agoIf you can choose still, study something that is related to laboratory work rather than programming, because anyone can buy a laptop and learn to program, but almost no one can access a lab. If you can only program, first choose an application that you are passionate about, that is new, hard and important, and then learn whatever you need to achieve that goal. Application first, method later. After that, if you still want to learn low level programming... :-) use emulators + minimal examples like in my tutorials, read / step debug the source of major projects and document that somewhere, and then try to modify those major projects with useful extensions.
- rramadass 8y agoStart with the book "Computer Systems: A Programmer's perspective by Bryant and O'Hallaron". Become fluent in C and its toolchains and you will be able to program everything (learn assembly only as needed).
- tempodox 8y ago"\n\r" should be "\r\n" (0D, 0A -> CR, LF).
- cirosantilli 8y agoDo you mean at: https://github.com/cirosantilli/x86-bare-metal-examples/blob/28598672c95fc519a296132200cbcce9012fa7d3/bios_carriage_return.S https://github.com/cirosantilli/x86-bare-metal-examples/blob... ? Does it make any difference in BIOS, where \n seems to be "move cursor down" and "\r" seems to be "go to start of line"?
- mammalutte 8y agoDo you have any hello-world examples of how to load a 64bit ELF kernel with a GRUB2 bootloader? I don't mean Linux kernel, I literally mean a simple program that only prints "hello world". Something like this [1] but in long mode. [1] https://wiki.osdev.org/Bare_Bones https://wiki.osdev.org/Bare_Bones