]> git.proxmox.com Git - mirror_qemu.git/blame - hw/mips_r4k.c
compilation fix
[mirror_qemu.git] / hw / mips_r4k.c
CommitLineData
6af0bf9c
FB
1#include "vl.h"
2
6af0bf9c
FB
3#define BIOS_FILENAME "mips_bios.bin"
4//#define BIOS_FILENAME "system.bin"
5#define KERNEL_LOAD_ADDR 0x80010000
6#define INITRD_LOAD_ADDR 0x80800000
7
66a93e0f
FB
8#define VIRT_TO_PHYS_ADDEND (-0x80000000LL)
9
6af0bf9c
FB
10extern FILE *logfile;
11
697584ab
FB
12static PITState *pit;
13
73133662 14static void pic_irq_request(void *opaque, int level)
6af0bf9c 15{
c68ea704 16 CPUState *env = first_cpu;
73133662 17 if (level) {
c68ea704
FB
18 env->CP0_Cause |= 0x00000400;
19 cpu_interrupt(env, CPU_INTERRUPT_HARD);
6af0bf9c 20 } else {
c68ea704
FB
21 env->CP0_Cause &= ~0x00000400;
22 cpu_reset_interrupt(env, CPU_INTERRUPT_HARD);
6af0bf9c 23 }
6af0bf9c
FB
24}
25
26void cpu_mips_irqctrl_init (void)
27{
28}
29
f5d2a381 30/* XXX: do not use a global */
6af0bf9c
FB
31uint32_t cpu_mips_get_random (CPUState *env)
32{
f5d2a381
FB
33 static uint32_t seed = 0;
34 uint32_t idx;
35 seed = seed * 314159 + 1;
36 idx = (seed >> 16) % (MIPS_TLB_NB - env->CP0_Wired) + env->CP0_Wired;
37 return idx;
6af0bf9c
FB
38}
39
899abcf5 40/* MIPS R4K timer */
6af0bf9c
FB
41uint32_t cpu_mips_get_count (CPUState *env)
42{
43 return env->CP0_Count +
44 (uint32_t)muldiv64(qemu_get_clock(vm_clock),
45 100 * 1000 * 1000, ticks_per_sec);
46}
47
48static void cpu_mips_update_count (CPUState *env, uint32_t count,
49 uint32_t compare)
50{
51 uint64_t now, next;
52 uint32_t tmp;
53
54 tmp = count;
55 if (count == compare)
56 tmp++;
57 now = qemu_get_clock(vm_clock);
58 next = now + muldiv64(compare - tmp, ticks_per_sec, 100 * 1000 * 1000);
59 if (next == now)
60 next++;
2d7272a5 61#if 0
6af0bf9c 62 if (logfile) {
26a76461 63 fprintf(logfile, "%s: 0x%08" PRIx64 " %08x %08x => 0x%08" PRIx64 "\n",
6af0bf9c
FB
64 __func__, now, count, compare, next - now);
65 }
66#endif
67 /* Store new count and compare registers */
68 env->CP0_Compare = compare;
69 env->CP0_Count =
70 count - (uint32_t)muldiv64(now, 100 * 1000 * 1000, ticks_per_sec);
71 /* Adjust timer */
72 qemu_mod_timer(env->timer, next);
73}
74
75void cpu_mips_store_count (CPUState *env, uint32_t value)
76{
77 cpu_mips_update_count(env, value, env->CP0_Compare);
78}
79
80void cpu_mips_store_compare (CPUState *env, uint32_t value)
81{
82 cpu_mips_update_count(env, cpu_mips_get_count(env), value);
c68ea704
FB
83 env->CP0_Cause &= ~0x00008000;
84 cpu_reset_interrupt(env, CPU_INTERRUPT_HARD);
6af0bf9c
FB
85}
86
87static void mips_timer_cb (void *opaque)
88{
89 CPUState *env;
90
91 env = opaque;
2d7272a5 92#if 0
6af0bf9c
FB
93 if (logfile) {
94 fprintf(logfile, "%s\n", __func__);
95 }
96#endif
97 cpu_mips_update_count(env, cpu_mips_get_count(env), env->CP0_Compare);
c68ea704
FB
98 env->CP0_Cause |= 0x00008000;
99 cpu_interrupt(env, CPU_INTERRUPT_HARD);
6af0bf9c
FB
100}
101
102void cpu_mips_clock_init (CPUState *env)
103{
104 env->timer = qemu_new_timer(vm_clock, &mips_timer_cb, env);
105 env->CP0_Compare = 0;
106 cpu_mips_update_count(env, 1, 0);
107}
108
66a93e0f 109
6af0bf9c
FB
110void mips_r4k_init (int ram_size, int vga_ram_size, int boot_device,
111 DisplayState *ds, const char **fd_filename, int snapshot,
112 const char *kernel_filename, const char *kernel_cmdline,
113 const char *initrd_filename)
114{
115 char buf[1024];
66a93e0f 116 int64_t entry = 0;
6af0bf9c 117 unsigned long bios_offset;
6af0bf9c 118 int ret;
c68ea704 119 CPUState *env;
66a93e0f 120 long kernel_size;
c68ea704
FB
121
122 env = cpu_init();
123 register_savevm("cpu", 0, 3, cpu_save, cpu_load, env);
124
6af0bf9c
FB
125 /* allocate RAM */
126 cpu_register_physical_memory(0, ram_size, IO_MEM_RAM);
66a93e0f
FB
127
128 /* Try to load a BIOS image. If this fails, we continue regardless,
129 but initialize the hardware ourselves. When a kernel gets
130 preloaded we also initialize the hardware, since the BIOS wasn't
131 run. */
6af0bf9c
FB
132 bios_offset = ram_size + vga_ram_size;
133 snprintf(buf, sizeof(buf), "%s/%s", bios_dir, BIOS_FILENAME);
6af0bf9c 134 ret = load_image(buf, phys_ram_base + bios_offset);
66a93e0f
FB
135 if (ret == BIOS_SIZE) {
136 cpu_register_physical_memory((uint32_t)(0x1fc00000),
137 BIOS_SIZE, bios_offset | IO_MEM_ROM);
66a93e0f
FB
138 } else {
139 /* not fatal */
140 fprintf(stderr, "qemu: Warning, could not load MIPS bios '%s'\n",
141 buf);
6af0bf9c 142 }
66a93e0f
FB
143
144 kernel_size = 0;
145 if (kernel_filename) {
146 kernel_size = load_elf(kernel_filename, VIRT_TO_PHYS_ADDEND, &entry);
147 if (kernel_size >= 0)
148 env->PC = entry;
149 else {
150 kernel_size = load_image(kernel_filename,
151 phys_ram_base + KERNEL_LOAD_ADDR + VIRT_TO_PHYS_ADDEND);
152 if (kernel_size < 0) {
153 fprintf(stderr, "qemu: could not load kernel '%s'\n",
154 kernel_filename);
155 exit(1);
156 }
157 env->PC = KERNEL_LOAD_ADDR;
158 }
159
6af0bf9c
FB
160 /* load initrd */
161 if (initrd_filename) {
66a93e0f
FB
162 if (load_image(initrd_filename,
163 phys_ram_base + INITRD_LOAD_ADDR + VIRT_TO_PHYS_ADDEND)
164 == (target_ulong) -1) {
6af0bf9c
FB
165 fprintf(stderr, "qemu: could not load initial ram disk '%s'\n",
166 initrd_filename);
167 exit(1);
168 }
6af0bf9c 169 }
66a93e0f 170
2d7272a5
FB
171 /* Store command line. */
172 strcpy (phys_ram_base + (16 << 20) - 256, kernel_cmdline);
173 /* FIXME: little endian support */
174 *(int *)(phys_ram_base + (16 << 20) - 260) = tswap32 (0x12345678);
175 *(int *)(phys_ram_base + (16 << 20) - 264) = tswap32 (ram_size);
6af0bf9c 176 }
6af0bf9c
FB
177
178 /* Init internal devices */
c68ea704 179 cpu_mips_clock_init(env);
6af0bf9c
FB
180 cpu_mips_irqctrl_init();
181
0699b548 182 /* Register 64 KB of ISA IO space at 0x14000000 */
aef445bd 183 isa_mmio_init(0x14000000, 0x00010000);
0699b548
FB
184 isa_mem_base = 0x10000000;
185
c68ea704 186 isa_pic = pic_init(pic_irq_request, env);
697584ab 187 pit = pit_init(0x40, 0);
e5d13e2f 188 serial_init(&pic_set_irq_new, isa_pic, 0x3f8, 4, serial_hds[0]);
89b6b508
FB
189 isa_vga_init(ds, phys_ram_base + ram_size, ram_size,
190 vga_ram_size);
9827e95c 191
a41b2ff2
PB
192 if (nd_table[0].vlan) {
193 if (nd_table[0].model == NULL
194 || strcmp(nd_table[0].model, "ne2k_isa") == 0) {
195 isa_ne2000_init(0x300, 9, &nd_table[0]);
196 } else {
197 fprintf(stderr, "qemu: Unsupported NIC: %s\n", nd_table[0].model);
198 exit (1);
199 }
200 }
6af0bf9c
FB
201}
202
203QEMUMachine mips_machine = {
204 "mips",
205 "mips r4k platform",
206 mips_r4k_init,
207};