【发布时间】:2013-08-31 10:12:23
【问题描述】:
我正在摆弄自己的引导加载程序 (MBR)。这是我更好地了解操作系统的第一步。
我的配置是:
MacBook Air、OsX 10.8.4、Parallels Desktop、Xcode、XCode 命令行工具、Nasm、LD、gcc、...
我已经编写了一个引导加载程序:
;
; FpLoader.s
;
bits 16 ; 16-bit Real Mode
org 0x7c00 ; Set origin to BIOS boot origin
;
; Bootloader entry-code
;
Main: cli ; Enable interrupts
mov ax, cs ; Setup stack segments
mov ds, ax
mov es, ax
mov ss, ax
sti ; Enable interrupts
mov si, Message_1 ; Print string
call PrintLn
mov si, Message_2 ; Print string
call PrintLn
call PrintCrLf
call PrintCrLf
call Reboot
;
; Read keypress
;
ReadKeypress:
mov ah, 0 ; BIOS function - Wait for and read keyboard
int 0x16 ; Call BIOS Keyboard Service
ret ; Return from procedure
;
; PrintLn string
;
PrintLn:
lodsb ; Load [Si] in Al and increment Si
or al, al ; Check if end of string reached (Al == 0)
jz .PrintLnEnd
mov ah, 0x0e ; BIOS function - Print character on screen
int 0x10 ; Call BIOS Screen Service
jmp PrintLn ; Loop
.PrintLnEnd call PrintCrLf
;
; Print Cr/Lf
PrintCrLf: mov ah, 0x0E ; BIOS function - Print character on screen
mov al, 0x0D ; Character to print: Cr
int 0x10 ; Call BIOS Screen Service
mov al, 0x0A ; Character to print: Lf
int 0x10 ; Call BIOS Screen Service
ret ; Return from procedure
;
; Reboot the machine
;
Reboot: mov si, AnyKey ; Print string
call PrintLn
call ReadKeypress
db 0x0ea ; Sends us to the end of the memory causing reboot
dw 0x0000
dw 0xffff
;
; Data
;
; Program data
Message_1 db "Hello World...", 0x0
Message_2 db "Painted Black bootloader.", 0x0
AnyKey db "Press any key to reboot...", 0x0
; Filler bytes
times 510 - ($-$$) db 0
; Trailer bytes
dw 0xAA55 ;Boot signature
我正在组装这段代码:
nasm -f bin FpLoader.s -o FpLoader.img
sudo dd if=FpLoader.img of=FpLoader.iso bs=2k
当我尝试从 FpLoader.iso 启动 Parallels 虚拟机时,它拒绝启动,告诉我它无法从 iso 启动(在 Parallels 配置中配置为 CD)。
由于我对该主题完全陌生,并且对如何继续使用我可用的工具感到困惑,因此我很感激您能给我的任何帮助。
我已经找到了一些适用于 Linux、Bochs 的部分解决方案……但没有一个真正为我指明了正确的方向。
我对 Iso 文件并不严格。如果有人可以向我展示一种使用 img 文件、真正的可启动 USB(在 Parallels 虚拟机中)或其他一些解决方案(与我的配置兼容)来测试我的开发的方法,那也很好。
提前致谢和亲切的问候, 铅
【问题讨论】:
-
同时,我已经找到了解决方案:"dd if=/dev/zero of=FpLoader.img bs=1024 count=1440" 之后"dd if=FpLoader.bin of=FpLoader.imb bs=1 count=512 conv=notrunc"。最后将虚拟软盘连接到虚拟机并将该虚拟软盘与创建的 FpLoader.img 相关联
-
看起来像是一个非常有趣的问题的答案,你应该把它作为你设法找到的任何相关信息的答案。
标签: macos assembly iso bootloader parallels