Subversion Repositories Kolibri OS

Rev

Rev 1926 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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