Lotta Disk Changes, gonna basically redo half the floppy driver in the next commit.... wish me luck lol

This commit is contained in:
Tyler McGurrin 2025-06-04 06:15:53 -04:00
parent 5298dfd20b
commit a47dfc353b
7 changed files with 110 additions and 116 deletions

View File

@ -14,7 +14,17 @@ uint8_t Read_CMOS(uint8_t Register);
enum CMOSRegisters
{
CMOS_Floppy_Register = 0x10
CMOS_Floppy_Register = 0x10,
CMOS_RTC_Seconds = 0x00,
CMOS_RTC_Minutes = 0x02,
CMOS_RTC_Hours = 0x04,
CMOS_RTC_Weekday = 0x06,
CMOS_RTC_Day = 0x07,
CMOS_RTC_Month = 0x08,
CMOS_RTC_Year = 0x09,
CMOS_RTC_Century = 0x32,
CMOS_RTC_StatusA = 0x0A,
CMOS_RTC_StatusB = 0x0B,
};
/* RTC Registers

View File

@ -7,48 +7,4 @@
#include <stdio.h>
#define PORT_DRIVE_NUMBER 502
#define PORT_SECTOR_COUNT 498
#define PORT_SECTOR_NUMBER 499
#define PORT_CYLINDER_LOW 500
#define PORT_CYLINDER_HIGH 501
#define PORT_COMMAND 503
bool ATA_Drive_Init(DISK* disk, uint8_t driveNumber)
{
uint8_t driveType;
uint16_t cylinders, sectors, heads;
if (!ATA_Get_Drive_Params(disk->id, &driveType, &cylinders, &sectors, &heads))
return false;
disk->id = driveNumber;
disk->cylinders = cylinders;
disk->heads = heads;
disk->sectors = sectors;
return true;
}
bool ATA_Get_Drive_Params(uint8_t diskID, uint8_t* driveType, uint16_t* cylinders, uint16_t* sectors, uint16_t* heads)
{
}
void ATA_CHS_Read(int number_of_sectors, int drive_number, int buffer)
{
}
void ATA_LBA2CHS(DISK* disk, uint32_t lba, uint16_t* cylinderOut, uint16_t* sectorOut, uint16_t* headOut) {
// sector = (LBA % sectors per track + 1)
*sectorOut = lba % disk->sectors +1;
// cylinder = (LBA / sects per track / heads)
*cylinderOut = (lba / disk->sectors) / disk->heads;
// head = (LBA / sects per track % heads)
*headOut = (lba / disk->sectors) % disk->heads;
// printf("LBA2CHS: lba=%u sect=%u cyl=%u head=%u disk_sectors=%u disk_heads=%u\n", lba, *sectorOut, *cylinderOut, *headOut, disk->sectors, disk->heads);
}
// This Will one day be done, floppy disk comes first (its easier)

View File

@ -8,13 +8,5 @@
#include <stdbool.h>
#include <stdint.h>
typedef struct {
uint8_t id;
uint16_t cylinders;
uint16_t sectors;
uint16_t heads;
} DISK;
bool ATA_Drive_Init(DISK* disk, uint8_t driveNumber);
void ATA_LBA2CHS(DISK* disk, uint32_t lba, uint16_t* cylinderOut, uint16_t* sectorOut, uint16_t* headOut);
bool ATA_Get_Drive_Params(uint8_t disk, uint8_t* driveType, uint16_t* cylinders, uint16_t* sectors, uint16_t* heads);
// bool ATA_Drive_Init(DISK* disk, uint8_t driveNumber);
// bool ATA_Get_Drive_Params(uint8_t disk, uint8_t* driveType, uint16_t* cylinders, uint16_t* sectors, uint16_t* heads);

View File

@ -9,15 +9,40 @@
#include <stdio.h>
#include <arch/i686/io.h>
#include <arch/i686/irq.h>
#include <dri/serial.h>
extern uint16_t DEBUG_COM_PORT;
volatile unsigned char FloppyIRQRecived = false;
void Floppy_Handler()
{
printf("IRQ 6 Called");
FloppyIRQRecived = true;
Serial_Printf(DEBUG_COM_PORT, "Recived IRQ From Floppy Drive.\n");
}
void Floppy_Drive_Start(uint8_t drive)
void Floppy_Drive_Init(uint8_t drive)
{
uint8_t Buffer;
if (drive == 1) Buffer = 0 && DOR_DSEL1 && DOR_RESET && DOR_MOTA && 0 && 0 && 0;
if (drive == 2) Buffer = 0 && DOR_DSEL1 && DOR_RESET && 0 && DOR_MOTB && 0 && 0;
if (drive == 1) Buffer = FLOPPY_DOR_DSEL1 && FLOPPY_DOR_DSEL1 && FLOPPY_DOR_RESET && FLOPPY_DOR_MOTA && 0 && 0 && 0;
if (drive == 2) Buffer = FLOPPY_DOR_DSEL1 && FLOPPY_DOR_DSEL1 && FLOPPY_DOR_RESET && 0 && FLOPPY_DOR_MOTB && 0 && 0;
i686_outb(FLOPPY_DIGITAL_OUTPUT_REGISTER, Buffer);
Serial_Printf(DEBUG_COM_PORT, "Started Floppy Drive: %u\n", drive);
}
void Floppy_Send_Command(uint8_t command)
{
i686_outb(FLOPPY_DATA_FIFO, command);
Serial_Printf(DEBUG_COM_PORT, "Floppy Command Sent: %u\n", command);
}
void Floppy_LBA2CHS(FLOPPY_DISK* disk, uint32_t lba, uint16_t* cylinderOut, uint16_t* sectorOut, uint16_t* headOut) {
// sector = (LBA % sectors per track + 1)
*sectorOut = lba % disk->sectors +1;
// cylinder = (LBA / sects per track / heads)
*cylinderOut = (lba / disk->sectors) / disk->heads;
// head = (LBA / sects per track % heads)
*headOut = (lba / disk->sectors) % disk->heads;
}

View File

@ -7,8 +7,17 @@
#include <stdint.h>
void Floppy_Handler();
void Floppy_Drive_Start(uint8_t drive);
typedef struct {
uint8_t id;
uint16_t cylinders;
uint16_t sectors;
uint16_t heads;
} FLOPPY_DISK;
void FLPDSK_Handler();
void FLPDSK_Drive_Init(uint8_t drive);
/* DOR Command Table
@ -23,13 +32,13 @@ Mnemonic bit number value meaning/usage
*/
enum FloppyDORBitflags
{
DOR_MOTD = 0x80,
DOR_MOTC = 0x40,
DOR_MOTB = 0x20,
DOR_MOTA = 0x10,
DOR_IRQ = 0x08,
DOR_RESET = 0x04,
DOR_DSEL1 = 0x01
FLOPPY_DOR_MOTD = 0x80,
FLOPPY_DOR_MOTC = 0x40,
FLOPPY_DOR_MOTB = 0x20,
FLOPPY_DOR_MOTA = 0x10,
FLOPPY_DOR_IRQ = 0x08,
FLOPPY_DOR_RESET = 0x04,
FLOPPY_DOR_DSEL1 = 0x01
};
/* MSR Commands
Mnemonic Bit Value
@ -44,51 +53,51 @@ Mnemonic Bit Value
*/
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
FLOPPY_MSR_RQM = 0x80, // Set if it's OK (or mandatory) to exchange bytes with the FIFO IO port
FLOPPY_MSR_DIO = 0x40, // Set if FIFO IO port expects an IN opcode
FLOPPY_MSR_NDMA = 0x20, // Set in Execution phase of PIO mode read/write commands only.
FLOPPY_MSR_CB = 0x10, // Command Busy: set when command byte received, cleared at end of Result phase
FLOPPY_MSR_ACTD = 0x08, // Drive 3 is seeking
FLOPPY_MSR_ACTC = 0x04, // Drive 2 is seeking
FLOPPY_MSR_ACTB = 0x02, // Drive 1 is seeking
FLOPPY_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
FLOPPY_STATUS_REGISTER_A = 0x3F0, // read-only
FLOPPY_STATUS_REGISTER_B = 0x3F1, // read-only
FLOPPY_DIGITAL_OUTPUT_REGISTER = 0x3F2,
FLOPPY_TAPE_DRIVE_REGISTER = 0x3F3, // Basically Useless, unless for some reason you have a tape drive
FLOPPY_MAIN_STATUS_REGISTER = 0x3F4, // read-only
FLOPPY_DATARATE_SELECT_REGISTER = 0x3F4, // write-only
FLOPPY_DATA_FIFO = 0x3F5,
FLOPPY_DIGITAL_INPUT_REGISTER = 0x3F7, // read-only
FLOPPY_CONFIGURATION_CONTROL_REGISTER = 0x3F7 // write-only
};
enum FloppyCommands
{
READ_TRACK = 2, // generates IRQ6
SPECIFY = 3, // * set drive parameters
SENSE_DRIVE_STATUS = 4,
WRITE_DATA = 5, // * write to the disk
READ_DATA = 6, // * read from the disk
RECALIBRATE = 7, // * seek to cylinder 0
SENSE_INTERRUPT = 8, // * ack IRQ6, get status of last command
WRITE_DELETED_DATA = 9,
READ_ID = 10, // generates IRQ6
READ_DELETED_DATA = 12,
FORMAT_TRACK = 13, // *
DUMPREG = 14,
SEEK = 15, // * seek both heads to cylinder X
VERSION = 16, // * used during initialization, once
SCAN_EQUAL = 17,
PERPENDICULAR_MODE = 18, // * used during initialization, once, maybe
CONFIGURE = 19, // * set controller parameters
LOCK = 20, // * protect controller params from a reset
VERIFY = 22,
SCAN_LOW_OR_EQUAL = 25,
SCAN_HIGH_OR_EQUAL = 29
FLOPPY_READ_TRACK = 2, // generates IRQ6
FLOPPY_SPECIFY = 3, // * set drive parameters
FLOPPY_SENSE_DRIVE_STATUS = 4,
FLOPPY_WRITE_DATA = 5, // * write to the disk
FLOPPY_READ_DATA = 6, // * read from the disk
FLOPPY_RECALIBRATE = 7, // * seek to cylinder 0
FLOPPY_SENSE_INTERRUPT = 8, // * ack IRQ6, get status of last command
FLOPPY_WRITE_DELETED_DATA = 9,
FLOPPY_READ_ID = 10, // generates IRQ6
FLOPPY_READ_DELETED_DATA = 12,
FLOPPY_FORMAT_TRACK = 13, // *
FLOPPY_DUMPREG = 14,
FLOPPY_SEEK = 15, // * seek both heads to cylinder X
FLOPPY_VERSION = 16, // * used during initialization, once
FLOPPY_SCAN_EQUAL = 17,
FLOPPY_PERPENDICULAR_MODE = 18, // * used during initialization, once, maybe
FLOPPY_CONFIGURE = 19, // * set controller parameters
FLOPPY_LOCK = 20, // * protect controller params from a reset
FLOPPY_VERIFY = 22,
FLOPPY_SCAN_LOW_OR_EQUAL = 25,
FLOPPY_SCAN_HIGH_OR_EQUAL = 29
};

View File

@ -26,6 +26,8 @@
extern uint8_t __bss_start;
extern uint8_t __end;
uint16_t DEBUG_COM_PORT = COM1_PORT;
int masterFDDType;
int slaveFDDType;
@ -42,7 +44,7 @@ void keyboard()
{
keyboard_scancode = i686_inb(PS2_KEYBOARD_PORT);
// Debug Message, need to make a serial output thingy :)
Serial_Printf(COM1_PORT, "Keycode = %d Port = %d\n", keyboard_scancode, PS2_KEYBOARD_PORT);
Serial_Printf(DEBUG_COM_PORT, "Keycode = %d Port = %d\n", keyboard_scancode, PS2_KEYBOARD_PORT);
}
void __attribute__((section(".entry"))) start(BootParams* bootParams) {
@ -58,7 +60,7 @@ void __attribute__((section(".entry"))) start(BootParams* bootParams) {
HAL_Initialize();
movecursorpos(19, 8);
printf("Done!\n\n\n\n\n");
Init_Serial(COM1_PORT, 9600);
Init_Serial(DEBUG_COM_PORT, 9600);
i686_IRQ_RegisterHandler(0, timer);
i686_IRQ_RegisterHandler(8, CMOS_RTC_Handler);
i686_IRQ_RegisterHandler(4, COM1_Serial_Handler);
@ -69,11 +71,11 @@ void __attribute__((section(".entry"))) start(BootParams* bootParams) {
printf("Done!\n");
printf("Load Basic Storage Drivers...");
i686_IRQ_RegisterHandler(6, Floppy_Handler);
i686_IRQ_RegisterHandler(6, FLPDSK_Handler);
printf("Done!\n");
masterFDDType = Master_FDD_Detect();
slaveFDDType = Slave_FDD_Detect();
Floppy_Drive_Start(1);
FLPDSK_Drive_Init(1);
Print_Storage_Types(masterFDDType, slaveFDDType);
// printf("Kernel Params: %s\n", bootParams->KernelParams);
@ -81,11 +83,11 @@ void __attribute__((section(".entry"))) start(BootParams* bootParams) {
// Debug Info for Memory
Serial_Printf(COM1_PORT, "Memory Debug Info:\n");
Serial_Printf(COM1_PORT, "Boot Device: %x\n", bootParams->BootDevice);
Serial_Printf(COM1_PORT, "Memory Region Count: %x\n", bootParams->Memory.RegionCount);
Serial_Printf(DEBUG_COM_PORT, "Memory Debug Info:\n");
Serial_Printf(DEBUG_COM_PORT, "Boot Device: %x\n", bootParams->BootDevice);
Serial_Printf(DEBUG_COM_PORT, "Memory Region Count: %x\n", bootParams->Memory.RegionCount);
for (int i = 0; i < bootParams->Memory.RegionCount; i++) {
Serial_Printf(COM1_PORT, "Memory: start=0x%llx length=0x%llx type=0x%x\n",
Serial_Printf(DEBUG_COM_PORT, "Memory: start=0x%llx length=0x%llx type=0x%x\n",
bootParams->Memory.Regions[i].Begin, bootParams->Memory.Regions[i].Length, bootParams->Memory.Regions[i].Type);
}

View File

@ -6,5 +6,5 @@
#pragma once
#define LOGO " _ _____ _ __________________\n / | / / | / | / / _/_ __/ ____/\n / |/ / /| | / |/ // / / / / __/ \n / /| / ___ |/ /| // / / / / /___ \n/_/ |_/_/ |_/_/ |_/___/ /_/ /_____/ \n"
#define VERSION "RD-00024"
#define VERSION "RD-00025"
#define BOOTLOGO " _ ______ ____ ____ ______\n / | / / __ )/ __ \\/ __ /_ __/\n / |/ / __ / / / / / / // / \n / /| / /_/ / /_/ / /_/ // / \n/_/ |_/_____/\\____/\\____//_/ \n"