From: John Hodge Date: Sun, 27 Jun 2010 02:52:55 +0000 (+0800) Subject: Cleaning up timer code, implementing cursor in vesa X-Git-Tag: rel0.06~132 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=da7ef0c8cace452ccfdfa0881a3c0b09970874d8;p=tpg%2Facess2.git Cleaning up timer code, implementing cursor in vesa - fixed the usermode 64-bit div bug --- diff --git a/Kernel/include/acess.h b/Kernel/include/acess.h index 83a44ce5..f355a78d 100644 --- a/Kernel/include/acess.h +++ b/Kernel/include/acess.h @@ -7,6 +7,8 @@ #define NULL ((void*)0) #define PACKED __attribute__ ((packed)) +#define offsetof(st, m) ((Uint)((char *)&((st *)(0))->m - (char *)0 )) + //#include #include @@ -370,8 +372,24 @@ 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); +/** + * \brief Gets the current timestamp (miliseconds since Midnight 1st January 1970) + */ extern Sint64 now(void); -extern int Time_CreateTimer(int Delta, void *Callback, void *Argument); +/** + * \brief Timer callback function + */ +typedef void (tTimerCallback)(void *); +/** + * \brief Creates a one-shot timer + * \param Delta Period of the timer + * \param Callback Function to call each time + * \param Argument Argument to pass to the callback + */ +extern int Time_CreateTimer(int Delta, tTimerCallback *Callback, void *Argument); +/** + * \brief Removed an active timer + */ extern void Time_RemoveTimer(int ID); extern void Time_Delay(int Delay); /** diff --git a/Kernel/time.c b/Kernel/time.c index fcc13afb..c048d11a 100644 --- a/Kernel/time.c +++ b/Kernel/time.c @@ -57,9 +57,9 @@ void Timer_CallTimers() } /** - * \fn int Time_CreateTimer(int Delta, void *Callback, void *Argument) + * \fn int Time_CreateTimer(int Delta, tTimerCallback *Callback, void *Argument) */ -int Time_CreateTimer(int Delta, void *Callback, void *Argument) +int Time_CreateTimer(int Delta, tTimerCallback *Callback, void *Argument) { int ret; diff --git a/Modules/Display/VESA/main.c b/Modules/Display/VESA/main.c index d3beb1f7..d4e2d135 100644 --- a/Modules/Display/VESA/main.c +++ b/Modules/Display/VESA/main.c @@ -25,6 +25,7 @@ Uint64 Vesa_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer); int Vesa_Int_SetMode(int Mode); int Vesa_Int_FindMode(tVideo_IOCtl_Mode *data); int Vesa_Int_ModeInfo(tVideo_IOCtl_Mode *data); +void Vesa_FlipCursor(void *Arg); // --- 2D Acceleration Functions -- void Vesa_2D_Fill(void *Ent, Uint16 X, Uint16 Y, Uint16 W, Uint16 H, Uint32 Colour); void Vesa_2D_Blit(void *Ent, Uint16 DstX, Uint16 DstY, Uint16 SrcX, Uint16 SrcY, Uint16 W, Uint16 H); @@ -41,13 +42,20 @@ tDevFS_Driver gVesa_DriverStruct = { }; tSpinlock glVesa_Lock; tVM8086 *gpVesa_BiosState; + int giVesaDriverId = -1; +// --- Video Modes --- int giVesaCurrentMode = 0; int giVesaCurrentFormat = VIDEO_BUFFMT_TEXT; - int giVesaDriverId = -1; -char *gpVesa_Framebuffer = (void*)VESA_DEFAULT_FRAMEBUFFER; tVesa_Mode *gVesa_Modes; int giVesaModeCount = 0; - int giVesaPageCount = 0; +// --- Framebuffer --- +char *gpVesa_Framebuffer = (void*)VESA_DEFAULT_FRAMEBUFFER; + int giVesaPageCount = 0; //!< Framebuffer size in pages +// --- Cursor Control --- + int giVesaCursorX = -1; + int giVesaCursorY = -1; + int giVesaCursorTimer = -1; // Invalid timer +// --- 2D Video Stream Handlers --- tDrvUtil_Video_2DHandlers gVesa_2DFunctions = { NULL, Vesa_2D_Fill, @@ -348,6 +356,25 @@ int Vesa_Ioctl(tVFS_Node *Node, int ID, void *Data) return ret; case VIDEO_IOCTL_SETCURSOR: // Set cursor position + giVesaCursorX = ((tVideo_IOCtl_Pos*)Data)->x; + giVesaCursorY = ((tVideo_IOCtl_Pos*)Data)->y; + if( + giVesaCursorX < 0 || giVesaCursorY < 0 + || giVesaCursorX >= gVesa_Modes[giVesaCurrentMode].width + || giVesaCursorY >= gVesa_Modes[giVesaCurrentMode].height) + { + if(giVesaCursorTimer != -1) + Time_RemoveTimer(giVesaCursorTimer); + giVesaCursorX = -1; + giVesaCursorY = -1; + } + else { + if(giVesaCursorTimer == -1) + giVesaCursorTimer = Time_CreateTimer(500, Vesa_FlipCursor, Node); + } + + Log_Debug("VESA", "Cursor at (%i,%i), timer %i", + giVesaCursorX, giVesaCursorY, giVesaCursorTimer); return 0; case VIDEO_IOCTL_REQLFB: // Request Linear Framebuffer @@ -356,6 +383,9 @@ int Vesa_Ioctl(tVFS_Node *Node, int ID, void *Data) return 0; } +/** + * \brief Updates the video mode + */ int Vesa_Int_SetMode(int mode) { Log_Log("VESA", "Setting mode to %i", mode); @@ -446,6 +476,26 @@ int Vesa_Int_ModeInfo(tVideo_IOCtl_Mode *data) return 1; } +/** + * \brief Updates the state of the text cursor + * \note Just does a bitwise not on the cursor region + */ +void Vesa_FlipCursor(void *Arg) +{ + int pitch = gVesa_Modes[giVesaCurrentMode].pitch; + int x = giVesaCursorX*giVT_CharWidth; + int y = giVesaCursorY*giVT_CharHeight; + int i; + Uint32 *fb = (void*)gpVesa_Framebuffer; + + if(giVesaCursorX < 0 || giVesaCursorY < 0) return; + + for( i = 0; i < giVT_CharHeight; i++ ) + fb[(y+i)*pitch+x] = fb[(y+i)*pitch+x]; + + giVesaCursorTimer = Time_CreateTimer(500, Vesa_FlipCursor, Arg); +} + // ------------------------ // --- 2D Accelleration --- // ------------------------ diff --git a/Modules/Filesystems/NTFS/common.h b/Modules/Filesystems/NTFS/common.h index fb3fe357..8d2a9ecd 100644 --- a/Modules/Filesystems/NTFS/common.h +++ b/Modules/Filesystems/NTFS/common.h @@ -1,8 +1,17 @@ /* + * Acess2 - NTFS Driver + * By John Hodge (thePowersGang) + * This file is published under the terms of the Acess licence. See the + * file COPYING for details. + * + * common.h - Common Types and Definitions */ #ifndef _COMMON_H_ #define _COMMON_H_ +#include +#include + // === STRUCTURES === /** * In-memory representation of an NTFS Disk @@ -10,7 +19,10 @@ typedef struct sNTFS_Disk { int FD; - Uint64 MFTOfs; + + int ClusterSize; + Uint64 MFTBase; + tVFS_Node RootNode; } tNTFS_Disk; @@ -44,7 +56,7 @@ typedef struct sNTFS_BootSector Uint64 SerialNumber; - Uint8 Padding[515-offsetof(tNTFS_BootSector, Padding)]; + Uint8 Padding[512-72]; } tNTFS_BootSector; diff --git a/Modules/Filesystems/NTFS/main.c b/Modules/Filesystems/NTFS/main.c index 5ace3333..46930bd3 100644 --- a/Modules/Filesystems/NTFS/main.c +++ b/Modules/Filesystems/NTFS/main.c @@ -8,6 +8,8 @@ */ #define DEBUG 1 #define VERBOSE 0 +#include +#include #include "common.h" #include @@ -55,7 +57,7 @@ tVFS_Node *NTFS_InitDevice(char *Device, char **Options) disk->MFTBase = bs.MFTStart; Log_Debug("NTFS", "MFT Base = %i", disk->MFTBase); - disk->RootNode.Inode = 5; // MFT Ent #5 is '.' + disk->RootNode.Inode = 5; // MFT Ent #5 is filesystem root disk->RootNode.ImplPtr = disk; disk->RootNode.UID = 0; diff --git a/Modules/Storage/FDD/fdd.c b/Modules/Storage/FDD/fdd.c index 6ad2b1a1..23fd4db0 100644 --- a/Modules/Storage/FDD/fdd.c +++ b/Modules/Storage/FDD/fdd.c @@ -105,9 +105,9 @@ void FDD_int_SendByte(int base, char byte); void FDD_Reset(int id); void FDD_Recalibrate(int disk); int FDD_int_SeekTrack(int disk, int head, int track); -void FDD_int_TimerCallback(int arg); -void FDD_int_StopMotor(int disk); -void FDD_int_StartMotor(int disk); +void FDD_int_TimerCallback(void *Arg); +void FDD_int_StopMotor(void *Arg); +void FDD_int_StartMotor(int Disk); int FDD_int_GetDims(int type, int lba, int *c, int *h, int *s, int *spt); // === GLOBALS === @@ -208,7 +208,7 @@ void FDD_UnloadModule() LOCK(&glFDD); for(i=0;i<4;i++) { Time_RemoveTimer(gFDD_Devices[i].timer); - FDD_int_StopMotor(i); + FDD_int_StopMotor((void*)i); } RELEASE(&glFDD); //IRQ_Clear(6); @@ -726,7 +726,7 @@ void FDD_Recalibrate(int disk) FDD_SensInt(cPORTBASE[disk>>1], NULL, NULL); LOG("Stopping Motor"); - FDD_int_StopMotor(disk); + gFDD_Devices[disk].timer = Time_CreateTimer(MOTOR_OFF_DELAY, FDD_int_StopMotor, (void*)(Uint)disk); LEAVE('-'); } @@ -766,13 +766,14 @@ void FDD_Reset(int id) * \fn void FDD_int_TimerCallback() * \brief Called by timer */ -void FDD_int_TimerCallback(int arg) +void FDD_int_TimerCallback(void *Arg) { - ENTER("iarg", arg); - if(gFDD_Devices[arg].motorState == 1) - gFDD_Devices[arg].motorState = 2; - Time_RemoveTimer(gFDD_Devices[arg].timer); - gFDD_Devices[arg].timer = -1; + int disk = (int)Arg; + ENTER("iarg", disk); + if(gFDD_Devices[disk].motorState == 1) + gFDD_Devices[disk].motorState = 2; + Time_RemoveTimer(gFDD_Devices[disk].timer); + gFDD_Devices[disk].timer = -1; LEAVE('-'); } @@ -787,16 +788,16 @@ void FDD_int_StartMotor(int disk) state |= 1 << (4+disk); outb( cPORTBASE[ disk>>1 ] + PORT_DIGOUTPUT, state ); gFDD_Devices[disk].motorState = 1; - gFDD_Devices[disk].timer = Time_CreateTimer(MOTOR_ON_DELAY, FDD_int_TimerCallback, (void*)(tVAddr)disk); + gFDD_Devices[disk].timer = Time_CreateTimer(MOTOR_ON_DELAY, FDD_int_TimerCallback, (void*)(Uint)disk); } /** * \fn void FDD_int_StopMotor(int disk) * \brief Stops FDD Motor */ -void FDD_int_StopMotor(int disk) +void FDD_int_StopMotor(void *Arg) { - Uint8 state; + Uint8 state, disk = (int)Arg; if( IS_LOCKED(&glFDD) ) return ; ENTER("iDisk", disk); diff --git a/Usermode/Libraries/libgcc.so_src/libgcc.c b/Usermode/Libraries/libgcc.so_src/libgcc.c index 53ea6432..bd5d1f3a 100644 --- a/Usermode/Libraries/libgcc.so_src/libgcc.c +++ b/Usermode/Libraries/libgcc.so_src/libgcc.c @@ -46,7 +46,8 @@ uint64_t __udivdi3(uint64_t Num, uint64_t Den) } return ret; #else - uint64_t P[64], q, n; + uint64_t P[2]; + uint64_t q; int i; if(Den == 0) __asm__ __volatile__ ("int $0x0"); @@ -57,28 +58,31 @@ uint64_t __udivdi3(uint64_t Num, uint64_t Den) if(Den == 2) return Num >> 1; if(Den == 16) return Num >> 4; if(Num < Den) return 0; - if(Num == Den) return 1; + if(Num < Den*2) return 1; if(Num == Den*2) return 2; - // Non-restoring division, from wikipedia + // Restoring division, from wikipedia // http://en.wikipedia.org/wiki/Division_(digital) - P[0] = Num; - for( i = 0; i < 64; i ++ ) + P[0] = Num; P[1] = 0; + for( i = 64; i--; ) { - if( P[i] >= 0 ) { + // P <<= 1; + P[1] = (P[1] << 1) | (P[0] >> 63); + P[0] = P[0] << 1; + + // P -= Den << 64 + P[1] -= Den; + + // P >= 0 + if( !(P[1] & (1ULL<<63)) ) { q |= (uint64_t)1 << (63-i); - P[i+1] = 2*P[i] - Den; } else { //q |= 0 << (63-i); - P[i+1] = 2*P[i] + Den; + P[1] += Den; } } - n = ~q; - n = -n; - q += n; - return q; #endif }