summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichal Idziorek <m.i@gmx.at>2014-08-29 15:20:17 +0200
committerMichal Idziorek <m.i@gmx.at>2014-08-29 15:20:17 +0200
commit659f1f1ae057c82a154a1fd32cc9dca040979daa (patch)
tree41afd3afb1b3e29ea6bf8445e1a7b284e7043368
parent1cb4a8a202023958589d563ad132d701e27c008a (diff)
experimenting with a20 gate
-rw-r--r--boot/check_a20_16.asm61
-rw-r--r--boot/mbr.asm28
-rw-r--r--kernel/kernel.c12
3 files changed, 91 insertions, 10 deletions
diff --git a/boot/check_a20_16.asm b/boot/check_a20_16.asm
new file mode 100644
index 0000000..43da6e3
--- /dev/null
+++ b/boot/check_a20_16.asm
@@ -0,0 +1,61 @@
+; The following code is public domain licensed
+
+[bits 16]
+
+; Function: check_a20
+;
+; Purpose: to check the status of the a20 line in a completely self-contained state-preserving way.
+; The function can be modified as necessary by removing push's at the beginning and their
+; respective pop's at the end if complete self-containment is not required.
+;
+; Returns: 0 in ax if the a20 line is disabled (memory wraps around)
+; 1 in ax if the a20 line is enabled (memory does not wrap around)
+
+check_a20:
+ pushf
+ push ds
+ push es
+ push di
+ push si
+
+ cli
+
+ 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
+
+ mov ax, 0
+ je check_a20__exit
+
+ mov ax, 1
+
+check_a20__exit:
+ pop si
+ pop di
+ pop es
+ pop ds
+ popf
+
+ ret
diff --git a/boot/mbr.asm b/boot/mbr.asm
index 26d13bf..4dd82d1 100644
--- a/boot/mbr.asm
+++ b/boot/mbr.asm
@@ -56,20 +56,23 @@ jmp boot_16 ;start boot process
BOOT_DRIVE:
db 0xff
STR_VERSION:
- db "Fool Boot Loader v0.3.1~",0
+ db "v0.3.1~",0
VESA_CHECK1:
- db " VESA: Get Info.",0
+ db " V1.",0
VESA_CHECK2:
- db " VESA: Get Mode Info.",0
+ db " V2",0
VESA_CHECK3:
- db " VESA: Set Mode.",0
+ db " V2",0
+CHECK_A20:
+ db " A20",0
;lets put our temporary GDT (Global Descriptor Table) here
;kernel should move this away
%include "boot/GDT.asm"
-;include 16-bit real mode routines (print_string, disk_load, vesa_setup)
+;include 16-bit real mode routines (print_string, disk_load, vesa_setup,check_a20)
%include "boot/disk_load_16.asm"
+%include "boot/check_a20_16.asm"
%include "boot/print_string_16.asm"
%include "boot/vesa_setup_16.asm"
@@ -112,6 +115,15 @@ boot_16:
call BiosGetMemoryMap ; this will also put the number of entries
; of the memory map at MEMMAP_SIZE_OFFSET
+a20check:
+
+ mov bx, STR_VERSION
+ call print_string
+
+ call check_a20
+ cmp ax,0
+ je a20check ;hang if a20 is disabled!
+
;VESA: also setup vesa stuff before entering 32 bit protected mode
call VesaSetup
@@ -127,9 +139,11 @@ boot_32_pm:
;enable A20
;http://www.brokenthorn.com/Resources/OSDev9.html
;Method 3.1: Enables A20 through keyboard controller
+ ;Not all keyboard controllers support this
;todo: check if this has any effect at all !?!?
- mov al, 0xdd ; command 0xdd: enable a20
- out 0x64, al ; send command to controller
+ ;mov al, 0xdd ; command 0xdd: enable a20
+ ;mov al, 0xdf ; command 0xdf: disable a20
+ ;out 0x64, al ; send command to controller
;pic setup
call pic_setup
diff --git a/kernel/kernel.c b/kernel/kernel.c
index 3296b37..7d9b848 100644
--- a/kernel/kernel.c
+++ b/kernel/kernel.c
@@ -102,12 +102,18 @@ void kernel_main()
//init shell
shell_init();
+ /*
-/*
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"test mem");
- uint8_t *memtest=0x1fffffff;
+
+ // test a20 disabled / wrap
+ uint8_t *memtest=0x0;
+ uint8_t *memtest2=0b10000000000000000000;
+
*memtest=0xaf;
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"test mem %x",*memtest);
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"test mem %x",*(memtest2-1));
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"test mem %x",*memtest2);
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"test mem %x",*(memtest2+1));
*/