ARM aarch64 TCG target
v4 cover ARM aarch64 TCG target
This series implements preliminary support for the ARM aarch64 TCG target.
Limitations of this initial implementation (TODOs) include:
* missing TLB lookup in qemu_ld/st [C helpers always called]. An incremental patch, which requires this series, is coming up from colleague Jani Kokkonen to implement this.
* most optional opcodes are not implemented yet (only rotation done).
* CONFIG_SOFTMMU only
Tested running on a x86-64 physical machine running Foundation v8, running a linux 3.8.0-rc6+ minimal host system based on linaro v8 image 201301271620 for user space.
Tested guests: arm v5 test image, i386 FreeDOS test image, i386 linux test image, all from qemu-devel testing page. Also tested on x86-64/linux built with buildroot, and on arm v7/linux built with buildroot as well.
Changes in v2:
* for icache flushing, removed placeholder for old gcc
* aligned defines values in the elf aarch64 relocations
* added comment in the elf aarch64 relocations
* use X16 and X17 as well, they should be safe to use
* defined TCG_REG_TMP to TCG_REG_X8
* fix relocs and gotos to be more robust during retranslation
* removed declarations and assignments on same line
* added braces in 'if's even when unnecessary
* added comment about COND_NV behaving like COND_AL in aarch64
* added comment about no-extend field
* remove trampoline for the conditional branches, add CONDBR19
* set MAX_CODE_GEN_BUFFER_SIZE for aarch64, matching JUMP26
* improved left rotations, by using one less instruction
* for setcond_i32/i64 use CSET instead of CSEL
* implement andi and subi for working with the stack
* do not rely on temp_buf for tcg_set_frame: use stack
* remove unused constrained ARM constant
* redefine enums with same value to one-another
* fix setting of available regs (set all 32 bits)
* moved configure patch to after the tcg target in the series
* added low level operations useful in preparation of tlb lookup
Changes in v3:
* removed low level operations introduced in v2, will be in separate series
* honor 'addend' in patch_reloc, although it's always 0
* replace use of 'int' with 'TCGReg' when registers are expected
* merge movi32 and movi64 into movi_aux
* use 32bit version of the instructions when possible, to save energy/cycles
* do not clobber a passed register for INDEX_op_rotl_i32/i64
* removed hard coded SP and FP in stack functions, make them params
* zero-extend addr_reg for 32bit guests in qemu_ld/st
* make use of deposit32 (bitops) in reloc_pc26 and reloc_pc19
* never use multiple cases per line in switches even when empty
* less pessimistic range checks for instructions
* other formatting fixes that fell through the cracks in v2
Changes in v4:
* made move immediate implementation more concise
* added comments explaining how the move immediate works
* reserve the frame pointer register (FP)
Claudio Fontana (3):
include/elf.h: add aarch64 ELF machine and relocs tcg/aarch64: implement new TCG target for aarch64
configure: permit compilation on arm aarch64
configure | 8 + include/elf.h | 129 ++++++ include/exec/exec-all.h | 5 +- tcg/aarch64/tcg-target.c | 1161 ++++++++++++++++++++++++++++++++++++++++++++++ tcg/aarch64/tcg-target.h | 99 ++++ translate-all.c | 2 + 6 files changed, 1403 insertions(+), 1 deletion(-) create mode 100644 tcg/aarch64/tcg-target.c create mode 100644 tcg/aarch64/tcg-target.h
Signature · 1 line
1.8.1
PATCH v4 1/3 include/elf.h: add aarch64 ELF machine and relocs
we will use the 26bit relative relocs in the aarch64 tcg target.
--- include/elf.h | 129 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+)
include/elf.h +129 -0
@@ -129,6 +129,8 @@ typedef int64_t Elf64_Sxword;#define EM_XTENSA 94/* Tensilica Xtensa */ +#define EM_AARCH64 183 +/* This is the info that is needed to parse the dynamic section of the file */ #define DT_NULL 0#define DT_NEEDED 1
@@ -616,6 +618,133 @@ typedef struct {/* Keep this the last entry. */ #define R_ARM_NUM 256 +/* ARM Aarch64 relocation types */ +#define R_AARCH64_NONE 256/* also accepts R_ARM_NONE (0) */ +/* static data relocations */ +#define R_AARCH64_ABS64 257 +#define R_AARCH64_ABS32 258 +#define R_AARCH64_ABS16 259 +#define R_AARCH64_PREL64 260 +#define R_AARCH64_PREL32 261 +#define R_AARCH64_PREL16 262 +/* static aarch64 group relocations */ +/* group relocs to create unsigned data value or address inline */ +#define R_AARCH64_MOVW_UABS_G0 263 +#define R_AARCH64_MOVW_UABS_G0_NC 264 +#define R_AARCH64_MOVW_UABS_G1 265 +#define R_AARCH64_MOVW_UABS_G1_NC 266 +#define R_AARCH64_MOVW_UABS_G2 267 +#define R_AARCH64_MOVW_UABS_G2_NC 268 +#define R_AARCH64_MOVW_UABS_G3 269 +/* group relocs to create signed data or offset value inline */ +#define R_AARCH64_MOVW_SABS_G0 270 +#define R_AARCH64_MOVW_SABS_G1 271 +#define R_AARCH64_MOVW_SABS_G2 272 +/* relocs to generate 19, 21, and 33 bit PC-relative addresses */ +#define R_AARCH64_LD_PREL_LO19 273 +#define R_AARCH64_ADR_PREL_LO21 274 +#define R_AARCH64_ADR_PREL_PG_HI21 275 +#define R_AARCH64_ADR_PREL_PG_HI21_NC 276 +#define R_AARCH64_ADD_ABS_LO12_NC 277 +#define R_AARCH64_LDST8_ABS_LO12_NC 278 +#define R_AARCH64_LDST16_ABS_LO12_NC 284 +#define R_AARCH64_LDST32_ABS_LO12_NC 285 +#define R_AARCH64_LDST64_ABS_LO12_NC 286 +#define R_AARCH64_LDST128_ABS_LO12_NC 299 +/* relocs for control-flow - all offsets as multiple of 4 */ +#define R_AARCH64_TSTBR14 279 +#define R_AARCH64_CONDBR19 280 +#define R_AARCH64_JUMP26 282 +#define R_AARCH64_CALL26 283 +/* group relocs to create pc-relative offset inline */ +#define R_AARCH64_MOVW_PREL_G0 287 +#define R_AARCH64_MOVW_PREL_G0_NC 288 +#define R_AARCH64_MOVW_PREL_G1 289 +#define R_AARCH64_MOVW_PREL_G1_NC 290 +#define R_AARCH64_MOVW_PREL_G2 291 +#define R_AARCH64_MOVW_PREL_G2_NC 292 +#define R_AARCH64_MOVW_PREL_G3 293 +/* group relocs to create a GOT-relative offset inline */ +#define R_AARCH64_MOVW_GOTOFF_G0 300 +#define R_AARCH64_MOVW_GOTOFF_G0_NC 301 +#define R_AARCH64_MOVW_GOTOFF_G1 302 +#define R_AARCH64_MOVW_GOTOFF_G1_NC 303 +#define R_AARCH64_MOVW_GOTOFF_G2 304 +#define R_AARCH64_MOVW_GOTOFF_G2_NC 305 +#define R_AARCH64_MOVW_GOTOFF_G3 306 +/* GOT-relative data relocs */ +#define R_AARCH64_GOTREL64 307 +#define R_AARCH64_GOTREL32 308 +/* GOT-relative instr relocs */ +#define R_AARCH64_GOT_LD_PREL19 309 +#define R_AARCH64_LD64_GOTOFF_LO15 310 +#define R_AARCH64_ADR_GOT_PAGE 311 +#define R_AARCH64_LD64_GOT_LO12_NC 312 +#define R_AARCH64_LD64_GOTPAGE_LO15 313 +/* General Dynamic TLS relocations */ +#define R_AARCH64_TLSGD_ADR_PREL21 512 +#define R_AARCH64_TLSGD_ADR_PAGE21 513 +#define R_AARCH64_TLSGD_ADD_LO12_NC 514 +#define R_AARCH64_TLSGD_MOVW_G1 515 +#define R_AARCH64_TLSGD_MOVW_G0_NC 516 +/* Local Dynamic TLS relocations */ +#define R_AARCH64_TLSLD_ADR_PREL21 517 +#define R_AARCH64_TLSLD_ADR_PAGE21 518 +#define R_AARCH64_TLSLD_ADD_LO12_NC 519 +#define R_AARCH64_TLSLD_MOVW_G1 520 +#define R_AARCH64_TLSLD_MOVW_G0_NC 521 +#define R_AARCH64_TLSLD_LD_PREL19 522 +#define R_AARCH64_TLSLD_MOVW_DTPREL_G2 523 +#define R_AARCH64_TLSLD_MOVW_DTPREL_G1 524 +#define R_AARCH64_TLSLD_MOVW_DTPREL_G1_NC 525 +#define R_AARCH64_TLSLD_MOVW_DTPREL_G0 526 +#define R_AARCH64_TLSLD_MOVW_DTPREL_G0_NC 527 +#define R_AARCH64_TLSLD_ADD_DTPREL_HI12 528 +#define R_AARCH64_TLSLD_ADD_DTPREL_LO12 529 +#define R_AARCH64_TLSLD_ADD_DTPREL_LO12_NC 530 +#define R_AARCH64_TLSLD_LDST8_DTPREL_LO12 531 +#define R_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC 532 +#define R_AARCH64_TLSLD_LDST16_DTPREL_LO12 533 +#define R_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC 534 +#define R_AARCH64_TLSLD_LDST32_DTPREL_LO12 535 +#define R_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC 536 +#define R_AARCH64_TLSLD_LDST64_DTPREL_LO12 537 +#define R_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC 538 +/* initial exec TLS relocations */ +#define R_AARCH64_TLSIE_MOVW_GOTTPREL_G1 539 +#define R_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC 540 +#define R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 541 +#define R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC 542 +#define R_AARCH64_TLSIE_LD_GOTTPREL_PREL19 543 +/* local exec TLS relocations */ +#define R_AARCH64_TLSLE_MOVW_TPREL_G2 544 +#define R_AARCH64_TLSLE_MOVW_TPREL_G1 545 +#define R_AARCH64_TLSLE_MOVW_TPREL_G1_NC 546 +#define R_AARCH64_TLSLE_MOVW_TPREL_G0 547 +#define R_AARCH64_TLSLE_MOVW_TPREL_G0_NC 548 +#define R_AARCH64_TLSLE_ADD_TPREL_HI12 549 +#define R_AARCH64_TLSLE_ADD_TPREL_LO12 550 +#define R_AARCH64_TLSLE_ADD_TPREL_LO12_NC 551 +#define R_AARCH64_TLSLE_LDST8_TPREL_LO12 552 +#define R_AARCH64_TLSLE_LDST8_TPREL_LO12_NC 553 +#define R_AARCH64_TLSLE_LDST16_TPREL_LO12 554 +#define R_AARCH64_TLSLE_LDST16_TPREL_LO12_NC 555 +#define R_AARCH64_TLSLE_LDST32_TPREL_LO12 556 +#define R_AARCH64_TLSLE_LDST32_TPREL_LO12_NC 557 +#define R_AARCH64_TLSLE_LDST64_TPREL_LO12 558 +#define R_AARCH64_TLSLE_LDST64_TPREL_LO12_NC 559 +/* Dynamic Relocations */ +#define R_AARCH64_COPY 1024 +#define R_AARCH64_GLOB_DAT 1025 +#define R_AARCH64_JUMP_SLOT 1026 +#define R_AARCH64_RELATIVE 1027 +#define R_AARCH64_TLS_DTPREL64 1028 +#define R_AARCH64_TLS_DTPMOD64 1029 +#define R_AARCH64_TLS_TPREL64 1030 +#define R_AARCH64_TLS_DTPREL32 1031 +#define R_AARCH64_TLS_DTPMOD32 1032 +#define R_AARCH64_TLS_TPREL32 1033 +/* s390 relocations defined by the ABIs */ #define R_390_NONE 0/* No reloc. */ #define R_390_8 1/* Direct 8 bit. */
Signature · 1 line
1.8.1
PATCH v4 2/3 tcg/aarch64: implement new TCG target for aarch64
In reply to Claudio Fontanaadd preliminary support for TCG target aarch64.
--- include/exec/exec-all.h | 5 +- tcg/aarch64/tcg-target.c | 1161 ++++++++++++++++++++++++++++++++++++++++++++++ tcg/aarch64/tcg-target.h | 99 ++++ translate-all.c | 2 + 4 files changed, 1266 insertions(+), 1 deletion(-) create mode 100644 tcg/aarch64/tcg-target.c create mode 100644 tcg/aarch64/tcg-target.h
include/exec/exec-all.h +4 -1
@@ -128,7 +128,7 @@ static inline void tlb_flush(CPUArchState *env, int flush_global)#if defined(__arm__) || defined(_ARCH_PPC) \ || defined(__x86_64__) || defined(__i386__) \ - || defined(__sparc__) \ + || defined(__sparc__) || defined(__aarch64__) \ || defined(CONFIG_TCG_INTERPRETER )#define USE_DIRECT_JUMP #endif
@@ -230,6 +230,9 @@ static inline void tb_set_jmp_target1(uintptr_t jmp_addr, uintptr_t addr) *(uint32_t *)jmp_addr = addr - (jmp_addr +4 ); /* no need to flush icache explicitly */ } +#elif defined(__aarch64__) +void aarch64_tb_set_jmp_target (uintptr_t jmp_addr,uintptr_t addr); +#define tb_set_jmp_target1 aarch64_tb_set_jmp_target#elif defined(__arm__)static inline void tb_set_jmp_target1 (uintptr_t jmp_addr,uintptr_t addr) {
tcg/aarch64/tcg-target.c new file +1161 -0
1,161 lines not on this page · raw message
tcg/aarch64/tcg-target.h new file +99 -0
99 lines not on this page · raw message
translate-all.c +2 -0
@@ -460,6 +460,8 @@ static inline PageDesc *page_find(tb_page_addr_t index)# define MAX_CODE_GEN_BUFFER_SIZE (2ul * 1024 * 1024 * 1024)#elif defined(__sparc__)# define MAX_CODE_GEN_BUFFER_SIZE (2ul * 1024 * 1024 * 1024) +#elif defined(__aarch64__) +# define MAX_CODE_GEN_BUFFER_SIZE (128ul * 1024 * 1024)#elif defined(__arm__)# define MAX_CODE_GEN_BUFFER_SIZE (16u * 1024 * 1024)#elif defined(__s390x__)
Signature · 1 line
1.8.1
PATCH v4 3/3 configure: permit compilation on arm aarch64
In reply to Claudio Fontanasupport compiling on aarch64.
--- configure | 8 ++++++++ 1 file changed, 8 insertions(+)
configure +8 -0
@@ -385,6 +385,8 @@ elif check_define __s390__ ; then fi elif check_define __arm__ ; then cpu="arm" +elif check_define __aarch64__ ; then + cpu="aarch64" elif check_define __hppa__ ; then cpu="hppa" else
@@ -407,6 +409,9 @@ case "$cpu" in armv*b|armv*l|arm) cpu="arm" ;; + aarch64) + cpu="aarch64" + ;; hppa|parisc|parisc64) cpu="hppa" ;;
@@ -4127,6 +4132,9 @@ if test "$linux" = "yes" ; then s390x) linux_arch=s390 ;; + aarch64) + linux_arch=arm64 + ;; *) # For most CPUs the kernel architecture name and QEMU CPU name match. linux_arch="$cpu"
Signature · 1 line
1.8.1
Quoted 62 lines · Claudio Fontana
This series implements preliminary support for the ARM aarch64 TCG target.
Limitations of this initial implementation (TODOs) include:
* missing TLB lookup in qemu_ld/st [C helpers always called]. An incremental patch, which requires this series, is coming up from colleague Jani Kokkonen to implement this.
* most optional opcodes are not implemented yet (only rotation done).
*CONFIG_SOFTMMUonlyTested running on a x86-64 physical machine running Foundation v8, running a linux 3.8.0-rc6+ minimal host system based on linaro v8 image 201301271620 for user space.
Tested guests: arm v5 test image, i386 FreeDOS test image, i386 linux test image, all from qemu-devel testing page. Also tested on x86-64/linux built with buildroot, and on arm v7/linux built with buildroot as well.
Changes in v2:
* for icache flushing, removed placeholder for old gcc
* aligned defines values in the elf aarch64 relocations
* added comment in the elf aarch64 relocations
* use X16 and X17 as well, they should be safe to use
* definedTCG_REG_TMPtoTCG_REG_X8
* fix relocs and gotos to be more robust during retranslation
* removed declarations and assignments on same line
* added braces in 'if's even when unnecessary
* added comment aboutCOND_NVbehaving likeCOND_ALin aarch64
* added comment about no-extend field
* remove trampoline for the conditional branches, add CONDBR19
* setMAX_CODE_GEN_BUFFER_SIZEfor aarch64, matching JUMP26
* improved left rotations, by using one less instruction
* for setcond_i32/i64 use CSET instead of CSEL
* implement andi and subi for working with the stack
* do not rely ontemp_buffortcg_set_frame: use stack
* remove unused constrained ARM constant
* redefine enums with same value to one-another
* fix setting of available regs (set all 32 bits)
* moved configure patch to after the tcg target in the series
* added low level operations useful in preparation of tlb lookupChanges in v3:
* removed low level operations introduced in v2, will be in separate series
* honor 'addend' inpatch_reloc, although it's always 0
* replace use of 'int' with 'TCGReg' when registers are expected
* merge movi32 and movi64 intomovi_aux
* use 32bit version of the instructions when possible, to save energy/cycles
* do not clobber a passed register for INDEX_op_rotl_i32/i64
* removed hard coded SP and FP in stack functions, make them params
* zero-extendaddr_regfor 32bit guests in qemu_ld/st
* make use of deposit32 (bitops) inreloc_pc26andreloc_pc19
* never use multiple cases per line in switches even when empty
* less pessimistic range checks for instructions
* other formatting fixes that fell through the cracks in v2Changes in v4:
* made move immediate implementation more concise
* added comments explaining how the move immediate works
* reserve the frame pointer register (FP)
Quoted 4 lines
Claudio Fontana (3):
include/elf.h: add aarch64 ELF machine and relocs tcg/aarch64: implement new TCG target for aarch64
configure: permit compilation on arm aarch64
r~
Quoted 2 lines · Claudio Fontana
This series implements preliminary support for the ARM aarch64 TCG target.
Cc'd some people who might like to commit the patchset.
thanks
-- PMM