First of all, I am new to the forum, and new to such low-level development in general. Please pardon this if this isn't the best question... I'll learn over time.
I am trying to write my own boot loader in the D programming language, using the Digital Mars DMD compiler and linker for the binaries, and qEmu for the emulation. I've managed to get as far as writing single letters on the screen and even issuing int 13h interrupts to read and execute code from another sector on the HDD, so this isn't a question on how I should start. Rather, I'm having trouble calling other functions, perhaps because of my rather incomplete knowledge about the exact structure of real-mode memory and how the stack exactly works, as well as potentially huge differences between real-mode and protected mode that I do not know about.
My problem
My entire code is in an extern(C) block, so it would be using the C calling convention.
So far, this code works fine, and prints 'A' to the screen:
Code: Select all
pragma(startaddress, kmain); //Tell the compiler where kmain() is
void kmain()
{
asm
{
mov AH, 0x0E;
mov AL, 65; //ASCII for A
mov BH, 0;
mov BL, 0;
int 0x10;
}
}
Code: Select all
void putc()
{
asm
{
naked; //Don't generate any other code for stack and such
mov AH, 0x0E;
mov AL, 65;
mov BH, 0;
mov BL, 0;
int 0x10;
ret;
}
}
pragma(startaddress, kmain); //Tell the compiler where kmain() is
void kmain()
{
asm
{
naked;
call putc; //Works fine
call putc; //Doesn't ever happen... code never executes
}
}
I guess the question is: What am I doing wrong? If there's a huge idea that I'm missing, I'll be glad to read up on it if I know where to look. But so far, I've read quite a few guides on the web, and none of them have helped me solve this.
If the disassembly of the code or other information would help, please let me know.
Thank you!!