Move HAL Stuff to /dri, begin ISA DMA Stuff

This commit is contained in:
Tyler McGurrin 2025-06-04 11:44:24 -04:00
parent 8490ef9449
commit 8197dcc01d
8 changed files with 207 additions and 5 deletions

View File

@ -298,7 +298,7 @@ void Floppy_Motor_Control(bool enable)
outb (FLOPPY_DOR, FLOPPY_DOR_MASK_DRIVE0_MOTOR | FLOPPY_DOR_MASK_RESET);
Serial_Printf(DEBUG_COM_PORT, "FLOPPY:> Starting FDD Motor.\n");
int i;
while(i >= 500) i++;
while(i >= 50) i++;
}
else {
Floppy_Reset();

87
src/kernel/dri/dma/dma.c Normal file
View File

@ -0,0 +1,87 @@
/*----------------*\
|Nanite OS |
|Copyright (C) 2025|
|Tyler McGurrin |
\*----------------*/
#include "dma.h"
void DMA_Set_Address(uint8_t channel, uint8_t low, uint8_t high)
{
if ( channel > 8 )
return;
unsigned short port = 0;
switch ( channel ) {
case 0: {port = DMA0_CHANNNEL0_ADDR_REG; break;}
case 1: {port = DMA0_CHANNNEL1_ADDR_REG; break;}
case 2: {port = DMA0_CHANNNEL2_ADDR_REG; break;}
case 3: {port = DMA0_CHANNNEL3_ADDR_REG; break;}
case 4: {port = DMA1_CHANNNEL4_ADDR_REG; break;}
case 5: {port = DMA1_CHANNNEL5_ADDR_REG; break;}
case 6: {port = DMA1_CHANNNEL6_ADDR_REG; break;}
case 7: {port = DMA1_CHANNNEL7_ADDR_REG; break;}
}
outb(port, low);
outb(port, high);
}
void DMA_Set_Count(uint8_t channel, uint8_t low, uint8_t high)
{
if (channel > 8)
return;
unsigned short port = 0;
switch (channel) {
case 0: {port = DMA0_CHANNNEL0_COUNT_REG; break;}
case 1: {port = DMA0_CHANNNEL1_COUNT_REG; break;}
case 2: {port = DMA0_CHANNNEL2_COUNT_REG; break;}
case 3: {port = DMA0_CHANNNEL3_COUNT_REG; break;}
case 4: {port = DMA1_CHANNNEL4_COUNT_REG; break;}
case 5: {port = DMA1_CHANNNEL5_COUNT_REG; break;}
case 6: {port = DMA1_CHANNNEL6_COUNT_REG; break;}
case 7: {port = DMA1_CHANNNEL7_COUNT_REG; break;}
}
outb(port, low);
outb(port, high);
}
void DMA_Set_External_Page_Register(uint8_t register, uint8_t value)
{
if (register > 14)
return;
unsigned short port = 0;
switch (register) {
case 1: {port = DMA_PAGE_CHAN1_ADDRBYTE2; break;}
case 2: {port = DMA_PAGE_CHAN2_ADDRBYTE2; break;}
case 3: {port = DMA_PAGE_CHAN3_ADDRBYTE2; break;}
case 4: {return;}// nothing should ever write to register 4
case 5: {port = DMA_PAGE_CHAN5_ADDRBYTE2; break;}
case 6: {port = DMA_PAGE_CHAN6_ADDRBYTE2; break;}
case 7: {port = DMA_PAGE_CHAN7_ADDRBYTE2; break;}
}
outb(port, value);
}
void DMA_Set_Mode(uint8_t channel, uint8_t mode)
{
int dma = (channel < 4) ? 0 : 1;
int chan = (dma==0) ? channel : channel-4;
dma_mask_channel (channel);
outportb ( (channel < 4) ? (DMA0_MODE_REG) : DMA1_MODE_REG, chan | (mode) );
dma_unmask_all ( dma );
}
// prepares channel for read
void DMA_Set_Read(uint8_t channel)
{
DMA_Set_Mode(channel, DMA_MODE_READ_TRANSFER | DMA_MODE_TRANSFER_SINGLE | DMA_MODE_MASK_AUTO);
}
//! prepares channel for write
void DMA_Set_Write(uint8_t channel)
{
DMA_Set_Mode(channel, DMA_MODE_WRITE_TRANSFER | DMA_MODE_TRANSFER_SINGLE | DMA_MODE_MASK_AUTO);
}

103
src/kernel/dri/dma/dma.h Normal file
View File

@ -0,0 +1,103 @@
/*----------------*\
|Nanite OS |
|Copyright (C) 2025|
|Tyler McGurrin |
\*----------------*/
#pragma once
enum DMA0_IO {
DMA0_STATUS_REG = 0x08,
DMA0_COMMAND_REG = 0x08,
DMA0_REQUEST_REG = 0x09,
DMA0_CHANMASK_REG = 0x0a,
DMA0_MODE_REG = 0x0b,
DMA0_CLEARBYTE_FLIPFLOP_REG = 0x0c,
DMA0_TEMP_REG = 0x0d,
DMA0_MASTER_CLEAR_REG = 0x0d,
DMA0_CLEAR_MASK_REG = 0x0e,
DMA0_MASK_REG = 0x0f
};
enum DMA1_IO {
DMA1_STATUS_REG = 0xd0,
DMA1_COMMAND_REG = 0xd0,
DMA1_REQUEST_REG = 0xd2,
DMA1_CHANMASK_REG = 0xd4,
DMA1_MODE_REG = 0xd6,
DMA1_CLEARBYTE_FLIPFLOP_REG = 0xd8,
DMA1_INTER_REG = 0xda,
DMA1_UNMASK_ALL_REG = 0xdc,
DMA1_MASK_REG = 0xde
};
enum DMA0_CHANNEL_IO {
DMA0_CHANNEL0_ADDR_REG = 0,
DMA0_CHANNEL0_COUNT_REG = 1,
DMA0_CHANNEL1_ADDR_REG = 2,
DMA0_CHANNEL1_COUNT_REG = 3,
DMA0_CHANNEL2_ADDR_REG = 4,
DMA0_CHANNEL2_COUNT_REG = 5,
DMA0_CHANNEL3_ADDR_REG = 6,
DMA0_CHANNEL3_COUNT_REG = 7,
};
enum DMA1_CHANNEL_IO {
DMA1_CHANNNEL4_ADDR_REG = 0xc0,
DMA1_CHANNNEL4_COUNT_REG = 0xc2,
DMA1_CHANNNEL5_ADDR_REG = 0xc4,
DMA1_CHANNNEL5_COUNT_REG = 0xc6,
DMA1_CHANNNEL6_ADDR_REG = 0xc8,
DMA1_CHANNNEL6_COUNT_REG = 0xca,
DMA1_CHANNNEL7_ADDR_REG = 0xcc,
DMA1_CHANNNEL7_COUNT_REG = 0xce,
};
enum DMA0_PAGE_REG {
DMA_PAGE_EXTRA0 = 0x80, // diagnostics port
DMA_PAGE_CHANNEL2_ADDRBYTE2 = 0x81,
DMA_PAGE_CHANNEL3_ADDRBYTE2 = 0x82,
DMA_PAGE_CHANNEL1_ADDRBYTE2 = 0x83,
DMA_PAGE_EXTRA1 = 0x84,
DMA_PAGE_EXTRA2 = 0x85,
DMA_PAGE_EXTRA3 = 0x86,
DMA_PAGE_CHANNEL6_ADDRBYTE2 = 0x87,
DMA_PAGE_CHANNEL7_ADDRBYTE2 = 0x88,
DMA_PAGE_CHANNEL5_ADDRBYTE2 = 0x89,
DMA_PAGE_EXTRA4 = 0x8c,
DMA_PAGE_EXTRA5 = 0x8d,
DMA_PAGE_EXTRA6 = 0x8e,
DMA_PAGE_DRAM_REFRESH = 0x8f // no longer used in new PCs...
};
enum DMA_CMD_REG_MASK {
DMA_CMD_MASK_MEMTOMEM = 1,
DMA_CMD_MASK_CHAN0ADDRHOLD = 2,
DMA_CMD_MASK_ENABLE = 4,
DMA_CMD_MASK_TIMING = 8,
DMA_CMD_MASK_PRIORITY = 0x10,
DMA_CMD_MASK_WRITESEL = 0x20,
DMA_CMD_MASK_DREQ = 0x40,
DMA_CMD_MASK_DACK = 0x80
};
enum DMA_MODE_REG_MASK {
DMA_MODE_MASK_SEL = 3,
DMA_MODE_MASK_TRA = 0xc,
DMA_MODE_SELF_TEST = 0,
DMA_MODE_READ_TRANSFER =4,
DMA_MODE_WRITE_TRANSFER = 8,
DMA_MODE_MASK_AUTO = 0x10,
DMA_MODE_MASK_IDEC = 0x20,
DMA_MODE_MASK = 0xc0,
DMA_MODE_TRANSFER_ON_DEMAND= 0,
DMA_MODE_TRANSFER_SINGLE = 0x40,
DMA_MODE_TRANSFER_BLOCK = 0x80,
DMA_MODE_TRANSFER_CASCADE = 0xC0
};

View File

@ -9,6 +9,7 @@
#include <stdbool.h>
#include <arch/i686/irq.h>
#include <arch/i686/io.h>
#include <arch/i686/basicfunc.h>
#include <dri/serial.h>
#include <stdio.h>
@ -23,7 +24,18 @@ extern uint16_t DEBUG_COM_PORT;
void Keyboard_Handler()
{
_keyboard_scancode = inb(KEYBOARD_ENC_INPUT_BUF);
Serial_Printf(DEBUG_COM_PORT, "KEYBOARD:> Scancode %u Character %s\n", _keyboard_scancode);
Serial_Printf(DEBUG_COM_PORT, "KEYBOARD:> Scancode %u\n", _keyboard_scancode);
// CTRL + ALT + SHIFT Handlers
if(_keyboard_scancode == 29) _ctrl = true;
if(_keyboard_scancode == 157) _ctrl = false;
if(_keyboard_scancode == 56) _alt = true;
if(_keyboard_scancode == 184) _alt = false;
if(_keyboard_scancode == 42) _shift = true;
if(_keyboard_scancode == 170) _shift = false;
// If CTRL+ALT+DEL Reboot
if(_keyboard_scancode == 224 && _ctrl == true && _alt == true) Reboot();
}
uint8_t Keyboard_Controller_Status()

View File

@ -6,7 +6,6 @@
#include <stdint.h>
#include <stdio.h>
#include <memory.h>
#include <hal/hal.h>
#include <arch/i686/io.h>
#include <arch/i686/irq.h>
#include <arch/i686/basicfunc.h>
@ -16,6 +15,7 @@
#include <dri/fat.h>
#include <dri/disk/floppy.h>
#include <dri/disk/ata.h>
#include <dri/hal/hal.h>
#include <util/param.h>
#include <util/util.h>
#include "../libs/version.h"
@ -64,7 +64,7 @@ void __attribute__((section(".entry"))) start(BootParams* bootParams) {
printf("Initializing Basic Drivers...");
Serial_Init(DEBUG_COM_PORT, 9600);
Keyboard_Init();
Floppy_Init();
Floppy_Init(); // This should always be last; its slow as fuck
printf("Done!\n");

View File

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