From df1d534cfe822903fc38e1cc13c4b18941c91908 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sat, 28 May 2011 09:55:22 +0800 Subject: [PATCH] Kernel - More work on ARM port - Moved PCI into two files, one core (with the scanning etc) and one per architecture for the IO commands. - Addded time/pci to the ARM7 tree - Moved drv/vga.c to a module - Misc fiddling with ARM port - Removed Big/LittleEndian16/32 functions, now in acess.h as macros - Misc changes elsewhere --- Kernel/Makefile | 7 +- Kernel/arch/arm7/Makefile | 6 +- Kernel/arch/arm7/include/arch.h | 3 +- Kernel/arch/arm7/include/mm_virt.h | 8 + Kernel/arch/arm7/lib.c | 220 ++++++++++++++++++++++ Kernel/arch/arm7/link.ld | 9 + Kernel/arch/arm7/pci.c | 34 ++++ Kernel/arch/arm7/start.s | 6 +- Kernel/arch/arm7/time.c | 16 ++ Kernel/arch/x86/Makefile | 2 +- Kernel/arch/x86/lib.c | 19 -- Kernel/arch/x86/pci.c | 61 ++++++ Kernel/arch/x86/proc.c | 3 +- Kernel/arch/x86_64/Makefile | 2 +- Kernel/arch/x86_64/pci.c | 1 + Kernel/binary.c | 8 +- Kernel/drv/pci.c | 79 ++------ Kernel/include/acess.h | 17 +- Kernel/lib.c | 11 ++ Kernel/time.c | 1 - Modules/x86/VGAText/Makefile | 7 + {Kernel/drv => Modules/x86/VGAText}/vga.c | 2 +- 22 files changed, 422 insertions(+), 100 deletions(-) create mode 100644 Kernel/arch/arm7/link.ld create mode 100644 Kernel/arch/arm7/pci.c create mode 100644 Kernel/arch/arm7/time.c create mode 100644 Kernel/arch/x86/pci.c create mode 120000 Kernel/arch/x86_64/pci.c create mode 100644 Modules/x86/VGAText/Makefile rename {Kernel/drv => Modules/x86/VGAText}/vga.c (98%) diff --git a/Kernel/Makefile b/Kernel/Makefile index 10391b85..65527f62 100644 --- a/Kernel/Makefile +++ b/Kernel/Makefile @@ -15,7 +15,8 @@ KERNEL_VERSION = 0.5 MAKEDEP = $(CC) -M CPPFLAGS += -I./include -I./arch/$(ARCHDIR)/include -D_MODULE_NAME_=\"Kernel\" -CPPFLAGS += -DARCH=$(ARCH) -DARCHDIR=$(ARCHDIR) -DKERNEL_VERSION=$(KERNEL_VERSION) -DBUILD_NUM=$(BUILD_NUM) +CPPFLAGS += -DARCH=$(ARCH) -DARCHDIR=$(ARCHDIR) -DARCHDIR_IS_$(ARCHDIR)=1 +CPPFLAGS += -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 LDFLAGS += -T arch/$(ARCHDIR)/link.ld -g @@ -33,8 +34,8 @@ 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/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 += drv/vterm.o drv/proc.o drv/fifo.o drv/iocache.o drv/pci.o +#OBJ += drv/kb.o drv/dma.o drv/vga.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 OBJ += vfs/memfile.o vfs/nodecache.o vfs/handle.o vfs/select.o diff --git a/Kernel/arch/arm7/Makefile b/Kernel/arch/arm7/Makefile index edee2795..e7102f00 100644 --- a/Kernel/arch/arm7/Makefile +++ b/Kernel/arch/arm7/Makefile @@ -7,6 +7,7 @@ CPPFLAGS = CFLAGS = ASFLAGS = +PCI_ADDRESS=0 ifeq ($(ARCH),integrator-cp) MMU_PRESENT=1 else @@ -16,6 +17,7 @@ endif #ASFLAGS += -D USE_MP=$(USE_MP) -D USE_PAE=$(USE_PAE) -CPPFLAGS += -DMMU_PRESENT=$(MMU_PRESENT) +CPPFLAGS += -DMMU_PRESENT=$(MMU_PRESENT) -DPCI_ADDRESS=$(PCI_ADDRESS) +LDFLAGS += `$(CC) --print-libgcc-file-name` -A_OBJ = start.ao main.o +A_OBJ = start.ao main.o lib.o time.o pci.o diff --git a/Kernel/arch/arm7/include/arch.h b/Kernel/arch/arm7/include/arch.h index 528880b4..6fa39d3f 100644 --- a/Kernel/arch/arm7/include/arch.h +++ b/Kernel/arch/arm7/include/arch.h @@ -27,7 +27,8 @@ typedef char BOOL; typedef Uint32 tVAddr; typedef Uint32 tPAddr; -#include +#include "lock.h" +#include "div.h" // --- Debug extern void Debug_PutCharDebug(char Ch); diff --git a/Kernel/arch/arm7/include/mm_virt.h b/Kernel/arch/arm7/include/mm_virt.h index ed6f3aff..abbbe6c7 100644 --- a/Kernel/arch/arm7/include/mm_virt.h +++ b/Kernel/arch/arm7/include/mm_virt.h @@ -7,6 +7,10 @@ #define KERNEL_BASE 0x80000000 // 2GiB +#define MM_USER_MIN 0x00001000 +#define USER_LIB_MAX 0x7F800000 +#define MM_PPD_VFS 0x7F800000 + // Page Blocks are 12-bits wide (12 address bits used) // Hence, the table is 16KiB large (and must be so aligned) // and each block addresses 1MiB of data @@ -14,6 +18,10 @@ #define MM_KHEAP_BASE 0x80800000 // 8MiB of kernel code #define MM_KHEAP_MAX 0xC0000000 // 1GiB of kernel heap +#define MM_MODULE_MIN 0xC0000000 +#define MM_MODULE_MAX 0xD0000000 + +#define MM_KERNEL_VFS 0xFF800000 // #define MM_FRACTAL 0xFFE00000 // 2nd last block #endif diff --git a/Kernel/arch/arm7/lib.c b/Kernel/arch/arm7/lib.c index 1679577b..bfcfeb63 100644 --- a/Kernel/arch/arm7/lib.c +++ b/Kernel/arch/arm7/lib.c @@ -5,4 +5,224 @@ */ #include +// === PROTOTYPES === +Uint64 __udivdi3(Uint64 Num, Uint64 Den); +Uint64 __umoddi3(Uint64 Num, Uint64 Den); +Uint32 __udivsi3(Uint32 Num, Uint32 Den); +Uint32 __umodsi3(Uint32 Num, Uint32 Den); +Sint32 __divsi3(Sint32 Num, Sint32 Den); +Sint32 __modsi3(Sint32 Num, Sint32 Den); + // === CODE === +void *memcpy(void *_dest, const void *_src, size_t _length) +{ + Uint32 *dst; + const Uint32 *src; + Uint8 *dst8 = _dest; + const Uint8 *src8 = _src; + + // Handle small copies / Non-aligned + if( _length < 4 || ((tVAddr)_dest & 3) != ((tVAddr)_src & 3) ) + { + for( ; _length--; dst8++,src8++ ) + *dst8 = *src8; + return _dest; + } + + // Force alignment + while( (tVAddr)dst8 & 3 ) *dst8 ++ = *src8++; + dst = (void *)dst8; src = (void *)src8; + + // DWORD copies + for( ; _length > 3; _length -= 4) + *dst++ = *src++; + + // Trailing bytes + dst8 = (void*)dst; src8 = (void*)src; + for( ; _length; _length -- ) + *dst8 ++ = *src8 ++; + + return _dest; +} + +int memcmp(const void *_m1, const void *_m2, size_t _length) +{ + const Uint32 *m1, *m2; + const Uint8 *m1_8 = _m1, *m2_8 = _m2; + + // Handle small copies / Non-aligned + if( _length < 4 || ((tVAddr)_m1 & 3) != ((tVAddr)_m1 & 3) ) + { + for( ; _length--; m1_8++,m2_8++ ) { + if(*m1_8 != *m2_8) return *m1_8 - *m2_8; + } + return 0; + } + + // Force alignment + for( ; (tVAddr)m1_8 & 3; m1_8 ++, m2_8 ++) { + if(*m1_8 != *m2_8) return *m1_8 - *m2_8; + } + m1 = (void *)m1_8; m2 = (void *)m2_8; + + // DWORD copies + for( ; _length > 3; _length -= 4, m1++, m2++) + if(*m1 != *m2) return *m1 - *m2; + + // Trailing bytes + m1_8 = (void*)m1; m2_8 = (void*)m2; + for( ; _length; _length --, m1_8++, m2_8++ ) + if(*m1_8 != *m2_8) return *m1_8 - *m2_8; + + return 0; +} + +void *memset(void *_dest, int _value, size_t _length) +{ + Uint32 *dst, val32; + Uint8 *dst8 = _dest; + + _value = (Uint8)_value; + + // Handle small copies / Non-aligned + if( _length < 4 ) + { + for( ; _length--; dst8++ ) + *dst8 = _value; + return _dest; + } + + val32 = _value; + val32 |= val32 << 8; + val32 |= val32 << 16; + + // Force alignment + while( (tVAddr)dst8 & 3 ) *dst8 ++ = _value; + dst = (void *)dst8; + + // DWORD copies + for( ; _length > 3; _length -= 4) + *dst++ = val32; + + // Trailing bytes + dst8 = (void*)dst; + for( ; _length; _length -- ) + *dst8 ++ = _value; + + return _dest; +} + +// Unsigned Divide 64-bit Integer +Uint64 __udivdi3(Uint64 Num, Uint64 Den) +{ + if( Num == 0 ) return 0; + if( Den == 0 ) return 5 / (Uint32)Den; // Force a #DIV0 + if( Den == 1 ) return Num; + if( Den == 2 ) return Num >> 1; + if( Den == 16 ) return Num >> 4; + if( Den == 256 ) return Num >> 8; + if( Den == 512 ) return Num >> 9; + if( Den == 1024 ) return Num >> 10; + if( Den == 2048 ) return Num >> 11; + if( Den == 4096 ) return Num >> 12; + if( Num < Den ) return 0; + if( Num <= 0xFFFFFFFF && Den <= 0xFFFFFFFF ) + return (Uint32)Num / (Uint32)Den; + + #if 0 + if( Den <= 0xFFFFFFFF ) { + (Uint32)(Num >> 32) / (Uint32)Den + } + #endif + Uint64 ret = 0; + for( ret = 0; Num > Den; ret ++, Num -= Den ); + return ret; +} + +// Unsigned Modulus 64-bit Integer +Uint64 __umoddi3(Uint64 Num, Uint64 Den) +{ + if( Num == 0 ) return 0; + if( Den == 0 ) return 5 / (Uint32)Den; // Force a #DIV0 + if( Den == 1 ) return 0; + if( Den == 2 ) return Num & 1; + if( Den == 16 ) return Num & 3; + if( Den == 256 ) return Num & 0xFF; + if( Den == 512 ) return Num & 0x1FF; + if( Den == 1024 ) return Num & 0x3FF; + if( Den == 2048 ) return Num & 0x7FF; + if( Den == 4096 ) return Num & 0xFFF; + if( Num < Den ) return 0; + if( Num <= 0xFFFFFFFF && Den <= 0xFFFFFFFF ) + return (Uint32)Num % (Uint32)Den; + + #if 0 + if( Den <= 0xFFFFFFFF ) { + (Uint32)(Num >> 32) / (Uint32)Den + } + #endif + for( ; Num > Den; Num -= Den ); + return Num; +} + +#define _divide_s_32(Num, Den, rem) __asm__ __volatile__ ( \ + "mov %0, #0\n" \ + " adds %1, %1, %1\n" \ + " .rept 32\n" \ + " adcs %0, %2, %0, lsl #1\n" \ + " subcc %0, %0, %3\n" \ + " adcs %1, %1, %1\n" \ + " .endr\n" \ + : "=r" (rem), "=r" (Num) \ + : "r" (Den) \ + : "cc" \ + ) +Uint32 __udivsi3(Uint32 Num, Uint32 Den) +{ + register Uint32 ret; + Uint64 P, D; + int i; + + if( Num == 0 ) return 0; + if( Den == 0 ) return 0xFFFFFFFF; // TODO: Throw an error + if( Den == 1 ) return Num; + + D = ((Uint64)Den) << 32; + + for( i = 32; i --; ) + { + P = 2*P - D; + if( P >= 0 ) + ret |= 1; + else + P += D; + ret <<= 1; + } + +// _divide_s_32(Num, Den, rem); + return Num; +} + +Uint32 __umodsi3(Uint32 Num, Uint32 Den) +{ + return Num - __udivsi3(Num, Den)*Den; +} + +Sint32 __divsi3(Sint32 Num, Sint32 Den) +{ + if( (Num < 0) && (Den < 0) ) + return __udivsi3(-Num, -Den); + else if( Num < 0 ) + return __udivsi3(-Num, Den); + else if( Den < 0 ) + return __udivsi3(Den, -Den); + else + return __udivsi3(Den, Den); +} + +Sint32 __modsi3(Sint32 Num, Sint32 Den) +{ + //register Sint32 rem; + //_divide_s_32(Num, Den, rem); + return Num - __divsi3(Num, Den) * Den; +} diff --git a/Kernel/arch/arm7/link.ld b/Kernel/arch/arm7/link.ld new file mode 100644 index 00000000..53e1a605 --- /dev/null +++ b/Kernel/arch/arm7/link.ld @@ -0,0 +1,9 @@ +ENTRY (_start) + +SECTIONS +{ + . = 0x80000000; + .text : { *(.text*) *(.rodata*) } + .data : { *(.data*) } + .bss : { *(.bss*) *(COMMON*) } +} diff --git a/Kernel/arch/arm7/pci.c b/Kernel/arch/arm7/pci.c new file mode 100644 index 00000000..91cfe99b --- /dev/null +++ b/Kernel/arch/arm7/pci.c @@ -0,0 +1,34 @@ +/* + * + */ +#include + +// === PROTOTYPES === +#if 1 +void PCI_CfgWriteDWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset, Uint32 data); +Uint32 PCI_CfgReadDWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset); +Uint16 PCI_CfgReadWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset); +Uint8 PCI_CfgReadByte(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset); +#endif + +// === CODE === +void PCI_CfgWriteDWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset, Uint32 data) +{ + // TODO: Use PCI_ADDRESS constant +} + +Uint32 PCI_CfgReadDWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset) +{ + // TODO: Locate PCI base and read/write data + return 0; +} + +Uint16 PCI_CfgReadWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset) +{ + return PCI_CfgReadDWord(bus, dev, func, offset & ~3) >> (8*(offset&2)); +} + +Uint8 PCI_CfgReadByte(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset) +{ + return PCI_CfgReadDWord(bus, dev, func, offset & ~3) >> (8*(offset&3)); +} diff --git a/Kernel/arch/arm7/start.s b/Kernel/arch/arm7/start.s index 1597ba19..43468fc5 100644 --- a/Kernel/arch/arm7/start.s +++ b/Kernel/arch/arm7/start.s @@ -1,7 +1,7 @@ interrupt_vector_table: b . @ Reset b . - b . @ SWI instruction + b SyscallHandler @ SWI instruction b . b . b . @@ -16,3 +16,7 @@ _start: bl main 1: b 1b @ Infinite loop + +SyscallHandler: + + diff --git a/Kernel/arch/arm7/time.c b/Kernel/arch/arm7/time.c new file mode 100644 index 00000000..d4ae4fa6 --- /dev/null +++ b/Kernel/arch/arm7/time.c @@ -0,0 +1,16 @@ +/* + * Acess2 + * + * ARM7 Time code + * arch/arm7/time.c + */ +#include + +// === GLOBALS === +tTime giTimestamp; + +// === CODE === +tTime now(void) +{ + return giTimestamp; +} diff --git a/Kernel/arch/x86/Makefile b/Kernel/arch/x86/Makefile index aa5d8e2f..6d9d14b9 100644 --- a/Kernel/arch/x86/Makefile +++ b/Kernel/arch/x86/Makefile @@ -29,4 +29,4 @@ CPPFLAGS += -DUSE_MP=$(USE_MP) -DUSE_PAE=$(USE_PAE) A_OBJ = start.ao main.o lib.o desctab.ao errors.o irq.o A_OBJ += mm_phys.o mm_virt.o A_OBJ += proc.o proc.ao time.o vm8086.o -A_OBJ += kpanic.o +A_OBJ += kpanic.o pci.o diff --git a/Kernel/arch/x86/lib.c b/Kernel/arch/x86/lib.c index 969332b0..dbdb98d3 100644 --- a/Kernel/arch/x86/lib.c +++ b/Kernel/arch/x86/lib.c @@ -424,22 +424,6 @@ Uint64 __umoddi3(Uint64 Num, Uint64 Den) return Num - __udivdi3(Num, Den) * Den; } -Uint16 LittleEndian16(Uint16 Val) -{ - return Val; -} -Uint16 BigEndian16(Uint16 Val) -{ - return ((Val&0xFF)<<8) | ((Val>>8)&0xFF); -} -Uint32 LittleEndian32(Uint32 Val) -{ - return Val; -} -Uint32 BigEndian32(Uint32 Val) -{ - return ((Val&0xFF)<<24) | ((Val&0xFF00)<<8) | ((Val>>8)&0xFF00) | ((Val>>24)&0xFF); -} // --- EXPORTS --- EXPORT(memcpy); EXPORT(memset); @@ -450,9 +434,6 @@ EXPORT(inb); EXPORT(inw); EXPORT(ind); EXPORT(outb); EXPORT(outw); EXPORT(outd); EXPORT(__udivdi3); EXPORT(__umoddi3); -EXPORT(LittleEndian16); EXPORT(BigEndian16); -EXPORT(LittleEndian32); EXPORT(BigEndian32); - EXPORT(SHORTLOCK); EXPORT(SHORTREL); EXPORT(IS_LOCKED); diff --git a/Kernel/arch/x86/pci.c b/Kernel/arch/x86/pci.c new file mode 100644 index 00000000..b5410a39 --- /dev/null +++ b/Kernel/arch/x86/pci.c @@ -0,0 +1,61 @@ +/* + * Acess2 + * arch/x86/pci.h - x86 PCI Bus Access + */ +#define DEBUG 0 +#include + +// === PROTOTYPES === +Uint32 PCI_CfgReadDWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset); +void PCI_CfgWriteDWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset, Uint32 data); +Uint16 PCI_CfgReadWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset); +Uint8 PCI_CfgReadByte(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset); + +// === CODE === +Uint32 PCI_CfgReadDWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset) +{ + Uint32 address; + Uint32 data; + + bus &= 0xFF; // 8 Bits + dev &= 0x1F; // 5 Bits + func &= 0x7; // 3 Bits + offset &= 0xFF; // 8 Bits + + address = 0x80000000 | ((Uint)bus<<16) | ((Uint)dev<<11) | ((Uint)func<<8) | (offset&0xFC); + outd(0xCF8, address); + + data = ind(0xCFC); + //Debug("PCI(0x%x) = 0x%08x", address, data); + return data; +} +void PCI_CfgWriteDWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset, Uint32 data) +{ + Uint32 address; + + bus &= 0xFF; // 8 Bits + dev &= 0x1F; // 5 Bits + func &= 0x7; // 3 Bits + offset &= 0xFF; // 8 Bits + + address = 0x80000000 | ((Uint)bus<<16) | ((Uint)dev<<11) | ((Uint)func<<8) | (offset&0xFC); + outd(0xCF8, address); + outd(0xCFC, data); +} +Uint16 PCI_CfgReadWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset) +{ + Uint32 data = PCI_CfgReadDWord(bus, dev, func, offset); + + data >>= (offset&2)*8; // Allow Access to Upper Word + + return (Uint16)data; +} + +Uint8 PCI_CfgReadByte(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset) +{ + Uint32 data = PCI_CfgReadDWord(bus, dev, func, offset); + + data >>= (offset&3)*8; //Allow Access to Upper Word + return (Uint8)data; +} + diff --git a/Kernel/arch/x86/proc.c b/Kernel/arch/x86/proc.c index b677dfdb..6e944009 100644 --- a/Kernel/arch/x86/proc.c +++ b/Kernel/arch/x86/proc.c @@ -1001,8 +1001,9 @@ void Proc_Scheduler(int CPU) #if DEBUG_TRACE_SWITCH if(thread) { - Log("Switching to task %i, CR3 = 0x%x, EIP = %p", + Log("Switching to task %i(%s), CR3 = 0x%x, EIP = %p", thread->TID, + thread->ThreadName, thread->MemState.CR3, thread->SavedState.EIP ); diff --git a/Kernel/arch/x86_64/Makefile b/Kernel/arch/x86_64/Makefile index 1b0246bb..2c577b07 100644 --- a/Kernel/arch/x86_64/Makefile +++ b/Kernel/arch/x86_64/Makefile @@ -25,7 +25,7 @@ endif A_OBJ := start32.ao start64.ao desctab.ao A_OBJ += main.o lib.o proc.o mm_virt.o mm_phys.o -A_OBJ += kernelpanic.o errors.o time.o +A_OBJ += kernelpanic.o errors.o time.o pci.o A_OBJ += vm8086.o # rme.o diff --git a/Kernel/arch/x86_64/pci.c b/Kernel/arch/x86_64/pci.c new file mode 120000 index 00000000..cac29a8f --- /dev/null +++ b/Kernel/arch/x86_64/pci.c @@ -0,0 +1 @@ +../x86/pci.c \ No newline at end of file diff --git a/Kernel/binary.c b/Kernel/binary.c index 5a919e17..0f5183c0 100644 --- a/Kernel/binary.c +++ b/Kernel/binary.c @@ -28,7 +28,7 @@ extern char *Threads_GetName(int ID); extern Uint MM_ClearUser(void); extern void Proc_StartUser(Uint Entrypoint, Uint *Bases, int ArgC, char **ArgV, char **EnvP, int DataSize); extern tKernelSymbol gKernelSymbols[]; -extern void gKernelSymbolsEnd; +extern tKernelSymbol gKernelSymbolsEnd[]; extern tBinaryType gELF_Info; // === PROTOTYPES === @@ -101,7 +101,7 @@ int Proc_Execve(const char *File, const char **ArgV, const char **EnvP) { int argc, envc, i; int argenvBytes; - char *argenvBuf, *strBuf; + char **argenvBuf, *strBuf; char **argvSaved, **envpSaved; char *savedFile; Uint entry; @@ -127,10 +127,10 @@ int Proc_Execve(const char *File, const char **ArgV, const char **EnvP) LEAVE('i', 0); return 0; } - strBuf = argenvBuf + (argc+1)*sizeof(void*) + (envc+1)*sizeof(void*); + strBuf = (char*)argenvBuf + (argc+1)*sizeof(void*) + (envc+1)*sizeof(void*); // Populate - argvSaved = (char **) argenvBuf; + argvSaved = argenvBuf; for( i = 0; i < argc; i++ ) { argvSaved[i] = strBuf; diff --git a/Kernel/drv/pci.c b/Kernel/drv/pci.c index 73e3a40c..df5c1144 100644 --- a/Kernel/drv/pci.c +++ b/Kernel/drv/pci.c @@ -11,6 +11,12 @@ #define LIST_DEVICES 1 +// === IMPORTS === +extern Uint32 PCI_CfgReadDWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset); +extern void PCI_CfgWriteDWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset, Uint32 data); +extern Uint16 PCI_CfgReadWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset); +extern Uint8 PCI_CfgReadByte(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset); + // === STRUCTURES === typedef struct sPCIDevice { @@ -55,10 +61,6 @@ Uint16 PCI_AssignPort(int id, int bar, int count); #endif int PCI_EnumDevice(Uint16 bus, Uint16 dev, Uint16 fcn, tPCIDevice *info); -Uint32 PCI_CfgReadDWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset); -void PCI_CfgWriteDWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset, Uint32 data); -Uint16 PCI_CfgReadWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset); -Uint8 PCI_CfgReadByte(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset); // === GLOBALS === MODULE_DEFINE(0, 0x0100, PCI, PCI_Install, NULL, NULL); @@ -184,13 +186,9 @@ int PCI_ScanBus(int BusID, int bFill) } giPCI_DeviceCount ++; - // WTF is this for? - // Maybe bit 23 must be set for the device to be valid? - // - Actually, maybe 23 means that there are sub-functions - if(fcn == 0) { - if( !(devInfo.ConfigCache[3] & 0x00800000) ) - break; - } + // If bit 23 of (soemthing) is set, there are sub-functions + if(fcn == 0 && !(devInfo.ConfigCache[3] & 0x00800000) ) + break; } } @@ -429,8 +427,14 @@ Uint16 PCI_AssignPort(int id, int bar, int count) portVals &= ~1; // Get Granuality + #if ARCHDIR_IS_x86 || ARCHDIR_IS_x86_64 __asm__ __volatile__ ("bsf %%eax, %%ecx" : "=c" (gran) : "a" (portVals) ); gran = 1 << gran; + #else + { + for(gran = 1; gran && !(portVals & gran); gran <<= 1); + } + #endif //LogF(" PCI_AssignPort: gran = 0x%x\n", gran); // Find free space @@ -465,9 +469,10 @@ Uint16 PCI_AssignPort(int id, int bar, int count) } /** - * \fn int PCI_EnumDevice(Uint16 bus, Uint16 slot, Uint16 fcn, tPCIDevice *info) + * \fn int PCI_EnumDevice(Uint16 bus, Uint16 slot, Uint16 fcn, tPCIDevice *info) + * \brief Get device information for a slot/function */ -int PCI_EnumDevice(Uint16 bus, Uint16 slot, Uint16 fcn, tPCIDevice *info) +int PCI_EnumDevice(Uint16 bus, Uint16 slot, Uint16 fcn, tPCIDevice *info) { Uint16 vendor; int i; @@ -518,54 +523,6 @@ int PCI_EnumDevice(Uint16 bus, Uint16 slot, Uint16 fcn, tPCIDevice *info) return 1; } -Uint32 PCI_CfgReadDWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset) -{ - Uint32 address; - Uint32 data; - - bus &= 0xFF; // 8 Bits - dev &= 0x1F; // 5 Bits - func &= 0x7; // 3 Bits - offset &= 0xFF; // 8 Bits - - address = 0x80000000 | ((Uint)bus<<16) | ((Uint)dev<<11) | ((Uint)func<<8) | (offset&0xFC); - outd(0xCF8, address); - - data = ind(0xCFC); - //Debug("PCI(0x%x) = 0x%08x", address, data); - return data; -} -void PCI_CfgWriteDWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset, Uint32 data) -{ - Uint32 address; - - bus &= 0xFF; // 8 Bits - dev &= 0x1F; // 5 Bits - func &= 0x7; // 3 Bits - offset &= 0xFF; // 8 Bits - - address = 0x80000000 | ((Uint)bus<<16) | ((Uint)dev<<11) | ((Uint)func<<8) | (offset&0xFC); - outd(0xCF8, address); - outd(0xCFC, data); -} -Uint16 PCI_CfgReadWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset) -{ - Uint32 data = PCI_CfgReadDWord(bus, dev, func, offset); - - data >>= (offset&2)*8; // Allow Access to Upper Word - - return (Uint16)data; -} - -Uint8 PCI_CfgReadByte(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset) -{ - Uint32 data = PCI_CfgReadDWord(bus, dev, func, offset); - - data >>= (offset&3)*8; //Allow Access to Upper Word - return (Uint8)data; -} - - // === EXPORTS === //* EXPORT(PCI_CountDevices); diff --git a/Kernel/include/acess.h b/Kernel/include/acess.h index 79c5062b..f046a11f 100644 --- a/Kernel/include/acess.h +++ b/Kernel/include/acess.h @@ -307,10 +307,19 @@ extern int CheckMem(const void *Mem, int Num); * \name Endianness Swapping * \{ */ -extern Uint16 LittleEndian16(Uint16 Val); -extern Uint16 BigEndian16(Uint16 Val); -extern Uint32 LittleEndian32(Uint32 Val); -extern Uint32 BigEndian32(Uint32 Val); +#if __ENDIAN == BIG_ENDIAN +#define LittleEndian16(_val) SwapEndian16(_val) +#define LittleEndian32(_val) SwapEndian32(_val) +#define BigEndian16(_val) (_val) +#define BigEndian32(_val) (_val) +#else +#define LittleEndian16(_val) (_val) +#define LittleEndian32(_val) (_val) +#define BigEndian16(_val) SwapEndian16(_val) +#define BigEndian32(_val) SwapEndian32(_val) +#endif +extern Uint16 SwapEndian16(Uint16 Val); +extern Uint32 SwapEndian32(Uint32 Val); /** * \} */ diff --git a/Kernel/lib.c b/Kernel/lib.c index 27995b07..51dbe058 100644 --- a/Kernel/lib.c +++ b/Kernel/lib.c @@ -77,6 +77,8 @@ EXPORT(CheckMem); EXPORT(ModUtil_LookupString); EXPORT(ModUtil_SetIdent); EXPORT(UnHex); +EXPORT(SwapEndian16); +EXPORT(SwapEndian32); // === CODE === /** @@ -902,3 +904,12 @@ int UnHex(Uint8 *Dest, size_t DestSize, const char *SourceString) } return i/2; } + +Uint16 SwapEndian16(Uint16 Val) +{ + return ((Val&0xFF)<<8) | ((Val>>8)&0xFF); +} +Uint32 SwapEndian32(Uint32 Val) +{ + return ((Val&0xFF)<<24) | ((Val&0xFF00)<<8) | ((Val>>8)&0xFF00) | ((Val>>24)&0xFF); +} diff --git a/Kernel/time.c b/Kernel/time.c index 54ef08fc..1180cad9 100644 --- a/Kernel/time.c +++ b/Kernel/time.c @@ -91,7 +91,6 @@ void Time_Delay(int Delay) } // === EXPORTS === -EXPORT(now); EXPORT(Time_CreateTimer); EXPORT(Time_RemoveTimer); EXPORT(Time_Delay); diff --git a/Modules/x86/VGAText/Makefile b/Modules/x86/VGAText/Makefile new file mode 100644 index 00000000..8f1aee6d --- /dev/null +++ b/Modules/x86/VGAText/Makefile @@ -0,0 +1,7 @@ +# +# + +OBJ := vga.o +NAME := VGAText + +-include ../Makefile.tpl diff --git a/Kernel/drv/vga.c b/Modules/x86/VGAText/vga.c similarity index 98% rename from Kernel/drv/vga.c rename to Modules/x86/VGAText/vga.c index 54360697..f512231d 100644 --- a/Kernel/drv/vga.c +++ b/Modules/x86/VGAText/vga.c @@ -20,7 +20,7 @@ Uint16 VGA_int_GetWord(tVT_Char *Char); void VGA_int_SetCursor(Sint16 x, Sint16 y); // === GLOBALS === -MODULE_DEFINE(0, 0x000A, VGA, VGA_Install, NULL, NULL); +MODULE_DEFINE(0, 0x000A, x86_VGAText, VGA_Install, NULL, NULL); tDevFS_Driver gVGA_DevInfo = { NULL, "VGA", { -- 2.20.1