OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 12:21 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Comments / improvement on the A20 Line wiki article
PostPosted: Fri Jul 18, 2014 9:14 am 
Offline

Joined: Fri Jul 18, 2014 8:11 am
Posts: 2
Location: France
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:
    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:
    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:


Top
 Profile  
 
 Post subject: Re: Comments / improvement on the A20 Line wiki article
PostPosted: Fri Jul 18, 2014 12:24 pm 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9301
Location: On the balcony, where I can actually keep 1½m distance
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 ]


Top
 Profile  
 
 Post subject: Re: Comments / improvement on the A20 Line wiki article
PostPosted: Fri Jul 18, 2014 3:22 pm 
Offline

Joined: Fri Jul 18, 2014 8:11 am
Posts: 2
Location: France
Well, yes, indeed, it turns out to be just a matter of taste. That message seemed more interesting before I actually posted it. :?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 21 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group