【问题标题】:How to use more than 512 bytes of my own bootable floppy如何使用超过 512 字节的我自己的可启动软盘
【发布时间】:2014-02-18 06:54:10
【问题描述】:

我正在学习汇编语言,我按照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

【问题讨论】:

  • 链接文章的底部包含对您问题的详细解答。
  • 感谢您的回答,我会在其他时间尝试理解这些信息和代码。

标签: assembly bootable floppy


【解决方案1】:

这并不容易:

实际上 BIOS 只将磁盘的前 512 个字节加载到内存中。

然后您要做的就是将其余数据加载到内存中。这通常使用中断 13h(子功能 AH=2 或 AH=42h)来完成。

如果您确切知道数据在磁盘上的位置,这很容易。出于这个原因,像 GRUB 这样的引导加载程序使用众所周知的位置 - 不幸的是,这些位置有时会被其他程序(如复制保护驱动程序)覆盖。

如果您需要从定义明确的文件系统(例如 FAT 或 NTFS)加载,这将更加棘手:您只有约 450 字节的空间(因为文件系统内部使用了 512 字节中的约 60 字节)对于解释文件系统数据的代码,找到包含代码的文件并将其加载到内存中!

【讨论】:

  • 感谢您的回答,现在我正在关注这个网址 www.nondot.org/sabre/os/files/Booting/nasmBoot.txt 最后一个示例,但它不起作用。
【解决方案2】:

这是我制作的一个简单的引导加载程序:

[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

【讨论】:

  • 您应该在mov sp, bp 之前立即添加mov ss, ax,因为ss:sp 远指针应该始终一起修改。此外,地址0:8000h 对于堆栈来说也是一个糟糕的选择,因为您将使用正在读取的扇区覆盖堆栈,反之亦然。 (7C00h 后面是 7E00h,后面是 8000h。)
猜你喜欢
  • 2018-07-21
  • 1970-01-01
  • 1970-01-01
  • 2015-12-29
  • 2011-06-30
  • 1970-01-01
  • 2020-08-05
  • 1970-01-01
相关资源
最近更新 更多