背景信息
我正在開發一個簡單的DOS操作系統。所以我不打算很快進入保護模式。操作系統將以彙編形式編寫;順便說一句,NASM語法。引導扇區應該將引導扇區保存在硬盤的第一個扇區上,並在第二扇區上保存OS的代碼。以便它可以從硬盤啓動,而不是從CD映像啓動。無法保存磁盤上的引導扇區和磁盤上的操作系統然後將其加載到內存中
The Issue
問題是引導扇區似乎在硬盤上正確保存了一切。但是當我重新啓動VMware Player時,彈出虛擬光盤。它啓動一個背景綠色(圖1.1)。這隻能意味着引導扇區不會加載地址爲0x7e00的第二個扇區,並且無法跳轉。奇怪的是進位標誌沒有被設置,所以我假設沒有錯誤發生。所以基本上,當我從CD-ROM映像啓動時,它顯示了一切正常(圖1.2)。但是當我重新啓動並從硬盤啓動時,它無法跳轉到應該在0x7e00加載的操作系統。引導扇區在0x7c00加載。我假設我的網段地址是正確的,也許我的偏移地址不正確,或者我的磁盤寫入和讀取完全錯誤?
事情是,OS圓滿完成
基本系統軟件的中斷調用的形式。改性的IVT(中斷向量表)主硬盤上
負載引導扇區,並且BIOS可以從硬盤加載引導扇區到內存位置0x7c00
的代碼,可能是導致此問題
這裏是boot.asm代碼:
[ORG 0x7c00] ; BIOS loads at 0x7c00 in memory
jmp start
%include "C:\Users\OSDEV\OS-SRC\MonsterOS\source\syscalls\syscalls.inc"
start:
xor ax, ax ; make it zero
mov ds, ax ; Data segment is zero
;Set desired video mode (Graphics Mode)
mov ah, 0
mov al, 12h
int 10h
call init_int
;Set desired background color (Green)
mov ah, 0x0b
mov bh, 0
mov bl, 2
int 10h
; Display Box Shaped Cursor
mov ch, 0
mov cl, 7
mov ah, 1
int 10h
;Save BootLoader on the DISK
xor ax, ax
mov es, ax ; ES <- 0
mov cx, 1 ; cylinder 0, sector 1
mov dx, 0080h ; DH = 0 (head), drive = 80h (0th hard disk)
mov bx, 7c00h ; segment offset of the buffer
mov ax, 0301h ; AH = 03 (disk write), AL = 01 (number of sectors to write)
int 13h
;Save OS on the DISK
xor ax, ax
mov es, ax ; ES <- 0
mov cx, 2 ; cylinder 0, sector 2
mov dx, 0080h ; DH = 0 (head), drive = 80h (0th hard disk)
mov bx, 7e00h ; segment offset of the buffer
mov ax, 0301h ; AH = 03 (disk write), AL = 01 (number of sectors to write)
int 13h
;Load OS from DISK at 0x7e00
xor ax, ax
mov es, ax ; ES <- 0
mov cx, 2 ; cylinder 0, sector 2
mov dx, 0080h ; DH = 0 (head), drive = 80h (0th hard disk)
mov bx, 7e00h ; segment offset of the buffer
mov ax, 0201h ; AH = 02 (disk read), AL = 01 (number of sectors to read)
int 13h
jc err
jmp 0h:0x7e00 ; Jump To OS
err:
mov ax, err_msg
mov bh, 0
mov bl, 0xf
int 21h ; Print error message
err_msg: db 'Error Failed To Load OS From Disk!', 0
times 510-($-$$) db 0
db 0x55
db 0xAA
這裏是os.asm:
[ORG 0x7e00]
xor ax, ax ; make it zero
mov ds, ax ; Data segment is zero
mov es, ax
; Clear Screen
int 27h
;Set desired background color (Green)
mov ah, 0x0b
mov bh, 0
mov bl, 2
int 0x10
; Display Box Shaped Cursor
mov cx, 0607h
mov ah, 1
int 10h
; Print Desired Message
mov ax, msg
mov bh, 0
mov bl, 0xf
int 21h
int 23h ; Print newline
hang:
mov ax, buffer
int 25h ; SIZE(buffer)
mov ax, buffer
int 24h ;ZERO(buffer)
; Print Desired Message
mov ax, cli_msg
mov bh, 0
mov bl, 0xf
int 21h ; print ax=msg bl=blue
; Get Input
mov bx, buffer
int 22h ; Read From Keyboard And Print The String With Line Feed
; ECHO String Stored At The Address Buffer
mov ax, buffer
mov bh, 0
mov bl, 0xf
int 21h ;
int 23h ; Print newline
jmp hang
msg: db 'Welcome To MonsterOS!', 0
cli_msg: db 'MonsterOS> ', 0
buffer: times 64 db 0
這裏是腳本代碼的build.bat:
nasm -f bin C:\Users\OSDEV\OS-SRC\MonsterOS\source\boot.asm -o C:\Users\OSDEV\OS-SRC\MonsterOS\bin\boot.bin
nasm -f bin C:\Users\OSDEV\OS-SRC\MonsterOS\source\os.asm -o C:\Users\OSDEV\OS-SRC\MonsterOS\bin\os.bin
copy /b C:\Users\OSDEV\OS-SRC\MonsterOS\bin\boot.bin + C:\Users\OSDEV\OS-SRC\MonsterOS\bin\os.bin C:\Users\OSDEV\OS-SRC\MonsterOS\bin\img.bin
miso C:\Users\OSDEV\OS-SRC\MonsterOS\bin\os.iso -ab C:\Users\OSDEV\OS-SRC\MonsterOS\bin\img.bin
後腳本
中斷21H,22H,23H,24H, 25h,26h,是我爲我的操作系統編寫的自定義軟件中斷。如果您有任何問題或需要更多的代碼或信息,我在這裏提供更多信息。
解決方案
對於那些誰照顧,我在用VirtualBox的創建,並從VHD啓動一個VHD寫img.bin解決它。所以它就像一個魅力。順便說一下,我使用了十六進制編輯器。
圖1.1
圖1。2
不清楚0x7E00處的「OS」來自何處。 BIOS會將您的啓動扇區加載到0x7C00,然後將其寫入硬盤(在引導扇區中做一件奇怪的事情)。然後,您將0x7E00寫入硬盤並讀回來......但是,首先如何獲得0x7E00? – 2013-05-05 03:54:42
那麼我沒有顯示整個代碼,可能是你的困惑的原因。然後你又可能是對的。我在我的問題中發佈了更多代碼。 – 2013-05-05 14:21:37
@FrankKotler嗯,我想從硬盤啓動,而不是CD映像。我對操作系統開發很陌生,所以如果我沒有正確地做事,請原諒我。 :D – 2013-05-05 14:24:41