1 | ; $Id: memrchr.asm 96407 2022-08-22 17:43:14Z vboxsync $
|
---|
2 | ;; @file
|
---|
3 | ; IPRT - No-CRT memrchr - AMD64 & X86.
|
---|
4 | ;
|
---|
5 |
|
---|
6 | ;
|
---|
7 | ; Copyright (C) 2006-2022 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 | ; The contents of this file may alternatively be used under the terms
|
---|
26 | ; of the Common Development and Distribution License Version 1.0
|
---|
27 | ; (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
28 | ; in the VirtualBox distribution, in which case the provisions of the
|
---|
29 | ; CDDL are applicable instead of those of the GPL.
|
---|
30 | ;
|
---|
31 | ; You may elect to license modified versions of this file under the
|
---|
32 | ; terms and conditions of either the GPL or the CDDL or both.
|
---|
33 | ;
|
---|
34 | ; SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
35 | ;
|
---|
36 |
|
---|
37 | %include "iprt/asmdefs.mac"
|
---|
38 |
|
---|
39 | BEGINCODE
|
---|
40 |
|
---|
41 | ;;
|
---|
42 | ; @param pv gcc: rdi msc: ecx x86:[esp+4] wcall: eax
|
---|
43 | ; @param ch gcc: esi msc: edx x86:[esp+8] wcall: edx
|
---|
44 | ; @param cb gcc: rdx msc: r8 x86:[esp+0ch] wcall: ebx
|
---|
45 | RT_NOCRT_BEGINPROC memrchr
|
---|
46 | std
|
---|
47 | %ifdef RT_ARCH_AMD64
|
---|
48 | %ifdef ASM_CALL64_MSC
|
---|
49 | or r8, r8
|
---|
50 | jz .not_found_early
|
---|
51 |
|
---|
52 | mov r9, rdi ; save rdi
|
---|
53 | mov eax, edx
|
---|
54 | lea rdi, [rcx + r8 - 1]
|
---|
55 | mov rcx, r8
|
---|
56 | %else
|
---|
57 | mov rcx, rdx
|
---|
58 | jrcxz .not_found_early
|
---|
59 |
|
---|
60 | mov eax, esi
|
---|
61 | lea rdi, [rdi + rcx - 1]
|
---|
62 | %endif
|
---|
63 |
|
---|
64 | %else
|
---|
65 | %ifdef ASM_CALL32_WATCOM
|
---|
66 | mov ecx, ebx
|
---|
67 | jecxz .not_found_early
|
---|
68 | xchg eax, edx
|
---|
69 | xchg edi, edx ; load + save edi
|
---|
70 | %else
|
---|
71 | mov ecx, [esp + 0ch]
|
---|
72 | jecxz .not_found_early
|
---|
73 | mov edx, edi ; save edi
|
---|
74 | mov eax, [esp + 8]
|
---|
75 | mov edi, [esp + 4]
|
---|
76 | %endif
|
---|
77 | lea edi, [edi + ecx - 1]
|
---|
78 | %endif
|
---|
79 |
|
---|
80 | ; do the search
|
---|
81 | repne scasb
|
---|
82 | jne .not_found
|
---|
83 |
|
---|
84 | ; found it
|
---|
85 | lea xAX, [xDI + 1]
|
---|
86 | %ifdef ASM_CALL64_MSC
|
---|
87 | mov rdi, r9
|
---|
88 | %endif
|
---|
89 | %ifdef RT_ARCH_X86
|
---|
90 | mov edi, edx
|
---|
91 | %endif
|
---|
92 | cld
|
---|
93 | ret
|
---|
94 |
|
---|
95 | .not_found:
|
---|
96 | %ifdef ASM_CALL64_MSC
|
---|
97 | mov rdi, r9
|
---|
98 | %endif
|
---|
99 | %ifdef RT_ARCH_X86
|
---|
100 | mov edi, edx
|
---|
101 | %endif
|
---|
102 | .not_found_early:
|
---|
103 | xor eax, eax
|
---|
104 | cld
|
---|
105 | ret
|
---|
106 | ENDPROC RT_NOCRT(memrchr)
|
---|
107 |
|
---|