hi..
im a newbie os-developer, and i was able to write a bootsector which loads
sector 2 into a specified address and starts executing it...sector 2 contains asm code..
i would like to know how i can write C code and get the bootsector to jump to it
thanks.
pratap
booting C kernel
RE:booting C kernel
Pretty much the same way. Though how you go about doing this, would be up to you. You could have your 'C code' which I'll now call 'kernel' in binary format, then it's a matter of just loading it up and executing it. Depending on your file system, your bootsector might have to figure out some of that...if the kernel is in a binary format (like ELF), you'd need to move that around in memory a bit, etc... but for the most part, it's the same principle...you'll just end up reading more than 1 sector
RE:booting C kernel
A few points to be made:
First, if you are using a 32-bit C compiler such as gcc, you will need to switch into protected mode before running the C code. If you already have done this in your bootloader, all is good; if not, it may be a lot easier to use a second-stage loader in assembly which switches to p-mode and then loads the kernel image.
Second, you'll probably want to use a small assembly language 'stub' at the beginning of the second stage, which is linked to the kernel code and calls it directly. This allows you to place the entry point where you need it, otherwise it will be rather difficult. Conversely, you can write a second stage loader, which can read an ELF executable from the file system and load it in the conventional manner.
Third, while I agree that writing your own boot loader is a good and insightful programming exercise, I don't recommend it in a final design. Existing boot loader such as GRUB and BING have been written which already handle these issues, and which are designed to cover many more potentialities than a simple OS sepcifc loader would (including booting multiple OSes from a single disk, in the case of GRUB). While it is only a suggestion, it is one which is certain to save you a lot of time and effort.
First, if you are using a 32-bit C compiler such as gcc, you will need to switch into protected mode before running the C code. If you already have done this in your bootloader, all is good; if not, it may be a lot easier to use a second-stage loader in assembly which switches to p-mode and then loads the kernel image.
Second, you'll probably want to use a small assembly language 'stub' at the beginning of the second stage, which is linked to the kernel code and calls it directly. This allows you to place the entry point where you need it, otherwise it will be rather difficult. Conversely, you can write a second stage loader, which can read an ELF executable from the file system and load it in the conventional manner.
Third, while I agree that writing your own boot loader is a good and insightful programming exercise, I don't recommend it in a final design. Existing boot loader such as GRUB and BING have been written which already handle these issues, and which are designed to cover many more potentialities than a simple OS sepcifc loader would (including booting multiple OSes from a single disk, in the case of GRUB). While it is only a suggestion, it is one which is certain to save you a lot of time and effort.