Altered & Renamed LookupString, Added DrvUtil_SetIdent
authorJohn Hodge <tpg@prelude.(none)>
Sat, 23 Jan 2010 11:48:18 +0000 (19:48 +0800)
committerJohn Hodge <tpg@prelude.(none)>
Sat, 23 Jan 2010 11:48:18 +0000 (19:48 +0800)
- Both now check the user memory before using it

Kernel/Makefile.BuildNum
Kernel/drv/vterm.c
Kernel/include/acess.h
Kernel/include/tpl_drv_terminal.h
Kernel/lib.c
Kernel/vfs/fs/fat.c
Modules/ATA/mbr.c
Modules/FDD/fdd.c
Modules/IPStack/main.c
Modules/Makefile.tpl
Modules/NE2000/ne2000.c

index 2c33bfc..3ef05ea 100644 (file)
@@ -1 +1 @@
-BUILD_NUM = 1389
+BUILD_NUM = 1398
index 0e66601..76b7f1e 100644 (file)
@@ -318,7 +318,7 @@ Uint64 VT_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
                break;
        
        case TERM_MODE_FB:
-       case TERM_MODE_OPENGL:
+       //case TERM_MODE_:
                while(pos < Length)
                {
                        while(term->InputRead == term->InputWrite)      Threads_Yield();
@@ -922,8 +922,8 @@ void VT_int_ChangeMode(tVTerm *Term, int NewMode)
                free(Term->Text);
                Term->Buffer = calloc( Term->Width*Term->Height, sizeof(Uint32) );
                break;
-       case TERM_MODE_OPENGL:
-               return;
+       //case TERM_MODE_OPENGL:
+       //      return;
        }
        
        Term->Mode = NewMode;
index d4df34b..930e323 100644 (file)
@@ -293,6 +293,7 @@ extern Uint32       BigEndian32(Uint32 Val);
  * \name Strings
  * \{
  */
+extern int     sprintf(char *__s, const char *__format, ...);
 extern Uint    strlen(const char *Str);
 extern char    *strcpy(char *__dest, const char *__src);
 extern int     strcmp(const char *__str1, const char *__str2);
@@ -304,7 +305,8 @@ extern int  strpos8(const char *str, Uint32 search);
 extern void    itoa(char *buf, Uint num, int base, int minLength, char pad);
 extern int     ReadUTF8(Uint8 *str, Uint32 *Val);
 extern int     WriteUTF8(Uint8 *str, Uint32 Val);
-extern int     LookupString(char **Array, char *Needle);
+extern int     ModUtil_SetIdent(char *Dest, char *Value);
+extern int     ModUtil_LookupString(char **Array, char *Needle);
 extern Uint8   ByteSum(void *Ptr, int Size);
 /**
  * \}
index fa90c86..907cc14 100644 (file)
@@ -97,13 +97,15 @@ enum eTplTerminal_Modes {
         */\r
        TERM_MODE_FB,\r
        \r
+       TERM_MODE_2DACCEL,\r
+       \r
        /**\r
         * \brief OpenGL 2D/3D\r
         * Writes to the terminal file will send 3D commands\r
         * Reads will return UTF-32 characters\r
         * \note May or may not stay in the spec\r
         */\r
-       TERM_MODE_OPENGL,\r
+       TERM_MODE_3D,\r
        \r
        /**\r
         * \brief Number of terminal modes\r
@@ -111,5 +113,17 @@ enum eTplTerminal_Modes {
        NUM_TERM_MODES\r
 };\r
 \r
+enum eTplTerminal_2D_Commands\r
+{\r
+       TERM_2DCMD_NOP,\r
+       \r
+       /**\r
+        * (Uint16 X, Y, W, H, Uint32 Data[])\r
+        * \param X,Y   Coordinates of Top-Left corner\r
+        * \param W,H   Dimensions\r
+        * \param Data  32-bpp pixel data\r
+        */\r
+       TERM_2DCMD_PUSH,\r
+};\r
 \r
 #endif\r
index db01450..f99f58a 100644 (file)
@@ -55,6 +55,148 @@ void itoa(char *buf, Uint num, int base, int minLength, char pad)
        buf[i] = 0;
 }
 
+#define PUTCH(c)       do{if(pos==__maxlen)break;if(__s){__s[pos++]=(c);}else{pos++;}}while(0)
+int vsnprintf(char *__s, size_t __maxlen, const char *__format, va_list args)
+{
+       char    c, pad = ' ';
+        int    minSize = 0;
+       char    tmpBuf[34];     // For Integers
+       char    *p = NULL;
+        int    isLongLong = 0;
+       Uint64  val;
+       size_t  pos = 0;
+       
+       while((c = *__format++) != 0)
+       {
+               // Non control character
+               if(c != '%') { PUTCH(c); continue; }
+               
+               c = *__format++;
+               
+               // Literal %
+               if(c == '%') { PUTCH('%'); continue; }
+               
+               // Pointer - Done first for debugging
+               if(c == 'p') {
+                       Uint    ptr = va_arg(args, Uint);
+                       PUTCH('*');     PUTCH('0');     PUTCH('x');
+                       p = tmpBuf;
+                       itoa(p, ptr, 16, BITS/4, '0');
+                       goto printString;
+               }
+               
+               // Get Argument
+               val = va_arg(args, Uint);
+               
+               // - 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++;
+                       }
+               }
+               
+               // - Default, Long or LongLong?
+               isLongLong = 0;
+               if(c == 'l')    // Long is actually the default on x86
+               {
+                       c = *__format++;
+                       if(c == 'l') {
+                               #if BITS == 32
+                               val |= (Uint64)va_arg(args, Uint) << 32;
+                               #endif
+                               c = *__format++;
+                               isLongLong = 1;
+                       }
+               }
+               
+               // - Now get the format code
+               p = tmpBuf;
+               switch(c)
+               {
+               case 'd':
+               case 'i':
+                       if( (isLongLong && val >> 63) || (!isLongLong && val >> 31) ) {
+                               PUTCH('-');
+                               val = -val;
+                       }
+                       itoa(p, val, 10, minSize, pad);
+                       goto printString;
+               case 'u':
+                       itoa(p, val, 10, minSize, pad);
+                       goto printString;
+               case 'x':
+                       itoa(p, val, 16, minSize, pad);
+                       goto printString;
+               case 'o':
+                       itoa(p, val, 8, minSize, pad);
+                       goto printString;
+               case 'b':
+                       itoa(p, val, 2, minSize, pad);
+                       goto printString;
+
+               case 'B':       //Boolean
+                       if(val) p = "True";
+                       else    p = "False";
+                       goto printString;
+               
+               // String - Null Terminated Array
+               case 's':
+                       p = (char*)(Uint)val;
+               printString:
+                       if(!p)          p = "(null)";
+                       while(*p)       PUTCH(*p++);
+                       break;
+               
+               case 'C':       // Non-Null Terminated Character Array
+                       p = (char*)(Uint)val;
+                       if(!p)  goto printString;
+                       while(minSize--)        PUTCH(*p++);
+                       break;
+               
+               // Single Character
+               case 'c':
+               default:
+                       PUTCH( (Uint8)val );
+                       break;
+               }
+       }
+       
+       if(__s && pos != __maxlen)
+               __s[pos] = '\0';
+               
+       
+       return pos;
+}
+#undef PUTCH
+
+/**
+ */
+int sprintf(char *__s, const char *__format, ...)
+{
+       va_list args;
+        int    ret;
+       
+       va_start(args, __format);
+       ret = vsnprintf(__s, -1, __format, args);
+       va_end(args);
+       
+       return ret;
+}
+
 /**
  * \fn int tolower(int c)
  * \brief Converts a character to lower case
@@ -125,6 +267,19 @@ char *strcpy(char *__str1, const char *__str2)
        return __str1;
 }
 
+/**
+ * \fn char *strcpy(const char *__str1, const char *__str2)
+ * \brief Copy a string to a new location
+ */
+char *strncpy(char *__str1, const char *__str2, size_t max)
+{
+       while(*__str2 && max-- >= 1)
+               *__str1++ = *__str2++;
+       if(max)
+               *__str1 = '\0'; // Terminate String
+       return __str1;
+}
+
 /**
  * \fn int strcmp(const char *str1, const char *str2)
  * \brief Compare two strings return the difference between
@@ -411,9 +566,10 @@ int CheckMem(void *Mem, int NumBytes)
  * \brief Search a string array for \a Needle
  * \note Helper function for eTplDrv_IOCtl::DRV_IOCTL_LOOKUP
  */
-int LookupString(char **Array, char *Needle)
+int ModUtil_LookupString(char **Array, char *Needle)
 {
         int    i;
+       if( !CheckString(Needle) )      return -1;
        for( i = 0; Array[i]; i++ )
        {
                if(strcmp(Array[i], Needle) == 0)       return i;
@@ -421,15 +577,23 @@ int LookupString(char **Array, char *Needle)
        return -1;
 }
 
+int ModUtil_SetIdent(char *Dest, char *Value)
+{
+       if( !CheckMem(Dest, 32) )       return -1;
+       strncpy(Dest, Value, 32);
+       return 1;
+}
+
 EXPORT(strlen);
 EXPORT(strdup);
 EXPORT(strcmp);
 EXPORT(strncmp);
 EXPORT(strcpy);
-//EXPORT(strncpy);
+EXPORT(strncpy);
 
 EXPORT(timestamp);
 EXPORT(ReadUTF8);
 EXPORT(CheckMem);
 EXPORT(CheckString);
-EXPORT(LookupString);
+EXPORT(ModUtil_LookupString);
+EXPORT(ModUtil_SetIdent);
index c840bdd..3ebe89a 100644 (file)
@@ -116,6 +116,7 @@ tVFS_Node *FAT_InitDevice(char *Device, char **options)
                case FAT12:     sFatType = "FAT12";     break;\r
                case FAT16:     sFatType = "FAT16";     break;\r
                case FAT32:     sFatType = "FAT32";     break;\r
+               default:        sFatType = "UNKNOWN";   break;\r
                }\r
                if(iSize <= 2*1024) {\r
                        sSize = "KiB";\r
index de02505..45ade88 100644 (file)
@@ -34,8 +34,7 @@ void ATA_ParseMBR(int Disk)
        for( i = 0; i < 4; i ++ )
        {
                if( mbr.Parts[i].SystemID == 0 )        continue;
-               if(
-                       mbr.Parts[i].Boot == 0x0 || mbr.Parts[i].Boot == 0x80   // LBA 28
+               if(     mbr.Parts[i].Boot == 0x0 || mbr.Parts[i].Boot == 0x80   // LBA 28
                ||      mbr.Parts[i].Boot == 0x1 || mbr.Parts[i].Boot == 0x81   // LBA 48
                        )
                {
index 69d3a55..6b55f17 100644 (file)
@@ -277,23 +277,12 @@ int FDD_IOCtl(tVFS_Node *Node, int ID, void *Data)
 {\r
        switch(ID)\r
        {\r
-       case DRV_IOCTL_TYPE:\r
-               return DRV_TYPE_DISK;\r
+       case DRV_IOCTL_TYPE:    return DRV_TYPE_DISK;\r
+       case DRV_IOCTL_IDENT:   return ModUtil_SetIdent(Data, "FDD");\r
+       case DRV_IOCTL_VERSION: return FDD_VERSION;\r
+       case DRV_IOCTL_LOOKUP:  return ModUtil_LookupString((char**)casIOCTLS, Data);\r
        \r
-       case DRV_IOCTL_IDENT:\r
-               if(!CheckMem(Data, 4))  return -1;\r
-               memcpy(Data, "FDD\0", 4);\r
-               return 1;\r
-       \r
-       case DRV_IOCTL_VERSION:\r
-               return FDD_VERSION;\r
-       \r
-       case DRV_IOCTL_LOOKUP:\r
-               if(!CheckString(Data))  return -1;\r
-               return LookupString((char**)casIOCTLS, Data);\r
-       \r
-       case DISK_IOCTL_GETBLOCKSIZE:\r
-               return 512;     \r
+       case DISK_IOCTL_GETBLOCKSIZE:   return 512;     \r
        \r
        default:\r
                return 0;\r
index 5f34d9a..01e65f9 100644 (file)
@@ -4,6 +4,7 @@
  */
 #define DEBUG  0
 #define VERSION        VER2(0,10)
+#define IDENT  IPStack
 #include "ipstack.h"
 #include "link.h"
 #include <modules.h>
@@ -30,7 +31,7 @@ tVFS_Node     *IPStack_FindDir(tVFS_Node *Node, char *Name);
 tAdapter       *IPStack_GetAdapter(char *Path);
 
 // === GLOBALS ===
-MODULE_DEFINE(0, VERSION, IPStack, IPStack_Install, NULL, NULL);
+MODULE_DEFINE(0, VERSION, IDENT, IPStack_Install, NULL, NULL);
 tDevFS_Driver  gIP_DriverInfo = {
        NULL, "ip",
        {
@@ -180,8 +181,7 @@ int IPStack_IOCtlRoot(tVFS_Node *Node, int ID, void *Data)
                return DRV_TYPE_MISC;
        
        case DRV_IOCTL_IDENT:
-               if( !CheckMem( Data, 4 ) )      LEAVE_RET('i', -1);
-               memcpy(Data, "IP\0\0", 4);
+               tmp = ModUtil_SetIdent(Data, STR(IDENT));
                LEAVE('i', 1);
                return 1;
        
@@ -190,9 +190,7 @@ int IPStack_IOCtlRoot(tVFS_Node *Node, int ID, void *Data)
                return VERSION;
        
        case DRV_IOCTL_LOOKUP:
-               if( !CheckString( Data ) )      LEAVE_RET('i', -1);
-               LOG("Lookup '%s'", Data);
-               tmp = LookupString( (char**)casIOCtls_Root, (char*)Data );
+               tmp = ModUtil_LookupString( (char**)casIOCtls_Root, (char*)Data );
                LEAVE('i', tmp);
                return tmp;
                
@@ -236,8 +234,7 @@ int IPStack_IOCtl(tVFS_Node *Node, int ID, void *Data)
                return DRV_TYPE_MISC;
        
        case DRV_IOCTL_IDENT:
-               if( !CheckMem( Data, 4 ) )      LEAVE_RET('i', -1);
-               memcpy(Data, "IP\0\0", 4);
+               tmp = ModUtil_SetIdent(Data, STR(IDENT));
                LEAVE('i', 1);
                return 1;
        
@@ -246,9 +243,7 @@ int IPStack_IOCtl(tVFS_Node *Node, int ID, void *Data)
                return VERSION;
        
        case DRV_IOCTL_LOOKUP:
-               if( !CheckString( Data ) )      LEAVE_RET('i', -1);
-               LOG("Lookup '%s'", Data);
-               tmp = LookupString( (char**)casIOCtls_Iface, (char*)Data );
+               tmp = ModUtil_LookupString( (char**)casIOCtls_Iface, (char*)Data );
                LEAVE('i', tmp);
                return tmp;
        
index 0627559..ae6d574 100644 (file)
@@ -4,9 +4,13 @@
 
 _CPPFLAGS := $(CPPFLAGS)
 
--include ../../Makefile.cfg
+CFGFILES = 
+CFGFILES += $(shell test -f ../../Makefile.cfg && echo ../../Makefile.cfg)
+CFGFILES += $(shell test -f ../Makefile.cfg && echo ../Makefile.cfg)
+CFGFILES += $(shell test -f Makefile.cfg && echo Makefile.cfg)
+-include $(CFGFILES)
 
-CPPFLAGS = -I../../Kernel/include -I../../Kernel/arch/$(ARCHDIR)/include -DARCH=$(ARCH) $(_CPPFLAGS)
+CPPFLAGS = -I$(ACESSDIR)/Kernel/include -I$(ACESSDIR)/Kernel/arch/$(ARCHDIR)/include -DARCH=$(ARCH) $(_CPPFLAGS)
 CFLAGS = -Wall -Werror -fno-stack-protector $(CPPFLAGS)
 
 OBJ := $(addsuffix .$(ARCH),$(OBJ))
@@ -28,12 +32,12 @@ install: $(BIN)
 
 $(BIN): $(OBJ)
        @echo --- $(LD) -o $@
-       @$(LD) -T ../link.ld -shared -nostdlib -o $@ $(OBJ)
+       @$(LD) -T $(ACESSDIR)/Modules/link.ld -shared -nostdlib -o $@ $(OBJ)
        @$(OBJDUMP) -d $(BIN) > $(BIN).dsm
        @echo --- $(LD) -o $(KOBJ)
        @$(CC) -Wl,-r -nostdlib -o $(KOBJ) $(OBJ)
 
-%.o.$(ARCH): %.c Makefile ../Makefile.tpl ../../Makefile.cfg 
+%.o.$(ARCH): %.c Makefile ../Makefile.tpl $(CFGFILES)
        @echo --- $(CC) -o $@
        @$(CC) $(CFLAGS) -o $@ -c $<
        @$(CC) -M $(CPPFLAGS) -MT $@ -o $*.d.$(ARCH) $<
index 99abbb3..76e4379 100644 (file)
@@ -257,24 +257,16 @@ int Ne2k_IOCtl(tVFS_Node *Node, int ID, void *Data)
                return DRV_TYPE_NETWORK;
        
        case DRV_IOCTL_IDENT:
-               if(!CheckMem(Data, 4)) {
-                       LEAVE('i', -1);
-                       return -1;
-               }
-               memcpy(Data, "NE2K", 4);
-               LEAVE('i', 1);
-               return 1;
+               tmp = ModUtil_SetIdent(Data, "Ne2k");
+               LEAVE('i', tmp);
+               return tmp;
        
        case DRV_IOCTL_VERSION:
                LEAVE('x', VERSION);
                return VERSION;
        
        case DRV_IOCTL_LOOKUP:
-               if( !CheckString(Data) ) {
-                       LEAVE('i', -1);
-                       return -1;
-               }
-               tmp = LookupString( (char**)casIOCtls, Data );
+               tmp = ModUtil_LookupString( (char**)casIOCtls, Data );
                LEAVE('i', tmp);
                return tmp;
        }

UCC git Repository :: git.ucc.asn.au