Merge into main the new state of the operating system/kernel #1
@ -15,8 +15,6 @@ $(OUTPUTFILE): $(OFILES)
|
|||||||
pwd
|
pwd
|
||||||
ar -rc $(OUTPUTFILE) $(OFILES)
|
ar -rc $(OUTPUTFILE) $(OFILES)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$(OBJ_FOLDER)/ctype.o: ctype.cpp
|
$(OBJ_FOLDER)/ctype.o: ctype.cpp
|
||||||
$(CPP) -c ctype.cpp -o $(OBJ_FOLDER)/ctype.o $(CFLAGS)
|
$(CPP) -c ctype.cpp -o $(OBJ_FOLDER)/ctype.o $(CFLAGS)
|
||||||
|
|
||||||
|
@ -42,43 +42,33 @@ extern "C" void kernel ()
|
|||||||
{
|
{
|
||||||
init_serial();
|
init_serial();
|
||||||
kterm_init();
|
kterm_init();
|
||||||
|
print_serial("kterm initialized...\n");
|
||||||
setup_tss();
|
setup_tss();
|
||||||
initGDT();
|
initGDT();
|
||||||
initidt();
|
initidt();
|
||||||
LoadGlobalDescriptorTable();
|
LoadGlobalDescriptorTable();
|
||||||
flush_tss();
|
flush_tss();
|
||||||
printf("Memory setup complete!\n");
|
printf("Memory setup complete!\n");
|
||||||
|
print_serial("Memory initialized....\n");
|
||||||
// Enable interrupts
|
// Enable interrupts
|
||||||
asm volatile("STI");
|
asm volatile("STI");
|
||||||
|
|
||||||
initHeap();
|
initHeap();
|
||||||
pit_initialise();
|
print_serial("Heap initialized...\n");
|
||||||
ACPI::initialize();
|
//pit_initialise();
|
||||||
PCI::Scan();
|
|
||||||
|
|
||||||
|
//ACPI::initialize();
|
||||||
|
//PCI::Scan();
|
||||||
processor::initialize();
|
processor::initialize();
|
||||||
processor::enable_protectedMode();
|
processor::enable_protectedMode();
|
||||||
initBootDrive();
|
initBootDrive();
|
||||||
VirtualFileSystem::initialize();
|
VirtualFileSystem::initialize();
|
||||||
|
|
||||||
|
print_serial("Run test!");
|
||||||
|
#define VFS_EXAMPLE
|
||||||
#ifdef VFS_EXAMPLE
|
#ifdef VFS_EXAMPLE
|
||||||
auto fontFile = VirtualFileSystem::open("/FONT PSF", 0);
|
auto fontFile = VirtualFileSystem::open("/FONT PSF", 0);
|
||||||
if(grubcfg->flags == 0){
|
printf("Size of font file: %d bytes", fontFile->root->size); // COOL This Works like a charm
|
||||||
uint16_t* contents = (uint16_t*) malloc(sizeof(uint16_t) * 256);
|
|
||||||
grubcfg->read(grubcfg, contents, 512);
|
|
||||||
|
|
||||||
for(int i =0 ; i < grubcfg->root->size; i++ ){
|
|
||||||
kterm_put(contents[i] & 0x00ff);
|
|
||||||
kterm_put(contents[i] >> 8);
|
|
||||||
}
|
|
||||||
kterm_put('\n');
|
|
||||||
free((void*)contents);
|
|
||||||
}else{
|
|
||||||
printf("Could not find file\n");
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USERMODE_RELEASE
|
#ifdef USERMODE_RELEASE
|
||||||
@ -86,6 +76,7 @@ extern "C" void kernel ()
|
|||||||
jump_usermode();
|
jump_usermode();
|
||||||
#else
|
#else
|
||||||
startSuperVisorTerminal();
|
startSuperVisorTerminal();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
@ -1,4 +1,6 @@
|
|||||||
#include "VirtualMemoryManager.h"
|
#include "VirtualMemoryManager.h"
|
||||||
|
#include "../../CoreLib/Memory.h"
|
||||||
|
|
||||||
#define ALIGN(addr, align) (((addr) & ~((align) - 1 )) + (align))
|
#define ALIGN(addr, align) (((addr) & ~((align) - 1 )) + (align))
|
||||||
|
|
||||||
extern uint32_t boot_page_directory[1024] ; // points to the wrong location
|
extern uint32_t boot_page_directory[1024] ; // points to the wrong location
|
||||||
@ -14,7 +16,7 @@ void flush_cr3(){
|
|||||||
|
|
||||||
void AllocatePage(uint32_t vaddr)
|
void AllocatePage(uint32_t vaddr)
|
||||||
{
|
{
|
||||||
uint32_t page_aligned_address = ALIGN(vaddr, 4096);
|
//uint32_t page_aligned_address = ALIGN(vaddr, 4096);
|
||||||
|
|
||||||
// allocate a page at virtual address
|
// allocate a page at virtual address
|
||||||
int PageDirectoryEntryIndex = vaddr >> 22;
|
int PageDirectoryEntryIndex = vaddr >> 22;
|
||||||
@ -54,16 +56,16 @@ void AllocatePage(uint32_t vaddr)
|
|||||||
|
|
||||||
void FreePage(uint32_t vaddr )
|
void FreePage(uint32_t vaddr )
|
||||||
{
|
{
|
||||||
uint32_t page_aligned_address = ALIGN(vaddr, 4096);
|
// uint32_t page_aligned_address = ALIGN(vaddr, 4096);
|
||||||
|
|
||||||
// allocate a page at virtual address
|
// allocate a page at virtual address
|
||||||
int PageDirectoryEntryIndex = vaddr >> 22;
|
int PageDirectoryEntryIndex = vaddr >> 22;
|
||||||
int PageTableEntryIndex = (vaddr >> 12) & 0x1FFF;
|
int PageTableEntryIndex = (vaddr >> 12) & 0x1FFF;
|
||||||
|
|
||||||
uint32_t* pageTable = (uint32_t*)(boot_page_directory[PageDirectoryEntryIndex] & 0xFFFFE000 + 0xC0000000);
|
uint32_t* pageTable = (uint32_t*)(boot_page_directory[PageDirectoryEntryIndex] & (0xFFFFE000 + 0xC0000000));
|
||||||
|
|
||||||
|
|
||||||
void* physicalAddressToFree = (void*)(pageTable[PageTableEntryIndex] & 0xFFFFE000 + 0xC0000000);
|
void* physicalAddressToFree = (void*)(pageTable[PageTableEntryIndex] & (0xFFFFE000 + 0xC0000000));
|
||||||
free_block(physicalAddressToFree);
|
free_block(physicalAddressToFree);
|
||||||
|
|
||||||
pageTable[PageTableEntryIndex] = 0x0;
|
pageTable[PageTableEntryIndex] = 0x0;
|
||||||
@ -80,9 +82,9 @@ void Immediate_Map ( uint32_t vaddr, uint32_t paddr)
|
|||||||
int PageTableEntryIndex = (vaddr >> 12) & 0x1FFF;
|
int PageTableEntryIndex = (vaddr >> 12) & 0x1FFF;
|
||||||
|
|
||||||
printf("Map address at PDE 0x%x PTE 0x%x\n", PageDirectoryEntryIndex, PageTableEntryIndex);
|
printf("Map address at PDE 0x%x PTE 0x%x\n", PageDirectoryEntryIndex, PageTableEntryIndex);
|
||||||
|
printf("boot pagedirectoy address: 0x%x\n", &boot_page_directory);
|
||||||
if ((boot_page_directory - 0xC0000000)[PageDirectoryEntryIndex] & 0x1 )
|
printf("PDE : 0x%x\n", boot_page_directory[PageTableEntryIndex]);
|
||||||
{
|
if (boot_page_directory[PageDirectoryEntryIndex] & 0x1 ) {
|
||||||
printf("Directory entry is marked as present\n");
|
printf("Directory entry is marked as present\n");
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -90,37 +92,39 @@ void Immediate_Map ( uint32_t vaddr, uint32_t paddr)
|
|||||||
// mark the page table as present and allocate a physical block for it
|
// mark the page table as present and allocate a physical block for it
|
||||||
|
|
||||||
void* new_page_dir = allocate_block();
|
void* new_page_dir = allocate_block();
|
||||||
printf("New page directory address 0x%x\n", new_page_dir);
|
memset(new_page_dir, 0 , 1024 * sizeof (uint32_t));
|
||||||
|
printf("New page directory address 0x%x\n", &new_page_dir);
|
||||||
boot_page_directory[PageDirectoryEntryIndex] = (uint32_t)new_page_dir | 0x3;
|
boot_page_directory[PageDirectoryEntryIndex] = (uint32_t)new_page_dir | 0x3;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("PDE found at : 0x%x\n", (uint32_t) &boot_page_directory[PageDirectoryEntryIndex]);
|
printf("PDE found at : 0x%x\n", (uint32_t) &boot_page_directory[PageDirectoryEntryIndex]);
|
||||||
uint32_t* page_table = (uint32_t*)(boot_page_directory[PageDirectoryEntryIndex] & 0xFFFFE000) ;
|
uint32_t* page_table = (uint32_t*)(boot_page_directory[PageDirectoryEntryIndex] & 0xFFFFE000) ;
|
||||||
//page_table = (uint32_t*) ((uint32_t)page_table - 0xC0000000); // remove kernel offset
|
printf("Page table address: 0x%x\n", (uint32_t)page_table);
|
||||||
printf("Page table address: 0x%x\n", (uint32_t)page_table);
|
|
||||||
|
|
||||||
// check if the page table entry is marked as present
|
// check if the page table entry is marked as present
|
||||||
if ( page_table[PageTableEntryIndex] & 0x1 )
|
if ( page_table[PageTableEntryIndex] & 0x1 )
|
||||||
{
|
{
|
||||||
printf("page already present!\n");
|
printf("page already present!\n");
|
||||||
printf("Entry found at addr: 0x%x\n", &(page_table[PageTableEntryIndex]));
|
printf("Entry found at addr: 0x%x\n", &(page_table[PageTableEntryIndex]));
|
||||||
} else{
|
} else{
|
||||||
printf("Mapping a physical page.\n");
|
printf("Mapping a physical page.\n");
|
||||||
// Map the entry to a physical page
|
// Map the entry to a physical page
|
||||||
page_table[PageTableEntryIndex] = (uint32_t)(paddr | 0x3);
|
page_table[PageTableEntryIndex] = (uint32_t)(paddr | 0x3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
asm ("cli; invlpg (%0); sti" :: "r" (vaddr) : "memory" );
|
asm ("invlpg (%0)" :: "r" (vaddr) : "memory" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// NOT IMPLEMENTED
|
||||||
void Immediate_Unmap(uint32_t vaddr)
|
void Immediate_Unmap(uint32_t vaddr)
|
||||||
{
|
{
|
||||||
// NOTE: I will implement lazy unmapping for now
|
// NOTE: I will implement lazy unmapping for now
|
||||||
uint32_t page_aligned_address = ALIGN(vaddr, 4096);
|
//uint32_t page_aligned_address = ALIGN(vaddr, 4096);
|
||||||
|
|
||||||
// allocate a page at virtual address
|
// allocate a page at virtual address
|
||||||
int PageDirectoryEntryIndex = vaddr >> 22;
|
//int PageDirectoryEntryIndex = vaddr >> 22;
|
||||||
int PageTableEntryIndex = (vaddr >> 12) & 0x1FFF;
|
//int PageTableEntryIndex = (vaddr >> 12) & 0x1FFF;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -107,10 +107,10 @@ DirectoryNode* FAT::Lookup (inode* currentDir , DirectoryNode* dir)
|
|||||||
for(int i = 0; i < sizeof(data) / sizeof (DIR); i++)
|
for(int i = 0; i < sizeof(data) / sizeof (DIR); i++)
|
||||||
{
|
{
|
||||||
DIR* entry = (DIR*)((uint32_t)directory + (i * sizeof(DIR)));
|
DIR* entry = (DIR*)((uint32_t)directory + (i * sizeof(DIR)));
|
||||||
|
|
||||||
|
|
||||||
if(
|
if(
|
||||||
entry->Name[0] == FAT::FREE_DIR ||
|
entry->Name[0] == FAT::FREE_DIR ||
|
||||||
entry->Name[0] == FAT::FREE_DIR_2 ||
|
|
||||||
entry->Name[0] == 0xE5 ||
|
|
||||||
entry->ATTR & FAT::ATTRIBUTES::ATTR_VOLUME_ID ||
|
entry->ATTR & FAT::ATTRIBUTES::ATTR_VOLUME_ID ||
|
||||||
entry->ATTR & FAT::ATTRIBUTES::ATTR_SYSTEM ||
|
entry->ATTR & FAT::ATTRIBUTES::ATTR_SYSTEM ||
|
||||||
entry->ATTR & FAT::ATTRIBUTES::ATTR_HIDDEN
|
entry->ATTR & FAT::ATTRIBUTES::ATTR_HIDDEN
|
||||||
@ -118,6 +118,20 @@ DirectoryNode* FAT::Lookup (inode* currentDir , DirectoryNode* dir)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if( entry->ATTR & FAT::ATTRIBUTES::ATTR_DIRECTORY){
|
||||||
|
printf("entry in directory\n");
|
||||||
|
for(int i = 0; i < 11 ;i ++)
|
||||||
|
kterm_put(entry->Name[i]);
|
||||||
|
kterm_put('\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if( entry->Name[0] == FAT::FREE_DIR_2 )
|
||||||
|
break;
|
||||||
|
|
||||||
auto* dirNode = (DirectoryNode*) malloc(sizeof (DirectoryNode));
|
auto* dirNode = (DirectoryNode*) malloc(sizeof (DirectoryNode));
|
||||||
|
|
||||||
char* name = (char*)malloc(sizeof(char[11]));
|
char* name = (char*)malloc(sizeof(char[11]));
|
||||||
|
@ -22,22 +22,22 @@ inline MBR* GetPartitions(bool DEBUG = false){
|
|||||||
int S =1;
|
int S =1;
|
||||||
uint32_t LBA = (C*HPC+H) * SPT + (S-1);
|
uint32_t LBA = (C*HPC+H) * SPT + (S-1);
|
||||||
|
|
||||||
MBR* mbr =(MBR*) malloc(sizeof (MBR));
|
uint16_t* mbr =(uint16_t*) malloc(sizeof (MBR));
|
||||||
|
|
||||||
ATAPIO::Read(ATAPIO_PORT::Primary, DEVICE_DRIVE::MASTER, LBA, (uint16_t*)mbr);
|
ATAPIO::Read(ATAPIO_PORT::Primary, DEVICE_DRIVE::MASTER, LBA, mbr );
|
||||||
|
auto bootRecord = (MBR*)(mbr);
|
||||||
|
|
||||||
|
printf("MBR (In Memory) Address 0x%x, Size = %d\n", bootRecord, sizeof (MBR));
|
||||||
printf("MBR (In Memory) Address 0x%x, Size = %d\n", mbr, sizeof (MBR));
|
|
||||||
if(DEBUG){
|
if(DEBUG){
|
||||||
printf("BootSector: 0x%x\n", mbr->ValidBootsector );
|
printf("BootSector: 0x%x\n", bootRecord->ValidBootsector );
|
||||||
for( int i = 0 ; i < 4 ; i ++){
|
for( int i = 0 ; i < 4 ; i ++){
|
||||||
PartitionTableEntry PT = mbr->TableEntries[i];
|
PartitionTableEntry PT = bootRecord->TableEntries[i];
|
||||||
|
|
||||||
printf("Partition %d [ %d sectors, PartitionType: 0x%x, 0x%x, \nLBA Start: 0x%x ]\n" ,
|
printf("Partition %d [ %d sectors, PartitionType: 0x%x, 0x%x, \nLBA Start: 0x%x ]\n" ,
|
||||||
i, PT.Number_sectors_inPartition, PT.PartitionType, mbr->uniqueID, PT.LBA_partition_start );
|
i, PT.Number_sectors_inPartition, PT.PartitionType, bootRecord->uniqueID, PT.LBA_partition_start );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return mbr;
|
return bootRecord;
|
||||||
}
|
}
|
||||||
|
@ -80,20 +80,37 @@ FILE* VirtualFileSystem::open(const char* pathname, int flags){
|
|||||||
}
|
}
|
||||||
|
|
||||||
// let's just loop through the folder first
|
// let's just loop through the folder first
|
||||||
|
printf("looking for: ");
|
||||||
|
for(int i = 0; i < 5; i++)
|
||||||
|
kterm_put(nextdir[i]);
|
||||||
|
kterm_put('\n');
|
||||||
auto* child = rootentry->children;
|
auto* child = rootentry->children;
|
||||||
while(child->next != nullptr){
|
while(child->next != nullptr){
|
||||||
|
|
||||||
auto* directory = (DirectoryNode*)child->data;
|
auto* directory = (DirectoryNode*)child->data;
|
||||||
|
|
||||||
|
for(int i = 0; i < 11 ; i++)
|
||||||
|
kterm_put(directory->name[i]);
|
||||||
|
kterm_put('\n');
|
||||||
|
|
||||||
if( directory->compare(directory, directory->name, nextdir) == 0){
|
if( directory->compare(directory, directory->name, nextdir) == 0){
|
||||||
nextdir = strtok(nullptr, "/", &tokstate);
|
nextdir = strtok(nullptr, "/", &tokstate);
|
||||||
|
printf("Found dir!\n");
|
||||||
if(nextdir == NULL){
|
if(nextdir == NULL){
|
||||||
file->root = directory->node;
|
file->root = directory->node;
|
||||||
file->flags =0;
|
file->flags =0;
|
||||||
file->read = FAT::Read;
|
file->read = FAT::Read;
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
printf("continue searching next directory!\n");
|
||||||
|
if(directory->children == nullptr)
|
||||||
|
directory->node->lookup(directory->node, directory);
|
||||||
|
|
||||||
|
|
||||||
|
child = directory->children;
|
||||||
|
|
||||||
|
}else{
|
||||||
|
child = child->next;
|
||||||
}
|
}
|
||||||
child = child->next;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,7 +21,14 @@ void kterm_init () {
|
|||||||
kterm_row = 0;
|
kterm_row = 0;
|
||||||
kterm_column = 0;
|
kterm_column = 0;
|
||||||
kterm_color = vga_entry_color ( VGA_COLOR_LIGHT_GREY , VGA_COLOR_BLACK);
|
kterm_color = vga_entry_color ( VGA_COLOR_LIGHT_GREY , VGA_COLOR_BLACK);
|
||||||
kterm_buffer = (uint16_t*) 0xC03FF000;
|
|
||||||
|
//Physical address
|
||||||
|
// 0xB8000
|
||||||
|
// Virtual address
|
||||||
|
// 0xC03FF000
|
||||||
|
|
||||||
|
//kterm_buffer = ((uint16_t*) 0xB8000);
|
||||||
|
kterm_buffer = ((uint16_t*) 0xC03FF000 );
|
||||||
|
|
||||||
for (size_t y = 0; y < VGA_HEIGHT; y++ ){
|
for (size_t y = 0; y < VGA_HEIGHT; y++ ){
|
||||||
for( size_t x = 0; x < VGA_WIDTH; x++){
|
for( size_t x = 0; x < VGA_WIDTH; x++){
|
||||||
@ -59,7 +66,6 @@ void disable_cursor()
|
|||||||
outb(0x3D5, 0x20);
|
outb(0x3D5, 0x20);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void update_cursor(int x, int y){
|
void update_cursor(int x, int y){
|
||||||
uint16_t pos = y * VGA_WIDTH + x;
|
uint16_t pos = y * VGA_WIDTH + x;
|
||||||
|
|
||||||
@ -86,8 +92,6 @@ int get_cursor_y (uint16_t cursor_pos ) {
|
|||||||
return cursor_pos / VGA_WIDTH;
|
return cursor_pos / VGA_WIDTH;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* With the help from:
|
* With the help from:
|
||||||
* https://whiteheadsoftware.dev/operating-systems-development-for-dummies/
|
* https://whiteheadsoftware.dev/operating-systems-development-for-dummies/
|
||||||
@ -134,7 +138,6 @@ void kterm_writestring(const char* data ){
|
|||||||
kterm_write(data, strlen(data));
|
kterm_write(data, strlen(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void itoa (char *buf, int base, int d) {
|
static void itoa (char *buf, int base, int d) {
|
||||||
char *p = buf;
|
char *p = buf;
|
||||||
char *p1, *p2;
|
char *p1, *p2;
|
||||||
@ -173,28 +176,28 @@ static void itoa (char *buf, int base, int d) {
|
|||||||
|
|
||||||
void printf ( const char *format, ...) {
|
void printf ( const char *format, ...) {
|
||||||
|
|
||||||
char **arg = (char **)&format;
|
auto **arg = (unsigned char **)&format;
|
||||||
int c;
|
int c;
|
||||||
char buf[20];
|
char buf[20];
|
||||||
|
|
||||||
arg++;
|
arg++;
|
||||||
|
|
||||||
while ((c = *format++) != 0){
|
while ((c = *(const unsigned char*)format++) != 0){
|
||||||
if( c != '%')
|
if( c != '%')
|
||||||
kterm_put(c);
|
kterm_put(c);
|
||||||
else{
|
else{
|
||||||
char *p, *p2;
|
char const *p, *p2;
|
||||||
int pad0 = 0, pad = 0;
|
int pad0 = 0, pad = 0;
|
||||||
|
|
||||||
c = *format++;
|
c = *(const unsigned char*)format++;
|
||||||
if(c =='0'){
|
if(c =='0'){
|
||||||
pad0 = 1;
|
pad0 = 1;
|
||||||
c = *format++;
|
c = *(const unsigned char*)format++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( c >= '0' && c <= '9'){
|
if ( c >= '0' && c <= '9'){
|
||||||
pad = c - '0';
|
pad = c - '0';
|
||||||
c = *format++;
|
c = *(const unsigned char*)format++;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (c)
|
switch (c)
|
||||||
@ -210,7 +213,7 @@ void printf ( const char *format, ...) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 's':
|
case 's':
|
||||||
p = *arg++;
|
p = (char const *)*arg++;
|
||||||
if(!p)
|
if(!p)
|
||||||
p = "(null)";
|
p = "(null)";
|
||||||
|
|
||||||
@ -224,7 +227,7 @@ void printf ( const char *format, ...) {
|
|||||||
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
kterm_put(*((int *)arg++));
|
kterm_put(*(int *) arg++); // NOLINT(cppcoreguidelines-narrowing-conversions)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user