VirtualBox

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

Last change on this file since 102468 was 98103, checked in by vboxsync, 2 years ago

Copyright year updates by scm.

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

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