Skip to content

Commit 02ae26c

Browse files
committed
setup, multiboot: add map_multiboot_areas() function
The multiboot provided memory is referenced after initial boot phase for information about available physical memory, kernel command line, etc. Add map_multiboot_areas() that explicitely maps multiboot areas into final page tables. This is needed to get rid of "Low memory" static mapping. Signed-off-by: Pawel Wieczorkiewicz <[email protected]>
1 parent a05a6da commit 02ae26c

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

arch/x86/boot/multiboot.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,33 @@ void init_multiboot(multiboot_info_t *mbi, const char **cmdline) {
8181
*cmdline = (const char *) _ptr(mbi->cmdline);
8282
}
8383

84+
void map_multiboot_areas(void) {
85+
paddr_t mbi = _paddr(multiboot_info);
86+
87+
vmap_4k(paddr_to_virt(mbi), paddr_to_mfn(mbi), L1_PROT_RO);
88+
kmap_4k(paddr_to_mfn(mbi), L1_PROT_RO);
89+
90+
if (has_mbi_flag(MULTIBOOT_INFO_MEM_MAP)) {
91+
paddr_t mmap_start = _paddr(multiboot_info->mmap_addr);
92+
paddr_t mmap_stop = mmap_start + _paddr(multiboot_info->mmap_length);
93+
94+
for (mfn_t mmap_mfn = paddr_to_mfn(mmap_start);
95+
mmap_mfn < paddr_to_mfn(mmap_stop); mmap_mfn++) {
96+
vmap_4k(mfn_to_virt(mmap_mfn), mmap_mfn, L1_PROT_RO);
97+
kmap_4k(mmap_mfn, L1_PROT_RO);
98+
}
99+
}
100+
101+
if (has_mbi_flag(MULTIBOOT_INFO_CMDLINE)) {
102+
paddr_t cmdline_start = _paddr(multiboot_info->cmdline);
103+
paddr_t cmdline_stop = cmdline_start + strlen((const char *) _ptr(cmdline_start));
104+
105+
for (mfn_t cmdline_mfn = paddr_to_mfn(cmdline_start);
106+
cmdline_mfn < paddr_to_mfn(cmdline_stop); cmdline_mfn++)
107+
kmap_4k(cmdline_mfn, L1_PROT_RO);
108+
}
109+
}
110+
84111
unsigned mbi_get_avail_memory_ranges_num(void) {
85112
unsigned num = 0;
86113

common/setup.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,9 @@ void __noreturn __text_init kernel_start(uint32_t multiboot_magic,
218218

219219
/* Setup final pagetables */
220220
init_pagetables();
221+
222+
map_multiboot_areas();
223+
221224
write_cr3(cr3.paddr);
222225
WRITE_SP(get_free_pages_top(PAGE_ORDER_2M, GFP_KERNEL));
223226
if (opt_debug)

include/multiboot.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ extern void init_multiboot(multiboot_info_t *mbi, const char **cmdline);
292292

293293
#include <mm/pmm.h>
294294
#include <page.h>
295+
extern void map_multiboot_areas(void);
295296
extern unsigned mbi_get_avail_memory_ranges_num(void);
296297
extern int mbi_get_avail_memory_range(unsigned index, addr_range_t *r);
297298
extern int mbi_get_memory_range(paddr_t pa, addr_range_t *r);

0 commit comments

Comments
 (0)