VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMR3/PGMR3DbgA.asm@ 61116

Last change on this file since 61116 was 61110, checked in by vboxsync, 9 years ago

pgmR3DbgFixedMemScan8Wide8Step: Fixed bugs both the 32-bit and 64-bit versions, former were more severe.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.1 KB
Line 
1; $Id: PGMR3DbgA.asm 61110 2016-05-20 16:43:12Z 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;
56BEGINPROC 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 push ebp
67 mov ebp, esp
68 push edi ; save it
69 mov edi, [ebp + 08h] ; pbHaystack
70 mov ecx, [ebp + 0ch] ; cbHaystack
71 mov eax, [ebp + 10h] ; pvNeedle
72 mov edx, [eax + 4] ; ((uint32_t *)pvNeedle)[1]
73 mov eax, [eax] ; ((uint32_t *)pvNeedle)[0]
74%else
75 %error "Unsupported arch!"
76%endif
77SEH64_END_PROLOGUE
78
79%ifdef RT_ARCH_X86
80 ;
81 ; No string instruction to help us here. Do a simple tight loop instead.
82 ;
83 shr ecx, 3
84 jz .return_null
85.again:
86 cmp [edi], eax
87 je .needle_check
88.continue:
89 add edi, 8
90 dec ecx
91 jnz .again
92 jmp .return_null
93
94 ; Check the needle 2nd dword, caller can do the rest.
95.needle_check:
96 cmp edx, [edi + 4]
97 jne .continue
98
99.return_edi:
100 mov eax, edi
101
102%else ; RT_ARCH_AMD64
103 cmp ecx, 8
104 jb .return_null
105.continue:
106 shr ecx, 3
107 repne scasq
108 jne .return_null
109 ; check more of the needle if we can.
110 mov r11d, 8
111 shl ecx, 3
112.needle_check:
113 cmp cbNeedle, r11d
114 je .return_edi
115 cmp ecx, r11d
116 jb .return_edi ; returns success here as we've might've lost stuff while shifting ecx around.
117 mov bTmp, [pvNeedle + r11]
118 cmp bTmp, [xDI + r11 - 8]
119 jne .continue
120 inc r11d
121 jmp .needle_check
122
123.return_edi:
124 lea xAX, [xDI - 8]
125%endif ; RT_ARCH_AMD64
126
127.return:
128%ifdef ASM_CALL64_MSC
129 mov rdi, r10
130%elifdef RT_ARCH_X86
131 pop edi
132 leave
133%endif
134 ret
135
136.return_null:
137 xor eax, eax
138 jmp .return
139ENDPROC pgmR3DbgFixedMemScan8Wide8Step
140
141
142;;
143; Searches for a 4 byte needle in steps of 4.
144;
145; @param pbHaystack [msc:rcx, gcc:rdi, x86:esp+04h] What to search thru.
146; @param cbHaystack [msc:edx, gcc:rsi, x86:esp+08h] The amount of hay to search.
147; @param pvNeedle [msc:r8, gcc:rdx, x86:esp+0ch] What we're searching for
148; @param cbNeedle [msc:r9, gcc:rcx, x86:esp+10h] Size of what we're searcing for. Currently ignored.
149;
150; @remarks ASSUMES pbHaystack is aligned at uAlign.
151;
152BEGINPROC pgmR3DbgFixedMemScan4Wide4Step
153%ifdef ASM_CALL64_MSC
154 mov r10, rdi ; save it
155 mov rdi, rcx ; rdi=pbHaystack
156 mov ecx, edx ; rcx=cbHaystack
157 mov eax, [r8] ; *(uint32_t *)pvNeedle
158%elifdef ASM_CALL64_GCC
159 xchg rcx, rsi ; rcx=cbHaystack, rsi=cbNeedle
160 mov eax, [rdx] ; *(uint32_t *)pvNeedle
161%elifdef RT_ARCH_X86
162 mov edx, edi ; save it
163 mov edi, [esp + 04h] ; pbHaystack
164 mov ecx, [esp + 08h] ; cbHaystack
165 mov eax, [esp + 0ch] ; pvNeedle
166 mov eax, [eax] ; *(uint32_t *)pvNeedle
167%else
168 %error "Unsupported arch!"
169%endif
170SEH64_END_PROLOGUE
171
172.continue:
173 cmp ecx, 4
174 jb .return_null
175 shr ecx, 2
176 repne scasd
177 jne .return_null
178
179%ifdef RT_ARCH_AMD64
180 ; check more of the needle if we can.
181 mov r11d, 4
182.needle_check:
183 cmp cbNeedle, r11d
184 je .return_edi
185 cmp ecx, r11d ; don't bother converting ecx to bytes.
186 jb .return_edi
187 mov bTmp, [pvNeedle + r11]
188 cmp bTmp, [xDI + r11 - 4]
189 jne .continue
190 inc r11d
191 jmp .needle_check
192%endif
193
194.return_edi:
195 lea xAX, [xDI - 4]
196.return:
197%ifdef ASM_CALL64_MSC
198 mov rdi, r10
199%elifdef RT_ARCH_X86
200 mov edi, edx
201%endif
202 ret
203
204.return_null:
205 xor eax, eax
206 jmp .return
207ENDPROC pgmR3DbgFixedMemScan4Wide4Step
208
209
210;;
211; Searches for a 2 byte needle in steps of 2.
212;
213; @param pbHaystack [msc:rcx, gcc:rdi, x86:esp+04h] What to search thru.
214; @param cbHaystack [msc:edx, gcc:rsi, x86:esp+08h] The amount of hay to search.
215; @param pvNeedle [msc:r8, gcc:rdx, x86:esp+0ch] What we're searching for
216; @param cbNeedle [msc:r9, gcc:rcx, x86:esp+10h] Size of what we're searcing for. Currently ignored.
217;
218; @remarks ASSUMES pbHaystack is aligned at uAlign.
219;
220BEGINPROC pgmR3DbgFixedMemScan2Wide2Step
221%ifdef ASM_CALL64_MSC
222 mov r10, rdi ; save it
223 mov rdi, rcx ; rdi=pbHaystack
224 mov ecx, edx ; rcx=cbHaystack
225 mov ax, [r8] ; *(uint16_t *)pvNeedle
226%elifdef ASM_CALL64_GCC
227 xchg rcx, rsi ; rcx=cbHaystack, rsi=cbNeedle
228 mov ax, [rdx] ; *(uint16_t *)pvNeedle
229%elifdef RT_ARCH_X86
230 mov edx, edi ; save it
231 mov edi, [esp + 04h] ; pbHaystack
232 mov ecx, [esp + 08h] ; cbHaystack
233 mov eax, [esp + 0ch] ; pvNeedle
234 mov ax, [eax] ; *(uint16_t *)pvNeedle
235%else
236 %error "Unsupported arch!"
237%endif
238SEH64_END_PROLOGUE
239
240.continue:
241 cmp ecx, 2
242 jb .return_null
243 shr ecx, 1
244 repne scasw
245 jne .return_null
246
247%ifdef RT_ARCH_AMD64
248 ; check more of the needle if we can.
249 mov r11d, 2
250.needle_check:
251 cmp cbNeedle, r11d
252 je .return_edi
253 cmp ecx, r11d ; don't bother converting ecx to bytes.
254 jb .return_edi
255 mov bTmp, [pvNeedle + r11]
256 cmp bTmp, [xDI + r11 - 2]
257 jne .continue
258 inc r11d
259 jmp .needle_check
260%endif
261
262.return_edi:
263 lea xAX, [xDI - 2]
264.return:
265%ifdef ASM_CALL64_MSC
266 mov rdi, r10
267%elifdef RT_ARCH_X86
268 mov edi, edx
269%endif
270 ret
271
272.return_null:
273 xor eax, eax
274 jmp .return
275ENDPROC pgmR3DbgFixedMemScan2Wide2Step
276
277
278;;
279; Searches for a 1 byte needle in steps of 1.
280;
281; @param pbHaystack [msc:rcx, gcc:rdi, x86:esp+04h] What to search thru.
282; @param cbHaystack [msc:edx, gcc:rsi, x86:esp+08h] The amount of hay to search.
283; @param pvNeedle [msc:r8, gcc:rdx, x86:esp+0ch] What we're searching for
284; @param cbNeedle [msc:r9, gcc:rcx, x86:esp+10h] Size of what we're searcing for. Currently ignored.
285;
286BEGINPROC pgmR3DbgFixedMemScan1Wide1Step
287%ifdef ASM_CALL64_MSC
288 mov r10, rdi ; save it
289 mov rdi, rcx ; rdi=pbHaystack
290 mov ecx, edx ; rcx=cbHaystack
291 mov al, [r8] ; *(uint8_t *)pvNeedle
292%elifdef ASM_CALL64_GCC
293 xchg rcx, rsi ; rcx=cbHaystack, rsi=cbNeedle
294 mov al, [rdx] ; *(uint8_t *)pvNeedle
295%elifdef RT_ARCH_X86
296 mov edx, edi ; save it
297 mov edi, [esp + 04h] ; pbHaystack
298 mov ecx, [esp + 08h] ; cbHaystack
299 mov eax, [esp + 0ch] ; pvNeedle
300 mov al, [eax] ; *(uint8_t *)pvNeedle
301%else
302 %error "Unsupported arch!"
303%endif
304SEH64_END_PROLOGUE
305
306 cmp ecx, 1
307 jb .return_null
308.continue:
309 repne scasb
310 jne .return_null
311
312%ifdef RT_ARCH_AMD64
313 ; check more of the needle if we can.
314 mov r11d, 1
315.needle_check:
316 cmp cbNeedle, r11d
317 je .return_edi
318 cmp ecx, r11d
319 jb .return_edi
320 mov bTmp, [pvNeedle + r11]
321 cmp bTmp, [xDI + r11 - 1]
322 jne .continue
323 inc r11d
324 jmp .needle_check
325%endif
326
327.return_edi:
328 lea xAX, [xDI - 1]
329.return:
330%ifdef ASM_CALL64_MSC
331 mov rdi, r10
332%elifdef RT_ARCH_X86
333 mov edi, edx
334%endif
335 ret
336
337.return_null:
338 xor eax, eax
339%ifdef ASM_CALL64_MSC
340 mov rdi, r10
341%elifdef RT_ARCH_X86
342 mov edi, edx
343%endif
344 ret
345ENDPROC pgmR3DbgFixedMemScan1Wide1Step
346
347
348;;
349; Searches for a 4 byte needle in steps of 1.
350;
351; @param pbHaystack [msc:rcx, gcc:rdi, x86:esp+04h] What to search thru.
352; @param cbHaystack [msc:edx, gcc:rsi, x86:esp+08h] The amount of hay to search.
353; @param pvNeedle [msc:r8, gcc:rdx, x86:esp+0ch] What we're searching for
354; @param cbNeedle [msc:r9, gcc:rcx, x86:esp+10h] Size of what we're searcing for. Currently ignored.
355;
356BEGINPROC pgmR3DbgFixedMemScan4Wide1Step
357%ifdef ASM_CALL64_MSC
358 mov r10, rdi ; save it
359 mov rdi, rcx ; rdi=pbHaystack
360 mov ecx, edx ; rcx=cbHaystack
361 mov eax, [r8] ; *(uint32_t *)pvNeedle
362%elifdef ASM_CALL64_GCC
363 xchg rcx, rsi ; rcx=cbHaystack, rsi=cbNeedle
364 mov eax, [rdx] ; *(uint32_t *)pvNeedle
365%elifdef RT_ARCH_X86
366 mov edx, edi ; save it
367 mov edi, [esp + 04h] ; pbHaystack
368 mov ecx, [esp + 08h] ; cbHaystack
369 mov eax, [esp + 0ch] ; pvNeedle
370 mov eax, [eax] ; *(uint32_t *)pvNeedle
371%else
372 %error "Unsupported arch!"
373%endif
374SEH64_END_PROLOGUE
375
376 cmp ecx, 1
377 jb .return_null
378.continue:
379 repne scasb
380 jne .return_null
381 cmp ecx, 3
382 jb .return_null
383 cmp eax, [xDI - 1]
384 jne .continue
385
386.return_edi:
387 lea xAX, [xDI - 1]
388.return:
389%ifdef ASM_CALL64_MSC
390 mov rdi, r10
391%elifdef RT_ARCH_X86
392 mov edi, edx
393%endif
394 ret
395
396.return_null:
397 xor eax, eax
398%ifdef ASM_CALL64_MSC
399 mov rdi, r10
400%elifdef RT_ARCH_X86
401 mov edi, edx
402%endif
403 ret
404ENDPROC pgmR3DbgFixedMemScan4Wide1Step
405
406;;
407; Searches for a 8 byte needle in steps of 1.
408;
409; @param pbHaystack [msc:rcx, gcc:rdi, x86:esp+04h] What to search thru.
410; @param cbHaystack [msc:edx, gcc:rsi, x86:esp+08h] The amount of hay to search.
411; @param pvNeedle [msc:r8, gcc:rdx, x86:esp+0ch] What we're searching for
412; @param cbNeedle [msc:r9, gcc:rcx, x86:esp+10h] Size of what we're searcing for. Currently ignored.
413;
414; @remarks The 32-bit version is currently identical to pgmR3DbgFixedMemScan4Wide1Step.
415;
416BEGINPROC pgmR3DbgFixedMemScan8Wide1Step
417%ifdef ASM_CALL64_MSC
418 mov r10, rdi ; save it
419 mov rdi, rcx ; rdi=pbHaystack
420 mov ecx, edx ; rcx=cbHaystack
421 mov rax, [r8] ; *(uint64_t *)pvNeedle
422%elifdef ASM_CALL64_GCC
423 xchg rcx, rsi ; rcx=cbHaystack, rsi=cbNeedle
424 mov rax, [rdx] ; *(uint64_t *)pvNeedle
425%elifdef RT_ARCH_X86
426 mov edx, edi ; save it
427 mov edi, [esp + 04h] ; pbHaystack
428 mov ecx, [esp + 08h] ; cbHaystack
429 mov eax, [esp + 0ch] ; pvNeedle
430 mov eax, [eax] ; *(uint32_t *)pvNeedle
431%else
432 %error "Unsupported arch!"
433%endif
434SEH64_END_PROLOGUE
435
436 cmp ecx, 1
437 jb .return_null
438.continue:
439 repne scasb
440 jne .return_null
441%ifdef RT_ARCH_AMD64
442 cmp ecx, 7
443 jb .check_smaller
444 cmp rax, [xDI - 1]
445 jne .continue
446 jmp .return_edi
447.check_smaller:
448%endif
449 cmp ecx, 3
450 jb .return_null
451 cmp eax, [xDI - 1]
452 jne .continue
453
454.return_edi:
455 lea xAX, [xDI - 1]
456.return:
457%ifdef ASM_CALL64_MSC
458 mov rdi, r10
459%elifdef RT_ARCH_X86
460 mov edi, edx
461%endif
462 ret
463
464.return_null:
465 xor eax, eax
466%ifdef ASM_CALL64_MSC
467 mov rdi, r10
468%elifdef RT_ARCH_X86
469 mov edi, edx
470%endif
471 ret
472ENDPROC pgmR3DbgFixedMemScan8Wide1Step
473
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette