Skip to content

Commit

Permalink
feat: Initial arm64 support
Browse files Browse the repository at this point in the history
This includes `monika_linux`, `haiku_loader`, and `hyclone_server`.

`build_hprefix.sh` will not work yet since arm64 packages are not
available on HaikuPorts yet.

HPREFIXes themselves will also not work due to errors/stubs in Haiku's
own `runtime_loader`.
  • Loading branch information
trungnt2910 committed Mar 5, 2024
1 parent b80e6d9 commit b759b73
Show file tree
Hide file tree
Showing 13 changed files with 128 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Expand Up @@ -14,5 +14,5 @@
build/**
**/*.o
**/*.a
**/*.so
**/haiku_include/**
**/*.so*
**/haiku_include/**
6 changes: 6 additions & 0 deletions haiku_loader/sys/linux/loader_commpage.cpp
Expand Up @@ -50,6 +50,12 @@ void* loader_allocate_commpage()
// Stubbed.
realTimeData->arch_data.system_time_conversion_factor = 0;
realTimeData->arch_data.system_time_offset = 0;
#elif defined(__aarch64__)
// Stubbed.
realTimeData->arch_data.data[0].system_time_offset = 0;
realTimeData->arch_data.data[1].system_time_offset = 0;
realTimeData->arch_data.system_time_conversion_factor = 0;
realTimeData->arch_data.version = 0;
#else
#warning commpage time data not set up for this architecture.
#endif
Expand Down
Binary file removed libroot/libgcc_s.so.1
Binary file not shown.
8 changes: 7 additions & 1 deletion monika/linux/linux_syscall.S
Expand Up @@ -35,8 +35,14 @@ linux_syscall:
pop %ebx
ret

#elif defined(__aarch64__)

mov x8, x6
svc 0
ret

#else

# error Missing assembly!

#endif
#endif
4 changes: 2 additions & 2 deletions monika/linux/process.cpp
Expand Up @@ -2,9 +2,9 @@
#include "haiku_signal.h"

#include <cstddef>
#include <linux/resource.h>
#include <memory.h>
#include <signal.h>
#include <sys/resource.h>
#include <wait.h>

#include "BeDefs.h"
Expand Down Expand Up @@ -270,4 +270,4 @@ haiku_pid_t _moni_setsid()
return result;
}

}
}
17 changes: 16 additions & 1 deletion monika/linux/signal_conversion.cpp
Expand Up @@ -384,7 +384,22 @@ void ContextLinuxToB(const ucontext_t& linuxContext, haiku_ucontext_t& context)

// TODO: floating point registers.
memset(&context.uc_mcontext.fpu, 0, sizeof(context.uc_mcontext.fpu));
#elif defined(__aarch64__)
for (int i = 0; i < 29; ++i)
{
context.uc_mcontext.x[i] = linuxContext.uc_mcontext.regs[i];
}
context.uc_mcontext.lr = linuxContext.uc_mcontext.regs[30];
context.uc_mcontext.sp = linuxContext.uc_mcontext.sp;

// TODO: additional rocessor state
// https://elixir.bootlin.com/linux/latest/source/arch/arm64/include/uapi/asm/sigcontext.h
context.uc_mcontext.elr = 0;
context.uc_mcontext.spsr = 0;
memset(&context.uc_mcontext.fp_q, 0, sizeof(context.uc_mcontext.fp_q));
context.uc_mcontext.fpsr = 0;
context.uc_mcontext.fpcr = 0;
#else
# error Implement mcontext_t marshalling on this platform!
#endif
}
}
9 changes: 8 additions & 1 deletion monika/linux/signal_restore.S
Expand Up @@ -22,8 +22,15 @@ __restore_rt:
movl $173, %eax
int $0x80

#elif defined(__aarch64__)

__restore:
__restore_rt:
mov x8,#139 // SYS_rt_sigreturn
svc 0

#else

# error Missing assembly!

#endif
#endif
Empty file removed runtime_loader/stl6c1j9
Empty file.
8 changes: 7 additions & 1 deletion shared_headers/BeDefs.h
Expand Up @@ -11,6 +11,9 @@ typedef unsigned int uint32;
typedef int64_t int64;
typedef uint64_t uint64;

typedef volatile int32 vint32;
typedef volatile int64 vint64;

typedef unsigned char uchar;

typedef int32 status_t;
Expand Down Expand Up @@ -65,6 +68,9 @@ typedef long signed int haiku_ssize_t;
#ifdef __x86_64__
#define B_PAGE_SIZE 4096
#define B_HAIKU_64_BIT 1
#elif defined(__aarch64__)
#define B_PAGE_SIZE 4096
#define B_HAIKU_64_BIT 1
#endif

struct user_space_program_args
Expand Down Expand Up @@ -101,4 +107,4 @@ enum
| B_TIMEOUT_REAL_TIME_BASE
};

#endif // __HAIKU_STRUCTS_H__
#endif // __HAIKU_STRUCTS_H__
15 changes: 15 additions & 0 deletions shared_headers/arm64/arch_commpage_defs.h
@@ -0,0 +1,15 @@
/*
* Copyright 2019 Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*/

#ifndef _SYSTEM_ARCH_ARM64_COMMPAGE_DEFS_H
#define _SYSTEM_ARCH_ARM64_COMMPAGE_DEFS_H

#ifndef _SYSTEM_COMMPAGE_DEFS_H
# error Must not be included directly. Include <commpage_defs.h> instead!
#endif

#define COMMPAGE_ENTRY_ARM64_THREAD_EXIT (COMMPAGE_ENTRY_FIRST_ARCH_SPECIFIC + 0)

#endif /* _SYSTEM_ARCH_ARM64_COMMPAGE_DEFS_H */
16 changes: 16 additions & 0 deletions shared_headers/arm64/arch_debugger.h
@@ -0,0 +1,16 @@
/*
* Copyright 2019 Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _ARCH_ARM64_DEBUGGER_H
#define _ARCH_ARM64_DEBUGGER_H

struct arm64_debug_cpu_state {
unsigned long x[30];
unsigned long lr;
unsigned long sp;
unsigned long elr;
unsigned int spsr;
} __attribute__((aligned(16)));

#endif // _ARCH_ARM_DEBUGGER_H
20 changes: 20 additions & 0 deletions shared_headers/arm64/arch_real_time_data.h
@@ -0,0 +1,20 @@
/*
* Copyright 2019 Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _KERNEL_ARCH_REAL_TIME_DATA_H
#define _KERNEL_ARCH_REAL_TIME_DATA_H

#include "BeDefs.h"

struct arm64_real_time_data {
vint64 system_time_offset;
};

struct arch_real_time_data {
struct arm64_real_time_data data[2];
vint32 system_time_conversion_factor;
vint32 version;
};

#endif /* _KERNEL_ARCH_REAL_TIME_DATA_H */
29 changes: 29 additions & 0 deletions shared_headers/arm64/arch_signal.h
@@ -0,0 +1,29 @@
/*
* Copyright 2019 Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*/

#ifndef _ARCH_ARM64_SIGNAL_H_
#define _ARCH_ARM64_SIGNAL_H_


/*
* Architecture-specific structure passed to signal handlers
*/

#if defined(__aarch64__)
struct vregs
{
unsigned long x[30];
unsigned long lr;
unsigned long sp;
unsigned long elr;
unsigned long spsr;
__uint128_t fp_q[32];
unsigned int fpsr;
unsigned int fpcr;
};
#endif /* defined(__aarch64__) */


#endif /* _ARCH_ARM64_SIGNAL_H_ */

0 comments on commit b759b73

Please sign in to comment.