Statistics
| Branch: | Revision:

root / hw / r2d.c @ b319feb7

History | View | Annotate | Download (4.3 kB)

1
/*
2
 * Renesas SH7751R R2D-PLUS emulation
3
 *
4
 * Copyright (c) 2007 Magnus Damm
5
 * Copyright (c) 2008 Paul Mundt
6
 *
7
 * Permission is hereby granted, free of charge, to any person obtaining a copy
8
 * of this software and associated documentation files (the "Software"), to deal
9
 * in the Software without restriction, including without limitation the rights
10
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
 * copies of the Software, and to permit persons to whom the Software is
12
 * furnished to do so, subject to the following conditions:
13
 *
14
 * The above copyright notice and this permission notice shall be included in
15
 * all copies or substantial portions of the Software.
16
 *
17
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
 * THE SOFTWARE.
24
 */
25

    
26
#include "hw.h"
27
#include "sh.h"
28
#include "sysemu.h"
29
#include "boards.h"
30
#include "assert.h"
31

    
32
#define SDRAM_BASE 0x0c000000 /* Physical location of SDRAM: Area 3 */
33
#define SDRAM_SIZE 0x04000000
34

    
35
#define PA_POWOFF        0x30
36
#define PA_VERREG        0x32
37
#define PA_OUTPORT        0x36
38

    
39
typedef struct {
40
    target_phys_addr_t base;
41

    
42
    uint16_t bcr;
43
    uint16_t irlmon;
44
    uint16_t cfctl;
45
    uint16_t cfpow;
46
    uint16_t dispctl;
47
    uint16_t sdmpow;
48
    uint16_t rtcce;
49
    uint16_t pcicd;
50
    uint16_t voyagerrts;
51
    uint16_t cfrst;
52
    uint16_t admrts;
53
    uint16_t extrst;
54
    uint16_t cfcdintclr;
55
    uint16_t keyctlclr;
56
    uint16_t pad0;
57
    uint16_t pad1;
58
    uint16_t powoff;
59
    uint16_t verreg;
60
    uint16_t inport;
61
    uint16_t outport;
62
    uint16_t bverreg;
63
} r2d_fpga_t;
64

    
65
static uint32_t r2d_fpga_read(void *opaque, target_phys_addr_t addr)
66
{
67
    r2d_fpga_t *s = opaque;
68

    
69
    addr -= s->base;
70

    
71
    switch (addr) {
72
    case PA_OUTPORT:
73
        return s->outport;
74
    case PA_POWOFF:
75
        return s->powoff;
76
    case PA_VERREG:
77
        return 0x10;
78
    }
79

    
80
    return 0;
81
}
82

    
83
static void
84
r2d_fpga_write(void *opaque, target_phys_addr_t addr, uint32_t value)
85
{
86
    r2d_fpga_t *s = opaque;
87

    
88
    addr -= s->base;
89

    
90
    switch (addr) {
91
    case PA_OUTPORT:
92
        s->outport = value;
93
        break;
94
    case PA_POWOFF:
95
        s->powoff = value;
96
        break;
97
    case PA_VERREG:
98
        /* Discard writes */
99
        break;
100
    }
101
}
102

    
103
static uint32_t invalid_read(void *opaque, target_phys_addr_t addr)
104
{
105
    assert(0);
106

    
107
    return 0;
108
}
109

    
110
static void invalid_write(void *opaque, target_phys_addr_t addr,
111
                          uint32_t mem_value)
112
{
113
    assert(0);
114
}
115

    
116
static CPUReadMemoryFunc *r2d_fpga_readfn[] = {
117
    r2d_fpga_read,
118
    r2d_fpga_read,
119
    invalid_read,
120
};
121

    
122
static CPUWriteMemoryFunc *r2d_fpga_writefn[] = {
123
    r2d_fpga_write,
124
    r2d_fpga_write,
125
    invalid_write,
126
};
127

    
128
static void r2d_fpga_init(target_phys_addr_t base)
129
{
130
    int iomemtype;
131
    r2d_fpga_t *s;
132

    
133
    s = qemu_mallocz(sizeof(r2d_fpga_t));
134
    if (!s)
135
        return;
136

    
137
    s->base = base;
138
    iomemtype = cpu_register_io_memory(0, r2d_fpga_readfn,
139
                                       r2d_fpga_writefn, s);
140
    cpu_register_physical_memory(base, 0x40, iomemtype);
141
}
142

    
143
static void r2d_init(ram_addr_t ram_size, int vga_ram_size,
144
              const char *boot_device, DisplayState * ds,
145
              const char *kernel_filename, const char *kernel_cmdline,
146
              const char *initrd_filename, const char *cpu_model)
147
{
148
    CPUState *env;
149
    struct SH7750State *s;
150

    
151
    if (!cpu_model)
152
        cpu_model = "SH7751R";
153

    
154
    env = cpu_init(cpu_model);
155
    if (!env) {
156
        fprintf(stderr, "Unable to find CPU definition\n");
157
        exit(1);
158
    }
159

    
160
    /* Allocate memory space */
161
    cpu_register_physical_memory(SDRAM_BASE, SDRAM_SIZE, 0);
162
    /* Register peripherals */
163
    r2d_fpga_init(0x04000000);
164
    s = sh7750_init(env);
165
    /* Todo: register on board registers */
166
    {
167
      int kernel_size;
168

    
169
      kernel_size = load_image(kernel_filename, phys_ram_base);
170

    
171
      if (kernel_size < 0) {
172
        fprintf(stderr, "qemu: could not load kernel '%s'\n", kernel_filename);
173
        exit(1);
174
      }
175

    
176
      env->pc = SDRAM_BASE | 0xa0000000; /* Start from P2 area */
177
    }
178
}
179

    
180
QEMUMachine r2d_machine = {
181
    "r2d",
182
    "r2d-plus board",
183
    r2d_init,
184
    SDRAM_SIZE | RAMSIZE_FIXED
185
};