Path: blob/master/tools/testing/selftests/arm64/fp/asm-utils.S
26292 views
// SPDX-License-Identifier: GPL-2.0-only1// Copyright (C) 2015-2021 ARM Limited.2// Original author: Dave Martin <Dave.Martin@arm.com>3//4// Utility functions for assembly code.56#include <asm/unistd.h>7#include "assembler.h"89// Print a single character x0 to stdout10// Clobbers x0-x2,x811function putc12str x0, [sp, #-16]!1314mov x0, #1 // STDOUT_FILENO15mov x1, sp16mov x2, #117mov x8, #__NR_write18svc #01920add sp, sp, #1621ret22endfunction23.globl putc2425// Print a NUL-terminated string starting at address x0 to stdout26// Clobbers x0-x3,x827function puts28mov x1, x02930mov x2, #0310: ldrb w3, [x0], #132cbz w3, 1f33add x2, x2, #134b 0b35361: mov w0, #1 // STDOUT_FILENO37mov x8, #__NR_write38svc #03940ret41endfunction42.globl puts4344// Print an unsigned decimal number x0 to stdout45// Clobbers x0-x4,x846function putdec47mov x1, sp48str x30, [sp, #-32]! // Result can't be > 20 digits4950mov x2, #051strb w2, [x1, #-1]! // Write the NUL terminator5253mov x2, #10540: udiv x3, x0, x2 // div-mod loop to generate the digits55msub x0, x3, x2, x056add w0, w0, #'0'57strb w0, [x1, #-1]!58mov x0, x359cbnz x3, 0b6061ldrb w0, [x1]62cbnz w0, 1f63mov w0, #'0' // Print "0" for 0, not ""64strb w0, [x1, #-1]!65661: mov x0, x167bl puts6869ldr x30, [sp], #3270ret71endfunction72.globl putdec7374// Print an unsigned decimal number x0 to stdout, followed by a newline75// Clobbers x0-x5,x876function putdecn77mov x5, x307879bl putdec80mov x0, #'\n'81bl putc8283ret x584endfunction85.globl putdecn8687// Clobbers x0-x3,x888function puthexb89str x30, [sp, #-0x10]!9091mov w3, w092lsr w0, w0, #493bl puthexnibble94mov w0, w39596ldr x30, [sp], #0x1097// fall through to puthexnibble98endfunction99.globl puthexb100101// Clobbers x0-x2,x8102function puthexnibble103and w0, w0, #0xf104cmp w0, #10105blo 1f106add w0, w0, #'a' - ('9' + 1)1071: add w0, w0, #'0'108b putc109endfunction110.globl puthexnibble111112// x0=data in, x1=size in, clobbers x0-x5,x8113function dumphex114str x30, [sp, #-0x10]!115116mov x4, x0117mov x5, x11181190: subs x5, x5, #1120b.lo 1f121ldrb w0, [x4], #1122bl puthexb123b 0b1241251: ldr x30, [sp], #0x10126ret127endfunction128.globl dumphex129130// Trivial memory copy: copy x2 bytes, starting at address x1, to address x0.131// Clobbers x0-x3132function memcpy133cmp x2, #0134b.eq 1f1350: ldrb w3, [x1], #1136strb w3, [x0], #1137subs x2, x2, #1138b.ne 0b1391: ret140endfunction141.globl memcpy142143// Fill x1 bytes starting at x0 with 0xae (for canary purposes)144// Clobbers x1, x2.145function memfill_ae146mov w2, #0xae147b memfill148endfunction149.globl memfill_ae150151// Fill x1 bytes starting at x0 with 0.152// Clobbers x1, x2.153function memclr154mov w2, #0155endfunction156.globl memclr157// fall through to memfill158159// Trivial memory fill: fill x1 bytes starting at address x0 with byte w2160// Clobbers x1161function memfill162cmp x1, #0163b.eq 1f1641650: strb w2, [x0], #1166subs x1, x1, #1167b.ne 0b1681691: ret170endfunction171.globl memfill172173174