Need help with C Kernel
Posted: Wed Jul 21, 2010 4:55 pm
Hey guys, I finally got a C kernel with assembly to boot but there is a problem. It is not displaying the text that it is supposed to be. Can someone please tell me what is going wrong?
kernel.c
kernel.h
kernel.asm
This is what I'm using to compile,
C Source files - gcc -c -o kernel.o kernel.c
ASM - nasm -f win32 -o asmkernel.o kernel.asm
Linker - ld -o kernel.img kernel.o asmkernel.o
The linker script used to be ld -o kernel.bin kernel.o asmkernel.o but I changed it to .img so I can write it to a floppy. Hopefully, this is not the problem as I do not know if you can even convert a .bin to a .img file, or if you can write a .bin file to a floppy.
Thanks for any help.
kernel.c
Code: Select all
#define WHITE_TXT 0x07 // white on black text
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("Hi!\nHow's this for a starter OS?", 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
#define WHITE_TXT 0x07 // white on black text
void k_clear_screen();
unsigned int k_printf(char *message, unsigned int line);
Code: Select all
[BITS 32]
[global start]
[extern _k_main] ; this is in the c file
start:
call _k_main
cli ; stop interrupts
hlt ; halt the CPU
C Source files - gcc -c -o kernel.o kernel.c
ASM - nasm -f win32 -o asmkernel.o kernel.asm
Linker - ld -o kernel.img kernel.o asmkernel.o
The linker script used to be ld -o kernel.bin kernel.o asmkernel.o but I changed it to .img so I can write it to a floppy. Hopefully, this is not the problem as I do not know if you can even convert a .bin to a .img file, or if you can write a .bin file to a floppy.
Thanks for any help.