ETRAX-FS board: Add more flash and internal memory. Select interrupt nr for the
[qemu] / hw / etraxfs.c
1 /*
2  * QEMU ETRAX System Emulator
3  *
4  * Copyright (c) 2007 Edgar E. Iglesias, Axis Communications AB.
5  *
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:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
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
22  * THE SOFTWARE.
23  */
24 #include <time.h>
25 #include <sys/time.h>
26 #include "hw.h"
27 #include "sysemu.h"
28 #include "flash.h"
29 #include "boards.h"
30
31 static void main_cpu_reset(void *opaque)
32 {
33     CPUState *env = opaque;
34     cpu_reset(env);
35 }
36
37 /* Init functions for different blocks.  */
38 extern qemu_irq *etraxfs_pic_init(CPUState *env, target_phys_addr_t base);
39 void etraxfs_timer_init(CPUState *env, qemu_irq *irqs, 
40                         target_phys_addr_t base);
41 void etraxfs_ser_init(CPUState *env, qemu_irq *irq, CharDriverState *chr,
42                       target_phys_addr_t base);
43
44 #define FLASH_SIZE 0x2000000
45 #define INTMEM_SIZE (128 * 1024)
46
47 static
48 void bareetraxfs_init (ram_addr_t ram_size, int vga_ram_size,
49                        const char *boot_device, DisplayState *ds,
50                        const char *kernel_filename, const char *kernel_cmdline,
51                        const char *initrd_filename, const char *cpu_model)
52 {
53     CPUState *env;
54     qemu_irq *pic;
55     int kernel_size;
56     int index;
57     ram_addr_t phys_ram;
58     ram_addr_t phys_intmem;
59
60     /* init CPUs */
61     if (cpu_model == NULL) {
62         cpu_model = "crisv32";
63     }
64     env = cpu_init(cpu_model);
65 /*    register_savevm("cpu", 0, 3, cpu_save, cpu_load, env); */
66     qemu_register_reset(main_cpu_reset, env);
67
68     /* allocate RAM */
69     phys_ram = qemu_ram_alloc(ram_size);
70     cpu_register_physical_memory(0x40000000, ram_size, phys_ram | IO_MEM_RAM);
71     /* Unached mapping.  */
72     cpu_register_physical_memory(0xc0000000, ram_size, phys_ram | IO_MEM_RAM);
73
74     /* The ETRAX-FS has 128Kb on chip ram, the docs refer to it as the 
75        internal memory. Cached and uncached mappings.  */
76     phys_intmem = qemu_ram_alloc(INTMEM_SIZE);
77     cpu_register_physical_memory(0xb8000000, INTMEM_SIZE, 
78                                  phys_intmem | IO_MEM_RAM);
79     cpu_register_physical_memory(0x38000000, INTMEM_SIZE, 
80                                  phys_intmem | IO_MEM_RAM);
81
82     cpu_register_physical_memory(0, FLASH_SIZE, IO_MEM_ROM);
83     cpu_register_physical_memory(0x80000000, FLASH_SIZE, IO_MEM_ROM);
84     cpu_register_physical_memory(0x04000000, FLASH_SIZE, IO_MEM_ROM);
85     cpu_register_physical_memory(0x84000000, FLASH_SIZE, 
86                                  0x04000000 | IO_MEM_ROM);
87     index = drive_get_index(IF_PFLASH, 0, 0);
88     pflash_cfi01_register(0x80000000, FLASH_SIZE,
89                           drives_table[index].bdrv, 65536, FLASH_SIZE >> 16,
90                           4, 0x0000, 0x0000, 0x0000, 0x0000);
91
92     pic = etraxfs_pic_init(env, 0xb001c000);
93     /* 2 timers.  */
94     etraxfs_timer_init(env, pic + 26, 0xb001e000);
95     etraxfs_timer_init(env, pic + 26, 0xb005e000);
96     /* 4 serial ports.  */
97     etraxfs_ser_init(env, pic + 19, serial_hds[0], 0xb0026000);
98     if (serial_hds[1])
99             etraxfs_ser_init(env, pic + 20, serial_hds[1], 0xb0028000);
100     if (serial_hds[2])
101             etraxfs_ser_init(env, pic + 21, serial_hds[2], 0xb002a000);
102     if (serial_hds[3])
103             etraxfs_ser_init(env, pic + 22, serial_hds[3], 0xb002c000);
104
105 #if 1
106     /* Boots a kernel elf binary, os/linux-2.6/vmlinux from the axis devboard
107        SDK.  */
108     kernel_size = load_elf(kernel_filename, 0, &env->pc, NULL, NULL);
109 #else
110     /* Takes a kimage from the axis devboard SDK.  */
111     kernel_size = load_image(kernel_filename, phys_ram_base + 0x4000);
112     env->pc = 0x40004000;
113 #endif
114     /* magic for boot.  */
115     env->regs[8] = 0x56902387;
116     env->regs[9] = 0x40004000 + kernel_size;
117
118     {
119        unsigned char *ptr = phys_ram_base + 0x4000;
120        int i;
121        for (i = 0; i < 8; i++)
122        {
123                 printf ("%2.2x ", ptr[i]);
124        }
125         printf("\n");
126     }
127
128     printf ("pc =%x\n", env->pc);
129     printf ("ram size =%d\n", ram_size);
130     printf ("kernel name =%s\n", kernel_filename);
131     printf ("kernel size =%d\n", kernel_size);
132     printf ("cpu haltd =%d\n", env->halted);
133 }
134
135 void DMA_run(void)
136 {
137 }
138
139 QEMUMachine bareetraxfs_machine = {
140     "bareetraxfs",
141     "Bare ETRAX FS board",
142     bareetraxfs_init,
143     0x800000,
144 };