mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-03-03 07:29:23 +00:00
Bare metal: fix some issues in initial page table creation
hello4.com now works outside of an emulator.
This commit is contained in:
parent
816a71bfa0
commit
577c0f6226
2 changed files with 10 additions and 3 deletions
|
@ -74,6 +74,10 @@ 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);
|
||||||
|
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));
|
||||||
|
@ -117,16 +121,18 @@ static noasan textreal void __invert_memory(struct mman *mm, uint64_t *pml4t) {
|
||||||
uint64_t i, j, *m, p, pe;
|
uint64_t i, j, *m, p, pe;
|
||||||
for (i = 0; i < mm->e820n; ++i) {
|
for (i = 0; i < mm->e820n; ++i) {
|
||||||
for (p = mm->e820[i].addr, pe = mm->e820[i].addr + mm->e820[i].size;
|
for (p = mm->e820[i].addr, pe = mm->e820[i].addr + mm->e820[i].size;
|
||||||
p + 0x200000 < pe; p += 4096) {
|
p != pe + 0x200000; p += 4096) {
|
||||||
m = __get_virtual(mm, pml4t, BANE + p, true);
|
m = __get_virtual(mm, pml4t, BANE + p, true);
|
||||||
if (m && !(*m & PAGE_V)) {
|
if (m && !(*m & PAGE_V)) {
|
||||||
*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);
|
||||||
}
|
}
|
||||||
|
@ -150,7 +156,7 @@ noasan textreal void __map_phdrs(struct mman *mm, uint64_t *pml4t, uint64_t b) {
|
||||||
v = b + p->p_offset + i;
|
v = b + p->p_offset + i;
|
||||||
m = MAX(m, v);
|
m = MAX(m, v);
|
||||||
} else {
|
} else {
|
||||||
v = __clear_page(__new_page(mm));
|
v = __clear_page(BANE + __new_page(mm));
|
||||||
}
|
}
|
||||||
*__get_virtual(mm, pml4t, p->p_vaddr + i, true) = (v & PAGE_TA) | f;
|
*__get_virtual(mm, pml4t, p->p_vaddr + i, true) = (v & PAGE_TA) | f;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ COSMOPOLITAN_C_START_
|
||||||
struct mman {
|
struct mman {
|
||||||
int64_t pdp; /* 0x0500 */
|
int64_t pdp; /* 0x0500 */
|
||||||
int32_t pdpi; /* 0x0508 */
|
int32_t pdpi; /* 0x0508 */
|
||||||
int32_t e820n; /* 0x050a */
|
int32_t e820n; /* 0x050c */
|
||||||
struct SmapEntry e820[256]; /* 0x0510 */
|
struct SmapEntry e820[256]; /* 0x0510 */
|
||||||
char pc_drive_base_table[11]; /* 0x1d10 */
|
char pc_drive_base_table[11]; /* 0x1d10 */
|
||||||
unsigned char pc_drive_type; /* 0x1d1b */
|
unsigned char pc_drive_type; /* 0x1d1b */
|
||||||
|
@ -17,6 +17,7 @@ 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_
|
||||||
|
|
Loading…
Add table
Reference in a new issue