Skip to content

Commit d866398

Browse files
committed
Enable A20 at bootloader stage 2
1 parent 7d7c367 commit d866398

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ binaries: $(bt_stage1) $(bt_stage2) $(kernel_core) $(rm_static)
101101
# Note: Relying on default value doesn't guarantee bin size.
102102
SECTOR_COUNT_BT_STAGE1 = 1
103103
SECTOR_COUNT_SHARED_LIBRARY = 1
104-
SECTOR_COUNT_BT_STAGE2 = 11
104+
SECTOR_COUNT_BT_STAGE2 = 12
105105
SECTOR_COUNT_KERNEL = 47
106106

107107
SECTOR_START_BT_STAGE1 = 0

src/bootloader/stage2.asm

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ extern entry_stage
88
extern gdtr
99
global enter_protected_mode
1010
global label_exit
11+
global call_int_0x15
1112

1213
[SECTION .text]
1314
mov eax, 0x0
@@ -43,6 +44,16 @@ global label_exit
4344
HLT
4445
JMP label_exit
4546

47+
call_int_0x15:
48+
push ebp
49+
mov ebp, esp
50+
51+
mov ax, [ebp+0x08]
52+
int 0x15
53+
54+
pop ebp
55+
ret
56+
4657

4758
[SECTION .data]
4859
bl_stage_2 db "Bootloader: Stage 2"

src/bootloader/stage2.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,30 @@ char DIGIT_TO_HEX[] = "0123456789ABCDEF";
1616

1717
extern void enter_protected_mode();
1818
extern void label_exit();
19+
extern unsigned short call_int_0x15(unsigned short ax);
20+
21+
void enable_a20() {
22+
int ax;
23+
ax = call_int_0x15(0x2403);
24+
if (!ax) {
25+
print_log("BIOS A20-gate not supported");
26+
label_exit();
27+
}
28+
29+
ax = call_int_0x15(0x2402);
30+
if (ax==1) {
31+
print_log("BIOS A20-gate already enabled");
32+
return;
33+
}
34+
35+
ax = call_int_0x15(0x2401);
36+
if (!ax) {
37+
print_log("BIOS A20-gate enabling attempt failed");
38+
label_exit();
39+
}
40+
41+
print_log("BIOS A20-gate enabled");
42+
}
1943

2044
char *get_memdump_8byte(void *address) {
2145
static char shared_memdump[17];
@@ -62,6 +86,7 @@ void entry_stage() {
6286
load_static_library();
6387
load_kernel();
6488

89+
enable_a20();
6590
populate_gdt_table(&gdtr, gdt_table, GDT_TABLE_SIZE, 0);
6691

6792
// Enter_protected_mode never returns.

0 commit comments

Comments
 (0)