C Bootloader

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.
Post Reply
A. W. Soukup

C Bootloader

Post by A. W. Soukup »

A. W. Soukup

RE:C Bootloader

Post by A. W. Soukup »

>On 2001-11-12 23:52:22, A. W. Soukup wrote:

I have a few questions. I'm not that great at
the hardware side of computers, so bear with me.
Can the bootloader be written in C? I think I
heard something about it once, but haven't found
much information about. Second, if the kernel is
placed at the 1Mb mark, then where do you put the
bootloader? Also, how do you offset the memory on
the disk? I hope someone can help me?
Chase

RE:C Bootloader

Post by Chase »

>On 2001-11-12 23:58:23, A. W. Soukup wrote:
>>On 2001-11-12 23:52:22, A. W. Soukup wrote:
>
>I have a few questions. I'm not that great at
>the hardware side of computers, so bear with me.
>Can the bootloader be written in C? I think I
>heard something about it once, but haven't found
>much information about. Second, if the kernel is
>placed at the 1Mb mark, then where do you put the
>bootloader? Also, how do you offset the memory on
>the disk? I hope someone can help me?

Because the boot sector is so small (512 bytes) and
some registers require initilization with assembly, boot
sector are almost always written in assembly.

Also some C compilers (gcc) don't produce 16-bit code needed
for a boot sector.

The only memory location the is an standard is were the boot
sector is loaded by the bios. Your boot sector gets to decide
where your loader goes, and loader decides where the kernel
goes. Some OS move the boot sector to another location to make
room for the loader, some don't.

-Chase
A. W. Soukup

RE:C Bootloader

Post by A. W. Soukup »

>On 2001-11-13 11:36:08, Chase wrote:
>>On 2001-11-12 23:58:23, A. W. Soukup wrote:
>>>On 2001-11-12 23:52:22, A. W. Soukup wrote:
>>
>>I have a few questions. I'm not that great at
>>the hardware side of computers, so bear with me.
>>Can the bootloader be written in C? I think I
>>heard something about it once, but haven't found
>>much information about. Second, if the kernel is
>>placed at the 1Mb mark, then where do you put the
>>bootloader? Also, how do you offset the memory on
>>the disk? I hope someone can help me?

What exactly is the boot sector? I had the
impression that the loader and the boot sector were
the same.
Chris Giese

RE:C Bootloader

Post by Chris Giese »

>On 2001-11-13 13:44:28, A. W. Soukup wrote:
>>On 2001-11-13 11:36:08, Chase wrote:
>>>On 2001-11-12 23:58:23, A. W. Soukup wrote:
>>>>On 2001-11-12 23:52:22, A. W. Soukup wrote:
>>>
>>>I have a few questions. I'm not that great at
>>>the hardware side of computers, so bear with me.
>>>Can the bootloader be written in C? I think I

Yes. I wrote my BING bootloader in Turbo C. A
graphical bootloader called XOSL is written in
Borland C. And GRUB is written in GNU C.

>>>heard something about it once, but haven't found
>>>much information about. Second, if the kernel is
>>>placed at the 1Mb mark, then where do you put the
>>>bootloader?

In conventional memory...? Below 1 Mb.

>>>Also, how do you offset the memory on
>>>the disk?

I don't know what that means. If you write
a bootloader, you must write your own
filesystem code, typically these functions:
stat(), opendir(), readdir(), open(),
read(), lseek()

>What exactly is the boot sector? I had the
>impression that the loader and the boot sector were
>the same.

The BIOS loads only sector 0 of the disk (the
boot sector) into memory at boot time. A
program compiled from C is too large to fit
into one disk sector (512 bytes), so you need
a separate assembly-language "first stage"
to load the C-language bootloader.

http://www.execpc.com/~geezer/osd/boot/index.htm
Post Reply