1
0
Fork 0
mirror of https://github.com/hermitcore/libhermit.git synced 2025-03-09 00:00:03 +01:00

add the possibility to map more than 2 MB byte into the boot page table

- this feature is required for larger images
- however, the image should be smaller than 1020 MB (=510*2 MB)
This commit is contained in:
Stefan Lankes 2015-08-19 23:13:57 +02:00
parent 98a09ede87
commit fc790b44ca
2 changed files with 31 additions and 20 deletions

View file

@ -55,6 +55,7 @@ align 4
global possible_cpus
global timer_ticks
global current_boot_id
global image_size
base dq 0
limit dq 0
cpu_freq dd 0
@ -63,6 +64,25 @@ align 4
possible_cpus dd 0
timer_ticks dq 0
current_boot_id dd 0
dummy dd 0
image_size dq 0
; Bootstrap page tables are used during the initialization.
align 4096
boot_pml4:
DQ boot_pdpt + 0x7 ; PG_PRESENT | PG_RW | PG_USER
times 510 DQ 0 ; PAGE_MAP_ENTRIES - 2
DQ boot_pml4 + 0x203 ; PG_PRESENT | PG_RW | PG_SELF (self-reference)
boot_pdpt:
DQ boot_pgd + 0x7 ; PG_PRESENT | PG_RW | PG_USER
times 510 DQ 0 ; PAGE_MAP_ENTRIES - 2
DQ boot_pml4 + 0x203 ; PG_PRESENT | PG_RW | PG_SELF (self-reference)
boot_pgd:
DQ boot_pgt + 0x7 ; PG_PRESENT | PG_RW | PG_USER
times 510 DQ 0 ; PAGE_MAP_ENTRIES - 2
DQ boot_pml4 + 0x203 ; PG_PRESENT | PG_RW | PG_SELF (self-reference)
boot_pgt:
times 512 DQ 0
SECTION .text
align 4
@ -111,7 +131,14 @@ start64:
add rdi, boot_pgd
mov rax, [base]
or rax, 0x183
xor rcx, rcx
Lremap:
mov QWORD [rdi], rax
add rax, 0x200000
add rcx, 0x200000
add rdi, 8
cmp rcx, QWORD [image_size]
jb Lremap
Lno_pml4_init:
; Set CR3
@ -552,22 +579,5 @@ global boot_stack
boot_stack:
TIMES (MAX_CORES*KERNEL_STACK_SIZE) DB 0xcd
; Bootstrap page tables are used during the initialization.
align 4096
boot_pml4:
DQ boot_pdpt + 0x7 ; PG_PRESENT | PG_RW | PG_USER
times 510 DQ 0 ; PAGE_MAP_ENTRIES - 2
DQ boot_pml4 + 0x203 ; PG_PRESENT | PG_RW | PG_SELF (self-reference)
boot_pdpt:
DQ boot_pgd + 0x7 ; PG_PRESENT | PG_RW | PG_USER
times 510 DQ 0 ; PAGE_MAP_ENTRIES - 2
DQ boot_pml4 + 0x203 ; PG_PRESENT | PG_RW | PG_SELF (self-reference)
boot_pgd:
DQ boot_pgt + 0x7 ; PG_PRESENT | PG_RW | PG_USER
times 510 DQ 0 ; PAGE_MAP_ENTRIES - 2
DQ boot_pml4 + 0x203 ; PG_PRESENT | PG_RW | PG_SELF (self-reference)
boot_pgt:
times 512 DQ 0
; add some hints to the ELF file
SECTION .note.GNU-stack noalloc noexec nowrite progbits

View file

@ -36,6 +36,7 @@
extern uint64_t base;
extern uint64_t limit;
extern uint64_t image_size;
typedef struct free_list {
size_t start, end;
@ -201,7 +202,7 @@ int memory_init(void)
return ret;
}
kprintf("memory_init: base 0x%zx, limit 0x%zx\n", base, limit);
kprintf("memory_init: base 0x%zx, image_size 0x%zx, limit 0x%zx\n", base, image_size, limit);
// mark available memory as free
for(addr=base; addr<limit; addr+=PAGE_SIZE) {
@ -210,13 +211,13 @@ int memory_init(void)
}
// mark kernel as used, we use 2MB pages to map the kernel
for(addr=base; addr<((base + 0x200000ULL) & 0xFFFFFFFFFFE00000ULL); addr+=PAGE_SIZE) {
for(addr=base; addr<((base + image_size + 0x200000) & 0xFFFFFFFFFFE00000ULL); addr+=PAGE_SIZE) {
atomic_int64_inc(&total_allocated_pages);
atomic_int64_dec(&total_available_pages);
}
//initialize free list
init_list.start = (base + 0x200000ULL) & 0xFFFFFFFFFFE00000ULL;
init_list.start = (base + image_size + 0x200000) & 0xFFFFFFFFFFE00000ULL;
init_list.end = limit;
init_list.prev = init_list.next = NULL;