From 25b5eb6c783a76cbc0008f338211c5358890366d Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Wed, 15 Jan 2020 16:26:44 +0100 Subject: [PATCH] Cleanup in boot --- boot/loader/mem/management.inc | 39 ++++++++++++++-------------------- boot/loader/mem/structures.inc | 2 +- 2 files changed, 17 insertions(+), 24 deletions(-) diff --git a/boot/loader/mem/management.inc b/boot/loader/mem/management.inc index dc67950..961478f 100644 --- a/boot/loader/mem/management.inc +++ b/boot/loader/mem/management.inc @@ -23,43 +23,36 @@ ; along with OS/K. If not, see . ; ;=----------------------------------------------------------------------------=; -%define MAX_MEMORY 1 ; GiB - [BITS 32] [section .text] ; ---------------------------------------------------------------------------- ; ; Constructor for the page tables in protected mode ; ; ---------------------------------------------------------------------------- ; Setup_paging: - ;; Map the first PML4 entry to PDP table + ;; Map first PML4 entry to PDP table mov eax, PDP_table - or eax, 1 << 1 | 1 << 0 ; present + writable + or eax, 0b11 ; Present + writable mov [PML4_table], eax - ;; Map the PDP entries to PD tables - mov ebx, PD_table ; start address - mov ecx, 0x0 ; counter variable -.map_pdp_table: - mov eax, ebx - or eax, 1 << 1 | 1 << 0 ; present + writable - mov [PDP_table + 8 * ecx], eax - inc ecx - add ebx, 4096 - cmp ecx, MAX_MEMORY ; PDP table is mapped if MAX_MEMORY - jne .map_pdp_table ; else map the next entry + ;; Map first PDP entry to PD table + mov eax, PD_table + or eax, 0b11 ; Present + writable + mov [PDP_table], eax - ;; Map each PD entry to a 'huge' 4MiB page + ;; Map each PD entry to a huge 2MiB page + mov ecx, 0 ; counter variable - mov ecx, 0x0 ; counter variable .map_pd_table: - ;; map ecx-th PD entry to a huge page that starts at address 4MiB*ecx - mov eax, 0x200000 + ;; Map ecx-th PD entry to a huge page that starts at address 2MiB*ecx + mov eax, 0x200000 ; 2MiB mul ecx ; start address of ecx-th page - or eax, 1 << 7 | 1 << 1 | 1 << 0 ; present + writable + huge - mov [PD_table + ecx * 8], eax - inc ecx - cmp ecx, 512 * MAX_MEMORY ; PD table is mapped if 512 + or eax, 0b10000011 ; present + writable + huge + mov [PD_table + ecx * 8], eax ; map ecx-th entry + + inc ecx ; increase counter + cmp ecx, 512 ; if counter == 512, the whole P2 table is mapped jne .map_pd_table ; else map the next entry + ret ; ---------------------------------------------------------------------------- ; diff --git a/boot/loader/mem/structures.inc b/boot/loader/mem/structures.inc index 590f651..ebed229 100644 --- a/boot/loader/mem/structures.inc +++ b/boot/loader/mem/structures.inc @@ -63,4 +63,4 @@ PML4_table: PDP_table: resb 4096 PD_table: - times MAX_MEMORY resb 4096 + resb 4096