Rev 431 | Rev 593 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 431 | Rev 465 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | $Revision: 431 $ |
1 | $Revision: 465 $ |
2 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
3 | ;; ;; |
3 | ;; ;; |
4 | ;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;; |
4 | ;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;; |
5 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; Distributed under terms of the GNU General Public License ;; |
6 | ;; ;; |
6 | ;; ;; |
Line 25... | Line 25... | ||
25 | dd debug_set_drx |
25 | dd debug_set_drx |
Line 26... | Line 26... | ||
26 | 26 | ||
27 | debug_set_event_data: |
27 | debug_set_event_data: |
28 | ; in: ebx = pointer |
28 | ; in: ebx = pointer |
29 | ; destroys eax |
29 | ; destroys eax |
30 | mov eax, [CURRENT_TASK] |
- | |
31 | shl eax, 8 |
30 | mov eax, [current_slot] |
32 | mov [eax+SLOT_BASE+APPDATA.dbg_event_mem], ebx |
31 | mov [eax+APPDATA.dbg_event_mem], ebx |
Line 33... | Line 32... | ||
33 | ret |
32 | ret |
34 | 33 | ||
35 | get_debuggee_slot: |
34 | get_debuggee_slot: |
Line 121... | Line 120... | ||
121 | ; ecx=sizeof(CONTEXT) |
120 | ; ecx=sizeof(CONTEXT) |
122 | ; edx->CONTEXT |
121 | ; edx->CONTEXT |
123 | ; destroys eax,ecx,edx,esi,edi |
122 | ; destroys eax,ecx,edx,esi,edi |
124 | cmp ecx, 28h |
123 | cmp ecx, 28h |
125 | jnz .ret |
124 | jnz .ret |
126 | add edx, std_application_base_address |
- | |
127 | push ebx |
125 | push ebx |
128 | mov ebx, edx |
126 | mov ebx, edx |
129 | call check_region |
127 | call check_region |
130 | pop ebx |
128 | pop ebx |
131 | dec eax |
129 | dec eax |
132 | jnz .ret |
130 | jnz .ret |
133 | call get_debuggee_slot |
131 | call get_debuggee_slot |
134 | jc .ret |
132 | jc .ret |
135 | imul eax, tss_step/32 |
133 | mov eax, [eax*8+SLOT_BASE+APPDATA.pl0_stack] |
136 | add eax, tss_data |
134 | lea esi, [eax+RING0_STACK_SIZE] |
137 | mov edi, edx |
135 | mov edi, edx |
138 | cmp [eax+TSS._cs], app_code |
- | |
139 | jnz .ring0 |
- | |
140 | lea esi, [eax+TSS._eip] |
- | |
141 | shr ecx, 2 |
- | |
142 | rep movsd |
- | |
143 | jmp .ret |
- | |
144 | .ring0: |
136 | .ring0: |
145 | ; note that following code assumes that all interrupt/exception handlers |
137 | ; note that following code assumes that all interrupt/exception handlers |
146 | ; saves ring-3 context by push ds es, pushad in this order |
138 | ; saves ring-3 context by pushad in this order |
147 | mov esi, [eax+TSS._esp0] |
- | |
148 | ; top of ring0 stack: ring3 stack ptr (ss+esp), iret data (cs+eip+eflags), ds, es, pushad |
139 | ; top of ring0 stack: ring3 stack ptr (ss+esp), iret data (cs+eip+eflags), pushad |
149 | sub esi, 8+12+8+20h |
140 | sub esi, 8+12+20h |
150 | lodsd |
141 | lodsd ;edi |
151 | mov [edi+24h], eax |
142 | mov [edi+24h], eax |
152 | lodsd |
143 | lodsd ;esi |
153 | mov [edi+20h], eax |
144 | mov [edi+20h], eax |
154 | lodsd |
145 | lodsd ; ebp |
155 | mov [edi+1Ch], eax |
146 | mov [edi+1Ch], eax |
156 | lodsd |
147 | lodsd ;esp |
157 | lodsd |
148 | lodsd ;ebx |
158 | mov [edi+14h], eax |
149 | mov [edi+14h], eax |
159 | lodsd |
150 | lodsd ;edx |
160 | mov [edi+10h], eax |
151 | mov [edi+10h], eax |
161 | lodsd |
152 | lodsd ;ecx |
162 | mov [edi+0Ch], eax |
153 | mov [edi+0Ch], eax |
163 | lodsd |
154 | lodsd ;eax |
164 | mov [edi+8], eax |
155 | mov [edi+8], eax |
165 | add esi, 8 |
156 | lodsd ;eip |
166 | lodsd |
- | |
167 | mov [edi], eax |
157 | mov [edi], eax |
168 | lodsd |
158 | lodsd ;cs |
169 | lodsd |
159 | lodsd ;eflags |
170 | mov [edi+4], eax |
160 | mov [edi+4], eax |
171 | lodsd |
161 | lodsd ;esp |
172 | mov [edi+18h], eax |
162 | mov [edi+18h], eax |
173 | .ret: |
163 | .ret: |
174 | sti |
164 | sti |
175 | ret |
165 | ret |
Line 180... | Line 170... | ||
180 | ; ecx=sizeof(CONTEXT) |
170 | ; ecx=sizeof(CONTEXT) |
181 | ; edx->CONTEXT |
171 | ; edx->CONTEXT |
182 | ; destroys eax,ecx,edx,esi,edi |
172 | ; destroys eax,ecx,edx,esi,edi |
183 | cmp ecx, 28h |
173 | cmp ecx, 28h |
184 | jnz .ret |
174 | jnz .ret |
185 | add edx, std_application_base_address |
- | |
186 | push ebx |
175 | push ebx |
187 | mov ebx, edx |
176 | mov ebx, edx |
188 | call check_region |
177 | call check_region |
189 | pop ebx |
178 | pop ebx |
190 | dec eax |
179 | dec eax |
191 | jnz .ret |
180 | jnz .ret |
192 | call get_debuggee_slot |
181 | call get_debuggee_slot |
193 | jc .stiret |
182 | jc .stiret |
194 | imul eax, tss_step/32 |
183 | mov eax, [eax*8+SLOT_BASE+APPDATA.pl0_stack] |
195 | add eax, tss_data |
184 | lea edi, [eax+RING0_STACK_SIZE] |
196 | mov esi, edx |
185 | mov esi, edx |
197 | cmp [eax+TSS._cs], app_code |
- | |
198 | jnz .ring0 |
- | |
199 | lea edi, [eax+TSS._eip] |
- | |
200 | shr ecx, 2 |
- | |
201 | rep movsd |
- | |
202 | jmp .stiret |
- | |
203 | .ring0: |
186 | .ring0: |
204 | mov edi, [eax+TSS._esp0] |
187 | sub edi, 8+12+20h |
205 | sub edi, 8+12+8+20h |
- | |
206 | mov eax, [esi+24h] |
188 | mov eax, [esi+24h] ;edi |
207 | stosd |
189 | stosd |
208 | mov eax, [esi+20h] |
190 | mov eax, [esi+20h] ;esi |
209 | stosd |
191 | stosd |
210 | mov eax, [esi+1Ch] |
192 | mov eax, [esi+1Ch] ;ebp |
211 | stosd |
193 | stosd |
212 | scasd |
194 | scasd |
213 | mov eax, [esi+14h] |
195 | mov eax, [esi+14h] ;ebx |
214 | stosd |
196 | stosd |
215 | mov eax, [esi+10h] |
197 | mov eax, [esi+10h] ;edx |
216 | stosd |
198 | stosd |
217 | mov eax, [esi+0Ch] |
199 | mov eax, [esi+0Ch] ;ecx |
218 | stosd |
200 | stosd |
219 | mov eax, [esi+8] |
201 | mov eax, [esi+8] ;eax |
220 | stosd |
202 | stosd |
221 | add edi, 8 |
- | |
222 | mov eax, [esi] |
203 | mov eax, [esi] ;eip |
223 | stosd |
204 | stosd |
224 | scasd |
205 | scasd |
225 | mov eax, [esi+4] |
206 | mov eax, [esi+4] ;eflags |
226 | stosd |
207 | stosd |
227 | mov eax, [esi+18h] |
208 | mov eax, [esi+18h] ;esp |
228 | stosd |
209 | stosd |
229 | .stiret: |
210 | .stiret: |
230 | sti |
211 | sti |
231 | .ret: |
212 | .ret: |
232 | ret |
213 | ret |
Line 236... | Line 217... | ||
236 | jc .errret |
217 | jc .errret |
237 | mov ebp, eax |
218 | mov ebp, eax |
238 | lea eax, [eax*8+SLOT_BASE+APPDATA.dbg_regs] |
219 | lea eax, [eax*8+SLOT_BASE+APPDATA.dbg_regs] |
239 | ; [eax]=dr0, [eax+4]=dr1, [eax+8]=dr2, [eax+C]=dr3 |
220 | ; [eax]=dr0, [eax+4]=dr1, [eax+8]=dr2, [eax+C]=dr3 |
240 | ; [eax+10]=dr7 |
221 | ; [eax+10]=dr7 |
241 | add edx, std_application_base_address |
222 | cmp edx, OS_BASE |
242 | jc .errret |
223 | jae .errret |
243 | cmp cl, 3 |
224 | cmp cl, 3 |
244 | ja .errret |
225 | ja .errret |
245 | mov ebx, dr7 |
226 | mov ebx, dr7 |
246 | shr ebx, cl |
227 | shr ebx, cl |
247 | shr ebx, cl |
228 | shr ebx, cl |
Line 254... | Line 235... | ||
254 | add ecx, ecx |
235 | add ecx, ecx |
255 | and dword [eax+ecx*2], 0 ; clear DR |
236 | and dword [eax+ecx*2], 0 ; clear DR |
256 | btr dword [eax+10h], ecx ; clear L bit |
237 | btr dword [eax+10h], ecx ; clear L bit |
257 | test byte [eax+10h], 55h |
238 | test byte [eax+10h], 55h |
258 | jnz .okret |
239 | jnz .okret |
259 | imul eax, ebp, tss_step/32 |
240 | ; imul eax, ebp, tss_step/32 |
260 | and byte [eax + tss_data + TSS._trap], not 1 |
241 | ; and byte [eax + tss_data + TSS._trap], not 1 |
- | 242 | and [ebp*8 + SLOT_BASE+APPDATA.dbg_state], not 1 |
|
261 | .okret: |
243 | .okret: |
262 | and dword [esp+36], 0 |
244 | and dword [esp+36], 0 |
263 | sti |
245 | sti |
264 | ret |
246 | ret |
265 | .errret: |
247 | .errret: |
Line 296... | Line 278... | ||
296 | mov edx, 0xF |
278 | mov edx, 0xF |
297 | shl edx, cl |
279 | shl edx, cl |
298 | not edx |
280 | not edx |
299 | and [eax+10h+2], dx |
281 | and [eax+10h+2], dx |
300 | or [eax+10h+2], bx ; set R/W and LEN fields |
282 | or [eax+10h+2], bx ; set R/W and LEN fields |
301 | imul eax, ebp, tss_step/32 |
283 | ; imul eax, ebp, tss_step/32 |
302 | or byte [eax + tss_data + TSS._trap], 1 |
284 | ; or byte [eax + tss_data + TSS._trap], 1 |
- | 285 | or [ebp*8 + SLOT_BASE+APPDATA.dbg_state], 1 |
|
303 | jmp .okret |
286 | jmp .okret |
Line 304... | Line 287... | ||
304 | 287 | ||
305 | debug_read_process_memory: |
288 | debug_read_process_memory: |
306 | ; in: |
289 | ; in: |
307 | ; ebx=pid |
290 | ; ebx=pid |
308 | ; ecx=length |
291 | ; ecx=length |
309 | ; esi->buffer in debugger |
292 | ; esi->buffer in debugger |
310 | ; edx=address in debuggee |
293 | ; edx=address in debuggee |
311 | ; out: [esp+36]=sizeof(read) |
294 | ; out: [esp+36]=sizeof(read) |
312 | ; destroys all |
- | |
313 | add esi, std_application_base_address |
295 | ; destroys all |
314 | push ebx |
296 | push ebx |
315 | mov ebx, esi |
297 | mov ebx, esi |
316 | call check_region |
298 | call check_region |
317 | pop ebx |
299 | pop ebx |
Line 335... | Line 317... | ||
335 | ; ecx=length |
317 | ; ecx=length |
336 | ; esi->buffer in debugger |
318 | ; esi->buffer in debugger |
337 | ; edx=address in debuggee |
319 | ; edx=address in debuggee |
338 | ; out: [esp+36]=sizeof(write) |
320 | ; out: [esp+36]=sizeof(write) |
339 | ; destroys all |
321 | ; destroys all |
340 | add esi, std_application_base_address |
- | |
341 | push ebx |
322 | push ebx |
342 | mov ebx, esi |
323 | mov ebx, esi |
343 | call check_region |
324 | call check_region |
344 | pop ebx |
325 | pop ebx |
345 | dec eax |
326 | dec eax |
Line 428... | Line 409... | ||
428 | 409 | ||
429 | debug_exc: |
410 | debug_exc: |
430 | ; int 1 = #DB |
411 | ; int 1 = #DB |
431 | save_ring3_context |
412 | save_ring3_context |
432 | cld |
413 | cld |
433 | mov ax, os_data |
414 | mov ax, app_data ;os_data |
434 | mov ds, ax |
415 | mov ds, ax |
435 | mov es, ax |
416 | mov es, ax |
436 | mov eax, dr6 |
- | |
437 | test ax, ax |
- | |
438 | jns @f |
- | |
439 | ; this is exception from task switch |
- | |
440 | ; set DRx registers for task and continue |
- | |
441 | mov eax, [CURRENT_TASK] |
- | |
442 | shl eax, 8 |
- | |
443 | add eax, SLOT_BASE+APPDATA.dbg_regs |
- | |
444 | mov ecx, [eax+0] |
- | |
445 | mov dr0, ecx |
- | |
446 | mov ecx, [eax+4] |
- | |
447 | mov dr1, ecx |
- | |
448 | mov ecx, [eax+8] |
- | |
449 | mov dr2, ecx |
- | |
450 | mov ecx, [eax+0Ch] |
- | |
451 | mov dr3, ecx |
- | |
452 | xor ecx, ecx |
- | |
453 | mov dr6, ecx |
- | |
454 | mov ecx, [eax+10h] |
- | |
455 | mov dr7, ecx |
- | |
456 | restore_ring3_context |
- | |
457 | iretd |
- | |
458 | @@: |
417 | mov eax, dr6 |
459 | push eax |
418 | push eax |
460 | xor eax, eax |
419 | xor eax, eax |
461 | mov dr6, eax |
420 | mov dr6, eax |
462 | ; test if debugging |
421 | ; test if debugging |
463 | cli |
422 | cli |
464 | mov eax, [CURRENT_TASK] |
- | |
465 | shl eax, 8 |
423 | mov eax, [current_slot] |
466 | mov eax, [SLOT_BASE+eax+APPDATA.debugger_slot] |
424 | mov eax, [eax+APPDATA.debugger_slot] |
467 | test eax, eax |
425 | test eax, eax |
468 | jnz .debug |
426 | jnz .debug |
469 | sti |
427 | sti |
470 | ; not debuggee => say error and terminate |
428 | ; not debuggee => say error and terminate |
471 | add esp, 28h+4 |
429 | add esp, 0x20+4 |
472 | mov [error_interrupt], 1 |
430 | mov [error_interrupt], 1 |
473 | call show_error_parameters |
431 | call show_error_parameters |
474 | mov edx, [TASK_BASE] |
432 | mov edx, [TASK_BASE] |
475 | mov byte [edx+TASKDATA.state], 4 |
433 | mov byte [edx+TASKDATA.state], 4 |