From 6db1f4dd5ac133b296ab3ff526cf1178fa9515c8 Mon Sep 17 00:00:00 2001 From: superturbocat2001 Date: Fri, 25 Dec 2020 23:07:44 +0000 Subject: [PATCH] - Module files are removed from the source folder. - Removed fasm debug module. - Added debug function to "kolibri" module. git-svn-id: svn://kolibrios.org@8475 a494cfbc-eb01-0410-851d-a64ba20cac60 --- .../develop/tinypy/modules/kolibri/debug.c | 19 ++ .../kolibri_gui.c => modules/kolibri/gui.c} | 0 .../develop/tinypy/modules/kolibri/init.c | 3 + .../kolibri_net.c => modules/kolibri/net.c} | 0 programs/develop/tinypy/tinypy/Makefile | 19 +- .../tinypy/tinypy/fasm_modules/kolibri_dbg.s | 155 --------------- .../tinypy/tinypy/fasm_modules/tinypy.inc | 184 ------------------ programs/develop/tinypy/tinypy/kolibri_fs.c | 1 - programs/develop/tinypy/tinypy/kolibri_init.c | 1 - programs/develop/tinypy/tinypy/test.py | 1 + programs/develop/tinypy/tinypy/tpmain.c | 3 +- 11 files changed, 35 insertions(+), 351 deletions(-) create mode 100644 programs/develop/tinypy/modules/kolibri/debug.c rename programs/develop/tinypy/{tinypy/kolibri_gui.c => modules/kolibri/gui.c} (100%) rename programs/develop/tinypy/{tinypy/kolibri_net.c => modules/kolibri/net.c} (100%) delete mode 100644 programs/develop/tinypy/tinypy/fasm_modules/kolibri_dbg.s delete mode 100644 programs/develop/tinypy/tinypy/fasm_modules/tinypy.inc delete mode 100755 programs/develop/tinypy/tinypy/kolibri_fs.c delete mode 100755 programs/develop/tinypy/tinypy/kolibri_init.c diff --git a/programs/develop/tinypy/modules/kolibri/debug.c b/programs/develop/tinypy/modules/kolibri/debug.c new file mode 100644 index 0000000000..9615712b04 --- /dev/null +++ b/programs/develop/tinypy/modules/kolibri/debug.c @@ -0,0 +1,19 @@ +#include "tp.h" + +void debug_write_byte(const char ch){ + __asm__ __volatile__( + "int $0x40" + ::"a"(63), "b"(1), "c"(ch) + ); +} + +tp_obj kolibri_debug_print(TP) +{ + tp_obj str = TP_TYPE(TP_STRING); + for(int i=0; i < str.string.len; i++) + { + debug_write_byte(str.string.val[i]); + } + return tp_None; +} + diff --git a/programs/develop/tinypy/tinypy/kolibri_gui.c b/programs/develop/tinypy/modules/kolibri/gui.c similarity index 100% rename from programs/develop/tinypy/tinypy/kolibri_gui.c rename to programs/develop/tinypy/modules/kolibri/gui.c diff --git a/programs/develop/tinypy/modules/kolibri/init.c b/programs/develop/tinypy/modules/kolibri/init.c index c73d4a8ae9..c16e66a8c9 100755 --- a/programs/develop/tinypy/modules/kolibri/init.c +++ b/programs/develop/tinypy/modules/kolibri/init.c @@ -2,6 +2,7 @@ extern tp_obj kolibri_open(TP); extern tp_obj kolibri_mainwindow(TP); +extern tp_obj kolibri_debug_print(TP); extern tp_obj kolibri_socket_module(TP); extern tp_obj tp_dict(TP); extern tp_obj tp_fnc(TP,tp_obj v(TP)); @@ -13,6 +14,8 @@ void kolibri_init(TP) tp_set(tp, kolibri_mod, tp_string("open"), tp_fnc(tp, kolibri_open)); tp_set(tp, kolibri_mod, tp_string("window"), tp_fnc(tp, kolibri_mainwindow)); + /* debug */ + tp_set(tp, kolibri_mod, tp_string("debug_print"), tp_fnc(tp, kolibri_debug_print)); /* socket is a separated module. */ tp_set(tp, kolibri_mod, tp_string("socket"), socket_mod); diff --git a/programs/develop/tinypy/tinypy/kolibri_net.c b/programs/develop/tinypy/modules/kolibri/net.c similarity index 100% rename from programs/develop/tinypy/tinypy/kolibri_net.c rename to programs/develop/tinypy/modules/kolibri/net.c diff --git a/programs/develop/tinypy/tinypy/Makefile b/programs/develop/tinypy/tinypy/Makefile index 5a9d5c7a10..e626c91269 100644 --- a/programs/develop/tinypy/tinypy/Makefile +++ b/programs/develop/tinypy/tinypy/Makefile @@ -13,21 +13,24 @@ CFLAGS = -U_Win32 -U_WIN32 -U__MINGW32__ -mpreferred-stack-boundary=2 \ INCLUDES= -I. -I$(SDK_DIR)/sources/newlib/libc/include LIBPATH:= -L $(SDK_DIR)/lib -L /home/autobuild/tools/win32/mingw32/lib - -OBJECTS = tpmain.o kolibri_init.o kolibri_fs.o kolibri_gui.o kolibri_net.o kolibri_dbg.obj +KOLIBRI_M_OBJ= ../modules/kolibri/init.o \ + ../modules/kolibri/fs.o \ + ../modules/kolibri/net.o \ + ../modules/kolibri/gui.o \ + ../modules/kolibri/debug.o \ + + +OBJECTS = tpmain.o $(KOLIBRI_M_OBJ) all:$(NAME) -$(NAME): $(OBJECTS) Makefile +$(NAME): $(OBJECTS) $(LD) $(LIBPATH) --subsystem native -o $@ $(OBJECTS) $(LDFLAGS) -n -Map $(NAME).map kos32-objcopy $@ -O binary + kpack $@ %.o : %.c Makefile $(CC) -c $(INCLUDES) $(CFLAGS) -o $@ $< -kolibri_dbg.obj: fasm_modules/kolibri_dbg.s - fasm fasm_modules/kolibri_dbg.s - cp fasm_modules/kolibri_dbg.obj . - clean: - -rm -f *.o $(NAME).map fasm_modules/kolibri_dbg.obj kolibri_dbg.obj + rm -f *.o $(NAME).map $(KOLIBRI_M_OBJ) diff --git a/programs/develop/tinypy/tinypy/fasm_modules/kolibri_dbg.s b/programs/develop/tinypy/tinypy/fasm_modules/kolibri_dbg.s deleted file mode 100644 index ee6a26aceb..0000000000 --- a/programs/develop/tinypy/tinypy/fasm_modules/kolibri_dbg.s +++ /dev/null @@ -1,155 +0,0 @@ -; TinyPy module -; Name: kolibri_dbg -; -; Exports: -; debug_print(msg) - prints a message to debug board. - -format coff -use32 ; Tell compiler to use 32 bit instructions - -section '.init' code ; Keep this line before includes or GCC messes up call addresses - -include '../../../proc32.inc' -include '../../../struct.inc' -purge section,mov,add,sub -include 'tinypy.inc' - -include '../../../../programs/dll.inc' - -extrn '_tp_dict' as tp_dict -extrn '_tp_set' as tp_set -extrn '_tp_get' as tp_get -extrn '_tp_None' as tp_None -extrn '_tp_fnc' as tp_fnc - -public kolibri_dbg_init as '_kolibri_dbg_init' - -; Module name -modname db "kolibri_dbg" -modnamelen = $-modname - -; Exported function name -debug_print_name db "debug_print" -debug_print_namelen = $-debug_print_name -; Export dictionary for module -kolibri_dbg_dict rb sizeof.tp_obj -; tp_obj of exported function -debug_print_obj rb sizeof.tp_obj - -; Function debug_print(tp_vm *tp) -; return nothing -debug_print: - push ebp - mov ebp, esp - ; Store registers - push eax - push ebx - push ecx - push edx - sub esp, sizeof.tp_obj; Reserve tp_obj tmp - mov edx, esp - push edx ;Store &tmp - ; Obtain tp_string parameter - ; tp_get(&tmp, tp, *(tp_obj *)(tp_vm->params), tp_None) - push_tp_none - mov eax, dword[ebp+12] ;4 for return address, 4 for result pointer; 4 for tp_vm - add eax, tp_vm.params - push_tp_obj_at_reg eax - push dword[ebp+12] - push edx ;ebx contains address of reserved tp_obj variable - call tp_get - - ;Restore stack - add esp, sizeof.tp_obj*2+4;2 tp_obj's and 2 pointers in parameters minus 1 pointer to result (cleared inside tp_get) - - ;Leave if parameter is not a string. tp_raise() should be called here. - pop edx; edx = &tmp - cmp dword[edx], TP_STRING ; Check that function returned a TP_STRING - jne .exit - mov ecx, dword[edx+tp_string_.len] ; String length - mov edx, dword[edx+tp_string_.val] ; - mov eax, 63 - mov ebx, 1 -.cont: - ; Print message. - push ecx ; Store ecx to use it in inner loop - mov cl, byte[edx] - inc edx - int 40h - pop ecx ; Get ecx back - loop .cont -.exit: - add esp, sizeof.tp_obj ; Release tp_obj reserved in stack. - ; Returning tp_None - mov eax, dword[ebp+8] - mov dword[eax], 0 - ; Restore registers - pop edx - pop ecx - pop ebx - pop eax - mov esp, ebp - pop ebp - ret - -;void kolibri_dbg_init(tp_vm *tp); -kolibri_dbg_init: - push ebp - mov ebp, esp - ;Save registers - push eax - push ebx - push ecx - ; Create module dictionary and store its address in kolibri_dbg_str - mov eax, dword [ebp + 8] - push eax - push kolibri_dbg_dict - call tp_dict - add esp, 4 ;Clear stack - ; Push tp_obj structure pointed by kolibri_dbg_dict - push_tp_obj kolibri_dbg_dict - ; Push modname as a tp_obj object - push modnamelen; len - push modname ; val - push 0 ;_tp_string info - push TP_STRING ; type - ; Push tp_obj structure pointed by tp->modules - mov eax, dword [ebp + 8] - add eax, tp_vm.modules + 16 - mov ecx, 4 -.push_tpobj1: - sub eax, 4 - push dword[eax] -loop .push_tpobj1 - push eax - call tp_set - add esp, sizeof.tp_obj*3+4 - ; Register "debug_print" function - ;Reserve memory for function tp_obj object - sub esp, sizeof.tp_obj - mov eax, esp - push debug_print - push dword[ebp+8] - push eax - call tp_fnc - add esp, 8; tp_obj is already in stack, adding other arguments - ;Pushing function name tp_obj - ;mov eax, esp - ;push_tp_obj_at_reg eax - push debug_print_namelen - push debug_print_name - push 0 - push TP_STRING - ;Pushing module dictionary tp_obj - push_tp_obj kolibri_dbg_dict - ;Pushing tp_vm - push dword[ebp+8] - call tp_set - add esp, sizeof.tp_obj*3+4 - ; Leaving function - pop ecx - pop ebx - pop eax - mov esp, ebp - pop ebp - ret diff --git a/programs/develop/tinypy/tinypy/fasm_modules/tinypy.inc b/programs/develop/tinypy/tinypy/fasm_modules/tinypy.inc deleted file mode 100644 index 37e8045a53..0000000000 --- a/programs/develop/tinypy/tinypy/fasm_modules/tinypy.inc +++ /dev/null @@ -1,184 +0,0 @@ -; Python object types -TP_NONE equ 0 -TP_NUMBER equ 1 -TP_STRING equ 2 -TP_DICT equ 3 -TP_LIST equ 4 -TP_FNC equ 5 -TP_DATA equ 6 - -; Python "number" object. Can be treated as integer or float. -struct tp_number_ - type rd 1 - val rd 1 -ends - -; GC information for "string" object -struct _tp_string - gci rd 1 - s rb 1 -ends - -; Python "string" object -struct tp_string_ - type rd 1 - info rd 1 ;pointer to _tp_string - val rd 1 - len rd 1 -ends - -; GC information for "list" object -struct _tp_list - gci rd 1 - items rd 1 - len rd 1 - alloc rd 1 -ends - -; Python "list" object -struct tp_list_ - type rd 1 - val rd 1 ;pointer to _tp_list -ends - - -; GC information for "dict" object -struct _tp_dict - gci rd 1 - items rd 1 - len rd 1 - alloc rd 1 - cur rd 1 - mask rd 1 - used rd 1 -ends - -; Python "dict" object -struct tp_dict_ - type rd 1 - val rd 1 ;pointer to _tp_dict -ends - -; GC information for "function" object -; todo - -; Python "function" object -struct tp_fnc_ - type rd 1 - info rd 1 - ftype rd 1 - val rd 1 -ends - -; Python "data" object -struct tp_data_ - type rd 1 - info rd 1 - val rd 1 - magic rd 1 -ends - -struct tp_gc_info - type rd 1 - data rd 1 -ends - -; Generic Python object -struct tp_obj -union - type rd 1 - string tp_string_ - number tp_number_ - gc_info tp_gc_info - dict tp_dict_ - list tp_list_ - fnc tp_fnc_ - dat tp_data_ -ends -ends - -; Bytecode element -struct sregs - .i rb 1 - .a rb 1 - .b rb 1 - .c rb 1 -ends - -struct tp_code -union - i rb 1 - regs sregs - string rb 4 - number rp 1 -ends -ends - -; TinyPy VM frame -struct tp_frame_ - .codes rd 1 - .cur rd 1 - .jump rd 1 - .regs rd 1 - .ret_dest rd 1 - .fname rb sizeof.tp_obj - .name rb sizeof.tp_obj - .line rb sizeof.tp_obj - .globals rb sizeof.tp_obj - .lineno rd 1 - .cregs rd 1 -ends - -; TinyPy VM -TP_FRAMES equ 256 -struct tp_vm - builtins rb sizeof.tp_obj - modules rb sizeof.tp_obj - frames rb TP_FRAMES*sizeof.tp_frame_ - _params rb sizeof.tp_obj - params rb sizeof.tp_obj - _regs rb sizeof.tp_obj - regs rq 1 - root rb sizeof.tp_obj - jmp_buf rd 1 - jump rd 1 - ex rb sizeof.tp_obj - chars rb 512 - cur rd 1 - white rb sizeof._tp_list - grey rb sizeof._tp_list - black rb sizeof._tp_list - strings rb sizeof._tp_dict - steps rd 1 -ends - -macro push_tp_none -{ - local .push_more - mov ecx, 4 -.push_more: - push 0 - loop .push_more -} - -macro push_tp_obj obj -{ - local .push_more - mov ebx, obj + 12 - mov ecx, 4 -.push_more: - push dword[ebx] - sub ebx, 4 - loop .push_more -} - -macro push_tp_obj_at_reg reg -{ - local .push_more - add reg, 12 - mov ecx, 4 -.push_more: - push dword[reg] - sub reg, 4 - loop .push_more -} diff --git a/programs/develop/tinypy/tinypy/kolibri_fs.c b/programs/develop/tinypy/tinypy/kolibri_fs.c deleted file mode 100755 index 9296d6537c..0000000000 --- a/programs/develop/tinypy/tinypy/kolibri_fs.c +++ /dev/null @@ -1 +0,0 @@ -#include "../modules/kolibri/fs.c" diff --git a/programs/develop/tinypy/tinypy/kolibri_init.c b/programs/develop/tinypy/tinypy/kolibri_init.c deleted file mode 100755 index 1d36aa86ad..0000000000 --- a/programs/develop/tinypy/tinypy/kolibri_init.c +++ /dev/null @@ -1 +0,0 @@ -#include "../modules/kolibri/init.c" diff --git a/programs/develop/tinypy/tinypy/test.py b/programs/develop/tinypy/tinypy/test.py index 76e2e29d64..86fa808a25 100644 --- a/programs/develop/tinypy/tinypy/test.py +++ b/programs/develop/tinypy/tinypy/test.py @@ -10,6 +10,7 @@ def onbtn(): print("Button pressed") if __name__=="__main__": + kolibri.debug_print("Debug test line\n") w = kolibri.window(10,10,400, 400, False) w.on_show = onshow w.on_key = onkey diff --git a/programs/develop/tinypy/tinypy/tpmain.c b/programs/develop/tinypy/tinypy/tpmain.c index d11da85ca6..a9e965c2cb 100644 --- a/programs/develop/tinypy/tinypy/tpmain.c +++ b/programs/develop/tinypy/tinypy/tpmain.c @@ -2,11 +2,10 @@ /* INCLUDE */ const char header[]="TinyPy for kolibriOS"; -extern void (*kolibri_dbg_init)(tp_vm *tp) __attribute__((__stdcall__)); +//extern void kolibri_dbg_init(tp_vm *tp); //__attribute__((__stdcall__)); void main(int argc, const char *argv[]) { tp_vm *tp = tp_init(argc, argv); - // kolibri_dbg_init(tp); kolibri_init(tp); CONSOLE_INIT(header); /* INIT */