I'm working on a simple real-mode OS in c++. I can't figure out how to print strings, though. The following code works when it's in the bootloader, but not when it's in the kernel.
__asm__ __volatile__(".code16gcc \n");
__asm__ __volatile__ ("xor ax, ax\n");
__asm__ __volatile__ ("mov ds, ax\n");
__asm__ __volatile__("jmp main \n");
void printf(const char* str)
{
while(*str)
{
__asm__ __volatile__("int 0x10" : : "a"(0x0e00 | *str), "b"(0x0007));
++str;
}
}
void main(){
printf("Hi!");
}
I'm sure it's because the ds register it set to 0, but the code is actually at 0x7E00 (that's where the bootloader puts it). I've tried setting ds to 0x7E0, which should cause it to load data correctly because 0x7E0 * 16 = 0x7E00, but it still doesn't work. It's probably just some silly mistake, but I would appreciate some help. If it matters, here is my bootloader code:
__asm__(".code16gcc \n");
void main(){
__asm__ __volatile__("mov al, 0x02 \n");
__asm__ __volatile__("xor ah, ah \n");
__asm__ __volatile__("int 0x10 \n");
__asm__ __volatile__("xor ax, ax \n");
__asm__ __volatile__("mov es, ax \n");
__asm__ __volatile__("mov bx, 0x7E00 \n");
__asm__ __volatile__("mov al, 0x03 \n");
__asm__ __volatile__("mov ch, 0x00 \n");
__asm__ __volatile__("mov cl, 0x02 \n");
__asm__ __volatile__("mov dh, 0x00 \n");
__asm__ __volatile__("mov ah, 0x02 \n");
__asm__ __volatile__("int 0x13 \n");
__asm__ __volatile__("jmp 0:0x7E00 \n");
}