Page 1 of 1

Boot Loader Help [Fixed]

Posted: Tue Mar 20, 2007 2:07 pm
by jzgriffin
Hey! I've been working on a simple operating system for a while, but the boot loader I've made is giving me problems (actually, I'm not sure if it's the boot loader or the kernel, but it seems to be the boot loader).

It's a simple 32-bit protected mode loader that enables A20 and reads the kernel from an unformatted floppy, then jumps to it. Virtual PC (2007) gives the an unrecoverable processor error whenever I try to boot the DD-created image. Here's the code, for anyone who has the time to check it for errors:

Code: Select all

;;;
;; [ID]
;;     Boot-Loader\Source\Boot-Loader.asm
;;
;; [Description]
;;     Boot loader, or boot sector, for the Grakos kernel. The boot loader is
;; loaded at 0x7C00 by the BIOS startup routines.
;;     After that, it loads the kernel at 0x1000 using the BIOS. Upon loading,
;; it disables interrupts, switches to protected mode, and starts the system.
;;
;; [Copyright]
;;     Copyright (C) 2007, Griffinsoft Corporation
;;
;; [Web Site]
;;     http://www.griffinsoft.net/ 
;;;

;; NASM is compiling 16-bit code
[BITS 16]

;; This is loaded at 0x7C00
[ORG 0x7C00]

;; Go directly to Start
jmp Start

;;;
;; [ID]
;;     Start
;;
;; [Description]
;;     Starts the loading process.
;;;
Start:
    mov si, 0x100
    mov ax, 0x1000
    mov es, ax
    mov ax, 0x0
    mov bx, ax
    mov cx, 0x0002
    mov dx, ax

;;;
;; [ID]
;;     ReadSector
;;
;; [Description]
;;     Reads the sector.
;;;
ReadSector:
    mov ax, 0x0201
    int 0x13
    mov ax, es
    add ax, 0x20
    mov es, ax
    dec si
    jz ReadSectorEnd
    inc cl
    cmp cl, 0x12
    jbe ReadSector
    mov cl, 1
    inc dh
    cmp dh, 2
    jne ReadSector
    mov dh, 0
    inc ch
    jmp ReadSector

;;;
;; [ID]
;;     ReadSectorEnd
;;
;; [Description]
;;     Kills the floppy drive.
;;;
ReadSectorEnd:
    pusha
    mov al, 0x0C
    mov dx, 0x3F2
    out dx, al
    popa

;;;
;; [ID]
;;     EnableA20
;;
;; [Description]
;;     Enables the A20 gate.
;;;
EnableA20:
    in al, 0x64
    test al, 2
    jnz EnableA20
    mov al, 0xD1
    out 0x64, al

;;;
;; [ID]
;;     EnterProtectedMode
;;
;; [Description]
;;     Enters protected mode.
;;;
EnterProtectedMode:
    in al, 0x64
    and ax, byte 2
    jnz EnterProtectedMode
    mov al, 0xDF
    out 0x60, al
    cli
    mov eax, cr0
    or eax, 1
    mov cr0, eax
    jmp 0x8 : ProtectedMode

[BITS 32]
;;;
;; [ID]
;;     ProtectedMode
;;
;; [Description]
;;     Goes to the kernel.
;;;
ProtectedMode:
    jmp 0x8 : 0x10000

;; Write the boot signature
times 510-($-$$) db 0
dw 0xAA55
Thanks in advance for any help!

- Jeremiah

Edit: Updated source code.

Posted: Tue Mar 20, 2007 2:23 pm
by Combuster

Code: Select all

[ORG 0x0000]
should be

Code: Select all

[ORG 0x7C00]
because the bootloader is loaded at 0x07c00, not the start of memory

[edit]mixed up 'kernel' and 'bootloader':oops:[/edit]

Posted: Tue Mar 20, 2007 2:39 pm
by jzgriffin
Arg. Typos. >_<

Thanks, Combuster. I'll see if that works.

Edit: Nope. I still get the same VPC error. Maybe I should .ZIP the whole OS code and let people have a look at it as a whole?

Posted: Tue Mar 20, 2007 2:51 pm
by Brynet-Inc
Jeremiah Griffin wrote:Nope. I still get the same VPC error. Maybe I should .ZIP the whole OS code and let people have a look at it as a whole?
May I ask if you have tested your OS on another emulator? Bochs/QEMU maybe? :?

Something with a debugger is always more efficient.. :wink:

Posted: Tue Mar 20, 2007 2:53 pm
by jzgriffin
No, I haven't tested in any other emulators. Didn't know there was debuggers in QEMU/Bochs. *installs*

Edit: This boot sector is fine. The kernel is the problem.