mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-03 11:12:27 +00:00
[WIP] Get bare metal working outside of an emulator (#609)
You can now run bare metal on bare metal!
* Fix handling of int 0x15 eax = 0xe820 memory map
* Fix some issues in initial page table creation
* hello4.com now works outside emulators
* Ensure area for identity page tables are zeroed first
* Simplify logic for creating page table entries, this partly
reverts 577c0f6226
* Add degenerate MBR partition entry, to ease testing
Co-authored-by: tkchia <tkchia-cosmo@gmx.com>
This commit is contained in:
parent
c03359c637
commit
116bda997e
3 changed files with 55 additions and 35 deletions
|
@ -74,6 +74,7 @@ noasan textreal uint64_t *__get_virtual(struct mman *mm, uint64_t *t,
|
|||
if (!(*e & PAGE_V)) {
|
||||
if (!maketables) return NULL;
|
||||
if (!(p = __new_page(mm))) return NULL;
|
||||
__clear_page(BANE + p);
|
||||
*e = p | PAGE_V | PAGE_RW;
|
||||
}
|
||||
t = (uint64_t *)(BANE + (*e & PAGE_TA));
|
||||
|
@ -117,7 +118,7 @@ static noasan textreal void __invert_memory(struct mman *mm, uint64_t *pml4t) {
|
|||
uint64_t i, j, *m, p, pe;
|
||||
for (i = 0; i < mm->e820n; ++i) {
|
||||
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);
|
||||
if (m && !(*m & PAGE_V)) {
|
||||
*m = p | PAGE_V | PAGE_RW;
|
||||
|
@ -150,7 +151,7 @@ noasan textreal void __map_phdrs(struct mman *mm, uint64_t *pml4t, uint64_t b) {
|
|||
v = b + p->p_offset + i;
|
||||
m = MAX(m, v);
|
||||
} 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;
|
||||
}
|
||||
|
|
|
@ -7,16 +7,16 @@ COSMOPOLITAN_C_START_
|
|||
struct mman {
|
||||
int64_t pdp; /* 0x0500 */
|
||||
int32_t pdpi; /* 0x0508 */
|
||||
int32_t e820n; /* 0x050a */
|
||||
int32_t e820n; /* 0x050c */
|
||||
struct SmapEntry e820[256]; /* 0x0510 */
|
||||
char pc_drive_base_table[11]; /* 0x1510 */
|
||||
unsigned char pc_drive_type; /* 0x151b */
|
||||
unsigned char pc_drive_last_sector; /* 0x151c */
|
||||
unsigned short pc_drive_last_cylinder; /* 0x151d */
|
||||
unsigned char pc_drives_attached; /* 0x151f */
|
||||
unsigned char pc_drive_last_head; /* 0x1520 */
|
||||
unsigned char pc_drive; /* 0x1521 */
|
||||
char bad_idt[6]; /* 0x1522 */
|
||||
char pc_drive_base_table[11]; /* 0x1d10 */
|
||||
unsigned char pc_drive_type; /* 0x1d1b */
|
||||
unsigned char pc_drive_last_sector; /* 0x1d1c */
|
||||
unsigned short pc_drive_last_cylinder; /* 0x1d1d */
|
||||
unsigned char pc_drives_attached; /* 0x1d1f */
|
||||
unsigned char pc_drive_last_head; /* 0x1d20 */
|
||||
unsigned char pc_drive; /* 0x1d21 */
|
||||
char bad_idt[6]; /* 0x1d22 */
|
||||
};
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue