![](/img/trans.png)
[英]How do i write a function that prints a null terminated string in NASM 16 bit real mode?
[英]NASM, how to write straight to the hard disk and read from it in Real Mode
在最新版本的 Ubuntu 上,x64。
我本質上想知道從閃存驅動器啟動時操作系統如何能夠將自己安裝在計算機上,但我想在實模式下而不是保護或長模式下執行此操作。 當然,像 MS-DOS 這樣的舊操作系統曾經這樣做過。
對於實模式,是否有中斷? 或者我是否需要先切換到保護模式或長模式,然后才能將數據直接寫入硬盤和/或從同一區域讀取?
為具有 2 階段引導加載程序的小型實模式操作系統執行此操作:
org 0x7C00
mov ah, 0
int 13h
mov dx, 0
mov ah, 2
mov al, 10h
mov dl, 0x80
mov ch, 0
mov dh, 0
mov cl, 2
mov bx, stage2
int 0x13
jmp stage2
times 510-($-$$) db 0
dw 0xAA55
msg db "!!"
%include "read.s" ;read.s does not exist yet, as I do not know how to read from an address on the hard disk
%include "write.s" ;write.s does not exist yet, as I do not know how to write to an address on the hard disk
stage2:
call ReadStr ;always reads from the same address, if the message is there, sets bl to 0x01. Otherwise, sets bl to 0x00.
cmp bl, 0x00
je load
mov ah, 0eh
mov al, "#" ;tiny message to tell me that the string is already at the address
mov bx, 0
int 10h
jmp $
load:
mov ax, [msg]
call LoadStr ;loads the message to the same address that ReadStr reads from
mov ah, 0eh
mov al, "$" ;tiny message to tell me that the string does not already exist at the address
mov bx, 0
int 10h
jmp $
這里的想法是,第一次啟動引導加載程序時,它應該打印“$”,但是第二次啟動它時,它應該打印“#”,因為數據已經存在於硬盤上的特定地址。 但是我不知道如何實現read.s和write.s。 理想情況下(此的主要目標),操作系統將在我第一次啟動閃存驅動器上的引導加載程序時自行安裝在計算機上。 我需要先設置長模式才能做到這一點,還是可以在 BIOS 中實現?
得到了一些工作; 第一次啟動時它會打印“!#”,但之后每次啟動時都會打印“##”,因為閃存驅動器的第二個扇區已被閃存驅動器的第三個扇區覆蓋。 唯一缺少的是如何使用硬盤驅動器而不是閃存驅動器來做到這一點,但至少我現在知道如何重寫閃存驅動器,因此可以以某種方式模擬內存存儲,即使是以一種低效的方式。 下一步是找出如何將可引導扇區注入實際計算機的內存中,以便我可以使用 RAM 的原始功能來存儲和操作數據。
org 0x7C00
stage1:
mov ah, 2
mov cl, 2
mov bx, stage2
int 13h
call stage2
mov ah, 2
mov cl, 3
mov bx, stage2
int 13h
mov ah, 3
mov cl, 2
mov bx, stage2
int 13h
mov ah, 2
mov cl, 2
mov bx, stage2
int 13h
call stage2
jmp $
times 510-($-$$) db 0
dw 0xAA55
stage2:
mov ah, 0eh
mov al, "!"
mov bx, 0
int 10h
ret
times 1024-($-$$) db 0
stage3:
mov ah, 0eh
mov al, "#"
mov bx, 0
int 10h
ret
times 1536-($-$$) db 0
您的答案在https://en.wikipedia.org/wiki/INT_13H 上,您應該將 dl 更改為驅動程序編號,然后對該驅動程序進行操作:
mov dl,[that_driver_number]
注意:當 bios 想要運行引導加載程序時,將 dl 設置為引導加載程序驅動程序(例如,如果引導加載程序在 cd 驅動程序 1 上,它設置為 E0),並且當您沒有更改它時,您的操作發生在引導程序上,例如此代碼應復制你在硬盤上的引導程序
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.