Get aarch64 hello world working

$ m=aarch64-tiny
    $ make -j8 m=$m o/$m/tool/hello/hello.com o/third_party/qemu/qemu-aarch64
    $ o/third_party/qemu/qemu-aarch64 o/$m/tool/hello/hello.com
    hello world
    $ ls -hal o/$m/tool/hello/hello.com
    -rwxr-xr-x 1 jart jart 4.0K May  9 05:04 o/aarch64-tiny/tool/hello/hello.com
This commit is contained in:
Justine Tunney 2023-05-09 02:35:05 -07:00
parent e5e3cdf447
commit ae0ee59614
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
174 changed files with 1454 additions and 851 deletions

View file

@ -1021,9 +1021,9 @@ static void __asan_trace(struct AsanTrace *bt, const struct StackFrame *bp) {
}
if (!__asan_checka(SHADOW(bp), sizeof(*bp) >> 3).kind) {
addr = bp->addr;
if (addr == _weakaddr("__gc") && _weakaddr("__gc")) {
if (addr == (uintptr_t)_weaken(__gc) && (uintptr_t)_weaken(__gc)) {
do --gi;
while ((addr = garbage->p[gi].ret) == _weakaddr("__gc"));
while ((addr = garbage->p[gi].ret) == (uintptr_t)_weaken(__gc));
}
bt->p[i] = addr;
} else {

46
libc/intrin/ashlti3.c Normal file
View file

@ -0,0 +1,46 @@
/* clang-format off */
/* ===-- ashlti3.c - Implement __ashlti3 -----------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __ashlti3 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
#include "third_party/compiler_rt/int_lib.h"
#ifdef CRT_HAS_128BIT
/* Returns: a << b */
/* Precondition: 0 <= b < bits_in_tword */
COMPILER_RT_ABI ti_int
__ashlti3(ti_int a, si_int b)
{
const int bits_in_dword = (int)(sizeof(di_int) * CHAR_BIT);
twords input;
twords result;
input.all = a;
if (b & bits_in_dword) /* bits_in_dword <= b < bits_in_tword */
{
result.s.low = 0;
result.s.high = input.s.low << (b - bits_in_dword);
}
else /* 0 <= b < bits_in_dword */
{
if (b == 0)
return a;
result.s.low = input.s.low << b;
result.s.high = (input.s.high << b) | (input.s.low >> (bits_in_dword - b));
}
return result.all;
}
#endif /* CRT_HAS_128BIT */

View file

@ -36,7 +36,7 @@
* @vforksafe
* @noreturn
*/
privileged wontreturn void _Exit(int exitcode) {
wontreturn void _Exit(int exitcode) {
int i;
STRACE("_Exit(%d)", exitcode);
#ifdef __x86_64__
@ -67,7 +67,7 @@ privileged wontreturn void _Exit(int exitcode) {
for (;;) asm("ud2");
#elif defined(__aarch64__)
register long x0 asm("x0") = exitcode;
asm volatile("mov\tx8,%1\n\t"
asm volatile("mov\tx8,%0\n\t"
"svc\t0"
: /* no outputs */
: "i"(94), "r"(x0)

View file

@ -75,7 +75,7 @@ privileged wontreturn void _Exit1(int rc) {
notpossible;
#elif defined(__aarch64__)
register long r0 asm("x0") = rc;
asm volatile("mov\tx8,%1\n\t"
asm volatile("mov\tx8,%0\n\t"
"svc\t0"
: /* no outputs */
: "i"(93), "r"(r0)

View file

@ -16,9 +16,12 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/dce.h"
#include "libc/runtime/runtime.h"
privileged wontreturn void _Exitr(int exitcode) {
wontreturn void _Exitr(int exitcode) {
#if SupportsWindows()
_restorewintty();
#endif
_Exit(exitcode);
}

View file

@ -1,12 +0,0 @@
#ifndef COSMOPOLITAN_LIBC_BITS_EZLEA_H_
#define COSMOPOLITAN_LIBC_BITS_EZLEA_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
#if __pic__ + __pie__ + __code_model_medium__ + __code_model_large__ + 0 > 1
#define _ezlea(symbol) "lea\t" symbol "(%%rip),%"
#else
#define _ezlea(symbol) "mov\t$" symbol ",%k"
#endif
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_BITS_EZLEA_H_ */

View file

@ -29,7 +29,7 @@
feclearexcept:
#ifdef __x86_64__
# maintain exceptions in the sse mxcsr, clear x87 exceptions
// maintain exceptions in the sse mxcsr, clear x87 exceptions
mov %edi,%ecx
and $0x3f,%ecx
fnstsw %ax

View file

@ -35,7 +35,7 @@ const unsigned char kConsoleHandles[3] = {
};
// Puts cmd.exe gui back the way it was.
privileged noinstrument void _restorewintty(void) {
noinstrument void _restorewintty(void) {
if (!IsWindows()) return;
if (__imp_GetCurrentProcessId() != __pid_exec) return;
for (int i = 0; i < 3; ++i) {

View file

@ -91,7 +91,6 @@ sched_yield:
#elif defined(__aarch64__)
mov x8,#0x7c
svc 0
mov w0,#0
ret
#else

View file

@ -1,33 +1,12 @@
#ifndef COSMOPOLITAN_LIBC_BITS_WEAKEN_H_
#define COSMOPOLITAN_LIBC_BITS_WEAKEN_H_
#include "libc/intrin/ezlea.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
#ifndef __STRICT_ANSI__
#define _weaken(symbol) \
({ \
typeof(&symbol) _p = &symbol; \
asm(".weak\t" #symbol : "+r"(_p)); \
_p; \
#define _weaken(symbol) \
__extension__({ \
extern __typeof__(symbol) symbol __attribute__((__weak__)); \
&symbol; \
})
#define _strongaddr(symbolstr) \
({ \
intptr_t waddr; \
asm(_ezlea(symbolstr) "0" : "=r"(waddr)); \
waddr; \
})
#define _weakaddr(symbolstr) \
({ \
intptr_t waddr; \
asm(".weak\t" symbolstr "\n\t" _ezlea(symbolstr) "0" : "=r"(waddr)); \
waddr; \
})
#else
#define _weaken(symbol) symbol
#define _weakaddr(symbolstr) &(symbolstr)
#endif /* __STRICT_ANSI__ */
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_BITS_WEAKEN_H_ */