Rev 1076 | Rev 1394 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
431 | serge | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
3 | ;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;; |
||
4 | ;; Distributed under terms of the GNU General Public License ;; |
||
5 | ;; ;; |
||
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
7 | |||
593 | mikedld | 8 | $Revision: 1329 $ |
9 | |||
10 | |||
40 | halyavin | 11 | ; diamond, 2006 |
12 | sys_debug_services: |
||
1329 | Lrz | 13 | cmp ebx, 9 |
1056 | Galkov | 14 | ja @f |
1329 | Lrz | 15 | jmp dword [sys_debug_services_table+ebx*4] |
1056 | Galkov | 16 | @@: ret |
1329 | Lrz | 17 | iglobal |
18 | align 4 |
||
40 | halyavin | 19 | sys_debug_services_table: |
1056 | Galkov | 20 | dd debug_set_event_data |
21 | dd debug_getcontext |
||
22 | dd debug_setcontext |
||
23 | dd debug_detach |
||
24 | dd debug_suspend |
||
25 | dd debug_resume |
||
26 | dd debug_read_process_memory |
||
27 | dd debug_write_process_memory |
||
28 | dd debug_terminate |
||
29 | dd debug_set_drx |
||
1329 | Lrz | 30 | endg |
40 | halyavin | 31 | debug_set_event_data: |
1329 | Lrz | 32 | ; in: ecx = pointer |
40 | halyavin | 33 | ; destroys eax |
465 | serge | 34 | mov eax, [current_slot] |
1329 | Lrz | 35 | mov [eax+APPDATA.dbg_event_mem], ecx |
1056 | Galkov | 36 | ret |
40 | halyavin | 37 | |
38 | get_debuggee_slot: |
||
1329 | Lrz | 39 | ; in: ecx=PID |
40 | halyavin | 40 | ; out: CF=1 if error |
41 | ; CF=0 and eax=slot*0x20 if ok |
||
42 | ; out: interrupts disabled |
||
1056 | Galkov | 43 | cli |
1329 | Lrz | 44 | mov eax, ecx |
1056 | Galkov | 45 | call pid_to_slot |
46 | test eax, eax |
||
47 | jz .ret_bad |
||
48 | shl eax, 5 |
||
49 | push ebx |
||
379 | serge | 50 | mov ebx, [CURRENT_TASK] |
380 | serge | 51 | cmp [SLOT_BASE+eax*8+APPDATA.debugger_slot], ebx |
1056 | Galkov | 52 | pop ebx |
53 | jnz .ret_bad |
||
54 | ; clc ; automatically |
||
55 | ret |
||
40 | halyavin | 56 | .ret_bad: |
1056 | Galkov | 57 | stc |
58 | ret |
||
40 | halyavin | 59 | |
60 | debug_detach: |
||
1329 | Lrz | 61 | ; in: ecx=pid |
40 | halyavin | 62 | ; destroys eax,ebx |
1056 | Galkov | 63 | call get_debuggee_slot |
64 | jc .ret |
||
380 | serge | 65 | and dword [eax*8+SLOT_BASE+APPDATA.debugger_slot], 0 |
1056 | Galkov | 66 | call do_resume |
40 | halyavin | 67 | .ret: |
1056 | Galkov | 68 | sti |
69 | ret |
||
40 | halyavin | 70 | |
71 | debug_terminate: |
||
1329 | Lrz | 72 | ; in: ecx=pid |
1056 | Galkov | 73 | call get_debuggee_slot |
74 | jc debug_detach.ret |
||
75 | mov ecx, eax |
||
76 | shr ecx, 5 |
||
1329 | Lrz | 77 | ; push 2 |
78 | ; pop ebx |
||
79 | mov edx,esi |
||
80 | jmp sysfn_terminate |
||
40 | halyavin | 81 | |
82 | debug_suspend: |
||
1329 | Lrz | 83 | ; in: ecx=pid |
84 | ; destroys eax,ecx |
||
667 | diamond | 85 | cli |
1329 | Lrz | 86 | mov eax, ecx |
667 | diamond | 87 | call pid_to_slot |
680 | diamond | 88 | shl eax, 5 |
667 | diamond | 89 | jz .ret |
1329 | Lrz | 90 | mov cl, [CURRENT_TASK+eax+TASKDATA.state] ; process state |
91 | test cl, cl |
||
1056 | Galkov | 92 | jz .1 |
1329 | Lrz | 93 | cmp cl, 5 |
1056 | Galkov | 94 | jnz .ret |
1329 | Lrz | 95 | mov cl, 2 |
96 | .2: mov [CURRENT_TASK+eax+TASKDATA.state], cl |
||
40 | halyavin | 97 | .ret: |
1056 | Galkov | 98 | sti |
99 | ret |
||
40 | halyavin | 100 | .1: |
1329 | Lrz | 101 | inc ecx |
1056 | Galkov | 102 | jmp .2 |
40 | halyavin | 103 | |
104 | do_resume: |
||
1329 | Lrz | 105 | mov cl, [CURRENT_TASK+eax+TASKDATA.state] |
106 | cmp cl, 1 |
||
1056 | Galkov | 107 | jz .1 |
1329 | Lrz | 108 | cmp cl, 2 |
1056 | Galkov | 109 | jnz .ret |
1329 | Lrz | 110 | mov cl, 5 |
111 | .2: mov [CURRENT_TASK+eax+TASKDATA.state], cl |
||
1056 | Galkov | 112 | .ret: ret |
1329 | Lrz | 113 | .1: dec ecx |
1056 | Galkov | 114 | jmp .2 |
40 | halyavin | 115 | |
116 | debug_resume: |
||
1329 | Lrz | 117 | ; in: ecx=pid |
40 | halyavin | 118 | ; destroys eax,ebx |
667 | diamond | 119 | cli |
1329 | Lrz | 120 | mov eax, ecx |
667 | diamond | 121 | call pid_to_slot |
680 | diamond | 122 | shl eax, 5 |
667 | diamond | 123 | jz .ret |
124 | call do_resume |
||
1056 | Galkov | 125 | .ret: sti |
126 | ret |
||
40 | halyavin | 127 | |
128 | debug_getcontext: |
||
129 | ; in: |
||
1329 | Lrz | 130 | ; ecx=pid |
131 | ; edx=sizeof(CONTEXT) |
||
132 | ; esi->CONTEXT |
||
40 | halyavin | 133 | ; destroys eax,ecx,edx,esi,edi |
1329 | Lrz | 134 | cmp edx, 28h |
1056 | Galkov | 135 | jnz .ret |
1329 | Lrz | 136 | ; push ecx |
137 | ; mov ecx, esi |
||
1056 | Galkov | 138 | call check_region |
1329 | Lrz | 139 | ; pop ecx |
1056 | Galkov | 140 | dec eax |
141 | jnz .ret |
||
142 | call get_debuggee_slot |
||
143 | jc .ret |
||
1329 | Lrz | 144 | mov edi, esi |
465 | serge | 145 | mov eax, [eax*8+SLOT_BASE+APPDATA.pl0_stack] |
146 | lea esi, [eax+RING0_STACK_SIZE] |
||
1329 | Lrz | 147 | |
40 | halyavin | 148 | .ring0: |
149 | ; note that following code assumes that all interrupt/exception handlers |
||
465 | serge | 150 | ; saves ring-3 context by pushad in this order |
151 | ; top of ring0 stack: ring3 stack ptr (ss+esp), iret data (cs+eip+eflags), pushad |
||
152 | sub esi, 8+12+20h |
||
153 | lodsd ;edi |
||
1056 | Galkov | 154 | mov [edi+24h], eax |
465 | serge | 155 | lodsd ;esi |
1056 | Galkov | 156 | mov [edi+20h], eax |
465 | serge | 157 | lodsd ; ebp |
1056 | Galkov | 158 | mov [edi+1Ch], eax |
465 | serge | 159 | lodsd ;esp |
160 | lodsd ;ebx |
||
1056 | Galkov | 161 | mov [edi+14h], eax |
465 | serge | 162 | lodsd ;edx |
1056 | Galkov | 163 | mov [edi+10h], eax |
465 | serge | 164 | lodsd ;ecx |
1056 | Galkov | 165 | mov [edi+0Ch], eax |
465 | serge | 166 | lodsd ;eax |
1056 | Galkov | 167 | mov [edi+8], eax |
465 | serge | 168 | lodsd ;eip |
1056 | Galkov | 169 | mov [edi], eax |
465 | serge | 170 | lodsd ;cs |
171 | lodsd ;eflags |
||
1056 | Galkov | 172 | mov [edi+4], eax |
465 | serge | 173 | lodsd ;esp |
1056 | Galkov | 174 | mov [edi+18h], eax |
40 | halyavin | 175 | .ret: |
1056 | Galkov | 176 | sti |
177 | ret |
||
40 | halyavin | 178 | |
179 | debug_setcontext: |
||
180 | ; in: |
||
1329 | Lrz | 181 | ; ecx=pid |
182 | ; edx=sizeof(CONTEXT) |
||
183 | ; esi->CONTEXT |
||
40 | halyavin | 184 | ; destroys eax,ecx,edx,esi,edi |
1329 | Lrz | 185 | cmp edx, 28h |
1056 | Galkov | 186 | jnz .ret |
1329 | Lrz | 187 | ; push ebx |
188 | ; mov ebx, edx |
||
1056 | Galkov | 189 | call check_region |
1329 | Lrz | 190 | ; pop ebx |
1056 | Galkov | 191 | dec eax |
192 | jnz .ret |
||
193 | call get_debuggee_slot |
||
194 | jc .stiret |
||
1329 | Lrz | 195 | ; mov esi, edx |
465 | serge | 196 | mov eax, [eax*8+SLOT_BASE+APPDATA.pl0_stack] |
197 | lea edi, [eax+RING0_STACK_SIZE] |
||
1329 | Lrz | 198 | |
40 | halyavin | 199 | .ring0: |
465 | serge | 200 | sub edi, 8+12+20h |
201 | mov eax, [esi+24h] ;edi |
||
1056 | Galkov | 202 | stosd |
465 | serge | 203 | mov eax, [esi+20h] ;esi |
1056 | Galkov | 204 | stosd |
465 | serge | 205 | mov eax, [esi+1Ch] ;ebp |
1056 | Galkov | 206 | stosd |
465 | serge | 207 | scasd |
208 | mov eax, [esi+14h] ;ebx |
||
1056 | Galkov | 209 | stosd |
465 | serge | 210 | mov eax, [esi+10h] ;edx |
1056 | Galkov | 211 | stosd |
465 | serge | 212 | mov eax, [esi+0Ch] ;ecx |
1056 | Galkov | 213 | stosd |
465 | serge | 214 | mov eax, [esi+8] ;eax |
1056 | Galkov | 215 | stosd |
465 | serge | 216 | mov eax, [esi] ;eip |
1056 | Galkov | 217 | stosd |
218 | scasd |
||
465 | serge | 219 | mov eax, [esi+4] ;eflags |
1056 | Galkov | 220 | stosd |
465 | serge | 221 | mov eax, [esi+18h] ;esp |
1056 | Galkov | 222 | stosd |
40 | halyavin | 223 | .stiret: |
1056 | Galkov | 224 | sti |
40 | halyavin | 225 | .ret: |
1056 | Galkov | 226 | ret |
40 | halyavin | 227 | |
66 | diamond | 228 | debug_set_drx: |
1056 | Galkov | 229 | call get_debuggee_slot |
230 | jc .errret |
||
231 | mov ebp, eax |
||
380 | serge | 232 | lea eax, [eax*8+SLOT_BASE+APPDATA.dbg_regs] |
66 | diamond | 233 | ; [eax]=dr0, [eax+4]=dr1, [eax+8]=dr2, [eax+C]=dr3 |
234 | ; [eax+10]=dr7 |
||
1329 | Lrz | 235 | cmp esi, OS_BASE |
465 | serge | 236 | jae .errret |
1329 | Lrz | 237 | cmp dl, 3 |
1056 | Galkov | 238 | ja .errret |
1329 | Lrz | 239 | mov ecx, dr7 |
240 | ;fix me |
||
241 | xchg ecx,edx |
||
242 | shr edx, cl |
||
243 | shr edx, cl |
||
244 | xchg ecx,edx |
||
245 | |||
246 | test ecx, 2 ; bit 1+2*index = G0..G3, global break enable |
||
1056 | Galkov | 247 | jnz .errret2 |
1329 | Lrz | 248 | test dh, dh |
1056 | Galkov | 249 | jns .new |
66 | diamond | 250 | ; clear breakpoint |
1329 | Lrz | 251 | movzx edx, dl |
252 | add edx, edx |
||
253 | and dword [eax+edx*2], 0 ; clear DR |
||
254 | btr dword [eax+10h], edx ; clear L bit |
||
1056 | Galkov | 255 | test byte [eax+10h], 55h |
256 | jnz .okret |
||
465 | serge | 257 | ; imul eax, ebp, tss_step/32 |
258 | ; and byte [eax + tss_data + TSS._trap], not 1 |
||
259 | and [ebp*8 + SLOT_BASE+APPDATA.dbg_state], not 1 |
||
66 | diamond | 260 | .okret: |
1329 | Lrz | 261 | and dword [esp+32], 0 |
1056 | Galkov | 262 | sti |
263 | ret |
||
66 | diamond | 264 | .errret: |
1056 | Galkov | 265 | sti |
1329 | Lrz | 266 | mov dword [esp+32], 1 |
1056 | Galkov | 267 | ret |
66 | diamond | 268 | .errret2: |
1056 | Galkov | 269 | sti |
1329 | Lrz | 270 | mov dword [esp+32], 2 |
1056 | Galkov | 271 | ret |
66 | diamond | 272 | .new: |
273 | ; add new breakpoint |
||
1329 | Lrz | 274 | ; dl=index; dh=flags; esi=address |
275 | test dh, 0xF0 |
||
1056 | Galkov | 276 | jnz .errret |
1329 | Lrz | 277 | mov cl, dh |
278 | and cl, 3 |
||
279 | cmp cl, 2 |
||
1056 | Galkov | 280 | jz .errret |
1329 | Lrz | 281 | mov cl, dh |
282 | shr cl, 2 |
||
283 | cmp cl, 2 |
||
1056 | Galkov | 284 | jz .errret |
1329 | Lrz | 285 | |
286 | mov ebx,esi |
||
287 | test bl, dl |
||
288 | |||
1056 | Galkov | 289 | jnz .errret |
290 | or byte [eax+10h+1], 3 ; set GE and LE flags |
||
1329 | Lrz | 291 | |
292 | movzx edx, dh |
||
293 | movzx ecx, dl |
||
1056 | Galkov | 294 | add ecx, ecx |
295 | bts dword [eax+10h], ecx ; set L flag |
||
296 | add ecx, ecx |
||
1329 | Lrz | 297 | mov [eax+ecx], ebx;esi ; set DR |
298 | shl edx, cl |
||
299 | mov ebx, 0xF |
||
1056 | Galkov | 300 | shl ebx, cl |
1329 | Lrz | 301 | not ebx |
302 | and [eax+10h+2], bx |
||
303 | or [eax+10h+2], dx ; set R/W and LEN fields |
||
465 | serge | 304 | ; imul eax, ebp, tss_step/32 |
305 | ; or byte [eax + tss_data + TSS._trap], 1 |
||
306 | or [ebp*8 + SLOT_BASE+APPDATA.dbg_state], 1 |
||
1056 | Galkov | 307 | jmp .okret |
66 | diamond | 308 | |
40 | halyavin | 309 | debug_read_process_memory: |
310 | ; in: |
||
1329 | Lrz | 311 | ; ecx=pid |
312 | ; edx=length |
||
313 | ; edi->buffer in debugger |
||
314 | ; esi=address in debuggee |
||
44 | halyavin | 315 | ; out: [esp+36]=sizeof(read) |
40 | halyavin | 316 | ; destroys all |
1329 | Lrz | 317 | ; push ebx |
318 | ; mov ebx, esi |
||
1056 | Galkov | 319 | call check_region |
1329 | Lrz | 320 | ; pop ebx |
1056 | Galkov | 321 | dec eax |
322 | jnz .err |
||
323 | call get_debuggee_slot |
||
324 | jc .err |
||
325 | shr eax, 5 |
||
1329 | Lrz | 326 | ; mov ebx, esi |
1056 | Galkov | 327 | call read_process_memory |
328 | sti |
||
1329 | Lrz | 329 | mov dword [esp+32], eax |
1056 | Galkov | 330 | ret |
44 | halyavin | 331 | .err: |
1329 | Lrz | 332 | or dword [esp+32], -1 |
1056 | Galkov | 333 | ret |
40 | halyavin | 334 | |
335 | debug_write_process_memory: |
||
336 | ; in: |
||
1329 | Lrz | 337 | ; ecx=pid |
338 | ; edx=length |
||
339 | ; edi->buffer in debugger |
||
340 | ; esi=address in debuggee |
||
44 | halyavin | 341 | ; out: [esp+36]=sizeof(write) |
40 | halyavin | 342 | ; destroys all |
1329 | Lrz | 343 | ; push ebx |
344 | ; mov ebx, esi |
||
1056 | Galkov | 345 | call check_region |
1329 | Lrz | 346 | ; pop ebx |
1056 | Galkov | 347 | dec eax |
348 | jnz debug_read_process_memory.err |
||
349 | call get_debuggee_slot |
||
350 | jc debug_read_process_memory.err |
||
351 | shr eax, 5 |
||
1329 | Lrz | 352 | ; mov ebx, esi |
1056 | Galkov | 353 | call write_process_memory |
354 | sti |
||
1329 | Lrz | 355 | mov [esp+32], eax |
1056 | Galkov | 356 | ret |
40 | halyavin | 357 | |
358 | debugger_notify: |
||
359 | ; in: eax=debugger slot |
||
360 | ; ecx=size of debug message |
||
361 | ; [esp+4]..[esp+4+ecx]=message |
||
362 | ; interrupts must be disabled! |
||
363 | ; destroys all general registers |
||
364 | ; interrupts remain disabled |
||
1056 | Galkov | 365 | xchg ebp, eax |
366 | mov edi, [timer_ticks] |
||
367 | add edi, 500 ; 5 sec timeout |
||
40 | halyavin | 368 | .1: |
1056 | Galkov | 369 | mov eax, ebp |
370 | shl eax, 8 |
||
380 | serge | 371 | mov edx, [SLOT_BASE+eax+APPDATA.dbg_event_mem] |
1056 | Galkov | 372 | test edx, edx |
373 | jz .ret |
||
40 | halyavin | 374 | ; read buffer header |
1056 | Galkov | 375 | push ecx |
376 | push eax |
||
377 | push eax |
||
378 | mov eax, ebp |
||
379 | mov ebx, esp |
||
380 | mov ecx, 8 |
||
381 | call read_process_memory |
||
382 | cmp eax, ecx |
||
383 | jz @f |
||
384 | add esp, 12 |
||
385 | jmp .ret |
||
40 | halyavin | 386 | @@: |
1056 | Galkov | 387 | cmp dword [ebx], 0 |
388 | jg @f |
||
40 | halyavin | 389 | .2: |
1056 | Galkov | 390 | pop ecx |
391 | pop ecx |
||
392 | pop ecx |
||
379 | serge | 393 | cmp dword [CURRENT_TASK], 1 |
1056 | Galkov | 394 | jnz .notos |
395 | cmp [timer_ticks], edi |
||
396 | jae .ret |
||
66 | diamond | 397 | .notos: |
1056 | Galkov | 398 | sti |
399 | call change_task |
||
400 | cli |
||
401 | jmp .1 |
||
40 | halyavin | 402 | @@: |
1056 | Galkov | 403 | mov ecx, [ebx+8] |
404 | add ecx, [ebx+4] |
||
405 | cmp ecx, [ebx] |
||
406 | ja .2 |
||
40 | halyavin | 407 | ; advance buffer position |
1056 | Galkov | 408 | push ecx |
409 | mov ecx, 4 |
||
410 | sub ebx, ecx |
||
411 | mov eax, ebp |
||
412 | add edx, ecx |
||
413 | call write_process_memory |
||
414 | pop eax |
||
40 | halyavin | 415 | ; write message |
1056 | Galkov | 416 | mov eax, ebp |
417 | add edx, ecx |
||
418 | add edx, [ebx+8] |
||
419 | add ebx, 20 |
||
420 | pop ecx |
||
421 | pop ecx |
||
422 | pop ecx |
||
423 | call write_process_memory |
||
40 | halyavin | 424 | ; new debug event |
1056 | Galkov | 425 | mov eax, ebp |
426 | shl eax, 8 |
||
380 | serge | 427 | or byte [SLOT_BASE+eax+APPDATA.event_mask+1], 1 ; set flag 100h |
40 | halyavin | 428 | .ret: |
1056 | Galkov | 429 | ret |