Skip to content
This repository has been archived by the owner on Feb 3, 2020. It is now read-only.

Arm support #24

Open
wants to merge 59 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
4b8541c
Imported source files from QEMU v1.0.0 target-arm/libcpu
weizhou-chaojixx Jan 20, 2020
9991870
feat: add cortex-m r/w ioctl and regs and sregs structs
weizhou-chaojixx Oct 17, 2019
eececf9
cpu:fix GVA->HVA
weizhou-chaojixx Nov 8, 2019
fadd2c0
ARM interrupt: fix armv7m interrupt
weizhou-chaojixx Oct 17, 2019
749030c
feat:sync sregs with kvm cpu
weizhou-chaojixx Oct 17, 2019
0b6de3b
Enable symbex mode of s2e compatible with arm cpu.
weizhou-chaojixx Oct 17, 2019
c1529d2
Applied clang format
weizhou-chaojixx Oct 17, 2019
c6530a9
Made arm library usable from C++ code
weizhou-chaojixx Nov 2, 2019
c8cf7dc
fpu:no support symbex mode for arm
weizhou-chaojixx Nov 7, 2019
5a50aad
fix ram_access for compatibility
weizhou-chaojixx Nov 7, 2019
95d083a
io_read: fix mmio_access return
weizhou-chaojixx Nov 16, 2019
b5556c2
target-arm/translate: fix exc_return value
weizhou-chaojixx Dec 2, 2019
3789ea0
log: add log and log defination
weizhou-chaojixx Dec 2, 2019
7e700de
helper: replace w/r regs with WR/RR
weizhou-chaojixx Dec 2, 2019
44b40c9
target-arm/translate: deal with CONFIG_SYMBEX mode according to x86
weizhou-chaojixx Dec 2, 2019
ac77643
log: change the log location and information
weizhou-chaojixx Dec 13, 2019
34a2eec
msr:hard-code sync sregs between kvm env with cpu env
weizhou-chaojixx Dec 11, 2019
128cbe6
v7m_interrupt: add interrupt support for symbex mode
weizhou-chaojixx Dec 10, 2019
3fb3562
helper: abort hard fault interrupt
weizhou-chaojixx Dec 11, 2019
927edb6
add exit reason KVM_EXIT_SYNC_SREGS
weizhou-chaojixx Dec 18, 2019
4e1b1ae
target-arm:remove helper.h
weizhou-chaojixx Dec 28, 2019
e7b51a2
S2E/issue/269-upgrade
weizhou-chaojixx Dec 28, 2019
b3492f1
CMakeLists:TARGET_INSN_START_EXTRA_WORDS is 2 in ARM
weizhou-chaojixx Dec 25, 2019
ac5dfdf
se_libcpu_config.h: add arm SE_RAM_OBJECT_BIT
weizhou-chaojixx Dec 26, 2019
b8aac2e
add TARGET_X86_64
weizhou-chaojixx Dec 26, 2019
04874da
cpu-exec: ltb should be reset after processing interrupts
weizhou-chaojixx Dec 27, 2019
c56160b
softmmu_template.h: no need for original mmio rw for symbolic mmio ports
weizhou-chaojixx Dec 30, 2019
401e95f
cpu-exec:only allow interrupt in concrete mode
weizhou-chaojixx Jan 9, 2020
4b2cfa5
target-arm/translate.c: update gen_test_cc from 1.0 to 3.0
weizhou-chaojixx Jan 9, 2020
58af1d4
kvm.h: add firmware init interfaces
weizhou-chaojixx Jan 15, 2020
d768c7c
exe.c: use phy_addr for mem_desc_find in ARM
weizhou-chaojixx Jan 20, 2020
82533c1
kvm_arm.h: add kvm_m_vcpu_init struct for KVM_CUSTOM_M_INIT ioctl int…
weizhou-chaojixx Jan 20, 2020
266afd7
softmmu_template.h: write symbol value to io casue unexpected state …
weizhou-chaojixx Jan 22, 2020
7931e67
cpu-exec.c: in case execution mode switch during interrupt
weizhou-chaojixx Jan 24, 2020
3ffe667
target-arm/translate: fix cortex-m interrupt return
weizhou-chaojixx Jan 24, 2020
ac394e5
target-arm/translate: add instr_gen_pc_update
weizhou-chaojixx Feb 2, 2020
d38669e
fixup! target-arm/translate: fix cortex-m interrupt return regs in en…
weizhou-chaojixx Feb 14, 2020
b4d2444
target-arm/helper: set the LSB of the return pc to zero
weizhou-chaojixx Feb 14, 2020
8aec36a
fixup! softmmu_template.h: write symbol value to io casue unexpected…
weizhou-chaojixx Feb 18, 2020
490cf47
helper: move helper instructions to op_helper for symobolic execution
weizhou-chaojixx Feb 18, 2020
4940c84
fixup! target-arm/translate: fix cortex-m interrupt return regs in en…
weizhou-chaojixx Mar 27, 2020
6b8b118
target-arm: add interrupt_flag in env to make sure the execution will…
weizhou-chaojixx Mar 28, 2020
c2a8b08
se_libcpu: add external irqs control interfaces
weizhou-chaojixx Mar 28, 2020
6d2572a
fixup! target-arm: add interrupt_flag in env to make sure the executi…
weizhou-chaojixx May 5, 2020
b8b4d5f
comment debug log
weizhou-chaojixx May 19, 2020
ddc30aa
fixup! softmmu_template.h: no need for original mmio rw for symbolic …
weizhou-chaojixx May 22, 2020
c2dccf8
check env S2EDIR;
weizhou-chaojixx May 22, 2020
df5a3d1
fixup! check env S2EDIR;
weizhou-chaojixx May 22, 2020
c0bb0f5
fixup! target-arm: add interrupt_flag in env to make sure the executi…
weizhou-chaojixx May 22, 2020
e673a65
uncomment
weizhou-chaojixx May 25, 2020
2f5a1b2
helper: change armv7m_nvic_acknowledge_irq prototype
weizhou-chaojixx May 25, 2020
dd147c0
fixup! target-arm: add interrupt_flag in env to make sure the executi…
weizhou-chaojixx Jun 20, 2020
82409e6
target-arm/translate.c: add TB type
weizhou-chaojixx Jul 18, 2020
5a69042
target-arm/translate.c: replace wfi irq continue execution
weizhou-chaojixx Jul 18, 2020
afef143
fixup! target-arm/translate.c: add TB type
weizhou-chaojixx Oct 9, 2020
e18da50
se_libcpu.h: add invalid_pc_access event
weizhou-chaojixx Dec 18, 2020
7acb974
exec.c: trigger invalid_pc_access event
weizhou-chaojixx Dec 18, 2020
724800d
se_libcpu.h: add on_armv7m_interrupt_exit event
weizhou-chaojixx Dec 19, 2020
5307ae5
helper.c: trigger on_armv7m_interrupt_exit event
weizhou-chaojixx Dec 19, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,11 @@ file(WRITE ${CONFIG_TARGET_H}
#define TARGET_SHORT_ALIGNMENT 2
#define TARGET_INT_ALIGNMENT 4
#define TARGET_LLONG_ALIGNMENT 8
#define TARGET_I386 1
#define TARGET_PHYS_ADDR_BITS 64
#define CONFIG_SOFTMMU 1
#define CONFIG_I386_DIS 1
"
)

if (S2EGUEST_INCLUDE_DIR)
if(S2EGUEST_INCLUDE_DIR)
file(APPEND ${CONFIG_TARGET_H} "#define CONFIG_SYMBEX_OPCODES 1\n")
endif()

Expand All @@ -72,13 +69,25 @@ message(STATUS "WITH_TARGET: ${WITH_TARGET}")

if(WITH_TARGET MATCHES "i386")
file(APPEND ${CONFIG_TARGET_H} "#define TARGET_ARCH \"i386\"\n")
file(APPEND ${CONFIG_TARGET_H} "#define TARGET_I386 1\n")
file(APPEND ${CONFIG_TARGET_H} "#define TARGET_LONG_ALIGNMENT 4\n")
file(APPEND ${CONFIG_TARGET_H} "#define TARGET_INSN_START_EXTRA_WORDS 1\n")

set(TARGET_DIR "target-i386")
elseif(WITH_TARGET MATCHES "x86_64")
file(APPEND ${CONFIG_TARGET_H} "#define TARGET_ARCH \"x86_64\"\n")
file(APPEND ${CONFIG_TARGET_H} "#define TARGET_X86_64 1\n")
file(APPEND ${CONFIG_TARGET_H} "#define TARGET_LONG_ALIGNMENT 8\n")
file(APPEND ${CONFIG_TARGET_H} "#define TARGET_INSN_START_EXTRA_WORDS 1\n")

set(TARGET_DIR "target-i386")
elseif(WITH_TARGET MATCHES "arm")
file(APPEND ${CONFIG_TARGET_H} "#define TARGET_ARCH \"arm\"\n")
file(APPEND ${CONFIG_TARGET_H} "#define TARGET_ARM 1\n")
file(APPEND ${CONFIG_TARGET_H} "#define TARGET_LONG_ALIGNMENT 4\n")
file(APPEND ${CONFIG_TARGET_H} "#define TARGET_INSN_START_EXTRA_WORDS 2\n")

set(TARGET_DIR "target-arm")
else()
message(FATAL_ERROR "Incorrect target ${WITH_TARGET}")
endif()
Expand All @@ -93,15 +102,13 @@ if(WITH_TARGET MATCHES "s2e")
endif()

# We want to keep NDEBUG in all builds
foreach (flags_var_to_scrub
CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_RELWITHDEBINFO
CMAKE_CXX_FLAGS_MINSIZEREL
CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_RELWITHDEBINFO
CMAKE_C_FLAGS_MINSIZEREL)
string (REGEX REPLACE "(^| )[/-]D *NDEBUG($| )" " "
"${flags_var_to_scrub}" "${${flags_var_to_scrub}}")
foreach(flags_var_to_scrub CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_RELWITHDEBINFO
CMAKE_CXX_FLAGS_MINSIZEREL
CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_RELWITHDEBINFO
CMAKE_C_FLAGS_MINSIZEREL)
string(REGEX REPLACE "(^| )[/-]D *NDEBUG($| )" " " "${flags_var_to_scrub}" "${${flags_var_to_scrub}}")
endforeach()

include_directories(${GLIB_PKG_INCLUDE_DIRS}
Expand Down
8 changes: 8 additions & 0 deletions include/cpu/apic.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@
#ifndef APIC_H
#define APIC_H

#include <cpu/config.h>

#if defined(TARGET_I386) || defined(TARGET_X86_64)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary? AFAIK, TARGET_X86_64 implies TARGET_I386.
In anycase, this should be sent to a separate PR.

#include <cpu/i386/cpu.h>
#elif defined(TARGET_ARM)
#include <cpu/arm/cpu.h>
#else
#error unsupported target CPU
#endif
#include <cpu/types.h>
#include <inttypes.h>

Expand Down
265 changes: 265 additions & 0 deletions include/cpu/arm/cpu.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,265 @@
/// Copyright (C) 2003 Fabrice Bellard
/// Copyright (C) 2010 Dependable Systems Laboratory, EPFL
/// Copyright (C) 2017 Adrian Herrera
/// Copyrights of all contributions belong to their respective owners.
///
/// This library is free software; you can redistribute it and/or
/// modify it under the terms of the GNU Library General Public
/// License as published by the Free Software Foundation; either
/// version 2 of the License, or (at your option) any later version.
///
/// This library is distributed in the hope that it will be useful,
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
/// Library General Public License for more details.
///
/// You should have received a copy of the GNU Library General Public
/// License along with this library; if not, see <http://www.gnu.org/licenses/>.

#ifndef __LIBCPU_ARM_CPU_H__
#define __LIBCPU_ARM_CPU_H__

#include <stdbool.h>

#include <cpu/common.h>
#include <cpu/interrupt.h>
#include <cpu/types.h>
#include <fpu/softfloat.h>

//#define CPUState struct CPUARMState

#define CPUArchState struct CPUARMState

#include "defs.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef void ARMWriteCPFunc(void *opaque, int cp_info, int srcreg, int operand, uint32_t value);
typedef uint32_t ARMReadCPFunc(void *opaque, int cp_info, int dstreg, int operand);

/*
* We currently assume float and double are IEEE single and double precision respectively. Doing runtime conversions is
* tricky because VFP registers may contain integer values (eg. as the result of a FTOSI instruction).
*
* s<2n> maps to the least significant half of d<n>
* s<2n+1> maps to the most significant half of d<n>
*/

typedef struct CPUARMState {
uint32_t spsr;

/* Banked registers. */
uint32_t banked_spsr[6];
uint32_t banked_r13[6];
uint32_t banked_r14[6];

/* These hold r8-r12. */
uint32_t usr_regs[5];
uint32_t fiq_regs[5];

/* cpsr flag cache for faster execution */
uint32_t CF; /* 0 or 1 */
uint32_t VF; /* V is the bit 31. All other bits are undefined */
uint32_t NF; /* N is bit 31. All other bits are undefined. */
uint32_t ZF; /* Z set if zero. */

/*
* Regs for current mode.
*
* regs[15] is the border between concrete and symbolic area, i.e., regs[15] is in concrete-only-area
*/
uint32_t regs[16];

uint32_t QF; /* 0 or 1 */
uint32_t GE; /* cpsr[19:16] */
uint32_t thumb; /* cpsr[5]. 0 = arm mode, 1 = thumb mode. */
uint32_t condexec_bits; /* IT bits. cpsr[15:10,26:25]. */

/*
* Frequently accessed CPSR bits are stored separately for efficiently. This contains all the other bits. Use
* cpsr_{read,write} to access the whole CPSR.
*/
uint32_t uncached_cpsr;

/* System control coprocessor (cp15) */
struct {
uint32_t c0_cpuid;
uint32_t c0_cachetype;
uint32_t c0_ccsid[16]; /* Cache size. */
uint32_t c0_clid; /* Cache level. */
uint32_t c0_cssel; /* Cache size selection. */
uint32_t c0_c1[8]; /* Feature registers. */
uint32_t c0_c2[8]; /* Instruction set registers. */
uint32_t c1_sys; /* System control register. */
uint32_t c1_coproc; /* Coprocessor access register. */
uint32_t c1_xscaleauxcr; /* XScale auxiliary control register. */
uint32_t c1_scr; /* secure config register. */
uint32_t c2_base0; /* MMU translation table base 0. */
uint32_t c2_base1; /* MMU translation table base 1. */
uint32_t c2_control; /* MMU translation table base control. */
uint32_t c2_mask; /* MMU translation table base selection mask. */
uint32_t c2_base_mask; /* MMU translation table base 0 mask. */
uint32_t c2_data; /* MPU data cachable bits. */
uint32_t c2_insn; /* MPU instruction cachable bits. */
uint32_t c3; /* MMU domain access control register
MPU write buffer control. */
uint32_t c5_insn; /* Fault status registers. */
uint32_t c5_data;
uint32_t c6_region[8]; /* MPU base/size registers. */
uint32_t c6_insn; /* Fault address registers. */
uint32_t c6_data;
uint32_t c7_par; /* Translation result. */
uint32_t c9_insn; /* Cache lockdown registers. */
uint32_t c9_data;
uint32_t c9_pmcr; /* performance monitor control register */
uint32_t c9_pmcnten; /* perf monitor counter enables */
uint32_t c9_pmovsr; /* perf monitor overflow status */
uint32_t c9_pmxevtyper; /* perf monitor event type */
uint32_t c9_pmuserenr; /* perf monitor user enable */
uint32_t c9_pminten; /* perf monitor interrupt enables */
uint32_t c13_fcse; /* FCSE PID. */
uint32_t c13_context; /* Context ID. */
uint32_t c13_tls1; /* User RW Thread register. */
uint32_t c13_tls2; /* User RO Thread register. */
uint32_t c13_tls3; /* Privileged Thread register. */
uint32_t c15_cpar; /* XScale Coprocessor Access Register */
uint32_t c15_ticonfig; /* TI925T configuration byte. */
uint32_t c15_i_max; /* Maximum D-cache dirty line index. */
uint32_t c15_i_min; /* Minimum D-cache dirty line index. */
uint32_t c15_threadid; /* TI debugger thread-ID. */
uint32_t c15_config_base_address; /* SCU base address. */
uint32_t c15_diagnostic; /* diagnostic register */
uint32_t c15_power_diagnostic;
uint32_t c15_power_control; /* power control */
} cp15;

struct {
uint32_t other_sp;
uint32_t vecbase;
uint32_t basepri;
uint32_t control;
int current_sp;
int exception;
int pending_exception;
} v7m;

/* Thumb-2 EE state. */
uint32_t teecr;
uint32_t teehbr;

/* VFP coprocessor state. */
struct {
float64 regs[32];

uint32_t xregs[16];
/* We store these fpcsr fields separately for convenience. */
int vec_len;
int vec_stride;

/* scratch space when Tn are not sufficient. */
uint32_t scratch[8];

/* fp_status is the "normal" fp status. standard_fp_status retains
* values corresponding to the ARM "Standard FPSCR Value", ie
* default-NaN, flush-to-zero, round-to-nearest and is used by
* any operations (generally Neon) which the architecture defines
* as controlled by the standard FPSCR value rather than the FPSCR.
*
* To avoid having to transfer exception bits around, we simply
* say that the FPSCR cumulative exception flags are the logical
* OR of the flags in the two fp statuses. This relies on the
* only thing which needs to read the exception flags being
* an explicit FPSCR read.
*/
float_status fp_status;
float_status standard_fp_status;
} vfp;
uint32_t exclusive_addr;
uint32_t exclusive_val;
uint32_t exclusive_high;

/* iwMMXt coprocessor state. */
struct {
uint64_t regs[16];
uint64_t val;

uint32_t cregs[16];
} iwmmxt;

/* For mixed endian mode. */
bool bswap_code;

CPU_COMMON

/* These fields after the common ones so they are preserved on reset. */

/* Internal CPU feature flags. */
uint32_t features;
/* Coprocessor IO used by peripherals */
struct {
ARMReadCPFunc *cp_read;
ARMWriteCPFunc *cp_write;
void *opaque;
} cp[15];
void *nvic;
const struct arm_boot_info *boot_info;

/* For KVM */
int kvm_request_interrupt_window;
int kvm_irq;
uint8_t timer_interrupt_disabled;
int interrupt_flag; //indicate in interrupt or not

} CPUARMState;
CPUARMState *cpu_arm_init(const char *cpu_model);
void do_cpu_arm_init(CPUARMState *env);
int cpu_arm_exec(CPUARMState *s);

void arm_cpu_set_irq(CPUARMState *env, int level);

int cpu_arm_handle_mmu_fault(CPUARMState *env, target_ulong addr, int is_write, int mmu_idx);

enum arm_cpu_mode {
ARM_CPU_MODE_USR = 0x10,
ARM_CPU_MODE_FIQ = 0x11,
ARM_CPU_MODE_IRQ = 0x12,
ARM_CPU_MODE_SVC = 0x13,
ARM_CPU_MODE_ABT = 0x17,
ARM_CPU_MODE_UND = 0x1b,
ARM_CPU_MODE_SYS = 0x1f
};
#define CPSR_M (0x1f)
#define CPSR_T (1 << 5)
#define CPSR_F (1 << 6)
#define CPSR_I (1 << 7)
#define CPSR_A (1 << 8)
#define CPSR_E (1 << 9)
#define CPSR_IT_2_7 (0xfc00)
#define CPSR_GE (0xf << 16)
#define CPSR_RESERVED (0xf << 20)
#define CPSR_J (1 << 24)
#define CPSR_IT_0_1 (3 << 25)
#define CPSR_Q (1 << 27)
#define CPSR_V (1 << 28)
#define CPSR_C (1 << 29)
#define CPSR_Z (1 << 30)
#define CPSR_N (1 << 31)
#define CPSR_NZCV (CPSR_N | CPSR_Z | CPSR_C | CPSR_V)

#define CPSR_IT (CPSR_IT_0_1 | CPSR_IT_2_7)
#define CACHED_CPSR_BITS (CPSR_T | CPSR_GE | CPSR_IT | CPSR_Q | CPSR_NZCV)
/* Bits writable in user mode. */
#define CPSR_USER (CPSR_NZCV | CPSR_Q | CPSR_GE)
/* Execution state bits. MRS read as zero, MSR writes ignored. */
#define CPSR_EXEC (CPSR_T | CPSR_IT | CPSR_J)

static inline int cpu_mmu_index(CPUARMState *env) {
return (env->uncached_cpsr & CPSR_M) == ARM_CPU_MODE_USR ? 1 : 0;
}
#ifdef __cplusplus
}
#endif

#endif
41 changes: 41 additions & 0 deletions include/cpu/arm/defs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/// Copyright (C) 2003 Fabrice Bellard
/// Copyright (C) 2010 Dependable Systems Laboratory, EPFL
/// Copyright (C) 2017 Adrian Herrera
/// Copyrights of all contributions belong to their respective owners.
///
/// This library is free software; you can redistribute it and/or
/// modify it under the terms of the GNU Library General Public
/// License as published by the Free Software Foundation; either
/// version 2 of the License, or (at your option) any later version.
///
/// This library is distributed in the hope that it will be useful,
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
/// Library General Public License for more details.
///
/// You should have received a copy of the GNU Library General Public
/// License along with this library; if not, see <http://www.gnu.org/licenses/>.

#ifndef __CPU_ARM_DEFS__
#define __CPU_ARM_DEFS__

#ifdef __cplusplus
extern "C" {
#endif
// clang-format off

/*******************************************/

#define NB_MMU_MODES 2
/* The ARM MMU allows 1k pages. */
/* ??? Linux doesn't actually use these, and they're deprecated in recent
architecture revisions. Maybe a configure option to disable them. */
#define TARGET_PAGE_BITS 10

#define TARGET_HAS_ICE 1

#ifdef __cplusplus
}
#endif

#endif
Loading