2 * QEMU Cirrus CLGD 54xx VGA Emulator.
4 * Copyright (c) 2004 Fabrice Bellard
5 * Copyright (c) 2004 Makoto Suzuki (suzu)
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:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
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
26 * Reference: Finn Thogersons' VGADOC4b
27 * available at http://home.worldonline.dk/~finth/
34 * - destination write mask support not complete (bits 5..7)
35 * - optimize linear mappings
36 * - optimize bitblt functions
39 //#define DEBUG_CIRRUS
40 //#define DEBUG_BITBLT
42 /***************************************
46 ***************************************/
48 #define qemu_MIN(a,b) ((a) < (b) ? (a) : (b))
51 #define CIRRUS_ID_CLGD5422 (0x23<<2)
52 #define CIRRUS_ID_CLGD5426 (0x24<<2)
53 #define CIRRUS_ID_CLGD5424 (0x25<<2)
54 #define CIRRUS_ID_CLGD5428 (0x26<<2)
55 #define CIRRUS_ID_CLGD5430 (0x28<<2)
56 #define CIRRUS_ID_CLGD5434 (0x2A<<2)
57 #define CIRRUS_ID_CLGD5436 (0x2B<<2)
58 #define CIRRUS_ID_CLGD5446 (0x2E<<2)
61 #define CIRRUS_SR7_BPP_VGA 0x00
62 #define CIRRUS_SR7_BPP_SVGA 0x01
63 #define CIRRUS_SR7_BPP_MASK 0x0e
64 #define CIRRUS_SR7_BPP_8 0x00
65 #define CIRRUS_SR7_BPP_16_DOUBLEVCLK 0x02
66 #define CIRRUS_SR7_BPP_24 0x04
67 #define CIRRUS_SR7_BPP_16 0x06
68 #define CIRRUS_SR7_BPP_32 0x08
69 #define CIRRUS_SR7_ISAADDR_MASK 0xe0
72 #define CIRRUS_MEMSIZE_512k 0x08
73 #define CIRRUS_MEMSIZE_1M 0x10
74 #define CIRRUS_MEMSIZE_2M 0x18
75 #define CIRRUS_MEMFLAGS_BANKSWITCH 0x80 // bank switching is enabled.
78 #define CIRRUS_CURSOR_SHOW 0x01
79 #define CIRRUS_CURSOR_HIDDENPEL 0x02
80 #define CIRRUS_CURSOR_LARGE 0x04 // 64x64 if set, 32x32 if clear
83 #define CIRRUS_BUSTYPE_VLBFAST 0x10
84 #define CIRRUS_BUSTYPE_PCI 0x20
85 #define CIRRUS_BUSTYPE_VLBSLOW 0x30
86 #define CIRRUS_BUSTYPE_ISA 0x38
87 #define CIRRUS_MMIO_ENABLE 0x04
88 #define CIRRUS_MMIO_USE_PCIADDR 0x40 // 0xb8000 if cleared.
89 #define CIRRUS_MEMSIZEEXT_DOUBLE 0x80
92 #define CIRRUS_BANKING_DUAL 0x01
93 #define CIRRUS_BANKING_GRANULARITY_16K 0x20 // set:16k, clear:4k
96 #define CIRRUS_BLTMODE_BACKWARDS 0x01
97 #define CIRRUS_BLTMODE_MEMSYSDEST 0x02
98 #define CIRRUS_BLTMODE_MEMSYSSRC 0x04
99 #define CIRRUS_BLTMODE_TRANSPARENTCOMP 0x08
100 #define CIRRUS_BLTMODE_PATTERNCOPY 0x40
101 #define CIRRUS_BLTMODE_COLOREXPAND 0x80
102 #define CIRRUS_BLTMODE_PIXELWIDTHMASK 0x30
103 #define CIRRUS_BLTMODE_PIXELWIDTH8 0x00
104 #define CIRRUS_BLTMODE_PIXELWIDTH16 0x10
105 #define CIRRUS_BLTMODE_PIXELWIDTH24 0x20
106 #define CIRRUS_BLTMODE_PIXELWIDTH32 0x30
109 #define CIRRUS_BLT_BUSY 0x01
110 #define CIRRUS_BLT_START 0x02
111 #define CIRRUS_BLT_RESET 0x04
112 #define CIRRUS_BLT_FIFOUSED 0x10
113 #define CIRRUS_BLT_AUTOSTART 0x80
116 #define CIRRUS_ROP_0 0x00
117 #define CIRRUS_ROP_SRC_AND_DST 0x05
118 #define CIRRUS_ROP_NOP 0x06
119 #define CIRRUS_ROP_SRC_AND_NOTDST 0x09
120 #define CIRRUS_ROP_NOTDST 0x0b
121 #define CIRRUS_ROP_SRC 0x0d
122 #define CIRRUS_ROP_1 0x0e
123 #define CIRRUS_ROP_NOTSRC_AND_DST 0x50
124 #define CIRRUS_ROP_SRC_XOR_DST 0x59
125 #define CIRRUS_ROP_SRC_OR_DST 0x6d
126 #define CIRRUS_ROP_NOTSRC_OR_NOTDST 0x90
127 #define CIRRUS_ROP_SRC_NOTXOR_DST 0x95
128 #define CIRRUS_ROP_SRC_OR_NOTDST 0xad
129 #define CIRRUS_ROP_NOTSRC 0xd0
130 #define CIRRUS_ROP_NOTSRC_OR_DST 0xd6
131 #define CIRRUS_ROP_NOTSRC_AND_NOTDST 0xda
133 #define CIRRUS_ROP_NOP_INDEX 2
134 #define CIRRUS_ROP_SRC_INDEX 5
137 #define CIRRUS_BLTMODEEXT_SOLIDFILL 0x04
138 #define CIRRUS_BLTMODEEXT_COLOREXPINV 0x02
139 #define CIRRUS_BLTMODEEXT_DWORDGRANULARITY 0x01
142 #define CIRRUS_MMIO_BLTBGCOLOR 0x00 // dword
143 #define CIRRUS_MMIO_BLTFGCOLOR 0x04 // dword
144 #define CIRRUS_MMIO_BLTWIDTH 0x08 // word
145 #define CIRRUS_MMIO_BLTHEIGHT 0x0a // word
146 #define CIRRUS_MMIO_BLTDESTPITCH 0x0c // word
147 #define CIRRUS_MMIO_BLTSRCPITCH 0x0e // word
148 #define CIRRUS_MMIO_BLTDESTADDR 0x10 // dword
149 #define CIRRUS_MMIO_BLTSRCADDR 0x14 // dword
150 #define CIRRUS_MMIO_BLTWRITEMASK 0x17 // byte
151 #define CIRRUS_MMIO_BLTMODE 0x18 // byte
152 #define CIRRUS_MMIO_BLTROP 0x1a // byte
153 #define CIRRUS_MMIO_BLTMODEEXT 0x1b // byte
154 #define CIRRUS_MMIO_BLTTRANSPARENTCOLOR 0x1c // word?
155 #define CIRRUS_MMIO_BLTTRANSPARENTCOLORMASK 0x20 // word?
156 #define CIRRUS_MMIO_LINEARDRAW_START_X 0x24 // word
157 #define CIRRUS_MMIO_LINEARDRAW_START_Y 0x26 // word
158 #define CIRRUS_MMIO_LINEARDRAW_END_X 0x28 // word
159 #define CIRRUS_MMIO_LINEARDRAW_END_Y 0x2a // word
160 #define CIRRUS_MMIO_LINEARDRAW_LINESTYLE_INC 0x2c // byte
161 #define CIRRUS_MMIO_LINEARDRAW_LINESTYLE_ROLLOVER 0x2d // byte
162 #define CIRRUS_MMIO_LINEARDRAW_LINESTYLE_MASK 0x2e // byte
163 #define CIRRUS_MMIO_LINEARDRAW_LINESTYLE_ACCUM 0x2f // byte
164 #define CIRRUS_MMIO_BRESENHAM_K1 0x30 // word
165 #define CIRRUS_MMIO_BRESENHAM_K3 0x32 // word
166 #define CIRRUS_MMIO_BRESENHAM_ERROR 0x34 // word
167 #define CIRRUS_MMIO_BRESENHAM_DELTA_MAJOR 0x36 // word
168 #define CIRRUS_MMIO_BRESENHAM_DIRECTION 0x38 // byte
169 #define CIRRUS_MMIO_LINEDRAW_MODE 0x39 // byte
170 #define CIRRUS_MMIO_BLTSTATUS 0x40 // byte
172 // PCI 0x00: vendor, 0x02: device
173 #define PCI_VENDOR_CIRRUS 0x1013
174 #define PCI_DEVICE_CLGD5462 0x00d0
175 #define PCI_DEVICE_CLGD5465 0x00d6
177 // PCI 0x04: command(word), 0x06(word): status
178 #define PCI_COMMAND_IOACCESS 0x0001
179 #define PCI_COMMAND_MEMACCESS 0x0002
180 #define PCI_COMMAND_BUSMASTER 0x0004
181 #define PCI_COMMAND_SPECIALCYCLE 0x0008
182 #define PCI_COMMAND_MEMWRITEINVALID 0x0010
183 #define PCI_COMMAND_PALETTESNOOPING 0x0020
184 #define PCI_COMMAND_PARITYDETECTION 0x0040
185 #define PCI_COMMAND_ADDRESSDATASTEPPING 0x0080
186 #define PCI_COMMAND_SERR 0x0100
187 #define PCI_COMMAND_BACKTOBACKTRANS 0x0200
188 // PCI 0x08, 0xff000000 (0x09-0x0b:class,0x08:rev)
189 #define PCI_CLASS_BASE_DISPLAY 0x03
190 // PCI 0x08, 0x00ff0000
191 #define PCI_CLASS_SUB_VGA 0x00
192 // PCI 0x0c, 0x00ff0000 (0x0c:cacheline,0x0d:latency,0x0e:headertype,0x0f:Built-in self test)
193 #define PCI_CLASS_HEADERTYPE_00h 0x00
194 // 0x10-0x3f (headertype 00h)
195 // PCI 0x10,0x14,0x18,0x1c,0x20,0x24: base address mapping registers
196 // 0x10: MEMBASE, 0x14: IOBASE(hard-coded in XFree86 3.x)
197 #define PCI_MAP_MEM 0x0
198 #define PCI_MAP_IO 0x1
199 #define PCI_MAP_MEM_ADDR_MASK (~0xf)
200 #define PCI_MAP_IO_ADDR_MASK (~0x3)
201 #define PCI_MAP_MEMFLAGS_32BIT 0x0
202 #define PCI_MAP_MEMFLAGS_32BIT_1M 0x1
203 #define PCI_MAP_MEMFLAGS_64BIT 0x4
204 #define PCI_MAP_MEMFLAGS_CACHEABLE 0x8
205 // PCI 0x28: cardbus CIS pointer
206 // PCI 0x2c: subsystem vendor id, 0x2e: subsystem id
207 // PCI 0x30: expansion ROM base address
208 #define PCI_ROMBIOS_ENABLED 0x1
209 // PCI 0x34: 0xffffff00=reserved, 0x000000ff=capabilities pointer
210 // PCI 0x38: reserved
211 // PCI 0x3c: 0x3c=int-line, 0x3d=int-pin, 0x3e=min-gnt, 0x3f=maax-lat
213 #define CIRRUS_PNPMMIO_SIZE 0x1000
216 /* I/O and memory hook */
217 #define CIRRUS_HOOK_NOT_HANDLED 0
218 #define CIRRUS_HOOK_HANDLED 1
220 struct CirrusVGAState
;
221 typedef void (*cirrus_bitblt_rop_t
) (struct CirrusVGAState
*s
,
222 uint8_t * dst
, const uint8_t * src
,
223 int dstpitch
, int srcpitch
,
224 int bltwidth
, int bltheight
);
225 typedef void (*cirrus_fill_t
)(struct CirrusVGAState
*s
,
226 uint8_t *dst
, int dst_pitch
, int width
, int height
);
228 typedef struct CirrusVGAState
{
231 int cirrus_linear_io_addr
;
232 int cirrus_linear_bitblt_io_addr
;
233 int cirrus_mmio_io_addr
;
234 uint32_t cirrus_addr_mask
;
235 uint32_t linear_mmio_mask
;
236 uint8_t cirrus_shadow_gr0
;
237 uint8_t cirrus_shadow_gr1
;
238 uint8_t cirrus_hidden_dac_lockindex
;
239 uint8_t cirrus_hidden_dac_data
;
240 uint32_t cirrus_bank_base
[2];
241 uint32_t cirrus_bank_limit
[2];
242 uint8_t cirrus_hidden_palette
[48];
243 uint32_t hw_cursor_x
;
244 uint32_t hw_cursor_y
;
245 int cirrus_blt_pixelwidth
;
246 int cirrus_blt_width
;
247 int cirrus_blt_height
;
248 int cirrus_blt_dstpitch
;
249 int cirrus_blt_srcpitch
;
250 uint32_t cirrus_blt_fgcol
;
251 uint32_t cirrus_blt_bgcol
;
252 uint32_t cirrus_blt_dstaddr
;
253 uint32_t cirrus_blt_srcaddr
;
254 uint8_t cirrus_blt_mode
;
255 uint8_t cirrus_blt_modeext
;
256 cirrus_bitblt_rop_t cirrus_rop
;
257 #define CIRRUS_BLTBUFSIZE (2048 * 4) /* one line width */
258 uint8_t cirrus_bltbuf
[CIRRUS_BLTBUFSIZE
];
259 uint8_t *cirrus_srcptr
;
260 uint8_t *cirrus_srcptr_end
;
261 uint32_t cirrus_srccounter
;
262 /* hwcursor display state */
263 int last_hw_cursor_size
;
264 int last_hw_cursor_x
;
265 int last_hw_cursor_y
;
266 int last_hw_cursor_y_start
;
267 int last_hw_cursor_y_end
;
268 int real_vram_size
; /* XXX: suppress that */
269 CPUWriteMemoryFunc
**cirrus_linear_write
;
272 typedef struct PCICirrusVGAState
{
274 CirrusVGAState cirrus_vga
;
277 static uint8_t rop_to_index
[256];
279 /***************************************
283 ***************************************/
286 static void cirrus_bitblt_reset(CirrusVGAState
*s
);
287 static void cirrus_update_memory_access(CirrusVGAState
*s
);
289 /***************************************
293 ***************************************/
295 static void cirrus_bitblt_rop_nop(CirrusVGAState
*s
,
296 uint8_t *dst
,const uint8_t *src
,
297 int dstpitch
,int srcpitch
,
298 int bltwidth
,int bltheight
)
302 static void cirrus_bitblt_fill_nop(CirrusVGAState
*s
,
304 int dstpitch
, int bltwidth
,int bltheight
)
309 #define ROP_OP(d, s) d = 0
310 #include "cirrus_vga_rop.h"
312 #define ROP_NAME src_and_dst
313 #define ROP_OP(d, s) d = (s) & (d)
314 #include "cirrus_vga_rop.h"
316 #define ROP_NAME src_and_notdst
317 #define ROP_OP(d, s) d = (s) & (~(d))
318 #include "cirrus_vga_rop.h"
320 #define ROP_NAME notdst
321 #define ROP_OP(d, s) d = ~(d)
322 #include "cirrus_vga_rop.h"
325 #define ROP_OP(d, s) d = s
326 #include "cirrus_vga_rop.h"
329 #define ROP_OP(d, s) d = ~0
330 #include "cirrus_vga_rop.h"
332 #define ROP_NAME notsrc_and_dst
333 #define ROP_OP(d, s) d = (~(s)) & (d)
334 #include "cirrus_vga_rop.h"
336 #define ROP_NAME src_xor_dst
337 #define ROP_OP(d, s) d = (s) ^ (d)
338 #include "cirrus_vga_rop.h"
340 #define ROP_NAME src_or_dst
341 #define ROP_OP(d, s) d = (s) | (d)
342 #include "cirrus_vga_rop.h"
344 #define ROP_NAME notsrc_or_notdst
345 #define ROP_OP(d, s) d = (~(s)) | (~(d))
346 #include "cirrus_vga_rop.h"
348 #define ROP_NAME src_notxor_dst
349 #define ROP_OP(d, s) d = ~((s) ^ (d))
350 #include "cirrus_vga_rop.h"
352 #define ROP_NAME src_or_notdst
353 #define ROP_OP(d, s) d = (s) | (~(d))
354 #include "cirrus_vga_rop.h"
356 #define ROP_NAME notsrc
357 #define ROP_OP(d, s) d = (~(s))
358 #include "cirrus_vga_rop.h"
360 #define ROP_NAME notsrc_or_dst
361 #define ROP_OP(d, s) d = (~(s)) | (d)
362 #include "cirrus_vga_rop.h"
364 #define ROP_NAME notsrc_and_notdst
365 #define ROP_OP(d, s) d = (~(s)) & (~(d))
366 #include "cirrus_vga_rop.h"
368 static const cirrus_bitblt_rop_t cirrus_fwd_rop
[16] = {
369 cirrus_bitblt_rop_fwd_0
,
370 cirrus_bitblt_rop_fwd_src_and_dst
,
371 cirrus_bitblt_rop_nop
,
372 cirrus_bitblt_rop_fwd_src_and_notdst
,
373 cirrus_bitblt_rop_fwd_notdst
,
374 cirrus_bitblt_rop_fwd_src
,
375 cirrus_bitblt_rop_fwd_1
,
376 cirrus_bitblt_rop_fwd_notsrc_and_dst
,
377 cirrus_bitblt_rop_fwd_src_xor_dst
,
378 cirrus_bitblt_rop_fwd_src_or_dst
,
379 cirrus_bitblt_rop_fwd_notsrc_or_notdst
,
380 cirrus_bitblt_rop_fwd_src_notxor_dst
,
381 cirrus_bitblt_rop_fwd_src_or_notdst
,
382 cirrus_bitblt_rop_fwd_notsrc
,
383 cirrus_bitblt_rop_fwd_notsrc_or_dst
,
384 cirrus_bitblt_rop_fwd_notsrc_and_notdst
,
387 static const cirrus_bitblt_rop_t cirrus_bkwd_rop
[16] = {
388 cirrus_bitblt_rop_bkwd_0
,
389 cirrus_bitblt_rop_bkwd_src_and_dst
,
390 cirrus_bitblt_rop_nop
,
391 cirrus_bitblt_rop_bkwd_src_and_notdst
,
392 cirrus_bitblt_rop_bkwd_notdst
,
393 cirrus_bitblt_rop_bkwd_src
,
394 cirrus_bitblt_rop_bkwd_1
,
395 cirrus_bitblt_rop_bkwd_notsrc_and_dst
,
396 cirrus_bitblt_rop_bkwd_src_xor_dst
,
397 cirrus_bitblt_rop_bkwd_src_or_dst
,
398 cirrus_bitblt_rop_bkwd_notsrc_or_notdst
,
399 cirrus_bitblt_rop_bkwd_src_notxor_dst
,
400 cirrus_bitblt_rop_bkwd_src_or_notdst
,
401 cirrus_bitblt_rop_bkwd_notsrc
,
402 cirrus_bitblt_rop_bkwd_notsrc_or_dst
,
403 cirrus_bitblt_rop_bkwd_notsrc_and_notdst
,
406 #define ROP2(name) {\
413 #define ROP_NOP2(func) {\
420 static const cirrus_bitblt_rop_t cirrus_patternfill
[16][4] = {
421 ROP2(cirrus_patternfill_0
),
422 ROP2(cirrus_patternfill_src_and_dst
),
423 ROP_NOP2(cirrus_bitblt_rop_nop
),
424 ROP2(cirrus_patternfill_src_and_notdst
),
425 ROP2(cirrus_patternfill_notdst
),
426 ROP2(cirrus_patternfill_src
),
427 ROP2(cirrus_patternfill_1
),
428 ROP2(cirrus_patternfill_notsrc_and_dst
),
429 ROP2(cirrus_patternfill_src_xor_dst
),
430 ROP2(cirrus_patternfill_src_or_dst
),
431 ROP2(cirrus_patternfill_notsrc_or_notdst
),
432 ROP2(cirrus_patternfill_src_notxor_dst
),
433 ROP2(cirrus_patternfill_src_or_notdst
),
434 ROP2(cirrus_patternfill_notsrc
),
435 ROP2(cirrus_patternfill_notsrc_or_dst
),
436 ROP2(cirrus_patternfill_notsrc_and_notdst
),
439 static const cirrus_bitblt_rop_t cirrus_colorexpand_transp
[16][4] = {
440 ROP2(cirrus_colorexpand_transp_0
),
441 ROP2(cirrus_colorexpand_transp_src_and_dst
),
442 ROP_NOP2(cirrus_bitblt_rop_nop
),
443 ROP2(cirrus_colorexpand_transp_src_and_notdst
),
444 ROP2(cirrus_colorexpand_transp_notdst
),
445 ROP2(cirrus_colorexpand_transp_src
),
446 ROP2(cirrus_colorexpand_transp_1
),
447 ROP2(cirrus_colorexpand_transp_notsrc_and_dst
),
448 ROP2(cirrus_colorexpand_transp_src_xor_dst
),
449 ROP2(cirrus_colorexpand_transp_src_or_dst
),
450 ROP2(cirrus_colorexpand_transp_notsrc_or_notdst
),
451 ROP2(cirrus_colorexpand_transp_src_notxor_dst
),
452 ROP2(cirrus_colorexpand_transp_src_or_notdst
),
453 ROP2(cirrus_colorexpand_transp_notsrc
),
454 ROP2(cirrus_colorexpand_transp_notsrc_or_dst
),
455 ROP2(cirrus_colorexpand_transp_notsrc_and_notdst
),
458 static const cirrus_bitblt_rop_t cirrus_colorexpand
[16][4] = {
459 ROP2(cirrus_colorexpand_0
),
460 ROP2(cirrus_colorexpand_src_and_dst
),
461 ROP_NOP2(cirrus_bitblt_rop_nop
),
462 ROP2(cirrus_colorexpand_src_and_notdst
),
463 ROP2(cirrus_colorexpand_notdst
),
464 ROP2(cirrus_colorexpand_src
),
465 ROP2(cirrus_colorexpand_1
),
466 ROP2(cirrus_colorexpand_notsrc_and_dst
),
467 ROP2(cirrus_colorexpand_src_xor_dst
),
468 ROP2(cirrus_colorexpand_src_or_dst
),
469 ROP2(cirrus_colorexpand_notsrc_or_notdst
),
470 ROP2(cirrus_colorexpand_src_notxor_dst
),
471 ROP2(cirrus_colorexpand_src_or_notdst
),
472 ROP2(cirrus_colorexpand_notsrc
),
473 ROP2(cirrus_colorexpand_notsrc_or_dst
),
474 ROP2(cirrus_colorexpand_notsrc_and_notdst
),
477 static const cirrus_bitblt_rop_t cirrus_colorexpand_pattern_transp
[16][4] = {
478 ROP2(cirrus_colorexpand_pattern_transp_0
),
479 ROP2(cirrus_colorexpand_pattern_transp_src_and_dst
),
480 ROP_NOP2(cirrus_bitblt_rop_nop
),
481 ROP2(cirrus_colorexpand_pattern_transp_src_and_notdst
),
482 ROP2(cirrus_colorexpand_pattern_transp_notdst
),
483 ROP2(cirrus_colorexpand_pattern_transp_src
),
484 ROP2(cirrus_colorexpand_pattern_transp_1
),
485 ROP2(cirrus_colorexpand_pattern_transp_notsrc_and_dst
),
486 ROP2(cirrus_colorexpand_pattern_transp_src_xor_dst
),
487 ROP2(cirrus_colorexpand_pattern_transp_src_or_dst
),
488 ROP2(cirrus_colorexpand_pattern_transp_notsrc_or_notdst
),
489 ROP2(cirrus_colorexpand_pattern_transp_src_notxor_dst
),
490 ROP2(cirrus_colorexpand_pattern_transp_src_or_notdst
),
491 ROP2(cirrus_colorexpand_pattern_transp_notsrc
),
492 ROP2(cirrus_colorexpand_pattern_transp_notsrc_or_dst
),
493 ROP2(cirrus_colorexpand_pattern_transp_notsrc_and_notdst
),
496 static const cirrus_bitblt_rop_t cirrus_colorexpand_pattern
[16][4] = {
497 ROP2(cirrus_colorexpand_pattern_0
),
498 ROP2(cirrus_colorexpand_pattern_src_and_dst
),
499 ROP_NOP2(cirrus_bitblt_rop_nop
),
500 ROP2(cirrus_colorexpand_pattern_src_and_notdst
),
501 ROP2(cirrus_colorexpand_pattern_notdst
),
502 ROP2(cirrus_colorexpand_pattern_src
),
503 ROP2(cirrus_colorexpand_pattern_1
),
504 ROP2(cirrus_colorexpand_pattern_notsrc_and_dst
),
505 ROP2(cirrus_colorexpand_pattern_src_xor_dst
),
506 ROP2(cirrus_colorexpand_pattern_src_or_dst
),
507 ROP2(cirrus_colorexpand_pattern_notsrc_or_notdst
),
508 ROP2(cirrus_colorexpand_pattern_src_notxor_dst
),
509 ROP2(cirrus_colorexpand_pattern_src_or_notdst
),
510 ROP2(cirrus_colorexpand_pattern_notsrc
),
511 ROP2(cirrus_colorexpand_pattern_notsrc_or_dst
),
512 ROP2(cirrus_colorexpand_pattern_notsrc_and_notdst
),
515 static const cirrus_fill_t cirrus_fill
[16][4] = {
517 ROP2(cirrus_fill_src_and_dst
),
518 ROP_NOP2(cirrus_bitblt_fill_nop
),
519 ROP2(cirrus_fill_src_and_notdst
),
520 ROP2(cirrus_fill_notdst
),
521 ROP2(cirrus_fill_src
),
523 ROP2(cirrus_fill_notsrc_and_dst
),
524 ROP2(cirrus_fill_src_xor_dst
),
525 ROP2(cirrus_fill_src_or_dst
),
526 ROP2(cirrus_fill_notsrc_or_notdst
),
527 ROP2(cirrus_fill_src_notxor_dst
),
528 ROP2(cirrus_fill_src_or_notdst
),
529 ROP2(cirrus_fill_notsrc
),
530 ROP2(cirrus_fill_notsrc_or_dst
),
531 ROP2(cirrus_fill_notsrc_and_notdst
),
534 static inline void cirrus_bitblt_fgcol(CirrusVGAState
*s
)
537 switch (s
->cirrus_blt_pixelwidth
) {
539 s
->cirrus_blt_fgcol
= s
->cirrus_shadow_gr1
;
542 color
= s
->cirrus_shadow_gr1
| (s
->gr
[0x11] << 8);
543 s
->cirrus_blt_fgcol
= le16_to_cpu(color
);
546 s
->cirrus_blt_fgcol
= s
->cirrus_shadow_gr1
|
547 (s
->gr
[0x11] << 8) | (s
->gr
[0x13] << 16);
551 color
= s
->cirrus_shadow_gr1
| (s
->gr
[0x11] << 8) |
552 (s
->gr
[0x13] << 16) | (s
->gr
[0x15] << 24);
553 s
->cirrus_blt_fgcol
= le32_to_cpu(color
);
558 static inline void cirrus_bitblt_bgcol(CirrusVGAState
*s
)
561 switch (s
->cirrus_blt_pixelwidth
) {
563 s
->cirrus_blt_bgcol
= s
->cirrus_shadow_gr0
;
566 color
= s
->cirrus_shadow_gr0
| (s
->gr
[0x10] << 8);
567 s
->cirrus_blt_bgcol
= le16_to_cpu(color
);
570 s
->cirrus_blt_bgcol
= s
->cirrus_shadow_gr0
|
571 (s
->gr
[0x10] << 8) | (s
->gr
[0x12] << 16);
575 color
= s
->cirrus_shadow_gr0
| (s
->gr
[0x10] << 8) |
576 (s
->gr
[0x12] << 16) | (s
->gr
[0x14] << 24);
577 s
->cirrus_blt_bgcol
= le32_to_cpu(color
);
582 static void cirrus_invalidate_region(CirrusVGAState
* s
, int off_begin
,
583 int off_pitch
, int bytesperline
,
590 for (y
= 0; y
< lines
; y
++) {
592 off_cur_end
= off_cur
+ bytesperline
;
593 off_cur
&= TARGET_PAGE_MASK
;
594 while (off_cur
< off_cur_end
) {
595 cpu_physical_memory_set_dirty(s
->vram_offset
+ off_cur
);
596 off_cur
+= TARGET_PAGE_SIZE
;
598 off_begin
+= off_pitch
;
602 static int cirrus_bitblt_common_patterncopy(CirrusVGAState
* s
,
607 dst
= s
->vram_ptr
+ s
->cirrus_blt_dstaddr
;
608 (*s
->cirrus_rop
) (s
, dst
, src
,
609 s
->cirrus_blt_dstpitch
, 0,
610 s
->cirrus_blt_width
, s
->cirrus_blt_height
);
611 cirrus_invalidate_region(s
, s
->cirrus_blt_dstaddr
,
612 s
->cirrus_blt_dstpitch
, s
->cirrus_blt_width
,
613 s
->cirrus_blt_height
);
619 static int cirrus_bitblt_solidfill(CirrusVGAState
*s
, int blt_rop
)
621 cirrus_fill_t rop_func
;
623 rop_func
= cirrus_fill
[rop_to_index
[blt_rop
]][s
->cirrus_blt_pixelwidth
- 1];
624 rop_func(s
, s
->vram_ptr
+ s
->cirrus_blt_dstaddr
,
625 s
->cirrus_blt_dstpitch
,
626 s
->cirrus_blt_width
, s
->cirrus_blt_height
);
627 cirrus_invalidate_region(s
, s
->cirrus_blt_dstaddr
,
628 s
->cirrus_blt_dstpitch
, s
->cirrus_blt_width
,
629 s
->cirrus_blt_height
);
630 cirrus_bitblt_reset(s
);
634 /***************************************
636 * bitblt (video-to-video)
638 ***************************************/
640 static int cirrus_bitblt_videotovideo_patterncopy(CirrusVGAState
* s
)
642 return cirrus_bitblt_common_patterncopy(s
,
644 (s
->cirrus_blt_srcaddr
& ~7));
647 static void cirrus_do_copy(CirrusVGAState
*s
, int dst
, int src
, int w
, int h
)
655 depth
= s
->get_bpp((VGAState
*)s
) / 8;
656 s
->get_resolution((VGAState
*)s
, &width
, &height
);
659 sx
= (src
% (width
* depth
)) / depth
;
660 sy
= (src
/ (width
* depth
));
661 dx
= (dst
% (width
*depth
)) / depth
;
662 dy
= (dst
/ (width
* depth
));
664 /* normalize width */
667 /* if we're doing a backward copy, we have to adjust
668 our x/y to be the upper left corner (instead of the lower
670 if (s
->cirrus_blt_dstpitch
< 0) {
671 sx
-= (s
->cirrus_blt_width
/ depth
) - 1;
672 dx
-= (s
->cirrus_blt_width
/ depth
) - 1;
673 sy
-= s
->cirrus_blt_height
- 1;
674 dy
-= s
->cirrus_blt_height
- 1;
677 /* are we in the visible portion of memory? */
678 if (sx
>= 0 && sy
>= 0 && dx
>= 0 && dy
>= 0 &&
679 (sx
+ w
) <= width
&& (sy
+ h
) <= height
&&
680 (dx
+ w
) <= width
&& (dy
+ h
) <= height
) {
684 /* make to sure only copy if it's a plain copy ROP */
685 if (*s
->cirrus_rop
!= cirrus_bitblt_rop_fwd_src
&&
686 *s
->cirrus_rop
!= cirrus_bitblt_rop_bkwd_src
)
689 /* we have to flush all pending changes so that the copy
690 is generated at the appropriate moment in time */
694 (*s
->cirrus_rop
) (s
, s
->vram_ptr
+ s
->cirrus_blt_dstaddr
,
695 s
->vram_ptr
+ s
->cirrus_blt_srcaddr
,
696 s
->cirrus_blt_dstpitch
, s
->cirrus_blt_srcpitch
,
697 s
->cirrus_blt_width
, s
->cirrus_blt_height
);
700 s
->ds
->dpy_copy(s
->ds
,
702 s
->cirrus_blt_width
/ depth
,
703 s
->cirrus_blt_height
);
705 /* we don't have to notify the display that this portion has
706 changed since dpy_copy implies this */
709 cirrus_invalidate_region(s
, s
->cirrus_blt_dstaddr
,
710 s
->cirrus_blt_dstpitch
, s
->cirrus_blt_width
,
711 s
->cirrus_blt_height
);
714 static int cirrus_bitblt_videotovideo_copy(CirrusVGAState
* s
)
716 if (s
->ds
->dpy_copy
) {
717 cirrus_do_copy(s
, s
->cirrus_blt_dstaddr
- s
->start_addr
,
718 s
->cirrus_blt_srcaddr
- s
->start_addr
,
719 s
->cirrus_blt_width
, s
->cirrus_blt_height
);
721 (*s
->cirrus_rop
) (s
, s
->vram_ptr
+ s
->cirrus_blt_dstaddr
,
722 s
->vram_ptr
+ s
->cirrus_blt_srcaddr
,
723 s
->cirrus_blt_dstpitch
, s
->cirrus_blt_srcpitch
,
724 s
->cirrus_blt_width
, s
->cirrus_blt_height
);
726 cirrus_invalidate_region(s
, s
->cirrus_blt_dstaddr
,
727 s
->cirrus_blt_dstpitch
, s
->cirrus_blt_width
,
728 s
->cirrus_blt_height
);
734 /***************************************
736 * bitblt (cpu-to-video)
738 ***************************************/
740 static void cirrus_bitblt_cputovideo_next(CirrusVGAState
* s
)
745 if (s
->cirrus_srccounter
> 0) {
746 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_PATTERNCOPY
) {
747 cirrus_bitblt_common_patterncopy(s
, s
->cirrus_bltbuf
);
749 s
->cirrus_srccounter
= 0;
750 cirrus_bitblt_reset(s
);
752 /* at least one scan line */
754 (*s
->cirrus_rop
)(s
, s
->vram_ptr
+ s
->cirrus_blt_dstaddr
,
755 s
->cirrus_bltbuf
, 0, 0, s
->cirrus_blt_width
, 1);
756 cirrus_invalidate_region(s
, s
->cirrus_blt_dstaddr
, 0,
757 s
->cirrus_blt_width
, 1);
758 s
->cirrus_blt_dstaddr
+= s
->cirrus_blt_dstpitch
;
759 s
->cirrus_srccounter
-= s
->cirrus_blt_srcpitch
;
760 if (s
->cirrus_srccounter
<= 0)
762 /* more bytes than needed can be transfered because of
763 word alignment, so we keep them for the next line */
764 /* XXX: keep alignment to speed up transfer */
765 end_ptr
= s
->cirrus_bltbuf
+ s
->cirrus_blt_srcpitch
;
766 copy_count
= s
->cirrus_srcptr_end
- end_ptr
;
767 memmove(s
->cirrus_bltbuf
, end_ptr
, copy_count
);
768 s
->cirrus_srcptr
= s
->cirrus_bltbuf
+ copy_count
;
769 s
->cirrus_srcptr_end
= s
->cirrus_bltbuf
+ s
->cirrus_blt_srcpitch
;
770 } while (s
->cirrus_srcptr
>= s
->cirrus_srcptr_end
);
775 /***************************************
779 ***************************************/
781 static void cirrus_bitblt_reset(CirrusVGAState
* s
)
784 ~(CIRRUS_BLT_START
| CIRRUS_BLT_BUSY
| CIRRUS_BLT_FIFOUSED
);
785 s
->cirrus_srcptr
= &s
->cirrus_bltbuf
[0];
786 s
->cirrus_srcptr_end
= &s
->cirrus_bltbuf
[0];
787 s
->cirrus_srccounter
= 0;
788 cirrus_update_memory_access(s
);
791 static int cirrus_bitblt_cputovideo(CirrusVGAState
* s
)
795 s
->cirrus_blt_mode
&= ~CIRRUS_BLTMODE_MEMSYSSRC
;
796 s
->cirrus_srcptr
= &s
->cirrus_bltbuf
[0];
797 s
->cirrus_srcptr_end
= &s
->cirrus_bltbuf
[0];
799 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_PATTERNCOPY
) {
800 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_COLOREXPAND
) {
801 s
->cirrus_blt_srcpitch
= 8;
803 /* XXX: check for 24 bpp */
804 s
->cirrus_blt_srcpitch
= 8 * 8 * s
->cirrus_blt_pixelwidth
;
806 s
->cirrus_srccounter
= s
->cirrus_blt_srcpitch
;
808 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_COLOREXPAND
) {
809 w
= s
->cirrus_blt_width
/ s
->cirrus_blt_pixelwidth
;
810 if (s
->cirrus_blt_modeext
& CIRRUS_BLTMODEEXT_DWORDGRANULARITY
)
811 s
->cirrus_blt_srcpitch
= ((w
+ 31) >> 5);
813 s
->cirrus_blt_srcpitch
= ((w
+ 7) >> 3);
815 /* always align input size to 32 bits */
816 s
->cirrus_blt_srcpitch
= (s
->cirrus_blt_width
+ 3) & ~3;
818 s
->cirrus_srccounter
= s
->cirrus_blt_srcpitch
* s
->cirrus_blt_height
;
820 s
->cirrus_srcptr
= s
->cirrus_bltbuf
;
821 s
->cirrus_srcptr_end
= s
->cirrus_bltbuf
+ s
->cirrus_blt_srcpitch
;
822 cirrus_update_memory_access(s
);
826 static int cirrus_bitblt_videotocpu(CirrusVGAState
* s
)
830 printf("cirrus: bitblt (video to cpu) is not implemented yet\n");
835 static int cirrus_bitblt_videotovideo(CirrusVGAState
* s
)
839 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_PATTERNCOPY
) {
840 ret
= cirrus_bitblt_videotovideo_patterncopy(s
);
842 ret
= cirrus_bitblt_videotovideo_copy(s
);
845 cirrus_bitblt_reset(s
);
849 static void cirrus_bitblt_start(CirrusVGAState
* s
)
853 s
->gr
[0x31] |= CIRRUS_BLT_BUSY
;
855 s
->cirrus_blt_width
= (s
->gr
[0x20] | (s
->gr
[0x21] << 8)) + 1;
856 s
->cirrus_blt_height
= (s
->gr
[0x22] | (s
->gr
[0x23] << 8)) + 1;
857 s
->cirrus_blt_dstpitch
= (s
->gr
[0x24] | (s
->gr
[0x25] << 8));
858 s
->cirrus_blt_srcpitch
= (s
->gr
[0x26] | (s
->gr
[0x27] << 8));
859 s
->cirrus_blt_dstaddr
=
860 (s
->gr
[0x28] | (s
->gr
[0x29] << 8) | (s
->gr
[0x2a] << 16));
861 s
->cirrus_blt_srcaddr
=
862 (s
->gr
[0x2c] | (s
->gr
[0x2d] << 8) | (s
->gr
[0x2e] << 16));
863 s
->cirrus_blt_mode
= s
->gr
[0x30];
864 s
->cirrus_blt_modeext
= s
->gr
[0x33];
865 blt_rop
= s
->gr
[0x32];
868 printf("rop=0x%02x mode=0x%02x modeext=0x%02x w=%d h=%d dpitch=%d spitch=%d daddr=0x%08x saddr=0x%08x writemask=0x%02x\n",
871 s
->cirrus_blt_modeext
,
873 s
->cirrus_blt_height
,
874 s
->cirrus_blt_dstpitch
,
875 s
->cirrus_blt_srcpitch
,
876 s
->cirrus_blt_dstaddr
,
877 s
->cirrus_blt_srcaddr
,
881 switch (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_PIXELWIDTHMASK
) {
882 case CIRRUS_BLTMODE_PIXELWIDTH8
:
883 s
->cirrus_blt_pixelwidth
= 1;
885 case CIRRUS_BLTMODE_PIXELWIDTH16
:
886 s
->cirrus_blt_pixelwidth
= 2;
888 case CIRRUS_BLTMODE_PIXELWIDTH24
:
889 s
->cirrus_blt_pixelwidth
= 3;
891 case CIRRUS_BLTMODE_PIXELWIDTH32
:
892 s
->cirrus_blt_pixelwidth
= 4;
896 printf("cirrus: bitblt - pixel width is unknown\n");
900 s
->cirrus_blt_mode
&= ~CIRRUS_BLTMODE_PIXELWIDTHMASK
;
903 cirrus_blt_mode
& (CIRRUS_BLTMODE_MEMSYSSRC
|
904 CIRRUS_BLTMODE_MEMSYSDEST
))
905 == (CIRRUS_BLTMODE_MEMSYSSRC
| CIRRUS_BLTMODE_MEMSYSDEST
)) {
907 printf("cirrus: bitblt - memory-to-memory copy is requested\n");
912 if ((s
->cirrus_blt_modeext
& CIRRUS_BLTMODEEXT_SOLIDFILL
) &&
913 (s
->cirrus_blt_mode
& (CIRRUS_BLTMODE_MEMSYSDEST
|
914 CIRRUS_BLTMODE_TRANSPARENTCOMP
|
915 CIRRUS_BLTMODE_PATTERNCOPY
|
916 CIRRUS_BLTMODE_COLOREXPAND
)) ==
917 (CIRRUS_BLTMODE_PATTERNCOPY
| CIRRUS_BLTMODE_COLOREXPAND
)) {
918 cirrus_bitblt_fgcol(s
);
919 cirrus_bitblt_solidfill(s
, blt_rop
);
921 if ((s
->cirrus_blt_mode
& (CIRRUS_BLTMODE_COLOREXPAND
|
922 CIRRUS_BLTMODE_PATTERNCOPY
)) ==
923 CIRRUS_BLTMODE_COLOREXPAND
) {
925 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_TRANSPARENTCOMP
) {
926 if (s
->cirrus_blt_modeext
& CIRRUS_BLTMODEEXT_COLOREXPINV
)
927 cirrus_bitblt_bgcol(s
);
929 cirrus_bitblt_fgcol(s
);
930 s
->cirrus_rop
= cirrus_colorexpand_transp
[rop_to_index
[blt_rop
]][s
->cirrus_blt_pixelwidth
- 1];
932 cirrus_bitblt_fgcol(s
);
933 cirrus_bitblt_bgcol(s
);
934 s
->cirrus_rop
= cirrus_colorexpand
[rop_to_index
[blt_rop
]][s
->cirrus_blt_pixelwidth
- 1];
936 } else if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_PATTERNCOPY
) {
937 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_COLOREXPAND
) {
938 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_TRANSPARENTCOMP
) {
939 if (s
->cirrus_blt_modeext
& CIRRUS_BLTMODEEXT_COLOREXPINV
)
940 cirrus_bitblt_bgcol(s
);
942 cirrus_bitblt_fgcol(s
);
943 s
->cirrus_rop
= cirrus_colorexpand_pattern_transp
[rop_to_index
[blt_rop
]][s
->cirrus_blt_pixelwidth
- 1];
945 cirrus_bitblt_fgcol(s
);
946 cirrus_bitblt_bgcol(s
);
947 s
->cirrus_rop
= cirrus_colorexpand_pattern
[rop_to_index
[blt_rop
]][s
->cirrus_blt_pixelwidth
- 1];
950 s
->cirrus_rop
= cirrus_patternfill
[rop_to_index
[blt_rop
]][s
->cirrus_blt_pixelwidth
- 1];
953 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_BACKWARDS
) {
954 s
->cirrus_blt_dstpitch
= -s
->cirrus_blt_dstpitch
;
955 s
->cirrus_blt_srcpitch
= -s
->cirrus_blt_srcpitch
;
956 s
->cirrus_rop
= cirrus_bkwd_rop
[rop_to_index
[blt_rop
]];
958 s
->cirrus_rop
= cirrus_fwd_rop
[rop_to_index
[blt_rop
]];
962 // setup bitblt engine.
963 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_MEMSYSSRC
) {
964 if (!cirrus_bitblt_cputovideo(s
))
966 } else if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_MEMSYSDEST
) {
967 if (!cirrus_bitblt_videotocpu(s
))
970 if (!cirrus_bitblt_videotovideo(s
))
976 cirrus_bitblt_reset(s
);
979 static void cirrus_write_bitblt(CirrusVGAState
* s
, unsigned reg_value
)
983 old_value
= s
->gr
[0x31];
984 s
->gr
[0x31] = reg_value
;
986 if (((old_value
& CIRRUS_BLT_RESET
) != 0) &&
987 ((reg_value
& CIRRUS_BLT_RESET
) == 0)) {
988 cirrus_bitblt_reset(s
);
989 } else if (((old_value
& CIRRUS_BLT_START
) == 0) &&
990 ((reg_value
& CIRRUS_BLT_START
) != 0)) {
991 cirrus_bitblt_start(s
);
996 /***************************************
1000 ***************************************/
1002 static void cirrus_get_offsets(VGAState
*s1
,
1003 uint32_t *pline_offset
,
1004 uint32_t *pstart_addr
,
1005 uint32_t *pline_compare
)
1007 CirrusVGAState
* s
= (CirrusVGAState
*)s1
;
1008 uint32_t start_addr
, line_offset
, line_compare
;
1010 line_offset
= s
->cr
[0x13]
1011 | ((s
->cr
[0x1b] & 0x10) << 4);
1013 *pline_offset
= line_offset
;
1015 start_addr
= (s
->cr
[0x0c] << 8)
1017 | ((s
->cr
[0x1b] & 0x01) << 16)
1018 | ((s
->cr
[0x1b] & 0x0c) << 15)
1019 | ((s
->cr
[0x1d] & 0x80) << 12);
1020 *pstart_addr
= start_addr
;
1022 line_compare
= s
->cr
[0x18] |
1023 ((s
->cr
[0x07] & 0x10) << 4) |
1024 ((s
->cr
[0x09] & 0x40) << 3);
1025 *pline_compare
= line_compare
;
1028 static uint32_t cirrus_get_bpp16_depth(CirrusVGAState
* s
)
1032 switch (s
->cirrus_hidden_dac_data
& 0xf) {
1035 break; /* Sierra HiColor */
1038 break; /* XGA HiColor */
1041 printf("cirrus: invalid DAC value %x in 16bpp\n",
1042 (s
->cirrus_hidden_dac_data
& 0xf));
1050 static int cirrus_get_bpp(VGAState
*s1
)
1052 CirrusVGAState
* s
= (CirrusVGAState
*)s1
;
1055 if ((s
->sr
[0x07] & 0x01) != 0) {
1057 switch (s
->sr
[0x07] & CIRRUS_SR7_BPP_MASK
) {
1058 case CIRRUS_SR7_BPP_8
:
1061 case CIRRUS_SR7_BPP_16_DOUBLEVCLK
:
1062 ret
= cirrus_get_bpp16_depth(s
);
1064 case CIRRUS_SR7_BPP_24
:
1067 case CIRRUS_SR7_BPP_16
:
1068 ret
= cirrus_get_bpp16_depth(s
);
1070 case CIRRUS_SR7_BPP_32
:
1075 printf("cirrus: unknown bpp - sr7=%x\n", s
->sr
[0x7]);
1088 static void cirrus_get_resolution(VGAState
*s
, int *pwidth
, int *pheight
)
1092 width
= (s
->cr
[0x01] + 1) * 8;
1093 height
= s
->cr
[0x12] |
1094 ((s
->cr
[0x07] & 0x02) << 7) |
1095 ((s
->cr
[0x07] & 0x40) << 3);
1096 height
= (height
+ 1);
1097 /* interlace support */
1098 if (s
->cr
[0x1a] & 0x01)
1099 height
= height
* 2;
1104 /***************************************
1108 ***************************************/
1110 static void cirrus_update_bank_ptr(CirrusVGAState
* s
, unsigned bank_index
)
1115 if ((s
->gr
[0x0b] & 0x01) != 0) /* dual bank */
1116 offset
= s
->gr
[0x09 + bank_index
];
1117 else /* single bank */
1118 offset
= s
->gr
[0x09];
1120 if ((s
->gr
[0x0b] & 0x20) != 0)
1125 if (s
->real_vram_size
<= offset
)
1128 limit
= s
->real_vram_size
- offset
;
1130 if (((s
->gr
[0x0b] & 0x01) == 0) && (bank_index
!= 0)) {
1131 if (limit
> 0x8000) {
1140 s
->cirrus_bank_base
[bank_index
] = offset
;
1141 s
->cirrus_bank_limit
[bank_index
] = limit
;
1143 s
->cirrus_bank_base
[bank_index
] = 0;
1144 s
->cirrus_bank_limit
[bank_index
] = 0;
1148 /***************************************
1150 * I/O access between 0x3c4-0x3c5
1152 ***************************************/
1155 cirrus_hook_read_sr(CirrusVGAState
* s
, unsigned reg_index
, int *reg_value
)
1157 switch (reg_index
) {
1158 case 0x00: // Standard VGA
1159 case 0x01: // Standard VGA
1160 case 0x02: // Standard VGA
1161 case 0x03: // Standard VGA
1162 case 0x04: // Standard VGA
1163 return CIRRUS_HOOK_NOT_HANDLED
;
1164 case 0x06: // Unlock Cirrus extensions
1165 *reg_value
= s
->sr
[reg_index
];
1170 case 0x70: // Graphics Cursor X
1174 case 0xf0: // Graphics Cursor X
1175 *reg_value
= s
->sr
[0x10];
1180 case 0x71: // Graphics Cursor Y
1184 case 0xf1: // Graphics Cursor Y
1185 *reg_value
= s
->sr
[0x11];
1188 case 0x07: // Extended Sequencer Mode
1189 case 0x08: // EEPROM Control
1190 case 0x09: // Scratch Register 0
1191 case 0x0a: // Scratch Register 1
1192 case 0x0b: // VCLK 0
1193 case 0x0c: // VCLK 1
1194 case 0x0d: // VCLK 2
1195 case 0x0e: // VCLK 3
1196 case 0x0f: // DRAM Control
1197 case 0x12: // Graphics Cursor Attribute
1198 case 0x13: // Graphics Cursor Pattern Address
1199 case 0x14: // Scratch Register 2
1200 case 0x15: // Scratch Register 3
1201 case 0x16: // Performance Tuning Register
1202 case 0x17: // Configuration Readback and Extended Control
1203 case 0x18: // Signature Generator Control
1204 case 0x19: // Signal Generator Result
1205 case 0x1a: // Signal Generator Result
1206 case 0x1b: // VCLK 0 Denominator & Post
1207 case 0x1c: // VCLK 1 Denominator & Post
1208 case 0x1d: // VCLK 2 Denominator & Post
1209 case 0x1e: // VCLK 3 Denominator & Post
1210 case 0x1f: // BIOS Write Enable and MCLK select
1212 printf("cirrus: handled inport sr_index %02x\n", reg_index
);
1214 *reg_value
= s
->sr
[reg_index
];
1218 printf("cirrus: inport sr_index %02x\n", reg_index
);
1224 return CIRRUS_HOOK_HANDLED
;
1228 cirrus_hook_write_sr(CirrusVGAState
* s
, unsigned reg_index
, int reg_value
)
1230 switch (reg_index
) {
1231 case 0x00: // Standard VGA
1232 case 0x01: // Standard VGA
1233 case 0x02: // Standard VGA
1234 case 0x03: // Standard VGA
1235 case 0x04: // Standard VGA
1236 return CIRRUS_HOOK_NOT_HANDLED
;
1237 case 0x06: // Unlock Cirrus extensions
1239 if (reg_value
== 0x12) {
1240 s
->sr
[reg_index
] = 0x12;
1242 s
->sr
[reg_index
] = 0x0f;
1248 case 0x70: // Graphics Cursor X
1252 case 0xf0: // Graphics Cursor X
1253 s
->sr
[0x10] = reg_value
;
1254 s
->hw_cursor_x
= (reg_value
<< 3) | (reg_index
>> 5);
1259 case 0x71: // Graphics Cursor Y
1263 case 0xf1: // Graphics Cursor Y
1264 s
->sr
[0x11] = reg_value
;
1265 s
->hw_cursor_y
= (reg_value
<< 3) | (reg_index
>> 5);
1267 case 0x07: // Extended Sequencer Mode
1268 case 0x08: // EEPROM Control
1269 case 0x09: // Scratch Register 0
1270 case 0x0a: // Scratch Register 1
1271 case 0x0b: // VCLK 0
1272 case 0x0c: // VCLK 1
1273 case 0x0d: // VCLK 2
1274 case 0x0e: // VCLK 3
1275 case 0x0f: // DRAM Control
1276 case 0x12: // Graphics Cursor Attribute
1277 case 0x13: // Graphics Cursor Pattern Address
1278 case 0x14: // Scratch Register 2
1279 case 0x15: // Scratch Register 3
1280 case 0x16: // Performance Tuning Register
1281 case 0x18: // Signature Generator Control
1282 case 0x19: // Signature Generator Result
1283 case 0x1a: // Signature Generator Result
1284 case 0x1b: // VCLK 0 Denominator & Post
1285 case 0x1c: // VCLK 1 Denominator & Post
1286 case 0x1d: // VCLK 2 Denominator & Post
1287 case 0x1e: // VCLK 3 Denominator & Post
1288 case 0x1f: // BIOS Write Enable and MCLK select
1289 s
->sr
[reg_index
] = reg_value
;
1291 printf("cirrus: handled outport sr_index %02x, sr_value %02x\n",
1292 reg_index
, reg_value
);
1295 case 0x17: // Configuration Readback and Extended Control
1296 s
->sr
[reg_index
] = (s
->sr
[reg_index
] & 0x38) | (reg_value
& 0xc7);
1297 cirrus_update_memory_access(s
);
1301 printf("cirrus: outport sr_index %02x, sr_value %02x\n", reg_index
,
1307 return CIRRUS_HOOK_HANDLED
;
1310 /***************************************
1312 * I/O access at 0x3c6
1314 ***************************************/
1316 static void cirrus_read_hidden_dac(CirrusVGAState
* s
, int *reg_value
)
1319 if (++s
->cirrus_hidden_dac_lockindex
== 5) {
1320 *reg_value
= s
->cirrus_hidden_dac_data
;
1321 s
->cirrus_hidden_dac_lockindex
= 0;
1325 static void cirrus_write_hidden_dac(CirrusVGAState
* s
, int reg_value
)
1327 if (s
->cirrus_hidden_dac_lockindex
== 4) {
1328 s
->cirrus_hidden_dac_data
= reg_value
;
1329 #if defined(DEBUG_CIRRUS)
1330 printf("cirrus: outport hidden DAC, value %02x\n", reg_value
);
1333 s
->cirrus_hidden_dac_lockindex
= 0;
1336 /***************************************
1338 * I/O access at 0x3c9
1340 ***************************************/
1342 static int cirrus_hook_read_palette(CirrusVGAState
* s
, int *reg_value
)
1344 if (!(s
->sr
[0x12] & CIRRUS_CURSOR_HIDDENPEL
))
1345 return CIRRUS_HOOK_NOT_HANDLED
;
1347 s
->cirrus_hidden_palette
[(s
->dac_read_index
& 0x0f) * 3 +
1349 if (++s
->dac_sub_index
== 3) {
1350 s
->dac_sub_index
= 0;
1351 s
->dac_read_index
++;
1353 return CIRRUS_HOOK_HANDLED
;
1356 static int cirrus_hook_write_palette(CirrusVGAState
* s
, int reg_value
)
1358 if (!(s
->sr
[0x12] & CIRRUS_CURSOR_HIDDENPEL
))
1359 return CIRRUS_HOOK_NOT_HANDLED
;
1360 s
->dac_cache
[s
->dac_sub_index
] = reg_value
;
1361 if (++s
->dac_sub_index
== 3) {
1362 memcpy(&s
->cirrus_hidden_palette
[(s
->dac_write_index
& 0x0f) * 3],
1364 /* XXX update cursor */
1365 s
->dac_sub_index
= 0;
1366 s
->dac_write_index
++;
1368 return CIRRUS_HOOK_HANDLED
;
1371 /***************************************
1373 * I/O access between 0x3ce-0x3cf
1375 ***************************************/
1378 cirrus_hook_read_gr(CirrusVGAState
* s
, unsigned reg_index
, int *reg_value
)
1380 switch (reg_index
) {
1381 case 0x00: // Standard VGA, BGCOLOR 0x000000ff
1382 *reg_value
= s
->cirrus_shadow_gr0
;
1383 return CIRRUS_HOOK_HANDLED
;
1384 case 0x01: // Standard VGA, FGCOLOR 0x000000ff
1385 *reg_value
= s
->cirrus_shadow_gr1
;
1386 return CIRRUS_HOOK_HANDLED
;
1387 case 0x02: // Standard VGA
1388 case 0x03: // Standard VGA
1389 case 0x04: // Standard VGA
1390 case 0x06: // Standard VGA
1391 case 0x07: // Standard VGA
1392 case 0x08: // Standard VGA
1393 return CIRRUS_HOOK_NOT_HANDLED
;
1394 case 0x05: // Standard VGA, Cirrus extended mode
1399 if (reg_index
< 0x3a) {
1400 *reg_value
= s
->gr
[reg_index
];
1403 printf("cirrus: inport gr_index %02x\n", reg_index
);
1408 return CIRRUS_HOOK_HANDLED
;
1412 cirrus_hook_write_gr(CirrusVGAState
* s
, unsigned reg_index
, int reg_value
)
1414 #if defined(DEBUG_BITBLT) && 0
1415 printf("gr%02x: %02x\n", reg_index
, reg_value
);
1417 switch (reg_index
) {
1418 case 0x00: // Standard VGA, BGCOLOR 0x000000ff
1419 s
->cirrus_shadow_gr0
= reg_value
;
1420 return CIRRUS_HOOK_NOT_HANDLED
;
1421 case 0x01: // Standard VGA, FGCOLOR 0x000000ff
1422 s
->cirrus_shadow_gr1
= reg_value
;
1423 return CIRRUS_HOOK_NOT_HANDLED
;
1424 case 0x02: // Standard VGA
1425 case 0x03: // Standard VGA
1426 case 0x04: // Standard VGA
1427 case 0x06: // Standard VGA
1428 case 0x07: // Standard VGA
1429 case 0x08: // Standard VGA
1430 return CIRRUS_HOOK_NOT_HANDLED
;
1431 case 0x05: // Standard VGA, Cirrus extended mode
1432 s
->gr
[reg_index
] = reg_value
& 0x7f;
1433 cirrus_update_memory_access(s
);
1435 case 0x09: // bank offset #0
1436 case 0x0A: // bank offset #1
1437 s
->gr
[reg_index
] = reg_value
;
1438 cirrus_update_bank_ptr(s
, 0);
1439 cirrus_update_bank_ptr(s
, 1);
1442 s
->gr
[reg_index
] = reg_value
;
1443 cirrus_update_bank_ptr(s
, 0);
1444 cirrus_update_bank_ptr(s
, 1);
1445 cirrus_update_memory_access(s
);
1447 case 0x10: // BGCOLOR 0x0000ff00
1448 case 0x11: // FGCOLOR 0x0000ff00
1449 case 0x12: // BGCOLOR 0x00ff0000
1450 case 0x13: // FGCOLOR 0x00ff0000
1451 case 0x14: // BGCOLOR 0xff000000
1452 case 0x15: // FGCOLOR 0xff000000
1453 case 0x20: // BLT WIDTH 0x0000ff
1454 case 0x22: // BLT HEIGHT 0x0000ff
1455 case 0x24: // BLT DEST PITCH 0x0000ff
1456 case 0x26: // BLT SRC PITCH 0x0000ff
1457 case 0x28: // BLT DEST ADDR 0x0000ff
1458 case 0x29: // BLT DEST ADDR 0x00ff00
1459 case 0x2c: // BLT SRC ADDR 0x0000ff
1460 case 0x2d: // BLT SRC ADDR 0x00ff00
1461 case 0x2f: // BLT WRITEMASK
1462 case 0x30: // BLT MODE
1463 case 0x32: // RASTER OP
1464 case 0x33: // BLT MODEEXT
1465 case 0x34: // BLT TRANSPARENT COLOR 0x00ff
1466 case 0x35: // BLT TRANSPARENT COLOR 0xff00
1467 case 0x38: // BLT TRANSPARENT COLOR MASK 0x00ff
1468 case 0x39: // BLT TRANSPARENT COLOR MASK 0xff00
1469 s
->gr
[reg_index
] = reg_value
;
1471 case 0x21: // BLT WIDTH 0x001f00
1472 case 0x23: // BLT HEIGHT 0x001f00
1473 case 0x25: // BLT DEST PITCH 0x001f00
1474 case 0x27: // BLT SRC PITCH 0x001f00
1475 s
->gr
[reg_index
] = reg_value
& 0x1f;
1477 case 0x2a: // BLT DEST ADDR 0x3f0000
1478 s
->gr
[reg_index
] = reg_value
& 0x3f;
1479 /* if auto start mode, starts bit blt now */
1480 if (s
->gr
[0x31] & CIRRUS_BLT_AUTOSTART
) {
1481 cirrus_bitblt_start(s
);
1484 case 0x2e: // BLT SRC ADDR 0x3f0000
1485 s
->gr
[reg_index
] = reg_value
& 0x3f;
1487 case 0x31: // BLT STATUS/START
1488 cirrus_write_bitblt(s
, reg_value
);
1492 printf("cirrus: outport gr_index %02x, gr_value %02x\n", reg_index
,
1498 return CIRRUS_HOOK_HANDLED
;
1501 /***************************************
1503 * I/O access between 0x3d4-0x3d5
1505 ***************************************/
1508 cirrus_hook_read_cr(CirrusVGAState
* s
, unsigned reg_index
, int *reg_value
)
1510 switch (reg_index
) {
1511 case 0x00: // Standard VGA
1512 case 0x01: // Standard VGA
1513 case 0x02: // Standard VGA
1514 case 0x03: // Standard VGA
1515 case 0x04: // Standard VGA
1516 case 0x05: // Standard VGA
1517 case 0x06: // Standard VGA
1518 case 0x07: // Standard VGA
1519 case 0x08: // Standard VGA
1520 case 0x09: // Standard VGA
1521 case 0x0a: // Standard VGA
1522 case 0x0b: // Standard VGA
1523 case 0x0c: // Standard VGA
1524 case 0x0d: // Standard VGA
1525 case 0x0e: // Standard VGA
1526 case 0x0f: // Standard VGA
1527 case 0x10: // Standard VGA
1528 case 0x11: // Standard VGA
1529 case 0x12: // Standard VGA
1530 case 0x13: // Standard VGA
1531 case 0x14: // Standard VGA
1532 case 0x15: // Standard VGA
1533 case 0x16: // Standard VGA
1534 case 0x17: // Standard VGA
1535 case 0x18: // Standard VGA
1536 return CIRRUS_HOOK_NOT_HANDLED
;
1537 case 0x19: // Interlace End
1538 case 0x1a: // Miscellaneous Control
1539 case 0x1b: // Extended Display Control
1540 case 0x1c: // Sync Adjust and Genlock
1541 case 0x1d: // Overlay Extended Control
1542 case 0x22: // Graphics Data Latches Readback (R)
1543 case 0x24: // Attribute Controller Toggle Readback (R)
1544 case 0x25: // Part Status
1545 case 0x27: // Part ID (R)
1546 *reg_value
= s
->cr
[reg_index
];
1548 case 0x26: // Attribute Controller Index Readback (R)
1549 *reg_value
= s
->ar_index
& 0x3f;
1553 printf("cirrus: inport cr_index %02x\n", reg_index
);
1559 return CIRRUS_HOOK_HANDLED
;
1563 cirrus_hook_write_cr(CirrusVGAState
* s
, unsigned reg_index
, int reg_value
)
1565 switch (reg_index
) {
1566 case 0x00: // Standard VGA
1567 case 0x01: // Standard VGA
1568 case 0x02: // Standard VGA
1569 case 0x03: // Standard VGA
1570 case 0x04: // Standard VGA
1571 case 0x05: // Standard VGA
1572 case 0x06: // Standard VGA
1573 case 0x07: // Standard VGA
1574 case 0x08: // Standard VGA
1575 case 0x09: // Standard VGA
1576 case 0x0a: // Standard VGA
1577 case 0x0b: // Standard VGA
1578 case 0x0c: // Standard VGA
1579 case 0x0d: // Standard VGA
1580 case 0x0e: // Standard VGA
1581 case 0x0f: // Standard VGA
1582 case 0x10: // Standard VGA
1583 case 0x11: // Standard VGA
1584 case 0x12: // Standard VGA
1585 case 0x13: // Standard VGA
1586 case 0x14: // Standard VGA
1587 case 0x15: // Standard VGA
1588 case 0x16: // Standard VGA
1589 case 0x17: // Standard VGA
1590 case 0x18: // Standard VGA
1591 return CIRRUS_HOOK_NOT_HANDLED
;
1592 case 0x19: // Interlace End
1593 case 0x1a: // Miscellaneous Control
1594 case 0x1b: // Extended Display Control
1595 case 0x1c: // Sync Adjust and Genlock
1596 case 0x1d: // Overlay Extended Control
1597 s
->cr
[reg_index
] = reg_value
;
1599 printf("cirrus: handled outport cr_index %02x, cr_value %02x\n",
1600 reg_index
, reg_value
);
1603 case 0x22: // Graphics Data Latches Readback (R)
1604 case 0x24: // Attribute Controller Toggle Readback (R)
1605 case 0x26: // Attribute Controller Index Readback (R)
1606 case 0x27: // Part ID (R)
1608 case 0x25: // Part Status
1611 printf("cirrus: outport cr_index %02x, cr_value %02x\n", reg_index
,
1617 return CIRRUS_HOOK_HANDLED
;
1620 /***************************************
1622 * memory-mapped I/O (bitblt)
1624 ***************************************/
1626 static uint8_t cirrus_mmio_blt_read(CirrusVGAState
* s
, unsigned address
)
1631 case (CIRRUS_MMIO_BLTBGCOLOR
+ 0):
1632 cirrus_hook_read_gr(s
, 0x00, &value
);
1634 case (CIRRUS_MMIO_BLTBGCOLOR
+ 1):
1635 cirrus_hook_read_gr(s
, 0x10, &value
);
1637 case (CIRRUS_MMIO_BLTBGCOLOR
+ 2):
1638 cirrus_hook_read_gr(s
, 0x12, &value
);
1640 case (CIRRUS_MMIO_BLTBGCOLOR
+ 3):
1641 cirrus_hook_read_gr(s
, 0x14, &value
);
1643 case (CIRRUS_MMIO_BLTFGCOLOR
+ 0):
1644 cirrus_hook_read_gr(s
, 0x01, &value
);
1646 case (CIRRUS_MMIO_BLTFGCOLOR
+ 1):
1647 cirrus_hook_read_gr(s
, 0x11, &value
);
1649 case (CIRRUS_MMIO_BLTFGCOLOR
+ 2):
1650 cirrus_hook_read_gr(s
, 0x13, &value
);
1652 case (CIRRUS_MMIO_BLTFGCOLOR
+ 3):
1653 cirrus_hook_read_gr(s
, 0x15, &value
);
1655 case (CIRRUS_MMIO_BLTWIDTH
+ 0):
1656 cirrus_hook_read_gr(s
, 0x20, &value
);
1658 case (CIRRUS_MMIO_BLTWIDTH
+ 1):
1659 cirrus_hook_read_gr(s
, 0x21, &value
);
1661 case (CIRRUS_MMIO_BLTHEIGHT
+ 0):
1662 cirrus_hook_read_gr(s
, 0x22, &value
);
1664 case (CIRRUS_MMIO_BLTHEIGHT
+ 1):
1665 cirrus_hook_read_gr(s
, 0x23, &value
);
1667 case (CIRRUS_MMIO_BLTDESTPITCH
+ 0):
1668 cirrus_hook_read_gr(s
, 0x24, &value
);
1670 case (CIRRUS_MMIO_BLTDESTPITCH
+ 1):
1671 cirrus_hook_read_gr(s
, 0x25, &value
);
1673 case (CIRRUS_MMIO_BLTSRCPITCH
+ 0):
1674 cirrus_hook_read_gr(s
, 0x26, &value
);
1676 case (CIRRUS_MMIO_BLTSRCPITCH
+ 1):
1677 cirrus_hook_read_gr(s
, 0x27, &value
);
1679 case (CIRRUS_MMIO_BLTDESTADDR
+ 0):
1680 cirrus_hook_read_gr(s
, 0x28, &value
);
1682 case (CIRRUS_MMIO_BLTDESTADDR
+ 1):
1683 cirrus_hook_read_gr(s
, 0x29, &value
);
1685 case (CIRRUS_MMIO_BLTDESTADDR
+ 2):
1686 cirrus_hook_read_gr(s
, 0x2a, &value
);
1688 case (CIRRUS_MMIO_BLTSRCADDR
+ 0):
1689 cirrus_hook_read_gr(s
, 0x2c, &value
);
1691 case (CIRRUS_MMIO_BLTSRCADDR
+ 1):
1692 cirrus_hook_read_gr(s
, 0x2d, &value
);
1694 case (CIRRUS_MMIO_BLTSRCADDR
+ 2):
1695 cirrus_hook_read_gr(s
, 0x2e, &value
);
1697 case CIRRUS_MMIO_BLTWRITEMASK
:
1698 cirrus_hook_read_gr(s
, 0x2f, &value
);
1700 case CIRRUS_MMIO_BLTMODE
:
1701 cirrus_hook_read_gr(s
, 0x30, &value
);
1703 case CIRRUS_MMIO_BLTROP
:
1704 cirrus_hook_read_gr(s
, 0x32, &value
);
1706 case CIRRUS_MMIO_BLTMODEEXT
:
1707 cirrus_hook_read_gr(s
, 0x33, &value
);
1709 case (CIRRUS_MMIO_BLTTRANSPARENTCOLOR
+ 0):
1710 cirrus_hook_read_gr(s
, 0x34, &value
);
1712 case (CIRRUS_MMIO_BLTTRANSPARENTCOLOR
+ 1):
1713 cirrus_hook_read_gr(s
, 0x35, &value
);
1715 case (CIRRUS_MMIO_BLTTRANSPARENTCOLORMASK
+ 0):
1716 cirrus_hook_read_gr(s
, 0x38, &value
);
1718 case (CIRRUS_MMIO_BLTTRANSPARENTCOLORMASK
+ 1):
1719 cirrus_hook_read_gr(s
, 0x39, &value
);
1721 case CIRRUS_MMIO_BLTSTATUS
:
1722 cirrus_hook_read_gr(s
, 0x31, &value
);
1726 printf("cirrus: mmio read - address 0x%04x\n", address
);
1731 return (uint8_t) value
;
1734 static void cirrus_mmio_blt_write(CirrusVGAState
* s
, unsigned address
,
1738 case (CIRRUS_MMIO_BLTBGCOLOR
+ 0):
1739 cirrus_hook_write_gr(s
, 0x00, value
);
1741 case (CIRRUS_MMIO_BLTBGCOLOR
+ 1):
1742 cirrus_hook_write_gr(s
, 0x10, value
);
1744 case (CIRRUS_MMIO_BLTBGCOLOR
+ 2):
1745 cirrus_hook_write_gr(s
, 0x12, value
);
1747 case (CIRRUS_MMIO_BLTBGCOLOR
+ 3):
1748 cirrus_hook_write_gr(s
, 0x14, value
);
1750 case (CIRRUS_MMIO_BLTFGCOLOR
+ 0):
1751 cirrus_hook_write_gr(s
, 0x01, value
);
1753 case (CIRRUS_MMIO_BLTFGCOLOR
+ 1):
1754 cirrus_hook_write_gr(s
, 0x11, value
);
1756 case (CIRRUS_MMIO_BLTFGCOLOR
+ 2):
1757 cirrus_hook_write_gr(s
, 0x13, value
);
1759 case (CIRRUS_MMIO_BLTFGCOLOR
+ 3):
1760 cirrus_hook_write_gr(s
, 0x15, value
);
1762 case (CIRRUS_MMIO_BLTWIDTH
+ 0):
1763 cirrus_hook_write_gr(s
, 0x20, value
);
1765 case (CIRRUS_MMIO_BLTWIDTH
+ 1):
1766 cirrus_hook_write_gr(s
, 0x21, value
);
1768 case (CIRRUS_MMIO_BLTHEIGHT
+ 0):
1769 cirrus_hook_write_gr(s
, 0x22, value
);
1771 case (CIRRUS_MMIO_BLTHEIGHT
+ 1):
1772 cirrus_hook_write_gr(s
, 0x23, value
);
1774 case (CIRRUS_MMIO_BLTDESTPITCH
+ 0):
1775 cirrus_hook_write_gr(s
, 0x24, value
);
1777 case (CIRRUS_MMIO_BLTDESTPITCH
+ 1):
1778 cirrus_hook_write_gr(s
, 0x25, value
);
1780 case (CIRRUS_MMIO_BLTSRCPITCH
+ 0):
1781 cirrus_hook_write_gr(s
, 0x26, value
);
1783 case (CIRRUS_MMIO_BLTSRCPITCH
+ 1):
1784 cirrus_hook_write_gr(s
, 0x27, value
);
1786 case (CIRRUS_MMIO_BLTDESTADDR
+ 0):
1787 cirrus_hook_write_gr(s
, 0x28, value
);
1789 case (CIRRUS_MMIO_BLTDESTADDR
+ 1):
1790 cirrus_hook_write_gr(s
, 0x29, value
);
1792 case (CIRRUS_MMIO_BLTDESTADDR
+ 2):
1793 cirrus_hook_write_gr(s
, 0x2a, value
);
1795 case (CIRRUS_MMIO_BLTDESTADDR
+ 3):
1798 case (CIRRUS_MMIO_BLTSRCADDR
+ 0):
1799 cirrus_hook_write_gr(s
, 0x2c, value
);
1801 case (CIRRUS_MMIO_BLTSRCADDR
+ 1):
1802 cirrus_hook_write_gr(s
, 0x2d, value
);
1804 case (CIRRUS_MMIO_BLTSRCADDR
+ 2):
1805 cirrus_hook_write_gr(s
, 0x2e, value
);
1807 case CIRRUS_MMIO_BLTWRITEMASK
:
1808 cirrus_hook_write_gr(s
, 0x2f, value
);
1810 case CIRRUS_MMIO_BLTMODE
:
1811 cirrus_hook_write_gr(s
, 0x30, value
);
1813 case CIRRUS_MMIO_BLTROP
:
1814 cirrus_hook_write_gr(s
, 0x32, value
);
1816 case CIRRUS_MMIO_BLTMODEEXT
:
1817 cirrus_hook_write_gr(s
, 0x33, value
);
1819 case (CIRRUS_MMIO_BLTTRANSPARENTCOLOR
+ 0):
1820 cirrus_hook_write_gr(s
, 0x34, value
);
1822 case (CIRRUS_MMIO_BLTTRANSPARENTCOLOR
+ 1):
1823 cirrus_hook_write_gr(s
, 0x35, value
);
1825 case (CIRRUS_MMIO_BLTTRANSPARENTCOLORMASK
+ 0):
1826 cirrus_hook_write_gr(s
, 0x38, value
);
1828 case (CIRRUS_MMIO_BLTTRANSPARENTCOLORMASK
+ 1):
1829 cirrus_hook_write_gr(s
, 0x39, value
);
1831 case CIRRUS_MMIO_BLTSTATUS
:
1832 cirrus_hook_write_gr(s
, 0x31, value
);
1836 printf("cirrus: mmio write - addr 0x%04x val 0x%02x (ignored)\n",
1843 /***************************************
1847 * assume TARGET_PAGE_SIZE >= 16
1849 ***************************************/
1851 static void cirrus_mem_writeb_mode4and5_8bpp(CirrusVGAState
* s
,
1857 unsigned val
= mem_value
;
1860 dst
= s
->vram_ptr
+ offset
;
1861 for (x
= 0; x
< 8; x
++) {
1863 *dst
= s
->cirrus_shadow_gr1
;
1864 } else if (mode
== 5) {
1865 *dst
= s
->cirrus_shadow_gr0
;
1870 cpu_physical_memory_set_dirty(s
->vram_offset
+ offset
);
1871 cpu_physical_memory_set_dirty(s
->vram_offset
+ offset
+ 7);
1874 static void cirrus_mem_writeb_mode4and5_16bpp(CirrusVGAState
* s
,
1880 unsigned val
= mem_value
;
1883 dst
= s
->vram_ptr
+ offset
;
1884 for (x
= 0; x
< 8; x
++) {
1886 *dst
= s
->cirrus_shadow_gr1
;
1887 *(dst
+ 1) = s
->gr
[0x11];
1888 } else if (mode
== 5) {
1889 *dst
= s
->cirrus_shadow_gr0
;
1890 *(dst
+ 1) = s
->gr
[0x10];
1895 cpu_physical_memory_set_dirty(s
->vram_offset
+ offset
);
1896 cpu_physical_memory_set_dirty(s
->vram_offset
+ offset
+ 15);
1899 /***************************************
1901 * memory access between 0xa0000-0xbffff
1903 ***************************************/
1905 static uint32_t cirrus_vga_mem_readb(void *opaque
, target_phys_addr_t addr
)
1907 CirrusVGAState
*s
= opaque
;
1908 unsigned bank_index
;
1909 unsigned bank_offset
;
1912 if ((s
->sr
[0x07] & 0x01) == 0) {
1913 return vga_mem_readb(s
, addr
);
1918 if (addr
< 0x10000) {
1919 /* XXX handle bitblt */
1921 bank_index
= addr
>> 15;
1922 bank_offset
= addr
& 0x7fff;
1923 if (bank_offset
< s
->cirrus_bank_limit
[bank_index
]) {
1924 bank_offset
+= s
->cirrus_bank_base
[bank_index
];
1925 if ((s
->gr
[0x0B] & 0x14) == 0x14) {
1927 } else if (s
->gr
[0x0B] & 0x02) {
1930 bank_offset
&= s
->cirrus_addr_mask
;
1931 val
= *(s
->vram_ptr
+ bank_offset
);
1934 } else if (addr
>= 0x18000 && addr
< 0x18100) {
1935 /* memory-mapped I/O */
1937 if ((s
->sr
[0x17] & 0x44) == 0x04) {
1938 val
= cirrus_mmio_blt_read(s
, addr
& 0xff);
1943 printf("cirrus: mem_readb %06x\n", addr
);
1949 static uint32_t cirrus_vga_mem_readw(void *opaque
, target_phys_addr_t addr
)
1952 #ifdef TARGET_WORDS_BIGENDIAN
1953 v
= cirrus_vga_mem_readb(opaque
, addr
) << 8;
1954 v
|= cirrus_vga_mem_readb(opaque
, addr
+ 1);
1956 v
= cirrus_vga_mem_readb(opaque
, addr
);
1957 v
|= cirrus_vga_mem_readb(opaque
, addr
+ 1) << 8;
1962 static uint32_t cirrus_vga_mem_readl(void *opaque
, target_phys_addr_t addr
)
1965 #ifdef TARGET_WORDS_BIGENDIAN
1966 v
= cirrus_vga_mem_readb(opaque
, addr
) << 24;
1967 v
|= cirrus_vga_mem_readb(opaque
, addr
+ 1) << 16;
1968 v
|= cirrus_vga_mem_readb(opaque
, addr
+ 2) << 8;
1969 v
|= cirrus_vga_mem_readb(opaque
, addr
+ 3);
1971 v
= cirrus_vga_mem_readb(opaque
, addr
);
1972 v
|= cirrus_vga_mem_readb(opaque
, addr
+ 1) << 8;
1973 v
|= cirrus_vga_mem_readb(opaque
, addr
+ 2) << 16;
1974 v
|= cirrus_vga_mem_readb(opaque
, addr
+ 3) << 24;
1979 static void cirrus_vga_mem_writeb(void *opaque
, target_phys_addr_t addr
,
1982 CirrusVGAState
*s
= opaque
;
1983 unsigned bank_index
;
1984 unsigned bank_offset
;
1987 if ((s
->sr
[0x07] & 0x01) == 0) {
1988 vga_mem_writeb(s
, addr
, mem_value
);
1994 if (addr
< 0x10000) {
1995 if (s
->cirrus_srcptr
!= s
->cirrus_srcptr_end
) {
1997 *s
->cirrus_srcptr
++ = (uint8_t) mem_value
;
1998 if (s
->cirrus_srcptr
>= s
->cirrus_srcptr_end
) {
1999 cirrus_bitblt_cputovideo_next(s
);
2003 bank_index
= addr
>> 15;
2004 bank_offset
= addr
& 0x7fff;
2005 if (bank_offset
< s
->cirrus_bank_limit
[bank_index
]) {
2006 bank_offset
+= s
->cirrus_bank_base
[bank_index
];
2007 if ((s
->gr
[0x0B] & 0x14) == 0x14) {
2009 } else if (s
->gr
[0x0B] & 0x02) {
2012 bank_offset
&= s
->cirrus_addr_mask
;
2013 mode
= s
->gr
[0x05] & 0x7;
2014 if (mode
< 4 || mode
> 5 || ((s
->gr
[0x0B] & 0x4) == 0)) {
2015 *(s
->vram_ptr
+ bank_offset
) = mem_value
;
2016 cpu_physical_memory_set_dirty(s
->vram_offset
+
2019 if ((s
->gr
[0x0B] & 0x14) != 0x14) {
2020 cirrus_mem_writeb_mode4and5_8bpp(s
, mode
,
2024 cirrus_mem_writeb_mode4and5_16bpp(s
, mode
,
2031 } else if (addr
>= 0x18000 && addr
< 0x18100) {
2032 /* memory-mapped I/O */
2033 if ((s
->sr
[0x17] & 0x44) == 0x04) {
2034 cirrus_mmio_blt_write(s
, addr
& 0xff, mem_value
);
2038 printf("cirrus: mem_writeb %06x value %02x\n", addr
, mem_value
);
2043 static void cirrus_vga_mem_writew(void *opaque
, target_phys_addr_t addr
, uint32_t val
)
2045 #ifdef TARGET_WORDS_BIGENDIAN
2046 cirrus_vga_mem_writeb(opaque
, addr
, (val
>> 8) & 0xff);
2047 cirrus_vga_mem_writeb(opaque
, addr
+ 1, val
& 0xff);
2049 cirrus_vga_mem_writeb(opaque
, addr
, val
& 0xff);
2050 cirrus_vga_mem_writeb(opaque
, addr
+ 1, (val
>> 8) & 0xff);
2054 static void cirrus_vga_mem_writel(void *opaque
, target_phys_addr_t addr
, uint32_t val
)
2056 #ifdef TARGET_WORDS_BIGENDIAN
2057 cirrus_vga_mem_writeb(opaque
, addr
, (val
>> 24) & 0xff);
2058 cirrus_vga_mem_writeb(opaque
, addr
+ 1, (val
>> 16) & 0xff);
2059 cirrus_vga_mem_writeb(opaque
, addr
+ 2, (val
>> 8) & 0xff);
2060 cirrus_vga_mem_writeb(opaque
, addr
+ 3, val
& 0xff);
2062 cirrus_vga_mem_writeb(opaque
, addr
, val
& 0xff);
2063 cirrus_vga_mem_writeb(opaque
, addr
+ 1, (val
>> 8) & 0xff);
2064 cirrus_vga_mem_writeb(opaque
, addr
+ 2, (val
>> 16) & 0xff);
2065 cirrus_vga_mem_writeb(opaque
, addr
+ 3, (val
>> 24) & 0xff);
2069 static CPUReadMemoryFunc
*cirrus_vga_mem_read
[3] = {
2070 cirrus_vga_mem_readb
,
2071 cirrus_vga_mem_readw
,
2072 cirrus_vga_mem_readl
,
2075 static CPUWriteMemoryFunc
*cirrus_vga_mem_write
[3] = {
2076 cirrus_vga_mem_writeb
,
2077 cirrus_vga_mem_writew
,
2078 cirrus_vga_mem_writel
,
2081 /***************************************
2085 ***************************************/
2087 static inline void invalidate_cursor1(CirrusVGAState
*s
)
2089 if (s
->last_hw_cursor_size
) {
2090 vga_invalidate_scanlines((VGAState
*)s
,
2091 s
->last_hw_cursor_y
+ s
->last_hw_cursor_y_start
,
2092 s
->last_hw_cursor_y
+ s
->last_hw_cursor_y_end
);
2096 static inline void cirrus_cursor_compute_yrange(CirrusVGAState
*s
)
2100 int y
, y_min
, y_max
;
2102 src
= s
->vram_ptr
+ s
->real_vram_size
- 16 * 1024;
2103 if (s
->sr
[0x12] & CIRRUS_CURSOR_LARGE
) {
2104 src
+= (s
->sr
[0x13] & 0x3c) * 256;
2107 for(y
= 0; y
< 64; y
++) {
2108 content
= ((uint32_t *)src
)[0] |
2109 ((uint32_t *)src
)[1] |
2110 ((uint32_t *)src
)[2] |
2111 ((uint32_t *)src
)[3];
2121 src
+= (s
->sr
[0x13] & 0x3f) * 256;
2124 for(y
= 0; y
< 32; y
++) {
2125 content
= ((uint32_t *)src
)[0] |
2126 ((uint32_t *)(src
+ 128))[0];
2136 if (y_min
> y_max
) {
2137 s
->last_hw_cursor_y_start
= 0;
2138 s
->last_hw_cursor_y_end
= 0;
2140 s
->last_hw_cursor_y_start
= y_min
;
2141 s
->last_hw_cursor_y_end
= y_max
+ 1;
2145 /* NOTE: we do not currently handle the cursor bitmap change, so we
2146 update the cursor only if it moves. */
2147 static void cirrus_cursor_invalidate(VGAState
*s1
)
2149 CirrusVGAState
*s
= (CirrusVGAState
*)s1
;
2152 if (!s
->sr
[0x12] & CIRRUS_CURSOR_SHOW
) {
2155 if (s
->sr
[0x12] & CIRRUS_CURSOR_LARGE
)
2160 /* invalidate last cursor and new cursor if any change */
2161 if (s
->last_hw_cursor_size
!= size
||
2162 s
->last_hw_cursor_x
!= s
->hw_cursor_x
||
2163 s
->last_hw_cursor_y
!= s
->hw_cursor_y
) {
2165 invalidate_cursor1(s
);
2167 s
->last_hw_cursor_size
= size
;
2168 s
->last_hw_cursor_x
= s
->hw_cursor_x
;
2169 s
->last_hw_cursor_y
= s
->hw_cursor_y
;
2170 /* compute the real cursor min and max y */
2171 cirrus_cursor_compute_yrange(s
);
2172 invalidate_cursor1(s
);
2176 static void cirrus_cursor_draw_line(VGAState
*s1
, uint8_t *d1
, int scr_y
)
2178 CirrusVGAState
*s
= (CirrusVGAState
*)s1
;
2179 int w
, h
, bpp
, x1
, x2
, poffset
;
2180 unsigned int color0
, color1
;
2181 const uint8_t *palette
, *src
;
2184 if (!(s
->sr
[0x12] & CIRRUS_CURSOR_SHOW
))
2186 /* fast test to see if the cursor intersects with the scan line */
2187 if (s
->sr
[0x12] & CIRRUS_CURSOR_LARGE
) {
2192 if (scr_y
< s
->hw_cursor_y
||
2193 scr_y
>= (s
->hw_cursor_y
+ h
))
2196 src
= s
->vram_ptr
+ s
->real_vram_size
- 16 * 1024;
2197 if (s
->sr
[0x12] & CIRRUS_CURSOR_LARGE
) {
2198 src
+= (s
->sr
[0x13] & 0x3c) * 256;
2199 src
+= (scr_y
- s
->hw_cursor_y
) * 16;
2201 content
= ((uint32_t *)src
)[0] |
2202 ((uint32_t *)src
)[1] |
2203 ((uint32_t *)src
)[2] |
2204 ((uint32_t *)src
)[3];
2206 src
+= (s
->sr
[0x13] & 0x3f) * 256;
2207 src
+= (scr_y
- s
->hw_cursor_y
) * 4;
2209 content
= ((uint32_t *)src
)[0] |
2210 ((uint32_t *)(src
+ 128))[0];
2212 /* if nothing to draw, no need to continue */
2217 x1
= s
->hw_cursor_x
;
2218 if (x1
>= s
->last_scr_width
)
2220 x2
= s
->hw_cursor_x
+ w
;
2221 if (x2
> s
->last_scr_width
)
2222 x2
= s
->last_scr_width
;
2224 palette
= s
->cirrus_hidden_palette
;
2225 color0
= s
->rgb_to_pixel(c6_to_8(palette
[0x0 * 3]),
2226 c6_to_8(palette
[0x0 * 3 + 1]),
2227 c6_to_8(palette
[0x0 * 3 + 2]));
2228 color1
= s
->rgb_to_pixel(c6_to_8(palette
[0xf * 3]),
2229 c6_to_8(palette
[0xf * 3 + 1]),
2230 c6_to_8(palette
[0xf * 3 + 2]));
2231 bpp
= ((s
->ds
->depth
+ 7) >> 3);
2233 switch(s
->ds
->depth
) {
2237 vga_draw_cursor_line_8(d1
, src
, poffset
, w
, color0
, color1
, 0xff);
2240 vga_draw_cursor_line_16(d1
, src
, poffset
, w
, color0
, color1
, 0x7fff);
2243 vga_draw_cursor_line_16(d1
, src
, poffset
, w
, color0
, color1
, 0xffff);
2246 vga_draw_cursor_line_32(d1
, src
, poffset
, w
, color0
, color1
, 0xffffff);
2251 /***************************************
2255 ***************************************/
2257 static uint32_t cirrus_linear_readb(void *opaque
, target_phys_addr_t addr
)
2259 CirrusVGAState
*s
= (CirrusVGAState
*) opaque
;
2262 addr
&= s
->cirrus_addr_mask
;
2264 if (((s
->sr
[0x17] & 0x44) == 0x44) &&
2265 ((addr
& s
->linear_mmio_mask
) == s
->linear_mmio_mask
)) {
2266 /* memory-mapped I/O */
2267 ret
= cirrus_mmio_blt_read(s
, addr
& 0xff);
2269 /* XXX handle bitblt */
2273 if ((s
->gr
[0x0B] & 0x14) == 0x14) {
2275 } else if (s
->gr
[0x0B] & 0x02) {
2278 addr
&= s
->cirrus_addr_mask
;
2279 ret
= *(s
->vram_ptr
+ addr
);
2285 static uint32_t cirrus_linear_readw(void *opaque
, target_phys_addr_t addr
)
2288 #ifdef TARGET_WORDS_BIGENDIAN
2289 v
= cirrus_linear_readb(opaque
, addr
) << 8;
2290 v
|= cirrus_linear_readb(opaque
, addr
+ 1);
2292 v
= cirrus_linear_readb(opaque
, addr
);
2293 v
|= cirrus_linear_readb(opaque
, addr
+ 1) << 8;
2298 static uint32_t cirrus_linear_readl(void *opaque
, target_phys_addr_t addr
)
2301 #ifdef TARGET_WORDS_BIGENDIAN
2302 v
= cirrus_linear_readb(opaque
, addr
) << 24;
2303 v
|= cirrus_linear_readb(opaque
, addr
+ 1) << 16;
2304 v
|= cirrus_linear_readb(opaque
, addr
+ 2) << 8;
2305 v
|= cirrus_linear_readb(opaque
, addr
+ 3);
2307 v
= cirrus_linear_readb(opaque
, addr
);
2308 v
|= cirrus_linear_readb(opaque
, addr
+ 1) << 8;
2309 v
|= cirrus_linear_readb(opaque
, addr
+ 2) << 16;
2310 v
|= cirrus_linear_readb(opaque
, addr
+ 3) << 24;
2315 static void cirrus_linear_writeb(void *opaque
, target_phys_addr_t addr
,
2318 CirrusVGAState
*s
= (CirrusVGAState
*) opaque
;
2321 addr
&= s
->cirrus_addr_mask
;
2323 if (((s
->sr
[0x17] & 0x44) == 0x44) &&
2324 ((addr
& s
->linear_mmio_mask
) == s
->linear_mmio_mask
)) {
2325 /* memory-mapped I/O */
2326 cirrus_mmio_blt_write(s
, addr
& 0xff, val
);
2327 } else if (s
->cirrus_srcptr
!= s
->cirrus_srcptr_end
) {
2329 *s
->cirrus_srcptr
++ = (uint8_t) val
;
2330 if (s
->cirrus_srcptr
>= s
->cirrus_srcptr_end
) {
2331 cirrus_bitblt_cputovideo_next(s
);
2335 if ((s
->gr
[0x0B] & 0x14) == 0x14) {
2337 } else if (s
->gr
[0x0B] & 0x02) {
2340 addr
&= s
->cirrus_addr_mask
;
2342 mode
= s
->gr
[0x05] & 0x7;
2343 if (mode
< 4 || mode
> 5 || ((s
->gr
[0x0B] & 0x4) == 0)) {
2344 *(s
->vram_ptr
+ addr
) = (uint8_t) val
;
2345 cpu_physical_memory_set_dirty(s
->vram_offset
+ addr
);
2347 if ((s
->gr
[0x0B] & 0x14) != 0x14) {
2348 cirrus_mem_writeb_mode4and5_8bpp(s
, mode
, addr
, val
);
2350 cirrus_mem_writeb_mode4and5_16bpp(s
, mode
, addr
, val
);
2356 static void cirrus_linear_writew(void *opaque
, target_phys_addr_t addr
,
2359 #ifdef TARGET_WORDS_BIGENDIAN
2360 cirrus_linear_writeb(opaque
, addr
, (val
>> 8) & 0xff);
2361 cirrus_linear_writeb(opaque
, addr
+ 1, val
& 0xff);
2363 cirrus_linear_writeb(opaque
, addr
, val
& 0xff);
2364 cirrus_linear_writeb(opaque
, addr
+ 1, (val
>> 8) & 0xff);
2368 static void cirrus_linear_writel(void *opaque
, target_phys_addr_t addr
,
2371 #ifdef TARGET_WORDS_BIGENDIAN
2372 cirrus_linear_writeb(opaque
, addr
, (val
>> 24) & 0xff);
2373 cirrus_linear_writeb(opaque
, addr
+ 1, (val
>> 16) & 0xff);
2374 cirrus_linear_writeb(opaque
, addr
+ 2, (val
>> 8) & 0xff);
2375 cirrus_linear_writeb(opaque
, addr
+ 3, val
& 0xff);
2377 cirrus_linear_writeb(opaque
, addr
, val
& 0xff);
2378 cirrus_linear_writeb(opaque
, addr
+ 1, (val
>> 8) & 0xff);
2379 cirrus_linear_writeb(opaque
, addr
+ 2, (val
>> 16) & 0xff);
2380 cirrus_linear_writeb(opaque
, addr
+ 3, (val
>> 24) & 0xff);
2385 static CPUReadMemoryFunc
*cirrus_linear_read
[3] = {
2386 cirrus_linear_readb
,
2387 cirrus_linear_readw
,
2388 cirrus_linear_readl
,
2391 static CPUWriteMemoryFunc
*cirrus_linear_write
[3] = {
2392 cirrus_linear_writeb
,
2393 cirrus_linear_writew
,
2394 cirrus_linear_writel
,
2397 static void cirrus_linear_mem_writeb(void *opaque
, target_phys_addr_t addr
,
2400 CirrusVGAState
*s
= (CirrusVGAState
*) opaque
;
2402 addr
&= s
->cirrus_addr_mask
;
2403 *(s
->vram_ptr
+ addr
) = val
;
2404 cpu_physical_memory_set_dirty(s
->vram_offset
+ addr
);
2407 static void cirrus_linear_mem_writew(void *opaque
, target_phys_addr_t addr
,
2410 CirrusVGAState
*s
= (CirrusVGAState
*) opaque
;
2412 addr
&= s
->cirrus_addr_mask
;
2413 cpu_to_le16w((uint16_t *)(s
->vram_ptr
+ addr
), val
);
2414 cpu_physical_memory_set_dirty(s
->vram_offset
+ addr
);
2417 static void cirrus_linear_mem_writel(void *opaque
, target_phys_addr_t addr
,
2420 CirrusVGAState
*s
= (CirrusVGAState
*) opaque
;
2422 addr
&= s
->cirrus_addr_mask
;
2423 cpu_to_le32w((uint32_t *)(s
->vram_ptr
+ addr
), val
);
2424 cpu_physical_memory_set_dirty(s
->vram_offset
+ addr
);
2427 /***************************************
2429 * system to screen memory access
2431 ***************************************/
2434 static uint32_t cirrus_linear_bitblt_readb(void *opaque
, target_phys_addr_t addr
)
2438 /* XXX handle bitblt */
2443 static uint32_t cirrus_linear_bitblt_readw(void *opaque
, target_phys_addr_t addr
)
2446 #ifdef TARGET_WORDS_BIGENDIAN
2447 v
= cirrus_linear_bitblt_readb(opaque
, addr
) << 8;
2448 v
|= cirrus_linear_bitblt_readb(opaque
, addr
+ 1);
2450 v
= cirrus_linear_bitblt_readb(opaque
, addr
);
2451 v
|= cirrus_linear_bitblt_readb(opaque
, addr
+ 1) << 8;
2456 static uint32_t cirrus_linear_bitblt_readl(void *opaque
, target_phys_addr_t addr
)
2459 #ifdef TARGET_WORDS_BIGENDIAN
2460 v
= cirrus_linear_bitblt_readb(opaque
, addr
) << 24;
2461 v
|= cirrus_linear_bitblt_readb(opaque
, addr
+ 1) << 16;
2462 v
|= cirrus_linear_bitblt_readb(opaque
, addr
+ 2) << 8;
2463 v
|= cirrus_linear_bitblt_readb(opaque
, addr
+ 3);
2465 v
= cirrus_linear_bitblt_readb(opaque
, addr
);
2466 v
|= cirrus_linear_bitblt_readb(opaque
, addr
+ 1) << 8;
2467 v
|= cirrus_linear_bitblt_readb(opaque
, addr
+ 2) << 16;
2468 v
|= cirrus_linear_bitblt_readb(opaque
, addr
+ 3) << 24;
2473 static void cirrus_linear_bitblt_writeb(void *opaque
, target_phys_addr_t addr
,
2476 CirrusVGAState
*s
= (CirrusVGAState
*) opaque
;
2478 if (s
->cirrus_srcptr
!= s
->cirrus_srcptr_end
) {
2480 *s
->cirrus_srcptr
++ = (uint8_t) val
;
2481 if (s
->cirrus_srcptr
>= s
->cirrus_srcptr_end
) {
2482 cirrus_bitblt_cputovideo_next(s
);
2487 static void cirrus_linear_bitblt_writew(void *opaque
, target_phys_addr_t addr
,
2490 #ifdef TARGET_WORDS_BIGENDIAN
2491 cirrus_linear_bitblt_writeb(opaque
, addr
, (val
>> 8) & 0xff);
2492 cirrus_linear_bitblt_writeb(opaque
, addr
+ 1, val
& 0xff);
2494 cirrus_linear_bitblt_writeb(opaque
, addr
, val
& 0xff);
2495 cirrus_linear_bitblt_writeb(opaque
, addr
+ 1, (val
>> 8) & 0xff);
2499 static void cirrus_linear_bitblt_writel(void *opaque
, target_phys_addr_t addr
,
2502 #ifdef TARGET_WORDS_BIGENDIAN
2503 cirrus_linear_bitblt_writeb(opaque
, addr
, (val
>> 24) & 0xff);
2504 cirrus_linear_bitblt_writeb(opaque
, addr
+ 1, (val
>> 16) & 0xff);
2505 cirrus_linear_bitblt_writeb(opaque
, addr
+ 2, (val
>> 8) & 0xff);
2506 cirrus_linear_bitblt_writeb(opaque
, addr
+ 3, val
& 0xff);
2508 cirrus_linear_bitblt_writeb(opaque
, addr
, val
& 0xff);
2509 cirrus_linear_bitblt_writeb(opaque
, addr
+ 1, (val
>> 8) & 0xff);
2510 cirrus_linear_bitblt_writeb(opaque
, addr
+ 2, (val
>> 16) & 0xff);
2511 cirrus_linear_bitblt_writeb(opaque
, addr
+ 3, (val
>> 24) & 0xff);
2516 static CPUReadMemoryFunc
*cirrus_linear_bitblt_read
[3] = {
2517 cirrus_linear_bitblt_readb
,
2518 cirrus_linear_bitblt_readw
,
2519 cirrus_linear_bitblt_readl
,
2522 static CPUWriteMemoryFunc
*cirrus_linear_bitblt_write
[3] = {
2523 cirrus_linear_bitblt_writeb
,
2524 cirrus_linear_bitblt_writew
,
2525 cirrus_linear_bitblt_writel
,
2528 /* Compute the memory access functions */
2529 static void cirrus_update_memory_access(CirrusVGAState
*s
)
2533 if ((s
->sr
[0x17] & 0x44) == 0x44) {
2535 } else if (s
->cirrus_srcptr
!= s
->cirrus_srcptr_end
) {
2538 if ((s
->gr
[0x0B] & 0x14) == 0x14) {
2540 } else if (s
->gr
[0x0B] & 0x02) {
2544 mode
= s
->gr
[0x05] & 0x7;
2545 if (mode
< 4 || mode
> 5 || ((s
->gr
[0x0B] & 0x4) == 0)) {
2546 s
->cirrus_linear_write
[0] = cirrus_linear_mem_writeb
;
2547 s
->cirrus_linear_write
[1] = cirrus_linear_mem_writew
;
2548 s
->cirrus_linear_write
[2] = cirrus_linear_mem_writel
;
2551 s
->cirrus_linear_write
[0] = cirrus_linear_writeb
;
2552 s
->cirrus_linear_write
[1] = cirrus_linear_writew
;
2553 s
->cirrus_linear_write
[2] = cirrus_linear_writel
;
2561 static uint32_t vga_ioport_read(void *opaque
, uint32_t addr
)
2563 CirrusVGAState
*s
= opaque
;
2566 /* check port range access depending on color/monochrome mode */
2567 if ((addr
>= 0x3b0 && addr
<= 0x3bf && (s
->msr
& MSR_COLOR_EMULATION
))
2568 || (addr
>= 0x3d0 && addr
<= 0x3df
2569 && !(s
->msr
& MSR_COLOR_EMULATION
))) {
2574 if (s
->ar_flip_flop
== 0) {
2581 index
= s
->ar_index
& 0x1f;
2594 if (cirrus_hook_read_sr(s
, s
->sr_index
, &val
))
2596 val
= s
->sr
[s
->sr_index
];
2597 #ifdef DEBUG_VGA_REG
2598 printf("vga: read SR%x = 0x%02x\n", s
->sr_index
, val
);
2602 cirrus_read_hidden_dac(s
, &val
);
2608 val
= s
->dac_write_index
;
2609 s
->cirrus_hidden_dac_lockindex
= 0;
2612 if (cirrus_hook_read_palette(s
, &val
))
2614 val
= s
->palette
[s
->dac_read_index
* 3 + s
->dac_sub_index
];
2615 if (++s
->dac_sub_index
== 3) {
2616 s
->dac_sub_index
= 0;
2617 s
->dac_read_index
++;
2630 if (cirrus_hook_read_gr(s
, s
->gr_index
, &val
))
2632 val
= s
->gr
[s
->gr_index
];
2633 #ifdef DEBUG_VGA_REG
2634 printf("vga: read GR%x = 0x%02x\n", s
->gr_index
, val
);
2643 if (cirrus_hook_read_cr(s
, s
->cr_index
, &val
))
2645 val
= s
->cr
[s
->cr_index
];
2646 #ifdef DEBUG_VGA_REG
2647 printf("vga: read CR%x = 0x%02x\n", s
->cr_index
, val
);
2652 /* just toggle to fool polling */
2653 s
->st01
^= ST01_V_RETRACE
| ST01_DISP_ENABLE
;
2655 s
->ar_flip_flop
= 0;
2662 #if defined(DEBUG_VGA)
2663 printf("VGA: read addr=0x%04x data=0x%02x\n", addr
, val
);
2668 static void vga_ioport_write(void *opaque
, uint32_t addr
, uint32_t val
)
2670 CirrusVGAState
*s
= opaque
;
2673 /* check port range access depending on color/monochrome mode */
2674 if ((addr
>= 0x3b0 && addr
<= 0x3bf && (s
->msr
& MSR_COLOR_EMULATION
))
2675 || (addr
>= 0x3d0 && addr
<= 0x3df
2676 && !(s
->msr
& MSR_COLOR_EMULATION
)))
2680 printf("VGA: write addr=0x%04x data=0x%02x\n", addr
, val
);
2685 if (s
->ar_flip_flop
== 0) {
2689 index
= s
->ar_index
& 0x1f;
2692 s
->ar
[index
] = val
& 0x3f;
2695 s
->ar
[index
] = val
& ~0x10;
2701 s
->ar
[index
] = val
& ~0xc0;
2704 s
->ar
[index
] = val
& ~0xf0;
2707 s
->ar
[index
] = val
& ~0xf0;
2713 s
->ar_flip_flop
^= 1;
2716 s
->msr
= val
& ~0x10;
2722 if (cirrus_hook_write_sr(s
, s
->sr_index
, val
))
2724 #ifdef DEBUG_VGA_REG
2725 printf("vga: write SR%x = 0x%02x\n", s
->sr_index
, val
);
2727 s
->sr
[s
->sr_index
] = val
& sr_mask
[s
->sr_index
];
2730 cirrus_write_hidden_dac(s
, val
);
2733 s
->dac_read_index
= val
;
2734 s
->dac_sub_index
= 0;
2738 s
->dac_write_index
= val
;
2739 s
->dac_sub_index
= 0;
2743 if (cirrus_hook_write_palette(s
, val
))
2745 s
->dac_cache
[s
->dac_sub_index
] = val
;
2746 if (++s
->dac_sub_index
== 3) {
2747 memcpy(&s
->palette
[s
->dac_write_index
* 3], s
->dac_cache
, 3);
2748 s
->dac_sub_index
= 0;
2749 s
->dac_write_index
++;
2756 if (cirrus_hook_write_gr(s
, s
->gr_index
, val
))
2758 #ifdef DEBUG_VGA_REG
2759 printf("vga: write GR%x = 0x%02x\n", s
->gr_index
, val
);
2761 s
->gr
[s
->gr_index
] = val
& gr_mask
[s
->gr_index
];
2769 if (cirrus_hook_write_cr(s
, s
->cr_index
, val
))
2771 #ifdef DEBUG_VGA_REG
2772 printf("vga: write CR%x = 0x%02x\n", s
->cr_index
, val
);
2774 /* handle CR0-7 protection */
2775 if ((s
->cr
[0x11] & 0x80) && s
->cr_index
<= 7) {
2776 /* can always write bit 4 of CR7 */
2777 if (s
->cr_index
== 7)
2778 s
->cr
[7] = (s
->cr
[7] & ~0x10) | (val
& 0x10);
2781 switch (s
->cr_index
) {
2782 case 0x01: /* horizontal display end */
2787 case 0x12: /* veritcal display end */
2788 s
->cr
[s
->cr_index
] = val
;
2792 s
->cr
[s
->cr_index
] = val
;
2798 s
->fcr
= val
& 0x10;
2803 /***************************************
2805 * memory-mapped I/O access
2807 ***************************************/
2809 static uint32_t cirrus_mmio_readb(void *opaque
, target_phys_addr_t addr
)
2811 CirrusVGAState
*s
= (CirrusVGAState
*) opaque
;
2813 addr
&= CIRRUS_PNPMMIO_SIZE
- 1;
2815 if (addr
>= 0x100) {
2816 return cirrus_mmio_blt_read(s
, addr
- 0x100);
2818 return vga_ioport_read(s
, addr
+ 0x3c0);
2822 static uint32_t cirrus_mmio_readw(void *opaque
, target_phys_addr_t addr
)
2825 #ifdef TARGET_WORDS_BIGENDIAN
2826 v
= cirrus_mmio_readb(opaque
, addr
) << 8;
2827 v
|= cirrus_mmio_readb(opaque
, addr
+ 1);
2829 v
= cirrus_mmio_readb(opaque
, addr
);
2830 v
|= cirrus_mmio_readb(opaque
, addr
+ 1) << 8;
2835 static uint32_t cirrus_mmio_readl(void *opaque
, target_phys_addr_t addr
)
2838 #ifdef TARGET_WORDS_BIGENDIAN
2839 v
= cirrus_mmio_readb(opaque
, addr
) << 24;
2840 v
|= cirrus_mmio_readb(opaque
, addr
+ 1) << 16;
2841 v
|= cirrus_mmio_readb(opaque
, addr
+ 2) << 8;
2842 v
|= cirrus_mmio_readb(opaque
, addr
+ 3);
2844 v
= cirrus_mmio_readb(opaque
, addr
);
2845 v
|= cirrus_mmio_readb(opaque
, addr
+ 1) << 8;
2846 v
|= cirrus_mmio_readb(opaque
, addr
+ 2) << 16;
2847 v
|= cirrus_mmio_readb(opaque
, addr
+ 3) << 24;
2852 static void cirrus_mmio_writeb(void *opaque
, target_phys_addr_t addr
,
2855 CirrusVGAState
*s
= (CirrusVGAState
*) opaque
;
2857 addr
&= CIRRUS_PNPMMIO_SIZE
- 1;
2859 if (addr
>= 0x100) {
2860 cirrus_mmio_blt_write(s
, addr
- 0x100, val
);
2862 vga_ioport_write(s
, addr
+ 0x3c0, val
);
2866 static void cirrus_mmio_writew(void *opaque
, target_phys_addr_t addr
,
2869 #ifdef TARGET_WORDS_BIGENDIAN
2870 cirrus_mmio_writeb(opaque
, addr
, (val
>> 8) & 0xff);
2871 cirrus_mmio_writeb(opaque
, addr
+ 1, val
& 0xff);
2873 cirrus_mmio_writeb(opaque
, addr
, val
& 0xff);
2874 cirrus_mmio_writeb(opaque
, addr
+ 1, (val
>> 8) & 0xff);
2878 static void cirrus_mmio_writel(void *opaque
, target_phys_addr_t addr
,
2881 #ifdef TARGET_WORDS_BIGENDIAN
2882 cirrus_mmio_writeb(opaque
, addr
, (val
>> 24) & 0xff);
2883 cirrus_mmio_writeb(opaque
, addr
+ 1, (val
>> 16) & 0xff);
2884 cirrus_mmio_writeb(opaque
, addr
+ 2, (val
>> 8) & 0xff);
2885 cirrus_mmio_writeb(opaque
, addr
+ 3, val
& 0xff);
2887 cirrus_mmio_writeb(opaque
, addr
, val
& 0xff);
2888 cirrus_mmio_writeb(opaque
, addr
+ 1, (val
>> 8) & 0xff);
2889 cirrus_mmio_writeb(opaque
, addr
+ 2, (val
>> 16) & 0xff);
2890 cirrus_mmio_writeb(opaque
, addr
+ 3, (val
>> 24) & 0xff);
2895 static CPUReadMemoryFunc
*cirrus_mmio_read
[3] = {
2901 static CPUWriteMemoryFunc
*cirrus_mmio_write
[3] = {
2907 /* load/save state */
2909 static void cirrus_vga_save(QEMUFile
*f
, void *opaque
)
2911 CirrusVGAState
*s
= opaque
;
2914 pci_device_save(s
->pci_dev
, f
);
2916 qemu_put_be32s(f
, &s
->latch
);
2917 qemu_put_8s(f
, &s
->sr_index
);
2918 qemu_put_buffer(f
, s
->sr
, 256);
2919 qemu_put_8s(f
, &s
->gr_index
);
2920 qemu_put_8s(f
, &s
->cirrus_shadow_gr0
);
2921 qemu_put_8s(f
, &s
->cirrus_shadow_gr1
);
2922 qemu_put_buffer(f
, s
->gr
+ 2, 254);
2923 qemu_put_8s(f
, &s
->ar_index
);
2924 qemu_put_buffer(f
, s
->ar
, 21);
2925 qemu_put_be32s(f
, &s
->ar_flip_flop
);
2926 qemu_put_8s(f
, &s
->cr_index
);
2927 qemu_put_buffer(f
, s
->cr
, 256);
2928 qemu_put_8s(f
, &s
->msr
);
2929 qemu_put_8s(f
, &s
->fcr
);
2930 qemu_put_8s(f
, &s
->st00
);
2931 qemu_put_8s(f
, &s
->st01
);
2933 qemu_put_8s(f
, &s
->dac_state
);
2934 qemu_put_8s(f
, &s
->dac_sub_index
);
2935 qemu_put_8s(f
, &s
->dac_read_index
);
2936 qemu_put_8s(f
, &s
->dac_write_index
);
2937 qemu_put_buffer(f
, s
->dac_cache
, 3);
2938 qemu_put_buffer(f
, s
->palette
, 768);
2940 qemu_put_be32s(f
, &s
->bank_offset
);
2942 qemu_put_8s(f
, &s
->cirrus_hidden_dac_lockindex
);
2943 qemu_put_8s(f
, &s
->cirrus_hidden_dac_data
);
2945 qemu_put_be32s(f
, &s
->hw_cursor_x
);
2946 qemu_put_be32s(f
, &s
->hw_cursor_y
);
2947 /* XXX: we do not save the bitblt state - we assume we do not save
2948 the state when the blitter is active */
2951 static int cirrus_vga_load(QEMUFile
*f
, void *opaque
, int version_id
)
2953 CirrusVGAState
*s
= opaque
;
2959 if (s
->pci_dev
&& version_id
>= 2) {
2960 ret
= pci_device_load(s
->pci_dev
, f
);
2965 qemu_get_be32s(f
, &s
->latch
);
2966 qemu_get_8s(f
, &s
->sr_index
);
2967 qemu_get_buffer(f
, s
->sr
, 256);
2968 qemu_get_8s(f
, &s
->gr_index
);
2969 qemu_get_8s(f
, &s
->cirrus_shadow_gr0
);
2970 qemu_get_8s(f
, &s
->cirrus_shadow_gr1
);
2971 s
->gr
[0x00] = s
->cirrus_shadow_gr0
& 0x0f;
2972 s
->gr
[0x01] = s
->cirrus_shadow_gr1
& 0x0f;
2973 qemu_get_buffer(f
, s
->gr
+ 2, 254);
2974 qemu_get_8s(f
, &s
->ar_index
);
2975 qemu_get_buffer(f
, s
->ar
, 21);
2976 qemu_get_be32s(f
, &s
->ar_flip_flop
);
2977 qemu_get_8s(f
, &s
->cr_index
);
2978 qemu_get_buffer(f
, s
->cr
, 256);
2979 qemu_get_8s(f
, &s
->msr
);
2980 qemu_get_8s(f
, &s
->fcr
);
2981 qemu_get_8s(f
, &s
->st00
);
2982 qemu_get_8s(f
, &s
->st01
);
2984 qemu_get_8s(f
, &s
->dac_state
);
2985 qemu_get_8s(f
, &s
->dac_sub_index
);
2986 qemu_get_8s(f
, &s
->dac_read_index
);
2987 qemu_get_8s(f
, &s
->dac_write_index
);
2988 qemu_get_buffer(f
, s
->dac_cache
, 3);
2989 qemu_get_buffer(f
, s
->palette
, 768);
2991 qemu_get_be32s(f
, &s
->bank_offset
);
2993 qemu_get_8s(f
, &s
->cirrus_hidden_dac_lockindex
);
2994 qemu_get_8s(f
, &s
->cirrus_hidden_dac_data
);
2996 qemu_get_be32s(f
, &s
->hw_cursor_x
);
2997 qemu_get_be32s(f
, &s
->hw_cursor_y
);
3000 s
->graphic_mode
= -1;
3001 cirrus_update_bank_ptr(s
, 0);
3002 cirrus_update_bank_ptr(s
, 1);
3006 /***************************************
3010 ***************************************/
3012 static void cirrus_init_common(CirrusVGAState
* s
, int device_id
, int is_pci
)
3014 int vga_io_memory
, i
;
3019 for(i
= 0;i
< 256; i
++)
3020 rop_to_index
[i
] = CIRRUS_ROP_NOP_INDEX
; /* nop rop */
3021 rop_to_index
[CIRRUS_ROP_0
] = 0;
3022 rop_to_index
[CIRRUS_ROP_SRC_AND_DST
] = 1;
3023 rop_to_index
[CIRRUS_ROP_NOP
] = 2;
3024 rop_to_index
[CIRRUS_ROP_SRC_AND_NOTDST
] = 3;
3025 rop_to_index
[CIRRUS_ROP_NOTDST
] = 4;
3026 rop_to_index
[CIRRUS_ROP_SRC
] = 5;
3027 rop_to_index
[CIRRUS_ROP_1
] = 6;
3028 rop_to_index
[CIRRUS_ROP_NOTSRC_AND_DST
] = 7;
3029 rop_to_index
[CIRRUS_ROP_SRC_XOR_DST
] = 8;
3030 rop_to_index
[CIRRUS_ROP_SRC_OR_DST
] = 9;
3031 rop_to_index
[CIRRUS_ROP_NOTSRC_OR_NOTDST
] = 10;
3032 rop_to_index
[CIRRUS_ROP_SRC_NOTXOR_DST
] = 11;
3033 rop_to_index
[CIRRUS_ROP_SRC_OR_NOTDST
] = 12;
3034 rop_to_index
[CIRRUS_ROP_NOTSRC
] = 13;
3035 rop_to_index
[CIRRUS_ROP_NOTSRC_OR_DST
] = 14;
3036 rop_to_index
[CIRRUS_ROP_NOTSRC_AND_NOTDST
] = 15;
3039 register_ioport_write(0x3c0, 16, 1, vga_ioport_write
, s
);
3041 register_ioport_write(0x3b4, 2, 1, vga_ioport_write
, s
);
3042 register_ioport_write(0x3d4, 2, 1, vga_ioport_write
, s
);
3043 register_ioport_write(0x3ba, 1, 1, vga_ioport_write
, s
);
3044 register_ioport_write(0x3da, 1, 1, vga_ioport_write
, s
);
3046 register_ioport_read(0x3c0, 16, 1, vga_ioport_read
, s
);
3048 register_ioport_read(0x3b4, 2, 1, vga_ioport_read
, s
);
3049 register_ioport_read(0x3d4, 2, 1, vga_ioport_read
, s
);
3050 register_ioport_read(0x3ba, 1, 1, vga_ioport_read
, s
);
3051 register_ioport_read(0x3da, 1, 1, vga_ioport_read
, s
);
3053 vga_io_memory
= cpu_register_io_memory(0, cirrus_vga_mem_read
,
3054 cirrus_vga_mem_write
, s
);
3055 cpu_register_physical_memory(isa_mem_base
+ 0x000a0000, 0x20000,
3059 if (device_id
== CIRRUS_ID_CLGD5446
) {
3060 /* 4MB 64 bit memory config, always PCI */
3061 s
->sr
[0x1F] = 0x2d; // MemClock
3062 s
->gr
[0x18] = 0x0f; // fastest memory configuration
3066 s
->sr
[0x15] = 0x04; /* memory size, 3=2MB, 4=4MB */
3067 s
->real_vram_size
= 4096 * 1024;
3071 s
->sr
[0x15] = 0x03; /* memory size, 3=2MB, 4=4MB */
3072 s
->real_vram_size
= 2048 * 1024;
3075 s
->sr
[0x1F] = 0x22; // MemClock
3076 s
->sr
[0x0F] = CIRRUS_MEMSIZE_2M
;
3078 s
->sr
[0x17] = CIRRUS_BUSTYPE_PCI
;
3080 s
->sr
[0x17] = CIRRUS_BUSTYPE_ISA
;
3081 s
->real_vram_size
= 2048 * 1024;
3082 s
->sr
[0x15] = 0x03; /* memory size, 3=2MB, 4=4MB */
3084 s
->cr
[0x27] = device_id
;
3086 /* Win2K seems to assume that the pattern buffer is at 0xff
3088 memset(s
->vram_ptr
, 0xff, s
->real_vram_size
);
3090 s
->cirrus_hidden_dac_lockindex
= 5;
3091 s
->cirrus_hidden_dac_data
= 0;
3093 /* I/O handler for LFB */
3094 s
->cirrus_linear_io_addr
=
3095 cpu_register_io_memory(0, cirrus_linear_read
, cirrus_linear_write
,
3097 s
->cirrus_linear_write
= cpu_get_io_memory_write(s
->cirrus_linear_io_addr
);
3099 /* I/O handler for LFB */
3100 s
->cirrus_linear_bitblt_io_addr
=
3101 cpu_register_io_memory(0, cirrus_linear_bitblt_read
, cirrus_linear_bitblt_write
,
3104 /* I/O handler for memory-mapped I/O */
3105 s
->cirrus_mmio_io_addr
=
3106 cpu_register_io_memory(0, cirrus_mmio_read
, cirrus_mmio_write
, s
);
3108 /* XXX: s->vram_size must be a power of two */
3109 s
->cirrus_addr_mask
= s
->real_vram_size
- 1;
3110 s
->linear_mmio_mask
= s
->real_vram_size
- 256;
3112 s
->get_bpp
= cirrus_get_bpp
;
3113 s
->get_offsets
= cirrus_get_offsets
;
3114 s
->get_resolution
= cirrus_get_resolution
;
3115 s
->cursor_invalidate
= cirrus_cursor_invalidate
;
3116 s
->cursor_draw_line
= cirrus_cursor_draw_line
;
3118 register_savevm("cirrus_vga", 0, 2, cirrus_vga_save
, cirrus_vga_load
, s
);
3121 /***************************************
3125 ***************************************/
3127 void isa_cirrus_vga_init(DisplayState
*ds
, uint8_t *vga_ram_base
,
3128 unsigned long vga_ram_offset
, int vga_ram_size
)
3132 s
= qemu_mallocz(sizeof(CirrusVGAState
));
3134 vga_common_init((VGAState
*)s
,
3135 ds
, vga_ram_base
, vga_ram_offset
, vga_ram_size
);
3136 cirrus_init_common(s
, CIRRUS_ID_CLGD5430
, 0);
3137 /* XXX ISA-LFB support */
3140 /***************************************
3144 ***************************************/
3146 static void cirrus_pci_lfb_map(PCIDevice
*d
, int region_num
,
3147 uint32_t addr
, uint32_t size
, int type
)
3149 CirrusVGAState
*s
= &((PCICirrusVGAState
*)d
)->cirrus_vga
;
3151 /* XXX: add byte swapping apertures */
3152 cpu_register_physical_memory(addr
, s
->vram_size
,
3153 s
->cirrus_linear_io_addr
);
3154 cpu_register_physical_memory(addr
+ 0x1000000, 0x400000,
3155 s
->cirrus_linear_bitblt_io_addr
);
3158 static void cirrus_pci_mmio_map(PCIDevice
*d
, int region_num
,
3159 uint32_t addr
, uint32_t size
, int type
)
3161 CirrusVGAState
*s
= &((PCICirrusVGAState
*)d
)->cirrus_vga
;
3163 cpu_register_physical_memory(addr
, CIRRUS_PNPMMIO_SIZE
,
3164 s
->cirrus_mmio_io_addr
);
3167 void pci_cirrus_vga_init(PCIBus
*bus
, DisplayState
*ds
, uint8_t *vga_ram_base
,
3168 unsigned long vga_ram_offset
, int vga_ram_size
)
3170 PCICirrusVGAState
*d
;
3175 device_id
= CIRRUS_ID_CLGD5446
;
3177 /* setup PCI configuration registers */
3178 d
= (PCICirrusVGAState
*)pci_register_device(bus
, "Cirrus VGA",
3179 sizeof(PCICirrusVGAState
),
3181 pci_conf
= d
->dev
.config
;
3182 pci_conf
[0x00] = (uint8_t) (PCI_VENDOR_CIRRUS
& 0xff);
3183 pci_conf
[0x01] = (uint8_t) (PCI_VENDOR_CIRRUS
>> 8);
3184 pci_conf
[0x02] = (uint8_t) (device_id
& 0xff);
3185 pci_conf
[0x03] = (uint8_t) (device_id
>> 8);
3186 pci_conf
[0x04] = PCI_COMMAND_IOACCESS
| PCI_COMMAND_MEMACCESS
;
3187 pci_conf
[0x0a] = PCI_CLASS_SUB_VGA
;
3188 pci_conf
[0x0b] = PCI_CLASS_BASE_DISPLAY
;
3189 pci_conf
[0x0e] = PCI_CLASS_HEADERTYPE_00h
;
3193 vga_common_init((VGAState
*)s
,
3194 ds
, vga_ram_base
, vga_ram_offset
, vga_ram_size
);
3195 cirrus_init_common(s
, device_id
, 1);
3196 s
->pci_dev
= (PCIDevice
*)d
;
3198 /* setup memory space */
3200 /* memory #1 memory-mapped I/O */
3201 /* XXX: s->vram_size must be a power of two */
3202 pci_register_io_region((PCIDevice
*)d
, 0, 0x2000000,
3203 PCI_ADDRESS_SPACE_MEM_PREFETCH
, cirrus_pci_lfb_map
);
3204 if (device_id
== CIRRUS_ID_CLGD5446
) {
3205 pci_register_io_region((PCIDevice
*)d
, 1, CIRRUS_PNPMMIO_SIZE
,
3206 PCI_ADDRESS_SPACE_MEM
, cirrus_pci_mmio_map
);