From 71b99beec570fb84fe1352fed4dbafc79e65e2f0 Mon Sep 17 00:00:00 2001 From: "Magomed Kostoev (mkostoevr)" Date: Sun, 3 May 2020 08:09:36 +0000 Subject: [PATCH] Make libck project self-containing. git-svn-id: svn://kolibrios.org@7855 a494cfbc-eb01-0410-851d-a64ba20cac60 --- .../libc/kolibrisys/_ksys_files_acces.asm | 2 +- .../ktcc/trunk/libc/kolibrisys/clock.asm | 2 +- .../ktcc/trunk/libc/kolibrisys/cofflib.asm | 2 +- .../trunk/libc/kolibrisys/debug_board.asm | 2 +- .../ktcc/trunk/libc/kolibrisys/keyboard.asm | 2 +- .../develop/ktcc/trunk/libc/math/acos.asm | 2 +- .../develop/ktcc/trunk/libc/math/atan.asm | 2 +- .../develop/ktcc/trunk/libc/math/atan2.asm | 2 +- .../develop/ktcc/trunk/libc/math/ceil.asm | 2 +- .../develop/ktcc/trunk/libc/math/ceilf.asm | 2 +- programs/develop/ktcc/trunk/libc/math/cos.asm | 2 +- programs/develop/ktcc/trunk/libc/math/exp.asm | 2 +- .../develop/ktcc/trunk/libc/math/fabs.asm | 2 +- .../develop/ktcc/trunk/libc/math/fabsf.asm | 2 +- .../develop/ktcc/trunk/libc/math/floor.asm | 2 +- .../develop/ktcc/trunk/libc/math/floorf.asm | 2 +- programs/develop/ktcc/trunk/libc/math/log.asm | 2 +- .../develop/ktcc/trunk/libc/math/log10.asm | 2 +- programs/develop/ktcc/trunk/libc/math/sin.asm | 2 +- .../develop/ktcc/trunk/libc/math/sqrt.asm | 2 +- .../develop/ktcc/trunk/libc/math/sqrtf.asm | 2 +- programs/develop/ktcc/trunk/libc/math/tan.asm | 2 +- .../ktcc/trunk/libc/memory/memalloc.asm | 2 +- programs/develop/ktcc/trunk/libc/proc32.inc | 301 ++++++++++++++++++ .../ktcc/trunk/libc/string/memmove.asm | 2 +- 25 files changed, 325 insertions(+), 24 deletions(-) create mode 100644 programs/develop/ktcc/trunk/libc/proc32.inc diff --git a/programs/develop/ktcc/trunk/libc/kolibrisys/_ksys_files_acces.asm b/programs/develop/ktcc/trunk/libc/kolibrisys/_ksys_files_acces.asm index 1c7143ba35..2c7c51a72e 100644 --- a/programs/develop/ktcc/trunk/libc/kolibrisys/_ksys_files_acces.asm +++ b/programs/develop/ktcc/trunk/libc/kolibrisys/_ksys_files_acces.asm @@ -2,7 +2,7 @@ format ELF section '.text' executable -include 'proc32.inc' +include '../proc32.inc' public _ksys_get_filesize public _ksys_readfile public _ksys_rewritefile diff --git a/programs/develop/ktcc/trunk/libc/kolibrisys/clock.asm b/programs/develop/ktcc/trunk/libc/kolibrisys/clock.asm index 7681d6dae4..726852a650 100644 --- a/programs/develop/ktcc/trunk/libc/kolibrisys/clock.asm +++ b/programs/develop/ktcc/trunk/libc/kolibrisys/clock.asm @@ -1,6 +1,6 @@ format ELF -include "proc32.inc" +include "../proc32.inc" section '.text' executable public _ksys_get_system_clock diff --git a/programs/develop/ktcc/trunk/libc/kolibrisys/cofflib.asm b/programs/develop/ktcc/trunk/libc/kolibrisys/cofflib.asm index 8de57ed061..a4114fd1b0 100644 --- a/programs/develop/ktcc/trunk/libc/kolibrisys/cofflib.asm +++ b/programs/develop/ktcc/trunk/libc/kolibrisys/cofflib.asm @@ -1,5 +1,5 @@ format ELF -include 'proc32.inc' +include '../proc32.inc' section '.text' executable public _ksys_cofflib_load diff --git a/programs/develop/ktcc/trunk/libc/kolibrisys/debug_board.asm b/programs/develop/ktcc/trunk/libc/kolibrisys/debug_board.asm index b0dbd8eaca..9f27e6bd1b 100644 --- a/programs/develop/ktcc/trunk/libc/kolibrisys/debug_board.asm +++ b/programs/develop/ktcc/trunk/libc/kolibrisys/debug_board.asm @@ -1,6 +1,6 @@ format ELF -include "proc32.inc" +include "../proc32.inc" section '.text' executable diff --git a/programs/develop/ktcc/trunk/libc/kolibrisys/keyboard.asm b/programs/develop/ktcc/trunk/libc/kolibrisys/keyboard.asm index bc50099ba6..8d9f13c6c3 100644 --- a/programs/develop/ktcc/trunk/libc/kolibrisys/keyboard.asm +++ b/programs/develop/ktcc/trunk/libc/kolibrisys/keyboard.asm @@ -1,6 +1,6 @@ format ELF -include "proc32.inc" +include "../proc32.inc" section '.text' executable diff --git a/programs/develop/ktcc/trunk/libc/math/acos.asm b/programs/develop/ktcc/trunk/libc/math/acos.asm index ce7dc21ef0..959e9e7a48 100644 --- a/programs/develop/ktcc/trunk/libc/math/acos.asm +++ b/programs/develop/ktcc/trunk/libc/math/acos.asm @@ -1,6 +1,6 @@ format ELF -include 'proc32.inc' +include '../proc32.inc' section '.text' executable public acos_ as "acos" diff --git a/programs/develop/ktcc/trunk/libc/math/atan.asm b/programs/develop/ktcc/trunk/libc/math/atan.asm index 6b7355150b..68f6fddc1f 100644 --- a/programs/develop/ktcc/trunk/libc/math/atan.asm +++ b/programs/develop/ktcc/trunk/libc/math/atan.asm @@ -1,6 +1,6 @@ format ELF -include 'proc32.inc' +include '../proc32.inc' section '.text' executable public atan_ as "atan" diff --git a/programs/develop/ktcc/trunk/libc/math/atan2.asm b/programs/develop/ktcc/trunk/libc/math/atan2.asm index b08e30fc5f..e0587bc3e5 100644 --- a/programs/develop/ktcc/trunk/libc/math/atan2.asm +++ b/programs/develop/ktcc/trunk/libc/math/atan2.asm @@ -1,6 +1,6 @@ format ELF -include 'proc32.inc' +include '../proc32.inc' section '.text' executable public atan2_ as "atan2" diff --git a/programs/develop/ktcc/trunk/libc/math/ceil.asm b/programs/develop/ktcc/trunk/libc/math/ceil.asm index 21cc9add0c..c03f6056fd 100644 --- a/programs/develop/ktcc/trunk/libc/math/ceil.asm +++ b/programs/develop/ktcc/trunk/libc/math/ceil.asm @@ -1,6 +1,6 @@ format ELF -include 'proc32.inc' +include '../proc32.inc' section '.text' executable public ceil diff --git a/programs/develop/ktcc/trunk/libc/math/ceilf.asm b/programs/develop/ktcc/trunk/libc/math/ceilf.asm index 1af7292fec..e5180d68e8 100644 --- a/programs/develop/ktcc/trunk/libc/math/ceilf.asm +++ b/programs/develop/ktcc/trunk/libc/math/ceilf.asm @@ -1,6 +1,6 @@ format ELF -include 'proc32.inc' +include '../proc32.inc' section '.text' executable public ceilf diff --git a/programs/develop/ktcc/trunk/libc/math/cos.asm b/programs/develop/ktcc/trunk/libc/math/cos.asm index fdbb3b9b56..75ac75e182 100644 --- a/programs/develop/ktcc/trunk/libc/math/cos.asm +++ b/programs/develop/ktcc/trunk/libc/math/cos.asm @@ -1,6 +1,6 @@ format ELF -include 'proc32.inc' +include '../proc32.inc' section '.text' executable public cos_ as "cos" diff --git a/programs/develop/ktcc/trunk/libc/math/exp.asm b/programs/develop/ktcc/trunk/libc/math/exp.asm index 83c1a89963..d3b27b41fa 100644 --- a/programs/develop/ktcc/trunk/libc/math/exp.asm +++ b/programs/develop/ktcc/trunk/libc/math/exp.asm @@ -1,6 +1,6 @@ format ELF -include 'proc32.inc' +include '../proc32.inc' section '.text' executable public exp_ as "exp" diff --git a/programs/develop/ktcc/trunk/libc/math/fabs.asm b/programs/develop/ktcc/trunk/libc/math/fabs.asm index 97f3679e39..1e2cd067c4 100644 --- a/programs/develop/ktcc/trunk/libc/math/fabs.asm +++ b/programs/develop/ktcc/trunk/libc/math/fabs.asm @@ -1,6 +1,6 @@ format ELF -include 'proc32.inc' +include '../proc32.inc' section '.text' executable public fabs_ as "fabs" diff --git a/programs/develop/ktcc/trunk/libc/math/fabsf.asm b/programs/develop/ktcc/trunk/libc/math/fabsf.asm index 7c069e2297..fba999a01b 100644 --- a/programs/develop/ktcc/trunk/libc/math/fabsf.asm +++ b/programs/develop/ktcc/trunk/libc/math/fabsf.asm @@ -1,6 +1,6 @@ format ELF -include 'proc32.inc' +include '../proc32.inc' section '.text' executable public fabsf diff --git a/programs/develop/ktcc/trunk/libc/math/floor.asm b/programs/develop/ktcc/trunk/libc/math/floor.asm index 7d6b206e53..8df60993ed 100644 --- a/programs/develop/ktcc/trunk/libc/math/floor.asm +++ b/programs/develop/ktcc/trunk/libc/math/floor.asm @@ -1,6 +1,6 @@ format ELF -include 'proc32.inc' +include '../proc32.inc' section '.text' executable public floor diff --git a/programs/develop/ktcc/trunk/libc/math/floorf.asm b/programs/develop/ktcc/trunk/libc/math/floorf.asm index e58d305126..bc262752c6 100644 --- a/programs/develop/ktcc/trunk/libc/math/floorf.asm +++ b/programs/develop/ktcc/trunk/libc/math/floorf.asm @@ -1,6 +1,6 @@ format ELF -include 'proc32.inc' +include '../proc32.inc' section '.text' executable public floorf diff --git a/programs/develop/ktcc/trunk/libc/math/log.asm b/programs/develop/ktcc/trunk/libc/math/log.asm index a9c0c58c4b..964c711268 100644 --- a/programs/develop/ktcc/trunk/libc/math/log.asm +++ b/programs/develop/ktcc/trunk/libc/math/log.asm @@ -1,6 +1,6 @@ format ELF -include 'proc32.inc' +include '../proc32.inc' section '.text' executable public log_ as "log" diff --git a/programs/develop/ktcc/trunk/libc/math/log10.asm b/programs/develop/ktcc/trunk/libc/math/log10.asm index 34340e0c04..8c5c4daa51 100644 --- a/programs/develop/ktcc/trunk/libc/math/log10.asm +++ b/programs/develop/ktcc/trunk/libc/math/log10.asm @@ -1,6 +1,6 @@ format ELF -include 'proc32.inc' +include '../proc32.inc' section '.text' executable public log10_ as "log10" diff --git a/programs/develop/ktcc/trunk/libc/math/sin.asm b/programs/develop/ktcc/trunk/libc/math/sin.asm index 469bf7cb42..97515945cd 100644 --- a/programs/develop/ktcc/trunk/libc/math/sin.asm +++ b/programs/develop/ktcc/trunk/libc/math/sin.asm @@ -1,6 +1,6 @@ format ELF -include 'proc32.inc' +include '../proc32.inc' section '.text' executable public sin_ as "sin" diff --git a/programs/develop/ktcc/trunk/libc/math/sqrt.asm b/programs/develop/ktcc/trunk/libc/math/sqrt.asm index 7f0b37c4ba..4016991d7f 100644 --- a/programs/develop/ktcc/trunk/libc/math/sqrt.asm +++ b/programs/develop/ktcc/trunk/libc/math/sqrt.asm @@ -1,6 +1,6 @@ format ELF -include 'proc32.inc' +include '../proc32.inc' section '.text' executable public sqrt diff --git a/programs/develop/ktcc/trunk/libc/math/sqrtf.asm b/programs/develop/ktcc/trunk/libc/math/sqrtf.asm index 404e2c1202..9306ad4ec1 100644 --- a/programs/develop/ktcc/trunk/libc/math/sqrtf.asm +++ b/programs/develop/ktcc/trunk/libc/math/sqrtf.asm @@ -1,6 +1,6 @@ format ELF -include 'proc32.inc' +include '../proc32.inc' section '.text' executable public sqrtf diff --git a/programs/develop/ktcc/trunk/libc/math/tan.asm b/programs/develop/ktcc/trunk/libc/math/tan.asm index 0fc3b14f39..2dae8a0312 100644 --- a/programs/develop/ktcc/trunk/libc/math/tan.asm +++ b/programs/develop/ktcc/trunk/libc/math/tan.asm @@ -1,6 +1,6 @@ format ELF -include 'proc32.inc' +include '../proc32.inc' section '.text' executable public tan_ as "tan" diff --git a/programs/develop/ktcc/trunk/libc/memory/memalloc.asm b/programs/develop/ktcc/trunk/libc/memory/memalloc.asm index a68f188bd5..2c45afb329 100644 --- a/programs/develop/ktcc/trunk/libc/memory/memalloc.asm +++ b/programs/develop/ktcc/trunk/libc/memory/memalloc.asm @@ -1,6 +1,6 @@ format ELF -;include "proc32.inc" +;include "../proc32.inc" section '.text' executable public sysmalloc public sysfree diff --git a/programs/develop/ktcc/trunk/libc/proc32.inc b/programs/develop/ktcc/trunk/libc/proc32.inc new file mode 100644 index 0000000000..762826cbbb --- /dev/null +++ b/programs/develop/ktcc/trunk/libc/proc32.inc @@ -0,0 +1,301 @@ + +; Macroinstructions for defining and calling procedures + +macro stdcall proc,[arg] ; directly call STDCALL procedure + { common + if ~ arg eq + reverse + pushd arg + common + end if + call proc } + +macro invoke proc,[arg] ; indirectly call STDCALL procedure + { common + if ~ arg eq + reverse + pushd arg + common + end if + call [proc] } + +macro ccall proc,[arg] ; directly call CDECL procedure + { common + size@ccall = 0 + if ~ arg eq + reverse + pushd arg + size@ccall = size@ccall+4 + common + end if + call proc + if size@ccall + add esp,size@ccall + end if } + +macro cinvoke proc,[arg] ; indirectly call CDECL procedure + { common + size@ccall = 0 + if ~ arg eq + reverse + pushd arg + size@ccall = size@ccall+4 + common + end if + call [proc] + if size@ccall + add esp,size@ccall + end if } + +macro proc [args] ; define procedure + { common + match name params, args> + \{ define@proc name, \{ prologue name,flag,parmbytes,localbytes,reglist \} + virtual at parmbase@proc + match =,args, params \{ defargs@proc args \} + match =args@proc args, args@proc params \{ defargs@proc args \} + parmbytes = $-(parmbase@proc) + end virtual + name # % = parmbytes/4 + all@vars equ + current = 0 + macro locals + \{ virtual at localbase@proc+current + macro label def \\{ match . type,def> \\\{ deflocal@proc .,label, \\\{ epilogue name,flag,parmbytes,localbytes,reglist \\\} \\} \} + macro finish@proc + \{ localbytes = current + match close:reglist, close@proc: \\{ close name,flag,parmbytes,localbytes,reglist \\} + end if \} } + +macro defargs@proc [arg] + { common + if ~ arg eq + forward + local ..arg,current@arg + match argname:type, arg + \{ current@arg equ argname + label ..arg type + argname equ ..arg + if qqword eq type + dd ?,?,?,?,?,?,?,? + else if dqword eq type + dd ?,?,?,? + else if tbyte eq type + dd ?,?,? + else if qword eq type | pword eq type + dd ?,? + else + dd ? + end if \} + match =current@arg,current@arg + \{ current@arg equ arg + arg equ ..arg + ..arg dd ? \} + common + args@proc equ current@arg + forward + restore current@arg + common + end if } + +macro deflocal@proc name,def,[val] { name def val } + +macro deflocal@proc name,def,[val] + { common + match vars, all@vars \{ all@vars equ all@vars, \} + all@vars equ all@vars name + forward + local ..var,..tmp + ..var def val + match =?, val \{ ..tmp equ \} + match any =?, val \{ ..tmp equ \} + match any (=?), val \{ ..tmp equ \} + match =label, def \{ ..tmp equ \} + match tmp : value, ..tmp : val + \{ tmp: end virtual + initlocal@proc ..var,def value + virtual at tmp\} + common + match first rest, ..var, \{ name equ first \} } + +struc label type { label . type } + +macro initlocal@proc name,def + { virtual at name + def + size@initlocal = $ - name + end virtual + position@initlocal = 0 + while size@initlocal > position@initlocal + virtual at name + def + if size@initlocal - position@initlocal < 2 + current@initlocal = 1 + load byte@initlocal byte from name+position@initlocal + else if size@initlocal - position@initlocal < 4 + current@initlocal = 2 + load word@initlocal word from name+position@initlocal + else + current@initlocal = 4 + load dword@initlocal dword from name+position@initlocal + end if + end virtual + if current@initlocal = 1 + mov byte [name+position@initlocal],byte@initlocal + else if current@initlocal = 2 + mov word [name+position@initlocal],word@initlocal + else + mov dword [name+position@initlocal],dword@initlocal + end if + position@initlocal = position@initlocal + current@initlocal + end while } + +macro endp + { purge ret,locals,endl + finish@proc + purge finish@proc + restore regs@proc + match all,args@proc \{ restore all \} + restore args@proc + match all,all@vars \{ restore all \} } + +macro local [var] + { common + locals + forward done@local equ + match varname[count]:vartype, var + \{ match =BYTE, vartype \\{ varname rb count + restore done@local \\} + match =WORD, vartype \\{ varname rw count + restore done@local \\} + match =DWORD, vartype \\{ varname rd count + restore done@local \\} + match =PWORD, vartype \\{ varname rp count + restore done@local \\} + match =QWORD, vartype \\{ varname rq count + restore done@local \\} + match =TBYTE, vartype \\{ varname rt count + restore done@local \\} + match =DQWORD, vartype \\{ label varname dqword + rq count*2 + restore done@local \\} + match =QQWORD, vartype \\{ label varname qqword + rq count*4 + restore done@local \\} + match =XWORD, vartype \\{ label varname xword + rq count*2 + restore done@local \\} + match =YWORD, vartype \\{ label varname yword + rq count*4 + restore done@local \\} + match , done@local \\{ virtual + varname vartype + end virtual + rb count*sizeof.\#vartype + restore done@local \\} \} + match :varname:vartype, done@local:var + \{ match =BYTE, vartype \\{ varname db ? + restore done@local \\} + match =WORD, vartype \\{ varname dw ? + restore done@local \\} + match =DWORD, vartype \\{ varname dd ? + restore done@local \\} + match =PWORD, vartype \\{ varname dp ? + restore done@local \\} + match =QWORD, vartype \\{ varname dq ? + restore done@local \\} + match =TBYTE, vartype \\{ varname dt ? + restore done@local \\} + match =DQWORD, vartype \\{ label varname dqword + dq ?,? + restore done@local \\} + match =QQWORD, vartype \\{ label varname qqword + dq ?,?,?,? + restore done@local \\} + match =XWORD, vartype \\{ label varname xword + dq ?,? + restore done@local \\} + match =YWORD, vartype \\{ label varname yword + dq ?,?,?,? + restore done@local \\} + match , done@local \\{ varname vartype + restore done@local \\} \} + match ,done@local + \{ var + restore done@local \} + common + endl } diff --git a/programs/develop/ktcc/trunk/libc/string/memmove.asm b/programs/develop/ktcc/trunk/libc/string/memmove.asm index a654d869f5..32a1989392 100644 --- a/programs/develop/ktcc/trunk/libc/string/memmove.asm +++ b/programs/develop/ktcc/trunk/libc/string/memmove.asm @@ -1,7 +1,7 @@ format ELF section '.text' executable -include 'proc32.inc' +include '../proc32.inc' public memcpy public memmove