1

我制作了应该与 vmem 一起使用的驱动程序,但它不起作用。我认为错误是我用来指向内存的寄存器。

有驱动代码:

;;;;;;; Primary Video Driver
PVideo:
                .treadbyte:    ; in:eax=ID, [0 - 3440]; out:cl=BYTE [0 - 255]
                        push eax ebx
                        mov ebx, 0xb8000
                        imul eax, 2
                        inc eax
                        add ebx, eax
                        mov cl, byte[ebx]
                        pop eax ebx di
                        ret
                .treadattr:    ; in:eax=ID, [0 - 3440]; out:cl=BYTE [0 - 255]
                        push eax ebx
                        mov ebx, 0xb8000
                        imul eax, 2
                        add ebx, eax
                        mov cl, byte[ebx]
                        pop eax ebx
                        ret
                .twritebyte:   ; in:eax=ID, [0 - 3440]/dl=BYTE, [0 - 255]; out:none
                        push eax ebx
                        mov ebx, 0xb8000
                        imul eax, 2
                        inc ax
                        add ebx, eax
                        mov byte[ebx], dl
                        pop eax ebx
                        ret
                .twriteattr:   ; in:eax=ID, [0 - 3440]/dl=BYTE, [0 - 255]; out:none
                        push eax ebx
                        mov ebx, 0xb8000
                        imul eax, 2
                        add ebx, eax
                        mov byte[ebx], dl
                        pop eax ebx
                        ret
                .twritezs:     ; in:eax=POS, [0 - 3440-len(ZS)]/si=ZS, offset[0 - 32512]/dl=BYTE; out:none
                        push eax ebx
                        mov ebx, 0xb8000
                        ;imul eax, 2
                        ;inc eax
                        add ebx, eax
                    .l:
                        lodsb
                        cmp al, 0x00
                        je .ret
                        mov byte[ebx], dl
                        inc ebx
                        mov byte[ebx], al
                        inc ebx
                        jmp .l
                    .ret:
                        pop eax ebx
                        ret

我正在分析代码,但找不到任何错误。

PS:我只测试了 .twritezs 功能,也许另一个也不起作用。

4

1 回答 1

0

这些是代码片段中的错误:

  • push在堆栈中的所有内容都需要以相反的顺序退出(如果使用pop)。
  • 在 0x000B8000 的视频内存中,字符代码(ASCII)进入偶数地址的字节,颜色代码(属性)进入奇数地址的字节。
    push eax ebx
    lea  ebx, [0x000B8000 + eax]
    mov  ah, dl      ; Attribute
  .next:
    lodsb            ; ASCII
    cmp  al, 0
    je   .ret
    mov  [ebx], ax   ; Store ASCII at even address and Attribute at next odd address
    add  ebx, 2
    jmp  .next
  .ret:
    pop  ebx eax
    ret

如果将 ASCII(在偶数地址)和属性(在下一个奇数地址)存储在一条指令中,则可以更快地获取.twritezs代码。
请注意(E)SI已修改。你没有push


目前尚不清楚为什么要乘以 2,EAX即其他代码片段中的值。EAX就像在.twritezs代码中一样,视频缓冲区中的偏移量不是已经准备好了吗?

于 2021-11-16T01:57:44.683 回答