Skip to content

Commit c79f01c

Browse files
committed
Merge remote-tracking branch 'remotes/rth-gitlab/tags/pull-hex-20210218' into staging
Initial commit for the Qualcomm Hexagon processor. # gpg: Signature made Thu 18 Feb 2021 16:26:52 GMT # gpg: using RSA key 7A481E78868B4DB6A85A05C064DF38E8AF7E215F # gpg: issuer "[email protected]" # gpg: Good signature from "Richard Henderson <[email protected]>" [full] # Primary key fingerprint: 7A48 1E78 868B 4DB6 A85A 05C0 64DF 38E8 AF7E 215F * remotes/rth-gitlab/tags/pull-hex-20210218: (35 commits) Hexagon build infrastructure Hexagon (tests/tcg/hexagon) TCG tests - floating point Hexagon (tests/tcg/hexagon) TCG tests - atomics/load/store/misc Hexagon (tests/tcg/hexagon) TCG tests - multiarch Hexagon (linux-user/hexagon) Linux user emulation Hexagon (target/hexagon) translation Hexagon (target/hexagon) TCG for floating point instructions Hexagon (target/hexagon) TCG for instructions with multiple definitions Hexagon (target/hexagon) TCG generation Hexagon (target/hexagon) instruction classes Hexagon (target/hexagon) macros Hexagon (target/hexagon) opcode data structures Hexagon (target/hexagon) generater phase 4 - decode tree Hexagon (target/hexagon) generator phase 3 - C preprocessor for decode tree Hexagon (target/hexagon) generator phase 2 - generate header files Hexagon (target/hexagon) generator phase 1 - C preprocessor for semantics Hexagon (target/hexagon/imported) arch import Hexagon (target/hexagon/fma_emu.[ch]) utility functions Hexagon (target/hexagon/conv_emu.[ch]) utility functions Hexagon (target/hexagon/arch.[ch]) utility functions ... Signed-off-by: Peter Maydell <[email protected]>
2 parents b826fb8 + 3e7a84e commit c79f01c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+23183
-2
lines changed

MAINTAINERS

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,15 @@ F: include/hw/cris/
188188
F: tests/tcg/cris/
189189
F: disas/cris.c
190190

191+
Hexagon TCG CPUs
192+
M: Taylor Simpson <[email protected]>
193+
S: Supported
194+
F: target/hexagon/
195+
F: linux-user/hexagon/
196+
F: tests/tcg/hexagon/
197+
F: disas/hexagon.c
198+
F: default-configs/targets/hexagon-linux-user.mak
199+
191200
HPPA (PA-RISC) TCG CPUs
192201
M: Richard Henderson <[email protected]>
193202
S: Maintained
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TARGET_ARCH=hexagon

disas/hexagon.c

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright(c) 2019-2021 Qualcomm Innovation Center, Inc. All Rights Reserved.
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
/*
19+
* QEMU Hexagon Disassembler
20+
*/
21+
22+
#include "qemu/osdep.h"
23+
#include "disas/dis-asm.h"
24+
#include "target/hexagon/cpu_bits.h"
25+
26+
/*
27+
* We will disassemble a packet with up to 4 instructions, so we need
28+
* a hefty size buffer.
29+
*/
30+
#define PACKET_BUFFER_LEN 1028
31+
32+
int print_insn_hexagon(bfd_vma memaddr, struct disassemble_info *info)
33+
{
34+
uint32_t words[PACKET_WORDS_MAX];
35+
bool found_end = false;
36+
GString *buf = g_string_sized_new(PACKET_BUFFER_LEN);
37+
int i, len;
38+
39+
for (i = 0; i < PACKET_WORDS_MAX && !found_end; i++) {
40+
int status = (*info->read_memory_func)(memaddr + i * sizeof(uint32_t),
41+
(bfd_byte *)&words[i],
42+
sizeof(uint32_t), info);
43+
if (status) {
44+
if (i > 0) {
45+
break;
46+
}
47+
(*info->memory_error_func)(status, memaddr, info);
48+
return status;
49+
}
50+
if (is_packet_end(words[i])) {
51+
found_end = true;
52+
}
53+
}
54+
55+
if (!found_end) {
56+
(*info->fprintf_func)(info->stream, "<invalid>");
57+
return PACKET_WORDS_MAX * sizeof(uint32_t);
58+
}
59+
60+
len = disassemble_hexagon(words, i, memaddr, buf);
61+
(*info->fprintf_func)(info->stream, "%s", buf->str);
62+
g_string_free(buf, true);
63+
64+
return len;
65+
}

disas/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ common_ss.add(when: 'CONFIG_ARM_A64_DIS', if_true: files('arm-a64.cc'))
66
common_ss.add_all(when: 'CONFIG_ARM_A64_DIS', if_true: libvixl_ss)
77
common_ss.add(when: 'CONFIG_ARM_DIS', if_true: files('arm.c'))
88
common_ss.add(when: 'CONFIG_CRIS_DIS', if_true: files('cris.c'))
9+
common_ss.add(when: 'CONFIG_HEXAGON_DIS', if_true: files('hexagon.c'))
910
common_ss.add(when: 'CONFIG_HPPA_DIS', if_true: files('hppa.c'))
1011
common_ss.add(when: 'CONFIG_I386_DIS', if_true: files('i386.c'))
1112
common_ss.add(when: 'CONFIG_LM32_DIS', if_true: files('lm32.c'))

include/disas/dis-asm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,7 @@ int print_insn_xtensa (bfd_vma, disassemble_info*);
459459
int print_insn_riscv32 (bfd_vma, disassemble_info*);
460460
int print_insn_riscv64 (bfd_vma, disassemble_info*);
461461
int print_insn_rx(bfd_vma, disassemble_info *);
462+
int print_insn_hexagon(bfd_vma, disassemble_info *);
462463

463464
#ifdef CONFIG_CAPSTONE
464465
bool cap_disas_target(disassemble_info *info, uint64_t pc, size_t size);

include/elf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ typedef struct mips_elf_abiflags_v0 {
176176

177177
#define EM_UNICORE32 110 /* UniCore32 */
178178

179+
#define EM_HEXAGON 164 /* Qualcomm Hexagon */
179180
#define EM_RX 173 /* Renesas RX family */
180181

181182
#define EM_RISCV 243 /* RISC-V */

include/qemu/int128.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ static inline Int128 int128_and(Int128 a, Int128 b)
5858
return a & b;
5959
}
6060

61+
static inline Int128 int128_or(Int128 a, Int128 b)
62+
{
63+
return a | b;
64+
}
65+
6166
static inline Int128 int128_rshift(Int128 a, int n)
6267
{
6368
return a >> n;
@@ -208,6 +213,11 @@ static inline Int128 int128_and(Int128 a, Int128 b)
208213
return (Int128) { a.lo & b.lo, a.hi & b.hi };
209214
}
210215

216+
static inline Int128 int128_or(Int128 a, Int128 b)
217+
{
218+
return (Int128) { a.lo | b.lo, a.hi | b.hi };
219+
}
220+
211221
static inline Int128 int128_rshift(Int128 a, int n)
212222
{
213223
int64_t h;

linux-user/elfload.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,6 +1514,22 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs,
15141514

15151515
#endif /* TARGET_XTENSA */
15161516

1517+
#ifdef TARGET_HEXAGON
1518+
1519+
#define ELF_START_MMAP 0x20000000
1520+
1521+
#define ELF_CLASS ELFCLASS32
1522+
#define ELF_ARCH EM_HEXAGON
1523+
1524+
static inline void init_thread(struct target_pt_regs *regs,
1525+
struct image_info *infop)
1526+
{
1527+
regs->sepc = infop->entry;
1528+
regs->sp = infop->start_stack;
1529+
}
1530+
1531+
#endif /* TARGET_HEXAGON */
1532+
15171533
#ifndef ELF_PLATFORM
15181534
#define ELF_PLATFORM (NULL)
15191535
#endif

linux-user/hexagon/cpu_loop.c

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
* qemu user cpu loop
3+
*
4+
* Copyright (c) 2003-2008 Fabrice Bellard
5+
* Copyright(c) 2019-2021 Qualcomm Innovation Center, Inc. All Rights Reserved.
6+
*
7+
* This program is free software; you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation; either version 2 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program; if not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
21+
#include "qemu/osdep.h"
22+
#include "qemu.h"
23+
#include "cpu_loop-common.h"
24+
#include "internal.h"
25+
26+
void cpu_loop(CPUHexagonState *env)
27+
{
28+
CPUState *cs = CPU(hexagon_env_get_cpu(env));
29+
int trapnr, signum, sigcode;
30+
target_ulong sigaddr;
31+
target_ulong syscallnum;
32+
target_ulong ret;
33+
34+
for (;;) {
35+
cpu_exec_start(cs);
36+
trapnr = cpu_exec(cs);
37+
cpu_exec_end(cs);
38+
process_queued_cpu_work(cs);
39+
40+
signum = 0;
41+
sigcode = 0;
42+
sigaddr = 0;
43+
44+
switch (trapnr) {
45+
case EXCP_INTERRUPT:
46+
/* just indicate that signals should be handled asap */
47+
break;
48+
case HEX_EXCP_TRAP0:
49+
syscallnum = env->gpr[6];
50+
env->gpr[HEX_REG_PC] += 4;
51+
ret = do_syscall(env,
52+
syscallnum,
53+
env->gpr[0],
54+
env->gpr[1],
55+
env->gpr[2],
56+
env->gpr[3],
57+
env->gpr[4],
58+
env->gpr[5],
59+
0, 0);
60+
if (ret == -TARGET_ERESTARTSYS) {
61+
env->gpr[HEX_REG_PC] -= 4;
62+
} else if (ret != -TARGET_QEMU_ESIGRETURN) {
63+
env->gpr[0] = ret;
64+
}
65+
break;
66+
case HEX_EXCP_FETCH_NO_UPAGE:
67+
case HEX_EXCP_PRIV_NO_UREAD:
68+
case HEX_EXCP_PRIV_NO_UWRITE:
69+
signum = TARGET_SIGSEGV;
70+
sigcode = TARGET_SEGV_MAPERR;
71+
break;
72+
case EXCP_ATOMIC:
73+
cpu_exec_step_atomic(cs);
74+
break;
75+
default:
76+
EXCP_DUMP(env, "\nqemu: unhandled CPU exception %#x - aborting\n",
77+
trapnr);
78+
exit(EXIT_FAILURE);
79+
}
80+
81+
if (signum) {
82+
target_siginfo_t info = {
83+
.si_signo = signum,
84+
.si_errno = 0,
85+
.si_code = sigcode,
86+
._sifields._sigfault._addr = sigaddr
87+
};
88+
queue_signal(env, info.si_signo, QEMU_SI_KILL, &info);
89+
}
90+
91+
process_pending_signals(env);
92+
}
93+
}
94+
95+
void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs)
96+
{
97+
env->gpr[HEX_REG_PC] = regs->sepc;
98+
env->gpr[HEX_REG_SP] = regs->sp;
99+
env->gpr[HEX_REG_USR] = 0x56000;
100+
}

0 commit comments

Comments
 (0)