views:

132

answers:

2

Where can I find resources/tutorials on how to implement threads on a x86 architecture bootloader... lets say I want to load resources in the background while displaying a progress bar..

A: 

This book might help you somewhat -- it describes various aspects of the linux kernel -- including initialization. You might want to look at GRUB its pretty standard across UNIX flavours.

The book I mentioned should be your resource of choice, the kernel doesn't consider its metal thread-capable till quite late in the initialization cycle, and by this I mean setting up the data structures for threading is well-documented.

Although I can't seem to think of any real benefit of allowing threading constructs in a boot loader -- firstly its simpler to setup your basic hardware using single threaded procedural code and secondly you expect the code to be bullet-proof so threading as a defence mechanism isn't needed.

So I'd expect you're looking at emulating a progress bar :D

Hassan Syed
Yeah, trying to emulate one. I'll try find the book
Fredrick
+6  A: 

That is a very unusual question...so allow me to provide my opinion on it...

  • Bootloaders, are really a limited bunch of assembly code, 464 bytes to be exact, 64 bytes for partition information and a final two bytes for the magic marker to indicate the end of the boot loader, that is 512bytes in total.
  • Bootloaders such as Grub can get around this limitation by implementing a two phase bootloader, the first phase is the 512 bytes as mentioned, then the second phase is loaded in which further options etc are performed.
  • Generally, the bootloader code is in 16 bit assembly because the original BIOS code is 16bit code, and that is what the processor 386 upwards to the modern processor today, boots up in, real mode.
  • Using a two phase bootloader, the first 512bytes is 16bit, then the second phase switches the processor into 32bit mode, setting up the registers and gate selectors in preparation, which in turn then jumps to the entry code of the actual program to do the booting up - this is taking into account in having to read from a specific location on disk or reading a configuration file which contains data on where the boot code is stored.
  • Implmenting threads in 32bit mode is something that will be tricky to produce as you will have to create some kind of a scheduler in Assembly (Since you mentioned implement threads on a x86 architecture bootloader).

You may get around this by implementing a second phase part of the bootloader using C (but the tricky bit is that no standard libraries are to be used as the runtime environment has not been set up yet!)

You may be better by using Grub or even check out this Open source BIOS bootloaders here, nowadays, bios's are flashable so you may be able to get an EFI (Extensible Firmware Interface here) which is pure 32bit bios - this will be dependant on your processor. There is also another website here which might provide further info here.

The progress bar on boot, is unfortunately written in C/C++ which (already, in 32bit, environment set up, tasking scheduler set up, threads included, virtual memory manager loaded etc - this is the kernel level, after boot up procedure is complete), in which is a process where a thread has been created, that runs in the background illustrating hardware detection/further environment set up etc by using a progress bar as a way to tell the user to "wait, the system is loading"

Hope this information is of help to you, Best regards, Tom.

tommieb75
Your are right, i'm actually in the second stage and i've defined most of the classes and types. Most resources i found use a scheduler. Which seems like a linked list to me. Only problem i faced with writin a linked list in c, is usin the keyword "new". I've writen a linked list before in c++. Its back to the drawing board
Fredrick