boot in C

Programming, for all ages and all languages.
Post Reply
arming
Member
Member
Posts: 38
Joined: Sat Dec 10, 2011 6:23 am

boot in C

Post by arming »

I have looked for it, but I haven't found it. Do you know any example of a bootloader written in C? something like GRUB but written 100% in C?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: boot in C

Post by Combuster »

That's because it is not possible. C can't do the necessary instructions.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
arming
Member
Member
Posts: 38
Joined: Sat Dec 10, 2011 6:23 am

Re: boot in C

Post by arming »

Combuster wrote:That's because it is not possible. C can't do the necessary instructions.
d'ouch! :evil:

and what about a very simple boot?
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: boot in C

Post by AJ »

Hi,

No - you won't find it. Anything you do manage to find written in C will rely heavily on inline assembly.

Cheers,
Adam
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: boot in C

Post by Combuster »

Think about it, if you can boot something simple, then you can use that simple thing to load something less simple, and after some iterations you can boot grub....wait what did we say earlier?!
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: boot in C

Post by neon »

Hello,

It can be written with very little to no inline assembly. Bootloaders that utilize the BIOS will require quite a bit of assembly language for startup and possibly I/O depending on design. Bootloaders that utilize EFI dont really need any. (Speaking from experience with ours.)

Really depends heavily on design I think. In all cases though you will need "some" assembly language. I must emphasize though that writing a bootloader in C takes a lot of patience and time: you should know assembly language.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
ACcurrent
Member
Member
Posts: 125
Joined: Thu Aug 11, 2011 12:04 am
Location: Watching You

Re: boot in C

Post by ACcurrent »

Generally the 1st stage is always asm because of the size constraints (Bios) though with UEFI it is possible to have 100% C. Speaking of that, the best bet for getting UEFI are apple macs. Qemu and virtualbox can be configured to run EFI though.
start looking for a bootloader written in Python.
Actually I was looking for a pink pony!
Get back to work!
Github
arming
Member
Member
Posts: 38
Joined: Sat Dec 10, 2011 6:23 am

Re: boot in C

Post by arming »

berkus wrote:GRUB is 98% in C, is that not enough?

Or start looking for a bootloader written in Python.
Well, for me it isn't enough, because then is not as portable as I want.

And why not, a bootloader in Python :mrgreen: .

But you won't read that because I'm in your ignoring list =D>
Nable
Member
Member
Posts: 453
Joined: Tue Nov 08, 2011 11:35 am

Re: boot in C

Post by Nable »

When you use HighLevelLanguages, it doesn't mean that you code is portable.
Even more, when you use Asm, it doen't mean that your code is not portable, as you can use different asm blobs for different architectures and compilation script will choose which to link with.
And.. fully portable bootloader - it's nonsence, really.
Is topic-starter a kind of a troll? I'm sorry but his ideas demoralise me.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: boot in C

Post by Solar »

arming wrote:Well, for me it isn't enough, because then is not as portable as I want.
Where do you want to port it to?

You are aware that booting processes differ wildly between architectures, so that a "portable" bootloader doesn't make much sense to begin with?
Every good solution is obvious once you've found it.
arming
Member
Member
Posts: 38
Joined: Sat Dec 10, 2011 6:23 am

Re: boot in C

Post by arming »

Nable wrote:When you use HighLevelLanguages, it doesn't mean that you code is portable.
Even more, when you use Asm, it doen't mean that your code is not portable, as you can use different asm blobs for different architectures and compilation script will choose which to link with.
And.. fully portable bootloader - it's nonsence, really.
Is topic-starter a kind of a troll? I'm sorry but his ideas demoralise me.
of course I don't want to do 100% portable bootloader, I know that that hasn't sense. But I want to have a boot as portable as it's possible.

And... when the people despise me because I'm a noob... that demoralise me to. I know that I say several stupid things ( :mrgreen: ) but I say it to learn, not to be a troll.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: boot in C

Post by Brendan »

Hi,
arming wrote:of course I don't want to do 100% portable bootloader, I know that that hasn't sense. But I want to have a boot as portable as it's possible.
First step would be to determine everything the kernel could/would want to know, and create a specification that describes how the boot code should present all that information to the kernel.

Second step would be to realise that everything before your boot code hands control to the kernel depends on the firmware you're booting from, and in some cases also depends on which boot device.

In cases where it's possible (where the boot loader doesn't depend on the type of device you're booting from), write a boot loader for each type of firmware. These boot loaders won't be portable to other types of firmware, but might be portable to the same type of firmware on different architectures - e.g. a UEFI boot loader should/could be ported easily from 32-bit 80x86 to 64-bit 80x86 to Itanium.

In cases where it's not possible (where the boot loader has to depend on the type of device you're booting from), write a common module for each type of firmware. These common modules may be portable to the same type of firmware on different architectures (but probably won't be). Then, write a boot loader for each type of device that uses the appropriate common module. In this case the boot loaders should do as little work as possible (e.g. reading files) while the common module should do everything else.


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
arming
Member
Member
Posts: 38
Joined: Sat Dec 10, 2011 6:23 am

Re: boot in C

Post by arming »

Brendan wrote:Hi,
arming wrote:of course I don't want to do 100% portable bootloader, I know that that hasn't sense. But I want to have a boot as portable as it's possible.
First step would be to determine everything the kernel could/would want to know, and create a specification that describes how the boot code should present all that information to the kernel.

Second step would be to realise that everything before your boot code hands control to the kernel depends on the firmware you're booting from, and in some cases also depends on which boot device.

In cases where it's possible (where the boot loader doesn't depend on the type of device you're booting from), write a boot loader for each type of firmware. These boot loaders won't be portable to other types of firmware, but might be portable to the same type of firmware on different architectures - e.g. a UEFI boot loader should/could be ported easily from 32-bit 80x86 to 64-bit 80x86 to Itanium.

In cases where it's not possible (where the boot loader has to depend on the type of device you're booting from), write a common module for each type of firmware. These common modules may be portable to the same type of firmware on different architectures (but probably won't be). Then, write a boot loader for each type of device that uses the appropriate common module. In this case the boot loaders should do as little work as possible (e.g. reading files) while the common module should do everything else.


Cheers,

Brendan
I've understood. Thanks!
Post Reply