为什么BIOS没有调用AH = 0xB,BH = 0x00的INT 0x10在这里工作?

时间:2017-11-04 06:04:04

标签: assembly bootloader bios osdev

我刚刚关注了MikeOS网站上的bootloader开发指南,到目前为止我已经理解了代码。我正在尝试向bootsector添加一些额外的例程,特别是将背景颜色更改为BIOS颜色0x1。但是,下面的代码不会将背景设置为正确的颜色,而是仅为黑色。这有什么不对? (我希望我的代码得到很好的评论)

    BITS 16     ; tell nasm we're working in 16 bit real mode

start:          ; entry symbol for the os          

        mov ax, 0x07C0          ; 4 kilobyte stack space set up
        add ax, 288             ; (4096+512) / 16 bytes per paragraph
        mov ss, ax              
        mov sp, 4096

        mov ax, 0x07C0          ; set data segment to where we've loaded
        mov ds, ax

        mov si, text_string     ; put our string position into SI
        call write_string       ; call our string-printing function
        call set_bg             ; call our background-setting routine

        jmp $                   ; jump here for an infinite loop

        text_string db 'Mao Mao Loader version 0.01'

write_string:                   ; output string located in si
    mov ah, 0xE                 ; the 'print char' function of int 0x10
.repeat:                
    lodsb                       ; get character from the string
    cmp al, 0                   ; check if it is zero   
    je .done                    ; if it is, jump to .done and finish the function
    int 10h                     ; call interrupt 10h    
    jmp .repeat                 ; repeat for every char in the string
.done:                  
    ret

set_bg:
    mov ah, 0x0B                ; set up function 'change bg' of int 0x10
    mov bh, 0x00                ; set up function 'change bg' of int 0x10
    mov bl, 0x1                 ; move the colour 0x1 (blue) to bl register (bl is where wikipedia tells us to store the colour)
    jmp .done                   ; jump to 'done'
.done:
    nop

    times 510-($-$$) db 0       ; pad boot sector with zeroes
    dw 0xAA55                   ; standard bootsig
    hlt

;TODO: read key pressed, change background colour and start writing kernel

1 个答案:

答案 0 :(得分:0)

Registration

您必须调用 set_bg: mov ah, 0x0B ; set up function 'change bg' of int 0x10 mov bh, 0x00 ; set up function 'change bg' of int 0x10 mov bl, 0x1 ; move the colour 0x1 (blue) to bl register ; CHANGE HERE int 0x10 ; you have to call the interrupt only then it ; would come to work jmp .done ; jump to 'done' .done: nop times 510-($-$$) db 0 ; pad boot sector with zeroes dw 0xAA55 ; standard bootsig hlt ;TODO: read key pressed, change background colour and start writing kernel 0x10 中断来更改背景颜色。