目前,我正在閱讀 v0.01 的 Linux 內核源代碼。我正在嘗試模仿代碼并使其作業。但是在引導扇區的一開始就卡住了。在 bootsect.s 中,程式首先在 0x7c00 加載并將自身移動到 0x90000,然后跳轉到 0x90000,但不知何故該'jmpi'指令不起作用。
SETUPLEN = 4 ! len of setup-sectors, 4 sectors
BOOTSEG = 0x07c0 ! original address of boot sector
INITSEG = 0x9000 ! move bootsect here
SETUPSEG = 0x9020 ! setup starts here
SYSSEG = 0x1000 ! system loaded at 0x10000 (65536)
ENDSEG = SYSSEG SYSSIZE ! where to stop loading
entry start
start:
mov ax, #BOOTSEG
mov ds, ax
mov ax, #INITSEG
mov es, ax
mov cx, #256
sub si, si
sub di, di
rep
movw ! move bootsect itself to address 0x90000 (256 * 2 Bytes)
jmpi go, INITSEG ! jump to address 0x90000 and execute
!j go
go:
mov ax, cs
mov ds, ax
mov es, ax
mov ss, ax
mov sp, #0xFF00 ! Top of the stack - ss:sp address is 0x9FF00
! print something
mov ah, #0x03 ! read cursor pos
xor bh, bh
int 0x10
mov cx, #7
mov bx, #0x0007 ! page 0, attribute 7 (normal)
mov bp, #msg
mov ax, #0x1300 ! write string, move cursor
int 0x10
msg:
.byte 13,10
.ascii "!"
.byte 13,10,13,10
我還想提一提的是,如果我將'jmpi go, INITSEG'替換為'j go''go''!'"≡S"
我不確定是否'jmpi'完全不起作用,或者僅僅是因為 print(0x10) 函式有問題,所以我在螢屏上看不到任何東西。
我是匯編語言的初學者,我不知道代碼有什么問題,即使代碼幾乎是從 Linux 內核復制的。
uj5u.com熱心網友回復:
問題解決了!
我使用 as86 & ld86 來編譯和鏈接。為了使其可啟動,我嘗試將 510 和 511 位元組設定為 0xAA 和 0x55。我預計二進制檔案只有 512 個位元組,重寫 510&511 個位元組就可以了。
但實際上,二進制檔案前面有 32 個位元組的 MINIX 頭,使得二進制檔案的總大小為 544 個位元組。重寫 510&511 上的位元組會使整個二進制檔案變得一團糟。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/482894.html
上一篇:我需要在notepad 中使用tasm/tlink/dosbox顯示3位數的答案
下一篇:在x86中交換地址后程式崩潰
