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
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
CFLAGS =
ASFLAGS =
+PCI_ADDRESS=0
ifeq ($(ARCH),integrator-cp)
MMU_PRESENT=1
else
#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
typedef Uint32 tVAddr;
typedef Uint32 tPAddr;
-#include <lock.h>
+#include "lock.h"
+#include "div.h"
// --- Debug
extern void Debug_PutCharDebug(char Ch);
#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
#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
*/
#include <acess.h>
+// === 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;
+}
--- /dev/null
+ENTRY (_start)
+
+SECTIONS
+{
+ . = 0x80000000;
+ .text : { *(.text*) *(.rodata*) }
+ .data : { *(.data*) }
+ .bss : { *(.bss*) *(COMMON*) }
+}
--- /dev/null
+/*
+ *
+ */
+#include <acess.h>
+
+// === 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));
+}
interrupt_vector_table:
b . @ Reset
b .
- b . @ SWI instruction
+ b SyscallHandler @ SWI instruction
b .
b .
b .
bl main
1: b 1b @ Infinite loop
+
+SyscallHandler:
+
+
--- /dev/null
+/*
+ * Acess2
+ *
+ * ARM7 Time code
+ * arch/arm7/time.c
+ */
+#include <acess.h>
+
+// === GLOBALS ===
+tTime giTimestamp;
+
+// === CODE ===
+tTime now(void)
+{
+ return giTimestamp;
+}
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
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);
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);
--- /dev/null
+/*\r
+ * Acess2\r
+ * arch/x86/pci.h - x86 PCI Bus Access\r
+ */\r
+#define DEBUG 0\r
+#include <acess.h>\r
+\r
+// === PROTOTYPES ===\r
+Uint32 PCI_CfgReadDWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset);\r
+void PCI_CfgWriteDWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset, Uint32 data);\r
+Uint16 PCI_CfgReadWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset);\r
+Uint8 PCI_CfgReadByte(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset);\r
+\r
+// === CODE ===\r
+Uint32 PCI_CfgReadDWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset)\r
+{\r
+ Uint32 address;\r
+ Uint32 data;\r
+ \r
+ bus &= 0xFF; // 8 Bits\r
+ dev &= 0x1F; // 5 Bits\r
+ func &= 0x7; // 3 Bits\r
+ offset &= 0xFF; // 8 Bits\r
+ \r
+ address = 0x80000000 | ((Uint)bus<<16) | ((Uint)dev<<11) | ((Uint)func<<8) | (offset&0xFC);\r
+ outd(0xCF8, address);\r
+ \r
+ data = ind(0xCFC);\r
+ //Debug("PCI(0x%x) = 0x%08x", address, data);\r
+ return data;\r
+}\r
+void PCI_CfgWriteDWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset, Uint32 data)\r
+{\r
+ Uint32 address;\r
+ \r
+ bus &= 0xFF; // 8 Bits\r
+ dev &= 0x1F; // 5 Bits\r
+ func &= 0x7; // 3 Bits\r
+ offset &= 0xFF; // 8 Bits\r
+ \r
+ address = 0x80000000 | ((Uint)bus<<16) | ((Uint)dev<<11) | ((Uint)func<<8) | (offset&0xFC);\r
+ outd(0xCF8, address);\r
+ outd(0xCFC, data);\r
+}\r
+Uint16 PCI_CfgReadWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset)\r
+{\r
+ Uint32 data = PCI_CfgReadDWord(bus, dev, func, offset);\r
+ \r
+ data >>= (offset&2)*8; // Allow Access to Upper Word\r
+ \r
+ return (Uint16)data;\r
+}\r
+\r
+Uint8 PCI_CfgReadByte(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset)\r
+{\r
+ Uint32 data = PCI_CfgReadDWord(bus, dev, func, offset);\r
+ \r
+ data >>= (offset&3)*8; //Allow Access to Upper Word\r
+ return (Uint8)data;\r
+}\r
+\r
#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
);
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
--- /dev/null
+../x86/pci.c
\ No newline at end of file
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 ===
{
int argc, envc, i;
int argenvBytes;
- char *argenvBuf, *strBuf;
+ char **argenvBuf, *strBuf;
char **argvSaved, **envpSaved;
char *savedFile;
Uint entry;
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;
\r
#define LIST_DEVICES 1\r
\r
+// === IMPORTS ===\r
+extern Uint32 PCI_CfgReadDWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset);\r
+extern void PCI_CfgWriteDWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset, Uint32 data);\r
+extern Uint16 PCI_CfgReadWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset);\r
+extern Uint8 PCI_CfgReadByte(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset);\r
+\r
// === STRUCTURES ===\r
typedef struct sPCIDevice\r
{\r
#endif\r
\r
int PCI_EnumDevice(Uint16 bus, Uint16 dev, Uint16 fcn, tPCIDevice *info);\r
-Uint32 PCI_CfgReadDWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset);\r
-void PCI_CfgWriteDWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset, Uint32 data);\r
-Uint16 PCI_CfgReadWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset);\r
-Uint8 PCI_CfgReadByte(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset);\r
\r
// === GLOBALS ===\r
MODULE_DEFINE(0, 0x0100, PCI, PCI_Install, NULL, NULL);\r
}\r
giPCI_DeviceCount ++;\r
\r
- // WTF is this for?\r
- // Maybe bit 23 must be set for the device to be valid?\r
- // - Actually, maybe 23 means that there are sub-functions\r
- if(fcn == 0) {\r
- if( !(devInfo.ConfigCache[3] & 0x00800000) )\r
- break;\r
- }\r
+ // If bit 23 of (soemthing) is set, there are sub-functions\r
+ if(fcn == 0 && !(devInfo.ConfigCache[3] & 0x00800000) )\r
+ break;\r
}\r
}\r
\r
portVals &= ~1;\r
\r
// Get Granuality\r
+ #if ARCHDIR_IS_x86 || ARCHDIR_IS_x86_64\r
__asm__ __volatile__ ("bsf %%eax, %%ecx" : "=c" (gran) : "a" (portVals) );\r
gran = 1 << gran;\r
+ #else\r
+ {\r
+ for(gran = 1; gran && !(portVals & gran); gran <<= 1);\r
+ }\r
+ #endif\r
//LogF(" PCI_AssignPort: gran = 0x%x\n", gran);\r
\r
// Find free space\r
}\r
\r
/**\r
- * \fn int PCI_EnumDevice(Uint16 bus, Uint16 slot, Uint16 fcn, tPCIDevice *info)\r
+ * \fn int PCI_EnumDevice(Uint16 bus, Uint16 slot, Uint16 fcn, tPCIDevice *info)\r
+ * \brief Get device information for a slot/function\r
*/\r
-int PCI_EnumDevice(Uint16 bus, Uint16 slot, Uint16 fcn, tPCIDevice *info)\r
+int PCI_EnumDevice(Uint16 bus, Uint16 slot, Uint16 fcn, tPCIDevice *info)\r
{\r
Uint16 vendor;\r
int i;\r
return 1;\r
}\r
\r
-Uint32 PCI_CfgReadDWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset)\r
-{\r
- Uint32 address;\r
- Uint32 data;\r
- \r
- bus &= 0xFF; // 8 Bits\r
- dev &= 0x1F; // 5 Bits\r
- func &= 0x7; // 3 Bits\r
- offset &= 0xFF; // 8 Bits\r
- \r
- address = 0x80000000 | ((Uint)bus<<16) | ((Uint)dev<<11) | ((Uint)func<<8) | (offset&0xFC);\r
- outd(0xCF8, address);\r
- \r
- data = ind(0xCFC);\r
- //Debug("PCI(0x%x) = 0x%08x", address, data);\r
- return data;\r
-}\r
-void PCI_CfgWriteDWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset, Uint32 data)\r
-{\r
- Uint32 address;\r
- \r
- bus &= 0xFF; // 8 Bits\r
- dev &= 0x1F; // 5 Bits\r
- func &= 0x7; // 3 Bits\r
- offset &= 0xFF; // 8 Bits\r
- \r
- address = 0x80000000 | ((Uint)bus<<16) | ((Uint)dev<<11) | ((Uint)func<<8) | (offset&0xFC);\r
- outd(0xCF8, address);\r
- outd(0xCFC, data);\r
-}\r
-Uint16 PCI_CfgReadWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset)\r
-{\r
- Uint32 data = PCI_CfgReadDWord(bus, dev, func, offset);\r
- \r
- data >>= (offset&2)*8; // Allow Access to Upper Word\r
- \r
- return (Uint16)data;\r
-}\r
-\r
-Uint8 PCI_CfgReadByte(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset)\r
-{\r
- Uint32 data = PCI_CfgReadDWord(bus, dev, func, offset);\r
- \r
- data >>= (offset&3)*8; //Allow Access to Upper Word\r
- return (Uint8)data;\r
-}\r
-\r
-\r
// === EXPORTS ===\r
//*\r
EXPORT(PCI_CountDevices);\r
+++ /dev/null
-/*
- * Acess2 VGA Controller Driver
- */
-#define DEBUG 0
-#include <acess.h>
-#include <fs_devfs.h>
-#include <tpl_drv_video.h>
-#include <modules.h>
-
-// === CONSTANTS ===
-#define VGA_WIDTH 80
-#define VGA_HEIGHT 25
-
-// === PROTOTYPES ===
- int VGA_Install(char **Arguments);
-Uint64 VGA_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer);
- int VGA_IOCtl(tVFS_Node *Node, int Id, void *Data);
-Uint8 VGA_int_GetColourNibble(Uint16 col);
-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);
-tDevFS_Driver gVGA_DevInfo = {
- NULL, "VGA",
- {
- .NumACLs = 0,
- .Size = VGA_WIDTH*VGA_HEIGHT*sizeof(tVT_Char),
- //.Read = VGA_Read,
- .Write = VGA_Write,
- .IOCtl = VGA_IOCtl
- }
-};
-Uint16 *gVGA_Framebuffer = (void*)( KERNEL_BASE|0xB8000 );
-
-// === CODE ===
-/**
- * \fn int VGA_Install(char **Arguments)
- */
-int VGA_Install(char **Arguments)
-{
- Uint8 byte;
-
- // Enable Bright Backgrounds
- inb(0x3DA); // Reset flipflop
- outb(0x3C0, 0x30); // Index 0x10, PAS
- byte = inb(0x3C1);
- byte &= ~8; // Disable Blink
- outb(0x3C0, byte); // Write value
-
-
- // Install DevFS
- DevFS_AddDevice( &gVGA_DevInfo );
-
- return MODULE_ERR_OK;
-}
-
-/**
- * \fn Uint64 VGA_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
- * \brief Writes a string of bytes to the VGA controller
- */
-Uint64 VGA_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
-{
- int num = Length / sizeof(tVT_Char);
- int ofs = Offset / sizeof(tVT_Char);
- int i = 0;
- tVT_Char *chars = Buffer;
- Uint16 word;
-
- //ENTER("pNode XOffset XLength pBuffer", Node, Offset, Length, Buffer);
-
- for( ; num--; i ++, ofs ++)
- {
- word = VGA_int_GetWord( &chars[i] );
- gVGA_Framebuffer[ ofs ] = word;
- }
-
- //LEAVE('X', Length);
- return Length;
-}
-
-/**
- * \fn int VGA_IOCtl(tVFS_Node *Node, int Id, void *Data)
- * \brief IO Control Call
- */
-int VGA_IOCtl(tVFS_Node *Node, int Id, void *Data)
-{
- switch(Id)
- {
- case DRV_IOCTL_TYPE: return DRV_TYPE_VIDEO;
- case DRV_IOCTL_IDENT: memcpy(Data, "VGA\0", 4); return 1;
- case DRV_IOCTL_VERSION: *(int*)Data = 50; return 1;
- case DRV_IOCTL_LOOKUP: return 0;
-
- case VIDEO_IOCTL_GETSETMODE: return 0; // Mode 0 only
- case VIDEO_IOCTL_FINDMODE: return 0; // Text Only!
- case VIDEO_IOCTL_MODEINFO:
- if( ((tVideo_IOCtl_Mode*)Data)->id != 0) return 0;
- ((tVideo_IOCtl_Mode*)Data)->width = VGA_WIDTH;
- ((tVideo_IOCtl_Mode*)Data)->height = VGA_HEIGHT;
- ((tVideo_IOCtl_Mode*)Data)->bpp = 4;
- return 1;
-
- case VIDEO_IOCTL_SETBUFFORMAT:
- return 0;
-
- case VIDEO_IOCTL_SETCURSOR:
- VGA_int_SetCursor( ((tVideo_IOCtl_Pos*)Data)->x, ((tVideo_IOCtl_Pos*)Data)->y );
- return 1;
- }
- return 0;
-}
-
-/**
- * \fn Uint8 VGA_int_GetColourNibble(Uint16 col)
- * \brief Converts a 12-bit colour into a VGA 4-bit colour
- */
-Uint8 VGA_int_GetColourNibble(Uint16 col)
-{
- Uint8 ret = 0;
- int bright = 0;
-
- col = col & 0xCCC;
- col = ((col>>2)&3) | ((col>>4)&0xC) | ((col>>6)&0x30);
- bright = ( (col & 2 ? 1 : 0) + (col & 8 ? 1 : 0) + (col & 32 ? 1 : 0) ) / 2;
-
- switch(col)
- {
- // Black
- case 0x00: ret = 0x0; break;
- // Dark Grey
- case 0x15: ret = 0x8; break;
- // Blues
- case 0x01:
- case 0x02: ret = 0x1; break;
- case 0x03: ret = 0x9; break;
- // Green
- case 0x04:
- case 0x08: ret = 0x2; break;
- case 0x0C: ret = 0xA; break;
- // Reds
- case 0x10:
- case 0x20: ret = 0x4; break;
- case 0x30: ret = 0xC; break;
- // Light Grey
- case 0x2A: ret = 0x7; break;
- // White
- case 0x3F: ret = 0xF; break;
-
- default:
- ret |= (col & 0x03 ? 1 : 0);
- ret |= (col & 0x0C ? 2 : 0);
- ret |= (col & 0x30 ? 4 : 0);
- ret |= (bright ? 8 : 0);
- break;
- }
- return ret;
-}
-
-/**
- * \fn Uint16 VGA_int_GetWord(tVT_Char *Char)
- * \brief Convers a character structure to a VGA character word
- */
-Uint16 VGA_int_GetWord(tVT_Char *Char)
-{
- Uint16 ret;
- Uint16 col;
-
- // Get Character
- if(Char->Ch < 128)
- ret = Char->Ch;
- else {
- switch(Char->Ch)
- {
- default: ret = 0; break;
- }
- }
-
- col = VGA_int_GetColourNibble(Char->BGCol);
- ret |= col << 12;
-
- col = VGA_int_GetColourNibble(Char->FGCol);
- ret |= col << 8;
-
- return ret;
-}
-
-/**
- * \fn void VGA_int_SetCursor(Sint16 x, Sint16 y)
- * \brief Updates the cursor position
- */
-void VGA_int_SetCursor(Sint16 x, Sint16 y)
-{
- int pos = x+y*VGA_WIDTH;
- if(x == -1 || y == -1)
- pos = -1;
- outb(0x3D4, 14);
- outb(0x3D5, pos >> 8);
- outb(0x3D4, 15);
- outb(0x3D5, pos);
-}
* \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);
/**
* \}
*/
EXPORT(ModUtil_LookupString);
EXPORT(ModUtil_SetIdent);
EXPORT(UnHex);
+EXPORT(SwapEndian16);
+EXPORT(SwapEndian32);
// === CODE ===
/**
}
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);
+}
}
// === EXPORTS ===
-EXPORT(now);
EXPORT(Time_CreateTimer);
EXPORT(Time_RemoveTimer);
EXPORT(Time_Delay);
--- /dev/null
+#
+#
+
+OBJ := vga.o
+NAME := VGAText
+
+-include ../Makefile.tpl
--- /dev/null
+/*
+ * Acess2 VGA Controller Driver
+ */
+#define DEBUG 0
+#include <acess.h>
+#include <fs_devfs.h>
+#include <tpl_drv_video.h>
+#include <modules.h>
+
+// === CONSTANTS ===
+#define VGA_WIDTH 80
+#define VGA_HEIGHT 25
+
+// === PROTOTYPES ===
+ int VGA_Install(char **Arguments);
+Uint64 VGA_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer);
+ int VGA_IOCtl(tVFS_Node *Node, int Id, void *Data);
+Uint8 VGA_int_GetColourNibble(Uint16 col);
+Uint16 VGA_int_GetWord(tVT_Char *Char);
+void VGA_int_SetCursor(Sint16 x, Sint16 y);
+
+// === GLOBALS ===
+MODULE_DEFINE(0, 0x000A, x86_VGAText, VGA_Install, NULL, NULL);
+tDevFS_Driver gVGA_DevInfo = {
+ NULL, "VGA",
+ {
+ .NumACLs = 0,
+ .Size = VGA_WIDTH*VGA_HEIGHT*sizeof(tVT_Char),
+ //.Read = VGA_Read,
+ .Write = VGA_Write,
+ .IOCtl = VGA_IOCtl
+ }
+};
+Uint16 *gVGA_Framebuffer = (void*)( KERNEL_BASE|0xB8000 );
+
+// === CODE ===
+/**
+ * \fn int VGA_Install(char **Arguments)
+ */
+int VGA_Install(char **Arguments)
+{
+ Uint8 byte;
+
+ // Enable Bright Backgrounds
+ inb(0x3DA); // Reset flipflop
+ outb(0x3C0, 0x30); // Index 0x10, PAS
+ byte = inb(0x3C1);
+ byte &= ~8; // Disable Blink
+ outb(0x3C0, byte); // Write value
+
+
+ // Install DevFS
+ DevFS_AddDevice( &gVGA_DevInfo );
+
+ return MODULE_ERR_OK;
+}
+
+/**
+ * \fn Uint64 VGA_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
+ * \brief Writes a string of bytes to the VGA controller
+ */
+Uint64 VGA_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
+{
+ int num = Length / sizeof(tVT_Char);
+ int ofs = Offset / sizeof(tVT_Char);
+ int i = 0;
+ tVT_Char *chars = Buffer;
+ Uint16 word;
+
+ //ENTER("pNode XOffset XLength pBuffer", Node, Offset, Length, Buffer);
+
+ for( ; num--; i ++, ofs ++)
+ {
+ word = VGA_int_GetWord( &chars[i] );
+ gVGA_Framebuffer[ ofs ] = word;
+ }
+
+ //LEAVE('X', Length);
+ return Length;
+}
+
+/**
+ * \fn int VGA_IOCtl(tVFS_Node *Node, int Id, void *Data)
+ * \brief IO Control Call
+ */
+int VGA_IOCtl(tVFS_Node *Node, int Id, void *Data)
+{
+ switch(Id)
+ {
+ case DRV_IOCTL_TYPE: return DRV_TYPE_VIDEO;
+ case DRV_IOCTL_IDENT: memcpy(Data, "VGA\0", 4); return 1;
+ case DRV_IOCTL_VERSION: *(int*)Data = 50; return 1;
+ case DRV_IOCTL_LOOKUP: return 0;
+
+ case VIDEO_IOCTL_GETSETMODE: return 0; // Mode 0 only
+ case VIDEO_IOCTL_FINDMODE: return 0; // Text Only!
+ case VIDEO_IOCTL_MODEINFO:
+ if( ((tVideo_IOCtl_Mode*)Data)->id != 0) return 0;
+ ((tVideo_IOCtl_Mode*)Data)->width = VGA_WIDTH;
+ ((tVideo_IOCtl_Mode*)Data)->height = VGA_HEIGHT;
+ ((tVideo_IOCtl_Mode*)Data)->bpp = 4;
+ return 1;
+
+ case VIDEO_IOCTL_SETBUFFORMAT:
+ return 0;
+
+ case VIDEO_IOCTL_SETCURSOR:
+ VGA_int_SetCursor( ((tVideo_IOCtl_Pos*)Data)->x, ((tVideo_IOCtl_Pos*)Data)->y );
+ return 1;
+ }
+ return 0;
+}
+
+/**
+ * \fn Uint8 VGA_int_GetColourNibble(Uint16 col)
+ * \brief Converts a 12-bit colour into a VGA 4-bit colour
+ */
+Uint8 VGA_int_GetColourNibble(Uint16 col)
+{
+ Uint8 ret = 0;
+ int bright = 0;
+
+ col = col & 0xCCC;
+ col = ((col>>2)&3) | ((col>>4)&0xC) | ((col>>6)&0x30);
+ bright = ( (col & 2 ? 1 : 0) + (col & 8 ? 1 : 0) + (col & 32 ? 1 : 0) ) / 2;
+
+ switch(col)
+ {
+ // Black
+ case 0x00: ret = 0x0; break;
+ // Dark Grey
+ case 0x15: ret = 0x8; break;
+ // Blues
+ case 0x01:
+ case 0x02: ret = 0x1; break;
+ case 0x03: ret = 0x9; break;
+ // Green
+ case 0x04:
+ case 0x08: ret = 0x2; break;
+ case 0x0C: ret = 0xA; break;
+ // Reds
+ case 0x10:
+ case 0x20: ret = 0x4; break;
+ case 0x30: ret = 0xC; break;
+ // Light Grey
+ case 0x2A: ret = 0x7; break;
+ // White
+ case 0x3F: ret = 0xF; break;
+
+ default:
+ ret |= (col & 0x03 ? 1 : 0);
+ ret |= (col & 0x0C ? 2 : 0);
+ ret |= (col & 0x30 ? 4 : 0);
+ ret |= (bright ? 8 : 0);
+ break;
+ }
+ return ret;
+}
+
+/**
+ * \fn Uint16 VGA_int_GetWord(tVT_Char *Char)
+ * \brief Convers a character structure to a VGA character word
+ */
+Uint16 VGA_int_GetWord(tVT_Char *Char)
+{
+ Uint16 ret;
+ Uint16 col;
+
+ // Get Character
+ if(Char->Ch < 128)
+ ret = Char->Ch;
+ else {
+ switch(Char->Ch)
+ {
+ default: ret = 0; break;
+ }
+ }
+
+ col = VGA_int_GetColourNibble(Char->BGCol);
+ ret |= col << 12;
+
+ col = VGA_int_GetColourNibble(Char->FGCol);
+ ret |= col << 8;
+
+ return ret;
+}
+
+/**
+ * \fn void VGA_int_SetCursor(Sint16 x, Sint16 y)
+ * \brief Updates the cursor position
+ */
+void VGA_int_SetCursor(Sint16 x, Sint16 y)
+{
+ int pos = x+y*VGA_WIDTH;
+ if(x == -1 || y == -1)
+ pos = -1;
+ outb(0x3D4, 14);
+ outb(0x3D5, pos >> 8);
+ outb(0x3D4, 15);
+ outb(0x3D5, pos);
+}