* [PATCH v2 0/5] AVR target fixes
@ 2023-01-19 9:22 Pavel Dovgalyuk
2023-01-19 9:22 ` [PATCH v2 1/5] target/avr: fix long address calculation Pavel Dovgalyuk
` (4 more replies)
0 siblings, 5 replies; 13+ messages in thread
From: Pavel Dovgalyuk @ 2023-01-19 9:22 UTC (permalink / raw)
To: qemu-devel; +Cc: pavel.dovgalyuk, mrolnik, philmd, richard.henderson
This set of patches includes multiple changes for AVR target.
v2 changes:
- fixed instruction translation in icount mode
---
Pavel Dovgalyuk (5):
target/avr: fix long address calculation
target/avr: implement small RAM/large RAM feature
target/avr: fix avr features processing
target/avr: fix interrupt processing
target/avr: enable icount mode
target/avr/cpu.h | 6 ++-
target/avr/helper.c | 4 +-
target/avr/translate.c | 93 +++++++++++++++++++++++++++++++-----------
3 files changed, 75 insertions(+), 28 deletions(-)
--
Pavel Dovgalyuk
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v2 1/5] target/avr: fix long address calculation
2023-01-19 9:22 [PATCH v2 0/5] AVR target fixes Pavel Dovgalyuk
@ 2023-01-19 9:22 ` Pavel Dovgalyuk
2023-01-19 9:22 ` [PATCH v2 2/5] target/avr: implement small RAM/large RAM feature Pavel Dovgalyuk
` (3 subsequent siblings)
4 siblings, 0 replies; 13+ messages in thread
From: Pavel Dovgalyuk @ 2023-01-19 9:22 UTC (permalink / raw)
To: qemu-devel; +Cc: pavel.dovgalyuk, mrolnik, philmd, richard.henderson
AVR ELPMX instruction (and some others) use three registers to
form long 24-bit address from RAMPZ and two 8-bit registers.
RAMPZ stores shifted 8 bits like ff0000 to simplify address calculation.
This patch fixes full address calculation in function gen_get_addr
by changing the mess in offsets of deposit tcg instructions.
Signed-off-by: Pavel Dovgalyuk <Pavel.Dovgalyuk@ispras.ru>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Michael Rolnik <mrolnik@gmail.com>
---
target/avr/translate.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/target/avr/translate.c b/target/avr/translate.c
index 2bed56f135..552f739b3d 100644
--- a/target/avr/translate.c
+++ b/target/avr/translate.c
@@ -1572,8 +1572,8 @@ static TCGv gen_get_addr(TCGv H, TCGv M, TCGv L)
{
TCGv addr = tcg_temp_new_i32();
- tcg_gen_deposit_tl(addr, M, H, 8, 8);
- tcg_gen_deposit_tl(addr, L, addr, 8, 16);
+ tcg_gen_deposit_tl(addr, H, M, 8, 8);
+ tcg_gen_deposit_tl(addr, addr, L, 0, 8);
return addr;
}
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH v2 2/5] target/avr: implement small RAM/large RAM feature
2023-01-19 9:22 [PATCH v2 0/5] AVR target fixes Pavel Dovgalyuk
2023-01-19 9:22 ` [PATCH v2 1/5] target/avr: fix long address calculation Pavel Dovgalyuk
@ 2023-01-19 9:22 ` Pavel Dovgalyuk
2023-01-19 18:29 ` Richard Henderson
2023-01-19 9:22 ` [PATCH v2 3/5] target/avr: fix avr features processing Pavel Dovgalyuk
` (2 subsequent siblings)
4 siblings, 1 reply; 13+ messages in thread
From: Pavel Dovgalyuk @ 2023-01-19 9:22 UTC (permalink / raw)
To: qemu-devel; +Cc: pavel.dovgalyuk, mrolnik, philmd, richard.henderson
translate.c functions use RAMPZ for RAM access. This register
is also used for ROM reads. However, in MCUs with 64k RAM support
RAMPZ is used for ROM only. Therefore when RAMPZ is set,
addressing the RAM becomes incorrect in the emulator.
This patch adds LARGE RAM feature which can be used in xmega controllers,
that could be added later. For the currently supported MCUs this
feature is disabled and RAMPZ is not used for RAM access.
Signed-off-by: Pavel Dovgalyuk <Pavel.Dovgalyuk@ispras.ru>
---
target/avr/cpu.h | 2 ++
target/avr/translate.c | 63 ++++++++++++++++++++++++++++++------------------
2 files changed, 41 insertions(+), 24 deletions(-)
diff --git a/target/avr/cpu.h b/target/avr/cpu.h
index f19dd72926..7c3895b65e 100644
--- a/target/avr/cpu.h
+++ b/target/avr/cpu.h
@@ -106,6 +106,8 @@ typedef enum AVRFeature {
AVR_FEATURE_RAMPX,
AVR_FEATURE_RAMPY,
AVR_FEATURE_RAMPZ,
+
+ AVR_FEATURE_LARGE_RAM,
} AVRFeature;
typedef struct CPUArchState {
diff --git a/target/avr/translate.c b/target/avr/translate.c
index 552f739b3d..40b15d116e 100644
--- a/target/avr/translate.c
+++ b/target/avr/translate.c
@@ -1542,13 +1542,17 @@ static bool trans_BRBS(DisasContext *ctx, arg_BRBS *a)
* M assumed to be in 0x000000ff format
* L assumed to be in 0x000000ff format
*/
-static void gen_set_addr(TCGv addr, TCGv H, TCGv M, TCGv L)
+static void gen_set_addr_short(TCGv addr, TCGv M, TCGv L)
{
-
tcg_gen_andi_tl(L, addr, 0x000000ff);
tcg_gen_andi_tl(M, addr, 0x0000ff00);
tcg_gen_shri_tl(M, M, 8);
+}
+
+static void gen_set_addr(TCGv addr, TCGv H, TCGv M, TCGv L)
+{
+ gen_set_addr_short(addr, M, L);
tcg_gen_andi_tl(H, addr, 0x00ff0000);
}
@@ -1563,9 +1567,13 @@ static void gen_set_yaddr(TCGv addr)
gen_set_addr(addr, cpu_rampY, cpu_r[29], cpu_r[28]);
}
-static void gen_set_zaddr(TCGv addr)
+static void gen_set_zaddr(DisasContext *ctx, TCGv addr, bool ram)
{
- gen_set_addr(addr, cpu_rampZ, cpu_r[31], cpu_r[30]);
+ if (!ram || avr_feature(ctx->env, AVR_FEATURE_LARGE_RAM)) {
+ gen_set_addr(addr, cpu_rampZ, cpu_r[31], cpu_r[30]);
+ } else {
+ gen_set_addr_short(addr, cpu_r[31], cpu_r[30]);
+ }
}
static TCGv gen_get_addr(TCGv H, TCGv M, TCGv L)
@@ -1588,9 +1596,16 @@ static TCGv gen_get_yaddr(void)
return gen_get_addr(cpu_rampY, cpu_r[29], cpu_r[28]);
}
-static TCGv gen_get_zaddr(void)
+static TCGv gen_get_zaddr(DisasContext *ctx, bool ram)
{
- return gen_get_addr(cpu_rampZ, cpu_r[31], cpu_r[30]);
+ if (!ram || avr_feature(ctx->env, AVR_FEATURE_LARGE_RAM)) {
+ return gen_get_addr(cpu_rampZ, cpu_r[31], cpu_r[30]);
+ } else {
+ TCGv zero = tcg_const_i32(0);
+ TCGv res = gen_get_addr(zero, cpu_r[31], cpu_r[30]);
+ tcg_temp_free_i32(zero);
+ return res;
+ }
}
/*
@@ -1868,12 +1883,12 @@ static bool trans_LDDY(DisasContext *ctx, arg_LDDY *a)
static bool trans_LDZ2(DisasContext *ctx, arg_LDZ2 *a)
{
TCGv Rd = cpu_r[a->rd];
- TCGv addr = gen_get_zaddr();
+ TCGv addr = gen_get_zaddr(ctx, true);
gen_data_load(ctx, Rd, addr);
tcg_gen_addi_tl(addr, addr, 1); /* addr = addr + 1 */
- gen_set_zaddr(addr);
+ gen_set_zaddr(ctx, addr, true);
tcg_temp_free_i32(addr);
@@ -1883,12 +1898,12 @@ static bool trans_LDZ2(DisasContext *ctx, arg_LDZ2 *a)
static bool trans_LDZ3(DisasContext *ctx, arg_LDZ3 *a)
{
TCGv Rd = cpu_r[a->rd];
- TCGv addr = gen_get_zaddr();
+ TCGv addr = gen_get_zaddr(ctx, true);
tcg_gen_subi_tl(addr, addr, 1); /* addr = addr - 1 */
gen_data_load(ctx, Rd, addr);
- gen_set_zaddr(addr);
+ gen_set_zaddr(ctx, addr, true);
tcg_temp_free_i32(addr);
@@ -1898,7 +1913,7 @@ static bool trans_LDZ3(DisasContext *ctx, arg_LDZ3 *a)
static bool trans_LDDZ(DisasContext *ctx, arg_LDDZ *a)
{
TCGv Rd = cpu_r[a->rd];
- TCGv addr = gen_get_zaddr();
+ TCGv addr = gen_get_zaddr(ctx, true);
tcg_gen_addi_tl(addr, addr, a->imm); /* addr = addr + q */
gen_data_load(ctx, Rd, addr);
@@ -2088,12 +2103,12 @@ static bool trans_STDY(DisasContext *ctx, arg_STDY *a)
static bool trans_STZ2(DisasContext *ctx, arg_STZ2 *a)
{
TCGv Rd = cpu_r[a->rd];
- TCGv addr = gen_get_zaddr();
+ TCGv addr = gen_get_zaddr(ctx, true);
gen_data_store(ctx, Rd, addr);
tcg_gen_addi_tl(addr, addr, 1); /* addr = addr + 1 */
- gen_set_zaddr(addr);
+ gen_set_zaddr(ctx, addr, true);
tcg_temp_free_i32(addr);
@@ -2103,12 +2118,12 @@ static bool trans_STZ2(DisasContext *ctx, arg_STZ2 *a)
static bool trans_STZ3(DisasContext *ctx, arg_STZ3 *a)
{
TCGv Rd = cpu_r[a->rd];
- TCGv addr = gen_get_zaddr();
+ TCGv addr = gen_get_zaddr(ctx, true);
tcg_gen_subi_tl(addr, addr, 1); /* addr = addr - 1 */
gen_data_store(ctx, Rd, addr);
- gen_set_zaddr(addr);
+ gen_set_zaddr(ctx, addr, true);
tcg_temp_free_i32(addr);
@@ -2118,7 +2133,7 @@ static bool trans_STZ3(DisasContext *ctx, arg_STZ3 *a)
static bool trans_STDZ(DisasContext *ctx, arg_STDZ *a)
{
TCGv Rd = cpu_r[a->rd];
- TCGv addr = gen_get_zaddr();
+ TCGv addr = gen_get_zaddr(ctx, true);
tcg_gen_addi_tl(addr, addr, a->imm); /* addr = addr + q */
gen_data_store(ctx, Rd, addr);
@@ -2228,7 +2243,7 @@ static bool trans_ELPM1(DisasContext *ctx, arg_ELPM1 *a)
}
TCGv Rd = cpu_r[0];
- TCGv addr = gen_get_zaddr();
+ TCGv addr = gen_get_zaddr(ctx, false);
tcg_gen_qemu_ld8u(Rd, addr, MMU_CODE_IDX); /* Rd = mem[addr] */
@@ -2244,7 +2259,7 @@ static bool trans_ELPM2(DisasContext *ctx, arg_ELPM2 *a)
}
TCGv Rd = cpu_r[a->rd];
- TCGv addr = gen_get_zaddr();
+ TCGv addr = gen_get_zaddr(ctx, false);
tcg_gen_qemu_ld8u(Rd, addr, MMU_CODE_IDX); /* Rd = mem[addr] */
@@ -2260,11 +2275,11 @@ static bool trans_ELPMX(DisasContext *ctx, arg_ELPMX *a)
}
TCGv Rd = cpu_r[a->rd];
- TCGv addr = gen_get_zaddr();
+ TCGv addr = gen_get_zaddr(ctx, false);
tcg_gen_qemu_ld8u(Rd, addr, MMU_CODE_IDX); /* Rd = mem[addr] */
tcg_gen_addi_tl(addr, addr, 1); /* addr = addr + 1 */
- gen_set_zaddr(addr);
+ gen_set_zaddr(ctx, addr, false);
tcg_temp_free_i32(addr);
@@ -2402,7 +2417,7 @@ static bool trans_XCH(DisasContext *ctx, arg_XCH *a)
TCGv Rd = cpu_r[a->rd];
TCGv t0 = tcg_temp_new_i32();
- TCGv addr = gen_get_zaddr();
+ TCGv addr = gen_get_zaddr(ctx, true);
gen_data_load(ctx, t0, addr);
gen_data_store(ctx, Rd, addr);
@@ -2432,7 +2447,7 @@ static bool trans_LAS(DisasContext *ctx, arg_LAS *a)
}
TCGv Rr = cpu_r[a->rd];
- TCGv addr = gen_get_zaddr();
+ TCGv addr = gen_get_zaddr(ctx, true);
TCGv t0 = tcg_temp_new_i32();
TCGv t1 = tcg_temp_new_i32();
@@ -2467,7 +2482,7 @@ static bool trans_LAC(DisasContext *ctx, arg_LAC *a)
}
TCGv Rr = cpu_r[a->rd];
- TCGv addr = gen_get_zaddr();
+ TCGv addr = gen_get_zaddr(ctx, true);
TCGv t0 = tcg_temp_new_i32();
TCGv t1 = tcg_temp_new_i32();
@@ -2502,7 +2517,7 @@ static bool trans_LAT(DisasContext *ctx, arg_LAT *a)
}
TCGv Rd = cpu_r[a->rd];
- TCGv addr = gen_get_zaddr();
+ TCGv addr = gen_get_zaddr(ctx, true);
TCGv t0 = tcg_temp_new_i32();
TCGv t1 = tcg_temp_new_i32();
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH v2 3/5] target/avr: fix avr features processing
2023-01-19 9:22 [PATCH v2 0/5] AVR target fixes Pavel Dovgalyuk
2023-01-19 9:22 ` [PATCH v2 1/5] target/avr: fix long address calculation Pavel Dovgalyuk
2023-01-19 9:22 ` [PATCH v2 2/5] target/avr: implement small RAM/large RAM feature Pavel Dovgalyuk
@ 2023-01-19 9:22 ` Pavel Dovgalyuk
2023-01-19 10:09 ` Philippe Mathieu-Daudé
2023-01-19 18:25 ` Richard Henderson
2023-01-19 9:23 ` [PATCH v2 4/5] target/avr: fix interrupt processing Pavel Dovgalyuk
2023-01-19 9:23 ` [PATCH v2 5/5] target/avr: enable icount mode Pavel Dovgalyuk
4 siblings, 2 replies; 13+ messages in thread
From: Pavel Dovgalyuk @ 2023-01-19 9:22 UTC (permalink / raw)
To: qemu-devel; +Cc: pavel.dovgalyuk, mrolnik, philmd, richard.henderson
Bit vector for features has 64 bits. This patch fixes bit shifts in
avr_feature and set_avr_feature functions to be 64-bit too.
Signed-off-by: Pavel Dovgalyuk <Pavel.Dovgalyuk@ispras.ru>
Reviewed-by: Michael Rolnik <mrolnik@gmail.com>
---
target/avr/cpu.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/target/avr/cpu.h b/target/avr/cpu.h
index 7c3895b65e..280edc495b 100644
--- a/target/avr/cpu.h
+++ b/target/avr/cpu.h
@@ -166,12 +166,12 @@ vaddr avr_cpu_gdb_adjust_breakpoint(CPUState *cpu, vaddr addr);
static inline int avr_feature(CPUAVRState *env, AVRFeature feature)
{
- return (env->features & (1U << feature)) != 0;
+ return (env->features & (1ULL << feature)) != 0;
}
static inline void set_avr_feature(CPUAVRState *env, int feature)
{
- env->features |= (1U << feature);
+ env->features |= (1ULL << feature);
}
#define cpu_list avr_cpu_list
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH v2 4/5] target/avr: fix interrupt processing
2023-01-19 9:22 [PATCH v2 0/5] AVR target fixes Pavel Dovgalyuk
` (2 preceding siblings ...)
2023-01-19 9:22 ` [PATCH v2 3/5] target/avr: fix avr features processing Pavel Dovgalyuk
@ 2023-01-19 9:23 ` Pavel Dovgalyuk
2023-01-19 10:09 ` Philippe Mathieu-Daudé
2023-01-19 18:26 ` Richard Henderson
2023-01-19 9:23 ` [PATCH v2 5/5] target/avr: enable icount mode Pavel Dovgalyuk
4 siblings, 2 replies; 13+ messages in thread
From: Pavel Dovgalyuk @ 2023-01-19 9:23 UTC (permalink / raw)
To: qemu-devel; +Cc: pavel.dovgalyuk, mrolnik, philmd, richard.henderson
Interrupt bit vector has 64 bits, but interrupt vector is found with ctz32
function. This patch replaces it with ctz64.
Signed-off-by: Pavel Dovgalyuk <Pavel.Dovgalyuk@ispras.ru>
---
target/avr/helper.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/target/avr/helper.c b/target/avr/helper.c
index 156dde4e92..61ab6feb25 100644
--- a/target/avr/helper.c
+++ b/target/avr/helper.c
@@ -51,7 +51,7 @@ bool avr_cpu_exec_interrupt(CPUState *cs, int interrupt_request)
}
if (interrupt_request & CPU_INTERRUPT_HARD) {
if (cpu_interrupts_enabled(env) && env->intsrc != 0) {
- int index = ctz32(env->intsrc);
+ int index = ctz64(env->intsrc);
cs->exception_index = EXCP_INT(index);
avr_cpu_do_interrupt(cs);
@@ -78,7 +78,7 @@ void avr_cpu_do_interrupt(CPUState *cs)
if (cs->exception_index == EXCP_RESET) {
vector = 0;
} else if (env->intsrc != 0) {
- vector = ctz32(env->intsrc) + 1;
+ vector = ctz64(env->intsrc) + 1;
}
if (avr_feature(env, AVR_FEATURE_3_BYTE_PC)) {
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH v2 5/5] target/avr: enable icount mode
2023-01-19 9:22 [PATCH v2 0/5] AVR target fixes Pavel Dovgalyuk
` (3 preceding siblings ...)
2023-01-19 9:23 ` [PATCH v2 4/5] target/avr: fix interrupt processing Pavel Dovgalyuk
@ 2023-01-19 9:23 ` Pavel Dovgalyuk
2023-01-19 18:28 ` Richard Henderson
4 siblings, 1 reply; 13+ messages in thread
From: Pavel Dovgalyuk @ 2023-01-19 9:23 UTC (permalink / raw)
To: qemu-devel; +Cc: pavel.dovgalyuk, mrolnik, philmd, richard.henderson
Icount mode requires correct can_do_io flag management for checking
that IO operations are performed only in the last TB instruction.
This patch sets this flag before every helper which can lead to
virtual hardware access. It enables deterministic execution
in icount mode for AVR.
Signed-off-by: Pavel Dovgalyuk <Pavel.Dovgalyuk@ispras.ru>
---
target/avr/translate.c | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/target/avr/translate.c b/target/avr/translate.c
index 40b15d116e..ee137dfe54 100644
--- a/target/avr/translate.c
+++ b/target/avr/translate.c
@@ -1406,6 +1406,10 @@ static bool trans_SBIC(DisasContext *ctx, arg_SBIC *a)
{
TCGv temp = tcg_const_i32(a->reg);
+ if (tb_cflags(ctx->base.tb) & CF_USE_ICOUNT) {
+ gen_io_start();
+ }
+
gen_helper_inb(temp, cpu_env, temp);
tcg_gen_andi_tl(temp, temp, 1 << a->bit);
ctx->skip_cond = TCG_COND_EQ;
@@ -1424,6 +1428,10 @@ static bool trans_SBIS(DisasContext *ctx, arg_SBIS *a)
{
TCGv temp = tcg_const_i32(a->reg);
+ if (tb_cflags(ctx->base.tb) & CF_USE_ICOUNT) {
+ gen_io_start();
+ }
+
gen_helper_inb(temp, cpu_env, temp);
tcg_gen_andi_tl(temp, temp, 1 << a->bit);
ctx->skip_cond = TCG_COND_NE;
@@ -1621,6 +1629,9 @@ static TCGv gen_get_zaddr(DisasContext *ctx, bool ram)
static void gen_data_store(DisasContext *ctx, TCGv data, TCGv addr)
{
if (ctx->base.tb->flags & TB_FLAGS_FULL_ACCESS) {
+ if (tb_cflags(ctx->base.tb) & CF_USE_ICOUNT) {
+ gen_io_start();
+ }
gen_helper_fullwr(cpu_env, data, addr);
} else {
tcg_gen_qemu_st8(data, addr, MMU_DATA_IDX); /* mem[addr] = data */
@@ -1630,6 +1641,9 @@ static void gen_data_store(DisasContext *ctx, TCGv data, TCGv addr)
static void gen_data_load(DisasContext *ctx, TCGv data, TCGv addr)
{
if (ctx->base.tb->flags & TB_FLAGS_FULL_ACCESS) {
+ if (tb_cflags(ctx->base.tb) & CF_USE_ICOUNT) {
+ gen_io_start();
+ }
gen_helper_fullrd(data, cpu_env, addr);
} else {
tcg_gen_qemu_ld8u(data, addr, MMU_DATA_IDX); /* data = mem[addr] */
@@ -2335,6 +2349,10 @@ static bool trans_IN(DisasContext *ctx, arg_IN *a)
TCGv Rd = cpu_r[a->rd];
TCGv port = tcg_const_i32(a->imm);
+ if (tb_cflags(ctx->base.tb) & CF_USE_ICOUNT) {
+ gen_io_start();
+ }
+
gen_helper_inb(Rd, cpu_env, port);
tcg_temp_free_i32(port);
@@ -2351,6 +2369,10 @@ static bool trans_OUT(DisasContext *ctx, arg_OUT *a)
TCGv Rd = cpu_r[a->rd];
TCGv port = tcg_const_i32(a->imm);
+ if (tb_cflags(ctx->base.tb) & CF_USE_ICOUNT) {
+ gen_io_start();
+ }
+
gen_helper_outb(cpu_env, port, Rd);
tcg_temp_free_i32(port);
@@ -2651,6 +2673,10 @@ static bool trans_SBI(DisasContext *ctx, arg_SBI *a)
TCGv data = tcg_temp_new_i32();
TCGv port = tcg_const_i32(a->reg);
+ if (tb_cflags(ctx->base.tb) & CF_USE_ICOUNT) {
+ gen_io_start();
+ }
+
gen_helper_inb(data, cpu_env, port);
tcg_gen_ori_tl(data, data, 1 << a->bit);
gen_helper_outb(cpu_env, port, data);
@@ -2670,6 +2696,10 @@ static bool trans_CBI(DisasContext *ctx, arg_CBI *a)
TCGv data = tcg_temp_new_i32();
TCGv port = tcg_const_i32(a->reg);
+ if (tb_cflags(ctx->base.tb) & CF_USE_ICOUNT) {
+ gen_io_start();
+ }
+
gen_helper_inb(data, cpu_env, port);
tcg_gen_andi_tl(data, data, ~(1 << a->bit));
gen_helper_outb(cpu_env, port, data);
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH v2 3/5] target/avr: fix avr features processing
2023-01-19 9:22 ` [PATCH v2 3/5] target/avr: fix avr features processing Pavel Dovgalyuk
@ 2023-01-19 10:09 ` Philippe Mathieu-Daudé
2023-01-19 18:25 ` Richard Henderson
1 sibling, 0 replies; 13+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-01-19 10:09 UTC (permalink / raw)
To: Pavel Dovgalyuk, qemu-devel; +Cc: mrolnik, richard.henderson
On 19/1/23 10:22, Pavel Dovgalyuk wrote:
> Bit vector for features has 64 bits. This patch fixes bit shifts in
> avr_feature and set_avr_feature functions to be 64-bit too.
>
> Signed-off-by: Pavel Dovgalyuk <Pavel.Dovgalyuk@ispras.ru>
> Reviewed-by: Michael Rolnik <mrolnik@gmail.com>
> ---
> target/avr/cpu.h | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/target/avr/cpu.h b/target/avr/cpu.h
> index 7c3895b65e..280edc495b 100644
> --- a/target/avr/cpu.h
> +++ b/target/avr/cpu.h
> @@ -166,12 +166,12 @@ vaddr avr_cpu_gdb_adjust_breakpoint(CPUState *cpu, vaddr addr);
>
> static inline int avr_feature(CPUAVRState *env, AVRFeature feature)
> {
> - return (env->features & (1U << feature)) != 0;
> + return (env->features & (1ULL << feature)) != 0;
> }
>
> static inline void set_avr_feature(CPUAVRState *env, int feature)
> {
> - env->features |= (1U << feature);
> + env->features |= (1ULL << feature);
> }
Consider using extract64() or BIT_ULL(). Regardless:
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 4/5] target/avr: fix interrupt processing
2023-01-19 9:23 ` [PATCH v2 4/5] target/avr: fix interrupt processing Pavel Dovgalyuk
@ 2023-01-19 10:09 ` Philippe Mathieu-Daudé
2023-01-19 18:26 ` Richard Henderson
1 sibling, 0 replies; 13+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-01-19 10:09 UTC (permalink / raw)
To: Pavel Dovgalyuk, qemu-devel; +Cc: mrolnik, richard.henderson
On 19/1/23 10:23, Pavel Dovgalyuk wrote:
> Interrupt bit vector has 64 bits, but interrupt vector is found with ctz32
> function. This patch replaces it with ctz64.
>
> Signed-off-by: Pavel Dovgalyuk <Pavel.Dovgalyuk@ispras.ru>
> ---
> target/avr/helper.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 3/5] target/avr: fix avr features processing
2023-01-19 9:22 ` [PATCH v2 3/5] target/avr: fix avr features processing Pavel Dovgalyuk
2023-01-19 10:09 ` Philippe Mathieu-Daudé
@ 2023-01-19 18:25 ` Richard Henderson
1 sibling, 0 replies; 13+ messages in thread
From: Richard Henderson @ 2023-01-19 18:25 UTC (permalink / raw)
To: Pavel Dovgalyuk, qemu-devel; +Cc: mrolnik, philmd
On 1/18/23 23:22, Pavel Dovgalyuk wrote:
> Bit vector for features has 64 bits. This patch fixes bit shifts in
> avr_feature and set_avr_feature functions to be 64-bit too.
>
> Signed-off-by: Pavel Dovgalyuk<Pavel.Dovgalyuk@ispras.ru>
> Reviewed-by: Michael Rolnik<mrolnik@gmail.com>
> ---
> target/avr/cpu.h | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 4/5] target/avr: fix interrupt processing
2023-01-19 9:23 ` [PATCH v2 4/5] target/avr: fix interrupt processing Pavel Dovgalyuk
2023-01-19 10:09 ` Philippe Mathieu-Daudé
@ 2023-01-19 18:26 ` Richard Henderson
1 sibling, 0 replies; 13+ messages in thread
From: Richard Henderson @ 2023-01-19 18:26 UTC (permalink / raw)
To: Pavel Dovgalyuk, qemu-devel; +Cc: mrolnik, philmd
On 1/18/23 23:23, Pavel Dovgalyuk wrote:
> Interrupt bit vector has 64 bits, but interrupt vector is found with ctz32
> function. This patch replaces it with ctz64.
>
> Signed-off-by: Pavel Dovgalyuk<Pavel.Dovgalyuk@ispras.ru>
> ---
> target/avr/helper.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 5/5] target/avr: enable icount mode
2023-01-19 9:23 ` [PATCH v2 5/5] target/avr: enable icount mode Pavel Dovgalyuk
@ 2023-01-19 18:28 ` Richard Henderson
0 siblings, 0 replies; 13+ messages in thread
From: Richard Henderson @ 2023-01-19 18:28 UTC (permalink / raw)
To: Pavel Dovgalyuk, qemu-devel; +Cc: mrolnik, philmd
On 1/18/23 23:23, Pavel Dovgalyuk wrote:
> Icount mode requires correct can_do_io flag management for checking
> that IO operations are performed only in the last TB instruction.
> This patch sets this flag before every helper which can lead to
> virtual hardware access. It enables deterministic execution
> in icount mode for AVR.
>
> Signed-off-by: Pavel Dovgalyuk<Pavel.Dovgalyuk@ispras.ru>
> ---
> target/avr/translate.c | 30 ++++++++++++++++++++++++++++++
> 1 file changed, 30 insertions(+)
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 2/5] target/avr: implement small RAM/large RAM feature
2023-01-19 9:22 ` [PATCH v2 2/5] target/avr: implement small RAM/large RAM feature Pavel Dovgalyuk
@ 2023-01-19 18:29 ` Richard Henderson
0 siblings, 0 replies; 13+ messages in thread
From: Richard Henderson @ 2023-01-19 18:29 UTC (permalink / raw)
To: Pavel Dovgalyuk, qemu-devel; +Cc: mrolnik, philmd
On 1/18/23 23:22, Pavel Dovgalyuk wrote:
> translate.c functions use RAMPZ for RAM access. This register
> is also used for ROM reads. However, in MCUs with 64k RAM support
> RAMPZ is used for ROM only. Therefore when RAMPZ is set,
> addressing the RAM becomes incorrect in the emulator.
> This patch adds LARGE RAM feature which can be used in xmega controllers,
> that could be added later. For the currently supported MCUs this
> feature is disabled and RAMPZ is not used for RAM access.
>
> Signed-off-by: Pavel Dovgalyuk<Pavel.Dovgalyuk@ispras.ru>
> ---
> target/avr/cpu.h | 2 ++
> target/avr/translate.c | 63 ++++++++++++++++++++++++++++++------------------
> 2 files changed, 41 insertions(+), 24 deletions(-)
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v2 5/5] target/avr: enable icount mode
2023-01-24 7:12 [PATCH v2 0/5] AVR target fixes Pavel Dovgalyuk
@ 2023-01-24 7:12 ` Pavel Dovgalyuk
0 siblings, 0 replies; 13+ messages in thread
From: Pavel Dovgalyuk @ 2023-01-24 7:12 UTC (permalink / raw)
To: qemu-devel; +Cc: pavel.dovgalyuk, mrolnik, philmd, richard.henderson
Icount mode requires correct can_do_io flag management for checking
that IO operations are performed only in the last TB instruction.
This patch sets this flag before every helper which can lead to
virtual hardware access. It enables deterministic execution
in icount mode for AVR.
Signed-off-by: Pavel Dovgalyuk <Pavel.Dovgalyuk@ispras.ru>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
target/avr/translate.c | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/target/avr/translate.c b/target/avr/translate.c
index 40b15d116e..ee137dfe54 100644
--- a/target/avr/translate.c
+++ b/target/avr/translate.c
@@ -1406,6 +1406,10 @@ static bool trans_SBIC(DisasContext *ctx, arg_SBIC *a)
{
TCGv temp = tcg_const_i32(a->reg);
+ if (tb_cflags(ctx->base.tb) & CF_USE_ICOUNT) {
+ gen_io_start();
+ }
+
gen_helper_inb(temp, cpu_env, temp);
tcg_gen_andi_tl(temp, temp, 1 << a->bit);
ctx->skip_cond = TCG_COND_EQ;
@@ -1424,6 +1428,10 @@ static bool trans_SBIS(DisasContext *ctx, arg_SBIS *a)
{
TCGv temp = tcg_const_i32(a->reg);
+ if (tb_cflags(ctx->base.tb) & CF_USE_ICOUNT) {
+ gen_io_start();
+ }
+
gen_helper_inb(temp, cpu_env, temp);
tcg_gen_andi_tl(temp, temp, 1 << a->bit);
ctx->skip_cond = TCG_COND_NE;
@@ -1621,6 +1629,9 @@ static TCGv gen_get_zaddr(DisasContext *ctx, bool ram)
static void gen_data_store(DisasContext *ctx, TCGv data, TCGv addr)
{
if (ctx->base.tb->flags & TB_FLAGS_FULL_ACCESS) {
+ if (tb_cflags(ctx->base.tb) & CF_USE_ICOUNT) {
+ gen_io_start();
+ }
gen_helper_fullwr(cpu_env, data, addr);
} else {
tcg_gen_qemu_st8(data, addr, MMU_DATA_IDX); /* mem[addr] = data */
@@ -1630,6 +1641,9 @@ static void gen_data_store(DisasContext *ctx, TCGv data, TCGv addr)
static void gen_data_load(DisasContext *ctx, TCGv data, TCGv addr)
{
if (ctx->base.tb->flags & TB_FLAGS_FULL_ACCESS) {
+ if (tb_cflags(ctx->base.tb) & CF_USE_ICOUNT) {
+ gen_io_start();
+ }
gen_helper_fullrd(data, cpu_env, addr);
} else {
tcg_gen_qemu_ld8u(data, addr, MMU_DATA_IDX); /* data = mem[addr] */
@@ -2335,6 +2349,10 @@ static bool trans_IN(DisasContext *ctx, arg_IN *a)
TCGv Rd = cpu_r[a->rd];
TCGv port = tcg_const_i32(a->imm);
+ if (tb_cflags(ctx->base.tb) & CF_USE_ICOUNT) {
+ gen_io_start();
+ }
+
gen_helper_inb(Rd, cpu_env, port);
tcg_temp_free_i32(port);
@@ -2351,6 +2369,10 @@ static bool trans_OUT(DisasContext *ctx, arg_OUT *a)
TCGv Rd = cpu_r[a->rd];
TCGv port = tcg_const_i32(a->imm);
+ if (tb_cflags(ctx->base.tb) & CF_USE_ICOUNT) {
+ gen_io_start();
+ }
+
gen_helper_outb(cpu_env, port, Rd);
tcg_temp_free_i32(port);
@@ -2651,6 +2673,10 @@ static bool trans_SBI(DisasContext *ctx, arg_SBI *a)
TCGv data = tcg_temp_new_i32();
TCGv port = tcg_const_i32(a->reg);
+ if (tb_cflags(ctx->base.tb) & CF_USE_ICOUNT) {
+ gen_io_start();
+ }
+
gen_helper_inb(data, cpu_env, port);
tcg_gen_ori_tl(data, data, 1 << a->bit);
gen_helper_outb(cpu_env, port, data);
@@ -2670,6 +2696,10 @@ static bool trans_CBI(DisasContext *ctx, arg_CBI *a)
TCGv data = tcg_temp_new_i32();
TCGv port = tcg_const_i32(a->reg);
+ if (tb_cflags(ctx->base.tb) & CF_USE_ICOUNT) {
+ gen_io_start();
+ }
+
gen_helper_inb(data, cpu_env, port);
tcg_gen_andi_tl(data, data, ~(1 << a->bit));
gen_helper_outb(cpu_env, port, data);
^ permalink raw reply related [flat|nested] 13+ messages in thread
end of thread, other threads:[~2023-01-24 7:13 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-19 9:22 [PATCH v2 0/5] AVR target fixes Pavel Dovgalyuk
2023-01-19 9:22 ` [PATCH v2 1/5] target/avr: fix long address calculation Pavel Dovgalyuk
2023-01-19 9:22 ` [PATCH v2 2/5] target/avr: implement small RAM/large RAM feature Pavel Dovgalyuk
2023-01-19 18:29 ` Richard Henderson
2023-01-19 9:22 ` [PATCH v2 3/5] target/avr: fix avr features processing Pavel Dovgalyuk
2023-01-19 10:09 ` Philippe Mathieu-Daudé
2023-01-19 18:25 ` Richard Henderson
2023-01-19 9:23 ` [PATCH v2 4/5] target/avr: fix interrupt processing Pavel Dovgalyuk
2023-01-19 10:09 ` Philippe Mathieu-Daudé
2023-01-19 18:26 ` Richard Henderson
2023-01-19 9:23 ` [PATCH v2 5/5] target/avr: enable icount mode Pavel Dovgalyuk
2023-01-19 18:28 ` Richard Henderson
-- strict thread matches above, loose matches on Subject: below --
2023-01-24 7:12 [PATCH v2 0/5] AVR target fixes Pavel Dovgalyuk
2023-01-24 7:12 ` [PATCH v2 5/5] target/avr: enable icount mode Pavel Dovgalyuk
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).