Comments / improvement on the A20 Line wiki article

All about the OSDev Wiki. Discussions about the organization and general structure of articles and how to use the wiki. Request changes here if you don't know how to use the wiki.
Post Reply
Magus
Posts: 2
Joined: Fri Jul 18, 2014 8:11 am
Location: France

Comments / improvement on the A20 Line wiki article

Post by Magus »

Hello,

I'm kind of new to this forum, but I've been reading it for a couple of weeks now and started doing a bit of OS development.
I have a (very small) concern about the A20 Line article, more specifically the part about testing whether the A20 line is enabled (http://wiki.osdev.org/A20_Line#Testing_the_A20_line).

Let me quote the relevant part :

Code: Select all

    xor ax, ax ; ax = 0
    mov es, ax
 
    not ax ; ax = 0xFFFF
    mov ds, ax

    mov di, 0x0500
    mov si, 0x0510
 
    mov al, byte [es:di]
    push ax
 
    mov al, byte [ds:si]
    push ax
 
    mov byte [es:di], 0x00
    mov byte [ds:si], 0xFF
 
    cmp byte [es:di], 0xFF
 
    pop ax
    mov byte [ds:si], al
 
    pop ax
    mov byte [es:di], al
Basically, we save the bytes at [ds:di] and [es:di] by pushing them on the stack before overwriting them with 0x00 and 0xFF to test whether the memory wraps around. Now, what if the current stack pointer happens to point to somewhere around 0x500 ? Wouldn't there be a risk to overwrite it and defeat the purpose of saving the bytes ? Of course, there is the BDA just below 0x500, so it would be risky in the first place to have the stack so close. But anyways, I think it's not even necessary to use the stack here, we could just leave the values in ax, like this :

Code: Select all

    mov al, byte [es:di]
    mov ah, byte [ds:si]
 
    mov byte [es:di], 0x00
    mov byte [ds:si], 0xFF
 
    cmp byte [es:di], 0xFF
 
    mov byte [ds:si], ah
    mov byte [es:di], al
Do you think this would be a reasonable improvement ?

Yeah, lots of text for such a small detail, that's my frenchness talking :wink:
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Comments / improvement on the A20 Line wiki article

Post by Combuster »

Mainly, if the stack is actually undefined, it is your fault for not having it set before using other code (like this). Everybody here will point it out as a bug if the stack is not configured early in the bootloader.

As for the push/pop, that's probably the original author's taste.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Magus
Posts: 2
Joined: Fri Jul 18, 2014 8:11 am
Location: France

Re: Comments / improvement on the A20 Line wiki article

Post by Magus »

Well, yes, indeed, it turns out to be just a matter of taste. That message seemed more interesting before I actually posted it. :?
Post Reply