From: John Hodge Date: Sat, 24 Jul 2010 03:59:59 +0000 (+0800) Subject: Fixing bugs and removing debug statements X-Git-Tag: rel0.06~89 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=3998cfbbadb005bf3ad52ea2538dc21f82864ddc;p=tpg%2Facess2.git Fixing bugs and removing debug statements - Killing debug in timer code - Changed the syscall method back to using int 0xAC (for now) - Working on RTL8139 driver - More UDI fiddling (I'm going to move to the UDIref implementation soon, just triying to make it compile properly) --- diff --git a/Kernel/arch/x86/desctab.asm b/Kernel/arch/x86/desctab.asm index 615d6a27..4223e6f1 100644 --- a/Kernel/arch/x86/desctab.asm +++ b/Kernel/arch/x86/desctab.asm @@ -31,7 +31,8 @@ gGDTPtr: ALIGN 8 [global gIDT] gIDT: - times 256 dd 0x00080000,0x00000F00 + ; CS = 0x08, Type = 32-bit Interrupt (0xE = 1 110) + times 256 dd 0x00080000,0x00000E00 [global gIDTPtr] gIDTPtr: dw 256 * 16 - 1 ; Limit @@ -52,7 +53,7 @@ Desctab_Install: jmp 0x08:.pl0code .pl0code: - ; Set IDT + ; Set up IDT %macro SETISR 1 mov eax, Isr%1 mov WORD [gIDT + %1*8], ax @@ -63,11 +64,13 @@ Desctab_Install: or ax, 0x8000 mov WORD [gIDT + %1*8 + 4], ax %endmacro -%macro SETUSER 1 - mov ax, WORD [gIDT + %1*8 + 4] - or ax, 0x6000 - mov WORD [gIDT + %1*8 + 4], ax +%macro SET_USER 1 + or WORD [gIDT + %1*8 + 4], 0x6000 +%endmacro +%macro SET_TRAP 1 + or WORD [gIDT + %1*8 + 4], 0x0100 %endmacro + %assign i 0 %rep 32 SETISR i @@ -75,13 +78,15 @@ Desctab_Install: %endrep SETISR 0xAC - SETUSER 0xAC + SET_USER 0xAC + SET_TRAP 0xAC ; Interruptable %if USE_MP SETISR 0xEE ; 0xEE Timer SETISR 0xEF ; 0xEF Spurious Interrupt %endif - + + ; IRQs %assign i 0xF0 %rep 16 SETISR i diff --git a/Kernel/arch/x86/main.c b/Kernel/arch/x86/main.c index 0557760e..f9e70e5c 100644 --- a/Kernel/arch/x86/main.c +++ b/Kernel/arch/x86/main.c @@ -81,13 +81,13 @@ int kmain(Uint MbMagic, void *MbInfoPtr) MM_InstallVirtual(); // Clean up virtual address space Heap_Install(); // Create initial heap - // Start Timers - Time_Setup(); - //Log_Log("Arch", "Starting Multitasking..."); // Start Multitasking Threads_Init(); + // Start Timers + Time_Setup(); + Log_Log("Arch", "Starting VFS..."); // Load Virtual Filesystem VFS_Init(); diff --git a/Kernel/arch/x86/proc.asm b/Kernel/arch/x86/proc.asm index fd863a42..20a4fd78 100644 --- a/Kernel/arch/x86/proc.asm +++ b/Kernel/arch/x86/proc.asm @@ -239,6 +239,7 @@ GetCPUNum: ; Export a place for the user to jump to to call a syscall ; - Allows the kernel to change the method easily User_Syscall: + xchg bx, bx int 0xAC ; A place to return to and exit diff --git a/Kernel/arch/x86/proc.c b/Kernel/arch/x86/proc.c index 1edfee23..9c1eb987 100644 --- a/Kernel/arch/x86/proc.c +++ b/Kernel/arch/x86/proc.c @@ -570,6 +570,7 @@ int Proc_Clone(Uint *Err, Uint Flags) eip = GetEIP(); if(eip == SWITCH_MAGIC) { outb(0x20, 0x20); // ACK Timer and return as child + __asm__ __volatile__ ("sti"); // Restart interrupts return 0; } diff --git a/Kernel/arch/x86/time.c b/Kernel/arch/x86/time.c index 49436988..c38a9cd4 100644 --- a/Kernel/arch/x86/time.c +++ b/Kernel/arch/x86/time.c @@ -8,7 +8,9 @@ // === MACROS === #define TIMER_QUANTUM 100 // 2^(15-rate), 15: 1HZ, 5: 1024Hz, 2: 8192Hz -#define TIMER_RATE 12 // (Max: 15, Min: 2) - 15 = 1Hz, 13 = 4Hz, 12 = 8Hz, 11 = 16Hz 10 = 32Hz, 2 +// (Max: 15, Min: 2) - 15 = 1Hz, 13 = 4Hz, 12 = 8Hz, 11 = 16Hz 10 = 32Hz, 2 = 8192Hz +#define TIMER_RATE 12 +//#define TIMER_RATE 15 #define TIMER_FREQ (0x8000>>TIMER_RATE) //Hz #define MS_PER_TICK_WHOLE (1000/(TIMER_FREQ)) #define MS_PER_TICK_FRACT ((0x80000000*(1000%TIMER_FREQ))/TIMER_FREQ) @@ -51,8 +53,8 @@ int Time_Setup(void) outb(0x70, 0x0B); // Set the index again (a read will reset the index to register D) outb(0x71, val | 0x40); // Write the previous value or'd with 0x40. This turns on bit 6 of register D - __asm__ __volatile__ ("sti"); // Disable normal interrupts - outb(0x70, inb(0x70)|0x80); // Disable NMIs + __asm__ __volatile__ ("sti"); // Re-enable normal interrupts + outb(0x70, inb(0x70)|0x80); // Re-enable NMIs // Install IRQ Handler IRQ_AddHandler(8, Time_Interrupt); @@ -70,6 +72,8 @@ int Time_Setup(void) */ void Time_Interrupt(int irq) { + //Log("RTC Tick"); + giTicks ++; giTimestamp += MS_PER_TICK_WHOLE; giPartMiliseconds += MS_PER_TICK_FRACT; diff --git a/Kernel/threads.c b/Kernel/threads.c index ba0f430d..23feb5db 100644 --- a/Kernel/threads.c +++ b/Kernel/threads.c @@ -105,10 +105,7 @@ void Threads_Init(void) cur->ThreadName = "Idle Thread"; Threads_SetTickets(0); // Never called randomly cur->Quantum = 1; // 1 slice quantum - HALT(); - for(;;) { - HALT(); // Just yeilds - } + for(;;) HALT(); // Just yeilds } #endif diff --git a/Modules/Display/VESA/main.c b/Modules/Display/VESA/main.c index e30d6406..9b3de8d1 100644 --- a/Modules/Display/VESA/main.c +++ b/Modules/Display/VESA/main.c @@ -16,7 +16,10 @@ // === CONSTANTS === #define FLAG_LFB 0x1 #define VESA_DEFAULT_FRAMEBUFFER (KERNEL_BASE|0xA0000) -#define VESA_CURSOR_PERIOD 1000 +#define BLINKING_CURSOR 0 +#if BLINKING_CURSOR +# define VESA_CURSOR_PERIOD 1000 +#endif // === PROTOTYPES === int Vesa_Install(char **Arguments); @@ -358,6 +361,10 @@ int Vesa_Ioctl(tVFS_Node *Node, int ID, void *Data) return ret; case VIDEO_IOCTL_SETCURSOR: // Set cursor position + #if !BLINKING_CURSOR + if(giVesaCursorX > 0 && giVesaCursorY) + Vesa_FlipCursor(Node); + #endif giVesaCursorX = ((tVideo_IOCtl_Pos*)Data)->x; giVesaCursorY = ((tVideo_IOCtl_Pos*)Data)->y; //Log_Debug("VESA", "Cursor position (%i,%i)", giVesaCursorX, giVesaCursorY); @@ -366,17 +373,23 @@ int Vesa_Ioctl(tVFS_Node *Node, int ID, void *Data) || giVesaCursorX >= gpVesaCurMode->width/giVT_CharWidth || giVesaCursorY >= gpVesaCurMode->height/giVT_CharHeight) { + #if BLINKING_CURSOR if(giVesaCursorTimer != -1) { Time_RemoveTimer(giVesaCursorTimer); giVesaCursorTimer = -1; } + #endif giVesaCursorX = -1; giVesaCursorY = -1; } else { + #if BLINKING_CURSOR // Log_Debug("VESA", "Updating timer %i?", giVesaCursorTimer); if(giVesaCursorTimer == -1) giVesaCursorTimer = Time_CreateTimer(VESA_CURSOR_PERIOD, Vesa_FlipCursor, Node); + #else + Vesa_FlipCursor(Node); + #endif } //Log_Debug("VESA", "Cursor position (%i,%i) Timer %i", giVesaCursorX, giVesaCursorY, giVesaCursorTimer); return 0; @@ -511,7 +524,9 @@ void Vesa_FlipCursor(void *Arg) for( i = 1; i < giVT_CharHeight-1; i++, fb += pitch ) *fb = ~*fb; + #if BLINKING_CURSOR giVesaCursorTimer = Time_CreateTimer(VESA_CURSOR_PERIOD, Vesa_FlipCursor, Arg); + #endif } // ------------------------ diff --git a/Modules/Interfaces/UDI/main.c b/Modules/Interfaces/UDI/main.c index eff960cf..a4a1504a 100644 --- a/Modules/Interfaces/UDI/main.c +++ b/Modules/Interfaces/UDI/main.c @@ -63,9 +63,39 @@ int UDI_LoadDriver(void *Base) Log_Warning("UDI", "_udiprops is not defined, this is usually bad"); } else { - if( Binary_FindSymbol(Base, "_udiprops_size", (Uint*)&udiprops_size) == 0) - Log_Warning("UDI", "_udiprops_size is not defined"); - Log_Log("UDI", "udiprops = %p, udiprops_size = 0x%x", udiprops, udiprops_size); + Uint udiprops_end = 0; + int i, j, nLines; + char **udipropsptrs; + + if( Binary_FindSymbol(Base, "_udiprops_end", (Uint*)&udiprops_end) == 0) + Log_Warning("UDI", "_udiprops_end is not defined"); + Log_Debug("UDI", "udiprops_end = %p", udiprops_end); + udiprops_size = udiprops_end - (Uint)udiprops; + Log_Debug("UDI", "udiprops = %p, udiprops_size = 0x%x", udiprops, udiprops_size); + + Debug_HexDump("UDI_LoadDriver", udiprops, udiprops_size); + + nLines = 1; + for( i = 0; i < udiprops_size; i++ ) + { + if( udiprops[i] == '\0' ) + nLines ++; + } + + Log_Debug("UDI", "nLines = %i", nLines); + + udipropsptrs = malloc( sizeof(char*)*nLines ); + udipropsptrs[0] = udiprops; + j = 0; + for( i = 0; i < udiprops_size; i++ ) + { + if( udiprops[i] == '\0' ) { + //Log_Debug("UDI", "udipropsptrs[%i] = '%s'", j, udipropsptrs[j]); + udipropsptrs[j++] = &udiprops[i+1]; + } + } + Log_Debug("UDI", "udipropsptrs[%i] = '%s'", j, udipropsptrs[j]); + Log_Debug("UDI", "udiprops = \"%s\"", udiprops); } diff --git a/Modules/Network/RTL8139/main.c b/Modules/Network/RTL8139/main.c index b458cdae..0031925f 100644 --- a/Modules/Network/RTL8139/main.c +++ b/Modules/Network/RTL8139/main.c @@ -21,7 +21,9 @@ enum eRTL8139_Regs MAR1, MAR2, MAR3, MAR4, MAR5, MAR6, MAR7, - RBSTART = 0x30, //!< Recieve Buffer Start + RBSTART = 0x30, //!< Recieve Buffer Start (DWord) + // 0x31, 0x32, 0x33 + // ??, ??, ??, RST, RE, TE, ??, ?? CMD = 0x37, IMR = 0x3C, @@ -149,16 +151,26 @@ int RTL8139_Install(char **Options) // --- Root Functions --- char *RTL8139_ReadDir(tVFS_Node *Node, int Pos) { - return NULL; + if( Pos < 0 || Pos > giRTL8139_CardCount ) return NULL; + + return strdup( gpRTL8139_Cards[Pos].Name ); } tVFS_Node *RTL8139_FindDir(tVFS_Node *Node, const char *Filename) { - return NULL; + //TODO: It might be an idea to supprt >10 cards + if(Filename[0] == '\0' || Filename[0] != '\0') return NULL; + if(Filename[0] < '0' || Filename[0] > '9') return NULL; + return &gpRTL8139_Cards[ Filename[0]-'0' ].Node; } +const char *csaRTL8139_RootIOCtls[] = {DRV_IOCTLNAMES, NULL}; int RTL8139_RootIOCtl(tVFS_Node *Node, int ID, void *Arg) { + switch(ID) + { + BASE_IOCTLS(DRV_TYPE_NETWORK, "RTL8139", VERSION, csaRTL8139_RootIOCtls); + } return 0; } @@ -173,7 +185,12 @@ Uint64 RTL8139_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer return 0; } +const char *csaRTL8139_NodeIOCtls[] = {DRV_IOCTLNAMES, NULL}; int RTL8139_IOCtl(tVFS_Node *Node, int ID, void *Arg) { + switch(ID) + { + BASE_IOCTLS(DRV_TYPE_NETWORK, "RTL8139", VERSION, csaRTL8139_NodeIOCtls); + } return 0; } diff --git a/Modules/Storage/ATA/main.c b/Modules/Storage/ATA/main.c index be77348a..ad550356 100644 --- a/Modules/Storage/ATA/main.c +++ b/Modules/Storage/ATA/main.c @@ -2,7 +2,7 @@ * Acess2 IDE Harddisk Driver * - main.c */ -#define DEBUG 0 +#define DEBUG 1 #include #include #include @@ -497,6 +497,7 @@ Uint64 ATA_ReadFS(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) { int ret = DrvUtil_ReadBlock(Offset, Length, Buffer, ATA_ReadRaw, SECTOR_SIZE, disk); + Log("ATA_ReadFS: disk=%i, Offset=%lli, Length=%lli", disk, Offset, Length); Debug_HexDump("ATA_ReadFS", Buffer, Length); LEAVE('i', ret); return ret; @@ -679,12 +680,7 @@ int ATA_ReadDMA(Uint8 Disk, Uint64 Address, Uint Count, void *Buffer) ATA_int_BusMasterWriteByte( cont << 3, 9 ); // Read and start // Wait for transfer to complete - val = 0; - while( gaATA_IRQs[cont] == 0 && !(val & 0x4) ) { - val = ATA_int_BusMasterReadByte( (cont << 3) + 2 ); - //LOG("val = 0x%02x", val); - Threads_Yield(); - } + while( gaATA_IRQs[cont] == 0 ) Threads_Yield(); // Complete Transfer ATA_int_BusMasterWriteByte( cont << 3, 8 ); // Read and stop diff --git a/UDI Drivers/UDI/link.ld b/UDI Drivers/UDI/link.ld index 1fcbce0f..64238ea6 100644 --- a/UDI Drivers/UDI/link.ld +++ b/UDI Drivers/UDI/link.ld @@ -1,6 +1,8 @@ ENTRY(start) +OUTPUT_FORMAT(elf32-i386) + SECTIONS { . = 0; @@ -22,7 +24,7 @@ SECTIONS .udiprops : { *(.udiprops) } - _udiprops_size = . - _udiprops; + _udiprops_end = .; . = (. + 0xFFF) & ~ 0xFFF; diff --git a/UDI Drivers/UDI/udisetup b/UDI Drivers/UDI/udisetup index 8329b49b..280af73e 100755 --- a/UDI Drivers/UDI/udisetup +++ b/UDI Drivers/UDI/udisetup @@ -1,2 +1,2 @@ #!/bin/sh -ld -T link.ld -shared -o $1.drv $1 +ld -melf_i386 -T link.ld -shared -o $1.drv $1 diff --git a/Usermode/Libraries/libacess.so_src/syscalls.inc.asm b/Usermode/Libraries/libacess.so_src/syscalls.inc.asm index 8e4e26a3..eea5573a 100644 --- a/Usermode/Libraries/libacess.so_src/syscalls.inc.asm +++ b/Usermode/Libraries/libacess.so_src/syscalls.inc.asm @@ -4,7 +4,8 @@ %include "../../../Kernel/include/syscalls.inc.asm" -SYSCALL_JUMP equ 0xCFFF0000 +;%define SYSCALL_OP jmp 0xCFFF0000 +%define SYSCALL_OP int 0xAC ; System Call - No Arguments %macro SYSCALL0 2 @@ -12,7 +13,7 @@ SYSCALL_JUMP equ 0xCFFF0000 %1: push ebx mov eax, %2 - jmp SYSCALL_JUMP + SYSCALL_OP mov [_errno], ebx pop ebx ret @@ -27,7 +28,7 @@ SYSCALL_JUMP equ 0xCFFF0000 push ebx mov eax, %2 mov ebx, [ebp+8] - jmp SYSCALL_JUMP + SYSCALL_OP mov [_errno], ebx pop ebx pop ebp @@ -44,7 +45,7 @@ SYSCALL_JUMP equ 0xCFFF0000 mov eax, %2 mov ebx, [ebp+8] mov ecx, [ebp+12] - jmp SYSCALL_JUMP + SYSCALL_OP mov [_errno], ebx pop ebx pop ebp @@ -62,7 +63,7 @@ SYSCALL_JUMP equ 0xCFFF0000 mov ebx, [ebp+8] mov ecx, [ebp+12] mov edx, [ebp+16] - jmp SYSCALL_JUMP + SYSCALL_OP mov [_errno], ebx pop ebx pop ebp @@ -82,7 +83,7 @@ SYSCALL_JUMP equ 0xCFFF0000 mov ecx, [ebp+12] mov edx, [ebp+16] mov edi, [ebp+20] - jmp SYSCALL_JUMP + SYSCALL_OP mov [_errno], ebx pop edi pop ebx @@ -105,7 +106,7 @@ SYSCALL_JUMP equ 0xCFFF0000 mov edx, [ebp+16] mov edi, [ebp+20] mov esi, [ebp+24] - jmp SYSCALL_JUMP + SYSCALL_OP mov [_errno], ebx pop esi pop edi @@ -130,7 +131,7 @@ SYSCALL_JUMP equ 0xCFFF0000 mov edi, [ebp+20] mov esi, [ebp+24] mov ebp, [ebp+28] - jmp SYSCALL_JUMP + SYSCALL_OP mov [_errno], ebx pop esi pop edi