1 | ; $Id: PGMR3DbgA.asm 57126 2015-07-30 10:17:57Z vboxsync $
|
---|
2 | ;; @file
|
---|
3 | ; PGM - Page Manager and Monitor - Debugger & Debugging API Optimizations.
|
---|
4 | ;
|
---|
5 |
|
---|
6 | ;
|
---|
7 | ; Copyright (C) 2006-2015 Oracle Corporation
|
---|
8 | ;
|
---|
9 | ; This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | ; available from http://www.virtualbox.org. This file is free software;
|
---|
11 | ; you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | ; General Public License (GPL) as published by the Free Software
|
---|
13 | ; Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | ; VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | ; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | ;
|
---|
17 |
|
---|
18 |
|
---|
19 | ;*******************************************************************************
|
---|
20 | ;* Header Files *
|
---|
21 | ;*******************************************************************************
|
---|
22 | %define RT_ASM_WITH_SEH64
|
---|
23 | %include "VBox/asmdefs.mac"
|
---|
24 |
|
---|
25 |
|
---|
26 | ;
|
---|
27 | ; Common to all code below.
|
---|
28 | ;
|
---|
29 | %ifdef ASM_CALL64_MSC
|
---|
30 | %define pvNeedle r8
|
---|
31 | %define cbNeedle r9d
|
---|
32 | %define bTmp dl
|
---|
33 | %elifdef ASM_CALL64_GCC
|
---|
34 | %define pvNeedle rdx
|
---|
35 | %define cbNeedle esi
|
---|
36 | %define bTmp r9b
|
---|
37 | %elifdef RT_ARCH_X86
|
---|
38 | %define pvNeedle dword [esp + 8h]
|
---|
39 | %define cbNeedle dword [esp + 10h]
|
---|
40 | %else
|
---|
41 | %error "Unsupported arch!"
|
---|
42 | %endif
|
---|
43 |
|
---|
44 | ;;
|
---|
45 | ; Searches for a 8 byte needle in steps of 8.
|
---|
46 | ;
|
---|
47 | ; In 32-bit mode, this will only actually search for a 8 byte needle.
|
---|
48 | ;
|
---|
49 | ; @param pbHaystack [msc:rcx, gcc:rdi, x86:ebp+08h] What to search thru.
|
---|
50 | ; @param cbHaystack [msc:edx, gcc:rsi, x86:ebp+0ch] The amount of hay to search.
|
---|
51 | ; @param pvNeedle [msc:r8, gcc:rdx, x86:ebp+10h] What we're searching for
|
---|
52 | ; @param cbNeedle [msc:r9, gcc:rcx, x86:esp+10h] Size of what we're searcing for. Currently ignored.
|
---|
53 | ;
|
---|
54 | ; @remarks ASSUMES pbHaystack is aligned at uAlign.
|
---|
55 | ;
|
---|
56 | BEGINPROC pgmR3DbgFixedMemScan8Wide8Step
|
---|
57 | %ifdef ASM_CALL64_MSC
|
---|
58 | mov r10, rdi ; save it
|
---|
59 | mov rdi, rcx ; rdi=pbHaystack
|
---|
60 | mov ecx, edx ; rcx=cbHaystack
|
---|
61 | mov rax, [r8] ; *(uint64_t *)pvNeedle
|
---|
62 | %elifdef ASM_CALL64_GCC
|
---|
63 | xchg rcx, rsi ; rcx=cbHaystack, rsi=cbNeedle
|
---|
64 | mov rax, [rdx] ; *(uint64_t *)pvNeedle
|
---|
65 | %elifdef RT_ARCH_X86
|
---|
66 | mov edx, edi ; save it
|
---|
67 | mov edi, [ebp + 08h] ; pbHaystack
|
---|
68 | mov ecx, [ebp + 0ch] ; cbHaystack
|
---|
69 | mov eax, [ebp + 10h] ; pvNeedle
|
---|
70 | mov eax, [eax] ; *(uint64_t *)pvNeedle
|
---|
71 | %else
|
---|
72 | %error "Unsupported arch!"
|
---|
73 | %endif
|
---|
74 | SEH64_END_PROLOGUE
|
---|
75 |
|
---|
76 | cmp ecx, 8
|
---|
77 | jb .return_null
|
---|
78 | %ifdef RT_ARCH_X86
|
---|
79 | .again:
|
---|
80 | cmp [edi], eax
|
---|
81 | je .return_edi
|
---|
82 | dec ecx
|
---|
83 | jnz .again
|
---|
84 | jmp .return_null
|
---|
85 | .return_edi:
|
---|
86 | ;; @todo check the whole needle.
|
---|
87 | mov eax, edi
|
---|
88 |
|
---|
89 | %else ; RT_ARCH_AMD64
|
---|
90 | .continue:
|
---|
91 | shr ecx, 3
|
---|
92 | repne scasq
|
---|
93 | jne .return_null
|
---|
94 | ; check more of the needle if we can.
|
---|
95 | mov r11d, 8
|
---|
96 | .needle_check:
|
---|
97 | cmp cbNeedle, r11d
|
---|
98 | je .return_edi
|
---|
99 | cmp ecx, r11d ; don't bother converting ecx to bytes.
|
---|
100 | jb .return_edi
|
---|
101 | mov bTmp, [pvNeedle + r11]
|
---|
102 | cmp bTmp, [xDI + r11 - 8]
|
---|
103 | jne .continue
|
---|
104 | inc r11d
|
---|
105 | jmp .needle_check
|
---|
106 |
|
---|
107 | .return_edi:
|
---|
108 | lea xAX, [xDI - 8]
|
---|
109 | %endif
|
---|
110 | .return:
|
---|
111 | %ifdef ASM_CALL64_MSC
|
---|
112 | mov rdi, r10
|
---|
113 | %elifdef RT_ARCH_X86
|
---|
114 | mov edi, edx
|
---|
115 | %endif
|
---|
116 | ret
|
---|
117 |
|
---|
118 | .return_null:
|
---|
119 | xor eax, eax
|
---|
120 | jmp .return
|
---|
121 | ENDPROC pgmR3DbgFixedMemScan8Wide8Step
|
---|
122 |
|
---|
123 |
|
---|
124 | ;;
|
---|
125 | ; Searches for a 4 byte needle in steps of 4.
|
---|
126 | ;
|
---|
127 | ; @param pbHaystack [msc:rcx, gcc:rdi, x86:esp+04h] What to search thru.
|
---|
128 | ; @param cbHaystack [msc:edx, gcc:rsi, x86:esp+08h] The amount of hay to search.
|
---|
129 | ; @param pvNeedle [msc:r8, gcc:rdx, x86:esp+0ch] What we're searching for
|
---|
130 | ; @param cbNeedle [msc:r9, gcc:rcx, x86:esp+10h] Size of what we're searcing for. Currently ignored.
|
---|
131 | ;
|
---|
132 | ; @remarks ASSUMES pbHaystack is aligned at uAlign.
|
---|
133 | ;
|
---|
134 | BEGINPROC pgmR3DbgFixedMemScan4Wide4Step
|
---|
135 | %ifdef ASM_CALL64_MSC
|
---|
136 | mov r10, rdi ; save it
|
---|
137 | mov rdi, rcx ; rdi=pbHaystack
|
---|
138 | mov ecx, edx ; rcx=cbHaystack
|
---|
139 | mov eax, [r8] ; *(uint32_t *)pvNeedle
|
---|
140 | %elifdef ASM_CALL64_GCC
|
---|
141 | xchg rcx, rsi ; rcx=cbHaystack, rsi=cbNeedle
|
---|
142 | mov eax, [rdx] ; *(uint32_t *)pvNeedle
|
---|
143 | %elifdef RT_ARCH_X86
|
---|
144 | mov edx, edi ; save it
|
---|
145 | mov edi, [esp + 04h] ; pbHaystack
|
---|
146 | mov ecx, [esp + 08h] ; cbHaystack
|
---|
147 | mov eax, [esp + 0ch] ; pvNeedle
|
---|
148 | mov eax, [eax] ; *(uint32_t *)pvNeedle
|
---|
149 | %else
|
---|
150 | %error "Unsupported arch!"
|
---|
151 | %endif
|
---|
152 | SEH64_END_PROLOGUE
|
---|
153 |
|
---|
154 | .continue:
|
---|
155 | cmp ecx, 4
|
---|
156 | jb .return_null
|
---|
157 | shr ecx, 2
|
---|
158 | repne scasd
|
---|
159 | jne .return_null
|
---|
160 |
|
---|
161 | %ifdef RT_ARCH_AMD64
|
---|
162 | ; check more of the needle if we can.
|
---|
163 | mov r11d, 4
|
---|
164 | .needle_check:
|
---|
165 | cmp cbNeedle, r11d
|
---|
166 | je .return_edi
|
---|
167 | cmp ecx, r11d ; don't bother converting ecx to bytes.
|
---|
168 | jb .return_edi
|
---|
169 | mov bTmp, [pvNeedle + r11]
|
---|
170 | cmp bTmp, [xDI + r11 - 4]
|
---|
171 | jne .continue
|
---|
172 | inc r11d
|
---|
173 | jmp .needle_check
|
---|
174 | %endif
|
---|
175 |
|
---|
176 | .return_edi:
|
---|
177 | lea xAX, [xDI - 4]
|
---|
178 | .return:
|
---|
179 | %ifdef ASM_CALL64_MSC
|
---|
180 | mov rdi, r10
|
---|
181 | %elifdef RT_ARCH_X86
|
---|
182 | mov edi, edx
|
---|
183 | %endif
|
---|
184 | ret
|
---|
185 |
|
---|
186 | .return_null:
|
---|
187 | xor eax, eax
|
---|
188 | jmp .return
|
---|
189 | ENDPROC pgmR3DbgFixedMemScan4Wide4Step
|
---|
190 |
|
---|
191 |
|
---|
192 | ;;
|
---|
193 | ; Searches for a 2 byte needle in steps of 2.
|
---|
194 | ;
|
---|
195 | ; @param pbHaystack [msc:rcx, gcc:rdi, x86:esp+04h] What to search thru.
|
---|
196 | ; @param cbHaystack [msc:edx, gcc:rsi, x86:esp+08h] The amount of hay to search.
|
---|
197 | ; @param pvNeedle [msc:r8, gcc:rdx, x86:esp+0ch] What we're searching for
|
---|
198 | ; @param cbNeedle [msc:r9, gcc:rcx, x86:esp+10h] Size of what we're searcing for. Currently ignored.
|
---|
199 | ;
|
---|
200 | ; @remarks ASSUMES pbHaystack is aligned at uAlign.
|
---|
201 | ;
|
---|
202 | BEGINPROC pgmR3DbgFixedMemScan2Wide2Step
|
---|
203 | %ifdef ASM_CALL64_MSC
|
---|
204 | mov r10, rdi ; save it
|
---|
205 | mov rdi, rcx ; rdi=pbHaystack
|
---|
206 | mov ecx, edx ; rcx=cbHaystack
|
---|
207 | mov ax, [r8] ; *(uint16_t *)pvNeedle
|
---|
208 | %elifdef ASM_CALL64_GCC
|
---|
209 | xchg rcx, rsi ; rcx=cbHaystack, rsi=cbNeedle
|
---|
210 | mov ax, [rdx] ; *(uint16_t *)pvNeedle
|
---|
211 | %elifdef RT_ARCH_X86
|
---|
212 | mov edx, edi ; save it
|
---|
213 | mov edi, [esp + 04h] ; pbHaystack
|
---|
214 | mov ecx, [esp + 08h] ; cbHaystack
|
---|
215 | mov eax, [esp + 0ch] ; pvNeedle
|
---|
216 | mov ax, [eax] ; *(uint16_t *)pvNeedle
|
---|
217 | %else
|
---|
218 | %error "Unsupported arch!"
|
---|
219 | %endif
|
---|
220 | SEH64_END_PROLOGUE
|
---|
221 |
|
---|
222 | .continue:
|
---|
223 | cmp ecx, 2
|
---|
224 | jb .return_null
|
---|
225 | shr ecx, 1
|
---|
226 | repne scasw
|
---|
227 | jne .return_null
|
---|
228 |
|
---|
229 | %ifdef RT_ARCH_AMD64
|
---|
230 | ; check more of the needle if we can.
|
---|
231 | mov r11d, 2
|
---|
232 | .needle_check:
|
---|
233 | cmp cbNeedle, r11d
|
---|
234 | je .return_edi
|
---|
235 | cmp ecx, r11d ; don't bother converting ecx to bytes.
|
---|
236 | jb .return_edi
|
---|
237 | mov bTmp, [pvNeedle + r11]
|
---|
238 | cmp bTmp, [xDI + r11 - 2]
|
---|
239 | jne .continue
|
---|
240 | inc r11d
|
---|
241 | jmp .needle_check
|
---|
242 | %endif
|
---|
243 |
|
---|
244 | .return_edi:
|
---|
245 | lea xAX, [xDI - 2]
|
---|
246 | .return:
|
---|
247 | %ifdef ASM_CALL64_MSC
|
---|
248 | mov rdi, r10
|
---|
249 | %elifdef RT_ARCH_X86
|
---|
250 | mov edi, edx
|
---|
251 | %endif
|
---|
252 | ret
|
---|
253 |
|
---|
254 | .return_null:
|
---|
255 | xor eax, eax
|
---|
256 | jmp .return
|
---|
257 | ENDPROC pgmR3DbgFixedMemScan2Wide2Step
|
---|
258 |
|
---|
259 |
|
---|
260 | ;;
|
---|
261 | ; Searches for a 1 byte needle in steps of 1.
|
---|
262 | ;
|
---|
263 | ; @param pbHaystack [msc:rcx, gcc:rdi, x86:esp+04h] What to search thru.
|
---|
264 | ; @param cbHaystack [msc:edx, gcc:rsi, x86:esp+08h] The amount of hay to search.
|
---|
265 | ; @param pvNeedle [msc:r8, gcc:rdx, x86:esp+0ch] What we're searching for
|
---|
266 | ; @param cbNeedle [msc:r9, gcc:rcx, x86:esp+10h] Size of what we're searcing for. Currently ignored.
|
---|
267 | ;
|
---|
268 | BEGINPROC pgmR3DbgFixedMemScan1Wide1Step
|
---|
269 | %ifdef ASM_CALL64_MSC
|
---|
270 | mov r10, rdi ; save it
|
---|
271 | mov rdi, rcx ; rdi=pbHaystack
|
---|
272 | mov ecx, edx ; rcx=cbHaystack
|
---|
273 | mov al, [r8] ; *(uint8_t *)pvNeedle
|
---|
274 | %elifdef ASM_CALL64_GCC
|
---|
275 | xchg rcx, rsi ; rcx=cbHaystack, rsi=cbNeedle
|
---|
276 | mov al, [rdx] ; *(uint8_t *)pvNeedle
|
---|
277 | %elifdef RT_ARCH_X86
|
---|
278 | mov edx, edi ; save it
|
---|
279 | mov edi, [esp + 04h] ; pbHaystack
|
---|
280 | mov ecx, [esp + 08h] ; cbHaystack
|
---|
281 | mov eax, [esp + 0ch] ; pvNeedle
|
---|
282 | mov al, [eax] ; *(uint8_t *)pvNeedle
|
---|
283 | %else
|
---|
284 | %error "Unsupported arch!"
|
---|
285 | %endif
|
---|
286 | SEH64_END_PROLOGUE
|
---|
287 |
|
---|
288 | cmp ecx, 1
|
---|
289 | jb .return_null
|
---|
290 | .continue:
|
---|
291 | repne scasb
|
---|
292 | jne .return_null
|
---|
293 |
|
---|
294 | %ifdef RT_ARCH_AMD64
|
---|
295 | ; check more of the needle if we can.
|
---|
296 | mov r11d, 1
|
---|
297 | .needle_check:
|
---|
298 | cmp cbNeedle, r11d
|
---|
299 | je .return_edi
|
---|
300 | cmp ecx, r11d
|
---|
301 | jb .return_edi
|
---|
302 | mov bTmp, [pvNeedle + r11]
|
---|
303 | cmp bTmp, [xDI + r11 - 1]
|
---|
304 | jne .continue
|
---|
305 | inc r11d
|
---|
306 | jmp .needle_check
|
---|
307 | %endif
|
---|
308 |
|
---|
309 | .return_edi:
|
---|
310 | lea xAX, [xDI - 1]
|
---|
311 | .return:
|
---|
312 | %ifdef ASM_CALL64_MSC
|
---|
313 | mov rdi, r10
|
---|
314 | %elifdef RT_ARCH_X86
|
---|
315 | mov edi, edx
|
---|
316 | %endif
|
---|
317 | ret
|
---|
318 |
|
---|
319 | .return_null:
|
---|
320 | xor eax, eax
|
---|
321 | %ifdef ASM_CALL64_MSC
|
---|
322 | mov rdi, r10
|
---|
323 | %elifdef RT_ARCH_X86
|
---|
324 | mov edi, edx
|
---|
325 | %endif
|
---|
326 | ret
|
---|
327 | ENDPROC pgmR3DbgFixedMemScan1Wide1Step
|
---|
328 |
|
---|
329 |
|
---|
330 | ;;
|
---|
331 | ; Searches for a 4 byte needle in steps of 1.
|
---|
332 | ;
|
---|
333 | ; @param pbHaystack [msc:rcx, gcc:rdi, x86:esp+04h] What to search thru.
|
---|
334 | ; @param cbHaystack [msc:edx, gcc:rsi, x86:esp+08h] The amount of hay to search.
|
---|
335 | ; @param pvNeedle [msc:r8, gcc:rdx, x86:esp+0ch] What we're searching for
|
---|
336 | ; @param cbNeedle [msc:r9, gcc:rcx, x86:esp+10h] Size of what we're searcing for. Currently ignored.
|
---|
337 | ;
|
---|
338 | BEGINPROC pgmR3DbgFixedMemScan4Wide1Step
|
---|
339 | %ifdef ASM_CALL64_MSC
|
---|
340 | mov r10, rdi ; save it
|
---|
341 | mov rdi, rcx ; rdi=pbHaystack
|
---|
342 | mov ecx, edx ; rcx=cbHaystack
|
---|
343 | mov eax, [r8] ; *(uint32_t *)pvNeedle
|
---|
344 | %elifdef ASM_CALL64_GCC
|
---|
345 | xchg rcx, rsi ; rcx=cbHaystack, rsi=cbNeedle
|
---|
346 | mov eax, [rdx] ; *(uint32_t *)pvNeedle
|
---|
347 | %elifdef RT_ARCH_X86
|
---|
348 | mov edx, edi ; save it
|
---|
349 | mov edi, [esp + 04h] ; pbHaystack
|
---|
350 | mov ecx, [esp + 08h] ; cbHaystack
|
---|
351 | mov eax, [esp + 0ch] ; pvNeedle
|
---|
352 | mov eax, [eax] ; *(uint32_t *)pvNeedle
|
---|
353 | %else
|
---|
354 | %error "Unsupported arch!"
|
---|
355 | %endif
|
---|
356 | SEH64_END_PROLOGUE
|
---|
357 |
|
---|
358 | cmp ecx, 1
|
---|
359 | jb .return_null
|
---|
360 | .continue:
|
---|
361 | repne scasb
|
---|
362 | jne .return_null
|
---|
363 | cmp ecx, 3
|
---|
364 | jb .return_null
|
---|
365 | cmp eax, [xDI - 1]
|
---|
366 | jne .continue
|
---|
367 |
|
---|
368 | .return_edi:
|
---|
369 | lea xAX, [xDI - 1]
|
---|
370 | .return:
|
---|
371 | %ifdef ASM_CALL64_MSC
|
---|
372 | mov rdi, r10
|
---|
373 | %elifdef RT_ARCH_X86
|
---|
374 | mov edi, edx
|
---|
375 | %endif
|
---|
376 | ret
|
---|
377 |
|
---|
378 | .return_null:
|
---|
379 | xor eax, eax
|
---|
380 | %ifdef ASM_CALL64_MSC
|
---|
381 | mov rdi, r10
|
---|
382 | %elifdef RT_ARCH_X86
|
---|
383 | mov edi, edx
|
---|
384 | %endif
|
---|
385 | ret
|
---|
386 | ENDPROC pgmR3DbgFixedMemScan4Wide1Step
|
---|
387 |
|
---|
388 | ;;
|
---|
389 | ; Searches for a 8 byte needle in steps of 1.
|
---|
390 | ;
|
---|
391 | ; @param pbHaystack [msc:rcx, gcc:rdi, x86:esp+04h] What to search thru.
|
---|
392 | ; @param cbHaystack [msc:edx, gcc:rsi, x86:esp+08h] The amount of hay to search.
|
---|
393 | ; @param pvNeedle [msc:r8, gcc:rdx, x86:esp+0ch] What we're searching for
|
---|
394 | ; @param cbNeedle [msc:r9, gcc:rcx, x86:esp+10h] Size of what we're searcing for. Currently ignored.
|
---|
395 | ;
|
---|
396 | ; @remarks The 32-bit version is currently identical to pgmR3DbgFixedMemScan4Wide1Step.
|
---|
397 | ;
|
---|
398 | BEGINPROC pgmR3DbgFixedMemScan8Wide1Step
|
---|
399 | %ifdef ASM_CALL64_MSC
|
---|
400 | mov r10, rdi ; save it
|
---|
401 | mov rdi, rcx ; rdi=pbHaystack
|
---|
402 | mov ecx, edx ; rcx=cbHaystack
|
---|
403 | mov rax, [r8] ; *(uint64_t *)pvNeedle
|
---|
404 | %elifdef ASM_CALL64_GCC
|
---|
405 | xchg rcx, rsi ; rcx=cbHaystack, rsi=cbNeedle
|
---|
406 | mov rax, [rdx] ; *(uint64_t *)pvNeedle
|
---|
407 | %elifdef RT_ARCH_X86
|
---|
408 | mov edx, edi ; save it
|
---|
409 | mov edi, [esp + 04h] ; pbHaystack
|
---|
410 | mov ecx, [esp + 08h] ; cbHaystack
|
---|
411 | mov eax, [esp + 0ch] ; pvNeedle
|
---|
412 | mov eax, [eax] ; *(uint32_t *)pvNeedle
|
---|
413 | %else
|
---|
414 | %error "Unsupported arch!"
|
---|
415 | %endif
|
---|
416 | SEH64_END_PROLOGUE
|
---|
417 |
|
---|
418 | cmp ecx, 1
|
---|
419 | jb .return_null
|
---|
420 | .continue:
|
---|
421 | repne scasb
|
---|
422 | jne .return_null
|
---|
423 | %ifdef RT_ARCH_AMD64
|
---|
424 | cmp ecx, 7
|
---|
425 | jb .check_smaller
|
---|
426 | cmp rax, [xDI - 1]
|
---|
427 | jne .continue
|
---|
428 | jmp .return_edi
|
---|
429 | .check_smaller:
|
---|
430 | %endif
|
---|
431 | cmp ecx, 3
|
---|
432 | jb .return_null
|
---|
433 | cmp eax, [xDI - 1]
|
---|
434 | jne .continue
|
---|
435 |
|
---|
436 | .return_edi:
|
---|
437 | lea xAX, [xDI - 1]
|
---|
438 | .return:
|
---|
439 | %ifdef ASM_CALL64_MSC
|
---|
440 | mov rdi, r10
|
---|
441 | %elifdef RT_ARCH_X86
|
---|
442 | mov edi, edx
|
---|
443 | %endif
|
---|
444 | ret
|
---|
445 |
|
---|
446 | .return_null:
|
---|
447 | xor eax, eax
|
---|
448 | %ifdef ASM_CALL64_MSC
|
---|
449 | mov rdi, r10
|
---|
450 | %elifdef RT_ARCH_X86
|
---|
451 | mov edi, edx
|
---|
452 | %endif
|
---|
453 | ret
|
---|
454 | ENDPROC pgmR3DbgFixedMemScan8Wide1Step
|
---|
455 |
|
---|