38 lines · c
1// This header provides replacements for certain libc functions. It is necessary2// in order to safely run the tests on aarch64, because the system libc might3// not have been compiled with -ffixed-x18.4 5#pragma once6 7#include <stddef.h>8#include <stdint.h>9#include <stdio.h>10 11#ifdef __aarch64__12 13size_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 not21// become leaf functions as a result of inlining. This is because we want to22// 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" // stdout27 "mov x1, %0\n"28 "mov x2, %1\n"29 "mov x8, #64\n" // write30 "svc #0\n" ::"r"(p),31 "r"(scs_strlen(p))32 : "x0", "x1", "x2", "x8");33}34 35#else36#error Unsupported platform37#endif38