From: John Hodge Date: Fri, 18 Jun 2010 08:42:31 +0000 (+0800) Subject: It's been too long since I committed X-Git-Tag: rel0.06~149 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=dea6bcf35a3f52396724d74e47f71cb3afade37c;p=tpg%2Facess2.git It's been too long since I committed - Mostly fixes to bugs exposed/caused by the 64-bit port or the new compiler. --- diff --git a/Kernel/Makefile b/Kernel/Makefile index b5a6db0a..225928c3 100644 --- a/Kernel/Makefile +++ b/Kernel/Makefile @@ -16,7 +16,7 @@ MAKEDEP = $(CC) -M CPPFLAGS += -I./include -I./arch/$(ARCHDIR)/include CPPFLAGS += -DARCH=$(ARCH) -DARCHDIR=$(ARCHDIR) -DKERNEL_VERSION=$(KERNEL_VERSION) -DBUILD_NUM=$(BUILD_NUM) -CFLAGS += -Wall -Werror -O3 -fno-stack-protector -fno-builtin +CFLAGS += -Wall -Werror -O3 -fno-stack-protector -fno-builtin -Wstrict-prototypes ASFLAGS += -D ARCH=\"$(ARCH)\" -D ARCHDIR=\"$(ARCHDIR)\" LDFLAGS += -T arch/$(ARCHDIR)/link.ld diff --git a/Kernel/arch/x86/errors.c b/Kernel/arch/x86/errors.c index d1d9cb72..3ae4bb28 100644 --- a/Kernel/arch/x86/errors.c +++ b/Kernel/arch/x86/errors.c @@ -31,7 +31,7 @@ const char *csaERROR_NAMES[] = { }; // === CODE === -void __stack_chk_fail() +void __stack_chk_fail(void) { Panic("FATAL ERROR: Stack Check Failed\n"); for(;;); diff --git a/Kernel/arch/x86/include/mm_phys.h b/Kernel/arch/x86/include/mm_phys.h index f72ebf6a..1e05c01a 100644 --- a/Kernel/arch/x86/include/mm_phys.h +++ b/Kernel/arch/x86/include/mm_phys.h @@ -6,7 +6,7 @@ #define _MM_PHYS_H // === FUNCTIONS === -extern tPAddr MM_AllocPhys(); +extern tPAddr MM_AllocPhys(void); extern tPAddr MM_AllocPhysRange(int Pages, int MaxBits); extern void MM_RefPhys(tPAddr PAddr); extern void MM_DerefPhys(tPAddr PAddr); diff --git a/Kernel/arch/x86/include/mm_virt.h b/Kernel/arch/x86/include/mm_virt.h index 4f650e8c..2664a104 100644 --- a/Kernel/arch/x86/include/mm_virt.h +++ b/Kernel/arch/x86/include/mm_virt.h @@ -25,13 +25,13 @@ #define MM_MODULE_MAX 0xF0000000 // 512 MiB // === FUNCTIONS === -extern void MM_FinishVirtualInit(); +extern void MM_FinishVirtualInit(void); extern void MM_SetCR3(Uint CR3); extern tPAddr MM_Allocate(tVAddr VAddr); extern void MM_Deallocate(tVAddr VAddr); extern int MM_Map(tVAddr VAddr, tPAddr PAddr); -extern tPAddr MM_Clone(); -extern tVAddr MM_NewKStack(); -extern tVAddr MM_NewWorkerStack(); +extern tPAddr MM_Clone(void); +extern tVAddr MM_NewKStack(void); +extern tVAddr MM_NewWorkerStack(void); #endif diff --git a/Kernel/arch/x86/include/proc.h b/Kernel/arch/x86/include/proc.h index baf9402c..5e3fadd9 100644 --- a/Kernel/arch/x86/include/proc.h +++ b/Kernel/arch/x86/include/proc.h @@ -34,7 +34,7 @@ typedef struct sTSS { } __attribute__((packed)) tTSS; // === FUNCTIONS === -extern void Proc_Start(); +extern void Proc_Start(void); extern int Proc_Clone(Uint *Err, Uint Flags); #endif diff --git a/Kernel/arch/x86/kpanic.c b/Kernel/arch/x86/kpanic.c index 798c5139..6454eca0 100644 --- a/Kernel/arch/x86/kpanic.c +++ b/Kernel/arch/x86/kpanic.c @@ -55,7 +55,7 @@ const struct { /** * \brief Sets the screen mode for a kernel panic */ -void KernelPanic_SetMode() +void KernelPanic_SetMode(void) { int i; diff --git a/Kernel/arch/x86/main.c b/Kernel/arch/x86/main.c index 34cc4146..1d5d3a7f 100644 --- a/Kernel/arch/x86/main.c +++ b/Kernel/arch/x86/main.c @@ -22,7 +22,6 @@ extern void Threads_Init(void); extern int Time_Setup(void); extern Uint Proc_Clone(Uint *Err, Uint Flags); extern void Threads_Sleep(void); -extern void Threads_Exit(void); // --- Core --- extern void System_Init(char *Commandline); diff --git a/Kernel/arch/x86/mm_phys.c b/Kernel/arch/x86/mm_phys.c index f091c63a..b3325c90 100644 --- a/Kernel/arch/x86/mm_phys.c +++ b/Kernel/arch/x86/mm_phys.c @@ -15,7 +15,7 @@ extern void gKernelEnd; // === PROTOTYPES === -tPAddr MM_AllocPhys(); +tPAddr MM_AllocPhys(void); tPAddr MM_AllocPhysRange(int Pages, int MaxBits); void MM_RefPhys(tPAddr PAddr); void MM_DerefPhys(tPAddr PAddr); @@ -123,10 +123,10 @@ void MM_Install(tMBoot_Info *MBoot) } /** - * \fn tPAddr MM_AllocPhys() + * \fn tPAddr MM_AllocPhys(void) * \brief Allocates a physical page from the general pool */ -tPAddr MM_AllocPhys() +tPAddr MM_AllocPhys(void) { // int a, b, c; int indx; diff --git a/Kernel/arch/x86/mm_virt.c b/Kernel/arch/x86/mm_virt.c index aaec06ea..7cdf5cd8 100644 --- a/Kernel/arch/x86/mm_virt.c +++ b/Kernel/arch/x86/mm_virt.c @@ -74,8 +74,8 @@ extern void Threads_SegFault(tVAddr Addr); extern void Error_Backtrace(Uint eip, Uint ebp); // === PROTOTYPES === -void MM_PreinitVirtual(); -void MM_InstallVirtual(); +void MM_PreinitVirtual(void); +void MM_InstallVirtual(void); void MM_PageFault(tVAddr Addr, Uint ErrorCode, tRegs *Regs); void MM_DumpTables(tVAddr Start, tVAddr End); tPAddr MM_DuplicatePage(tVAddr VAddr); @@ -102,10 +102,10 @@ Uint32 gWorkerStacks[(NUM_WORKER_STACKS+31)/32]; // === CODE === /** - * \fn void MM_PreinitVirtual() + * \fn void MM_PreinitVirtual(void) * \brief Maps the fractal mappings */ -void MM_PreinitVirtual() +void MM_PreinitVirtual(void) { #if USE_PAE gaInitPageDir[ ((PAGE_TABLE_ADDR >> TAB)-3*512+3)*2 ] = ((tTabEnt)&gaInitPageDir - KERNEL_BASE) | 3; @@ -116,10 +116,10 @@ void MM_PreinitVirtual() } /** - * \fn void MM_InstallVirtual() + * \fn void MM_InstallVirtual(void) * \brief Sets up the constant page mappings */ -void MM_InstallVirtual() +void MM_InstallVirtual(void) { int i; @@ -166,7 +166,7 @@ void MM_InstallVirtual() /** * \brief Cleans up the SMP required mappings */ -void MM_FinishVirtualInit() +void MM_FinishVirtualInit(void) { #if USE_PAE gaInitPDPT[ 0 ] = 0; @@ -479,7 +479,7 @@ int MM_Map(tVAddr VAddr, tPAddr PAddr) * \fn tVAddr MM_ClearUser() * \brief Clear user's address space */ -tVAddr MM_ClearUser() +tVAddr MM_ClearUser(void) { Uint i, j; @@ -510,10 +510,10 @@ tVAddr MM_ClearUser() } /** - * \fn tPAddr MM_Clone() + * \fn tPAddr MM_Clone(void) * \brief Clone the current address space */ -tPAddr MM_Clone() +tPAddr MM_Clone(void) { Uint i, j; tVAddr ret; @@ -636,10 +636,10 @@ tPAddr MM_Clone() } /** - * \fn tVAddr MM_NewKStack() + * \fn tVAddr MM_NewKStack(void) * \brief Create a new kernel stack */ -tVAddr MM_NewKStack() +tVAddr MM_NewKStack(void) { tVAddr base = KERNEL_STACKS; Uint i; diff --git a/Kernel/arch/x86/proc.c b/Kernel/arch/x86/proc.c index 45c5a561..43a88e38 100644 --- a/Kernel/arch/x86/proc.c +++ b/Kernel/arch/x86/proc.c @@ -22,8 +22,8 @@ // === IMPORTS === extern tGDT gGDT[]; extern tIDT gIDT[]; -extern void APStartup(); // 16-bit AP startup code -extern Uint GetEIP(); // start.asm +extern void APStartup(void); // 16-bit AP startup code +extern Uint GetEIP(void); // start.asm extern Uint32 gaInitPageDir[1024]; // start.asm extern void Kernel_Stack_Top; extern tSpinlock glThreadListLock; @@ -36,24 +36,24 @@ extern tThread *gActiveThreads; extern tThread *gSleepingThreads; extern tThread *gDeleteThreads; extern tThread *Threads_GetNextToRun(int CPU); -extern void Threads_Dump(); +extern void Threads_Dump(void); extern tThread *Threads_CloneTCB(Uint *Err, Uint Flags); -extern void Isr8(); // Double Fault -extern void Proc_ReturnToUser(); +extern void Isr8(void); // Double Fault +extern void Proc_ReturnToUser(void); // === PROTOTYPES === -void ArchThreads_Init(); +void ArchThreads_Init(void); #if USE_MP void MP_StartAP(int CPU); void MP_SendIPI(Uint8 APICID, int Vector, int DeliveryMode); #endif -void Proc_Start(); -tThread *Proc_GetCurThread(); -void Proc_ChangeStack(); +void Proc_Start(void); +tThread *Proc_GetCurThread(void); +void Proc_ChangeStack(void); int Proc_Clone(Uint *Err, Uint Flags); void Proc_StartProcess(Uint16 SS, Uint Stack, Uint Flags, Uint16 CS, Uint IP); void Proc_CallFaultHandler(tThread *Thread); -void Proc_Scheduler(); +void Proc_Scheduler(int CPU); // === GLOBALS === // --- Multiprocessing --- @@ -86,10 +86,10 @@ tTSS gDoubleFault_TSS = { // === CODE === /** - * \fn void ArchThreads_Init() + * \fn void ArchThreads_Init(void) * \brief Starts the process scheduler */ -void ArchThreads_Init() +void ArchThreads_Init(void) { Uint pos = 0; @@ -373,20 +373,20 @@ void MP_SendIPI(Uint8 APICID, int Vector, int DeliveryMode) #endif /** - * \fn void Proc_Start() + * \fn void Proc_Start(void) * \brief Start process scheduler */ -void Proc_Start() +void Proc_Start(void) { // Start Interrupts (and hence scheduler) __asm__ __volatile__("sti"); } /** - * \fn tThread *Proc_GetCurThread() + * \fn tThread *Proc_GetCurThread(void) * \brief Gets the current thread */ -tThread *Proc_GetCurThread() +tThread *Proc_GetCurThread(void) { #if USE_MP return gaCPUs[ gaAPIC_to_CPU[gpMP_LocalAPIC->ID.Val&0xFF] ].Current; @@ -396,10 +396,10 @@ tThread *Proc_GetCurThread() } /** - * \fn void Proc_ChangeStack() + * \fn void Proc_ChangeStack(void) * \brief Swaps the current stack for a new one (in the proper stack reigon) */ -void Proc_ChangeStack() +void Proc_ChangeStack(void) { Uint esp, ebp; Uint tmpEbp, oldEsp; @@ -517,10 +517,10 @@ int Proc_Clone(Uint *Err, Uint Flags) } /** - * \fn int Proc_SpawnWorker() + * \fn int Proc_SpawnWorker(void) * \brief Spawns a new worker thread */ -int Proc_SpawnWorker() +int Proc_SpawnWorker(void) { tThread *new, *cur; Uint eip, esp, ebp; @@ -565,10 +565,10 @@ int Proc_SpawnWorker() } /** - * \fn Uint Proc_MakeUserStack() + * \fn Uint Proc_MakeUserStack(void) * \brief Creates a new user stack */ -Uint Proc_MakeUserStack() +Uint Proc_MakeUserStack(void) { int i; Uint base = USER_STACK_TOP - USER_STACK_SZ; diff --git a/Kernel/arch/x86/time.c b/Kernel/arch/x86/time.c index 49d515e4..77683b55 100644 --- a/Kernel/arch/x86/time.c +++ b/Kernel/arch/x86/time.c @@ -20,14 +20,14 @@ extern Uint64 giPartMiliseconds; extern void Timer_CallTimers(void); // === PROTOTYPES === -void Time_Interrupt(); +void Time_Interrupt(int); // === CODE === /** - * \fn int Time_Setup() + * \fn int Time_Setup(void) * \brief Sets the system time from the Realtime-Clock */ -int Time_Setup() +int Time_Setup(void) { Uint8 val; @@ -57,10 +57,10 @@ int Time_Setup() } /** - * \fn void Time_Interrupt() + * \fn void Time_Interrupt(void) * \brief Called on the timekeeping IRQ */ -void Time_Interrupt() +void Time_Interrupt(int irq) { giTicks ++; giTimestamp += MS_PER_TICK_WHOLE; @@ -79,9 +79,9 @@ void Time_Interrupt() #if 0 /** - * \fn void Time_TimerThread() + * \fn void Time_TimerThread(void) */ -void Time_TimerThread() +void Time_TimerThread(void) { Sint64 next; Threads_SetName("TIMER"); diff --git a/Kernel/arch/x86_64/include/arch.h b/Kernel/arch/x86_64/include/arch.h index 9b3801bb..48d19ca7 100644 --- a/Kernel/arch/x86_64/include/arch.h +++ b/Kernel/arch/x86_64/include/arch.h @@ -6,7 +6,8 @@ #define _ARCH_H_ #include -#define KERNEL_BASE 0xFFFF8000##00000000 +//#define KERNEL_BASE 0xFFFF8000##00000000 +#define KERNEL_BASE 0xFFFFFFFF##80000000 #define BITS 64 // === Core Types === diff --git a/Kernel/arch/x86_64/include/mm_virt.h b/Kernel/arch/x86_64/include/mm_virt.h index 5221e511..ac90321d 100644 --- a/Kernel/arch/x86_64/include/mm_virt.h +++ b/Kernel/arch/x86_64/include/mm_virt.h @@ -20,8 +20,7 @@ * 0x00000000 00000000 - 0x00007FFF FFFFFFFF 47 128 TiB User Space * 0x00008000 00000000 - 0xFFFF7FFF FFFFFFFF --- SIGN EXTENSION NULL ZONE * 0xFFFF8000 00000000 - 0xFFFFFFFF FFFFFFFF 47 128 TiB Kernel Range - * 8000 00000000 - 8000 7FFFFFFF 31 2 GiB Identity Map - * 8000 80000000 - 9000 00000000 ~44 16 TiB Kernel Heap + * 8000 00000000 - 9000 00000000 44 16 TiB Kernel Heap * 9000 00000000 - 9800 00000000 43 8 TiB Module Space * 9800 00000000 - 9A00 00000000 41 2 TiB Kernel VFS * A000 00000000 - B000 00000000 44 16 TiB Kernel Stacks @@ -35,6 +34,9 @@ * FD00 00000000 - FD80 00000000 39 512 GiB Local APIC * FE00 00000000 - FE80 00000000 39 512 GiB Fractal Mapping (PML4 510) * FE80 00000000 - FF00 00000000 39 512 GiB Temp Fractal Mapping + * FF00 00000000 - FF80 00000000 39 512 GiB -- UNUSED -- + * FF80 00000000 - FFFF 80000000 ~39 GiB -- UNUSED -- + * FFFF 80000000 - FFFF 7FFFFFFF 31 2 GiB Identity Map */ #define MM_USER_MIN 0x00000000##00010000 diff --git a/Kernel/arch/x86_64/link.ld b/Kernel/arch/x86_64/link.ld index b688c7ad..f1df2299 100644 --- a/Kernel/arch/x86_64/link.ld +++ b/Kernel/arch/x86_64/link.ld @@ -3,7 +3,9 @@ * Linker Script */ -_kernel_base = 0xFFFF800000000000; +/* _kernel_base = 0xFFFF800000000000; */ +/* -2 GiB */ +_kernel_base = 0xFFFFFFFF80000000; OUTPUT_FORMAT(elf32-i386) OUTPUT_ARCH(i386:x86-64) diff --git a/Kernel/arch/x86_64/main.c b/Kernel/arch/x86_64/main.c index f2a92298..5ea1934b 100644 --- a/Kernel/arch/x86_64/main.c +++ b/Kernel/arch/x86_64/main.c @@ -35,7 +35,7 @@ void kmain(Uint MbMagic, void *MbInfoPtr) case MULTIBOOT_MAGIC: // Adjust Multiboot structure address mbInfo = (void*)( (Uint)MbInfoPtr + KERNEL_BASE ); - gsBootCmdLine = (char*)(mbInfo->CommandLine + KERNEL_BASE); + gsBootCmdLine = (char*)( (Uint)mbInfo->CommandLine + KERNEL_BASE); MM_InitPhys_Multiboot( mbInfo ); // Set up physical memory manager break; diff --git a/Kernel/arch/x86_64/proc.c b/Kernel/arch/x86_64/proc.c index 2a246a6c..4d502100 100644 --- a/Kernel/arch/x86_64/proc.c +++ b/Kernel/arch/x86_64/proc.c @@ -22,8 +22,8 @@ // === IMPORTS === extern tGDT gGDT[]; -extern void APStartup(); // 16-bit AP startup code -extern Uint GetRIP(); // start.asm +extern void APStartup(void); // 16-bit AP startup code +extern Uint GetRIP(void); // start.asm extern Uint64 gInitialPML4[512]; // start.asm extern void gInitialKernelStack; extern tSpinlock glThreadListLock; @@ -42,18 +42,18 @@ extern void Proc_ReturnToUser(void); extern void GetCPUNum(void); // === PROTOTYPES === -void ArchThreads_Init(); +void ArchThreads_Init(void); #if USE_MP void MP_StartAP(int CPU); void MP_SendIPI(Uint8 APICID, int Vector, int DeliveryMode); #endif -void Proc_Start(); -tThread *Proc_GetCurThread(); -void Proc_ChangeStack(); +void Proc_Start(void); +tThread *Proc_GetCurThread(void); +void Proc_ChangeStack(void); int Proc_Clone(Uint *Err, Uint Flags); void Proc_StartProcess(Uint16 SS, Uint Stack, Uint Flags, Uint16 CS, Uint IP); void Proc_CallFaultHandler(tThread *Thread); -void Proc_Scheduler(); +void Proc_Scheduler(int CPU); // === GLOBALS === // --- Multiprocessing --- @@ -73,10 +73,10 @@ Uint32 gaDoubleFaultStack[1024]; // === CODE === /** - * \fn void ArchThreads_Init() + * \fn void ArchThreads_Init(void) * \brief Starts the process scheduler */ -void ArchThreads_Init() +void ArchThreads_Init(void) { Uint pos = 0; @@ -333,20 +333,20 @@ void MP_SendIPI(Uint8 APICID, int Vector, int DeliveryMode) #endif /** - * \fn void Proc_Start() + * \fn void Proc_Start(void) * \brief Start process scheduler */ -void Proc_Start() +void Proc_Start(void) { // Start Interrupts (and hence scheduler) __asm__ __volatile__("sti"); } /** - * \fn tThread *Proc_GetCurThread() + * \fn tThread *Proc_GetCurThread(void) * \brief Gets the current thread */ -tThread *Proc_GetCurThread() +tThread *Proc_GetCurThread(void) { #if USE_MP //return gaCPUs[ gaAPIC_to_CPU[gpMP_LocalAPIC->ID.Val&0xFF] ].Current; @@ -357,10 +357,10 @@ tThread *Proc_GetCurThread() } /** - * \fn void Proc_ChangeStack() + * \fn void Proc_ChangeStack(void) * \brief Swaps the current stack for a new one (in the proper stack reigon) */ -void Proc_ChangeStack() +void Proc_ChangeStack(void) { Uint rsp, rbp; Uint tmp_rbp, old_rsp; @@ -487,10 +487,10 @@ int Proc_Clone(Uint *Err, Uint Flags) } /** - * \fn int Proc_SpawnWorker() + * \fn int Proc_SpawnWorker(void) * \brief Spawns a new worker thread */ -int Proc_SpawnWorker() +int Proc_SpawnWorker(void) { tThread *new, *cur; Uint rip, rsp, rbp; @@ -535,10 +535,10 @@ int Proc_SpawnWorker() } /** - * \fn Uint Proc_MakeUserStack() + * \fn Uint Proc_MakeUserStack(void) * \brief Creates a new user stack */ -Uint Proc_MakeUserStack() +Uint Proc_MakeUserStack(void) { int i; Uint base = USER_STACK_TOP - USER_STACK_SZ; diff --git a/Kernel/arch/x86_64/start32.asm b/Kernel/arch/x86_64/start32.asm index 0abf8eb0..0178bddb 100644 --- a/Kernel/arch/x86_64/start32.asm +++ b/Kernel/arch/x86_64/start32.asm @@ -1,7 +1,8 @@ [BITS 32] -KERNEL_BASE equ 0xFFFF800000000000 +;KERNEL_BASE equ 0xFFFF800000000000 +KERNEL_BASE equ 0xFFFFFFFF80000000 [section .multiboot] mboot: @@ -45,9 +46,11 @@ start: test edx, 1<<29 jz .not64bitCapable - ; Enable PAE + ; Enable PGE (Page Global Enable) + ; + PAE (Physical Address Extension) + ; + PSE (Page Size Extensions) mov eax, cr4 - or eax, 0x80|0x20 + or eax, 0x80|0x20|0x10 mov cr4, eax ; Load PDP4 @@ -110,18 +113,21 @@ gMultibootPtr: [global gInitialPML4] gInitialPML4: ; Covers 256 TiB (Full 48-bit Virtual Address Space) dd gInitialPDP - KERNEL_BASE + 3, 0 ; Identity Map Low 4Mb - times 256-1 dq 0 - dd gInitialPDP - KERNEL_BASE + 3, 0 ; Map Low 4Mb to kernel base - times 256-1-4 dq 0 + times 512-1-4 dq 0 dd gInitialPML4 - KERNEL_BASE + 3, 0 ; Fractal Mapping dq 0 dq 0 - dq 0 + dd gHighPDP - KERNEL_BASE + 3, 0 ; Map Low 4Mb to kernel base gInitialPDP: ; Covers 512 GiB dd gInitialPD - KERNEL_BASE + 3, 0 times 511 dq 0 +gHighPDP: ; Covers 512 GiB + times 510 dq 0 + dq 0 + 0x143 ; 1 GiB Page from zero + dq 0 + gInitialPD: ; Covers 1 GiB dd gInitialPT1 - KERNEL_BASE + 3, 0 dd gInitialPT2 - KERNEL_BASE + 3, 0 @@ -130,13 +136,13 @@ gInitialPD: ; Covers 1 GiB gInitialPT1: ; Covers 2 MiB %assign i 0 %rep 512 - dq i*4096+3 + dq i*4096+0x103 %assign i i+1 %endrep gInitialPT2: ; 2 MiB %assign i 512 %rep 512 - dq i*4096+3 + dq i*4096+0x103 %assign i i+1 %endrep diff --git a/Kernel/arch/x86_64/start64.asm b/Kernel/arch/x86_64/start64.asm index 33c77d62..7617d6ae 100644 --- a/Kernel/arch/x86_64/start64.asm +++ b/Kernel/arch/x86_64/start64.asm @@ -2,7 +2,8 @@ ; Acess2 x86_64 Port ; [bits 64] -KERNEL_BASE equ 0xFFFF800000000000 +;KERNEL_BASE equ 0xFFFF800000000000 +KERNEL_BASE equ 0xFFFFFFFF80000000 [extern kmain] diff --git a/Kernel/binary.c b/Kernel/binary.c index 4feb1d3a..9455a626 100644 --- a/Kernel/binary.c +++ b/Kernel/binary.c @@ -27,7 +27,7 @@ typedef struct sKernelBin { extern int Proc_Clone(Uint *Err, Uint Flags); extern char *Threads_GetName(int ID); extern void Threads_Exit(int, int); -extern Uint MM_ClearUser(); +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; diff --git a/Kernel/debug.c b/Kernel/debug.c index 06fb0709..3a038424 100644 --- a/Kernel/debug.c +++ b/Kernel/debug.c @@ -19,9 +19,9 @@ extern void KernelPanic_PutChar(char Ch); // === PROTOTYPES === int putDebugChar(char ch); - int getDebugChar(); + int getDebugChar(void); static void Debug_Putchar(char ch); -static void Debug_Puts(char *Str); +static void Debug_Puts(int DbgOnly, char *Str); void Debug_Fmt(const char *format, va_list args); // === GLOBALS === @@ -49,7 +49,7 @@ int putDebugChar(char ch) outb(GDB_SERIAL_PORT, ch); return 0; } -int getDebugChar() +int getDebugChar(void) { if(!gbGDB_SerialSetup) { outb(GDB_SERIAL_PORT + 1, 0x00); // Disable all interrupts @@ -65,7 +65,7 @@ int getDebugChar() return inb(GDB_SERIAL_PORT); } -static void Debug_Putchar(char ch) +static void Debug_PutCharDebug(char ch) { #if DEBUG_TO_E9 __asm__ __volatile__ ( "outb %%al, $0xe9" :: "a"(((Uint8)ch)) ); @@ -85,7 +85,11 @@ static void Debug_Putchar(char ch) while( (inb(SERIAL_PORT + 5) & 0x20) == 0 ); outb(SERIAL_PORT, ch); #endif - +} + +static void Debug_Putchar(char ch) +{ + Debug_PutCharDebug(ch); if( !gbDebug_IsKPanic ) { if(gbInPutChar) return ; @@ -98,29 +102,12 @@ static void Debug_Putchar(char ch) KernelPanic_PutChar(ch); } -static void Debug_Puts(char *Str) +static void Debug_Puts(int UseKTerm, char *Str) { int len = 0; while( *Str ) { - #if DEBUG_TO_E9 - __asm__ __volatile__ ( "outb %%al, $0xe9" :: "a" ((Uint8)*Str) ); - #endif - - #if DEBUG_TO_SERIAL - if(!gbDebug_SerialSetup) { - outb(SERIAL_PORT + 1, 0x00); // Disable all interrupts - outb(SERIAL_PORT + 3, 0x80); // Enable DLAB (set baud rate divisor) - outb(SERIAL_PORT + 0, 0x03); // Set divisor to 3 (lo byte) 38400 baud - outb(SERIAL_PORT + 1, 0x00); // (hi byte) - outb(SERIAL_PORT + 3, 0x03); // 8 bits, no parity, one stop bit - outb(SERIAL_PORT + 2, 0xC7); // Enable FIFO with 14-byte threshold and clear it - outb(SERIAL_PORT + 4, 0x0B); // IRQs enabled, RTS/DSR set - gbDebug_SerialSetup = 1; - } - while( (inb(SERIAL_PORT + 5) & 0x20) == 0 ); - outb(SERIAL_PORT, *Str); - #endif + Debug_PutCharDebug( *Str ); if( gbDebug_IsKPanic ) KernelPanic_PutChar(*Str); @@ -130,7 +117,7 @@ static void Debug_Puts(char *Str) Str -= len; - if( !gbDebug_IsKPanic && giDebug_KTerm != -1) + if( UseKTerm && !gbDebug_IsKPanic && giDebug_KTerm != -1) { if(gbInPutChar) return ; gbInPutChar = 1; @@ -139,152 +126,27 @@ static void Debug_Puts(char *Str) } } +void Debug_DbgOnlyFmt(const char *format, va_list args) +{ + char buf[DEBUG_MAX_LINE_LEN]; + int len; + buf[DEBUG_MAX_LINE_LEN-1] = 0; + len = vsnprintf(buf, DEBUG_MAX_LINE_LEN-1, format, args); + //if( len < DEBUG_MAX_LINE ) + // do something + Debug_Puts(0, buf); +} + void Debug_Fmt(const char *format, va_list args) { - #if DEBUG_USE_VSNPRINTF char buf[DEBUG_MAX_LINE_LEN]; int len; buf[DEBUG_MAX_LINE_LEN-1] = 0; len = vsnprintf(buf, DEBUG_MAX_LINE_LEN-1, format, args); //if( len < DEBUG_MAX_LINE ) // do something - Debug_Puts(buf); + Debug_Puts(1, buf); return ; - #else - char c, pad = ' '; - int minSize = 0, len; - char tmpBuf[34]; // For Integers - char *p = NULL; - int isLongLong = 0; - Uint64 arg; - int bPadLeft = 0; - - while((c = *format++) != 0) - { - // Non control character - if( c != '%' ) { - Debug_Putchar(c); - continue; - } - - c = *format++; - - // Literal % - if(c == '%') { - Debug_Putchar('%'); - continue; - } - - // Pointer - if(c == 'p') { - Uint ptr = va_arg(args, Uint); - Debug_Putchar('*'); Debug_Putchar('0'); Debug_Putchar('x'); - p = tmpBuf; - itoa(p, ptr, 16, BITS/4, '0'); - goto printString; - } - - // Get Argument - arg = va_arg(args, Uint); - - // - Padding Side Flag - if(c == '+') { - bPadLeft = 1; - c = *format++; - } - - // Padding - if(c == '0') { - pad = '0'; - c = *format++; - } else - pad = ' '; - - // Minimum length - minSize = 1; - if('1' <= c && c <= '9') - { - minSize = 0; - while('0' <= c && c <= '9') - { - minSize *= 10; - minSize += c - '0'; - c = *format++; - } - } - - // Long (default) - isLongLong = 0; - if(c == 'l') { - c = *format++; - if(c == 'l') { - #if BITS == 32 - arg |= va_arg(args, Uint); - #endif - c = *format++; - isLongLong = 1; - } - } - - p = tmpBuf; - switch (c) { - case 'd': - case 'i': - if( (isLongLong && arg >> 63) || (!isLongLong && arg >> 31) ) { - Debug_Putchar('-'); - arg = -arg; - } - itoa(p, arg, 10, minSize, pad); - goto printString; - case 'u': - itoa(p, arg, 10, minSize, pad); - goto printString; - case 'x': - itoa(p, arg, 16, minSize, pad); - goto printString; - case 'o': - itoa(p, arg, 8, minSize, pad); - goto printString; - case 'b': - itoa(p, arg, 2, minSize, pad); - goto printString; - - printString: - if(!p) p = "(null)"; - while(*p) Debug_Putchar(*p++); - break; - - case 'B': //Boolean - if(arg) Debug_Puts("True"); - else Debug_Puts("False"); - break; - - case 's': - p = (char*)(Uint)arg; - if(!p) p = "(null)"; - len = strlen(p); - if( !bPadLeft ) while(len++ < minSize) Debug_Putchar(pad); - while(*p) Debug_Putchar(*p++); - if( bPadLeft ) while(len++ < minSize) Debug_Putchar(pad); - break; - - // Single Character / Array - case 'c': - if(minSize == 1) { - Debug_Putchar(arg); - break; - } - p = (char*)(Uint)arg; - if(!p) goto printString; - while(minSize--) Debug_Putchar(*p++); - break; - - default: - Debug_Putchar(arg); - break; - } - } - #endif } void Debug_KernelPanic() @@ -306,6 +168,20 @@ void LogF(char *Fmt, ...) va_end(args); } +/** + * \fn void Debug(char *Msg, ...) + * \brief Print only to the debug channel + */ +void Debug(char *Fmt, ...) +{ + va_list args; + + Debug_Puts(0, "Debug: "); + va_start(args, Fmt); + Debug_DbgOnlyFmt(Fmt, args); + va_end(args); + Debug_PutCharDebug('\n'); +} /** * \fn void Log(char *Msg, ...) */ @@ -313,7 +189,7 @@ void Log(char *Fmt, ...) { va_list args; - Debug_Puts("Log: "); + Debug_Puts(1, "Log: "); va_start(args, Fmt); Debug_Fmt(Fmt, args); va_end(args); @@ -322,7 +198,7 @@ void Log(char *Fmt, ...) void Warning(char *Fmt, ...) { va_list args; - Debug_Puts("Warning: "); + Debug_Puts(1, "Warning: "); va_start(args, Fmt); Debug_Fmt(Fmt, args); va_end(args); @@ -334,7 +210,7 @@ void Panic(char *Fmt, ...) Debug_KernelPanic(); - Debug_Puts("Panic: "); + Debug_Puts(1, "Panic: "); va_start(args, Fmt); Debug_Fmt(Fmt, args); va_end(args); @@ -371,14 +247,14 @@ void Debug_Enter(char *FuncName, char *ArgTypes, ...) while(i--) Debug_Putchar(' '); - Debug_Puts(FuncName); Debug_Puts(": ("); + Debug_Puts(1, FuncName); Debug_Puts(1, ": ("); while(*ArgTypes) { pos = strpos(ArgTypes, ' '); if(pos != -1) ArgTypes[pos] = '\0'; if(pos == -1 || pos > 1) { - Debug_Puts(ArgTypes+1); + Debug_Puts(1, ArgTypes+1); Debug_Putchar('='); } if(pos != -1) ArgTypes[pos] = ' '; @@ -414,7 +290,7 @@ void Debug_Log(char *FuncName, char *Fmt, ...) while(i--) Debug_Putchar(' '); - Debug_Puts(FuncName); Debug_Puts(": "); + Debug_Puts(1, FuncName); Debug_Puts(1, ": "); Debug_Fmt(Fmt, args); va_end(args); @@ -435,7 +311,7 @@ void Debug_Leave(char *FuncName, char RetType, ...) // Indenting while(i--) Debug_Putchar(' '); - Debug_Puts(FuncName); Debug_Puts(": RETURN"); + Debug_Puts(1, FuncName); Debug_Puts(1, ": RETURN"); // No Return if(RetType == '-') { @@ -446,7 +322,7 @@ void Debug_Leave(char *FuncName, char RetType, ...) Debug_Putchar(' '); switch(RetType) { - case 'n': Debug_Puts("NULL"); break; + case 'n': Debug_Puts(1, "NULL"); break; case 'p': Debug_Fmt("%p", args); break; case 's': Debug_Fmt("'%s'", args); break; case 'i': Debug_Fmt("%i", args); break; @@ -464,7 +340,7 @@ void Debug_HexDump(char *Header, void *Data, Uint Length) { Uint8 *cdat = Data; Uint pos = 0; - Debug_Puts(Header); + Debug_Puts(1, Header); LogF(" (Hexdump of %p)\n", Data); while(Length >= 16) @@ -496,6 +372,7 @@ void Debug_HexDump(char *Header, void *Data, Uint Length) } // --- EXPORTS --- +EXPORT(Debug); EXPORT(Log); EXPORT(Warning); EXPORT(Debug_Enter); diff --git a/Kernel/drv/dma.c b/Kernel/drv/dma.c index 1f356cd4..56ab7e54 100644 --- a/Kernel/drv/dma.c +++ b/Kernel/drv/dma.c @@ -20,7 +20,7 @@ typedef struct } t_dmaChannel; // === PROTOTYPES === - int DMA_Install(); + int DMA_Install(char **Arguments); void DMA_SetChannel(int Channel, int length, int read); int DMA_ReadData(int channel, int count, void *buffer); @@ -39,10 +39,10 @@ t_dmaChannel dma_channels[8]; // === CODE === /** - * \fn int DMA_Install() + * \fn int DMA_Install(void) * \brief Initialise DMA channels */ -int DMA_Install() +int DMA_Install(char **Arguments) { Uint i; for(i=8;i--;) diff --git a/Kernel/drv/kb.c b/Kernel/drv/kb.c index 5e078406..edeb6859 100644 --- a/Kernel/drv/kb.c +++ b/Kernel/drv/kb.c @@ -14,14 +14,14 @@ #define USE_KERNEL_MAGIC 1 // === IMPORTS === -void Threads_Dump(); +void Threads_Dump(void); // === PROTOTYPES === int KB_Install(char **Arguments); -void KB_IRQHandler(); +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 KB_UpdateLEDs(void); int KB_IOCtl(tVFS_Node *Node, int Id, void *Data); // === GLOBALS === @@ -76,7 +76,7 @@ int KB_Install(char **Arguments) * \fn void KB_IRQHandler() * \brief Called on a keyboard IRQ */ -void KB_IRQHandler() +void KB_IRQHandler(int IRQNum) { Uint8 scancode; Uint32 ch; @@ -229,10 +229,10 @@ void KB_IRQHandler() } /** - * \fn void KB_UpdateLEDs() + * \fn void KB_UpdateLEDs(void) * \brief Updates the status of the keyboard LEDs */ -void KB_UpdateLEDs() +void KB_UpdateLEDs(void) { Uint8 leds; diff --git a/Kernel/drv/pci.c b/Kernel/drv/pci.c index e205d4f4..20eb9326 100644 --- a/Kernel/drv/pci.c +++ b/Kernel/drv/pci.c @@ -88,6 +88,10 @@ int PCI_Install(char **Arguments) // Build Portmap gaPCI_PortBitmap = malloc( 1 << 13 ); + if( !gaPCI_PortBitmap ) { + Log_Error("PCI", "Unable to allocate %i bytes for bitmap", 1 << 13); + return MODULE_ERR_MALLOC; + } memset( gaPCI_PortBitmap, 0, 1 << 13 ); for( i = 0; i < MAX_RESERVED_PORT / 32; i ++ ) gaPCI_PortBitmap[i] = -1; @@ -110,7 +114,7 @@ int PCI_Install(char **Arguments) space += SPACE_STEP; tmpPtr = realloc(gPCI_Devices, space*sizeof(tPCIDevice)); if(tmpPtr == NULL) - break; + return MODULE_ERR_MALLOC; gPCI_Devices = tmpPtr; } if(devInfo.oc == PCI_OC_PCIBRIDGE) @@ -141,15 +145,13 @@ int PCI_Install(char **Arguments) break; } } - if(tmpPtr != gPCI_Devices) - break; } - if(tmpPtr != gPCI_Devices) - break; } - if(giPCI_DeviceCount == 0) + if(giPCI_DeviceCount == 0) { + Log_Notice("PCI", "No devices were found"); return MODULE_ERR_NOTNEEDED; + } tmpPtr = realloc(gPCI_Devices, giPCI_DeviceCount*sizeof(tPCIDevice)); if(tmpPtr == NULL) diff --git a/Kernel/drv/vga.c b/Kernel/drv/vga.c index 700eae9e..ff83e539 100644 --- a/Kernel/drv/vga.c +++ b/Kernel/drv/vga.c @@ -99,6 +99,10 @@ int VGA_IOCtl(tVFS_Node *Node, int Id, void *Data) ((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; diff --git a/Kernel/drv/vterm.c b/Kernel/drv/vterm.c index d0106253..b19b3198 100644 --- a/Kernel/drv/vterm.c +++ b/Kernel/drv/vterm.c @@ -913,19 +913,23 @@ void VT_int_PutString(tVTerm *Term, Uint8 *Buffer, Uint Count) { Uint32 val; int i; + + // Iterate for( i = 0; i < Count; i++ ) { - if( Buffer[i] == 0x1B ) // Escape Sequence + // Handle escape sequences + if( Buffer[i] == 0x1B ) { i ++; i += VT_int_ParseEscape(Term, (char*)&Buffer[i]) - 1; continue; } + // Fast check for non UTF-8 if( Buffer[i] < 128 ) // Plain ASCII VT_int_PutChar(Term, Buffer[i]); else { // UTF-8 - i += ReadUTF8(&Buffer[i], &val); + i += ReadUTF8(&Buffer[i], &val) - 1; VT_int_PutChar(Term, val); } } @@ -949,9 +953,7 @@ void VT_int_PutString(tVTerm *Term, Uint8 *Buffer, Uint Count) void VT_int_PutChar(tVTerm *Term, Uint32 Ch) { int i; - //ENTER("pTerm xCh", Term, Ch); - //LOG("Term = {WritePos:%i, ViewPos:%i}", Term->WritePos, Term->ViewPos); - + switch(Ch) { case '\0': return; // Ignore NULL byte @@ -1000,21 +1002,27 @@ void VT_int_PutChar(tVTerm *Term, Uint32 Ch) } // Move Screen + // - Check if we need to scroll the entire scrollback buffer if(Term->WritePos >= Term->Width*Term->Height*(giVT_Scrollback+1)) { int base, i; + + //Debug("Scrolling entire buffer"); + + // Move back by one Term->WritePos -= Term->Width; + // Update the scren VT_int_UpdateScreen( Term, 0 ); // Update view position - base = Term->Width*Term->Height*(giVT_Scrollback-1); - if(Term->ViewPos < base) Term->ViewPos += Term->Width; - if(Term->ViewPos > base) Term->ViewPos = base; + base = Term->Width*Term->Height*(giVT_Scrollback); + if(Term->ViewPos < base) + Term->ViewPos += Term->Width; + if(Term->ViewPos > base) + Term->ViewPos = base; // Scroll terminal cache base = Term->Width*(Term->Height*(giVT_Scrollback+1)-1); - - // Scroll Back memcpy( Term->Text, &Term->Text[Term->Width], @@ -1028,18 +1036,26 @@ void VT_int_PutChar(tVTerm *Term, Uint32 Ch) Term->Text[ base + i ].Colour = Term->CurColour; } - //LOG("Scrolled buffer"); VT_int_ScrollFramebuffer( Term ); VT_int_UpdateScreen( Term, 0 ); } + // Ok, so we only need to scroll the screen else if(Term->WritePos >= Term->ViewPos + Term->Width*Term->Height) { - //LOG("Scrolled screen"); + //Debug("Term->WritePos (%i) >= %i", + // Term->WritePos, + // Term->ViewPos + Term->Width*Term->Height + // ); + //Debug("Scrolling screen only"); + + // Update the last line Term->WritePos -= Term->Width; VT_int_UpdateScreen( Term, 0 ); Term->WritePos += Term->Width; + // Scroll Term->ViewPos += Term->Width; + //Debug("Term->ViewPos = %i", Term->ViewPos); VT_int_ScrollFramebuffer( Term ); VT_int_UpdateScreen( Term, 0 ); } @@ -1060,23 +1076,23 @@ void VT_int_ScrollFramebuffer( tVTerm *Term ) Uint16 SrcX, SrcY; Uint16 W, H; } PACKED buf; + // Only update if this is the current terminal if( Term != gpVT_CurTerm ) return; - // This should only be called in text mode - + // Switch to 2D Command Stream tmp = VIDEO_BUFFMT_2DSTREAM; VFS_IOCtl(giVT_OutputDevHandle, VIDEO_IOCTL_SETBUFFORMAT, &tmp); + // BLIT from 0,0 to 0,giVT_CharHeight buf.Op = VIDEO_2DOP_BLIT; buf.DstX = 0; buf.DstY = 0; buf.SrcX = 0; buf.SrcY = giVT_CharHeight; buf.W = Term->Width * giVT_CharWidth; buf.H = (Term->Height-1) * giVT_CharHeight; + VFS_WriteAt(giVT_OutputDevHandle, 0, sizeof(buf), &buf); - VFS_WriteAt(giVT_OutputDevHandle, 0, 1+12, &buf); - - // Restore old mode + // Restore old mode (this function is only called during text mode) tmp = VIDEO_BUFFMT_TEXT; VFS_IOCtl(giVT_OutputDevHandle, VIDEO_IOCTL_SETBUFFORMAT, &tmp); } @@ -1093,21 +1109,18 @@ void VT_int_UpdateScreen( tVTerm *Term, int UpdateAll ) switch( Term->Mode ) { case TERM_MODE_TEXT: + // Re copy the entire screen? if(UpdateAll) { - //LOG("UpdateAll = 1"); - //LOG("VFS_WriteAt(0x%x, 0, %i*sizeof(tVT_Char), &Term->Text[%i])", - // giVT_OutputDevHandle, Term->Width*Term->Height, Term->ViewPos); VFS_WriteAt( giVT_OutputDevHandle, 0, Term->Width*Term->Height*sizeof(tVT_Char), &Term->Text[Term->ViewPos] ); - } else { + } + // Only copy the current line + else { int pos = Term->WritePos - Term->WritePos % Term->Width; - //LOG("UpdateAll = 0"); - //LOG("VFS_WriteAt(0x%x, %i*sizeof(tVT_Char), %i*sizeof(tVT_Char), &Term->Text[%i])", - // giVT_OutputDevHandle, (pos - Term->ViewPos), Term->Width, pos); VFS_WriteAt( giVT_OutputDevHandle, (pos - Term->ViewPos)*sizeof(tVT_Char), diff --git a/Kernel/drvutil.c b/Kernel/drvutil.c index 99d02f62..85d4434d 100644 --- a/Kernel/drvutil.c +++ b/Kernel/drvutil.c @@ -64,6 +64,12 @@ Uint64 DrvUtil_Video_2DStream(void *Ent, void *Buffer, int Length, return Length-rem; } + //Log("Handlers->Blit{%}}(%p, %i,%i, %i,%i, %i,%i)", + // Handlers->Blit, Ent, + // *(Uint16*)(&stream[0]), *(Uint16*)(&stream[2]), + // *(Uint16*)(&stream[4]), *(Uint16*)(&stream[6]), + // *(Uint16*)(&stream[8]), *(Uint16*)(&stream[10]) + // ); Handlers->Blit( Ent, *(Uint16*)(&stream[0]), *(Uint16*)(&stream[2]), diff --git a/Kernel/heap.c b/Kernel/heap.c index 920e9b68..a612d8a2 100644 --- a/Kernel/heap.c +++ b/Kernel/heap.c @@ -20,12 +20,12 @@ #define MAGIC_USED 0x862B0505 // MAGIC_FOOT ^ MAGIC_FREE // === PROTOTYPES === -void Heap_Install(); +void Heap_Install(void); void *Heap_Extend(int Bytes); void *Heap_Merge(tHeapHead *Head); void *malloc(size_t Bytes); void free(void *Ptr); -void Heap_Dump(); +void Heap_Dump(void); // === GLOBALS === tSpinlock glHeap; @@ -33,7 +33,7 @@ void *gHeapStart; void *gHeapEnd; // === CODE === -void Heap_Install() +void Heap_Install(void) { gHeapStart = (void*)MM_KHEAP_BASE; gHeapEnd = (void*)MM_KHEAP_BASE; @@ -425,7 +425,7 @@ int IsHeap(void *Ptr) } #if WARNINGS -void Heap_Dump() +void Heap_Dump(void) { tHeapHead *head; tHeapFoot *foot; diff --git a/Kernel/include/acess.h b/Kernel/include/acess.h index 394f9f1e..83a44ce5 100644 --- a/Kernel/include/acess.h +++ b/Kernel/include/acess.h @@ -112,11 +112,12 @@ extern void Log_Debug(char *Ident, char *Message, ...); * \name Debugging and Errors * \{ */ -extern void Debug_KernelPanic(); //!< Initiate a kernel panic +extern void Debug_KernelPanic(void); //!< Initiate a kernel panic extern void Panic(char *Msg, ...); //!< Print a panic message (initiates a kernel panic) extern void Warning(char *Msg, ...); //!< Print a warning message extern void LogF(char *Fmt, ...); //!< Print a log message without a trailing newline extern void Log(char *Fmt, ...); //!< Print a log message +extern void Debug(char *Fmt, ...); //!< Print a debug message (doesn't go to KTerm) extern void LogV(char *Fmt, va_list Args); //!< va_list Log message extern void Debug_Enter(char *FuncName, char *ArgTypes, ...); extern void Debug_Log(char *FuncName, char *Fmt, ...); @@ -247,7 +248,7 @@ extern void MM_UnmapHWPages(tVAddr VAddr, Uint Number); * \brief Allocate a single physical page * \return Physical address allocated */ -extern tPAddr MM_AllocPhys(); +extern tPAddr MM_AllocPhys(void); /** * \brief Allocate a contiguous range of physical pages * \param Pages Number of pages to allocate @@ -332,7 +333,7 @@ extern Uint8 ByteSum(void *Ptr, int Size); * \} */ -extern Uint rand(); +extern Uint rand(void); extern int CallWithArgArray(void *Function, int NArgs, Uint *Args); // --- Heap --- @@ -369,7 +370,7 @@ extern int Module_LoadFile(char *Path, char *ArgStr); * \brief Create a timestamp from a time */ extern Sint64 timestamp(int sec, int mins, int hrs, int day, int month, int year); -extern Sint64 now(); +extern Sint64 now(void); extern int Time_CreateTimer(int Delta, void *Callback, void *Argument); extern void Time_RemoveTimer(int ID); extern void Time_Delay(int Delay); @@ -382,16 +383,16 @@ extern void Time_Delay(int Delay); * \name Threads and Processes * \{ */ -extern int Proc_SpawnWorker(); +extern int Proc_SpawnWorker(void); extern int Proc_Spawn(char *Path); -extern void Threads_Exit(); -extern void Threads_Yield(); -extern void Threads_Sleep(); +extern void Threads_Exit(int TID, int Status); +extern void Threads_Yield(void); +extern void Threads_Sleep(void); extern void Threads_WakeTID(tTID Thread); -extern tPID Threads_GetPID(); -extern tTID Threads_GetTID(); -extern tUID Threads_GetUID(); -extern tGID Threads_GetGID(); +extern tPID Threads_GetPID(void); +extern tTID Threads_GetTID(void); +extern tUID Threads_GetUID(void); +extern tGID Threads_GetGID(void); extern int SpawnTask(tThreadFunction Function, void *Arg); extern Uint *Threads_GetCfgPtr(int Id); extern int Threads_SetName(char *NewName); diff --git a/Kernel/include/modules.h b/Kernel/include/modules.h index d4fb49c5..fb737bee 100644 --- a/Kernel/include/modules.h +++ b/Kernel/include/modules.h @@ -73,7 +73,7 @@ typedef struct sModule struct sModule *Next; //!< Next module in list (not to be touched by the driver) char *Name; //!< Module Name/Identifier int (*Init)(char **Arguments); //!< Module initialiser / entrypoint - void (*Deinit)(); //!< Cleanup Function + void (*Deinit)(void); //!< Cleanup Function char **Dependencies; //!< NULL terminated list of dependencies } PACKED tModule; diff --git a/Kernel/include/threads.h b/Kernel/include/threads.h index f23c5b56..e9cab730 100644 --- a/Kernel/include/threads.h +++ b/Kernel/include/threads.h @@ -81,7 +81,7 @@ enum eFaultNumbers #define GETMSG_IGNORE ((void*)-1) // === FUNCTIONS === -extern tThread *Proc_GetCurThread(); +extern tThread *Proc_GetCurThread(void); extern tThread *Threads_GetThread(Uint TID); extern void Threads_Wake(tThread *Thread); extern void Threads_AddActive(tThread *Thread); diff --git a/Kernel/include/vfs.h b/Kernel/include/vfs.h index 057f7f4c..f6659430 100644 --- a/Kernel/include/vfs.h +++ b/Kernel/include/vfs.h @@ -326,11 +326,11 @@ extern tVFS_ACL *VFS_UnixToAcessACL(Uint Mode, Uint Owner, Uint Group); * \{ */ /** - * \fn int Inode_GetHandle() + * \fn int Inode_GetHandle(void) * \brief Gets a unique handle to the Node Cache * \return A unique handle for use for the rest of the Inode_* functions */ -extern int Inode_GetHandle(); +extern int Inode_GetHandle(void); /** * \fn tVFS_Node *Inode_GetCache(int Handle, Uint64 Inode) * \brief Gets an inode from the node cache diff --git a/Kernel/include/vfs_ext.h b/Kernel/include/vfs_ext.h index c9d51100..cfd69497 100644 --- a/Kernel/include/vfs_ext.h +++ b/Kernel/include/vfs_ext.h @@ -109,7 +109,7 @@ typedef struct sFInfo * \brief Initialise the VFS (called by system.c) * \return Boolean Success */ -extern int VFS_Init(); +extern int VFS_Init(void); /** * \brief Open a file diff --git a/Kernel/syscalls.c b/Kernel/syscalls.c index 9e7d35f8..e6e828e3 100644 --- a/Kernel/syscalls.c +++ b/Kernel/syscalls.c @@ -26,11 +26,7 @@ extern int Proc_GetMessage(Uint *Err, Uint *Source, void *Buffer); extern int Proc_Execve(char *File, char **ArgV, char **EnvP); extern Uint Binary_Load(char *file, Uint *entryPoint); extern int Threads_SetName(char *NewName); -extern int Threads_GetPID(); -extern int Threads_GetTID(); -extern tUID Threads_GetUID(); extern int Threads_SetUID(Uint *errno, tUID ID); -extern tGID Threads_GetGID(); extern int Threads_SetGID(Uint *errno, tGID ID); extern int Threads_SetFaultHandler(Uint Handler); diff --git a/Kernel/system.c b/Kernel/system.c index 7c5ff32f..9ff5fd9f 100644 --- a/Kernel/system.c +++ b/Kernel/system.c @@ -32,8 +32,8 @@ typedef struct } tConfigCommand; // === IMPORTS === -extern void Arch_LoadBootModules(); -extern int Modules_LoadBuiltins(); +extern void Arch_LoadBootModules(void); +extern int Modules_LoadBuiltins(void); extern void Modules_SetBuiltinParams(char *Name, char *ArgString); extern void Debug_SetKTerminal(char *File); diff --git a/Kernel/threads.c b/Kernel/threads.c index 8c51d9a6..a947169d 100644 --- a/Kernel/threads.c +++ b/Kernel/threads.c @@ -18,14 +18,14 @@ const enum eConfigTypes cCONFIG_TYPES[] = { }; // === IMPORTS === -extern void ArchThreads_Init(); -extern void Proc_Start(); -extern tThread *Proc_GetCurThread(); +extern void ArchThreads_Init(void); +extern void Proc_Start(void); +extern tThread *Proc_GetCurThread(void); extern int Proc_Clone(Uint *Err, Uint Flags); extern void Proc_CallFaultHandler(tThread *Thread); // === PROTOTYPES === -void Threads_Init(); +void Threads_Init(void); int Threads_SetName(char *NewName); char *Threads_GetName(int ID); void Threads_SetTickets(int Num); @@ -36,17 +36,17 @@ void Threads_AddToDelete(tThread *Thread); tThread *Threads_int_GetPrev(tThread **List, tThread *Thread); void Threads_Exit(int TID, int Status); void Threads_Kill(tThread *Thread, int Status); -void Threads_Yield(); -void Threads_Sleep(); +void Threads_Yield(void); +void Threads_Sleep(void); void Threads_Wake(tThread *Thread); void Threads_AddActive(tThread *Thread); - int Threads_GetPID(); - int Threads_GetTID(); -tUID Threads_GetUID(); + int Threads_GetPID(void); + int Threads_GetTID(void); +tUID Threads_GetUID(void); int Threads_SetUID(Uint *Errno, tUID ID); -tGID Threads_GetGID(); +tGID Threads_GetGID(void); int Threads_SetGID(Uint *Errno, tUID ID); -void Threads_Dump(); +void Threads_Dump(void); // === GLOBALS === // -- Core Thread -- @@ -85,10 +85,10 @@ tThread *gDeleteThreads = NULL; // Threads to delete // === CODE === /** - * \fn void Threads_Init() + * \fn void Threads_Init(void) * \brief Initialse the thread list */ -void Threads_Init() +void Threads_Init(void) { ArchThreads_Init(); @@ -448,20 +448,20 @@ void Threads_Kill(tThread *Thread, int Status) } /** - * \fn void Threads_Yield() + * \fn void Threads_Yield(void) * \brief Yield remainder of timeslice */ -void Threads_Yield() +void Threads_Yield(void) { Proc_GetCurThread()->Remaining = 0; HALT(); } /** - * \fn void Threads_Sleep() + * \fn void Threads_Sleep(void) * \brief Take the current process off the run queue */ -void Threads_Sleep() +void Threads_Sleep(void) { tThread *cur = Proc_GetCurThread(); tThread *thread; @@ -612,19 +612,19 @@ void Threads_Fault(int Num) } // --- Process Structure Access Functions --- -tPID Threads_GetPID() +tPID Threads_GetPID(void) { return Proc_GetCurThread()->TGID; } -tTID Threads_GetTID() +tTID Threads_GetTID(void) { return Proc_GetCurThread()->TID; } -tUID Threads_GetUID() +tUID Threads_GetUID(void) { return Proc_GetCurThread()->UID; } -tGID Threads_GetGID() +tGID Threads_GetGID(void) { return Proc_GetCurThread()->GID; } @@ -654,10 +654,10 @@ int Threads_SetGID(Uint *Errno, tGID ID) } /** - * \fn void Threads_Dump() + * \fn void Threads_Dump(void) * \brief Dums a list of currently running threads */ -void Threads_Dump() +void Threads_Dump(void) { tThread *thread; tThread *cur = Proc_GetCurThread(); diff --git a/Kernel/time.c b/Kernel/time.c index e8206efa..fcc13afb 100644 --- a/Kernel/time.c +++ b/Kernel/time.c @@ -17,7 +17,8 @@ typedef struct sTimer { } tTimer; // === PROTOTYPES === -void Timer_CallTimers(); +Sint64 now(void); +void Timer_CallTimers(void); // === GLOBALS === Uint64 giTicks = 0; @@ -30,7 +31,7 @@ tTimer gTimers[NUM_TIMERS]; * \fn Sint64 now() * \brief Return the current timestamp */ -Sint64 now() +Sint64 now(void) { return giTimestamp; } diff --git a/Kernel/vfs/fs/root.c b/Kernel/vfs/fs/root.c index 7eed1235..c52313de 100644 --- a/Kernel/vfs/fs/root.c +++ b/Kernel/vfs/fs/root.c @@ -16,7 +16,7 @@ tVFS_Node *Root_FindDir(tVFS_Node *Node, char *Name); char *Root_ReadDir(tVFS_Node *Node, int Pos); Uint64 Root_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer); Uint64 Root_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer); -tRamFS_File *Root_int_AllocFile(); +tRamFS_File *Root_int_AllocFile(void); // === GLOBALS === tVFS_Driver gRootFS_Info = { @@ -210,10 +210,10 @@ Uint64 Root_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) } /** - * \fn tRamFS_File *Root_int_AllocFile() + * \fn tRamFS_File *Root_int_AllocFile(void) * \brief Allocates a file from the pool */ -tRamFS_File *Root_int_AllocFile() +tRamFS_File *Root_int_AllocFile(void) { int i; for( i = 0; i < MAX_FILES; i ++ ) diff --git a/Kernel/vfs/main.c b/Kernel/vfs/main.c index 45e20d91..fa7273d5 100644 --- a/Kernel/vfs/main.c +++ b/Kernel/vfs/main.c @@ -13,12 +13,12 @@ extern tVFS_Driver gRootFS_Info; extern tVFS_Driver gDevFS_Info; // === PROTOTYPES === - int VFS_Init(); + int VFS_Init(void); char *VFS_GetTruePath(char *Path); void VFS_GetMemPath(char *Dest, void *Base, Uint Length); tVFS_Driver *VFS_GetFSByName(char *Name); int VFS_AddDriver(tVFS_Driver *Info); -void VFS_UpdateDriverFile(); +void VFS_UpdateDriverFile(void); // === EXPORTS === EXPORT(VFS_AddDriver); @@ -35,10 +35,10 @@ char *gsVFS_MountFile = NULL; // === CODE === /** - * \fn int VFS_Init() + * \fn int VFS_Init(void) * \brief Initialises the VFS for use by the kernel and user */ -int VFS_Init() +int VFS_Init(void) { // Core Drivers gVFS_Drivers = &gRootFS_Info; @@ -125,10 +125,10 @@ int VFS_AddDriver(tVFS_Driver *Info) } /** - * \fn void VFS_UpdateDriverFile() + * \fn void VFS_UpdateDriverFile(void) * \brief Updates the driver list file */ -void VFS_UpdateDriverFile() +void VFS_UpdateDriverFile(void) { tVFS_Driver *drv; int len = 0; diff --git a/Kernel/vfs/mount.c b/Kernel/vfs/mount.c index 45591a46..0c07bcb8 100644 --- a/Kernel/vfs/mount.c +++ b/Kernel/vfs/mount.c @@ -12,7 +12,7 @@ extern char *gsVFS_MountFile; // === PROTOTYPES === int VFS_Mount(char *Device, char *MountPoint, char *Filesystem, char *Options); -void VFS_UpdateMountFile(); +void VFS_UpdateMountFile(void); // === GLOBALS === int glVFS_MountList = 0; @@ -108,7 +108,7 @@ int VFS_Mount(char *Device, char *MountPoint, char *Filesystem, char *Options) * * Updates the ProcFS mounts file buffer to match the current mounts list. */ -void VFS_UpdateMountFile() +void VFS_UpdateMountFile(void) { int len = 0; char *buf; diff --git a/Makefile.i386.cfg b/Makefile.i386.cfg index 8f8b9ca5..beb3cd73 100644 --- a/Makefile.i386.cfg +++ b/Makefile.i386.cfg @@ -12,3 +12,5 @@ MKDIR = mkdir ARCHDIR = x86 +DYNMOD_FLAGS := -mcmodel=small -fPIC + diff --git a/Makefile.x86_64.cfg b/Makefile.x86_64.cfg index a5bfe218..e2b7c31b 100644 --- a/Makefile.x86_64.cfg +++ b/Makefile.x86_64.cfg @@ -3,7 +3,8 @@ CC = x86_64-linux-gnu-gcc LD = ld DISASM = objdump -d -M x86-64 -KERNEL_CFLAGS = -mcmodel=large -nostdlib +KERNEL_CFLAGS := -mcmodel=kernel -nostdlib +DYNMOD_CFLAGS := -mcmodel=small -fPIC ARCHDIR = x86_64 diff --git a/Modules/Display/VESA/main.c b/Modules/Display/VESA/main.c index 0524a35f..c075fccd 100644 --- a/Modules/Display/VESA/main.c +++ b/Modules/Display/VESA/main.c @@ -54,7 +54,7 @@ tDrvUtil_Video_2DHandlers gVesa_2DFunctions = { Vesa_2D_Blit }; -//CODE +// === CODE === int Vesa_Install(char **Arguments) { tVesa_CallInfo *info; @@ -240,7 +240,7 @@ Uint64 Vesa_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) ); // Sanity Check - if(y > heightInChars) { + if(y >= heightInChars) { LEAVE('i', 0); return 0; } @@ -461,42 +461,46 @@ void Vesa_2D_Fill(void *Ent, Uint16 X, Uint16 Y, Uint16 W, Uint16 H, Uint32 Colo void Vesa_2D_Blit(void *Ent, Uint16 DstX, Uint16 DstY, Uint16 SrcX, Uint16 SrcY, Uint16 W, Uint16 H) { - int scrnwidth = gVesa_Modes[giVesaCurrentMode].width; - int dst = DstY*scrnwidth + DstX; - int src = SrcY*scrnwidth + SrcX; + int scrnpitch = gVesa_Modes[giVesaCurrentMode].pitch; + int dst = DstY*scrnpitch + DstX; + int src = SrcY*scrnpitch + SrcX; int tmp; //Log("Vesa_2D_Blit: (Ent=%p, DstX=%i, DstY=%i, SrcX=%i, SrcY=%i, W=%i, H=%i)", // Ent, DstX, DstY, SrcX, SrcY, W, H); - if(SrcX + W > scrnwidth) - W = scrnwidth - SrcX; - if(DstX + W > scrnwidth) - W = scrnwidth - DstX; + if(SrcX + W > gVesa_Modes[giVesaCurrentMode].width) + W = gVesa_Modes[giVesaCurrentMode].width - SrcX; + if(DstX + W > gVesa_Modes[giVesaCurrentMode].width) + W = gVesa_Modes[giVesaCurrentMode].width - DstX; if(SrcY + H > gVesa_Modes[giVesaCurrentMode].height) H = gVesa_Modes[giVesaCurrentMode].height - SrcY; if(DstY + H > gVesa_Modes[giVesaCurrentMode].height) H = gVesa_Modes[giVesaCurrentMode].height - DstY; + //Debug("W = %i, H = %i", W, H); + if( dst > src ) { // Reverse copy - dst += H*scrnwidth; - src += H*scrnwidth; + Debug("Reverse scroll"); + dst += H*scrnpitch; + src += H*scrnpitch; while( H -- ) { - dst -= scrnwidth; - src -= scrnwidth; + dst -= scrnpitch; + src -= scrnpitch; tmp = W; for( tmp = W; tmp --; ) { - *((Uint32*)gpVesa_Framebuffer + dst + tmp) = *((Uint32*)gpVesa_Framebuffer + src + tmp); + *(Uint32*)(gpVesa_Framebuffer + dst + tmp) = *(Uint32*)(gpVesa_Framebuffer + src + tmp); } } } else { // Normal copy is OK + Debug("memcpy scroll"); while( H -- ) { - memcpy((Uint32*)gpVesa_Framebuffer + dst, (Uint32*)gpVesa_Framebuffer + src, W); - dst += scrnwidth; - src += scrnwidth; + memcpy((void*)gpVesa_Framebuffer + dst, (void*)gpVesa_Framebuffer + src, W); + dst += scrnpitch; + src += scrnpitch; } } } diff --git a/Modules/IPStack/Makefile b/Modules/IPStack/Makefile index 08cbe609..a8380f48 100644 --- a/Modules/IPStack/Makefile +++ b/Modules/IPStack/Makefile @@ -5,6 +5,7 @@ OBJ := main.o link.o arp.o OBJ += ipv4.o icmp.o OBJ += ipv6.o OBJ += udp.o tcp.o -NAME = IPStack +NAME := IPStack +CATEGORY := -include ../Makefile.tpl diff --git a/Modules/Makefile.tpl b/Modules/Makefile.tpl index 73efa631..60824e84 100644 --- a/Modules/Makefile.tpl +++ b/Modules/Makefile.tpl @@ -12,7 +12,7 @@ CFGFILES += $(shell test -f Makefile.cfg && echo Makefile.cfg) -include $(CFGFILES) CPPFLAGS := -I$(ACESSDIR)/Kernel/include -I$(ACESSDIR)/Kernel/arch/$(ARCHDIR)/include -DARCH=$(ARCH) $(_CPPFLAGS) -CFLAGS := $(KERNEL_CFLAGS) -Wall -Werror -fno-stack-protector $(CPPFLAGS) -O3 -fno-builtin +CFLAGS := -Wall -Werror -fno-stack-protector $(CPPFLAGS) -O3 -fno-builtin ifeq ($(BUILDTYPE),dynamic) _SUFFIX := dyn_$(ARCH) @@ -21,9 +21,10 @@ ifeq ($(BUILDTYPE),dynamic) else BIN := ../$(NAME).kmd.$(ARCH) endif - CFLAGS += -fPIC + CFLAGS += $(DYNMOD_CFLAGS) -fPIC else _SUFFIX := st_$(ARCH) + CFLAGS += $(KERNEL_CFLAGS) BIN := ../$(NAME).xo.$(ARCH) endif