Boot Loader Help [Fixed]

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
jzgriffin
Member
Member
Posts: 190
Joined: Tue Sep 26, 2006 1:40 pm
Libera.chat IRC: Nokurn
Location: Ontario, CA, USA
Contact:

Boot Loader Help [Fixed]

Post 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.
Last edited by jzgriffin on Tue Mar 20, 2007 3:59 pm, edited 2 times in total.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post 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]
Last edited by Combuster on Tue Mar 20, 2007 4:53 pm, edited 1 time in total.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
jzgriffin
Member
Member
Posts: 190
Joined: Tue Sep 26, 2006 1:40 pm
Libera.chat IRC: Nokurn
Location: Ontario, CA, USA
Contact:

Post 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?
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Post 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:
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
jzgriffin
Member
Member
Posts: 190
Joined: Tue Sep 26, 2006 1:40 pm
Libera.chat IRC: Nokurn
Location: Ontario, CA, USA
Contact:

Post 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.
Post Reply