hexagon system emulation v2, part 2/3
v2 cover hexagon system emulation v2, part 2/3
As with part 1, several issues have been addressed with v2 but some remain.
* From "Implement modify SSR": HVX context management is moved out of this series (it is no longer present in any of part 1, 2, 3). It can be revisited after these land.
Issues remaining, to be considered for v3:
* "Implement wait helper" - move hexagon_wait_thread() to op_helper.c?
* "Implement arch_{s, g}et_{thread, system}_reg()" - remove arch_[sg]et_system_reg() entirely?
* "Implement setprio, resched" - use ~0 for BESTWAIT_PRIO
* "Add exec-start-addr prop" - don't use ULL for UINT32
* "Define system, guest reg names" - fix last five reg names
* "Add TLB, k0 {un,}lock" - revisit design with suggestion from Richard
* "Define gen_precise_exception" - reword commit subject
Brian Cain (37):
target/hexagon: Implement ciad helper
target/hexagon: Implement {c,}swi helpers target/hexagon: Implement iassign{r,w} helpers target/hexagon: Implement start/stop helpers, soft reset target/hexagon: Implement modify SSR
target/hexagon: Implement {g,s}etimask helpers target/hexagon: Implement wait helper
target/hexagon: Implement get_exe_mode() target/hexagon: Implement arch_get_system_reg() target/hexagon: Implement arch_{s,g}et_{thread,system}_reg() target/hexagon: Add representation to count cycles target/hexagon: Add implementation of cycle counters target/hexagon: Implement modify_syscfg() target/hexagon: Implement hex_tlb_entry_get_perm() target/hexagon: Implement hex_tlb_lookup_by_asid() target/hexagon: Implement software interrupt target/hexagon: Implement exec_interrupt, set_irq target/hexagon: Implement hexagon_tlb_fill() target/hexagon: Implement siad inst
target/hexagon: Implement hexagon_resume_threads() target/hexagon: Implement setprio, resched target/hexagon: Add sysemu_ops, cpu_get_phys_page_debug() target/hexagon: Add exec-start-addr prop target/hexagon: extend hexagon_cpu_mmu_index() for sysemu target/hexagon: Decode trap1, rte as COF target/hexagon: Implement hexagon_find_last_irq() target/hexagon: Implement modify_ssr, resched, pending_interrupt target/hexagon: Add pkt_ends_tb to translation target/hexagon: Add next_PC, {s,g}reg writes target/hexagon: Add implicit sysreg writes target/hexagon: Define system, guest reg names target/hexagon: initialize sys/guest reg TCGvs target/hexagon: Add TLB, k0 {un,}lock
target/hexagon: Define gen_precise_exception() target/hexagon: Add TCG overrides for transfer insts target/hexagon: Add support for loadw_phys target/hexagon: Add pcycle setting functionality
Matheus Tavares Bernardino (2):
target/hexagon: add simple cpu_exec_reset and pointer_wrap target/hexagon: Add guest reg reading functionality
target/hexagon/cpu.h | 13 +- target/hexagon/cpu_helper.h | 21 +- target/hexagon/gen_tcg.h | 7 - target/hexagon/gen_tcg_sys.h | 25 ++ target/hexagon/helper.h | 7 +- target/hexagon/hexswi.h | 17 + target/hexagon/internal.h | 2 + target/hexagon/sys_macros.h | 8 +- target/hexagon/translate.h | 5 + target/hexagon/reg_fields_def.h.inc | 11 + linux-user/hexagon/cpu_loop.c | 7 + target/hexagon/cpu.c | 349 ++++++++++++++++++++- target/hexagon/cpu_helper.c | 358 ++++++++++++++++++++- target/hexagon/decode.c | 14 + target/hexagon/genptr.c | 7 +- target/hexagon/hex_mmu.c | 84 ++++- target/hexagon/hexswi.c | 256 +++++++++++++++ target/hexagon/machine.c | 2 +- target/hexagon/op_helper.c | 430 ++++++++++++++++++++++++-- target/hexagon/translate.c | 304 ++++++++++++++++-- target/hexagon/hex_common.py | 3 + target/hexagon/imported/encode_pp.def | 1 + target/hexagon/imported/ldst.idef | 3 + 23 files changed, 1848 insertions(+), 86 deletions(-) create mode 100644 target/hexagon/hexswi.h create mode 100644 target/hexagon/hexswi.c
Signature · 1 line
2.34.1
PATCH v2 1/39 target/hexagon: Implement ciad helper
From: Brian Cain <[email protected]>
ciad is the clear interrupt auto disable instruction.
--- target/hexagon/op_helper.c | 45 +++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 6 deletions(-)
target/hexagon/op_helper.c +39 -6
@@ -34,6 +34,12 @@#include "op_helper.h" #include "cpu_helper.h" #include "translate.h" +#ifndef CONFIG_USER_ONLY +#include "hw/hexagon/hexagon_globalreg.h" +#include "hex_mmu.h" +#include "hw/intc/l2vic.h" +#include "hex_interrupts.h" +#endif #define SF_BIAS 127#define SF_MANTBITS 23
@@ -1338,9 +1344,41 @@ void HELPER(vwhist128qm)(CPUHexagonState *env, int32_t uiV) }#ifndef CONFIG_USER_ONLY +static void hexagon_set_vid (CPUHexagonState *env,uint32_t offset,uint32_t val) +{ +g_assert ((offset ==L2VIC_VID_0 ) || (offset ==L2VIC_VID_1 )); +CPUState *cs =env_cpu (env); +HexagonCPU *cpu =HEXAGON_CPU (cs); +const hwaddr pend_mem = cpu->l2vic_base_addr + offset; +cpu_physical_memory_write (pend_mem, &val,sizeof (val)); +} + +static void hexagon_clear_last_irq (CPUHexagonState *env,uint32_t offset) +{ +hexagon_set_vid (env, offset,L2VIC_CIAD_INSTRUCTION ); +} + +/* +* ciad - clear interrupt auto disable +* - When taking an interrupt the hardware will set ipend.iad to +* prevent another thread from servicing the interrupt. At the completion +* of service software uses ciad to clear the bit indicating the +* interrupt can be accepted again. +* - ciad also handshakes with the l2vic allowing a new vid on the vector +* port. +*/ void HELPER (ciad )(CPUHexagonState *env,uint32_t mask) { -g_assert_not_reached (); +uint32_t ipendad; +uint32_t iad; + +BQL_LOCK_GUARD (); + ipendad =READ_SREG (HEX_SREG_IPENDAD ); + iad =fGET_FIELD (ipendad,IPENDAD_IAD ); +fSET_FIELD (ipendad,IPENDAD_IAD , iad & ~(mask)); +arch_set_system_reg (env,HEX_SREG_IPENDAD , ipendad); +hexagon_clear_last_irq (env,L2VIC_VID_0 ); +hex_interrupt_update (env); }void HELPER (siad )(CPUHexagonState *env,uint32_t mask)
@@ -1416,11 +1454,6 @@ static void modify_syscfg(CPUHexagonState *env, uint32_t val)g_assert_not_reached (); } -static void hexagon_set_vid (CPUHexagonState *env,uint32_t offset,int val) -{ -g_assert_not_reached (); -} -static uint32_t hexagon_find_last_irq (CPUHexagonState *env,uint32_t vid) {g_assert_not_reached ();
Signature · 1 line
2.34.1
PATCH v2 2/39 target/hexagon: Implement {c,}swi helpers
In reply to Brian CainFrom: Brian Cain <[email protected]>
{c,}swi are the "software interrupt"/"Cancel pending interrupts" instructions.
--- target/hexagon/op_helper.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
target/hexagon/op_helper.c +5 -2
@@ -23,6 +23,7 @@#include "exec/helper-proto.h" #include "fpu/softfloat.h" #include "cpu.h" +#include "exec/cpu-interrupt.h" #include "internal.h" #include "macros.h" #include "sys_macros.h"
@@ -1388,12 +1389,14 @@ void HELPER(siad)(CPUHexagonState *env, uint32_t mask)void HELPER (swi )(CPUHexagonState *env,uint32_t mask) { -g_assert_not_reached (); +BQL_LOCK_GUARD (); +hex_raise_interrupts (env, mask,CPU_INTERRUPT_SWI ); }void HELPER (cswi )(CPUHexagonState *env,uint32_t mask) { -g_assert_not_reached (); +BQL_LOCK_GUARD (); +hex_clear_interrupts (env, mask,CPU_INTERRUPT_SWI ); }void HELPER (iassignw )(CPUHexagonState *env,uint32_t src)
Signature · 1 line
2.34.1
PATCH v2 3/39 target/hexagon: Implement iassign{r,w} helpers
In reply to Brian CainFrom: Brian Cain <[email protected]>
iassign{r,w} are the "Interrupt to thread assignment {read,write}" instructions.
--- target/hexagon/op_helper.c | 48 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-)
target/hexagon/op_helper.c +46 -2
@@ -1401,12 +1401,56 @@ void HELPER(cswi)(CPUHexagonState *env, uint32_t mask)void HELPER (iassignw )(CPUHexagonState *env,uint32_t src) { -g_assert_not_reached (); +uint32_t modectl; +uint32_t thread_enabled_mask; +CPUState *cpu; + +BQL_LOCK_GUARD (); + modectl =arch_get_system_reg (env,HEX_SREG_MODECTL ); + thread_enabled_mask =GET_FIELD (MODECTL_E , modectl); + +CPU_FOREACH (cpu) { +CPUHexagonState *thread_env = &(HEXAGON_CPU (cpu)->env); +uint32_t thread_id_mask =0x1 << thread_env->threadId; +if (thread_enabled_mask & thread_id_mask) { +uint32_t imask =arch_get_system_reg (thread_env,HEX_SREG_IMASK ); +uint32_t intbitpos = (src >>16 ) &0xF ; +uint32_t val = (src >> thread_env->threadId) &0x1 ; + imask =deposit32 (imask, intbitpos,1 , val); +arch_set_system_reg (thread_env,HEX_SREG_IMASK , imask); + +qemu_log_mask (CPU_LOG_INT ,"%s: thread " TARGET_FMT_ld +", new imask 0x%" PRIx32"\n" , __func__, + thread_env->threadId, imask); + } + } +hex_interrupt_update (env); }uint32_t HELPER (iassignr )(CPUHexagonState *env,uint32_t src) { -g_assert_not_reached (); +uint32_t modectl; +uint32_t thread_enabled_mask; +uint32_t intbitpos; +uint32_t dest_reg; +CPUState *cpu; + +BQL_LOCK_GUARD (); + modectl =arch_get_system_reg (env,HEX_SREG_MODECTL ); + thread_enabled_mask =GET_FIELD (MODECTL_E , modectl); +/* src fields are in same position as modectl, but mean different things */ + intbitpos =GET_FIELD (MODECTL_W , src); + dest_reg =0 ; +CPU_FOREACH (cpu) { +CPUHexagonState *thread_env = &(HEXAGON_CPU (cpu)->env); +uint32_t thread_id_mask =0x1 << thread_env->threadId; +if (thread_enabled_mask & thread_id_mask) { +uint32_t imask =arch_get_system_reg (thread_env,HEX_SREG_IMASK ); + dest_reg |= ((imask >> intbitpos) &0x1 ) << thread_env->threadId; + } + } + +return dest_reg; }void HELPER (start )(CPUHexagonState *env,uint32_t imask)
Signature · 1 line
2.34.1
PATCH v2 4/39 target/hexagon: Implement start/stop helpers, soft reset
In reply to Brian CainFrom: Brian Cain <[email protected]>
--- target/hexagon/cpu.h | 1 + target/hexagon/cpu_helper.h | 3 ++ target/hexagon/cpu.c | 18 ++++++- target/hexagon/cpu_helper.c | 94 +++++++++++++++++++++++++++++++++++++ target/hexagon/op_helper.c | 4 +- 5 files changed, 117 insertions(+), 3 deletions(-)
target/hexagon/cpu.h +1 -0
@@ -209,6 +209,7 @@ G_NORETURN void hexagon_raise_exception_err(CPUHexagonState *env,uint32_t hexagon_greg_read (CPUHexagonState *env,uint32_t reg);uint32_t hexagon_sreg_read (CPUHexagonState *env,uint32_t reg);void hexagon_gdb_sreg_write (CPUHexagonState *env,uint32_t reg,uint32_t val); +void hexagon_cpu_soft_reset (CPUHexagonState *env);#endif typedef HexagonCPU ArchCPU ;
target/hexagon/cpu_helper.h +3 -0
@@ -17,6 +17,9 @@ void hexagon_set_sys_pcycle_count_high(CPUHexagonState *env, uint32_t);void hexagon_modify_ssr (CPUHexagonState *env,uint32_t new,uint32_t old);int get_exe_mode (CPUHexagonState *env);void clear_wait_mode (CPUHexagonState *env); +void hexagon_ssr_set_cause (CPUHexagonState *env,uint32_t cause); +void hexagon_start_threads (CPUHexagonState *env,uint32_t mask); +void hexagon_stop_thread (CPUHexagonState *env);static inline void arch_set_thread_reg (CPUHexagonState *env,uint32_t reg,uint32_t val)
target/hexagon/cpu.c +17 -1
@@ -32,6 +32,7 @@#ifndef CONFIG_USER_ONLY #include "sys_macros.h" #include "accel/tcg/cpu-ldst.h" +#include "qemu/main-loop.h" #endif static void hexagon_v66_cpu_init (Object *obj) { }
@@ -312,9 +313,23 @@ static void mmu_reset(CPUHexagonState *env) memset(env->hex_tlb, 0, sizeof(*env->hex_tlb)); } } + +void hexagon_cpu_soft_reset (CPUHexagonState *env) +{ +BQL_LOCK_GUARD (); +arch_set_system_reg (env,HEX_SREG_SSR ,0 ); +hexagon_ssr_set_cause (env,HEX_CAUSE_RESET ); + +HexagonCPU *cpu =env_archcpu (env); +if (cpu->globalregs) { +target_ulong evb =arch_get_system_reg (env,HEX_SREG_EVB ); +arch_set_thread_reg (env,HEX_REG_PC , evb); + }else { +arch_set_thread_reg (env,HEX_REG_PC , cpu->boot_addr); + } +}#endif -static void hexagon_cpu_reset_hold (Object *obj,ResetType type) {CPUState *cs =CPU (obj);
@@ -337,6 +352,7 @@ static void hexagon_cpu_reset_hold(Object *obj, ResetType type)mmu_reset (env);arch_set_system_reg (env,HEX_SREG_HTID , cs->cpu_index); +hexagon_cpu_soft_reset (env);memset (env->t_sreg,0 ,sizeof (target_ulong) *NUM_SREGS );memset (env->greg,0 ,sizeof (target_ulong) *NUM_GREGS ); env->threadId = cs->cpu_index;
target/hexagon/cpu_helper.c +94 -0
102 lines not on this page · raw message
target/hexagon/op_helper.c +2 -2
@@ -1455,12 +1455,12 @@ uint32_t HELPER(iassignr)(CPUHexagonState *env, uint32_t src)void HELPER (start )(CPUHexagonState *env,uint32_t imask) { -g_assert_not_reached (); +hexagon_start_threads (env, imask); }void HELPER (stop )(CPUHexagonState *env) { -g_assert_not_reached (); +hexagon_stop_thread (env); }void HELPER (wait )(CPUHexagonState *env,target_ulong PC )
Signature · 1 line
2.34.1
PATCH v2 5/39 target/hexagon: Implement modify SSR
In reply to Brian CainFrom: Brian Cain <[email protected]>
The per-vCPU System Status Register controls many modal behaviors of the system architecture. When the SSR is updated, we trigger the necessary effects for interrupts, privilege/MMU, and HVX context mapping.
--- target/hexagon/cpu_helper.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-)
target/hexagon/cpu_helper.c +32 -1
@@ -14,6 +14,9 @@#else #include "hw/boards.h" #include "hw/hexagon/hexagon.h" +#include "hw/hexagon/hexagon_globalreg.h" +#include "hex_interrupts.h" +#include "hex_mmu.h" #endif #include "exec/cpu-interrupt.h" #include "exec/target_page.h"
@@ -73,7 +76,35 @@ void hexagon_set_sys_pcycle_count(CPUHexagonState *env, uint64_t cycles)void hexagon_modify_ssr (CPUHexagonState *env,uint32_t new,uint32_t old) { -g_assert_not_reached (); +g_assert (bql_locked ()); + +bool old_EX =GET_SSR_FIELD (SSR_EX , old); +bool old_UM =GET_SSR_FIELD (SSR_UM , old); +bool old_GM =GET_SSR_FIELD (SSR_GM , old); +bool old_IE =GET_SSR_FIELD (SSR_IE , old); +bool new_EX =GET_SSR_FIELD (SSR_EX , new); +bool new_UM =GET_SSR_FIELD (SSR_UM , new); +bool new_GM =GET_SSR_FIELD (SSR_GM , new); +bool new_IE =GET_SSR_FIELD (SSR_IE , new); + +if ((old_EX != new_EX) || + (old_UM != new_UM) || + (old_GM != new_GM)) { +hex_mmu_mode_change (env); + } + +uint8_t old_asid =GET_SSR_FIELD (SSR_ASID , old); +uint8_t new_asid =GET_SSR_FIELD (SSR_ASID , new); +if (new_asid != old_asid) { +CPUState *cs =env_cpu (env); +tlb_flush (cs); + } + +/* See if the interrupts have been enabled or we have exited EX mode */ +if ((new_IE && !old_IE) || + (!new_EX && old_EX)) { +hex_interrupt_update (env); + } }void clear_wait_mode (CPUHexagonState *env)
Signature · 1 line
2.34.1
PATCH v2 6/39 target/hexagon: Implement {g,s}etimask helpers
In reply to Brian CainFrom: Brian Cain <[email protected]>
--- target/hexagon/op_helper.c | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-)
target/hexagon/op_helper.c +31 -2
@@ -1475,12 +1475,41 @@ void HELPER(resume)(CPUHexagonState *env, uint32_t mask)uint32_t HELPER (getimask )(CPUHexagonState *env,uint32_t tid) { -g_assert_not_reached (); +CPUState *cs; +CPU_FOREACH (cs) { +HexagonCPU *found_cpu =HEXAGON_CPU (cs); +CPUHexagonState *found_env = &found_cpu->env; +if (found_env->threadId == tid) { +target_ulong imask =arch_get_system_reg (found_env,HEX_SREG_IMASK ); +qemu_log_mask (CPU_LOG_INT ,"%s: tid %d imask = 0x%x\n" , + __func__, env->threadId, + (unsigned )GET_FIELD (IMASK_MASK , imask)); +return GET_FIELD (IMASK_MASK , imask); + } + } +return 0 ; }void HELPER (setimask )(CPUHexagonState *env,uint32_t pred,uint32_t imask) { -g_assert_not_reached (); +CPUState *cs; + +BQL_LOCK_GUARD (); +CPU_FOREACH (cs) { +HexagonCPU *found_cpu =HEXAGON_CPU (cs); +CPUHexagonState *found_env = &found_cpu->env; + +if (pred == found_env->threadId) { +SET_SYSTEM_FIELD (found_env,HEX_SREG_IMASK ,IMASK_MASK , imask); +qemu_log_mask (CPU_LOG_INT ,"%s: tid %d imask 0x%x\n" , + __func__, found_env->threadId, imask); +hex_interrupt_update (env); +return ; + } + } +qemu_log_mask (LOG_GUEST_ERROR , +"setimask used with an invalid predicate near PC: 0x%x\n" , + env->next_PC); } static bool handle_pmu_sreg_write(CPUHexagonState *env, uint32_t reg,
Signature · 1 line
2.34.1
PATCH v2 7/39 target/hexagon: Implement wait helper
In reply to Brian CainFrom: Brian Cain <[email protected]>
--- target/hexagon/cpu_helper.h | 1 + target/hexagon/op_helper.c | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-)
target/hexagon/cpu_helper.h +1 -0
@@ -20,6 +20,7 @@ void clear_wait_mode(CPUHexagonState *env);void hexagon_ssr_set_cause (CPUHexagonState *env,uint32_t cause);void hexagon_start_threads (CPUHexagonState *env,uint32_t mask);void hexagon_stop_thread (CPUHexagonState *env); +void hexagon_wait_thread (CPUHexagonState *env,target_ulong PC );static inline void arch_set_thread_reg (CPUHexagonState *env,uint32_t reg,uint32_t val)
target/hexagon/op_helper.c +5 -1
@@ -1465,7 +1465,11 @@ void HELPER(stop)(CPUHexagonState *env)void HELPER (wait )(CPUHexagonState *env,target_ulong PC ) { -g_assert_not_reached (); +BQL_LOCK_GUARD (); + +if (!fIN_DEBUG_MODE (env->threadId)) { +hexagon_wait_thread (env,PC ); + } }void HELPER (resume )(CPUHexagonState *env,uint32_t mask)
Signature · 1 line
2.34.1
PATCH v2 8/39 target/hexagon: Implement get_exe_mode()
In reply to Brian CainFrom: Brian Cain <[email protected]>
--- target/hexagon/reg_fields_def.h.inc | 11 +++++++++++ target/hexagon/cpu_helper.c | 23 +++++++++++++++++++++++ 2 files changed, 34 insertions(+)
target/hexagon/reg_fields_def.h.inc +11 -0
@@ -135,3 +135,14 @@ DEF_REG_FIELD(CCR_GRE, 27, 1) DEF_REG_FIELD(CCR_VV1, 29, 1) DEF_REG_FIELD(CCR_VV2, 30, 1) DEF_REG_FIELD(CCR_VV3, 31, 1) + +/* ISDB ST fields */ +DEF_REG_FIELD(ISDBST_WAITRUN, 24, 8) +DEF_REG_FIELD(ISDBST_ONOFF, 16, 8) +DEF_REG_FIELD(ISDBST_DEBUGMODE, 8, 8) +DEF_REG_FIELD(ISDBST_STUFFSTATUS, 5, 1) +DEF_REG_FIELD(ISDBST_CMDSTATUS, 4, 1) +DEF_REG_FIELD(ISDBST_PROCMODE, 3, 1) +DEF_REG_FIELD(ISDBST_MBXINSTATUS, 2, 1) +DEF_REG_FIELD(ISDBST_MBXOUTSTATUS, 1, 1) +DEF_REG_FIELD(ISDBST_READY, 0, 1)
target/hexagon/cpu_helper.c +23 -0
@@ -135,6 +135,29 @@ void hexagon_ssr_set_cause(CPUHexagonState *env, uint32_t cause)int get_exe_mode (CPUHexagonState *env) { +g_assert (bql_locked ()); + +target_ulong modectl =arch_get_system_reg (env,HEX_SREG_MODECTL ); +uint32_t thread_enabled_mask =GET_FIELD (MODECTL_E , modectl); +bool E_bit = thread_enabled_mask & (0x1 << env->threadId); +uint32_t thread_wait_mask =GET_FIELD (MODECTL_W , modectl); +bool W_bit = thread_wait_mask & (0x1 << env->threadId); +target_ulong isdbst =arch_get_system_reg (env,HEX_SREG_ISDBST ); +uint32_t debugmode =GET_FIELD (ISDBST_DEBUGMODE , isdbst); +bool D_bit = debugmode & (0x1 << env->threadId); + +if (!D_bit && !W_bit && !E_bit) { +return HEX_EXE_MODE_OFF ; + } +if (!D_bit && !W_bit && E_bit) { +return HEX_EXE_MODE_RUN ; + } +if (!D_bit && W_bit && E_bit) { +return HEX_EXE_MODE_WAIT ; + } +if (D_bit && !W_bit && E_bit) { +return HEX_EXE_MODE_DEBUG ; + }g_assert_not_reached (); }
Signature · 1 line
2.34.1
PATCH v2 9/39 target/hexagon: Implement arch_get_system_reg()
In reply to Brian CainFrom: Brian Cain <[email protected]>
--- target/hexagon/cpu_helper.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-)
target/hexagon/cpu_helper.c +32 -1
@@ -39,7 +39,38 @@ uint32_t hexagon_get_pmu_counter(CPUHexagonState *cur_env, int index)uint32_t arch_get_system_reg (CPUHexagonState *env,uint32_t reg) { -g_assert_not_reached (); +if (reg ==HEX_SREG_PCYCLELO ) { +return hexagon_get_sys_pcycle_count_low (env); + }else if (reg ==HEX_SREG_PCYCLEHI ) { +return hexagon_get_sys_pcycle_count_high (env); + } + +g_assert (reg <NUM_SREGS ); +if (reg <HEX_SREG_GLB_START ) { +return env->t_sreg[reg]; + }else { +#ifndef CONFIG_USER_ONLY +HexagonCPU *cpu =env_archcpu (env); +return cpu->globalregs ?hexagon_globalreg_read (cpu, reg) :0 ; +#else +return 0 ; +#endif + } +} + +void arch_set_system_reg (CPUHexagonState *env,uint32_t reg,uint32_t val) +{ +g_assert (reg <NUM_SREGS ); +if (reg <HEX_SREG_GLB_START ) { + env->t_sreg[reg] = val; + }else { +#ifndef CONFIG_USER_ONLY +HexagonCPU *cpu =env_archcpu (env); +if (cpu->globalregs) { +hexagon_globalreg_write (cpu, reg, val); + } +#endif + } }uint64_t hexagon_get_sys_pcycle_count (CPUHexagonState *env)
Signature · 1 line
2.34.1
PATCH v2 10/39 target/hexagon: Implement arch_{s, g}et_{thread, system}_reg()
In reply to Brian CainFrom: Brian Cain <[email protected]>
--- target/hexagon/cpu_helper.h | 15 ++++++++------- target/hexagon/cpu_helper.c | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 7 deletions(-)
target/hexagon/cpu_helper.h +8 -7
@@ -26,20 +26,21 @@ static inline void arch_set_thread_reg(CPUHexagonState *env, uint32_t reg, uint32_t val) {g_assert (reg <TOTAL_PER_THREAD_REGS ); -g_assert_not_reached (); + env->gpr[reg] = val; }static inline uint32_t arch_get_thread_reg (CPUHexagonState *env,uint32_t reg) {g_assert (reg <TOTAL_PER_THREAD_REGS ); -g_assert_not_reached (); +return env->gpr[reg]; } -static inline void arch_set_system_reg (CPUHexagonState *env,uint32_t reg, -uint32_t val) -{ -g_assert_not_reached (); -} +#ifndef CONFIG_USER_ONLY +void arch_set_system_reg (CPUHexagonState *env,uint32_t reg, +uint32_t val); +void arch_set_system_reg_masked (CPUHexagonState *env,uint32_t reg, +uint32_t val); +#endif uint32_t arch_get_system_reg (CPUHexagonState *env,uint32_t reg);
target/hexagon/cpu_helper.c +16 -0
@@ -73,6 +73,22 @@ void arch_set_system_reg(CPUHexagonState *env, uint32_t reg, uint32_t val) } } +void arch_set_system_reg_masked (CPUHexagonState *env,uint32_t reg, +uint32_t val) +{ +g_assert (reg <NUM_SREGS ); +if (reg <HEX_SREG_GLB_START ) { + env->t_sreg[reg] = val; + }else { +#ifndef CONFIG_USER_ONLY +HexagonCPU *cpu =env_archcpu (env); +if (cpu->globalregs) { +hexagon_globalreg_write_masked (cpu, reg, val); + } +#endif + } +} +uint64_t hexagon_get_sys_pcycle_count (CPUHexagonState *env) {g_assert_not_reached ();
Signature · 1 line
2.34.1
PATCH v2 11/39 target/hexagon: Add representation to count cycles
In reply to Brian CainFrom: Brian Cain <[email protected]>
The PCYCLE register can be enabled to indicate accumulated clock cycles.
--- target/hexagon/cpu.h | 2 +- target/hexagon/machine.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
target/hexagon/cpu.h +1 -1
@@ -128,7 +128,7 @@ typedef struct CPUArchState {target_ulong stack_start;uint8_t slot_cancelled; - +uint64_t t_cycle_count;#ifndef CONFIG_USER_ONLY /* Some system registers are per thread and some are global. */ target_ulong t_sreg[NUM_SREGS ];
target/hexagon/machine.c +1 -1
@@ -35,7 +35,6 @@ const VMStateInfo vmstate_info_hex_tlb_ptr = { .put = put_hex_tlb_ptr, }; -const VMStateDescription vmstate_hexagon_cpu = { .name ="cpu" , .version_id =0 ,
@@ -56,6 +55,7 @@ const VMStateDescription vmstate_hexagon_cpu = {VMSTATE_UINTTL (env.wait_next_pc, HexagonCPU),VMSTATE_POINTER (env.hex_tlb, HexagonCPU,0 , vmstate_info_hex_tlb_ptr, CPUHexagonTLBContext *), +VMSTATE_UINT64 (env.t_cycle_count, HexagonCPU),VMSTATE_END_OF_LIST () },
Signature · 1 line
2.34.1
PATCH v2 12/39 target/hexagon: Add implementation of cycle counters
In reply to Brian CainFrom: Brian Cain <[email protected]>
The PCYCLE register is available in system mode, but only increments when the SYSCFG.PCYCLEEN field is set.
The UPCYCLE register is available in user mode and we model it unconditionally in linux-user emulation, as if the system had enabled PCYCCLEEN.
For now, the model is very crudely counting the sum of instructions executed among vCPUs, regardless of how the instructions were actually scheduled. This is sufficient for demonstrating a rough level of activity but will be particularly misleading for benchmarks and performance tuning. We may decide to revisit this model in order to give more a bit more fidelity, though without a cache model it would still be very far from accurate.
--- target/hexagon/cpu.h | 3 +++ target/hexagon/translate.h | 2 ++ target/hexagon/cpu.c | 11 +++++++++++ target/hexagon/cpu_helper.c | 33 +++++++++++++++++++++++++++++---- target/hexagon/translate.c | 27 +++++++++++++++++++++++++++ 5 files changed, 72 insertions(+), 4 deletions(-)
target/hexagon/cpu.h +3 -0
@@ -28,6 +28,7 @@#include "cpu-qom.h" #include "exec/cpu-common.h" #include "exec/cpu-defs.h" +#include "exec/cpu-common.h" #include "hex_regs.h" #include "mmvec/mmvec.h" #include "hw/registerfields.h"
@@ -37,6 +38,7 @@#endif #ifndef CONFIG_USER_ONLY +#include "reg_fields.h" typedef struct CPUHexagonTLBContext CPUHexagonTLBContext ;#endif
@@ -200,6 +202,7 @@ struct ArchCPU { FIELD(TB_FLAGS, IS_TIGHT_LOOP, 0, 1) FIELD(TB_FLAGS, MMU_INDEX, 1, 3) +FIELD(TB_FLAGS, PCYCLE_ENABLED, 4, 1) G_NORETURN void hexagon_raise_exception_err(CPUHexagonState *env, uint32_t exception,
target/hexagon/translate.h +2 -0
@@ -83,6 +83,8 @@ typedef struct DisasContext {TCGv new_pred_value[NUM_PREGS ];TCGv branch_taken;TCGv dczero_addr; +bool pcycle_enabled; +uint32_t num_cycles; } DisasContext;bool is_gather_store_insn (DisasContext *ctx);
target/hexagon/cpu.c +11 -0
@@ -281,9 +281,20 @@ static TCGTBCPUState hexagon_get_tb_cpu_state(CPUState *cs) }#ifndef CONFIG_USER_ONLY +target_ulong syscfg =arch_get_system_reg (env,HEX_SREG_SYSCFG ); + +bool pcycle_enabled =extract32 (syscfg, + reg_field_info[SYSCFG_PCYCLEEN ].offset, + reg_field_info[SYSCFG_PCYCLEEN ].width); + hex_flags =FIELD_DP32 (hex_flags,TB_FLAGS ,MMU_INDEX ,cpu_mmu_index (env_cpu (env), false)); + +if (pcycle_enabled) { + hex_flags =FIELD_DP32 (hex_flags,TB_FLAGS ,PCYCLE_ENABLED ,1 ); + }#else + hex_flags =FIELD_DP32 (hex_flags,TB_FLAGS ,PCYCLE_ENABLED , true); hex_flags =FIELD_DP32 (hex_flags,TB_FLAGS ,MMU_INDEX ,MMU_USER_IDX );#endif
target/hexagon/cpu_helper.c +29 -4
@@ -91,17 +91,30 @@ void arch_set_system_reg_masked(CPUHexagonState *env, uint32_t reg,uint64_t hexagon_get_sys_pcycle_count (CPUHexagonState *env) { -g_assert_not_reached (); +BQL_LOCK_GUARD (); +uint64_t cycles =0 ; +CPUState *cs; +CPU_FOREACH (cs) { +CPUHexagonState *thread_env =cpu_env (cs); + cycles += thread_env->t_cycle_count; + } +#ifndef CONFIG_USER_ONLY +HexagonCPU *cpu =env_archcpu (env); +return (cpu->globalregs ?hexagon_globalreg_get_pcycle_base (cpu) :0 ) + + cycles; +#else +return cycles; +#endif }uint32_t hexagon_get_sys_pcycle_count_high (CPUHexagonState *env) { -g_assert_not_reached (); +return hexagon_get_sys_pcycle_count (env) >>32 ; }uint32_t hexagon_get_sys_pcycle_count_low (CPUHexagonState *env) { -g_assert_not_reached (); +return extract64 (hexagon_get_sys_pcycle_count (env),0 ,32 ); } void hexagon_set_sys_pcycle_count_high(CPUHexagonState *env,
@@ -118,7 +131,19 @@ void hexagon_set_sys_pcycle_count_low(CPUHexagonState *env,void hexagon_set_sys_pcycle_count (CPUHexagonState *env,uint64_t cycles) { -g_assert_not_reached (); +BQL_LOCK_GUARD (); +#ifndef CONFIG_USER_ONLY +HexagonCPU *cpu =env_archcpu (env); +if (cpu->globalregs) { +hexagon_globalreg_set_pcycle_base (cpu, cycles); + } +#endif + +CPUState *cs; +CPU_FOREACH (cs) { +CPUHexagonState *thread_env =cpu_env (cs); + thread_env->t_cycle_count =0 ; + } }void hexagon_modify_ssr (CPUHexagonState *env,uint32_t new,uint32_t old)
target/hexagon/translate.c +27 -0
@@ -57,6 +57,7 @@ TCGv_i64 hex_store_val64[STORES_MAX];TCGv hex_llsc_addr;TCGv hex_llsc_val;TCGv_i64 hex_llsc_val_i64; +TCGv_i64 hex_cycle_count;TCGv hex_vstore_addr[VSTORES_MAX ];TCGv hex_vstore_size[VSTORES_MAX ];TCGv hex_vstore_pending[VSTORES_MAX ];
@@ -124,6 +125,22 @@ static void gen_exception_raw(int excp)gen_helper_raise_exception (tcg_env,tcg_constant_i32 (excp)); } +#ifndef CONFIG_USER_ONLY +static inline void gen_precise_exception (int excp,target_ulong PC ) +{ +tcg_gen_movi_tl (hex_cause_code, excp); +gen_exception (HEX_EVENT_PRECISE ,PC ); +} + +static inline void gen_pcycle_counters (DisasContext *ctx) +{ +if (ctx->pcycle_enabled) { +tcg_gen_addi_i64 (hex_cycle_count, hex_cycle_count, ctx->num_cycles); + ctx->num_cycles =0 ; + } +} +#endif +static void gen_exec_counters (DisasContext *ctx) { tcg_gen_addi_tl(hex_gpr[HEX_REG_QEMU_PKT_CNT],
@@ -132,6 +149,10 @@ static void gen_exec_counters(DisasContext *ctx) hex_gpr[HEX_REG_QEMU_INSN_CNT], ctx->num_insns);tcg_gen_addi_tl (hex_gpr[HEX_REG_QEMU_HVX_CNT ], hex_gpr[HEX_REG_QEMU_HVX_CNT ], ctx->num_hvx_insns); + +#ifndef CONFIG_USER_ONLY +gen_pcycle_counters (ctx); +#endif }static bool use_goto_tb (DisasContext *ctx,target_ulong dest)
@@ -784,6 +805,7 @@ static void gen_commit_hvx(DisasContext *ctx) } } +static const int PCYCLES_PER_PACKET =3 ;static void update_exec_counters (DisasContext *ctx) {Packet *pkt = ctx->pkt;
@@ -803,6 +825,7 @@ static void update_exec_counters(DisasContext *ctx) } ctx->num_packets++; + ctx->num_cycles +=PCYCLES_PER_PACKET ; ctx->num_insns += num_real_insns; ctx->num_hvx_insns += num_hvx_insns; }
@@ -945,11 +968,13 @@ static void hexagon_tr_init_disas_context(DisasContextBase *dcbase, ctx->mem_idx =FIELD_EX32 (hex_flags,TB_FLAGS ,MMU_INDEX ); ctx->num_packets =0 ; + ctx->num_cycles =0 ; ctx->num_insns =0 ; ctx->num_hvx_insns =0 ; ctx->branch_cond =TCG_COND_NEVER ; ctx->is_tight_loop =FIELD_EX32 (hex_flags,TB_FLAGS ,IS_TIGHT_LOOP ); ctx->short_circuit = hex_cpu->short_circuit; + ctx->pcycle_enabled =FIELD_EX32 (hex_flags,TB_FLAGS ,PCYCLE_ENABLED ); }static void hexagon_tr_tb_start (DisasContextBase *db,CPUState *cpu)
@@ -1076,6 +1101,8 @@ void hexagon_translate_init(void) offsetof(CPUHexagonState, llsc_val), "llsc_val"); hex_llsc_val_i64 =tcg_global_mem_new_i64 (tcg_env, offsetof(CPUHexagonState , llsc_val_i64),"llsc_val_i64" ); + hex_cycle_count =tcg_global_mem_new_i64 (tcg_env, + offsetof(CPUHexagonState , t_cycle_count),"t_cycle_count" );for (i =0 ; i <STORES_MAX ; i++) {snprintf (store_addr_names[i],NAME_LEN ,"store_addr_%d" , i); hex_store_addr[i] = tcg_global_mem_new(tcg_env,
Signature · 1 line
2.34.1
PATCH v2 13/39 target/hexagon: Implement modify_syscfg()
In reply to Brian CainFrom: Brian Cain <[email protected]>
--- target/hexagon/op_helper.c | 47 +++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-)
target/hexagon/op_helper.c +46 -1
@@ -1531,7 +1531,52 @@ static bool handle_pmu_sreg_write(CPUHexagonState *env, uint32_t reg,static void modify_syscfg (CPUHexagonState *env,uint32_t val) { -g_assert_not_reached (); +g_assert (bql_locked ()); + +uint32_t syscfg_read_only_mask =0x80001c00 ; +uint32_t old =arch_get_system_reg (env,HEX_SREG_SYSCFG ); +uint8_t old_en =GET_SYSCFG_FIELD (SYSCFG_PCYCLEEN , old); +uint8_t old_gie =GET_SYSCFG_FIELD (SYSCFG_GIE , old); +uint8_t new_en =GET_SYSCFG_FIELD (SYSCFG_PCYCLEEN , val); +uint8_t new_gie =GET_SYSCFG_FIELD (SYSCFG_GIE , val); +CPUState *cs; +target_ulong old_mmu_enable =GET_SYSCFG_FIELD (SYSCFG_MMUEN , old); +target_ulong new_mmu_enable = +GET_SYSCFG_FIELD (SYSCFG_MMUEN , val); + +/* clear read-only bits if they are set in the new value. */ + val &= ~syscfg_read_only_mask; +/* if read-only are currently set in syscfg keep them set. */ + val |= (old & syscfg_read_only_mask); + +arch_set_system_reg (env,HEX_SREG_SYSCFG , val); + +/* Check for change in MMU enable */ +if (new_mmu_enable && !old_mmu_enable) { +hex_mmu_on (env); + }else if (!new_mmu_enable && old_mmu_enable) { +hex_mmu_off (env); + } + +/* Changing pcycle enable from 0 to 1 resets the counters */ +if (old_en ==0 && new_en ==1 ) { +CPU_FOREACH (cs) { +cpu_env (cs)->t_cycle_count =0 ; + } + } + +/* See if global interrupts are turned on */ +if (!old_gie && new_gie) { +qemu_log_mask (CPU_LOG_INT ,"%s: global interrupts enabled\n" , __func__); +hex_interrupt_update (env); + } + +if (qemu_loglevel_mask (LOG_UNIMP )) { +int new_v2x =GET_SYSCFG_FIELD (SYSCFG_V2X , val); +if (!new_v2x) { +qemu_log ("HVX: 64 byte vector length is unsupported\n" ); + } + } }static uint32_t hexagon_find_last_irq (CPUHexagonState *env,uint32_t vid)
Signature · 1 line
2.34.1
PATCH v2 14/39 target/hexagon: Implement hex_tlb_entry_get_perm()
In reply to Brian CainFrom: Brian Cain <[email protected]>
--- linux-user/hexagon/cpu_loop.c | 7 +++++ target/hexagon/hex_mmu.c | 54 ++++++++++++++++++++++++++++++++++- 2 files changed, 60 insertions(+), 1 deletion(-)
linux-user/hexagon/cpu_loop.c +7 -0
@@ -63,6 +63,13 @@ void cpu_loop(CPUHexagonState *env)break ;case HEX_EVENT_PRECISE :switch (env->cause_code) { +case HEX_CAUSE_FETCH_NO_UPAGE : +case HEX_CAUSE_PRIV_NO_UREAD : +case HEX_CAUSE_PRIV_NO_UWRITE : +force_sig_fault (TARGET_SIGSEGV ,TARGET_SEGV_MAPERR , + env->gpr[HEX_REG_PC ]); + +break ;case HEX_CAUSE_PRIV_USER_NO_GINSN :case HEX_CAUSE_PRIV_USER_NO_SINSN :case HEX_CAUSE_INVALID_PACKET :
target/hexagon/hex_mmu.c +53 -1
60 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v2 15/39 target/hexagon: Implement hex_tlb_lookup_by_asid()
In reply to Brian CainFrom: Brian Cain <[email protected]>
--- target/hexagon/hex_mmu.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-)
target/hexagon/hex_mmu.c +28 -2
@@ -359,7 +359,32 @@ bool hex_tlb_find_match(CPUHexagonState *env, target_ulong VA,static uint32_t hex_tlb_lookup_by_asid (CPUHexagonState *env,uint32_t asid,uint32_t VA ) { -g_assert_not_reached (); +uint32_t not_found =0x80000000 ; +uint32_t idx = not_found; +int i; + +HexagonCPU *cpu =env_archcpu (env); +for (i =0 ; i < cpu->num_tlbs; i++) { +uint64_t entry = env->hex_tlb->entries[i]; +if (hex_tlb_entry_match_noperm (entry, asid,VA )) { +if (idx != not_found) { + env->cause_code =HEX_CAUSE_IMPRECISE_MULTI_TLB_MATCH ; +break ; + } + idx = i; + } + } + +if (idx == not_found) { +qemu_log_mask (CPU_LOG_MMU , +"%s: 0x%" PRIx32", 0x%08" PRIx32" => NOT FOUND\n" , + __func__, asid,VA ); + }else { +qemu_log_mask (CPU_LOG_MMU ,"%s: 0x%" PRIx32", 0x%08" PRIx32" => %d\n" , + __func__, asid,VA , idx); + } + +return idx; }/* Called from tlbp instruction */
@@ -461,7 +486,8 @@ static inline void print_thread_states(const char *str)void hex_tlb_lock (CPUHexagonState *env) { -qemu_log_mask (CPU_LOG_MMU ,"hex_tlb_lock: %d\n" , env->threadId); +qemu_log_mask (CPU_LOG_MMU ,"hex_tlb_lock: " TARGET_FMT_ld"\n" , + env->threadId);BQL_LOCK_GUARD ();g_assert ((env->tlb_lock_count ==0 ) || (env->tlb_lock_count ==1 ));
Signature · 1 line
2.34.1
PATCH v2 16/39 target/hexagon: Implement software interrupt
In reply to Brian CainFrom: Brian Cain <[email protected]>
--- target/hexagon/hexswi.h | 17 +++ target/hexagon/cpu.c | 2 + target/hexagon/hexswi.c | 256 +++++++++++++++++++++++++++++++++++++ target/hexagon/op_helper.c | 1 + 4 files changed, 276 insertions(+) create mode 100644 target/hexagon/hexswi.h create mode 100644 target/hexagon/hexswi.c
target/hexagon/hexswi.h new file +17 -0
@@ -0,0 +1,17 @@ +/* +* Copyright(c) 2025 Qualcomm Innovation Center, Inc. All Rights Reserved. +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#ifndef HEXSWI_H +#define HEXSWI_H + + +#include "cpu.h" + +void hexagon_cpu_do_interrupt (CPUState *cpu); +void register_trap_exception (CPUHexagonState *env,int type,int imm, +target_ulong PC ); + +#endif /* HEXSWI_H */
target/hexagon/cpu.c +2 -0
@@ -33,6 +33,8 @@#include "sys_macros.h" #include "accel/tcg/cpu-ldst.h" #include "qemu/main-loop.h" +#include "hex_interrupts.h" +#include "hexswi.h" #endif static void hexagon_v66_cpu_init (Object *obj) { }
target/hexagon/hexswi.c new file +256 -0
256 lines not on this page · raw message
target/hexagon/op_helper.c +1 -0
@@ -40,6 +40,7 @@#include "hex_mmu.h" #include "hw/intc/l2vic.h" #include "hex_interrupts.h" +#include "hexswi.h" #endif #define SF_BIAS 127
Signature · 1 line
2.34.1
PATCH v2 17/39 target/hexagon: Implement exec_interrupt, set_irq
In reply to Brian CainFrom: Brian Cain <[email protected]>
--- target/hexagon/cpu.h | 5 +++ target/hexagon/cpu.c | 81 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+)
target/hexagon/cpu.h +5 -0
@@ -209,6 +209,11 @@ G_NORETURN void hexagon_raise_exception_err(CPUHexagonState *env, uintptr_t pc);#ifndef CONFIG_USER_ONLY +/* +* @return true if the @a thread_env hardware thread is +* not stopped. +*/ +bool hexagon_thread_is_enabled (CPUHexagonState *thread_env);uint32_t hexagon_greg_read (CPUHexagonState *env,uint32_t reg);uint32_t hexagon_sreg_read (CPUHexagonState *env,uint32_t reg);void hexagon_gdb_sreg_write (CPUHexagonState *env,uint32_t reg,uint32_t val);
target/hexagon/cpu.c +81 -0
114 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v2 18/39 target/hexagon: add simple cpu_exec_reset and pointer_wrap
In reply to Brian CainFrom: Matheus Tavares Bernardino <[email protected]>
--- target/hexagon/cpu.c | 8 ++++++++ 1 file changed, 8 insertions(+)
target/hexagon/cpu.c +8 -0
@@ -511,6 +511,12 @@ static bool hexagon_cpu_exec_interrupt(CPUState *cs, int interrupt_request)return false; } +static vaddr hexagon_pointer_wrap (CPUState *cs,int mmu_idx, +vaddr result,vaddr base) +{ +return result; +} +#endif static const TCGCPUOps hexagon_tcg_ops = {
@@ -525,6 +531,8 @@ static const TCGCPUOps hexagon_tcg_ops = { .mmu_index = hexagon_cpu_mmu_index,#if !defined(CONFIG_USER_ONLY ) .cpu_exec_interrupt = hexagon_cpu_exec_interrupt, + .pointer_wrap = hexagon_pointer_wrap, + .cpu_exec_reset = cpu_reset,#endif /* !CONFIG_USER_ONLY */ };
Signature · 1 line
2.34.1
PATCH v2 19/39 target/hexagon: Implement hexagon_tlb_fill()
In reply to Brian CainFrom: Brian Cain <[email protected]>
--- target/hexagon/cpu.c | 134 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 133 insertions(+), 1 deletion(-)
target/hexagon/cpu.c +133 -1
@@ -37,6 +37,8 @@#include "hex_interrupts.h" #include "hexswi.h" #include "exec/cpu-interrupt.h" +#include "exec/target_page.h" +#include "hw/hexagon/hexagon_globalreg.h" #endif static void hexagon_v66_cpu_init (Object *obj) { }
@@ -490,7 +492,136 @@ static void hexagon_cpu_init(Object *obj)#endif } -#ifndef CONFIG_USER_ONLY +#if !defined(CONFIG_USER_ONLY ) +static bool get_physical_address (CPUHexagonState *env,hwaddr *phys,int *prot, +int *size,int32_t *excp,target_ulong address, +MMUAccessType access_type,int mmu_idx) + +{ +if (hexagon_cpu_mmu_enabled (env)) { +return hex_tlb_find_match (env, address, access_type, phys, prot, size, + excp, mmu_idx); + }else { + *phys = address &0xFFFFFFFF ; + *prot =PAGE_VALID |PAGE_READ |PAGE_WRITE |PAGE_EXEC ; + *size =TARGET_PAGE_SIZE ; +return true; + } +} + +/* qemu seems to only want to know about TARGET_PAGE_SIZE pages */ +static void find_qemu_subpage (vaddr *addr,hwaddr *phys,int page_size) +{ +vaddr page_start = *addr & ~((vaddr)(page_size -1 )); +vaddr offset = ((*addr - page_start) /TARGET_PAGE_SIZE ) *TARGET_PAGE_SIZE ; + *addr = page_start + offset; + *phys += offset; +} + + +#define INVALID_BADVA 0xbadabada + +static void set_badva_regs (CPUHexagonState *env,target_ulong VA ,int slot, +MMUAccessType access_type) +{ +arch_set_system_reg (env,HEX_SREG_BADVA ,VA ); + +if (access_type ==MMU_INST_FETCH || slot ==0 ) { +arch_set_system_reg (env,HEX_SREG_BADVA0 ,VA ); +arch_set_system_reg (env,HEX_SREG_BADVA1 ,INVALID_BADVA ); +SET_SSR_FIELD (env,SSR_V0 ,1 ); +SET_SSR_FIELD (env,SSR_V1 ,0 ); +SET_SSR_FIELD (env,SSR_BVS ,0 ); + }else if (slot ==1 ) { +arch_set_system_reg (env,HEX_SREG_BADVA0 ,INVALID_BADVA ); +arch_set_system_reg (env,HEX_SREG_BADVA1 ,VA ); +SET_SSR_FIELD (env,SSR_V0 ,0 ); +SET_SSR_FIELD (env,SSR_V1 ,1 ); +SET_SSR_FIELD (env,SSR_BVS ,1 ); + }else { +g_assert_not_reached (); + } +} + +static void raise_tlbmiss_exception (CPUState *cs,target_ulong VA ,int slot, +MMUAccessType access_type) +{ +CPUHexagonState *env =cpu_env (cs); + +set_badva_regs (env,VA , slot, access_type); + +switch (access_type) { +case MMU_INST_FETCH : + cs->exception_index =HEX_EVENT_TLB_MISS_X ; +if ((VA & ~TARGET_PAGE_MASK ) ==0 ) { + env->cause_code =HEX_CAUSE_TLBMISSX_CAUSE_NEXTPAGE ; + }else { + env->cause_code =HEX_CAUSE_TLBMISSX_CAUSE_NORMAL ; + } +break ; +case MMU_DATA_LOAD : + cs->exception_index =HEX_EVENT_TLB_MISS_RW ; + env->cause_code =HEX_CAUSE_TLBMISSRW_CAUSE_READ ; +break ; +case MMU_DATA_STORE : + cs->exception_index =HEX_EVENT_TLB_MISS_RW ; + env->cause_code =HEX_CAUSE_TLBMISSRW_CAUSE_WRITE ; +break ; + } +} + +static void raise_perm_exception (CPUState *cs,target_ulong VA ,int slot, +MMUAccessType access_type,int32_t excp) +{ +CPUHexagonState *env =cpu_env (cs); + +set_badva_regs (env,VA , slot, access_type); + cs->exception_index = excp; +} + +static const char *access_type_names[] = {"MMU_DATA_LOAD " ,"MMU_DATA_STORE" , +"MMU_INST_FETCH" }; + +static const char *mmu_idx_names[] = {"MMU_USER_IDX" ,"MMU_GUEST_IDX" , +"MMU_KERNEL_IDX" }; + +static bool hexagon_tlb_fill (CPUState *cs,vaddr address,int size, +MMUAccessType access_type,int mmu_idx,bool probe, +uintptr_t retaddr) +{ +CPUHexagonState *env =cpu_env (cs); +static int slot =0 /* This is always zero for now */ ; +hwaddr phys; +int prot =0 ; +int page_size =0 ; +int32_t excp =0 ; +bool ret =0 ; + +qemu_log_mask ( +CPU_LOG_MMU , +"%s: tid = 0x%x, pc = 0x%08" PRIx32", vaddr = 0x%08" VADDR_PRIx +", size = %d, %s,\tprobe = %d, %s\n" , + __func__, env->threadId, env->gpr[HEX_REG_PC ], address, size, + access_type_names[access_type], probe, mmu_idx_names[mmu_idx]); + ret =get_physical_address (env, &phys, &prot, &page_size, &excp, address, + access_type, mmu_idx); +if (ret) { +if (!excp) { +find_qemu_subpage (&address, &phys, page_size); +tlb_set_page (cs, address, phys, prot, mmu_idx,TARGET_PAGE_SIZE ); +return ret; + }else { +raise_perm_exception (cs, address, slot, access_type, excp); +do_raise_exception (env, cs->exception_index, env->gpr[HEX_REG_PC ], + retaddr); + } + } +if (probe) { +return false; + } +raise_tlbmiss_exception (cs, address, slot, access_type); +do_raise_exception (env, cs->exception_index, env->gpr[HEX_REG_PC ], retaddr); +}static bool hexagon_cpu_exec_interrupt (CPUState *cs,int interrupt_request) {
@@ -533,6 +664,7 @@ static const TCGCPUOps hexagon_tcg_ops = { .cpu_exec_interrupt = hexagon_cpu_exec_interrupt, .pointer_wrap = hexagon_pointer_wrap, .cpu_exec_reset = cpu_reset, + .tlb_fill = hexagon_tlb_fill,#endif /* !CONFIG_USER_ONLY */ };
Signature · 1 line
2.34.1
PATCH v2 20/39 target/hexagon: Implement siad inst
In reply to Brian CainFrom: Brian Cain <[email protected]>
siad is the 'Set interrupt auto disable' instruction.
--- target/hexagon/op_helper.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
target/hexagon/op_helper.c +9 -1
@@ -1385,7 +1385,15 @@ void HELPER(ciad)(CPUHexagonState *env, uint32_t mask)void HELPER (siad )(CPUHexagonState *env,uint32_t mask) { -g_assert_not_reached (); +uint32_t ipendad; +uint32_t iad; + +BQL_LOCK_GUARD (); + ipendad =READ_SREG (HEX_SREG_IPENDAD ); + iad =fGET_FIELD (ipendad,IPENDAD_IAD ); +fSET_FIELD (ipendad,IPENDAD_IAD , iad | mask); +arch_set_system_reg (env,HEX_SREG_IPENDAD , ipendad); +hex_interrupt_update (env); }void HELPER (swi )(CPUHexagonState *env,uint32_t mask)
Signature · 1 line
2.34.1
PATCH v2 21/39 target/hexagon: Implement hexagon_resume_threads()
In reply to Brian CainFrom: Brian Cain <[email protected]>
--- target/hexagon/cpu.h | 1 + target/hexagon/cpu_helper.h | 1 + target/hexagon/cpu_helper.c | 76 +++++++++++++++++++++++++++++++++++++ target/hexagon/op_helper.c | 3 +- 4 files changed, 80 insertions(+), 1 deletion(-)
target/hexagon/cpu.h +1 -0
@@ -51,6 +51,7 @@ typedef struct CPUHexagonTLBContext CPUHexagonTLBContext;#define PRED_WRITES_MAX 5/* 4 insns + endloop */ #define VSTORES_MAX 2#define MAX_TLB_ENTRIES 1024 +#define THREADS_MAX 8#define CPU_RESOLVING_TYPE TYPE_HEXAGON_CPU#ifndef CONFIG_USER_ONLY
target/hexagon/cpu_helper.h +1 -0
@@ -21,6 +21,7 @@ void hexagon_ssr_set_cause(CPUHexagonState *env, uint32_t cause);void hexagon_start_threads (CPUHexagonState *env,uint32_t mask);void hexagon_stop_thread (CPUHexagonState *env);void hexagon_wait_thread (CPUHexagonState *env,target_ulong PC ); +void hexagon_resume_threads (CPUHexagonState *env,uint32_t mask);static inline void arch_set_thread_reg (CPUHexagonState *env,uint32_t reg,uint32_t val)
target/hexagon/cpu_helper.c +76 -0
82 lines not on this page · raw message
target/hexagon/op_helper.c +2 -1
@@ -1483,7 +1483,8 @@ void HELPER(wait)(CPUHexagonState *env, target_ulong PC)void HELPER (resume )(CPUHexagonState *env,uint32_t mask) { -g_assert_not_reached (); +BQL_LOCK_GUARD (); +hexagon_resume_threads (env, mask); }uint32_t HELPER (getimask )(CPUHexagonState *env,uint32_t tid)
Signature · 1 line
2.34.1
PATCH v2 22/39 target/hexagon: Implement setprio, resched
In reply to Brian CainFrom: Brian Cain <[email protected]>
The hardware-assisted scheduler helps manage tasks on the run queue and interrupt steering.
This instruction is defined in the Qualcomm Hexagon V71 Programmer's Reference Manual -
https://docs.qualcomm.com/bundle/publicresource/80-N2040-51_REV_AB_Hexagon_V71_ProgrammerS_Reference_Manual.pdf
See §11.9.2 SYSTEM MONITOR.
--- target/hexagon/op_helper.c | 71 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 69 insertions(+), 2 deletions(-)
target/hexagon/op_helper.c +69 -2
@@ -1472,6 +1472,57 @@ void HELPER(stop)(CPUHexagonState *env)hexagon_stop_thread (env); } +static inline QEMU_ALWAYS_INLINE void resched(CPUHexagonState *env) +{ +uint32_t schedcfg; +uint32_t schedcfg_en; +int int_number; +CPUState *cs; +uint32_t lowest_th_prio =0 ;/* 0 is highest prio */ +uint32_t bestwait_reg; +uint32_t best_prio; + +BQL_LOCK_GUARD (); +qemu_log_mask (CPU_LOG_INT ,"%s: check resched\n" , __func__); + schedcfg =arch_get_system_reg (env,HEX_SREG_SCHEDCFG ); + schedcfg_en =GET_FIELD (SCHEDCFG_EN , schedcfg); + int_number =GET_FIELD (SCHEDCFG_INTNO , schedcfg); + +if (!schedcfg_en) { +return ; + } + +CPU_FOREACH (cs) { +HexagonCPU *thread =HEXAGON_CPU (cs); +CPUHexagonState *thread_env = &(thread->env); +uint32_t th_prio =GET_FIELD ( +STID_PRIO ,arch_get_system_reg (thread_env,HEX_SREG_STID )); +if (!hexagon_thread_is_enabled (thread_env)) { +continue ; + } + + lowest_th_prio = (lowest_th_prio > th_prio) + ? lowest_th_prio + : th_prio; + } + + bestwait_reg =arch_get_system_reg (env,HEX_SREG_BESTWAIT ); + best_prio =GET_FIELD (BESTWAIT_PRIO , bestwait_reg); + +/* +* If the lowest priority thread is lower priority than the +* value in the BESTWAIT register, we must raise the reschedule +* interrupt on the lowest priority thread. +*/ +if (lowest_th_prio > best_prio) { +qemu_log_mask (CPU_LOG_INT , +"%s: raising resched int %d, cur PC 0x" TARGET_FMT_lx"\n" , + __func__, int_number,arch_get_thread_reg (env,HEX_REG_PC )); +SET_SYSTEM_FIELD (env,HEX_SREG_BESTWAIT ,BESTWAIT_PRIO , ~0 ); +hex_raise_interrupts (env,1 << int_number,CPU_INTERRUPT_SWI ); + } +} +void HELPER (wait )(CPUHexagonState *env,target_ulong PC ) {BQL_LOCK_GUARD ();
@@ -1495,7 +1546,8 @@ uint32_t HELPER(getimask)(CPUHexagonState *env, uint32_t tid)CPUHexagonState *found_env = &found_cpu->env;if (found_env->threadId == tid) {target_ulong imask =arch_get_system_reg (found_env,HEX_SREG_IMASK ); -qemu_log_mask (CPU_LOG_INT ,"%s: tid %d imask = 0x%x\n" , +qemu_log_mask (CPU_LOG_INT , +"%s: tid " TARGET_FMT_lx" imask = 0x%x\n" , __func__, env->threadId, (unsigned )GET_FIELD (IMASK_MASK , imask));return GET_FIELD (IMASK_MASK , imask);
@@ -1515,7 +1567,7 @@ void HELPER(setimask)(CPUHexagonState *env, uint32_t pred, uint32_t imask)if (pred == found_env->threadId) {SET_SYSTEM_FIELD (found_env,HEX_SREG_IMASK ,IMASK_MASK , imask); -qemu_log_mask (CPU_LOG_INT ,"%s: tid %d imask 0x%x\n" , +qemu_log_mask (CPU_LOG_INT ,"%s: tid " TARGET_FMT_lx" imask 0x%x\n" , __func__, found_env->threadId, imask);hex_interrupt_update (env);return ;
@@ -1764,6 +1816,21 @@ uint64_t HELPER(greg_read_pair)(CPUHexagonState *env, uint32_t reg)void HELPER (setprio )(CPUHexagonState *env,uint32_t thread,uint32_t prio) { +CPUState *cs; + +BQL_LOCK_GUARD (); +CPU_FOREACH (cs) { +HexagonCPU *found_cpu =HEXAGON_CPU (cs); +CPUHexagonState *found_env = &found_cpu->env; +if (thread == found_env->threadId) { +SET_SYSTEM_FIELD (found_env,HEX_SREG_STID ,STID_PRIO , prio); +qemu_log_mask (CPU_LOG_INT , +"%s: tid " TARGET_FMT_lx" prio = 0x%x\n" , + __func__, found_env->threadId, prio); +resched (env); +return ; + } + }g_assert_not_reached (); }
Signature · 1 line
2.34.1
PATCH v2 23/39 target/hexagon: Add sysemu_ops, cpu_get_phys_page_debug()
In reply to Brian CainFrom: Brian Cain <[email protected]>
--- target/hexagon/cpu.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)
target/hexagon/cpu.c +31 -0
@@ -19,6 +19,7 @@#include "qemu/qemu-print.h" #include "cpu.h" #include "internal.h" +#include "exec/cputlb.h" #include "exec/translation-block.h" #include "qapi/error.h" #include "hw/qdev-properties.h"
@@ -518,6 +519,24 @@ static void find_qemu_subpage(vaddr *addr, hwaddr *phys, int page_size) *phys += offset; } +static hwaddr hexagon_cpu_get_phys_page_debug (CPUState *cs,vaddr addr) +{ +CPUHexagonState *env =cpu_env (cs); +hwaddr phys_addr; +int prot; +int page_size =0 ; +int32_t excp =0 ; +int mmu_idx =MMU_KERNEL_IDX ; + +if (get_physical_address (env, &phys_addr, &prot, &page_size, &excp, + addr,0 , mmu_idx)) { +find_qemu_subpage (&addr, &phys_addr, page_size); +return phys_addr; + } + +return -1 ; +} +#define INVALID_BADVA 0xbadabada
@@ -623,6 +642,13 @@ static bool hexagon_tlb_fill(CPUState *cs, vaddr address, int size,do_raise_exception (env, cs->exception_index, env->gpr[HEX_REG_PC ], retaddr); } +#include "hw/core/sysemu-cpu-ops.h" + +static const struct SysemuCPUOps hexagon_sysemu_ops = { + .has_work = hexagon_cpu_has_work, + .get_phys_page_debug = hexagon_cpu_get_phys_page_debug, +}; +static bool hexagon_cpu_exec_interrupt (CPUState *cs,int interrupt_request) {CPUHexagonState *env =cpu_env (cs);
@@ -665,6 +691,8 @@ static const TCGCPUOps hexagon_tcg_ops = { .pointer_wrap = hexagon_pointer_wrap, .cpu_exec_reset = cpu_reset, .tlb_fill = hexagon_tlb_fill, + .cpu_exec_halt = hexagon_cpu_has_work, + .do_interrupt = hexagon_cpu_do_interrupt,#endif /* !CONFIG_USER_ONLY */ };
@@ -692,9 +720,12 @@ static void hexagon_cpu_class_init(ObjectClass *c, const void *data) cc->gdb_core_xml_file ="hexagon-core.xml" ; cc->disas_set_info = hexagon_cpu_disas_set_info;#ifndef CONFIG_USER_ONLY + cc->sysemu_ops = &hexagon_sysemu_ops; dc->vmsd = &vmstate_hexagon_cpu;#endif +#ifdef CONFIG_TCG cc->tcg_ops = &hexagon_tcg_ops; +#endif }#ifndef CONFIG_USER_ONLY
Signature · 1 line
2.34.1
PATCH v2 24/39 target/hexagon: Add exec-start-addr prop
In reply to Brian CainFrom: Brian Cain <[email protected]>
--- target/hexagon/cpu.h | 1 + target/hexagon/cpu.c | 2 ++ 2 files changed, 3 insertions(+)
target/hexagon/cpu.h +1 -0
@@ -196,6 +196,7 @@ struct ArchCPU {#ifndef CONFIG_USER_ONLY uint32_t num_tlbs;uint32_t l2vic_base_addr; +uint32_t boot_addr;#endif };
target/hexagon/cpu.c +2 -0
@@ -69,6 +69,7 @@ static const Property hexagon_cpu_properties[] = {DEFINE_PROP_UINT32 ("jtlb-entries" , HexagonCPU, num_tlbs,MAX_TLB_ENTRIES ),DEFINE_PROP_UINT32 ("l2vic-base-addr" , HexagonCPU, l2vic_base_addr,0xffffffffULL ), +DEFINE_PROP_UINT32 ("exec-start-addr" , HexagonCPU, boot_addr,0xffffffffULL ), #endifDEFINE_PROP_BOOL ("lldb-compat" , HexagonCPU, lldb_compat, false), DEFINE_PROP_UNSIGNED("lldb-stack-adjust", HexagonCPU, lldb_stack_adjust, 0,
@@ -409,6 +410,7 @@ static void hexagon_cpu_reset_hold(Object *obj, ResetType type) env->next_PC =0 ; env->wait_next_pc =0 ; env->cause_code =HEX_EVENT_NONE ; +arch_set_thread_reg (env,HEX_REG_PC , cpu->boot_addr);#endif env->cause_code =HEX_EVENT_NONE ; }
Signature · 1 line
2.34.1
PATCH v2 25/39 target/hexagon: extend hexagon_cpu_mmu_index() for sysemu
In reply to Brian CainFrom: Brian Cain <[email protected]>
--- target/hexagon/cpu_helper.h | 1 + target/hexagon/cpu.c | 26 ++++++++++++++++++----- target/hexagon/cpu_helper.c | 41 +++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 5 deletions(-)
target/hexagon/cpu_helper.h +1 -0
@@ -15,6 +15,7 @@ void hexagon_set_sys_pcycle_count(CPUHexagonState *env, uint64_t);void hexagon_set_sys_pcycle_count_low (CPUHexagonState *env,uint32_t );void hexagon_set_sys_pcycle_count_high (CPUHexagonState *env,uint32_t );void hexagon_modify_ssr (CPUHexagonState *env,uint32_t new,uint32_t old); +int get_cpu_mode (CPUHexagonState *env);int get_exe_mode (CPUHexagonState *env);void clear_wait_mode (CPUHexagonState *env);void hexagon_ssr_set_cause (CPUHexagonState *env,uint32_t cause);
target/hexagon/cpu.c +21 -5
@@ -329,20 +329,16 @@ bool hexagon_thread_is_enabled(CPUHexagonState *env)return E_bit; } -#endif static bool hexagon_cpu_has_work (CPUState *cs) { -#ifndef CONFIG_USER_ONLY CPUHexagonState *env =cpu_env (cs);return hexagon_thread_is_enabled (env) && (cs->interrupt_request & (CPU_INTERRUPT_HARD |CPU_INTERRUPT_SWI |CPU_INTERRUPT_K0_UNLOCK |CPU_INTERRUPT_TLB_UNLOCK )); -#else -return true; -#endif } +#endif static void hexagon_restore_state_to_opc(CPUState *cs, const TranslationBlock *tb,
@@ -463,6 +459,26 @@ static void hexagon_cpu_realize(DeviceState *dev, Error **errp)static int hexagon_cpu_mmu_index (CPUState *cs,bool ifetch) { +#ifndef CONFIG_USER_ONLY +BQL_LOCK_GUARD (); +CPUHexagonState *env =cpu_env (cs); +HexagonCPU *cpu =HEXAGON_CPU (cs); +if (cpu->globalregs) { +uint32_t syscfg =arch_get_system_reg (env,HEX_SREG_SYSCFG ); +uint8_t mmuen =GET_SYSCFG_FIELD (SYSCFG_MMUEN , syscfg); +if (!mmuen) { +return MMU_KERNEL_IDX ; + } + } + +int cpu_mode =get_cpu_mode (env); +if (cpu_mode ==HEX_CPU_MODE_MONITOR ) { +return MMU_KERNEL_IDX ; + }else if (cpu_mode ==HEX_CPU_MODE_GUEST ) { +return MMU_GUEST_IDX ; + } +#endif +return MMU_USER_IDX ; }
target/hexagon/cpu_helper.c +41 -0
45 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v2 26/39 target/hexagon: Decode trap1, rte as COF
In reply to Brian CainFrom: Brian Cain <[email protected]>
Also: handle rte instructions at the end of the packet.
--- target/hexagon/decode.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
target/hexagon/decode.c +14 -0
@@ -193,6 +193,8 @@ static bool decode_opcode_can_jump(int opcode)if ((GET_ATTRIB (opcode,A_JUMP )) || (GET_ATTRIB (opcode,A_CALL )) || (opcode == J2_trap0) || + (opcode == J2_trap1) || + (opcode == J2_rte) || (opcode == J2_pause)) {/* Exception to A_JUMP attribute */ if (opcode == J4_hintjumpr) {
@@ -371,6 +373,18 @@ static void decode_shuffle_for_execution(Packet *packet)break ; } } +/* +* And at the very very very end, move any RTE's, since they update +* user/supervisor mode. +*/ +#if !defined(CONFIG_USER_ONLY ) +for (i =0 ; i < last_insn; i++) { +if (packet->insn[i].opcode == J2_rte) { +decode_send_insn_to (packet, i, last_insn); +break ; + } + } +#endif } static void
Signature · 1 line
2.34.1
PATCH v2 27/39 target/hexagon: Implement hexagon_find_last_irq()
In reply to Brian CainFrom: Brian Cain <[email protected]>
--- target/hexagon/op_helper.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
target/hexagon/op_helper.c +7 -1
@@ -1643,7 +1643,13 @@ static void modify_syscfg(CPUHexagonState *env, uint32_t val)static uint32_t hexagon_find_last_irq (CPUHexagonState *env,uint32_t vid) { -g_assert_not_reached (); +int offset = (vid ==HEX_SREG_VID ) ?L2VIC_VID_0 :L2VIC_VID_1 ; +CPUState *cs =env_cpu (env); +HexagonCPU *cpu =HEXAGON_CPU (cs); +const hwaddr pend_mem = cpu->l2vic_base_addr + offset; +uint32_t irq; +cpu_physical_memory_read (pend_mem, &irq,sizeof (irq)); +return irq; } static void hexagon_read_timer(CPUHexagonState *env, uint32_t *low,
Signature · 1 line
2.34.1
PATCH v2 28/39 target/hexagon: Implement modify_ssr, resched, pending_interrupt
In reply to Brian CainFrom: Brian Cain <[email protected]>
--- target/hexagon/helper.h | 5 +++++ target/hexagon/op_helper.c | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+)
target/hexagon/helper.h +5 -0
@@ -129,4 +129,9 @@ DEF_HELPER_1(stop, void, env) DEF_HELPER_2(wait, void, env, i32) DEF_HELPER_2(resume, void, env, i32) DEF_HELPER_2(nmi, void, env, i32) +DEF_HELPER_1(resched, void, env) +DEF_HELPER_3(modify_ssr, void, env, i32, i32) +DEF_HELPER_1(pending_interrupt, void, env) +DEF_HELPER_3(sreg_write_masked, void, env, i32, i32) +DEF_HELPER_3(sreg_write_pair_masked, void, env, i32, i64)#endif
target/hexagon/op_helper.c +20 -0
@@ -1180,6 +1180,15 @@ float64 HELPER(dfmpyhh)(CPUHexagonState *env, float64 RxxV,return RxxV; } +#ifndef CONFIG_USER_ONLY +void HELPER (modify_ssr )(CPUHexagonState *env,uint32_t new,uint32_t old) +{ +BQL_LOCK_GUARD (); +hexagon_modify_ssr (env, new, old); +} +#endif + +/* Histogram instructions */ void HELPER (vhist )(CPUHexagonState *env)
@@ -1523,6 +1532,11 @@ static inline QEMU_ALWAYS_INLINE void resched(CPUHexagonState *env) } } +void HELPER (resched )(CPUHexagonState *env) +{ +resched (env); +} +void HELPER (wait )(CPUHexagonState *env,target_ulong PC ) {BQL_LOCK_GUARD ();
@@ -1844,6 +1858,12 @@ void HELPER(nmi)(CPUHexagonState *env, uint32_t thread_mask) {g_assert_not_reached (); } + +void HELPER (pending_interrupt )(CPUHexagonState *env) +{ +BQL_LOCK_GUARD (); +hex_interrupt_update (env); +}#endif
Signature · 1 line
2.34.1
PATCH v2 29/39 target/hexagon: Add pkt_ends_tb to translation
In reply to Brian CainFrom: Brian Cain <[email protected]>
--- target/hexagon/translate.h | 1 + target/hexagon/translate.c | 102 ++++++++++++++++++++++++++++++++++++- 2 files changed, 101 insertions(+), 2 deletions(-)
target/hexagon/translate.h +1 -0
@@ -84,6 +84,7 @@ typedef struct DisasContext {TCGv branch_taken;TCGv dczero_addr;bool pcycle_enabled; +bool pkt_ends_tb;uint32_t num_cycles; } DisasContext;
target/hexagon/translate.c +100 -2
132 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v2 30/39 target/hexagon: Add next_PC, {s,g}reg writes
In reply to Brian CainFrom: Brian Cain <[email protected]>
--- target/hexagon/translate.h | 2 + target/hexagon/genptr.c | 7 +- target/hexagon/translate.c | 134 ++++++++++++++++++++++++++++++++----- 3 files changed, 123 insertions(+), 20 deletions(-)
target/hexagon/translate.h +2 -0
@@ -85,6 +85,7 @@ typedef struct DisasContext {TCGv dczero_addr;bool pcycle_enabled;bool pkt_ends_tb; +bool need_next_pc;uint32_t num_cycles; } DisasContext;
@@ -306,6 +307,7 @@ static inline void ctx_log_qreg_read(DisasContext *ctx, }extern TCGv hex_gpr[TOTAL_PER_THREAD_REGS ]; +extern TCGv hex_next_PC;extern TCGv hex_pred[NUM_PREGS ];extern TCGv hex_slot_cancelled;extern TCGv hex_new_value_usr;
target/hexagon/genptr.c +4 -3
@@ -613,14 +613,15 @@ static void gen_write_new_pc_addr(DisasContext *ctx, TCGv addr,tcg_gen_brcondi_tl (cond, pred,0 , pred_false); } +TCGv PC_wr = ctx->need_next_pc ? hex_next_PC : hex_gpr[HEX_REG_PC ];if (ctx->pkt->pkt_has_multi_cof) {/* If there are multiple branches in a packet, ignore the second one */ -tcg_gen_movcond_tl (TCG_COND_NE , hex_gpr[HEX_REG_PC ], +tcg_gen_movcond_tl (TCG_COND_NE , PC_wr, ctx->branch_taken,tcg_constant_tl (0 ), - hex_gpr[HEX_REG_PC ], addr); + PC_wr, addr);tcg_gen_movi_tl (ctx->branch_taken,1 ); }else { -tcg_gen_mov_tl (hex_gpr[HEX_REG_PC ], addr); +tcg_gen_mov_tl (PC_wr, addr); }if (cond !=TCG_COND_ALWAYS ) {
target/hexagon/translate.c +117 -17
204 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v2 31/39 target/hexagon: Add implicit sysreg writes
In reply to Brian CainFrom: Brian Cain <[email protected]>
--- target/hexagon/translate.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
target/hexagon/translate.c +16 -0
@@ -422,6 +422,16 @@ static void mark_implicit_reg_write(DisasContext *ctx, int attrib, int rnum) } } +#ifndef CONFIG_USER_ONLY +static void mark_implicit_sreg_write (DisasContext *ctx,int attrib,int snum) +{ +uint16_t opcode = ctx->insn->opcode; +if (GET_ATTRIB (opcode, attrib)) { +ctx_log_sreg_write (ctx, snum); + } +} +#endif +static void mark_implicit_reg_writes (DisasContext *ctx) {mark_implicit_reg_write (ctx,A_IMPLICIT_WRITES_FP ,HEX_REG_FP );
@@ -433,6 +443,12 @@ static void mark_implicit_reg_writes(DisasContext *ctx)mark_implicit_reg_write (ctx,A_IMPLICIT_WRITES_SA1 ,HEX_REG_SA1 );mark_implicit_reg_write (ctx,A_IMPLICIT_WRITES_USR ,HEX_REG_USR );mark_implicit_reg_write (ctx,A_FPOP ,HEX_REG_USR ); + +#ifndef CONFIG_USER_ONLY +mark_implicit_sreg_write (ctx,A_IMPLICIT_WRITES_SGP0 ,HEX_SREG_SGP0 ); +mark_implicit_sreg_write (ctx,A_IMPLICIT_WRITES_SGP1 ,HEX_SREG_SGP1 ); +mark_implicit_sreg_write (ctx,A_IMPLICIT_WRITES_SSR ,HEX_SREG_SSR ); +#endif }static void mark_implicit_pred_write (DisasContext *ctx,int attrib,int pnum)
Signature · 1 line
2.34.1
PATCH v2 32/39 target/hexagon: Define system, guest reg names
In reply to Brian CainFrom: Brian Cain <[email protected]>
--- target/hexagon/internal.h | 2 ++ target/hexagon/cpu.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+)
target/hexagon/internal.h +2 -0
@@ -34,6 +34,8 @@ void hexagon_debug_qreg(CPUHexagonState *env, int regnum);void hexagon_debug (CPUHexagonState *env);extern const char *const hexagon_regnames[TOTAL_PER_THREAD_REGS ]; +extern const char *const hexagon_sregnames[]; +extern const char *const hexagon_gregnames[]; void G_NORETURN do_raise_exception(CPUHexagonState *env, uint32_t exception,
target/hexagon/cpu.c +29 -0
@@ -88,6 +88,35 @@ const char * const hexagon_regnames[TOTAL_PER_THREAD_REGS] = { "c24", "c25", "c26", "c27", "c28", "c29", "c30", "c31", }; +#ifndef CONFIG_USER_ONLY +const char *const hexagon_sregnames[] = { +"sgp0" ,"sgp1" ,"stid" ,"elr" ,"badva0" , +"badva1" ,"ssr" ,"ccr" ,"htid" ,"badva" , +"imask" ,"gevb" ,"vwctrl" ,"s13" ,"s14" , +"s15" ,"evb" ,"modectl" ,"syscfg" ,"segment" , +"ipendad" ,"vid" ,"vid1" ,"bestwait" ,"s24" , +"schedcfg" ,"s26" ,"cfgbase" ,"diag" ,"rev" , +"pcyclelo" ,"pcyclehi" ,"isdbst" ,"isdbcfg0" ,"isdbcfg1" , +"livelock" ,"brkptpc0" ,"brkptcfg0" ,"brkptpc1" ,"brkptcfg1" , +"isdbmbxin" ,"isdbmbxout" ,"isdben" ,"isdbgpr" ,"pmucnt4" , +"pmucnt5" ,"pmucnt6" ,"pmucnt7" ,"pmucnt0" ,"pmucnt1" , +"pmucnt2" ,"pmucnt3" ,"pmuevtcfg" ,"pmustid0" ,"pmuevtcfg1" , +"pmustid1" ,"timerlo" ,"timerhi" ,"pmucfg" ,"rgdr2" , +"rgdr" ,"turkey" ,"duck" ,"chicken" , +}; + +G_STATIC_ASSERT (NUM_SREGS ==ARRAY_SIZE (hexagon_sregnames)); + +const char *const hexagon_gregnames[] = { +"gelr" ,"gsr" ,"gosp" ,"gbadva" ,"gcommit1t" , +"gcommit2t" ,"gcommit3t" ,"gcommit4t" ,"gcommit5t" ,"gcommit6t" , +"gpcycle1t" ,"gpcycle2t" ,"gpcycle3t" ,"gpcycle4t" ,"gpcycle5t" , +"gpcycle6t" ,"gpmucnt4" ,"gpmucnt5" ,"gpmucnt6" ,"gpmucnt7" , +"gcommit7t" ,"gcommit8t" ,"gpcycle7t" ,"gpcycle8t" ,"gpcyclelo" , +"gpcyclehi" ,"gpmucnt0" ,"gpmucnt1" ,"gpmucnt2" ,"gpmucnt3" , +"g30" ,"g31" , +}; +#endif /* * One of the main debugging techniques is to use "-d cpu" and compare against * LLDB output when single stepping. However, the target and qemu put the
Signature · 1 line
2.34.1
PATCH v2 33/39 target/hexagon: initialize sys/guest reg TCGvs
In reply to Brian CainFrom: Brian Cain <[email protected]>
--- target/hexagon/translate.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
target/hexagon/translate.c +14 -0
@@ -1287,6 +1287,20 @@ void hexagon_translate_init(void)opcode_init (); +#ifndef CONFIG_USER_ONLY +for (i =0 ; i <NUM_GREGS ; i++) { + hex_greg[i] =tcg_global_mem_new (tcg_env, + offsetof(CPUHexagonState, greg[i]), + hexagon_gregnames[i]); + } +for (i =0 ; i <NUM_SREGS ; i++) { +if (i <HEX_SREG_GLB_START ) { + hex_t_sreg[i] =tcg_global_mem_new (tcg_env, + offsetof(CPUHexagonState, t_sreg[i]), + hexagon_sregnames[i]); + } + } +#endif for (i =0 ; i <TOTAL_PER_THREAD_REGS ; i++) { hex_gpr[i] =tcg_global_mem_new (tcg_env, offsetof(CPUHexagonState, gpr[i]),
Signature · 1 line
2.34.1
PATCH v2 34/39 target/hexagon: Add TLB, k0 {un,}lock
In reply to Brian CainFrom: Brian Cain <[email protected]>
--- target/hexagon/sys_macros.h | 8 +-- target/hexagon/op_helper.c | 104 ++++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+), 4 deletions(-)
target/hexagon/sys_macros.h +4 -4
@@ -143,11 +143,11 @@#define fDCINVIDX (REG )#define fDCINVA (REG ) do { REG = REG; } while (0)/* Nothing to do in qemu */ -#define fSET_TLB_LOCK () g_assert_not_reached() -#define fCLEAR_TLB_LOCK () g_assert_not_reached() +#define fSET_TLB_LOCK () hex_tlb_lock(env); +#define fCLEAR_TLB_LOCK () hex_tlb_unlock(env); -#define fSET_K0_LOCK () g_assert_not_reached() -#define fCLEAR_K0_LOCK () g_assert_not_reached() +#define fSET_K0_LOCK () hex_k0_lock(env); +#define fCLEAR_K0_LOCK () hex_k0_unlock(env);#define fTLB_IDXMASK (INDEX ) \ ((INDEX) & (fPOW2_ROUNDUP(fCAST4u(env_archcpu(env)->num_tlbs)) - 1))
target/hexagon/op_helper.c +104 -0
110 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v2 35/39 target/hexagon: Define gen_precise_exception()
In reply to Brian CainFrom: Brian Cain <[email protected]>
Add PC to raise_exception helper
Replace the fGEN_TCG_J2_trap0 macro override with the fTRAP()-generated system helper instead.
--- target/hexagon/gen_tcg.h | 7 ------- target/hexagon/helper.h | 2 +- target/hexagon/op_helper.c | 10 ++++------ target/hexagon/translate.c | 13 ++++++++----- 4 files changed, 13 insertions(+), 19 deletions(-)
target/hexagon/gen_tcg.h +0 -7
@@ -1370,13 +1370,6 @@#define fGEN_TCG_S2_storew_rl_st_vi (SHORTCODE ) SHORTCODE#define fGEN_TCG_S4_stored_rl_st_vi (SHORTCODE ) SHORTCODE -#define fGEN_TCG_J2_trap0 (SHORTCODE ) \ - do { \ - uiV = uiV; \ - tcg_gen_movi_tl(hex_gpr[HEX_REG_PC], ctx->pkt->pc); \ - TCGv excp = tcg_constant_tl(HEX_EVENT_TRAP0); \ - gen_helper_raise_exception(tcg_env, excp); \ - } while (0)#endif #define fGEN_TCG_A2_nop (SHORTCODE ) do { } while (0)
target/hexagon/helper.h +1 -1
@@ -18,7 +18,7 @@#include "internal.h" #include "helper_protos_generated.h.inc" -DEF_HELPER_FLAGS_2(raise_exception, TCG_CALL_NO_RETURN, noreturn, env, i32) +DEF_HELPER_FLAGS_3(raise_exception, TCG_CALL_NO_RETURN, noreturn, env, i32, i32) DEF_HELPER_2(commit_store, void, env, int) DEF_HELPER_3(gather_store, void, env, i32, int)DEF_HELPER_1 (commit_hvx_stores, void, env)
target/hexagon/op_helper.c +4 -6
@@ -71,15 +71,13 @@ G_NORETURN void hexagon_raise_exception_err(CPUHexagonState *env,uint32_t exception, uintptr_t pc) { -CPUState *cs =env_cpu (env); -qemu_log_mask (CPU_LOG_INT ,"%s: %d\n" , __func__, exception); - cs->exception_index = exception; -cpu_loop_exit_restore (cs, pc); + do_raise_exception(env, exception, pc, 0); } -G_NORETURN void HELPER(raise_exception)(CPUHexagonState *env, uint32_t excp) +G_NORETURN void HELPER(raise_exception)(CPUHexagonState *env, uint32_t excp, +target_ulong PC ) { -hexagon_raise_exception_err (env, excp,0 ); +hexagon_raise_exception_err (env, excp,PC ); } void log_store32(CPUHexagonState *env, target_ulong addr,
target/hexagon/translate.c +8 -5
@@ -122,9 +122,10 @@ intptr_t ctx_tmp_vreg_off(DisasContext *ctx, int regnum,return offset; } -static void gen_exception_raw (int excp) +static void gen_exception (int excp,target_ulong PC ) { -gen_helper_raise_exception (tcg_env,tcg_constant_i32 (excp)); +gen_helper_raise_exception (tcg_env,tcg_constant_i32 (excp), +tcg_constant_tl (PC )); }#ifndef CONFIG_USER_ONLY
@@ -219,9 +220,11 @@ static void gen_end_tb(DisasContext *ctx)void hex_gen_exception_end_tb (DisasContext *ctx,int excp) { -gen_exec_counters (ctx); -tcg_gen_movi_tl (hex_gpr[HEX_REG_PC ], ctx->next_PC); -gen_exception_raw (excp); +#ifdef CONFIG_USER_ONLY +gen_exception (excp, ctx->pkt->pc); +#else +gen_precise_exception (excp, ctx->pkt->pc); +#endif ctx->base.is_jmp =DISAS_NORETURN ; }
Signature · 1 line
2.34.1
PATCH v2 36/39 target/hexagon: Add TCG overrides for transfer insts
In reply to Brian CainFrom: Brian Cain <[email protected]>
--- target/hexagon/gen_tcg_sys.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
target/hexagon/gen_tcg_sys.h +25 -0
@@ -81,6 +81,31 @@gen_helper_stop (tcg_env); \ } while (0) +#define fGEN_TCG_Y2_tfrscrr (SHORTCODE ) \ + tcg_gen_mov_tl(RdV, SsV) + +#define fGEN_TCG_Y2_tfrsrcr (SHORTCODE ) \ + tcg_gen_mov_tl(SdV, RsV) + +#define fGEN_TCG_Y4_tfrscpp (SHORTCODE ) \ + tcg_gen_mov_i64(RddV, SssV) + +#define fGEN_TCG_Y4_tfrspcp (SHORTCODE ) \ + tcg_gen_mov_i64(SddV, RssV) + +#define fGEN_TCG_G4_tfrgcrr (SHORTCODE ) \ + tcg_gen_mov_tl(RdV, GsV) + +#define fGEN_TCG_G4_tfrgrcr (SHORTCODE ) \ + tcg_gen_mov_tl(GdV, RsV) + +#define fGEN_TCG_G4_tfrgcpp (SHORTCODE ) \ + tcg_gen_mov_i64(RddV, GssV) + +#define fGEN_TCG_G4_tfrgpcp (SHORTCODE ) \ + tcg_gen_mov_i64(GddV, RssV) + +/* * rte (return from exception) * Clear the EX bit in SSR
Signature · 1 line
2.34.1
PATCH v2 37/39 target/hexagon: Add support for loadw_phys
In reply to Brian CainFrom: Brian Cain <[email protected]>
--- target/hexagon/hex_common.py | 3 +++ target/hexagon/imported/encode_pp.def | 1 + target/hexagon/imported/ldst.idef | 3 +++ 3 files changed, 7 insertions(+)
target/hexagon/hex_common.py +3 -0
@@ -265,6 +265,9 @@ def need_slot(tag): and "A_CVI_GATHER" not in attribdict[tag] and ("A_STORE" in attribdict[tag] or "A_LOAD" in attribdict[tag]) + and tag != "L4_loadw_phys" + and tag != "L6_memcpy" + and tag != "Y6_dmlink" ): return 1 else:
target/hexagon/imported/encode_pp.def +1 -0
@@ -388,6 +388,7 @@ DEF_ENC32(L4_return_fnew_pnt, ICLASS_LD" 011 0 000 sssss PP1010vv ---ddddd") /** Load Acquire Store Release Encoding **/ +DEF_ENC32(L4_loadw_phys, ICLASS_LD" 001 0 000 sssss PP1ttttt -00ddddd") DEF_ENC32(L2_loadw_locked, ICLASS_LD" 001 0 000 sssss PP000--- 000ddddd") DEF_ENC32(L4_loadd_locked, ICLASS_LD" 001 0 000 sssss PP010--- 000ddddd")
target/hexagon/imported/ldst.idef +3 -0
@@ -203,6 +203,9 @@ Q6INSN(S2_storew_locked,"memw_locked(Rs32,Pd4)=Rt32", ATTRIBS(A_REGWRSIZE_4B,A_M Q6INSN(L4_loadd_locked,"Rdd32=memd_locked(Rs32)", ATTRIBS(A_REGWRSIZE_8B,A_MEMSIZE_8B,A_LOAD,A_RESTRICT_SLOT0ONLY,A_RESTRICT_PACKET_AXOK,A_NOTE_AXOK), "Load double with lock", { fEA_REG(RsV); fLOAD_LOCKED(1,8,u,EA,RddV) }) +Q6INSN(L4_loadw_phys,"Rd32=memw_phys(Rs32,Rt32)", ATTRIBS(A_REGWRSIZE_4B,A_PRIV,A_RESTRICT_SLOT0ONLY,A_NOTE_PRIV,A_MEMSIZE_4B,A_LOAD,A_NOTE_NOPACKET,A_RESTRICT_NOPACKET), "Load word from physical address", +{ fLOAD_PHYS(1,4,u,RsV,RtV,RdV); }) + Q6INSN(S4_stored_locked,"memd_locked(Rs32,Pd4)=Rtt32", ATTRIBS(A_REGWRSIZE_8B,A_MEMSIZE_8B,A_STORE,A_RESTRICT_SLOT0ONLY,A_RESTRICT_PACKET_AXOK,A_NOTE_AXOK,A_RESTRICT_LATEPRED,A_NOTE_LATEPRED), "Store word with lock", { fEA_REG(RsV); fSTORE_LOCKED(1,8,EA,RttV,PdV) })
Signature · 1 line
2.34.1
PATCH v2 38/39 target/hexagon: Add guest reg reading functionality
In reply to Brian CainFrom: Matheus Tavares Bernardino <[email protected]>
--- target/hexagon/cpu.c | 19 ++++++++++++++++++- target/hexagon/op_helper.c | 19 +++++++++++++++++-- 2 files changed, 35 insertions(+), 3 deletions(-)
target/hexagon/cpu.c +18 -1
@@ -778,7 +778,24 @@ static void hexagon_cpu_class_init(ObjectClass *c, const void *data)#ifndef CONFIG_USER_ONLY uint32_t hexagon_greg_read (CPUHexagonState *env,uint32_t reg) { -g_assert_not_reached (); +target_ulong ssr =arch_get_system_reg (env,HEX_SREG_SSR ); +int ssr_ce =GET_SSR_FIELD (SSR_CE , ssr); + +if (reg <=HEX_GREG_G3 ) { +return env->greg[reg]; + } +switch (reg) { +case HEX_GREG_GPCYCLELO : +return ssr_ce ?hexagon_get_sys_pcycle_count_low (env) :0 ; + +case HEX_GREG_GPCYCLEHI : +return ssr_ce ?hexagon_get_sys_pcycle_count_high (env) :0 ; + +default : +qemu_log_mask (LOG_UNIMP ,"reading greg %" PRId32 +" not yet supported.\n" , reg); +return 0 ; + } }#endif
target/hexagon/op_helper.c +17 -2
@@ -1927,13 +1927,28 @@ uint64_t HELPER(sreg_read_pair)(CPUHexagonState *env, uint32_t reg) }uint32_t HELPER (greg_read )(CPUHexagonState *env,uint32_t reg) + { -g_assert_not_reached (); +return hexagon_greg_read (env, reg); }uint64_t HELPER (greg_read_pair )(CPUHexagonState *env,uint32_t reg) + { -g_assert_not_reached (); +if (reg ==HEX_GREG_G0 || reg ==HEX_GREG_G2 ) { +return (uint64_t )(env->greg[reg]) | + (((uint64_t )(env->greg[reg +1 ])) <<32 ); + } +switch (reg) { +case HEX_GREG_GPCYCLELO : { +target_ulong ssr =arch_get_system_reg (env,HEX_SREG_SSR ); +int ssr_ce =GET_SSR_FIELD (SSR_CE , ssr); +return ssr_ce ?hexagon_get_sys_pcycle_count (env) :0 ; + } +default : +return (uint64_t )hexagon_greg_read (env, reg) | + ((uint64_t )(hexagon_greg_read (env, reg +1 )) <<32 ); + } }void HELPER (setprio )(CPUHexagonState *env,uint32_t thread,uint32_t prio)
Signature · 1 line
2.34.1
PATCH v2 39/39 target/hexagon: Add pcycle setting functionality
In reply to Brian Cain--- target/hexagon/cpu_helper.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
target/hexagon/cpu_helper.c +7 -2
@@ -120,13 +120,18 @@ uint32_t hexagon_get_sys_pcycle_count_low(CPUHexagonState *env)void hexagon_set_sys_pcycle_count_high (CPUHexagonState *env,uint32_t cycles_hi) { -g_assert_not_reached (); +uint64_t cur_cycles =hexagon_get_sys_pcycle_count (env); +uint64_t cycles = + ((uint64_t )cycles_hi <<32 ) |extract64 (cur_cycles,0 ,32 ); +hexagon_set_sys_pcycle_count (env, cycles); }void hexagon_set_sys_pcycle_count_low (CPUHexagonState *env,uint32_t cycles_lo) { -g_assert_not_reached (); +uint64_t cur_cycles =hexagon_get_sys_pcycle_count (env); +uint64_t cycles =extract64 (cur_cycles,32 ,32 ) | cycles_lo; +hexagon_set_sys_pcycle_count (env, cycles); }void hexagon_set_sys_pcycle_count (CPUHexagonState *env,uint64_t cycles)
Signature · 1 line
2.34.1