Bare metal: simplify logic for creating page table entries

(partly reverts 577c0f6226)

It turns out that I can address the physical addresses [0, 0x200000 - 1] via
the virtual addresses [BANE, BANE + 0x200000 - 1], even within
__get_virtual( ), rather than having to go through VAs [0, 0x200000 - 1].

This is because the [BANE, ...] mapping had already been created earlier by
the pinit routine in ape.S.
This commit is contained in:
tkchia 2022-09-12 05:25:10 +00:00
parent d94c373484
commit ae3f8612eb
2 changed files with 1 additions and 7 deletions

View file

@ -74,10 +74,7 @@ noasan textreal uint64_t *__get_virtual(struct mman *mm, uint64_t *t,
if (!(*e & PAGE_V)) { if (!(*e & PAGE_V)) {
if (!maketables) return NULL; if (!maketables) return NULL;
if (!(p = __new_page(mm))) return NULL; if (!(p = __new_page(mm))) return NULL;
if (mm->use_bane)
__clear_page(BANE + p); __clear_page(BANE + p);
else
__clear_page(p);
*e = p | PAGE_V | PAGE_RW; *e = p | PAGE_V | PAGE_RW;
} }
t = (uint64_t *)(BANE + (*e & PAGE_TA)); t = (uint64_t *)(BANE + (*e & PAGE_TA));
@ -127,12 +124,10 @@ static noasan textreal void __invert_memory(struct mman *mm, uint64_t *pml4t) {
*m = p | PAGE_V | PAGE_RW; *m = p | PAGE_V | PAGE_RW;
} }
} }
mm->use_bane = 1;
} }
} }
noasan textreal void __setup_mman(struct mman *mm, uint64_t *pml4t) { noasan textreal void __setup_mman(struct mman *mm, uint64_t *pml4t) {
mm->use_bane = 0;
__normalize_e820(mm); __normalize_e820(mm);
__invert_memory(mm, pml4t); __invert_memory(mm, pml4t);
} }

View file

@ -17,7 +17,6 @@ struct mman {
unsigned char pc_drive_last_head; /* 0x1d20 */ unsigned char pc_drive_last_head; /* 0x1d20 */
unsigned char pc_drive; /* 0x1d21 */ unsigned char pc_drive; /* 0x1d21 */
char bad_idt[6]; /* 0x1d22 */ char bad_idt[6]; /* 0x1d22 */
unsigned use_bane : 1, : 31; /* 0x1d28 */
}; };
COSMOPOLITAN_C_END_ COSMOPOLITAN_C_END_