Nyanix

Bootloader
Log | Files | Refs | LICENSE

a20gate.s (2084B)


      1 ; =========================================================================== ;
      2 ; /boot_early/a20gate.s                                                       ;
      3 ; Copyright (C) 2018, k4m1 <k4m1@protonmail.com>                              ;
      4 ; See /LICENSE for full license text.                                         ;
      5 ;                                                                             ;
      6 ; This file provides functionality for checking the status of a20 gate, and   ;
      7 ; toggling the a20 gate.                                                      ;
      8 ; =========================================================================== ;
      9 
     10 [ BITS 16 ]
     11 
     12 
     13 %ifndef __a20_gate_h__
     14 %define __a20_gate_h__ 1
     15 
     16 a20wait:
     17 	in	al, 0x64
     18 	cmp	bl, 1
     19 	jne	.a20wait2
     20 	test	al, 2
     21 	jnz	a20wait
     22 	ret
     23 	.a20wait2:
     24 		test	al, 1
     25 		jz	a20wait
     26 		ret
     27 
     28 ; Check A20 line
     29 ; Returns to caller if A20 gate is cleared.
     30 ; Continues to A20_on if A20 line is set.
     31 ; Written by Elad Ashkcenazi 
     32 check_a20gate:
     33 	xor	eax, eax
     34 	pushad
     35 	mov	esi, 0x012345
     36 	mov	edi, 0x112345
     37 	mov	[esi], esi
     38 	mov	[edi], edi
     39 	cmpsd
     40 	popad
     41 	jne	.a20_isenabled 
     42 	ret
     43 .a20_isenabled:
     44 	inc 	eax
     45 	ret
     46 
     47 ; =========================================================================== ;
     48 ; This function is used for togglin the a20 gate.                             ;
     49 ; Not returning anythin, nor requiring arguments.                             ;
     50 ; =========================================================================== ; 
     51 toggle_a20_status:
     52         cli
     53  
     54 	mov	bl, 1
     55         call    a20wait
     56         mov     al,0xAD
     57         out     0x64,al
     58  
     59 	mov	bl, 1
     60         call    a20wait
     61         mov     al,0xD0
     62         out     0x64,al
     63  
     64 	mov	bl, 2
     65         call    a20wait
     66         in      al,0x60
     67         push    eax
     68  
     69 	mov	bl, 1
     70         call    a20wait
     71         mov     al,0xD1
     72         out     0x64,al
     73  
     74 	mov	bl, 1
     75         call    a20wait
     76         pop     eax
     77         or      al,2
     78         out     0x60,al
     79  
     80 	mov	bl, 1
     81         call    a20wait
     82         mov     al,0xAE
     83         out     0x64,al
     84  
     85 	mov	bl, 1
     86         call    a20wait
     87         sti
     88         ret
     89  
     90 %endif