Skip to content

Commit

Permalink
AK+Userland: Stub out code that isn't currently implemented on AARCH64
Browse files Browse the repository at this point in the history
Even though this almost certainly wouldn't run properly even if we had
a working kernel for AARCH64 this at least lets us build all the
userland binaries.
  • Loading branch information
gunnarbeutner authored and linusg committed Oct 14, 2022
1 parent c18c84d commit 31bd5b1
Show file tree
Hide file tree
Showing 17 changed files with 206 additions and 6 deletions.
1 change: 1 addition & 0 deletions AK/Assertions.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ extern "C" __attribute__((noreturn)) void ak_verification_failed(char const*);
# define VERIFY_NOT_REACHED() VERIFY(false) /* NOLINT(cert-dcl03-c,misc-static-assert) No, this can't be static_assert, it's a runtime check */
static constexpr bool TODO = false;
# define TODO() VERIFY(TODO) /* NOLINT(cert-dcl03-c,misc-static-assert) No, this can't be static_assert, it's a runtime check */
# define TODO_AARCH64() VERIFY(TODO) /* NOLINT(cert-dcl03-c,misc-static-assert) No, this can't be static_assert, it's a runtime check */
#endif
23 changes: 23 additions & 0 deletions Tests/Kernel/crash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,14 @@ int main(int argc, char** argv)
return Crash::Failure::UnexpectedError;

u8* makeshift_esp = makeshift_stack + 2048;
#if ARCH(I386) || ARCH(X86_64)
asm volatile("mov %%eax, %%esp" ::"a"(makeshift_esp));
#elif ARCH(AARCH64)
(void)makeshift_esp;
TODO_AARCH64();
#else
# error Unknown architecture
#endif
getuid();
dbgln("Survived syscall with MAP_STACK stack");

Expand All @@ -209,7 +216,14 @@ int main(int argc, char** argv)
return Crash::Failure::UnexpectedError;

u8* bad_esp = bad_stack + 2048;
#if ARCH(I386) || ARCH(X86_64)
asm volatile("mov %%eax, %%esp" ::"a"(bad_esp));
#elif ARCH(AARCH64)
(void)bad_esp;
TODO_AARCH64();
#else
# error Unknown architecture
#endif
getuid();
return Crash::Failure::DidNotCrash;
}).run(run_type);
Expand All @@ -228,6 +242,9 @@ int main(int argc, char** argv)
#elif ARCH(X86_64)
asm volatile("movq %%rax, %%rsp" ::"a"(bad_esp));
asm volatile("pushq $0");
#elif ARCH(AARCH64)
(void)bad_esp;
TODO_AARCH64();
#else
# error Unknown architecture
#endif
Expand Down Expand Up @@ -267,7 +284,13 @@ int main(int argc, char** argv)

if (do_trigger_user_mode_instruction_prevention) {
any_failures |= !Crash("Trigger x86 User Mode Instruction Prevention", []() {
#if ARCH(I386) || ARCH(X86_64)
asm volatile("str %eax");
#elif ARCH(AARCH64)
TODO_AARCH64();
#else
# error Unknown architecture
#endif
return Crash::Failure::DidNotCrash;
}).run(run_type);
}
Expand Down
3 changes: 3 additions & 0 deletions Userland/Applications/CrashReporter/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ static TitleAndText build_cpu_registers(const ELF::Core::ThreadInfo& thread_info
builder.appendff(" r8={:p} r9={:p} r10={:p} r11={:p}\n", regs.r8, regs.r9, regs.r10, regs.r11);
builder.appendff("r12={:p} r13={:p} r14={:p} r15={:p}\n", regs.r12, regs.r13, regs.r14, regs.r15);
builder.appendff("rip={:p} rflags={:p}", regs.rip, regs.rflags);
#elif ARCH(AARCH64)
(void)regs;
TODO_AARCH64();
#else
# error Unknown architecture
#endif
Expand Down
6 changes: 6 additions & 0 deletions Userland/Applications/Debugger/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ static void handle_print_registers(PtraceRegisters const& regs)
outln("r8 ={:p} r9 ={:p} r10={:p} r11={:p}", regs.r8, regs.r9, regs.r10, regs.r11);
outln("r12={:p} r13={:p} r14={:p} r15={:p}", regs.r12, regs.r13, regs.r14, regs.r15);
outln("rip={:p} rflags={:p}", regs.rip, regs.rflags);
#elif ARCH(AARCH64)
(void)regs;
TODO_AARCH64();
#else
# error Unknown architecture
#endif
Expand Down Expand Up @@ -250,6 +253,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
const FlatPtr ip = regs.eip;
#elif ARCH(X86_64)
const FlatPtr ip = regs.rip;
#elif ARCH(AARCH64)
const FlatPtr ip = 0; // FIXME
TODO_AARCH64();
#else
# error Unknown architecture
#endif
Expand Down
5 changes: 5 additions & 0 deletions Userland/DevTools/HackStudio/Debugger/RegistersModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ RegistersModel::RegistersModel(PtraceRegisters const& regs)
m_registers.append({ "es", regs.es });
m_registers.append({ "fs", regs.fs });
m_registers.append({ "gs", regs.gs });
#elif ARCH(AARCH64)
TODO_AARCH64();
#else
# error Unknown architecture
#endif
Expand Down Expand Up @@ -97,6 +99,9 @@ RegistersModel::RegistersModel(PtraceRegisters const& current_regs, PtraceRegist
m_registers.append({ "es", current_regs.es, current_regs.es != previous_regs.es });
m_registers.append({ "fs", current_regs.fs, current_regs.fs != previous_regs.fs });
m_registers.append({ "gs", current_regs.gs, current_regs.gs != previous_regs.gs });
#elif ARCH(AARCH64)
(void)previous_regs;
TODO_AARCH64();
#else
# error Unknown architecture
#endif
Expand Down
40 changes: 40 additions & 0 deletions Userland/Libraries/LibC/fenv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
// This is the size of the floating point environment image in protected mode
static_assert(sizeof(__x87_floating_point_environment) == 28);

#ifndef AK_ARCH_AARCH64
static u16 read_status_register()
{
u16 status_register;
Expand Down Expand Up @@ -45,6 +46,7 @@ static void set_mxcsr(u32 new_mxcsr)
}

static constexpr u32 default_mxcsr_value = 0x1f80;
#endif

extern "C" {

Expand All @@ -53,10 +55,14 @@ int fegetenv(fenv_t* env)
if (!env)
return 1;

#ifdef AK_ARCH_AARCH64
TODO_AARCH64();
#else
asm volatile("fnstenv %0"
: "=m"(env->__x87_fpu_env)::"memory");

env->__mxcsr = read_mxcsr();
#endif

return 0;
}
Expand All @@ -66,6 +72,9 @@ int fesetenv(fenv_t const* env)
if (!env)
return 1;

#ifdef AK_ARCH_AARCH64
TODO_AARCH64();
#else
if (env == FE_DFL_ENV) {
asm volatile("finit");
set_mxcsr(default_mxcsr_value);
Expand All @@ -76,6 +85,7 @@ int fesetenv(fenv_t const* env)
: "memory");

set_mxcsr(env->__mxcsr);
#endif

return 0;
}
Expand All @@ -87,9 +97,13 @@ int feholdexcept(fenv_t* env)
fenv_t current_env;
fegetenv(&current_env);

#ifdef AK_ARCH_AARCH64
TODO_AARCH64();
#else
current_env.__x87_fpu_env.__status_word &= ~FE_ALL_EXCEPT;
current_env.__x87_fpu_env.__status_word &= ~(1 << 7); // Clear the "Exception Status Summary" bit
current_env.__x87_fpu_env.__control_word &= FE_ALL_EXCEPT; // Masking these bits stops the corresponding exceptions from being generated according to the Intel Programmer's Manual
#endif

fesetenv(&current_env);

Expand Down Expand Up @@ -122,24 +136,35 @@ int fesetexceptflag(fexcept_t const* except, int exceptions)
fegetenv(&current_env);

exceptions &= FE_ALL_EXCEPT;
#ifdef AK_ARCH_AARCH64
TODO_AARCH64();
#else
current_env.__x87_fpu_env.__status_word &= exceptions;
current_env.__x87_fpu_env.__status_word &= ~(1 << 7); // Make sure exceptions don't get raised
#endif

fesetenv(&current_env);
return 0;
}

int fegetround()
{
#ifdef AK_ARCH_AARCH64
TODO_AARCH64();
#else
// There's no way to signal whether the SSE rounding mode and x87 ones are different, so we assume they're the same
return (read_status_register() >> 10) & 3;
#endif
}

int fesetround(int rounding_mode)
{
if (rounding_mode < FE_TONEAREST || rounding_mode > FE_TOWARDZERO)
return 1;

#ifdef AK_ARCH_AARCH64
TODO_AARCH64();
#else
auto control_word = read_control_word();

control_word &= ~(3 << 10);
Expand All @@ -154,6 +179,8 @@ int fesetround(int rounding_mode)

set_mxcsr(mxcsr);

#endif

return 0;
}

Expand All @@ -164,19 +191,28 @@ int feclearexcept(int exceptions)
fenv_t current_env;
fegetenv(&current_env);

#ifdef AK_ARCH_AARCH64
TODO_AARCH64();
#else
current_env.__x87_fpu_env.__status_word &= ~exceptions;
current_env.__x87_fpu_env.__status_word &= ~(1 << 7); // Clear the "Exception Status Summary" bit
#endif

fesetenv(&current_env);
return 0;
}

int fetestexcept(int exceptions)
{
#ifdef AK_ARCH_AARCH64
(void)exceptions;
TODO_AARCH64();
#else
u16 status_register = read_status_register() & FE_ALL_EXCEPT;
exceptions &= FE_ALL_EXCEPT;

return status_register & exceptions;
#endif
}

int feraiseexcept(int exceptions)
Expand All @@ -186,6 +222,9 @@ int feraiseexcept(int exceptions)

exceptions &= FE_ALL_EXCEPT;

#ifdef AK_ARCH_AARCH64
TODO_AARCH64();
#else
// While the order in which the exceptions is raised is unspecified, FE_OVERFLOW and FE_UNDERFLOW must be raised before FE_INEXACT, so handle that case in this branch
if (exceptions & FE_INEXACT) {
env.__x87_fpu_env.__status_word &= ((u16)exceptions & ~FE_INEXACT);
Expand All @@ -203,6 +242,7 @@ int feraiseexcept(int exceptions)
env.__x87_fpu_env.__status_word &= exceptions;
fesetenv(&env);
asm volatile("fwait");
#endif

return 0;
}
Expand Down
Loading

0 comments on commit 31bd5b1

Please sign in to comment.