From 35580b646a841d59323953f4dfaf47e678dd9d64 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Mon, 3 May 2010 22:50:02 +0800 Subject: [PATCH] Bugfixes to usermode 64-bit division, more work on GUI (now sizes almost correctly) --- Kernel/logging.c | 2 - .../Applications/axwin2_src/WM/interface.c | 27 +++---- Usermode/Applications/axwin2_src/WM/wm.c | 68 ++++++++---------- Usermode/Applications/axwin2_src/WM/wm.h | 8 ++- Usermode/Libraries/Makefile.cfg | 4 +- Usermode/Libraries/Makefile.tpl | 2 +- Usermode/Libraries/libc.so_src/fileIO.c | 22 +++--- Usermode/Libraries/libgcc.so_src/libgcc.c | 71 +++++++++++++++++-- 8 files changed, 134 insertions(+), 70 deletions(-) diff --git a/Kernel/logging.c b/Kernel/logging.c index f4a23b4b..747094d2 100644 --- a/Kernel/logging.c +++ b/Kernel/logging.c @@ -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); diff --git a/Usermode/Applications/axwin2_src/WM/interface.c b/Usermode/Applications/axwin2_src/WM/interface.c index 3876b77d..52030f3b 100644 --- a/Usermode/Applications/axwin2_src/WM/interface.c +++ b/Usermode/Applications/axwin2_src/WM/interface.c @@ -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
style spacer + // ---- Plain
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
style spacer + // ---- Plain
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) diff --git a/Usermode/Applications/axwin2_src/WM/wm.c b/Usermode/Applications/axwin2_src/WM/wm.c index 9ddff76c..a8fc96db 100644 --- a/Usermode/Applications/axwin2_src/WM/wm.c +++ b/Usermode/Applications/axwin2_src/WM/wm.c @@ -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); } diff --git a/Usermode/Applications/axwin2_src/WM/wm.h b/Usermode/Applications/axwin2_src/WM/wm.h index 4c25c925..96d488d5 100644 --- a/Usermode/Applications/axwin2_src/WM/wm.h +++ b/Usermode/Applications/axwin2_src/WM/wm.h @@ -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 }; /** diff --git a/Usermode/Libraries/Makefile.cfg b/Usermode/Libraries/Makefile.cfg index abd8c812..78e39fb9 100644 --- a/Usermode/Libraries/Makefile.cfg +++ b/Usermode/Libraries/Makefile.cfg @@ -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 diff --git a/Usermode/Libraries/Makefile.tpl b/Usermode/Libraries/Makefile.tpl index 678ec07c..b501b7d2 100644 --- a/Usermode/Libraries/Makefile.tpl +++ b/Usermode/Libraries/Makefile.tpl @@ -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 $< diff --git a/Usermode/Libraries/libc.so_src/fileIO.c b/Usermode/Libraries/libc.so_src/fileIO.c index 4a6a779d..1b1d3f38 100644 --- a/Usermode/Libraries/libc.so_src/fileIO.c +++ b/Usermode/Libraries/libc.so_src/fileIO.c @@ -17,7 +17,7 @@ #define _stdout 1 // === PROTOTYPES === -EXPORT void itoa(char *buf, uint64_t num, int base, int minLength, char pad, int bSigned); +EXPORT void itoa(char *buf, uint64_t num, uint base, int minLength, char pad, int bSigned); struct sFILE *get_file_struct(); // === GLOBALS === @@ -294,7 +294,7 @@ EXPORT int vsprintf(char * __s, const char *__format, va_list __args) */ EXPORT int vsnprintf(char *buf, size_t __maxlen, const char *format, va_list args) { - char tmp[33]; + char tmp[65]; int c, minSize; int pos = 0; char *p; @@ -377,6 +377,9 @@ EXPORT int vsnprintf(char *buf, size_t __maxlen, const char *format, va_list arg buf[pos+2] = 'x'; } pos += 3; + arg = va_arg(args, uint32_t); + itoa(tmp, arg, 16, minSize, pad, 0); + goto sprintf_puts; // Fall through to hex // Unsigned Hexadecimal case 'x': @@ -405,6 +408,7 @@ EXPORT int vsnprintf(char *buf, size_t __maxlen, const char *format, va_list arg p = (void*)(intptr_t)arg; sprintf_puts: if(!p) p = "(null)"; + //_SysDebug("vsnprintf: p = '%s'", p); if(buf) { while(*p) { if(pos < __maxlen) buf[pos] = *p; @@ -428,6 +432,8 @@ EXPORT int vsnprintf(char *buf, size_t __maxlen, const char *format, va_list arg } if(buf && pos < __maxlen) buf[pos] = '\0'; + //_SysDebug("vsnprintf: buf = '%s'", buf); + return pos; } @@ -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) * \brief Convert an integer into a character string */ -EXPORT void itoa(char *buf, uint64_t num, int base, int minLength, char pad, int bSigned) +EXPORT void itoa(char *buf, uint64_t num, size_t base, int minLength, char pad, int bSigned) { - char tmpBuf[32]; + char tmpBuf[64]; int pos=0, i; if(!buf) return; - if(base > 16) { + if(base > 16 || base < 2) { buf[0] = 0; return; } @@ -455,13 +461,13 @@ EXPORT void itoa(char *buf, uint64_t num, int base, int minLength, char pad, int bSigned = 0; while(num > base-1) { - tmpBuf[pos] = cUCDIGITS[ num % base ]; - num = (long) num / base; // Shift {number} right 1 digit - pos++; + tmpBuf[pos++] = cUCDIGITS[ num % base ]; + num = (uint64_t) num / (uint64_t)base; // Shift {number} right 1 digit } tmpBuf[pos++] = cUCDIGITS[ num % base ]; // Last digit of {number} if(bSigned) tmpBuf[pos++] = '-'; // Append sign symbol if needed + i = 0; minLength -= pos; while(minLength-- > 0) buf[i++] = pad; diff --git a/Usermode/Libraries/libgcc.so_src/libgcc.c b/Usermode/Libraries/libgcc.so_src/libgcc.c index 3b0f2124..6e7fb089 100644 --- a/Usermode/Libraries/libgcc.so_src/libgcc.c +++ b/Usermode/Libraries/libgcc.so_src/libgcc.c @@ -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 } -- 2.20.1