+++ /dev/null
-/*\r
- * AcessOS 1.0\r
- * DMA Driver\r
- */\r
-#include <acess.h>\r
-#include <modules.h>\r
-\r
-#define DMA_SIZE (0x2400)\r
-#define DMA_ADDRESS(c) ((c)*DMA_SIZE+0x500) //Save Space for IDT and BDA\r
-\r
-#define LOWB(x) ((x)&0xFF)\r
-#define HIB(x) (((x)>>8)&0xFF)\r
-#define HIW(x) (((x)>>16)&0xFFFF)\r
-\r
-// === TYPES ===\r
-typedef struct\r
-{\r
- int mode;\r
- char *address;\r
-} t_dmaChannel;\r
-\r
-// === PROTOTYPES ===\r
- int DMA_Install(char **Arguments);\r
-void DMA_SetChannel(int Channel, int length, int read);\r
- int DMA_ReadData(int channel, int count, void *buffer);\r
- int DMA_WriteData(int channel, int count, const void *buffer);\r
-\r
-// === CONSTANTS ===\r
-const Uint8 cMASKPORT [8] = { 0x0A, 0x0A, 0x0A, 0x0A, 0xD4, 0xD4, 0xD4, 0xD4 };\r
-const Uint8 cMODEPORT [8] = { 0x0B, 0x0B, 0x0B, 0x0B, 0xD6, 0xD6, 0xD6, 0xD6 };\r
-const Uint8 cCLEARPORT[8] = { 0x0C, 0x0C, 0x0C, 0x0C, 0xD8, 0xD8, 0xD8, 0xD8 };\r
-const Uint8 cPAGEPORT [8] = { 0x87, 0x83, 0x81, 0x82, 0x8F, 0x8B, 0x89, 0x8A };\r
-const Uint8 cADDRPORT [8] = { 0x00, 0x02, 0x04, 0x06, 0xC0, 0xC4, 0xC8, 0xCC };\r
-const Uint8 cCOUNTPORT[8] = { 0x01, 0x03, 0x05, 0x07, 0xC2, 0xC6, 0xCA, 0xCE };\r
-\r
-// === GLOBALS ===\r
-MODULE_DEFINE(0, 0x0100, ISADMA, DMA_Install, NULL, NULL);\r
-char *dma_addresses[8];\r
-t_dmaChannel dma_channels[8];\r
-\r
-// === CODE ===\r
-/**\r
- * \brief Initialise DMA channels\r
- * \param Arguments Arguments passed at boot time\r
- */\r
-int DMA_Install(char **Arguments)\r
-{\r
- Uint i;\r
- for(i=8;i--;)\r
- {\r
- outb( cMASKPORT[i], 0x04 | (i & 0x3) ); // mask channel\r
- outb( cCLEARPORT[i], 0x00 );\r
- outb( cMODEPORT[i], 0x48 | (i & 0x3) ); //Read Flag\r
- outb( 0xd8, 0xff); //Reset Flip-Flop\r
- outb( cADDRPORT[i], LOWB(DMA_ADDRESS(i)) ); // send address\r
- outb( cADDRPORT[i], HIB(DMA_ADDRESS(i)) ); // send address\r
- outb( 0xd8, 0xff); //Reset Flip-Flop\r
- outb( cCOUNTPORT[i], LOWB(DMA_SIZE) ); // send size\r
- outb( cCOUNTPORT[i], HIB(DMA_SIZE) ); // send size\r
- outb( cPAGEPORT[i], LOWB(HIW(DMA_ADDRESS(i))) ); // send page\r
- outb( cMASKPORT[i], i & 0x3 ); // unmask channel\r
- \r
- dma_channels[i].mode = 0;\r
- dma_addresses[i] = (char*)DMA_ADDRESS(i);\r
- dma_addresses[i] += KERNEL_BASE;\r
- }\r
- return MODULE_ERR_OK;\r
-}\r
-\r
-/**\r
- * \fn void DMA_SetChannel(int Channel, int length, int read)\r
- * \brief Set DMA Channel Length and RW\r
- */\r
-void DMA_SetChannel(int Channel, int length, int read)\r
-{\r
- Uint chan = Channel & 7;\r
- read = !!read;\r
- if(length > DMA_SIZE) length = DMA_SIZE;\r
- length --; //Adjust for DMA\r
- //__asm__ __volatile__ ("cli");\r
- outb( cMASKPORT[chan], 0x04 | (chan & 0x3) ); // mask channel\r
- outb( cCLEARPORT[chan], 0x00 );\r
- outb( cMODEPORT[chan], (0x44 + (!read)*4) | (chan & 0x3) );\r
- outb( cADDRPORT[chan], LOWB(DMA_ADDRESS(chan)) ); // send address\r
- outb( cADDRPORT[chan], HIB(DMA_ADDRESS(chan)) ); // send address\r
- outb( cPAGEPORT[chan], HIW(DMA_ADDRESS(chan)) ); // send page\r
- outb( cCOUNTPORT[chan], LOWB(length) ); // send size\r
- outb( cCOUNTPORT[chan], HIB(length) ); // send size\r
- outb( cMASKPORT[chan], chan & 0x3 ); // unmask channel\r
- dma_addresses[chan] = (char*)DMA_ADDRESS(chan);\r
- dma_addresses[chan] += KERNEL_BASE;\r
- //__asm__ __volatile__ ("sti");\r
-}\r
-\r
-/**\r
- * \fn void DMA_ReadData(int channel, int count, void *buffer)\r
- * \brief Read data from a DMA buffer\r
- */\r
-int DMA_ReadData(int channel, int count, void *buffer)\r
-{\r
- if(channel < 0 || channel > 7)\r
- return -1;\r
- if(count < 0 || count > DMA_SIZE)\r
- return -2;\r
- //LogF("memcpy(*0x%x, dma_channels[channel].address, count)\n", buffer\r
- memcpy(buffer, dma_addresses[channel], count);\r
- return 0;\r
-}\r
-\r
-/**\r
- * \fn void DMA_WriteData(int channel, int count, void *buffer)\r
- * \brief Write data to a DMA buffer\r
- */\r
-int DMA_WriteData(int channel, int count, const void *buffer)\r
-{\r
- if(channel < 0 || channel > 7)\r
- return -1;\r
- if(count < 0 || count > DMA_SIZE)\r
- return -2;\r
- \r
- memcpy(dma_addresses[channel], buffer, count);\r
- \r
- return 0;\r
-}\r
+++ /dev/null
-/*
- * Acess2
- * PS2 Keyboard Driver
- */
-#include <acess.h>
-#include <modules.h>
-#include <fs_devfs.h>
-#include <tpl_drv_common.h>
-#include <tpl_drv_keyboard.h>
-#include "kb_kbdus.h"
-
-// === CONSTANTS ===
-#define KB_BUFFER_SIZE 1024
-#define USE_KERNEL_MAGIC 1
-
-// === IMPORTS ===
-extern void Threads_ToggleTrace(int TID);
-extern void Threads_Dump(void);
-extern void Heap_Stats(void);
-
-// === PROTOTYPES ===
- int KB_Install(char **Arguments);
-void KB_IRQHandler(int IRQNum);
-void KB_AddBuffer(char ch);
-Uint64 KB_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Dest);
-void KB_UpdateLEDs(void);
- int KB_IOCtl(tVFS_Node *Node, int Id, void *Data);
-
-// === GLOBALS ===
-MODULE_DEFINE(0, 0x0100, PS2Keyboard, KB_Install, NULL, NULL);
-tDevFS_Driver gKB_DevInfo = {
- NULL, "PS2Keyboard",
- {
- .NumACLs = 0,
- .Size = 0,
- //.Read = KB_Read,
- .IOCtl = KB_IOCtl
- }
-};
-tKeybardCallback gKB_Callback = NULL;
-Uint32 **gpKB_Map = gpKBDUS;
-Uint8 gbaKB_States[3][256];
- int gbKB_ShiftState = 0;
- int gbKB_CapsState = 0;
- int gbKB_KeyUp = 0;
- int giKB_KeyLayer = 0;
-#if USE_KERNEL_MAGIC
- int gbKB_MagicState = 0;
- int giKB_MagicAddress = 0;
- int giKB_MagicAddressPos = 0;
-#endif
-//Uint64 giKB_ReadBase = 0;
-//Uint32 gaKB_Buffer[KB_BUFFER_SIZE]; //!< Keyboard Ring Buffer
-//volatile int giKB_InsertPoint = 0; //!< Writing location marker
-//volatile int giKB_ReadPoint = 0; //!< Reading location marker
-//volatile int giKB_InUse = 0; //!< Lock marker
-
-// === CODE ===
-/**
- * \brief Install the keyboard driver
- */
-int KB_Install(char **Arguments)
-{
- Uint8 temp;
-
- // Attempt to get around a strange bug in Bochs/Qemu by toggling
- // the controller on and off
- temp = inb(0x61);
- outb(0x61, temp | 0x80);
- outb(0x61, temp & 0x7F);
- inb(0x60); // Clear keyboard buffer
-
- IRQ_AddHandler(1, KB_IRQHandler);
- DevFS_AddDevice( &gKB_DevInfo );
- //Log("KB_Install: Installed");
- return MODULE_ERR_OK;
-}
-
-/**
- * \brief Called on a keyboard IRQ
- * \param IRQNum IRQ number (unused)
- */
-void KB_IRQHandler(int IRQNum)
-{
- Uint8 scancode;
- Uint32 ch;
- // int keyNum;
-
- // Check port 0x64 to tell if this is from the aux port
- //if( inb(0x64) & 0x20 ) return;
-
- scancode = inb(0x60); // Read from the keyboard's data buffer
- //Log_Debug("Keyboard", "scancode = %02x", scancode);
-
- // Ignore ACKs
- if(scancode == 0xFA) {
- // Oh man! This is anarchic (I'm leaving it here to represent
- // the mess that Acess once was)
- //kb_lastChar = KB_ACK;
- return;
- }
-
- // Layer +1
- if(scancode == 0xE0) {
- giKB_KeyLayer = 1;
- return;
- }
- // Layer +2
- if(scancode == 0xE1) {
- giKB_KeyLayer = 2;
- return;
- }
-
- #if KB_ALT_SCANCODES
- if(scancode == 0xF0)
- {
- gbKB_KeyUp = 1;
- return;
- }
- #else
- if(scancode & 0x80)
- {
- scancode &= 0x7F;
- gbKB_KeyUp = 1;
- }
- #endif
-
- // Translate
- ch = gpKB_Map[giKB_KeyLayer][scancode];
- //keyNum = giKB_KeyLayer * 256 + scancode;
- // Check for unknown key
- if(!ch && !gbKB_KeyUp)
- Log_Warning("Keyboard", "UNK %i %x", giKB_KeyLayer, scancode);
-
- // Key Up?
- if (gbKB_KeyUp)
- {
- gbKB_KeyUp = 0;
- gbaKB_States[giKB_KeyLayer][scancode] = 0; // Unset key state flag
-
- #if USE_KERNEL_MAGIC
- if(ch == KEY_LCTRL) gbKB_MagicState &= ~1;
- if(ch == KEY_LALT) gbKB_MagicState &= ~2;
- #endif
-
- if(ch == KEY_LSHIFT) gbKB_ShiftState &= ~1;
- if(ch == KEY_RSHIFT) gbKB_ShiftState &= ~2;
-
- // Call callback
- if(ch != 0 && gKB_Callback)
- gKB_Callback( ch & 0x80000000 );
-
- // Reset Layer
- giKB_KeyLayer = 0;
- return;
- }
-
- // Set the bit relating to the key
- gbaKB_States[giKB_KeyLayer][scancode] = 1;
- // Set shift key bits
- if(ch == KEY_LSHIFT) gbKB_ShiftState |= 1;
- if(ch == KEY_RSHIFT) gbKB_ShiftState |= 2;
-
- // Check for Caps Lock
- if(ch == KEY_CAPSLOCK) {
- gbKB_CapsState = !gbKB_CapsState;
- KB_UpdateLEDs();
- }
-
- // Reset Layer
- giKB_KeyLayer = 0;
-
- // Ignore Non-Printable Characters
- if(ch == 0) return;
-
- // --- Check for Kernel Magic Combos
- #if USE_KERNEL_MAGIC
- if(ch == KEY_LCTRL) {
- gbKB_MagicState |= 1;
- //Log_Log("Keyboard", "Kernel Magic LCTRL Down\n");
- }
- if(ch == KEY_LALT) {
- gbKB_MagicState |= 2;
- //Log_Log("Keyboard", "Kernel Magic LALT Down\n");
- }
- if(gbKB_MagicState == 3)
- {
- switch(ch)
- {
- case '0': case '1': case '2': case '3':
- case '4': case '5': case '6': case '7':
- case '8': case '9': case 'a': case 'b':
- case 'c': case 'd': case 'e': case 'f':
- {
- char str[4] = {'0', 'x', ch, 0};
- if(giKB_MagicAddressPos == BITS/4) return;
- giKB_MagicAddress |= atoi(str) << giKB_MagicAddressPos;
- giKB_MagicAddressPos ++;
- }
- return;
-
- // Instruction Tracing
- case 't':
- Log("Toggle instruction tracing on %i\n", giKB_MagicAddress);
- Threads_ToggleTrace( giKB_MagicAddress );
- giKB_MagicAddress = 0; giKB_MagicAddressPos = 0;
- return;
-
- // Thread List Dump
- case 'p': Threads_Dump(); return;
- // Heap Statistics
- case 'h': Heap_Stats(); return;
- // Dump Structure
- case 's': return;
- }
- }
- #endif
-
- // Capitals required?
- if( (gbKB_ShiftState != 0) != (gbKB_CapsState != 0))
- {
- // TODO: Move this to the keyboard map header
- switch(ch)
- {
- case 0: break;
- case '`': ch = '~'; break;
- case '1': ch = '!'; break;
- case '2': ch = '@'; break;
- case '3': ch = '#'; break;
- case '4': ch = '$'; break;
- case '5': ch = '%'; break;
- case '6': ch = '^'; break;
- case '7': ch = '&'; break;
- case '8': ch = '*'; break;
- case '9': ch = '('; break;
- case '0': ch = ')'; break;
- case '-': ch = '_'; break;
- case '=': ch = '+'; break;
- case '[': ch = '{'; break;
- case ']': ch = '}'; break;
- case '\\': ch = '|'; break;
- case ';': ch = ':'; break;
- case '\'': ch = '"'; break;
- case ',': ch = '<'; break;
- case '.': ch = '>'; break;
- case '/': ch = '?'; break;
- default:
- if('a' <= ch && ch <= 'z')
- ch -= 0x20;
- break;
- }
- }
-
- if(gKB_Callback && ch != 0) gKB_Callback(ch);
-}
-
-/**
- * \fn void KB_UpdateLEDs(void)
- * \brief Updates the status of the keyboard LEDs
- */
-void KB_UpdateLEDs(void)
-{
- Uint8 leds;
-
- leds = (gbKB_CapsState ? 4 : 0);
-
- while( inb(0x64) & 2 ); // Wait for bit 2 to unset
- outb(0x60, 0xED); // Send update command
-
- while( inb(0x64) & 2 ); // Wait for bit 2 to unset
- outb(0x60, leds);
-}
-
-/**
- * \fn int KB_IOCtl(tVFS_Node *Node, int Id, void *Data)
- * \brief Calls an IOCtl Command
- */
-int KB_IOCtl(tVFS_Node *Node, int Id, void *Data)
-{
- switch(Id)
- {
- case DRV_IOCTL_TYPE: return DRV_TYPE_KEYBOARD;
- case DRV_IOCTL_IDENT: memcpy(Data, "KB\0\0", 4); return 1;
- case DRV_IOCTL_VERSION: return 0x100;
- case DRV_IOCTL_LOOKUP: return 0;
-
- // Sets the Keyboard Callback
- case KB_IOCTL_SETCALLBACK:
- // Sanity Check
- if((Uint)Data < KERNEL_BASE) return 0;
- // Can only be set once
- if(gKB_Callback != NULL) return 0;
- // Set Callback
- gKB_Callback = Data;
- return 1;
-
- default:
- return 0;
- }
-}
+++ /dev/null
-\r
-#ifndef _KBDUS_H\r
-#define _KBDUS_H\r
-\r
-// - BASE (NO PREFIX)\r
-Uint32 gpKBDUS1[256] = {\r
-/*00*/ 0, KEY_ESC, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', '\b', '\t',\r
-/*10*/ 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', KEY_LCTRL, 'a', 's',\r
-/*20*/ 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';','\'', '`', KEY_LSHIFT,'\\', 'z', 'x', 'c', 'v',\r
-/*30*/ 'b', 'n', 'm', ',', '.', '/', KEY_RSHIFT, KEY_KPSTAR,\r
- KEY_LALT, ' ', KEY_CAPSLOCK, KEY_F1, KEY_F2, KEY_F3, KEY_F4, KEY_F5,\r
-/*40*/ KEY_F6, KEY_F7, KEY_F8, KEY_F9, KEY_F10, KEY_NUMLOCK, KEY_SCROLLLOCK, KEY_KPHOME,\r
- KEY_KPUP, KEY_KPPGUP, KEY_KPMINUS, KEY_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