Fix paging to completion.
More debug messages, some things are slightly broken. We can recover.
This commit is contained in:
parent
bd9f994648
commit
98f3786e8b
|
@ -35,6 +35,7 @@
|
|||
"$root/chroma/system/memory/abstract_allocator.c",
|
||||
"$root/chroma/system/memory/physmem.c",
|
||||
"$root/chroma/system/memory/paging.c",
|
||||
"$root/chroma/system/memory/liballoc.c",
|
||||
"$root/chroma/system/drivers/keyboard.c",
|
||||
"$root/chroma/system/drivers/elf.c"
|
||||
],
|
||||
|
|
|
@ -110,7 +110,7 @@
|
|||
|
||||
#define MMIO_REGION 0xFFFFFFFFF8000000ull // Cannot move!
|
||||
#define FB_REGION 0xFFFFFFFFFC000000ull // Cannot move!
|
||||
#define FB_PHYSICAL 0x00000000FD000000ull // Physical location of the Framebuffer
|
||||
#define FB_PHYSICAL (size_t) bootldr.fb_ptr // 0x00000000FD000000ull - Physical location of the Framebuffer
|
||||
#define KERNEL_REGION 0xFFFFFFFFFFE00000ull // -2MiB, from bootloader
|
||||
#define KERNEL_TEXT 0x0000000000002000ull // Offset of symbols from the kernel text
|
||||
|
||||
|
|
|
@ -22,7 +22,9 @@ int Main(void) {
|
|||
KernelAddressSpace = (address_space_t) {0};
|
||||
|
||||
SerialPrintf("\r\n[ boot] Booting Chroma..\r\n");
|
||||
SerialPrintf("[ boot] Bootloader data structure at 0x%p\r\n", (size_t) &bootldr);
|
||||
SerialPrintf("[ boot] Kernel loaded at 0x%p, ends at 0x%p, is %d bytes long.\r\n", KernelAddr, KernelEnd, KernelEnd - KernelAddr);
|
||||
SerialPrintf("[ boot] Framebuffer at 0x%p / 0x%p, is %dx%d, 0x%x bytes long.\r\n", bootldr.fb_ptr, (size_t) &fb, bootldr.fb_width, bootldr.fb_height, bootldr.fb_size);
|
||||
SerialPrintf("[ boot] Initrd is physically at 0x%p, and is %d bytes long.\r\n", bootldr.initrd_ptr, bootldr.initrd_size);
|
||||
SerialPrintf("[ boot] Initrd's header is 0x%p\r\n", FIXENDIAN32(*((volatile uint32_t*)(bootldr.initrd_ptr))));
|
||||
|
||||
|
@ -48,6 +50,10 @@ int Main(void) {
|
|||
|
||||
InitPaging();
|
||||
|
||||
InitPrint();
|
||||
|
||||
WriteString("Paging complete. System initialized.");
|
||||
|
||||
|
||||
for(;;) { }
|
||||
|
||||
|
|
|
@ -34,6 +34,14 @@ void InitPaging() {
|
|||
.PML4 = PhysAllocateZeroMem(4096)
|
||||
};
|
||||
|
||||
address_space_t BootloaderAddressSpace = (address_space_t) {
|
||||
.Lock = {0},
|
||||
.PML4 = (size_t*) ReadControlRegister(3)
|
||||
};
|
||||
|
||||
size_t AddressToFind = (size_t) &fb;
|
||||
size_t BootldrAddress = 0x8000;
|
||||
|
||||
SerialPrintf("[ Mem] Identity mapping the entirety of physical memory\r\n");
|
||||
|
||||
for(size_t i = 0; i < MemorySize / PAGE_SIZE; i++) {
|
||||
|
@ -43,15 +51,21 @@ void InitPaging() {
|
|||
// TODO: Map kernel mem
|
||||
}
|
||||
|
||||
SerialPrintf("[ Mem] Mapping 0x%x bytes of bootloader structure, starting at 0x%p\r\n", bootldr.size, BootldrAddress);
|
||||
for(size_t i = BootldrAddress; i < (BootldrAddress + bootldr.size); i += PAGE_SIZE)
|
||||
MapVirtualPageNoDirect(&KernelAddressSpace, i, KERNEL_REGION + (i - BootldrAddress), 0x3);
|
||||
|
||||
// This allows the code to actually run
|
||||
SerialPrintf("[ Mem] Mapping kernel\r\n");
|
||||
for(size_t i = KERNEL_PHYSICAL + KERNEL_TEXT; i < KERNEL_END; i += PAGE_SIZE)
|
||||
SerialPrintf("[ Mem] Mapping 0x%x bytes of kernel, starting at 0x%p\r\n", KernelEnd - KernelAddr, KERNEL_PHYSICAL + KERNEL_TEXT);
|
||||
for(size_t i = KERNEL_PHYSICAL + KERNEL_TEXT; i < (KernelEnd - KernelAddr) + KERNEL_PHYSICAL; i += PAGE_SIZE)
|
||||
MapVirtualPageNoDirect(&KernelAddressSpace, i, (i - KERNEL_PHYSICAL) + KERNEL_REGION, 0x3);
|
||||
|
||||
// This allows us to write to the screen
|
||||
SerialPrintf("[ Mem] Mapping framebuffer\r\n");
|
||||
for(size_t i = FB_PHYSICAL; i < bootldr.fb_size + FB_PHYSICAL; i += PAGE_SIZE)
|
||||
MapVirtualPageNoDirect(&KernelAddressSpace, i, (i - FB_PHYSICAL) + FB_REGION, 0x3);
|
||||
SerialPrintf("[ Mem] Mapping 0x%x bytes of framebuffer, starting at 0x%p\r\n", bootldr.fb_size, FB_PHYSICAL);
|
||||
for(size_t i = FB_PHYSICAL; i < bootldr.fb_size + FB_PHYSICAL; i += PAGE_SIZE) {
|
||||
MapVirtualPageNoDirect(&KernelAddressSpace, i, i, 0x3); // FD000000 + (page)
|
||||
MapVirtualPageNoDirect(&KernelAddressSpace, i, (i - FB_PHYSICAL) + FB_REGION, 0x3); // FFFFFFFFFC000000 + (page)
|
||||
}
|
||||
|
||||
// This allows us to call functions
|
||||
SerialPrintf("[ Mem] Mapping stack\r\n");
|
||||
|
@ -59,16 +73,12 @@ void InitPaging() {
|
|||
|
||||
// Make sure everything is sane
|
||||
SerialPrintf("[ Mem] Diagnostic: Querying existing page tables\r\n");
|
||||
address_space_t BootloaderAddressSpace = (address_space_t) {
|
||||
.Lock = {0},
|
||||
.PML4 = (size_t*) ReadControlRegister(3)
|
||||
};
|
||||
|
||||
size_t AddressToFind = 0xffffffffffffff58;
|
||||
AddressToFind = (size_t) &(bootldr);
|
||||
size_t BootloaderAddress = DecodeVirtualAddressNoDirect(&BootloaderAddressSpace, AddressToFind);
|
||||
size_t KernelDisoveredAddress = DecodeVirtualAddressNoDirect(&KernelAddressSpace, AddressToFind);
|
||||
SerialPrintf("[ Mem] Diagnostic: Existing pagetables put 0x%p at 0x%p.\r\n", AddressToFind, BootloaderAddress);
|
||||
SerialPrintf("[ Mem] Diagnostic: Our pagetables put 0x%p at 0x%p.\r\n", AddressToFind, KernelDisoveredAddress);
|
||||
SerialPrintf("[ Mem] Diagnostic: Existing pagetables put 0x%p at 0x%p + 0x%p.\r\n", AddressToFind, BootloaderAddress, AddressToFind & ~STACK_TOP);
|
||||
SerialPrintf("[ Mem] Diagnostic: Our pagetables put 0x%p at 0x%p + 0x%p.\r\n", AddressToFind, KernelDisoveredAddress, AddressToFind & ~STACK_TOP);
|
||||
SerialPrintf("[ Mem] %s\r\n", BootloaderAddress == KernelDisoveredAddress ? "These match. Continuing." : "These do not match. Continuing with caution..");
|
||||
|
||||
//if(BootloaderAddress != KernelDisoveredAddress)
|
||||
|
@ -77,7 +87,6 @@ void InitPaging() {
|
|||
SerialPrintf("[ Mem] Attempting to jump into our new pagetables: 0x%p\r\n", (size_t) KernelAddressSpace.PML4);
|
||||
WriteControlRegister(3, (size_t) KernelAddressSpace.PML4 & STACK_TOP);
|
||||
SerialPrintf("[ Mem] Worked\r\n");
|
||||
for(;;) {}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ typedef struct {
|
|||
uint32_t scrlMode;
|
||||
} PRINTINFO;
|
||||
|
||||
PRINTINFO PrintInfo = {0};
|
||||
static PRINTINFO PrintInfo = {0};
|
||||
|
||||
void InitPrint() {
|
||||
PrintInfo.charHeight = 8;
|
||||
|
|
Loading…
Reference in New Issue
Block a user