Write Bootloader in C
I am a newbie in writing bootloaders. I have written a helloworld bootloader in asm, and __asm__( Solutions/Answers:Solution 1:I would suggest you to have a look at http://wiki./Rolling_Your_Own_Bootloader and also the Bootloader section of : http://www./Resources/OSDevIndex.html There are excellent tutorials to get yourself started to make yourself your own bootloader. Also you can join the #osdev channel in freenode to join a discussion if you need more information. Solution 2:Let me assume a lot of things here: you want to run your bootloader on an x86 system, you have the gcc toolchain set up on a *nix box. There are some points to be taken into account when writing a bootloader:
now if you want gcc to output such a binary, you need to play some tricks with it.
– Solution 3:A bootloader is written in ASM. When compiling C code (or C++, or whatever), a compiler will ‘transform’ your human readable code into machine code. So you can’t be sure about the result. When a PC boots, the BIOS will execute code from a specific address. That’s why you’ll use assembly. If you want to code in C, you’ll still have to code an ASM bootloader, which will be in charge to load properly the machine code generated by the compiler you use. You need to understand that each compiler will generate different machine codes, that may need pre-processing before execution. The BIOS won’t let you pre-process your machine code. The PC boot is just a jump to a memory location, meaning the machine code located at this location will be directly executed. Solution 4:Since you are using GCC, you should read the info pages about the different “target environments”. You most probably want to use the -ffreestanding flag. Also I had to use -fno-stack-protector flags to avoid some ugly magic of the compiler. Then, you will get linker errors saying that memset and the like are not found. So you should implement your own version of these and link them in. Solution 5:I tried this a few years ago — options may have changed. You have to run References |
|
来自: astrotycoon > 《待分类》