gpt4 book ai didi

Linux x86 Bootstrap

转载 作者:IT王子 更新时间:2023-10-29 00:39:08 25 4
gpt4 key购买 nike

我正在尝试在 nasm 中构建一个简单的 x86 Linux 引导加载程序。

Linux bzImage 存储在磁盘分区 sda1 上,从第一个扇区开始。

我从 bzImage(15 个扇区)读取实模式代码到从 0x7E00 开始的内存中。
但是,当我跳入代码时,它只是挂起,什么也没有发生。

我已经为 sda 上的主引导记录创建了代码。如果我只是附加,我可能是最好的
整个东西。我想知道为什么它只是在远跳指令之后挂起。

[BITS 16]

%define BOOTSEG 0x7C0
%define BOOTADDR (BOOTSEG * 0x10)

%define HDRSEG (BOOTSEG + 0x20)
%define HDRADDR (HDRSEG * 0x10)

%define KERNSEG (HDRSEG + 0x20)

[ORG BOOTADDR]
entry_section:
cli
jmp start
start:
; Clear segments
xor ax, ax
mov ds, ax
mov es, ax
mov gs, ax
mov fs, ax
mov ss, ax
mov sp, BOOTADDR ; Lots of room for it to grow down from here

; Read all 15 sectors of realmode code in the kernel
mov ah, 0x42
mov si, dap
mov dl, 0x80
int 0x13
jc bad

; Test magic number of kernel header
mov eax, dword [HDRADDR + 0x202]
cmp eax, 'HdrS'
jne bad

; Test jump instruction is there
mov al, byte [KERNSEG * 16]
cmp al, 0xEB
jne bad

xor ax, ax ; Kernel entry code will set ds = ax
xor bx, bx ; Will also set ss = dx
jmp dword KERNSEG:0

; Simple function to report an error and halt
bad:
mov al, "B"
call putc
jmp halt

; Param: char in al
putc:
mov ah, 0X0E
mov bh, 0x0F
xor bl, bl
int 0x10
ret

halt:
hlt
jmp halt

; Begin data section
dap: ; Disk address packet
db 0x10 ; Size of dap in bytes
db 0 ; Unused
dw 15 ; Number of sectors to read
dw 0 ; Offset where to place data
dw HDRSEG ; Segment where to place data
dd 0x3F ; Low order of start addres in sectors
dd 0 ; High order of start address in sectors

; End data section

times 446-($-$$) db 0 ; Padding to make the MBR 512 bytes

; Hardcoded partition entries
part_boot:
dw 0x0180, 0x0001, 0xFE83, 0x3c3f, 0x003F, 0x0000, 0xF3BE, 0x000E
part_sda2:
dw 0x0000, 0x3D01, 0xFE83, 0xFFFF, 0xF3FD, 0x000E, 0x5AF0, 0x01B3
part_sda3:
dw 0xFE00, 0xFFFF, 0xFE83, 0xFFFF, 0x4EED, 0x01C2, 0xb113, 0x001D
part_sda4:
dw 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000

dw 0xAA55 ; Magic number at relative address 510
mbrend: ; Relative address 512

最佳答案

评论与代码不符!

xor bx, bx ; Will also set ss = dx

我严重怀疑这是否是你的问题......

免责声明:我没有这样做!我是“小鸡”,总是从软盘启动。

我“期望”在 MBR 中看到的是它自己移开,然后再次将事件分区上的第一个扇区加载到 7C00h,然后跳转到那里。这个“真正的引导加载程序”加载其余的。我不熟悉 bzImage 的布局 - 也许它会在 7E00h 加载...

我想我在我的头上。我去拿外套...

关于Linux x86 Bootstrap ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14658119/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com