1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2010 Nils Wallménius
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; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 /* size_t strlen(const char *str) */
24 .section .text,"ax",@progbits
27 .type strlen, @function
30 move.l 4(%sp), %a0 /* %a0 = *str */
31 move.l %a0, %a1 /* %a1 = start address */
33 andi.l #3, %d0 /* %d0 = %a0 & 3 */
34 beq.b 1f /* already aligned */
35 jmp.l (-2,%pc,%d0.l*4)
44 move.l (%a0)+, %d0 /* load %d0 increment %a0 */
45 /* use trick to test the whole word for null bytes */
47 subi.l #0x01010101, %d1
50 andi.l #0x80808080, %d0
51 beq.b 1b /* if the test was false repeat */
53 /* ok, so the last word contained a 0 byte, test individual bytes */
61 /* last byte must be 0 so we don't need to load it, so we don't increment a0
62 so we jump past the subq instr */
63 .word 0x51fa /* trapf.w, shadow next instr */
66 subq.l #1, %a0 /* %a0 is 1 too large due to the last increment */
67 sub.l %a1, %a0 /* how many times did we repeat? */
68 move.l %a0, %d0 /* return value in %d0 */
70 .size strlen, .-strlen