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/
37 * - destination write mask support not complete (bits 5..7)
38 * - optimize linear mappings
39 * - optimize bitblt functions
42 //#define DEBUG_CIRRUS
43 //#define DEBUG_BITBLT
45 /***************************************
49 ***************************************/
51 #define qemu_MIN(a,b) ((a) < (b) ? (a) : (b))
54 #define CIRRUS_ID_CLGD5422 (0x23<<2)
55 #define CIRRUS_ID_CLGD5426 (0x24<<2)
56 #define CIRRUS_ID_CLGD5424 (0x25<<2)
57 #define CIRRUS_ID_CLGD5428 (0x26<<2)
58 #define CIRRUS_ID_CLGD5430 (0x28<<2)
59 #define CIRRUS_ID_CLGD5434 (0x2A<<2)
60 #define CIRRUS_ID_CLGD5436 (0x2B<<2)
61 #define CIRRUS_ID_CLGD5446 (0x2E<<2)
64 #define CIRRUS_SR7_BPP_VGA 0x00
65 #define CIRRUS_SR7_BPP_SVGA 0x01
66 #define CIRRUS_SR7_BPP_MASK 0x0e
67 #define CIRRUS_SR7_BPP_8 0x00
68 #define CIRRUS_SR7_BPP_16_DOUBLEVCLK 0x02
69 #define CIRRUS_SR7_BPP_24 0x04
70 #define CIRRUS_SR7_BPP_16 0x06
71 #define CIRRUS_SR7_BPP_32 0x08
72 #define CIRRUS_SR7_ISAADDR_MASK 0xe0
75 #define CIRRUS_MEMSIZE_512k 0x08
76 #define CIRRUS_MEMSIZE_1M 0x10
77 #define CIRRUS_MEMSIZE_2M 0x18
78 #define CIRRUS_MEMFLAGS_BANKSWITCH 0x80 // bank switching is enabled.
81 #define CIRRUS_CURSOR_SHOW 0x01
82 #define CIRRUS_CURSOR_HIDDENPEL 0x02
83 #define CIRRUS_CURSOR_LARGE 0x04 // 64x64 if set, 32x32 if clear
86 #define CIRRUS_BUSTYPE_VLBFAST 0x10
87 #define CIRRUS_BUSTYPE_PCI 0x20
88 #define CIRRUS_BUSTYPE_VLBSLOW 0x30
89 #define CIRRUS_BUSTYPE_ISA 0x38
90 #define CIRRUS_MMIO_ENABLE 0x04
91 #define CIRRUS_MMIO_USE_PCIADDR 0x40 // 0xb8000 if cleared.
92 #define CIRRUS_MEMSIZEEXT_DOUBLE 0x80
95 #define CIRRUS_BANKING_DUAL 0x01
96 #define CIRRUS_BANKING_GRANULARITY_16K 0x20 // set:16k, clear:4k
99 #define CIRRUS_BLTMODE_BACKWARDS 0x01
100 #define CIRRUS_BLTMODE_MEMSYSDEST 0x02
101 #define CIRRUS_BLTMODE_MEMSYSSRC 0x04
102 #define CIRRUS_BLTMODE_TRANSPARENTCOMP 0x08
103 #define CIRRUS_BLTMODE_PATTERNCOPY 0x40
104 #define CIRRUS_BLTMODE_COLOREXPAND 0x80
105 #define CIRRUS_BLTMODE_PIXELWIDTHMASK 0x30
106 #define CIRRUS_BLTMODE_PIXELWIDTH8 0x00
107 #define CIRRUS_BLTMODE_PIXELWIDTH16 0x10
108 #define CIRRUS_BLTMODE_PIXELWIDTH24 0x20
109 #define CIRRUS_BLTMODE_PIXELWIDTH32 0x30
112 #define CIRRUS_BLT_BUSY 0x01
113 #define CIRRUS_BLT_START 0x02
114 #define CIRRUS_BLT_RESET 0x04
115 #define CIRRUS_BLT_FIFOUSED 0x10
116 #define CIRRUS_BLT_AUTOSTART 0x80
119 #define CIRRUS_ROP_0 0x00
120 #define CIRRUS_ROP_SRC_AND_DST 0x05
121 #define CIRRUS_ROP_NOP 0x06
122 #define CIRRUS_ROP_SRC_AND_NOTDST 0x09
123 #define CIRRUS_ROP_NOTDST 0x0b
124 #define CIRRUS_ROP_SRC 0x0d
125 #define CIRRUS_ROP_1 0x0e
126 #define CIRRUS_ROP_NOTSRC_AND_DST 0x50
127 #define CIRRUS_ROP_SRC_XOR_DST 0x59
128 #define CIRRUS_ROP_SRC_OR_DST 0x6d
129 #define CIRRUS_ROP_NOTSRC_OR_NOTDST 0x90
130 #define CIRRUS_ROP_SRC_NOTXOR_DST 0x95
131 #define CIRRUS_ROP_SRC_OR_NOTDST 0xad
132 #define CIRRUS_ROP_NOTSRC 0xd0
133 #define CIRRUS_ROP_NOTSRC_OR_DST 0xd6
134 #define CIRRUS_ROP_NOTSRC_AND_NOTDST 0xda
136 #define CIRRUS_ROP_NOP_INDEX 2
137 #define CIRRUS_ROP_SRC_INDEX 5
140 #define CIRRUS_BLTMODEEXT_SOLIDFILL 0x04
141 #define CIRRUS_BLTMODEEXT_COLOREXPINV 0x02
142 #define CIRRUS_BLTMODEEXT_DWORDGRANULARITY 0x01
145 #define CIRRUS_MMIO_BLTBGCOLOR 0x00 // dword
146 #define CIRRUS_MMIO_BLTFGCOLOR 0x04 // dword
147 #define CIRRUS_MMIO_BLTWIDTH 0x08 // word
148 #define CIRRUS_MMIO_BLTHEIGHT 0x0a // word
149 #define CIRRUS_MMIO_BLTDESTPITCH 0x0c // word
150 #define CIRRUS_MMIO_BLTSRCPITCH 0x0e // word
151 #define CIRRUS_MMIO_BLTDESTADDR 0x10 // dword
152 #define CIRRUS_MMIO_BLTSRCADDR 0x14 // dword
153 #define CIRRUS_MMIO_BLTWRITEMASK 0x17 // byte
154 #define CIRRUS_MMIO_BLTMODE 0x18 // byte
155 #define CIRRUS_MMIO_BLTROP 0x1a // byte
156 #define CIRRUS_MMIO_BLTMODEEXT 0x1b // byte
157 #define CIRRUS_MMIO_BLTTRANSPARENTCOLOR 0x1c // word?
158 #define CIRRUS_MMIO_BLTTRANSPARENTCOLORMASK 0x20 // word?
159 #define CIRRUS_MMIO_LINEARDRAW_START_X 0x24 // word
160 #define CIRRUS_MMIO_LINEARDRAW_START_Y 0x26 // word
161 #define CIRRUS_MMIO_LINEARDRAW_END_X 0x28 // word
162 #define CIRRUS_MMIO_LINEARDRAW_END_Y 0x2a // word
163 #define CIRRUS_MMIO_LINEARDRAW_LINESTYLE_INC 0x2c // byte
164 #define CIRRUS_MMIO_LINEARDRAW_LINESTYLE_ROLLOVER 0x2d // byte
165 #define CIRRUS_MMIO_LINEARDRAW_LINESTYLE_MASK 0x2e // byte
166 #define CIRRUS_MMIO_LINEARDRAW_LINESTYLE_ACCUM 0x2f // byte
167 #define CIRRUS_MMIO_BRESENHAM_K1 0x30 // word
168 #define CIRRUS_MMIO_BRESENHAM_K3 0x32 // word
169 #define CIRRUS_MMIO_BRESENHAM_ERROR 0x34 // word
170 #define CIRRUS_MMIO_BRESENHAM_DELTA_MAJOR 0x36 // word
171 #define CIRRUS_MMIO_BRESENHAM_DIRECTION 0x38 // byte
172 #define CIRRUS_MMIO_LINEDRAW_MODE 0x39 // byte
173 #define CIRRUS_MMIO_BLTSTATUS 0x40 // byte
175 // PCI 0x00: vendor, 0x02: device
176 #define PCI_VENDOR_CIRRUS 0x1013
177 #define PCI_DEVICE_CLGD5462 0x00d0
178 #define PCI_DEVICE_CLGD5465 0x00d6
180 // PCI 0x04: command(word), 0x06(word): status
181 #define PCI_COMMAND_IOACCESS 0x0001
182 #define PCI_COMMAND_MEMACCESS 0x0002
183 #define PCI_COMMAND_BUSMASTER 0x0004
184 #define PCI_COMMAND_SPECIALCYCLE 0x0008
185 #define PCI_COMMAND_MEMWRITEINVALID 0x0010
186 #define PCI_COMMAND_PALETTESNOOPING 0x0020
187 #define PCI_COMMAND_PARITYDETECTION 0x0040
188 #define PCI_COMMAND_ADDRESSDATASTEPPING 0x0080
189 #define PCI_COMMAND_SERR 0x0100
190 #define PCI_COMMAND_BACKTOBACKTRANS 0x0200
191 // PCI 0x08, 0xff000000 (0x09-0x0b:class,0x08:rev)
192 #define PCI_CLASS_BASE_DISPLAY 0x03
193 // PCI 0x08, 0x00ff0000
194 #define PCI_CLASS_SUB_VGA 0x00
195 // PCI 0x0c, 0x00ff0000 (0x0c:cacheline,0x0d:latency,0x0e:headertype,0x0f:Built-in self test)
196 #define PCI_CLASS_HEADERTYPE_00h 0x00
197 // 0x10-0x3f (headertype 00h)
198 // PCI 0x10,0x14,0x18,0x1c,0x20,0x24: base address mapping registers
199 // 0x10: MEMBASE, 0x14: IOBASE(hard-coded in XFree86 3.x)
200 #define PCI_MAP_MEM 0x0
201 #define PCI_MAP_IO 0x1
202 #define PCI_MAP_MEM_ADDR_MASK (~0xf)
203 #define PCI_MAP_IO_ADDR_MASK (~0x3)
204 #define PCI_MAP_MEMFLAGS_32BIT 0x0
205 #define PCI_MAP_MEMFLAGS_32BIT_1M 0x1
206 #define PCI_MAP_MEMFLAGS_64BIT 0x4
207 #define PCI_MAP_MEMFLAGS_CACHEABLE 0x8
208 // PCI 0x28: cardbus CIS pointer
209 // PCI 0x2c: subsystem vendor id, 0x2e: subsystem id
210 // PCI 0x30: expansion ROM base address
211 #define PCI_ROMBIOS_ENABLED 0x1
212 // PCI 0x34: 0xffffff00=reserved, 0x000000ff=capabilities pointer
213 // PCI 0x38: reserved
214 // PCI 0x3c: 0x3c=int-line, 0x3d=int-pin, 0x3e=min-gnt, 0x3f=maax-lat
216 #define CIRRUS_PNPMMIO_SIZE 0x1000
219 /* I/O and memory hook */
220 #define CIRRUS_HOOK_NOT_HANDLED 0
221 #define CIRRUS_HOOK_HANDLED 1
223 #define BLTUNSAFE(s) \
225 ( /* check dst is within bounds */ \
226 (s)->cirrus_blt_height * (s)->cirrus_blt_dstpitch \
227 + ((s)->cirrus_blt_dstaddr & (s)->cirrus_addr_mask) > \
230 ( /* check src is within bounds */ \
231 (s)->cirrus_blt_height * (s)->cirrus_blt_srcpitch \
232 + ((s)->cirrus_blt_srcaddr & (s)->cirrus_addr_mask) > \
237 struct CirrusVGAState
;
238 typedef void (*cirrus_bitblt_rop_t
) (struct CirrusVGAState
*s
,
239 uint8_t * dst
, const uint8_t * src
,
240 int dstpitch
, int srcpitch
,
241 int bltwidth
, int bltheight
);
242 typedef void (*cirrus_fill_t
)(struct CirrusVGAState
*s
,
243 uint8_t *dst
, int dst_pitch
, int width
, int height
);
245 typedef struct CirrusVGAState
{
248 int cirrus_linear_io_addr
;
249 int cirrus_linear_bitblt_io_addr
;
250 int cirrus_mmio_io_addr
;
251 uint32_t cirrus_addr_mask
;
252 uint32_t linear_mmio_mask
;
253 uint8_t cirrus_shadow_gr0
;
254 uint8_t cirrus_shadow_gr1
;
255 uint8_t cirrus_hidden_dac_lockindex
;
256 uint8_t cirrus_hidden_dac_data
;
257 uint32_t cirrus_bank_base
[2];
258 uint32_t cirrus_bank_limit
[2];
259 uint8_t cirrus_hidden_palette
[48];
260 uint32_t hw_cursor_x
;
261 uint32_t hw_cursor_y
;
262 int cirrus_blt_pixelwidth
;
263 int cirrus_blt_width
;
264 int cirrus_blt_height
;
265 int cirrus_blt_dstpitch
;
266 int cirrus_blt_srcpitch
;
267 uint32_t cirrus_blt_fgcol
;
268 uint32_t cirrus_blt_bgcol
;
269 uint32_t cirrus_blt_dstaddr
;
270 uint32_t cirrus_blt_srcaddr
;
271 uint8_t cirrus_blt_mode
;
272 uint8_t cirrus_blt_modeext
;
273 cirrus_bitblt_rop_t cirrus_rop
;
274 #define CIRRUS_BLTBUFSIZE (2048 * 4) /* one line width */
275 uint8_t cirrus_bltbuf
[CIRRUS_BLTBUFSIZE
];
276 uint8_t *cirrus_srcptr
;
277 uint8_t *cirrus_srcptr_end
;
278 uint32_t cirrus_srccounter
;
279 /* hwcursor display state */
280 int last_hw_cursor_size
;
281 int last_hw_cursor_x
;
282 int last_hw_cursor_y
;
283 int last_hw_cursor_y_start
;
284 int last_hw_cursor_y_end
;
285 int real_vram_size
; /* XXX: suppress that */
286 CPUWriteMemoryFunc
**cirrus_linear_write
;
289 typedef struct PCICirrusVGAState
{
291 CirrusVGAState cirrus_vga
;
294 static uint8_t rop_to_index
[256];
296 /***************************************
300 ***************************************/
303 static void cirrus_bitblt_reset(CirrusVGAState
*s
);
304 static void cirrus_update_memory_access(CirrusVGAState
*s
);
306 /***************************************
310 ***************************************/
312 static void cirrus_bitblt_rop_nop(CirrusVGAState
*s
,
313 uint8_t *dst
,const uint8_t *src
,
314 int dstpitch
,int srcpitch
,
315 int bltwidth
,int bltheight
)
319 static void cirrus_bitblt_fill_nop(CirrusVGAState
*s
,
321 int dstpitch
, int bltwidth
,int bltheight
)
326 #define ROP_OP(d, s) d = 0
327 #include "cirrus_vga_rop.h"
329 #define ROP_NAME src_and_dst
330 #define ROP_OP(d, s) d = (s) & (d)
331 #include "cirrus_vga_rop.h"
333 #define ROP_NAME src_and_notdst
334 #define ROP_OP(d, s) d = (s) & (~(d))
335 #include "cirrus_vga_rop.h"
337 #define ROP_NAME notdst
338 #define ROP_OP(d, s) d = ~(d)
339 #include "cirrus_vga_rop.h"
342 #define ROP_OP(d, s) d = s
343 #include "cirrus_vga_rop.h"
346 #define ROP_OP(d, s) d = ~0
347 #include "cirrus_vga_rop.h"
349 #define ROP_NAME notsrc_and_dst
350 #define ROP_OP(d, s) d = (~(s)) & (d)
351 #include "cirrus_vga_rop.h"
353 #define ROP_NAME src_xor_dst
354 #define ROP_OP(d, s) d = (s) ^ (d)
355 #include "cirrus_vga_rop.h"
357 #define ROP_NAME src_or_dst
358 #define ROP_OP(d, s) d = (s) | (d)
359 #include "cirrus_vga_rop.h"
361 #define ROP_NAME notsrc_or_notdst
362 #define ROP_OP(d, s) d = (~(s)) | (~(d))
363 #include "cirrus_vga_rop.h"
365 #define ROP_NAME src_notxor_dst
366 #define ROP_OP(d, s) d = ~((s) ^ (d))
367 #include "cirrus_vga_rop.h"
369 #define ROP_NAME src_or_notdst
370 #define ROP_OP(d, s) d = (s) | (~(d))
371 #include "cirrus_vga_rop.h"
373 #define ROP_NAME notsrc
374 #define ROP_OP(d, s) d = (~(s))
375 #include "cirrus_vga_rop.h"
377 #define ROP_NAME notsrc_or_dst
378 #define ROP_OP(d, s) d = (~(s)) | (d)
379 #include "cirrus_vga_rop.h"
381 #define ROP_NAME notsrc_and_notdst
382 #define ROP_OP(d, s) d = (~(s)) & (~(d))
383 #include "cirrus_vga_rop.h"
385 static const cirrus_bitblt_rop_t cirrus_fwd_rop
[16] = {
386 cirrus_bitblt_rop_fwd_0
,
387 cirrus_bitblt_rop_fwd_src_and_dst
,
388 cirrus_bitblt_rop_nop
,
389 cirrus_bitblt_rop_fwd_src_and_notdst
,
390 cirrus_bitblt_rop_fwd_notdst
,
391 cirrus_bitblt_rop_fwd_src
,
392 cirrus_bitblt_rop_fwd_1
,
393 cirrus_bitblt_rop_fwd_notsrc_and_dst
,
394 cirrus_bitblt_rop_fwd_src_xor_dst
,
395 cirrus_bitblt_rop_fwd_src_or_dst
,
396 cirrus_bitblt_rop_fwd_notsrc_or_notdst
,
397 cirrus_bitblt_rop_fwd_src_notxor_dst
,
398 cirrus_bitblt_rop_fwd_src_or_notdst
,
399 cirrus_bitblt_rop_fwd_notsrc
,
400 cirrus_bitblt_rop_fwd_notsrc_or_dst
,
401 cirrus_bitblt_rop_fwd_notsrc_and_notdst
,
404 static const cirrus_bitblt_rop_t cirrus_bkwd_rop
[16] = {
405 cirrus_bitblt_rop_bkwd_0
,
406 cirrus_bitblt_rop_bkwd_src_and_dst
,
407 cirrus_bitblt_rop_nop
,
408 cirrus_bitblt_rop_bkwd_src_and_notdst
,
409 cirrus_bitblt_rop_bkwd_notdst
,
410 cirrus_bitblt_rop_bkwd_src
,
411 cirrus_bitblt_rop_bkwd_1
,
412 cirrus_bitblt_rop_bkwd_notsrc_and_dst
,
413 cirrus_bitblt_rop_bkwd_src_xor_dst
,
414 cirrus_bitblt_rop_bkwd_src_or_dst
,
415 cirrus_bitblt_rop_bkwd_notsrc_or_notdst
,
416 cirrus_bitblt_rop_bkwd_src_notxor_dst
,
417 cirrus_bitblt_rop_bkwd_src_or_notdst
,
418 cirrus_bitblt_rop_bkwd_notsrc
,
419 cirrus_bitblt_rop_bkwd_notsrc_or_dst
,
420 cirrus_bitblt_rop_bkwd_notsrc_and_notdst
,
423 #define TRANSP_ROP(name) {\
427 #define TRANSP_NOP(func) {\
432 static const cirrus_bitblt_rop_t cirrus_fwd_transp_rop
[16][2] = {
433 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_0
),
434 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_src_and_dst
),
435 TRANSP_NOP(cirrus_bitblt_rop_nop
),
436 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_src_and_notdst
),
437 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_notdst
),
438 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_src
),
439 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_1
),
440 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_notsrc_and_dst
),
441 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_src_xor_dst
),
442 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_src_or_dst
),
443 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_notsrc_or_notdst
),
444 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_src_notxor_dst
),
445 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_src_or_notdst
),
446 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_notsrc
),
447 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_notsrc_or_dst
),
448 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_notsrc_and_notdst
),
451 static const cirrus_bitblt_rop_t cirrus_bkwd_transp_rop
[16][2] = {
452 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_0
),
453 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_src_and_dst
),
454 TRANSP_NOP(cirrus_bitblt_rop_nop
),
455 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_src_and_notdst
),
456 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_notdst
),
457 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_src
),
458 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_1
),
459 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_notsrc_and_dst
),
460 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_src_xor_dst
),
461 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_src_or_dst
),
462 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_notsrc_or_notdst
),
463 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_src_notxor_dst
),
464 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_src_or_notdst
),
465 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_notsrc
),
466 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_notsrc_or_dst
),
467 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_notsrc_and_notdst
),
470 #define ROP2(name) {\
477 #define ROP_NOP2(func) {\
484 static const cirrus_bitblt_rop_t cirrus_patternfill
[16][4] = {
485 ROP2(cirrus_patternfill_0
),
486 ROP2(cirrus_patternfill_src_and_dst
),
487 ROP_NOP2(cirrus_bitblt_rop_nop
),
488 ROP2(cirrus_patternfill_src_and_notdst
),
489 ROP2(cirrus_patternfill_notdst
),
490 ROP2(cirrus_patternfill_src
),
491 ROP2(cirrus_patternfill_1
),
492 ROP2(cirrus_patternfill_notsrc_and_dst
),
493 ROP2(cirrus_patternfill_src_xor_dst
),
494 ROP2(cirrus_patternfill_src_or_dst
),
495 ROP2(cirrus_patternfill_notsrc_or_notdst
),
496 ROP2(cirrus_patternfill_src_notxor_dst
),
497 ROP2(cirrus_patternfill_src_or_notdst
),
498 ROP2(cirrus_patternfill_notsrc
),
499 ROP2(cirrus_patternfill_notsrc_or_dst
),
500 ROP2(cirrus_patternfill_notsrc_and_notdst
),
503 static const cirrus_bitblt_rop_t cirrus_colorexpand_transp
[16][4] = {
504 ROP2(cirrus_colorexpand_transp_0
),
505 ROP2(cirrus_colorexpand_transp_src_and_dst
),
506 ROP_NOP2(cirrus_bitblt_rop_nop
),
507 ROP2(cirrus_colorexpand_transp_src_and_notdst
),
508 ROP2(cirrus_colorexpand_transp_notdst
),
509 ROP2(cirrus_colorexpand_transp_src
),
510 ROP2(cirrus_colorexpand_transp_1
),
511 ROP2(cirrus_colorexpand_transp_notsrc_and_dst
),
512 ROP2(cirrus_colorexpand_transp_src_xor_dst
),
513 ROP2(cirrus_colorexpand_transp_src_or_dst
),
514 ROP2(cirrus_colorexpand_transp_notsrc_or_notdst
),
515 ROP2(cirrus_colorexpand_transp_src_notxor_dst
),
516 ROP2(cirrus_colorexpand_transp_src_or_notdst
),
517 ROP2(cirrus_colorexpand_transp_notsrc
),
518 ROP2(cirrus_colorexpand_transp_notsrc_or_dst
),
519 ROP2(cirrus_colorexpand_transp_notsrc_and_notdst
),
522 static const cirrus_bitblt_rop_t cirrus_colorexpand
[16][4] = {
523 ROP2(cirrus_colorexpand_0
),
524 ROP2(cirrus_colorexpand_src_and_dst
),
525 ROP_NOP2(cirrus_bitblt_rop_nop
),
526 ROP2(cirrus_colorexpand_src_and_notdst
),
527 ROP2(cirrus_colorexpand_notdst
),
528 ROP2(cirrus_colorexpand_src
),
529 ROP2(cirrus_colorexpand_1
),
530 ROP2(cirrus_colorexpand_notsrc_and_dst
),
531 ROP2(cirrus_colorexpand_src_xor_dst
),
532 ROP2(cirrus_colorexpand_src_or_dst
),
533 ROP2(cirrus_colorexpand_notsrc_or_notdst
),
534 ROP2(cirrus_colorexpand_src_notxor_dst
),
535 ROP2(cirrus_colorexpand_src_or_notdst
),
536 ROP2(cirrus_colorexpand_notsrc
),
537 ROP2(cirrus_colorexpand_notsrc_or_dst
),
538 ROP2(cirrus_colorexpand_notsrc_and_notdst
),
541 static const cirrus_bitblt_rop_t cirrus_colorexpand_pattern_transp
[16][4] = {
542 ROP2(cirrus_colorexpand_pattern_transp_0
),
543 ROP2(cirrus_colorexpand_pattern_transp_src_and_dst
),
544 ROP_NOP2(cirrus_bitblt_rop_nop
),
545 ROP2(cirrus_colorexpand_pattern_transp_src_and_notdst
),
546 ROP2(cirrus_colorexpand_pattern_transp_notdst
),
547 ROP2(cirrus_colorexpand_pattern_transp_src
),
548 ROP2(cirrus_colorexpand_pattern_transp_1
),
549 ROP2(cirrus_colorexpand_pattern_transp_notsrc_and_dst
),
550 ROP2(cirrus_colorexpand_pattern_transp_src_xor_dst
),
551 ROP2(cirrus_colorexpand_pattern_transp_src_or_dst
),
552 ROP2(cirrus_colorexpand_pattern_transp_notsrc_or_notdst
),
553 ROP2(cirrus_colorexpand_pattern_transp_src_notxor_dst
),
554 ROP2(cirrus_colorexpand_pattern_transp_src_or_notdst
),
555 ROP2(cirrus_colorexpand_pattern_transp_notsrc
),
556 ROP2(cirrus_colorexpand_pattern_transp_notsrc_or_dst
),
557 ROP2(cirrus_colorexpand_pattern_transp_notsrc_and_notdst
),
560 static const cirrus_bitblt_rop_t cirrus_colorexpand_pattern
[16][4] = {
561 ROP2(cirrus_colorexpand_pattern_0
),
562 ROP2(cirrus_colorexpand_pattern_src_and_dst
),
563 ROP_NOP2(cirrus_bitblt_rop_nop
),
564 ROP2(cirrus_colorexpand_pattern_src_and_notdst
),
565 ROP2(cirrus_colorexpand_pattern_notdst
),
566 ROP2(cirrus_colorexpand_pattern_src
),
567 ROP2(cirrus_colorexpand_pattern_1
),
568 ROP2(cirrus_colorexpand_pattern_notsrc_and_dst
),
569 ROP2(cirrus_colorexpand_pattern_src_xor_dst
),
570 ROP2(cirrus_colorexpand_pattern_src_or_dst
),
571 ROP2(cirrus_colorexpand_pattern_notsrc_or_notdst
),
572 ROP2(cirrus_colorexpand_pattern_src_notxor_dst
),
573 ROP2(cirrus_colorexpand_pattern_src_or_notdst
),
574 ROP2(cirrus_colorexpand_pattern_notsrc
),
575 ROP2(cirrus_colorexpand_pattern_notsrc_or_dst
),
576 ROP2(cirrus_colorexpand_pattern_notsrc_and_notdst
),
579 static const cirrus_fill_t cirrus_fill
[16][4] = {
581 ROP2(cirrus_fill_src_and_dst
),
582 ROP_NOP2(cirrus_bitblt_fill_nop
),
583 ROP2(cirrus_fill_src_and_notdst
),
584 ROP2(cirrus_fill_notdst
),
585 ROP2(cirrus_fill_src
),
587 ROP2(cirrus_fill_notsrc_and_dst
),
588 ROP2(cirrus_fill_src_xor_dst
),
589 ROP2(cirrus_fill_src_or_dst
),
590 ROP2(cirrus_fill_notsrc_or_notdst
),
591 ROP2(cirrus_fill_src_notxor_dst
),
592 ROP2(cirrus_fill_src_or_notdst
),
593 ROP2(cirrus_fill_notsrc
),
594 ROP2(cirrus_fill_notsrc_or_dst
),
595 ROP2(cirrus_fill_notsrc_and_notdst
),
598 static inline void cirrus_bitblt_fgcol(CirrusVGAState
*s
)
601 switch (s
->cirrus_blt_pixelwidth
) {
603 s
->cirrus_blt_fgcol
= s
->cirrus_shadow_gr1
;
606 color
= s
->cirrus_shadow_gr1
| (s
->gr
[0x11] << 8);
607 s
->cirrus_blt_fgcol
= le16_to_cpu(color
);
610 s
->cirrus_blt_fgcol
= s
->cirrus_shadow_gr1
|
611 (s
->gr
[0x11] << 8) | (s
->gr
[0x13] << 16);
615 color
= s
->cirrus_shadow_gr1
| (s
->gr
[0x11] << 8) |
616 (s
->gr
[0x13] << 16) | (s
->gr
[0x15] << 24);
617 s
->cirrus_blt_fgcol
= le32_to_cpu(color
);
622 static inline void cirrus_bitblt_bgcol(CirrusVGAState
*s
)
625 switch (s
->cirrus_blt_pixelwidth
) {
627 s
->cirrus_blt_bgcol
= s
->cirrus_shadow_gr0
;
630 color
= s
->cirrus_shadow_gr0
| (s
->gr
[0x10] << 8);
631 s
->cirrus_blt_bgcol
= le16_to_cpu(color
);
634 s
->cirrus_blt_bgcol
= s
->cirrus_shadow_gr0
|
635 (s
->gr
[0x10] << 8) | (s
->gr
[0x12] << 16);
639 color
= s
->cirrus_shadow_gr0
| (s
->gr
[0x10] << 8) |
640 (s
->gr
[0x12] << 16) | (s
->gr
[0x14] << 24);
641 s
->cirrus_blt_bgcol
= le32_to_cpu(color
);
646 static void cirrus_invalidate_region(CirrusVGAState
* s
, int off_begin
,
647 int off_pitch
, int bytesperline
,
654 for (y
= 0; y
< lines
; y
++) {
656 off_cur_end
= (off_cur
+ bytesperline
) & s
->cirrus_addr_mask
;
657 off_cur
&= TARGET_PAGE_MASK
;
658 while (off_cur
< off_cur_end
) {
659 cpu_physical_memory_set_dirty(s
->vram_offset
+ off_cur
);
660 off_cur
+= TARGET_PAGE_SIZE
;
662 off_begin
+= off_pitch
;
666 static int cirrus_bitblt_common_patterncopy(CirrusVGAState
* s
,
671 dst
= s
->vram_ptr
+ (s
->cirrus_blt_dstaddr
& s
->cirrus_addr_mask
);
676 (*s
->cirrus_rop
) (s
, dst
, src
,
677 s
->cirrus_blt_dstpitch
, 0,
678 s
->cirrus_blt_width
, s
->cirrus_blt_height
);
679 cirrus_invalidate_region(s
, s
->cirrus_blt_dstaddr
,
680 s
->cirrus_blt_dstpitch
, s
->cirrus_blt_width
,
681 s
->cirrus_blt_height
);
687 static int cirrus_bitblt_solidfill(CirrusVGAState
*s
, int blt_rop
)
689 cirrus_fill_t rop_func
;
693 rop_func
= cirrus_fill
[rop_to_index
[blt_rop
]][s
->cirrus_blt_pixelwidth
- 1];
694 rop_func(s
, s
->vram_ptr
+ (s
->cirrus_blt_dstaddr
& s
->cirrus_addr_mask
),
695 s
->cirrus_blt_dstpitch
,
696 s
->cirrus_blt_width
, s
->cirrus_blt_height
);
697 cirrus_invalidate_region(s
, s
->cirrus_blt_dstaddr
,
698 s
->cirrus_blt_dstpitch
, s
->cirrus_blt_width
,
699 s
->cirrus_blt_height
);
700 cirrus_bitblt_reset(s
);
704 /***************************************
706 * bitblt (video-to-video)
708 ***************************************/
710 static int cirrus_bitblt_videotovideo_patterncopy(CirrusVGAState
* s
)
712 return cirrus_bitblt_common_patterncopy(s
,
713 s
->vram_ptr
+ ((s
->cirrus_blt_srcaddr
& ~7) &
714 s
->cirrus_addr_mask
));
717 static void cirrus_do_copy(CirrusVGAState
*s
, int dst
, int src
, int w
, int h
)
725 depth
= s
->get_bpp((VGAState
*)s
) / 8;
726 s
->get_resolution((VGAState
*)s
, &width
, &height
);
729 sx
= (src
% (width
* depth
)) / depth
;
730 sy
= (src
/ (width
* depth
));
731 dx
= (dst
% (width
*depth
)) / depth
;
732 dy
= (dst
/ (width
* depth
));
734 /* normalize width */
737 /* if we're doing a backward copy, we have to adjust
738 our x/y to be the upper left corner (instead of the lower
740 if (s
->cirrus_blt_dstpitch
< 0) {
741 sx
-= (s
->cirrus_blt_width
/ depth
) - 1;
742 dx
-= (s
->cirrus_blt_width
/ depth
) - 1;
743 sy
-= s
->cirrus_blt_height
- 1;
744 dy
-= s
->cirrus_blt_height
- 1;
747 /* are we in the visible portion of memory? */
748 if (sx
>= 0 && sy
>= 0 && dx
>= 0 && dy
>= 0 &&
749 (sx
+ w
) <= width
&& (sy
+ h
) <= height
&&
750 (dx
+ w
) <= width
&& (dy
+ h
) <= height
) {
754 /* make to sure only copy if it's a plain copy ROP */
755 if (*s
->cirrus_rop
!= cirrus_bitblt_rop_fwd_src
&&
756 *s
->cirrus_rop
!= cirrus_bitblt_rop_bkwd_src
)
759 /* we have to flush all pending changes so that the copy
760 is generated at the appropriate moment in time */
764 (*s
->cirrus_rop
) (s
, s
->vram_ptr
+
765 (s
->cirrus_blt_dstaddr
& s
->cirrus_addr_mask
),
767 (s
->cirrus_blt_srcaddr
& s
->cirrus_addr_mask
),
768 s
->cirrus_blt_dstpitch
, s
->cirrus_blt_srcpitch
,
769 s
->cirrus_blt_width
, s
->cirrus_blt_height
);
772 s
->ds
->dpy_copy(s
->ds
,
774 s
->cirrus_blt_width
/ depth
,
775 s
->cirrus_blt_height
);
777 /* we don't have to notify the display that this portion has
778 changed since dpy_copy implies this */
781 cirrus_invalidate_region(s
, s
->cirrus_blt_dstaddr
,
782 s
->cirrus_blt_dstpitch
, s
->cirrus_blt_width
,
783 s
->cirrus_blt_height
);
786 static int cirrus_bitblt_videotovideo_copy(CirrusVGAState
* s
)
788 if (s
->ds
->dpy_copy
) {
789 cirrus_do_copy(s
, s
->cirrus_blt_dstaddr
- s
->start_addr
,
790 s
->cirrus_blt_srcaddr
- s
->start_addr
,
791 s
->cirrus_blt_width
, s
->cirrus_blt_height
);
797 (*s
->cirrus_rop
) (s
, s
->vram_ptr
+
798 (s
->cirrus_blt_dstaddr
& s
->cirrus_addr_mask
),
800 (s
->cirrus_blt_srcaddr
& s
->cirrus_addr_mask
),
801 s
->cirrus_blt_dstpitch
, s
->cirrus_blt_srcpitch
,
802 s
->cirrus_blt_width
, s
->cirrus_blt_height
);
804 cirrus_invalidate_region(s
, s
->cirrus_blt_dstaddr
,
805 s
->cirrus_blt_dstpitch
, s
->cirrus_blt_width
,
806 s
->cirrus_blt_height
);
812 /***************************************
814 * bitblt (cpu-to-video)
816 ***************************************/
818 static void cirrus_bitblt_cputovideo_next(CirrusVGAState
* s
)
823 if (s
->cirrus_srccounter
> 0) {
824 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_PATTERNCOPY
) {
825 cirrus_bitblt_common_patterncopy(s
, s
->cirrus_bltbuf
);
827 s
->cirrus_srccounter
= 0;
828 cirrus_bitblt_reset(s
);
830 /* at least one scan line */
832 (*s
->cirrus_rop
)(s
, s
->vram_ptr
+
833 (s
->cirrus_blt_dstaddr
& s
->cirrus_addr_mask
),
834 s
->cirrus_bltbuf
, 0, 0, s
->cirrus_blt_width
, 1);
835 cirrus_invalidate_region(s
, s
->cirrus_blt_dstaddr
, 0,
836 s
->cirrus_blt_width
, 1);
837 s
->cirrus_blt_dstaddr
+= s
->cirrus_blt_dstpitch
;
838 s
->cirrus_srccounter
-= s
->cirrus_blt_srcpitch
;
839 if (s
->cirrus_srccounter
<= 0)
841 /* more bytes than needed can be transfered because of
842 word alignment, so we keep them for the next line */
843 /* XXX: keep alignment to speed up transfer */
844 end_ptr
= s
->cirrus_bltbuf
+ s
->cirrus_blt_srcpitch
;
845 copy_count
= s
->cirrus_srcptr_end
- end_ptr
;
846 memmove(s
->cirrus_bltbuf
, end_ptr
, copy_count
);
847 s
->cirrus_srcptr
= s
->cirrus_bltbuf
+ copy_count
;
848 s
->cirrus_srcptr_end
= s
->cirrus_bltbuf
+ s
->cirrus_blt_srcpitch
;
849 } while (s
->cirrus_srcptr
>= s
->cirrus_srcptr_end
);
854 /***************************************
858 ***************************************/
860 static void cirrus_bitblt_reset(CirrusVGAState
* s
)
863 ~(CIRRUS_BLT_START
| CIRRUS_BLT_BUSY
| CIRRUS_BLT_FIFOUSED
);
864 s
->cirrus_srcptr
= &s
->cirrus_bltbuf
[0];
865 s
->cirrus_srcptr_end
= &s
->cirrus_bltbuf
[0];
866 s
->cirrus_srccounter
= 0;
867 cirrus_update_memory_access(s
);
870 static int cirrus_bitblt_cputovideo(CirrusVGAState
* s
)
874 s
->cirrus_blt_mode
&= ~CIRRUS_BLTMODE_MEMSYSSRC
;
875 s
->cirrus_srcptr
= &s
->cirrus_bltbuf
[0];
876 s
->cirrus_srcptr_end
= &s
->cirrus_bltbuf
[0];
878 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_PATTERNCOPY
) {
879 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_COLOREXPAND
) {
880 s
->cirrus_blt_srcpitch
= 8;
882 /* XXX: check for 24 bpp */
883 s
->cirrus_blt_srcpitch
= 8 * 8 * s
->cirrus_blt_pixelwidth
;
885 s
->cirrus_srccounter
= s
->cirrus_blt_srcpitch
;
887 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_COLOREXPAND
) {
888 w
= s
->cirrus_blt_width
/ s
->cirrus_blt_pixelwidth
;
889 if (s
->cirrus_blt_modeext
& CIRRUS_BLTMODEEXT_DWORDGRANULARITY
)
890 s
->cirrus_blt_srcpitch
= ((w
+ 31) >> 5);
892 s
->cirrus_blt_srcpitch
= ((w
+ 7) >> 3);
894 /* always align input size to 32 bits */
895 s
->cirrus_blt_srcpitch
= (s
->cirrus_blt_width
+ 3) & ~3;
897 s
->cirrus_srccounter
= s
->cirrus_blt_srcpitch
* s
->cirrus_blt_height
;
899 s
->cirrus_srcptr
= s
->cirrus_bltbuf
;
900 s
->cirrus_srcptr_end
= s
->cirrus_bltbuf
+ s
->cirrus_blt_srcpitch
;
901 cirrus_update_memory_access(s
);
905 static int cirrus_bitblt_videotocpu(CirrusVGAState
* s
)
909 printf("cirrus: bitblt (video to cpu) is not implemented yet\n");
914 static int cirrus_bitblt_videotovideo(CirrusVGAState
* s
)
918 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_PATTERNCOPY
) {
919 ret
= cirrus_bitblt_videotovideo_patterncopy(s
);
921 ret
= cirrus_bitblt_videotovideo_copy(s
);
924 cirrus_bitblt_reset(s
);
928 static void cirrus_bitblt_start(CirrusVGAState
* s
)
932 s
->gr
[0x31] |= CIRRUS_BLT_BUSY
;
934 s
->cirrus_blt_width
= (s
->gr
[0x20] | (s
->gr
[0x21] << 8)) + 1;
935 s
->cirrus_blt_height
= (s
->gr
[0x22] | (s
->gr
[0x23] << 8)) + 1;
936 s
->cirrus_blt_dstpitch
= (s
->gr
[0x24] | (s
->gr
[0x25] << 8));
937 s
->cirrus_blt_srcpitch
= (s
->gr
[0x26] | (s
->gr
[0x27] << 8));
938 s
->cirrus_blt_dstaddr
=
939 (s
->gr
[0x28] | (s
->gr
[0x29] << 8) | (s
->gr
[0x2a] << 16));
940 s
->cirrus_blt_srcaddr
=
941 (s
->gr
[0x2c] | (s
->gr
[0x2d] << 8) | (s
->gr
[0x2e] << 16));
942 s
->cirrus_blt_mode
= s
->gr
[0x30];
943 s
->cirrus_blt_modeext
= s
->gr
[0x33];
944 blt_rop
= s
->gr
[0x32];
947 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",
950 s
->cirrus_blt_modeext
,
952 s
->cirrus_blt_height
,
953 s
->cirrus_blt_dstpitch
,
954 s
->cirrus_blt_srcpitch
,
955 s
->cirrus_blt_dstaddr
,
956 s
->cirrus_blt_srcaddr
,
960 switch (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_PIXELWIDTHMASK
) {
961 case CIRRUS_BLTMODE_PIXELWIDTH8
:
962 s
->cirrus_blt_pixelwidth
= 1;
964 case CIRRUS_BLTMODE_PIXELWIDTH16
:
965 s
->cirrus_blt_pixelwidth
= 2;
967 case CIRRUS_BLTMODE_PIXELWIDTH24
:
968 s
->cirrus_blt_pixelwidth
= 3;
970 case CIRRUS_BLTMODE_PIXELWIDTH32
:
971 s
->cirrus_blt_pixelwidth
= 4;
975 printf("cirrus: bitblt - pixel width is unknown\n");
979 s
->cirrus_blt_mode
&= ~CIRRUS_BLTMODE_PIXELWIDTHMASK
;
982 cirrus_blt_mode
& (CIRRUS_BLTMODE_MEMSYSSRC
|
983 CIRRUS_BLTMODE_MEMSYSDEST
))
984 == (CIRRUS_BLTMODE_MEMSYSSRC
| CIRRUS_BLTMODE_MEMSYSDEST
)) {
986 printf("cirrus: bitblt - memory-to-memory copy is requested\n");
991 if ((s
->cirrus_blt_modeext
& CIRRUS_BLTMODEEXT_SOLIDFILL
) &&
992 (s
->cirrus_blt_mode
& (CIRRUS_BLTMODE_MEMSYSDEST
|
993 CIRRUS_BLTMODE_TRANSPARENTCOMP
|
994 CIRRUS_BLTMODE_PATTERNCOPY
|
995 CIRRUS_BLTMODE_COLOREXPAND
)) ==
996 (CIRRUS_BLTMODE_PATTERNCOPY
| CIRRUS_BLTMODE_COLOREXPAND
)) {
997 cirrus_bitblt_fgcol(s
);
998 cirrus_bitblt_solidfill(s
, blt_rop
);
1000 if ((s
->cirrus_blt_mode
& (CIRRUS_BLTMODE_COLOREXPAND
|
1001 CIRRUS_BLTMODE_PATTERNCOPY
)) ==
1002 CIRRUS_BLTMODE_COLOREXPAND
) {
1004 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_TRANSPARENTCOMP
) {
1005 if (s
->cirrus_blt_modeext
& CIRRUS_BLTMODEEXT_COLOREXPINV
)
1006 cirrus_bitblt_bgcol(s
);
1008 cirrus_bitblt_fgcol(s
);
1009 s
->cirrus_rop
= cirrus_colorexpand_transp
[rop_to_index
[blt_rop
]][s
->cirrus_blt_pixelwidth
- 1];
1011 cirrus_bitblt_fgcol(s
);
1012 cirrus_bitblt_bgcol(s
);
1013 s
->cirrus_rop
= cirrus_colorexpand
[rop_to_index
[blt_rop
]][s
->cirrus_blt_pixelwidth
- 1];
1015 } else if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_PATTERNCOPY
) {
1016 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_COLOREXPAND
) {
1017 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_TRANSPARENTCOMP
) {
1018 if (s
->cirrus_blt_modeext
& CIRRUS_BLTMODEEXT_COLOREXPINV
)
1019 cirrus_bitblt_bgcol(s
);
1021 cirrus_bitblt_fgcol(s
);
1022 s
->cirrus_rop
= cirrus_colorexpand_pattern_transp
[rop_to_index
[blt_rop
]][s
->cirrus_blt_pixelwidth
- 1];
1024 cirrus_bitblt_fgcol(s
);
1025 cirrus_bitblt_bgcol(s
);
1026 s
->cirrus_rop
= cirrus_colorexpand_pattern
[rop_to_index
[blt_rop
]][s
->cirrus_blt_pixelwidth
- 1];
1029 s
->cirrus_rop
= cirrus_patternfill
[rop_to_index
[blt_rop
]][s
->cirrus_blt_pixelwidth
- 1];
1032 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_TRANSPARENTCOMP
) {
1033 if (s
->cirrus_blt_pixelwidth
> 2) {
1034 printf("src transparent without colorexpand must be 8bpp or 16bpp\n");
1037 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_BACKWARDS
) {
1038 s
->cirrus_blt_dstpitch
= -s
->cirrus_blt_dstpitch
;
1039 s
->cirrus_blt_srcpitch
= -s
->cirrus_blt_srcpitch
;
1040 s
->cirrus_rop
= cirrus_bkwd_transp_rop
[rop_to_index
[blt_rop
]][s
->cirrus_blt_pixelwidth
- 1];
1042 s
->cirrus_rop
= cirrus_fwd_transp_rop
[rop_to_index
[blt_rop
]][s
->cirrus_blt_pixelwidth
- 1];
1045 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_BACKWARDS
) {
1046 s
->cirrus_blt_dstpitch
= -s
->cirrus_blt_dstpitch
;
1047 s
->cirrus_blt_srcpitch
= -s
->cirrus_blt_srcpitch
;
1048 s
->cirrus_rop
= cirrus_bkwd_rop
[rop_to_index
[blt_rop
]];
1050 s
->cirrus_rop
= cirrus_fwd_rop
[rop_to_index
[blt_rop
]];
1054 // setup bitblt engine.
1055 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_MEMSYSSRC
) {
1056 if (!cirrus_bitblt_cputovideo(s
))
1058 } else if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_MEMSYSDEST
) {
1059 if (!cirrus_bitblt_videotocpu(s
))
1062 if (!cirrus_bitblt_videotovideo(s
))
1068 cirrus_bitblt_reset(s
);
1071 static void cirrus_write_bitblt(CirrusVGAState
* s
, unsigned reg_value
)
1075 old_value
= s
->gr
[0x31];
1076 s
->gr
[0x31] = reg_value
;
1078 if (((old_value
& CIRRUS_BLT_RESET
) != 0) &&
1079 ((reg_value
& CIRRUS_BLT_RESET
) == 0)) {
1080 cirrus_bitblt_reset(s
);
1081 } else if (((old_value
& CIRRUS_BLT_START
) == 0) &&
1082 ((reg_value
& CIRRUS_BLT_START
) != 0)) {
1083 cirrus_bitblt_start(s
);
1088 /***************************************
1092 ***************************************/
1094 static void cirrus_get_offsets(VGAState
*s1
,
1095 uint32_t *pline_offset
,
1096 uint32_t *pstart_addr
,
1097 uint32_t *pline_compare
)
1099 CirrusVGAState
* s
= (CirrusVGAState
*)s1
;
1100 uint32_t start_addr
, line_offset
, line_compare
;
1102 line_offset
= s
->cr
[0x13]
1103 | ((s
->cr
[0x1b] & 0x10) << 4);
1105 *pline_offset
= line_offset
;
1107 start_addr
= (s
->cr
[0x0c] << 8)
1109 | ((s
->cr
[0x1b] & 0x01) << 16)
1110 | ((s
->cr
[0x1b] & 0x0c) << 15)
1111 | ((s
->cr
[0x1d] & 0x80) << 12);
1112 *pstart_addr
= start_addr
;
1114 line_compare
= s
->cr
[0x18] |
1115 ((s
->cr
[0x07] & 0x10) << 4) |
1116 ((s
->cr
[0x09] & 0x40) << 3);
1117 *pline_compare
= line_compare
;
1120 static uint32_t cirrus_get_bpp16_depth(CirrusVGAState
* s
)
1124 switch (s
->cirrus_hidden_dac_data
& 0xf) {
1127 break; /* Sierra HiColor */
1130 break; /* XGA HiColor */
1133 printf("cirrus: invalid DAC value %x in 16bpp\n",
1134 (s
->cirrus_hidden_dac_data
& 0xf));
1142 static int cirrus_get_bpp(VGAState
*s1
)
1144 CirrusVGAState
* s
= (CirrusVGAState
*)s1
;
1147 if ((s
->sr
[0x07] & 0x01) != 0) {
1149 switch (s
->sr
[0x07] & CIRRUS_SR7_BPP_MASK
) {
1150 case CIRRUS_SR7_BPP_8
:
1153 case CIRRUS_SR7_BPP_16_DOUBLEVCLK
:
1154 ret
= cirrus_get_bpp16_depth(s
);
1156 case CIRRUS_SR7_BPP_24
:
1159 case CIRRUS_SR7_BPP_16
:
1160 ret
= cirrus_get_bpp16_depth(s
);
1162 case CIRRUS_SR7_BPP_32
:
1167 printf("cirrus: unknown bpp - sr7=%x\n", s
->sr
[0x7]);
1180 static void cirrus_get_resolution(VGAState
*s
, int *pwidth
, int *pheight
)
1184 width
= (s
->cr
[0x01] + 1) * 8;
1185 height
= s
->cr
[0x12] |
1186 ((s
->cr
[0x07] & 0x02) << 7) |
1187 ((s
->cr
[0x07] & 0x40) << 3);
1188 height
= (height
+ 1);
1189 /* interlace support */
1190 if (s
->cr
[0x1a] & 0x01)
1191 height
= height
* 2;
1196 /***************************************
1200 ***************************************/
1202 static void cirrus_update_bank_ptr(CirrusVGAState
* s
, unsigned bank_index
)
1207 if ((s
->gr
[0x0b] & 0x01) != 0) /* dual bank */
1208 offset
= s
->gr
[0x09 + bank_index
];
1209 else /* single bank */
1210 offset
= s
->gr
[0x09];
1212 if ((s
->gr
[0x0b] & 0x20) != 0)
1217 if (s
->real_vram_size
<= offset
)
1220 limit
= s
->real_vram_size
- offset
;
1222 if (((s
->gr
[0x0b] & 0x01) == 0) && (bank_index
!= 0)) {
1223 if (limit
> 0x8000) {
1232 s
->cirrus_bank_base
[bank_index
] = offset
;
1233 s
->cirrus_bank_limit
[bank_index
] = limit
;
1235 s
->cirrus_bank_base
[bank_index
] = 0;
1236 s
->cirrus_bank_limit
[bank_index
] = 0;
1240 /***************************************
1242 * I/O access between 0x3c4-0x3c5
1244 ***************************************/
1247 cirrus_hook_read_sr(CirrusVGAState
* s
, unsigned reg_index
, int *reg_value
)
1249 switch (reg_index
) {
1250 case 0x00: // Standard VGA
1251 case 0x01: // Standard VGA
1252 case 0x02: // Standard VGA
1253 case 0x03: // Standard VGA
1254 case 0x04: // Standard VGA
1255 return CIRRUS_HOOK_NOT_HANDLED
;
1256 case 0x06: // Unlock Cirrus extensions
1257 *reg_value
= s
->sr
[reg_index
];
1262 case 0x70: // Graphics Cursor X
1266 case 0xf0: // Graphics Cursor X
1267 *reg_value
= s
->sr
[0x10];
1272 case 0x71: // Graphics Cursor Y
1276 case 0xf1: // Graphics Cursor Y
1277 *reg_value
= s
->sr
[0x11];
1280 case 0x07: // Extended Sequencer Mode
1281 case 0x08: // EEPROM Control
1282 case 0x09: // Scratch Register 0
1283 case 0x0a: // Scratch Register 1
1284 case 0x0b: // VCLK 0
1285 case 0x0c: // VCLK 1
1286 case 0x0d: // VCLK 2
1287 case 0x0e: // VCLK 3
1288 case 0x0f: // DRAM Control
1289 case 0x12: // Graphics Cursor Attribute
1290 case 0x13: // Graphics Cursor Pattern Address
1291 case 0x14: // Scratch Register 2
1292 case 0x15: // Scratch Register 3
1293 case 0x16: // Performance Tuning Register
1294 case 0x17: // Configuration Readback and Extended Control
1295 case 0x18: // Signature Generator Control
1296 case 0x19: // Signal Generator Result
1297 case 0x1a: // Signal Generator Result
1298 case 0x1b: // VCLK 0 Denominator & Post
1299 case 0x1c: // VCLK 1 Denominator & Post
1300 case 0x1d: // VCLK 2 Denominator & Post
1301 case 0x1e: // VCLK 3 Denominator & Post
1302 case 0x1f: // BIOS Write Enable and MCLK select
1304 printf("cirrus: handled inport sr_index %02x\n", reg_index
);
1306 *reg_value
= s
->sr
[reg_index
];
1310 printf("cirrus: inport sr_index %02x\n", reg_index
);
1316 return CIRRUS_HOOK_HANDLED
;
1320 cirrus_hook_write_sr(CirrusVGAState
* s
, unsigned reg_index
, int reg_value
)
1322 switch (reg_index
) {
1323 case 0x00: // Standard VGA
1324 case 0x01: // Standard VGA
1325 case 0x02: // Standard VGA
1326 case 0x03: // Standard VGA
1327 case 0x04: // Standard VGA
1328 return CIRRUS_HOOK_NOT_HANDLED
;
1329 case 0x06: // Unlock Cirrus extensions
1331 if (reg_value
== 0x12) {
1332 s
->sr
[reg_index
] = 0x12;
1334 s
->sr
[reg_index
] = 0x0f;
1340 case 0x70: // Graphics Cursor X
1344 case 0xf0: // Graphics Cursor X
1345 s
->sr
[0x10] = reg_value
;
1346 s
->hw_cursor_x
= (reg_value
<< 3) | (reg_index
>> 5);
1351 case 0x71: // Graphics Cursor Y
1355 case 0xf1: // Graphics Cursor Y
1356 s
->sr
[0x11] = reg_value
;
1357 s
->hw_cursor_y
= (reg_value
<< 3) | (reg_index
>> 5);
1359 case 0x07: // Extended Sequencer Mode
1360 case 0x08: // EEPROM Control
1361 case 0x09: // Scratch Register 0
1362 case 0x0a: // Scratch Register 1
1363 case 0x0b: // VCLK 0
1364 case 0x0c: // VCLK 1
1365 case 0x0d: // VCLK 2
1366 case 0x0e: // VCLK 3
1367 case 0x0f: // DRAM Control
1368 case 0x12: // Graphics Cursor Attribute
1369 case 0x13: // Graphics Cursor Pattern Address
1370 case 0x14: // Scratch Register 2
1371 case 0x15: // Scratch Register 3
1372 case 0x16: // Performance Tuning Register
1373 case 0x18: // Signature Generator Control
1374 case 0x19: // Signature Generator Result
1375 case 0x1a: // Signature Generator Result
1376 case 0x1b: // VCLK 0 Denominator & Post
1377 case 0x1c: // VCLK 1 Denominator & Post
1378 case 0x1d: // VCLK 2 Denominator & Post
1379 case 0x1e: // VCLK 3 Denominator & Post
1380 case 0x1f: // BIOS Write Enable and MCLK select
1381 s
->sr
[reg_index
] = reg_value
;
1383 printf("cirrus: handled outport sr_index %02x, sr_value %02x\n",
1384 reg_index
, reg_value
);
1387 case 0x17: // Configuration Readback and Extended Control
1388 s
->sr
[reg_index
] = (s
->sr
[reg_index
] & 0x38) | (reg_value
& 0xc7);
1389 cirrus_update_memory_access(s
);
1393 printf("cirrus: outport sr_index %02x, sr_value %02x\n", reg_index
,
1399 return CIRRUS_HOOK_HANDLED
;
1402 /***************************************
1404 * I/O access at 0x3c6
1406 ***************************************/
1408 static void cirrus_read_hidden_dac(CirrusVGAState
* s
, int *reg_value
)
1411 if (++s
->cirrus_hidden_dac_lockindex
== 5) {
1412 *reg_value
= s
->cirrus_hidden_dac_data
;
1413 s
->cirrus_hidden_dac_lockindex
= 0;
1417 static void cirrus_write_hidden_dac(CirrusVGAState
* s
, int reg_value
)
1419 if (s
->cirrus_hidden_dac_lockindex
== 4) {
1420 s
->cirrus_hidden_dac_data
= reg_value
;
1421 #if defined(DEBUG_CIRRUS)
1422 printf("cirrus: outport hidden DAC, value %02x\n", reg_value
);
1425 s
->cirrus_hidden_dac_lockindex
= 0;
1428 /***************************************
1430 * I/O access at 0x3c9
1432 ***************************************/
1434 static int cirrus_hook_read_palette(CirrusVGAState
* s
, int *reg_value
)
1436 if (!(s
->sr
[0x12] & CIRRUS_CURSOR_HIDDENPEL
))
1437 return CIRRUS_HOOK_NOT_HANDLED
;
1439 s
->cirrus_hidden_palette
[(s
->dac_read_index
& 0x0f) * 3 +
1441 if (++s
->dac_sub_index
== 3) {
1442 s
->dac_sub_index
= 0;
1443 s
->dac_read_index
++;
1445 return CIRRUS_HOOK_HANDLED
;
1448 static int cirrus_hook_write_palette(CirrusVGAState
* s
, int reg_value
)
1450 if (!(s
->sr
[0x12] & CIRRUS_CURSOR_HIDDENPEL
))
1451 return CIRRUS_HOOK_NOT_HANDLED
;
1452 s
->dac_cache
[s
->dac_sub_index
] = reg_value
;
1453 if (++s
->dac_sub_index
== 3) {
1454 memcpy(&s
->cirrus_hidden_palette
[(s
->dac_write_index
& 0x0f) * 3],
1456 /* XXX update cursor */
1457 s
->dac_sub_index
= 0;
1458 s
->dac_write_index
++;
1460 return CIRRUS_HOOK_HANDLED
;
1463 /***************************************
1465 * I/O access between 0x3ce-0x3cf
1467 ***************************************/
1470 cirrus_hook_read_gr(CirrusVGAState
* s
, unsigned reg_index
, int *reg_value
)
1472 switch (reg_index
) {
1473 case 0x00: // Standard VGA, BGCOLOR 0x000000ff
1474 *reg_value
= s
->cirrus_shadow_gr0
;
1475 return CIRRUS_HOOK_HANDLED
;
1476 case 0x01: // Standard VGA, FGCOLOR 0x000000ff
1477 *reg_value
= s
->cirrus_shadow_gr1
;
1478 return CIRRUS_HOOK_HANDLED
;
1479 case 0x02: // Standard VGA
1480 case 0x03: // Standard VGA
1481 case 0x04: // Standard VGA
1482 case 0x06: // Standard VGA
1483 case 0x07: // Standard VGA
1484 case 0x08: // Standard VGA
1485 return CIRRUS_HOOK_NOT_HANDLED
;
1486 case 0x05: // Standard VGA, Cirrus extended mode
1491 if (reg_index
< 0x3a) {
1492 *reg_value
= s
->gr
[reg_index
];
1495 printf("cirrus: inport gr_index %02x\n", reg_index
);
1500 return CIRRUS_HOOK_HANDLED
;
1504 cirrus_hook_write_gr(CirrusVGAState
* s
, unsigned reg_index
, int reg_value
)
1506 #if defined(DEBUG_BITBLT) && 0
1507 printf("gr%02x: %02x\n", reg_index
, reg_value
);
1509 switch (reg_index
) {
1510 case 0x00: // Standard VGA, BGCOLOR 0x000000ff
1511 s
->cirrus_shadow_gr0
= reg_value
;
1512 return CIRRUS_HOOK_NOT_HANDLED
;
1513 case 0x01: // Standard VGA, FGCOLOR 0x000000ff
1514 s
->cirrus_shadow_gr1
= reg_value
;
1515 return CIRRUS_HOOK_NOT_HANDLED
;
1516 case 0x02: // Standard VGA
1517 case 0x03: // Standard VGA
1518 case 0x04: // Standard VGA
1519 case 0x06: // Standard VGA
1520 case 0x07: // Standard VGA
1521 case 0x08: // Standard VGA
1522 return CIRRUS_HOOK_NOT_HANDLED
;
1523 case 0x05: // Standard VGA, Cirrus extended mode
1524 s
->gr
[reg_index
] = reg_value
& 0x7f;
1525 cirrus_update_memory_access(s
);
1527 case 0x09: // bank offset #0
1528 case 0x0A: // bank offset #1
1529 s
->gr
[reg_index
] = reg_value
;
1530 cirrus_update_bank_ptr(s
, 0);
1531 cirrus_update_bank_ptr(s
, 1);
1534 s
->gr
[reg_index
] = reg_value
;
1535 cirrus_update_bank_ptr(s
, 0);
1536 cirrus_update_bank_ptr(s
, 1);
1537 cirrus_update_memory_access(s
);
1539 case 0x10: // BGCOLOR 0x0000ff00
1540 case 0x11: // FGCOLOR 0x0000ff00
1541 case 0x12: // BGCOLOR 0x00ff0000
1542 case 0x13: // FGCOLOR 0x00ff0000
1543 case 0x14: // BGCOLOR 0xff000000
1544 case 0x15: // FGCOLOR 0xff000000
1545 case 0x20: // BLT WIDTH 0x0000ff
1546 case 0x22: // BLT HEIGHT 0x0000ff
1547 case 0x24: // BLT DEST PITCH 0x0000ff
1548 case 0x26: // BLT SRC PITCH 0x0000ff
1549 case 0x28: // BLT DEST ADDR 0x0000ff
1550 case 0x29: // BLT DEST ADDR 0x00ff00
1551 case 0x2c: // BLT SRC ADDR 0x0000ff
1552 case 0x2d: // BLT SRC ADDR 0x00ff00
1553 case 0x2f: // BLT WRITEMASK
1554 case 0x30: // BLT MODE
1555 case 0x32: // RASTER OP
1556 case 0x33: // BLT MODEEXT
1557 case 0x34: // BLT TRANSPARENT COLOR 0x00ff
1558 case 0x35: // BLT TRANSPARENT COLOR 0xff00
1559 case 0x38: // BLT TRANSPARENT COLOR MASK 0x00ff
1560 case 0x39: // BLT TRANSPARENT COLOR MASK 0xff00
1561 s
->gr
[reg_index
] = reg_value
;
1563 case 0x21: // BLT WIDTH 0x001f00
1564 case 0x23: // BLT HEIGHT 0x001f00
1565 case 0x25: // BLT DEST PITCH 0x001f00
1566 case 0x27: // BLT SRC PITCH 0x001f00
1567 s
->gr
[reg_index
] = reg_value
& 0x1f;
1569 case 0x2a: // BLT DEST ADDR 0x3f0000
1570 s
->gr
[reg_index
] = reg_value
& 0x3f;
1571 /* if auto start mode, starts bit blt now */
1572 if (s
->gr
[0x31] & CIRRUS_BLT_AUTOSTART
) {
1573 cirrus_bitblt_start(s
);
1576 case 0x2e: // BLT SRC ADDR 0x3f0000
1577 s
->gr
[reg_index
] = reg_value
& 0x3f;
1579 case 0x31: // BLT STATUS/START
1580 cirrus_write_bitblt(s
, reg_value
);
1584 printf("cirrus: outport gr_index %02x, gr_value %02x\n", reg_index
,
1590 return CIRRUS_HOOK_HANDLED
;
1593 /***************************************
1595 * I/O access between 0x3d4-0x3d5
1597 ***************************************/
1600 cirrus_hook_read_cr(CirrusVGAState
* s
, unsigned reg_index
, int *reg_value
)
1602 switch (reg_index
) {
1603 case 0x00: // Standard VGA
1604 case 0x01: // Standard VGA
1605 case 0x02: // Standard VGA
1606 case 0x03: // Standard VGA
1607 case 0x04: // Standard VGA
1608 case 0x05: // Standard VGA
1609 case 0x06: // Standard VGA
1610 case 0x07: // Standard VGA
1611 case 0x08: // Standard VGA
1612 case 0x09: // Standard VGA
1613 case 0x0a: // Standard VGA
1614 case 0x0b: // Standard VGA
1615 case 0x0c: // Standard VGA
1616 case 0x0d: // Standard VGA
1617 case 0x0e: // Standard VGA
1618 case 0x0f: // Standard VGA
1619 case 0x10: // Standard VGA
1620 case 0x11: // Standard VGA
1621 case 0x12: // Standard VGA
1622 case 0x13: // Standard VGA
1623 case 0x14: // Standard VGA
1624 case 0x15: // Standard VGA
1625 case 0x16: // Standard VGA
1626 case 0x17: // Standard VGA
1627 case 0x18: // Standard VGA
1628 return CIRRUS_HOOK_NOT_HANDLED
;
1629 case 0x24: // Attribute Controller Toggle Readback (R)
1630 *reg_value
= (s
->ar_flip_flop
<< 7);
1632 case 0x19: // Interlace End
1633 case 0x1a: // Miscellaneous Control
1634 case 0x1b: // Extended Display Control
1635 case 0x1c: // Sync Adjust and Genlock
1636 case 0x1d: // Overlay Extended Control
1637 case 0x22: // Graphics Data Latches Readback (R)
1638 case 0x25: // Part Status
1639 case 0x27: // Part ID (R)
1640 *reg_value
= s
->cr
[reg_index
];
1642 case 0x26: // Attribute Controller Index Readback (R)
1643 *reg_value
= s
->ar_index
& 0x3f;
1647 printf("cirrus: inport cr_index %02x\n", reg_index
);
1653 return CIRRUS_HOOK_HANDLED
;
1657 cirrus_hook_write_cr(CirrusVGAState
* s
, unsigned reg_index
, int reg_value
)
1659 switch (reg_index
) {
1660 case 0x00: // Standard VGA
1661 case 0x01: // Standard VGA
1662 case 0x02: // Standard VGA
1663 case 0x03: // Standard VGA
1664 case 0x04: // Standard VGA
1665 case 0x05: // Standard VGA
1666 case 0x06: // Standard VGA
1667 case 0x07: // Standard VGA
1668 case 0x08: // Standard VGA
1669 case 0x09: // Standard VGA
1670 case 0x0a: // Standard VGA
1671 case 0x0b: // Standard VGA
1672 case 0x0c: // Standard VGA
1673 case 0x0d: // Standard VGA
1674 case 0x0e: // Standard VGA
1675 case 0x0f: // Standard VGA
1676 case 0x10: // Standard VGA
1677 case 0x11: // Standard VGA
1678 case 0x12: // Standard VGA
1679 case 0x13: // Standard VGA
1680 case 0x14: // Standard VGA
1681 case 0x15: // Standard VGA
1682 case 0x16: // Standard VGA
1683 case 0x17: // Standard VGA
1684 case 0x18: // Standard VGA
1685 return CIRRUS_HOOK_NOT_HANDLED
;
1686 case 0x19: // Interlace End
1687 case 0x1a: // Miscellaneous Control
1688 case 0x1b: // Extended Display Control
1689 case 0x1c: // Sync Adjust and Genlock
1690 case 0x1d: // Overlay Extended Control
1691 s
->cr
[reg_index
] = reg_value
;
1693 printf("cirrus: handled outport cr_index %02x, cr_value %02x\n",
1694 reg_index
, reg_value
);
1697 case 0x22: // Graphics Data Latches Readback (R)
1698 case 0x24: // Attribute Controller Toggle Readback (R)
1699 case 0x26: // Attribute Controller Index Readback (R)
1700 case 0x27: // Part ID (R)
1702 case 0x25: // Part Status
1705 printf("cirrus: outport cr_index %02x, cr_value %02x\n", reg_index
,
1711 return CIRRUS_HOOK_HANDLED
;
1714 /***************************************
1716 * memory-mapped I/O (bitblt)
1718 ***************************************/
1720 static uint8_t cirrus_mmio_blt_read(CirrusVGAState
* s
, unsigned address
)
1725 case (CIRRUS_MMIO_BLTBGCOLOR
+ 0):
1726 cirrus_hook_read_gr(s
, 0x00, &value
);
1728 case (CIRRUS_MMIO_BLTBGCOLOR
+ 1):
1729 cirrus_hook_read_gr(s
, 0x10, &value
);
1731 case (CIRRUS_MMIO_BLTBGCOLOR
+ 2):
1732 cirrus_hook_read_gr(s
, 0x12, &value
);
1734 case (CIRRUS_MMIO_BLTBGCOLOR
+ 3):
1735 cirrus_hook_read_gr(s
, 0x14, &value
);
1737 case (CIRRUS_MMIO_BLTFGCOLOR
+ 0):
1738 cirrus_hook_read_gr(s
, 0x01, &value
);
1740 case (CIRRUS_MMIO_BLTFGCOLOR
+ 1):
1741 cirrus_hook_read_gr(s
, 0x11, &value
);
1743 case (CIRRUS_MMIO_BLTFGCOLOR
+ 2):
1744 cirrus_hook_read_gr(s
, 0x13, &value
);
1746 case (CIRRUS_MMIO_BLTFGCOLOR
+ 3):
1747 cirrus_hook_read_gr(s
, 0x15, &value
);
1749 case (CIRRUS_MMIO_BLTWIDTH
+ 0):
1750 cirrus_hook_read_gr(s
, 0x20, &value
);
1752 case (CIRRUS_MMIO_BLTWIDTH
+ 1):
1753 cirrus_hook_read_gr(s
, 0x21, &value
);
1755 case (CIRRUS_MMIO_BLTHEIGHT
+ 0):
1756 cirrus_hook_read_gr(s
, 0x22, &value
);
1758 case (CIRRUS_MMIO_BLTHEIGHT
+ 1):
1759 cirrus_hook_read_gr(s
, 0x23, &value
);
1761 case (CIRRUS_MMIO_BLTDESTPITCH
+ 0):
1762 cirrus_hook_read_gr(s
, 0x24, &value
);
1764 case (CIRRUS_MMIO_BLTDESTPITCH
+ 1):
1765 cirrus_hook_read_gr(s
, 0x25, &value
);
1767 case (CIRRUS_MMIO_BLTSRCPITCH
+ 0):
1768 cirrus_hook_read_gr(s
, 0x26, &value
);
1770 case (CIRRUS_MMIO_BLTSRCPITCH
+ 1):
1771 cirrus_hook_read_gr(s
, 0x27, &value
);
1773 case (CIRRUS_MMIO_BLTDESTADDR
+ 0):
1774 cirrus_hook_read_gr(s
, 0x28, &value
);
1776 case (CIRRUS_MMIO_BLTDESTADDR
+ 1):
1777 cirrus_hook_read_gr(s
, 0x29, &value
);
1779 case (CIRRUS_MMIO_BLTDESTADDR
+ 2):
1780 cirrus_hook_read_gr(s
, 0x2a, &value
);
1782 case (CIRRUS_MMIO_BLTSRCADDR
+ 0):
1783 cirrus_hook_read_gr(s
, 0x2c, &value
);
1785 case (CIRRUS_MMIO_BLTSRCADDR
+ 1):
1786 cirrus_hook_read_gr(s
, 0x2d, &value
);
1788 case (CIRRUS_MMIO_BLTSRCADDR
+ 2):
1789 cirrus_hook_read_gr(s
, 0x2e, &value
);
1791 case CIRRUS_MMIO_BLTWRITEMASK
:
1792 cirrus_hook_read_gr(s
, 0x2f, &value
);
1794 case CIRRUS_MMIO_BLTMODE
:
1795 cirrus_hook_read_gr(s
, 0x30, &value
);
1797 case CIRRUS_MMIO_BLTROP
:
1798 cirrus_hook_read_gr(s
, 0x32, &value
);
1800 case CIRRUS_MMIO_BLTMODEEXT
:
1801 cirrus_hook_read_gr(s
, 0x33, &value
);
1803 case (CIRRUS_MMIO_BLTTRANSPARENTCOLOR
+ 0):
1804 cirrus_hook_read_gr(s
, 0x34, &value
);
1806 case (CIRRUS_MMIO_BLTTRANSPARENTCOLOR
+ 1):
1807 cirrus_hook_read_gr(s
, 0x35, &value
);
1809 case (CIRRUS_MMIO_BLTTRANSPARENTCOLORMASK
+ 0):
1810 cirrus_hook_read_gr(s
, 0x38, &value
);
1812 case (CIRRUS_MMIO_BLTTRANSPARENTCOLORMASK
+ 1):
1813 cirrus_hook_read_gr(s
, 0x39, &value
);
1815 case CIRRUS_MMIO_BLTSTATUS
:
1816 cirrus_hook_read_gr(s
, 0x31, &value
);
1820 printf("cirrus: mmio read - address 0x%04x\n", address
);
1825 return (uint8_t) value
;
1828 static void cirrus_mmio_blt_write(CirrusVGAState
* s
, unsigned address
,
1832 case (CIRRUS_MMIO_BLTBGCOLOR
+ 0):
1833 cirrus_hook_write_gr(s
, 0x00, value
);
1835 case (CIRRUS_MMIO_BLTBGCOLOR
+ 1):
1836 cirrus_hook_write_gr(s
, 0x10, value
);
1838 case (CIRRUS_MMIO_BLTBGCOLOR
+ 2):
1839 cirrus_hook_write_gr(s
, 0x12, value
);
1841 case (CIRRUS_MMIO_BLTBGCOLOR
+ 3):
1842 cirrus_hook_write_gr(s
, 0x14, value
);
1844 case (CIRRUS_MMIO_BLTFGCOLOR
+ 0):
1845 cirrus_hook_write_gr(s
, 0x01, value
);
1847 case (CIRRUS_MMIO_BLTFGCOLOR
+ 1):
1848 cirrus_hook_write_gr(s
, 0x11, value
);
1850 case (CIRRUS_MMIO_BLTFGCOLOR
+ 2):
1851 cirrus_hook_write_gr(s
, 0x13, value
);
1853 case (CIRRUS_MMIO_BLTFGCOLOR
+ 3):
1854 cirrus_hook_write_gr(s
, 0x15, value
);
1856 case (CIRRUS_MMIO_BLTWIDTH
+ 0):
1857 cirrus_hook_write_gr(s
, 0x20, value
);
1859 case (CIRRUS_MMIO_BLTWIDTH
+ 1):
1860 cirrus_hook_write_gr(s
, 0x21, value
);
1862 case (CIRRUS_MMIO_BLTHEIGHT
+ 0):
1863 cirrus_hook_write_gr(s
, 0x22, value
);
1865 case (CIRRUS_MMIO_BLTHEIGHT
+ 1):
1866 cirrus_hook_write_gr(s
, 0x23, value
);
1868 case (CIRRUS_MMIO_BLTDESTPITCH
+ 0):
1869 cirrus_hook_write_gr(s
, 0x24, value
);
1871 case (CIRRUS_MMIO_BLTDESTPITCH
+ 1):
1872 cirrus_hook_write_gr(s
, 0x25, value
);
1874 case (CIRRUS_MMIO_BLTSRCPITCH
+ 0):
1875 cirrus_hook_write_gr(s
, 0x26, value
);
1877 case (CIRRUS_MMIO_BLTSRCPITCH
+ 1):
1878 cirrus_hook_write_gr(s
, 0x27, value
);
1880 case (CIRRUS_MMIO_BLTDESTADDR
+ 0):
1881 cirrus_hook_write_gr(s
, 0x28, value
);
1883 case (CIRRUS_MMIO_BLTDESTADDR
+ 1):
1884 cirrus_hook_write_gr(s
, 0x29, value
);
1886 case (CIRRUS_MMIO_BLTDESTADDR
+ 2):
1887 cirrus_hook_write_gr(s
, 0x2a, value
);
1889 case (CIRRUS_MMIO_BLTDESTADDR
+ 3):
1892 case (CIRRUS_MMIO_BLTSRCADDR
+ 0):
1893 cirrus_hook_write_gr(s
, 0x2c, value
);
1895 case (CIRRUS_MMIO_BLTSRCADDR
+ 1):
1896 cirrus_hook_write_gr(s
, 0x2d, value
);
1898 case (CIRRUS_MMIO_BLTSRCADDR
+ 2):
1899 cirrus_hook_write_gr(s
, 0x2e, value
);
1901 case CIRRUS_MMIO_BLTWRITEMASK
:
1902 cirrus_hook_write_gr(s
, 0x2f, value
);
1904 case CIRRUS_MMIO_BLTMODE
:
1905 cirrus_hook_write_gr(s
, 0x30, value
);
1907 case CIRRUS_MMIO_BLTROP
:
1908 cirrus_hook_write_gr(s
, 0x32, value
);
1910 case CIRRUS_MMIO_BLTMODEEXT
:
1911 cirrus_hook_write_gr(s
, 0x33, value
);
1913 case (CIRRUS_MMIO_BLTTRANSPARENTCOLOR
+ 0):
1914 cirrus_hook_write_gr(s
, 0x34, value
);
1916 case (CIRRUS_MMIO_BLTTRANSPARENTCOLOR
+ 1):
1917 cirrus_hook_write_gr(s
, 0x35, value
);
1919 case (CIRRUS_MMIO_BLTTRANSPARENTCOLORMASK
+ 0):
1920 cirrus_hook_write_gr(s
, 0x38, value
);
1922 case (CIRRUS_MMIO_BLTTRANSPARENTCOLORMASK
+ 1):
1923 cirrus_hook_write_gr(s
, 0x39, value
);
1925 case CIRRUS_MMIO_BLTSTATUS
:
1926 cirrus_hook_write_gr(s
, 0x31, value
);
1930 printf("cirrus: mmio write - addr 0x%04x val 0x%02x (ignored)\n",
1937 /***************************************
1941 * assume TARGET_PAGE_SIZE >= 16
1943 ***************************************/
1945 static void cirrus_mem_writeb_mode4and5_8bpp(CirrusVGAState
* s
,
1951 unsigned val
= mem_value
;
1954 dst
= s
->vram_ptr
+ (offset
&= s
->cirrus_addr_mask
);
1955 for (x
= 0; x
< 8; x
++) {
1957 *dst
= s
->cirrus_shadow_gr1
;
1958 } else if (mode
== 5) {
1959 *dst
= s
->cirrus_shadow_gr0
;
1964 cpu_physical_memory_set_dirty(s
->vram_offset
+ offset
);
1965 cpu_physical_memory_set_dirty(s
->vram_offset
+ offset
+ 7);
1968 static void cirrus_mem_writeb_mode4and5_16bpp(CirrusVGAState
* s
,
1974 unsigned val
= mem_value
;
1977 dst
= s
->vram_ptr
+ (offset
&= s
->cirrus_addr_mask
);
1978 for (x
= 0; x
< 8; x
++) {
1980 *dst
= s
->cirrus_shadow_gr1
;
1981 *(dst
+ 1) = s
->gr
[0x11];
1982 } else if (mode
== 5) {
1983 *dst
= s
->cirrus_shadow_gr0
;
1984 *(dst
+ 1) = s
->gr
[0x10];
1989 cpu_physical_memory_set_dirty(s
->vram_offset
+ offset
);
1990 cpu_physical_memory_set_dirty(s
->vram_offset
+ offset
+ 15);
1993 /***************************************
1995 * memory access between 0xa0000-0xbffff
1997 ***************************************/
1999 static uint32_t cirrus_vga_mem_readb(void *opaque
, target_phys_addr_t addr
)
2001 CirrusVGAState
*s
= opaque
;
2002 unsigned bank_index
;
2003 unsigned bank_offset
;
2006 if ((s
->sr
[0x07] & 0x01) == 0) {
2007 return vga_mem_readb(s
, addr
);
2012 if (addr
< 0x10000) {
2013 /* XXX handle bitblt */
2015 bank_index
= addr
>> 15;
2016 bank_offset
= addr
& 0x7fff;
2017 if (bank_offset
< s
->cirrus_bank_limit
[bank_index
]) {
2018 bank_offset
+= s
->cirrus_bank_base
[bank_index
];
2019 if ((s
->gr
[0x0B] & 0x14) == 0x14) {
2021 } else if (s
->gr
[0x0B] & 0x02) {
2024 bank_offset
&= s
->cirrus_addr_mask
;
2025 val
= *(s
->vram_ptr
+ bank_offset
);
2028 } else if (addr
>= 0x18000 && addr
< 0x18100) {
2029 /* memory-mapped I/O */
2031 if ((s
->sr
[0x17] & 0x44) == 0x04) {
2032 val
= cirrus_mmio_blt_read(s
, addr
& 0xff);
2037 printf("cirrus: mem_readb %06x\n", addr
);
2043 static uint32_t cirrus_vga_mem_readw(void *opaque
, target_phys_addr_t addr
)
2046 #ifdef TARGET_WORDS_BIGENDIAN
2047 v
= cirrus_vga_mem_readb(opaque
, addr
) << 8;
2048 v
|= cirrus_vga_mem_readb(opaque
, addr
+ 1);
2050 v
= cirrus_vga_mem_readb(opaque
, addr
);
2051 v
|= cirrus_vga_mem_readb(opaque
, addr
+ 1) << 8;
2056 static uint32_t cirrus_vga_mem_readl(void *opaque
, target_phys_addr_t addr
)
2059 #ifdef TARGET_WORDS_BIGENDIAN
2060 v
= cirrus_vga_mem_readb(opaque
, addr
) << 24;
2061 v
|= cirrus_vga_mem_readb(opaque
, addr
+ 1) << 16;
2062 v
|= cirrus_vga_mem_readb(opaque
, addr
+ 2) << 8;
2063 v
|= cirrus_vga_mem_readb(opaque
, addr
+ 3);
2065 v
= cirrus_vga_mem_readb(opaque
, addr
);
2066 v
|= cirrus_vga_mem_readb(opaque
, addr
+ 1) << 8;
2067 v
|= cirrus_vga_mem_readb(opaque
, addr
+ 2) << 16;
2068 v
|= cirrus_vga_mem_readb(opaque
, addr
+ 3) << 24;
2073 static void cirrus_vga_mem_writeb(void *opaque
, target_phys_addr_t addr
,
2076 CirrusVGAState
*s
= opaque
;
2077 unsigned bank_index
;
2078 unsigned bank_offset
;
2081 if ((s
->sr
[0x07] & 0x01) == 0) {
2082 vga_mem_writeb(s
, addr
, mem_value
);
2088 if (addr
< 0x10000) {
2089 if (s
->cirrus_srcptr
!= s
->cirrus_srcptr_end
) {
2091 *s
->cirrus_srcptr
++ = (uint8_t) mem_value
;
2092 if (s
->cirrus_srcptr
>= s
->cirrus_srcptr_end
) {
2093 cirrus_bitblt_cputovideo_next(s
);
2097 bank_index
= addr
>> 15;
2098 bank_offset
= addr
& 0x7fff;
2099 if (bank_offset
< s
->cirrus_bank_limit
[bank_index
]) {
2100 bank_offset
+= s
->cirrus_bank_base
[bank_index
];
2101 if ((s
->gr
[0x0B] & 0x14) == 0x14) {
2103 } else if (s
->gr
[0x0B] & 0x02) {
2106 bank_offset
&= s
->cirrus_addr_mask
;
2107 mode
= s
->gr
[0x05] & 0x7;
2108 if (mode
< 4 || mode
> 5 || ((s
->gr
[0x0B] & 0x4) == 0)) {
2109 *(s
->vram_ptr
+ bank_offset
) = mem_value
;
2110 cpu_physical_memory_set_dirty(s
->vram_offset
+
2113 if ((s
->gr
[0x0B] & 0x14) != 0x14) {
2114 cirrus_mem_writeb_mode4and5_8bpp(s
, mode
,
2118 cirrus_mem_writeb_mode4and5_16bpp(s
, mode
,
2125 } else if (addr
>= 0x18000 && addr
< 0x18100) {
2126 /* memory-mapped I/O */
2127 if ((s
->sr
[0x17] & 0x44) == 0x04) {
2128 cirrus_mmio_blt_write(s
, addr
& 0xff, mem_value
);
2132 printf("cirrus: mem_writeb %06x value %02x\n", addr
, mem_value
);
2137 static void cirrus_vga_mem_writew(void *opaque
, target_phys_addr_t addr
, uint32_t val
)
2139 #ifdef TARGET_WORDS_BIGENDIAN
2140 cirrus_vga_mem_writeb(opaque
, addr
, (val
>> 8) & 0xff);
2141 cirrus_vga_mem_writeb(opaque
, addr
+ 1, val
& 0xff);
2143 cirrus_vga_mem_writeb(opaque
, addr
, val
& 0xff);
2144 cirrus_vga_mem_writeb(opaque
, addr
+ 1, (val
>> 8) & 0xff);
2148 static void cirrus_vga_mem_writel(void *opaque
, target_phys_addr_t addr
, uint32_t val
)
2150 #ifdef TARGET_WORDS_BIGENDIAN
2151 cirrus_vga_mem_writeb(opaque
, addr
, (val
>> 24) & 0xff);
2152 cirrus_vga_mem_writeb(opaque
, addr
+ 1, (val
>> 16) & 0xff);
2153 cirrus_vga_mem_writeb(opaque
, addr
+ 2, (val
>> 8) & 0xff);
2154 cirrus_vga_mem_writeb(opaque
, addr
+ 3, val
& 0xff);
2156 cirrus_vga_mem_writeb(opaque
, addr
, val
& 0xff);
2157 cirrus_vga_mem_writeb(opaque
, addr
+ 1, (val
>> 8) & 0xff);
2158 cirrus_vga_mem_writeb(opaque
, addr
+ 2, (val
>> 16) & 0xff);
2159 cirrus_vga_mem_writeb(opaque
, addr
+ 3, (val
>> 24) & 0xff);
2163 static CPUReadMemoryFunc
*cirrus_vga_mem_read
[3] = {
2164 cirrus_vga_mem_readb
,
2165 cirrus_vga_mem_readw
,
2166 cirrus_vga_mem_readl
,
2169 static CPUWriteMemoryFunc
*cirrus_vga_mem_write
[3] = {
2170 cirrus_vga_mem_writeb
,
2171 cirrus_vga_mem_writew
,
2172 cirrus_vga_mem_writel
,
2175 /***************************************
2179 ***************************************/
2181 static inline void invalidate_cursor1(CirrusVGAState
*s
)
2183 if (s
->last_hw_cursor_size
) {
2184 vga_invalidate_scanlines((VGAState
*)s
,
2185 s
->last_hw_cursor_y
+ s
->last_hw_cursor_y_start
,
2186 s
->last_hw_cursor_y
+ s
->last_hw_cursor_y_end
);
2190 static inline void cirrus_cursor_compute_yrange(CirrusVGAState
*s
)
2194 int y
, y_min
, y_max
;
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;
2201 for(y
= 0; y
< 64; y
++) {
2202 content
= ((uint32_t *)src
)[0] |
2203 ((uint32_t *)src
)[1] |
2204 ((uint32_t *)src
)[2] |
2205 ((uint32_t *)src
)[3];
2215 src
+= (s
->sr
[0x13] & 0x3f) * 256;
2218 for(y
= 0; y
< 32; y
++) {
2219 content
= ((uint32_t *)src
)[0] |
2220 ((uint32_t *)(src
+ 128))[0];
2230 if (y_min
> y_max
) {
2231 s
->last_hw_cursor_y_start
= 0;
2232 s
->last_hw_cursor_y_end
= 0;
2234 s
->last_hw_cursor_y_start
= y_min
;
2235 s
->last_hw_cursor_y_end
= y_max
+ 1;
2239 /* NOTE: we do not currently handle the cursor bitmap change, so we
2240 update the cursor only if it moves. */
2241 static void cirrus_cursor_invalidate(VGAState
*s1
)
2243 CirrusVGAState
*s
= (CirrusVGAState
*)s1
;
2246 if (!s
->sr
[0x12] & CIRRUS_CURSOR_SHOW
) {
2249 if (s
->sr
[0x12] & CIRRUS_CURSOR_LARGE
)
2254 /* invalidate last cursor and new cursor if any change */
2255 if (s
->last_hw_cursor_size
!= size
||
2256 s
->last_hw_cursor_x
!= s
->hw_cursor_x
||
2257 s
->last_hw_cursor_y
!= s
->hw_cursor_y
) {
2259 invalidate_cursor1(s
);
2261 s
->last_hw_cursor_size
= size
;
2262 s
->last_hw_cursor_x
= s
->hw_cursor_x
;
2263 s
->last_hw_cursor_y
= s
->hw_cursor_y
;
2264 /* compute the real cursor min and max y */
2265 cirrus_cursor_compute_yrange(s
);
2266 invalidate_cursor1(s
);
2270 static void cirrus_cursor_draw_line(VGAState
*s1
, uint8_t *d1
, int scr_y
)
2272 CirrusVGAState
*s
= (CirrusVGAState
*)s1
;
2273 int w
, h
, bpp
, x1
, x2
, poffset
;
2274 unsigned int color0
, color1
;
2275 const uint8_t *palette
, *src
;
2278 if (!(s
->sr
[0x12] & CIRRUS_CURSOR_SHOW
))
2280 /* fast test to see if the cursor intersects with the scan line */
2281 if (s
->sr
[0x12] & CIRRUS_CURSOR_LARGE
) {
2286 if (scr_y
< s
->hw_cursor_y
||
2287 scr_y
>= (s
->hw_cursor_y
+ h
))
2290 src
= s
->vram_ptr
+ s
->real_vram_size
- 16 * 1024;
2291 if (s
->sr
[0x12] & CIRRUS_CURSOR_LARGE
) {
2292 src
+= (s
->sr
[0x13] & 0x3c) * 256;
2293 src
+= (scr_y
- s
->hw_cursor_y
) * 16;
2295 content
= ((uint32_t *)src
)[0] |
2296 ((uint32_t *)src
)[1] |
2297 ((uint32_t *)src
)[2] |
2298 ((uint32_t *)src
)[3];
2300 src
+= (s
->sr
[0x13] & 0x3f) * 256;
2301 src
+= (scr_y
- s
->hw_cursor_y
) * 4;
2303 content
= ((uint32_t *)src
)[0] |
2304 ((uint32_t *)(src
+ 128))[0];
2306 /* if nothing to draw, no need to continue */
2311 x1
= s
->hw_cursor_x
;
2312 if (x1
>= s
->last_scr_width
)
2314 x2
= s
->hw_cursor_x
+ w
;
2315 if (x2
> s
->last_scr_width
)
2316 x2
= s
->last_scr_width
;
2318 palette
= s
->cirrus_hidden_palette
;
2319 color0
= s
->rgb_to_pixel(c6_to_8(palette
[0x0 * 3]),
2320 c6_to_8(palette
[0x0 * 3 + 1]),
2321 c6_to_8(palette
[0x0 * 3 + 2]));
2322 color1
= s
->rgb_to_pixel(c6_to_8(palette
[0xf * 3]),
2323 c6_to_8(palette
[0xf * 3 + 1]),
2324 c6_to_8(palette
[0xf * 3 + 2]));
2325 bpp
= ((s
->ds
->depth
+ 7) >> 3);
2327 switch(s
->ds
->depth
) {
2331 vga_draw_cursor_line_8(d1
, src
, poffset
, w
, color0
, color1
, 0xff);
2334 vga_draw_cursor_line_16(d1
, src
, poffset
, w
, color0
, color1
, 0x7fff);
2337 vga_draw_cursor_line_16(d1
, src
, poffset
, w
, color0
, color1
, 0xffff);
2340 vga_draw_cursor_line_32(d1
, src
, poffset
, w
, color0
, color1
, 0xffffff);
2345 /***************************************
2349 ***************************************/
2351 static uint32_t cirrus_linear_readb(void *opaque
, target_phys_addr_t addr
)
2353 CirrusVGAState
*s
= (CirrusVGAState
*) opaque
;
2356 addr
&= s
->cirrus_addr_mask
;
2358 if (((s
->sr
[0x17] & 0x44) == 0x44) &&
2359 ((addr
& s
->linear_mmio_mask
) == s
->linear_mmio_mask
)) {
2360 /* memory-mapped I/O */
2361 ret
= cirrus_mmio_blt_read(s
, addr
& 0xff);
2363 /* XXX handle bitblt */
2367 if ((s
->gr
[0x0B] & 0x14) == 0x14) {
2369 } else if (s
->gr
[0x0B] & 0x02) {
2372 addr
&= s
->cirrus_addr_mask
;
2373 ret
= *(s
->vram_ptr
+ addr
);
2379 static uint32_t cirrus_linear_readw(void *opaque
, target_phys_addr_t addr
)
2382 #ifdef TARGET_WORDS_BIGENDIAN
2383 v
= cirrus_linear_readb(opaque
, addr
) << 8;
2384 v
|= cirrus_linear_readb(opaque
, addr
+ 1);
2386 v
= cirrus_linear_readb(opaque
, addr
);
2387 v
|= cirrus_linear_readb(opaque
, addr
+ 1) << 8;
2392 static uint32_t cirrus_linear_readl(void *opaque
, target_phys_addr_t addr
)
2395 #ifdef TARGET_WORDS_BIGENDIAN
2396 v
= cirrus_linear_readb(opaque
, addr
) << 24;
2397 v
|= cirrus_linear_readb(opaque
, addr
+ 1) << 16;
2398 v
|= cirrus_linear_readb(opaque
, addr
+ 2) << 8;
2399 v
|= cirrus_linear_readb(opaque
, addr
+ 3);
2401 v
= cirrus_linear_readb(opaque
, addr
);
2402 v
|= cirrus_linear_readb(opaque
, addr
+ 1) << 8;
2403 v
|= cirrus_linear_readb(opaque
, addr
+ 2) << 16;
2404 v
|= cirrus_linear_readb(opaque
, addr
+ 3) << 24;
2409 static void cirrus_linear_writeb(void *opaque
, target_phys_addr_t addr
,
2412 CirrusVGAState
*s
= (CirrusVGAState
*) opaque
;
2415 addr
&= s
->cirrus_addr_mask
;
2417 if (((s
->sr
[0x17] & 0x44) == 0x44) &&
2418 ((addr
& s
->linear_mmio_mask
) == s
->linear_mmio_mask
)) {
2419 /* memory-mapped I/O */
2420 cirrus_mmio_blt_write(s
, addr
& 0xff, val
);
2421 } else if (s
->cirrus_srcptr
!= s
->cirrus_srcptr_end
) {
2423 *s
->cirrus_srcptr
++ = (uint8_t) val
;
2424 if (s
->cirrus_srcptr
>= s
->cirrus_srcptr_end
) {
2425 cirrus_bitblt_cputovideo_next(s
);
2429 if ((s
->gr
[0x0B] & 0x14) == 0x14) {
2431 } else if (s
->gr
[0x0B] & 0x02) {
2434 addr
&= s
->cirrus_addr_mask
;
2436 mode
= s
->gr
[0x05] & 0x7;
2437 if (mode
< 4 || mode
> 5 || ((s
->gr
[0x0B] & 0x4) == 0)) {
2438 *(s
->vram_ptr
+ addr
) = (uint8_t) val
;
2439 cpu_physical_memory_set_dirty(s
->vram_offset
+ addr
);
2441 if ((s
->gr
[0x0B] & 0x14) != 0x14) {
2442 cirrus_mem_writeb_mode4and5_8bpp(s
, mode
, addr
, val
);
2444 cirrus_mem_writeb_mode4and5_16bpp(s
, mode
, addr
, val
);
2450 static void cirrus_linear_writew(void *opaque
, target_phys_addr_t addr
,
2453 #ifdef TARGET_WORDS_BIGENDIAN
2454 cirrus_linear_writeb(opaque
, addr
, (val
>> 8) & 0xff);
2455 cirrus_linear_writeb(opaque
, addr
+ 1, val
& 0xff);
2457 cirrus_linear_writeb(opaque
, addr
, val
& 0xff);
2458 cirrus_linear_writeb(opaque
, addr
+ 1, (val
>> 8) & 0xff);
2462 static void cirrus_linear_writel(void *opaque
, target_phys_addr_t addr
,
2465 #ifdef TARGET_WORDS_BIGENDIAN
2466 cirrus_linear_writeb(opaque
, addr
, (val
>> 24) & 0xff);
2467 cirrus_linear_writeb(opaque
, addr
+ 1, (val
>> 16) & 0xff);
2468 cirrus_linear_writeb(opaque
, addr
+ 2, (val
>> 8) & 0xff);
2469 cirrus_linear_writeb(opaque
, addr
+ 3, val
& 0xff);
2471 cirrus_linear_writeb(opaque
, addr
, val
& 0xff);
2472 cirrus_linear_writeb(opaque
, addr
+ 1, (val
>> 8) & 0xff);
2473 cirrus_linear_writeb(opaque
, addr
+ 2, (val
>> 16) & 0xff);
2474 cirrus_linear_writeb(opaque
, addr
+ 3, (val
>> 24) & 0xff);
2479 static CPUReadMemoryFunc
*cirrus_linear_read
[3] = {
2480 cirrus_linear_readb
,
2481 cirrus_linear_readw
,
2482 cirrus_linear_readl
,
2485 static CPUWriteMemoryFunc
*cirrus_linear_write
[3] = {
2486 cirrus_linear_writeb
,
2487 cirrus_linear_writew
,
2488 cirrus_linear_writel
,
2491 static void cirrus_linear_mem_writeb(void *opaque
, target_phys_addr_t addr
,
2494 CirrusVGAState
*s
= (CirrusVGAState
*) opaque
;
2496 addr
&= s
->cirrus_addr_mask
;
2497 *(s
->vram_ptr
+ addr
) = val
;
2498 cpu_physical_memory_set_dirty(s
->vram_offset
+ addr
);
2501 static void cirrus_linear_mem_writew(void *opaque
, target_phys_addr_t addr
,
2504 CirrusVGAState
*s
= (CirrusVGAState
*) opaque
;
2506 addr
&= s
->cirrus_addr_mask
;
2507 cpu_to_le16w((uint16_t *)(s
->vram_ptr
+ addr
), val
);
2508 cpu_physical_memory_set_dirty(s
->vram_offset
+ addr
);
2511 static void cirrus_linear_mem_writel(void *opaque
, target_phys_addr_t addr
,
2514 CirrusVGAState
*s
= (CirrusVGAState
*) opaque
;
2516 addr
&= s
->cirrus_addr_mask
;
2517 cpu_to_le32w((uint32_t *)(s
->vram_ptr
+ addr
), val
);
2518 cpu_physical_memory_set_dirty(s
->vram_offset
+ addr
);
2521 /***************************************
2523 * system to screen memory access
2525 ***************************************/
2528 static uint32_t cirrus_linear_bitblt_readb(void *opaque
, target_phys_addr_t addr
)
2532 /* XXX handle bitblt */
2537 static uint32_t cirrus_linear_bitblt_readw(void *opaque
, target_phys_addr_t addr
)
2540 #ifdef TARGET_WORDS_BIGENDIAN
2541 v
= cirrus_linear_bitblt_readb(opaque
, addr
) << 8;
2542 v
|= cirrus_linear_bitblt_readb(opaque
, addr
+ 1);
2544 v
= cirrus_linear_bitblt_readb(opaque
, addr
);
2545 v
|= cirrus_linear_bitblt_readb(opaque
, addr
+ 1) << 8;
2550 static uint32_t cirrus_linear_bitblt_readl(void *opaque
, target_phys_addr_t addr
)
2553 #ifdef TARGET_WORDS_BIGENDIAN
2554 v
= cirrus_linear_bitblt_readb(opaque
, addr
) << 24;
2555 v
|= cirrus_linear_bitblt_readb(opaque
, addr
+ 1) << 16;
2556 v
|= cirrus_linear_bitblt_readb(opaque
, addr
+ 2) << 8;
2557 v
|= cirrus_linear_bitblt_readb(opaque
, addr
+ 3);
2559 v
= cirrus_linear_bitblt_readb(opaque
, addr
);
2560 v
|= cirrus_linear_bitblt_readb(opaque
, addr
+ 1) << 8;
2561 v
|= cirrus_linear_bitblt_readb(opaque
, addr
+ 2) << 16;
2562 v
|= cirrus_linear_bitblt_readb(opaque
, addr
+ 3) << 24;
2567 static void cirrus_linear_bitblt_writeb(void *opaque
, target_phys_addr_t addr
,
2570 CirrusVGAState
*s
= (CirrusVGAState
*) opaque
;
2572 if (s
->cirrus_srcptr
!= s
->cirrus_srcptr_end
) {
2574 *s
->cirrus_srcptr
++ = (uint8_t) val
;
2575 if (s
->cirrus_srcptr
>= s
->cirrus_srcptr_end
) {
2576 cirrus_bitblt_cputovideo_next(s
);
2581 static void cirrus_linear_bitblt_writew(void *opaque
, target_phys_addr_t addr
,
2584 #ifdef TARGET_WORDS_BIGENDIAN
2585 cirrus_linear_bitblt_writeb(opaque
, addr
, (val
>> 8) & 0xff);
2586 cirrus_linear_bitblt_writeb(opaque
, addr
+ 1, val
& 0xff);
2588 cirrus_linear_bitblt_writeb(opaque
, addr
, val
& 0xff);
2589 cirrus_linear_bitblt_writeb(opaque
, addr
+ 1, (val
>> 8) & 0xff);
2593 static void cirrus_linear_bitblt_writel(void *opaque
, target_phys_addr_t addr
,
2596 #ifdef TARGET_WORDS_BIGENDIAN
2597 cirrus_linear_bitblt_writeb(opaque
, addr
, (val
>> 24) & 0xff);
2598 cirrus_linear_bitblt_writeb(opaque
, addr
+ 1, (val
>> 16) & 0xff);
2599 cirrus_linear_bitblt_writeb(opaque
, addr
+ 2, (val
>> 8) & 0xff);
2600 cirrus_linear_bitblt_writeb(opaque
, addr
+ 3, val
& 0xff);
2602 cirrus_linear_bitblt_writeb(opaque
, addr
, val
& 0xff);
2603 cirrus_linear_bitblt_writeb(opaque
, addr
+ 1, (val
>> 8) & 0xff);
2604 cirrus_linear_bitblt_writeb(opaque
, addr
+ 2, (val
>> 16) & 0xff);
2605 cirrus_linear_bitblt_writeb(opaque
, addr
+ 3, (val
>> 24) & 0xff);
2610 static CPUReadMemoryFunc
*cirrus_linear_bitblt_read
[3] = {
2611 cirrus_linear_bitblt_readb
,
2612 cirrus_linear_bitblt_readw
,
2613 cirrus_linear_bitblt_readl
,
2616 static CPUWriteMemoryFunc
*cirrus_linear_bitblt_write
[3] = {
2617 cirrus_linear_bitblt_writeb
,
2618 cirrus_linear_bitblt_writew
,
2619 cirrus_linear_bitblt_writel
,
2622 /* Compute the memory access functions */
2623 static void cirrus_update_memory_access(CirrusVGAState
*s
)
2627 if ((s
->sr
[0x17] & 0x44) == 0x44) {
2629 } else if (s
->cirrus_srcptr
!= s
->cirrus_srcptr_end
) {
2632 if ((s
->gr
[0x0B] & 0x14) == 0x14) {
2634 } else if (s
->gr
[0x0B] & 0x02) {
2638 mode
= s
->gr
[0x05] & 0x7;
2639 if (mode
< 4 || mode
> 5 || ((s
->gr
[0x0B] & 0x4) == 0)) {
2640 s
->cirrus_linear_write
[0] = cirrus_linear_mem_writeb
;
2641 s
->cirrus_linear_write
[1] = cirrus_linear_mem_writew
;
2642 s
->cirrus_linear_write
[2] = cirrus_linear_mem_writel
;
2645 s
->cirrus_linear_write
[0] = cirrus_linear_writeb
;
2646 s
->cirrus_linear_write
[1] = cirrus_linear_writew
;
2647 s
->cirrus_linear_write
[2] = cirrus_linear_writel
;
2655 static uint32_t vga_ioport_read(void *opaque
, uint32_t addr
)
2657 CirrusVGAState
*s
= opaque
;
2660 /* check port range access depending on color/monochrome mode */
2661 if ((addr
>= 0x3b0 && addr
<= 0x3bf && (s
->msr
& MSR_COLOR_EMULATION
))
2662 || (addr
>= 0x3d0 && addr
<= 0x3df
2663 && !(s
->msr
& MSR_COLOR_EMULATION
))) {
2668 if (s
->ar_flip_flop
== 0) {
2675 index
= s
->ar_index
& 0x1f;
2688 if (cirrus_hook_read_sr(s
, s
->sr_index
, &val
))
2690 val
= s
->sr
[s
->sr_index
];
2691 #ifdef DEBUG_VGA_REG
2692 printf("vga: read SR%x = 0x%02x\n", s
->sr_index
, val
);
2696 cirrus_read_hidden_dac(s
, &val
);
2702 val
= s
->dac_write_index
;
2703 s
->cirrus_hidden_dac_lockindex
= 0;
2706 if (cirrus_hook_read_palette(s
, &val
))
2708 val
= s
->palette
[s
->dac_read_index
* 3 + s
->dac_sub_index
];
2709 if (++s
->dac_sub_index
== 3) {
2710 s
->dac_sub_index
= 0;
2711 s
->dac_read_index
++;
2724 if (cirrus_hook_read_gr(s
, s
->gr_index
, &val
))
2726 val
= s
->gr
[s
->gr_index
];
2727 #ifdef DEBUG_VGA_REG
2728 printf("vga: read GR%x = 0x%02x\n", s
->gr_index
, val
);
2737 if (cirrus_hook_read_cr(s
, s
->cr_index
, &val
))
2739 val
= s
->cr
[s
->cr_index
];
2740 #ifdef DEBUG_VGA_REG
2741 printf("vga: read CR%x = 0x%02x\n", s
->cr_index
, val
);
2746 /* just toggle to fool polling */
2747 s
->st01
^= ST01_V_RETRACE
| ST01_DISP_ENABLE
;
2749 s
->ar_flip_flop
= 0;
2756 #if defined(DEBUG_VGA)
2757 printf("VGA: read addr=0x%04x data=0x%02x\n", addr
, val
);
2762 static void vga_ioport_write(void *opaque
, uint32_t addr
, uint32_t val
)
2764 CirrusVGAState
*s
= opaque
;
2767 /* check port range access depending on color/monochrome mode */
2768 if ((addr
>= 0x3b0 && addr
<= 0x3bf && (s
->msr
& MSR_COLOR_EMULATION
))
2769 || (addr
>= 0x3d0 && addr
<= 0x3df
2770 && !(s
->msr
& MSR_COLOR_EMULATION
)))
2774 printf("VGA: write addr=0x%04x data=0x%02x\n", addr
, val
);
2779 if (s
->ar_flip_flop
== 0) {
2783 index
= s
->ar_index
& 0x1f;
2786 s
->ar
[index
] = val
& 0x3f;
2789 s
->ar
[index
] = val
& ~0x10;
2795 s
->ar
[index
] = val
& ~0xc0;
2798 s
->ar
[index
] = val
& ~0xf0;
2801 s
->ar
[index
] = val
& ~0xf0;
2807 s
->ar_flip_flop
^= 1;
2810 s
->msr
= val
& ~0x10;
2816 if (cirrus_hook_write_sr(s
, s
->sr_index
, val
))
2818 #ifdef DEBUG_VGA_REG
2819 printf("vga: write SR%x = 0x%02x\n", s
->sr_index
, val
);
2821 s
->sr
[s
->sr_index
] = val
& sr_mask
[s
->sr_index
];
2824 cirrus_write_hidden_dac(s
, val
);
2827 s
->dac_read_index
= val
;
2828 s
->dac_sub_index
= 0;
2832 s
->dac_write_index
= val
;
2833 s
->dac_sub_index
= 0;
2837 if (cirrus_hook_write_palette(s
, val
))
2839 s
->dac_cache
[s
->dac_sub_index
] = val
;
2840 if (++s
->dac_sub_index
== 3) {
2841 memcpy(&s
->palette
[s
->dac_write_index
* 3], s
->dac_cache
, 3);
2842 s
->dac_sub_index
= 0;
2843 s
->dac_write_index
++;
2850 if (cirrus_hook_write_gr(s
, s
->gr_index
, val
))
2852 #ifdef DEBUG_VGA_REG
2853 printf("vga: write GR%x = 0x%02x\n", s
->gr_index
, val
);
2855 s
->gr
[s
->gr_index
] = val
& gr_mask
[s
->gr_index
];
2863 if (cirrus_hook_write_cr(s
, s
->cr_index
, val
))
2865 #ifdef DEBUG_VGA_REG
2866 printf("vga: write CR%x = 0x%02x\n", s
->cr_index
, val
);
2868 /* handle CR0-7 protection */
2869 if ((s
->cr
[0x11] & 0x80) && s
->cr_index
<= 7) {
2870 /* can always write bit 4 of CR7 */
2871 if (s
->cr_index
== 7)
2872 s
->cr
[7] = (s
->cr
[7] & ~0x10) | (val
& 0x10);
2875 switch (s
->cr_index
) {
2876 case 0x01: /* horizontal display end */
2881 case 0x12: /* vertical display end */
2882 s
->cr
[s
->cr_index
] = val
;
2886 s
->cr
[s
->cr_index
] = val
;
2892 s
->fcr
= val
& 0x10;
2897 /***************************************
2899 * memory-mapped I/O access
2901 ***************************************/
2903 static uint32_t cirrus_mmio_readb(void *opaque
, target_phys_addr_t addr
)
2905 CirrusVGAState
*s
= (CirrusVGAState
*) opaque
;
2907 addr
&= CIRRUS_PNPMMIO_SIZE
- 1;
2909 if (addr
>= 0x100) {
2910 return cirrus_mmio_blt_read(s
, addr
- 0x100);
2912 return vga_ioport_read(s
, addr
+ 0x3c0);
2916 static uint32_t cirrus_mmio_readw(void *opaque
, target_phys_addr_t addr
)
2919 #ifdef TARGET_WORDS_BIGENDIAN
2920 v
= cirrus_mmio_readb(opaque
, addr
) << 8;
2921 v
|= cirrus_mmio_readb(opaque
, addr
+ 1);
2923 v
= cirrus_mmio_readb(opaque
, addr
);
2924 v
|= cirrus_mmio_readb(opaque
, addr
+ 1) << 8;
2929 static uint32_t cirrus_mmio_readl(void *opaque
, target_phys_addr_t addr
)
2932 #ifdef TARGET_WORDS_BIGENDIAN
2933 v
= cirrus_mmio_readb(opaque
, addr
) << 24;
2934 v
|= cirrus_mmio_readb(opaque
, addr
+ 1) << 16;
2935 v
|= cirrus_mmio_readb(opaque
, addr
+ 2) << 8;
2936 v
|= cirrus_mmio_readb(opaque
, addr
+ 3);
2938 v
= cirrus_mmio_readb(opaque
, addr
);
2939 v
|= cirrus_mmio_readb(opaque
, addr
+ 1) << 8;
2940 v
|= cirrus_mmio_readb(opaque
, addr
+ 2) << 16;
2941 v
|= cirrus_mmio_readb(opaque
, addr
+ 3) << 24;
2946 static void cirrus_mmio_writeb(void *opaque
, target_phys_addr_t addr
,
2949 CirrusVGAState
*s
= (CirrusVGAState
*) opaque
;
2951 addr
&= CIRRUS_PNPMMIO_SIZE
- 1;
2953 if (addr
>= 0x100) {
2954 cirrus_mmio_blt_write(s
, addr
- 0x100, val
);
2956 vga_ioport_write(s
, addr
+ 0x3c0, val
);
2960 static void cirrus_mmio_writew(void *opaque
, target_phys_addr_t addr
,
2963 #ifdef TARGET_WORDS_BIGENDIAN
2964 cirrus_mmio_writeb(opaque
, addr
, (val
>> 8) & 0xff);
2965 cirrus_mmio_writeb(opaque
, addr
+ 1, val
& 0xff);
2967 cirrus_mmio_writeb(opaque
, addr
, val
& 0xff);
2968 cirrus_mmio_writeb(opaque
, addr
+ 1, (val
>> 8) & 0xff);
2972 static void cirrus_mmio_writel(void *opaque
, target_phys_addr_t addr
,
2975 #ifdef TARGET_WORDS_BIGENDIAN
2976 cirrus_mmio_writeb(opaque
, addr
, (val
>> 24) & 0xff);
2977 cirrus_mmio_writeb(opaque
, addr
+ 1, (val
>> 16) & 0xff);
2978 cirrus_mmio_writeb(opaque
, addr
+ 2, (val
>> 8) & 0xff);
2979 cirrus_mmio_writeb(opaque
, addr
+ 3, val
& 0xff);
2981 cirrus_mmio_writeb(opaque
, addr
, val
& 0xff);
2982 cirrus_mmio_writeb(opaque
, addr
+ 1, (val
>> 8) & 0xff);
2983 cirrus_mmio_writeb(opaque
, addr
+ 2, (val
>> 16) & 0xff);
2984 cirrus_mmio_writeb(opaque
, addr
+ 3, (val
>> 24) & 0xff);
2989 static CPUReadMemoryFunc
*cirrus_mmio_read
[3] = {
2995 static CPUWriteMemoryFunc
*cirrus_mmio_write
[3] = {
3001 /* load/save state */
3003 static void cirrus_vga_save(QEMUFile
*f
, void *opaque
)
3005 CirrusVGAState
*s
= opaque
;
3008 pci_device_save(s
->pci_dev
, f
);
3010 qemu_put_be32s(f
, &s
->latch
);
3011 qemu_put_8s(f
, &s
->sr_index
);
3012 qemu_put_buffer(f
, s
->sr
, 256);
3013 qemu_put_8s(f
, &s
->gr_index
);
3014 qemu_put_8s(f
, &s
->cirrus_shadow_gr0
);
3015 qemu_put_8s(f
, &s
->cirrus_shadow_gr1
);
3016 qemu_put_buffer(f
, s
->gr
+ 2, 254);
3017 qemu_put_8s(f
, &s
->ar_index
);
3018 qemu_put_buffer(f
, s
->ar
, 21);
3019 qemu_put_be32(f
, s
->ar_flip_flop
);
3020 qemu_put_8s(f
, &s
->cr_index
);
3021 qemu_put_buffer(f
, s
->cr
, 256);
3022 qemu_put_8s(f
, &s
->msr
);
3023 qemu_put_8s(f
, &s
->fcr
);
3024 qemu_put_8s(f
, &s
->st00
);
3025 qemu_put_8s(f
, &s
->st01
);
3027 qemu_put_8s(f
, &s
->dac_state
);
3028 qemu_put_8s(f
, &s
->dac_sub_index
);
3029 qemu_put_8s(f
, &s
->dac_read_index
);
3030 qemu_put_8s(f
, &s
->dac_write_index
);
3031 qemu_put_buffer(f
, s
->dac_cache
, 3);
3032 qemu_put_buffer(f
, s
->palette
, 768);
3034 qemu_put_be32(f
, s
->bank_offset
);
3036 qemu_put_8s(f
, &s
->cirrus_hidden_dac_lockindex
);
3037 qemu_put_8s(f
, &s
->cirrus_hidden_dac_data
);
3039 qemu_put_be32s(f
, &s
->hw_cursor_x
);
3040 qemu_put_be32s(f
, &s
->hw_cursor_y
);
3041 /* XXX: we do not save the bitblt state - we assume we do not save
3042 the state when the blitter is active */
3045 static int cirrus_vga_load(QEMUFile
*f
, void *opaque
, int version_id
)
3047 CirrusVGAState
*s
= opaque
;
3053 if (s
->pci_dev
&& version_id
>= 2) {
3054 ret
= pci_device_load(s
->pci_dev
, f
);
3059 qemu_get_be32s(f
, &s
->latch
);
3060 qemu_get_8s(f
, &s
->sr_index
);
3061 qemu_get_buffer(f
, s
->sr
, 256);
3062 qemu_get_8s(f
, &s
->gr_index
);
3063 qemu_get_8s(f
, &s
->cirrus_shadow_gr0
);
3064 qemu_get_8s(f
, &s
->cirrus_shadow_gr1
);
3065 s
->gr
[0x00] = s
->cirrus_shadow_gr0
& 0x0f;
3066 s
->gr
[0x01] = s
->cirrus_shadow_gr1
& 0x0f;
3067 qemu_get_buffer(f
, s
->gr
+ 2, 254);
3068 qemu_get_8s(f
, &s
->ar_index
);
3069 qemu_get_buffer(f
, s
->ar
, 21);
3070 s
->ar_flip_flop
=qemu_get_be32(f
);
3071 qemu_get_8s(f
, &s
->cr_index
);
3072 qemu_get_buffer(f
, s
->cr
, 256);
3073 qemu_get_8s(f
, &s
->msr
);
3074 qemu_get_8s(f
, &s
->fcr
);
3075 qemu_get_8s(f
, &s
->st00
);
3076 qemu_get_8s(f
, &s
->st01
);
3078 qemu_get_8s(f
, &s
->dac_state
);
3079 qemu_get_8s(f
, &s
->dac_sub_index
);
3080 qemu_get_8s(f
, &s
->dac_read_index
);
3081 qemu_get_8s(f
, &s
->dac_write_index
);
3082 qemu_get_buffer(f
, s
->dac_cache
, 3);
3083 qemu_get_buffer(f
, s
->palette
, 768);
3085 s
->bank_offset
=qemu_get_be32(f
);
3087 qemu_get_8s(f
, &s
->cirrus_hidden_dac_lockindex
);
3088 qemu_get_8s(f
, &s
->cirrus_hidden_dac_data
);
3090 qemu_get_be32s(f
, &s
->hw_cursor_x
);
3091 qemu_get_be32s(f
, &s
->hw_cursor_y
);
3094 s
->graphic_mode
= -1;
3095 cirrus_update_bank_ptr(s
, 0);
3096 cirrus_update_bank_ptr(s
, 1);
3100 /***************************************
3104 ***************************************/
3106 static void cirrus_init_common(CirrusVGAState
* s
, int device_id
, int is_pci
)
3108 int vga_io_memory
, i
;
3113 for(i
= 0;i
< 256; i
++)
3114 rop_to_index
[i
] = CIRRUS_ROP_NOP_INDEX
; /* nop rop */
3115 rop_to_index
[CIRRUS_ROP_0
] = 0;
3116 rop_to_index
[CIRRUS_ROP_SRC_AND_DST
] = 1;
3117 rop_to_index
[CIRRUS_ROP_NOP
] = 2;
3118 rop_to_index
[CIRRUS_ROP_SRC_AND_NOTDST
] = 3;
3119 rop_to_index
[CIRRUS_ROP_NOTDST
] = 4;
3120 rop_to_index
[CIRRUS_ROP_SRC
] = 5;
3121 rop_to_index
[CIRRUS_ROP_1
] = 6;
3122 rop_to_index
[CIRRUS_ROP_NOTSRC_AND_DST
] = 7;
3123 rop_to_index
[CIRRUS_ROP_SRC_XOR_DST
] = 8;
3124 rop_to_index
[CIRRUS_ROP_SRC_OR_DST
] = 9;
3125 rop_to_index
[CIRRUS_ROP_NOTSRC_OR_NOTDST
] = 10;
3126 rop_to_index
[CIRRUS_ROP_SRC_NOTXOR_DST
] = 11;
3127 rop_to_index
[CIRRUS_ROP_SRC_OR_NOTDST
] = 12;
3128 rop_to_index
[CIRRUS_ROP_NOTSRC
] = 13;
3129 rop_to_index
[CIRRUS_ROP_NOTSRC_OR_DST
] = 14;
3130 rop_to_index
[CIRRUS_ROP_NOTSRC_AND_NOTDST
] = 15;
3133 register_ioport_write(0x3c0, 16, 1, vga_ioport_write
, s
);
3135 register_ioport_write(0x3b4, 2, 1, vga_ioport_write
, s
);
3136 register_ioport_write(0x3d4, 2, 1, vga_ioport_write
, s
);
3137 register_ioport_write(0x3ba, 1, 1, vga_ioport_write
, s
);
3138 register_ioport_write(0x3da, 1, 1, vga_ioport_write
, s
);
3140 register_ioport_read(0x3c0, 16, 1, vga_ioport_read
, s
);
3142 register_ioport_read(0x3b4, 2, 1, vga_ioport_read
, s
);
3143 register_ioport_read(0x3d4, 2, 1, vga_ioport_read
, s
);
3144 register_ioport_read(0x3ba, 1, 1, vga_ioport_read
, s
);
3145 register_ioport_read(0x3da, 1, 1, vga_ioport_read
, s
);
3147 vga_io_memory
= cpu_register_io_memory(0, cirrus_vga_mem_read
,
3148 cirrus_vga_mem_write
, s
);
3149 cpu_register_physical_memory(isa_mem_base
+ 0x000a0000, 0x20000,
3153 if (device_id
== CIRRUS_ID_CLGD5446
) {
3154 /* 4MB 64 bit memory config, always PCI */
3155 s
->sr
[0x1F] = 0x2d; // MemClock
3156 s
->gr
[0x18] = 0x0f; // fastest memory configuration
3160 s
->sr
[0x15] = 0x04; /* memory size, 3=2MB, 4=4MB */
3161 s
->real_vram_size
= 4096 * 1024;
3165 s
->sr
[0x15] = 0x03; /* memory size, 3=2MB, 4=4MB */
3166 s
->real_vram_size
= 2048 * 1024;
3169 s
->sr
[0x1F] = 0x22; // MemClock
3170 s
->sr
[0x0F] = CIRRUS_MEMSIZE_2M
;
3172 s
->sr
[0x17] = CIRRUS_BUSTYPE_PCI
;
3174 s
->sr
[0x17] = CIRRUS_BUSTYPE_ISA
;
3175 s
->real_vram_size
= 2048 * 1024;
3176 s
->sr
[0x15] = 0x03; /* memory size, 3=2MB, 4=4MB */
3178 s
->cr
[0x27] = device_id
;
3180 /* Win2K seems to assume that the pattern buffer is at 0xff
3182 memset(s
->vram_ptr
, 0xff, s
->real_vram_size
);
3184 s
->cirrus_hidden_dac_lockindex
= 5;
3185 s
->cirrus_hidden_dac_data
= 0;
3187 /* I/O handler for LFB */
3188 s
->cirrus_linear_io_addr
=
3189 cpu_register_io_memory(0, cirrus_linear_read
, cirrus_linear_write
,
3191 s
->cirrus_linear_write
= cpu_get_io_memory_write(s
->cirrus_linear_io_addr
);
3193 /* I/O handler for LFB */
3194 s
->cirrus_linear_bitblt_io_addr
=
3195 cpu_register_io_memory(0, cirrus_linear_bitblt_read
, cirrus_linear_bitblt_write
,
3198 /* I/O handler for memory-mapped I/O */
3199 s
->cirrus_mmio_io_addr
=
3200 cpu_register_io_memory(0, cirrus_mmio_read
, cirrus_mmio_write
, s
);
3202 /* XXX: s->vram_size must be a power of two */
3203 s
->cirrus_addr_mask
= s
->real_vram_size
- 1;
3204 s
->linear_mmio_mask
= s
->real_vram_size
- 256;
3206 s
->get_bpp
= cirrus_get_bpp
;
3207 s
->get_offsets
= cirrus_get_offsets
;
3208 s
->get_resolution
= cirrus_get_resolution
;
3209 s
->cursor_invalidate
= cirrus_cursor_invalidate
;
3210 s
->cursor_draw_line
= cirrus_cursor_draw_line
;
3212 register_savevm("cirrus_vga", 0, 2, cirrus_vga_save
, cirrus_vga_load
, s
);
3215 /***************************************
3219 ***************************************/
3221 void isa_cirrus_vga_init(DisplayState
*ds
, uint8_t *vga_ram_base
,
3222 unsigned long vga_ram_offset
, int vga_ram_size
)
3226 s
= qemu_mallocz(sizeof(CirrusVGAState
));
3228 vga_common_init((VGAState
*)s
,
3229 ds
, vga_ram_base
, vga_ram_offset
, vga_ram_size
);
3230 cirrus_init_common(s
, CIRRUS_ID_CLGD5430
, 0);
3231 s
->console
= graphic_console_init(s
->ds
, s
->update
, s
->invalidate
,
3232 s
->screen_dump
, s
->text_update
, s
);
3233 /* XXX ISA-LFB support */
3236 /***************************************
3240 ***************************************/
3242 static void cirrus_pci_lfb_map(PCIDevice
*d
, int region_num
,
3243 uint32_t addr
, uint32_t size
, int type
)
3245 CirrusVGAState
*s
= &((PCICirrusVGAState
*)d
)->cirrus_vga
;
3247 /* XXX: add byte swapping apertures */
3248 cpu_register_physical_memory(addr
, s
->vram_size
,
3249 s
->cirrus_linear_io_addr
);
3250 cpu_register_physical_memory(addr
+ 0x1000000, 0x400000,
3251 s
->cirrus_linear_bitblt_io_addr
);
3254 static void cirrus_pci_mmio_map(PCIDevice
*d
, int region_num
,
3255 uint32_t addr
, uint32_t size
, int type
)
3257 CirrusVGAState
*s
= &((PCICirrusVGAState
*)d
)->cirrus_vga
;
3259 cpu_register_physical_memory(addr
, CIRRUS_PNPMMIO_SIZE
,
3260 s
->cirrus_mmio_io_addr
);
3263 void pci_cirrus_vga_init(PCIBus
*bus
, DisplayState
*ds
, uint8_t *vga_ram_base
,
3264 unsigned long vga_ram_offset
, int vga_ram_size
)
3266 PCICirrusVGAState
*d
;
3271 device_id
= CIRRUS_ID_CLGD5446
;
3273 /* setup PCI configuration registers */
3274 d
= (PCICirrusVGAState
*)pci_register_device(bus
, "Cirrus VGA",
3275 sizeof(PCICirrusVGAState
),
3277 pci_conf
= d
->dev
.config
;
3278 pci_conf
[0x00] = (uint8_t) (PCI_VENDOR_CIRRUS
& 0xff);
3279 pci_conf
[0x01] = (uint8_t) (PCI_VENDOR_CIRRUS
>> 8);
3280 pci_conf
[0x02] = (uint8_t) (device_id
& 0xff);
3281 pci_conf
[0x03] = (uint8_t) (device_id
>> 8);
3282 pci_conf
[0x04] = PCI_COMMAND_IOACCESS
| PCI_COMMAND_MEMACCESS
;
3283 pci_conf
[0x0a] = PCI_CLASS_SUB_VGA
;
3284 pci_conf
[0x0b] = PCI_CLASS_BASE_DISPLAY
;
3285 pci_conf
[0x0e] = PCI_CLASS_HEADERTYPE_00h
;
3289 vga_common_init((VGAState
*)s
,
3290 ds
, vga_ram_base
, vga_ram_offset
, vga_ram_size
);
3291 cirrus_init_common(s
, device_id
, 1);
3293 s
->console
= graphic_console_init(s
->ds
, s
->update
, s
->invalidate
,
3294 s
->screen_dump
, s
->text_update
, s
);
3296 s
->pci_dev
= (PCIDevice
*)d
;
3298 /* setup memory space */
3300 /* memory #1 memory-mapped I/O */
3301 /* XXX: s->vram_size must be a power of two */
3302 pci_register_io_region((PCIDevice
*)d
, 0, 0x2000000,
3303 PCI_ADDRESS_SPACE_MEM_PREFETCH
, cirrus_pci_lfb_map
);
3304 if (device_id
== CIRRUS_ID_CLGD5446
) {
3305 pci_register_io_region((PCIDevice
*)d
, 1, CIRRUS_PNPMMIO_SIZE
,
3306 PCI_ADDRESS_SPACE_MEM
, cirrus_pci_mmio_map
);