root / hw / sun4u.c @ 1f163b14
History | View | Annotate | Download (19.6 kB)
1 | 3475187d | bellard | /*
|
---|---|---|---|
2 | c7ba218d | blueswir1 | * QEMU Sun4u/Sun4v System Emulator
|
3 | 5fafdf24 | ths | *
|
4 | 3475187d | bellard | * Copyright (c) 2005 Fabrice Bellard
|
5 | 5fafdf24 | ths | *
|
6 | 3475187d | bellard | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 | 3475187d | bellard | * of this software and associated documentation files (the "Software"), to deal
|
8 | 3475187d | bellard | * in the Software without restriction, including without limitation the rights
|
9 | 3475187d | bellard | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 | 3475187d | bellard | * copies of the Software, and to permit persons to whom the Software is
|
11 | 3475187d | bellard | * furnished to do so, subject to the following conditions:
|
12 | 3475187d | bellard | *
|
13 | 3475187d | bellard | * The above copyright notice and this permission notice shall be included in
|
14 | 3475187d | bellard | * all copies or substantial portions of the Software.
|
15 | 3475187d | bellard | *
|
16 | 3475187d | bellard | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 | 3475187d | bellard | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 | 3475187d | bellard | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19 | 3475187d | bellard | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 | 3475187d | bellard | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 | 3475187d | bellard | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 | 3475187d | bellard | * THE SOFTWARE.
|
23 | 3475187d | bellard | */
|
24 | 87ecb68b | pbrook | #include "hw.h" |
25 | 87ecb68b | pbrook | #include "pci.h" |
26 | 87ecb68b | pbrook | #include "pc.h" |
27 | 87ecb68b | pbrook | #include "nvram.h" |
28 | 87ecb68b | pbrook | #include "fdc.h" |
29 | 87ecb68b | pbrook | #include "net.h" |
30 | 87ecb68b | pbrook | #include "qemu-timer.h" |
31 | 87ecb68b | pbrook | #include "sysemu.h" |
32 | 87ecb68b | pbrook | #include "boards.h" |
33 | d2c63fc1 | blueswir1 | #include "firmware_abi.h" |
34 | 3cce6243 | blueswir1 | #include "fw_cfg.h" |
35 | 3475187d | bellard | |
36 | 9d926598 | blueswir1 | //#define DEBUG_IRQ
|
37 | 9d926598 | blueswir1 | |
38 | 9d926598 | blueswir1 | #ifdef DEBUG_IRQ
|
39 | 9d926598 | blueswir1 | #define DPRINTF(fmt, args...) \
|
40 | 9d926598 | blueswir1 | do { printf("CPUIRQ: " fmt , ##args); } while (0) |
41 | 9d926598 | blueswir1 | #else
|
42 | 9d926598 | blueswir1 | #define DPRINTF(fmt, args...)
|
43 | 9d926598 | blueswir1 | #endif
|
44 | 9d926598 | blueswir1 | |
45 | 83469015 | bellard | #define KERNEL_LOAD_ADDR 0x00404000 |
46 | 83469015 | bellard | #define CMDLINE_ADDR 0x003ff000 |
47 | 83469015 | bellard | #define INITRD_LOAD_ADDR 0x00300000 |
48 | ac2e9d66 | blueswir1 | #define PROM_SIZE_MAX (4 * 1024 * 1024) |
49 | f930d07e | blueswir1 | #define PROM_VADDR 0x000ffd00000ULL |
50 | 83469015 | bellard | #define APB_SPECIAL_BASE 0x1fe00000000ULL |
51 | f930d07e | blueswir1 | #define APB_MEM_BASE 0x1ff00000000ULL |
52 | f930d07e | blueswir1 | #define VGA_BASE (APB_MEM_BASE + 0x400000ULL) |
53 | f930d07e | blueswir1 | #define PROM_FILENAME "openbios-sparc64" |
54 | 83469015 | bellard | #define NVRAM_SIZE 0x2000 |
55 | e4bcb14c | ths | #define MAX_IDE_BUS 2 |
56 | 3cce6243 | blueswir1 | #define BIOS_CFG_IOPORT 0x510 |
57 | 3475187d | bellard | |
58 | 9d926598 | blueswir1 | #define MAX_PILS 16 |
59 | 9d926598 | blueswir1 | |
60 | c7ba218d | blueswir1 | struct hwdef {
|
61 | c7ba218d | blueswir1 | const char * const default_cpu_model; |
62 | 905fdcb5 | blueswir1 | uint16_t machine_id; |
63 | e87231d4 | blueswir1 | uint64_t prom_addr; |
64 | e87231d4 | blueswir1 | uint64_t console_serial_base; |
65 | c7ba218d | blueswir1 | }; |
66 | c7ba218d | blueswir1 | |
67 | 3475187d | bellard | int DMA_get_channel_mode (int nchan) |
68 | 3475187d | bellard | { |
69 | 3475187d | bellard | return 0; |
70 | 3475187d | bellard | } |
71 | 3475187d | bellard | int DMA_read_memory (int nchan, void *buf, int pos, int size) |
72 | 3475187d | bellard | { |
73 | 3475187d | bellard | return 0; |
74 | 3475187d | bellard | } |
75 | 3475187d | bellard | int DMA_write_memory (int nchan, void *buf, int pos, int size) |
76 | 3475187d | bellard | { |
77 | 3475187d | bellard | return 0; |
78 | 3475187d | bellard | } |
79 | 3475187d | bellard | void DMA_hold_DREQ (int nchan) {} |
80 | 3475187d | bellard | void DMA_release_DREQ (int nchan) {} |
81 | 3475187d | bellard | void DMA_schedule(int nchan) {} |
82 | 3475187d | bellard | void DMA_init (int high_page_enable) {} |
83 | 3475187d | bellard | void DMA_register_channel (int nchan, |
84 | 3475187d | bellard | DMA_transfer_handler transfer_handler, |
85 | 3475187d | bellard | void *opaque)
|
86 | 3475187d | bellard | { |
87 | 3475187d | bellard | } |
88 | 3475187d | bellard | |
89 | 81864572 | blueswir1 | static int nvram_boot_set(void *opaque, const char *boot_device) |
90 | 81864572 | blueswir1 | { |
91 | 81864572 | blueswir1 | unsigned int i; |
92 | 81864572 | blueswir1 | uint8_t image[sizeof(ohwcfg_v3_t)];
|
93 | 81864572 | blueswir1 | ohwcfg_v3_t *header = (ohwcfg_v3_t *)ℑ |
94 | 81864572 | blueswir1 | m48t59_t *nvram = (m48t59_t *)opaque; |
95 | 81864572 | blueswir1 | |
96 | 81864572 | blueswir1 | for (i = 0; i < sizeof(image); i++) |
97 | 81864572 | blueswir1 | image[i] = m48t59_read(nvram, i) & 0xff;
|
98 | 81864572 | blueswir1 | |
99 | 363a37d5 | blueswir1 | pstrcpy((char *)header->boot_devices, sizeof(header->boot_devices), |
100 | 363a37d5 | blueswir1 | boot_device); |
101 | 81864572 | blueswir1 | header->nboot_devices = strlen(boot_device) & 0xff;
|
102 | 81864572 | blueswir1 | header->crc = cpu_to_be16(OHW_compute_crc(header, 0x00, 0xF8)); |
103 | 81864572 | blueswir1 | |
104 | 81864572 | blueswir1 | for (i = 0; i < sizeof(image); i++) |
105 | 81864572 | blueswir1 | m48t59_write(nvram, i, image[i]); |
106 | 81864572 | blueswir1 | |
107 | 81864572 | blueswir1 | return 0; |
108 | 81864572 | blueswir1 | } |
109 | 81864572 | blueswir1 | |
110 | d2c63fc1 | blueswir1 | static int sun4u_NVRAM_set_params (m48t59_t *nvram, uint16_t NVRAM_size, |
111 | e7fb1406 | blueswir1 | const char *arch, |
112 | 77f193da | blueswir1 | ram_addr_t RAM_size, |
113 | 77f193da | blueswir1 | const char *boot_devices, |
114 | d2c63fc1 | blueswir1 | uint32_t kernel_image, uint32_t kernel_size, |
115 | d2c63fc1 | blueswir1 | const char *cmdline, |
116 | d2c63fc1 | blueswir1 | uint32_t initrd_image, uint32_t initrd_size, |
117 | d2c63fc1 | blueswir1 | uint32_t NVRAM_image, |
118 | 0d31cb99 | blueswir1 | int width, int height, int depth, |
119 | 0d31cb99 | blueswir1 | const uint8_t *macaddr)
|
120 | 83469015 | bellard | { |
121 | 66508601 | blueswir1 | unsigned int i; |
122 | 66508601 | blueswir1 | uint32_t start, end; |
123 | d2c63fc1 | blueswir1 | uint8_t image[0x1ff0];
|
124 | d2c63fc1 | blueswir1 | ohwcfg_v3_t *header = (ohwcfg_v3_t *)ℑ |
125 | d2c63fc1 | blueswir1 | struct sparc_arch_cfg *sparc_header;
|
126 | d2c63fc1 | blueswir1 | struct OpenBIOS_nvpart_v1 *part_header;
|
127 | d2c63fc1 | blueswir1 | |
128 | d2c63fc1 | blueswir1 | memset(image, '\0', sizeof(image)); |
129 | d2c63fc1 | blueswir1 | |
130 | d2c63fc1 | blueswir1 | // Try to match PPC NVRAM
|
131 | 363a37d5 | blueswir1 | pstrcpy((char *)header->struct_ident, sizeof(header->struct_ident), |
132 | 363a37d5 | blueswir1 | "QEMU_BIOS");
|
133 | d2c63fc1 | blueswir1 | header->struct_version = cpu_to_be32(3); /* structure v3 */ |
134 | d2c63fc1 | blueswir1 | |
135 | d2c63fc1 | blueswir1 | header->nvram_size = cpu_to_be16(NVRAM_size); |
136 | d2c63fc1 | blueswir1 | header->nvram_arch_ptr = cpu_to_be16(sizeof(ohwcfg_v3_t));
|
137 | d2c63fc1 | blueswir1 | header->nvram_arch_size = cpu_to_be16(sizeof(struct sparc_arch_cfg)); |
138 | 363a37d5 | blueswir1 | pstrcpy((char *)header->arch, sizeof(header->arch), arch); |
139 | d2c63fc1 | blueswir1 | header->nb_cpus = smp_cpus & 0xff;
|
140 | d2c63fc1 | blueswir1 | header->RAM0_base = 0;
|
141 | d2c63fc1 | blueswir1 | header->RAM0_size = cpu_to_be64((uint64_t)RAM_size); |
142 | 363a37d5 | blueswir1 | pstrcpy((char *)header->boot_devices, sizeof(header->boot_devices), |
143 | 363a37d5 | blueswir1 | boot_devices); |
144 | d2c63fc1 | blueswir1 | header->nboot_devices = strlen(boot_devices) & 0xff;
|
145 | d2c63fc1 | blueswir1 | header->kernel_image = cpu_to_be64((uint64_t)kernel_image); |
146 | d2c63fc1 | blueswir1 | header->kernel_size = cpu_to_be64((uint64_t)kernel_size); |
147 | 3475187d | bellard | if (cmdline) {
|
148 | 293f78bc | blueswir1 | pstrcpy_targphys(CMDLINE_ADDR, TARGET_PAGE_SIZE, cmdline); |
149 | d2c63fc1 | blueswir1 | header->cmdline = cpu_to_be64((uint64_t)CMDLINE_ADDR); |
150 | d2c63fc1 | blueswir1 | header->cmdline_size = cpu_to_be64((uint64_t)strlen(cmdline)); |
151 | 3475187d | bellard | } |
152 | d2c63fc1 | blueswir1 | header->initrd_image = cpu_to_be64((uint64_t)initrd_image); |
153 | d2c63fc1 | blueswir1 | header->initrd_size = cpu_to_be64((uint64_t)initrd_size); |
154 | d2c63fc1 | blueswir1 | header->NVRAM_image = cpu_to_be64((uint64_t)NVRAM_image); |
155 | d2c63fc1 | blueswir1 | |
156 | d2c63fc1 | blueswir1 | header->width = cpu_to_be16(width); |
157 | d2c63fc1 | blueswir1 | header->height = cpu_to_be16(height); |
158 | d2c63fc1 | blueswir1 | header->depth = cpu_to_be16(depth); |
159 | d2c63fc1 | blueswir1 | if (nographic)
|
160 | d2c63fc1 | blueswir1 | header->graphic_flags = cpu_to_be16(OHW_GF_NOGRAPHICS); |
161 | 83469015 | bellard | |
162 | d2c63fc1 | blueswir1 | header->crc = cpu_to_be16(OHW_compute_crc(header, 0x00, 0xF8)); |
163 | d2c63fc1 | blueswir1 | |
164 | d2c63fc1 | blueswir1 | // Architecture specific header
|
165 | d2c63fc1 | blueswir1 | start = sizeof(ohwcfg_v3_t);
|
166 | d2c63fc1 | blueswir1 | sparc_header = (struct sparc_arch_cfg *)&image[start];
|
167 | d2c63fc1 | blueswir1 | sparc_header->valid = 0;
|
168 | d2c63fc1 | blueswir1 | start += sizeof(struct sparc_arch_cfg); |
169 | 83469015 | bellard | |
170 | 66508601 | blueswir1 | // OpenBIOS nvram variables
|
171 | 66508601 | blueswir1 | // Variable partition
|
172 | d2c63fc1 | blueswir1 | part_header = (struct OpenBIOS_nvpart_v1 *)&image[start];
|
173 | d2c63fc1 | blueswir1 | part_header->signature = OPENBIOS_PART_SYSTEM; |
174 | 363a37d5 | blueswir1 | pstrcpy(part_header->name, sizeof(part_header->name), "system"); |
175 | 66508601 | blueswir1 | |
176 | d2c63fc1 | blueswir1 | end = start + sizeof(struct OpenBIOS_nvpart_v1); |
177 | 66508601 | blueswir1 | for (i = 0; i < nb_prom_envs; i++) |
178 | d2c63fc1 | blueswir1 | end = OpenBIOS_set_var(image, end, prom_envs[i]); |
179 | d2c63fc1 | blueswir1 | |
180 | d2c63fc1 | blueswir1 | // End marker
|
181 | d2c63fc1 | blueswir1 | image[end++] = '\0';
|
182 | 66508601 | blueswir1 | |
183 | 66508601 | blueswir1 | end = start + ((end - start + 15) & ~15); |
184 | d2c63fc1 | blueswir1 | OpenBIOS_finish_partition(part_header, end - start); |
185 | 66508601 | blueswir1 | |
186 | 66508601 | blueswir1 | // free partition
|
187 | 66508601 | blueswir1 | start = end; |
188 | d2c63fc1 | blueswir1 | part_header = (struct OpenBIOS_nvpart_v1 *)&image[start];
|
189 | d2c63fc1 | blueswir1 | part_header->signature = OPENBIOS_PART_FREE; |
190 | 363a37d5 | blueswir1 | pstrcpy(part_header->name, sizeof(part_header->name), "free"); |
191 | 66508601 | blueswir1 | |
192 | 66508601 | blueswir1 | end = 0x1fd0;
|
193 | d2c63fc1 | blueswir1 | OpenBIOS_finish_partition(part_header, end - start); |
194 | d2c63fc1 | blueswir1 | |
195 | 0d31cb99 | blueswir1 | Sun_init_header((struct Sun_nvram *)&image[0x1fd8], macaddr, 0x80); |
196 | 0d31cb99 | blueswir1 | |
197 | d2c63fc1 | blueswir1 | for (i = 0; i < sizeof(image); i++) |
198 | d2c63fc1 | blueswir1 | m48t59_write(nvram, i, image[i]); |
199 | 66508601 | blueswir1 | |
200 | 81864572 | blueswir1 | qemu_register_boot_set(nvram_boot_set, nvram); |
201 | 81864572 | blueswir1 | |
202 | 83469015 | bellard | return 0; |
203 | 3475187d | bellard | } |
204 | 3475187d | bellard | |
205 | 22548760 | blueswir1 | void pic_info(void) |
206 | 3475187d | bellard | { |
207 | 3475187d | bellard | } |
208 | 3475187d | bellard | |
209 | 22548760 | blueswir1 | void irq_info(void) |
210 | 3475187d | bellard | { |
211 | 3475187d | bellard | } |
212 | 3475187d | bellard | |
213 | 9d926598 | blueswir1 | void cpu_check_irqs(CPUState *env)
|
214 | 9d926598 | blueswir1 | { |
215 | 9d926598 | blueswir1 | uint32_t pil = env->pil_in | (env->softint & ~SOFTINT_TIMER) | |
216 | 9d926598 | blueswir1 | ((env->softint & SOFTINT_TIMER) << 14);
|
217 | 9d926598 | blueswir1 | |
218 | 9d926598 | blueswir1 | if (pil && (env->interrupt_index == 0 || |
219 | 9d926598 | blueswir1 | (env->interrupt_index & ~15) == TT_EXTINT)) {
|
220 | 9d926598 | blueswir1 | unsigned int i; |
221 | 9d926598 | blueswir1 | |
222 | 9d926598 | blueswir1 | for (i = 15; i > 0; i--) { |
223 | 9d926598 | blueswir1 | if (pil & (1 << i)) { |
224 | 9d926598 | blueswir1 | int old_interrupt = env->interrupt_index;
|
225 | 9d926598 | blueswir1 | |
226 | 9d926598 | blueswir1 | env->interrupt_index = TT_EXTINT | i; |
227 | 9d926598 | blueswir1 | if (old_interrupt != env->interrupt_index) {
|
228 | 9d926598 | blueswir1 | DPRINTF("Set CPU IRQ %d\n", i);
|
229 | 9d926598 | blueswir1 | cpu_interrupt(env, CPU_INTERRUPT_HARD); |
230 | 9d926598 | blueswir1 | } |
231 | 9d926598 | blueswir1 | break;
|
232 | 9d926598 | blueswir1 | } |
233 | 9d926598 | blueswir1 | } |
234 | 9d926598 | blueswir1 | } else if (!pil && (env->interrupt_index & ~15) == TT_EXTINT) { |
235 | 9d926598 | blueswir1 | DPRINTF("Reset CPU IRQ %d\n", env->interrupt_index & 15); |
236 | 9d926598 | blueswir1 | env->interrupt_index = 0;
|
237 | 9d926598 | blueswir1 | cpu_reset_interrupt(env, CPU_INTERRUPT_HARD); |
238 | 9d926598 | blueswir1 | } |
239 | 9d926598 | blueswir1 | } |
240 | 9d926598 | blueswir1 | |
241 | 9d926598 | blueswir1 | static void cpu_set_irq(void *opaque, int irq, int level) |
242 | 9d926598 | blueswir1 | { |
243 | 9d926598 | blueswir1 | CPUState *env = opaque; |
244 | 9d926598 | blueswir1 | |
245 | 9d926598 | blueswir1 | if (level) {
|
246 | 9d926598 | blueswir1 | DPRINTF("Raise CPU IRQ %d\n", irq);
|
247 | 9d926598 | blueswir1 | env->halted = 0;
|
248 | 9d926598 | blueswir1 | env->pil_in |= 1 << irq;
|
249 | 9d926598 | blueswir1 | cpu_check_irqs(env); |
250 | 9d926598 | blueswir1 | } else {
|
251 | 9d926598 | blueswir1 | DPRINTF("Lower CPU IRQ %d\n", irq);
|
252 | 9d926598 | blueswir1 | env->pil_in &= ~(1 << irq);
|
253 | 9d926598 | blueswir1 | cpu_check_irqs(env); |
254 | 9d926598 | blueswir1 | } |
255 | 9d926598 | blueswir1 | } |
256 | 9d926598 | blueswir1 | |
257 | 83469015 | bellard | void qemu_system_powerdown(void) |
258 | 3475187d | bellard | { |
259 | 3475187d | bellard | } |
260 | 3475187d | bellard | |
261 | e87231d4 | blueswir1 | typedef struct ResetData { |
262 | e87231d4 | blueswir1 | CPUState *env; |
263 | e87231d4 | blueswir1 | uint64_t reset_addr; |
264 | e87231d4 | blueswir1 | } ResetData; |
265 | e87231d4 | blueswir1 | |
266 | c68ea704 | bellard | static void main_cpu_reset(void *opaque) |
267 | c68ea704 | bellard | { |
268 | e87231d4 | blueswir1 | ResetData *s = (ResetData *)opaque; |
269 | e87231d4 | blueswir1 | CPUState *env = s->env; |
270 | 20c9f095 | blueswir1 | |
271 | c68ea704 | bellard | cpu_reset(env); |
272 | 20c9f095 | blueswir1 | ptimer_set_limit(env->tick, 0x7fffffffffffffffULL, 1); |
273 | 20c9f095 | blueswir1 | ptimer_run(env->tick, 0);
|
274 | 20c9f095 | blueswir1 | ptimer_set_limit(env->stick, 0x7fffffffffffffffULL, 1); |
275 | 20c9f095 | blueswir1 | ptimer_run(env->stick, 0);
|
276 | 20c9f095 | blueswir1 | ptimer_set_limit(env->hstick, 0x7fffffffffffffffULL, 1); |
277 | 20c9f095 | blueswir1 | ptimer_run(env->hstick, 0);
|
278 | e87231d4 | blueswir1 | env->gregs[1] = 0; // Memory start |
279 | e87231d4 | blueswir1 | env->gregs[2] = ram_size; // Memory size |
280 | e87231d4 | blueswir1 | env->gregs[3] = 0; // Machine description XXX |
281 | e87231d4 | blueswir1 | env->pc = s->reset_addr; |
282 | e87231d4 | blueswir1 | env->npc = env->pc + 4;
|
283 | 20c9f095 | blueswir1 | } |
284 | 20c9f095 | blueswir1 | |
285 | 22548760 | blueswir1 | static void tick_irq(void *opaque) |
286 | 20c9f095 | blueswir1 | { |
287 | 20c9f095 | blueswir1 | CPUState *env = opaque; |
288 | 20c9f095 | blueswir1 | |
289 | 9d926598 | blueswir1 | env->softint |= SOFTINT_TIMER; |
290 | 20c9f095 | blueswir1 | cpu_interrupt(env, CPU_INTERRUPT_TIMER); |
291 | 20c9f095 | blueswir1 | } |
292 | 20c9f095 | blueswir1 | |
293 | 22548760 | blueswir1 | static void stick_irq(void *opaque) |
294 | 20c9f095 | blueswir1 | { |
295 | 20c9f095 | blueswir1 | CPUState *env = opaque; |
296 | 20c9f095 | blueswir1 | |
297 | 9d926598 | blueswir1 | env->softint |= SOFTINT_TIMER; |
298 | 20c9f095 | blueswir1 | cpu_interrupt(env, CPU_INTERRUPT_TIMER); |
299 | 20c9f095 | blueswir1 | } |
300 | 20c9f095 | blueswir1 | |
301 | 22548760 | blueswir1 | static void hstick_irq(void *opaque) |
302 | 20c9f095 | blueswir1 | { |
303 | 20c9f095 | blueswir1 | CPUState *env = opaque; |
304 | 20c9f095 | blueswir1 | |
305 | 9d926598 | blueswir1 | env->softint |= SOFTINT_TIMER; |
306 | 20c9f095 | blueswir1 | cpu_interrupt(env, CPU_INTERRUPT_TIMER); |
307 | c68ea704 | bellard | } |
308 | c68ea704 | bellard | |
309 | f4b1a842 | blueswir1 | void cpu_tick_set_count(void *opaque, uint64_t count) |
310 | f4b1a842 | blueswir1 | { |
311 | f4b1a842 | blueswir1 | ptimer_set_count(opaque, -count); |
312 | f4b1a842 | blueswir1 | } |
313 | f4b1a842 | blueswir1 | |
314 | f4b1a842 | blueswir1 | uint64_t cpu_tick_get_count(void *opaque)
|
315 | f4b1a842 | blueswir1 | { |
316 | f4b1a842 | blueswir1 | return -ptimer_get_count(opaque);
|
317 | f4b1a842 | blueswir1 | } |
318 | f4b1a842 | blueswir1 | |
319 | f4b1a842 | blueswir1 | void cpu_tick_set_limit(void *opaque, uint64_t limit) |
320 | f4b1a842 | blueswir1 | { |
321 | f4b1a842 | blueswir1 | ptimer_set_limit(opaque, -limit, 0);
|
322 | f4b1a842 | blueswir1 | } |
323 | f4b1a842 | blueswir1 | |
324 | 83469015 | bellard | static const int ide_iobase[2] = { 0x1f0, 0x170 }; |
325 | 83469015 | bellard | static const int ide_iobase2[2] = { 0x3f6, 0x376 }; |
326 | 83469015 | bellard | static const int ide_irq[2] = { 14, 15 }; |
327 | 3475187d | bellard | |
328 | 83469015 | bellard | static const int serial_io[MAX_SERIAL_PORTS] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 }; |
329 | 83469015 | bellard | static const int serial_irq[MAX_SERIAL_PORTS] = { 4, 3, 4, 3 }; |
330 | 83469015 | bellard | |
331 | 83469015 | bellard | static const int parallel_io[MAX_PARALLEL_PORTS] = { 0x378, 0x278, 0x3bc }; |
332 | 83469015 | bellard | static const int parallel_irq[MAX_PARALLEL_PORTS] = { 7, 7, 7 }; |
333 | 83469015 | bellard | |
334 | 83469015 | bellard | static fdctrl_t *floppy_controller;
|
335 | 3475187d | bellard | |
336 | c7ba218d | blueswir1 | static void sun4uv_init(ram_addr_t RAM_size, int vga_ram_size, |
337 | c7ba218d | blueswir1 | const char *boot_devices, DisplayState *ds, |
338 | c7ba218d | blueswir1 | const char *kernel_filename, const char *kernel_cmdline, |
339 | c7ba218d | blueswir1 | const char *initrd_filename, const char *cpu_model, |
340 | c7ba218d | blueswir1 | const struct hwdef *hwdef) |
341 | 3475187d | bellard | { |
342 | c68ea704 | bellard | CPUState *env; |
343 | 3475187d | bellard | char buf[1024]; |
344 | 83469015 | bellard | m48t59_t *nvram; |
345 | 3475187d | bellard | int ret, linux_boot;
|
346 | 3475187d | bellard | unsigned int i; |
347 | 83469015 | bellard | long prom_offset, initrd_size, kernel_size;
|
348 | 83469015 | bellard | PCIBus *pci_bus; |
349 | 20c9f095 | blueswir1 | QEMUBH *bh; |
350 | f19e918d | blueswir1 | qemu_irq *irq; |
351 | 22548760 | blueswir1 | int drive_index;
|
352 | e4bcb14c | ths | BlockDriverState *hd[MAX_IDE_BUS * MAX_IDE_DEVS]; |
353 | e4bcb14c | ths | BlockDriverState *fd[MAX_FD]; |
354 | 3cce6243 | blueswir1 | void *fw_cfg;
|
355 | e87231d4 | blueswir1 | ResetData *reset_info; |
356 | 3475187d | bellard | |
357 | 3475187d | bellard | linux_boot = (kernel_filename != NULL);
|
358 | 3475187d | bellard | |
359 | 62724a37 | blueswir1 | /* init CPUs */
|
360 | c7ba218d | blueswir1 | if (!cpu_model)
|
361 | c7ba218d | blueswir1 | cpu_model = hwdef->default_cpu_model; |
362 | c7ba218d | blueswir1 | |
363 | aaed909a | bellard | env = cpu_init(cpu_model); |
364 | aaed909a | bellard | if (!env) {
|
365 | 62724a37 | blueswir1 | fprintf(stderr, "Unable to find Sparc CPU definition\n");
|
366 | 62724a37 | blueswir1 | exit(1);
|
367 | 62724a37 | blueswir1 | } |
368 | 20c9f095 | blueswir1 | bh = qemu_bh_new(tick_irq, env); |
369 | 20c9f095 | blueswir1 | env->tick = ptimer_init(bh); |
370 | 20c9f095 | blueswir1 | ptimer_set_period(env->tick, 1ULL);
|
371 | 20c9f095 | blueswir1 | |
372 | 20c9f095 | blueswir1 | bh = qemu_bh_new(stick_irq, env); |
373 | 20c9f095 | blueswir1 | env->stick = ptimer_init(bh); |
374 | 20c9f095 | blueswir1 | ptimer_set_period(env->stick, 1ULL);
|
375 | 20c9f095 | blueswir1 | |
376 | 20c9f095 | blueswir1 | bh = qemu_bh_new(hstick_irq, env); |
377 | 20c9f095 | blueswir1 | env->hstick = ptimer_init(bh); |
378 | 20c9f095 | blueswir1 | ptimer_set_period(env->hstick, 1ULL);
|
379 | e87231d4 | blueswir1 | |
380 | e87231d4 | blueswir1 | reset_info = qemu_mallocz(sizeof(ResetData));
|
381 | e87231d4 | blueswir1 | reset_info->env = env; |
382 | e87231d4 | blueswir1 | reset_info->reset_addr = hwdef->prom_addr + 0x40ULL;
|
383 | e87231d4 | blueswir1 | qemu_register_reset(main_cpu_reset, reset_info); |
384 | e87231d4 | blueswir1 | main_cpu_reset(reset_info); |
385 | e87231d4 | blueswir1 | // Override warm reset address with cold start address
|
386 | e87231d4 | blueswir1 | env->pc = hwdef->prom_addr + 0x20ULL;
|
387 | e87231d4 | blueswir1 | env->npc = env->pc + 4;
|
388 | c68ea704 | bellard | |
389 | 3475187d | bellard | /* allocate RAM */
|
390 | 22548760 | blueswir1 | cpu_register_physical_memory(0, RAM_size, 0); |
391 | 3475187d | bellard | |
392 | 22548760 | blueswir1 | prom_offset = RAM_size + vga_ram_size; |
393 | e87231d4 | blueswir1 | cpu_register_physical_memory(hwdef->prom_addr, |
394 | 77f193da | blueswir1 | (PROM_SIZE_MAX + TARGET_PAGE_SIZE) & |
395 | 77f193da | blueswir1 | TARGET_PAGE_MASK, |
396 | b3783731 | bellard | prom_offset | IO_MEM_ROM); |
397 | 3475187d | bellard | |
398 | 1192dad8 | j_mayer | if (bios_name == NULL) |
399 | 1192dad8 | j_mayer | bios_name = PROM_FILENAME; |
400 | 1192dad8 | j_mayer | snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name); |
401 | e87231d4 | blueswir1 | ret = load_elf(buf, hwdef->prom_addr - PROM_VADDR, NULL, NULL, NULL); |
402 | 3475187d | bellard | if (ret < 0) { |
403 | e87231d4 | blueswir1 | ret = load_image_targphys(buf, hwdef->prom_addr, |
404 | e87231d4 | blueswir1 | (PROM_SIZE_MAX + TARGET_PAGE_SIZE) & |
405 | e87231d4 | blueswir1 | TARGET_PAGE_MASK); |
406 | e87231d4 | blueswir1 | if (ret < 0) { |
407 | e87231d4 | blueswir1 | fprintf(stderr, "qemu: could not load prom '%s'\n",
|
408 | e87231d4 | blueswir1 | buf); |
409 | e87231d4 | blueswir1 | exit(1);
|
410 | e87231d4 | blueswir1 | } |
411 | 3475187d | bellard | } |
412 | 3475187d | bellard | |
413 | 3475187d | bellard | kernel_size = 0;
|
414 | 83469015 | bellard | initrd_size = 0;
|
415 | 3475187d | bellard | if (linux_boot) {
|
416 | b3783731 | bellard | /* XXX: put correct offset */
|
417 | 74287114 | ths | kernel_size = load_elf(kernel_filename, 0, NULL, NULL, NULL); |
418 | 3475187d | bellard | if (kernel_size < 0) |
419 | 293f78bc | blueswir1 | kernel_size = load_aout(kernel_filename, KERNEL_LOAD_ADDR, |
420 | 293f78bc | blueswir1 | ram_size - KERNEL_LOAD_ADDR); |
421 | f930d07e | blueswir1 | if (kernel_size < 0) |
422 | 293f78bc | blueswir1 | kernel_size = load_image_targphys(kernel_filename, |
423 | 293f78bc | blueswir1 | KERNEL_LOAD_ADDR, |
424 | 293f78bc | blueswir1 | ram_size - KERNEL_LOAD_ADDR); |
425 | 3475187d | bellard | if (kernel_size < 0) { |
426 | 5fafdf24 | ths | fprintf(stderr, "qemu: could not load kernel '%s'\n",
|
427 | 3475187d | bellard | kernel_filename); |
428 | f930d07e | blueswir1 | exit(1);
|
429 | 3475187d | bellard | } |
430 | 3475187d | bellard | |
431 | 3475187d | bellard | /* load initrd */
|
432 | 3475187d | bellard | if (initrd_filename) {
|
433 | 293f78bc | blueswir1 | initrd_size = load_image_targphys(initrd_filename, |
434 | 293f78bc | blueswir1 | INITRD_LOAD_ADDR, |
435 | 293f78bc | blueswir1 | ram_size - INITRD_LOAD_ADDR); |
436 | 3475187d | bellard | if (initrd_size < 0) { |
437 | 5fafdf24 | ths | fprintf(stderr, "qemu: could not load initial ram disk '%s'\n",
|
438 | 3475187d | bellard | initrd_filename); |
439 | 3475187d | bellard | exit(1);
|
440 | 3475187d | bellard | } |
441 | 3475187d | bellard | } |
442 | 3475187d | bellard | if (initrd_size > 0) { |
443 | f930d07e | blueswir1 | for (i = 0; i < 64 * TARGET_PAGE_SIZE; i += TARGET_PAGE_SIZE) { |
444 | 293f78bc | blueswir1 | if (ldl_phys(KERNEL_LOAD_ADDR + i) == 0x48647253) { // HdrS |
445 | 293f78bc | blueswir1 | stl_phys(KERNEL_LOAD_ADDR + i + 16, INITRD_LOAD_ADDR);
|
446 | 293f78bc | blueswir1 | stl_phys(KERNEL_LOAD_ADDR + i + 20, initrd_size);
|
447 | f930d07e | blueswir1 | break;
|
448 | f930d07e | blueswir1 | } |
449 | f930d07e | blueswir1 | } |
450 | 3475187d | bellard | } |
451 | 3475187d | bellard | } |
452 | 502a5395 | pbrook | pci_bus = pci_apb_init(APB_SPECIAL_BASE, APB_MEM_BASE, NULL);
|
453 | 83469015 | bellard | isa_mem_base = VGA_BASE; |
454 | 77f193da | blueswir1 | pci_cirrus_vga_init(pci_bus, ds, phys_ram_base + RAM_size, RAM_size, |
455 | 77f193da | blueswir1 | vga_ram_size); |
456 | 83469015 | bellard | |
457 | e87231d4 | blueswir1 | i = 0;
|
458 | e87231d4 | blueswir1 | if (hwdef->console_serial_base) {
|
459 | e87231d4 | blueswir1 | serial_mm_init(hwdef->console_serial_base, 0, NULL, 115200, |
460 | e87231d4 | blueswir1 | serial_hds[i], 1);
|
461 | e87231d4 | blueswir1 | i++; |
462 | e87231d4 | blueswir1 | } |
463 | e87231d4 | blueswir1 | for(; i < MAX_SERIAL_PORTS; i++) {
|
464 | 83469015 | bellard | if (serial_hds[i]) {
|
465 | cbf5c748 | blueswir1 | serial_init(serial_io[i], NULL/*serial_irq[i]*/, 115200, |
466 | cbf5c748 | blueswir1 | serial_hds[i]); |
467 | 83469015 | bellard | } |
468 | 83469015 | bellard | } |
469 | 83469015 | bellard | |
470 | 83469015 | bellard | for(i = 0; i < MAX_PARALLEL_PORTS; i++) { |
471 | 83469015 | bellard | if (parallel_hds[i]) {
|
472 | 77f193da | blueswir1 | parallel_init(parallel_io[i], NULL/*parallel_irq[i]*/, |
473 | 77f193da | blueswir1 | parallel_hds[i]); |
474 | 83469015 | bellard | } |
475 | 83469015 | bellard | } |
476 | 83469015 | bellard | |
477 | 83469015 | bellard | for(i = 0; i < nb_nics; i++) { |
478 | a41b2ff2 | pbrook | if (!nd_table[i].model)
|
479 | a41b2ff2 | pbrook | nd_table[i].model = "ne2k_pci";
|
480 | f930d07e | blueswir1 | pci_nic_init(pci_bus, &nd_table[i], -1);
|
481 | 83469015 | bellard | } |
482 | 83469015 | bellard | |
483 | 9d926598 | blueswir1 | irq = qemu_allocate_irqs(cpu_set_irq, env, MAX_PILS); |
484 | e4bcb14c | ths | if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) {
|
485 | e4bcb14c | ths | fprintf(stderr, "qemu: too many IDE bus\n");
|
486 | e4bcb14c | ths | exit(1);
|
487 | e4bcb14c | ths | } |
488 | e4bcb14c | ths | for(i = 0; i < MAX_IDE_BUS * MAX_IDE_DEVS; i++) { |
489 | 22548760 | blueswir1 | drive_index = drive_get_index(IF_IDE, i / MAX_IDE_DEVS, |
490 | 22548760 | blueswir1 | i % MAX_IDE_DEVS); |
491 | 22548760 | blueswir1 | if (drive_index != -1) |
492 | 22548760 | blueswir1 | hd[i] = drives_table[drive_index].bdrv; |
493 | e4bcb14c | ths | else
|
494 | e4bcb14c | ths | hd[i] = NULL;
|
495 | e4bcb14c | ths | } |
496 | e4bcb14c | ths | |
497 | e4bcb14c | ths | // XXX pci_cmd646_ide_init(pci_bus, hd, 1);
|
498 | e4bcb14c | ths | pci_piix3_ide_init(pci_bus, hd, -1, irq);
|
499 | d537cf6c | pbrook | /* FIXME: wire up interrupts. */
|
500 | d537cf6c | pbrook | i8042_init(NULL/*1*/, NULL/*12*/, 0x60); |
501 | e4bcb14c | ths | for(i = 0; i < MAX_FD; i++) { |
502 | 22548760 | blueswir1 | drive_index = drive_get_index(IF_FLOPPY, 0, i);
|
503 | 22548760 | blueswir1 | if (drive_index != -1) |
504 | 22548760 | blueswir1 | fd[i] = drives_table[drive_index].bdrv; |
505 | e4bcb14c | ths | else
|
506 | e4bcb14c | ths | fd[i] = NULL;
|
507 | e4bcb14c | ths | } |
508 | e4bcb14c | ths | floppy_controller = fdctrl_init(NULL/*6*/, 2, 0, 0x3f0, fd); |
509 | d537cf6c | pbrook | nvram = m48t59_init(NULL/*8*/, 0, 0x0074, NVRAM_SIZE, 59); |
510 | 22548760 | blueswir1 | sun4u_NVRAM_set_params(nvram, NVRAM_SIZE, "Sun4u", RAM_size, boot_devices,
|
511 | 0d31cb99 | blueswir1 | KERNEL_LOAD_ADDR, kernel_size, |
512 | 0d31cb99 | blueswir1 | kernel_cmdline, |
513 | 0d31cb99 | blueswir1 | INITRD_LOAD_ADDR, initrd_size, |
514 | 0d31cb99 | blueswir1 | /* XXX: need an option to load a NVRAM image */
|
515 | 0d31cb99 | blueswir1 | 0,
|
516 | 0d31cb99 | blueswir1 | graphic_width, graphic_height, graphic_depth, |
517 | 0d31cb99 | blueswir1 | (uint8_t *)&nd_table[0].macaddr);
|
518 | 83469015 | bellard | |
519 | 3cce6243 | blueswir1 | fw_cfg = fw_cfg_init(BIOS_CFG_IOPORT, BIOS_CFG_IOPORT + 1, 0, 0); |
520 | 3cce6243 | blueswir1 | fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
|
521 | 905fdcb5 | blueswir1 | fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size); |
522 | 905fdcb5 | blueswir1 | fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id); |
523 | 3475187d | bellard | } |
524 | 3475187d | bellard | |
525 | 905fdcb5 | blueswir1 | enum {
|
526 | 905fdcb5 | blueswir1 | sun4u_id = 0,
|
527 | 905fdcb5 | blueswir1 | sun4v_id = 64,
|
528 | e87231d4 | blueswir1 | niagara_id, |
529 | 905fdcb5 | blueswir1 | }; |
530 | 905fdcb5 | blueswir1 | |
531 | c7ba218d | blueswir1 | static const struct hwdef hwdefs[] = { |
532 | c7ba218d | blueswir1 | /* Sun4u generic PC-like machine */
|
533 | c7ba218d | blueswir1 | { |
534 | c7ba218d | blueswir1 | .default_cpu_model = "TI UltraSparc II",
|
535 | 905fdcb5 | blueswir1 | .machine_id = sun4u_id, |
536 | e87231d4 | blueswir1 | .prom_addr = 0x1fff0000000ULL,
|
537 | e87231d4 | blueswir1 | .console_serial_base = 0,
|
538 | c7ba218d | blueswir1 | }, |
539 | c7ba218d | blueswir1 | /* Sun4v generic PC-like machine */
|
540 | c7ba218d | blueswir1 | { |
541 | c7ba218d | blueswir1 | .default_cpu_model = "Sun UltraSparc T1",
|
542 | 905fdcb5 | blueswir1 | .machine_id = sun4v_id, |
543 | e87231d4 | blueswir1 | .prom_addr = 0x1fff0000000ULL,
|
544 | e87231d4 | blueswir1 | .console_serial_base = 0,
|
545 | e87231d4 | blueswir1 | }, |
546 | e87231d4 | blueswir1 | /* Sun4v generic Niagara machine */
|
547 | e87231d4 | blueswir1 | { |
548 | e87231d4 | blueswir1 | .default_cpu_model = "Sun UltraSparc T1",
|
549 | e87231d4 | blueswir1 | .machine_id = niagara_id, |
550 | e87231d4 | blueswir1 | .prom_addr = 0xfff0000000ULL,
|
551 | e87231d4 | blueswir1 | .console_serial_base = 0xfff0c2c000ULL,
|
552 | c7ba218d | blueswir1 | }, |
553 | c7ba218d | blueswir1 | }; |
554 | c7ba218d | blueswir1 | |
555 | c7ba218d | blueswir1 | /* Sun4u hardware initialisation */
|
556 | c7ba218d | blueswir1 | static void sun4u_init(ram_addr_t RAM_size, int vga_ram_size, |
557 | c7ba218d | blueswir1 | const char *boot_devices, DisplayState *ds, |
558 | c7ba218d | blueswir1 | const char *kernel_filename, const char *kernel_cmdline, |
559 | c7ba218d | blueswir1 | const char *initrd_filename, const char *cpu_model) |
560 | c7ba218d | blueswir1 | { |
561 | c7ba218d | blueswir1 | sun4uv_init(RAM_size, vga_ram_size, boot_devices, ds, kernel_filename, |
562 | c7ba218d | blueswir1 | kernel_cmdline, initrd_filename, cpu_model, &hwdefs[0]);
|
563 | c7ba218d | blueswir1 | } |
564 | c7ba218d | blueswir1 | |
565 | c7ba218d | blueswir1 | /* Sun4v hardware initialisation */
|
566 | c7ba218d | blueswir1 | static void sun4v_init(ram_addr_t RAM_size, int vga_ram_size, |
567 | c7ba218d | blueswir1 | const char *boot_devices, DisplayState *ds, |
568 | c7ba218d | blueswir1 | const char *kernel_filename, const char *kernel_cmdline, |
569 | c7ba218d | blueswir1 | const char *initrd_filename, const char *cpu_model) |
570 | c7ba218d | blueswir1 | { |
571 | c7ba218d | blueswir1 | sun4uv_init(RAM_size, vga_ram_size, boot_devices, ds, kernel_filename, |
572 | c7ba218d | blueswir1 | kernel_cmdline, initrd_filename, cpu_model, &hwdefs[1]);
|
573 | c7ba218d | blueswir1 | } |
574 | c7ba218d | blueswir1 | |
575 | e87231d4 | blueswir1 | /* Niagara hardware initialisation */
|
576 | e87231d4 | blueswir1 | static void niagara_init(ram_addr_t RAM_size, int vga_ram_size, |
577 | e87231d4 | blueswir1 | const char *boot_devices, DisplayState *ds, |
578 | e87231d4 | blueswir1 | const char *kernel_filename, const char *kernel_cmdline, |
579 | e87231d4 | blueswir1 | const char *initrd_filename, const char *cpu_model) |
580 | e87231d4 | blueswir1 | { |
581 | e87231d4 | blueswir1 | sun4uv_init(RAM_size, vga_ram_size, boot_devices, ds, kernel_filename, |
582 | e87231d4 | blueswir1 | kernel_cmdline, initrd_filename, cpu_model, &hwdefs[2]);
|
583 | e87231d4 | blueswir1 | } |
584 | e87231d4 | blueswir1 | |
585 | 3475187d | bellard | QEMUMachine sun4u_machine = { |
586 | 66de733b | blueswir1 | .name = "sun4u",
|
587 | 66de733b | blueswir1 | .desc = "Sun4u platform",
|
588 | 66de733b | blueswir1 | .init = sun4u_init, |
589 | 66de733b | blueswir1 | .ram_require = PROM_SIZE_MAX + VGA_RAM_SIZE, |
590 | f88e4b91 | blueswir1 | .nodisk_ok = 1,
|
591 | 1bcee014 | blueswir1 | .max_cpus = 1, // XXX for now |
592 | 3475187d | bellard | }; |
593 | c7ba218d | blueswir1 | |
594 | c7ba218d | blueswir1 | QEMUMachine sun4v_machine = { |
595 | 66de733b | blueswir1 | .name = "sun4v",
|
596 | 66de733b | blueswir1 | .desc = "Sun4v platform",
|
597 | 66de733b | blueswir1 | .init = sun4v_init, |
598 | 66de733b | blueswir1 | .ram_require = PROM_SIZE_MAX + VGA_RAM_SIZE, |
599 | f88e4b91 | blueswir1 | .nodisk_ok = 1,
|
600 | 1bcee014 | blueswir1 | .max_cpus = 1, // XXX for now |
601 | c7ba218d | blueswir1 | }; |
602 | e87231d4 | blueswir1 | |
603 | e87231d4 | blueswir1 | QEMUMachine niagara_machine = { |
604 | e87231d4 | blueswir1 | .name = "Niagara",
|
605 | e87231d4 | blueswir1 | .desc = "Sun4v platform, Niagara",
|
606 | e87231d4 | blueswir1 | .init = niagara_init, |
607 | e87231d4 | blueswir1 | .ram_require = PROM_SIZE_MAX + VGA_RAM_SIZE, |
608 | e87231d4 | blueswir1 | .nodisk_ok = 1,
|
609 | 1bcee014 | blueswir1 | .max_cpus = 1, // XXX for now |
610 | e87231d4 | blueswir1 | }; |