diff options
Diffstat (limited to 'stage2')
-rw-r--r-- | stage2/main.asm | 69 | ||||
-rw-r--r-- | stage2/paging.asm | 5 |
2 files changed, 68 insertions, 6 deletions
diff --git a/stage2/main.asm b/stage2/main.asm index 3cfb5d2..5027546 100644 --- a/stage2/main.asm +++ b/stage2/main.asm @@ -44,8 +44,69 @@ long_mode: mov gs, ax mov ss, ax - ; align stack - and rsp, ~(0x0f) - sub rsp, 8 + mov eax, [kernel_elf] + cmp eax, [.elf] + jne .fail - ; kernel begins here + mov r8, [kernel_elf+32] ; program header pos + add r8, kernel_elf + + movzx rbx, word[kernel_elf+54] ; program header size + movzx rdx, word[kernel_elf+56] ; num of program headers + +.header: + cmp rdx, 0 + je .start + + mov edi, [r8] ; type + cmp edi, 0 + je .next + + cmp edi, 1 + je .load + + cmp edi, 2 + je .fail + + cmp edi, 3 + je .fail + + jmp .next + +.load: + ; zero out the segment + mov al, 0 + mov rdi, [r8+16] + mov rcx, [r8+40] + rep stosb + + ; load from file + mov rdi, [r8+16] + mov rsi, [r8+8] + add rsi, kernel_elf + mov rcx, [r8+32] + rep movsb + +.next: + + add r8, rbx + dec rdx + jmp .header + +.start: + ; more stack space + mov rsp, 0x80000 + xor rbp, rbp + + ; ELF entry point + mov rax, [kernel_elf+24] + call rax + +.fail: + cli + hlt + jmp $ + +.elf: db 0x7f, "ELF" + +kernel_elf: diff --git a/stage2/paging.asm b/stage2/paging.asm index cedc1e9..cd6ea1c 100644 --- a/stage2/paging.asm +++ b/stage2/paging.asm @@ -8,13 +8,14 @@ paging: .clr_buf: mov byte[di], 0 inc di - cmp di, PAGETABLE+0x4000 + cmp di, PAGETABLE+0x5000 jne .clr_buf ; init 3 page map levels mov dword[PAGETABLE+0x0000], PAGETABLE+0x1003 mov dword[PAGETABLE+0x1000], PAGETABLE+0x2003 mov dword[PAGETABLE+0x2000], PAGETABLE+0x3003 + mov dword[PAGETABLE+0x2008], PAGETABLE+0x4003 ; fill up level 4 page map mov eax, 3 @@ -23,7 +24,7 @@ paging: mov [di], eax add di, 8 add eax, 0x1000 - cmp eax, 0x100000 + cmp eax, 0x200000 jb .build_pt ; enable paging and long mode |