Merge into main the new state of the operating system/kernel #1
15
source/kernel/Boot/Multiboot.S
Normal file
15
source/kernel/Boot/Multiboot.S
Normal file
@ -0,0 +1,15 @@
|
||||
/*
|
||||
* Multiboot
|
||||
*/
|
||||
.set ALIGN, 1<<0 /* align loaded modules on page boundaries */
|
||||
.set MEMINFO, 1<<1 /* provide memory map */
|
||||
.set FLAGS, ALIGN | MEMINFO /* this is the Multiboot 'flag' field */
|
||||
.set MAGIC, 0x1BADB002 /* 'magic number' lets bootloader find the header */
|
||||
.set CHECKSUM, -(MAGIC + FLAGS) /* checksum of above, to prove we are multiboot */
|
||||
|
||||
.section .multiboot.data, "aw"
|
||||
.align 4
|
||||
.long MAGIC
|
||||
.long FLAGS
|
||||
.long CHECKSUM
|
||||
|
@ -1,18 +1,4 @@
|
||||
/*
|
||||
* Multiboot
|
||||
*/
|
||||
.set ALIGN, 1<<0 /* align loaded modules on page boundaries */
|
||||
.set MEMINFO, 1<<1 /* provide memory map */
|
||||
.set FLAGS, ALIGN | MEMINFO /* this is the Multiboot 'flag' field */
|
||||
.set MAGIC, 0x1BADB002 /* 'magic number' lets bootloader find the header */
|
||||
.set CHECKSUM, -(MAGIC + FLAGS) /* checksum of above, to prove we are multiboot */
|
||||
|
||||
.section .multiboot.data, "aw"
|
||||
.align 4
|
||||
.long MAGIC
|
||||
.long FLAGS
|
||||
.long CHECKSUM
|
||||
|
||||
.include "./source/kernel/Boot/Multiboot.S"
|
||||
/*
|
||||
* Allocate initial stack
|
||||
*/
|
||||
@ -120,14 +106,8 @@ isPaging:
|
||||
pushl $0
|
||||
popf
|
||||
|
||||
|
||||
|
||||
call early_main
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cli
|
||||
1: hlt
|
||||
jmp 1b
|
||||
|
@ -5,6 +5,24 @@
|
||||
|
||||
extern "C" const uint32_t kernel_begin;
|
||||
extern "C" const uint32_t kernel_end;
|
||||
// Put the BootInfoBlock 1MB above the kernel.
|
||||
const uint32_t BootInfoBlock_pptr = (uint32_t)&kernel_end - 0xC0000000 + 0x1;
|
||||
const uint32_t MemoryMapHeap_pptr = BootInfoBlock_pptr + 0x1;
|
||||
|
||||
|
||||
#define IS_AVAILABLE_MEM(MEM_TYPE) MEM_TYPE & 0x1
|
||||
#define IS_ACPI_MEM(MEM_TYPE) MEM_TYPE & 0x2
|
||||
#define IS_RESERVED_MEM(MEM_TYPE) MEM_TYPE & 0x3
|
||||
#define IS_NVS_MEMORY(MEM_TYPE) MEM_TYPE & 0x8
|
||||
#define IS_BADRAM_MEMORY(MEM_TYPE) MEM_TYPE & 0x10
|
||||
|
||||
struct MemoryInfoBlock {
|
||||
uint32_t Base_addr ;
|
||||
uint32_t Memory_Size;
|
||||
MemoryInfoBlock* next;
|
||||
uint8_t type;
|
||||
|
||||
};
|
||||
struct BootInfoBlock {
|
||||
bool MapIsInvalid;
|
||||
uint32_t bootDeviceID ;
|
||||
@ -21,8 +39,7 @@ struct BootInfoBlock {
|
||||
bool EnabledVBE;
|
||||
|
||||
bool PhysicalMemoryMapAvailable;
|
||||
MemoryInfoBlock* MemoryMap;
|
||||
|
||||
};
|
||||
|
||||
// Put the BootInfoBlock 1MB above the kernel.
|
||||
const uint32_t BootInfoBlock_pptr = kernel_end - 0xC0000000 + 0x1000;
|
||||
|
@ -25,6 +25,8 @@ extern "C" void testLauncher ( unsigned long magic, multiboot_info_t* mbi) {
|
||||
if (CHECK_FLAG (mbi->flags, 1))
|
||||
{
|
||||
BIB->bootDeviceID = mbi->boot_device;
|
||||
} else{
|
||||
BIB->bootDeviceID = 0x11111111;
|
||||
}
|
||||
|
||||
/* Are mods_* valid? */
|
||||
@ -60,29 +62,51 @@ extern "C" void testLauncher ( unsigned long magic, multiboot_info_t* mbi) {
|
||||
BIB->ValidELFHeader = false;
|
||||
}
|
||||
/*
|
||||
If we got a memory map from our bootloader we
|
||||
should be parsing it to find out the memory regions available.
|
||||
*/
|
||||
if (CHECK_FLAG(mbi->flags, 6))
|
||||
{
|
||||
If we got a memory map from our bootloader we
|
||||
should be parsing it to find out the memory regions available.
|
||||
*/
|
||||
if (CHECK_FLAG(mbi->flags, 6))
|
||||
{
|
||||
BIB->PhysicalMemoryMapAvailable = true;
|
||||
BIB->MemoryMap = (MemoryInfoBlock*) MemoryMapHeap_pptr;
|
||||
multiboot_memory_map_t *mmap = (multiboot_memory_map_t*) (mbi->mmap_addr) ;
|
||||
auto MemoryMapEnd = mbi->mmap_addr + mbi->mmap_length;
|
||||
|
||||
for (; (unsigned long) mmap < mbi->mmap_addr + mbi->mmap_length; mmap = (multiboot_memory_map_t *) ((unsigned long) mmap + mmap->size + sizeof(mmap->size))){
|
||||
auto CurrentInfoBlock = BIB->MemoryMap;
|
||||
|
||||
if ( mmap->type == MULTIBOOT_MEMORY_AVAILABLE){
|
||||
|
||||
} else{
|
||||
while((unsigned long) mmap < MemoryMapEnd){
|
||||
|
||||
CurrentInfoBlock->Base_addr = mmap->addr;
|
||||
CurrentInfoBlock->Memory_Size = mmap->len;
|
||||
|
||||
|
||||
if(mmap->type == MULTIBOOT_MEMORY_AVAILABLE)
|
||||
CurrentInfoBlock->type &= 0x1;
|
||||
if(mmap->type == MULTIBOOT_MEMORY_ACPI_RECLAIMABLE)
|
||||
CurrentInfoBlock->type &= 0x2;
|
||||
if(mmap->type == MULTIBOOT_MEMORY_RESERVED)
|
||||
CurrentInfoBlock->type &= 0x4;
|
||||
if(mmap->type == MULTIBOOT_MEMORY_NVS)
|
||||
CurrentInfoBlock->type &= 0x8;
|
||||
if(mmap->type == MULTIBOOT_MEMORY_BADRAM)
|
||||
CurrentInfoBlock->type &= 0x10;
|
||||
|
||||
|
||||
// continue to the next block
|
||||
mmap = (multiboot_memory_map_t *) ((unsigned long) mmap + mmap->size + sizeof(mmap->size));
|
||||
|
||||
CurrentInfoBlock->next = (MemoryInfoBlock*) ((uint32_t)CurrentInfoBlock) + sizeof(MemoryInfoBlock);
|
||||
CurrentInfoBlock = CurrentInfoBlock->next;
|
||||
|
||||
}
|
||||
|
||||
CurrentInfoBlock->next = (MemoryInfoBlock*) 0x0;
|
||||
|
||||
}
|
||||
|
||||
} else{
|
||||
} else
|
||||
{
|
||||
BIB->PhysicalMemoryMapAvailable = false;
|
||||
}
|
||||
}
|
||||
|
||||
/* Draw diagonal blue line */
|
||||
if (CHECK_FLAG (mbi->flags, 12)){
|
||||
|
@ -19,6 +19,22 @@ extern "C" void early_main()
|
||||
* Show a little banner for cuteness
|
||||
*/
|
||||
printf("|=== BarinkOS ===|\n");
|
||||
printf("Kernel End Addr: 0x%x\n" , &kernel_end + KERNEL_BASE_ADDR);
|
||||
|
||||
uint32_t PageDirectoryEntryIndex = ((uint32_t)&kernel_end + KERNEL_BASE_ADDR ) >> 2 ;
|
||||
|
||||
uint32_t PageTableEntryIndex = (((uint32_t)&kernel_end + KERNEL_BASE_ADDR) >> 12) & 0x1FFF;
|
||||
|
||||
printf("Kernel End PDE: %d, PTE: %d\n" , PageDirectoryEntryIndex, PageTableEntryIndex);
|
||||
|
||||
uint32_t BootInfoStruct = BootInfoBlock_pptr + 0xC0000000;
|
||||
printf("Addr BootInfostruct: 0x%x\n", BootInfoStruct);
|
||||
|
||||
uint32_t PageDirectoryEntryIndex2 = (BootInfoStruct ) >> 2 ;
|
||||
|
||||
uint32_t PageTableEntryIndex2 = (BootInfoStruct >> 12) & 0x1FFF;
|
||||
|
||||
printf("PDE: 0x%x, PTE: 0x%x\n", PageDirectoryEntryIndex2 , PageTableEntryIndex2 );
|
||||
|
||||
BootInfoBlock* BootInfo = (BootInfoBlock*) ( BootInfoBlock_pptr + 0xC0000000 );
|
||||
|
||||
@ -41,6 +57,62 @@ extern "C" void early_main()
|
||||
if(BootInfo->PhysicalMemoryMapAvailable)
|
||||
{
|
||||
printf("- Physical Memory Map available!\n");
|
||||
|
||||
// Print the memory regions
|
||||
MemoryInfoBlock* currentBlock = (MemoryInfoBlock*) ((uint32_t)BootInfo->MemoryMap + KERNEL_BASE_ADDR) ;
|
||||
|
||||
kterm_setcolor(VGA_COLOR_RED);
|
||||
printf("size of MemoryInfoBlock: 0x%x\n", sizeof(MemoryInfoBlock));
|
||||
kterm_setcolor(VGA_COLOR_CYAN);
|
||||
printf("Kernel End is at address: 0x%x\n", &kernel_end);
|
||||
printf("BootInfo is at address: 0x%x\n", BootInfo);
|
||||
printf("map is at address: 0x%x\n", currentBlock + KERNEL_BASE_ADDR);
|
||||
kterm_setcolor(VGA_COLOR_WHITE);
|
||||
while( (uint32_t)currentBlock->next != 0x0 )
|
||||
{
|
||||
kterm_setcolor(VGA_COLOR_CYAN);
|
||||
printf("map is at address: 0x%x\n", ( (uint32_t)currentBlock ));
|
||||
kterm_setcolor(VGA_COLOR_WHITE);
|
||||
|
||||
/*
|
||||
uint32_t pageDirectoryIndex = ((uint32_t)¤tBlock ) >> 22;
|
||||
printf("pageDirectoryIndex: %d\n", pageDirectoryIndex);
|
||||
|
||||
uint32_t pageTableIndex = ((uint32_t)¤tBlock >> 12) & 0x1FFF;
|
||||
printf("PagTableIndex: %d\n", pageTableIndex);
|
||||
*/
|
||||
|
||||
//printf("boot_page_directory addr: 0x%x\n", &boot_page_directory);
|
||||
//printf("boot_page_table addr: 0x%x\n", &multiboot_page_table);
|
||||
printf("Memory Region: \n");
|
||||
|
||||
if(IS_AVAILABLE_MEM(currentBlock->type)){
|
||||
//printf("AVAILABLE RAM\n");
|
||||
}
|
||||
else if(IS_ACPI_MEM(currentBlock->type)){
|
||||
printf("ACPI MEMORY\n");
|
||||
}
|
||||
else if(IS_RESERVED_MEM(currentBlock->type)){
|
||||
printf("RESERVED MEMORY\n");
|
||||
}
|
||||
else if(IS_NVS_MEMORY(currentBlock->type)){
|
||||
printf("NVS MEMORY \n");
|
||||
}
|
||||
else if(IS_BADRAM_MEMORY(currentBlock->type)){
|
||||
printf("BADRAM MEMORY \n");
|
||||
}
|
||||
else {
|
||||
// printf("(TYPE 0x%x )TYPE NOT SPECIFIED\n", currentBlock->type);
|
||||
}
|
||||
|
||||
// printf("Base address: 0x%x, Memory size: 0x%x\n", currentBlock->Base_addr, currentBlock->Memory_Size);
|
||||
|
||||
currentBlock = (MemoryInfoBlock*) ((uint32_t)currentBlock->next + KERNEL_BASE_ADDR );
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
asm volatile("mov %cr0, %eax ");
|
||||
|
Loading…
Reference in New Issue
Block a user