Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
I have followed the Bare Bones tutorial and thought it would be nice to create a simple bootloader without grub myself. I have looked around various pages on the wiki here and on the net (living in China though you would be suprised to know how many programming related pages 'don't exist').
I have obvioulsy missed something really simple. Could you please let me know where I went wrong?
I managed to get build and run OK with GRUB, but I guess that is because it can load the ELF format.
I am new, and there is a whole lot to learn!
So if I was to load the kernel like this, it would need to be a "flat kernel" is it called? Basically a kernel with no headers etc...? Or to manually parse the ELF format myself.
The bigger issue is, you need to learn how the boot process works if you intend on making a boot loader. The bios only loads the first 512 bytes from disk, which is your ASM file. The kernel.c is not loaded automatically, that is the job of the boot loader. Also, you never tell the .asm file where to start (it's ORG, or origin should be 0x7c00). There is a lot more to starting an operating system from disk than simply calling a function.
Ready4Dis wrote:The kernel.c is not loaded automatically, that is the job of the boot loader.
So I guess from this that I would need to jump to a predefined location which is set at compile time. Depending on my kernel file format, I would need to parse it appropriatly and run.
Ready4Dis wrote:Also, you never tell the .asm file where to start (it's ORG, or origin should be 0x7c00).
I did try [ORG 0x7C00] but got a compile time error. So I changed it to:
Ready4Dis wrote:The kernel.c is not loaded automatically, that is the job of the boot loader.
Nitpick: Neither kernel.c (C source) nor kernel.o (object file) are loaded; what the bootloader loads is usually a flat binary generated by the linker from the kernel.o.
I've read them and they make sense. I understand how to make an asm bootloader which prints to the screen, sets up the stack etc...
What I am trying to figure out, is how to call into a C method. If I create a flat asm bootloader using something like:
nasm boot.asm -f bin -o boot.o
I can't have any external references. For this I have read that I need to assemble into the ELF format. The problem with this, is that the ELF format cannot be loaded directly as a stage 1 boot loader.
So I suppose, my real problem is not knowing how to go from stage 1 to stage 2 - or perhaps I am again missing something.
Reaver Project :: Repository :: Ohloh project page
<klange> This is a horror story about what happens when you need a hammer and all you have is the skulls of the damned.
<drake1> as long as the lock is read and modified by atomic operations
Calling a c function and reading a elf binary is not the same thing. You can create a flat binary c program if you wish, have it loaded into memory and then just junp to the first address as you would a function. To call a function in c what you do is push the arguments in reverse order an then issue the call opcode.