From 48ecbd910496490f1eb2134909e51c2b867c31c9 Mon Sep 17 00:00:00 2001 From: andrew_programmer Date: Mon, 14 Jan 2008 19:33:34 +0000 Subject: [PATCH] Mathematical functions are added some. It is added makefile for compilation of programs under KolibriOS with the help gcc. git-svn-id: svn://kolibrios.org@696 a494cfbc-eb01-0410-851d-a64ba20cac60 --- .../libc/gcc compile programs/README.txt | 3 + .../trunk/libc/gcc compile programs/makefile | 22 ++++ .../trunk/libc/gcc compile programs/start.asm | 102 ++++++++++++++++++ .../develop/ktcc/trunk/libc/include/stdlib.h | 6 ++ .../ktcc/trunk/libc/kolibrisys/sound.asm | 16 +-- programs/develop/ktcc/trunk/libc/makefile | 2 +- .../develop/ktcc/trunk/libc/math/ceil.asm | 30 ++++++ .../develop/ktcc/trunk/libc/math/ceilf.asm | 30 ++++++ .../develop/ktcc/trunk/libc/math/fabs.asm | 14 +++ .../develop/ktcc/trunk/libc/math/fabsf.asm | 14 +++ .../develop/ktcc/trunk/libc/math/floor.asm | 29 +++++ .../develop/ktcc/trunk/libc/math/floorf.asm | 29 +++++ .../develop/ktcc/trunk/libc/math/sqrt.asm | 14 +++ .../develop/ktcc/trunk/libc/math/sqrtf.asm | 14 +++ .../develop/ktcc/trunk/libc/stdlib/random.c | 15 +++ 15 files changed, 331 insertions(+), 9 deletions(-) create mode 100644 programs/develop/ktcc/trunk/libc/gcc compile programs/README.txt create mode 100644 programs/develop/ktcc/trunk/libc/gcc compile programs/makefile create mode 100644 programs/develop/ktcc/trunk/libc/gcc compile programs/start.asm create mode 100644 programs/develop/ktcc/trunk/libc/math/ceil.asm create mode 100644 programs/develop/ktcc/trunk/libc/math/ceilf.asm create mode 100644 programs/develop/ktcc/trunk/libc/math/fabs.asm create mode 100644 programs/develop/ktcc/trunk/libc/math/fabsf.asm create mode 100644 programs/develop/ktcc/trunk/libc/math/floor.asm create mode 100644 programs/develop/ktcc/trunk/libc/math/floorf.asm create mode 100644 programs/develop/ktcc/trunk/libc/math/sqrt.asm create mode 100644 programs/develop/ktcc/trunk/libc/math/sqrtf.asm create mode 100644 programs/develop/ktcc/trunk/libc/stdlib/random.c diff --git a/programs/develop/ktcc/trunk/libc/gcc compile programs/README.txt b/programs/develop/ktcc/trunk/libc/gcc compile programs/README.txt new file mode 100644 index 0000000000..2177efb488 --- /dev/null +++ b/programs/develop/ktcc/trunk/libc/gcc compile programs/README.txt @@ -0,0 +1,3 @@ +В этом каталоге содержится 2 файла, необходимых для сборки программ для KolibriOS при помощи gcc. + +In this catalogue contains 2 files necessary for assembly of programs for KolibriOS with the help gcc. diff --git a/programs/develop/ktcc/trunk/libc/gcc compile programs/makefile b/programs/develop/ktcc/trunk/libc/gcc compile programs/makefile new file mode 100644 index 0000000000..79397d5ec9 --- /dev/null +++ b/programs/develop/ktcc/trunk/libc/gcc compile programs/makefile @@ -0,0 +1,22 @@ +OUTFILE = test.kex +INPUT = test.c +OUTPUT = test.o +OBJS = start.o test.o + + +.SUFFIXES: .asm .o + +$(OUTFILE) : $(OBJS) + fasm start.asm start.o + gcc -c $(INPUT) -nostdinc -m32 -I/home/andrew/kolibri/develop/include/ + ld -nostdlib -T kolibri.ld -n -m elf_i386 -L/home/andrew/kolibri/develop/lib/ -o $(OUTFILE) $(OBJS) -lck + objcopy $(OUTFILE) -O binary + +.asm.o: + fasm $*.asm + +.c.o: + gcc -c $*.c + +clean : + del *.o diff --git a/programs/develop/ktcc/trunk/libc/gcc compile programs/start.asm b/programs/develop/ktcc/trunk/libc/gcc compile programs/start.asm new file mode 100644 index 0000000000..b90ad4f909 --- /dev/null +++ b/programs/develop/ktcc/trunk/libc/gcc compile programs/start.asm @@ -0,0 +1,102 @@ +format ELF + +section '.text' executable + +public start_ + +extrn main + +buf_len = 0x400 +max_parameters=0x20 + +start_: + 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 params ; 7. Pointer to program arguments +hpath dd path ; 8. Pointer to program path + + start__: + + ;init heap of memory + mov eax,68 + mov ebx,11 + int 0x40 + + mov ebx,path + mov ecx,dword buf_len + add ebx,ecx + + next_simbol_check: + xor eax,eax + mov al,[ebx] + cmp al,'/' + je simbol_fined + dec ebx + dec ecx + jnz next_simbol_check + + simbol_fined: + inc ebx + + mov [argc],dword 1 + mov edx,argv + mov [edx],ebx ;argument number 0 - program name + + cmp [params],byte 0 + je exit_find_params + + mov [argc],dword 2 + mov ebx,params + add edx,4 + mov [edx],ebx + + next_symbol_parse: + xor eax,eax + mov al,[ebx] + test al,al + jz exit_find_params + cmp al,' ' + je save_param + + inc ebx + jmp next_symbol_parse + save_param: + + mov [ebx],byte 0 + inc ebx + add edx,4 + mov [edx],ebx + inc [argc] + + cmp [argc],max_parameters + jae exit_find_params + + jmp next_symbol_parse + + exit_find_params: + + push argv + push [argc] + + call main +exit: + + xor eax,eax + dec eax + int 0x40 + dd -1 +crash: + jmp exit + +public params as '__argv' +public path as '__path' + +section '.bss' +argc rd 1 +argv rd max_parameters +path rb buf_len +params rb buf_len diff --git a/programs/develop/ktcc/trunk/libc/include/stdlib.h b/programs/develop/ktcc/trunk/libc/include/stdlib.h index 71f2295aae..608113357d 100644 --- a/programs/develop/ktcc/trunk/libc/include/stdlib.h +++ b/programs/develop/ktcc/trunk/libc/include/stdlib.h @@ -2,6 +2,8 @@ #define stdlib_h #include "kolibrisys.h" +#define RAND_MAX 65535 + //#define isspace(c) ((c)==' ') #define abs(i) (((i)<0)?(-(i)):(i)) @@ -15,4 +17,8 @@ extern void itoa(int n,char* s); extern void* stdcall malloc(dword size); extern void stdcall free(void *pointer); extern void* stdcall realloc(void* pointer,dword size); + +extern int rand (void); +extern void srand (unsigned int seed); + #endif \ No newline at end of file diff --git a/programs/develop/ktcc/trunk/libc/kolibrisys/sound.asm b/programs/develop/ktcc/trunk/libc/kolibrisys/sound.asm index 209ba5b23f..2b6d4d7fc8 100644 --- a/programs/develop/ktcc/trunk/libc/kolibrisys/sound.asm +++ b/programs/develop/ktcc/trunk/libc/kolibrisys/sound.asm @@ -1,7 +1,7 @@ format ELF include "public_stdcall.inc" section '.text' executable -public_stdcall _ksy_sound_load_block,4 +public_stdcall _ksys_sound_load_block,4 ;arg1 - blockptr mov edx,ebx mov eax,55 @@ -11,7 +11,7 @@ public_stdcall _ksy_sound_load_block,4 mov ebx,edx ret 4 -public_stdcall _ksy_sound_play_block,0 +public_stdcall _ksys_sound_play_block,0 mov edx,ebx mov eax,55 xor ebx,ebx @@ -20,7 +20,7 @@ public_stdcall _ksy_sound_play_block,0 mov ebx,edx ret -public_stdcall _ksy_sound_set_channels,4 +public_stdcall _ksys_sound_set_channels,4 ;arg1 - channels push ebx mov eax,55 @@ -31,7 +31,7 @@ public_stdcall _ksy_sound_set_channels,4 pop ebx ret 4 -public_stdcall _ksy_sound_set_data_size,4 +public_stdcall _ksys_sound_set_data_size,4 ;arg1 - data size push ebx mov eax,55 @@ -43,7 +43,7 @@ public_stdcall _ksy_sound_set_data_size,4 pop ebx ret 4 -public_stdcall _ksy_sound_set_frequency,4 +public_stdcall _ksys_sound_set_frequency,4 ;arg1 - frequency push ebx mov eax,55 @@ -54,12 +54,12 @@ public_stdcall _ksy_sound_set_frequency,4 pop ebx ret 4 -public_stdcall _ksy_sound_speaker_play,4 +public_stdcall _ksys_sound_speaker_play,4 ;arg1 - data mov edx,ebx mov eax,55 mov ebx,55 - mov ecx,[esp+4] + mov esi,[esp+4] int 0x40 mov ebx,edx - ret 4 \ No newline at end of file + ret 4 diff --git a/programs/develop/ktcc/trunk/libc/makefile b/programs/develop/ktcc/trunk/libc/makefile index 178c94316c..1e4c6b4539 100644 --- a/programs/develop/ktcc/trunk/libc/makefile +++ b/programs/develop/ktcc/trunk/libc/makefile @@ -2,7 +2,7 @@ INCLUDE = include LIBSFORBUILD = math LIBNAME = libck.a CC = gcc -CFLAGS = -I$(INCLUDE) -nostdinc -DGNUC -L./ -lm +CFLAGS = -I$(INCLUDE) -m32 -nostdinc -nostdlib -DGNUC DIRS := stdio kolibrisys string stdlib memory math ############################################################## diff --git a/programs/develop/ktcc/trunk/libc/math/ceil.asm b/programs/develop/ktcc/trunk/libc/math/ceil.asm new file mode 100644 index 0000000000..21cc9add0c --- /dev/null +++ b/programs/develop/ktcc/trunk/libc/math/ceil.asm @@ -0,0 +1,30 @@ + +format ELF +include 'proc32.inc' +section '.text' executable + +public ceil + +ceil: + + push ebp + mov ebp,esp + sub esp,8 + + fstcw [ebp-12] + mov dx,[ebp-12] + or dx,0x0800 + and dx,0xfbff + mov word[ebp-16],dx + fldcw [ebp-16] + + fld qword[ebp+8] + frndint + + fldcw [ebp-12] + + leave + + ret + + diff --git a/programs/develop/ktcc/trunk/libc/math/ceilf.asm b/programs/develop/ktcc/trunk/libc/math/ceilf.asm new file mode 100644 index 0000000000..1af7292fec --- /dev/null +++ b/programs/develop/ktcc/trunk/libc/math/ceilf.asm @@ -0,0 +1,30 @@ + +format ELF +include 'proc32.inc' +section '.text' executable + +public ceilf + +ceilf: + + push ebp + mov ebp,esp + sub esp,8 + + fstcw [ebp-12] + mov dx,[ebp-12] + or dx,0x0800 + and dx,0xfbff + mov word[ebp-16],dx + fldcw [ebp-16] + + fld dword[ebp+8] + frndint + + fldcw [ebp-12] + + leave + + ret + + diff --git a/programs/develop/ktcc/trunk/libc/math/fabs.asm b/programs/develop/ktcc/trunk/libc/math/fabs.asm new file mode 100644 index 0000000000..97f3679e39 --- /dev/null +++ b/programs/develop/ktcc/trunk/libc/math/fabs.asm @@ -0,0 +1,14 @@ + +format ELF +include 'proc32.inc' +section '.text' executable + +public fabs_ as "fabs" + +fabs_: + + fld qword[esp+4] + fabs + + ret + diff --git a/programs/develop/ktcc/trunk/libc/math/fabsf.asm b/programs/develop/ktcc/trunk/libc/math/fabsf.asm new file mode 100644 index 0000000000..7c069e2297 --- /dev/null +++ b/programs/develop/ktcc/trunk/libc/math/fabsf.asm @@ -0,0 +1,14 @@ + +format ELF +include 'proc32.inc' +section '.text' executable + +public fabsf + +fabsf: + + fld dword[esp+4] + fabs + + ret + diff --git a/programs/develop/ktcc/trunk/libc/math/floor.asm b/programs/develop/ktcc/trunk/libc/math/floor.asm new file mode 100644 index 0000000000..7d6b206e53 --- /dev/null +++ b/programs/develop/ktcc/trunk/libc/math/floor.asm @@ -0,0 +1,29 @@ + +format ELF +include 'proc32.inc' +section '.text' executable + +public floor + +floor: + + push ebp + mov ebp,esp + sub esp,8 + + fstcw [ebp-12] + mov dx,word[ebp-12] + or dx,0x0400 + and dx,0xf7ff + mov word[ebp-16],dx + fldcw [ebp-16] + + fld qword[ebp+8] + frndint + + fldcw [ebp-12] + + leave + + ret + diff --git a/programs/develop/ktcc/trunk/libc/math/floorf.asm b/programs/develop/ktcc/trunk/libc/math/floorf.asm new file mode 100644 index 0000000000..e58d305126 --- /dev/null +++ b/programs/develop/ktcc/trunk/libc/math/floorf.asm @@ -0,0 +1,29 @@ + +format ELF +include 'proc32.inc' +section '.text' executable + +public floorf + +floorf: + + push ebp + mov ebp,esp + sub esp,8 + + fstcw [ebp-12] + mov dx,word[ebp-12] + or dx,0x0400 + and dx,0xf7ff + mov word[ebp-16],dx + fldcw [ebp-16] + + fld dword[ebp+8] + frndint + + fldcw [ebp-12] + + leave + + ret + diff --git a/programs/develop/ktcc/trunk/libc/math/sqrt.asm b/programs/develop/ktcc/trunk/libc/math/sqrt.asm new file mode 100644 index 0000000000..7f0b37c4ba --- /dev/null +++ b/programs/develop/ktcc/trunk/libc/math/sqrt.asm @@ -0,0 +1,14 @@ + +format ELF +include 'proc32.inc' +section '.text' executable + +public sqrt + +sqrt: + + fld qword[esp+4] + fsqrt + + ret + diff --git a/programs/develop/ktcc/trunk/libc/math/sqrtf.asm b/programs/develop/ktcc/trunk/libc/math/sqrtf.asm new file mode 100644 index 0000000000..404e2c1202 --- /dev/null +++ b/programs/develop/ktcc/trunk/libc/math/sqrtf.asm @@ -0,0 +1,14 @@ + +format ELF +include 'proc32.inc' +section '.text' executable + +public sqrtf + +sqrtf: + + fld dword[esp+4] + fsqrt + + ret + diff --git a/programs/develop/ktcc/trunk/libc/stdlib/random.c b/programs/develop/ktcc/trunk/libc/stdlib/random.c new file mode 100644 index 0000000000..c832bad477 --- /dev/null +++ b/programs/develop/ktcc/trunk/libc/stdlib/random.c @@ -0,0 +1,15 @@ + +#include "stdlib.h" + +unsigned int seed_o=1; + +void srand (unsigned int seed) +{ + seed_o=seed; +} + +int rand (void) +{ + seed_o=(seed_o*25173+13849) & (65535); + return(seed_o); +}