views:

253

answers:

2

We are working on a project to learn how to write a kernel and learn the ins and outs. We have a bootstrap loader written and it appears to work. However we are having a problem with the kernel loading. I'll start with the first part:

bootloader.asm:

    [BITS 16]
    [ORG 0x0000]
;
;    all the stuff in between
;
;    the bottom of the bootstrap loader

     datasector  dw 0x0000
     cluster     dw 0x0000
     ImageName   db "KERNEL  SYS"
     msgLoading  db 0x0D, 0x0A, "Loading Kernel Shell", 0x0D, 0x0A, 0x00
     msgCRLF     db 0x0D, 0x0A, 0x00
     msgProgress db ".", 0x00
     msgFailure  db 0x0D, 0x0A, "ERROR : Press key to reboot", 0x00

     TIMES 510-($-$$) DB 0
     DW 0xAA55

     ;*************************************************************************

The bootloader.asm is too long for the editor without causing it to chug and choke. In addition, the bootloader and kernel do work within bochs as we do get the message "Welcome to our OS". Anyway, the following is what we have for a kernel at this point.

kernel.asm:

[BITS 16]
[ORG 0x0000]

[SEGMENT .text]         ; code segment
    mov     ax, 0x0100          ; location where kernel is loaded
    mov     ds, ax
    mov     es, ax

    cli
    mov     ss, ax          ; stack segment
    mov     sp, 0xFFFF          ; stack pointer at 64k limit
    sti

    mov     si, strWelcomeMsg       ; load message
    call        _disp_str

    mov     ah, 0x00
    int     0x16                ; interrupt: await keypress
    int     0x19                ; interrupt: reboot

_disp_str:
    lodsb                       ; load next character
    or      al, al          ; test for NUL character
    jz      .DONE

    mov     ah, 0x0E            ; BIOS teletype
    mov     bh, 0x00            ; display page 0
    mov     bl, 0x07            ; text attribute
    int     0x10                ; interrupt: invoke BIOS

    jmp     _disp_str

.DONE:
    ret

[SEGMENT .data]                 ; initialized data segment
    strWelcomeMsg   db  "Welcome to our OS",    0x00

[SEGMENT .bss]              ; uninitialized data segment  

Using nasm 2.06rc2 I compile as such:
nasm bootloader.asm -o bootloader.bin -f bin
nasm kernel.asm -o kernel.sys -f bin

We write bootloader.bin to the floppy as such:
dd if=bootloader.bin bs=512 count=1 of/dev/fd0

We write kernel.sys to the floppy as such:
cp kernel.sys /dev/fd0

As I stated, this works in bochs. But booting from the floppy we get output like so:

Loading Kernel Shell
...........
ERROR : Press key to reboot

Other specifics: OpenSUSE 11.2, GNOME desktop, AMD x64 Any other information I may have missed, feel free to ask. I tried to get everything in here that would be needed. If I need to, I can find a way to get the entire bootloader.asm posted somewhere. We are not really interested in using GRUB either for several reasons. This could change, but we want to see this boot successful before we really consider GRUB.

EDIT: The bootstrap loader is suppose to be 512 bytes, written to the boot sector (very first sector) of the disk. Take my word for it, bootloader is 512 bytes compiled. The kernel is suppose to be in the very next sector.

A: 

Go to #osdev at irc.freenode.org and post a link to this question. They'll be happy to help you.

shs
+1  A: 

If you want kernel.sys to start at the second sector, use this instead of cp.

dd if=kernel.sys of=/dev/fd0 bs=512 seek=1

Or, assuming bootloader.bin is exactly 512 bytes, this works too:

cat bootloader.bin kernel.sys > /dev/fd0
ephemient
bootloader.bin is exactly 512 bytes...will the `cat...` command put bootloader.bin at sector 0 (the boot sector)???
dboarman
It will start at the beginning of the raw device (Linux is convenient and allows non-block access to block devices) which does happen to be sector 0.
ephemient
Apparently, this is an issue with writing to `/dev/fd0`. Even with the samples you provided, apparently the kernel.sys file isn't being written. When I make an image of the floppy, it returns a 1.4Mb image file; however, only the first 512 bytes are actually written with the bootstrap. There is no kernel.sys on the image.
dboarman
I'm going to go ahead and mark this the answer because I think it is as far as I can go on SO with it. I think the rest of the problem will have to be worked out on SU.
dboarman