禁用尝试后,A20门已启用

发布于 2025-01-17 23:31:23 字数 1998 浏览 1 评论 0原文

我遇到了禁用(出于学习目的)A20门的问题。

这是我的引导加载程序代码:

onboot:
    xorw %ax, %ax
    movw %ax, %ds
    movw %ax, %es
    movw %ax, %ss   
    movw $0x7c00, %ax
    movw %ax, %bp
    movw %ax, %sp

    /* reading disk */
    xorw %bx, %bx
    movw %bx, %es
    movw $0x7e00, %bx
    movw $0x0201, %ax
    movw $0x0002, %cx
    movb $0x00, %dh
    int $0x13

    /* Disable a20 through bios */
    movw $0x2400, %ax
    int $0x15

    /* clear through keyboard controller */

    call clear_8042 

    movb $0xd1, %al
    outb %al, $0x64
    call clear_8042

    movb $0b11011101, %al /* bit 0 = reset, must be 1, 
                 bit 1 = a20 gate */
    outb %al, $0x60
    call clear_8042

    movb $0xff, %al
    outb %al, $0x64
    call clear_8042

    /* 0xffff0 + 0x7e0e = 0x107dfe*/
    movw $0xffff, %bx
    movw %bx, %es
    movw %es:0x7e0e, %dx

    pushw %dx
    call printhex
    addw $0x2, %sp
loop:
    jmp %cs:loop

clear_8042:
    pushw %ax
    in $0x64, %al
    test $2, %al
    jnz clear_8042
    popw %ax
    ret


.= onboot+510
.word 0xaa55 /* little endian will reverse */
printhex:
    pusha
    movw %sp, %bp
    
    movw 18(%bp), %dx
    movw $0x0404, %cx /* ch = nibbles count, cl = iterator */
printhex_loop:
    movw $0x0e0f, %ax   
    rol $4, %dx     /* dl = nibble to show */
    andb %dl, %al   /* take a copy of dl in lowwer al nibble */
    addb $0x90, %al /* if al is decimal nibble = 0x90 - 0x99 
            else               = 0x9A - 0x9F */ 
    daa     /* if decimal = 0x90 - 0x99
            else 0x0 - 0x5 w/ CF    */
    adc $0x40, %al /* if decimal = 0xD0 - 0xD9
            else 0x41 - 0x46    */
    daa     /*if decimal = 0x30 = 0x39
            else 0x41 - 0x46    */
    int $0x10
    dec %cl
    jnz printhex_loop
    popa
    ret

以下指令的输出

movw%es:0x7e0e,%dx

必须为0xAA55(如果禁用A20门),但是由于某些原因,它启用了A20 Gate(输出)(输出)是0x0000)。

我在做什么错?如您所见,我一直在尝试使用BIOS中断和KBC控制器禁用它。

使用Manjaro和Qemu,如果有所不同。

I've encountered a problem with disabling (for learning purpose) a20 gate.

Here is my bootloader code:

onboot:
    xorw %ax, %ax
    movw %ax, %ds
    movw %ax, %es
    movw %ax, %ss   
    movw $0x7c00, %ax
    movw %ax, %bp
    movw %ax, %sp

    /* reading disk */
    xorw %bx, %bx
    movw %bx, %es
    movw $0x7e00, %bx
    movw $0x0201, %ax
    movw $0x0002, %cx
    movb $0x00, %dh
    int $0x13

    /* Disable a20 through bios */
    movw $0x2400, %ax
    int $0x15

    /* clear through keyboard controller */

    call clear_8042 

    movb $0xd1, %al
    outb %al, $0x64
    call clear_8042

    movb $0b11011101, %al /* bit 0 = reset, must be 1, 
                 bit 1 = a20 gate */
    outb %al, $0x60
    call clear_8042

    movb $0xff, %al
    outb %al, $0x64
    call clear_8042

    /* 0xffff0 + 0x7e0e = 0x107dfe*/
    movw $0xffff, %bx
    movw %bx, %es
    movw %es:0x7e0e, %dx

    pushw %dx
    call printhex
    addw $0x2, %sp
loop:
    jmp %cs:loop

clear_8042:
    pushw %ax
    in $0x64, %al
    test $2, %al
    jnz clear_8042
    popw %ax
    ret


.= onboot+510
.word 0xaa55 /* little endian will reverse */
printhex:
    pusha
    movw %sp, %bp
    
    movw 18(%bp), %dx
    movw $0x0404, %cx /* ch = nibbles count, cl = iterator */
printhex_loop:
    movw $0x0e0f, %ax   
    rol $4, %dx     /* dl = nibble to show */
    andb %dl, %al   /* take a copy of dl in lowwer al nibble */
    addb $0x90, %al /* if al is decimal nibble = 0x90 - 0x99 
            else               = 0x9A - 0x9F */ 
    daa     /* if decimal = 0x90 - 0x99
            else 0x0 - 0x5 w/ CF    */
    adc $0x40, %al /* if decimal = 0xD0 - 0xD9
            else 0x41 - 0x46    */
    daa     /*if decimal = 0x30 = 0x39
            else 0x41 - 0x46    */
    int $0x10
    dec %cl
    jnz printhex_loop
    popa
    ret

The output from following instruction

movw %es:0x7e0e, %dx

must be 0xaa55 (if a20 gate is DISABLED), but for some reason it acts like a20 gate is enabled (output is 0x0000).

What am i doing wrong? I've been trying disabling it with bios interrupts, and kbc controller as you see.

Using manjaro and qemu, if makes difference.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文