Correction of the mapping that sucked

This commit is contained in:
Adrien Bourmault 2019-03-28 10:34:18 +01:00
parent 58754a32af
commit c49941df7c
3 changed files with 32 additions and 11 deletions

View File

@ -36,18 +36,20 @@ Setup_paging:
or eax, 1 << 1 | 1 << 0 ; present + writable or eax, 1 << 1 | 1 << 0 ; present + writable
mov [PML4_table], eax mov [PML4_table], eax
;; Map the first PDP entries to PD table ;; Map the PDP entries to PD tables
mov ecx, 0x0 mov ebx, PD_table ; start address
mov eax, PD_table mov ecx, 0x0 ; counter variable
.map_pdp_table: .map_pdp_table:
mov eax, ebx
or eax, 1 << 1 | 1 << 0 ; present + writable or eax, 1 << 1 | 1 << 0 ; present + writable
mov [PDP_table + ecx * 8], eax mov [PDP_table + 8 * ecx], eax
add eax, 8
inc ecx inc ecx
cmp ecx, MAX_MEMORY add ebx, 4096
jne .map_pdp_table cmp ecx, MAX_MEMORY ; PDP table is mapped if MAX_MEMORY
jne .map_pdp_table ; else map the next entry
;; Map each PD entry to a 'huge' 2MiB page ;; Map each PD entry to a 'huge' 2MiB page
mov ecx, 0x0 ; counter variable mov ecx, 0x0 ; counter variable
.map_pd_table: .map_pd_table:
;; map ecx-th PD entry to a huge page that starts at address 2MiB*ecx ;; map ecx-th PD entry to a huge page that starts at address 2MiB*ecx
@ -59,8 +61,6 @@ Setup_paging:
cmp ecx, 512 * MAX_MEMORY ; PD table is mapped if 512 cmp ecx, 512 * MAX_MEMORY ; PD table is mapped if 512
jne .map_pd_table ; else map the next entry jne .map_pd_table ; else map the next entry
ret
; ---------------------------------------------------------------------------- ; ; ---------------------------------------------------------------------------- ;
; Enable long mode and paging ; ; Enable long mode and paging ;
; ---------------------------------------------------------------------------- ; ; ---------------------------------------------------------------------------- ;

View File

@ -59,4 +59,4 @@ PML4_table:
PDP_table: PDP_table:
resb 4096 resb 4096
PD_table: PD_table:
resb 4096 * MAX_MEMORY times MAX_MEMORY resb 4096

View File

@ -150,10 +150,31 @@ noreturn void BtStartKern(multiboot_info_t *mbInfo, int mbMagic)
//if(rc)KernLog("error\n"); //if(rc)KernLog("error\n");
//KernLog((char*)buf->buf); //KernLog((char*)buf->buf);
uchar *addr = (uchar *)(ullong)(1024*5*MB - 7); uchar *addr = (uchar *)(ullong)(10);
*addr = 2;
addr = (uchar *)(ullong)(1*GB+10);
*addr = 4;
addr = (uchar *)(ullong)(2*GB+10);
*addr = 9;
addr = (uchar *)(ullong)(4*GB + 10);
*addr = 16;
addr = (uchar *)(ullong)(10);
KernLog("Test, valeur autour de %p: %hhu\n", addr, *addr); KernLog("Test, valeur autour de %p: %hhu\n", addr, *addr);
addr = (uchar *)(ullong)(1*GB+10);
KernLog("Test, valeur autour de %p: %hhu\n", addr, *addr);
addr = (uchar *)(ullong)(2*GB+10);
KernLog("Test, valeur autour de %p: %hhu\n", addr, *addr);
addr = (uchar *)(ullong)(4*GB + 10);
KernLog("Test, valeur autour de %p: %hhu\n", addr, *addr);
// We're out // We're out
PsFiniSched(); PsFiniSched();
KeCrashSystem(); //yay KeCrashSystem(); //yay