所以,我使用bochs运行我的bootloader和https://www.cs.bham.ac.ac.uk/~exr/comentures/poctures/opsys/10_11/11/lectures/oss-dev。PDF第4.1章。
我试图通过直接写入视频记忆来打印到BIOS控制台,但是当我运行Bochs时,我看到没有打印的字符串。代码实际上与PDF上的代码相同。缺少什么吗?是否有bochs设置我忘记了,或者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
这是我实际的引导逻辑。
;
; 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
您当前处于实际模式,因为您在引导程序中,因此您不能将其作为长模式地址写入。而是将DS
设置为0xB800,然后将ebx
用作偏移:
mov ax, 0xb800
mov ds, ax
mov bx, 0
mov [bx], 0x412e ; A with a green background, yellow foreground
否则,您正在写信到当前DS的偏移。