Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

16 bit C code for real mode kernel

I don't know how to compile my C kernel for 16 bit real mode. I have tried a variety of compilers with no luck. My bootloader simply loads raw sectors from the floppy (my kernel lives right after the first sector on the disk) to the physical memory address 1000h:0000h then jumps to it. How can I compile my C kernel to work in 16 bit real mode?

my basic kernel:

void OSmain()
{
    unsigned char *videoram = (unsigned char *) 0xb8000;
    videoram[0] = 65;                                     /* character 'A' */
    videoram[1] = 0x07;                                   /* forground, background color. */

    while( 0 )
    {

    }
}

the compilers I have tried are GCC, tinyCC, and DMC. My goal is to get a flat binary file that I can jump to to begin execution.

like image 209
TheFuzz Avatar asked Jul 16 '11 22:07

TheFuzz


1 Answers

First, I recommend you check out the OSDev Wiki, which has resources upon resources for developing your own OS and components.

Second, have you considered writing a bootloader in assembly that starts off in real mode, switches to protected mode, and then jumps to your (32-bit) compiled kernel?

like image 127
Adam Maras Avatar answered Sep 23 '22 23:09

Adam Maras