在 32 位保护模式下启用 A20 行的问题

Problems enabling A20 line in 32 bit protected mode

我写了一个简单的引导加载程序,我在其中实现了从实模式到保护模式的切换。 我想启用 A20 地址线。 这是我的代码(不正确):

EnableA20:
        .try0:
                call .checkenabled
                cmp eax,0
                jne .done
        .fail:
                jmp $

        .checkenabled:
                push ebx
                mov eax,0x1234
                mov [0x10],eax
                mov ebx,[0x100010]
                sub eax,ebx
                pop ebx
                ret

.done:

这说明我的地址栏是默认启用的...这可能吗??

我哪里做错了?我使用的方法是将 0x1234 写入地址 0x10,然后从地址 0x100010 读取值。如果我写入的值与地址中存在的值相同(由于回绕),我知道不应启用该行。

我正在使用 qemu 作为我的模拟器:

qemu-system-i386 myos.bin

编辑:似乎默认启用了 A20。但是,如果我尝试这样做:

       .try1:  ;Using keyboard controller to enable A20
                mov al,0xdd
                out 0x64,al
                call .checkenabled
                cmp eax,0
                jne .done

失败了!我读过将 0xdd 移动到端口 0x64 会启用 A20,但不会禁用它。这里有什么问题?

根据 osdev wiki,在保护模式下启用 A20 线路的方法因芯片组而异。在某些情况下,它甚至可以在启动时通过 bios/bootrom 启用。因此,通常的做法是首先编写一个例程来检查 A20 行是否已启用(通过将数据写入可访问的 ram 区域并查找要在更高 ram 地址中镜像的数据)你所做的,你的方法似乎是正确的据我所知。只有在 bios/bootrom 没有启用的情况下才尝试其他方法。

When your PC boots, the A20 gate is always disabled, but some BIOSes do enable it for you, as do some high-memory managers (HIMEM.SYS) or bootloaders (GRUB). Once you have this check, you can then try all the methods foi wnabling it one by one and see which one works for the system

推荐的启用程序是:

Because there are several different methods that may or may not be supported, and because some of them cause problems on some computers; the recommended method is to try all of them until one works in the "order of least risk". Essentially:

Test if A20 is already enabled - if it is you don't need to do anything at all
Try the BIOS function. Ignore the returned status.
Test if A20 is enabled (to see if the BIOS function actually worked or not)
Try the keyboard controller method.
Test if A20 is enabled in a loop with a time-out (as the keyboard controller method may work slowly)
Try the Fast A20 method last
Test if A20 is enabled in a loop with a time-out (as the fast A20 method may work slowly)
If none of the above worked, give up

有关详细信息,请参阅 osdev wiki 上的 A20 行页面: https://wiki.osdev.org/A20