blob: 7b91d8c31ef8816cb7a9b26840c1bb78e25b91cf [file] [log] [blame]
Michael Walle143e8952011-02-17 23:45:04 +01001#include <assert.h>
Blue Swirl3e457172011-07-13 12:44:15 +00002#include "cpu.h"
Michael Walle143e8952011-02-17 23:45:04 +01003#include "helper.h"
4#include "host-utils.h"
5
6#include "hw/lm32_pic.h"
7#include "hw/lm32_juart.h"
8
9#if !defined(CONFIG_USER_ONLY)
10#define MMUSUFFIX _mmu
11#define SHIFT 0
12#include "softmmu_template.h"
13#define SHIFT 1
14#include "softmmu_template.h"
15#define SHIFT 2
16#include "softmmu_template.h"
17#define SHIFT 3
18#include "softmmu_template.h"
19
Blue Swirl32ac0ca2012-09-02 06:57:17 +000020void helper_raise_exception(CPULM32State *env, uint32_t index)
Michael Walle143e8952011-02-17 23:45:04 +010021{
22 env->exception_index = index;
Blue Swirl1162c042011-05-14 12:52:35 +000023 cpu_loop_exit(env);
Michael Walle143e8952011-02-17 23:45:04 +010024}
25
Blue Swirl32ac0ca2012-09-02 06:57:17 +000026void helper_hlt(CPULM32State *env)
Michael Walle143e8952011-02-17 23:45:04 +010027{
28 env->halted = 1;
29 env->exception_index = EXCP_HLT;
Blue Swirl1162c042011-05-14 12:52:35 +000030 cpu_loop_exit(env);
Michael Walle143e8952011-02-17 23:45:04 +010031}
32
Blue Swirl32ac0ca2012-09-02 06:57:17 +000033void helper_wcsr_im(CPULM32State *env, uint32_t im)
Michael Walle143e8952011-02-17 23:45:04 +010034{
35 lm32_pic_set_im(env->pic_state, im);
36}
37
Blue Swirl32ac0ca2012-09-02 06:57:17 +000038void helper_wcsr_ip(CPULM32State *env, uint32_t im)
Michael Walle143e8952011-02-17 23:45:04 +010039{
40 lm32_pic_set_ip(env->pic_state, im);
41}
42
Blue Swirl32ac0ca2012-09-02 06:57:17 +000043void helper_wcsr_jtx(CPULM32State *env, uint32_t jtx)
Michael Walle143e8952011-02-17 23:45:04 +010044{
45 lm32_juart_set_jtx(env->juart_state, jtx);
46}
47
Blue Swirl32ac0ca2012-09-02 06:57:17 +000048void helper_wcsr_jrx(CPULM32State *env, uint32_t jrx)
Michael Walle143e8952011-02-17 23:45:04 +010049{
50 lm32_juart_set_jrx(env->juart_state, jrx);
51}
52
Blue Swirl32ac0ca2012-09-02 06:57:17 +000053uint32_t helper_rcsr_im(CPULM32State *env)
Michael Walle143e8952011-02-17 23:45:04 +010054{
55 return lm32_pic_get_im(env->pic_state);
56}
57
Blue Swirl32ac0ca2012-09-02 06:57:17 +000058uint32_t helper_rcsr_ip(CPULM32State *env)
Michael Walle143e8952011-02-17 23:45:04 +010059{
60 return lm32_pic_get_ip(env->pic_state);
61}
62
Blue Swirl32ac0ca2012-09-02 06:57:17 +000063uint32_t helper_rcsr_jtx(CPULM32State *env)
Michael Walle143e8952011-02-17 23:45:04 +010064{
65 return lm32_juart_get_jtx(env->juart_state);
66}
67
Blue Swirl32ac0ca2012-09-02 06:57:17 +000068uint32_t helper_rcsr_jrx(CPULM32State *env)
Michael Walle143e8952011-02-17 23:45:04 +010069{
70 return lm32_juart_get_jrx(env->juart_state);
71}
72
73/* Try to fill the TLB and return an exception if error. If retaddr is
74 NULL, it means that the function was called in C code (i.e. not
75 from generated code or from helper.c) */
Blue Swirl32ac0ca2012-09-02 06:57:17 +000076void tlb_fill(CPULM32State *env, target_ulong addr, int is_write, int mmu_idx,
Blue Swirl20503962012-04-09 14:20:20 +000077 uintptr_t retaddr)
Michael Walle143e8952011-02-17 23:45:04 +010078{
79 TranslationBlock *tb;
Michael Walle143e8952011-02-17 23:45:04 +010080 int ret;
81
Blue Swirl97b348e2011-08-01 16:12:17 +000082 ret = cpu_lm32_handle_mmu_fault(env, addr, is_write, mmu_idx);
Michael Walle143e8952011-02-17 23:45:04 +010083 if (unlikely(ret)) {
84 if (retaddr) {
85 /* now we have a real cpu fault */
Blue Swirl20503962012-04-09 14:20:20 +000086 tb = tb_find_pc(retaddr);
Michael Walle143e8952011-02-17 23:45:04 +010087 if (tb) {
88 /* the PC is inside the translated code. It means that we have
89 a virtual CPU fault */
Blue Swirl20503962012-04-09 14:20:20 +000090 cpu_restore_state(tb, env, retaddr);
Michael Walle143e8952011-02-17 23:45:04 +010091 }
92 }
Blue Swirl1162c042011-05-14 12:52:35 +000093 cpu_loop_exit(env);
Michael Walle143e8952011-02-17 23:45:04 +010094 }
Michael Walle143e8952011-02-17 23:45:04 +010095}
96#endif
97