1

所以,我使用 Bochs 来运行我的引导加载程序和https://www.cs.bham.ac.uk/~exr/lectures/opsys/10_11/lectures/os-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
4

1 回答 1

1

由于您处于引导加载程序中,因此您当前处于实模式,因此您不能将其作为长模式地址写入。相反,设置DS为 0xb800 然后ebx用作偏移量:

mov ax, 0xb800
mov ds, ax
mov bx, 0
mov [bx], 0x412e  ; A with a green background, yellow foreground

否则,您将写入 DS 当前所在位置的偏移量。

于 2016-12-02T12:17:47.427 回答