2023-02-17 13:42:42 +00:00
|
|
|
/*
|
|
|
|
Copyright © Nigel Barink 2023
|
|
|
|
*/
|
2023-02-03 20:47:05 +00:00
|
|
|
#include "memory/memory.h"
|
2022-09-02 19:09:51 +00:00
|
|
|
#include "memory/KernelHeap.h"
|
|
|
|
#include "memory/gdt/gdtc.h"
|
2023-02-11 11:22:45 +00:00
|
|
|
#include "memory/TaskStateSegment.h"
|
2023-02-08 13:07:44 +00:00
|
|
|
#include "supervisorterminal/superVisorTerminal.h"
|
|
|
|
#include "drivers/vga/VBE.h"
|
2023-02-21 13:36:20 +00:00
|
|
|
#include "pci/pci.h"
|
2023-02-08 13:07:44 +00:00
|
|
|
#include "drivers/pit/pit.h"
|
2023-02-21 13:36:20 +00:00
|
|
|
#include "acpi/acpi.h"
|
2023-02-17 15:27:36 +00:00
|
|
|
#include "i386/processor.h"
|
2023-02-08 13:07:44 +00:00
|
|
|
#include "terminal/kterm.h"
|
2023-02-11 11:22:45 +00:00
|
|
|
#include "interrupts/idt.h"
|
2022-09-02 19:09:51 +00:00
|
|
|
#include "serial.h"
|
2023-02-21 20:43:14 +00:00
|
|
|
#include "storage/vfs/vfs.h"
|
2023-02-23 22:54:02 +00:00
|
|
|
#include "storage/filesystems/FAT/FAT.h"
|
|
|
|
|
2023-02-17 15:27:36 +00:00
|
|
|
|
2023-02-13 21:44:47 +00:00
|
|
|
extern "C" void LoadGlobalDescriptorTable();
|
2023-02-17 13:46:44 +00:00
|
|
|
extern "C" void jump_usermode();
|
2023-02-21 20:43:14 +00:00
|
|
|
extern BootInfoBlock* BIB;
|
2023-02-13 21:44:47 +00:00
|
|
|
|
2023-02-17 13:42:42 +00:00
|
|
|
extern "C" void kernel ()
|
2022-09-02 19:09:51 +00:00
|
|
|
{
|
2023-02-17 13:42:42 +00:00
|
|
|
|
2022-08-17 23:26:49 +00:00
|
|
|
init_serial();
|
2022-09-02 19:09:51 +00:00
|
|
|
kterm_init();
|
2023-02-11 11:22:45 +00:00
|
|
|
|
2023-02-13 21:44:47 +00:00
|
|
|
setup_tss();
|
2022-09-02 19:09:51 +00:00
|
|
|
initGDT();
|
2023-02-11 11:22:45 +00:00
|
|
|
initidt();
|
2023-02-13 21:44:47 +00:00
|
|
|
LoadGlobalDescriptorTable();
|
|
|
|
flush_tss();
|
|
|
|
printf("Memory setup complete!\n");
|
2023-02-17 13:42:42 +00:00
|
|
|
|
2022-08-18 22:44:52 +00:00
|
|
|
// Enable interrupts
|
|
|
|
asm volatile("STI");
|
2023-02-11 11:22:45 +00:00
|
|
|
|
2023-02-17 20:52:03 +00:00
|
|
|
initHeap();
|
2023-02-17 13:42:42 +00:00
|
|
|
pit_initialise();
|
2023-02-21 13:36:20 +00:00
|
|
|
ACPI::initialize();
|
|
|
|
|
2023-02-21 20:43:14 +00:00
|
|
|
PCI::Scan();
|
2023-02-17 15:27:36 +00:00
|
|
|
processor::initialize();
|
2023-02-17 21:01:32 +00:00
|
|
|
processor::enable_protectedMode();
|
2023-02-21 20:43:14 +00:00
|
|
|
printf("Boot device: 0x%x\n", BIB->bootDeviceID);
|
|
|
|
unsigned int part3 = BIB->bootDeviceID & 0xFF;
|
|
|
|
unsigned int part2 = (BIB->bootDeviceID & 0xFF00) >> 8;
|
|
|
|
unsigned int part1 = (BIB->bootDeviceID & 0xFF0000) >> 16;
|
|
|
|
unsigned int drive = (BIB->bootDeviceID & 0xFF000000) >> 24;
|
|
|
|
if (drive == 0x80 )
|
|
|
|
printf("booted from disk!\n");
|
|
|
|
if(drive == 0x00)
|
|
|
|
printf("booted from floppy disk\n");
|
|
|
|
|
|
|
|
printf("Part1: %d, Part2: %d, Part3: %d\n", part1, part2 , part3);
|
2023-02-23 22:54:02 +00:00
|
|
|
ATAPIO::Identify(ATAPIO_PORT::Primary, DEVICE_DRIVE::MASTER);
|
|
|
|
auto* bpb = FAT::getBPB(false);
|
|
|
|
auto* mbr = GetPartitions(false);
|
|
|
|
auto fsType = FAT::determineFATType(bpb);
|
|
|
|
switch (fsType) {
|
|
|
|
case FAT_TYPE::FAT12:
|
|
|
|
printf("FAT12 Disk!\n");
|
|
|
|
break;
|
|
|
|
case FAT_TYPE::FAT16:
|
|
|
|
printf("FAT16 Disk!\n");
|
|
|
|
break;
|
|
|
|
case FAT_TYPE::FAT32:
|
|
|
|
printf("FAT32 Disk!\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// list files in root
|
|
|
|
int total_sectors = bpb->TotSec32;
|
|
|
|
int fat_size = bpb->FATSz16;
|
|
|
|
int root_dir_sectors = FAT::RootDirSize(bpb);
|
|
|
|
int first_data_sector = bpb->RsvdSecCnt + (bpb->NumFATs * fat_size) + root_dir_sectors ;
|
|
|
|
int data_sectors = bpb->TotSec32 - (bpb->RsvdSecCnt + (bpb->NumFATs * fat_size) + root_dir_sectors);
|
|
|
|
int total_clusters = data_sectors / bpb->SecPerClus;
|
|
|
|
|
|
|
|
|
|
|
|
int first_root_dir_sector = first_data_sector - root_dir_sectors;
|
|
|
|
//int first_sector_of_cluster = ((cluster - 2) * bpb->SecPerClus) + first_data_sector;
|
|
|
|
uint16_t data[256];
|
|
|
|
ATAPIO::Read(ATAPIO_PORT::Primary, DEVICE_DRIVE::MASTER, first_root_dir_sector, data);
|
|
|
|
|
|
|
|
auto* RootDirectory = (DIR*)data;
|
|
|
|
for(int i = 0; i < sizeof(data) / sizeof (DIR); i++)
|
|
|
|
{
|
|
|
|
DIR* entry = (DIR*)((uint32_t)RootDirectory + (i * sizeof(DIR)));
|
|
|
|
|
|
|
|
|
|
|
|
if(entry->Name[0] == FAT::FREE_DIR || entry->Name[0] == FAT::FREE_DIR_2 || entry->Name[0] == 0xE5){
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2023-02-24 20:31:20 +00:00
|
|
|
|
2023-02-23 22:54:02 +00:00
|
|
|
if(entry->ATTR & FAT::ATTRIBUTES::ATTR_HIDDEN){
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(entry->ATTR & FAT::ATTRIBUTES::ATTR_SYSTEM)
|
|
|
|
continue;
|
|
|
|
|
2023-02-24 20:31:20 +00:00
|
|
|
|
2023-02-23 22:54:02 +00:00
|
|
|
if(entry->ATTR & FAT::ATTRIBUTES::ATTR_VOLUME_ID){
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!(entry->ATTR & FAT::ATTRIBUTES::ATTR_LONG_NAME)){
|
|
|
|
for(char n : entry->Name){
|
|
|
|
if(n == 0x20)
|
|
|
|
continue;
|
|
|
|
kterm_put(n);
|
|
|
|
}
|
|
|
|
}else{
|
2023-02-24 20:31:20 +00:00
|
|
|
printf("Long file name detected!");
|
2023-02-23 22:54:02 +00:00
|
|
|
}
|
|
|
|
|
2023-02-24 20:31:20 +00:00
|
|
|
printf(" [Size: %d bytes, Attributes: %d]\n", entry->ATTR, entry->FileSize);
|
|
|
|
if(entry->ATTR & FAT::ATTRIBUTES::ATTR_DIRECTORY ){
|
|
|
|
FAT::OpenSubdir(entry, bpb);
|
2023-02-25 20:03:10 +00:00
|
|
|
} else {
|
|
|
|
FAT::readFile(entry, bpb);
|
2023-02-24 20:31:20 +00:00
|
|
|
}
|
2023-02-23 22:54:02 +00:00
|
|
|
|
|
|
|
}
|
2023-02-21 20:43:14 +00:00
|
|
|
|
2022-08-23 19:35:19 +00:00
|
|
|
|
2023-02-19 21:14:58 +00:00
|
|
|
|
2023-02-21 20:43:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2023-02-23 22:54:02 +00:00
|
|
|
// VirtualFileSystem::initialize();
|
2023-02-21 20:43:14 +00:00
|
|
|
|
2023-02-23 22:54:02 +00:00
|
|
|
// VirtualFileSystem::open("/hello.txt", 0);
|
2023-02-21 20:43:14 +00:00
|
|
|
|
2022-08-23 19:35:19 +00:00
|
|
|
|
2023-02-17 13:46:44 +00:00
|
|
|
#ifdef USERMODE_RELEASE
|
|
|
|
// Lets jump into user mode
|
|
|
|
jump_usermode();
|
|
|
|
#else
|
|
|
|
startSuperVisorTerminal();
|
|
|
|
#endif
|
2021-12-28 18:47:32 +00:00
|
|
|
|
2023-02-17 13:42:42 +00:00
|
|
|
}
|