From: John Hodge Date: Sun, 21 Mar 2010 05:00:49 +0000 (+0800) Subject: Misc Changes, Added Logging Subsystem, Fixes to InitRD, Working on RTL8139 driver X-Git-Tag: rel0.06~271 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=bd8dc898108f10c0498f4dc5d0164a50b5ff2e5c;p=tpg%2Facess2.git Misc Changes, Added Logging Subsystem, Fixes to InitRD, Working on RTL8139 driver --- diff --git a/Kernel/Makefile b/Kernel/Makefile index ccc47dd8..5e6fafba 100644 --- a/Kernel/Makefile +++ b/Kernel/Makefile @@ -26,7 +26,7 @@ ifeq ($(DEBUG_BUILD),yes) endif OBJ = $(addprefix arch/$(ARCHDIR)/,$(A_OBJ)) -OBJ += heap.o messages.o debug.o modules.o lib.o syscalls.o system.o threads.o drvutil.o +OBJ += heap.o messages.o debug.o modules.o lib.o syscalls.o system.o threads.o drvutil.o logging.o OBJ += $(addprefix vfs/fs/, $(addsuffix .o,$(FILESYSTEMS))) OBJ += drv/vterm.o drv/proc.o drv/fifo.o drv/iocache.o drv/dma.o drv/pci.o drv/kb.o drv/vga.o OBJ += binary.o bin/elf.o bin/pe.o diff --git a/Kernel/Makefile.BuildNum b/Kernel/Makefile.BuildNum index 46b9e67e..b9b1128c 100644 --- a/Kernel/Makefile.BuildNum +++ b/Kernel/Makefile.BuildNum @@ -1 +1 @@ -BUILD_NUM = 1556 +BUILD_NUM = 1563 diff --git a/Kernel/arch/x86/main.c b/Kernel/arch/x86/main.c index c8e4e4df..fd257dbb 100644 --- a/Kernel/arch/x86/main.c +++ b/Kernel/arch/x86/main.c @@ -12,16 +12,18 @@ #define VGA_ERRORS 0 // === IMPORTS === -extern void Heap_Install(); -extern void Desctab_Install(); -extern void MM_PreinitVirtual(); +extern void Heap_Install(void); +extern void Desctab_Install(void); +extern void MM_PreinitVirtual(void); extern void MM_Install(tMBoot_Info *MBoot); -extern void MM_InstallVirtual(); -extern void Threads_Init(); -extern int Time_Setup(); +extern void MM_InstallVirtual(void); +extern void Threads_Init(void); +extern int Time_Setup(void); extern Uint Proc_Clone(Uint *Err, Uint Flags); -extern void Threads_Sleep(); -extern void Threads_Exit(); +extern void Threads_Sleep(void); +extern void Threads_Exit(void); + +extern int Modules_LoadBuiltins(void); // === GLOBALS === @@ -51,6 +53,10 @@ int kmain(Uint MbMagic, tMBoot_Info *MbInfo) // Load Virtual Filesystem VFS_Init(); + // Initialise builtin modules + Log("Initialising builtin modules..."); + Modules_LoadBuiltins(); + Log("Loading Modules... (%i of them)", MbInfo->ModuleCount); // Load initial modules diff --git a/Kernel/debug.c b/Kernel/debug.c index be937169..7168b3af 100644 --- a/Kernel/debug.c +++ b/Kernel/debug.c @@ -52,7 +52,7 @@ int getDebugChar() return inb(GDB_SERIAL_PORT); } -static void E9(char ch) +static void Debug_Putchar(char ch) { if(giDebug_KTerm != -1) VFS_Write(giDebug_KTerm, 1, &ch); @@ -77,12 +77,12 @@ static void E9(char ch) #endif } -static void E9_Str(char *Str) +static void Debug_Puts(char *Str) { - while(*Str) E9(*Str++); + while(*Str) Debug_Putchar(*Str++); } -void E9_Fmt(const char *format, va_list *args) +void Debug_Fmt(const char *format, va_list *args) { char c, pad = ' '; int minSize = 0; @@ -95,7 +95,7 @@ void E9_Fmt(const char *format, va_list *args) { // Non control character if( c != '%' ) { - E9(c); + Debug_Putchar(c); continue; } @@ -103,14 +103,14 @@ void E9_Fmt(const char *format, va_list *args) // Literal % if(c == '%') { - E9('%'); + Debug_Putchar('%'); continue; } // Pointer if(c == 'p') { Uint ptr = va_arg(*args, Uint); - E9('*'); E9('0'); E9('x'); + Debug_Putchar('*'); Debug_Putchar('0'); Debug_Putchar('x'); p = tmpBuf; itoa(p, ptr, 16, BITS/4, '0'); goto printString; @@ -157,7 +157,7 @@ void E9_Fmt(const char *format, va_list *args) case 'd': case 'i': if( (isLongLong && arg >> 63) || (!isLongLong && arg >> 31) ) { - E9('-'); + Debug_Putchar('-'); arg = -arg; } itoa(p, arg, 10, minSize, pad); @@ -176,42 +176,35 @@ void E9_Fmt(const char *format, va_list *args) goto printString; case 'B': //Boolean - if(arg) E9_Str("True"); - else E9_Str("False"); + if(arg) Debug_Puts("True"); + else Debug_Puts("False"); break; case 's': p = (char*)(Uint)arg; printString: if(!p) p = "(null)"; - while(*p) E9(*p++); + while(*p) Debug_Putchar(*p++); break; // Single Character / Array case 'c': if(minSize == 1) { - E9(arg); + Debug_Putchar(arg); break; } p = (char*)(Uint)arg; if(!p) goto printString; - while(minSize--) E9(*p++); + while(minSize--) Debug_Putchar(*p++); break; - default: E9(arg); break; + default: + Debug_Putchar(arg); + break; } } } -/** - * \fn void LogV(char *Fmt, va_list Args) - */ -void LogV(char *Fmt, va_list Args) -{ - E9_Str("Log: "); - E9_Fmt(Fmt, &Args); - E9('\n'); -} /** * \fn void LogF(char *Msg, ...) */ @@ -221,7 +214,7 @@ void LogF(char *Fmt, ...) va_start(args, Fmt); - E9_Fmt(Fmt, &args); + Debug_Fmt(Fmt, &args); va_end(args); } @@ -232,29 +225,29 @@ void Log(char *Fmt, ...) { va_list args; - E9_Str("Log: "); + Debug_Puts("Log: "); va_start(args, Fmt); - E9_Fmt(Fmt, &args); + Debug_Fmt(Fmt, &args); va_end(args); - E9('\n'); + Debug_Putchar('\n'); } void Warning(char *Fmt, ...) { va_list args; - E9_Str("Warning: "); + Debug_Puts("Warning: "); va_start(args, Fmt); - E9_Fmt(Fmt, &args); + Debug_Fmt(Fmt, &args); va_end(args); - E9('\n'); + Debug_Putchar('\n'); } void Panic(char *Fmt, ...) { va_list args; - E9_Str("Panic: "); + Debug_Puts("Panic: "); va_start(args, Fmt); - E9_Fmt(Fmt, &args); + Debug_Fmt(Fmt, &args); va_end(args); - E9('\n'); + Debug_Putchar('\n'); Threads_Dump(); @@ -279,33 +272,33 @@ void Debug_Enter(char *FuncName, char *ArgTypes, ...) va_start(args, ArgTypes); - while(i--) E9(' '); + while(i--) Debug_Putchar(' '); - E9_Str(FuncName); E9_Str(": ("); + Debug_Puts(FuncName); Debug_Puts(": ("); while(*ArgTypes) { pos = strpos(ArgTypes, ' '); if(pos != -1) ArgTypes[pos] = '\0'; if(pos == -1 || pos > 1) { - E9_Str(ArgTypes+1); - E9('='); + Debug_Puts(ArgTypes+1); + Debug_Putchar('='); } if(pos != -1) ArgTypes[pos] = ' '; switch(*ArgTypes) { - case 'p': E9_Fmt("%p", &args); break; - case 's': E9_Fmt("'%s'", &args); break; - case 'i': E9_Fmt("%i", &args); break; - case 'u': E9_Fmt("%u", &args); break; - case 'x': E9_Fmt("0x%x", &args); break; - case 'b': E9_Fmt("0b%b", &args); break; + case 'p': Debug_Fmt("%p", &args); break; + case 's': Debug_Fmt("'%s'", &args); break; + case 'i': Debug_Fmt("%i", &args); break; + case 'u': Debug_Fmt("%u", &args); break; + case 'x': Debug_Fmt("0x%x", &args); break; + case 'b': Debug_Fmt("0b%b", &args); break; // Extended (64-Bit) - case 'X': E9_Fmt("0x%llx", &args); break; - case 'B': E9_Fmt("0b%llb", &args); break; + case 'X': Debug_Fmt("0x%llx", &args); break; + case 'B': Debug_Fmt("0b%llb", &args); break; } if(pos != -1) { - E9(','); E9(' '); + Debug_Putchar(','); Debug_Putchar(' '); } if(pos == -1) break; @@ -313,7 +306,7 @@ void Debug_Enter(char *FuncName, char *ArgTypes, ...) } va_end(args); - E9(')'); E9('\n'); + Debug_Putchar(')'); Debug_Putchar('\n'); } void Debug_Log(char *FuncName, char *Fmt, ...) @@ -323,13 +316,13 @@ void Debug_Log(char *FuncName, char *Fmt, ...) va_start(args, Fmt); - while(i--) E9(' '); + while(i--) Debug_Putchar(' '); - E9_Str(FuncName); E9_Str(": "); - E9_Fmt(Fmt, &args); + Debug_Puts(FuncName); Debug_Puts(": "); + Debug_Fmt(Fmt, &args); va_end(args); - E9('\n'); + Debug_Putchar('\n'); } void Debug_Leave(char *FuncName, char RetType, ...) @@ -344,29 +337,29 @@ void Debug_Leave(char *FuncName, char RetType, ...) i = 0; } // Indenting - while(i--) E9(' '); + while(i--) Debug_Putchar(' '); - E9_Str(FuncName); E9_Str(": RETURN"); + Debug_Puts(FuncName); Debug_Puts(": RETURN"); // No Return if(RetType == '-') { - E9('\n'); + Debug_Putchar('\n'); return; } - E9(' '); + Debug_Putchar(' '); switch(RetType) { - case 'n': E9_Str("NULL"); break; - case 'p': E9_Fmt("%p", &args); break; - case 's': E9_Fmt("'%s'", &args); break; - case 'i': E9_Fmt("%i", &args); break; - case 'u': E9_Fmt("%u", &args); break; - case 'x': E9_Fmt("0x%x", &args); break; + case 'n': Debug_Puts("NULL"); break; + case 'p': Debug_Fmt("%p", &args); break; + case 's': Debug_Fmt("'%s'", &args); break; + case 'i': Debug_Fmt("%i", &args); break; + case 'u': Debug_Fmt("%u", &args); break; + case 'x': Debug_Fmt("0x%x", &args); break; // Extended (64-Bit) - case 'X': E9_Fmt("0x%llx", &args); break; + case 'X': Debug_Fmt("0x%llx", &args); break; } - E9('\n'); + Debug_Putchar('\n'); va_end(args); } @@ -375,7 +368,7 @@ void Debug_HexDump(char *Header, void *Data, Uint Length) { Uint8 *cdat = Data; Uint pos = 0; - E9_Str(Header); + Debug_Puts(Header); LogF(" (Hexdump of %p)\n", Data); while(Length >= 16) @@ -403,7 +396,7 @@ void Debug_HexDump(char *Header, void *Data, Uint Length) Length--; cdat ++; } - E9('\n'); + Debug_Putchar('\n'); } // --- EXPORTS --- diff --git a/Kernel/include/acess.h b/Kernel/include/acess.h index ddf69cba..9363dc0d 100644 --- a/Kernel/include/acess.h +++ b/Kernel/include/acess.h @@ -296,6 +296,7 @@ extern Uint32 BigEndian32(Uint32 Val); * \name Strings * \{ */ +extern int vsnprintf(char *__s, size_t __maxlen, const char *__format, va_list args); extern int sprintf(char *__s, const char *__format, ...); extern Uint strlen(const char *Str); extern char *strcpy(char *__dest, const char *__src); diff --git a/Kernel/include/vfs.h b/Kernel/include/vfs.h index 47cbe190..5d39a983 100644 --- a/Kernel/include/vfs.h +++ b/Kernel/include/vfs.h @@ -44,6 +44,24 @@ * Marks a file as a symbolic link */ #define VFS_FFLAG_SYMLINK 0x04 +/** + * \brief Set User ID Flag + * + * Allows an executable file to change it's executing user to the file's + * owner. + * In the case of a directory, it means that all immediate children will + * inherit the UID of the parent. + */ +#define VFS_FFLAG_SETUID 0x08 +/** + * \brief Set Group ID Flag + * + * Allows an executable file to change it's executing group to the file's + * owning group. + * In the case of a directory, it means that all immediate children will + * inherit the GID of the parent. + */ +#define VFS_FFLAG_SETGID 0x10 /** * \} */ @@ -54,7 +72,8 @@ * This structure provides the VFS with the functions required to read/write * the file (or directory) that it represents. */ -typedef struct sVFS_Node { +typedef struct sVFS_Node +{ /** * \name Identifiers * \brief Fields used by the driver to identify what data this node diff --git a/Kernel/lib.c b/Kernel/lib.c index bfae2a41..62500fe9 100644 --- a/Kernel/lib.c +++ b/Kernel/lib.c @@ -14,7 +14,55 @@ const short DAYS_BEFORE[] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 3 #define UNIX_TO_2K ((30*365*3600*24) + (7*3600*24)) //Normal years + leap years // === PROTOTYPES === + int atoi(const char *string); +void itoa(char *buf, Uint num, int base, int minLength, char pad); + int vsnprintf(char *__s, size_t __maxlen, const char *__format, va_list args); + int sprintf(char *__s, const char *__format, ...); + int tolower(int c); + int strucmp(const char *Str1, const char *Str2); + int strpos(const char *Str, char Ch); + Uint8 ByteSum(void *Ptr, int Size); +size_t strlen(const char *__s); +char *strcpy(char *__str1, const char *__str2); +char *strncpy(char *__str1, const char *__str2, size_t max); + int strcmp(const char *str1, const char *str2); + int strncmp(const char *str1, const char *str2, size_t num); +char *strdup(const char *Str); + int DivUp(int num, int dem); + int strpos8(const char *str, Uint32 Search); int ReadUTF8(Uint8 *str, Uint32 *Val); + int WriteUTF8(Uint8 *str, Uint32 Val); +Sint64 timestamp(int sec, int mins, int hrs, int day, int month, int year); +Uint rand(void); + int CheckString(char *String); + int CheckMem(void *Mem, int NumBytes); + int ModUtil_LookupString(char **Array, char *Needle); + int ModUtil_SetIdent(char *Dest, char *Value); + +// === EXPORTS === +EXPORT(atoi); +EXPORT(itoa); +EXPORT(vsnprintf); +EXPORT(sprintf); +EXPORT(tolower); +EXPORT(strucmp); +EXPORT(strpos); +EXPORT(ByteSum); +EXPORT(strlen); +EXPORT(strcpy); +EXPORT(strncpy); +EXPORT(strcmp); +EXPORT(strncmp); +EXPORT(strdup); +EXPORT(DivUp); +EXPORT(strpos8); +EXPORT(ReadUTF8); +EXPORT(WriteUTF8); +EXPORT(timestamp); +EXPORT(CheckString); +EXPORT(CheckMem); +EXPORT(ModUtil_LookupString); +EXPORT(ModUtil_SetIdent); // === GLOBALS === static Uint giRandomState = RANDOM_SEED; @@ -226,6 +274,9 @@ int vsnprintf(char *__s, size_t __maxlen, const char *__format, va_list args) PUTCH( (Uint8)val ); break; } + + if(pos == __maxlen) + break; } if(__s && pos != __maxlen) @@ -539,7 +590,7 @@ Sint64 timestamp(int sec, int mins, int hrs, int day, int month, int year) * \brief Pseudo random number generator * \note Unknown effectiveness (made up on the spot) */ -Uint rand() +Uint rand(void) { Uint old = giRandomState; // Get the next state value @@ -636,17 +687,3 @@ int ModUtil_SetIdent(char *Dest, char *Value) strncpy(Dest, Value, 32); return 1; } - -EXPORT(strlen); -EXPORT(strdup); -EXPORT(strcmp); -EXPORT(strncmp); -EXPORT(strcpy); -EXPORT(strncpy); - -EXPORT(timestamp); -EXPORT(ReadUTF8); -EXPORT(CheckMem); -EXPORT(CheckString); -EXPORT(ModUtil_LookupString); -EXPORT(ModUtil_SetIdent); diff --git a/Kernel/logging.c b/Kernel/logging.c new file mode 100644 index 00000000..567f64e3 --- /dev/null +++ b/Kernel/logging.c @@ -0,0 +1,219 @@ +/* + * Acess 2 Kernel + * - By John Hodge (thePowersGang) + * + * logging.c - Kernel Logging Service + */ +#include + +#define PRINT_ON_APPEND 1 + +// === CONSTANTS === +enum eLogLevels +{ + LOG_LEVEL_KPANIC, + LOG_LEVEL_PANIC, + LOG_LEVEL_FATAL, + LOG_LEVEL_ERROR, + LOG_LEVEL_WARNING, + LOG_LEVEL_NOTICE, + LOG_LEVEL_LOG, + LOG_LEVEL_DEBUG, + NUM_LOG_LEVELS +}; +const char csaLevelCodes[] = {'k','p','f','e','w','n','l','d'}; + +// === TYPES === +typedef struct sLogEntry +{ + struct sLogEntry *Next; + struct sLogEntry *LevelNext; + Sint64 Time; + Uint64 Ident; + int Level; + int Length; + char Data[]; +} tLogEntry; +typedef struct sLogList +{ + tLogEntry *Head; + tLogEntry *Tail; +} tLogList; + +// === PROTOTYPES === +void Log_AddEvent(char *Ident, int Level, char *Format, va_list Args); +static void Log_Int_PrintMessage(tLogEntry *Entry); +void Log_KernelPanic(char *Ident, char *Message, ...); +void Log_Panic(char *Ident, char *Message, ...); +void Log_Error(char *Ident, char *Message, ...); +void Log_Warning(char *Ident, char *Message, ...); +void Log_Log(char *Ident, char *Message, ...); +void Log_Notice(char *Ident, char *Message, ...); +void Log_Debug(char *Ident, char *Message, ...); +static Uint64 Log_Int_GetIdent(const char *Str); + +// === GLOBALS === +tSpinlock glLog; +tLogList gLog; +tLogList gLog_Levels[NUM_LOG_LEVELS]; + +// === CODE === +/** + * \brief Adds an event to the log + */ +void Log_AddEvent(char *Ident, int Level, char *Format, va_list Args) +{ + int len; + tLogEntry *ent; + Uint64 ident = Log_Int_GetIdent(Ident); + + if( Level >= NUM_LOG_LEVELS ) return; + + len = vsnprintf(NULL, 256, Format, Args); + + ent = malloc(sizeof(tLogEntry)+len+1); + ent->Time = now(); + ent->Ident = ident; + ent->Level = Level; + ent->Length = len; + vsnprintf( ent->Data, 256, Format, Args ); + + LOCK( &glLog ); + + ent->Next = gLog.Tail; + if(gLog.Head) + gLog.Tail = ent; + else + gLog.Tail = gLog.Head = ent; + + ent->LevelNext = gLog_Levels[Level].Tail; + if(gLog_Levels[Level].Head) + gLog_Levels[Level].Tail = ent; + else + gLog_Levels[Level].Tail = gLog_Levels[Level].Head = ent; + + RELEASE( &glLog ); + + #if PRINT_ON_APPEND + Log_Int_PrintMessage( ent ); + #endif + +} + +/** + * \brief Prints a log message to the debug console + */ +void Log_Int_PrintMessage(tLogEntry *Entry) +{ + LogF("%018%c [%8s] %s\n", + Entry->Time, + csaLevelCodes[Entry->Level], + &Entry->Ident, + Entry->Data + ); +} + +/** + * \brief KERNEL PANIC!!!! + */ +void Log_KernelPanic(char *Ident, char *Message, ...) +{ + va_list args; + va_start(args, Message); + Log_AddEvent(Ident, LOG_LEVEL_KPANIC, Message, args); + va_end(args); +} + +/** + * \brief Panic Message - Driver Unrecoverable error + */ +void Log_Panic(char *Ident, char *Message, ...) +{ + va_list args; + va_start(args, Message); + Log_AddEvent(Ident, LOG_LEVEL_PANIC, Message, args); + va_end(args); +} + +/** + * \brief Error Message - Recoverable Error + */ +void Log_Error(char *Ident, char *Message, ...) +{ + va_list args; + va_start(args, Message); + Log_AddEvent(Ident, LOG_LEVEL_ERROR, Message, args); + va_end(args); +} + +/** + * \brief Warning Message - Something the user should know + */ +void Log_Warning(char *Ident, char *Message, ...) +{ + va_list args; + + va_start(args, Message); + Log_AddEvent(Ident, LOG_LEVEL_WARNING, Message, args); + va_end(args); +} + +/** + * \brief Notice Message - Something the user might like to know + */ +void Log_Notice(char *Ident, char *Message, ...) +{ + va_list args; + va_start(args, Message); + Log_AddEvent(Ident, LOG_LEVEL_NOTICE, Message, args); + va_end(args); +} + +/** + * \brief Log Message - Possibly useful information + */ +void Log_Log(char *Ident, char *Message, ...) +{ + va_list args; + va_start(args, Message); + Log_AddEvent(Ident, LOG_LEVEL_LOG, Message, args); + va_end(args); +} + +/** + * \brief Debug Message - Only a developer would want this info + */ +void Log_Debug(char *Ident, char *Message, ...) +{ + va_list args; + va_start(args, Message); + Log_AddEvent(Ident, LOG_LEVEL_DEBUG, Message, args); + va_end(args); +} + +/** + * \brief Converts a string into a 64-bit ident + */ +static Uint64 Log_Int_GetIdent(const char *Str) +{ + Uint64 ret = 0; + int i; + char ch; + + for( i = 0; Str[i] && i < 7; i++ ) + { + ch = Str[i]; + + if(ch < ' ') + ch = '?'; + else if(ch > '~') + ch = '?'; + + ret |= (Uint64)ch << 8*i; + } + + for( ; i < 7; i++ ) + ret |= 0x20 << (8*i); + + return ret; +} diff --git a/Kernel/modules.c b/Kernel/modules.c index 29a03f84..37f5418b 100644 --- a/Kernel/modules.c +++ b/Kernel/modules.c @@ -7,15 +7,19 @@ #include #define USE_EDI 0 -#define USE_UDI 1 +#define USE_UDI 0 // === PROTOTYPES === - int Modules_LoadBuiltins(); + int Modules_LoadBuiltins(void); + int Module_RegisterLoader(tModuleLoader *Loader); int Module_LoadMem(void *Buffer, Uint Length, char *ArgString); int Module_LoadFile(char *Path, char *ArgString); int Module_int_ResolveDeps(tModule *Info); int Module_IsLoaded(char *Name); +// === EXPORTS === +EXPORT(Module_RegisterLoader); + // === IMPORTS === #if USE_UDI extern int UDI_LoadDriver(void *Base); diff --git a/Kernel/system.c b/Kernel/system.c index b30f4d04..463b4e0f 100644 --- a/Kernel/system.c +++ b/Kernel/system.c @@ -39,18 +39,10 @@ char *gsConfigScript = "/Acess/Conf/BootConf.cfg"; // === CODE === void System_Init(char *ArgString) -{ - // - Start Builtin Drivers & Filesystems - //StartupPrint("Scanning PCI Bus..."); - //PCI_Install(); - StartupPrint("Loading DMA..."); - DMA_Install(); - StartupPrint("Loading staticly compiled modules..."); - Modules_LoadBuiltins(); - +{ // Set the debug to be echoed to the terminal - StartupPrint("Kernel now echoes to VT6 (Ctrl-Alt-F7)"); - Debug_SetKTerminal("/Devices/VTerm/6"); + StartupPrint("Kernel now echoes to VT7 (Ctrl-Alt-F8)"); + Debug_SetKTerminal("/Devices/VTerm/7"); // - Parse Kernel's Command Line System_ParseCommandLine(ArgString); @@ -77,8 +69,10 @@ void System_ParseCommandLine(char *ArgString) str = ArgString; for( argc = 0; argc < 32; argc++ ) { - while(*str == ' ') str++; // Eat Whitespace - if(*str == '\0') { argc--; break;} // End of string + // Eat Whitespace + while(*str == ' ') str++; + // Check for the end of the string + if(*str == '\0') { argc--; break;} argv[argc] = str; while(*str && *str != ' ') { @@ -88,7 +82,7 @@ void System_ParseCommandLine(char *ArgString) }*/ str++; } - if(*str == '\0') break; // End of string + if(*str == '\0') break; // Check for EOS *str = '\0'; // Cap off argument string str ++; // and increment the string pointer } @@ -172,10 +166,10 @@ void System_ParseSetting(char *Arg) // Check for boolean/flag (no '=') if(*value == '\0') { - if(strcmp(Arg, "") == 0) { - } else { + //if(strcmp(Arg, "") == 0) { + //} else { Warning("Kernel flag '%s' is not recognised", Arg); - } + //} } else { @@ -225,14 +219,15 @@ void System_ExecuteScript() // Parse File file = System_Int_ParseFile(fData); - // Loop lines + // Parse each line for( i = 0; i < file->nLines; i++ ) { line = &file->Lines[i]; if( line->nParts == 0 ) continue; // Skip blank - // Mount - if( strcmp(line->Parts[0], "mount") == 0 ) { + // Mount Device + if( strcmp(line->Parts[0], "mount") == 0 ) + { if( line->nParts != 4 ) { Warning("Configuration command 'mount' requires 3 arguments, %i given", line->nParts-1); @@ -243,8 +238,9 @@ void System_ExecuteScript() //! \todo Use an optional 4th argument for the options string VFS_Mount(line->Parts[1], line->Parts[2], line->Parts[3], ""); } - // Module - else if(strcmp(line->Parts[0], "module") == 0) { + // Load a Module + else if(strcmp(line->Parts[0], "module") == 0) + { if( line->nParts < 2 || line->nParts > 3 ) { Warning("Configuration command 'module' requires 1 or 2 arguments, %i given", line->nParts-1); @@ -255,8 +251,9 @@ void System_ExecuteScript() else Module_LoadFile(line->Parts[1], ""); } - // UDI Module - else if(strcmp(line->Parts[0], "udimod") == 0) { + // Load a UDI Module + else if(strcmp(line->Parts[0], "udimod") == 0) + { if( line->nParts != 2 ) { Warning("Configuration command 'udimod' requires 1 argument, %i given", line->nParts-1); @@ -265,8 +262,9 @@ void System_ExecuteScript() Log("[CFG ] Load UDI Module '%s'", line->Parts[1]); Module_LoadFile(line->Parts[1], ""); } - // EDI Module - else if(strcmp(line->Parts[0], "edimod") == 0) { + // Load a EDI Module + else if(strcmp(line->Parts[0], "edimod") == 0) + { if( line->nParts != 2 ) { Warning("Configuration command 'edimod' requires 1 argument, %i given", line->nParts-1); @@ -275,8 +273,9 @@ void System_ExecuteScript() Log("[CFG ] Load EDI Module '%s'", line->Parts[1]); Module_LoadFile(line->Parts[1], ""); } - // Symbolic Link - else if(strcmp(line->Parts[0], "symlink") == 0) { + // Create a Symbolic Link + else if(strcmp(line->Parts[0], "symlink") == 0) + { if( line->nParts != 3 ) { Warning("Configuration command 'symlink' requires 2 arguments, %i given", line->nParts-1); @@ -286,8 +285,9 @@ void System_ExecuteScript() line->Parts[1], line->Parts[2]); VFS_Symlink(line->Parts[1], line->Parts[2]); } - // Create Directory - else if(strcmp(line->Parts[0], "mkdir") == 0) { + // Create a Directory + else if(strcmp(line->Parts[0], "mkdir") == 0) + { if( line->nParts != 2 ) { Warning("Configuration command 'mkdir' requires 1 argument, %i given", line->nParts-1); @@ -297,7 +297,8 @@ void System_ExecuteScript() VFS_MkDir(line->Parts[1]); } // Spawn a process - else if(strcmp(line->Parts[0], "spawn") == 0) { + else if(strcmp(line->Parts[0], "spawn") == 0) + { if( line->nParts != 2 ) { Warning("Configuration command 'spawn' requires 1 argument, %i given", line->nParts-1); diff --git a/Makefile.cfg b/Makefile.cfg index 5fc3af1d..4de3cd04 100644 --- a/Makefile.cfg +++ b/Makefile.cfg @@ -26,7 +26,7 @@ endif FILESYSTEMS = DRIVERS = MODULES = Storage/ATA Storage/FDD -#MODULES += Network/NE2000 +MODULES += Network/NE2000 #MODULES += Display/BochsGA MODULES += Filesystems/Ext2 MODULES += Filesystems/FAT diff --git a/Modules/Filesystems/FAT/fat.c b/Modules/Filesystems/FAT/fat.c index f41b9ea0..d063c874 100644 --- a/Modules/Filesystems/FAT/fat.c +++ b/Modules/Filesystems/FAT/fat.c @@ -1117,12 +1117,3 @@ void FAT_CloseFile(tVFS_Node *Node) #endif return ; } - -/** - * \fn void fat_install() - * \brief Add the FAT Filesystem to the VFS - */ -void fat_install() -{ - VFS_AddDriver( &gFAT_FSInfo ); -} diff --git a/Modules/Filesystems/InitRD/files.lst b/Modules/Filesystems/InitRD/files.lst index ea7797f5..7ebee226 100644 --- a/Modules/Filesystems/InitRD/files.lst +++ b/Modules/Filesystems/InitRD/files.lst @@ -6,6 +6,7 @@ Dir "Bin" { File "CLIShell" "../../../Usermode/Applications/CLIShell" File "ls" "../../../Usermode/Applications/ls" File "cat" "../../../Usermode/Applications/cat" + File "mount" "../../../Usermode/Applications/mount" } Dir "Libs" { File "ld-acess.so" "../../../Usermode/Libraries/ld-acess.so" diff --git a/Modules/Filesystems/InitRD/main.c b/Modules/Filesystems/InitRD/main.c index cc54f27d..08835bf7 100644 --- a/Modules/Filesystems/InitRD/main.c +++ b/Modules/Filesystems/InitRD/main.c @@ -82,7 +82,7 @@ tVFS_Node *InitRD_FindDir(tVFS_Node *Node, char *Name) int i; tInitRD_File *dir = Node->ImplPtr; - Log("InirRD_FindDir: Name = '%s'", Name); + //Log("InirRD_FindDir: Name = '%s'", Name); for( i = 0; i < Node->Size; i++ ) { diff --git a/Modules/Interfaces/UDI/strmem.c b/Modules/Interfaces/UDI/strmem.c index 4ab1e208..53cc933f 100644 --- a/Modules/Interfaces/UDI/strmem.c +++ b/Modules/Interfaces/UDI/strmem.c @@ -11,6 +11,12 @@ EXPORT(udi_snprintf); // === CODE === udi_size_t udi_snprintf(char *s, udi_size_t max_bytes, const char *format, ...) { - s[0] = '\0'; - return 0; + udi_size_t ret; + va_list args; + va_start(args, format); + + ret = vsnprintf(s, max_bytes, format, args); + + va_end(args); + return ret; } diff --git a/Modules/Network/NE2000/ne2000.c b/Modules/Network/NE2000/ne2000.c index 40d9b823..60f9ac2d 100644 --- a/Modules/Network/NE2000/ne2000.c +++ b/Modules/Network/NE2000/ne2000.c @@ -199,6 +199,13 @@ int Ne2k_Install(char **Options) Ne2k_WriteReg(base, MAC5, gpNe2k_Cards[ k ].MacAddr[5]); */ + Log_Log("NE2K", "Card %i 0x%04x %02x:%02x:%02x:%02x:%02x:%02x", + k, base, + gpNe2k_Cards[k].MacAddr[0], gpNe2k_Cards[k].MacAddr[1], + gpNe2k_Cards[k].MacAddr[2], gpNe2k_Cards[k].MacAddr[3], + gpNe2k_Cards[k].MacAddr[4], gpNe2k_Cards[k].MacAddr[5] + ); + Log("[NE2K]: Card #%i: IRQ=%i, IOBase=0x%x", k, gpNe2k_Cards[ k ].IRQ, gpNe2k_Cards[ k ].IOBase); Log("MAC Address %x:%x:%x:%x:%x:%x", diff --git a/Modules/Network/RTL8139/main.c b/Modules/Network/RTL8139/main.c new file mode 100644 index 00000000..aa7a4443 --- /dev/null +++ b/Modules/Network/RTL8139/main.c @@ -0,0 +1,124 @@ +/* Acess2 RTL8139 Driver + * - By John Hodge (thePowersGang) + * + * main.c - Driver Core + */ +#define DEBUG 0 +#define VERSION ((0<<8)|50) +#include +#include +#include +#include +#include + +// === CONSTANTS === +enum eRTL8139_Regs +{ + MAC0, MAC1, MAC2, + MAC3, MAC4, MAC5, + MAR0 = 0x08, + MAR1, MAR2, MAR3, + MAR4, MAR5, MAR6, MAR7, + + RBSTART = 0x30, //!< Recieve Buffer Start + // ??, ??, ??, RST, RE, TE, ??, ?? + CMD = 0x37, + IMR = 0x3C, + ISR = 0x3E, + + RCR = 0x44, + + CONFIG1 = 0x52 +}; + +// === TYPES === +typedef struct sCard +{ + Uint16 IOBase; + Uint8 IRQ; + + int NumWaitingPackets; + + void *ReceiveBuffer; + tPAddr PhysReceiveBuffer; + + char Name[2]; + tVFS_Node Node; + Uint8 MacAddr[6]; +} tCard; + +// === PROTOTYPES === + +// === GLOBALS === +MODULE_DEFINE(0, VERSION, RTL8139, RTL8139_Install, NULL, NULL); + int giRTL8139_CardCount; +tCard gpRTL8139_Cards; + +// === CODE === +/** + * \brief Installs the RTL8139 Driver + */ +int RTL8139_Install(char **Options) +{ + int id = -1; + int i = 0; + Uint16 base; + + giRTL8139_CardCount = PCI_CountDevices( 0x10EC, 0x8139, 0 ); + + gpRTL8139_Cards = calloc( giRTL8139_CardCount, sizeof(tCard) ); + + + while( (id = PCI_GetDevice(0x10EC, 0x8139, 0, id)) != -1 ) + { + base = PCI_AssignPort( id, 0, 0x100 ); + gpRTL8139_Cards[i].IOBase = base; + gpRTL8139_Cards[i].IRQ = PCI_GetIRQ( id ); + + // Install IRQ Handler + IRQ_AddHandler(gpRTL8139_Cards[ k ].IRQ, RTL8136_IRQHandler); + + // Power on + outb( base + CONFIG1, 0x00 ); + // Reset (0x10 to CMD) + outb( base + CMD, 0x10 ); + + gpRTL8139_Cards[i].ReceiveBuffer = MM_AllocDMA( 2, 32, &gpRTL8139_Cards[i].PhysReceiveBuffer ); + // Set up recieve buffer + outl(base + RBSTART, (Uint32)gpRTL8139_Cards[i].PhysReceiveBuffer); + // Set IMR to Transmit OK and Receive OK + outw(base + IMR, 0x5); + + // Set recieve buffer size, buffer wrap and recieve mask + outl(base + RCR, 0x8F); + + outb(base + CMD, 0x0C); // Recive Enable and Transmit Enable + + gpRTL8139_Cards[ i ].MacAddr[0] = inb(base+MAC0); + gpRTL8139_Cards[ i ].MacAddr[1] = inb(base+MAC1); + gpRTL8139_Cards[ i ].MacAddr[2] = inb(base+MAC2); + gpRTL8139_Cards[ i ].MacAddr[3] = inb(base+MAC3); + gpRTL8139_Cards[ i ].MacAddr[4] = inb(base+MAC4); + gpRTL8139_Cards[ i ].MacAddr[5] = inb(base+MAC5); + + // Set VFS Node + gpRTL8139_Cards[ i ].Name[0] = '0'+i; + gpRTL8139_Cards[ i ].Name[1] = '\0'; + gpRTL8139_Cards[ i ].Node.ImplPtr = &gpRTL8139_Cards[ i ]; + gpRTL8139_Cards[ i ].Node.NumACLs = 0; + gpRTL8139_Cards[ i ].Node.CTime = now(); + gpRTL8139_Cards[ i ].Node.Write = RTL8139_Write; + gpRTL8139_Cards[ i ].Node.Read = RTL8139_Read; + gpRTL8139_Cards[ i ].Node.IOCtl = RTL8139_IOCtl; + + Log_Log("RTL8139", "Card %i 0x%04x %02x:%02x:%02x:%02x:%02x:%02x", + i, base, + gpRTL8139_Cards[ i ].MacAddr[0], gpRTL8139_Cards[ i ].MacAddr[1], + gpRTL8139_Cards[ i ].MacAddr[2], gpRTL8139_Cards[ i ].MacAddr[3], + gpRTL8139_Cards[ i ].MacAddr[4], gpRTL8139_Cards[ i ].MacAddr[5] + ); + + i ++; + } + return MODULE_ERR_OK; +} diff --git a/Usermode/Applications/mount_src/main.c b/Usermode/Applications/mount_src/main.c index b84e85f4..16081088 100644 --- a/Usermode/Applications/mount_src/main.c +++ b/Usermode/Applications/mount_src/main.c @@ -6,11 +6,11 @@ #include #define MOUNTABLE_FILE "/Acess/Conf/Mountable" -#define MOUNTED_FILE "/Acess/Conf/Mounted" +#define MOUNTED_FILE "/Devices/System/VFS/Mounts" // === PROTOTYPES === void ShowUsage(); - int GetMountDefs(char **spDevice, char **spDir, char **spType, char **spOptions); + int GetMountDefs(char *Ident, char **spDevice, char **spDir, char **spType, char **spOptions); // === CODE === /** @@ -41,6 +41,7 @@ int main(int argc, char *argv[]) { switch(arg[1]) { + // -t :: Filesystem driver to use case 't': sType = argv[++i]; break; case '-': //TODO: Long Arguments @@ -51,11 +52,13 @@ int main(int argc, char *argv[]) continue; } + // Device? if(sDevice == NULL) { sDevice = arg; continue; } + // Directory? if(sDir == NULL) { sDir = arg; continue; @@ -77,7 +80,8 @@ int main(int argc, char *argv[]) if(sDir == NULL || getuid() != 0) { // Check if it is defined in the mounts file - if(GetMountDefs(&sDevice, &sDir, &sType, &sOptions) == 0) + // - At this point sDevice could be a device name or a mount point + if(GetMountDefs(sDevice, &sDevice, &sDir, &sType, &sOptions) == 0) { if(sDir == NULL) fprintf(stderr, "Unable to find '%s' in '%s'\n", @@ -136,12 +140,12 @@ void ShowUsage(char *ProgName) } /** - * \fn int GetMountDefs(char **spDevice, char **spDir, char **spType, char **spOptions) + * \fn int GetMountDefs(char *Ident, char **spDevice, char **spDir, char **spType, char **spOptions) * \brief Reads the mountable definitions file and returns the corresponding entry * \param spDevice Pointer to a string (pointer) determining the device (also is the input for this function) * \note STUB */ -int GetMountDefs(char **spDevice, char **spDir, char **spType, char **spOptions) +int GetMountDefs(char *Ident, char **spDevice, char **spDir, char **spType, char **spOptions) { // TODO: Read the mounts file (after deciding what it will be) return 0;