xref: /openbmc/qemu/target/avr/helper.c (revision 873f9ca3857cfeeef45441b116c91156736d529c)
17ccda78fSMichael Rolnik /*
27ccda78fSMichael Rolnik  * QEMU AVR CPU helpers
37ccda78fSMichael Rolnik  *
47ccda78fSMichael Rolnik  * Copyright (c) 2016-2020 Michael Rolnik
57ccda78fSMichael Rolnik  *
67ccda78fSMichael Rolnik  * This library is free software; you can redistribute it and/or
77ccda78fSMichael Rolnik  * modify it under the terms of the GNU Lesser General Public
87ccda78fSMichael Rolnik  * License as published by the Free Software Foundation; either
97ccda78fSMichael Rolnik  * version 2.1 of the License, or (at your option) any later version.
107ccda78fSMichael Rolnik  *
117ccda78fSMichael Rolnik  * This library is distributed in the hope that it will be useful,
127ccda78fSMichael Rolnik  * but WITHOUT ANY WARRANTY; without even the implied warranty of
137ccda78fSMichael Rolnik  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
147ccda78fSMichael Rolnik  * Lesser General Public License for more details.
157ccda78fSMichael Rolnik  *
167ccda78fSMichael Rolnik  * You should have received a copy of the GNU Lesser General Public
177ccda78fSMichael Rolnik  * License along with this library; if not, see
187ccda78fSMichael Rolnik  * <http://www.gnu.org/licenses/lgpl-2.1.html>
197ccda78fSMichael Rolnik  */
207ccda78fSMichael Rolnik 
217ccda78fSMichael Rolnik #include "qemu/osdep.h"
22cd617484SPhilippe Mathieu-Daudé #include "qemu/log.h"
23acf2f859SRichard Henderson #include "qemu/error-report.h"
247ccda78fSMichael Rolnik #include "cpu.h"
2578271684SClaudio Fontana #include "hw/core/tcg-cpu-ops.h"
267ccda78fSMichael Rolnik #include "exec/exec-all.h"
27*74781c08SPhilippe Mathieu-Daudé #include "exec/page-protection.h"
2809b07f28SPhilippe Mathieu-Daudé #include "exec/cpu_ldst.h"
2984a71e9aSMichael Rolnik #include "exec/address-spaces.h"
307ccda78fSMichael Rolnik #include "exec/helper-proto.h"
317ccda78fSMichael Rolnik 
avr_cpu_exec_interrupt(CPUState * cs,int interrupt_request)327ccda78fSMichael Rolnik bool avr_cpu_exec_interrupt(CPUState *cs, int interrupt_request)
337ccda78fSMichael Rolnik {
342db5b94dSPhilippe Mathieu-Daudé     CPUAVRState *env = cpu_env(cs);
357ccda78fSMichael Rolnik 
3636027c70SRichard Henderson     /*
3736027c70SRichard Henderson      * We cannot separate a skip from the next instruction,
3836027c70SRichard Henderson      * as the skip would not be preserved across the interrupt.
3936027c70SRichard Henderson      * Separating the two insn normally only happens at page boundaries.
4036027c70SRichard Henderson      */
4136027c70SRichard Henderson     if (env->skip) {
4236027c70SRichard Henderson         return false;
4336027c70SRichard Henderson     }
4436027c70SRichard Henderson 
457ccda78fSMichael Rolnik     if (interrupt_request & CPU_INTERRUPT_RESET) {
467ccda78fSMichael Rolnik         if (cpu_interrupts_enabled(env)) {
477ccda78fSMichael Rolnik             cs->exception_index = EXCP_RESET;
489e1b2375SRichard Henderson             avr_cpu_do_interrupt(cs);
497ccda78fSMichael Rolnik 
507ccda78fSMichael Rolnik             cs->interrupt_request &= ~CPU_INTERRUPT_RESET;
51cecaad54SRichard Henderson             return true;
527ccda78fSMichael Rolnik         }
537ccda78fSMichael Rolnik     }
547ccda78fSMichael Rolnik     if (interrupt_request & CPU_INTERRUPT_HARD) {
557ccda78fSMichael Rolnik         if (cpu_interrupts_enabled(env) && env->intsrc != 0) {
56fc97167fSLucas Dietrich             int index = ctz64(env->intsrc);
577ccda78fSMichael Rolnik             cs->exception_index = EXCP_INT(index);
589e1b2375SRichard Henderson             avr_cpu_do_interrupt(cs);
597ccda78fSMichael Rolnik 
607ccda78fSMichael Rolnik             env->intsrc &= env->intsrc - 1; /* clear the interrupt */
6156b90e60SIvanov Arkasha             if (!env->intsrc) {
627ccda78fSMichael Rolnik                 cs->interrupt_request &= ~CPU_INTERRUPT_HARD;
6356b90e60SIvanov Arkasha             }
64cecaad54SRichard Henderson             return true;
657ccda78fSMichael Rolnik         }
667ccda78fSMichael Rolnik     }
67cecaad54SRichard Henderson     return false;
687ccda78fSMichael Rolnik }
697ccda78fSMichael Rolnik 
avr_cpu_do_interrupt(CPUState * cs)707ccda78fSMichael Rolnik void avr_cpu_do_interrupt(CPUState *cs)
717ccda78fSMichael Rolnik {
722db5b94dSPhilippe Mathieu-Daudé     CPUAVRState *env = cpu_env(cs);
737ccda78fSMichael Rolnik 
747ccda78fSMichael Rolnik     uint32_t ret = env->pc_w;
757ccda78fSMichael Rolnik     int vector = 0;
767ccda78fSMichael Rolnik     int size = avr_feature(env, AVR_FEATURE_JMP_CALL) ? 2 : 1;
777ccda78fSMichael Rolnik     int base = 0;
787ccda78fSMichael Rolnik 
797ccda78fSMichael Rolnik     if (cs->exception_index == EXCP_RESET) {
807ccda78fSMichael Rolnik         vector = 0;
817ccda78fSMichael Rolnik     } else if (env->intsrc != 0) {
82fc97167fSLucas Dietrich         vector = ctz64(env->intsrc) + 1;
837ccda78fSMichael Rolnik     }
847ccda78fSMichael Rolnik 
857ccda78fSMichael Rolnik     if (avr_feature(env, AVR_FEATURE_3_BYTE_PC)) {
867ccda78fSMichael Rolnik         cpu_stb_data(env, env->sp--, (ret & 0x0000ff));
877ccda78fSMichael Rolnik         cpu_stb_data(env, env->sp--, (ret & 0x00ff00) >> 8);
887ccda78fSMichael Rolnik         cpu_stb_data(env, env->sp--, (ret & 0xff0000) >> 16);
897ccda78fSMichael Rolnik     } else if (avr_feature(env, AVR_FEATURE_2_BYTE_PC)) {
907ccda78fSMichael Rolnik         cpu_stb_data(env, env->sp--, (ret & 0x0000ff));
917ccda78fSMichael Rolnik         cpu_stb_data(env, env->sp--, (ret & 0x00ff00) >> 8);
927ccda78fSMichael Rolnik     } else {
937ccda78fSMichael Rolnik         cpu_stb_data(env, env->sp--, (ret & 0x0000ff));
947ccda78fSMichael Rolnik     }
957ccda78fSMichael Rolnik 
967ccda78fSMichael Rolnik     env->pc_w = base + vector * size;
977ccda78fSMichael Rolnik     env->sregI = 0; /* clear Global Interrupt Flag */
987ccda78fSMichael Rolnik 
997ccda78fSMichael Rolnik     cs->exception_index = -1;
1007ccda78fSMichael Rolnik }
101e2a2b0b9SMichael Rolnik 
avr_cpu_get_phys_page_debug(CPUState * cs,vaddr addr)102e2a2b0b9SMichael Rolnik hwaddr avr_cpu_get_phys_page_debug(CPUState *cs, vaddr addr)
103e2a2b0b9SMichael Rolnik {
1042e35dfb6SLichang Zhao     return addr; /* I assume 1:1 address correspondence */
105e2a2b0b9SMichael Rolnik }
106e2a2b0b9SMichael Rolnik 
avr_cpu_tlb_fill(CPUState * cs,vaddr address,int size,MMUAccessType access_type,int mmu_idx,bool probe,uintptr_t retaddr)107e2a2b0b9SMichael Rolnik bool avr_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
108e2a2b0b9SMichael Rolnik                       MMUAccessType access_type, int mmu_idx,
109e2a2b0b9SMichael Rolnik                       bool probe, uintptr_t retaddr)
110e2a2b0b9SMichael Rolnik {
1117bccb9e3SRichard Henderson     int prot, page_size = TARGET_PAGE_SIZE;
112e2a2b0b9SMichael Rolnik     uint32_t paddr;
113e2a2b0b9SMichael Rolnik 
114e2a2b0b9SMichael Rolnik     address &= TARGET_PAGE_MASK;
115e2a2b0b9SMichael Rolnik 
116e2a2b0b9SMichael Rolnik     if (mmu_idx == MMU_CODE_IDX) {
1177bccb9e3SRichard Henderson         /* Access to code in flash. */
118e2a2b0b9SMichael Rolnik         paddr = OFFSET_CODE + address;
119e2a2b0b9SMichael Rolnik         prot = PAGE_READ | PAGE_EXEC;
1207bccb9e3SRichard Henderson         if (paddr >= OFFSET_DATA) {
1217bccb9e3SRichard Henderson             /*
1227bccb9e3SRichard Henderson              * This should not be possible via any architectural operations.
1237bccb9e3SRichard Henderson              * There is certainly not an exception that we can deliver.
1247bccb9e3SRichard Henderson              * Accept probing that might come from generic code.
1257bccb9e3SRichard Henderson              */
1267bccb9e3SRichard Henderson             if (probe) {
1277bccb9e3SRichard Henderson                 return false;
1287bccb9e3SRichard Henderson             }
129e2a2b0b9SMichael Rolnik             error_report("execution left flash memory");
130e2a2b0b9SMichael Rolnik             abort();
131e2a2b0b9SMichael Rolnik         }
1327bccb9e3SRichard Henderson     } else {
1337bccb9e3SRichard Henderson         /* Access to memory. */
1347bccb9e3SRichard Henderson         paddr = OFFSET_DATA + address;
1357bccb9e3SRichard Henderson         prot = PAGE_READ | PAGE_WRITE;
1367bccb9e3SRichard Henderson         if (address < NUMBER_OF_CPU_REGISTERS + NUMBER_OF_IO_REGISTERS) {
137e2a2b0b9SMichael Rolnik             /*
1387bccb9e3SRichard Henderson              * Access to CPU registers, exit and rebuilt this TB to use
1397bccb9e3SRichard Henderson              * full access in case it touches specially handled registers
1407bccb9e3SRichard Henderson              * like SREG or SP.  For probing, set page_size = 1, in order
1417bccb9e3SRichard Henderson              * to force tlb_fill to be called for the next access.
142e2a2b0b9SMichael Rolnik              */
1437bccb9e3SRichard Henderson             if (probe) {
1447bccb9e3SRichard Henderson                 page_size = 1;
1457bccb9e3SRichard Henderson             } else {
1462db5b94dSPhilippe Mathieu-Daudé                 cpu_env(cs)->fullacc = 1;
147e2a2b0b9SMichael Rolnik                 cpu_loop_exit_restore(cs, retaddr);
1487bccb9e3SRichard Henderson             }
1497bccb9e3SRichard Henderson         }
150e2a2b0b9SMichael Rolnik     }
151e2a2b0b9SMichael Rolnik 
1527bccb9e3SRichard Henderson     tlb_set_page(cs, address, paddr, prot, mmu_idx, page_size);
153e2a2b0b9SMichael Rolnik     return true;
154e2a2b0b9SMichael Rolnik }
15584a71e9aSMichael Rolnik 
15684a71e9aSMichael Rolnik /*
15784a71e9aSMichael Rolnik  *  helpers
15884a71e9aSMichael Rolnik  */
15984a71e9aSMichael Rolnik 
helper_sleep(CPUAVRState * env)16084a71e9aSMichael Rolnik void helper_sleep(CPUAVRState *env)
16184a71e9aSMichael Rolnik {
16284a71e9aSMichael Rolnik     CPUState *cs = env_cpu(env);
16384a71e9aSMichael Rolnik 
16484a71e9aSMichael Rolnik     cs->exception_index = EXCP_HLT;
16584a71e9aSMichael Rolnik     cpu_loop_exit(cs);
16684a71e9aSMichael Rolnik }
16784a71e9aSMichael Rolnik 
helper_unsupported(CPUAVRState * env)16884a71e9aSMichael Rolnik void helper_unsupported(CPUAVRState *env)
16984a71e9aSMichael Rolnik {
17084a71e9aSMichael Rolnik     CPUState *cs = env_cpu(env);
17184a71e9aSMichael Rolnik 
17284a71e9aSMichael Rolnik     /*
17384a71e9aSMichael Rolnik      *  I count not find what happens on the real platform, so
17484a71e9aSMichael Rolnik      *  it's EXCP_DEBUG for meanwhile
17584a71e9aSMichael Rolnik      */
17684a71e9aSMichael Rolnik     cs->exception_index = EXCP_DEBUG;
17784a71e9aSMichael Rolnik     if (qemu_loglevel_mask(LOG_UNIMP)) {
17884a71e9aSMichael Rolnik         qemu_log("UNSUPPORTED\n");
17984a71e9aSMichael Rolnik         cpu_dump_state(cs, stderr, 0);
18084a71e9aSMichael Rolnik     }
18184a71e9aSMichael Rolnik     cpu_loop_exit(cs);
18284a71e9aSMichael Rolnik }
18384a71e9aSMichael Rolnik 
helper_debug(CPUAVRState * env)18484a71e9aSMichael Rolnik void helper_debug(CPUAVRState *env)
18584a71e9aSMichael Rolnik {
18684a71e9aSMichael Rolnik     CPUState *cs = env_cpu(env);
18784a71e9aSMichael Rolnik 
18884a71e9aSMichael Rolnik     cs->exception_index = EXCP_DEBUG;
18984a71e9aSMichael Rolnik     cpu_loop_exit(cs);
19084a71e9aSMichael Rolnik }
19184a71e9aSMichael Rolnik 
helper_break(CPUAVRState * env)19284a71e9aSMichael Rolnik void helper_break(CPUAVRState *env)
19384a71e9aSMichael Rolnik {
19484a71e9aSMichael Rolnik     CPUState *cs = env_cpu(env);
19584a71e9aSMichael Rolnik 
19684a71e9aSMichael Rolnik     cs->exception_index = EXCP_DEBUG;
19784a71e9aSMichael Rolnik     cpu_loop_exit(cs);
19884a71e9aSMichael Rolnik }
19984a71e9aSMichael Rolnik 
helper_wdr(CPUAVRState * env)20084a71e9aSMichael Rolnik void helper_wdr(CPUAVRState *env)
20184a71e9aSMichael Rolnik {
20229f9c636SPhilippe Mathieu-Daudé     qemu_log_mask(LOG_UNIMP, "WDG reset (not implemented)\n");
20384a71e9aSMichael Rolnik }
20484a71e9aSMichael Rolnik 
20584a71e9aSMichael Rolnik /*
20684a71e9aSMichael Rolnik  * This function implements IN instruction
20784a71e9aSMichael Rolnik  *
20884a71e9aSMichael Rolnik  * It does the following
20984a71e9aSMichael Rolnik  * a.  if an IO register belongs to CPU, its value is read and returned
21084a71e9aSMichael Rolnik  * b.  otherwise io address is translated to mem address and physical memory
21184a71e9aSMichael Rolnik  *     is read.
21284a71e9aSMichael Rolnik  * c.  it caches the value for sake of SBI, SBIC, SBIS & CBI implementation
21384a71e9aSMichael Rolnik  *
21484a71e9aSMichael Rolnik  */
helper_inb(CPUAVRState * env,uint32_t port)21584a71e9aSMichael Rolnik target_ulong helper_inb(CPUAVRState *env, uint32_t port)
21684a71e9aSMichael Rolnik {
21784a71e9aSMichael Rolnik     target_ulong data = 0;
21884a71e9aSMichael Rolnik 
21984a71e9aSMichael Rolnik     switch (port) {
22084a71e9aSMichael Rolnik     case 0x38: /* RAMPD */
22184a71e9aSMichael Rolnik         data = 0xff & (env->rampD >> 16);
22284a71e9aSMichael Rolnik         break;
22384a71e9aSMichael Rolnik     case 0x39: /* RAMPX */
22484a71e9aSMichael Rolnik         data = 0xff & (env->rampX >> 16);
22584a71e9aSMichael Rolnik         break;
22684a71e9aSMichael Rolnik     case 0x3a: /* RAMPY */
22784a71e9aSMichael Rolnik         data = 0xff & (env->rampY >> 16);
22884a71e9aSMichael Rolnik         break;
22984a71e9aSMichael Rolnik     case 0x3b: /* RAMPZ */
23084a71e9aSMichael Rolnik         data = 0xff & (env->rampZ >> 16);
23184a71e9aSMichael Rolnik         break;
23284a71e9aSMichael Rolnik     case 0x3c: /* EIND */
23384a71e9aSMichael Rolnik         data = 0xff & (env->eind >> 16);
23484a71e9aSMichael Rolnik         break;
23584a71e9aSMichael Rolnik     case 0x3d: /* SPL */
23684a71e9aSMichael Rolnik         data = env->sp & 0x00ff;
23784a71e9aSMichael Rolnik         break;
23884a71e9aSMichael Rolnik     case 0x3e: /* SPH */
23984a71e9aSMichael Rolnik         data = env->sp >> 8;
24084a71e9aSMichael Rolnik         break;
24184a71e9aSMichael Rolnik     case 0x3f: /* SREG */
24284a71e9aSMichael Rolnik         data = cpu_get_sreg(env);
24384a71e9aSMichael Rolnik         break;
24484a71e9aSMichael Rolnik     default:
24584a71e9aSMichael Rolnik         /* not a special register, pass to normal memory access */
24684a71e9aSMichael Rolnik         data = address_space_ldub(&address_space_memory,
24784a71e9aSMichael Rolnik                                   OFFSET_IO_REGISTERS + port,
24884a71e9aSMichael Rolnik                                   MEMTXATTRS_UNSPECIFIED, NULL);
24984a71e9aSMichael Rolnik     }
25084a71e9aSMichael Rolnik 
25184a71e9aSMichael Rolnik     return data;
25284a71e9aSMichael Rolnik }
25384a71e9aSMichael Rolnik 
25484a71e9aSMichael Rolnik /*
25584a71e9aSMichael Rolnik  *  This function implements OUT instruction
25684a71e9aSMichael Rolnik  *
25784a71e9aSMichael Rolnik  *  It does the following
25884a71e9aSMichael Rolnik  *  a.  if an IO register belongs to CPU, its value is written into the register
25984a71e9aSMichael Rolnik  *  b.  otherwise io address is translated to mem address and physical memory
26084a71e9aSMichael Rolnik  *      is written.
26184a71e9aSMichael Rolnik  *  c.  it caches the value for sake of SBI, SBIC, SBIS & CBI implementation
26284a71e9aSMichael Rolnik  *
26384a71e9aSMichael Rolnik  */
helper_outb(CPUAVRState * env,uint32_t port,uint32_t data)26484a71e9aSMichael Rolnik void helper_outb(CPUAVRState *env, uint32_t port, uint32_t data)
26584a71e9aSMichael Rolnik {
26684a71e9aSMichael Rolnik     data &= 0x000000ff;
26784a71e9aSMichael Rolnik 
26884a71e9aSMichael Rolnik     switch (port) {
26984a71e9aSMichael Rolnik     case 0x38: /* RAMPD */
27084a71e9aSMichael Rolnik         if (avr_feature(env, AVR_FEATURE_RAMPD)) {
27184a71e9aSMichael Rolnik             env->rampD = (data & 0xff) << 16;
27284a71e9aSMichael Rolnik         }
27384a71e9aSMichael Rolnik         break;
27484a71e9aSMichael Rolnik     case 0x39: /* RAMPX */
27584a71e9aSMichael Rolnik         if (avr_feature(env, AVR_FEATURE_RAMPX)) {
27684a71e9aSMichael Rolnik             env->rampX = (data & 0xff) << 16;
27784a71e9aSMichael Rolnik         }
27884a71e9aSMichael Rolnik         break;
27984a71e9aSMichael Rolnik     case 0x3a: /* RAMPY */
28084a71e9aSMichael Rolnik         if (avr_feature(env, AVR_FEATURE_RAMPY)) {
28184a71e9aSMichael Rolnik             env->rampY = (data & 0xff) << 16;
28284a71e9aSMichael Rolnik         }
28384a71e9aSMichael Rolnik         break;
28484a71e9aSMichael Rolnik     case 0x3b: /* RAMPZ */
28584a71e9aSMichael Rolnik         if (avr_feature(env, AVR_FEATURE_RAMPZ)) {
28684a71e9aSMichael Rolnik             env->rampZ = (data & 0xff) << 16;
28784a71e9aSMichael Rolnik         }
28884a71e9aSMichael Rolnik         break;
28984a71e9aSMichael Rolnik     case 0x3c: /* EIDN */
29084a71e9aSMichael Rolnik         env->eind = (data & 0xff) << 16;
29184a71e9aSMichael Rolnik         break;
29284a71e9aSMichael Rolnik     case 0x3d: /* SPL */
29384a71e9aSMichael Rolnik         env->sp = (env->sp & 0xff00) | (data);
29484a71e9aSMichael Rolnik         break;
29584a71e9aSMichael Rolnik     case 0x3e: /* SPH */
29684a71e9aSMichael Rolnik         if (avr_feature(env, AVR_FEATURE_2_BYTE_SP)) {
29784a71e9aSMichael Rolnik             env->sp = (env->sp & 0x00ff) | (data << 8);
29884a71e9aSMichael Rolnik         }
29984a71e9aSMichael Rolnik         break;
30084a71e9aSMichael Rolnik     case 0x3f: /* SREG */
30184a71e9aSMichael Rolnik         cpu_set_sreg(env, data);
30284a71e9aSMichael Rolnik         break;
30384a71e9aSMichael Rolnik     default:
30484a71e9aSMichael Rolnik         /* not a special register, pass to normal memory access */
30584a71e9aSMichael Rolnik         address_space_stb(&address_space_memory, OFFSET_IO_REGISTERS + port,
30684a71e9aSMichael Rolnik                           data, MEMTXATTRS_UNSPECIFIED, NULL);
30784a71e9aSMichael Rolnik     }
30884a71e9aSMichael Rolnik }
30984a71e9aSMichael Rolnik 
31084a71e9aSMichael Rolnik /*
3112e35dfb6SLichang Zhao  *  this function implements LD instruction when there is a possibility to read
31284a71e9aSMichael Rolnik  *  from a CPU register
31384a71e9aSMichael Rolnik  */
helper_fullrd(CPUAVRState * env,uint32_t addr)31484a71e9aSMichael Rolnik target_ulong helper_fullrd(CPUAVRState *env, uint32_t addr)
31584a71e9aSMichael Rolnik {
31684a71e9aSMichael Rolnik     uint8_t data;
31784a71e9aSMichael Rolnik 
31884a71e9aSMichael Rolnik     env->fullacc = false;
31984a71e9aSMichael Rolnik 
32084a71e9aSMichael Rolnik     if (addr < NUMBER_OF_CPU_REGISTERS) {
32184a71e9aSMichael Rolnik         /* CPU registers */
32284a71e9aSMichael Rolnik         data = env->r[addr];
32384a71e9aSMichael Rolnik     } else if (addr < NUMBER_OF_CPU_REGISTERS + NUMBER_OF_IO_REGISTERS) {
32484a71e9aSMichael Rolnik         /* IO registers */
32584a71e9aSMichael Rolnik         data = helper_inb(env, addr - NUMBER_OF_CPU_REGISTERS);
32684a71e9aSMichael Rolnik     } else {
32784a71e9aSMichael Rolnik         /* memory */
32884a71e9aSMichael Rolnik         data = address_space_ldub(&address_space_memory, OFFSET_DATA + addr,
32984a71e9aSMichael Rolnik                                   MEMTXATTRS_UNSPECIFIED, NULL);
33084a71e9aSMichael Rolnik     }
33184a71e9aSMichael Rolnik     return data;
33284a71e9aSMichael Rolnik }
33384a71e9aSMichael Rolnik 
33484a71e9aSMichael Rolnik /*
3352e35dfb6SLichang Zhao  *  this function implements ST instruction when there is a possibility to write
33684a71e9aSMichael Rolnik  *  into a CPU register
33784a71e9aSMichael Rolnik  */
helper_fullwr(CPUAVRState * env,uint32_t data,uint32_t addr)33884a71e9aSMichael Rolnik void helper_fullwr(CPUAVRState *env, uint32_t data, uint32_t addr)
33984a71e9aSMichael Rolnik {
34084a71e9aSMichael Rolnik     env->fullacc = false;
34184a71e9aSMichael Rolnik 
34284a71e9aSMichael Rolnik     /* Following logic assumes this: */
34384a71e9aSMichael Rolnik     assert(OFFSET_CPU_REGISTERS == OFFSET_DATA);
34484a71e9aSMichael Rolnik     assert(OFFSET_IO_REGISTERS == OFFSET_CPU_REGISTERS +
34584a71e9aSMichael Rolnik                                   NUMBER_OF_CPU_REGISTERS);
34684a71e9aSMichael Rolnik 
34784a71e9aSMichael Rolnik     if (addr < NUMBER_OF_CPU_REGISTERS) {
34884a71e9aSMichael Rolnik         /* CPU registers */
34984a71e9aSMichael Rolnik         env->r[addr] = data;
35084a71e9aSMichael Rolnik     } else if (addr < NUMBER_OF_CPU_REGISTERS + NUMBER_OF_IO_REGISTERS) {
35184a71e9aSMichael Rolnik         /* IO registers */
35284a71e9aSMichael Rolnik         helper_outb(env, addr - NUMBER_OF_CPU_REGISTERS, data);
35384a71e9aSMichael Rolnik     } else {
35484a71e9aSMichael Rolnik         /* memory */
35584a71e9aSMichael Rolnik         address_space_stb(&address_space_memory, OFFSET_DATA + addr, data,
35684a71e9aSMichael Rolnik                           MEMTXATTRS_UNSPECIFIED, NULL);
35784a71e9aSMichael Rolnik     }
35884a71e9aSMichael Rolnik }
359