]> git.dujemihanovic.xyz Git - nameless-os.git/blob - boot/x86/stage3/e820.s
Compile stage3 in ELF format
[nameless-os.git] / boot / x86 / stage3 / e820.s
1 ; Code for getting the BIOS E820 memory map
2
3 bits 16
4 section .text
5
6 ; Return: ECX - number of entries, DI - pointer to map
7 get_e820_map:
8 push eax
9 push ebx
10 push edx
11 push esi
12 push es
13
14 xor ax, ax
15 mov es, ax
16 push dword 1
17 sub sp, 20
18 xor si, si
19 xor ebx, ebx
20 mov edx, 0x534d4150
21 mov eax, 0xe820
22 mov ecx, 24
23 mov di, sp
24 int 0x15
25 jc .no_e820
26 cmp eax, 0x534d4150
27 jne .unexpected
28 inc si
29 .loop:
30 push dword 1
31 sub sp, 20
32 mov di, sp
33 mov eax, 0xe820
34 mov ecx, 24
35 int 0x15
36 jc .carry_done
37 inc si
38 cmp ebx, 0
39 je .done
40 jmp .loop
41 .carry_done:
42 add sp, 24
43 .done:
44 movzx ecx, si
45 movzx edi, sp
46 mov ax, 24
47 mul si
48 add sp, ax
49 pop es
50 pop esi
51 pop edx
52 pop ebx
53 pop eax
54 ret
55 .no_e820:
56 print no_e820
57 hlt
58 jmp $-1
59 .unexpected
60 print e820_unexpected
61 call print_dword
62 hlt
63 jmp $-1
64
65 section .rodata
66 no_e820: db "BIOS does not support E820, cannot proceed!", 0xd, 0xa, 0
67 e820_unexpected: db "Unexpected value in EAX after getting map entry: expected SMAP, got ", 0