From ec654143c6625e27c27ea812d581fb73cc7fa932 Mon Sep 17 00:00:00 2001 From: Nigel Date: Thu, 25 Nov 2021 22:05:16 +0100 Subject: [PATCH 01/21] Basic PCI Enumeration --- Makefile | 7 ++- src/kernel/gdt/gdtc.cpp | 4 -- src/kernel/io.cpp | 12 ++-- src/kernel/io.h | 8 +-- src/kernel/kernel.cpp | 81 ++++++++++++++++++++++++-- src/kernel/kernel.h | 2 + src/kernel/pci.cpp | 122 +++++++--------------------------------- src/kernel/pci.h | 55 +++--------------- 8 files changed, 120 insertions(+), 171 deletions(-) diff --git a/Makefile b/Makefile index afa65c7..c553ba1 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ CC = ${HOME}/opt/cross/bin/i686-elf-gcc CPP = ${HOME}/opt/cross/bin/i686-elf-g++ CFLAGS = -ffreestanding -O2 -Wall -Wextra -OFILES = $(BUILD_DIR)/boot.o $(BUILD_DIR)/kterm.o $(BUILD_DIR)/kernel.o $(BUILD_DIR)/PhysicalMemoryManager.o $(BUILD_DIR)/io.o $(BUILD_DIR)/PageDirectory.o $(BUILD_DIR)/gdtc.o $(BUILD_DIR)/idt.o $(BUILD_DIR)/pic.o $(BUILD_DIR)/string.o +OFILES = $(BUILD_DIR)/boot.o $(BUILD_DIR)/kterm.o $(BUILD_DIR)/kernel.o $(BUILD_DIR)/PhysicalMemoryManager.o $(BUILD_DIR)/io.o $(BUILD_DIR)/PageDirectory.o $(BUILD_DIR)/gdtc.o $(BUILD_DIR)/idt.o $(BUILD_DIR)/pci.o $(BUILD_DIR)/pic.o $(BUILD_DIR)/string.o SRC_DIR = src BUILD_DIR = build @@ -36,7 +36,7 @@ iso: clean_iso clean build grub-mkrescue -o build/barinkOS.iso root test: - $(EMULATOR) -kernel $(BUILD_DIR)/myos.bin -serial stdio -vga std -monitor stdio -display gtk -m 2G -cpu core2duo + $(EMULATOR) -kernel $(BUILD_DIR)/myos.bin -serial stdio -vga std -display gtk -m 2G -cpu core2duo build_kernel: $(OBJ_LINK_LIST) $(CC) -T $(SRC_DIR)/kernel//linker.ld -o $(BUILD_DIR)/myos.bin \ @@ -85,3 +85,6 @@ $(BUILD_DIR)/string.o: $(BUILD_DIR)/PhysicalMemoryManager.o: $(CPP) -c $(SRC_DIR)/kernel/memory/PhysicalMemoryManager.cpp -o $(BUILD_DIR)/PhysicalMemoryManager.o $(CFLAGS) -fno-exceptions -fno-rtti + +$(BUILD_DIR)/pci.o: + $(CPP) -c $(SRC_DIR)/kernel/pci.cpp -o $(BUILD_DIR)/pci.o $(CFLAGS) -fno-exceptions -fno-rtti diff --git a/src/kernel/gdt/gdtc.cpp b/src/kernel/gdt/gdtc.cpp index f2624bf..d02d0fd 100644 --- a/src/kernel/gdt/gdtc.cpp +++ b/src/kernel/gdt/gdtc.cpp @@ -52,10 +52,6 @@ void initGDT(){ LoadGlobalDescriptorTable(); - while (true) - asm volatile("hlt"); - - } diff --git a/src/kernel/io.cpp b/src/kernel/io.cpp index 8a0861c..80e16d3 100644 --- a/src/kernel/io.cpp +++ b/src/kernel/io.cpp @@ -12,9 +12,10 @@ unsigned short inw_p(unsigned short ){ // TODO: implement me! return 0; } -unsigned int inl(unsigned short ){ -// TODO: implement me! - return 0; +uint32_t inl( int port ){ + unsigned int data; + asm volatile ("inl %w1, %0": "=a" (data): "d" (port)); + return data; } unsigned int inl_p(unsigned short ){ // TODO: implement me! @@ -31,9 +32,12 @@ void outw(unsigned short , unsigned short ){ void outw_p(unsigned short , unsigned short ){ } -void outl(unsigned int , unsigned short ){ +void outl( int port , uint32_t data ){ + asm volatile ("outl %0, %1" :: "a" (data), "dn"(port)); } + + void outl_p(unsigned int , unsigned short ){ } diff --git a/src/kernel/io.h b/src/kernel/io.h index c7fd561..094d595 100644 --- a/src/kernel/io.h +++ b/src/kernel/io.h @@ -12,21 +12,17 @@ static inline uint8_t inb(uint16_t port) unsigned char inb_p(unsigned short port); unsigned short inw(unsigned short port); unsigned short inw_p(unsigned short port); -unsigned int inl(unsigned short port); +uint32_t inl( int port ); unsigned int inl_p(unsigned short port); static inline void outb(uint16_t port, uint8_t val) { asm volatile ( "outb %0, %1" : : "a"(val), "Nd"(port) ); - /* There's an outb %al, $imm8 encoding, for compile-time constant port numbers that fit in 8b. (N constraint). - * Wider immediate constants would be truncated at assemble-time (e.g. "i" constraint). - * The outb %al, %dx encoding is the only option for all other cases. - * %1 expands to %dx because port is a uint16_t. %w1 could be used if we had the port number a wider C type */ } void outb_p(unsigned char value, unsigned short port); void outw(unsigned short value, unsigned short port); void outw_p(unsigned short value, unsigned short port); -void outl(unsigned int value, unsigned short port); +void outl( int port , uint32_t data ); void outl_p(unsigned int value, unsigned short port); void insb(unsigned short port, void *addr, diff --git a/src/kernel/kernel.cpp b/src/kernel/kernel.cpp index d30350d..03654bf 100644 --- a/src/kernel/kernel.cpp +++ b/src/kernel/kernel.cpp @@ -1,15 +1,20 @@ #include "kernel.h" #define GB4 524288 #define GB2 262144 + +int memcmp( const void* ptr1, const void* ptr2, size_t num); + +extern "C" void kernel_main (void); + extern "C" void early_main(unsigned long magic, unsigned long addr){ - /** initialize terminal interface */ + /** initialize terminal interface */ kterm_init(); - + if (magic != MULTIBOOT_BOOTLOADER_MAGIC){ printf("Invalid magic number: 0x%x\n", magic); return; } - + CheckMBT( (multiboot_info_t *) addr); multiboot_info_t* mbt = (multiboot_info_t*) addr; @@ -27,19 +32,83 @@ } initGDT(); + + + + kernel_main(); + } + + int memcmp( const void* ptr1, const void* ptr2, size_t num) + { + const unsigned char * cs = (const unsigned char*) ptr1; + const unsigned char * ct = (const unsigned char*) ptr2; + + + for (int i = 0 ; i < num ; i++, cs++, ct++ ){ + if( *cs < *ct){ + return -1; + } else if( *cs > *ct){ + return 1; + } + } + + return 0; - } extern "C" void kernel_main (void) { printf("call to init serial\n"); init_serial(); + print_serial("Serial port initialized!"); + + // Enumerate the PCI bus + + int devicesFound = 0; + // loop through all possible busses, devices and their functions; + for( int bus = 0 ; bus < 256 ; bus++) + { + + for(int device = 0; device < 32 ; device ++) + { + for ( int function = 0; function < 8; function++) + { + + uint64_t DeviceIdentify = ConfigReadWord(bus, device, function,0x0); + uint32_t VendorID = DeviceIdentify & 0xFFFF; + uint32_t DeviceID = DeviceIdentify >> 16; + + + + if( DeviceID != 0xFFFF){ + printf("bus: %d, device: %d, function %d \n"); + printf("Device found!\n"); + printf("DeviceID: 0x%x, VendorID: 0x%x\n", DeviceID, VendorID); + + uint32_t classcodes = ConfigReadWord(bus, device, function, 0x8); + uint32_t classData = classcodes >> 16; // We only care for the last 2 bytes! + uint32_t deviceClass = classData >> 8; + uint32_t subclass = classData & 0xFF; + + printf(" class: %d, subClass: %d\n\n", deviceClass, subclass); + devicesFound++; + + } + + + + } + + } + + } + + printf("Found %d devices!", devicesFound); while (true){ //Read time indefinetely - read_rtc(); - printf( "UTC time: %02d-%02d-%02d %02d:%02d:%02d [ Formatted as YY-MM-DD h:mm:ss]\r" ,year, month, day, hour, minute, second); + //read_rtc(); + //printf( "UTC time: %02d-%02d-%02d %02d:%02d:%02d [ Formatted as YY-MM-DD h:mm:ss]\r" ,year, month, day, hour, minute, second); delay(1000); } diff --git a/src/kernel/kernel.h b/src/kernel/kernel.h index f82f5da..ff76ffa 100644 --- a/src/kernel/kernel.h +++ b/src/kernel/kernel.h @@ -16,6 +16,8 @@ extern "C"{ #include "time.h" #include "cpu.h" #include "serial.h" +#include "pci.h" + #define CHECK_FLAG(flags, bit) ((flags) & (1 <<(bit))) #define PANIC(message) { return; } diff --git a/src/kernel/pci.cpp b/src/kernel/pci.cpp index 3f81c29..a579fbd 100644 --- a/src/kernel/pci.cpp +++ b/src/kernel/pci.cpp @@ -1,108 +1,28 @@ #include "pci.h" +#include "tty/kterm.h" +#define PCI_BUS_ADDR_SHIFT 16 +#define PCI_DEVICE_ADDR_SHIFT 11 +#define PCI_FUNCTION_ADDR_SHIFT 8 +#define PCI_ENABLE_ADDR_SHIFT 31 -uint16_t ConfigReadWord (uint8_t bus, uint8_t slot, uint8_t func, uint8_t offset){ + + +uint32_t ConfigReadWord (uint8_t bus, uint8_t device, uint8_t func, uint8_t offset){ uint32_t address; - uint32_t lbus = (uint32_t) bus; - uint32_t lslot = (uint32_t) slot; - uint32_t lfunc = (uint32_t) func; - uint16_t tmp = 0; - /* Create configuration address as per Figure 1 */ - address = (uint32_t) ((lbus << 16) | (lslot << 11) | (lfunc << 8) | (offset & 0xFC) |((uint32_t) 0x80000000) ); - /*write out the address */ + address = (uint32_t) ( + ((uint32_t) 1 << PCI_ENABLE_ADDR_SHIFT) | + ((uint32_t)bus << PCI_BUS_ADDR_SHIFT) | + ((uint32_t)device << PCI_DEVICE_ADDR_SHIFT) | + ((uint32_t)func << PCI_FUNCTION_ADDR_SHIFT) | + offset ); + // printf("PCI address read 0x%x", address); + + + outl(CONFIG_ADDRESS, address); - /* read in the data */ - /* (offset & 2 ) * 8 ) = o will choosse the first word of the 32 bits register*/ - tmp = (uint16_t)((inl(CONFIG_DATA)) >> ((offset & 2) * 8) & 0xFFFF); - return (tmp); + + + return inl(CONFIG_DATA); } -uint16_t CheckVendor (uint8_t bus, uint8_t slot) { - uint16_t vendor, device; - /* - Try and read the first configuration register. Since there ar no - vendors that == 0xFFFF, it must be a non-existent device. - */ - if((vendor = ConfigReadWord(bus, slot, 0,0)) != 0xFFFF) { - device = ConfigReadWord(bus, slot, 0,2); - // Possible read more config values ... - } return (vendor); -} - -void checkDevice (uint8_t bus, uint8_t device ) { - uint8_t function = 0; - - uint16_t vendorID = CheckVendor(bus, device); - if (vendorID == 0xFFFF) { - return; - } - - checkFunction (bus, device, function ); - headerType = getHeaderType(bus, device, function ); - if( (headerType & 0x80) != 0) { - /* It is a multi-function device, so check remaining functions */ - for (function = 1; function < 8; function++){ - if (CheckVendor(bus, device)!= 0xFFFF){ - checkFunction(bus, device, function ); - } - } - } - -} - - -void checkFunction (uint8_t bus, uint8_t device, uint8_t function ){ - uint8_t baseClass; - uint8_t subClass; - uint8_t secondaryBus; - - baseClass = getBaseClass(bus, device, function); - subClass = getSubClass (bus, device, function ); - if ( (baseClass == 0x06) && (subClass == 0x04)){ - secondaryBus = getSecondaryBus(bus,device, function); - checkBus(secondaryBus); - } -} - - -// Brute-force scan -void checkAllBuses (){ - uint16_t bus; - uint8_t device; - - for(bus = 0; bus < 256; bus++){ - for(device = 0; device < 32; device++){ - checkDevice(bus,device); - } - } -} - -// Recursive scan -void checkBus (uint8_t bus){ - uint8_t device; - - for(device = 0; device < 32; device ++){ - checkDevice(bus,device); - } -} - -void checkAllBuses(){ - uint8_t function; - uint8_t bus; - - headerType = getHeaderType(0,0,0); - if ( (headerType & 0x80) == 0 ){ - /* Single PCI host controller */ - checkBus(0); - } else{ - /* Multiple PCI host controllers */ - for (function = 0; function < 8; function++){ - if( CheckVendor(0,0) != 0xFFFF) { - break; - } - bus = function; - checkBus(bus); - } - } - -} \ No newline at end of file diff --git a/src/kernel/pci.h b/src/kernel/pci.h index 93b15ce..7f5ed47 100644 --- a/src/kernel/pci.h +++ b/src/kernel/pci.h @@ -5,54 +5,13 @@ #define CONFIG_ADDRESS 0xCF8 // Configuration adress that is to be accessed #define CONFIG_DATA 0xCFC // Will do the actual configuration operation -/* -CONFIG_ADDRESS - -32 bit register - -bit 31 Enable bit (Should CONFIG_DATA be translatedc to configuration cycles) -bit 30 - 24 Reserved -bit 23 - 16 Bus Number (Choose a specific PCI BUS) -bit 15 - 11 Device Number (Selects specific device one the pci bus) -bit 10 - 8 Function Number (Selects a specific function in a device) -bit 7 - 0 Register Offset (Offset in the configuration space of 256 Bytes ) NOTE: lowest two bits will always be zero - -*/ +uint32_t ConfigReadWord (uint8_t bus, uint8_t device, uint8_t func, uint8_t offset); -/* -PCI Device structure +inline uint16_t getVendorID(uint8_t bus, uint8_t device, uint8_t function ){ + return ConfigReadWord ( bus , device, function, 0); +} -Register offset bits 31-24 bits 23-16 bits 15-8 bits 7-0 -00 00 Device ID <---- Vendor ID <------- -01 04 Status <---- Command <------- -02 08 Class code Sub class Prog IF Revision ID -03 0C BIST Header Type Ltncy Timer Cache line Size -04 10 Base address #0 (BAR0) -05 14 Base address #1 (BAR1) -06 18 Base address #2 (BAR2) -07 1C Base address #3 (BAR3) -08 20 Base address #4 (BAR4) -09 24 Base address #5 (BAR5) -0A 28 Cardbus CIS Pointer -0B 2C Subsystem ID <------ Subsystem Vendor ID <------- -0C 30 Expansion ROM base address -0D 34 Reserved <------- Capabilities Pointer <------ -0E 38 Reserved <------- <-------- <-------- -0F 3C Max ltncy Min Grant Interrupt PIN Interrupt Line - -*/ - - -/* -The idea for now is to support the minimal things necessary to find ATA supported drives - */ - - -// Lets write some boiler plate configuration code - -uint16_t ConfigReadWord (uint8_t bus, uint8_t slot, uint8_t func, uint8_t offset); - -uint16_t CheckVendor (uint8_t bus, uint8_t slot); - -void checkDevice (uint8_t bus, uint8_t device ); \ No newline at end of file +inline uint16_t getDeviceID(uint8_t bus, uint8_t device, uint8_t function ){ + return ConfigReadWord(bus, device, function , 16); +} From 5089da5e9e01cc217f8c5533d649296543285215 Mon Sep 17 00:00:00 2001 From: Nigel Date: Sun, 28 Nov 2021 16:46:16 +0100 Subject: [PATCH 02/21] PCI: Improved syntax of PCI enumeration, Added a PCI information storage class and structs --- Makefile | 19 +++- src/kernel/kernel.cpp | 47 +--------- src/kernel/kernel.h | 1 + src/kernel/pci.cpp | 177 ++++++++++++++++++++++++++++++++++- src/kernel/pci.h | 30 ++++-- src/kernel/pci/pciDevice.cpp | 7 ++ src/kernel/pci/pciDevice.h | 36 +++++++ 7 files changed, 264 insertions(+), 53 deletions(-) create mode 100644 src/kernel/pci/pciDevice.cpp create mode 100644 src/kernel/pci/pciDevice.h diff --git a/Makefile b/Makefile index c553ba1..365f8be 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,21 @@ CC = ${HOME}/opt/cross/bin/i686-elf-gcc CPP = ${HOME}/opt/cross/bin/i686-elf-g++ CFLAGS = -ffreestanding -O2 -Wall -Wextra -OFILES = $(BUILD_DIR)/boot.o $(BUILD_DIR)/kterm.o $(BUILD_DIR)/kernel.o $(BUILD_DIR)/PhysicalMemoryManager.o $(BUILD_DIR)/io.o $(BUILD_DIR)/PageDirectory.o $(BUILD_DIR)/gdtc.o $(BUILD_DIR)/idt.o $(BUILD_DIR)/pci.o $(BUILD_DIR)/pic.o $(BUILD_DIR)/string.o +OFILES = \ +$(BUILD_DIR)/boot.o \ +$(BUILD_DIR)/kterm.o \ +$(BUILD_DIR)/kernel.o \ +$(BUILD_DIR)/PhysicalMemoryManager.o \ +$(BUILD_DIR)/io.o \ +$(BUILD_DIR)/PageDirectory.o \ +$(BUILD_DIR)/gdtc.o \ +$(BUILD_DIR)/idt.o \ +$(BUILD_DIR)/pci.o \ +$(BUILD_DIR)/pic.o \ +$(BUILD_DIR)/string.o \ +$(BUILD_DIR)/pcidevice.o + + SRC_DIR = src BUILD_DIR = build @@ -88,3 +102,6 @@ $(BUILD_DIR)/PhysicalMemoryManager.o: $(BUILD_DIR)/pci.o: $(CPP) -c $(SRC_DIR)/kernel/pci.cpp -o $(BUILD_DIR)/pci.o $(CFLAGS) -fno-exceptions -fno-rtti + +$(BUILD_DIR)/pcidevice.o: + $(CPP) -c $(SRC_DIR)/kernel/pci/pciDevice.cpp -o $(BUILD_DIR)/pcidevice.o $(CFLAGS) -fno-exceptions -fno-rtti diff --git a/src/kernel/kernel.cpp b/src/kernel/kernel.cpp index 03654bf..8157292 100644 --- a/src/kernel/kernel.cpp +++ b/src/kernel/kernel.cpp @@ -62,53 +62,16 @@ extern "C" void kernel_main (void); init_serial(); print_serial("Serial port initialized!"); + + // Enumerate the PCI bus - - int devicesFound = 0; - // loop through all possible busses, devices and their functions; - for( int bus = 0 ; bus < 256 ; bus++) - { - - for(int device = 0; device < 32 ; device ++) - { - for ( int function = 0; function < 8; function++) - { - - uint64_t DeviceIdentify = ConfigReadWord(bus, device, function,0x0); - uint32_t VendorID = DeviceIdentify & 0xFFFF; - uint32_t DeviceID = DeviceIdentify >> 16; + PCI_Enumerate(); - - if( DeviceID != 0xFFFF){ - printf("bus: %d, device: %d, function %d \n"); - printf("Device found!\n"); - printf("DeviceID: 0x%x, VendorID: 0x%x\n", DeviceID, VendorID); - - uint32_t classcodes = ConfigReadWord(bus, device, function, 0x8); - uint32_t classData = classcodes >> 16; // We only care for the last 2 bytes! - uint32_t deviceClass = classData >> 8; - uint32_t subclass = classData & 0xFF; - - printf(" class: %d, subClass: %d\n\n", deviceClass, subclass); - devicesFound++; - - } - - - - } - - } - - } - - printf("Found %d devices!", devicesFound); - while (true){ //Read time indefinetely - //read_rtc(); - //printf( "UTC time: %02d-%02d-%02d %02d:%02d:%02d [ Formatted as YY-MM-DD h:mm:ss]\r" ,year, month, day, hour, minute, second); + read_rtc(); + printf( "UTC time: %02d-%02d-%02d %02d:%02d:%02d [ Formatted as YY-MM-DD h:mm:ss]\r" ,year, month, day, hour, minute, second); delay(1000); } diff --git a/src/kernel/kernel.h b/src/kernel/kernel.h index ff76ffa..cb9755a 100644 --- a/src/kernel/kernel.h +++ b/src/kernel/kernel.h @@ -19,6 +19,7 @@ extern "C"{ #include "pci.h" + #define CHECK_FLAG(flags, bit) ((flags) & (1 <<(bit))) #define PANIC(message) { return; } diff --git a/src/kernel/pci.cpp b/src/kernel/pci.cpp index a579fbd..e2d213c 100644 --- a/src/kernel/pci.cpp +++ b/src/kernel/pci.cpp @@ -1,11 +1,119 @@ #include "pci.h" -#include "tty/kterm.h" + #define PCI_BUS_ADDR_SHIFT 16 #define PCI_DEVICE_ADDR_SHIFT 11 #define PCI_FUNCTION_ADDR_SHIFT 8 #define PCI_ENABLE_ADDR_SHIFT 31 +const char* GetClassCodeName (uint64_t ClassCode ) { + + switch (ClassCode) + { + case 0x0 : + return "Unclassified"; + break; + case 0x1: + return "Mass Storage Controller"; + break; + + case 0x2: + return "Network Controller"; + break; + + case 0x3: + return "Display Controller"; + break; + + case 0x4: + return "Multimedia Controller"; + break; + + case 0x5: + return "Memory Controller"; + break; + + case 0x6: + return "Bridge"; + break; + + case 0x7 : + return "Simple Communication Controller"; + break; + + case 0x8: + return "Base System Peripheral"; + break; + + case 0x9: + return "Input Device Controller"; + break; + + case 0xA: + return "Docking station"; + break; + case 0xB: + return "Processor"; + break; + + case 0xC: + return "Serial Bus Controller"; + break; + + case 0xD: + return "Wireless Controller"; + break; + + case 0xE: + return "Intelligent Controller"; + break; + + case 0xF: + return "Satellite Communication Controller"; + break; + + case 0x10: + return "Encryption Controller"; + break; + + case 0x11: + return "Signal Processing Controller"; + break; + + case 0x12: + return "Processing Accelerator"; + break; + + case 0x13: + return "Non-Essential Instrumentation"; + break; + + default: + return "Unknown"; + break; + } + +} + +const char* getVendor( uint64_t VendorID){ + switch (VendorID) + { + case 0x8086: + return "Intel Corporation"; + break; + + default: + return "Vendor Unkown"; + break; + } +} + + + +uint32_t ConfigReadWord ( PCIBusAddress& PCIDeviceAddress , uint8_t offset){ + outl(CONFIG_ADDRESS , PCIDeviceAddress.getAddress() | offset ); + return inl(CONFIG_DATA); +} uint32_t ConfigReadWord (uint8_t bus, uint8_t device, uint8_t func, uint8_t offset){ uint32_t address; @@ -16,9 +124,6 @@ uint32_t ConfigReadWord (uint8_t bus, uint8_t device, uint8_t func, uint8_t offs ((uint32_t)device << PCI_DEVICE_ADDR_SHIFT) | ((uint32_t)func << PCI_FUNCTION_ADDR_SHIFT) | offset ); - // printf("PCI address read 0x%x", address); - - outl(CONFIG_ADDRESS, address); @@ -26,3 +131,67 @@ uint32_t ConfigReadWord (uint8_t bus, uint8_t device, uint8_t func, uint8_t offs return inl(CONFIG_DATA); } + + +uint8_t GetHeaderType( PCIBusAddress& PCIDeviceAddress ){ + uint32_t header_information = ConfigReadWord(PCIDeviceAddress , 0xC); + return (uint8_t) ( + (header_information >> 16) //Get higher half + & 0x00FF ); // Select the last two bytes +} + +uint16_t GetClassCodes( PCIBusAddress& PCIDeviceAddress ){ + uint32_t classcodes = ConfigReadWord(PCIDeviceAddress, 0x8); + return (uint16_t)((uint32_t)classcodes >> 16); + +} + +void PCI_Enumerate(){ + int devicesFound = 0; + // loop through all possible busses, devices and their functions; + for( int bus = 0 ; bus < 256 ; bus++) + { + + for(int device = 0; device < 32 ; device ++) + { + + + int function = 0; + + //uint64_t DeviceIdentify = ConfigReadWord(bus, device, function,0x0); + uint32_t VendorID = GetDevice(bus, device, function) & 0xFFFF; + uint32_t DeviceID = GetDevice(bus, device, function) >> 16; + + + + if( DeviceID != 0xFFFF){ + printf("Device found!\n"); + printf("Bus: %d, Device: %d, function: %d \n", bus, device, function); + printf("DeviceID: 0x%x, VendorID: %s\n", DeviceID, getVendor(VendorID) ); + + // iterate over the functions if it is a multi function device! + if( false ){ + for ( function ++ ; function < 8; function++) + { + + } + } + + PCIBusAddress busAddress = + PCIBusAddress{bus, device, function }; + + uint8_t header_type = GetHeaderType(busAddress); + printf( "Header type: 0x%x\n", header_type); + + uint16_t deviceClasses = GetClassCodes(busAddress); + printf(" class: %s, subClass: %d\n\n", + (deviceClasses >>8) > 0x13 ? "Unknown": GetClassCodeName((deviceClasses >>8)), deviceClasses & 0xFF); + + devicesFound++; + } + } + + } + + printf("Found %d PCI devices!\n", devicesFound); +} diff --git a/src/kernel/pci.h b/src/kernel/pci.h index 7f5ed47..137f950 100644 --- a/src/kernel/pci.h +++ b/src/kernel/pci.h @@ -1,17 +1,35 @@ #pragma once #include #include "io.h" +#include "tty/kterm.h" +#include "pci/pciDevice.h" + // Configuration Space Access Mechanism #1 #define CONFIG_ADDRESS 0xCF8 // Configuration adress that is to be accessed #define CONFIG_DATA 0xCFC // Will do the actual configuration operation +extern const char* ClassCodeTable [0x13]; + + + +// Note: this could be used to make the api for receiving PCI class codes a bit +// nicer. +struct ClassCodes { + uint8_t ClassCode; + uint8_t DeviceClass; +}__attribute__((packed)); + uint32_t ConfigReadWord (uint8_t bus, uint8_t device, uint8_t func, uint8_t offset); +uint32_t ConfigReadWord ( PCIBusAddress& PCIDeviceAddress , uint8_t offset); + inline uint64_t GetDevice (int bus, int device, int function ){ + return ConfigReadWord(bus, device, function,0x0); + } -inline uint16_t getVendorID(uint8_t bus, uint8_t device, uint8_t function ){ - return ConfigReadWord ( bus , device, function, 0); -} +uint8_t GetHeaderType( PCIBusAddress& PCIDeviceAddress ); -inline uint16_t getDeviceID(uint8_t bus, uint8_t device, uint8_t function ){ - return ConfigReadWord(bus, device, function , 16); -} +uint16_t GetClassCodes( PCIBusAddress& PICDeviceAddress ); +const char* getVendor( uint64_t VendorID); +const char* GetClassCodeName (uint64_t ClassCode ); + +void PCI_Enumerate(); \ No newline at end of file diff --git a/src/kernel/pci/pciDevice.cpp b/src/kernel/pci/pciDevice.cpp new file mode 100644 index 0000000..e4507fb --- /dev/null +++ b/src/kernel/pci/pciDevice.cpp @@ -0,0 +1,7 @@ + #include "pciDevice.h" + +// NOTE: we would really like to return a pointer +// to the newly created PCIBusAddress struct; + PCIBusAddress const PCIDevice::PCIAddress(){ + return PCIBusAddress{bus ,device, function}; + } \ No newline at end of file diff --git a/src/kernel/pci/pciDevice.h b/src/kernel/pci/pciDevice.h new file mode 100644 index 0000000..adc52f0 --- /dev/null +++ b/src/kernel/pci/pciDevice.h @@ -0,0 +1,36 @@ +#pragma once +#include + +/* +* PCI devices API +*/ +struct PCIBusAddress{ + + int bus ; + int device ; + int function[8]; + + + uint32_t getAddress( int deviceFunction = 0 ){ + return ((uint32_t) 1 << 31) | + ((uint32_t) bus << 16) | + ((uint32_t) device << 11)| + ((uint32_t) function[deviceFunction] << 8) | + 0x0000; + + }; +}; + +class PCIDevice { + public : + PCIDevice (PCIBusAddress* , int ); + ~PCIDevice(); + PCIBusAddress const PCIAddress(); + + private: + int bus; + int device; + int function; + int headerType; + +}; From 08b97af86318a9f53397154aedbcf6be7a9e149c Mon Sep 17 00:00:00 2001 From: Nigel Date: Sun, 28 Nov 2021 21:07:05 +0100 Subject: [PATCH 03/21] PCI: enumeration code cleanup --- src/kernel/pci.cpp | 105 +++++++++++++++++++++++++++---------- src/kernel/pci/pciDevice.h | 26 +++++++-- 2 files changed, 99 insertions(+), 32 deletions(-) diff --git a/src/kernel/pci.cpp b/src/kernel/pci.cpp index e2d213c..ae5c62c 100644 --- a/src/kernel/pci.cpp +++ b/src/kernel/pci.cpp @@ -95,17 +95,30 @@ const char* GetClassCodeName (uint64_t ClassCode ) { } -const char* getVendor( uint64_t VendorID){ +const char* getVendor( uint32_t VendorID){ switch (VendorID) { - case 0x8086: - return "Intel Corporation"; - break; - - default: - return "Vendor Unkown"; - break; + case 0x8086: + return "Intel Corporation"; + break; + + case 0x10DE: + return "NVIDIA Corporation"; + break; + + case 0x1022: + return "Advanced Micro Devices, Inc.[AMD]"; + break; + + case 0x1002: + return "Advanced Micor Devices, Inc.[AMD/ATI]"; + break; + + default: + return "Vendor Unkown"; + break; } + } @@ -136,8 +149,9 @@ uint32_t ConfigReadWord (uint8_t bus, uint8_t device, uint8_t func, uint8_t offs uint8_t GetHeaderType( PCIBusAddress& PCIDeviceAddress ){ uint32_t header_information = ConfigReadWord(PCIDeviceAddress , 0xC); return (uint8_t) ( - (header_information >> 16) //Get higher half - & 0x00FF ); // Select the last two bytes + ((header_information >> 16) //Get higher half + & 0x00FF) // Select the last two bytes + & 0x7F ); // Mask bit 7 as it indicates if the device is a mulit function device! } uint16_t GetClassCodes( PCIBusAddress& PCIDeviceAddress ){ @@ -146,6 +160,39 @@ uint16_t GetClassCodes( PCIBusAddress& PCIDeviceAddress ){ } +bool IsMultiFunctionDevice(PCIBusAddress& PCIDeviceAddress){ + uint32_t header_information = ConfigReadWord(PCIDeviceAddress, 0xC); + return (((header_information>>16) + & 0x80) + >> 7 ); +} + + + + +void PrintPCIDeviceInfo (PCIBusAddress& PCIDeviceAddress) +{ + uint32_t DeviceID = (GetDevice(PCIDeviceAddress.bus, PCIDeviceAddress.device, PCIDeviceAddress.function) >> 16); + uint32_t VendorID = GetDevice(PCIDeviceAddress.bus, PCIDeviceAddress.device, PCIDeviceAddress.function) & 0xFFFF; + printf("Device found!\n"); + printf("Bus: %d, Device: %d, function: %d \n", PCIDeviceAddress.bus, PCIDeviceAddress.device, PCIDeviceAddress.function); + printf("DeviceID: 0x%x, Vendor: %s\n", + DeviceID + , getVendor(VendorID) ); + + + + + uint8_t header_type = GetHeaderType(PCIDeviceAddress); + printf( "Header type: 0x%x\n", header_type); + + uint16_t deviceClasses = GetClassCodes(PCIDeviceAddress); + printf("class: %s, subClass: %d\n\n", GetClassCodeName((deviceClasses >>8)), deviceClasses & 0xFF); + +} + + + void PCI_Enumerate(){ int devicesFound = 0; // loop through all possible busses, devices and their functions; @@ -159,33 +206,35 @@ void PCI_Enumerate(){ int function = 0; //uint64_t DeviceIdentify = ConfigReadWord(bus, device, function,0x0); - uint32_t VendorID = GetDevice(bus, device, function) & 0xFFFF; uint32_t DeviceID = GetDevice(bus, device, function) >> 16; if( DeviceID != 0xFFFF){ - printf("Device found!\n"); - printf("Bus: %d, Device: %d, function: %d \n", bus, device, function); - printf("DeviceID: 0x%x, VendorID: %s\n", DeviceID, getVendor(VendorID) ); - - // iterate over the functions if it is a multi function device! - if( false ){ - for ( function ++ ; function < 8; function++) - { - - } - } - PCIBusAddress busAddress = PCIBusAddress{bus, device, function }; - uint8_t header_type = GetHeaderType(busAddress); - printf( "Header type: 0x%x\n", header_type); + PrintPCIDeviceInfo(busAddress); + + // iterate over the functions if it is a multi function device! + if( IsMultiFunctionDevice(busAddress) ){ + printf("Multi function device! \n"); + printf("Check remaining Functions\n"); + for ( function = 1 ; function < 8; function++) + { + uint32_t DeviceID = GetDevice(bus, device, function) >> 16; + + if( DeviceID != 0xFFFF){ + PCIBusAddress busAddress2 = PCIBusAddress{bus, device, function}; + PrintPCIDeviceInfo(busAddress2); + devicesFound++; + } + } + + } + + - uint16_t deviceClasses = GetClassCodes(busAddress); - printf(" class: %s, subClass: %d\n\n", - (deviceClasses >>8) > 0x13 ? "Unknown": GetClassCodeName((deviceClasses >>8)), deviceClasses & 0xFF); devicesFound++; } diff --git a/src/kernel/pci/pciDevice.h b/src/kernel/pci/pciDevice.h index adc52f0..9ef88f2 100644 --- a/src/kernel/pci/pciDevice.h +++ b/src/kernel/pci/pciDevice.h @@ -1,6 +1,5 @@ #pragma once #include - /* * PCI devices API */ @@ -8,14 +7,14 @@ struct PCIBusAddress{ int bus ; int device ; - int function[8]; + int function; - uint32_t getAddress( int deviceFunction = 0 ){ + uint32_t getAddress( ){ return ((uint32_t) 1 << 31) | ((uint32_t) bus << 16) | ((uint32_t) device << 11)| - ((uint32_t) function[deviceFunction] << 8) | + ((uint32_t) function << 8) | 0x0000; }; @@ -27,10 +26,29 @@ class PCIDevice { ~PCIDevice(); PCIBusAddress const PCIAddress(); + + inline const char* getDeviceString(){ + return "Not implemented"; //GetClassCodeName(deviceclass); + } + + inline const char* getVendorString(){ + return "Not implemented"; // getVendor(VendorID); + } + + inline void setVendorID (uint16_t id) { + this->VendorID = id; + } + private: int bus; int device; int function; + + uint16_t VendorID; + uint16_t DeviceID; + uint8_t deviceclass; + uint8_t devicesubclass; + int headerType; }; From a36e3d1c16916e836229a06cf10e6487f5fbcf07 Mon Sep 17 00:00:00 2001 From: Nigel Date: Sun, 28 Nov 2021 21:12:12 +0100 Subject: [PATCH 04/21] PCI support checked of on features.md, PCI enumeration screenshot added to readme.md --- README.md | 3 +++ features.md | 2 +- screenshots/PCIBusEnumeration.png | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 screenshots/PCIBusEnumeration.png diff --git a/README.md b/README.md index ee97592..5b50e3c 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,9 @@ W.I.P - Working on interrupt handling ![Multiboot integration](screenshots/multiboot.png) \ Multiboot information can be read by the kernel. + +![PCI enumeration](screenshots/PCIBusEnumeration.png) \ +Enumerating the PCI bus ________________________ ### The goal diff --git a/features.md b/features.md index 53b1cf0..155b5b5 100644 --- a/features.md +++ b/features.md @@ -17,7 +17,7 @@ Enable SIMD Extensions (SSE) ## Other features I am thinking of: - PCI support \ + PCI support \ ATA PIO Mode support \ USTAR Filesystem ( For its simplicity this is very likely the first filesystem the OS is going to support) \ ACPI support ( Or some other basic way to support shutdown, reboot and possibly hibernation ) \ diff --git a/screenshots/PCIBusEnumeration.png b/screenshots/PCIBusEnumeration.png new file mode 100644 index 0000000..cafbf48 --- /dev/null +++ b/screenshots/PCIBusEnumeration.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3873ae8e4e291661ae99310cf26ed6b51462a3434142423b55652e63efd96c79 +size 17146 From 72438ae70dabc0739dd5107892ecf1c57489114b Mon Sep 17 00:00:00 2001 From: Nigel Date: Sun, 28 Nov 2021 23:06:21 +0100 Subject: [PATCH 05/21] Makefile: Added ISO test option for qemu. --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index 365f8be..ada8e52 100644 --- a/Makefile +++ b/Makefile @@ -52,6 +52,9 @@ iso: clean_iso clean build test: $(EMULATOR) -kernel $(BUILD_DIR)/myos.bin -serial stdio -vga std -display gtk -m 2G -cpu core2duo +test_iso: + $(EMULATOR) -cdrom $(BUILD_DIR)/barinkOS.iso -serial stdio -vga std -display gtk -m 2G -cpu core2duo + build_kernel: $(OBJ_LINK_LIST) $(CC) -T $(SRC_DIR)/kernel//linker.ld -o $(BUILD_DIR)/myos.bin \ -ffreestanding -O2 -nostdlib $(OBJ_LINK_LIST) -lgcc From 5a68f77b33259c8cc25e9b576e0a2c603446656b Mon Sep 17 00:00:00 2001 From: Nigel Date: Mon, 29 Nov 2021 20:00:28 +0100 Subject: [PATCH 06/21] Started the base implementation for PCI IDE drivers --- src/kernel/ide/ide.h | 95 ++++++++++ src/kernel/ide/ideCommands.h | 86 +++++++++ src/kernel/ide/sampleIDE.definitions.h | 25 +++ src/kernel/ide/sampleIDE.h | 241 +++++++++++++++++++++++++ src/kernel/kernel.cpp | 6 +- src/kernel/kernel.h | 4 +- src/kernel/pci.cpp | 19 +- src/kernel/pci.h | 5 +- 8 files changed, 469 insertions(+), 12 deletions(-) create mode 100644 src/kernel/ide/ide.h create mode 100644 src/kernel/ide/ideCommands.h create mode 100644 src/kernel/ide/sampleIDE.definitions.h create mode 100644 src/kernel/ide/sampleIDE.h diff --git a/src/kernel/ide/ide.h b/src/kernel/ide/ide.h new file mode 100644 index 0000000..776915f --- /dev/null +++ b/src/kernel/ide/ide.h @@ -0,0 +1,95 @@ +#pragma once +#include +#include "../pci/pciDevice.h" +#include "../tty/kterm.h" +#include "ideCommands.h" +#include "sampleIDE.h" + +#define IS_BIT_SET(x, bit) ((x >> bit & 0x1) == 1) + + +inline void CheckProgIF(uint8_t ProgIF){ + if( IS_BIT_SET(ProgIF, 0) ) // Is the 0th bit set + { + printf ("Primary Channel is in PCI native mode\n"); + } else{ + printf("Primary Channel is in Compatibility mode\n"); + } + + if( IS_BIT_SET(ProgIF, 1)){ + printf("Bit 0 can be modified\n"); + }else{ + printf("Bit 0 cannot be modified\n"); + } + + if( IS_BIT_SET(ProgIF, 2)){ + printf("Secondary channel is in PCI native mode\n"); + }else{ + printf("Secondary channel is in Compatibility mode\n"); + } + + if( IS_BIT_SET(ProgIF, 3)){ + printf("Bit 2 can be modified\n"); + }else{ + printf("Bit 2 cannot be modified\n"); + } + + + if( IS_BIT_SET(ProgIF , 7)){ + printf("This is a bus master IDE Controller\n"); + } else{ + printf("This controller doesn't support DMA!\n"); + } + +} + +inline void TestIDEController(){ + // Do stuff + printf("Testing IDE controllers\n"); + + // NOTE: Testing done with a hard coded known PCI addres + // Of an intel PIIX3 IDE Controller + int bus = 0; + int device =1 , function = 1; + PCIBusAddress IDEControllerPCIAddress = PCIBusAddress{bus,device, function}; + + uint8_t ProgIF = GetProgIF(IDEControllerPCIAddress); + printf( "ProgIF: 0x%x\n" ,ProgIF); + + //CheckProgIF(ProgIF); + + // For this test will just assume all bits are set + // the CheckProgIF can check but on the test machine all bits are set anyways + + uint32_t BAR0,BAR1,BAR2,BAR3, BAR4; + + BAR0 = ReadBAR(IDEControllerPCIAddress, 0); + + BAR1 = ReadBAR(IDEControllerPCIAddress, 1); + + BAR2 = ReadBAR(IDEControllerPCIAddress, 2); + + BAR3 = ReadBAR(IDEControllerPCIAddress, 3); + + BAR4 = ReadBAR(IDEControllerPCIAddress, 4); + + // All bars are return 0xffffff for some as of yet mysterious reason! + printf( "BAR 0: 0x%x\n", BAR0); + + printf( "BAR 1: 0x%x\n", BAR1); + + printf( "BAR 2: 0x%x\n", BAR2); + + printf( "BAR 3: 0x%x\n", BAR3); + + printf( "BAR 4: 0x%x\n", BAR4); + + init_IDE(BAR0, BAR1, BAR2, BAR3, BAR4); + + // Read Something from disc + unsigned int maxByteCount = 20 ; + void* MDA_buffer = (void*)0xC0000000; + + + +} diff --git a/src/kernel/ide/ideCommands.h b/src/kernel/ide/ideCommands.h new file mode 100644 index 0000000..584756e --- /dev/null +++ b/src/kernel/ide/ideCommands.h @@ -0,0 +1,86 @@ +#pragma once + +// Commands +#define ATA_CMD_READ_PIO 0x20 +#define ATA_CMD_READ_PIO_EXT 0x24 +#define ATA_CMD_READ_DMA 0xC8 +#define ATA_CMD_READ_DMA_EXT 0x25 +#define ATA_CMD_WRITE_PIO 0x30 +#define ATA_CMD_WRITE_PIO_EXT 0x34 +#define ATA_CMD_WRITE_DMA 0xCA +#define ATA_CMD_WRITE_DMA_EXT 0x35 +#define ATA_CMD_CACHE_FLUSH 0xE7 +#define ATA_CMD_CACHE_FLUSH_EXT 0xEA +#define ATA_CMD_PACKET 0xA0 +#define ATA_CMD_IDENTIFY_PACKET 0xA1 +#define ATA_CMD_IDENTIFY 0xEC + +#define ATAPI_CMD_READ 0xA8 +#define ATAPI_CMD_EJECT 0x1B + +#define ATA_IDENT_DEVICETYPE 0 +#define ATA_IDENT_CYLINDERS 2 +#define ATA_IDENT_HEADS 6 +#define ATA_IDENT_SECTORS 12 +#define ATA_IDENT_SERIAL 20 +#define ATA_IDENT_MODEL 54 +#define ATA_IDENT_CAPABILITIES 98 +#define ATA_IDENT_FIELDVALID 106 +#define ATA_IDENT_MAX_LBA 120 +#define ATA_IDENT_COMMANDSETS 164 +#define ATA_IDENT_MAX_LBA_EXT 200 + +#define IDE_ATA 0x00 +#define IDE_ATAPI 0x01 + +#define ATA_MASTER 0x00 +#define ATA_SLAVE 0x01 + + +#define ATA_REG_DATA 0x00 +#define ATA_REG_ERROR 0x01 +#define ATA_REG_FEATURES 0x01 +#define ATA_REG_SECCOUNT0 0x02 +#define ATA_REG_LBA0 0x03 +#define ATA_REG_LBA1 0x04 +#define ATA_REG_LBA2 0x05 +#define ATA_REG_HDDEVSEL 0x06 +#define ATA_REG_COMMAND 0x07 +#define ATA_REG_STATUS 0x07 +#define ATA_REG_SECCOUNT1 0x08 +#define ATA_REG_LBA3 0x09 +#define ATA_REG_LBA4 0x0A +#define ATA_REG_LBA5 0x0B +#define ATA_REG_CONTROL 0x0C +#define ATA_REG_ALTSTATUS 0x0C +#define ATA_REG_DEVADDRESS 0x0D + +// Channels: +#define ATA_PRIMARY 0x00 +#define ATA_SECONDARY 0x01 + +// Directions: +#define ATA_READ 0x00 +#define ATA_WRITE 0x01 + + +// Status +#define ATA_SR_BSY 0x80 // Busy +#define ATA_SR_DRDY 0x40 // Drive ready +#define ATA_SR_DF 0x20 // Drive write fault +#define ATA_SR_DSC 0x10 // Drive seek complete +#define ATA_SR_DRQ 0x08 // Data request ready +#define ATA_SR_CORR 0x04 // Corrected data +#define ATA_SR_IDX 0x02 // Index +#define ATA_SR_ERR 0x01 // Error + + +// Errors +#define ATA_ER_BBK 0x80 // Bad block +#define ATA_ER_UNC 0x40 // Uncorrectable data +#define ATA_ER_MC 0x20 // Media changed +#define ATA_ER_IDNF 0x10 // ID mark not found +#define ATA_ER_MCR 0x08 // Media change request +#define ATA_ER_ABRT 0x04 // Command aborted +#define ATA_ER_TK0NF 0x02 // Track 0 not found +#define ATA_ER_AMNF 0x01 // No address mark \ No newline at end of file diff --git a/src/kernel/ide/sampleIDE.definitions.h b/src/kernel/ide/sampleIDE.definitions.h new file mode 100644 index 0000000..d24f62f --- /dev/null +++ b/src/kernel/ide/sampleIDE.definitions.h @@ -0,0 +1,25 @@ +#pragma once + +struct IDEChannelRegisters{ + unsigned short base; // I/O Base. + unsigned short ctrl; // Control Base + unsigned short bmide; // Bus Master IDE + unsigned char nIEN; // IEN (no interrupt) +}channels[2]; + +extern unsigned char ide_buf[2048]; +extern unsigned char ide_irq_invoked; +extern unsigned char atapi_packet[12]; + +struct IDE_DEVICE { + unsigned char Reserved; // 0 (Empty) or 1 (This device exists). + unsigned char Channel; // 0 (Primary Channel) or 1 (Secondary Channel). + unsigned char Drive; // 0 (Master Drive) or 1 (Slave Drive). + unsigned short Type; // 0 ATA, 1:ATAPI + unsigned short Signature; // Drive Signature + unsigned short Capabilities; // Features. + unsigned int CommandSets; // Command Sets Supported. + unsigned int Size; // Size in Sectors + unsigned char Model[41]; // Model in string. +} ide_devices[4]; + diff --git a/src/kernel/ide/sampleIDE.h b/src/kernel/ide/sampleIDE.h new file mode 100644 index 0000000..19a7baf --- /dev/null +++ b/src/kernel/ide/sampleIDE.h @@ -0,0 +1,241 @@ +#pragma once +#include +#include "../tty/kterm.h" +#include "sampleIDE.definitions.h" +#include "ideCommands.h" + +void Detect_IO_Ports(uint32_t BAR0, uint32_t BAR1,uint32_t BAR2, uint32_t BAR3, uint32_t BAR4); +void DetectDevices(); + +unsigned char ide_buf[2048] = {0}; +unsigned char ide_irq_invoked = 0; +unsigned char atapi_packet[12] = {0xA8,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + +void wait(int t){ + volatile int i,j; + for(i=0;i 0x07 && reg < 0x0C) + ide_write(channel, ATA_REG_CONTROL, 0x80 | channels[channel].nIEN); + if (reg < 0x08) + outb(channels[channel].base + reg - 0x00, data); + else if (reg < 0x0C) + outb(channels[channel].base + reg - 0x06, data); + else if (reg < 0x0E) + outb(channels[channel].ctrl + reg - 0x0A, data); + else if (reg < 0x16) + outb(channels[channel].bmide + reg - 0x0E, data); + if (reg > 0x07 && reg < 0x0C) + ide_write(channel, ATA_REG_CONTROL, channels[channel].nIEN); +} + +unsigned char ide_read(unsigned char channel, unsigned char reg){ + unsigned char result; + if( reg > 0x07 && reg < 0x0C) + ide_write(channel,ATA_REG_CONTROL, 0x80 | channels[channel].nIEN); + if( reg < 0x08) + result = inb(channels[channel].base + reg - 0x00); + else if (reg < 0x0C) + result = inb(channels[channel].base + reg - 0x06); + else if (reg < 0x0E) + result = inb(channels[channel].ctrl + reg - 0x0A); + else if (reg < 0x16) + result = inb(channels[channel].bmide + reg - 0x0E); + if (reg > 0x07 && reg < 0x0C) + ide_write(channel, ATA_REG_CONTROL, channels[channel].nIEN); + return result; +} + +void ide_read_buffer(unsigned char channel, unsigned char reg, unsigned int buffer, unsigned int quads){ + if (reg > 0x07 && reg < 0x0C) + ide_write(channel, ATA_REG_CONTROL, 0x80 | channels[channel].nIEN); + if (reg < 0x08) + insl(channels[channel].base + reg - 0x00, (void *)buffer, quads); + else if (reg < 0x0C) + insl(channels[channel].base + reg - 0x06, (void *)buffer, quads); + else if (reg < 0x0E) + insl(channels[channel].ctrl + reg - 0x0A, (void *)buffer, quads); + else if (reg < 0x16) + insl(channels[channel].bmide + reg - 0x0E, (void *)buffer, quads); + if (reg > 0x07 && reg < 0x0C) + ide_write(channel, ATA_REG_CONTROL, channels[channel].nIEN); +} + +unsigned char ide_polling(unsigned char channel, unsigned int advanced_check) { + + // (I) Delay 400 nanosecond for BSY to be set: + // ------------------------------------------------- + for(int i = 0; i < 4; i++) + ide_read(channel, ATA_REG_ALTSTATUS); // Reading the Alternate Status port wastes 100ns; loop four times. + + // (II) Wait for BSY to be cleared: + // ------------------------------------------------- + while (ide_read(channel, ATA_REG_STATUS) & ATA_SR_BSY) + ; // Wait for BSY to be zero. + + if (advanced_check) { + unsigned char state = ide_read(channel, ATA_REG_STATUS); // Read Status Register. + + // (III) Check For Errors: + // ------------------------------------------------- + if (state & ATA_SR_ERR) + return 2; // Error. + + // (IV) Check If Device fault: + // ------------------------------------------------- + if (state & ATA_SR_DF) + return 1; // Device Fault. + + // (V) Check DRQ: + // ------------------------------------------------- + // BSY = 0; DF = 0; ERR = 0 so we should check for DRQ now. + if ((state & ATA_SR_DRQ) == 0) + return 3; // DRQ should be set + + } + + return 0; // No Error. + +} + +unsigned char ide_print_error(unsigned int drive, unsigned char err) { + if (err == 0) + return err; + + printf("IDE:"); + if (err == 1) {printf("- Device Fault\n "); err = 19;} + else if (err == 2) { + unsigned char st = ide_read(ide_devices[drive].Channel, ATA_REG_ERROR); + if (st & ATA_ER_AMNF) {printf("- No Address Mark Found\n "); err = 7;} + if (st & ATA_ER_TK0NF) {printf("- No Media or Media Error\n "); err = 3;} + if (st & ATA_ER_ABRT) {printf("- Command Aborted\n "); err = 20;} + if (st & ATA_ER_MCR) {printf("- No Media or Media Error\n "); err = 3;} + if (st & ATA_ER_IDNF) {printf("- ID mark not Found\n "); err = 21;} + if (st & ATA_ER_MC) {printf("- No Media or Media Error\n "); err = 3;} + if (st & ATA_ER_UNC) {printf("- Uncorrectable Data Error\n "); err = 22;} + if (st & ATA_ER_BBK) {printf("- Bad Sectors\n "); err = 13;} + } else if (err == 3) {printf("- Reads Nothing\n "); err = 23;} + else if (err == 4) {printf("- Write Protected\n "); err = 8;} + printf("- [%s %s] %s\n", + (const char *[]){"Primary", "Secondary"}[ide_devices[drive].Channel], // Use the channel as an index into the array + (const char *[]){"Master", "Slave"}[ide_devices[drive].Drive], // Same as above, using the drive + ide_devices[drive].Model); + + return err; +} + + +inline void init_IDE( uint32_t BAR0, uint32_t BAR1,uint32_t BAR2, uint32_t BAR3, uint32_t BAR4) +{ + Detect_IO_Ports( BAR0, BAR1, BAR2, BAR3, BAR4); + + printf("ATA Primary port, base: 0x%x, ctrl: 0x%x\n", channels[ATA_PRIMARY].base , channels[ATA_PRIMARY].ctrl); + printf("ATA Secondary port, base: 0x%x, ctrl: 0x%x\n", channels[ATA_SECONDARY].base , channels[ATA_SECONDARY].ctrl); + + // 2- Disable IRQs: + ide_write(ATA_PRIMARY , ATA_REG_CONTROL, 2); + ide_write(ATA_SECONDARY, ATA_REG_CONTROL, 2); + + DetectDevices(); + + // 4- Print Summary: + for (int i = 0; i < 4; i++) + if (ide_devices[i].Reserved == 1) { + printf(" Found %s Drive %d bytes - %x\n", + (const char *[]){"ATA", "ATAPI"}[ide_devices[i].Type], /* Type */ + ide_devices[i].Size / 2, /* Size */ + ide_devices[i].Model); + } +} + + +// 3- Detect ATA-ATAPI Devices: +void DetectDevices(){ + int i, j, k, count = 0; + + for (i = 0; i < 2; i++) + for (j = 0; j < 2; j++) { + + unsigned char err = 0, type = IDE_ATA, status; + ide_devices[count].Reserved = 0; // Assuming that no drive here. + + // (I) Select Drive: + ide_write(i, ATA_REG_HDDEVSEL, 0xA0 | (j << 4)); // Select Drive. + wait(1000); // Wait 1ms for drive select to work. + + // (II) Send ATA Identify Command: + ide_write(i, ATA_REG_COMMAND, ATA_CMD_IDENTIFY); + wait(1000); + + // (III) Polling: + if (ide_read(i, ATA_REG_STATUS) == 0) continue; // If Status = 0, No Device. + + while(1) { + status = ide_read(i, ATA_REG_STATUS); + if ((status & ATA_SR_ERR)) {err = 1; break;} // If Err, Device is not ATA. + if (!(status & ATA_SR_BSY) && (status & ATA_SR_DRQ)) break; // Everything is right. + } + + // (IV) Probe for ATAPI Devices: + if (err != 0) { + unsigned char cl = ide_read(i, ATA_REG_LBA1); + unsigned char ch = ide_read(i, ATA_REG_LBA2); + + if (cl == 0x14 && ch ==0xEB) + type = IDE_ATAPI; + else if (cl == 0x69 && ch == 0x96) + type = IDE_ATAPI; + else + continue; // Unknown Type (may not be a device). + + ide_write(i, ATA_REG_COMMAND, ATA_CMD_IDENTIFY_PACKET); + wait(1000); + } + + // (V) Read Identification Space of the Device: + ide_read_buffer(i, ATA_REG_DATA, (unsigned int) ide_buf, 128); + + // (VI) Read Device Parameters: + ide_devices[count].Reserved = 1; + ide_devices[count].Type = type; + ide_devices[count].Channel = i; + ide_devices[count].Drive = j; + ide_devices[count].Signature = *((unsigned short *)(ide_buf + ATA_IDENT_DEVICETYPE)); + ide_devices[count].Capabilities = *((unsigned short *)(ide_buf + ATA_IDENT_CAPABILITIES)); + ide_devices[count].CommandSets = *((unsigned int *)(ide_buf + ATA_IDENT_COMMANDSETS)); + + // (VII) Get Size: + if (ide_devices[count].CommandSets & (1 << 26)) + // Device uses 48-Bit Addressing: + ide_devices[count].Size = *((unsigned int *)(ide_buf + ATA_IDENT_MAX_LBA_EXT)); + else + // Device uses CHS or 28-bit Addressing: + ide_devices[count].Size = *((unsigned int *)(ide_buf + ATA_IDENT_MAX_LBA)); + + // (VIII) String indicates model of device (like Western Digital HDD and SONY DVD-RW...): + for(k = 0; k < 40; k += 2) { + ide_devices[count].Model[k] = ide_buf[ATA_IDENT_MODEL + k + 1]; + ide_devices[count].Model[k + 1] = ide_buf[ATA_IDENT_MODEL + k];} + ide_devices[count].Model[40] = 0; // Terminate String. + + count++; + } +} + + +void Detect_IO_Ports(uint32_t BAR0, uint32_t BAR1,uint32_t BAR2, uint32_t BAR3, uint32_t BAR4){ + // 1 Detect I/O Ports which interface an IDE Controller + + // Based on the implementation within serenity + channels[ATA_PRIMARY].base = (BAR0 == 0x1 || BAR0 == 0x0) ? 0x1F0 : BAR0 & (~1); + channels[ATA_PRIMARY ].ctrl = (BAR1 == 0x1 || BAR1 == 0x0) ? 0x3F6 : BAR1 & (~1); + channels[ATA_SECONDARY].base = (BAR2 == 0x1 || BAR2 == 0x0) ? 0x170 : BAR2 & (~1); + channels[ATA_SECONDARY].ctrl = (BAR3 == 0x1 || BAR3 == 0x0) ? 0x376 : BAR3 & (~1); + channels[ATA_PRIMARY ].bmide = (BAR4 & (~1)) + 0; // Bus Master IDE + channels[ATA_SECONDARY].bmide = (BAR4 & (~1)) + 8; // Bus Master IDE + +} \ No newline at end of file diff --git a/src/kernel/kernel.cpp b/src/kernel/kernel.cpp index 8157292..d558d6d 100644 --- a/src/kernel/kernel.cpp +++ b/src/kernel/kernel.cpp @@ -65,7 +65,11 @@ extern "C" void kernel_main (void); // Enumerate the PCI bus - PCI_Enumerate(); + PCI_Enumerate(); + + + + TestIDEController(); while (true){ diff --git a/src/kernel/kernel.h b/src/kernel/kernel.h index cb9755a..240a57f 100644 --- a/src/kernel/kernel.h +++ b/src/kernel/kernel.h @@ -2,6 +2,8 @@ extern "C"{ #include "../libc/include/string.h" } + + #include "vga/VBE.h" #include "tty/kterm.h" @@ -17,7 +19,7 @@ extern "C"{ #include "cpu.h" #include "serial.h" #include "pci.h" - +#include "ide/ide.h" #define CHECK_FLAG(flags, bit) ((flags) & (1 <<(bit))) diff --git a/src/kernel/pci.cpp b/src/kernel/pci.cpp index ae5c62c..c7ba0ac 100644 --- a/src/kernel/pci.cpp +++ b/src/kernel/pci.cpp @@ -121,8 +121,6 @@ const char* getVendor( uint32_t VendorID){ } - - uint32_t ConfigReadWord ( PCIBusAddress& PCIDeviceAddress , uint8_t offset){ outl(CONFIG_ADDRESS , PCIDeviceAddress.getAddress() | offset ); return inl(CONFIG_DATA); @@ -144,8 +142,6 @@ uint32_t ConfigReadWord (uint8_t bus, uint8_t device, uint8_t func, uint8_t offs return inl(CONFIG_DATA); } - - uint8_t GetHeaderType( PCIBusAddress& PCIDeviceAddress ){ uint32_t header_information = ConfigReadWord(PCIDeviceAddress , 0xC); return (uint8_t) ( @@ -167,9 +163,6 @@ bool IsMultiFunctionDevice(PCIBusAddress& PCIDeviceAddress){ >> 7 ); } - - - void PrintPCIDeviceInfo (PCIBusAddress& PCIDeviceAddress) { uint32_t DeviceID = (GetDevice(PCIDeviceAddress.bus, PCIDeviceAddress.device, PCIDeviceAddress.function) >> 16); @@ -191,8 +184,6 @@ void PrintPCIDeviceInfo (PCIBusAddress& PCIDeviceAddress) } - - void PCI_Enumerate(){ int devicesFound = 0; // loop through all possible busses, devices and their functions; @@ -244,3 +235,13 @@ void PCI_Enumerate(){ printf("Found %d PCI devices!\n", devicesFound); } + +uint8_t GetProgIF (PCIBusAddress& PCIDeviceAddress){ + uint32_t data = ConfigReadWord(PCIDeviceAddress, 0x8); + return ((data >> 8) & 0xFF); +} + +uint32_t ReadBAR ( PCIBusAddress& PCIDeviceAddress, int bar_number){ + int offsetToBar = 0x10 + (bar_number* 0x4); + return ConfigReadWord(PCIDeviceAddress, offsetToBar); +} \ No newline at end of file diff --git a/src/kernel/pci.h b/src/kernel/pci.h index 137f950..fdfe5f2 100644 --- a/src/kernel/pci.h +++ b/src/kernel/pci.h @@ -32,4 +32,7 @@ uint16_t GetClassCodes( PCIBusAddress& PICDeviceAddress ); const char* getVendor( uint64_t VendorID); const char* GetClassCodeName (uint64_t ClassCode ); -void PCI_Enumerate(); \ No newline at end of file +uint8_t GetProgIF (PCIBusAddress& PCIDeviceAddress); +void PCI_Enumerate(); + +uint32_t ReadBAR ( PCIBusAddress& PCIDeviceAddress, int bar_number); \ No newline at end of file From 2db83b33e1166ea25e509f614767becfe3029099 Mon Sep 17 00:00:00 2001 From: Nigel Date: Wed, 1 Dec 2021 00:00:45 +0100 Subject: [PATCH 07/21] ATAPI can identify a device correctly --- Makefile | 6 +- README.md | 4 + screenshots/CD-ROM_Identify.png | 3 + src/kernel/drivers/ata/ataDevice.cpp | 131 ++++++++++++++++++++ src/kernel/drivers/ata/ataDevice.h | 29 +++++ src/kernel/drivers/atapi/atapiDevice.cpp | 145 +++++++++++++++++++++++ src/kernel/drivers/atapi/atapiDevice.h | 29 +++++ src/kernel/ide/ide.h | 2 + src/kernel/ide/sampleIDE.definitions.h | 16 ++- src/kernel/kernel.cpp | 27 +++++ src/kernel/kernel.h | 2 + 11 files changed, 387 insertions(+), 7 deletions(-) create mode 100644 screenshots/CD-ROM_Identify.png create mode 100644 src/kernel/drivers/ata/ataDevice.cpp create mode 100644 src/kernel/drivers/ata/ataDevice.h create mode 100644 src/kernel/drivers/atapi/atapiDevice.cpp create mode 100644 src/kernel/drivers/atapi/atapiDevice.h diff --git a/Makefile b/Makefile index ada8e52..7f3f9a4 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,8 @@ $(BUILD_DIR)/idt.o \ $(BUILD_DIR)/pci.o \ $(BUILD_DIR)/pic.o \ $(BUILD_DIR)/string.o \ -$(BUILD_DIR)/pcidevice.o +$(BUILD_DIR)/pcidevice.o \ +$(BUILD_DIR)/atapiDevice.o @@ -108,3 +109,6 @@ $(BUILD_DIR)/pci.o: $(BUILD_DIR)/pcidevice.o: $(CPP) -c $(SRC_DIR)/kernel/pci/pciDevice.cpp -o $(BUILD_DIR)/pcidevice.o $(CFLAGS) -fno-exceptions -fno-rtti + +$(BUILD_DIR)/atapiDevice.o: + $(CPP) -c $(SRC_DIR)/kernel/drivers/atapi/atapiDevice.cpp -o $(BUILD_DIR)/atapiDevice.o $(CFLAGS) -fno-exceptions -fno-rtti diff --git a/README.md b/README.md index 5b50e3c..1cd6063 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,10 @@ Multiboot information can be read by the kernel. ![PCI enumeration](screenshots/PCIBusEnumeration.png) \ Enumerating the PCI bus + +![ATAPI CD-ROM Identification](screenshots/CD-ROM_Identify.png) \ +Correctly identified our ATAPI device 🎉 + ________________________ ### The goal diff --git a/screenshots/CD-ROM_Identify.png b/screenshots/CD-ROM_Identify.png new file mode 100644 index 0000000..586d2ee --- /dev/null +++ b/screenshots/CD-ROM_Identify.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a49af346df5f591fd139ebda79fbb80e9d79b1db2697bc8e037ccc6955e69959 +size 58517 diff --git a/src/kernel/drivers/ata/ataDevice.cpp b/src/kernel/drivers/ata/ataDevice.cpp new file mode 100644 index 0000000..bd5f7d1 --- /dev/null +++ b/src/kernel/drivers/ata/ataDevice.cpp @@ -0,0 +1,131 @@ +#include "atapiDevice.h" +#define IS_BIT_SET(x, bit) ((x >> bit & 0x1) == 1) + +void ATA_DEVICE::Soft_Reset(uint8_t DEVICE_CHANNEL,DEVICE_DRIVE drive){ + printf("Soft reseting drive...\n"); + outb(channels[DEVICE_CHANNEL].base + 7 , 0x4); + // wait a bit.. + for(int i = 0 ; i < 1000000; i++){ + asm volatile("NOP"); + } + outb(channels[DEVICE_CHANNEL].base + 7 , 0x0); + +} + + +void ATA_DEVICE::Identify(uint8_t DEVICE_CHANNEL,DEVICE_DRIVE drive ){ + // lets ignore which port we actually want to check for now ! + + /* + THE STEPS INVOLVED + + 1. Select the target drive by sending master (0x0A) or slave (0x0B) to the + drive select IO port + + 2. Set the Sectorcount, LBAlo, LBAmid and LBAhi IO ports to 0 + + 3. Send the identify command (0xEC) to the command IO port + + 4. Read the status port + 4.2 If the value is 0x0 the drive does not exist + 4.3 If it has any other value continue + 5. poll the status port until bit 7 is clear. + 6. Check if the LBAmid and LBAhi ports are non-zero + 6.2. If non-zero stop polling this is not an ATA device + 6.3 If zero continue + + 7. poll status port until bit 3 is set or bit 0 is set + + 8. if err is clear, read the data from the data port + + + */ + + + // Assuming Master here + // Select the target drive + outb(0x176, 0x0A); // on the primary bus select the master drive + + // Set the Sectorcount, LBAlo, LBAmid and LBAhi IO ports to 0 + outb(0x172, 0); + + outb(0x173, 0); + + outb(0x174, 0); + + outb(0x175, 0); + + // send the identify command; + outb(0x177, 0xA1); + + // read the status port + uint8_t status = inb(0x177); + if( status == 0x00){ + printf("No drive\n"); + return; + } + + while(true){ + status = inb(0x177); + + if( status & (~8)) + break; + } + + printf("Is this an ATA device?\n"); + uint8_t LBAmid = inb(0x174); + uint8_t LBAhi = inb(0x175); + + printf("LBAmid: 0x%x, LBAhi: 0x%x\n", LBAmid, LBAhi); + + + if( LBAhi != 0x0 || LBAmid != 0x0){ + printf("Not ATA device.. Stopping..\n"); + // return; + } + + while(true){ + status = inb(0x177); + printf( "Status bit: 0x%x\n", status); + if ( IS_BIT_SET(status, 3)){ + printf("Status: ready!\n"); + break; + + } + + if( IS_BIT_SET(status, 0)){ + printf("Status: error!\n"); + break; + } + } + + if( IS_BIT_SET(status, 0) == false){ + // READ DATA + + uint16_t deviceIdentify [256]; + + for (int i= 0; i < 256; i++){ + uint8_t data = inb(0x170); + uint8_t data2 = inb(0x170); + + deviceIdentify[i] = (uint16_t) ( (uint16_t) data << 8 | (uint16_t) data2 ); + + } + + + printf("Data received!\n"); + } + + printf("Error bit was set!\n"); + + +} + + +void ATA_DEVICE::Read(uint8_t DEVICE_CHANNEL, DEVICE_DRIVE drive) { + printf("Not implemented"); +} + +void ATA_DEVICE::Write(uint8_t DEVICE_CHANNEL, DEVICE_DRIVE drive) { + printf("Not implemented"); +} \ No newline at end of file diff --git a/src/kernel/drivers/ata/ataDevice.h b/src/kernel/drivers/ata/ataDevice.h new file mode 100644 index 0000000..cccefa4 --- /dev/null +++ b/src/kernel/drivers/ata/ataDevice.h @@ -0,0 +1,29 @@ +#pragma once +#include +#include "../io.h" +#include "../ide/ideCommands.h" +#include "../ide/sampleIDE.definitions.h" + +#include "../tty/kterm.h" + +/* +* This first driver wil make use of IO ports. +* Doing so means reading or writing from disk is going +* to be very cpu intensive. +* +*/ + +enum DEVICE_DRIVE{ + MASTER = 0xA0, + SLAVE = 0xB0 +}; + + +namespace ATA_DEVICE +{ + void Identify ( uint8_t, DEVICE_DRIVE ); + void Read ( uint8_t, DEVICE_DRIVE ); + void Write ( uint8_t, DEVICE_DRIVE ); + void Soft_Reset ( uint8_t, DEVICE_DRIVE ); + +}; diff --git a/src/kernel/drivers/atapi/atapiDevice.cpp b/src/kernel/drivers/atapi/atapiDevice.cpp new file mode 100644 index 0000000..e619680 --- /dev/null +++ b/src/kernel/drivers/atapi/atapiDevice.cpp @@ -0,0 +1,145 @@ +#include "atapiDevice.h" +#define IS_BIT_SET(x, bit) ((x >> bit & 0x1) == 1) + +bool isPacketDevice(){ + + uint8_t LBAmid = inb(0x174); + uint8_t LBAhi = inb(0x175); + + printf(" LBAmid: 0x%x, LBAhi: 0x%x"); + return LBAmid == 0x14 && LBAhi == 0xEB; + +} + + +void ATAPI_DEVICE::Identify(uint8_t DEVICE_CHANNEL,DEVICE_DRIVE drive ){ + // lets ignore which port we actually want to check for now ! + + /* THE STEPS INVOLVED + + 1. Select the target drive by sending master (0x0A) or slave (0x0B) to the + drive select IO port + + 2. Set the Sectorcount, LBAlo, LBAmid and LBAhi IO ports to 0 + + 3. Send the identify command (0xEC) to the command IO port + + 4. Read the status port + 4.2 If the value is 0x0 the drive does not exist + 4.3 If it has any other value continue + 5. poll the status port until bit 7 is clear. + 6. Check if the LBAmid and LBAhi ports are non-zero + 6.2. If non-zero stop polling this is not an ATA device + 6.3 If zero continue + + 7. poll status port until bit 3 is set or bit 0 is set + + 8. if err is clear, read the data from the data port + + + */ + + // Select the target drive + outb(0x176, 0xA0); // on the secondary bus select the master drive + outb(0x170 + 0x206 , 0x0); // write 0 to the controlport for some reason + + outb(0x176, 0xA0); + // read the status port + uint8_t status = inb(0x177); + printf("status after drive select: 0x%x\n",status); + if( status == 0x00){ + printf("No drive\n"); + return; + } + + outb(0x176, 0xA0); + + + // Set the Sectorcount, LBAlo, LBAmid and LBAhi IO ports to 0 + outb(0x172, 0); + + outb(0x173, 0); + + outb(0x174, 0); + + outb(0x175, 0); + + // send the identify command; + printf("command sent!\n"); + outb(0x177, 0xA1); + + // read the status port + uint8_t status2 = inb(0x177); + if( status2 == 0x00){ + printf("No drive\n"); + return; + } + + + printf("Waiting until ready...\n"); + + while(((status2 & 0x80 == 0x80) + && (status2 & 0x01) != 0x01) + ) status2 = inb(0x177); + + + if(status2 & 0x01){ + printf("Error!"); + return; + } + + + // READ DATA + + uint16_t deviceIdentify [256] ={0}; + + for (int i= 0; i < 256; i++){ + uint16_t data; + asm volatile ( "in %1, %0" + : "=a"(data) + : "Nd"(0x170) ); + + + deviceIdentify[i] = data ; + + + } + + printf("Model-label (ASCII hex):\n"); + for(int i = 27; i < 47; i++){ + printf(" %x ",deviceIdentify[i]); + } + + printf("\nSerial number (ASCII hex):\n"); + for (int i = 10; i < 19; i++){ + printf(" %x ", deviceIdentify[i]); + } + + printf("\nFirmware revision (ASCII hex):\n"); + for (int i = 23; i < 26; i++){ + printf(" %x ", deviceIdentify[i]); + } + + printf("\nConfiguration: %x\n", deviceIdentify[0]); + + + + printf("\nData received!\n"); + + + + + + +} + + +void ATAPI_DEVICE::Read(uint8_t DEVICE_CHANNEL, DEVICE_DRIVE drive) { + printf("Not implemented"); +} + +void ATAPI_DEVICE::Write(uint8_t DEVICE_CHANNEL, DEVICE_DRIVE drive) { + printf("Not implemented"); +} + + diff --git a/src/kernel/drivers/atapi/atapiDevice.h b/src/kernel/drivers/atapi/atapiDevice.h new file mode 100644 index 0000000..51b7ffe --- /dev/null +++ b/src/kernel/drivers/atapi/atapiDevice.h @@ -0,0 +1,29 @@ +#pragma once +#include +#include "../../io.h" +#include "../../ide/ideCommands.h" +#include "../../ide/sampleIDE.definitions.h" + +#include "../../tty/kterm.h" + +/* +* This first driver wil make use of IO ports. +* Doing so means reading or writing from disk is going +* to be very cpu intensive. +* +*/ + +enum DEVICE_DRIVE{ + MASTER = 0xA0, + SLAVE = 0xB0 +}; + + +namespace ATAPI_DEVICE +{ + bool isPacketDevice(); + void Identify ( uint8_t, DEVICE_DRIVE ); + void Read ( uint8_t, DEVICE_DRIVE ); + void Write ( uint8_t, DEVICE_DRIVE ); + +}; diff --git a/src/kernel/ide/ide.h b/src/kernel/ide/ide.h index 776915f..ce2ebc1 100644 --- a/src/kernel/ide/ide.h +++ b/src/kernel/ide/ide.h @@ -7,6 +7,8 @@ #define IS_BIT_SET(x, bit) ((x >> bit & 0x1) == 1) +IDEChannelRegisters channels[2]; +IDE_DEVICE ide_devices[4]; inline void CheckProgIF(uint8_t ProgIF){ if( IS_BIT_SET(ProgIF, 0) ) // Is the 0th bit set diff --git a/src/kernel/ide/sampleIDE.definitions.h b/src/kernel/ide/sampleIDE.definitions.h index d24f62f..957dc60 100644 --- a/src/kernel/ide/sampleIDE.definitions.h +++ b/src/kernel/ide/sampleIDE.definitions.h @@ -5,11 +5,8 @@ struct IDEChannelRegisters{ unsigned short ctrl; // Control Base unsigned short bmide; // Bus Master IDE unsigned char nIEN; // IEN (no interrupt) -}channels[2]; +}; -extern unsigned char ide_buf[2048]; -extern unsigned char ide_irq_invoked; -extern unsigned char atapi_packet[12]; struct IDE_DEVICE { unsigned char Reserved; // 0 (Empty) or 1 (This device exists). @@ -19,7 +16,14 @@ struct IDE_DEVICE { unsigned short Signature; // Drive Signature unsigned short Capabilities; // Features. unsigned int CommandSets; // Command Sets Supported. - unsigned int Size; // Size in Sectors + unsigned int Size; // Size in Sectors (NOTE: Seems unused nowadays as i've only seen the value be zero unsigned char Model[41]; // Model in string. -} ide_devices[4]; +} ; + + +extern IDEChannelRegisters channels[2]; +extern IDE_DEVICE ide_devices[4]; +extern unsigned char ide_buf[2048]; +extern unsigned char ide_irq_invoked; +extern unsigned char atapi_packet[12]; diff --git a/src/kernel/kernel.cpp b/src/kernel/kernel.cpp index d558d6d..8f32274 100644 --- a/src/kernel/kernel.cpp +++ b/src/kernel/kernel.cpp @@ -71,6 +71,33 @@ extern "C" void kernel_main (void); TestIDEController(); + int devNumber = 0 ; + for ( auto device : ide_devices){ + if (!device.Reserved) + continue; + + + printf("Device %d\n" , devNumber); + printf (" Device on Channel: (0x%x) %s\n" ,device.Channel, device.Channel == 0 ? "Primary" : "Secondary"); + printf (" Device drive:(0x%x) %s\n" , device.Drive, device.Drive? "Slave" : "Master"); + printf (" Device Type:(0x%x) %s\n" , device.Type, device.Type ? "ATAPI" : "ATA"); + devNumber ++; + + + + + + + } + + // ATAPI_DEVICE::isPacketDevice(); + + + + + ATAPI_DEVICE::Identify(ATA_SECONDARY, DEVICE_DRIVE::MASTER); + + while (true){ //Read time indefinetely diff --git a/src/kernel/kernel.h b/src/kernel/kernel.h index 240a57f..9e84d19 100644 --- a/src/kernel/kernel.h +++ b/src/kernel/kernel.h @@ -20,6 +20,8 @@ extern "C"{ #include "serial.h" #include "pci.h" #include "ide/ide.h" +#include "drivers/atapi/atapiDevice.h" + #define CHECK_FLAG(flags, bit) ((flags) & (1 <<(bit))) From bd5d3f5d49e2c047bc29c1433a79be7e5ad5bcac Mon Sep 17 00:00:00 2001 From: Nigel Date: Thu, 23 Dec 2021 17:41:07 +0100 Subject: [PATCH 08/21] Basic PIO ATA driver which can read and identify ata drives --- src/kernel/drivers/ata/ataDevice.cpp | 206 +++++++++++++++++---------- src/kernel/drivers/ata/ataDevice.h | 24 ++-- 2 files changed, 147 insertions(+), 83 deletions(-) diff --git a/src/kernel/drivers/ata/ataDevice.cpp b/src/kernel/drivers/ata/ataDevice.cpp index bd5f7d1..246638f 100644 --- a/src/kernel/drivers/ata/ataDevice.cpp +++ b/src/kernel/drivers/ata/ataDevice.cpp @@ -1,4 +1,4 @@ -#include "atapiDevice.h" +#include "ataDevice.h" #define IS_BIT_SET(x, bit) ((x >> bit & 0x1) == 1) void ATA_DEVICE::Soft_Reset(uint8_t DEVICE_CHANNEL,DEVICE_DRIVE drive){ @@ -13,7 +13,7 @@ void ATA_DEVICE::Soft_Reset(uint8_t DEVICE_CHANNEL,DEVICE_DRIVE drive){ } -void ATA_DEVICE::Identify(uint8_t DEVICE_CHANNEL,DEVICE_DRIVE drive ){ +void ATA_DEVICE::Identify(uint16_t DEVICE_CHANNEL,DEVICE_DRIVE drive ){ // lets ignore which port we actually want to check for now ! /* @@ -41,91 +41,153 @@ void ATA_DEVICE::Identify(uint8_t DEVICE_CHANNEL,DEVICE_DRIVE drive ){ */ - + + //printf("channel selected: 0x%x", DEVICE_CHANNEL); // Assuming Master here // Select the target drive - outb(0x176, 0x0A); // on the primary bus select the master drive - - // Set the Sectorcount, LBAlo, LBAmid and LBAhi IO ports to 0 - outb(0x172, 0); - - outb(0x173, 0); - - outb(0x174, 0); - - outb(0x175, 0); + outb(DEVICE_CHANNEL | 6, drive); // on the primary bus select the master drive + outb(DEVICE_CHANNEL | 6 , 0x0); // write 0 to the controlport for some reason + outb(DEVICE_CHANNEL | 6, drive); + uint8_t status = inb(DEVICE_CHANNEL | 7 ); + if(status == 0x00){ + printf("No drive\n"); + return; + } // send the identify command; - outb(0x177, 0xA1); + outb(DEVICE_CHANNEL | 7, 0xEC); - // read the status port - uint8_t status = inb(0x177); + + // set the sectorCount, LBAlo, LBAmid, LBA,hi IO ports to 0 + outb(DEVICE_CHANNEL | 2, 0); + + outb(DEVICE_CHANNEL | 3, 0); + + outb(DEVICE_CHANNEL | 4, 0); + + outb(DEVICE_CHANNEL | 5, 0); + + // send the identify command ; + //printf("command sent!\n"); + outb(DEVICE_CHANNEL | 7 , 0xEC); + + // read the status port + uint8_t status2 = inb(DEVICE_CHANNEL | 7); + if( status2 == 0x00){ + printf("No drive\n"); + return; + } + + //printf("Waiting until ready...\n"); + while(((status2 & 0x80 == 0x80) + && (status2 & 0x01) != 0x01) + ) status2 = inb(DEVICE_CHANNEL | 7); + + if( status2 & 0x01){ + printf("Error!\n"); + return ; + } + + uint16_t deviceIdentify [256] = {0}; + + for ( int i = 0; i < 256; i++){ + uint16_t data; + asm volatile ("inw %1, %0" : "=a"(data): "Nd"(DEVICE_CHANNEL)); + + deviceIdentify[i] = data; + } + + + printf("Model-label (ASCII hex): "); + for(int i = 27; i < 47; i++){ + kterm_put((char)(deviceIdentify[i] >> 8)); + kterm_put((char)(deviceIdentify[i] & 0x00FF)); + } + kterm_put('\n'); + +} + +void ATA_DEVICE::Read(uint16_t DEVICE_CHANNEL, DEVICE_DRIVE drive, uint32_t LBA, uint16_t* buffer) { + /* + Assume you have a sectorcount byte and a 28 bit LBA value. A sectorcount of 0 means 256 sectors = 128K. + + Notes: - When you send a command byte and the RDY bit of the Status Registers is clear, you may have to wait (technically up to 30 seconds) for the drive to spin up, before DRQ sets. You may also need to ignore ERR and DF the first four times that you read the Status, if you are polling. + - for polling PIO drivers: After transferring the last uint16_t of a PIO data block to the data IO port, give the drive a 400ns delay to reset its DRQ bit (and possibly set BSY again, while emptying/filling its buffer to/from the drive). + - on the "magic bits" sent to port 0x1f6: Bit 6 (value = 0x40) is the LBA bit. This must be set for either LBA28 or LBA48 transfers. It must be clear for CHS transfers. Bits 7 and 5 are obsolete for current ATA drives, but must be set for backwards compatibility with very old (ATA1) drives. + + An example of a 28 bit LBA PIO mode read on the Primary bus: + + */ + + const int sectorCount = 1; + + // Floating bus check + uint8_t floatingBus = inb(DEVICE_CHANNEL | 7); + if (floatingBus == 0xFF){ + printf("Floating bus!!"); + return ; + } + + printf("Read LBA: 0x%x\n", LBA); + // Send 0xE0 for the "master" or 0xF0 for the "slave", ORed with the highest 4 bits of the LBA to port 0x1F6: outb(0x1F6, 0xE0 | (slavebit << 4) | ((LBA >> 24) & 0x0F)) + outb(DEVICE_CHANNEL | 6 , ( 0xE0 | (LBA >>28) ) ); + // Send a NULL byte to port 0x1F1, if you like (it is ignored and wastes lots of CPU time): outb(0x1F1, 0x00) + outb(DEVICE_CHANNEL | 1, 0x0000 ); + //Send the sectorcount to port 0x1F2: outb(0x1F2, (unsigned char) count) + outb(DEVICE_CHANNEL | 2, sectorCount); + //Send the low 8 bits of the LBA to port 0x1F3: outb(0x1F3, (unsigned char) LBA)) + outb(DEVICE_CHANNEL | 3, LBA); + //Send the next 8 bits of the LBA to port 0x1F4: outb(0x1F4, (unsigned char)(LBA >> 8)) + outb(DEVICE_CHANNEL | 4, (LBA >> 8)); + //Send the next 8 bits of the LBA to port 0x1F5: outb(0x1F5, (unsigned char)(LBA >> 16)) + outb(DEVICE_CHANNEL | 5, (LBA >> 16)); + //Send the "READ SECTORS" command (0x20) to port 0x1F7: outb(0x1F7, 0x20) + outb(DEVICE_CHANNEL | 7, 0x20); + + volatile int i,j; + for(i=0;i<2000;i++) + for(j=0;j<25000;j++) + asm("NOP"); + + //Wait for an IRQ or poll. + uint8_t status = inb(DEVICE_CHANNEL | 7); if( status == 0x00){ printf("No drive\n"); return; } - while(true){ - status = inb(0x177); - - if( status & (~8)) - break; + printf("Status: %x\n", status); + // Check if busy! + while((status & 0x80) == 0x80){ + printf("Reading....\r"); + status = inb(DEVICE_CHANNEL | 7); + } + + + if ((status & 0x01) == 0x01){ + printf("Error occured during read!\n"); + return; } - printf("Is this an ATA device?\n"); - uint8_t LBAmid = inb(0x174); - uint8_t LBAhi = inb(0x175); - - printf("LBAmid: 0x%x, LBAhi: 0x%x\n", LBAmid, LBAhi); - - - if( LBAhi != 0x0 || LBAmid != 0x0){ - printf("Not ATA device.. Stopping..\n"); - // return; - } - - while(true){ - status = inb(0x177); - printf( "Status bit: 0x%x\n", status); - if ( IS_BIT_SET(status, 3)){ - printf("Status: ready!\n"); - break; - - } - - if( IS_BIT_SET(status, 0)){ - printf("Status: error!\n"); - break; - } + //Transfer 256 16-bit values, a uint16_t at a time, into your buffer from I/O port 0x1F0. + if( status & 0x01){ + printf("Error!\n"); + printf("Status: 0x%x\n", status); + uint16_t error_register = inb(DEVICE_CHANNEL | 1); + printf("Error register 0x%x\n",error_register ); + return ; } - - if( IS_BIT_SET(status, 0) == false){ - // READ DATA - - uint16_t deviceIdentify [256]; - - for (int i= 0; i < 256; i++){ - uint8_t data = inb(0x170); - uint8_t data2 = inb(0x170); - - deviceIdentify[i] = (uint16_t) ( (uint16_t) data << 8 | (uint16_t) data2 ); - - } - - - printf("Data received!\n"); + for ( int i = 0; i < 256; i++){ + uint16_t data; + asm volatile ("inw %1, %0" : "=a"(data): "Nd"(DEVICE_CHANNEL)); + printf (" %x ", data); + buffer[i] = data; } - - printf("Error bit was set!\n"); - + + //Then loop back to waiting for the next IRQ (or poll again -- see next note) for each successive sector. } - -void ATA_DEVICE::Read(uint8_t DEVICE_CHANNEL, DEVICE_DRIVE drive) { - printf("Not implemented"); -} - -void ATA_DEVICE::Write(uint8_t DEVICE_CHANNEL, DEVICE_DRIVE drive) { - printf("Not implemented"); +void ATA_DEVICE::Write(uint16_t DEVICE_CHANNEL, DEVICE_DRIVE drive) { + printf("Not implemented\n"); } \ No newline at end of file diff --git a/src/kernel/drivers/ata/ataDevice.h b/src/kernel/drivers/ata/ataDevice.h index cccefa4..0c8abd7 100644 --- a/src/kernel/drivers/ata/ataDevice.h +++ b/src/kernel/drivers/ata/ataDevice.h @@ -1,10 +1,10 @@ #pragma once #include -#include "../io.h" -#include "../ide/ideCommands.h" -#include "../ide/sampleIDE.definitions.h" +#include "../../io.h" +#include "../../ide/ideCommands.h" +#include "../../ide/sampleIDE.definitions.h" -#include "../tty/kterm.h" +#include "../../tty/kterm.h" /* * This first driver wil make use of IO ports. @@ -19,11 +19,13 @@ enum DEVICE_DRIVE{ }; -namespace ATA_DEVICE -{ - void Identify ( uint8_t, DEVICE_DRIVE ); - void Read ( uint8_t, DEVICE_DRIVE ); - void Write ( uint8_t, DEVICE_DRIVE ); - void Soft_Reset ( uint8_t, DEVICE_DRIVE ); - + + +namespace ATA_DEVICE{ + void Identify(uint16_t, DEVICE_DRIVE); + void Read (uint16_t, DEVICE_DRIVE, uint32_t, uint16_t*); + void Write(uint16_t, DEVICE_DRIVE); + void Soft_Reset(uint8_t ,DEVICE_DRIVE ); }; + + From 9173b90eb16ea1c68f945e5768a665e34e7b5e50 Mon Sep 17 00:00:00 2001 From: Nigel Date: Thu, 23 Dec 2021 17:43:25 +0100 Subject: [PATCH 09/21] Structures added for MasterBootRecord support --- src/kernel/PartitionTable/MBR/MasterBootRecord.h | 11 +++++++++++ src/kernel/PartitionTable/MBR/PartitionTableEntry.h | 11 +++++++++++ 2 files changed, 22 insertions(+) create mode 100644 src/kernel/PartitionTable/MBR/MasterBootRecord.h create mode 100644 src/kernel/PartitionTable/MBR/PartitionTableEntry.h diff --git a/src/kernel/PartitionTable/MBR/MasterBootRecord.h b/src/kernel/PartitionTable/MBR/MasterBootRecord.h new file mode 100644 index 0000000..a8d7aea --- /dev/null +++ b/src/kernel/PartitionTable/MBR/MasterBootRecord.h @@ -0,0 +1,11 @@ +#pragma once +#include +#include "PartitionTableEntry.h" + +struct MBR { + uint8_t code [440]; + uint32_t uniqueID; + uint16_t Reserved; + PartitionTableEntry TableEntries[4]; + uint16_t ValidBootsector; +}__attribute__((packed)); \ No newline at end of file diff --git a/src/kernel/PartitionTable/MBR/PartitionTableEntry.h b/src/kernel/PartitionTable/MBR/PartitionTableEntry.h new file mode 100644 index 0000000..e1bd4d6 --- /dev/null +++ b/src/kernel/PartitionTable/MBR/PartitionTableEntry.h @@ -0,0 +1,11 @@ +#pragma once +#include + +struct PartitionTableEntry{ + uint8_t driveAttribute; + uint8_t CHS_start_address [3]; + uint8_t PartitionType; + uint8_t CHS_lastSector_Address[3]; + uint32_t LBA_partition_start; + uint32_t Number_sectors_inPartition; +}__attribute__((packed)); \ No newline at end of file From 6d946ddce3b6eec8e6de7411fdcadfd9320b5376 Mon Sep 17 00:00:00 2001 From: Nigel Date: Thu, 23 Dec 2021 17:44:27 +0100 Subject: [PATCH 10/21] Struct defining the EXT2 filesystems superblock --- src/kernel/filesytems/EXT2/SuperBlock.h | 29 +++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/kernel/filesytems/EXT2/SuperBlock.h diff --git a/src/kernel/filesytems/EXT2/SuperBlock.h b/src/kernel/filesytems/EXT2/SuperBlock.h new file mode 100644 index 0000000..35a5a94 --- /dev/null +++ b/src/kernel/filesytems/EXT2/SuperBlock.h @@ -0,0 +1,29 @@ +#pragma once +#include +struct SuperBlock { + uint32_t NumberOfInodes; + uint32_t NumberOfBlocks; + uint32_t NumberOfReservedBlocks; + uint32_t NumberOfUnallocatedBlocks; + uint32_t NumberOfUnallocatedInodes; + uint32_t BlockNumberOfSuperBlock; + uint32_t BlockSize;// Something about a shift left + uint32_t FragmentSize; + uint32_t NumberOfBlocksInGroup; + uint32_t NumberOfFragmentsInBlockGroup; + uint32_t NumberOfInodesInBlockGroup; + uint32_t LastMountTime; // POSIX + uint32_t LastWrittenTime; // POSIX + uint16_t TimesMountedSinceCheck; + uint16_t TimesMountedUntilCheck; + uint16_t EXT_SIG ; // 0xef53 + uint16_t FS_STATE; + uint16_t ON_ERR; + uint16_t VERSION_MINOR; + uint32_t TimeLastCheck; // POSIX + uint32_t CheckInterval; //POSIX + uint32_t OS_ID; // OS the FS was created with + uint32_t VERSION_MAJOR; + uint16_t UIDReservedBlocks; + uint16_t GIDReservedBlocks; +}__attribute__((packed)); \ No newline at end of file From 767dac7e731a6964ba82108ef297ca622eb05705 Mon Sep 17 00:00:00 2001 From: Nigel Date: Thu, 23 Dec 2021 17:46:27 +0100 Subject: [PATCH 11/21] Adjustments to IDE driver --- src/kernel/ide/sampleIDE.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/kernel/ide/sampleIDE.h b/src/kernel/ide/sampleIDE.h index 19a7baf..5e805e3 100644 --- a/src/kernel/ide/sampleIDE.h +++ b/src/kernel/ide/sampleIDE.h @@ -142,6 +142,7 @@ inline void init_IDE( uint32_t BAR0, uint32_t BAR1,uint32_t BAR2, uint32_t BAR3, DetectDevices(); + return; // 4- Print Summary: for (int i = 0; i < 4; i++) if (ide_devices[i].Reserved == 1) { From 26213993493ac67163e3920b06b45b25a1272199 Mon Sep 17 00:00:00 2001 From: Nigel Date: Fri, 24 Dec 2021 20:08:18 +0100 Subject: [PATCH 12/21] Small code fix up - Moved memcmp function to temporary libc/mem.h - I/O functions are inlined - ATA_DEVICE read function won't print the 512 bytes by default --- Makefile | 14 +++++++++++--- src/kernel/drivers/ata/ataDevice.cpp | 3 ++- src/kernel/kernel.cpp | 24 +----------------------- src/kernel/serial.h | 14 +++++++------- src/kernel/tty/kterm.cpp | 8 +++++++- src/libc/include/mem.h | 22 ++++++++++++++++++++++ src/libc/include/string.c | 4 +++- 7 files changed, 53 insertions(+), 36 deletions(-) diff --git a/Makefile b/Makefile index 7f3f9a4..a83b0c7 100644 --- a/Makefile +++ b/Makefile @@ -18,8 +18,9 @@ $(BUILD_DIR)/pci.o \ $(BUILD_DIR)/pic.o \ $(BUILD_DIR)/string.o \ $(BUILD_DIR)/pcidevice.o \ -$(BUILD_DIR)/atapiDevice.o - +$(BUILD_DIR)/atapiDevice.o \ +$(BUILD_DIR)/ataDevice.o \ +$(BUILD_DIR)/rsdp.o \ SRC_DIR = src @@ -54,7 +55,7 @@ test: $(EMULATOR) -kernel $(BUILD_DIR)/myos.bin -serial stdio -vga std -display gtk -m 2G -cpu core2duo test_iso: - $(EMULATOR) -cdrom $(BUILD_DIR)/barinkOS.iso -serial stdio -vga std -display gtk -m 2G -cpu core2duo + $(EMULATOR) -boot d -cdrom $(BUILD_DIR)/barinkOS.iso -serial stdio -vga std -display gtk -m 2G -cpu core2duo build_kernel: $(OBJ_LINK_LIST) $(CC) -T $(SRC_DIR)/kernel//linker.ld -o $(BUILD_DIR)/myos.bin \ @@ -112,3 +113,10 @@ $(BUILD_DIR)/pcidevice.o: $(BUILD_DIR)/atapiDevice.o: $(CPP) -c $(SRC_DIR)/kernel/drivers/atapi/atapiDevice.cpp -o $(BUILD_DIR)/atapiDevice.o $(CFLAGS) -fno-exceptions -fno-rtti + + +$(BUILD_DIR)/ataDevice.o: + $(CPP) -c $(SRC_DIR)/kernel/drivers/ata/ataDevice.cpp -o $(BUILD_DIR)/ataDevice.o $(CFLAGS) -fno-exceptions -fno-rtti + +$(BUILD_DIR)/rsdp.o: + $(CPP) -c $(SRC_DIR)/kernel/drivers/rsdp/rsdp.cpp -o $(BUILD_DIR)/rsdp.o $(CFLAGS) -fno-exceptions -fno-rtti diff --git a/src/kernel/drivers/ata/ataDevice.cpp b/src/kernel/drivers/ata/ataDevice.cpp index 246638f..05947f1 100644 --- a/src/kernel/drivers/ata/ataDevice.cpp +++ b/src/kernel/drivers/ata/ataDevice.cpp @@ -180,7 +180,8 @@ void ATA_DEVICE::Read(uint16_t DEVICE_CHANNEL, DEVICE_DRIVE drive, uint32_t LBA for ( int i = 0; i < 256; i++){ uint16_t data; asm volatile ("inw %1, %0" : "=a"(data): "Nd"(DEVICE_CHANNEL)); - printf (" %x ", data); + // printf (" %x ", data); + buffer[i] = data; } diff --git a/src/kernel/kernel.cpp b/src/kernel/kernel.cpp index 8f32274..5e30044 100644 --- a/src/kernel/kernel.cpp +++ b/src/kernel/kernel.cpp @@ -2,7 +2,6 @@ #define GB4 524288 #define GB2 262144 -int memcmp( const void* ptr1, const void* ptr2, size_t num); extern "C" void kernel_main (void); @@ -34,27 +33,10 @@ extern "C" void kernel_main (void); initGDT(); - kernel_main(); } - int memcmp( const void* ptr1, const void* ptr2, size_t num) - { - const unsigned char * cs = (const unsigned char*) ptr1; - const unsigned char * ct = (const unsigned char*) ptr2; - - - for (int i = 0 ; i < num ; i++, cs++, ct++ ){ - if( *cs < *ct){ - return -1; - } else if( *cs > *ct){ - return 1; - } - } - - return 0; - - } + extern "C" void kernel_main (void) { @@ -105,9 +87,5 @@ extern "C" void kernel_main (void); printf( "UTC time: %02d-%02d-%02d %02d:%02d:%02d [ Formatted as YY-MM-DD h:mm:ss]\r" ,year, month, day, hour, minute, second); delay(1000); } - - - } - diff --git a/src/kernel/serial.h b/src/kernel/serial.h index ecc82db..71d0da1 100644 --- a/src/kernel/serial.h +++ b/src/kernel/serial.h @@ -3,7 +3,7 @@ #include "tty/kterm.h" #include "io.h" #define PORT 0x3f8 -static int init_serial() { +inline static int init_serial() { outb(PORT + 1, 0x00); // Disable all interrupts outb(PORT + 3, 0x80); // Enable DLAB (set baud rate divisor) outb(PORT + 0, 0x03); // Set divisor to 3 (lo byte) 38400 baud @@ -25,33 +25,33 @@ static int init_serial() { return 0; } -int is_transmit_empty() { +inline int is_transmit_empty() { return inb(PORT + 5) & 0x20; } -void write_serial(char a) { +inline void write_serial(char a) { while (is_transmit_empty() == 0); outb(PORT,a); } -int serial_received() { +inline int serial_received() { return inb(PORT + 5) & 1; } -char read_serial() { +inline char read_serial() { while (serial_received() == 0); return inb(PORT); } -void print_serial(const char* string ){ +inline void print_serial(const char* string ){ for(size_t i = 0; i < strlen(string); i ++){ write_serial(string[i]); } } -void test_serial(){ +inline void test_serial(){ /** Serial test **/ kterm_writestring("Writing to COM1 serial port:"); init_serial(); diff --git a/src/kernel/tty/kterm.cpp b/src/kernel/tty/kterm.cpp index 94bc3f1..78e481a 100644 --- a/src/kernel/tty/kterm.cpp +++ b/src/kernel/tty/kterm.cpp @@ -1,5 +1,4 @@ #include "kterm.h" - static const size_t VGA_WIDTH = 80; static const size_t VGA_HEIGHT = 25; @@ -173,6 +172,13 @@ static void itoa (char *buf, int base, int d) { } + +/** + * @brief For now this will not only write to VGA memory but also write to serial + * + * @param format + * @param ... + */ void printf ( const char *format, ...) { char **arg = (char **)&format; diff --git a/src/libc/include/mem.h b/src/libc/include/mem.h index 62c4318..7a0e216 100644 --- a/src/libc/include/mem.h +++ b/src/libc/include/mem.h @@ -1,3 +1,5 @@ +#pragma once +// NOTE: These should not be inline inline void* memset (void* ptr, int value, size_t num){ for( int i = 0; i < num; i++ ) { @@ -6,3 +8,23 @@ inline void* memset (void* ptr, int value, size_t num){ } return ptr; } + + + +inline int memcmp( const void* ptr1, const void* ptr2, size_t num) + { + const unsigned char * cs = (const unsigned char*) ptr1; + const unsigned char * ct = (const unsigned char*) ptr2; + + + for (int i = 0 ; i < num ; i++, cs++, ct++ ){ + if( *cs < *ct){ + return -1; + } else if( *cs > *ct){ + return 1; + } + } + + return 0; + + } \ No newline at end of file diff --git a/src/libc/include/string.c b/src/libc/include/string.c index 60b96b8..7822a39 100644 --- a/src/libc/include/string.c +++ b/src/libc/include/string.c @@ -6,4 +6,6 @@ size_t strlen(const char* str) { len++; } return len; -} \ No newline at end of file +} + + From 72008b0a7a3dcff08fcf69d1b769b03c133aadc5 Mon Sep 17 00:00:00 2001 From: Nigel Date: Fri, 24 Dec 2021 20:13:28 +0100 Subject: [PATCH 13/21] Find RSD Table in early BIOS memory Adding functions and structures to read the RSD. --- src/kernel/drivers/rsdp/rsdp.cpp | 46 ++++++++++++++++++++++++++++++++ src/kernel/drivers/rsdp/rsdp.h | 36 +++++++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 src/kernel/drivers/rsdp/rsdp.cpp create mode 100644 src/kernel/drivers/rsdp/rsdp.h diff --git a/src/kernel/drivers/rsdp/rsdp.cpp b/src/kernel/drivers/rsdp/rsdp.cpp new file mode 100644 index 0000000..5f4991f --- /dev/null +++ b/src/kernel/drivers/rsdp/rsdp.cpp @@ -0,0 +1,46 @@ +#include "rsdp.h" + +void printRSD(RSDPTR* rsd){ + printf("Signature: "); + for(int i = 0; i < 8; i++){ + kterm_put(rsd->signature[i]); + } + kterm_put('\n'); + + printf("OEMID: "); + for(int i =0; i < 6 ; i++){ + kterm_put (rsd->OEMID[i]); + } + kterm_put('\n'); + + printf("Revision: %d\n", rsd->Revision); + printf("RSDT Address: 0x%x\n", rsd->RsdtAddress ); +} + +RSDPTR* FindRSD(){ + char* memory_byte = (char*) 0x000f2e14; + const void* string = "RSD PTR "; + + for( ; (uint32_t) memory_byte < 0x0100000; memory_byte+=10){ + if( memcmp(memory_byte , string , 8 ) == 0 ) { + printf("RSD PTR found at 0x%x !\n", memory_byte); + break; + } + } + + printRSD((RSDPTR*) memory_byte); + return (RSDPTR*) memory_byte; +} + + +RSDT* getRSDT(RSDPTR* rsd){ + + RSDT* rsdt = (RSDT*) rsd->RsdtAddress; + + printf("OEMID: "); + for(int i = 0; i < 6; i++){ + kterm_put(rsdt->header.OEMID[i]); + } + kterm_put('\n'); + return rsdt; +} \ No newline at end of file diff --git a/src/kernel/drivers/rsdp/rsdp.h b/src/kernel/drivers/rsdp/rsdp.h new file mode 100644 index 0000000..1bac440 --- /dev/null +++ b/src/kernel/drivers/rsdp/rsdp.h @@ -0,0 +1,36 @@ +#pragma once +#include +#include "./../../tty/kterm.h" +#include "../../../libc/include/mem.h" +struct RSDPTR { + char signature[8]; + uint8_t Checksum ; + char OEMID [6]; + uint8_t Revision; + uint32_t RsdtAddress; +}__attribute__((packed)); + +struct ACPISDTHeader{ + char Signature[4]; + uint32_t Length; + uint8_t CheckSum; + char OEMID[6]; + char OEMTableID[8]; + uint32_t OEMRevision; + uint32_t CreatorID; + uint32_t CreatorRevision; +}__attribute__((packed)); + + +struct RSDT{ + struct ACPISDTHeader header; + uint32_t PointerToSDT[]; // Length of array : (header.Length - sizeof(header))/ 4 +}__attribute__((packed)); + + +//NOTE: only scans EBDA enough to find RSD PTR in QEMU +RSDPTR* FindRSD(); + +void printRSD(RSDPTR* rsd); + +RSDT* getRSDT(RSDPTR* rsd); \ No newline at end of file From fb2a19e11db9d183f233af3da0cfef4950a0df5c Mon Sep 17 00:00:00 2001 From: Nigel Date: Fri, 24 Dec 2021 21:31:10 +0100 Subject: [PATCH 14/21] FAT16 structures read from disk using ATA. The proper reading of folders and files is not yet implemented. Although it is close. --- .../filesytems/FAT32/BiosParameterBlock.h | 21 +++++ .../filesytems/FAT32/ExtendBootRecord.h | 32 ++++++++ src/kernel/kernel.cpp | 76 +++++++++++++++---- src/kernel/kernel.h | 8 +- 4 files changed, 119 insertions(+), 18 deletions(-) create mode 100644 src/kernel/filesytems/FAT32/BiosParameterBlock.h create mode 100644 src/kernel/filesytems/FAT32/ExtendBootRecord.h diff --git a/src/kernel/filesytems/FAT32/BiosParameterBlock.h b/src/kernel/filesytems/FAT32/BiosParameterBlock.h new file mode 100644 index 0000000..3bf2de3 --- /dev/null +++ b/src/kernel/filesytems/FAT32/BiosParameterBlock.h @@ -0,0 +1,21 @@ +#pragma once +#include +#include "./ExtendBootRecord.h" + +struct BiosParameterBlock { + uint8_t BootLoaderCodeSection [3]; + uint8_t OEM_id [8]; + uint16_t BytesPerSector ; // I suspect would be 512 + uint8_t SectorsPerCluster ; + uint16_t ReservedSectors; + uint8_t NumberOfFileAllocationTables; // Probably equals 2 + uint16_t NumberOfDirectoryEntries; // Root directory must contain entire sectors + uint16_t TotalSectorsInLogicalVolume ; // 0 means >65535 sectors in volume , actual count can be found in LargeSectorCount + uint8_t MediaDescriptor ; // Indication the media descriptor type + uint16_t NumberOfSectorsPerFAT;// only in FAT12 / FAT 16 + uint16_t NumberOfSectorsPerTrack; + uint16_t NumberOfHeadsOnMedia; + uint32_t NumberOfHiddenSectors; + uint32_t LargeSectorCount; + ExtendedBootRecord_FAT16 ebpb; +}__attribute__((packed)); \ No newline at end of file diff --git a/src/kernel/filesytems/FAT32/ExtendBootRecord.h b/src/kernel/filesytems/FAT32/ExtendBootRecord.h new file mode 100644 index 0000000..38a40b7 --- /dev/null +++ b/src/kernel/filesytems/FAT32/ExtendBootRecord.h @@ -0,0 +1,32 @@ +#pragma once +#include + +struct ExtendedBootRecord_FAT16{ + uint8_t DriveNumber; + uint8_t Reserved; + uint8_t Signature; + const uint32_t VOLUME_ID_SERIAL_NUMBER; + uint8_t volume_label [11]; + uint8_t Identifier_string [8]; + uint8_t bootCode [448]; + uint16_t partitionSignature; +}__attribute__((packed)); + +struct ExtendedBootRecord_FAT32{ + uint32_t SectorsPerFAT; + uint16_t Flags; + const uint16_t FAT_VERSION_NUMBER; + uint32_t rootDirectory_clusterNumber;// Often set to 2; + uint16_t FSInfo_SectorNumber; + uint16_t backup_bpb_sectorNumber; + uint8_t Reserved [12]; + uint8_t DriveNumber; + uint8_t Reserved2; + uint8_t Signature; // must be 0x28 or 0x29 + uint32_t VOLUME_ID_SERIAL; + uint8_t volume_label[11]; + uint8_t SystemIdentifierString [8]; // ALWAYS "FAT32 " but spec says do not trust + uint8_t BootCode [420]; // NICE + uint16_t PartitionSignature; // 0xAA55 + +}__attribute__((packed)); \ No newline at end of file diff --git a/src/kernel/kernel.cpp b/src/kernel/kernel.cpp index 5e30044..407f637 100644 --- a/src/kernel/kernel.cpp +++ b/src/kernel/kernel.cpp @@ -44,40 +44,84 @@ extern "C" void kernel_main (void); init_serial(); print_serial("Serial port initialized!"); - + RSDPTR* rsd = FindRSD(); + RSDT* rsd_table = getRSDT(rsd); + // Enumerate the PCI bus PCI_Enumerate(); - - - - TestIDEController(); + TestIDEController(); int devNumber = 0 ; for ( auto device : ide_devices){ if (!device.Reserved) continue; - - printf("Device %d\n" , devNumber); printf (" Device on Channel: (0x%x) %s\n" ,device.Channel, device.Channel == 0 ? "Primary" : "Secondary"); printf (" Device drive:(0x%x) %s\n" , device.Drive, device.Drive? "Slave" : "Master"); printf (" Device Type:(0x%x) %s\n" , device.Type, device.Type ? "ATAPI" : "ATA"); devNumber ++; - - - - - } - // ATAPI_DEVICE::isPacketDevice(); - - + enum BUS_PORT { + Primary= 0x1f0, + Secondary = 0x170 + }; - ATAPI_DEVICE::Identify(ATA_SECONDARY, DEVICE_DRIVE::MASTER); + + ATA_DEVICE::Identify((uint16_t) BUS_PORT::Primary, DEVICE_DRIVE::MASTER); + + const int C = 0; + const int H = 0; + const int HPC = 16; + const int SPT = 63; + + int S = 1; + uint32_t LBA = (C*HPC+H) * SPT + (S-1); + printf("LBA: %d\n" , LBA); + uint16_t buffer [256]; + + + ATA_DEVICE::Read(BUS_PORT::Primary, DEVICE_DRIVE::MASTER, LBA, buffer); + + MBR* mbr = (MBR*) buffer; + + printf("BootSector: 0x%x\n", mbr->ValidBootsector ); + for( int i = 0 ; i < 4 ; i ++){ + PartitionTableEntry PT = mbr->TableEntries[i]; + + printf("Partition %d [ %d sectors, PartitionType: %x, 0x%x, \nLBA Start: 0x%x ]\n" , + i, PT.Number_sectors_inPartition, PT.PartitionType, mbr->uniqueID, PT.LBA_partition_start ); + } + + // Find the super block + uint16_t superBlock[256]; + ATA_DEVICE::Read(BUS_PORT::Primary, DEVICE_DRIVE::MASTER, mbr->TableEntries[0].LBA_partition_start, superBlock); + + BiosParameterBlock* bpb = (BiosParameterBlock*) superBlock; + + + printf("\nBPB: Bytes per Sector %d\n", bpb->BytesPerSector ); + printf("OEM ID: %s\n", bpb->OEM_id); + printf("Bytes per sector: %d\n", bpb->BytesPerSector); + printf("Sectors per cluster: %d\n", bpb->SectorsPerCluster); + printf("Reserved sectors: %d\n", bpb->ReservedSectors); + printf("Number of FAT: %d\n", bpb->NumberOfFileAllocationTables); + printf("Number of Dir entries: %d\n", bpb->NumberOfDirectoryEntries); + printf("Total Sectors in volume: %d\n", bpb->TotalSectorsInLogicalVolume); + printf("Sectors per FAT: %d\n", bpb->NumberOfSectorsPerFAT); + + uint32_t PartitionAddress = mbr->TableEntries[0].LBA_partition_start *512 ; + uint32_t RootDirAddress = PartitionAddress + ((bpb->ReservedSectors + bpb->NumberOfSectorsPerFAT * bpb->NumberOfFileAllocationTables ) * bpb->BytesPerSector); + uint32_t RootDirLBA =RootDirAddress/512; + + + + uint16_t RootDir [16]; + ATA_DEVICE::Read(BUS_PORT::Primary, DEVICE_DRIVE::MASTER,RootDirLBA, (uint16_t*) RootDir ); + diff --git a/src/kernel/kernel.h b/src/kernel/kernel.h index 9e84d19..5542a5c 100644 --- a/src/kernel/kernel.h +++ b/src/kernel/kernel.h @@ -20,8 +20,12 @@ extern "C"{ #include "serial.h" #include "pci.h" #include "ide/ide.h" -#include "drivers/atapi/atapiDevice.h" - +//#include "drivers/atapi/atapiDevice.h" +#include "drivers/ata/ataDevice.h" +#include "./PartitionTable/MBR/MasterBootRecord.h" +#include "./filesytems/FAT32/BiosParameterBlock.h" +#include "./filesytems/FAT32/ExtendBootRecord.h" +#include "./drivers/rsdp/rsdp.h" #define CHECK_FLAG(flags, bit) ((flags) & (1 <<(bit))) From b8d75dddaec072cff4f592ec0b461798ffbbc431 Mon Sep 17 00:00:00 2001 From: Nigel Date: Mon, 27 Dec 2021 15:26:32 +0100 Subject: [PATCH 15/21] Moving lots into seperate folders to cleanup the project structure - Drivers have now gotten Category folders - RSDP is now called ACPI - Ports folders is now called Serial to show that its a serial driver - Paging assembly definition is moved to the memory folder - VGA folder has moved into the drivers - Patched the makefile and include statements to reflect the changes in the project structure --- Makefile | 12 ++++++------ src/kernel/boot.S | 2 +- src/kernel/drivers/{rsdp => ACPI}/rsdp.cpp | 0 src/kernel/drivers/{rsdp => ACPI}/rsdp.h | 0 src/kernel/{ => drivers/IO/PCI}/pci.cpp | 0 src/kernel/{ => drivers/IO/PCI}/pci.h | 6 +++--- src/kernel/drivers/{ => IO}/ata/ataDevice.cpp | 0 src/kernel/drivers/{ => IO}/ata/ataDevice.h | 8 ++++---- src/kernel/drivers/{ => IO}/atapi/atapiDevice.cpp | 0 src/kernel/drivers/{ => IO}/atapi/atapiDevice.h | 8 ++++---- src/kernel/{ => drivers/IO}/io.cpp | 0 src/kernel/{ => drivers/IO}/io.h | 0 src/kernel/{vga => drivers/VGA}/VBE.h | 0 src/kernel/{vga => drivers/VGA}/colors.h | 0 src/kernel/idt/idt.h | 2 +- src/kernel/kernel.h | 11 +++++------ src/kernel/{ => memory}/paging.s | 0 src/kernel/pic/pic.h | 2 +- src/kernel/serial.h | 2 +- src/kernel/{ports => serial}/serial.cpp | 0 src/kernel/{ports => serial}/serial.h | 0 src/kernel/tty/kterm.h | 4 ++-- 22 files changed, 28 insertions(+), 29 deletions(-) rename src/kernel/drivers/{rsdp => ACPI}/rsdp.cpp (100%) rename src/kernel/drivers/{rsdp => ACPI}/rsdp.h (100%) rename src/kernel/{ => drivers/IO/PCI}/pci.cpp (100%) rename src/kernel/{ => drivers/IO/PCI}/pci.h (92%) rename src/kernel/drivers/{ => IO}/ata/ataDevice.cpp (100%) rename src/kernel/drivers/{ => IO}/ata/ataDevice.h (76%) rename src/kernel/drivers/{ => IO}/atapi/atapiDevice.cpp (100%) rename src/kernel/drivers/{ => IO}/atapi/atapiDevice.h (76%) rename src/kernel/{ => drivers/IO}/io.cpp (100%) rename src/kernel/{ => drivers/IO}/io.h (100%) rename src/kernel/{vga => drivers/VGA}/VBE.h (100%) rename src/kernel/{vga => drivers/VGA}/colors.h (100%) rename src/kernel/{ => memory}/paging.s (100%) rename src/kernel/{ports => serial}/serial.cpp (100%) rename src/kernel/{ports => serial}/serial.h (100%) diff --git a/Makefile b/Makefile index a83b0c7..5f7cbd5 100644 --- a/Makefile +++ b/Makefile @@ -75,7 +75,7 @@ $(BUILD_DIR)/kterm.o: $(CPP) -c $(SRC_DIR)/kernel/tty/kterm.cpp -o $(BUILD_DIR)/kterm.o $(CFLAGS) -fno-exceptions -fno-rtti $(BUILD_DIR)/boot.o: - $(AS) $(SRC_DIR)/kernel//boot.S -o $(BUILD_DIR)/boot.o + $(AS) $(SRC_DIR)/kernel/boot.S -o $(BUILD_DIR)/boot.o $(BUILD_DIR)/crti.o: $(AS) $(SRC_DIR)/kernel/crti.s -o $(BUILD_DIR)/crti.o @@ -84,7 +84,7 @@ $(BUILD_DIR)/crtn.o: $(AS) $(SRC_DIR)/kernel/crtn.s -o $(BUILD_DIR)/crtn.o $(BUILD_DIR)/io.o: - $(CPP) -c $(SRC_DIR)/kernel/io.cpp -o $(BUILD_DIR)/io.o $(CFLAGS) -fno-exceptions -fno-rtti + $(CPP) -c $(SRC_DIR)/kernel/drivers/IO/io.cpp -o $(BUILD_DIR)/io.o $(CFLAGS) -fno-exceptions -fno-rtti $(BUILD_DIR)/PageDirectory.o: $(CPP) -c $(SRC_DIR)/kernel/memory/PageDirectory.cpp -o $(BUILD_DIR)/PageDirectory.o $(CFLAGS) -fno-exceptions -fno-rtti @@ -106,17 +106,17 @@ $(BUILD_DIR)/PhysicalMemoryManager.o: $(CPP) -c $(SRC_DIR)/kernel/memory/PhysicalMemoryManager.cpp -o $(BUILD_DIR)/PhysicalMemoryManager.o $(CFLAGS) -fno-exceptions -fno-rtti $(BUILD_DIR)/pci.o: - $(CPP) -c $(SRC_DIR)/kernel/pci.cpp -o $(BUILD_DIR)/pci.o $(CFLAGS) -fno-exceptions -fno-rtti + $(CPP) -c $(SRC_DIR)/kernel/drivers/IO/PCI/pci.cpp -o $(BUILD_DIR)/pci.o $(CFLAGS) -fno-exceptions -fno-rtti $(BUILD_DIR)/pcidevice.o: $(CPP) -c $(SRC_DIR)/kernel/pci/pciDevice.cpp -o $(BUILD_DIR)/pcidevice.o $(CFLAGS) -fno-exceptions -fno-rtti $(BUILD_DIR)/atapiDevice.o: - $(CPP) -c $(SRC_DIR)/kernel/drivers/atapi/atapiDevice.cpp -o $(BUILD_DIR)/atapiDevice.o $(CFLAGS) -fno-exceptions -fno-rtti + $(CPP) -c $(SRC_DIR)/kernel/drivers/IO/atapi/atapiDevice.cpp -o $(BUILD_DIR)/atapiDevice.o $(CFLAGS) -fno-exceptions -fno-rtti $(BUILD_DIR)/ataDevice.o: - $(CPP) -c $(SRC_DIR)/kernel/drivers/ata/ataDevice.cpp -o $(BUILD_DIR)/ataDevice.o $(CFLAGS) -fno-exceptions -fno-rtti + $(CPP) -c $(SRC_DIR)/kernel/drivers/IO/ata/ataDevice.cpp -o $(BUILD_DIR)/ataDevice.o $(CFLAGS) -fno-exceptions -fno-rtti $(BUILD_DIR)/rsdp.o: - $(CPP) -c $(SRC_DIR)/kernel/drivers/rsdp/rsdp.cpp -o $(BUILD_DIR)/rsdp.o $(CFLAGS) -fno-exceptions -fno-rtti + $(CPP) -c $(SRC_DIR)/kernel/drivers/ACPI/rsdp.cpp -o $(BUILD_DIR)/rsdp.o $(CFLAGS) -fno-exceptions -fno-rtti diff --git a/src/kernel/boot.S b/src/kernel/boot.S index 0c79b10..ee4698e 100644 --- a/src/kernel/boot.S +++ b/src/kernel/boot.S @@ -24,7 +24,7 @@ stack_top: .include "./src/kernel/irs_table.s" .include "./src/kernel/irq_table.s" .include "./src/kernel/idt/idt.s" -.include "./src/kernel/paging.s" +.include "./src/kernel/memory/paging.s" .global _start diff --git a/src/kernel/drivers/rsdp/rsdp.cpp b/src/kernel/drivers/ACPI/rsdp.cpp similarity index 100% rename from src/kernel/drivers/rsdp/rsdp.cpp rename to src/kernel/drivers/ACPI/rsdp.cpp diff --git a/src/kernel/drivers/rsdp/rsdp.h b/src/kernel/drivers/ACPI/rsdp.h similarity index 100% rename from src/kernel/drivers/rsdp/rsdp.h rename to src/kernel/drivers/ACPI/rsdp.h diff --git a/src/kernel/pci.cpp b/src/kernel/drivers/IO/PCI/pci.cpp similarity index 100% rename from src/kernel/pci.cpp rename to src/kernel/drivers/IO/PCI/pci.cpp diff --git a/src/kernel/pci.h b/src/kernel/drivers/IO/PCI/pci.h similarity index 92% rename from src/kernel/pci.h rename to src/kernel/drivers/IO/PCI/pci.h index fdfe5f2..9f2bba2 100644 --- a/src/kernel/pci.h +++ b/src/kernel/drivers/IO/PCI/pci.h @@ -1,8 +1,8 @@ #pragma once #include -#include "io.h" -#include "tty/kterm.h" -#include "pci/pciDevice.h" +#include "../io.h" +#include "../../../tty/kterm.h" +#include "../../../pci/pciDevice.h" // Configuration Space Access Mechanism #1 #define CONFIG_ADDRESS 0xCF8 // Configuration adress that is to be accessed diff --git a/src/kernel/drivers/ata/ataDevice.cpp b/src/kernel/drivers/IO/ata/ataDevice.cpp similarity index 100% rename from src/kernel/drivers/ata/ataDevice.cpp rename to src/kernel/drivers/IO/ata/ataDevice.cpp diff --git a/src/kernel/drivers/ata/ataDevice.h b/src/kernel/drivers/IO/ata/ataDevice.h similarity index 76% rename from src/kernel/drivers/ata/ataDevice.h rename to src/kernel/drivers/IO/ata/ataDevice.h index 0c8abd7..89bfe7d 100644 --- a/src/kernel/drivers/ata/ataDevice.h +++ b/src/kernel/drivers/IO/ata/ataDevice.h @@ -1,10 +1,10 @@ #pragma once #include -#include "../../io.h" -#include "../../ide/ideCommands.h" -#include "../../ide/sampleIDE.definitions.h" +#include "../io.h" +#include "../../../ide/ideCommands.h" +#include "../../../ide/sampleIDE.definitions.h" -#include "../../tty/kterm.h" +#include "../../../tty/kterm.h" /* * This first driver wil make use of IO ports. diff --git a/src/kernel/drivers/atapi/atapiDevice.cpp b/src/kernel/drivers/IO/atapi/atapiDevice.cpp similarity index 100% rename from src/kernel/drivers/atapi/atapiDevice.cpp rename to src/kernel/drivers/IO/atapi/atapiDevice.cpp diff --git a/src/kernel/drivers/atapi/atapiDevice.h b/src/kernel/drivers/IO/atapi/atapiDevice.h similarity index 76% rename from src/kernel/drivers/atapi/atapiDevice.h rename to src/kernel/drivers/IO/atapi/atapiDevice.h index 51b7ffe..37d516e 100644 --- a/src/kernel/drivers/atapi/atapiDevice.h +++ b/src/kernel/drivers/IO/atapi/atapiDevice.h @@ -1,10 +1,10 @@ #pragma once #include -#include "../../io.h" -#include "../../ide/ideCommands.h" -#include "../../ide/sampleIDE.definitions.h" +#include "../io.h" +#include "../../../ide/ideCommands.h" +#include "../../../ide/sampleIDE.definitions.h" -#include "../../tty/kterm.h" +#include "../../../tty/kterm.h" /* * This first driver wil make use of IO ports. diff --git a/src/kernel/io.cpp b/src/kernel/drivers/IO/io.cpp similarity index 100% rename from src/kernel/io.cpp rename to src/kernel/drivers/IO/io.cpp diff --git a/src/kernel/io.h b/src/kernel/drivers/IO/io.h similarity index 100% rename from src/kernel/io.h rename to src/kernel/drivers/IO/io.h diff --git a/src/kernel/vga/VBE.h b/src/kernel/drivers/VGA/VBE.h similarity index 100% rename from src/kernel/vga/VBE.h rename to src/kernel/drivers/VGA/VBE.h diff --git a/src/kernel/vga/colors.h b/src/kernel/drivers/VGA/colors.h similarity index 100% rename from src/kernel/vga/colors.h rename to src/kernel/drivers/VGA/colors.h diff --git a/src/kernel/idt/idt.h b/src/kernel/idt/idt.h index 04173d3..48c026c 100644 --- a/src/kernel/idt/idt.h +++ b/src/kernel/idt/idt.h @@ -2,7 +2,7 @@ #include "stdint.h" #include "stddef.h" -#include "../vga/colors.h" +#include "../drivers/VGA/colors.h" #include "../pic/pic.h" #include "../tty/kterm.h" diff --git a/src/kernel/kernel.h b/src/kernel/kernel.h index 5542a5c..fe75fb4 100644 --- a/src/kernel/kernel.h +++ b/src/kernel/kernel.h @@ -4,7 +4,7 @@ extern "C"{ } -#include "vga/VBE.h" +#include "drivers/VGA/VBE.h" #include "tty/kterm.h" #include "./bootloader/multiboot.h" @@ -14,18 +14,17 @@ extern "C"{ #include "gdt/gdtc.h" #include "idt/idt.h" -#include "io.h" +#include "drivers/IO/io.h" #include "time.h" #include "cpu.h" #include "serial.h" -#include "pci.h" +#include "drivers/IO/PCI/pci.h" #include "ide/ide.h" -//#include "drivers/atapi/atapiDevice.h" -#include "drivers/ata/ataDevice.h" +#include "./drivers/IO/ata/ataDevice.h" #include "./PartitionTable/MBR/MasterBootRecord.h" #include "./filesytems/FAT32/BiosParameterBlock.h" #include "./filesytems/FAT32/ExtendBootRecord.h" -#include "./drivers/rsdp/rsdp.h" +#include "drivers/ACPI/rsdp.h" #define CHECK_FLAG(flags, bit) ((flags) & (1 <<(bit))) diff --git a/src/kernel/paging.s b/src/kernel/memory/paging.s similarity index 100% rename from src/kernel/paging.s rename to src/kernel/memory/paging.s diff --git a/src/kernel/pic/pic.h b/src/kernel/pic/pic.h index 9560cea..fa06d3d 100644 --- a/src/kernel/pic/pic.h +++ b/src/kernel/pic/pic.h @@ -1,5 +1,5 @@ #pragma once -#include "../io.h" +#include "../drivers/IO/io.h" #define PIC1 0x20 /* IO base address for master PIC */ #define PIC2 0xA0 /* IO base address for slave PIC */ diff --git a/src/kernel/serial.h b/src/kernel/serial.h index 71d0da1..edc2185 100644 --- a/src/kernel/serial.h +++ b/src/kernel/serial.h @@ -1,7 +1,7 @@ #pragma once #include "tty/kterm.h" -#include "io.h" +#include "drivers/IO/io.h" #define PORT 0x3f8 inline static int init_serial() { outb(PORT + 1, 0x00); // Disable all interrupts diff --git a/src/kernel/ports/serial.cpp b/src/kernel/serial/serial.cpp similarity index 100% rename from src/kernel/ports/serial.cpp rename to src/kernel/serial/serial.cpp diff --git a/src/kernel/ports/serial.h b/src/kernel/serial/serial.h similarity index 100% rename from src/kernel/ports/serial.h rename to src/kernel/serial/serial.h diff --git a/src/kernel/tty/kterm.h b/src/kernel/tty/kterm.h index 4f048d0..0753294 100644 --- a/src/kernel/tty/kterm.h +++ b/src/kernel/tty/kterm.h @@ -4,8 +4,8 @@ #include #include -#include "../vga/colors.h" -#include "../io.h" +#include "../drivers/VGA/colors.h" +#include "../drivers/IO/io.h" extern "C"{ #include "./../../libc/include/string.h" From 19b9cfe9086deb7e17509a2bb24a3593e5ba0936 Mon Sep 17 00:00:00 2001 From: Nigel Date: Mon, 27 Dec 2021 19:35:24 +0100 Subject: [PATCH 16/21] Reading files from disk - Modified makefile to start the virtualbox vm on `make run` - Listing files in rootdirectory with their properties and content --- Makefile | 4 +- .../{FAT32 => FAT}/BiosParameterBlock.h | 0 src/kernel/filesytems/FAT/DirectoryEntry.h | 19 ++ .../{FAT32 => FAT}/ExtendBootRecord.h | 0 src/kernel/kernel.cpp | 168 +++++++++++++----- src/kernel/kernel.h | 5 +- 6 files changed, 148 insertions(+), 48 deletions(-) rename src/kernel/filesytems/{FAT32 => FAT}/BiosParameterBlock.h (100%) create mode 100644 src/kernel/filesytems/FAT/DirectoryEntry.h rename src/kernel/filesytems/{FAT32 => FAT}/ExtendBootRecord.h (100%) diff --git a/Makefile b/Makefile index 5f7cbd5..173bd5c 100644 --- a/Makefile +++ b/Makefile @@ -50,7 +50,9 @@ iso: clean_iso clean build cp build/myos.bin root/boot/myos.bin cp src/grub.cfg root/boot/grub/grub.cfg grub-mkrescue -o build/barinkOS.iso root - +run: all + virtualboxvm --startvm "BarinkOS_test" + test: $(EMULATOR) -kernel $(BUILD_DIR)/myos.bin -serial stdio -vga std -display gtk -m 2G -cpu core2duo diff --git a/src/kernel/filesytems/FAT32/BiosParameterBlock.h b/src/kernel/filesytems/FAT/BiosParameterBlock.h similarity index 100% rename from src/kernel/filesytems/FAT32/BiosParameterBlock.h rename to src/kernel/filesytems/FAT/BiosParameterBlock.h diff --git a/src/kernel/filesytems/FAT/DirectoryEntry.h b/src/kernel/filesytems/FAT/DirectoryEntry.h new file mode 100644 index 0000000..c3e48ec --- /dev/null +++ b/src/kernel/filesytems/FAT/DirectoryEntry.h @@ -0,0 +1,19 @@ +#pragma once +#include + +struct DirectoryEntry { + uint8_t filename [8]; + uint8_t Extension [3]; + uint8_t attribute; + uint8_t Reserved; + uint8_t creation; + uint16_t CreationTime; + uint16_t CreationDate; + uint16_t LastAccessDate; + uint16_t ReservedFAT32; + uint16_t LastWriteTime; + uint16_t LastWriteDate; + uint16_t StartingCluster; + uint32_t FilesizeInBytes; + +}__attribute__((packed)); \ No newline at end of file diff --git a/src/kernel/filesytems/FAT32/ExtendBootRecord.h b/src/kernel/filesytems/FAT/ExtendBootRecord.h similarity index 100% rename from src/kernel/filesytems/FAT32/ExtendBootRecord.h rename to src/kernel/filesytems/FAT/ExtendBootRecord.h diff --git a/src/kernel/kernel.cpp b/src/kernel/kernel.cpp index 407f637..9e1a416 100644 --- a/src/kernel/kernel.cpp +++ b/src/kernel/kernel.cpp @@ -3,40 +3,17 @@ #define GB2 262144 -extern "C" void kernel_main (void); - extern "C" void early_main(unsigned long magic, unsigned long addr){ - /** initialize terminal interface */ - kterm_init(); - - if (magic != MULTIBOOT_BOOTLOADER_MAGIC){ - printf("Invalid magic number: 0x%x\n", magic); - return; - } - - CheckMBT( (multiboot_info_t *) addr); - - multiboot_info_t* mbt = (multiboot_info_t*) addr; - - /* Are mmap_* valid? */ - if (CHECK_FLAG(mbt->flags, 6)){ - PhysicalMemoryManager_initialise( mbt->mmap_addr, GB2/* Seriously dangerous hardcoded memory value*/); - PhysicalMemoryManager_initialise_available_regions(mbt->mmap_addr, mbt->mmap_addr + mbt->mmap_length); - PhysicalMemoryManager_deinitialise_kernel(); - extern uint8_t* kernel_begin; - extern uint8_t* kernel_end; - - printf("Kernel MemoryMap:\n"); - printf("kernel: 0x%x - 0x%x\n", &kernel_begin , &kernel_end); + extern "C" void wait_until_shutdown(){ + while (true){ + //Read time indefinetely + read_rtc(); + printf( "UTC time: %02d-%02d-%02d %02d:%02d:%02d [ Formatted as YY-MM-DD h:mm:ss]\r" ,year, month, day, hour, minute, second); + delay(1000); } - initGDT(); - - - kernel_main(); } - extern "C" void kernel_main (void) { @@ -96,11 +73,11 @@ extern "C" void kernel_main (void); i, PT.Number_sectors_inPartition, PT.PartitionType, mbr->uniqueID, PT.LBA_partition_start ); } - // Find the super block - uint16_t superBlock[256]; - ATA_DEVICE::Read(BUS_PORT::Primary, DEVICE_DRIVE::MASTER, mbr->TableEntries[0].LBA_partition_start, superBlock); + // Find the BiosParameter block + uint16_t biosparameterblock[256]; + ATA_DEVICE::Read(BUS_PORT::Primary, DEVICE_DRIVE::MASTER, mbr->TableEntries[0].LBA_partition_start, biosparameterblock); - BiosParameterBlock* bpb = (BiosParameterBlock*) superBlock; + BiosParameterBlock* bpb = (BiosParameterBlock*) biosparameterblock; printf("\nBPB: Bytes per Sector %d\n", bpb->BytesPerSector ); @@ -113,23 +90,124 @@ extern "C" void kernel_main (void); printf("Total Sectors in volume: %d\n", bpb->TotalSectorsInLogicalVolume); printf("Sectors per FAT: %d\n", bpb->NumberOfSectorsPerFAT); - uint32_t PartitionAddress = mbr->TableEntries[0].LBA_partition_start *512 ; - uint32_t RootDirAddress = PartitionAddress + ((bpb->ReservedSectors + bpb->NumberOfSectorsPerFAT * bpb->NumberOfFileAllocationTables ) * bpb->BytesPerSector); - uint32_t RootDirLBA =RootDirAddress/512; - - uint16_t RootDir [16]; - ATA_DEVICE::Read(BUS_PORT::Primary, DEVICE_DRIVE::MASTER,RootDirLBA, (uint16_t*) RootDir ); - + + /** + * @brief File Allocation Table + */ + uint32_t FATAddress = mbr->TableEntries[0].LBA_partition_start + bpb->ReservedSectors ; + uint16_t FAT[256]; + ATA_DEVICE::Read(BUS_PORT::Primary, DEVICE_DRIVE::MASTER, FATAddress, FAT ); - while (true){ - //Read time indefinetely - read_rtc(); - printf( "UTC time: %02d-%02d-%02d %02d:%02d:%02d [ Formatted as YY-MM-DD h:mm:ss]\r" ,year, month, day, hour, minute, second); - delay(1000); + // Show data in terminal + for(int i = 0; i < 256; i++ ) { + printf("%x ", FAT[i]); } + kterm_put('\n'); + + + uint32_t RootDirectoryRegion = FATAddress + ( bpb->NumberOfFileAllocationTables * bpb->NumberOfSectorsPerFAT ); + uint32_t DataRegion = RootDirectoryRegion + ((bpb->NumberOfDirectoryEntries * 32) / bpb->BytesPerSector ); + + uint16_t data2 [256]; + ATA_DEVICE::Read(BUS_PORT::Primary, DEVICE_DRIVE::MASTER, RootDirectoryRegion, data2 ); + DirectoryEntry* RootDirectory = (DirectoryEntry*) data2; + // List files in root + for(int i= 0; i < bpb->NumberOfDirectoryEntries ; i++ ) + { + DirectoryEntry* entry = (DirectoryEntry*)((uint32_t) RootDirectory + (i * sizeof(DirectoryEntry))); + + if( entry->filename[0] == (uint8_t) 0x00 ) + break; // There are no more entries in this directory or the entry is free + + if( entry->attribute & 0x01 == 0x01 || entry->attribute & 0x20 == 0x20) + continue; // Skip listing if hidden or Achieve flag is set + + // Print the filename; + for( int n = 0; n < 8; n++ ){ + if(entry->filename[n] == 0x20) + break; + kterm_put(entry->filename[n]); + }kterm_put('\n'); + + for( int n = 0; n < 3; n++){ + kterm_put(entry->Extension[n]); + }kterm_put('\n'); + + printf("Attribute: %x \n" , entry->attribute); + printf("FileSize: %d Bytes\n", entry->FilesizeInBytes); + + if( entry->FilesizeInBytes != 0x0 || entry->attribute & 0x8 == 0x0){ + printf("Show contents"); + + printf( "Start cluster of the file: 0x%x\n" , entry->StartingCluster); + + printf("IS it only 1 cluster? %s\n" , FAT[i] == 0xFFFF? "Yes": "No" ); + + uint32_t sector = DataRegion + ((entry->StartingCluster - 0x02 ) * bpb->SectorsPerCluster); + + + uint16_t dataBlob [256]; + ATA_DEVICE::Read(BUS_PORT::Primary, DEVICE_DRIVE::MASTER, sector, dataBlob ); + for( int n = 0; n < 256; n++) + { + kterm_put(dataBlob[n] & 0x00ff); + + kterm_put(dataBlob[n] >> 8); + }kterm_put('\n'); + + + } + + printf("======================\n"); + + + } + + + + + + + wait_until_shutdown(); } + + + + + extern "C" void early_main(unsigned long magic, unsigned long addr){ + /** initialize terminal interface */ + kterm_init(); + + if (magic != MULTIBOOT_BOOTLOADER_MAGIC){ + printf("Invalid magic number: 0x%x\n", magic); + return; + } + + CheckMBT( (multiboot_info_t *) addr); + + multiboot_info_t* mbt = (multiboot_info_t*) addr; + + /* Are mmap_* valid? */ + if (CHECK_FLAG(mbt->flags, 6)){ + PhysicalMemoryManager_initialise( mbt->mmap_addr, GB2/* Seriously dangerous hardcoded memory value*/); + PhysicalMemoryManager_initialise_available_regions(mbt->mmap_addr, mbt->mmap_addr + mbt->mmap_length); + PhysicalMemoryManager_deinitialise_kernel(); + extern uint8_t* kernel_begin; + extern uint8_t* kernel_end; + + printf("Kernel MemoryMap:\n"); + printf("kernel: 0x%x - 0x%x\n", &kernel_begin , &kernel_end); + } + + initGDT(); + + + kernel_main(); + } + + diff --git a/src/kernel/kernel.h b/src/kernel/kernel.h index fe75fb4..3dad1ef 100644 --- a/src/kernel/kernel.h +++ b/src/kernel/kernel.h @@ -22,8 +22,9 @@ extern "C"{ #include "ide/ide.h" #include "./drivers/IO/ata/ataDevice.h" #include "./PartitionTable/MBR/MasterBootRecord.h" -#include "./filesytems/FAT32/BiosParameterBlock.h" -#include "./filesytems/FAT32/ExtendBootRecord.h" +#include "./filesytems/FAT/BiosParameterBlock.h" +#include "./filesytems/FAT/ExtendBootRecord.h" +#include "./filesytems/FAT/DirectoryEntry.h" #include "drivers/ACPI/rsdp.h" From a93bf566c8a65ca9a166f33943b90bbcbd848a94 Mon Sep 17 00:00:00 2001 From: Nigel Date: Sat, 12 Mar 2022 17:04:38 +0100 Subject: [PATCH 17/21] Added FAT-16 screenshot --- README.md | 3 +++ screenshots/ReadingFilesFromFAT16.png | 3 +++ 2 files changed, 6 insertions(+) create mode 100644 screenshots/ReadingFilesFromFAT16.png diff --git a/README.md b/README.md index 6e37240..ce638ec 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,9 @@ Enumerating the PCI bus ![ATAPI CD-ROM Identification](screenshots/CD-ROM_Identify.png) \ Correctly identified our ATAPI device 🎉 +![Reading Files from FAT-16](screenshots/ReadingFilesFromFAT16.png) \ +Reading a file from a FAT-16 Formatted drive + ________________________ ### The goal diff --git a/screenshots/ReadingFilesFromFAT16.png b/screenshots/ReadingFilesFromFAT16.png new file mode 100644 index 0000000..f203823 --- /dev/null +++ b/screenshots/ReadingFilesFromFAT16.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ab26fe8f7b0d9fca81e8481a67796e93bbc2fb7369accac03a9aaecf415cd4de +size 27813 From 2e2693d1ea64eaca8e3e358bfd627c2483f580b8 Mon Sep 17 00:00:00 2001 From: Nigel Date: Tue, 15 Mar 2022 21:56:32 +0100 Subject: [PATCH 18/21] Build some structures will need for the virtual filesystem --- .../EXT2/SuperBlock.h | 0 .../FAT/BiosParameterBlock.h | 0 .../FAT/DirectoryEntry.h | 0 .../FAT/ExtendBootRecord.h | 0 src/kernel/kernel.h | 6 +-- src/kernel/vfs/File.h | 9 ++++ src/kernel/vfs/VFS.cpp | 50 +++++++++++++++++++ src/kernel/vfs/VFS.h | 29 +++++++++++ 8 files changed, 91 insertions(+), 3 deletions(-) rename src/kernel/{filesytems => filesystems}/EXT2/SuperBlock.h (100%) rename src/kernel/{filesytems => filesystems}/FAT/BiosParameterBlock.h (100%) rename src/kernel/{filesytems => filesystems}/FAT/DirectoryEntry.h (100%) rename src/kernel/{filesytems => filesystems}/FAT/ExtendBootRecord.h (100%) create mode 100644 src/kernel/vfs/File.h create mode 100644 src/kernel/vfs/VFS.cpp create mode 100644 src/kernel/vfs/VFS.h diff --git a/src/kernel/filesytems/EXT2/SuperBlock.h b/src/kernel/filesystems/EXT2/SuperBlock.h similarity index 100% rename from src/kernel/filesytems/EXT2/SuperBlock.h rename to src/kernel/filesystems/EXT2/SuperBlock.h diff --git a/src/kernel/filesytems/FAT/BiosParameterBlock.h b/src/kernel/filesystems/FAT/BiosParameterBlock.h similarity index 100% rename from src/kernel/filesytems/FAT/BiosParameterBlock.h rename to src/kernel/filesystems/FAT/BiosParameterBlock.h diff --git a/src/kernel/filesytems/FAT/DirectoryEntry.h b/src/kernel/filesystems/FAT/DirectoryEntry.h similarity index 100% rename from src/kernel/filesytems/FAT/DirectoryEntry.h rename to src/kernel/filesystems/FAT/DirectoryEntry.h diff --git a/src/kernel/filesytems/FAT/ExtendBootRecord.h b/src/kernel/filesystems/FAT/ExtendBootRecord.h similarity index 100% rename from src/kernel/filesytems/FAT/ExtendBootRecord.h rename to src/kernel/filesystems/FAT/ExtendBootRecord.h diff --git a/src/kernel/kernel.h b/src/kernel/kernel.h index 26f6fa5..ac164a3 100644 --- a/src/kernel/kernel.h +++ b/src/kernel/kernel.h @@ -28,9 +28,9 @@ extern "C" #include "ide/ide.h" #include "./drivers/IO/ata/ataDevice.h" #include "./PartitionTable/MBR/MasterBootRecord.h" -#include "./filesytems/FAT/BiosParameterBlock.h" -#include "./filesytems/FAT/ExtendBootRecord.h" -#include "./filesytems/FAT/DirectoryEntry.h" +#include "./filesystems/FAT/BiosParameterBlock.h" +#include "./filesystems/FAT/ExtendBootRecord.h" +#include "./filesystems/FAT/DirectoryEntry.h" #include "drivers/ACPI/rsdp.h" diff --git a/src/kernel/vfs/File.h b/src/kernel/vfs/File.h new file mode 100644 index 0000000..5a76c48 --- /dev/null +++ b/src/kernel/vfs/File.h @@ -0,0 +1,9 @@ +#pragma once + +class File { + +public: + virtual const File* Open () const ; // TODO: figure out a proper return value + virtual const char* Read() const; + virtual void Write(); +}; diff --git a/src/kernel/vfs/VFS.cpp b/src/kernel/vfs/VFS.cpp new file mode 100644 index 0000000..8eca77a --- /dev/null +++ b/src/kernel/vfs/VFS.cpp @@ -0,0 +1,50 @@ +#include "VFS.h" +/* + * TODO: Implement this!! + * + */ + + + +void VirtualFileSystem::Initialize(FS* root) +{ + root = root; +} + +void VirtualFileSystem::Open(const char* path) +{ + /* + What does this mean? + 1. Parse the path string + 2. Traverse the graph (Finding the correct Node) + 3. Create some kind of open file pointer thingy + */ +} + +void VirtualFileSystem::Read() +{ + // NOTE: we need some way to know what file we wish to read from +} + +void VirtualFileSystem::Write() +{ + // NOTE: we need some way to know what file we wish to write to +} + +void VirtualFileSystem::Mount(const char* path, FS* FileSystem) +{ + /* + What does this mean? + 1. Parse the path string + 2. Add a node to our internal graph + */ +} + +void VirtualFileSystem::UnMount(FS* FileSystem) +{ + /* + What does this mean? + 1. Parse the path string + 2. Remve a node to our internal graph + */ +} \ No newline at end of file diff --git a/src/kernel/vfs/VFS.h b/src/kernel/vfs/VFS.h new file mode 100644 index 0000000..b525cc2 --- /dev/null +++ b/src/kernel/vfs/VFS.h @@ -0,0 +1,29 @@ +#pragma once + +class VirtualFileSystem{ +public: + void Initialize( FS* root); + void Open (const char* path); + void Read(); + void Write(); + + void Mount(const char* path,FS* FileSystem); + void UnMount(FS* FileSystem); + +private: + FS* root; + + +}; + +struct FS +{ + const char* name ; + int DeviceID; + int ManufacturerID; + FS* next; + char**(Read)(); + void*(Write)(); + void*(Open)(); +}; + From 364d10d02e3220289e399c5debad5d9ea344a68c Mon Sep 17 00:00:00 2001 From: Nigel Date: Sat, 10 Sep 2022 20:06:49 +0200 Subject: [PATCH 19/21] src folder -> source folder; makes merging with dev a bit easier. --- Makefile | 6 +++--- {src => source}/grub.cfg | 0 .../kernel/PartitionTable/MBR/MasterBootRecord.h | 0 .../kernel/PartitionTable/MBR/PartitionTableEntry.h | 0 {src => source}/kernel/boot.s | 10 +++++----- {src => source}/kernel/bootcheck.h | 0 {src => source}/kernel/bootinfo.h | 0 {src => source}/kernel/bootloader/multiboot.h | 0 {src => source}/kernel/cpu.h | 0 {src => source}/kernel/crti.s | 0 {src => source}/kernel/crtn.s | 0 {src => source}/kernel/definitions.h | 0 {src => source}/kernel/drivers/ACPI/rsdp.cpp | 0 {src => source}/kernel/drivers/ACPI/rsdp.h | 0 {src => source}/kernel/drivers/IO/PCI/pci.cpp | 0 {src => source}/kernel/drivers/IO/PCI/pci.h | 0 {src => source}/kernel/drivers/IO/ata/ataDevice.cpp | 0 {src => source}/kernel/drivers/IO/ata/ataDevice.h | 0 .../kernel/drivers/IO/atapi/atapiDevice.cpp | 0 {src => source}/kernel/drivers/IO/atapi/atapiDevice.h | 0 {src => source}/kernel/drivers/IO/io.cpp | 0 {src => source}/kernel/drivers/IO/io.h | 0 {src => source}/kernel/drivers/VGA/VBE.h | 0 {src => source}/kernel/drivers/VGA/colors.h | 0 {src => source}/kernel/drivers/cmos/cmos.cpp | 0 {src => source}/kernel/filesystems/EXT2/SuperBlock.h | 0 .../kernel/filesystems/FAT/BiosParameterBlock.h | 0 .../kernel/filesystems/FAT/DirectoryEntry.h | 0 .../kernel/filesystems/FAT/ExtendBootRecord.h | 0 {src => source}/kernel/gdt/gdt.s | 0 {src => source}/kernel/gdt/gdtc.cpp | 0 {src => source}/kernel/gdt/gdtc.h | 0 {src => source}/kernel/ide/ide.h | 0 {src => source}/kernel/ide/ideCommands.h | 0 {src => source}/kernel/ide/sampleIDE.definitions.h | 0 {src => source}/kernel/ide/sampleIDE.h | 0 {src => source}/kernel/idt/idt.cpp | 0 {src => source}/kernel/idt/idt.h | 0 {src => source}/kernel/idt/idt.s | 0 {src => source}/kernel/idt/scancodes/set1.h | 0 {src => source}/kernel/irq_table.s | 0 {src => source}/kernel/irs_table.s | 0 {src => source}/kernel/kernel.cpp | 0 {src => source}/kernel/kernel.h | 0 {src => source}/kernel/keyboard/keyboard.cpp | 0 {src => source}/kernel/keyboard/keyboard.h | 0 {src => source}/kernel/kstructures/bitmap.h | 0 {src => source}/kernel/linker.ld | 0 {src => source}/kernel/memory/PageDirectory.cpp | 0 {src => source}/kernel/memory/PageDirectory.h | 0 {src => source}/kernel/memory/memory.cpp | 0 {src => source}/kernel/memory/memory.h | 0 {src => source}/kernel/memory/memoryinfo.h | 0 {src => source}/kernel/memory/paging.s | 0 {src => source}/kernel/pci/pciDevice.cpp | 0 {src => source}/kernel/pci/pciDevice.h | 0 {src => source}/kernel/pic/pic.cpp | 0 {src => source}/kernel/pic/pic.h | 0 {src => source}/kernel/pit.cpp | 0 {src => source}/kernel/pit.h | 0 {src => source}/kernel/serial.h | 0 {src => source}/kernel/serial/serial.cpp | 0 {src => source}/kernel/serial/serial.h | 0 .../kernel/sv-terminal/superVisorTerminal.cpp | 0 .../kernel/sv-terminal/superVisorTerminal.h | 0 {src => source}/kernel/time.cpp | 0 {src => source}/kernel/time.h | 0 {src => source}/kernel/timer.cpp | 0 {src => source}/kernel/timer.h | 0 {src => source}/kernel/tty/kterm.cpp | 0 {src => source}/kernel/tty/kterm.h | 0 {src => source}/kernel/vfs/File.h | 0 {src => source}/kernel/vfs/VFS.cpp | 0 {src => source}/kernel/vfs/VFS.h | 0 {src => source}/libc/include/mem.h | 0 {src => source}/libc/include/string.c | 0 {src => source}/libc/include/string.h | 0 77 files changed, 8 insertions(+), 8 deletions(-) rename {src => source}/grub.cfg (100%) rename {src => source}/kernel/PartitionTable/MBR/MasterBootRecord.h (100%) rename {src => source}/kernel/PartitionTable/MBR/PartitionTableEntry.h (100%) rename {src => source}/kernel/boot.s (84%) rename {src => source}/kernel/bootcheck.h (100%) rename {src => source}/kernel/bootinfo.h (100%) rename {src => source}/kernel/bootloader/multiboot.h (100%) rename {src => source}/kernel/cpu.h (100%) rename {src => source}/kernel/crti.s (100%) rename {src => source}/kernel/crtn.s (100%) rename {src => source}/kernel/definitions.h (100%) rename {src => source}/kernel/drivers/ACPI/rsdp.cpp (100%) rename {src => source}/kernel/drivers/ACPI/rsdp.h (100%) rename {src => source}/kernel/drivers/IO/PCI/pci.cpp (100%) rename {src => source}/kernel/drivers/IO/PCI/pci.h (100%) rename {src => source}/kernel/drivers/IO/ata/ataDevice.cpp (100%) rename {src => source}/kernel/drivers/IO/ata/ataDevice.h (100%) rename {src => source}/kernel/drivers/IO/atapi/atapiDevice.cpp (100%) rename {src => source}/kernel/drivers/IO/atapi/atapiDevice.h (100%) rename {src => source}/kernel/drivers/IO/io.cpp (100%) rename {src => source}/kernel/drivers/IO/io.h (100%) rename {src => source}/kernel/drivers/VGA/VBE.h (100%) rename {src => source}/kernel/drivers/VGA/colors.h (100%) rename {src => source}/kernel/drivers/cmos/cmos.cpp (100%) rename {src => source}/kernel/filesystems/EXT2/SuperBlock.h (100%) rename {src => source}/kernel/filesystems/FAT/BiosParameterBlock.h (100%) rename {src => source}/kernel/filesystems/FAT/DirectoryEntry.h (100%) rename {src => source}/kernel/filesystems/FAT/ExtendBootRecord.h (100%) rename {src => source}/kernel/gdt/gdt.s (100%) rename {src => source}/kernel/gdt/gdtc.cpp (100%) rename {src => source}/kernel/gdt/gdtc.h (100%) rename {src => source}/kernel/ide/ide.h (100%) rename {src => source}/kernel/ide/ideCommands.h (100%) rename {src => source}/kernel/ide/sampleIDE.definitions.h (100%) rename {src => source}/kernel/ide/sampleIDE.h (100%) rename {src => source}/kernel/idt/idt.cpp (100%) rename {src => source}/kernel/idt/idt.h (100%) rename {src => source}/kernel/idt/idt.s (100%) rename {src => source}/kernel/idt/scancodes/set1.h (100%) rename {src => source}/kernel/irq_table.s (100%) rename {src => source}/kernel/irs_table.s (100%) rename {src => source}/kernel/kernel.cpp (100%) rename {src => source}/kernel/kernel.h (100%) rename {src => source}/kernel/keyboard/keyboard.cpp (100%) rename {src => source}/kernel/keyboard/keyboard.h (100%) rename {src => source}/kernel/kstructures/bitmap.h (100%) rename {src => source}/kernel/linker.ld (100%) rename {src => source}/kernel/memory/PageDirectory.cpp (100%) rename {src => source}/kernel/memory/PageDirectory.h (100%) rename {src => source}/kernel/memory/memory.cpp (100%) rename {src => source}/kernel/memory/memory.h (100%) rename {src => source}/kernel/memory/memoryinfo.h (100%) rename {src => source}/kernel/memory/paging.s (100%) rename {src => source}/kernel/pci/pciDevice.cpp (100%) rename {src => source}/kernel/pci/pciDevice.h (100%) rename {src => source}/kernel/pic/pic.cpp (100%) rename {src => source}/kernel/pic/pic.h (100%) rename {src => source}/kernel/pit.cpp (100%) rename {src => source}/kernel/pit.h (100%) rename {src => source}/kernel/serial.h (100%) rename {src => source}/kernel/serial/serial.cpp (100%) rename {src => source}/kernel/serial/serial.h (100%) rename {src => source}/kernel/sv-terminal/superVisorTerminal.cpp (100%) rename {src => source}/kernel/sv-terminal/superVisorTerminal.h (100%) rename {src => source}/kernel/time.cpp (100%) rename {src => source}/kernel/time.h (100%) rename {src => source}/kernel/timer.cpp (100%) rename {src => source}/kernel/timer.h (100%) rename {src => source}/kernel/tty/kterm.cpp (100%) rename {src => source}/kernel/tty/kterm.h (100%) rename {src => source}/kernel/vfs/File.h (100%) rename {src => source}/kernel/vfs/VFS.cpp (100%) rename {src => source}/kernel/vfs/VFS.h (100%) rename {src => source}/libc/include/mem.h (100%) rename {src => source}/libc/include/string.c (100%) rename {src => source}/libc/include/string.h (100%) diff --git a/Makefile b/Makefile index 6b85a09..31eb6d9 100644 --- a/Makefile +++ b/Makefile @@ -27,7 +27,7 @@ $(BUILD_DIR)/sv-terminal.o \ -SRC_DIR = src +SRC_DIR = source BUILD_DIR = build CRTBEGIN_OBJ = $(shell $(CC) $(CFLAGS) -print-file-name=crtbegin.o) @@ -50,7 +50,7 @@ clean_iso: iso: clean_iso clean build mkdir -p root/boot/grub cp build/myos.bin root/boot/myos.bin - cp src/grub.cfg root/boot/grub/grub.cfg + cp source/grub.cfg root/boot/grub/grub.cfg grub-mkrescue -o build/barinkOS.iso root run: all virtualboxvm --startvm "BarinkOS_test" @@ -62,7 +62,7 @@ test_iso: $(EMULATOR) -boot d -cdrom $(BUILD_DIR)/barinkOS.iso -serial stdio -vga std -display gtk -m 2G -cpu core2duo build_kernel: $(OBJ_LINK_LIST) - $(CC) -T $(SRC_DIR)/kernel//linker.ld -o $(BUILD_DIR)/myos.bin \ + $(CC) -T $(SRC_DIR)/kernel/linker.ld -o $(BUILD_DIR)/myos.bin \ -ffreestanding -O2 -nostdlib $(OBJ_LINK_LIST) -lgcc build_x86_64: diff --git a/src/grub.cfg b/source/grub.cfg similarity index 100% rename from src/grub.cfg rename to source/grub.cfg diff --git a/src/kernel/PartitionTable/MBR/MasterBootRecord.h b/source/kernel/PartitionTable/MBR/MasterBootRecord.h similarity index 100% rename from src/kernel/PartitionTable/MBR/MasterBootRecord.h rename to source/kernel/PartitionTable/MBR/MasterBootRecord.h diff --git a/src/kernel/PartitionTable/MBR/PartitionTableEntry.h b/source/kernel/PartitionTable/MBR/PartitionTableEntry.h similarity index 100% rename from src/kernel/PartitionTable/MBR/PartitionTableEntry.h rename to source/kernel/PartitionTable/MBR/PartitionTableEntry.h diff --git a/src/kernel/boot.s b/source/kernel/boot.s similarity index 84% rename from src/kernel/boot.s rename to source/kernel/boot.s index 78f5912..3015e8d 100644 --- a/src/kernel/boot.s +++ b/source/kernel/boot.s @@ -21,11 +21,11 @@ stack_bottom: stack_top: .section .text -.include "./src/kernel/gdt/gdt.s" -.include "./src/kernel/irs_table.s" -.include "./src/kernel/irq_table.s" -.include "./src/kernel/idt/idt.s" -.include "./src/kernel/memory/paging.s" +.include "./source/kernel/gdt/gdt.s" +.include "./source/kernel/irs_table.s" +.include "./source/kernel/irq_table.s" +.include "./source/kernel/idt/idt.s" +.include "./source/kernel/memory/paging.s" .global _start diff --git a/src/kernel/bootcheck.h b/source/kernel/bootcheck.h similarity index 100% rename from src/kernel/bootcheck.h rename to source/kernel/bootcheck.h diff --git a/src/kernel/bootinfo.h b/source/kernel/bootinfo.h similarity index 100% rename from src/kernel/bootinfo.h rename to source/kernel/bootinfo.h diff --git a/src/kernel/bootloader/multiboot.h b/source/kernel/bootloader/multiboot.h similarity index 100% rename from src/kernel/bootloader/multiboot.h rename to source/kernel/bootloader/multiboot.h diff --git a/src/kernel/cpu.h b/source/kernel/cpu.h similarity index 100% rename from src/kernel/cpu.h rename to source/kernel/cpu.h diff --git a/src/kernel/crti.s b/source/kernel/crti.s similarity index 100% rename from src/kernel/crti.s rename to source/kernel/crti.s diff --git a/src/kernel/crtn.s b/source/kernel/crtn.s similarity index 100% rename from src/kernel/crtn.s rename to source/kernel/crtn.s diff --git a/src/kernel/definitions.h b/source/kernel/definitions.h similarity index 100% rename from src/kernel/definitions.h rename to source/kernel/definitions.h diff --git a/src/kernel/drivers/ACPI/rsdp.cpp b/source/kernel/drivers/ACPI/rsdp.cpp similarity index 100% rename from src/kernel/drivers/ACPI/rsdp.cpp rename to source/kernel/drivers/ACPI/rsdp.cpp diff --git a/src/kernel/drivers/ACPI/rsdp.h b/source/kernel/drivers/ACPI/rsdp.h similarity index 100% rename from src/kernel/drivers/ACPI/rsdp.h rename to source/kernel/drivers/ACPI/rsdp.h diff --git a/src/kernel/drivers/IO/PCI/pci.cpp b/source/kernel/drivers/IO/PCI/pci.cpp similarity index 100% rename from src/kernel/drivers/IO/PCI/pci.cpp rename to source/kernel/drivers/IO/PCI/pci.cpp diff --git a/src/kernel/drivers/IO/PCI/pci.h b/source/kernel/drivers/IO/PCI/pci.h similarity index 100% rename from src/kernel/drivers/IO/PCI/pci.h rename to source/kernel/drivers/IO/PCI/pci.h diff --git a/src/kernel/drivers/IO/ata/ataDevice.cpp b/source/kernel/drivers/IO/ata/ataDevice.cpp similarity index 100% rename from src/kernel/drivers/IO/ata/ataDevice.cpp rename to source/kernel/drivers/IO/ata/ataDevice.cpp diff --git a/src/kernel/drivers/IO/ata/ataDevice.h b/source/kernel/drivers/IO/ata/ataDevice.h similarity index 100% rename from src/kernel/drivers/IO/ata/ataDevice.h rename to source/kernel/drivers/IO/ata/ataDevice.h diff --git a/src/kernel/drivers/IO/atapi/atapiDevice.cpp b/source/kernel/drivers/IO/atapi/atapiDevice.cpp similarity index 100% rename from src/kernel/drivers/IO/atapi/atapiDevice.cpp rename to source/kernel/drivers/IO/atapi/atapiDevice.cpp diff --git a/src/kernel/drivers/IO/atapi/atapiDevice.h b/source/kernel/drivers/IO/atapi/atapiDevice.h similarity index 100% rename from src/kernel/drivers/IO/atapi/atapiDevice.h rename to source/kernel/drivers/IO/atapi/atapiDevice.h diff --git a/src/kernel/drivers/IO/io.cpp b/source/kernel/drivers/IO/io.cpp similarity index 100% rename from src/kernel/drivers/IO/io.cpp rename to source/kernel/drivers/IO/io.cpp diff --git a/src/kernel/drivers/IO/io.h b/source/kernel/drivers/IO/io.h similarity index 100% rename from src/kernel/drivers/IO/io.h rename to source/kernel/drivers/IO/io.h diff --git a/src/kernel/drivers/VGA/VBE.h b/source/kernel/drivers/VGA/VBE.h similarity index 100% rename from src/kernel/drivers/VGA/VBE.h rename to source/kernel/drivers/VGA/VBE.h diff --git a/src/kernel/drivers/VGA/colors.h b/source/kernel/drivers/VGA/colors.h similarity index 100% rename from src/kernel/drivers/VGA/colors.h rename to source/kernel/drivers/VGA/colors.h diff --git a/src/kernel/drivers/cmos/cmos.cpp b/source/kernel/drivers/cmos/cmos.cpp similarity index 100% rename from src/kernel/drivers/cmos/cmos.cpp rename to source/kernel/drivers/cmos/cmos.cpp diff --git a/src/kernel/filesystems/EXT2/SuperBlock.h b/source/kernel/filesystems/EXT2/SuperBlock.h similarity index 100% rename from src/kernel/filesystems/EXT2/SuperBlock.h rename to source/kernel/filesystems/EXT2/SuperBlock.h diff --git a/src/kernel/filesystems/FAT/BiosParameterBlock.h b/source/kernel/filesystems/FAT/BiosParameterBlock.h similarity index 100% rename from src/kernel/filesystems/FAT/BiosParameterBlock.h rename to source/kernel/filesystems/FAT/BiosParameterBlock.h diff --git a/src/kernel/filesystems/FAT/DirectoryEntry.h b/source/kernel/filesystems/FAT/DirectoryEntry.h similarity index 100% rename from src/kernel/filesystems/FAT/DirectoryEntry.h rename to source/kernel/filesystems/FAT/DirectoryEntry.h diff --git a/src/kernel/filesystems/FAT/ExtendBootRecord.h b/source/kernel/filesystems/FAT/ExtendBootRecord.h similarity index 100% rename from src/kernel/filesystems/FAT/ExtendBootRecord.h rename to source/kernel/filesystems/FAT/ExtendBootRecord.h diff --git a/src/kernel/gdt/gdt.s b/source/kernel/gdt/gdt.s similarity index 100% rename from src/kernel/gdt/gdt.s rename to source/kernel/gdt/gdt.s diff --git a/src/kernel/gdt/gdtc.cpp b/source/kernel/gdt/gdtc.cpp similarity index 100% rename from src/kernel/gdt/gdtc.cpp rename to source/kernel/gdt/gdtc.cpp diff --git a/src/kernel/gdt/gdtc.h b/source/kernel/gdt/gdtc.h similarity index 100% rename from src/kernel/gdt/gdtc.h rename to source/kernel/gdt/gdtc.h diff --git a/src/kernel/ide/ide.h b/source/kernel/ide/ide.h similarity index 100% rename from src/kernel/ide/ide.h rename to source/kernel/ide/ide.h diff --git a/src/kernel/ide/ideCommands.h b/source/kernel/ide/ideCommands.h similarity index 100% rename from src/kernel/ide/ideCommands.h rename to source/kernel/ide/ideCommands.h diff --git a/src/kernel/ide/sampleIDE.definitions.h b/source/kernel/ide/sampleIDE.definitions.h similarity index 100% rename from src/kernel/ide/sampleIDE.definitions.h rename to source/kernel/ide/sampleIDE.definitions.h diff --git a/src/kernel/ide/sampleIDE.h b/source/kernel/ide/sampleIDE.h similarity index 100% rename from src/kernel/ide/sampleIDE.h rename to source/kernel/ide/sampleIDE.h diff --git a/src/kernel/idt/idt.cpp b/source/kernel/idt/idt.cpp similarity index 100% rename from src/kernel/idt/idt.cpp rename to source/kernel/idt/idt.cpp diff --git a/src/kernel/idt/idt.h b/source/kernel/idt/idt.h similarity index 100% rename from src/kernel/idt/idt.h rename to source/kernel/idt/idt.h diff --git a/src/kernel/idt/idt.s b/source/kernel/idt/idt.s similarity index 100% rename from src/kernel/idt/idt.s rename to source/kernel/idt/idt.s diff --git a/src/kernel/idt/scancodes/set1.h b/source/kernel/idt/scancodes/set1.h similarity index 100% rename from src/kernel/idt/scancodes/set1.h rename to source/kernel/idt/scancodes/set1.h diff --git a/src/kernel/irq_table.s b/source/kernel/irq_table.s similarity index 100% rename from src/kernel/irq_table.s rename to source/kernel/irq_table.s diff --git a/src/kernel/irs_table.s b/source/kernel/irs_table.s similarity index 100% rename from src/kernel/irs_table.s rename to source/kernel/irs_table.s diff --git a/src/kernel/kernel.cpp b/source/kernel/kernel.cpp similarity index 100% rename from src/kernel/kernel.cpp rename to source/kernel/kernel.cpp diff --git a/src/kernel/kernel.h b/source/kernel/kernel.h similarity index 100% rename from src/kernel/kernel.h rename to source/kernel/kernel.h diff --git a/src/kernel/keyboard/keyboard.cpp b/source/kernel/keyboard/keyboard.cpp similarity index 100% rename from src/kernel/keyboard/keyboard.cpp rename to source/kernel/keyboard/keyboard.cpp diff --git a/src/kernel/keyboard/keyboard.h b/source/kernel/keyboard/keyboard.h similarity index 100% rename from src/kernel/keyboard/keyboard.h rename to source/kernel/keyboard/keyboard.h diff --git a/src/kernel/kstructures/bitmap.h b/source/kernel/kstructures/bitmap.h similarity index 100% rename from src/kernel/kstructures/bitmap.h rename to source/kernel/kstructures/bitmap.h diff --git a/src/kernel/linker.ld b/source/kernel/linker.ld similarity index 100% rename from src/kernel/linker.ld rename to source/kernel/linker.ld diff --git a/src/kernel/memory/PageDirectory.cpp b/source/kernel/memory/PageDirectory.cpp similarity index 100% rename from src/kernel/memory/PageDirectory.cpp rename to source/kernel/memory/PageDirectory.cpp diff --git a/src/kernel/memory/PageDirectory.h b/source/kernel/memory/PageDirectory.h similarity index 100% rename from src/kernel/memory/PageDirectory.h rename to source/kernel/memory/PageDirectory.h diff --git a/src/kernel/memory/memory.cpp b/source/kernel/memory/memory.cpp similarity index 100% rename from src/kernel/memory/memory.cpp rename to source/kernel/memory/memory.cpp diff --git a/src/kernel/memory/memory.h b/source/kernel/memory/memory.h similarity index 100% rename from src/kernel/memory/memory.h rename to source/kernel/memory/memory.h diff --git a/src/kernel/memory/memoryinfo.h b/source/kernel/memory/memoryinfo.h similarity index 100% rename from src/kernel/memory/memoryinfo.h rename to source/kernel/memory/memoryinfo.h diff --git a/src/kernel/memory/paging.s b/source/kernel/memory/paging.s similarity index 100% rename from src/kernel/memory/paging.s rename to source/kernel/memory/paging.s diff --git a/src/kernel/pci/pciDevice.cpp b/source/kernel/pci/pciDevice.cpp similarity index 100% rename from src/kernel/pci/pciDevice.cpp rename to source/kernel/pci/pciDevice.cpp diff --git a/src/kernel/pci/pciDevice.h b/source/kernel/pci/pciDevice.h similarity index 100% rename from src/kernel/pci/pciDevice.h rename to source/kernel/pci/pciDevice.h diff --git a/src/kernel/pic/pic.cpp b/source/kernel/pic/pic.cpp similarity index 100% rename from src/kernel/pic/pic.cpp rename to source/kernel/pic/pic.cpp diff --git a/src/kernel/pic/pic.h b/source/kernel/pic/pic.h similarity index 100% rename from src/kernel/pic/pic.h rename to source/kernel/pic/pic.h diff --git a/src/kernel/pit.cpp b/source/kernel/pit.cpp similarity index 100% rename from src/kernel/pit.cpp rename to source/kernel/pit.cpp diff --git a/src/kernel/pit.h b/source/kernel/pit.h similarity index 100% rename from src/kernel/pit.h rename to source/kernel/pit.h diff --git a/src/kernel/serial.h b/source/kernel/serial.h similarity index 100% rename from src/kernel/serial.h rename to source/kernel/serial.h diff --git a/src/kernel/serial/serial.cpp b/source/kernel/serial/serial.cpp similarity index 100% rename from src/kernel/serial/serial.cpp rename to source/kernel/serial/serial.cpp diff --git a/src/kernel/serial/serial.h b/source/kernel/serial/serial.h similarity index 100% rename from src/kernel/serial/serial.h rename to source/kernel/serial/serial.h diff --git a/src/kernel/sv-terminal/superVisorTerminal.cpp b/source/kernel/sv-terminal/superVisorTerminal.cpp similarity index 100% rename from src/kernel/sv-terminal/superVisorTerminal.cpp rename to source/kernel/sv-terminal/superVisorTerminal.cpp diff --git a/src/kernel/sv-terminal/superVisorTerminal.h b/source/kernel/sv-terminal/superVisorTerminal.h similarity index 100% rename from src/kernel/sv-terminal/superVisorTerminal.h rename to source/kernel/sv-terminal/superVisorTerminal.h diff --git a/src/kernel/time.cpp b/source/kernel/time.cpp similarity index 100% rename from src/kernel/time.cpp rename to source/kernel/time.cpp diff --git a/src/kernel/time.h b/source/kernel/time.h similarity index 100% rename from src/kernel/time.h rename to source/kernel/time.h diff --git a/src/kernel/timer.cpp b/source/kernel/timer.cpp similarity index 100% rename from src/kernel/timer.cpp rename to source/kernel/timer.cpp diff --git a/src/kernel/timer.h b/source/kernel/timer.h similarity index 100% rename from src/kernel/timer.h rename to source/kernel/timer.h diff --git a/src/kernel/tty/kterm.cpp b/source/kernel/tty/kterm.cpp similarity index 100% rename from src/kernel/tty/kterm.cpp rename to source/kernel/tty/kterm.cpp diff --git a/src/kernel/tty/kterm.h b/source/kernel/tty/kterm.h similarity index 100% rename from src/kernel/tty/kterm.h rename to source/kernel/tty/kterm.h diff --git a/src/kernel/vfs/File.h b/source/kernel/vfs/File.h similarity index 100% rename from src/kernel/vfs/File.h rename to source/kernel/vfs/File.h diff --git a/src/kernel/vfs/VFS.cpp b/source/kernel/vfs/VFS.cpp similarity index 100% rename from src/kernel/vfs/VFS.cpp rename to source/kernel/vfs/VFS.cpp diff --git a/src/kernel/vfs/VFS.h b/source/kernel/vfs/VFS.h similarity index 100% rename from src/kernel/vfs/VFS.h rename to source/kernel/vfs/VFS.h diff --git a/src/libc/include/mem.h b/source/libc/include/mem.h similarity index 100% rename from src/libc/include/mem.h rename to source/libc/include/mem.h diff --git a/src/libc/include/string.c b/source/libc/include/string.c similarity index 100% rename from src/libc/include/string.c rename to source/libc/include/string.c diff --git a/src/libc/include/string.h b/source/libc/include/string.h similarity index 100% rename from src/libc/include/string.h rename to source/libc/include/string.h From 891085e151966f1b21363e80139501137622eb88 Mon Sep 17 00:00:00 2001 From: Nigel Date: Thu, 2 Feb 2023 14:59:42 +0100 Subject: [PATCH 20/21] Successfully able to create a disk-image file - Created a scripts folder - Written instructions on how to create the disk image - Working on a python build script that executes all other scripts The scripts folder should contain scripts to build a full installation of our operating system. Scripts like creating a filesystem should be found here --- Makefile | 3 ++ scripts/build.py | 25 ++++++++++++++ scripts/create-filesystem.sh | 64 ++++++++++++++++++++++++++++++++++++ scripts/test.sh | 5 +++ 4 files changed, 97 insertions(+) create mode 100755 scripts/build.py create mode 100644 scripts/create-filesystem.sh create mode 100755 scripts/test.sh diff --git a/Makefile b/Makefile index 31eb6d9..fbdbff8 100644 --- a/Makefile +++ b/Makefile @@ -60,6 +60,9 @@ test: test_iso: $(EMULATOR) -boot d -cdrom $(BUILD_DIR)/barinkOS.iso -serial stdio -vga std -display gtk -m 2G -cpu core2duo +test_disk: + $(EMULATOR) -boot d -drive format=raw,file=disk.img -serial stdio -vga std -display gtk -m 2G -cpu core2duo + build_kernel: $(OBJ_LINK_LIST) $(CC) -T $(SRC_DIR)/kernel/linker.ld -o $(BUILD_DIR)/myos.bin \ diff --git a/scripts/build.py b/scripts/build.py new file mode 100755 index 0000000..cd06dc4 --- /dev/null +++ b/scripts/build.py @@ -0,0 +1,25 @@ +#!/usr/bin/python3 +import os +import subprocess + + +print("Building BarinkOS") + + +# list and run build scripts +print("Running build-scripts") +os.chdir("scripts") + +scripts=os.listdir() +currentScript=os.path.basename(__file__) + +if currentScript in scripts: + scripts.remove(currentScript) + + +for script in scripts: + print(os.getcwd()) + print("Running:" + script) + subprocess.call(script, cwd=os.getcwd()) + +os.chdir("..") \ No newline at end of file diff --git a/scripts/create-filesystem.sh b/scripts/create-filesystem.sh new file mode 100644 index 0000000..45dc117 --- /dev/null +++ b/scripts/create-filesystem.sh @@ -0,0 +1,64 @@ +#!/bin/bash +# +# How to build a boot image +# NOTE: This script cant run properly yet +# Things described here should be done manually for now +# +# COPYRIGHT © Nigel Barink 2023 +# + +echo "Building a FAT16 filesystem" + + +su + +# dd if=/dev/zero of=diks.img bs=512 count=131072 +# fdisk disk.img +# Use the following options in fdisk (Format Disk Tool) +# We want to create a MBR (NOT GPT) Partition table containing 1 logical disk +# with a primary FAT16 partition marked bootable + +#OPTIONs + +# Create new DOS disklabel +# o +# Create new partition +# n +# Choose Primary as partition type +# p +# hit enter to choose default for the other options + +# Mark partition 1 as bootable +# a + +# Change partition type to FAT16 +# t +# Choose Partition 1 +# 1 +# Choose HEX 6 for FAT16 +# 6 + +# Sync and write changes to disk +# w + +# Create a "block" device from the disk.img +# losetup /dev/loop9 disk.img + +# Format the partition on the disk as FAT16 +# mkdosfs -F16 /dev/loop9 + +# Mount the disk to a folder on our dev machine +# mount /dev/loop9 /mnt + +# Install the grub bootloader onto the disk +# grub-install --no-floppy --modules="normal multiboot" /dev/loop9 --target=i386-pc --boot-directory=/mnt/boot --force + +# copy the necessary OS files +# cp root/boot/myos.bin /mnt/boot/myos.bin +# cp root/boot/grub/grub.cfg /mnt/boot/grub/grub.cfg + +# Unmount the device +# umount /mnt + +# Destroy the loop device +# losetup -d /dev/loop9 diff --git a/scripts/test.sh b/scripts/test.sh new file mode 100755 index 0000000..cb84bbe --- /dev/null +++ b/scripts/test.sh @@ -0,0 +1,5 @@ +#!/bin/bash +start=`date +%s` +end=`date +%s` +echo That took $((end-start)) seconds +date +"%c" -d195440409 From 749f2aa492219fd5c00ac6ed5da0af39f7e10ba9 Mon Sep 17 00:00:00 2001 From: Nigel Date: Fri, 3 Feb 2023 20:01:31 +0100 Subject: [PATCH 21/21] Updating folders name's (1) This should help merging into dev branch --- Makefile | 10 +++++----- source/kernel/boot.s | 2 +- source/kernel/{bootloader => boot}/multiboot.h | 0 source/kernel/bootcheck.h | 2 +- source/kernel/drivers/ACPI/rsdp.h | 2 +- source/kernel/drivers/IO/PCI/pci.h | 2 +- source/kernel/drivers/IO/ata/ataDevice.h | 4 ++-- source/kernel/drivers/IO/atapi/atapiDevice.h | 4 ++-- source/kernel/{ => drivers}/ide/ide.h | 2 +- source/kernel/{ => drivers}/ide/ideCommands.h | 0 .../{ => drivers}/ide/sampleIDE.definitions.h | 0 source/kernel/{ => drivers}/ide/sampleIDE.h | 2 +- source/kernel/{ => drivers}/pci/pciDevice.cpp | 0 source/kernel/{ => drivers}/pci/pciDevice.h | 0 source/kernel/{ => drivers}/pic/pic.cpp | 0 source/kernel/{ => drivers}/pic/pic.h | 2 +- source/kernel/{ => drivers/pit}/pit.cpp | 2 +- source/kernel/{ => drivers/pit}/pit.h | 2 +- .../EXT2/SuperBlock.h | 0 .../FAT/BiosParameterBlock.h | 0 .../FAT/DirectoryEntry.h | 0 .../FAT/ExtendBootRecord.h | 0 source/kernel/{ => interrupts}/idt/idt.cpp | 4 ++-- source/kernel/{ => interrupts}/idt/idt.h | 6 +++--- source/kernel/{ => interrupts}/idt/idt.s | 0 .../kernel/{ => interrupts}/idt/scancodes/set1.h | 0 source/kernel/kernel.h | 16 ++++++++-------- source/kernel/memory/memory.h | 4 ++-- source/kernel/sv-terminal/superVisorTerminal.h | 2 +- source/kernel/tty/kterm.h | 2 +- source/{libc => lib}/include/mem.h | 0 source/{libc => lib}/include/string.c | 0 source/{libc => lib}/include/string.h | 0 33 files changed, 35 insertions(+), 35 deletions(-) rename source/kernel/{bootloader => boot}/multiboot.h (100%) rename source/kernel/{ => drivers}/ide/ide.h (98%) rename source/kernel/{ => drivers}/ide/ideCommands.h (100%) rename source/kernel/{ => drivers}/ide/sampleIDE.definitions.h (100%) rename source/kernel/{ => drivers}/ide/sampleIDE.h (99%) rename source/kernel/{ => drivers}/pci/pciDevice.cpp (100%) rename source/kernel/{ => drivers}/pci/pciDevice.h (100%) rename source/kernel/{ => drivers}/pic/pic.cpp (100%) rename source/kernel/{ => drivers}/pic/pic.h (95%) rename source/kernel/{ => drivers/pit}/pit.cpp (96%) rename source/kernel/{ => drivers/pit}/pit.h (89%) rename source/kernel/{filesystems => filesystem}/EXT2/SuperBlock.h (100%) rename source/kernel/{filesystems => filesystem}/FAT/BiosParameterBlock.h (100%) rename source/kernel/{filesystems => filesystem}/FAT/DirectoryEntry.h (100%) rename source/kernel/{filesystems => filesystem}/FAT/ExtendBootRecord.h (100%) rename source/kernel/{ => interrupts}/idt/idt.cpp (99%) rename source/kernel/{ => interrupts}/idt/idt.h (94%) rename source/kernel/{ => interrupts}/idt/idt.s (100%) rename source/kernel/{ => interrupts}/idt/scancodes/set1.h (100%) rename source/{libc => lib}/include/mem.h (100%) rename source/{libc => lib}/include/string.c (100%) rename source/{libc => lib}/include/string.h (100%) diff --git a/Makefile b/Makefile index fbdbff8..22df814 100644 --- a/Makefile +++ b/Makefile @@ -95,17 +95,17 @@ $(BUILD_DIR)/io.o: $(BUILD_DIR)/idt.o: - $(CPP) -c $(SRC_DIR)/kernel/idt/idt.cpp -o $(BUILD_DIR)/idt.o $(CFLAGS) -fno-exceptions -fno-rtti + $(CPP) -c $(SRC_DIR)/kernel/interrupts/idt/idt.cpp -o $(BUILD_DIR)/idt.o $(CFLAGS) -fno-exceptions -fno-rtti $(BUILD_DIR)/gdtc.o: $(CPP) -c $(SRC_DIR)/kernel/gdt/gdtc.cpp -o $(BUILD_DIR)/gdtc.o $(CFLAGS) -fno-exceptions -fno-rtti $(BUILD_DIR)/pic.o: - $(CPP) -c $(SRC_DIR)/kernel/pic/pic.cpp -o $(BUILD_DIR)/pic.o $(CFLAGS) -fno-exceptions -fno-rtti + $(CPP) -c $(SRC_DIR)/kernel/drivers/pic/pic.cpp -o $(BUILD_DIR)/pic.o $(CFLAGS) -fno-exceptions -fno-rtti $(BUILD_DIR)/string.o: - $(CC) -c $(SRC_DIR)/libc/include/string.c -o $(BUILD_DIR)/string.o $(CFLAGS) -std=gnu99 + $(CC) -c $(SRC_DIR)/lib/include/string.c -o $(BUILD_DIR)/string.o $(CFLAGS) -std=gnu99 $(BUILD_DIR)/PhysicalMemoryManager.o: $(CPP) -c $(SRC_DIR)/kernel/memory/PhysicalMemoryManager.cpp -o $(BUILD_DIR)/PhysicalMemoryManager.o $(CFLAGS) -fno-exceptions -fno-rtti @@ -114,7 +114,7 @@ $(BUILD_DIR)/pci.o: $(CPP) -c $(SRC_DIR)/kernel/drivers/IO/PCI/pci.cpp -o $(BUILD_DIR)/pci.o $(CFLAGS) -fno-exceptions -fno-rtti $(BUILD_DIR)/pcidevice.o: - $(CPP) -c $(SRC_DIR)/kernel/pci/pciDevice.cpp -o $(BUILD_DIR)/pcidevice.o $(CFLAGS) -fno-exceptions -fno-rtti + $(CPP) -c $(SRC_DIR)/kernel/drivers/pci/pciDevice.cpp -o $(BUILD_DIR)/pcidevice.o $(CFLAGS) -fno-exceptions -fno-rtti $(BUILD_DIR)/atapiDevice.o: $(CPP) -c $(SRC_DIR)/kernel/drivers/IO/atapi/atapiDevice.cpp -o $(BUILD_DIR)/atapiDevice.o $(CFLAGS) -fno-exceptions -fno-rtti @@ -127,7 +127,7 @@ $(BUILD_DIR)/rsdp.o: $(CPP) -c $(SRC_DIR)/kernel/drivers/ACPI/rsdp.cpp -o $(BUILD_DIR)/rsdp.o $(CFLAGS) -fno-exceptions -fno-rtti $(BUILD_DIR)/pit.o: - $(CPP) -c $(SRC_DIR)/kernel/pit.cpp -o $(BUILD_DIR)/pit.o $(CFLAGS) -fno-exceptions -fno-rtti + $(CPP) -c $(SRC_DIR)/kernel/drivers/pit/pit.cpp -o $(BUILD_DIR)/pit.o $(CFLAGS) -fno-exceptions -fno-rtti $(BUILD_DIR)/keyboard.o: diff --git a/source/kernel/boot.s b/source/kernel/boot.s index 3015e8d..7cccd17 100644 --- a/source/kernel/boot.s +++ b/source/kernel/boot.s @@ -24,7 +24,7 @@ stack_top: .include "./source/kernel/gdt/gdt.s" .include "./source/kernel/irs_table.s" .include "./source/kernel/irq_table.s" -.include "./source/kernel/idt/idt.s" +.include "./source/kernel/interrupts/idt/idt.s" .include "./source/kernel/memory/paging.s" diff --git a/source/kernel/bootloader/multiboot.h b/source/kernel/boot/multiboot.h similarity index 100% rename from source/kernel/bootloader/multiboot.h rename to source/kernel/boot/multiboot.h diff --git a/source/kernel/bootcheck.h b/source/kernel/bootcheck.h index 62765a5..70c0354 100644 --- a/source/kernel/bootcheck.h +++ b/source/kernel/bootcheck.h @@ -1,5 +1,5 @@ #pragma once -#include "bootloader/multiboot.h" +#include "boot/multiboot.h" #define CHECK_FLAG(flags, bit) ((flags) & (1 <<(bit))) #include "tty/kterm.h" diff --git a/source/kernel/drivers/ACPI/rsdp.h b/source/kernel/drivers/ACPI/rsdp.h index 1bac440..cb3ac24 100644 --- a/source/kernel/drivers/ACPI/rsdp.h +++ b/source/kernel/drivers/ACPI/rsdp.h @@ -1,7 +1,7 @@ #pragma once #include #include "./../../tty/kterm.h" -#include "../../../libc/include/mem.h" +#include "../../../lib/include/mem.h" struct RSDPTR { char signature[8]; uint8_t Checksum ; diff --git a/source/kernel/drivers/IO/PCI/pci.h b/source/kernel/drivers/IO/PCI/pci.h index 9f2bba2..d9a86f4 100644 --- a/source/kernel/drivers/IO/PCI/pci.h +++ b/source/kernel/drivers/IO/PCI/pci.h @@ -2,7 +2,7 @@ #include #include "../io.h" #include "../../../tty/kterm.h" -#include "../../../pci/pciDevice.h" +#include "../../pci/pciDevice.h" // Configuration Space Access Mechanism #1 #define CONFIG_ADDRESS 0xCF8 // Configuration adress that is to be accessed diff --git a/source/kernel/drivers/IO/ata/ataDevice.h b/source/kernel/drivers/IO/ata/ataDevice.h index 89bfe7d..ab8822b 100644 --- a/source/kernel/drivers/IO/ata/ataDevice.h +++ b/source/kernel/drivers/IO/ata/ataDevice.h @@ -1,8 +1,8 @@ #pragma once #include #include "../io.h" -#include "../../../ide/ideCommands.h" -#include "../../../ide/sampleIDE.definitions.h" +#include "../../ide/ideCommands.h" +#include "../../ide/sampleIDE.definitions.h" #include "../../../tty/kterm.h" diff --git a/source/kernel/drivers/IO/atapi/atapiDevice.h b/source/kernel/drivers/IO/atapi/atapiDevice.h index 37d516e..ba06167 100644 --- a/source/kernel/drivers/IO/atapi/atapiDevice.h +++ b/source/kernel/drivers/IO/atapi/atapiDevice.h @@ -1,8 +1,8 @@ #pragma once #include #include "../io.h" -#include "../../../ide/ideCommands.h" -#include "../../../ide/sampleIDE.definitions.h" +#include "../../ide/ideCommands.h" +#include "../../ide/sampleIDE.definitions.h" #include "../../../tty/kterm.h" diff --git a/source/kernel/ide/ide.h b/source/kernel/drivers/ide/ide.h similarity index 98% rename from source/kernel/ide/ide.h rename to source/kernel/drivers/ide/ide.h index ce2ebc1..516f7c7 100644 --- a/source/kernel/ide/ide.h +++ b/source/kernel/drivers/ide/ide.h @@ -1,7 +1,7 @@ #pragma once #include #include "../pci/pciDevice.h" -#include "../tty/kterm.h" +#include "../../tty/kterm.h" #include "ideCommands.h" #include "sampleIDE.h" diff --git a/source/kernel/ide/ideCommands.h b/source/kernel/drivers/ide/ideCommands.h similarity index 100% rename from source/kernel/ide/ideCommands.h rename to source/kernel/drivers/ide/ideCommands.h diff --git a/source/kernel/ide/sampleIDE.definitions.h b/source/kernel/drivers/ide/sampleIDE.definitions.h similarity index 100% rename from source/kernel/ide/sampleIDE.definitions.h rename to source/kernel/drivers/ide/sampleIDE.definitions.h diff --git a/source/kernel/ide/sampleIDE.h b/source/kernel/drivers/ide/sampleIDE.h similarity index 99% rename from source/kernel/ide/sampleIDE.h rename to source/kernel/drivers/ide/sampleIDE.h index 5e805e3..ad978b5 100644 --- a/source/kernel/ide/sampleIDE.h +++ b/source/kernel/drivers/ide/sampleIDE.h @@ -1,6 +1,6 @@ #pragma once #include -#include "../tty/kterm.h" +#include "../../tty/kterm.h" #include "sampleIDE.definitions.h" #include "ideCommands.h" diff --git a/source/kernel/pci/pciDevice.cpp b/source/kernel/drivers/pci/pciDevice.cpp similarity index 100% rename from source/kernel/pci/pciDevice.cpp rename to source/kernel/drivers/pci/pciDevice.cpp diff --git a/source/kernel/pci/pciDevice.h b/source/kernel/drivers/pci/pciDevice.h similarity index 100% rename from source/kernel/pci/pciDevice.h rename to source/kernel/drivers/pci/pciDevice.h diff --git a/source/kernel/pic/pic.cpp b/source/kernel/drivers/pic/pic.cpp similarity index 100% rename from source/kernel/pic/pic.cpp rename to source/kernel/drivers/pic/pic.cpp diff --git a/source/kernel/pic/pic.h b/source/kernel/drivers/pic/pic.h similarity index 95% rename from source/kernel/pic/pic.h rename to source/kernel/drivers/pic/pic.h index fa06d3d..9f05d73 100644 --- a/source/kernel/pic/pic.h +++ b/source/kernel/drivers/pic/pic.h @@ -1,5 +1,5 @@ #pragma once -#include "../drivers/IO/io.h" +#include "../IO/io.h" #define PIC1 0x20 /* IO base address for master PIC */ #define PIC2 0xA0 /* IO base address for slave PIC */ diff --git a/source/kernel/pit.cpp b/source/kernel/drivers/pit/pit.cpp similarity index 96% rename from source/kernel/pit.cpp rename to source/kernel/drivers/pit/pit.cpp index d2b6527..d345517 100644 --- a/source/kernel/pit.cpp +++ b/source/kernel/drivers/pit/pit.cpp @@ -1,5 +1,5 @@ #include "pit.h" -#include "tty/kterm.h" +#include "../../tty/kterm.h" uint32_t pit_tick = 0; diff --git a/source/kernel/pit.h b/source/kernel/drivers/pit/pit.h similarity index 89% rename from source/kernel/pit.h rename to source/kernel/drivers/pit/pit.h index 0bc988f..268937a 100644 --- a/source/kernel/pit.h +++ b/source/kernel/drivers/pit/pit.h @@ -1,6 +1,6 @@ #pragma once #include -#include "drivers/IO/io.h" +#include "../IO/io.h" #define PIT_DATA_0 0x40 #define PIT_DATA_1 0x41 #define PIT_DATA_2 0x42 diff --git a/source/kernel/filesystems/EXT2/SuperBlock.h b/source/kernel/filesystem/EXT2/SuperBlock.h similarity index 100% rename from source/kernel/filesystems/EXT2/SuperBlock.h rename to source/kernel/filesystem/EXT2/SuperBlock.h diff --git a/source/kernel/filesystems/FAT/BiosParameterBlock.h b/source/kernel/filesystem/FAT/BiosParameterBlock.h similarity index 100% rename from source/kernel/filesystems/FAT/BiosParameterBlock.h rename to source/kernel/filesystem/FAT/BiosParameterBlock.h diff --git a/source/kernel/filesystems/FAT/DirectoryEntry.h b/source/kernel/filesystem/FAT/DirectoryEntry.h similarity index 100% rename from source/kernel/filesystems/FAT/DirectoryEntry.h rename to source/kernel/filesystem/FAT/DirectoryEntry.h diff --git a/source/kernel/filesystems/FAT/ExtendBootRecord.h b/source/kernel/filesystem/FAT/ExtendBootRecord.h similarity index 100% rename from source/kernel/filesystems/FAT/ExtendBootRecord.h rename to source/kernel/filesystem/FAT/ExtendBootRecord.h diff --git a/source/kernel/idt/idt.cpp b/source/kernel/interrupts/idt/idt.cpp similarity index 99% rename from source/kernel/idt/idt.cpp rename to source/kernel/interrupts/idt/idt.cpp index 393902b..6184dd8 100644 --- a/source/kernel/idt/idt.cpp +++ b/source/kernel/interrupts/idt/idt.cpp @@ -1,6 +1,6 @@ #include "idt.h" -#include "../pit.h" -#include "../keyboard/keyboard.h" +#include "../../drivers/pit/pit.h" +#include "../../keyboard/keyboard.h" IDT_entry idt_table[256]; IDT_ptr idt_ptr; diff --git a/source/kernel/idt/idt.h b/source/kernel/interrupts/idt/idt.h similarity index 94% rename from source/kernel/idt/idt.h rename to source/kernel/interrupts/idt/idt.h index 48c026c..b09d7c6 100644 --- a/source/kernel/idt/idt.h +++ b/source/kernel/interrupts/idt/idt.h @@ -2,10 +2,10 @@ #include "stdint.h" #include "stddef.h" -#include "../drivers/VGA/colors.h" -#include "../pic/pic.h" +#include "../../drivers/VGA/colors.h" +#include "../../drivers/pic/pic.h" -#include "../tty/kterm.h" +#include "../../tty/kterm.h" extern "C" { diff --git a/source/kernel/idt/idt.s b/source/kernel/interrupts/idt/idt.s similarity index 100% rename from source/kernel/idt/idt.s rename to source/kernel/interrupts/idt/idt.s diff --git a/source/kernel/idt/scancodes/set1.h b/source/kernel/interrupts/idt/scancodes/set1.h similarity index 100% rename from source/kernel/idt/scancodes/set1.h rename to source/kernel/interrupts/idt/scancodes/set1.h diff --git a/source/kernel/kernel.h b/source/kernel/kernel.h index ac164a3..30285b9 100644 --- a/source/kernel/kernel.h +++ b/source/kernel/kernel.h @@ -1,14 +1,14 @@ #pragma once extern "C" { - #include "../libc/include/string.h" + #include "../lib/include/string.h" } #include "drivers/VGA/VBE.h" #include "tty/kterm.h" -#include "./bootloader/multiboot.h" +#include "./boot/multiboot.h" #include "bootinfo.h" #include "memory/memory.h" @@ -16,21 +16,21 @@ extern "C" #include "bootcheck.h" #include "gdt/gdtc.h" -#include "idt/idt.h" +#include "interrupts/idt/idt.h" #include "drivers/IO/io.h" #include "time.h" -#include "pit.h" +#include "drivers/pit/pit.h" #include "cpu.h" #include "serial.h" #include "drivers/IO/PCI/pci.h" -#include "ide/ide.h" +#include "drivers/ide/ide.h" #include "./drivers/IO/ata/ataDevice.h" #include "./PartitionTable/MBR/MasterBootRecord.h" -#include "./filesystems/FAT/BiosParameterBlock.h" -#include "./filesystems/FAT/ExtendBootRecord.h" -#include "./filesystems/FAT/DirectoryEntry.h" +#include "./filesystem/FAT/BiosParameterBlock.h" +#include "./filesystem/FAT/ExtendBootRecord.h" +#include "./filesystem/FAT/DirectoryEntry.h" #include "drivers/ACPI/rsdp.h" diff --git a/source/kernel/memory/memory.h b/source/kernel/memory/memory.h index 2d0d309..9f344b1 100644 --- a/source/kernel/memory/memory.h +++ b/source/kernel/memory/memory.h @@ -3,9 +3,9 @@ #include #include "memoryinfo.h" -#include "../bootloader/multiboot.h" +#include "../boot/multiboot.h" #include "../tty/kterm.h" -#include "../../libc/include/mem.h" +#include "../../lib/include/mem.h" #include "../kstructures/bitmap.h" #define BLOCK_SIZE 4092 diff --git a/source/kernel/sv-terminal/superVisorTerminal.h b/source/kernel/sv-terminal/superVisorTerminal.h index 5d4519d..752f289 100644 --- a/source/kernel/sv-terminal/superVisorTerminal.h +++ b/source/kernel/sv-terminal/superVisorTerminal.h @@ -1,7 +1,7 @@ #pragma once #include "../tty/kterm.h" #include "../time.h" -#include "../pit.h" +#include "../drivers/pit/pit.h" #include "../keyboard/keyboard.h" #include "../memory/memory.h" #include "../bootinfo.h" diff --git a/source/kernel/tty/kterm.h b/source/kernel/tty/kterm.h index 0753294..71e45c4 100644 --- a/source/kernel/tty/kterm.h +++ b/source/kernel/tty/kterm.h @@ -8,7 +8,7 @@ #include "../drivers/IO/io.h" extern "C"{ - #include "./../../libc/include/string.h" + #include "./../../lib/include/string.h" } void kterm_init(); diff --git a/source/libc/include/mem.h b/source/lib/include/mem.h similarity index 100% rename from source/libc/include/mem.h rename to source/lib/include/mem.h diff --git a/source/libc/include/string.c b/source/lib/include/string.c similarity index 100% rename from source/libc/include/string.c rename to source/lib/include/string.c diff --git a/source/libc/include/string.h b/source/lib/include/string.h similarity index 100% rename from source/libc/include/string.h rename to source/lib/include/string.h