root / hw / etraxfs.c @ a3867ed2
History | View | Annotate | Download (5.5 kB)
1 | 83fa1010 | ths | /*
|
---|---|---|---|
2 | 83fa1010 | ths | * QEMU ETRAX System Emulator
|
3 | 83fa1010 | ths | *
|
4 | 83fa1010 | ths | * Copyright (c) 2007 Edgar E. Iglesias, Axis Communications AB.
|
5 | 83fa1010 | ths | *
|
6 | 83fa1010 | ths | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 | 83fa1010 | ths | * of this software and associated documentation files (the "Software"), to deal
|
8 | 83fa1010 | ths | * in the Software without restriction, including without limitation the rights
|
9 | 83fa1010 | ths | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 | 83fa1010 | ths | * copies of the Software, and to permit persons to whom the Software is
|
11 | 83fa1010 | ths | * furnished to do so, subject to the following conditions:
|
12 | 83fa1010 | ths | *
|
13 | 83fa1010 | ths | * The above copyright notice and this permission notice shall be included in
|
14 | 83fa1010 | ths | * all copies or substantial portions of the Software.
|
15 | 83fa1010 | ths | *
|
16 | 83fa1010 | ths | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 | 83fa1010 | ths | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 | 83fa1010 | ths | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19 | 83fa1010 | ths | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 | 83fa1010 | ths | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 | 83fa1010 | ths | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 | 83fa1010 | ths | * THE SOFTWARE.
|
23 | 83fa1010 | ths | */
|
24 | 83fa1010 | ths | #include <time.h> |
25 | 83fa1010 | ths | #include <sys/time.h> |
26 | 87ecb68b | pbrook | #include "hw.h" |
27 | 48318011 | edgar_igl | #include "net.h" |
28 | e62b5b13 | edgar_igl | #include "flash.h" |
29 | 48318011 | edgar_igl | #include "sysemu.h" |
30 | 48318011 | edgar_igl | #include "devices.h" |
31 | 87ecb68b | pbrook | #include "boards.h" |
32 | 83fa1010 | ths | |
33 | 5ef98b47 | edgar_igl | #include "etraxfs.h" |
34 | b01cde7b | edgar_igl | |
35 | b01cde7b | edgar_igl | #define FLASH_SIZE 0x2000000 |
36 | b01cde7b | edgar_igl | #define INTMEM_SIZE (128 * 1024) |
37 | 83fa1010 | ths | |
38 | 5439779e | edgar_igl | static uint32_t bootstrap_pc;
|
39 | 5439779e | edgar_igl | |
40 | 5439779e | edgar_igl | static void main_cpu_reset(void *opaque) |
41 | 5439779e | edgar_igl | { |
42 | 5439779e | edgar_igl | CPUState *env = opaque; |
43 | 5439779e | edgar_igl | cpu_reset(env); |
44 | 5439779e | edgar_igl | |
45 | 5439779e | edgar_igl | env->pc = bootstrap_pc; |
46 | 5439779e | edgar_igl | } |
47 | 48318011 | edgar_igl | |
48 | 83fa1010 | ths | static
|
49 | 00f82b8a | aurel32 | void bareetraxfs_init (ram_addr_t ram_size, int vga_ram_size, |
50 | 3023f332 | aliguori | const char *boot_device, |
51 | 83fa1010 | ths | const char *kernel_filename, const char *kernel_cmdline, |
52 | 83fa1010 | ths | const char *initrd_filename, const char *cpu_model) |
53 | 83fa1010 | ths | { |
54 | 83fa1010 | ths | CPUState *env; |
55 | 5ef98b47 | edgar_igl | struct etraxfs_pic *pic;
|
56 | fa1bdde4 | edgar_igl | void *etraxfs_dmac;
|
57 | 4eeed608 | edgar_igl | struct etraxfs_dma_client *eth[2] = {NULL, NULL}; |
58 | 83fa1010 | ths | int kernel_size;
|
59 | 48318011 | edgar_igl | int i;
|
60 | e62b5b13 | edgar_igl | ram_addr_t phys_ram; |
61 | 5439779e | edgar_igl | ram_addr_t phys_flash; |
62 | b01cde7b | edgar_igl | ram_addr_t phys_intmem; |
63 | 83fa1010 | ths | |
64 | 83fa1010 | ths | /* init CPUs */
|
65 | 83fa1010 | ths | if (cpu_model == NULL) { |
66 | 83fa1010 | ths | cpu_model = "crisv32";
|
67 | 83fa1010 | ths | } |
68 | aaed909a | bellard | env = cpu_init(cpu_model); |
69 | 83fa1010 | ths | qemu_register_reset(main_cpu_reset, env); |
70 | 83fa1010 | ths | |
71 | 83fa1010 | ths | /* allocate RAM */
|
72 | e62b5b13 | edgar_igl | phys_ram = qemu_ram_alloc(ram_size); |
73 | e62b5b13 | edgar_igl | cpu_register_physical_memory(0x40000000, ram_size, phys_ram | IO_MEM_RAM);
|
74 | e62b5b13 | edgar_igl | |
75 | b01cde7b | edgar_igl | /* The ETRAX-FS has 128Kb on chip ram, the docs refer to it as the
|
76 | 980f8a0b | edgar_igl | internal memory. */
|
77 | b01cde7b | edgar_igl | phys_intmem = qemu_ram_alloc(INTMEM_SIZE); |
78 | 5439779e | edgar_igl | cpu_register_physical_memory(0x38000000, INTMEM_SIZE,
|
79 | 5439779e | edgar_igl | phys_intmem | IO_MEM_RAM); |
80 | 5439779e | edgar_igl | |
81 | e62b5b13 | edgar_igl | |
82 | 5439779e | edgar_igl | phys_flash = qemu_ram_alloc(FLASH_SIZE); |
83 | 5439779e | edgar_igl | i = drive_get_index(IF_PFLASH, 0, 0); |
84 | 5439779e | edgar_igl | pflash_cfi02_register(0x0, phys_flash,
|
85 | 9eee9a5d | edgar_igl | i != -1 ? drives_table[i].bdrv : NULL, (64 * 1024), |
86 | 5439779e | edgar_igl | FLASH_SIZE >> 16,
|
87 | 5439779e | edgar_igl | 1, 2, 0x0000, 0x0000, 0x0000, 0x0000, |
88 | 5439779e | edgar_igl | 0x555, 0x2aa); |
89 | 980f8a0b | edgar_igl | pic = etraxfs_pic_init(env, 0x3001c000);
|
90 | 980f8a0b | edgar_igl | etraxfs_dmac = etraxfs_dmac_init(env, 0x30000000, 10); |
91 | 48318011 | edgar_igl | for (i = 0; i < 10; i++) { |
92 | 5439779e | edgar_igl | /* On ETRAX, odd numbered channels are inputs. */
|
93 | 5ef98b47 | edgar_igl | etraxfs_dmac_connect(etraxfs_dmac, i, pic->irq + 7 + i, i & 1); |
94 | 48318011 | edgar_igl | } |
95 | 48318011 | edgar_igl | |
96 | 4eeed608 | edgar_igl | /* Add the two ethernet blocks. */
|
97 | 94410b78 | edgar_igl | eth[0] = etraxfs_eth_init(&nd_table[0], env, pic->irq + 25, 0x30034000, 1); |
98 | 0ae18cee | aliguori | if (nb_nics > 1) |
99 | 94410b78 | edgar_igl | eth[1] = etraxfs_eth_init(&nd_table[1], env, |
100 | 94410b78 | edgar_igl | pic->irq + 26, 0x30036000, 2); |
101 | 5439779e | edgar_igl | |
102 | 48318011 | edgar_igl | /* The DMA Connector block is missing, hardwire things for now. */
|
103 | 4eeed608 | edgar_igl | etraxfs_dmac_connect_client(etraxfs_dmac, 0, eth[0]); |
104 | 4eeed608 | edgar_igl | etraxfs_dmac_connect_client(etraxfs_dmac, 1, eth[0] + 1); |
105 | 4eeed608 | edgar_igl | if (eth[1]) { |
106 | 5439779e | edgar_igl | etraxfs_dmac_connect_client(etraxfs_dmac, 6, eth[1]); |
107 | 5439779e | edgar_igl | etraxfs_dmac_connect_client(etraxfs_dmac, 7, eth[1] + 1); |
108 | 4eeed608 | edgar_igl | } |
109 | 48318011 | edgar_igl | |
110 | ca87d03b | edgar_igl | /* 2 timers. */
|
111 | 980f8a0b | edgar_igl | etraxfs_timer_init(env, pic->irq + 0x1b, pic->nmi + 1, 0x3001e000); |
112 | 980f8a0b | edgar_igl | etraxfs_timer_init(env, pic->irq + 0x1b, pic->nmi + 1, 0x3005e000); |
113 | 48318011 | edgar_igl | |
114 | 48318011 | edgar_igl | for (i = 0; i < 4; i++) { |
115 | 5439779e | edgar_igl | if (serial_hds[i]) {
|
116 | 5ef98b47 | edgar_igl | etraxfs_ser_init(env, pic->irq + 0x14 + i,
|
117 | 980f8a0b | edgar_igl | serial_hds[i], 0x30026000 + i * 0x2000); |
118 | 5439779e | edgar_igl | } |
119 | 48318011 | edgar_igl | } |
120 | 83fa1010 | ths | |
121 | 5439779e | edgar_igl | if (kernel_filename) {
|
122 | f5a5cca3 | edgar_igl | uint64_t entry, high; |
123 | f5a5cca3 | edgar_igl | int kcmdline_len;
|
124 | f5a5cca3 | edgar_igl | |
125 | 5439779e | edgar_igl | /* Boots a kernel elf binary, os/linux-2.6/vmlinux from the axis
|
126 | 5439779e | edgar_igl | devboard SDK. */
|
127 | 8ab94444 | edgar_igl | kernel_size = load_elf(kernel_filename, -0x80000000LL,
|
128 | f5a5cca3 | edgar_igl | &entry, NULL, &high);
|
129 | fa1bdde4 | edgar_igl | bootstrap_pc = entry; |
130 | fa1bdde4 | edgar_igl | if (kernel_size < 0) { |
131 | fa1bdde4 | edgar_igl | /* Takes a kimage from the axis devboard SDK. */
|
132 | dcac9679 | pbrook | kernel_size = load_image_targphys(kernel_filename, 0x40004000,
|
133 | dcac9679 | pbrook | ram_size); |
134 | fa1bdde4 | edgar_igl | bootstrap_pc = 0x40004000;
|
135 | fa1bdde4 | edgar_igl | env->regs[9] = 0x40004000 + kernel_size; |
136 | fa1bdde4 | edgar_igl | } |
137 | 8ab94444 | edgar_igl | env->regs[8] = 0x56902387; /* RAM init magic. */ |
138 | f5a5cca3 | edgar_igl | |
139 | f5a5cca3 | edgar_igl | if (kernel_cmdline && (kcmdline_len = strlen(kernel_cmdline))) {
|
140 | f5a5cca3 | edgar_igl | if (kcmdline_len > 256) { |
141 | f5a5cca3 | edgar_igl | fprintf(stderr, "Too long CRIS kernel cmdline (max 256)\n");
|
142 | f5a5cca3 | edgar_igl | exit(1);
|
143 | f5a5cca3 | edgar_igl | } |
144 | f5a5cca3 | edgar_igl | pstrcpy_targphys(high, 256, kernel_cmdline);
|
145 | f5a5cca3 | edgar_igl | /* Let the kernel know we are modifying the cmdline. */
|
146 | f5a5cca3 | edgar_igl | env->regs[10] = 0x87109563; |
147 | f5a5cca3 | edgar_igl | env->regs[11] = high;
|
148 | f5a5cca3 | edgar_igl | } |
149 | 83fa1010 | ths | } |
150 | 5439779e | edgar_igl | env->pc = bootstrap_pc; |
151 | 83fa1010 | ths | |
152 | 83fa1010 | ths | printf ("pc =%x\n", env->pc);
|
153 | 48318011 | edgar_igl | printf ("ram size =%ld\n", ram_size);
|
154 | 83fa1010 | ths | } |
155 | 83fa1010 | ths | |
156 | 83fa1010 | ths | QEMUMachine bareetraxfs_machine = { |
157 | 4b32e168 | aliguori | .name = "bareetraxfs",
|
158 | 4b32e168 | aliguori | .desc = "Bare ETRAX FS board",
|
159 | 4b32e168 | aliguori | .init = bareetraxfs_init, |
160 | 83fa1010 | ths | }; |