I am currently writing a small embedded os to run on an x86 platform. Right now I have just been writing it, compiling it, and running it in my linux shell for testing. I would like to install it to a floppy or flash disk and boot to that just to see it running on its own. Can anyone point me in the right direction to get that started?
Also, I am very new to the embedded world and to the operating system design in general. I am sure I'll need to copy the c libraries so they can be loaded, or i'll have to statically link them. What is the best way to go about this?
If you run Linux, chances are good you use Grub as a bootloader. Grub understands the 'multiboot format' - basically a header you stick before your binary image which holds info about the type and size of your image, its entry point, etc. Grub reads the header, loads your image and jumps to your entry point.
Take a look at the multiboot specification for more info :
If your OS is written in C, you will at least need to provide some startup code to prepare the C-environment for your program: initializing the data section, cleaning the BSS, setting up a stack, etc. From this startup code you jump to your C-entry point (main?).
Also I can recommend using a PC-emulator like Qemu or vmware for doing this kind of work, this will speed up your development process considerably.
If you really want to do things the hard way, you can do without the standard C libary (don't forget your compiler and linker to omit those from the build, -fno-builtin, --nostdlib, etc).
If you really need C-library, there are several small alternatives especially ment for embedded systems. newlib or uClibc would be good candidates.
However, adding support for dynamic libraries to the 'small embedded os' the OP is writing is a non-trivial exercise. Even he wanted to go that route, it would only work for the user applications, not the kernel itself.
I second Ico's recommendation to use an emulator for experimenting. It makes it much easier to debug the initial steps of bringing the system up. Check out bochs
The kernel takes approx. 1MB, so it's no big deal for flash drives. It's a problem for floppy and CD (floppy boot image). But with 32M CF going for couple of dollars, I don't know why people still deal with floppy. The basic Dynamic C run-time libraries needs less than 16M. So, there are plenty of application space left. However, we do need
128M for the development environment. For about $15, 128M flash drives are not too expensive as well.
So, for approx. $20, you can compile on a 128M and run on a 32M.
So, I have solved my library issue. Now I really want to load my os on a flash drive and boot to it there. I know I could use an emulator, but this is more of a learning project I am wanting to do than a testing process.
What I have is the executable of my operating system that I have compiled using gcc with all libraries statically linked in. For now, I don't need to run any programs, everything is built in to the operating system and run as tasks from my scheduler. I just want to be able to put my executable on a flash drive and make the drive bootable so that it will run my os. Is that possible? Any docs I can read on how to do that?
I guess I forgot to mention something and wasn't too clear on something else. This is a USB flash drive I am trying to put it on. Second, I am in linux. If I can create the bootable flash without using windows, that'd be nice, but I am sure I can find a windows box if necessary. I'll start searching on how to make a bootable flash drive in windows, since it isn't as simple as a floppy.
But it will be easier to just start over , with a replacement for Linux and Windows . Then it would not be so much work to do anything .
Ill be working on a new O.S. that has no file system , no "Boot" , no text command line , no problems .. It boots its debugger in 10k of the loader , thus there is no boot ! It will load any o.s. , and if you like what it loaded , you can save that to flash .
it will be far less work to create this o.s. , because i will be eliminating excess bags , not adding new code . Thus it will be tiny .
Now , C programmers can say its impossible ,
because C programmers cant do a tiny powerful o.s. without a U-Bloat loader , thus NO ONE CAN . Duh !!
Its easy to write an o.s. 10 times better than Linux , in 1/10 th the time and in 1/4th the space ..
I think you are reading more into his posts than is there. He mentions booting a small embedded OS but not linux. He mentions using linux but from context that just appears to mean that's his development platform.
You may remove the word "might" from that statement. The OP
*specifically* mentions "writing his own" "small", "embedded" OS. Meaning "not linux" since linux wouldn't be "his own" nor would it be considered "small" by embedded programmers.
Not necessarily. If the BIOS or bootloader can boot from USB it for you then you don't need to even care about USB. His root filesystem need not be on the USB drive, just his OS executable image (I would have said kernel image but most small embedded OSes are just simple executives). Heck, most embedded OSes don't even have a concept of a filesystem much less requiring a root filesystem.
So again his best bet is to use a BIOS and/or bootloader capable of booting from USB. I know my BIOS can boot from a USB drive but I don't know much about bootloaders apart from embedded bootloaders like Redboot and APEX.
That would be tough to do. To run the BIOS code, you must be in 16 bit mode. The OP is using gcc. I am not aware of any recent 16 bit gcc. You can boot 32 bit OS in BIOS. But once you are booted, you are on your own.