Very simple realmode kernel not printing
Posted: Tue Nov 20, 2012 11:59 am
I decided to go back to OS development starting with a basic DOS system. However, the code doesn't seem to print "Starting OT-DOS..". When running in virtual box the cursor will move down a few lines, but it won't continue from there. I'm using DJGPP for the C/++ compiler. Here is the code:
build.bat
ot.asm
ot.c
And finally, the linker script
It compiles without errors, and I know it loads the kernel because I used an assembler version earlier. Much help would be appreciated.
build.bat
Code: Select all
nasm -f aout ot.asm -o entry.o
gcc -c ot.c -o ot.o
ld -T link.ld -o OT.SYS entry.o ot.o
copy OT.SYS A:\OT.SYS
pause
Code: Select all
bits 16 ; we are still in real mode
global start
extern _k_main
; we are loaded at linear address 0x10000
start:
call _k_main ;call our c source
cli
hlt ;stop execution
Code: Select all
void k_clear_screen();
unsigned int k_printf(char *message, unsigned int line);
k_main() // like main in a normal C program
{
//k_clear_screen();
k_printf("Starting OT-DOS..", 0);
};
void k_clear_screen() // clear the entire text screen
{
char *vidmem = (char *) 0xb8000;
unsigned int i=0;
while(i < (80*25*2))
{
vidmem[i]=' ';
i++;
vidmem[i]=WHITE_TXT;
i++;
};
};
unsigned int k_printf(char *message, unsigned int line) // the message and then the line #
{
char *vidmem = (char *) 0xb8000;
unsigned int i=0;
i=(line*80*2);
while(*message!=0)
{
if(*message=='\n') // check for a new line
{
line++;
i=(line*80*2);
*message++;
} else {
vidmem[i]=*message;
*message++;
i++;
vidmem[i]=WHITE_TXT;
i++;
};
};
return(1);
};
Code: Select all
OUTPUT_FORMAT("binary")
ENTRY(start)
SECTIONS
{
.text 0x010000 : {
code = .; _code = .; __code = .;
*(.text)
}
.data : {
data = .; _data = .; __data = .;
*(.data)
}
.bss :
{
bss = .; _bss = .; __bss = .;
*(.bss)
}
end = .; _end = .; __end = .;
}