Thats the bootloader

Click to reveal..
Code:
org 0x7C00		;start address of the bootloder that will load the kernel

xor ax, ax
mov ds, ax
mov es, ax
mov ss, ax
mov sp, ax


mov [bootdrive], dl 	;bootdrive stored by BIOS in DL.
                        ;we save it to [bootdrive] to play for safety.


mov si, strLoad		;show loading message
call printStr


;-----------------------

loadKernel:
  mov si, strDot	;show loading progress
  call printStr

  xor ax, ax         	;mov ax, 0 => function "reset"
  mov dl, [bootdrive] 	;boot drive
  int 0x13   		;reset floppy drivers
  jc loadKernel     	;CF set? try again

  mov si, strDot
  call printStr

			;set parameters for reading function
  mov ah, 0x2          	;read sectors 
  mov al, 10          	;read 10 sectors
  mov ch, 0          	;cylinder = 0
  mov cl, 2          	;sector = 2
  mov dh, 0          	;head = 0
  mov dl, [bootdrive] 	;boot drive
  mov bx, 0x8000	;start address of kernel

  int 0x13         	;read sectors
  jc loadKernel     	;CF set? try again

  mov si, strDot
  call printStr
  
  mov si, strDone
  call printStr

  jmp 0x8000

;-----------------------

printStr:
  mov ah, 0x0E      	;teletype output
.loop:   
  lodsb             	;grab a byte from SI
  test al, al       	;NULL?
  jz .done          	;if NULL exit
  int 0x10          	;print out the character!
  jmp .loop
.done:
  ret

;-----------------------

bootdrive db 0    	;boot drive, 0 = floppy
strLoad db "Loading kernel", 0
strDot db ".", 0
strDone db "[DONE]", 13, 10, 0
    
times 510-($-$$) hlt
db 0x55
db 0xAA



and thats the kernel:

Code:
[BITS 32]
[global kernelMain]
[extern _main]

kernelMain:
    jmp 0xffff:0x0000  ;reset pc
    jmp $



the c kernel is just a main function. At this stage i dont call it.

The linker script:
Code:
ENTRY(kernelMain)
SECTIONS
{
  .text  0x8000 : {
    *(.text)
  }
  .data  : {
    *(.data)
  }
  .bss  :  { 					
    *(.bss)
  }
}




and the program to create the floppy image:
Code:
char boot_buf[512];
	char kernel_buf[1024];
	char space_buf[1474560-512-1024] = {0};
	int floppy_desc, file_desc;

	file_desc = open("boot.bin", O_RDONLY);

        read(file_desc, boot_buf, 512);
        close(file_desc);

        floppy_desc = open("floppy.img", O_RDWR);

        lseek(floppy_desc, 0, SEEK_SET);
        write(floppy_desc, boot_buf, 512);

        file_desc = open("kernel.bin", O_RDONLY);
        read(file_desc, kernel_buf, 1024);
        close(file_desc);

        lseek(floppy_desc, 512, SEEK_SET);
        write(floppy_desc, kernel_buf, 1024);

	lseek(floppy_desc, 1024+512, SEEK_SET);
        write(floppy_desc, space, 1474560-512-1024);

        close(floppy_desc);




Last edited by Fear411; 04/15/10 14:19.