root / hw / g364fb.c @ 0c3271c5
History | View | Annotate | Download (18 kB)
1 | 1fc3d392 | aurel32 | /*
|
---|---|---|---|
2 | 1fc3d392 | aurel32 | * QEMU G364 framebuffer Emulator.
|
3 | 1fc3d392 | aurel32 | *
|
4 | 0add30cf | aurel32 | * Copyright (c) 2007-2009 Herve Poussineau
|
5 | 1fc3d392 | aurel32 | *
|
6 | 1fc3d392 | aurel32 | * This program is free software; you can redistribute it and/or
|
7 | 1fc3d392 | aurel32 | * modify it under the terms of the GNU General Public License as
|
8 | 1fc3d392 | aurel32 | * published by the Free Software Foundation; either version 2 of
|
9 | 1fc3d392 | aurel32 | * the License, or (at your option) any later version.
|
10 | 1fc3d392 | aurel32 | *
|
11 | 1fc3d392 | aurel32 | * This program is distributed in the hope that it will be useful,
|
12 | 1fc3d392 | aurel32 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 1fc3d392 | aurel32 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 | 1fc3d392 | aurel32 | * GNU General Public License for more details.
|
15 | 1fc3d392 | aurel32 | *
|
16 | fad6cb1a | aurel32 | * You should have received a copy of the GNU General Public License along
|
17 | fad6cb1a | aurel32 | * with this program; if not, write to the Free Software Foundation, Inc.,
|
18 | fad6cb1a | aurel32 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
19 | 1fc3d392 | aurel32 | */
|
20 | 1fc3d392 | aurel32 | |
21 | 1fc3d392 | aurel32 | #include "hw.h" |
22 | cd5158ea | aurel32 | #include "mips.h" |
23 | 1fc3d392 | aurel32 | #include "console.h" |
24 | 1fc3d392 | aurel32 | #include "pixel_ops.h" |
25 | 1fc3d392 | aurel32 | |
26 | 1fc3d392 | aurel32 | //#define DEBUG_G364
|
27 | 1fc3d392 | aurel32 | |
28 | 0add30cf | aurel32 | #ifdef DEBUG_G364
|
29 | 001faf32 | Blue Swirl | #define DPRINTF(fmt, ...) \
|
30 | 001faf32 | Blue Swirl | do { printf("g364: " fmt , ## __VA_ARGS__); } while (0) |
31 | 0add30cf | aurel32 | #else
|
32 | 001faf32 | Blue Swirl | #define DPRINTF(fmt, ...) do {} while (0) |
33 | 0add30cf | aurel32 | #endif
|
34 | 001faf32 | Blue Swirl | #define BADF(fmt, ...) \
|
35 | 001faf32 | Blue Swirl | do { fprintf(stderr, "g364 ERROR: " fmt , ## __VA_ARGS__);} while (0) |
36 | 0add30cf | aurel32 | |
37 | 1fc3d392 | aurel32 | typedef struct G364State { |
38 | 0add30cf | aurel32 | /* hardware */
|
39 | 0add30cf | aurel32 | uint8_t *vram; |
40 | 0add30cf | aurel32 | ram_addr_t vram_offset; |
41 | 0add30cf | aurel32 | int vram_size;
|
42 | 0add30cf | aurel32 | qemu_irq irq; |
43 | 0add30cf | aurel32 | /* registers */
|
44 | 0add30cf | aurel32 | uint8_t color_palette[256][3]; |
45 | 0add30cf | aurel32 | uint8_t cursor_palette[3][3]; |
46 | 0add30cf | aurel32 | uint16_t cursor[512];
|
47 | 0add30cf | aurel32 | uint32_t cursor_position; |
48 | 1fc3d392 | aurel32 | uint32_t ctla; |
49 | 0add30cf | aurel32 | uint32_t top_of_screen; |
50 | 0add30cf | aurel32 | uint32_t width, height; /* in pixels */
|
51 | 1fc3d392 | aurel32 | /* display refresh support */
|
52 | 1fc3d392 | aurel32 | DisplayState *ds; |
53 | 0add30cf | aurel32 | int depth;
|
54 | 0add30cf | aurel32 | int blanked;
|
55 | 1fc3d392 | aurel32 | } G364State; |
56 | 1fc3d392 | aurel32 | |
57 | 0add30cf | aurel32 | #define REG_ID 0x000000 |
58 | 0add30cf | aurel32 | #define REG_BOOT 0x080000 |
59 | 0add30cf | aurel32 | #define REG_DISPLAY 0x080118 |
60 | 0add30cf | aurel32 | #define REG_VDISPLAY 0x080150 |
61 | 0add30cf | aurel32 | #define REG_CTLA 0x080300 |
62 | 0add30cf | aurel32 | #define REG_TOP 0x080400 |
63 | 0add30cf | aurel32 | #define REG_CURS_PAL 0x080508 |
64 | 0add30cf | aurel32 | #define REG_CURS_POS 0x080638 |
65 | 0add30cf | aurel32 | #define REG_CLR_PAL 0x080800 |
66 | 0add30cf | aurel32 | #define REG_CURS_PAT 0x081000 |
67 | 0add30cf | aurel32 | #define REG_RESET 0x180000 |
68 | 0add30cf | aurel32 | |
69 | 0add30cf | aurel32 | #define CTLA_FORCE_BLANK 0x00000400 |
70 | 0add30cf | aurel32 | #define CTLA_NO_CURSOR 0x00800000 |
71 | 0add30cf | aurel32 | |
72 | 0add30cf | aurel32 | static inline int check_dirty(ram_addr_t page) |
73 | 0add30cf | aurel32 | { |
74 | 0add30cf | aurel32 | return cpu_physical_memory_get_dirty(page, VGA_DIRTY_FLAG);
|
75 | 0add30cf | aurel32 | } |
76 | 0add30cf | aurel32 | |
77 | 0add30cf | aurel32 | static inline void reset_dirty(G364State *s, |
78 | 0add30cf | aurel32 | ram_addr_t page_min, ram_addr_t page_max) |
79 | 0add30cf | aurel32 | { |
80 | 0add30cf | aurel32 | cpu_physical_memory_reset_dirty(page_min, page_max + TARGET_PAGE_SIZE - 1,
|
81 | 0add30cf | aurel32 | VGA_DIRTY_FLAG); |
82 | 0add30cf | aurel32 | } |
83 | 0add30cf | aurel32 | |
84 | 0add30cf | aurel32 | static void g364fb_draw_graphic8(G364State *s) |
85 | 1fc3d392 | aurel32 | { |
86 | 0add30cf | aurel32 | int i, w;
|
87 | 0add30cf | aurel32 | uint8_t *vram; |
88 | 0add30cf | aurel32 | uint8_t *data_display, *dd; |
89 | 0add30cf | aurel32 | ram_addr_t page, page_min, page_max; |
90 | 0add30cf | aurel32 | int x, y;
|
91 | 0add30cf | aurel32 | int xmin, xmax;
|
92 | 0add30cf | aurel32 | int ymin, ymax;
|
93 | 0add30cf | aurel32 | int xcursor, ycursor;
|
94 | 0add30cf | aurel32 | unsigned int (*rgb_to_pixel)(unsigned int r, unsigned int g, unsigned int b); |
95 | 0add30cf | aurel32 | |
96 | 0e1f5a0c | aliguori | switch (ds_get_bits_per_pixel(s->ds)) {
|
97 | 1fc3d392 | aurel32 | case 8: |
98 | 0add30cf | aurel32 | rgb_to_pixel = rgb_to_pixel8; |
99 | 0add30cf | aurel32 | w = 1;
|
100 | 1fc3d392 | aurel32 | break;
|
101 | 1fc3d392 | aurel32 | case 15: |
102 | 0add30cf | aurel32 | rgb_to_pixel = rgb_to_pixel15; |
103 | 0add30cf | aurel32 | w = 2;
|
104 | 1fc3d392 | aurel32 | break;
|
105 | 1fc3d392 | aurel32 | case 16: |
106 | 0add30cf | aurel32 | rgb_to_pixel = rgb_to_pixel16; |
107 | 0add30cf | aurel32 | w = 2;
|
108 | 1fc3d392 | aurel32 | break;
|
109 | 1fc3d392 | aurel32 | case 32: |
110 | 0add30cf | aurel32 | rgb_to_pixel = rgb_to_pixel32; |
111 | 0add30cf | aurel32 | w = 4;
|
112 | 1fc3d392 | aurel32 | break;
|
113 | 1fc3d392 | aurel32 | default:
|
114 | 0add30cf | aurel32 | BADF("unknown host depth %d\n", ds_get_bits_per_pixel(s->ds));
|
115 | 1fc3d392 | aurel32 | return;
|
116 | 1fc3d392 | aurel32 | } |
117 | 1fc3d392 | aurel32 | |
118 | 0add30cf | aurel32 | page = s->vram_offset; |
119 | 0add30cf | aurel32 | page_min = (ram_addr_t)-1;
|
120 | 0add30cf | aurel32 | page_max = 0;
|
121 | 0add30cf | aurel32 | |
122 | 0add30cf | aurel32 | x = y = 0;
|
123 | 0add30cf | aurel32 | xmin = s->width; |
124 | 0add30cf | aurel32 | xmax = 0;
|
125 | 0add30cf | aurel32 | ymin = s->height; |
126 | 0add30cf | aurel32 | ymax = 0;
|
127 | 0add30cf | aurel32 | |
128 | 0add30cf | aurel32 | if (!(s->ctla & CTLA_NO_CURSOR)) {
|
129 | 0add30cf | aurel32 | xcursor = s->cursor_position >> 12;
|
130 | 0add30cf | aurel32 | ycursor = s->cursor_position & 0xfff;
|
131 | 0add30cf | aurel32 | } else {
|
132 | 0add30cf | aurel32 | xcursor = ycursor = -65;
|
133 | 0add30cf | aurel32 | } |
134 | 0add30cf | aurel32 | |
135 | 0add30cf | aurel32 | vram = s->vram + s->top_of_screen; |
136 | 0add30cf | aurel32 | /* XXX: out of range in vram? */
|
137 | 0add30cf | aurel32 | data_display = dd = ds_get_data(s->ds); |
138 | 0add30cf | aurel32 | while (y < s->height) {
|
139 | 0add30cf | aurel32 | if (check_dirty(page)) {
|
140 | 0add30cf | aurel32 | if (y < ymin)
|
141 | 0add30cf | aurel32 | ymin = ymax = y; |
142 | 0add30cf | aurel32 | if (page_min == (ram_addr_t)-1) |
143 | 0add30cf | aurel32 | page_min = page; |
144 | 0add30cf | aurel32 | page_max = page; |
145 | 0add30cf | aurel32 | if (x < xmin)
|
146 | 0add30cf | aurel32 | xmin = x; |
147 | 0add30cf | aurel32 | for (i = 0; i < TARGET_PAGE_SIZE; i++) { |
148 | 0add30cf | aurel32 | uint8_t index; |
149 | 0add30cf | aurel32 | unsigned int color; |
150 | 0add30cf | aurel32 | if (unlikely((y >= ycursor && y < ycursor + 64) && |
151 | 0add30cf | aurel32 | (x >= xcursor && x < xcursor + 64))) {
|
152 | 0add30cf | aurel32 | /* pointer area */
|
153 | 0add30cf | aurel32 | int xdiff = x - xcursor;
|
154 | 0add30cf | aurel32 | uint16_t curs = s->cursor[(y - ycursor) * 8 + xdiff / 8]; |
155 | 0add30cf | aurel32 | int op = (curs >> ((xdiff & 7) * 2)) & 3; |
156 | 0add30cf | aurel32 | if (likely(op == 0)) { |
157 | 0add30cf | aurel32 | /* transparent */
|
158 | 0add30cf | aurel32 | index = *vram; |
159 | 0add30cf | aurel32 | color = (*rgb_to_pixel)( |
160 | 0add30cf | aurel32 | s->color_palette[index][0],
|
161 | 0add30cf | aurel32 | s->color_palette[index][1],
|
162 | 0add30cf | aurel32 | s->color_palette[index][2]);
|
163 | 0add30cf | aurel32 | } else {
|
164 | 0add30cf | aurel32 | /* get cursor color */
|
165 | 0add30cf | aurel32 | index = op - 1;
|
166 | 0add30cf | aurel32 | color = (*rgb_to_pixel)( |
167 | 0add30cf | aurel32 | s->cursor_palette[index][0],
|
168 | 0add30cf | aurel32 | s->cursor_palette[index][1],
|
169 | 0add30cf | aurel32 | s->cursor_palette[index][2]);
|
170 | 0add30cf | aurel32 | } |
171 | 0add30cf | aurel32 | } else {
|
172 | 0add30cf | aurel32 | /* normal area */
|
173 | 0add30cf | aurel32 | index = *vram; |
174 | 0add30cf | aurel32 | color = (*rgb_to_pixel)( |
175 | 0add30cf | aurel32 | s->color_palette[index][0],
|
176 | 0add30cf | aurel32 | s->color_palette[index][1],
|
177 | 0add30cf | aurel32 | s->color_palette[index][2]);
|
178 | 0add30cf | aurel32 | } |
179 | 0add30cf | aurel32 | memcpy(dd, &color, w); |
180 | 0add30cf | aurel32 | dd += w; |
181 | 0add30cf | aurel32 | x++; |
182 | 0add30cf | aurel32 | vram++; |
183 | 0add30cf | aurel32 | if (x == s->width) {
|
184 | 0add30cf | aurel32 | xmax = s->width - 1;
|
185 | 0add30cf | aurel32 | y++; |
186 | 0add30cf | aurel32 | if (y == s->height) {
|
187 | 0add30cf | aurel32 | ymax = s->height - 1;
|
188 | 0add30cf | aurel32 | goto done;
|
189 | 0add30cf | aurel32 | } |
190 | 0add30cf | aurel32 | data_display = dd = data_display + ds_get_linesize(s->ds); |
191 | 0add30cf | aurel32 | xmin = 0;
|
192 | 0add30cf | aurel32 | x = 0;
|
193 | 0add30cf | aurel32 | } |
194 | 0add30cf | aurel32 | } |
195 | 0add30cf | aurel32 | if (x > xmax)
|
196 | 0add30cf | aurel32 | xmax = x; |
197 | 0add30cf | aurel32 | if (y > ymax)
|
198 | 0add30cf | aurel32 | ymax = y; |
199 | 0add30cf | aurel32 | } else {
|
200 | 0add30cf | aurel32 | int dy;
|
201 | 0add30cf | aurel32 | if (page_min != (ram_addr_t)-1) { |
202 | 0add30cf | aurel32 | reset_dirty(s, page_min, page_max); |
203 | 0add30cf | aurel32 | page_min = (ram_addr_t)-1;
|
204 | 0add30cf | aurel32 | page_max = 0;
|
205 | 0add30cf | aurel32 | dpy_update(s->ds, xmin, ymin, xmax - xmin + 1, ymax - ymin + 1); |
206 | 0add30cf | aurel32 | xmin = s->width; |
207 | 0add30cf | aurel32 | xmax = 0;
|
208 | 0add30cf | aurel32 | ymin = s->height; |
209 | 0add30cf | aurel32 | ymax = 0;
|
210 | 0add30cf | aurel32 | } |
211 | 0add30cf | aurel32 | x += TARGET_PAGE_SIZE; |
212 | 0add30cf | aurel32 | dy = x / s->width; |
213 | 0add30cf | aurel32 | x = x % s->width; |
214 | 0add30cf | aurel32 | y += dy; |
215 | 0add30cf | aurel32 | vram += TARGET_PAGE_SIZE; |
216 | 0add30cf | aurel32 | data_display += dy * ds_get_linesize(s->ds); |
217 | 0add30cf | aurel32 | dd = data_display + x * w; |
218 | 0add30cf | aurel32 | } |
219 | 0add30cf | aurel32 | page += TARGET_PAGE_SIZE; |
220 | 0add30cf | aurel32 | } |
221 | 0add30cf | aurel32 | |
222 | 0add30cf | aurel32 | done:
|
223 | 0add30cf | aurel32 | if (page_min != (ram_addr_t)-1) { |
224 | 0add30cf | aurel32 | dpy_update(s->ds, xmin, ymin, xmax - xmin + 1, ymax - ymin + 1); |
225 | 0add30cf | aurel32 | reset_dirty(s, page_min, page_max); |
226 | 0add30cf | aurel32 | } |
227 | 1fc3d392 | aurel32 | } |
228 | 1fc3d392 | aurel32 | |
229 | 0add30cf | aurel32 | static void g364fb_draw_blank(G364State *s) |
230 | 1fc3d392 | aurel32 | { |
231 | 1fc3d392 | aurel32 | int i, w;
|
232 | 1fc3d392 | aurel32 | uint8_t *d; |
233 | 1fc3d392 | aurel32 | |
234 | 0add30cf | aurel32 | if (s->blanked) {
|
235 | 0add30cf | aurel32 | /* Screen is already blank. No need to redraw it */
|
236 | 1fc3d392 | aurel32 | return;
|
237 | 0add30cf | aurel32 | } |
238 | 1fc3d392 | aurel32 | |
239 | 0add30cf | aurel32 | w = s->width * ((ds_get_bits_per_pixel(s->ds) + 7) >> 3); |
240 | 0e1f5a0c | aliguori | d = ds_get_data(s->ds); |
241 | 0add30cf | aurel32 | for (i = 0; i < s->height; i++) { |
242 | 1fc3d392 | aurel32 | memset(d, 0, w);
|
243 | 0e1f5a0c | aliguori | d += ds_get_linesize(s->ds); |
244 | 1fc3d392 | aurel32 | } |
245 | 221bb2d5 | aurel32 | |
246 | 0add30cf | aurel32 | dpy_update(s->ds, 0, 0, s->width, s->height); |
247 | 0add30cf | aurel32 | s->blanked = 1;
|
248 | 1fc3d392 | aurel32 | } |
249 | 1fc3d392 | aurel32 | |
250 | 1fc3d392 | aurel32 | static void g364fb_update_display(void *opaque) |
251 | 1fc3d392 | aurel32 | { |
252 | 1fc3d392 | aurel32 | G364State *s = opaque; |
253 | 1fc3d392 | aurel32 | |
254 | 0add30cf | aurel32 | if (s->width == 0 || s->height == 0) |
255 | 221bb2d5 | aurel32 | return;
|
256 | 221bb2d5 | aurel32 | |
257 | 0add30cf | aurel32 | if (s->width != ds_get_width(s->ds) || s->height != ds_get_height(s->ds)) {
|
258 | 0add30cf | aurel32 | qemu_console_resize(s->ds, s->width, s->height); |
259 | 221bb2d5 | aurel32 | } |
260 | 0add30cf | aurel32 | |
261 | 0add30cf | aurel32 | if (s->ctla & CTLA_FORCE_BLANK) {
|
262 | 0add30cf | aurel32 | g364fb_draw_blank(s); |
263 | 0add30cf | aurel32 | } else if (s->depth == 8) { |
264 | 0add30cf | aurel32 | g364fb_draw_graphic8(s); |
265 | 0add30cf | aurel32 | } else {
|
266 | 0add30cf | aurel32 | BADF("unknown guest depth %d\n", s->depth);
|
267 | 1fc3d392 | aurel32 | } |
268 | 0add30cf | aurel32 | |
269 | 0add30cf | aurel32 | qemu_irq_raise(s->irq); |
270 | 1fc3d392 | aurel32 | } |
271 | 1fc3d392 | aurel32 | |
272 | 0add30cf | aurel32 | static void inline g364fb_invalidate_display(void *opaque) |
273 | 1fc3d392 | aurel32 | { |
274 | 1fc3d392 | aurel32 | G364State *s = opaque; |
275 | 0add30cf | aurel32 | int i;
|
276 | 0add30cf | aurel32 | |
277 | 0add30cf | aurel32 | s->blanked = 0;
|
278 | 0add30cf | aurel32 | for (i = 0; i < s->vram_size; i += TARGET_PAGE_SIZE) { |
279 | 0add30cf | aurel32 | cpu_physical_memory_set_dirty(s->vram_offset + i); |
280 | 0add30cf | aurel32 | } |
281 | 1fc3d392 | aurel32 | } |
282 | 1fc3d392 | aurel32 | |
283 | 1fc3d392 | aurel32 | static void g364fb_reset(void *opaque) |
284 | 1fc3d392 | aurel32 | { |
285 | 1fc3d392 | aurel32 | G364State *s = opaque; |
286 | 0add30cf | aurel32 | qemu_irq_lower(s->irq); |
287 | 0add30cf | aurel32 | |
288 | 0add30cf | aurel32 | memset(s->color_palette, 0, sizeof(s->color_palette)); |
289 | 0add30cf | aurel32 | memset(s->cursor_palette, 0, sizeof(s->cursor_palette)); |
290 | 0add30cf | aurel32 | memset(s->cursor, 0, sizeof(s->cursor)); |
291 | 0add30cf | aurel32 | s->cursor_position = 0;
|
292 | 0add30cf | aurel32 | s->ctla = 0;
|
293 | 0add30cf | aurel32 | s->top_of_screen = 0;
|
294 | 0add30cf | aurel32 | s->width = s->height = 0;
|
295 | 0add30cf | aurel32 | memset(s->vram, 0, s->vram_size);
|
296 | 0add30cf | aurel32 | g364fb_invalidate_display(opaque); |
297 | 1fc3d392 | aurel32 | } |
298 | 1fc3d392 | aurel32 | |
299 | 1fc3d392 | aurel32 | static void g364fb_screen_dump(void *opaque, const char *filename) |
300 | 1fc3d392 | aurel32 | { |
301 | 1fc3d392 | aurel32 | G364State *s = opaque; |
302 | 1fc3d392 | aurel32 | int y, x;
|
303 | 1fc3d392 | aurel32 | uint8_t index; |
304 | 1fc3d392 | aurel32 | uint8_t *data_buffer; |
305 | 1fc3d392 | aurel32 | FILE *f; |
306 | 1fc3d392 | aurel32 | |
307 | 0add30cf | aurel32 | if (s->depth != 8) { |
308 | 0add30cf | aurel32 | BADF("unknown guest depth %d\n", s->depth);
|
309 | 0add30cf | aurel32 | return;
|
310 | 0add30cf | aurel32 | } |
311 | 0add30cf | aurel32 | |
312 | 1fc3d392 | aurel32 | f = fopen(filename, "wb");
|
313 | 1fc3d392 | aurel32 | if (!f)
|
314 | 1fc3d392 | aurel32 | return;
|
315 | 1fc3d392 | aurel32 | |
316 | 0add30cf | aurel32 | if (s->ctla & CTLA_FORCE_BLANK) {
|
317 | 0add30cf | aurel32 | /* blank screen */
|
318 | 0add30cf | aurel32 | fprintf(f, "P4\n%d %d\n",
|
319 | 0add30cf | aurel32 | s->width, s->height); |
320 | 0add30cf | aurel32 | for (y = 0; y < s->height; y++) |
321 | 0add30cf | aurel32 | for (x = 0; x < s->width; x++) |
322 | 0add30cf | aurel32 | fputc(0, f);
|
323 | 0add30cf | aurel32 | } else {
|
324 | 0add30cf | aurel32 | data_buffer = s->vram + s->top_of_screen; |
325 | 0add30cf | aurel32 | fprintf(f, "P6\n%d %d\n%d\n",
|
326 | 0add30cf | aurel32 | s->width, s->height, 255);
|
327 | 0add30cf | aurel32 | for (y = 0; y < s->height; y++) |
328 | 0add30cf | aurel32 | for (x = 0; x < s->width; x++, data_buffer++) { |
329 | 0add30cf | aurel32 | index = *data_buffer; |
330 | 0add30cf | aurel32 | fputc(s->color_palette[index][0], f);
|
331 | 0add30cf | aurel32 | fputc(s->color_palette[index][1], f);
|
332 | 0add30cf | aurel32 | fputc(s->color_palette[index][2], f);
|
333 | 1fc3d392 | aurel32 | } |
334 | 0add30cf | aurel32 | } |
335 | 0add30cf | aurel32 | |
336 | 1fc3d392 | aurel32 | fclose(f); |
337 | 1fc3d392 | aurel32 | } |
338 | 1fc3d392 | aurel32 | |
339 | 1fc3d392 | aurel32 | /* called for accesses to io ports */
|
340 | 0add30cf | aurel32 | static uint32_t g364fb_ctrl_readl(void *opaque, target_phys_addr_t addr) |
341 | 1fc3d392 | aurel32 | { |
342 | 0add30cf | aurel32 | G364State *s = opaque; |
343 | 1fc3d392 | aurel32 | uint32_t val; |
344 | 1fc3d392 | aurel32 | |
345 | 0add30cf | aurel32 | if (addr >= REG_CURS_PAT && addr < REG_CURS_PAT + 0x1000) { |
346 | 0add30cf | aurel32 | /* cursor pattern */
|
347 | 0add30cf | aurel32 | int idx = (addr - REG_CURS_PAT) >> 3; |
348 | 0add30cf | aurel32 | val = s->cursor[idx]; |
349 | 0add30cf | aurel32 | } else if (addr >= REG_CURS_PAL && addr < REG_CURS_PAL + 0x18) { |
350 | 0add30cf | aurel32 | /* cursor palette */
|
351 | 0add30cf | aurel32 | int idx = (addr - REG_CURS_PAL) >> 3; |
352 | 0add30cf | aurel32 | val = ((uint32_t)s->cursor_palette[idx][0] << 16); |
353 | 0add30cf | aurel32 | val |= ((uint32_t)s->cursor_palette[idx][1] << 8); |
354 | 0add30cf | aurel32 | val |= ((uint32_t)s->cursor_palette[idx][2] << 0); |
355 | 0add30cf | aurel32 | } else {
|
356 | 0add30cf | aurel32 | switch (addr) {
|
357 | 0add30cf | aurel32 | case REG_ID:
|
358 | 0add30cf | aurel32 | val = 0x10; /* Mips G364 */ |
359 | 0add30cf | aurel32 | break;
|
360 | 0add30cf | aurel32 | case REG_DISPLAY:
|
361 | 0add30cf | aurel32 | val = s->width / 4;
|
362 | 0add30cf | aurel32 | break;
|
363 | 0add30cf | aurel32 | case REG_VDISPLAY:
|
364 | 0add30cf | aurel32 | val = s->height * 2;
|
365 | 0add30cf | aurel32 | break;
|
366 | 0add30cf | aurel32 | case REG_CTLA:
|
367 | 0add30cf | aurel32 | val = s->ctla; |
368 | 0add30cf | aurel32 | break;
|
369 | 0add30cf | aurel32 | default:
|
370 | 0add30cf | aurel32 | { |
371 | 0add30cf | aurel32 | BADF("invalid read at [" TARGET_FMT_plx "]\n", addr); |
372 | 0add30cf | aurel32 | val = 0;
|
373 | 0add30cf | aurel32 | break;
|
374 | 0add30cf | aurel32 | } |
375 | 0add30cf | aurel32 | } |
376 | 1fc3d392 | aurel32 | } |
377 | 1fc3d392 | aurel32 | |
378 | 0add30cf | aurel32 | DPRINTF("read 0x%08x at [" TARGET_FMT_plx "]\n", val, addr); |
379 | 1fc3d392 | aurel32 | |
380 | 1fc3d392 | aurel32 | return val;
|
381 | 1fc3d392 | aurel32 | } |
382 | 1fc3d392 | aurel32 | |
383 | 1fc3d392 | aurel32 | static uint32_t g364fb_ctrl_readw(void *opaque, target_phys_addr_t addr) |
384 | 1fc3d392 | aurel32 | { |
385 | 0add30cf | aurel32 | uint32_t v = g364fb_ctrl_readl(opaque, addr & ~0x3);
|
386 | 0add30cf | aurel32 | if (addr & 0x2) |
387 | 0add30cf | aurel32 | return v >> 16; |
388 | 0add30cf | aurel32 | else
|
389 | 0add30cf | aurel32 | return v & 0xffff; |
390 | 1fc3d392 | aurel32 | } |
391 | 1fc3d392 | aurel32 | |
392 | 0add30cf | aurel32 | static uint32_t g364fb_ctrl_readb(void *opaque, target_phys_addr_t addr) |
393 | 1fc3d392 | aurel32 | { |
394 | 0add30cf | aurel32 | uint32_t v = g364fb_ctrl_readl(opaque, addr & ~0x3);
|
395 | 0add30cf | aurel32 | return (v >> (8 * (addr & 0x3))) & 0xff; |
396 | 1fc3d392 | aurel32 | } |
397 | 1fc3d392 | aurel32 | |
398 | 0add30cf | aurel32 | static void g364fb_update_depth(G364State *s) |
399 | 1fc3d392 | aurel32 | { |
400 | 0add30cf | aurel32 | const static int depths[8] = { 1, 2, 4, 8, 15, 16, 0 }; |
401 | 0add30cf | aurel32 | s->depth = depths[(s->ctla & 0x00700000) >> 20]; |
402 | 0add30cf | aurel32 | } |
403 | 1fc3d392 | aurel32 | |
404 | 0add30cf | aurel32 | static void g364_invalidate_cursor_position(G364State *s) |
405 | 0add30cf | aurel32 | { |
406 | 0add30cf | aurel32 | int ymin, ymax, start, end, i;
|
407 | 1fc3d392 | aurel32 | |
408 | 0add30cf | aurel32 | /* invalidate only near the cursor */
|
409 | 0add30cf | aurel32 | ymin = s->cursor_position & 0xfff;
|
410 | 0add30cf | aurel32 | ymax = MIN(s->height, ymin + 64);
|
411 | 0add30cf | aurel32 | start = ymin * ds_get_linesize(s->ds); |
412 | 0add30cf | aurel32 | end = (ymax + 1) * ds_get_linesize(s->ds);
|
413 | 1fc3d392 | aurel32 | |
414 | 0add30cf | aurel32 | for (i = start; i < end; i += TARGET_PAGE_SIZE) {
|
415 | 0add30cf | aurel32 | cpu_physical_memory_set_dirty(s->vram_offset + i); |
416 | 0add30cf | aurel32 | } |
417 | 0add30cf | aurel32 | } |
418 | 0add30cf | aurel32 | |
419 | 0add30cf | aurel32 | static void g364fb_ctrl_writel(void *opaque, target_phys_addr_t addr, uint32_t val) |
420 | 0add30cf | aurel32 | { |
421 | 0add30cf | aurel32 | G364State *s = opaque; |
422 | 0add30cf | aurel32 | |
423 | 0add30cf | aurel32 | DPRINTF("write 0x%08x at [" TARGET_FMT_plx "]\n", val, addr); |
424 | 0add30cf | aurel32 | |
425 | 0add30cf | aurel32 | if (addr >= REG_CLR_PAL && addr < REG_CLR_PAL + 0x800) { |
426 | 1fc3d392 | aurel32 | /* color palette */
|
427 | 0add30cf | aurel32 | int idx = (addr - REG_CLR_PAL) >> 3; |
428 | 0add30cf | aurel32 | s->color_palette[idx][0] = (val >> 16) & 0xff; |
429 | 0add30cf | aurel32 | s->color_palette[idx][1] = (val >> 8) & 0xff; |
430 | 0add30cf | aurel32 | s->color_palette[idx][2] = val & 0xff; |
431 | 0add30cf | aurel32 | g364fb_invalidate_display(s); |
432 | 0add30cf | aurel32 | } else if (addr >= REG_CURS_PAT && addr < REG_CURS_PAT + 0x1000) { |
433 | 0add30cf | aurel32 | /* cursor pattern */
|
434 | 0add30cf | aurel32 | int idx = (addr - REG_CURS_PAT) >> 3; |
435 | 0add30cf | aurel32 | s->cursor[idx] = val; |
436 | 0add30cf | aurel32 | g364fb_invalidate_display(s); |
437 | 0add30cf | aurel32 | } else if (addr >= REG_CURS_PAL && addr < REG_CURS_PAL + 0x18) { |
438 | 0add30cf | aurel32 | /* cursor palette */
|
439 | 0add30cf | aurel32 | int idx = (addr - REG_CURS_PAL) >> 3; |
440 | 0add30cf | aurel32 | s->cursor_palette[idx][0] = (val >> 16) & 0xff; |
441 | 0add30cf | aurel32 | s->cursor_palette[idx][1] = (val >> 8) & 0xff; |
442 | 0add30cf | aurel32 | s->cursor_palette[idx][2] = val & 0xff; |
443 | 0add30cf | aurel32 | g364fb_invalidate_display(s); |
444 | 1fc3d392 | aurel32 | } else {
|
445 | 1fc3d392 | aurel32 | switch (addr) {
|
446 | 0add30cf | aurel32 | case REG_ID: /* Card identifier; read-only */ |
447 | 0add30cf | aurel32 | case REG_BOOT: /* Boot timing */ |
448 | 0add30cf | aurel32 | case 0x80108: /* Line timing: half sync */ |
449 | 0add30cf | aurel32 | case 0x80110: /* Line timing: back porch */ |
450 | 0add30cf | aurel32 | case 0x80120: /* Line timing: short display */ |
451 | 0add30cf | aurel32 | case 0x80128: /* Frame timing: broad pulse */ |
452 | 0add30cf | aurel32 | case 0x80130: /* Frame timing: v sync */ |
453 | 0add30cf | aurel32 | case 0x80138: /* Frame timing: v preequalise */ |
454 | 0add30cf | aurel32 | case 0x80140: /* Frame timing: v postequalise */ |
455 | 0add30cf | aurel32 | case 0x80148: /* Frame timing: v blank */ |
456 | 0add30cf | aurel32 | case 0x80158: /* Line timing: line time */ |
457 | 0add30cf | aurel32 | case 0x80160: /* Frame store: line start */ |
458 | 0add30cf | aurel32 | case 0x80168: /* vram cycle: mem init */ |
459 | 0add30cf | aurel32 | case 0x80170: /* vram cycle: transfer delay */ |
460 | 0add30cf | aurel32 | case 0x80200: /* vram cycle: mask register */ |
461 | 0add30cf | aurel32 | /* ignore */
|
462 | 0add30cf | aurel32 | break;
|
463 | 0add30cf | aurel32 | case REG_TOP:
|
464 | 0add30cf | aurel32 | s->top_of_screen = val; |
465 | 0add30cf | aurel32 | g364fb_invalidate_display(s); |
466 | 0add30cf | aurel32 | break;
|
467 | 0add30cf | aurel32 | case REG_DISPLAY:
|
468 | 0add30cf | aurel32 | s->width = val * 4;
|
469 | 1fc3d392 | aurel32 | break;
|
470 | 0add30cf | aurel32 | case REG_VDISPLAY:
|
471 | 0add30cf | aurel32 | s->height = val / 2;
|
472 | 1fc3d392 | aurel32 | break;
|
473 | 0add30cf | aurel32 | case REG_CTLA:
|
474 | 0add30cf | aurel32 | s->ctla = val; |
475 | 0add30cf | aurel32 | g364fb_update_depth(s); |
476 | 0add30cf | aurel32 | g364fb_invalidate_display(s); |
477 | 1fc3d392 | aurel32 | break;
|
478 | 0add30cf | aurel32 | case REG_CURS_POS:
|
479 | 0add30cf | aurel32 | g364_invalidate_cursor_position(s); |
480 | 0add30cf | aurel32 | s->cursor_position = val; |
481 | 0add30cf | aurel32 | g364_invalidate_cursor_position(s); |
482 | 0add30cf | aurel32 | break;
|
483 | 0add30cf | aurel32 | case REG_RESET:
|
484 | 0add30cf | aurel32 | g364fb_reset(s); |
485 | 1fc3d392 | aurel32 | break;
|
486 | 1fc3d392 | aurel32 | default:
|
487 | 0add30cf | aurel32 | BADF("invalid write of 0x%08x at [" TARGET_FMT_plx "]\n", val, addr); |
488 | 1fc3d392 | aurel32 | break;
|
489 | 1fc3d392 | aurel32 | } |
490 | 1fc3d392 | aurel32 | } |
491 | 0add30cf | aurel32 | qemu_irq_lower(s->irq); |
492 | 1fc3d392 | aurel32 | } |
493 | 1fc3d392 | aurel32 | |
494 | 1fc3d392 | aurel32 | static void g364fb_ctrl_writew(void *opaque, target_phys_addr_t addr, uint32_t val) |
495 | 1fc3d392 | aurel32 | { |
496 | 0add30cf | aurel32 | uint32_t old_val = g364fb_ctrl_readl(opaque, addr & ~0x3);
|
497 | 0add30cf | aurel32 | |
498 | 0add30cf | aurel32 | if (addr & 0x2) |
499 | 0add30cf | aurel32 | val = (val << 16) | (old_val & 0x0000ffff); |
500 | 0add30cf | aurel32 | else
|
501 | 0add30cf | aurel32 | val = val | (old_val & 0xffff0000);
|
502 | 0add30cf | aurel32 | g364fb_ctrl_writel(opaque, addr & ~0x3, val);
|
503 | 1fc3d392 | aurel32 | } |
504 | 1fc3d392 | aurel32 | |
505 | 0add30cf | aurel32 | static void g364fb_ctrl_writeb(void *opaque, target_phys_addr_t addr, uint32_t val) |
506 | 1fc3d392 | aurel32 | { |
507 | 0add30cf | aurel32 | uint32_t old_val = g364fb_ctrl_readl(opaque, addr & ~0x3);
|
508 | 0add30cf | aurel32 | |
509 | 0add30cf | aurel32 | switch (addr & 3) { |
510 | 0add30cf | aurel32 | case 0: |
511 | 0add30cf | aurel32 | val = val | (old_val & 0xffffff00);
|
512 | 0add30cf | aurel32 | break;
|
513 | 0add30cf | aurel32 | case 1: |
514 | 0add30cf | aurel32 | val = (val << 8) | (old_val & 0xffff00ff); |
515 | 0add30cf | aurel32 | break;
|
516 | 0add30cf | aurel32 | case 2: |
517 | 0add30cf | aurel32 | val = (val << 16) | (old_val & 0xff00ffff); |
518 | 0add30cf | aurel32 | break;
|
519 | 0add30cf | aurel32 | case 3: |
520 | 0add30cf | aurel32 | val = (val << 24) | (old_val & 0x00ffffff); |
521 | 0add30cf | aurel32 | break;
|
522 | 0add30cf | aurel32 | } |
523 | 0add30cf | aurel32 | g364fb_ctrl_writel(opaque, addr & ~0x3, val);
|
524 | 1fc3d392 | aurel32 | } |
525 | 1fc3d392 | aurel32 | |
526 | 1fc3d392 | aurel32 | static CPUReadMemoryFunc *g364fb_ctrl_read[3] = { |
527 | 1fc3d392 | aurel32 | g364fb_ctrl_readb, |
528 | 1fc3d392 | aurel32 | g364fb_ctrl_readw, |
529 | 1fc3d392 | aurel32 | g364fb_ctrl_readl, |
530 | 1fc3d392 | aurel32 | }; |
531 | 1fc3d392 | aurel32 | |
532 | 1fc3d392 | aurel32 | static CPUWriteMemoryFunc *g364fb_ctrl_write[3] = { |
533 | 1fc3d392 | aurel32 | g364fb_ctrl_writeb, |
534 | 1fc3d392 | aurel32 | g364fb_ctrl_writew, |
535 | 1fc3d392 | aurel32 | g364fb_ctrl_writel, |
536 | 1fc3d392 | aurel32 | }; |
537 | 1fc3d392 | aurel32 | |
538 | 0add30cf | aurel32 | static int g364fb_load(QEMUFile *f, void *opaque, int version_id) |
539 | 1fc3d392 | aurel32 | { |
540 | 1fc3d392 | aurel32 | G364State *s = opaque; |
541 | 0add30cf | aurel32 | unsigned int i, vram_size; |
542 | 0add30cf | aurel32 | |
543 | 0add30cf | aurel32 | if (version_id != 1) |
544 | 0add30cf | aurel32 | return -EINVAL;
|
545 | 0add30cf | aurel32 | |
546 | 0add30cf | aurel32 | vram_size = qemu_get_be32(f); |
547 | 0add30cf | aurel32 | if (vram_size < s->vram_size)
|
548 | 0add30cf | aurel32 | return -EINVAL;
|
549 | 0add30cf | aurel32 | qemu_get_buffer(f, s->vram, s->vram_size); |
550 | 0add30cf | aurel32 | for (i = 0; i < 256; i++) |
551 | 0add30cf | aurel32 | qemu_get_buffer(f, s->color_palette[i], 3);
|
552 | 0add30cf | aurel32 | for (i = 0; i < 3; i++) |
553 | 0add30cf | aurel32 | qemu_get_buffer(f, s->cursor_palette[i], 3);
|
554 | 0add30cf | aurel32 | qemu_get_buffer(f, (uint8_t *)s->cursor, sizeof(s->cursor));
|
555 | 0add30cf | aurel32 | s->cursor_position = qemu_get_be32(f); |
556 | 0add30cf | aurel32 | s->ctla = qemu_get_be32(f); |
557 | 0add30cf | aurel32 | s->top_of_screen = qemu_get_be32(f); |
558 | 0add30cf | aurel32 | s->width = qemu_get_be32(f); |
559 | 0add30cf | aurel32 | s->height = qemu_get_be32(f); |
560 | 0add30cf | aurel32 | |
561 | 0add30cf | aurel32 | /* force refresh */
|
562 | 0add30cf | aurel32 | g364fb_update_depth(s); |
563 | 0add30cf | aurel32 | g364fb_invalidate_display(s); |
564 | 1fc3d392 | aurel32 | |
565 | 0add30cf | aurel32 | return 0; |
566 | 1fc3d392 | aurel32 | } |
567 | 1fc3d392 | aurel32 | |
568 | 0add30cf | aurel32 | static void g364fb_save(QEMUFile *f, void *opaque) |
569 | 1fc3d392 | aurel32 | { |
570 | 1fc3d392 | aurel32 | G364State *s = opaque; |
571 | 0add30cf | aurel32 | int i;
|
572 | 0add30cf | aurel32 | |
573 | 0add30cf | aurel32 | qemu_put_be32(f, s->vram_size); |
574 | 0add30cf | aurel32 | qemu_put_buffer(f, s->vram, s->vram_size); |
575 | 0add30cf | aurel32 | for (i = 0; i < 256; i++) |
576 | 0add30cf | aurel32 | qemu_put_buffer(f, s->color_palette[i], 3);
|
577 | 0add30cf | aurel32 | for (i = 0; i < 3; i++) |
578 | 0add30cf | aurel32 | qemu_put_buffer(f, s->cursor_palette[i], 3);
|
579 | 0add30cf | aurel32 | qemu_put_buffer(f, (uint8_t *)s->cursor, sizeof(s->cursor));
|
580 | 0add30cf | aurel32 | qemu_put_be32(f, s->cursor_position); |
581 | 0add30cf | aurel32 | qemu_put_be32(f, s->ctla); |
582 | 0add30cf | aurel32 | qemu_put_be32(f, s->top_of_screen); |
583 | 0add30cf | aurel32 | qemu_put_be32(f, s->width); |
584 | 0add30cf | aurel32 | qemu_put_be32(f, s->height); |
585 | 1fc3d392 | aurel32 | } |
586 | 1fc3d392 | aurel32 | |
587 | fbe1b595 | Paul Brook | int g364fb_mm_init(target_phys_addr_t vram_base,
|
588 | 0add30cf | aurel32 | target_phys_addr_t ctrl_base, int it_shift,
|
589 | 0add30cf | aurel32 | qemu_irq irq) |
590 | 1fc3d392 | aurel32 | { |
591 | 1fc3d392 | aurel32 | G364State *s; |
592 | 0add30cf | aurel32 | int io_ctrl;
|
593 | 1fc3d392 | aurel32 | |
594 | 1fc3d392 | aurel32 | s = qemu_mallocz(sizeof(G364State));
|
595 | 1fc3d392 | aurel32 | |
596 | fbe1b595 | Paul Brook | s->vram_size = 8 * 1024 * 1024; |
597 | fbe1b595 | Paul Brook | s->vram_offset = qemu_ram_alloc(s->vram_size); |
598 | b584726d | pbrook | s->vram = qemu_get_ram_ptr(s->vram_offset); |
599 | 0add30cf | aurel32 | s->irq = irq; |
600 | 1fc3d392 | aurel32 | |
601 | a08d4367 | Jan Kiszka | qemu_register_reset(g364fb_reset, s); |
602 | 0add30cf | aurel32 | register_savevm("g364fb", 0, 1, g364fb_save, g364fb_load, s); |
603 | 1fc3d392 | aurel32 | g364fb_reset(s); |
604 | 1fc3d392 | aurel32 | |
605 | 3023f332 | aliguori | s->ds = graphic_console_init(g364fb_update_display, |
606 | 3023f332 | aliguori | g364fb_invalidate_display, |
607 | 3023f332 | aliguori | g364fb_screen_dump, NULL, s);
|
608 | 1fc3d392 | aurel32 | |
609 | 0add30cf | aurel32 | cpu_register_physical_memory(vram_base, s->vram_size, s->vram_offset); |
610 | 1fc3d392 | aurel32 | |
611 | 1eed09cb | Avi Kivity | io_ctrl = cpu_register_io_memory(g364fb_ctrl_read, g364fb_ctrl_write, s); |
612 | 0add30cf | aurel32 | cpu_register_physical_memory(ctrl_base, 0x200000, io_ctrl);
|
613 | 1fc3d392 | aurel32 | |
614 | 1fc3d392 | aurel32 | return 0; |
615 | 1fc3d392 | aurel32 | } |