From: John Hodge Date: Mon, 16 May 2011 11:52:16 +0000 (+0800) Subject: Hore work to allow ARM builds X-Git-Tag: rel0.10~110 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=9c61cf12758c0977ee1dc5791cba638fd3437ba6;p=tpg%2Facess2.git Hore work to allow ARM builds - Cleaning out some x86 specific code from the kernel tree - Added AS_SUFFIX to allow .asm and .s for diffent archs - Debugging and fixes for x86/x86_64 - Fixing some bugs exposed by ARM build messages --- diff --git a/Kernel/Makefile b/Kernel/Makefile index d7bc08f4..10391b85 100644 --- a/Kernel/Makefile +++ b/Kernel/Makefile @@ -18,7 +18,6 @@ CPPFLAGS += -I./include -I./arch/$(ARCHDIR)/include -D_MODULE_NAME_=\"Kernel\" CPPFLAGS += -DARCH=$(ARCH) -DARCHDIR=$(ARCHDIR) -DKERNEL_VERSION=$(KERNEL_VERSION) -DBUILD_NUM=$(BUILD_NUM) CFLAGS += -Wall -Werror -fno-stack-protector -fno-builtin -Wstrict-prototypes -g CFLAGS += -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -Wnested-externs -Winline -Wuninitialized -#ASFLAGS += -D ARCH=\"$(ARCH)\" -D ARCHDIR=\"$(ARCHDIR)\" LDFLAGS += -T arch/$(ARCHDIR)/link.ld -g ifeq ($(DEBUG_BUILD),yes) @@ -34,9 +33,11 @@ OBJ := $(addprefix arch/$(ARCHDIR)/,$(A_OBJ)) OBJ += heap.o drvutil.o logging.o debug.o lib.o adt.o time.o OBJ += messages.o modules.o syscalls.o system.o threads.o OBJ += $(addprefix vfs/fs/, $(addsuffix .o,$(FILESYSTEMS))) -OBJ += drv/kb.o drv/vterm.o drv/proc.o drv/fifo.o drv/iocache.o drv/dma.o drv/pci.o drv/vga.o +OBJ += drv/vterm.o drv/proc.o drv/fifo.o drv/iocache.o drv/pci.o drv/vga.o +#OBJ += drv/kb.o drv/dma.o OBJ += binary.o bin/elf.o bin/pe.o -OBJ += vfs/main.o vfs/open.o vfs/acls.o vfs/dir.o vfs/io.o vfs/mount.o vfs/memfile.o vfs/nodecache.o vfs/handle.o vfs/select.o +OBJ += vfs/main.o vfs/open.o vfs/acls.o vfs/dir.o vfs/io.o vfs/mount.o +OBJ += vfs/memfile.o vfs/nodecache.o vfs/handle.o vfs/select.o OBJ += vfs/fs/root.o vfs/fs/devfs.o OBJ += $(addprefix drv/, $(addsuffix .o,$(DRIVERS))) OBJ := $(addsuffix .$(ARCH), $(OBJ)) @@ -48,7 +49,7 @@ DEPFILES = $(filter %.o.$(ARCH),$(OBJ)) DEPFILES := $(DEPFILES:%.o.$(ARCH)=%.d.$(ARCH)) SRCFILES = $(OBJ:%.o.$(ARCH)=%.c) -SRCFILES := $(SRCFILES:%.ao.$(ARCH)=%.asm) +SRCFILES := $(SRCFILES:%.ao.$(ARCH)=%.$(AS_SUFFIX)) .PHONY: all clean install apidoc @@ -90,7 +91,7 @@ $(BIN): $(OBJ) $(MODS) arch/$(ARCHDIR)/link.ld Makefile # endif %.xo.$(ARCH): - @make -C $* all + @BUILDTYPE=static make -C $* all include/syscalls.h include/syscalls.inc.asm: syscalls.lst Makefile GenSyscalls.pl perl GenSyscalls.pl diff --git a/Kernel/Makefile.BuildNum.x86_64 b/Kernel/Makefile.BuildNum.x86_64 index 2d4893a3..f4eadab5 100644 --- a/Kernel/Makefile.BuildNum.x86_64 +++ b/Kernel/Makefile.BuildNum.x86_64 @@ -1 +1 @@ -BUILD_NUM = 237 +BUILD_NUM = 238 diff --git a/Kernel/arch/x86/Makefile b/Kernel/arch/x86/Makefile index 27a2ec02..aa5d8e2f 100644 --- a/Kernel/arch/x86/Makefile +++ b/Kernel/arch/x86/Makefile @@ -22,6 +22,7 @@ else ifeq ($(ARCH),i586) USE_PAE=1 endif +#ASFLAGS += -D ARCH=\"$(ARCH)\" -D ARCHDIR=\"$(ARCHDIR)\" ASFLAGS += -D USE_MP=$(USE_MP) -D USE_PAE=$(USE_PAE) CPPFLAGS += -DUSE_MP=$(USE_MP) -DUSE_PAE=$(USE_PAE) diff --git a/Kernel/arch/x86/proc.c b/Kernel/arch/x86/proc.c index ea8f8ad9..b677dfdb 100644 --- a/Kernel/arch/x86/proc.c +++ b/Kernel/arch/x86/proc.c @@ -998,6 +998,17 @@ void Proc_Scheduler(int CPU) // Get next thread to run thread = Threads_GetNextToRun(CPU, thread); + + #if DEBUG_TRACE_SWITCH + if(thread) { + Log("Switching to task %i, CR3 = 0x%x, EIP = %p", + thread->TID, + thread->MemState.CR3, + thread->SavedState.EIP + ); + } + #endif + // No avaliable tasks, just go into low power mode (idle thread) if(thread == NULL) { #if USE_MP @@ -1015,14 +1026,6 @@ void Proc_Scheduler(int CPU) gCurrentThread = thread; #endif - #if DEBUG_TRACE_SWITCH - Log("Switching to task %i, CR3 = 0x%x, EIP = %p", - thread->TID, - thread->MemState.CR3, - thread->SavedState.EIP - ); - #endif - #if USE_MP // MP Debug // Log("CPU = %i, Thread %p", CPU, thread); #endif diff --git a/Kernel/arch/x86/start.asm b/Kernel/arch/x86/start.asm index 4be41301..8c7d9a64 100644 --- a/Kernel/arch/x86/start.asm +++ b/Kernel/arch/x86/start.asm @@ -96,7 +96,7 @@ start: jmp .hlt ; -; Multiprocessing AP Startup Code (Must be within 0x10FFF0) +; Multiprocessing AP Startup Code (Must be within 0 - 0x10FFF0) ; %if USE_MP [extern gGDT] @@ -123,12 +123,15 @@ APWait: [global APStartup] APStartup: ;xchg bx, bx ; MAGIC BREAK! + ; Load initial GDT mov ax, 0xFFFF mov ds, ax lgdt [DWORD ds:lGDTPtr-KERNEL_BASE-0xFFFF0] + ; Enable PMode in CR0 mov eax, cr0 or al, 1 mov cr0, eax + ; Jump into PMode jmp 08h:DWORD .ProtectedMode-KERNEL_BASE [bits 32] .ProtectedMode: @@ -228,7 +231,7 @@ CallWithArgArray: [section .initpd] [global gaInitPageDir] [global gaInitPageTable] -align 0x1000 +align 4096 gaInitPageDir: dd gaInitPageTable-KERNEL_BASE+3 ; 0x000 - Low kernel times 0x300-0x000-1 dd 0 @@ -236,7 +239,7 @@ gaInitPageDir: times 0x3F0-0x300-1 dd 0 dd gaInitPageDir-KERNEL_BASE+3 ; 0xFC0 - Fractal times 0x400-0x3F0-1 dd 0 -align 0x1000 +align 4096 gaInitPageTable: %assign i 0 %rep 1024 @@ -244,7 +247,7 @@ gaInitPageTable: %assign i i+1 %endrep [global Kernel_Stack_Top] -ALIGN 0x1000 +ALIGN 4096 times 1024 dd 0 Kernel_Stack_Top: gInitAPStacks: diff --git a/Kernel/arch/x86_64/Makefile b/Kernel/arch/x86_64/Makefile index 906b726f..1b0246bb 100644 --- a/Kernel/arch/x86_64/Makefile +++ b/Kernel/arch/x86_64/Makefile @@ -5,6 +5,8 @@ MAX_CPUS := 4 +AS_SUFFIX = asm + CPPFLAGS := -DMAX_CPUS=$(MAX_CPUS) -D USE_MP=0 CFLAGS := $(KERNEL_CFLAGS) -mno-sse -mno-mmx ASFLAGS := -f elf64 -D MAX_CPUS=$(MAX_CPUS) -D USE_MP=0 diff --git a/Kernel/arch/x86_64/include/arch.h b/Kernel/arch/x86_64/include/arch.h index e43bd97c..c2c622e5 100644 --- a/Kernel/arch/x86_64/include/arch.h +++ b/Kernel/arch/x86_64/include/arch.h @@ -101,5 +101,8 @@ extern int CPU_HAS_LOCK(struct sShortSpinlock *Lock); extern void SHORTLOCK(struct sShortSpinlock *Lock); extern void SHORTREL(struct sShortSpinlock *Lock); +extern void Debug_PutCharDebug(char ch); +extern void Debug_PutStringDebug(const char *Str); + #endif diff --git a/Kernel/arch/x86_64/lib.c b/Kernel/arch/x86_64/lib.c index 7402bdaf..75d544b6 100644 --- a/Kernel/arch/x86_64/lib.c +++ b/Kernel/arch/x86_64/lib.c @@ -8,6 +8,7 @@ #define SERIAL_PORT 0x3F8 #define GDB_SERIAL_PORT 0x2F8 + // === IMPORTS === extern int GetCPUNum(void); extern void *Proc_GetCurThread(void); @@ -16,6 +17,9 @@ extern void *Proc_GetCurThread(void); int gbDebug_SerialSetup = 0; int gbGDB_SerialSetup = 0; +// === PROTOTYPEs === + int putDebugChar(char ch); + // === CODE === /** * \brief Determine if a short spinlock is locked @@ -141,6 +145,7 @@ void SHORTREL(struct sShortSpinlock *Lock) } // === DEBUG IO === +#if USE_GDB_STUB int putDebugChar(char ch) { if(!gbGDB_SerialSetup) { @@ -172,6 +177,7 @@ int getDebugChar(void) while( (inb(GDB_SERIAL_PORT + 5) & 1) == 0) ; return inb(GDB_SERIAL_PORT); } +#endif void Debug_PutCharDebug(char ch) { @@ -195,6 +201,12 @@ void Debug_PutCharDebug(char ch) #endif } +void Debug_PutStringDebug(const char *String) +{ + while(*String) + Debug_PutCharDebug(*String++); +} + // === PORT IO === void outb(Uint16 Port, Uint8 Data) { diff --git a/Kernel/arch/x86_64/mm_phys.c b/Kernel/arch/x86_64/mm_phys.c index 062b1387..670beb92 100644 --- a/Kernel/arch/x86_64/mm_phys.c +++ b/Kernel/arch/x86_64/mm_phys.c @@ -32,7 +32,7 @@ void MM_InitPhys_Multiboot(tMBoot_Info *MBoot); // === GLOBALS === tMutex glPhysicalPages; -Uint64 *gaSuperBitmap = (void*)MM_PAGE_SUPBMP; // 1 bit = 64 Pages, 16 MiB Per Word +Uint64 *gaSuperBitmap = (void*)MM_PAGE_SUPBMP; // 1 bit = 64 Pages, 16 MiB per Word Uint64 *gaMainBitmap = (void*)MM_PAGE_BITMAP; // 1 bit = 1 Page, 256 KiB per Word Uint64 *gaMultiBitmap = (void*)MM_PAGE_DBLBMP; // Each bit means that the page is being used multiple times Uint32 *gaiPageReferences = (void*)MM_PAGE_COUNTS; // Reference Counts diff --git a/Kernel/arch/x86_64/proc.c b/Kernel/arch/x86_64/proc.c index 105a59a5..99fa7e60 100644 --- a/Kernel/arch/x86_64/proc.c +++ b/Kernel/arch/x86_64/proc.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -62,6 +63,7 @@ void Proc_StartUser(Uint Entrypoint, Uint *Bases, int ArgC, char **ArgV, char ** void Proc_StartProcess(Uint16 SS, Uint Stack, Uint Flags, Uint16 CS, Uint IP); int Proc_Demote(Uint *Err, int Dest, tRegs *Regs); void Proc_CallFaultHandler(tThread *Thread); +void Proc_DumpThreadCPUState(tThread *Thread); void Proc_Scheduler(int CPU); // === GLOBALS === @@ -738,6 +740,10 @@ void Proc_CallFaultHandler(tThread *Thread) for(;;); } +void Proc_DumpThreadCPUState(tThread *Thread) +{ +} + /** * \fn void Proc_Scheduler(int CPU) * \brief Swap current thread and clears dead threads diff --git a/Kernel/debug.c b/Kernel/debug.c index 57964bde..6e7a0003 100644 --- a/Kernel/debug.c +++ b/Kernel/debug.c @@ -215,9 +215,10 @@ void Panic(const char *Fmt, ...) Threads_Dump(); - __asm__ __volatile__ ("xchg %bx, %bx"); - __asm__ __volatile__ ("cli;\n\thlt"); - for(;;) __asm__ __volatile__ ("hlt"); +// __asm__ __volatile__ ("xchg %bx, %bx"); +// __asm__ __volatile__ ("cli;\n\thlt"); +// for(;;) __asm__ __volatile__ ("hlt"); + for(;;) ; } void Debug_SetKTerminal(const char *File) diff --git a/Kernel/drv/dma.c b/Kernel/drv/dma.c deleted file mode 100644 index dd8e88f7..00000000 --- a/Kernel/drv/dma.c +++ /dev/null @@ -1,124 +0,0 @@ -/* - * AcessOS 1.0 - * DMA Driver - */ -#include -#include - -#define DMA_SIZE (0x2400) -#define DMA_ADDRESS(c) ((c)*DMA_SIZE+0x500) //Save Space for IDT and BDA - -#define LOWB(x) ((x)&0xFF) -#define HIB(x) (((x)>>8)&0xFF) -#define HIW(x) (((x)>>16)&0xFFFF) - -// === TYPES === -typedef struct -{ - int mode; - char *address; -} t_dmaChannel; - -// === PROTOTYPES === - int DMA_Install(char **Arguments); -void DMA_SetChannel(int Channel, int length, int read); - int DMA_ReadData(int channel, int count, void *buffer); - int DMA_WriteData(int channel, int count, const void *buffer); - -// === CONSTANTS === -const Uint8 cMASKPORT [8] = { 0x0A, 0x0A, 0x0A, 0x0A, 0xD4, 0xD4, 0xD4, 0xD4 }; -const Uint8 cMODEPORT [8] = { 0x0B, 0x0B, 0x0B, 0x0B, 0xD6, 0xD6, 0xD6, 0xD6 }; -const Uint8 cCLEARPORT[8] = { 0x0C, 0x0C, 0x0C, 0x0C, 0xD8, 0xD8, 0xD8, 0xD8 }; -const Uint8 cPAGEPORT [8] = { 0x87, 0x83, 0x81, 0x82, 0x8F, 0x8B, 0x89, 0x8A }; -const Uint8 cADDRPORT [8] = { 0x00, 0x02, 0x04, 0x06, 0xC0, 0xC4, 0xC8, 0xCC }; -const Uint8 cCOUNTPORT[8] = { 0x01, 0x03, 0x05, 0x07, 0xC2, 0xC6, 0xCA, 0xCE }; - -// === GLOBALS === -MODULE_DEFINE(0, 0x0100, ISADMA, DMA_Install, NULL, NULL); -char *dma_addresses[8]; -t_dmaChannel dma_channels[8]; - -// === CODE === -/** - * \brief Initialise DMA channels - * \param Arguments Arguments passed at boot time - */ -int DMA_Install(char **Arguments) -{ - Uint i; - for(i=8;i--;) - { - outb( cMASKPORT[i], 0x04 | (i & 0x3) ); // mask channel - outb( cCLEARPORT[i], 0x00 ); - outb( cMODEPORT[i], 0x48 | (i & 0x3) ); //Read Flag - outb( 0xd8, 0xff); //Reset Flip-Flop - outb( cADDRPORT[i], LOWB(DMA_ADDRESS(i)) ); // send address - outb( cADDRPORT[i], HIB(DMA_ADDRESS(i)) ); // send address - outb( 0xd8, 0xff); //Reset Flip-Flop - outb( cCOUNTPORT[i], LOWB(DMA_SIZE) ); // send size - outb( cCOUNTPORT[i], HIB(DMA_SIZE) ); // send size - outb( cPAGEPORT[i], LOWB(HIW(DMA_ADDRESS(i))) ); // send page - outb( cMASKPORT[i], i & 0x3 ); // unmask channel - - dma_channels[i].mode = 0; - dma_addresses[i] = (char*)DMA_ADDRESS(i); - dma_addresses[i] += KERNEL_BASE; - } - return MODULE_ERR_OK; -} - -/** - * \fn void DMA_SetChannel(int Channel, int length, int read) - * \brief Set DMA Channel Length and RW - */ -void DMA_SetChannel(int Channel, int length, int read) -{ - Uint chan = Channel & 7; - read = !!read; - if(length > DMA_SIZE) length = DMA_SIZE; - length --; //Adjust for DMA - //__asm__ __volatile__ ("cli"); - outb( cMASKPORT[chan], 0x04 | (chan & 0x3) ); // mask channel - outb( cCLEARPORT[chan], 0x00 ); - outb( cMODEPORT[chan], (0x44 + (!read)*4) | (chan & 0x3) ); - outb( cADDRPORT[chan], LOWB(DMA_ADDRESS(chan)) ); // send address - outb( cADDRPORT[chan], HIB(DMA_ADDRESS(chan)) ); // send address - outb( cPAGEPORT[chan], HIW(DMA_ADDRESS(chan)) ); // send page - outb( cCOUNTPORT[chan], LOWB(length) ); // send size - outb( cCOUNTPORT[chan], HIB(length) ); // send size - outb( cMASKPORT[chan], chan & 0x3 ); // unmask channel - dma_addresses[chan] = (char*)DMA_ADDRESS(chan); - dma_addresses[chan] += KERNEL_BASE; - //__asm__ __volatile__ ("sti"); -} - -/** - * \fn void DMA_ReadData(int channel, int count, void *buffer) - * \brief Read data from a DMA buffer - */ -int DMA_ReadData(int channel, int count, void *buffer) -{ - if(channel < 0 || channel > 7) - return -1; - if(count < 0 || count > DMA_SIZE) - return -2; - //LogF("memcpy(*0x%x, dma_channels[channel].address, count)\n", buffer - memcpy(buffer, dma_addresses[channel], count); - return 0; -} - -/** - * \fn void DMA_WriteData(int channel, int count, void *buffer) - * \brief Write data to a DMA buffer - */ -int DMA_WriteData(int channel, int count, const void *buffer) -{ - if(channel < 0 || channel > 7) - return -1; - if(count < 0 || count > DMA_SIZE) - return -2; - - memcpy(dma_addresses[channel], buffer, count); - - return 0; -} diff --git a/Kernel/drv/kb.c b/Kernel/drv/kb.c deleted file mode 100644 index b67c8e31..00000000 --- a/Kernel/drv/kb.c +++ /dev/null @@ -1,300 +0,0 @@ -/* - * Acess2 - * PS2 Keyboard Driver - */ -#include -#include -#include -#include -#include -#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; - } -} diff --git a/Kernel/drv/kb_kbdus.h b/Kernel/drv/kb_kbdus.h deleted file mode 100644 index 441b19a5..00000000 --- a/Kernel/drv/kb_kbdus.h +++ /dev/null @@ -1,73 +0,0 @@ - -#ifndef _KBDUS_H -#define _KBDUS_H - -// - BASE (NO PREFIX) -Uint32 gpKBDUS1[256] = { -/*00*/ 0, KEY_ESC, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', '\b', '\t', -/*10*/ 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', KEY_LCTRL, 'a', 's', -/*20*/ 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';','\'', '`', KEY_LSHIFT,'\\', 'z', 'x', 'c', 'v', -/*30*/ 'b', 'n', 'm', ',', '.', '/', KEY_RSHIFT, KEY_KPSTAR, - KEY_LALT, ' ', KEY_CAPSLOCK, KEY_F1, KEY_F2, KEY_F3, KEY_F4, KEY_F5, -/*40*/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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/*30*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/*40*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/*50*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/*60*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/*70*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/*80*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/*90*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/*A0*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/*B0*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/*C0*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/*D0*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/*E0*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/*F0*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 -}; - - -Uint32 *gpKBDUS[3] = { gpKBDUS1, gpKBDUS2, gpKBDUS3 }; - -#endif diff --git a/Kernel/drv/vterm.c b/Kernel/drv/vterm.c index ec5c1f54..9e1055ef 100644 --- a/Kernel/drv/vterm.c +++ b/Kernel/drv/vterm.c @@ -423,6 +423,8 @@ Uint64 VT_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) int pos = 0; int avail; tVTerm *term = &gVT_Terminals[ Node->Inode ]; + Uint32 *codepoint_buf = Buffer; + Uint32 *codepoint_in; Mutex_Acquire( &term->ReadingLock ); @@ -459,10 +461,12 @@ Uint64 VT_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) if(avail > Length - pos) avail = Length/4 - pos; + codepoint_in = (void*)term->InputBuffer; + codepoint_buf = Buffer; while( avail -- ) { - ((Uint32*)Buffer)[pos] = ((Uint32*)term->InputBuffer)[term->InputRead]; + codepoint_buf[pos] = codepoint_in[term->InputRead]; pos ++; term->InputRead ++; term->InputRead %= MAX_INPUT_CHARS32; @@ -858,7 +862,8 @@ void VT_KBCallBack(Uint32 Codepoint) else { // Encode the raw UTF-32 Key - ((Uint32*)term->InputBuffer)[ term->InputWrite ] = Codepoint; + Uint32 *raw_in = (void*)term->InputBuffer; + raw_in[ term->InputWrite ] = Codepoint; term->InputWrite ++; term->InputWrite %= MAX_INPUT_CHARS32; if(term->InputRead == term->InputWrite) { diff --git a/Kernel/include/threads_int.h b/Kernel/include/threads_int.h index ed2af53d..f5c7b1b8 100644 --- a/Kernel/include/threads_int.h +++ b/Kernel/include/threads_int.h @@ -6,6 +6,7 @@ #define _THREADS_INT_H_ #include +#include /** * \brief IPC Message diff --git a/Kernel/messages.c b/Kernel/messages.c index 03e225b8..45b5dfa8 100644 --- a/Kernel/messages.c +++ b/Kernel/messages.c @@ -4,6 +4,7 @@ */ #include #include +#include #include // === IMPORTS === diff --git a/Kernel/modules.c b/Kernel/modules.c index b2923f7c..1dc11499 100644 --- a/Kernel/modules.c +++ b/Kernel/modules.c @@ -28,8 +28,8 @@ EXPORT(Module_RegisterLoader); extern int UDI_LoadDriver(void *Base); #endif extern void StartupPrint(const char *Str); -extern void gKernelModules; -extern void gKernelModulesEnd; +extern tModule gKernelModules; +extern tModule gKernelModulesEnd; // === GLOBALS === int giNumBuiltinModules = 0; diff --git a/Kernel/threads.c b/Kernel/threads.c index 7a8cbde7..ecddf945 100644 --- a/Kernel/threads.c +++ b/Kernel/threads.c @@ -5,6 +5,7 @@ */ #include #include +#include #include #include