所以,我使用Bochs来运行我的引导装载程序和https://www.cs.bham.ac.uk/~exr/lectures/opsys/10_11/lectures/os-dev.pdf第4.1章。
我试图通过直接写入视频内存来打印到BIOS控制台,但当我运行Bochs时,我看不到打印的字符串。该代码实际上与PDF上的代码相同。我错过了什么?有没有一个博克斯设置我忘记了或PDF没有告诉我的东西?
下面是包含函数的汇编文件
;
; A simple collection of string routines for 32-bit protected mode.
;
[bits 32]
VIDEO_MEMORY equ 0xB8000
WHITE_ON_BLACK equ 0x0f ; Color mode for the text to be written
PrintString: ; Assume ebx holds memory address of string.
; edx will hold start of video memory
; Recall that each character written will take up 2 bytes of video memory
; So any particular row or column on the screen will have mem location = 0xb80000
; + 2 * (80r + c)
; The way this code is written, its always writing starting from the start of the
; video memory at 0xb8000, the top left of the screen, replacing everything there.
pusha
mov edx, VIDEO_MEMORY
PrintLoop:
mov al, [ebx] ; Only ebx can be used to index
mov ah, WHITE_ON_BLACK
cmp al, 0
je ExitRoutine
mov [edx], ax
inc ebx
add edx, 2
jmp PrintLoop
ExitRoutine:
popa
ret
下面是我实际的 Boot 逻辑。
;
; A simple boot sector program that loops forever.
;
[bits 32]
[org 0x7c00]
mov ebx, welcome_msg
call PrintString
jmp $
%include "string_utils.s"
welcome_msg db 'WELCOME TO BASICOS OMFG!', 0
goodbye_msg db 'Goodbye! Thanks for using my BasicOS!', 0
times 510 -( $ - $$ ) db 0
dw 0xaa55
1条答案
按热度按时间sf6xfgos1#
由于您处于引导加载程序中,因此当前处于真实的模式,因此无法将其作为长模式地址写入。相反,将
DS
设置为0xb800,然后使用ebx
作为偏移量:否则,您将写入DS当前所在位置的偏移量。