x86 - x86 程序集:引导加载程序不加载程序
问题描述
在过去的几天里,我一直在尝试制作操作系统,并从制作引导加载程序开始。我特别想加载一个小示例程序来测试它。这是引导加载程序代码:
org 0x7c00
bits 16
start: jmp boot
boot:
cli ; Disable interrupts
cld ; Clear direction flags
mov al, 2 ; Read 2 sectors
mov ch, 0 ; Track 0
mov cl, 2 ; Read 2nd sector (1st sector is bootloader)
mov dh, 0 ; Head number
mov dl, 0 ; Drive number (0 = floppy drive)
; Specify memory address to read floppy to
mov bx, 0x5000
mov es, bx
xor bx, bx
mov ah, 0x2 ; INT 0x13 with AH=0x2 means read sector
int 0x13 ; Call BIOS to read sector
jmp 0x5000:0x0000 ; Jump to sector
; Must be 512 bytes
times 510 - ($-$$) db 0
dw 0xAA55 ; Boot Signature
这是示例程序代码:
msg db "Welcome to kOS!", 0ah, 0dh, 0h
start: jmp moveCursor
moveCursor:
mov ah, 0x2 ; INT 0x10 with AH=0x2 means set cursor position
mov bh, 0 ; Page number
mov dh, 12 ; Row
mov dl, 0 ; Column
int 0x10 ; Call BIOS to set position
jmp putChar
putChar:
mov ah, 0xA ; INT 0x10/AH=0xA means write character
mov al, 0x48 ; Character H
mov bh, 0 ; Page number
mov cx, 1 ; Times to write character
int 0x10 ; Call BIOS to write character
jmp print
print:
mov si, msg ; Move starting address of message into SI
jmp printstring
printstring:
xor ax, ax ; Set AX to 0
mov ds, ax ; Set Data Segment to 0
lodsb ; Load byte at Data Segment into AL, increment SI
or al, al ; Check if AL is 0
jz exitloop ; If zero exit the loop
mov ah, 0xE ; INT 0x10/AH=0xE means teletype output
int 0x10 ; Call BIOS to write character
jmp printstring ; Repeat for next character
exitloop:
hlt ; Halt the system
但是,使用 QEMU/GDB 进行调试时,我发现引导加载程序代码的跳转从未发生(我在地址 0x5000 处设置了一个断点,但它从未到达它),并且程序永远不会运行。我在这里发现了许多具有相同问题的问题,但他们的解决方案对我没有帮助。感谢所有帮助。谢谢!
解决方案
推荐阅读
- java - 在 SpringBoot 中使用 ExecutorService 时出现“内存不足”和“超出 GC 限制”
- python - 如果将每个视图类移到单独的 .py 文件中,会影响性能吗?
- node.js - 如何获取 Loopback 3 条件“数据源”和“模型配置”:按照说明操作但不起作用
- assembly - 反转字符串并以汇编 MIPS 语言打印
- hyperledger-fabric - 将组织添加到现有网络失败,频道 ID 不匹配 $CHANNEL_NAME != mychannel
- batch-file - 非英文键盘的发送键故障
- javascript - Laravel 和 Vue:在使用渲染任何组件之前从 Store 初始化身份验证
- java - javax.servlet.http.HttpServletRequest 中的 HttpSession 是如何工作的
- android - 如果模块大小小于 10MB,则会显示动态交付用户确认对话框
- azure-service-fabric - 在 Service Fabric 中查询可靠集合(IReliableDictionary)的方法是什么?