Skip to content

Commit

Permalink
AARCH64 support
Browse files Browse the repository at this point in the history
  • Loading branch information
dsamersoff authored and Andrei Pangin committed Oct 5, 2017
1 parent bd49b2c commit 627adcf
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,17 @@ const instruction_t BREAKPOINT = 0xe7f001f0;
#define rmb() asm volatile("dmb ish" : : : "memory")
#define flushCache(addr) __builtin___clear_cache((char*)(addr), (char*)(addr) + sizeof(instruction_t))

#elif defined(__aarch64__)

typedef unsigned int instruction_t;
const instruction_t BREAKPOINT = 0xd4200000;

#define spinPause() asm volatile("yield")
#define rmb() asm volatile("dmb ish" : : : "memory")
#define flushCache(addr) __builtin___clear_cache((char*)(addr), (char*)(addr) + sizeof(instruction_t))

#else
#warning "Compiling on unsupported arch"

#define spinPause()
#define rmb() __sync_synchronize()
Expand Down
73 changes: 73 additions & 0 deletions src/stackFrame_aarch64.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright 2017 Andrei Pangin
* Copyright 2017 BellSoft LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Author: Dmitry Samersoff
*/

#if defined(__aarch64__)

#include "stackFrame.h"

#include <stdio.h>

#define REG_FP 29
#define REG_LR 30

uintptr_t& StackFrame::pc() {
return (uintptr_t&)_ucontext->uc_mcontext.pc;
}

uintptr_t& StackFrame::sp() {
return (uintptr_t&)_ucontext->uc_mcontext.sp;
}

uintptr_t& StackFrame::fp() {
return (uintptr_t&)_ucontext->uc_mcontext.regs[REG_FP];
}

uintptr_t StackFrame::arg0() {
return (uintptr_t)_ucontext->uc_mcontext.regs[0];
}

uintptr_t StackFrame::arg1() {
return (uintptr_t)_ucontext->uc_mcontext.regs[1];
}

uintptr_t StackFrame::arg2() {
return (uintptr_t)_ucontext->uc_mcontext.regs[2];
}

void StackFrame::ret() {
_ucontext->uc_mcontext.pc = _ucontext->uc_mcontext.regs[REG_LR];
}

bool StackFrame::pop() {
if (fp() == sp()) {
// Expected frame layout:
// sp 000000nnnnnnnnnn [stack]
// sp+8 000000nnnnnnnnnn [link]
fp() = stackAt(0);
pc() = stackAt(1);
sp() += 16;
}
else {
// Hope LR holds correct value
pc() = _ucontext->uc_mcontext.regs[REG_LR];
}
return true;
}

#endif // defined(__aarch64__)

0 comments on commit 627adcf

Please sign in to comment.