FreeCalypso > hg > freecalypso-tools
annotate target-utils/libc/bzero.S @ 465:003e48f8ebe1
rvinterf/etmsync/fsnew.c: cast 0 to (char *) for execl sentinel
I generally don't use NULL and use plain 0 instead, based on a "NULL
considered harmful" discussion on the classiccmp mailing list many aeons
ago (I couldn't find it, and I reason that it must have been 2005 or
earlier), but a recent complaint by a packager sent me searching, and I
found this:
https://ewontfix.com/11/
While I don't give a @#$% about "modern" systems and code-nazi tools,
I realized that passing a plain 0 as a pointer sentinel in execl is wrong
because it will break on systems where pointers are longer than the plain
int type. Again, I don't give a @#$% about the abomination of x86_64 and
the like, but if anyone ever manages to port my code to something like a
PDP-11 (16-bit int, 32-bit long and pointers), then passing a plain 0
as a function argument where a pointer is expected most definitely won't
work: if the most natural stack slot and SP alignment unit is 16 bits,
fitting an int, with longs and pointers taking up two such slots, then
the call stack will be totally wrong with a plain 0 passed for a pointer.
Casting the 0 to (char *) ought to be the most kosher solution for the
most retro systems possible.
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 11 Feb 2019 00:00:19 +0000 |
parents | bfed7a5c21a6 |
children |
rev | line source |
---|---|
88
4f3843165014
target-utils/libc: bzero imported from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
4f3843165014
target-utils/libc: bzero imported from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This ARM implementation of bzero() has been derived from: |
4f3843165014
target-utils/libc: bzero imported from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * |
4f3843165014
target-utils/libc: bzero imported from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * linux/arch/arm/lib/memzero.S |
4f3843165014
target-utils/libc: bzero imported from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 * |
4f3843165014
target-utils/libc: bzero imported from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 * Copyright (C) 1995-2000 Russell King |
4f3843165014
target-utils/libc: bzero imported from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 * |
4f3843165014
target-utils/libc: bzero imported from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 * This program is free software; you can redistribute it and/or modify |
4f3843165014
target-utils/libc: bzero imported from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 * it under the terms of the GNU General Public License version 2 as |
4f3843165014
target-utils/libc: bzero imported from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 * published by the Free Software Foundation. |
4f3843165014
target-utils/libc: bzero imported from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 */ |
4f3843165014
target-utils/libc: bzero imported from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 |
4f3843165014
target-utils/libc: bzero imported from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 .text |
4f3843165014
target-utils/libc: bzero imported from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 .code 32 |
4f3843165014
target-utils/libc: bzero imported from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 .globl bzero |
4f3843165014
target-utils/libc: bzero imported from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 |
4f3843165014
target-utils/libc: bzero imported from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 /* |
4f3843165014
target-utils/libc: bzero imported from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 * Align the pointer in r0. r3 contains the number of bytes that we are |
4f3843165014
target-utils/libc: bzero imported from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 * mis-aligned by, and r1 is the number of bytes. If r1 < 4, then we |
4f3843165014
target-utils/libc: bzero imported from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 * don't bother; we use byte stores instead. |
4f3843165014
target-utils/libc: bzero imported from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 */ |
4f3843165014
target-utils/libc: bzero imported from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 1: subs r1, r1, #4 @ 1 do we have enough |
4f3843165014
target-utils/libc: bzero imported from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 blt 5f @ 1 bytes to align with? |
4f3843165014
target-utils/libc: bzero imported from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 cmp r3, #2 @ 1 |
4f3843165014
target-utils/libc: bzero imported from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 strltb r2, [r0], #1 @ 1 |
4f3843165014
target-utils/libc: bzero imported from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 strleb r2, [r0], #1 @ 1 |
4f3843165014
target-utils/libc: bzero imported from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 strb r2, [r0], #1 @ 1 |
4f3843165014
target-utils/libc: bzero imported from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 add r1, r1, r3 @ 1 (r1 = r1 - (4 - r3)) |
4f3843165014
target-utils/libc: bzero imported from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 /* |
4f3843165014
target-utils/libc: bzero imported from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 * The pointer is now aligned and the length is adjusted. Try doing the |
4f3843165014
target-utils/libc: bzero imported from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 * bzero again. |
4f3843165014
target-utils/libc: bzero imported from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 */ |
4f3843165014
target-utils/libc: bzero imported from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 |
4f3843165014
target-utils/libc: bzero imported from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 bzero: |
4f3843165014
target-utils/libc: bzero imported from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 mov r2, #0 @ 1 |
4f3843165014
target-utils/libc: bzero imported from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 ands r3, r0, #3 @ 1 unaligned? |
4f3843165014
target-utils/libc: bzero imported from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 bne 1b @ 1 |
4f3843165014
target-utils/libc: bzero imported from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 /* |
4f3843165014
target-utils/libc: bzero imported from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 * r3 = 0, and we know that the pointer in r0 is aligned to a word boundary. |
4f3843165014
target-utils/libc: bzero imported from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 */ |
4f3843165014
target-utils/libc: bzero imported from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 3: subs r1, r1, #4 |
92
bfed7a5c21a6
target-utils/libc/bzero.S: changed signed conditions to unsigned
Mychaela Falconia <falcon@freecalypso.org>
parents:
88
diff
changeset
|
42 strcs r2, [r0], #4 |
bfed7a5c21a6
target-utils/libc/bzero.S: changed signed conditions to unsigned
Mychaela Falconia <falcon@freecalypso.org>
parents:
88
diff
changeset
|
43 bhi 3b @ 1 |
88
4f3843165014
target-utils/libc: bzero imported from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 bxeq lr @ 1/2 quick exit |
4f3843165014
target-utils/libc: bzero imported from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 /* |
4f3843165014
target-utils/libc: bzero imported from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 * No need to correct the count; we're only testing bits from now on |
4f3843165014
target-utils/libc: bzero imported from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 * |
4f3843165014
target-utils/libc: bzero imported from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 * When we get here, we've got less than 4 bytes to zero. We |
4f3843165014
target-utils/libc: bzero imported from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 * may have an unaligned pointer as well. |
4f3843165014
target-utils/libc: bzero imported from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 */ |
4f3843165014
target-utils/libc: bzero imported from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 5: tst r1, #2 @ 1 2 bytes or more? |
4f3843165014
target-utils/libc: bzero imported from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 strneb r2, [r0], #1 @ 1 |
4f3843165014
target-utils/libc: bzero imported from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 strneb r2, [r0], #1 @ 1 |
4f3843165014
target-utils/libc: bzero imported from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 tst r1, #1 @ 1 a byte left over |
4f3843165014
target-utils/libc: bzero imported from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 strneb r2, [r0], #1 @ 1 |
4f3843165014
target-utils/libc: bzero imported from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 bx lr @ 1 |