diff --git a/src/kernel/dri/cmos.c b/src/kernel/dri/cmos.c index af6f5a2..509cf06 100644 --- a/src/kernel/dri/cmos.c +++ b/src/kernel/dri/cmos.c @@ -5,8 +5,72 @@ \*----------------*/ #include "cmos.h" +#include +#include +#include +#include +#include + +#define CMOS_ADDPORT 0x70 +#define CMOS_DATAPORT 0x71 void CMOS_RTC_Handler() { +} + +uint8_t Read_CMOS(uint8_t Register) +{ + uint8_t data; + i686_outb(0x70, Register); + data = i686_inb(CMOS_DATAPORT); + return data; +} + +int Master_FDD_Detect() +{ + int Buffer; + int FDDType; + /* FDD Drive Values + Value: Drive Type: + 00h no drive + 01h 360 KB 5.25 Drive + 02h 1.2 MB 5.25 Drive + 03h 720 KB 3.5 Drive + 04h 1.44 MB 3.5 Drive + 05h 2.88 MB 3.5 drive*/ + Buffer = BCD2BIN(Read_CMOS(CMOS_Floppy_Register)); + + int bit = Get_Bit(Buffer, 1); + int i = 2; + while(i < 5) { + FDDType = bit & bit; + bit = Get_Bit(Buffer, i); + i++; + } + return FDDType; +} + +int Slave_FDD_Detect() +{ + int Buffer; + int FDDType; + /* FDD Drive Values + Value: Drive Type: + 00h no drive + 01h 360 KB 5.25 Drive + 02h 1.2 MB 5.25 Drive + 03h 720 KB 3.5 Drive + 04h 1.44 MB 3.5 Drive + 05h 2.88 MB 3.5 drive*/ + Buffer = BCD2BIN(Read_CMOS(CMOS_Floppy_Register)); + + int bit = Get_Bit(Buffer, 4); + int i = 5; + while(i < 9) { + FDDType = bit & bit; + bit = Get_Bit(Buffer, i); + i++; + } + return FDDType; } \ No newline at end of file diff --git a/src/kernel/dri/cmos.h b/src/kernel/dri/cmos.h index f5ebd06..ed5f65e 100644 --- a/src/kernel/dri/cmos.h +++ b/src/kernel/dri/cmos.h @@ -5,4 +5,32 @@ \*----------------*/ #pragma once -void CMOS_RTC_Handler(); \ No newline at end of file +#include + +#define BCD2BIN(bcd) ((((bcd)&15) + ((bcd)>>4)*10)) + +void CMOS_RTC_Handler(); +int Master_FDD_Detect(); +int Slave_FDD_Detect(); +uint8_t Read_CMOS(uint8_t Register); + +enum CMOSRegisters +{ + CMOS_Floppy_Register = 0x10 +}; + +/* RTC Registers +Register Contents Range + 0x00 Seconds 0–59 + 0x02 Minutes 0–59 + 0x04 Hours 0–23 in 24-hour mode, + 1–12 in 12-hour mode, highest bit set if pm + 0x06 Weekday 1–7, Sunday = 1 + 0x07 Day of Month 1–31 + 0x08 Month 1–12 + 0x09 Year 0–99 + 0x32 Century (maybe) 19–20? + 0x0A Status Register A + 0x0B Status Register B + +*/ \ No newline at end of file diff --git a/src/kernel/dri/disk/floppy.c b/src/kernel/dri/disk/floppy.c index f3ebd16..eea6bf4 100644 --- a/src/kernel/dri/disk/floppy.c +++ b/src/kernel/dri/disk/floppy.c @@ -7,7 +7,6 @@ #include #include -#include #include #include @@ -15,7 +14,7 @@ void Floppy_Handler() { - + printf("IRQ 6 Called"); } @@ -28,60 +27,6 @@ void Floppy_Handler() // Basically Gonna hard-code the driver for 1.44MB Drives // Since Nanite is only capable of running off one without modifications to the bootloader, // this is not an issue... but its sure as shit annoying -int Master_FDD_Detect() -{ - uint8_t Buffer; - int FDDType; - int bit1, bit2, bit3, bit4; - /* FDD Drive Values - Value: Drive Type: - 00h no drive - 01h 360 KB 5.25 Drive - 02h 1.2 MB 5.25 Drive - 03h 720 KB 3.5 Drive - 04h 1.44 MB 3.5 Drive - 05h 2.88 MB 3.5 drive*/ - Buffer = i686_inb(PORT_FLOPPY_TYPE); +// Correction im stupid... - // bit1 = Byte_Parse(Buffer, 0); - // bit2 = Byte_Parse(Buffer, 1); - // bit3 = Byte_Parse(Buffer, 2); - // bit4 = Byte_Parse(Buffer, 3); - // printf("Bits: %d, %d, %d, %d\n", bit1, bit2, bit3, bit4); - printf("Buffer: %s", Buffer); - // int bit = Byte_Parse(Buffer, 0); - // int i = 1; - // while(i < 4) { - // FDDType = bit & bit; - // bit = Byte_Parse(Buffer, i); - // i++; - // printf("MFDD Bit %d: %d\n", i, bit); - // } - FDDType = bit1 & bit2 & bit3 & bit4; - return FDDType; -} - -int Slave_FDD_Detect() -{ - int Buffer; - int FDDType; - /* FDD Drive Values - Value: Drive Type: - 00h no drive - 01h 360 KB 5.25 Drive - 02h 1.2 MB 5.25 Drive - 03h 720 KB 3.5 Drive - 04h 1.44 MB 3.5 Drive - 05h 2.88 MB 3.5 drive*/ - Buffer = i686_inb(PORT_FLOPPY_TYPE); - - int bit = Byte_Parse(Buffer, 3); - int i = 4; - while(i < 8) { - FDDType = bit & bit; - bit = Byte_Parse(Buffer, i); - i++; - printf("SFDD Bit %d: %d\n", i, bit); - } - return FDDType; -} \ No newline at end of file +// Moved to CMOS Driver. \ No newline at end of file diff --git a/src/kernel/dri/disk/floppy.h b/src/kernel/dri/disk/floppy.h index c5b48a5..26e1a9b 100644 --- a/src/kernel/dri/disk/floppy.h +++ b/src/kernel/dri/disk/floppy.h @@ -7,6 +7,65 @@ void Floppy_Handler(); + + +/* DOR Command Table +Mnemonic bit number value meaning/usage + MOTD 7 0x80 Set to turn drive 3's motor ON + MOTC 6 0x40 Set to turn drive 2's motor ON + MOTB 5 0x20 Set to turn drive 1's motor ON + MOTA 4 0x10 Set to turn drive 0's motor ON + IRQ 3 8 Set to enable IRQs and DMA + RESET 2 4 Clear = enter reset mode, Set = normal operation + DSEL1 and 0 0, 1 3 "Select" drive number for next access +*/ +enum FloppyDORBitflags +{ + DOR_MOTD = 0x80, + DOR_MOTC = 0x40, + DOR_MOTB = 0x20, + DOR_MOTA = 0x10, + DOR_IRQ = 0x08, + DOR_RESET = 0x04, + DOR_DSEL1 = 0x01 +}; +/* MSR Commands +Mnemonic Bit Value + RQM 7 0x80 + DIO 6 0x40 + NDMA 5 0x20 + CB 4 0x10 + ACTD 3 8 + ACTC 2 4 + ACTB 1 2 + ACTA 0 1 +*/ +enum FloppyMSRBitflags +{ + MSR_RQM = 0x80, // Set if it's OK (or mandatory) to exchange bytes with the FIFO IO port + MSR_DIO = 0x40, // Set if FIFO IO port expects an IN opcode + MSR_NDMA = 0x20, // Set in Execution phase of PIO mode read/write commands only. + MSR_CB = 0x10, // Command Busy: set when command byte received, cleared at end of Result phase + MSR_ACTD = 0x08, // Drive 3 is seeking + MSR_ACTC = 0x04, // Drive 2 is seeking + MSR_ACTB = 0x02, // Drive 1 is seeking + MSR_ACTA = 0x01, // Drive 0 is seeking +}; + +// Bottom 2 Bits of DSR match CCR +enum FloppyRegisters +{ + STATUS_REGISTER_A = 0x3F0, // read-only + STATUS_REGISTER_B = 0x3F1, // read-only + DIGITAL_OUTPUT_REGISTER = 0x3F2, + TAPE_DRIVE_REGISTER = 0x3F3, // Basically Useless, unless for some reason you have a tape drive + MAIN_STATUS_REGISTER = 0x3F4, // read-only + DATARATE_SELECT_REGISTER = 0x3F4, // write-only + DATA_FIFO = 0x3F5, + DIGITAL_INPUT_REGISTER = 0x3F7, // read-only + CONFIGURATION_CONTROL_REGISTER = 0x3F7 // write-only +}; + enum FloppyCommands { READ_TRACK = 2, // generates IRQ6 diff --git a/src/kernel/main.c b/src/kernel/main.c index fb46d03..a916dcc 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -68,6 +68,9 @@ void __attribute__((section(".entry"))) start(BootParams* bootParams) { printf("Load Basic Storage Drivers..."); i686_IRQ_RegisterHandler(6, Floppy_Handler); printf("Done!\n"); + masterFDDType = Master_FDD_Detect(); + slaveFDDType = Slave_FDD_Detect(); + Print_Storage_Types(masterFDDType, slaveFDDType); diff --git a/src/kernel/util/binary.c b/src/kernel/util/binary.c index 50fb6db..00f61f6 100644 --- a/src/kernel/util/binary.c +++ b/src/kernel/util/binary.c @@ -6,10 +6,15 @@ #include -int Byte_Parse(int8_t byteFlag, int whichBit) +uint8_t Get_Bit(uint8_t bits, uint8_t pos) { - if (whichBit > 0 && whichBit <= 8) - return (byteFlag & (1<<(whichBit-1))); - else - return 0; -} \ No newline at end of file + return (bits >> pos) & 0x01; +} + +// int Byte_Parse(int8_t byteFlag, int whichBit) +// { +// if (whichBit > 0 && whichBit <= 8) +// return (byteFlag & (1<<(whichBit-1))); +// else +// return 0; +// } \ No newline at end of file diff --git a/src/kernel/util/binary.h b/src/kernel/util/binary.h index aac05d3..778024f 100644 --- a/src/kernel/util/binary.h +++ b/src/kernel/util/binary.h @@ -8,4 +8,6 @@ #define FLAG_SET(x, flag) x |= (flag) #define FLAG_UNSET(x, flag) x &= ~(flag) -int Byte_Parse(int8_t byteFlag, int whichBit); \ No newline at end of file +uint8_t Get_Bit(uint8_t bits, uint8_t pos); + +//int Byte_Parse(int8_t byteFlag, int whichBit); \ No newline at end of file diff --git a/src/libs/version.h b/src/libs/version.h index d6ce68f..def3e67 100644 --- a/src/libs/version.h +++ b/src/libs/version.h @@ -6,5 +6,5 @@ #pragma once #define LOGO " _ _____ _ __________________\n / | / / | / | / / _/_ __/ ____/\n / |/ / /| | / |/ // / / / / __/ \n / /| / ___ |/ /| // / / / / /___ \n/_/ |_/_/ |_/_/ |_/___/ /_/ /_____/ \n" -#define VERSION "RD-00012" +#define VERSION "RD-00014" #define BOOTLOGO " _ ______ ____ ____ ______\n / | / / __ )/ __ \\/ __ /_ __/\n / |/ / __ / / / / / / // / \n / /| / /_/ / /_/ / /_/ // / \n/_/ |_/_____/\\____/\\____//_/ \n"