2 * QEMU ETRAX System Emulator
4 * Copyright (c) 2007 Edgar E. Iglesias, Axis Communications AB.
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
32 static void main_cpu_reset(void *opaque
)
34 CPUState
*env
= opaque
;
38 static uint32_t fs_mmio_readb (void *opaque
, target_phys_addr_t addr
)
40 CPUState
*env
= opaque
;
42 printf ("%s %x pc=%x\n", __func__
, addr
, env
->pc
);
45 static uint32_t fs_mmio_readw (void *opaque
, target_phys_addr_t addr
)
47 CPUState
*env
= opaque
;
49 printf ("%s %x pc=%x\n", __func__
, addr
, env
->pc
);
53 static uint32_t fs_mmio_readl (void *opaque
, target_phys_addr_t addr
)
55 CPUState
*env
= opaque
;
57 printf ("%s %x p=%x\n", __func__
, addr
, env
->pc
);
62 fs_mmio_writeb (void *opaque
, target_phys_addr_t addr
, uint32_t value
)
64 CPUState
*env
= opaque
;
65 printf ("%s %x %x pc=%x\n", __func__
, addr
, value
, env
->pc
);
68 fs_mmio_writew (void *opaque
, target_phys_addr_t addr
, uint32_t value
)
70 CPUState
*env
= opaque
;
71 printf ("%s %x %x pc=%x\n", __func__
, addr
, value
, env
->pc
);
74 fs_mmio_writel (void *opaque
, target_phys_addr_t addr
, uint32_t value
)
76 CPUState
*env
= opaque
;
77 printf ("%s %x %x pc=%x\n", __func__
, addr
, value
, env
->pc
);
80 static CPUReadMemoryFunc
*fs_mmio_read
[] = {
86 static CPUWriteMemoryFunc
*fs_mmio_write
[] = {
93 /* Init functions for different blocks. */
94 extern void etraxfs_timer_init(CPUState
*env
, qemu_irq
*irqs
);
95 extern void etraxfs_ser_init(CPUState
*env
, qemu_irq
*irqs
);
97 void etrax_ack_irq(CPUState
*env
, uint32_t mask
)
99 env
->pending_interrupts
&= ~mask
;
102 static void dummy_cpu_set_irq(void *opaque
, int irq
, int level
)
104 CPUState
*env
= opaque
;
106 /* Hmm, should this really be done here? */
107 env
->pending_interrupts
|= 1 << irq
;
108 cpu_interrupt(env
, CPU_INTERRUPT_HARD
);
112 void bareetraxfs_init (int ram_size
, int vga_ram_size
,
113 const char *boot_device
, DisplayState
*ds
,
114 const char *kernel_filename
, const char *kernel_cmdline
,
115 const char *initrd_filename
, const char *cpu_model
)
123 if (cpu_model
== NULL
) {
124 cpu_model
= "crisv32";
126 env
= cpu_init(cpu_model
);
127 /* register_savevm("cpu", 0, 3, cpu_save, cpu_load, env); */
128 qemu_register_reset(main_cpu_reset
, env
);
129 irqs
= qemu_allocate_irqs(dummy_cpu_set_irq
, env
, 32);
131 internal_regs
= cpu_register_io_memory(0,
132 fs_mmio_read
, fs_mmio_write
, env
);
133 /* 0xb0050000 is the last reg. */
134 cpu_register_physical_memory (0xac000000, 0x4010000, internal_regs
);
136 cpu_register_physical_memory(0x40000000, ram_size
, IO_MEM_RAM
);
138 etraxfs_timer_init(env
, irqs
);
139 etraxfs_ser_init(env
, irqs
);
141 kernel_size
= load_image(kernel_filename
, phys_ram_base
+ 0x4000);
142 /* magic for boot. */
143 env
->regs
[8] = 0x56902387;
144 env
->regs
[9] = 0x40004000 + kernel_size
;
145 env
->pc
= 0x40004000;
148 unsigned char *ptr
= phys_ram_base
+ 0x4000;
150 for (i
= 0; i
< 8; i
++)
152 printf ("%2.2x ", ptr
[i
]);
157 printf ("pc =%x\n", env
->pc
);
158 printf ("ram size =%d\n", ram_size
);
159 printf ("kernel name =%s\n", kernel_filename
);
160 printf ("kernel size =%d\n", kernel_size
);
161 printf ("cpu haltd =%d\n", env
->halted
);
176 QEMUMachine bareetraxfs_machine
= {
178 "Bare ETRAX FS board",