Help with NASM+DJGPP loader/kernel
Posted: Thu Oct 23, 2003 11:48 pm
First, off, this being my first post, a kind hello to everyone!
Okay -- briefly, here's my setup:
- boot.asm loads the kernel to 0x7e00 and jumps there (using JMP08:0x8000)
- kernel.c contains a function called kmain()
Simple enough. Here's the commands I use to make everything:
nasm -o boot.bin boot.asm
gcc -c -ffreestanding -fwritable-strings -o kernel.o kernel.c
ld --oformat binary -Ttext 0x7e00 -e _kmain -o kernel.bin kernel.o
From there, I move boot.bin and kernel.bin to a floppy image (BOCHS).
The problem lies with using -fwritable-strings for GCC. I had to add this in case kmain() used any constants -- I found out soon enough that constants are declared before the functions that use them, and in my case would end up right at 0x7e00. So, without this flag, code like:
void kmain()
{
char *t = "Hello there";
DoStuff();
while (1);
}
...wouldn't work.
My question is this: is there a more convenient way of dealing with this problem that I've overlooked? I've considered the following, but don't quite have the inherent skill to implement them -- moreover, I'd like to know what the 'status-quo' is on what must be a common procedure:
- somehow telling LD where the EXACT location of kmain() is (after any constant declarations)
- using a proper object format with a coinciding makefile to properly relocate everything
- writing a first function (without constants) in kernel.c that calls kmain() explicitly (yuck)
- writing an asm stub to call kmain() (yuck again)
Mind you, with -fwritable-strings everything is working, but I'm not in the mood to have to settle for kludges so early in my OS development (not to mention what other side effects might crop up from using this flag that I'm not aware of).
Thanks all in advance -- this forum is certainly a goldmine of useful, nay, necessary 'know-how' for budding OS developers!
Okay -- briefly, here's my setup:
- boot.asm loads the kernel to 0x7e00 and jumps there (using JMP08:0x8000)
- kernel.c contains a function called kmain()
Simple enough. Here's the commands I use to make everything:
nasm -o boot.bin boot.asm
gcc -c -ffreestanding -fwritable-strings -o kernel.o kernel.c
ld --oformat binary -Ttext 0x7e00 -e _kmain -o kernel.bin kernel.o
From there, I move boot.bin and kernel.bin to a floppy image (BOCHS).
The problem lies with using -fwritable-strings for GCC. I had to add this in case kmain() used any constants -- I found out soon enough that constants are declared before the functions that use them, and in my case would end up right at 0x7e00. So, without this flag, code like:
void kmain()
{
char *t = "Hello there";
DoStuff();
while (1);
}
...wouldn't work.
My question is this: is there a more convenient way of dealing with this problem that I've overlooked? I've considered the following, but don't quite have the inherent skill to implement them -- moreover, I'd like to know what the 'status-quo' is on what must be a common procedure:
- somehow telling LD where the EXACT location of kmain() is (after any constant declarations)
- using a proper object format with a coinciding makefile to properly relocate everything
- writing a first function (without constants) in kernel.c that calls kmain() explicitly (yuck)
- writing an asm stub to call kmain() (yuck again)
Mind you, with -fwritable-strings everything is working, but I'm not in the mood to have to settle for kludges so early in my OS development (not to mention what other side effects might crop up from using this flag that I'm not aware of).
Thanks all in advance -- this forum is certainly a goldmine of useful, nay, necessary 'know-how' for budding OS developers!