flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Examples and Tutorials > Asserting A20 in protected mode

Author
Thread Post new topic Reply to topic
TightCoderEx



Joined: 14 Feb 2013
Posts: 52
Location: Alberta

Asserting A20 in protected mode

My boot loader has passed control to second stage in protected mode. This example shows how to determine if A20 is on or not, by probing memory. I will eventually use color saved @ [A20_STATUS]. Colors conform to BIOS/DOS color mapping.

Code:
  Test_A20:

    ; Now we can turn A20 on. Point to a pair of locations where wrap around can be determined.

        mov     esi0x7d2c             ; Point to any volatile place in boot sector
        mov     ediesi
        bts     edi20                 ; Point to same address in next meg of memory

    ; Procedure will set of 4 colors.

    ;    (1) Green, A20 was already on
    ;    (2) Yellow, Fast A20 gate succeeded, but took ECX times
    ;    (3) Brown, A20 activated using fast method
    ;    (4) Red, couldn't turn on A20 so alternate method must be implemented

        mov     dlGREEN               ; Assume A20 is already.
        or      ecx, -1                 ; Large retry count, but probably won't be needed.

    ; Will loop back to here until retry count in ECX is exhausted.

  .Retry:
        push    esi
        push    edi
        lodsd                           ; Read dword from boot sector
        not     eax                     ; Invert 32 bits
        stosd                           ; Write back
        cmp     [esi - 4], eax          ; Are they the same
        pop     esi
        pop     edi
        jnz     .Ok                     ; ZF = 1, A20 is already on. Probably in BOCHS.

    ; Set color to YELLOW indicating gate was not active, but this method succeeded.

        mov     dlYELLOW
        in      alA20_GATE
        or      al2
        out     A20_GATEal
        dec     ecx
        jnz     .Retry

    ; *** TO DO ***
    ; This is where an alternate method would be implemented, but all my test computers
    ; succeeded with this method, so I'll assume most others will work too.

        mov     dlRED                 ; All methods will fall through to here if they fail.
        jmp     @F

   .Okinc     ecx                     ; Bump ECX. It will be NULL if gate was already on
        jz      @F

    ; We will always get to this point unless in BOCHS or another emulator where A20 is
    ; already on. If method only needed to be used once, color will not be changed

        not     ecx                     ; Indicates actual number of retries
        or      ecxecx
        jz      @F                      ; Don't change if we only tried Fast A20 gate once.

        mov     dlBROWN               ; Indicates there were retrys with fast method

    @@mov     [A20_STATUS], dl        ; Write status of operation to scatch area

Post 29 Sep 2015, 17:00
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >

Forum Rules:
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 vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2017, Tomasz Grysztar.