From 845d2f0618aa8da08babb53d003440aeb0fb3130 Mon Sep 17 00:00:00 2001 From: siemargl Date: Wed, 27 Apr 2016 19:59:20 +0000 Subject: [PATCH] small fixes. need more git-svn-id: svn://kolibrios.org@6410 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/develop/ktcc/trunk/libc/build.bat | 6 +- .../ktcc/trunk/libc/string/memmove.asm | 4 +- .../develop/ktcc/trunk/libc/string/strcat.c | 2 +- .../develop/ktcc/trunk/libc/string/strcpy.c | 2 +- programs/develop/ktcc/trunk/source/Makefile | 4 +- programs/develop/ktcc/trunk/source/config.h | 4 + .../develop/ktcc/trunk/source/console.asm | 86 +++++++++---------- programs/develop/ktcc/trunk/source/libtcc1.c | 4 +- programs/develop/ktcc/trunk/source/start.asm | 46 +++++----- programs/develop/ktcc/trunk/source/tcc.c | 5 +- 10 files changed, 84 insertions(+), 79 deletions(-) diff --git a/programs/develop/ktcc/trunk/libc/build.bat b/programs/develop/ktcc/trunk/libc/build.bat index 73d2afd643..1547ff2427 100644 --- a/programs/develop/ktcc/trunk/libc/build.bat +++ b/programs/develop/ktcc/trunk/libc/build.bat @@ -6,10 +6,10 @@ echo #################################################### rem #### CONFIG SECTION #### set LIBNAME=libck.a set INCLUDE=include -set CC= +set CC=kos32-tcc set CFLAGS=-c -nostdinc -DGNUC -I"%cd%\%INCLUDE%" -set AR= -set ASM= +set AR=kos32-ar +set ASM=fasm set dirs=stdio memory kolibrisys string stdlib rem #### END OF CONFIG SECTION #### diff --git a/programs/develop/ktcc/trunk/libc/string/memmove.asm b/programs/develop/ktcc/trunk/libc/string/memmove.asm index f7f25dd344..d8b59ac669 100644 --- a/programs/develop/ktcc/trunk/libc/string/memmove.asm +++ b/programs/develop/ktcc/trunk/libc/string/memmove.asm @@ -6,7 +6,7 @@ include 'proc32.inc' public memcpy public memmove -proc memcpy stdcall, to:dword,from:dword,count:dword +proc memcpy c, to:dword,from:dword,count:dword mov ecx,[count] test ecx,ecx @@ -20,7 +20,7 @@ proc memcpy stdcall, to:dword,from:dword,count:dword ret endp -proc memmove stdcall, to:dword,from:dword,count:dword +proc memmove c, to:dword,from:dword,count:dword mov ecx,[count] test ecx,ecx diff --git a/programs/develop/ktcc/trunk/libc/string/strcat.c b/programs/develop/ktcc/trunk/libc/string/strcat.c index 2d1d2c3cd4..ba7340a7f0 100644 --- a/programs/develop/ktcc/trunk/libc/string/strcat.c +++ b/programs/develop/ktcc/trunk/libc/string/strcat.c @@ -2,7 +2,7 @@ char* strcat(char* strDest, const char* strSource) { char* res; res=strDest; - while (*strDest++) ; + while (*strDest) strDest++; while (*strDest++ = *strSource++) ; return res; } diff --git a/programs/develop/ktcc/trunk/libc/string/strcpy.c b/programs/develop/ktcc/trunk/libc/string/strcpy.c index f0327666de..850b51909e 100644 --- a/programs/develop/ktcc/trunk/libc/string/strcpy.c +++ b/programs/develop/ktcc/trunk/libc/string/strcpy.c @@ -2,6 +2,6 @@ char* strcpy(char* strDest,char* strSource) { char* res; res=strDest; - while(*strDest++ == strSource++) ; + while(*strDest++ = *strSource++) ; return res; } \ No newline at end of file diff --git a/programs/develop/ktcc/trunk/source/Makefile b/programs/develop/ktcc/trunk/source/Makefile index 63d75e633d..cf1d18bb32 100644 --- a/programs/develop/ktcc/trunk/source/Makefile +++ b/programs/develop/ktcc/trunk/source/Makefile @@ -1,4 +1,4 @@ OUTFILE = ktcc.kex -OBJS = tcc.o console.o +OBJS = tcc.o console.o getcwd.o CGLAGS =-O2 -g -Wall -mpreferred-stack-boundary=2 -march=i386 -falign-functions=0 -fno-strict-aliasing -include $(MENUETDEV)/makefiles/Makefile_for_program +include Makefile_for_program diff --git a/programs/develop/ktcc/trunk/source/config.h b/programs/develop/ktcc/trunk/source/config.h index 87d0537419..8cc1019c55 100644 --- a/programs/develop/ktcc/trunk/source/config.h +++ b/programs/develop/ktcc/trunk/source/config.h @@ -5,3 +5,7 @@ #define TCC_VERSION "0.9.23" //#define TCC_TARGET_PE #define TCC_TARGET_MEOS + +/* enable bound checking code */ +//#define CONFIG_TCC_BCHECK 1 + diff --git a/programs/develop/ktcc/trunk/source/console.asm b/programs/develop/ktcc/trunk/source/console.asm index 83c464abbf..309379b4ca 100644 --- a/programs/develop/ktcc/trunk/source/console.asm +++ b/programs/develop/ktcc/trunk/source/console.asm @@ -8,68 +8,68 @@ public console_exit align 4 console_init: - pushad + pushad - mov eax,[console_init_status] - test eax,eax - jnz console_initializated + mov eax,[console_init_status] + test eax,eax + jnz console_initializated - mov [console_init_status],1 + mov [console_init_status],1 - mov eax,68 - mov ebx,19 - mov ecx,console_path - int 0x40 + mov eax,68 + mov ebx,19 + mov ecx,console_path + int 0x40 - test eax,eax - jz console_not_loaded + test eax,eax + jz console_not_loaded - mov ebx,[eax+4] - mov [con_start],ebx + mov ebx,[eax+4] + mov [con_start],ebx - mov ebx,[eax+4+16] - mov [con_init],ebx + mov ebx,[eax+4+16] + mov [con_init],ebx - mov ebx,[eax+4+32] - mov [con_printf],ebx + mov ebx,[eax+4+32] + mov [con_printf],ebx - push 1 - call [con_start] + push 1 + call [con_start] - push caption - push -1 - push -1 - push -1 - push -1 - call [con_init] + push caption + push -1 + push -1 + push -1 + push -1 + call [con_init] - console_not_loaded: + console_not_loaded: - console_initializated: + console_initializated: - popad + popad - ret + ret align 4 console_printf: - pop [return_addres] + pop [return_addres] - call [con_printf] - ;add esp,8 + call [con_printf] + ;add esp,8 - push [return_addres] + push [return_addres] - ret + ret align 4 console_exit: - push 0 - call [con_exit] + push 0 + call [con_exit] - ret + ret ;----------------------------- @@ -77,9 +77,9 @@ console_path db '/sys/dll/console.obj',0 caption db 'Console',0 align 4 -con_start rd 1 -con_init rd 1 -con_printf rd 1 -con_exit rd 1 -console_init_status rd 1 -return_addres rd 1 +con_start rd 1 +con_init rd 1 +con_printf rd 1 +con_exit rd 1 +console_init_status rd 1 +return_addres rd 1 diff --git a/programs/develop/ktcc/trunk/source/libtcc1.c b/programs/develop/ktcc/trunk/source/libtcc1.c index a06016e4fb..11393e30c5 100644 --- a/programs/develop/ktcc/trunk/source/libtcc1.c +++ b/programs/develop/ktcc/trunk/source/libtcc1.c @@ -399,7 +399,7 @@ long long __moddi3(long long u, long long v) if (vv.s.high < 0) vv.ll = __negdi2 (vv.ll); - __udivmoddi4 (uu.ll, vv.ll, &w); + __udivmoddi4 (uu.ll, vv.ll, (UDWtype *) &w); if (c) w = __negdi2 (w); return w; @@ -466,7 +466,7 @@ long long __shldi3(long long a, int b) u.s.high = (unsigned)u.s.low << (b - 32); u.s.low = 0; } else if (b != 0) { - u.s.high = ((unsigned)u.s.high << b) | (u.s.low >> (32 - b)); + u.s.high = ((unsigned)u.s.high << b) | ((unsigned)u.s.low >> (32 - b)); u.s.low = (unsigned)u.s.low << b; } return u.ll; diff --git a/programs/develop/ktcc/trunk/source/start.asm b/programs/develop/ktcc/trunk/source/start.asm index 2f81ac6571..0819f9b2c1 100644 --- a/programs/develop/ktcc/trunk/source/start.asm +++ b/programs/develop/ktcc/trunk/source/start.asm @@ -8,14 +8,14 @@ __DEBUG__=0 ;start_: virtual at 0 - db 'MENUET01' ; 1. Magic number (8 bytes) - dd 0x01 ; 2. Version of executable file - dd start ; 3. Start address - dd 0x0 ; 4. Size of image - dd 0x100000 ; 5. Size of needed memory - dd 0x100000 ; 6. Pointer to stack -hparams dd 0x0 ; 7. Pointer to program arguments -hpath dd 0x0 ; 8. Pointer to program path + db 'MENUET01' ; 1. Magic number (8 bytes) + dd 0x01 ; 2. Version of executable file + dd start ; 3. Start address + dd 0x0 ; 4. Size of image + dd 0x100000 ; 5. Size of needed memory + dd 0x100000 ; 6. Pointer to stack +hparams dd 0x0 ; 7. Pointer to program arguments +hpath dd 0x0 ; 8. Pointer to program path end virtual start: @@ -28,12 +28,12 @@ start: ;DEBUGF ' path "%s"\n params "%s"\n', .path, .params ; check for overflow mov al, [path+buf_len-1] - or al, [params+buf_len-1] + or al, [params+buf_len-1] jnz .crash ; check if path written by OS mov eax, [hparams] test eax, eax - jz .without_path + jz .without_path mov eax, path .without_path: mov esi, eax @@ -41,21 +41,21 @@ start: ; retrieving parameters mov esi, params xor edx, edx ; dl - идёт параметр(1) или разделители(0) - ; dh - символ с которого начался параметр (1 кавычки, 0 остальное) + ; dh - символ с которого начался параметр (1 кавычки, 0 остальное) mov ecx, 1 ; cl = 1 - ; ch = 0 просто ноль + ; ch = 0 просто ноль .parse: lodsb test al, al - jz .run + jz .run test dl, dl jnz .findendparam - ;{если был разделитель + ;{если был разделитель cmp al, ' ' - jz .parse ;загружен пробел, грузим следующий символ + jz .parse ;загружен пробел, грузим следующий символ mov dl, cl ;начинается параметр cmp al, '"' - jz @f ;загружены кавычки + jz @f ;загружены кавычки mov dh, ch ;параметр без кавычек dec esi call push_param @@ -69,9 +69,9 @@ start: .findendparam: test dh, dh - jz @f ; без кавычек + jz @f ; без кавычек cmp al, '"' - jz .clear + jz .clear jmp .parse @@: cmp al, ' ' @@ -100,7 +100,7 @@ end if xor eax,eax dec eax int 0x40 - dd -1 + dd -1 .crash: ;DEBUGF 'E:buffer overflowed\n' jmp .exit @@ -127,10 +127,10 @@ public path as '__path' section '.bss' buf_len = 0x400 max_parameters=0x20 -argc rd 1 -argv rd max_parameters -path rb buf_len -params rb buf_len +argc rd 1 +argv rd max_parameters +path rb buf_len +params rb buf_len ;section '.data' ;include_debug_strings ; ALWAYS present in data section \ No newline at end of file diff --git a/programs/develop/ktcc/trunk/source/tcc.c b/programs/develop/ktcc/trunk/source/tcc.c index b37bf29693..51158270f0 100644 --- a/programs/develop/ktcc/trunk/source/tcc.c +++ b/programs/develop/ktcc/trunk/source/tcc.c @@ -1034,7 +1034,8 @@ static inline void tcc_free(void *ptr) #ifdef MEM_DEBUG mem_cur_size -= malloc_usable_size(ptr); #endif - free(ptr); +//2016-04-27 siemargl commented to fix crash temporally. Need to fix +// free(ptr); } static void *tcc_malloc(unsigned long size) @@ -10591,7 +10592,7 @@ int parse_args(TCCState *s, int argc, char **argv) return optind; } -int app_main(int argc, char **argv) +int main(int argc, char **argv) { int i; TCCState *s;