[英]How to use more than 512 bytes of my own bootable floppy
我正在學習匯編語言,我按照http://mikeos.berlios.de/write-your-own-os.html 的步驟制作了一個可啟動的圖形游戲,但我有一個問題:我不能使用超過 512我的程序的內存字節。
我怎么解決這個問題?
我很感激任何幫助。
這是我的代碼(仍然小於 512 字節): http : //pastebin.com/i6ehx8dT
編輯:我解決了我的問題,這里是用 16 位匯編語言制作的軟盤引導程序的最小示例: http : //pastebin.com/x1SawyjN
最后這個鏈接非常有幫助: http : //www.nondot.org/sabre/os/files/Booting/nasmBoot.txt
這很難做到:
實際上,BIOS僅將磁盤的前512個字節加載到內存中。
然后,您要做的就是將其余數據加載到內存中。 通常使用中斷13h(子功能AH = 2或AH = 42h)完成此操作。
如果您確切地知道數據在磁盤上的位置,這很容易。 因此,GRUB之類的引導加載程序會使用眾所周知的位置-不幸的是,此類位置有時會被其他程序(如復制保護驅動程序)覆蓋。
如果您需要從定義良好的文件系統(例如FAT或NTFS)中加載,則比較棘手:您只有約450字節的空間(因為文件系統內部使用了512字節中的約60字節)來存儲以下代碼:解釋文件系統的數據,找到包含代碼的文件並將其加載到內存中!
這是我制作的一個簡單的引導程序:
[org 0x7c00]
; stack and segment setup
xor ax, ax
mov es, ax
mov ds, ax
mov bp, 0x1200 ; thank you user ecm for notifying me to not use
; 0x8000 as the stack address
mov ss, ax ; thank you user ecm for notifying me to add this specified line of code
mov sp, bp
; load more than 512 bytes into memory
mov ah, 0x02 ; read sectors
mov al, 0x01 ; sectors to read
mov ch, 0x00 ; cylinder idx
mov dh, 0x00 ; head idx
mov cl, 0x02 ; sector idx
mov dl, 0x00 ; disk idx
mov bx, program ; address of more than 512 bytes
int 0x13
; because i'm tired you can do the error checking by checking if al is the
; same as what you set it to and checking for the carry flag
; jump to program (no error checking!)
jmp program
times 510-($-$$) db 0
dw 0xAA55
; more than 512 bytes program
program:
mov ah, 0x0E
mov bh, 0x00
mov al, 'A'
int 0x10
jmp $
; amount of zeros = 512 + (number of sectors read * 512)
times 1024-($-$$) db 0
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.