1 | // This header provides replacements for certain libc functions. It is necessary |
2 | // in order to safely run the tests on aarch64, because the system libc might |
3 | // not have been compiled with -ffixed-x18. |
4 | |
5 | #pragma once |
6 | |
7 | #include <stddef.h> |
8 | #include <stdint.h> |
9 | #include <stdio.h> |
10 | |
11 | #ifdef __aarch64__ |
12 | |
13 | size_t scs_strlen(const char *p) { |
14 | size_t retval = 0; |
15 | while (*p++) |
16 | retval++; |
17 | return retval; |
18 | } |
19 | |
20 | // We mark this function as noinline to make sure that its callers do not |
21 | // become leaf functions as a result of inlining. This is because we want to |
22 | // make sure that we generate the correct code for non-leaf functions. |
23 | |
24 | __attribute__((noinline)) void scs_fputs_stdout(const char *p) { |
25 | __asm__ __volatile__( |
26 | "mov x0, #1\n" // stdout |
27 | "mov x1, %0\n" |
28 | "mov x2, %1\n" |
29 | "mov x8, #64\n" // write |
30 | "svc #0\n" ::"r" (p), |
31 | "r" (scs_strlen(p)) |
32 | : "x0" , "x1" , "x2" , "x8" ); |
33 | } |
34 | |
35 | #else |
36 | #error Unsupported platform |
37 | #endif |
38 | |