i have done some tutorials etc and have a basic grasp of assembly and i have managed to write a bootloader for a floppy that displays some text on the screen.
i am not a huge fan of assembly and i'm wondering where i can go from here ie writing it in C or something similar. I am aware however that gcc produces a file designed to be run in an operating system and that if i simply put it onto a disk and booted it wouldn't work.
how would i replace my assembly program with something more like:
void main() {
printf("Hello");
while(1){
}
}
begginers question
Hi,
I strongly advise you to read Bran's Kernel Development Tutorial.
When you run an executable on e.g. Windows, the exe file is loaded in to RAM at appropriate locations (i.e. code and data may be relocated) and you have the entire Windows API at your disposal.
The main things with developping a C kernel are:
* You have no standard library available. Do not #include any headers you have not written yourself (or ported). This means, in your example, printf() will not work as you have not yet written any kind of video driver.
* Either you need to compile in flat binary format, or your boot loader needs to be capable of exe relocation to load your kernel. This will mean writing a linker script and probably an executable stub (which will call your main() function) in assembly.
The tutorial given above will take you through the compiler and linker commands you will need for both of these.
HTH,
Adam
I strongly advise you to read Bran's Kernel Development Tutorial.
When you run an executable on e.g. Windows, the exe file is loaded in to RAM at appropriate locations (i.e. code and data may be relocated) and you have the entire Windows API at your disposal.
The main things with developping a C kernel are:
* You have no standard library available. Do not #include any headers you have not written yourself (or ported). This means, in your example, printf() will not work as you have not yet written any kind of video driver.
* Either you need to compile in flat binary format, or your boot loader needs to be capable of exe relocation to load your kernel. This will mean writing a linker script and probably an executable stub (which will call your main() function) in assembly.
The tutorial given above will take you through the compiler and linker commands you will need for both of these.
HTH,
Adam
i have been following the tutorial, but when i try and link the assembly code with the c code i get the following error:
undefined reference to '_main'
however i have added it to my compile script which looks like this:
gcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -c -o lib/main.o src/main.c
nasm -f aout -o lib/kernel.o src/kernel.s
ld -T lib/link.ld -o kernel.bin lib/main.o lib/kernel.o
I am not sure what is wrong.
undefined reference to '_main'
however i have added it to my compile script which looks like this:
gcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -c -o lib/main.o src/main.c
nasm -f aout -o lib/kernel.o src/kernel.s
ld -T lib/link.ld -o kernel.bin lib/main.o lib/kernel.o
I am not sure what is wrong.