Subversion Repositories Kolibri OS

Rev

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