Rev 1926 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2048 | jaeger | 1 | ; TinyPy module |
2 | ; Name: kolibri_dbg |
||
3 | ; |
||
4 | ; Exports: |
||
5 | ; debug_print(msg) - prints a message to debug board. |
||
6 | |||
1926 | jaeger | 7 | format ELF |
8 | use32 |
||
9 | include 'proc32.inc' |
||
10 | include 'struct.inc' |
||
11 | include 'tinypy.inc' |
||
12 | |||
13 | extrn tp_dict |
||
14 | extrn tp_set |
||
15 | extrn tp_get |
||
16 | extrn tp_None |
||
17 | extrn tp_fnc |
||
18 | |||
2048 | jaeger | 19 | public kolibri_dbg_init |
1926 | jaeger | 20 | |
2048 | jaeger | 21 | ; Module name |
22 | modname db "kolibri_dbg" |
||
1926 | jaeger | 23 | modnamelen = $-modname |
2048 | jaeger | 24 | |
25 | ; Exported function name |
||
1926 | jaeger | 26 | debug_print_name db "debug_print" |
27 | debug_print_namelen = $-debug_print_name |
||
2048 | jaeger | 28 | ; Export dictionary for module |
29 | kolibri_dbg_dict rb sizeof.tp_obj |
||
30 | ; tp_obj of exported function |
||
1926 | jaeger | 31 | debug_print_obj rb sizeof.tp_obj |
32 | |||
2048 | jaeger | 33 | ; Function debug_print(tp_vm *tp) |
34 | ; return nothing |
||
1926 | jaeger | 35 | debug_print: |
36 | push ebp |
||
37 | mov ebp, esp |
||
38 | ; Store registers |
||
39 | push eax |
||
40 | push ebx |
||
41 | push ecx |
||
42 | push edx |
||
2048 | jaeger | 43 | sub esp, sizeof.tp_obj; Reserve tp_obj tmp |
44 | mov edx, esp |
||
45 | push edx ;Store &tmp |
||
1926 | jaeger | 46 | ; Obtain tp_string parameter |
2048 | jaeger | 47 | ; tp_get(&tmp, tp, *(tp_obj *)(tp_vm->params), tp_None) |
48 | push_tp_none |
||
49 | mov eax, dword[ebp+12] ;4 for return address, 4 for result pointer; 4 for tp_vm |
||
1926 | jaeger | 50 | add eax, tp_vm.params |
51 | push_tp_obj_at_reg eax |
||
2048 | jaeger | 52 | push dword[ebp+12] |
53 | push edx ;ebx contains address of reserved tp_obj variable |
||
1926 | jaeger | 54 | call tp_get |
2048 | jaeger | 55 | |
1926 | jaeger | 56 | ;Restore stack |
2048 | jaeger | 57 | 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) |
58 | |||
1926 | jaeger | 59 | ;Leave if parameter is not a string. tp_raise() should be called here. |
2048 | jaeger | 60 | pop edx; edx = &tmp |
61 | cmp dword[edx], TP_STRING ; Check that function returned a TP_STRING |
||
62 | jne .exit |
||
63 | mov ecx, dword[edx+tp_string_.len] ; String length |
||
64 | mov edx, dword[edx+tp_string_.val] ; |
||
65 | mov eax, 63 |
||
66 | mov ebx, 1 |
||
67 | .cont: |
||
68 | ; Print message. |
||
69 | push ecx ; Store ecx to use it in inner loop |
||
70 | mov cl, byte[edx] |
||
71 | inc edx |
||
72 | int 40h |
||
73 | pop ecx ; Get ecx back |
||
74 | loop .cont |
||
75 | .exit: |
||
76 | add esp, sizeof.tp_obj ; Release tp_obj reserved in stack. |
||
77 | ; Returning tp_None |
||
78 | mov eax, dword[ebp+8] |
||
79 | mov dword[eax], 0 |
||
80 | ; Restore registers |
||
1926 | jaeger | 81 | pop edx |
82 | pop ecx |
||
83 | pop ebx |
||
84 | pop eax |
||
85 | mov esp, ebp |
||
86 | pop ebp |
||
87 | ret |
||
88 | |||
2048 | jaeger | 89 | ;void kolibri_dbg_init(tp_vm *tp); |
90 | kolibri_dbg_init: |
||
1926 | jaeger | 91 | push ebp |
92 | mov ebp, esp |
||
93 | ;Save registers |
||
94 | push eax |
||
95 | push ebx |
||
96 | push ecx |
||
2048 | jaeger | 97 | ; Create module dictionary and store its address in kolibri_dbg_str |
1926 | jaeger | 98 | mov eax, dword [ebp + 8] |
99 | push eax |
||
2048 | jaeger | 100 | push kolibri_dbg_dict |
1926 | jaeger | 101 | call tp_dict |
102 | add esp, 4 ;Clear stack |
||
2048 | jaeger | 103 | ; Push tp_obj structure pointed by kolibri_dbg_dict |
104 | push_tp_obj kolibri_dbg_dict |
||
1926 | jaeger | 105 | ; Push modname as a tp_obj object |
106 | push modnamelen; len |
||
107 | push modname ; val |
||
108 | push 0 ;_tp_string info |
||
109 | push TP_STRING ; type |
||
110 | ; Push tp_obj structure pointed by tp->modules |
||
111 | mov eax, dword [ebp + 8] |
||
112 | add eax, tp_vm.modules + 16 |
||
113 | mov ecx, 4 |
||
114 | .push_tpobj1: |
||
115 | sub eax, 4 |
||
116 | push dword[eax] |
||
117 | loop .push_tpobj1 |
||
118 | push eax |
||
119 | call tp_set |
||
120 | add esp, sizeof.tp_obj*3+4 |
||
121 | ; Register "debug_print" function |
||
122 | ;Reserve memory for function tp_obj object |
||
123 | sub esp, sizeof.tp_obj |
||
124 | mov eax, esp |
||
125 | push debug_print |
||
126 | push dword[ebp+8] |
||
127 | push eax |
||
128 | call tp_fnc |
||
129 | add esp, 8; tp_obj is already in stack, adding other arguments |
||
130 | ;Pushing function name tp_obj |
||
131 | ;mov eax, esp |
||
132 | ;push_tp_obj_at_reg eax |
||
133 | push debug_print_namelen |
||
134 | push debug_print_name |
||
135 | push 0 |
||
136 | push TP_STRING |
||
137 | ;Pushing module dictionary tp_obj |
||
2048 | jaeger | 138 | push_tp_obj kolibri_dbg_dict |
1926 | jaeger | 139 | ;Pushing tp_vm |
140 | push dword[ebp+8] |
||
141 | call tp_set |
||
142 | add esp, sizeof.tp_obj*3+4 |
||
143 | ; Leaving function |
||
144 | pop ecx |
||
145 | pop ebx |
||
146 | pop eax |
||
147 | mov esp, ebp |
||
148 | pop ebp |
||
149 | ret |