Bugfixes to usermode 64-bit division, more work on GUI (now sizes almost correctly)
authorJohn Hodge <[email protected]>
Mon, 3 May 2010 14:50:02 +0000 (22:50 +0800)
committerJohn Hodge <[email protected]>
Mon, 3 May 2010 14:50:02 +0000 (22:50 +0800)
Kernel/logging.c
Usermode/Applications/axwin2_src/WM/interface.c
Usermode/Applications/axwin2_src/WM/wm.c
Usermode/Applications/axwin2_src/WM/wm.h
Usermode/Libraries/Makefile.cfg
Usermode/Libraries/Makefile.tpl
Usermode/Libraries/libc.so_src/fileIO.c
Usermode/Libraries/libgcc.so_src/libgcc.c

index f4a23b4..747094d 100644 (file)
@@ -54,10 +54,8 @@ void Log_Warning(char *Ident, char *Message, ...);
 void   Log_Notice(char *Ident, char *Message, ...);
 void   Log_Log(char *Ident, char *Message, ...);
 void   Log_Debug(char *Ident, char *Message, ...);
-//static Uint64        Log_Int_GetIdent(const char *Str);
 
 // === EXPORTS ===
-EXPORT(Log_KernelPanic);
 EXPORT(Log_Panic);
 EXPORT(Log_Error);
 EXPORT(Log_Warning);
index 3876b77..52030f3 100644 (file)
@@ -22,39 +22,40 @@ void Interface_Init(void)
        
        WM_SetFlags(NULL, 0);
        
-       // Create Sidebar
+       // -- Create Sidebar --
        gpInterface_Sidebar = WM_CreateElement(NULL, ELETYPE_TOOLBAR, ELEFLAG_VERTICAL);
        WM_SetSize( gpInterface_Sidebar, giInterface_Width );
-       // Create Main Area and regions within
-       gpInterface_MainArea = WM_CreateElement(NULL, ELETYPE_BOX, ELEFLAG_VERTICAL);
-       gpInterface_HeaderBar = WM_CreateElement(gpInterface_MainArea, ELETYPE_BOX, 0);
-       gpInterface_TabBar = WM_CreateElement(gpInterface_MainArea, ELETYPE_TABBAR, 0);
-       gpInterface_TabContent = WM_CreateElement(gpInterface_MainArea, ELETYPE_BOX, 0);
        
-       // Main segment of the "taskbar"
+       // --- Top segment ---
        area = WM_CreateElement(gpInterface_Sidebar, ELETYPE_BOX, ELEFLAG_VERTICAL);
-       // Menu Button
-       btn = WM_CreateElement(area, ELETYPE_BUTTON, ELEFLAG_NOEXPAND);
+       // ---- Menu Button ----
+       btn = WM_CreateElement(area, ELETYPE_BUTTON, ELEFLAG_NOSTRETCH);
        WM_SetSize(btn, giInterface_Width);
        //text = WM_CreateElement(btn, ELETYPE_IMAGE, ELEFLAG_SCALE);
        //WM_SetText(text, "asset://LogoSmall.sif");
        text = WM_CreateElement(btn, ELETYPE_TEXT, 0);
        WM_SetText(text, "Acess");
        
-       // Plain <hr/> style spacer
+       // ---- Plain <hr/> style spacer ----
        WM_CreateElement(area, ELETYPE_SPACER, 0);
        
        // Windows Go Here
        
-       // Bottom Segment
+       // --- Bottom Segment ---
        area = WM_CreateElement(gpInterface_Sidebar, ELETYPE_BOX, ELEFLAG_VERTICAL|ELEFLAG_ALIGN_END);
        
-       // Plain <hr/> style spacer
+       // ---- Plain <hr/> style spacer ----
        WM_CreateElement(area, ELETYPE_SPACER, 0);
        
-       // Version String
+       // ---- Version String ----
        text = WM_CreateElement(area, ELETYPE_TEXT, ELEFLAG_WRAP);
        WM_SetText(text, "AxWin 1.0");
+       
+       // -- Create Main Area and regions within --
+       gpInterface_MainArea = WM_CreateElement(NULL, ELETYPE_BOX, ELEFLAG_VERTICAL);
+       gpInterface_HeaderBar = WM_CreateElement(gpInterface_MainArea, ELETYPE_BOX, 0);
+       gpInterface_TabBar = WM_CreateElement(gpInterface_MainArea, ELETYPE_TABBAR, 0);
+       gpInterface_TabContent = WM_CreateElement(gpInterface_MainArea, ELETYPE_BOX, 0);
 }
 
 void Interface_Update(void)
index 9ddff76..a8fc96d 100644 (file)
@@ -193,44 +193,38 @@ void WM_UpdateDimensions(tElement *Element, int Pass)
        // Pass 2 - Set sizes and recurse
        for( child = Element->FirstChild; child; child = child->NextSibling )
        {
-               // Cross Size
-               if( child->FixedCross ) {
-                       if( Element->Flags & ELEFLAG_VERTICAL )
-                               child->CachedW = child->FixedCross;
-                       else
-                               child->CachedH = child->FixedCross;
-               }
-               else {
-                        int    cross;
-                       _SysDebug("%p,%p ->MinCross = %i", Element, child, child->MinCross);
-                       // Expand to fill?
-                       // TODO: Extra flag so options are (Expand, Equal, Wrap)
-                       if( child->Flags & ELEFLAG_NOEXPAND )
-                               cross = child->MinCross;
-                       else
-                               cross = fullCross;
-                       
-                       _SysDebug("%p,%p - cross = %i", Element, child, cross);
-                       
-                       if( Element->Flags & ELEFLAG_VERTICAL )
-                               child->CachedW = cross;
-                       else
-                               child->CachedH = cross;
-               }
+                int    cross, with;
                
-               // With size
-               if( child->FixedWith ) {
-                       if( Element->Flags & ELEFLAG_VERTICAL )
-                               child->CachedH = child->FixedWith;
-                       else
-                               child->CachedW = child->FixedWith;
-               }
-               else {
-                       if( Element->Flags & ELEFLAG_VERTICAL )
-                               child->CachedH = dynWith;
-                       else
-                               child->CachedW = dynWith;
-               }
+               _SysDebug("%p,%p ->MinCross = %i", Element, child, child->MinCross);
+
+               
+               // --- Cross Size ---
+               if( child->FixedCross )
+                       cross = child->FixedCross;
+               // Expand to fill?
+               // TODO: Extra flag so options are (Expand, Equal, Wrap)
+               else if( child->Flags & ELEFLAG_NOEXPAND )
+                       cross = child->MinCross;
+               else
+                       cross = fullCross;
+               _SysDebug("%p,%p - cross = %i", Element, child, cross);
+               if( Element->Flags & ELEFLAG_VERTICAL )
+                       child->CachedW = cross;
+               else
+                       child->CachedH = cross;
+               
+               // --- With Size ---
+               if( child->FixedWith)
+                       with = child->FixedWith;
+               else if( child->Flags & ELEFLAG_NOSTRETCH )
+                       with = child->MinWith;
+               else
+                       with = dynWith;
+               _SysDebug("%p,%p - with = %i", Element, child, with);
+               if( Element->Flags & ELEFLAG_VERTICAL )
+                       child->CachedH = with;
+               else
+                       child->CachedW = with;
                
                WM_UpdateDimensions(child, 0);
        }
index 4c25c92..96d488d 100644 (file)
@@ -98,16 +98,18 @@ enum eElementFlags
         * its parent) as is needed to encase the contents of the element.
         * Otherwise, the element will expand to fill all avaliable space.
         */
-       ELEFLAG_NOEXPAND    = 0x040,    //      ELEFLAG_EXPAND      = 0x000
+       ELEFLAG_NOEXPAND    = 0x040,
+       
+       ELEFLAG_NOSTRETCH   = 0x080,
        
        /**
         * \brief Center alignment
         */
-       ELEFLAG_ALIGN_CENTER= 0x080,
+       ELEFLAG_ALIGN_CENTER= 0x100,
        /**
         * \brief Right/Bottom alignment
         */
-       ELEFLAG_ALIGN_END = 0x100
+       ELEFLAG_ALIGN_END = 0x200
 };
 
 /**
index abd8c81..78e39fb 100644 (file)
@@ -7,5 +7,5 @@ MAKEDEP  = $(CC) -M
 
 ASFLAGS  = -felf
 CPPFLAGS = -I$(ACESSDIR)/Usermode/include/
-CFLAGS   = -Wall -fPIC -fno-builtin -fno-stack-protector $(CPPFLAGS)
-LDFLAGS  = -nostdlib -shared -I/Acess/Libs/ld-acess.so -e SoMain -x -L.. -lacess
+CFLAGS   = -g -Wall -fPIC -fno-builtin -fno-stack-protector $(CPPFLAGS)
+LDFLAGS  = -g -nostdlib -shared -I/Acess/Libs/ld-acess.so -e SoMain -x -L.. -lacess
index 678ec07..b501b7d 100644 (file)
@@ -13,7 +13,7 @@ install: $(BIN)
 
 $(BIN): $(OBJ)
        $(LD) $(LDFLAGS) -o $(BIN) $(OBJ)
-       @$(OBJDUMP) -d $(BIN) > $(BIN).dsm
+       @$(OBJDUMP) -d -S $(BIN) > $(BIN).dsm
 
 %.o: %.c
        $(CC) $(CFLAGS) -o $@ -c $<
index 4a6a779..1b1d3f3 100644 (file)
@@ -17,7 +17,7 @@
 #define        _stdout 1\r
 \r
 // === PROTOTYPES ===\r
-EXPORT void    itoa(char *buf, uint64_t num, int base, int minLength, char pad, int bSigned);\r
+EXPORT void    itoa(char *buf, uint64_t num, uint base, int minLength, char pad, int bSigned);\r
 struct sFILE   *get_file_struct();\r
 \r
 // === GLOBALS ===\r
@@ -294,7 +294,7 @@ EXPORT int vsprintf(char * __s, const char *__format, va_list __args)
 */\r
 EXPORT int vsnprintf(char *buf, size_t __maxlen, const char *format, va_list args)\r
 {\r
-       char    tmp[33];\r
+       char    tmp[65];\r
         int    c, minSize;\r
         int    pos = 0;\r
        char    *p;\r
@@ -377,6 +377,9 @@ EXPORT int vsnprintf(char *buf, size_t __maxlen, const char *format, va_list arg
                                buf[pos+2] = 'x';\r
                        }\r
                        pos += 3;\r
+                       arg = va_arg(args, uint32_t);\r
+                       itoa(tmp, arg, 16, minSize, pad, 0);\r
+                       goto sprintf_puts;\r
                        // Fall through to hex\r
                // Unsigned Hexadecimal\r
                case 'x':\r
@@ -405,6 +408,7 @@ EXPORT int vsnprintf(char *buf, size_t __maxlen, const char *format, va_list arg
                        p = (void*)(intptr_t)arg;\r
                sprintf_puts:\r
                        if(!p)  p = "(null)";\r
+                       //_SysDebug("vsnprintf: p = '%s'", p);\r
                        if(buf) {\r
                                while(*p) {\r
                                        if(pos < __maxlen)      buf[pos] = *p;\r
@@ -428,6 +432,8 @@ EXPORT int vsnprintf(char *buf, size_t __maxlen, const char *format, va_list arg
     }\r
        if(buf && pos < __maxlen)       buf[pos] = '\0';\r
        \r
+       //_SysDebug("vsnprintf: buf = '%s'", buf);\r
+       \r
        return pos;\r
 }\r
 \r
@@ -436,13 +442,13 @@ const char cUCDIGITS[] = "0123456789ABCDEF";
  * \fn static void itoa(char *buf, uint64_t num, int base, int minLength, char pad, int bSigned)\r
  * \brief Convert an integer into a character string\r
  */\r
-EXPORT void itoa(char *buf, uint64_t num, int base, int minLength, char pad, int bSigned)\r
+EXPORT void itoa(char *buf, uint64_t num, size_t base, int minLength, char pad, int bSigned)\r
 {\r
-       char    tmpBuf[32];\r
+       char    tmpBuf[64];\r
         int    pos=0, i;\r
 \r
        if(!buf)        return;\r
-       if(base > 16) {\r
+       if(base > 16 || base < 2) {\r
                buf[0] = 0;\r
                return;\r
        }\r
@@ -455,13 +461,13 @@ EXPORT void itoa(char *buf, uint64_t num, int base, int minLength, char pad, int
                bSigned = 0;\r
        \r
        while(num > base-1) {\r
-               tmpBuf[pos] = cUCDIGITS[ num % base ];\r
-               num = (long) num / base;                // Shift {number} right 1 digit\r
-               pos++;\r
+               tmpBuf[pos++] = cUCDIGITS[ num % base ];\r
+               num = (uint64_t) num / (uint64_t)base;          // Shift {number} right 1 digit\r
        }\r
 \r
        tmpBuf[pos++] = cUCDIGITS[ num % base ];                // Last digit of {number}\r
        if(bSigned)     tmpBuf[pos++] = '-';    // Append sign symbol if needed\r
+       \r
        i = 0;\r
        minLength -= pos;\r
        while(minLength-- > 0)  buf[i++] = pad;\r
index 3b0f212..6e7fb08 100644 (file)
@@ -25,14 +25,58 @@ void __stack_chk_fail()
  */
 uint64_t __udivdi3(uint64_t Num, uint64_t Den)
 {
+       #if 0
        uint64_t        ret = 0;
        if(Den == 0)    // Call Div by Zero Error
                __asm__ __volatile__ ("int $0");
+       
+       if(Den == 1)    return Num;
+       if(Den == 2)    return Num >> 1;
+       if(Den == 4)    return Num >> 2;
+       if(Den == 8)    return Num >> 3;
+       if(Den == 16)   return Num >> 4;
+       if(Den == 32)   return Num >> 5;
+       if(Den == 64)   return Num >> 6;
+       if(Den == 128)  return Num >> 7;
+       if(Den == 256)  return Num >> 8;
+       
        while(Num > Den) {
                ret ++;
                Num -= Den;
        }
        return ret;
+       #else
+       uint64_t        P[64], q, n;
+        int    i;
+       
+       if(Den == 0)    __asm__ __volatile__ ("int $0x0");
+       // Common speedups
+       if(Den == 1)    return Num;
+       if(Den == 2)    return Num >> 1;
+       if(Den == 16)   return Num >> 4;
+       
+       
+       // Non-restoring division, from wikipedia
+       // http://en.wikipedia.org/wiki/Division_(digital)
+       P[0] = Num;
+       for( i = 0; i < 64; i ++ )
+       {
+               if( P[i] >= 0 ) {
+                       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;
+               }
+       }
+       
+       n = ~q;
+       n = -n;
+       q += n;
+       
+       return q;
+       #endif
 }
 
 /**
@@ -41,9 +85,28 @@ uint64_t __udivdi3(uint64_t Num, uint64_t Den)
  */
 uint64_t __umoddi3(uint64_t Num, uint64_t Den)
 {
-       if(Den == 0)    // Call Div by Zero Error
-               __asm__ __volatile__ ("int $0");
-       while(Num >= Den)
-               Num -= Den;
+       #if 0
+       if(Den == 0)    __asm__ __volatile__ ("int $0");        // Call Div by Zero Error
+       
+       if(Den == 1)    return 0;
+       if(Den == 2)    return Num & 0x01;
+       if(Den == 4)    return Num & 0x03;
+       if(Den == 8)    return Num & 0x07;
+       if(Den == 16)   return Num & 0x0F;
+       if(Den == 32)   return Num & 0x1F;
+       if(Den == 64)   return Num & 0x3F;
+       if(Den == 128)  return Num & 0x3F;
+       if(Den == 256)  return Num & 0x7F;
+       
+       while(Num >= Den)       Num -= Den;
+       
        return Num;
+       #else
+       if(Den == 0)    __asm__ __volatile__ ("int $0");        // Call Div by Zero Error
+       // Speedups for common operations
+       if(Den == 1)    return 0;
+       if(Den == 2)    return Num & 0x01;
+       if(Den == 16)   return Num & 0x0F;
+       return Num - __udivdi3(Num, Den) * Den;
+       #endif
 }

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