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/
41 * - destination write mask support not complete (bits 5..7)
42 * - optimize linear mappings
43 * - optimize bitblt functions
46 //#define DEBUG_CIRRUS
47 //#define DEBUG_BITBLT
49 /***************************************
53 ***************************************/
55 #define qemu_MIN(a,b) ((a) < (b) ? (a) : (b))
58 #define CIRRUS_ID_CLGD5422 (0x23<<2)
59 #define CIRRUS_ID_CLGD5426 (0x24<<2)
60 #define CIRRUS_ID_CLGD5424 (0x25<<2)
61 #define CIRRUS_ID_CLGD5428 (0x26<<2)
62 #define CIRRUS_ID_CLGD5430 (0x28<<2)
63 #define CIRRUS_ID_CLGD5434 (0x2A<<2)
64 #define CIRRUS_ID_CLGD5436 (0x2B<<2)
65 #define CIRRUS_ID_CLGD5446 (0x2E<<2)
68 #define CIRRUS_SR7_BPP_VGA 0x00
69 #define CIRRUS_SR7_BPP_SVGA 0x01
70 #define CIRRUS_SR7_BPP_MASK 0x0e
71 #define CIRRUS_SR7_BPP_8 0x00
72 #define CIRRUS_SR7_BPP_16_DOUBLEVCLK 0x02
73 #define CIRRUS_SR7_BPP_24 0x04
74 #define CIRRUS_SR7_BPP_16 0x06
75 #define CIRRUS_SR7_BPP_32 0x08
76 #define CIRRUS_SR7_ISAADDR_MASK 0xe0
79 #define CIRRUS_MEMSIZE_512k 0x08
80 #define CIRRUS_MEMSIZE_1M 0x10
81 #define CIRRUS_MEMSIZE_2M 0x18
82 #define CIRRUS_MEMFLAGS_BANKSWITCH 0x80 // bank switching is enabled.
85 #define CIRRUS_CURSOR_SHOW 0x01
86 #define CIRRUS_CURSOR_HIDDENPEL 0x02
87 #define CIRRUS_CURSOR_LARGE 0x04 // 64x64 if set, 32x32 if clear
90 #define CIRRUS_BUSTYPE_VLBFAST 0x10
91 #define CIRRUS_BUSTYPE_PCI 0x20
92 #define CIRRUS_BUSTYPE_VLBSLOW 0x30
93 #define CIRRUS_BUSTYPE_ISA 0x38
94 #define CIRRUS_MMIO_ENABLE 0x04
95 #define CIRRUS_MMIO_USE_PCIADDR 0x40 // 0xb8000 if cleared.
96 #define CIRRUS_MEMSIZEEXT_DOUBLE 0x80
99 #define CIRRUS_BANKING_DUAL 0x01
100 #define CIRRUS_BANKING_GRANULARITY_16K 0x20 // set:16k, clear:4k
103 #define CIRRUS_BLTMODE_BACKWARDS 0x01
104 #define CIRRUS_BLTMODE_MEMSYSDEST 0x02
105 #define CIRRUS_BLTMODE_MEMSYSSRC 0x04
106 #define CIRRUS_BLTMODE_TRANSPARENTCOMP 0x08
107 #define CIRRUS_BLTMODE_PATTERNCOPY 0x40
108 #define CIRRUS_BLTMODE_COLOREXPAND 0x80
109 #define CIRRUS_BLTMODE_PIXELWIDTHMASK 0x30
110 #define CIRRUS_BLTMODE_PIXELWIDTH8 0x00
111 #define CIRRUS_BLTMODE_PIXELWIDTH16 0x10
112 #define CIRRUS_BLTMODE_PIXELWIDTH24 0x20
113 #define CIRRUS_BLTMODE_PIXELWIDTH32 0x30
116 #define CIRRUS_BLT_BUSY 0x01
117 #define CIRRUS_BLT_START 0x02
118 #define CIRRUS_BLT_RESET 0x04
119 #define CIRRUS_BLT_FIFOUSED 0x10
120 #define CIRRUS_BLT_AUTOSTART 0x80
123 #define CIRRUS_ROP_0 0x00
124 #define CIRRUS_ROP_SRC_AND_DST 0x05
125 #define CIRRUS_ROP_NOP 0x06
126 #define CIRRUS_ROP_SRC_AND_NOTDST 0x09
127 #define CIRRUS_ROP_NOTDST 0x0b
128 #define CIRRUS_ROP_SRC 0x0d
129 #define CIRRUS_ROP_1 0x0e
130 #define CIRRUS_ROP_NOTSRC_AND_DST 0x50
131 #define CIRRUS_ROP_SRC_XOR_DST 0x59
132 #define CIRRUS_ROP_SRC_OR_DST 0x6d
133 #define CIRRUS_ROP_NOTSRC_OR_NOTDST 0x90
134 #define CIRRUS_ROP_SRC_NOTXOR_DST 0x95
135 #define CIRRUS_ROP_SRC_OR_NOTDST 0xad
136 #define CIRRUS_ROP_NOTSRC 0xd0
137 #define CIRRUS_ROP_NOTSRC_OR_DST 0xd6
138 #define CIRRUS_ROP_NOTSRC_AND_NOTDST 0xda
140 #define CIRRUS_ROP_NOP_INDEX 2
141 #define CIRRUS_ROP_SRC_INDEX 5
144 #define CIRRUS_BLTMODEEXT_SOLIDFILL 0x04
145 #define CIRRUS_BLTMODEEXT_COLOREXPINV 0x02
146 #define CIRRUS_BLTMODEEXT_DWORDGRANULARITY 0x01
149 #define CIRRUS_MMIO_BLTBGCOLOR 0x00 // dword
150 #define CIRRUS_MMIO_BLTFGCOLOR 0x04 // dword
151 #define CIRRUS_MMIO_BLTWIDTH 0x08 // word
152 #define CIRRUS_MMIO_BLTHEIGHT 0x0a // word
153 #define CIRRUS_MMIO_BLTDESTPITCH 0x0c // word
154 #define CIRRUS_MMIO_BLTSRCPITCH 0x0e // word
155 #define CIRRUS_MMIO_BLTDESTADDR 0x10 // dword
156 #define CIRRUS_MMIO_BLTSRCADDR 0x14 // dword
157 #define CIRRUS_MMIO_BLTWRITEMASK 0x17 // byte
158 #define CIRRUS_MMIO_BLTMODE 0x18 // byte
159 #define CIRRUS_MMIO_BLTROP 0x1a // byte
160 #define CIRRUS_MMIO_BLTMODEEXT 0x1b // byte
161 #define CIRRUS_MMIO_BLTTRANSPARENTCOLOR 0x1c // word?
162 #define CIRRUS_MMIO_BLTTRANSPARENTCOLORMASK 0x20 // word?
163 #define CIRRUS_MMIO_LINEARDRAW_START_X 0x24 // word
164 #define CIRRUS_MMIO_LINEARDRAW_START_Y 0x26 // word
165 #define CIRRUS_MMIO_LINEARDRAW_END_X 0x28 // word
166 #define CIRRUS_MMIO_LINEARDRAW_END_Y 0x2a // word
167 #define CIRRUS_MMIO_LINEARDRAW_LINESTYLE_INC 0x2c // byte
168 #define CIRRUS_MMIO_LINEARDRAW_LINESTYLE_ROLLOVER 0x2d // byte
169 #define CIRRUS_MMIO_LINEARDRAW_LINESTYLE_MASK 0x2e // byte
170 #define CIRRUS_MMIO_LINEARDRAW_LINESTYLE_ACCUM 0x2f // byte
171 #define CIRRUS_MMIO_BRESENHAM_K1 0x30 // word
172 #define CIRRUS_MMIO_BRESENHAM_K3 0x32 // word
173 #define CIRRUS_MMIO_BRESENHAM_ERROR 0x34 // word
174 #define CIRRUS_MMIO_BRESENHAM_DELTA_MAJOR 0x36 // word
175 #define CIRRUS_MMIO_BRESENHAM_DIRECTION 0x38 // byte
176 #define CIRRUS_MMIO_LINEDRAW_MODE 0x39 // byte
177 #define CIRRUS_MMIO_BLTSTATUS 0x40 // byte
179 // PCI 0x00: vendor, 0x02: device
180 #define PCI_VENDOR_CIRRUS 0x1013
181 #define PCI_DEVICE_CLGD5462 0x00d0
182 #define PCI_DEVICE_CLGD5465 0x00d6
184 // PCI 0x04: command(word), 0x06(word): status
185 #define PCI_COMMAND_IOACCESS 0x0001
186 #define PCI_COMMAND_MEMACCESS 0x0002
187 #define PCI_COMMAND_BUSMASTER 0x0004
188 #define PCI_COMMAND_SPECIALCYCLE 0x0008
189 #define PCI_COMMAND_MEMWRITEINVALID 0x0010
190 #define PCI_COMMAND_PALETTESNOOPING 0x0020
191 #define PCI_COMMAND_PARITYDETECTION 0x0040
192 #define PCI_COMMAND_ADDRESSDATASTEPPING 0x0080
193 #define PCI_COMMAND_SERR 0x0100
194 #define PCI_COMMAND_BACKTOBACKTRANS 0x0200
195 // PCI 0x08, 0xff000000 (0x09-0x0b:class,0x08:rev)
196 #define PCI_CLASS_BASE_DISPLAY 0x03
197 // PCI 0x08, 0x00ff0000
198 #define PCI_CLASS_SUB_VGA 0x00
199 // PCI 0x0c, 0x00ff0000 (0x0c:cacheline,0x0d:latency,0x0e:headertype,0x0f:Built-in self test)
200 #define PCI_CLASS_HEADERTYPE_00h 0x00
201 // 0x10-0x3f (headertype 00h)
202 // PCI 0x10,0x14,0x18,0x1c,0x20,0x24: base address mapping registers
203 // 0x10: MEMBASE, 0x14: IOBASE(hard-coded in XFree86 3.x)
204 #define PCI_MAP_MEM 0x0
205 #define PCI_MAP_IO 0x1
206 #define PCI_MAP_MEM_ADDR_MASK (~0xf)
207 #define PCI_MAP_IO_ADDR_MASK (~0x3)
208 #define PCI_MAP_MEMFLAGS_32BIT 0x0
209 #define PCI_MAP_MEMFLAGS_32BIT_1M 0x1
210 #define PCI_MAP_MEMFLAGS_64BIT 0x4
211 #define PCI_MAP_MEMFLAGS_CACHEABLE 0x8
212 // PCI 0x28: cardbus CIS pointer
213 // PCI 0x2c: subsystem vendor id, 0x2e: subsystem id
214 // PCI 0x30: expansion ROM base address
215 #define PCI_ROMBIOS_ENABLED 0x1
216 // PCI 0x34: 0xffffff00=reserved, 0x000000ff=capabilities pointer
217 // PCI 0x38: reserved
218 // PCI 0x3c: 0x3c=int-line, 0x3d=int-pin, 0x3e=min-gnt, 0x3f=maax-lat
220 #define CIRRUS_PNPMMIO_SIZE 0x1000
223 /* I/O and memory hook */
224 #define CIRRUS_HOOK_NOT_HANDLED 0
225 #define CIRRUS_HOOK_HANDLED 1
227 #define BLTUNSAFE(s) \
229 ( /* check dst is within bounds */ \
230 (s)->cirrus_blt_height * (s)->cirrus_blt_dstpitch \
231 + ((s)->cirrus_blt_dstaddr & (s)->cirrus_addr_mask) > \
234 ( /* check src is within bounds */ \
235 (s)->cirrus_blt_height * (s)->cirrus_blt_srcpitch \
236 + ((s)->cirrus_blt_srcaddr & (s)->cirrus_addr_mask) > \
241 struct CirrusVGAState
;
242 typedef void (*cirrus_bitblt_rop_t
) (struct CirrusVGAState
*s
,
243 uint8_t * dst
, const uint8_t * src
,
244 int dstpitch
, int srcpitch
,
245 int bltwidth
, int bltheight
);
246 typedef void (*cirrus_fill_t
)(struct CirrusVGAState
*s
,
247 uint8_t *dst
, int dst_pitch
, int width
, int height
);
249 typedef struct CirrusVGAState
{
252 int cirrus_linear_io_addr
;
253 int cirrus_linear_bitblt_io_addr
;
254 int cirrus_mmio_io_addr
;
255 unsigned long cirrus_lfb_addr
;
256 unsigned long cirrus_lfb_end
;
257 uint32_t cirrus_addr_mask
;
258 uint32_t linear_mmio_mask
;
259 uint8_t cirrus_shadow_gr0
;
260 uint8_t cirrus_shadow_gr1
;
261 uint8_t cirrus_hidden_dac_lockindex
;
262 uint8_t cirrus_hidden_dac_data
;
263 uint32_t cirrus_bank_base
[2];
264 uint32_t cirrus_bank_limit
[2];
265 uint8_t cirrus_hidden_palette
[48];
266 uint32_t hw_cursor_x
;
267 uint32_t hw_cursor_y
;
268 int cirrus_blt_pixelwidth
;
269 int cirrus_blt_width
;
270 int cirrus_blt_height
;
271 int cirrus_blt_dstpitch
;
272 int cirrus_blt_srcpitch
;
273 uint32_t cirrus_blt_fgcol
;
274 uint32_t cirrus_blt_bgcol
;
275 uint32_t cirrus_blt_dstaddr
;
276 uint32_t cirrus_blt_srcaddr
;
277 uint8_t cirrus_blt_mode
;
278 uint8_t cirrus_blt_modeext
;
279 cirrus_bitblt_rop_t cirrus_rop
;
280 #define CIRRUS_BLTBUFSIZE (2048 * 4) /* one line width */
281 uint8_t cirrus_bltbuf
[CIRRUS_BLTBUFSIZE
];
282 uint8_t *cirrus_srcptr
;
283 uint8_t *cirrus_srcptr_end
;
284 uint32_t cirrus_srccounter
;
285 /* hwcursor display state */
286 int last_hw_cursor_size
;
287 int last_hw_cursor_x
;
288 int last_hw_cursor_y
;
289 int last_hw_cursor_y_start
;
290 int last_hw_cursor_y_end
;
291 int real_vram_size
; /* XXX: suppress that */
292 CPUWriteMemoryFunc
**cirrus_linear_write
;
295 typedef struct PCICirrusVGAState
{
297 CirrusVGAState cirrus_vga
;
300 static uint8_t rop_to_index
[256];
302 /***************************************
306 ***************************************/
309 static void cirrus_bitblt_reset(CirrusVGAState
*s
);
310 static void cirrus_update_memory_access(CirrusVGAState
*s
);
312 /***************************************
316 ***************************************/
318 static void cirrus_bitblt_rop_nop(CirrusVGAState
*s
,
319 uint8_t *dst
,const uint8_t *src
,
320 int dstpitch
,int srcpitch
,
321 int bltwidth
,int bltheight
)
325 static void cirrus_bitblt_fill_nop(CirrusVGAState
*s
,
327 int dstpitch
, int bltwidth
,int bltheight
)
332 #define ROP_OP(d, s) d = 0
333 #include "cirrus_vga_rop.h"
335 #define ROP_NAME src_and_dst
336 #define ROP_OP(d, s) d = (s) & (d)
337 #include "cirrus_vga_rop.h"
339 #define ROP_NAME src_and_notdst
340 #define ROP_OP(d, s) d = (s) & (~(d))
341 #include "cirrus_vga_rop.h"
343 #define ROP_NAME notdst
344 #define ROP_OP(d, s) d = ~(d)
345 #include "cirrus_vga_rop.h"
348 #define ROP_OP(d, s) d = s
349 #include "cirrus_vga_rop.h"
352 #define ROP_OP(d, s) d = ~0
353 #include "cirrus_vga_rop.h"
355 #define ROP_NAME notsrc_and_dst
356 #define ROP_OP(d, s) d = (~(s)) & (d)
357 #include "cirrus_vga_rop.h"
359 #define ROP_NAME src_xor_dst
360 #define ROP_OP(d, s) d = (s) ^ (d)
361 #include "cirrus_vga_rop.h"
363 #define ROP_NAME src_or_dst
364 #define ROP_OP(d, s) d = (s) | (d)
365 #include "cirrus_vga_rop.h"
367 #define ROP_NAME notsrc_or_notdst
368 #define ROP_OP(d, s) d = (~(s)) | (~(d))
369 #include "cirrus_vga_rop.h"
371 #define ROP_NAME src_notxor_dst
372 #define ROP_OP(d, s) d = ~((s) ^ (d))
373 #include "cirrus_vga_rop.h"
375 #define ROP_NAME src_or_notdst
376 #define ROP_OP(d, s) d = (s) | (~(d))
377 #include "cirrus_vga_rop.h"
379 #define ROP_NAME notsrc
380 #define ROP_OP(d, s) d = (~(s))
381 #include "cirrus_vga_rop.h"
383 #define ROP_NAME notsrc_or_dst
384 #define ROP_OP(d, s) d = (~(s)) | (d)
385 #include "cirrus_vga_rop.h"
387 #define ROP_NAME notsrc_and_notdst
388 #define ROP_OP(d, s) d = (~(s)) & (~(d))
389 #include "cirrus_vga_rop.h"
391 static const cirrus_bitblt_rop_t cirrus_fwd_rop
[16] = {
392 cirrus_bitblt_rop_fwd_0
,
393 cirrus_bitblt_rop_fwd_src_and_dst
,
394 cirrus_bitblt_rop_nop
,
395 cirrus_bitblt_rop_fwd_src_and_notdst
,
396 cirrus_bitblt_rop_fwd_notdst
,
397 cirrus_bitblt_rop_fwd_src
,
398 cirrus_bitblt_rop_fwd_1
,
399 cirrus_bitblt_rop_fwd_notsrc_and_dst
,
400 cirrus_bitblt_rop_fwd_src_xor_dst
,
401 cirrus_bitblt_rop_fwd_src_or_dst
,
402 cirrus_bitblt_rop_fwd_notsrc_or_notdst
,
403 cirrus_bitblt_rop_fwd_src_notxor_dst
,
404 cirrus_bitblt_rop_fwd_src_or_notdst
,
405 cirrus_bitblt_rop_fwd_notsrc
,
406 cirrus_bitblt_rop_fwd_notsrc_or_dst
,
407 cirrus_bitblt_rop_fwd_notsrc_and_notdst
,
410 static const cirrus_bitblt_rop_t cirrus_bkwd_rop
[16] = {
411 cirrus_bitblt_rop_bkwd_0
,
412 cirrus_bitblt_rop_bkwd_src_and_dst
,
413 cirrus_bitblt_rop_nop
,
414 cirrus_bitblt_rop_bkwd_src_and_notdst
,
415 cirrus_bitblt_rop_bkwd_notdst
,
416 cirrus_bitblt_rop_bkwd_src
,
417 cirrus_bitblt_rop_bkwd_1
,
418 cirrus_bitblt_rop_bkwd_notsrc_and_dst
,
419 cirrus_bitblt_rop_bkwd_src_xor_dst
,
420 cirrus_bitblt_rop_bkwd_src_or_dst
,
421 cirrus_bitblt_rop_bkwd_notsrc_or_notdst
,
422 cirrus_bitblt_rop_bkwd_src_notxor_dst
,
423 cirrus_bitblt_rop_bkwd_src_or_notdst
,
424 cirrus_bitblt_rop_bkwd_notsrc
,
425 cirrus_bitblt_rop_bkwd_notsrc_or_dst
,
426 cirrus_bitblt_rop_bkwd_notsrc_and_notdst
,
429 #define TRANSP_ROP(name) {\
433 #define TRANSP_NOP(func) {\
438 static const cirrus_bitblt_rop_t cirrus_fwd_transp_rop
[16][2] = {
439 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_0
),
440 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_src_and_dst
),
441 TRANSP_NOP(cirrus_bitblt_rop_nop
),
442 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_src_and_notdst
),
443 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_notdst
),
444 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_src
),
445 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_1
),
446 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_notsrc_and_dst
),
447 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_src_xor_dst
),
448 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_src_or_dst
),
449 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_notsrc_or_notdst
),
450 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_src_notxor_dst
),
451 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_src_or_notdst
),
452 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_notsrc
),
453 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_notsrc_or_dst
),
454 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_notsrc_and_notdst
),
457 static const cirrus_bitblt_rop_t cirrus_bkwd_transp_rop
[16][2] = {
458 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_0
),
459 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_src_and_dst
),
460 TRANSP_NOP(cirrus_bitblt_rop_nop
),
461 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_src_and_notdst
),
462 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_notdst
),
463 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_src
),
464 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_1
),
465 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_notsrc_and_dst
),
466 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_src_xor_dst
),
467 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_src_or_dst
),
468 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_notsrc_or_notdst
),
469 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_src_notxor_dst
),
470 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_src_or_notdst
),
471 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_notsrc
),
472 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_notsrc_or_dst
),
473 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_notsrc_and_notdst
),
476 #define ROP2(name) {\
483 #define ROP_NOP2(func) {\
490 static const cirrus_bitblt_rop_t cirrus_patternfill
[16][4] = {
491 ROP2(cirrus_patternfill_0
),
492 ROP2(cirrus_patternfill_src_and_dst
),
493 ROP_NOP2(cirrus_bitblt_rop_nop
),
494 ROP2(cirrus_patternfill_src_and_notdst
),
495 ROP2(cirrus_patternfill_notdst
),
496 ROP2(cirrus_patternfill_src
),
497 ROP2(cirrus_patternfill_1
),
498 ROP2(cirrus_patternfill_notsrc_and_dst
),
499 ROP2(cirrus_patternfill_src_xor_dst
),
500 ROP2(cirrus_patternfill_src_or_dst
),
501 ROP2(cirrus_patternfill_notsrc_or_notdst
),
502 ROP2(cirrus_patternfill_src_notxor_dst
),
503 ROP2(cirrus_patternfill_src_or_notdst
),
504 ROP2(cirrus_patternfill_notsrc
),
505 ROP2(cirrus_patternfill_notsrc_or_dst
),
506 ROP2(cirrus_patternfill_notsrc_and_notdst
),
509 static const cirrus_bitblt_rop_t cirrus_colorexpand_transp
[16][4] = {
510 ROP2(cirrus_colorexpand_transp_0
),
511 ROP2(cirrus_colorexpand_transp_src_and_dst
),
512 ROP_NOP2(cirrus_bitblt_rop_nop
),
513 ROP2(cirrus_colorexpand_transp_src_and_notdst
),
514 ROP2(cirrus_colorexpand_transp_notdst
),
515 ROP2(cirrus_colorexpand_transp_src
),
516 ROP2(cirrus_colorexpand_transp_1
),
517 ROP2(cirrus_colorexpand_transp_notsrc_and_dst
),
518 ROP2(cirrus_colorexpand_transp_src_xor_dst
),
519 ROP2(cirrus_colorexpand_transp_src_or_dst
),
520 ROP2(cirrus_colorexpand_transp_notsrc_or_notdst
),
521 ROP2(cirrus_colorexpand_transp_src_notxor_dst
),
522 ROP2(cirrus_colorexpand_transp_src_or_notdst
),
523 ROP2(cirrus_colorexpand_transp_notsrc
),
524 ROP2(cirrus_colorexpand_transp_notsrc_or_dst
),
525 ROP2(cirrus_colorexpand_transp_notsrc_and_notdst
),
528 static const cirrus_bitblt_rop_t cirrus_colorexpand
[16][4] = {
529 ROP2(cirrus_colorexpand_0
),
530 ROP2(cirrus_colorexpand_src_and_dst
),
531 ROP_NOP2(cirrus_bitblt_rop_nop
),
532 ROP2(cirrus_colorexpand_src_and_notdst
),
533 ROP2(cirrus_colorexpand_notdst
),
534 ROP2(cirrus_colorexpand_src
),
535 ROP2(cirrus_colorexpand_1
),
536 ROP2(cirrus_colorexpand_notsrc_and_dst
),
537 ROP2(cirrus_colorexpand_src_xor_dst
),
538 ROP2(cirrus_colorexpand_src_or_dst
),
539 ROP2(cirrus_colorexpand_notsrc_or_notdst
),
540 ROP2(cirrus_colorexpand_src_notxor_dst
),
541 ROP2(cirrus_colorexpand_src_or_notdst
),
542 ROP2(cirrus_colorexpand_notsrc
),
543 ROP2(cirrus_colorexpand_notsrc_or_dst
),
544 ROP2(cirrus_colorexpand_notsrc_and_notdst
),
547 static const cirrus_bitblt_rop_t cirrus_colorexpand_pattern_transp
[16][4] = {
548 ROP2(cirrus_colorexpand_pattern_transp_0
),
549 ROP2(cirrus_colorexpand_pattern_transp_src_and_dst
),
550 ROP_NOP2(cirrus_bitblt_rop_nop
),
551 ROP2(cirrus_colorexpand_pattern_transp_src_and_notdst
),
552 ROP2(cirrus_colorexpand_pattern_transp_notdst
),
553 ROP2(cirrus_colorexpand_pattern_transp_src
),
554 ROP2(cirrus_colorexpand_pattern_transp_1
),
555 ROP2(cirrus_colorexpand_pattern_transp_notsrc_and_dst
),
556 ROP2(cirrus_colorexpand_pattern_transp_src_xor_dst
),
557 ROP2(cirrus_colorexpand_pattern_transp_src_or_dst
),
558 ROP2(cirrus_colorexpand_pattern_transp_notsrc_or_notdst
),
559 ROP2(cirrus_colorexpand_pattern_transp_src_notxor_dst
),
560 ROP2(cirrus_colorexpand_pattern_transp_src_or_notdst
),
561 ROP2(cirrus_colorexpand_pattern_transp_notsrc
),
562 ROP2(cirrus_colorexpand_pattern_transp_notsrc_or_dst
),
563 ROP2(cirrus_colorexpand_pattern_transp_notsrc_and_notdst
),
566 static const cirrus_bitblt_rop_t cirrus_colorexpand_pattern
[16][4] = {
567 ROP2(cirrus_colorexpand_pattern_0
),
568 ROP2(cirrus_colorexpand_pattern_src_and_dst
),
569 ROP_NOP2(cirrus_bitblt_rop_nop
),
570 ROP2(cirrus_colorexpand_pattern_src_and_notdst
),
571 ROP2(cirrus_colorexpand_pattern_notdst
),
572 ROP2(cirrus_colorexpand_pattern_src
),
573 ROP2(cirrus_colorexpand_pattern_1
),
574 ROP2(cirrus_colorexpand_pattern_notsrc_and_dst
),
575 ROP2(cirrus_colorexpand_pattern_src_xor_dst
),
576 ROP2(cirrus_colorexpand_pattern_src_or_dst
),
577 ROP2(cirrus_colorexpand_pattern_notsrc_or_notdst
),
578 ROP2(cirrus_colorexpand_pattern_src_notxor_dst
),
579 ROP2(cirrus_colorexpand_pattern_src_or_notdst
),
580 ROP2(cirrus_colorexpand_pattern_notsrc
),
581 ROP2(cirrus_colorexpand_pattern_notsrc_or_dst
),
582 ROP2(cirrus_colorexpand_pattern_notsrc_and_notdst
),
585 static const cirrus_fill_t cirrus_fill
[16][4] = {
587 ROP2(cirrus_fill_src_and_dst
),
588 ROP_NOP2(cirrus_bitblt_fill_nop
),
589 ROP2(cirrus_fill_src_and_notdst
),
590 ROP2(cirrus_fill_notdst
),
591 ROP2(cirrus_fill_src
),
593 ROP2(cirrus_fill_notsrc_and_dst
),
594 ROP2(cirrus_fill_src_xor_dst
),
595 ROP2(cirrus_fill_src_or_dst
),
596 ROP2(cirrus_fill_notsrc_or_notdst
),
597 ROP2(cirrus_fill_src_notxor_dst
),
598 ROP2(cirrus_fill_src_or_notdst
),
599 ROP2(cirrus_fill_notsrc
),
600 ROP2(cirrus_fill_notsrc_or_dst
),
601 ROP2(cirrus_fill_notsrc_and_notdst
),
604 static inline void cirrus_bitblt_fgcol(CirrusVGAState
*s
)
607 switch (s
->cirrus_blt_pixelwidth
) {
609 s
->cirrus_blt_fgcol
= s
->cirrus_shadow_gr1
;
612 color
= s
->cirrus_shadow_gr1
| (s
->gr
[0x11] << 8);
613 s
->cirrus_blt_fgcol
= le16_to_cpu(color
);
616 s
->cirrus_blt_fgcol
= s
->cirrus_shadow_gr1
|
617 (s
->gr
[0x11] << 8) | (s
->gr
[0x13] << 16);
621 color
= s
->cirrus_shadow_gr1
| (s
->gr
[0x11] << 8) |
622 (s
->gr
[0x13] << 16) | (s
->gr
[0x15] << 24);
623 s
->cirrus_blt_fgcol
= le32_to_cpu(color
);
628 static inline void cirrus_bitblt_bgcol(CirrusVGAState
*s
)
631 switch (s
->cirrus_blt_pixelwidth
) {
633 s
->cirrus_blt_bgcol
= s
->cirrus_shadow_gr0
;
636 color
= s
->cirrus_shadow_gr0
| (s
->gr
[0x10] << 8);
637 s
->cirrus_blt_bgcol
= le16_to_cpu(color
);
640 s
->cirrus_blt_bgcol
= s
->cirrus_shadow_gr0
|
641 (s
->gr
[0x10] << 8) | (s
->gr
[0x12] << 16);
645 color
= s
->cirrus_shadow_gr0
| (s
->gr
[0x10] << 8) |
646 (s
->gr
[0x12] << 16) | (s
->gr
[0x14] << 24);
647 s
->cirrus_blt_bgcol
= le32_to_cpu(color
);
652 static void cirrus_invalidate_region(CirrusVGAState
* s
, int off_begin
,
653 int off_pitch
, int bytesperline
,
660 for (y
= 0; y
< lines
; y
++) {
662 off_cur_end
= (off_cur
+ bytesperline
) & s
->cirrus_addr_mask
;
663 off_cur
&= TARGET_PAGE_MASK
;
664 while (off_cur
< off_cur_end
) {
665 cpu_physical_memory_set_dirty(s
->vram_offset
+ off_cur
);
666 off_cur
+= TARGET_PAGE_SIZE
;
668 off_begin
+= off_pitch
;
672 static int cirrus_bitblt_common_patterncopy(CirrusVGAState
* s
,
677 dst
= s
->vram_ptr
+ (s
->cirrus_blt_dstaddr
& s
->cirrus_addr_mask
);
682 (*s
->cirrus_rop
) (s
, dst
, src
,
683 s
->cirrus_blt_dstpitch
, 0,
684 s
->cirrus_blt_width
, s
->cirrus_blt_height
);
685 cirrus_invalidate_region(s
, s
->cirrus_blt_dstaddr
,
686 s
->cirrus_blt_dstpitch
, s
->cirrus_blt_width
,
687 s
->cirrus_blt_height
);
693 static int cirrus_bitblt_solidfill(CirrusVGAState
*s
, int blt_rop
)
695 cirrus_fill_t rop_func
;
699 rop_func
= cirrus_fill
[rop_to_index
[blt_rop
]][s
->cirrus_blt_pixelwidth
- 1];
700 rop_func(s
, s
->vram_ptr
+ (s
->cirrus_blt_dstaddr
& s
->cirrus_addr_mask
),
701 s
->cirrus_blt_dstpitch
,
702 s
->cirrus_blt_width
, s
->cirrus_blt_height
);
703 cirrus_invalidate_region(s
, s
->cirrus_blt_dstaddr
,
704 s
->cirrus_blt_dstpitch
, s
->cirrus_blt_width
,
705 s
->cirrus_blt_height
);
706 cirrus_bitblt_reset(s
);
710 /***************************************
712 * bitblt (video-to-video)
714 ***************************************/
716 static int cirrus_bitblt_videotovideo_patterncopy(CirrusVGAState
* s
)
718 return cirrus_bitblt_common_patterncopy(s
,
719 s
->vram_ptr
+ ((s
->cirrus_blt_srcaddr
& ~7) &
720 s
->cirrus_addr_mask
));
723 static void cirrus_do_copy(CirrusVGAState
*s
, int dst
, int src
, int w
, int h
)
731 depth
= s
->get_bpp((VGAState
*)s
) / 8;
732 s
->get_resolution((VGAState
*)s
, &width
, &height
);
735 sx
= (src
% (width
* depth
)) / depth
;
736 sy
= (src
/ (width
* depth
));
737 dx
= (dst
% (width
*depth
)) / depth
;
738 dy
= (dst
/ (width
* depth
));
740 /* normalize width */
743 /* if we're doing a backward copy, we have to adjust
744 our x/y to be the upper left corner (instead of the lower
746 if (s
->cirrus_blt_dstpitch
< 0) {
747 sx
-= (s
->cirrus_blt_width
/ depth
) - 1;
748 dx
-= (s
->cirrus_blt_width
/ depth
) - 1;
749 sy
-= s
->cirrus_blt_height
- 1;
750 dy
-= s
->cirrus_blt_height
- 1;
753 /* are we in the visible portion of memory? */
754 if (sx
>= 0 && sy
>= 0 && dx
>= 0 && dy
>= 0 &&
755 (sx
+ w
) <= width
&& (sy
+ h
) <= height
&&
756 (dx
+ w
) <= width
&& (dy
+ h
) <= height
) {
760 /* make to sure only copy if it's a plain copy ROP */
761 if (*s
->cirrus_rop
!= cirrus_bitblt_rop_fwd_src
&&
762 *s
->cirrus_rop
!= cirrus_bitblt_rop_bkwd_src
)
765 /* we have to flush all pending changes so that the copy
766 is generated at the appropriate moment in time */
770 (*s
->cirrus_rop
) (s
, s
->vram_ptr
+
771 (s
->cirrus_blt_dstaddr
& s
->cirrus_addr_mask
),
773 (s
->cirrus_blt_srcaddr
& s
->cirrus_addr_mask
),
774 s
->cirrus_blt_dstpitch
, s
->cirrus_blt_srcpitch
,
775 s
->cirrus_blt_width
, s
->cirrus_blt_height
);
778 s
->ds
->dpy_copy(s
->ds
,
780 s
->cirrus_blt_width
/ depth
,
781 s
->cirrus_blt_height
);
783 /* we don't have to notify the display that this portion has
784 changed since dpy_copy implies this */
787 cirrus_invalidate_region(s
, s
->cirrus_blt_dstaddr
,
788 s
->cirrus_blt_dstpitch
, s
->cirrus_blt_width
,
789 s
->cirrus_blt_height
);
792 static int cirrus_bitblt_videotovideo_copy(CirrusVGAState
* s
)
794 if (s
->ds
->dpy_copy
) {
795 cirrus_do_copy(s
, s
->cirrus_blt_dstaddr
- s
->start_addr
,
796 s
->cirrus_blt_srcaddr
- s
->start_addr
,
797 s
->cirrus_blt_width
, s
->cirrus_blt_height
);
803 (*s
->cirrus_rop
) (s
, s
->vram_ptr
+
804 (s
->cirrus_blt_dstaddr
& s
->cirrus_addr_mask
),
806 (s
->cirrus_blt_srcaddr
& s
->cirrus_addr_mask
),
807 s
->cirrus_blt_dstpitch
, s
->cirrus_blt_srcpitch
,
808 s
->cirrus_blt_width
, s
->cirrus_blt_height
);
810 cirrus_invalidate_region(s
, s
->cirrus_blt_dstaddr
,
811 s
->cirrus_blt_dstpitch
, s
->cirrus_blt_width
,
812 s
->cirrus_blt_height
);
818 /***************************************
820 * bitblt (cpu-to-video)
822 ***************************************/
824 static void cirrus_bitblt_cputovideo_next(CirrusVGAState
* s
)
829 if (s
->cirrus_srccounter
> 0) {
830 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_PATTERNCOPY
) {
831 cirrus_bitblt_common_patterncopy(s
, s
->cirrus_bltbuf
);
833 s
->cirrus_srccounter
= 0;
834 cirrus_bitblt_reset(s
);
836 /* at least one scan line */
838 (*s
->cirrus_rop
)(s
, s
->vram_ptr
+
839 (s
->cirrus_blt_dstaddr
& s
->cirrus_addr_mask
),
840 s
->cirrus_bltbuf
, 0, 0, s
->cirrus_blt_width
, 1);
841 cirrus_invalidate_region(s
, s
->cirrus_blt_dstaddr
, 0,
842 s
->cirrus_blt_width
, 1);
843 s
->cirrus_blt_dstaddr
+= s
->cirrus_blt_dstpitch
;
844 s
->cirrus_srccounter
-= s
->cirrus_blt_srcpitch
;
845 if (s
->cirrus_srccounter
<= 0)
847 /* more bytes than needed can be transfered because of
848 word alignment, so we keep them for the next line */
849 /* XXX: keep alignment to speed up transfer */
850 end_ptr
= s
->cirrus_bltbuf
+ s
->cirrus_blt_srcpitch
;
851 copy_count
= s
->cirrus_srcptr_end
- end_ptr
;
852 memmove(s
->cirrus_bltbuf
, end_ptr
, copy_count
);
853 s
->cirrus_srcptr
= s
->cirrus_bltbuf
+ copy_count
;
854 s
->cirrus_srcptr_end
= s
->cirrus_bltbuf
+ s
->cirrus_blt_srcpitch
;
855 } while (s
->cirrus_srcptr
>= s
->cirrus_srcptr_end
);
860 /***************************************
864 ***************************************/
866 static void cirrus_bitblt_reset(CirrusVGAState
* s
)
869 ~(CIRRUS_BLT_START
| CIRRUS_BLT_BUSY
| CIRRUS_BLT_FIFOUSED
);
870 s
->cirrus_srcptr
= &s
->cirrus_bltbuf
[0];
871 s
->cirrus_srcptr_end
= &s
->cirrus_bltbuf
[0];
872 s
->cirrus_srccounter
= 0;
873 cirrus_update_memory_access(s
);
876 static int cirrus_bitblt_cputovideo(CirrusVGAState
* s
)
880 s
->cirrus_blt_mode
&= ~CIRRUS_BLTMODE_MEMSYSSRC
;
881 s
->cirrus_srcptr
= &s
->cirrus_bltbuf
[0];
882 s
->cirrus_srcptr_end
= &s
->cirrus_bltbuf
[0];
884 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_PATTERNCOPY
) {
885 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_COLOREXPAND
) {
886 s
->cirrus_blt_srcpitch
= 8;
888 /* XXX: check for 24 bpp */
889 s
->cirrus_blt_srcpitch
= 8 * 8 * s
->cirrus_blt_pixelwidth
;
891 s
->cirrus_srccounter
= s
->cirrus_blt_srcpitch
;
893 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_COLOREXPAND
) {
894 w
= s
->cirrus_blt_width
/ s
->cirrus_blt_pixelwidth
;
895 if (s
->cirrus_blt_modeext
& CIRRUS_BLTMODEEXT_DWORDGRANULARITY
)
896 s
->cirrus_blt_srcpitch
= ((w
+ 31) >> 5);
898 s
->cirrus_blt_srcpitch
= ((w
+ 7) >> 3);
900 /* always align input size to 32 bits */
901 s
->cirrus_blt_srcpitch
= (s
->cirrus_blt_width
+ 3) & ~3;
903 s
->cirrus_srccounter
= s
->cirrus_blt_srcpitch
* s
->cirrus_blt_height
;
905 s
->cirrus_srcptr
= s
->cirrus_bltbuf
;
906 s
->cirrus_srcptr_end
= s
->cirrus_bltbuf
+ s
->cirrus_blt_srcpitch
;
907 cirrus_update_memory_access(s
);
911 static int cirrus_bitblt_videotocpu(CirrusVGAState
* s
)
915 printf("cirrus: bitblt (video to cpu) is not implemented yet\n");
920 static int cirrus_bitblt_videotovideo(CirrusVGAState
* s
)
924 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_PATTERNCOPY
) {
925 ret
= cirrus_bitblt_videotovideo_patterncopy(s
);
927 ret
= cirrus_bitblt_videotovideo_copy(s
);
930 cirrus_bitblt_reset(s
);
934 static void cirrus_bitblt_start(CirrusVGAState
* s
)
938 s
->gr
[0x31] |= CIRRUS_BLT_BUSY
;
940 s
->cirrus_blt_width
= (s
->gr
[0x20] | (s
->gr
[0x21] << 8)) + 1;
941 s
->cirrus_blt_height
= (s
->gr
[0x22] | (s
->gr
[0x23] << 8)) + 1;
942 s
->cirrus_blt_dstpitch
= (s
->gr
[0x24] | (s
->gr
[0x25] << 8));
943 s
->cirrus_blt_srcpitch
= (s
->gr
[0x26] | (s
->gr
[0x27] << 8));
944 s
->cirrus_blt_dstaddr
=
945 (s
->gr
[0x28] | (s
->gr
[0x29] << 8) | (s
->gr
[0x2a] << 16));
946 s
->cirrus_blt_srcaddr
=
947 (s
->gr
[0x2c] | (s
->gr
[0x2d] << 8) | (s
->gr
[0x2e] << 16));
948 s
->cirrus_blt_mode
= s
->gr
[0x30];
949 s
->cirrus_blt_modeext
= s
->gr
[0x33];
950 blt_rop
= s
->gr
[0x32];
953 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",
956 s
->cirrus_blt_modeext
,
958 s
->cirrus_blt_height
,
959 s
->cirrus_blt_dstpitch
,
960 s
->cirrus_blt_srcpitch
,
961 s
->cirrus_blt_dstaddr
,
962 s
->cirrus_blt_srcaddr
,
966 switch (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_PIXELWIDTHMASK
) {
967 case CIRRUS_BLTMODE_PIXELWIDTH8
:
968 s
->cirrus_blt_pixelwidth
= 1;
970 case CIRRUS_BLTMODE_PIXELWIDTH16
:
971 s
->cirrus_blt_pixelwidth
= 2;
973 case CIRRUS_BLTMODE_PIXELWIDTH24
:
974 s
->cirrus_blt_pixelwidth
= 3;
976 case CIRRUS_BLTMODE_PIXELWIDTH32
:
977 s
->cirrus_blt_pixelwidth
= 4;
981 printf("cirrus: bitblt - pixel width is unknown\n");
985 s
->cirrus_blt_mode
&= ~CIRRUS_BLTMODE_PIXELWIDTHMASK
;
988 cirrus_blt_mode
& (CIRRUS_BLTMODE_MEMSYSSRC
|
989 CIRRUS_BLTMODE_MEMSYSDEST
))
990 == (CIRRUS_BLTMODE_MEMSYSSRC
| CIRRUS_BLTMODE_MEMSYSDEST
)) {
992 printf("cirrus: bitblt - memory-to-memory copy is requested\n");
997 if ((s
->cirrus_blt_modeext
& CIRRUS_BLTMODEEXT_SOLIDFILL
) &&
998 (s
->cirrus_blt_mode
& (CIRRUS_BLTMODE_MEMSYSDEST
|
999 CIRRUS_BLTMODE_TRANSPARENTCOMP
|
1000 CIRRUS_BLTMODE_PATTERNCOPY
|
1001 CIRRUS_BLTMODE_COLOREXPAND
)) ==
1002 (CIRRUS_BLTMODE_PATTERNCOPY
| CIRRUS_BLTMODE_COLOREXPAND
)) {
1003 cirrus_bitblt_fgcol(s
);
1004 cirrus_bitblt_solidfill(s
, blt_rop
);
1006 if ((s
->cirrus_blt_mode
& (CIRRUS_BLTMODE_COLOREXPAND
|
1007 CIRRUS_BLTMODE_PATTERNCOPY
)) ==
1008 CIRRUS_BLTMODE_COLOREXPAND
) {
1010 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_TRANSPARENTCOMP
) {
1011 if (s
->cirrus_blt_modeext
& CIRRUS_BLTMODEEXT_COLOREXPINV
)
1012 cirrus_bitblt_bgcol(s
);
1014 cirrus_bitblt_fgcol(s
);
1015 s
->cirrus_rop
= cirrus_colorexpand_transp
[rop_to_index
[blt_rop
]][s
->cirrus_blt_pixelwidth
- 1];
1017 cirrus_bitblt_fgcol(s
);
1018 cirrus_bitblt_bgcol(s
);
1019 s
->cirrus_rop
= cirrus_colorexpand
[rop_to_index
[blt_rop
]][s
->cirrus_blt_pixelwidth
- 1];
1021 } else if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_PATTERNCOPY
) {
1022 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_COLOREXPAND
) {
1023 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_TRANSPARENTCOMP
) {
1024 if (s
->cirrus_blt_modeext
& CIRRUS_BLTMODEEXT_COLOREXPINV
)
1025 cirrus_bitblt_bgcol(s
);
1027 cirrus_bitblt_fgcol(s
);
1028 s
->cirrus_rop
= cirrus_colorexpand_pattern_transp
[rop_to_index
[blt_rop
]][s
->cirrus_blt_pixelwidth
- 1];
1030 cirrus_bitblt_fgcol(s
);
1031 cirrus_bitblt_bgcol(s
);
1032 s
->cirrus_rop
= cirrus_colorexpand_pattern
[rop_to_index
[blt_rop
]][s
->cirrus_blt_pixelwidth
- 1];
1035 s
->cirrus_rop
= cirrus_patternfill
[rop_to_index
[blt_rop
]][s
->cirrus_blt_pixelwidth
- 1];
1038 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_TRANSPARENTCOMP
) {
1039 if (s
->cirrus_blt_pixelwidth
> 2) {
1040 printf("src transparent without colorexpand must be 8bpp or 16bpp\n");
1043 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_BACKWARDS
) {
1044 s
->cirrus_blt_dstpitch
= -s
->cirrus_blt_dstpitch
;
1045 s
->cirrus_blt_srcpitch
= -s
->cirrus_blt_srcpitch
;
1046 s
->cirrus_rop
= cirrus_bkwd_transp_rop
[rop_to_index
[blt_rop
]][s
->cirrus_blt_pixelwidth
- 1];
1048 s
->cirrus_rop
= cirrus_fwd_transp_rop
[rop_to_index
[blt_rop
]][s
->cirrus_blt_pixelwidth
- 1];
1051 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_BACKWARDS
) {
1052 s
->cirrus_blt_dstpitch
= -s
->cirrus_blt_dstpitch
;
1053 s
->cirrus_blt_srcpitch
= -s
->cirrus_blt_srcpitch
;
1054 s
->cirrus_rop
= cirrus_bkwd_rop
[rop_to_index
[blt_rop
]];
1056 s
->cirrus_rop
= cirrus_fwd_rop
[rop_to_index
[blt_rop
]];
1060 // setup bitblt engine.
1061 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_MEMSYSSRC
) {
1062 if (!cirrus_bitblt_cputovideo(s
))
1064 } else if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_MEMSYSDEST
) {
1065 if (!cirrus_bitblt_videotocpu(s
))
1068 if (!cirrus_bitblt_videotovideo(s
))
1074 cirrus_bitblt_reset(s
);
1077 static void cirrus_write_bitblt(CirrusVGAState
* s
, unsigned reg_value
)
1081 old_value
= s
->gr
[0x31];
1082 s
->gr
[0x31] = reg_value
;
1084 if (((old_value
& CIRRUS_BLT_RESET
) != 0) &&
1085 ((reg_value
& CIRRUS_BLT_RESET
) == 0)) {
1086 cirrus_bitblt_reset(s
);
1087 } else if (((old_value
& CIRRUS_BLT_START
) == 0) &&
1088 ((reg_value
& CIRRUS_BLT_START
) != 0)) {
1089 cirrus_bitblt_start(s
);
1094 /***************************************
1098 ***************************************/
1100 static void cirrus_get_offsets(VGAState
*s1
,
1101 uint32_t *pline_offset
,
1102 uint32_t *pstart_addr
,
1103 uint32_t *pline_compare
)
1105 CirrusVGAState
* s
= (CirrusVGAState
*)s1
;
1106 uint32_t start_addr
, line_offset
, line_compare
;
1108 line_offset
= s
->cr
[0x13]
1109 | ((s
->cr
[0x1b] & 0x10) << 4);
1111 *pline_offset
= line_offset
;
1113 start_addr
= (s
->cr
[0x0c] << 8)
1115 | ((s
->cr
[0x1b] & 0x01) << 16)
1116 | ((s
->cr
[0x1b] & 0x0c) << 15)
1117 | ((s
->cr
[0x1d] & 0x80) << 12);
1118 *pstart_addr
= start_addr
;
1120 line_compare
= s
->cr
[0x18] |
1121 ((s
->cr
[0x07] & 0x10) << 4) |
1122 ((s
->cr
[0x09] & 0x40) << 3);
1123 *pline_compare
= line_compare
;
1126 static uint32_t cirrus_get_bpp16_depth(CirrusVGAState
* s
)
1130 switch (s
->cirrus_hidden_dac_data
& 0xf) {
1133 break; /* Sierra HiColor */
1136 break; /* XGA HiColor */
1139 printf("cirrus: invalid DAC value %x in 16bpp\n",
1140 (s
->cirrus_hidden_dac_data
& 0xf));
1148 static int cirrus_get_bpp(VGAState
*s1
)
1150 CirrusVGAState
* s
= (CirrusVGAState
*)s1
;
1153 if ((s
->sr
[0x07] & 0x01) != 0) {
1155 switch (s
->sr
[0x07] & CIRRUS_SR7_BPP_MASK
) {
1156 case CIRRUS_SR7_BPP_8
:
1159 case CIRRUS_SR7_BPP_16_DOUBLEVCLK
:
1160 ret
= cirrus_get_bpp16_depth(s
);
1162 case CIRRUS_SR7_BPP_24
:
1165 case CIRRUS_SR7_BPP_16
:
1166 ret
= cirrus_get_bpp16_depth(s
);
1168 case CIRRUS_SR7_BPP_32
:
1173 printf("cirrus: unknown bpp - sr7=%x\n", s
->sr
[0x7]);
1186 static void cirrus_get_resolution(VGAState
*s
, int *pwidth
, int *pheight
)
1190 width
= (s
->cr
[0x01] + 1) * 8;
1191 height
= s
->cr
[0x12] |
1192 ((s
->cr
[0x07] & 0x02) << 7) |
1193 ((s
->cr
[0x07] & 0x40) << 3);
1194 height
= (height
+ 1);
1195 /* interlace support */
1196 if (s
->cr
[0x1a] & 0x01)
1197 height
= height
* 2;
1202 /***************************************
1206 ***************************************/
1208 static void cirrus_update_bank_ptr(CirrusVGAState
* s
, unsigned bank_index
)
1213 if ((s
->gr
[0x0b] & 0x01) != 0) /* dual bank */
1214 offset
= s
->gr
[0x09 + bank_index
];
1215 else /* single bank */
1216 offset
= s
->gr
[0x09];
1218 if ((s
->gr
[0x0b] & 0x20) != 0)
1223 if (s
->real_vram_size
<= offset
)
1226 limit
= s
->real_vram_size
- offset
;
1228 if (((s
->gr
[0x0b] & 0x01) == 0) && (bank_index
!= 0)) {
1229 if (limit
> 0x8000) {
1238 s
->cirrus_bank_base
[bank_index
] = offset
;
1239 s
->cirrus_bank_limit
[bank_index
] = limit
;
1241 s
->cirrus_bank_base
[bank_index
] = 0;
1242 s
->cirrus_bank_limit
[bank_index
] = 0;
1246 /***************************************
1248 * I/O access between 0x3c4-0x3c5
1250 ***************************************/
1253 cirrus_hook_read_sr(CirrusVGAState
* s
, unsigned reg_index
, int *reg_value
)
1255 switch (reg_index
) {
1256 case 0x00: // Standard VGA
1257 case 0x01: // Standard VGA
1258 case 0x02: // Standard VGA
1259 case 0x03: // Standard VGA
1260 case 0x04: // Standard VGA
1261 return CIRRUS_HOOK_NOT_HANDLED
;
1262 case 0x06: // Unlock Cirrus extensions
1263 *reg_value
= s
->sr
[reg_index
];
1268 case 0x70: // Graphics Cursor X
1272 case 0xf0: // Graphics Cursor X
1273 *reg_value
= s
->sr
[0x10];
1278 case 0x71: // Graphics Cursor Y
1282 case 0xf1: // Graphics Cursor Y
1283 *reg_value
= s
->sr
[0x11];
1286 case 0x07: // Extended Sequencer Mode
1287 case 0x08: // EEPROM Control
1288 case 0x09: // Scratch Register 0
1289 case 0x0a: // Scratch Register 1
1290 case 0x0b: // VCLK 0
1291 case 0x0c: // VCLK 1
1292 case 0x0d: // VCLK 2
1293 case 0x0e: // VCLK 3
1294 case 0x0f: // DRAM Control
1295 case 0x12: // Graphics Cursor Attribute
1296 case 0x13: // Graphics Cursor Pattern Address
1297 case 0x14: // Scratch Register 2
1298 case 0x15: // Scratch Register 3
1299 case 0x16: // Performance Tuning Register
1300 case 0x17: // Configuration Readback and Extended Control
1301 case 0x18: // Signature Generator Control
1302 case 0x19: // Signal Generator Result
1303 case 0x1a: // Signal Generator Result
1304 case 0x1b: // VCLK 0 Denominator & Post
1305 case 0x1c: // VCLK 1 Denominator & Post
1306 case 0x1d: // VCLK 2 Denominator & Post
1307 case 0x1e: // VCLK 3 Denominator & Post
1308 case 0x1f: // BIOS Write Enable and MCLK select
1310 printf("cirrus: handled inport sr_index %02x\n", reg_index
);
1312 *reg_value
= s
->sr
[reg_index
];
1316 printf("cirrus: inport sr_index %02x\n", reg_index
);
1322 return CIRRUS_HOOK_HANDLED
;
1326 cirrus_hook_write_sr(CirrusVGAState
* s
, unsigned reg_index
, int reg_value
)
1328 switch (reg_index
) {
1329 case 0x00: // Standard VGA
1330 case 0x01: // Standard VGA
1331 case 0x02: // Standard VGA
1332 case 0x03: // Standard VGA
1333 case 0x04: // Standard VGA
1334 return CIRRUS_HOOK_NOT_HANDLED
;
1335 case 0x06: // Unlock Cirrus extensions
1337 if (reg_value
== 0x12) {
1338 s
->sr
[reg_index
] = 0x12;
1340 s
->sr
[reg_index
] = 0x0f;
1346 case 0x70: // Graphics Cursor X
1350 case 0xf0: // Graphics Cursor X
1351 s
->sr
[0x10] = reg_value
;
1352 s
->hw_cursor_x
= (reg_value
<< 3) | (reg_index
>> 5);
1357 case 0x71: // Graphics Cursor Y
1361 case 0xf1: // Graphics Cursor Y
1362 s
->sr
[0x11] = reg_value
;
1363 s
->hw_cursor_y
= (reg_value
<< 3) | (reg_index
>> 5);
1365 case 0x07: // Extended Sequencer Mode
1366 case 0x08: // EEPROM Control
1367 case 0x09: // Scratch Register 0
1368 case 0x0a: // Scratch Register 1
1369 case 0x0b: // VCLK 0
1370 case 0x0c: // VCLK 1
1371 case 0x0d: // VCLK 2
1372 case 0x0e: // VCLK 3
1373 case 0x0f: // DRAM Control
1374 case 0x12: // Graphics Cursor Attribute
1375 case 0x13: // Graphics Cursor Pattern Address
1376 case 0x14: // Scratch Register 2
1377 case 0x15: // Scratch Register 3
1378 case 0x16: // Performance Tuning Register
1379 case 0x18: // Signature Generator Control
1380 case 0x19: // Signature Generator Result
1381 case 0x1a: // Signature Generator Result
1382 case 0x1b: // VCLK 0 Denominator & Post
1383 case 0x1c: // VCLK 1 Denominator & Post
1384 case 0x1d: // VCLK 2 Denominator & Post
1385 case 0x1e: // VCLK 3 Denominator & Post
1386 case 0x1f: // BIOS Write Enable and MCLK select
1387 s
->sr
[reg_index
] = reg_value
;
1389 printf("cirrus: handled outport sr_index %02x, sr_value %02x\n",
1390 reg_index
, reg_value
);
1392 if (reg_index
== 0x07)
1393 cirrus_update_memory_access(s
);
1395 case 0x17: // Configuration Readback and Extended Control
1396 s
->sr
[reg_index
] = (s
->sr
[reg_index
] & 0x38) | (reg_value
& 0xc7);
1397 cirrus_update_memory_access(s
);
1401 printf("cirrus: outport sr_index %02x, sr_value %02x\n", reg_index
,
1407 return CIRRUS_HOOK_HANDLED
;
1410 /***************************************
1412 * I/O access at 0x3c6
1414 ***************************************/
1416 static void cirrus_read_hidden_dac(CirrusVGAState
* s
, int *reg_value
)
1419 if (++s
->cirrus_hidden_dac_lockindex
== 5) {
1420 *reg_value
= s
->cirrus_hidden_dac_data
;
1421 s
->cirrus_hidden_dac_lockindex
= 0;
1425 static void cirrus_write_hidden_dac(CirrusVGAState
* s
, int reg_value
)
1427 if (s
->cirrus_hidden_dac_lockindex
== 4) {
1428 s
->cirrus_hidden_dac_data
= reg_value
;
1429 #if defined(DEBUG_CIRRUS)
1430 printf("cirrus: outport hidden DAC, value %02x\n", reg_value
);
1433 s
->cirrus_hidden_dac_lockindex
= 0;
1436 /***************************************
1438 * I/O access at 0x3c9
1440 ***************************************/
1442 static int cirrus_hook_read_palette(CirrusVGAState
* s
, int *reg_value
)
1444 if (!(s
->sr
[0x12] & CIRRUS_CURSOR_HIDDENPEL
))
1445 return CIRRUS_HOOK_NOT_HANDLED
;
1447 s
->cirrus_hidden_palette
[(s
->dac_read_index
& 0x0f) * 3 +
1449 if (++s
->dac_sub_index
== 3) {
1450 s
->dac_sub_index
= 0;
1451 s
->dac_read_index
++;
1453 return CIRRUS_HOOK_HANDLED
;
1456 static int cirrus_hook_write_palette(CirrusVGAState
* s
, int reg_value
)
1458 if (!(s
->sr
[0x12] & CIRRUS_CURSOR_HIDDENPEL
))
1459 return CIRRUS_HOOK_NOT_HANDLED
;
1460 s
->dac_cache
[s
->dac_sub_index
] = reg_value
;
1461 if (++s
->dac_sub_index
== 3) {
1462 memcpy(&s
->cirrus_hidden_palette
[(s
->dac_write_index
& 0x0f) * 3],
1464 /* XXX update cursor */
1465 s
->dac_sub_index
= 0;
1466 s
->dac_write_index
++;
1468 return CIRRUS_HOOK_HANDLED
;
1471 /***************************************
1473 * I/O access between 0x3ce-0x3cf
1475 ***************************************/
1478 cirrus_hook_read_gr(CirrusVGAState
* s
, unsigned reg_index
, int *reg_value
)
1480 switch (reg_index
) {
1481 case 0x00: // Standard VGA, BGCOLOR 0x000000ff
1482 *reg_value
= s
->cirrus_shadow_gr0
;
1483 return CIRRUS_HOOK_HANDLED
;
1484 case 0x01: // Standard VGA, FGCOLOR 0x000000ff
1485 *reg_value
= s
->cirrus_shadow_gr1
;
1486 return CIRRUS_HOOK_HANDLED
;
1487 case 0x02: // Standard VGA
1488 case 0x03: // Standard VGA
1489 case 0x04: // Standard VGA
1490 case 0x06: // Standard VGA
1491 case 0x07: // Standard VGA
1492 case 0x08: // Standard VGA
1493 return CIRRUS_HOOK_NOT_HANDLED
;
1494 case 0x05: // Standard VGA, Cirrus extended mode
1499 if (reg_index
< 0x3a) {
1500 *reg_value
= s
->gr
[reg_index
];
1503 printf("cirrus: inport gr_index %02x\n", reg_index
);
1508 return CIRRUS_HOOK_HANDLED
;
1512 cirrus_hook_write_gr(CirrusVGAState
* s
, unsigned reg_index
, int reg_value
)
1514 #if defined(DEBUG_BITBLT) && 0
1515 printf("gr%02x: %02x\n", reg_index
, reg_value
);
1517 switch (reg_index
) {
1518 case 0x00: // Standard VGA, BGCOLOR 0x000000ff
1519 s
->cirrus_shadow_gr0
= reg_value
;
1520 return CIRRUS_HOOK_NOT_HANDLED
;
1521 case 0x01: // Standard VGA, FGCOLOR 0x000000ff
1522 s
->cirrus_shadow_gr1
= reg_value
;
1523 return CIRRUS_HOOK_NOT_HANDLED
;
1524 case 0x02: // Standard VGA
1525 case 0x03: // Standard VGA
1526 case 0x04: // Standard VGA
1527 case 0x06: // Standard VGA
1528 case 0x07: // Standard VGA
1529 case 0x08: // Standard VGA
1530 return CIRRUS_HOOK_NOT_HANDLED
;
1531 case 0x05: // Standard VGA, Cirrus extended mode
1532 s
->gr
[reg_index
] = reg_value
& 0x7f;
1533 cirrus_update_memory_access(s
);
1535 case 0x09: // bank offset #0
1536 case 0x0A: // bank offset #1
1537 s
->gr
[reg_index
] = reg_value
;
1538 cirrus_update_bank_ptr(s
, 0);
1539 cirrus_update_bank_ptr(s
, 1);
1540 cirrus_update_memory_access(s
);
1543 s
->gr
[reg_index
] = reg_value
;
1544 cirrus_update_bank_ptr(s
, 0);
1545 cirrus_update_bank_ptr(s
, 1);
1546 cirrus_update_memory_access(s
);
1548 case 0x10: // BGCOLOR 0x0000ff00
1549 case 0x11: // FGCOLOR 0x0000ff00
1550 case 0x12: // BGCOLOR 0x00ff0000
1551 case 0x13: // FGCOLOR 0x00ff0000
1552 case 0x14: // BGCOLOR 0xff000000
1553 case 0x15: // FGCOLOR 0xff000000
1554 case 0x20: // BLT WIDTH 0x0000ff
1555 case 0x22: // BLT HEIGHT 0x0000ff
1556 case 0x24: // BLT DEST PITCH 0x0000ff
1557 case 0x26: // BLT SRC PITCH 0x0000ff
1558 case 0x28: // BLT DEST ADDR 0x0000ff
1559 case 0x29: // BLT DEST ADDR 0x00ff00
1560 case 0x2c: // BLT SRC ADDR 0x0000ff
1561 case 0x2d: // BLT SRC ADDR 0x00ff00
1562 case 0x2f: // BLT WRITEMASK
1563 case 0x30: // BLT MODE
1564 case 0x32: // RASTER OP
1565 case 0x33: // BLT MODEEXT
1566 case 0x34: // BLT TRANSPARENT COLOR 0x00ff
1567 case 0x35: // BLT TRANSPARENT COLOR 0xff00
1568 case 0x38: // BLT TRANSPARENT COLOR MASK 0x00ff
1569 case 0x39: // BLT TRANSPARENT COLOR MASK 0xff00
1570 s
->gr
[reg_index
] = reg_value
;
1572 case 0x21: // BLT WIDTH 0x001f00
1573 case 0x23: // BLT HEIGHT 0x001f00
1574 case 0x25: // BLT DEST PITCH 0x001f00
1575 case 0x27: // BLT SRC PITCH 0x001f00
1576 s
->gr
[reg_index
] = reg_value
& 0x1f;
1578 case 0x2a: // BLT DEST ADDR 0x3f0000
1579 s
->gr
[reg_index
] = reg_value
& 0x3f;
1580 /* if auto start mode, starts bit blt now */
1581 if (s
->gr
[0x31] & CIRRUS_BLT_AUTOSTART
) {
1582 cirrus_bitblt_start(s
);
1585 case 0x2e: // BLT SRC ADDR 0x3f0000
1586 s
->gr
[reg_index
] = reg_value
& 0x3f;
1588 case 0x31: // BLT STATUS/START
1589 cirrus_write_bitblt(s
, reg_value
);
1593 printf("cirrus: outport gr_index %02x, gr_value %02x\n", reg_index
,
1599 return CIRRUS_HOOK_HANDLED
;
1602 /***************************************
1604 * I/O access between 0x3d4-0x3d5
1606 ***************************************/
1609 cirrus_hook_read_cr(CirrusVGAState
* s
, unsigned reg_index
, int *reg_value
)
1611 switch (reg_index
) {
1612 case 0x00: // Standard VGA
1613 case 0x01: // Standard VGA
1614 case 0x02: // Standard VGA
1615 case 0x03: // Standard VGA
1616 case 0x04: // Standard VGA
1617 case 0x05: // Standard VGA
1618 case 0x06: // Standard VGA
1619 case 0x07: // Standard VGA
1620 case 0x08: // Standard VGA
1621 case 0x09: // Standard VGA
1622 case 0x0a: // Standard VGA
1623 case 0x0b: // Standard VGA
1624 case 0x0c: // Standard VGA
1625 case 0x0d: // Standard VGA
1626 case 0x0e: // Standard VGA
1627 case 0x0f: // Standard VGA
1628 case 0x10: // Standard VGA
1629 case 0x11: // Standard VGA
1630 case 0x12: // Standard VGA
1631 case 0x13: // Standard VGA
1632 case 0x14: // Standard VGA
1633 case 0x15: // Standard VGA
1634 case 0x16: // Standard VGA
1635 case 0x17: // Standard VGA
1636 case 0x18: // Standard VGA
1637 return CIRRUS_HOOK_NOT_HANDLED
;
1638 case 0x24: // Attribute Controller Toggle Readback (R)
1639 *reg_value
= (s
->ar_flip_flop
<< 7);
1641 case 0x19: // Interlace End
1642 case 0x1a: // Miscellaneous Control
1643 case 0x1b: // Extended Display Control
1644 case 0x1c: // Sync Adjust and Genlock
1645 case 0x1d: // Overlay Extended Control
1646 case 0x22: // Graphics Data Latches Readback (R)
1647 case 0x25: // Part Status
1648 case 0x27: // Part ID (R)
1649 *reg_value
= s
->cr
[reg_index
];
1651 case 0x26: // Attribute Controller Index Readback (R)
1652 *reg_value
= s
->ar_index
& 0x3f;
1656 printf("cirrus: inport cr_index %02x\n", reg_index
);
1662 return CIRRUS_HOOK_HANDLED
;
1666 cirrus_hook_write_cr(CirrusVGAState
* s
, unsigned reg_index
, int reg_value
)
1668 switch (reg_index
) {
1669 case 0x00: // Standard VGA
1670 case 0x01: // Standard VGA
1671 case 0x02: // Standard VGA
1672 case 0x03: // Standard VGA
1673 case 0x04: // Standard VGA
1674 case 0x05: // Standard VGA
1675 case 0x06: // Standard VGA
1676 case 0x07: // Standard VGA
1677 case 0x08: // Standard VGA
1678 case 0x09: // Standard VGA
1679 case 0x0a: // Standard VGA
1680 case 0x0b: // Standard VGA
1681 case 0x0c: // Standard VGA
1682 case 0x0d: // Standard VGA
1683 case 0x0e: // Standard VGA
1684 case 0x0f: // Standard VGA
1685 case 0x10: // Standard VGA
1686 case 0x11: // Standard VGA
1687 case 0x12: // Standard VGA
1688 case 0x13: // Standard VGA
1689 case 0x14: // Standard VGA
1690 case 0x15: // Standard VGA
1691 case 0x16: // Standard VGA
1692 case 0x17: // Standard VGA
1693 case 0x18: // Standard VGA
1694 return CIRRUS_HOOK_NOT_HANDLED
;
1695 case 0x19: // Interlace End
1696 case 0x1a: // Miscellaneous Control
1697 case 0x1b: // Extended Display Control
1698 case 0x1c: // Sync Adjust and Genlock
1699 case 0x1d: // Overlay Extended Control
1700 s
->cr
[reg_index
] = reg_value
;
1702 printf("cirrus: handled outport cr_index %02x, cr_value %02x\n",
1703 reg_index
, reg_value
);
1706 case 0x22: // Graphics Data Latches Readback (R)
1707 case 0x24: // Attribute Controller Toggle Readback (R)
1708 case 0x26: // Attribute Controller Index Readback (R)
1709 case 0x27: // Part ID (R)
1711 case 0x25: // Part Status
1714 printf("cirrus: outport cr_index %02x, cr_value %02x\n", reg_index
,
1720 return CIRRUS_HOOK_HANDLED
;
1723 /***************************************
1725 * memory-mapped I/O (bitblt)
1727 ***************************************/
1729 static uint8_t cirrus_mmio_blt_read(CirrusVGAState
* s
, unsigned address
)
1734 case (CIRRUS_MMIO_BLTBGCOLOR
+ 0):
1735 cirrus_hook_read_gr(s
, 0x00, &value
);
1737 case (CIRRUS_MMIO_BLTBGCOLOR
+ 1):
1738 cirrus_hook_read_gr(s
, 0x10, &value
);
1740 case (CIRRUS_MMIO_BLTBGCOLOR
+ 2):
1741 cirrus_hook_read_gr(s
, 0x12, &value
);
1743 case (CIRRUS_MMIO_BLTBGCOLOR
+ 3):
1744 cirrus_hook_read_gr(s
, 0x14, &value
);
1746 case (CIRRUS_MMIO_BLTFGCOLOR
+ 0):
1747 cirrus_hook_read_gr(s
, 0x01, &value
);
1749 case (CIRRUS_MMIO_BLTFGCOLOR
+ 1):
1750 cirrus_hook_read_gr(s
, 0x11, &value
);
1752 case (CIRRUS_MMIO_BLTFGCOLOR
+ 2):
1753 cirrus_hook_read_gr(s
, 0x13, &value
);
1755 case (CIRRUS_MMIO_BLTFGCOLOR
+ 3):
1756 cirrus_hook_read_gr(s
, 0x15, &value
);
1758 case (CIRRUS_MMIO_BLTWIDTH
+ 0):
1759 cirrus_hook_read_gr(s
, 0x20, &value
);
1761 case (CIRRUS_MMIO_BLTWIDTH
+ 1):
1762 cirrus_hook_read_gr(s
, 0x21, &value
);
1764 case (CIRRUS_MMIO_BLTHEIGHT
+ 0):
1765 cirrus_hook_read_gr(s
, 0x22, &value
);
1767 case (CIRRUS_MMIO_BLTHEIGHT
+ 1):
1768 cirrus_hook_read_gr(s
, 0x23, &value
);
1770 case (CIRRUS_MMIO_BLTDESTPITCH
+ 0):
1771 cirrus_hook_read_gr(s
, 0x24, &value
);
1773 case (CIRRUS_MMIO_BLTDESTPITCH
+ 1):
1774 cirrus_hook_read_gr(s
, 0x25, &value
);
1776 case (CIRRUS_MMIO_BLTSRCPITCH
+ 0):
1777 cirrus_hook_read_gr(s
, 0x26, &value
);
1779 case (CIRRUS_MMIO_BLTSRCPITCH
+ 1):
1780 cirrus_hook_read_gr(s
, 0x27, &value
);
1782 case (CIRRUS_MMIO_BLTDESTADDR
+ 0):
1783 cirrus_hook_read_gr(s
, 0x28, &value
);
1785 case (CIRRUS_MMIO_BLTDESTADDR
+ 1):
1786 cirrus_hook_read_gr(s
, 0x29, &value
);
1788 case (CIRRUS_MMIO_BLTDESTADDR
+ 2):
1789 cirrus_hook_read_gr(s
, 0x2a, &value
);
1791 case (CIRRUS_MMIO_BLTSRCADDR
+ 0):
1792 cirrus_hook_read_gr(s
, 0x2c, &value
);
1794 case (CIRRUS_MMIO_BLTSRCADDR
+ 1):
1795 cirrus_hook_read_gr(s
, 0x2d, &value
);
1797 case (CIRRUS_MMIO_BLTSRCADDR
+ 2):
1798 cirrus_hook_read_gr(s
, 0x2e, &value
);
1800 case CIRRUS_MMIO_BLTWRITEMASK
:
1801 cirrus_hook_read_gr(s
, 0x2f, &value
);
1803 case CIRRUS_MMIO_BLTMODE
:
1804 cirrus_hook_read_gr(s
, 0x30, &value
);
1806 case CIRRUS_MMIO_BLTROP
:
1807 cirrus_hook_read_gr(s
, 0x32, &value
);
1809 case CIRRUS_MMIO_BLTMODEEXT
:
1810 cirrus_hook_read_gr(s
, 0x33, &value
);
1812 case (CIRRUS_MMIO_BLTTRANSPARENTCOLOR
+ 0):
1813 cirrus_hook_read_gr(s
, 0x34, &value
);
1815 case (CIRRUS_MMIO_BLTTRANSPARENTCOLOR
+ 1):
1816 cirrus_hook_read_gr(s
, 0x35, &value
);
1818 case (CIRRUS_MMIO_BLTTRANSPARENTCOLORMASK
+ 0):
1819 cirrus_hook_read_gr(s
, 0x38, &value
);
1821 case (CIRRUS_MMIO_BLTTRANSPARENTCOLORMASK
+ 1):
1822 cirrus_hook_read_gr(s
, 0x39, &value
);
1824 case CIRRUS_MMIO_BLTSTATUS
:
1825 cirrus_hook_read_gr(s
, 0x31, &value
);
1829 printf("cirrus: mmio read - address 0x%04x\n", address
);
1834 return (uint8_t) value
;
1837 static void cirrus_mmio_blt_write(CirrusVGAState
* s
, unsigned address
,
1841 case (CIRRUS_MMIO_BLTBGCOLOR
+ 0):
1842 cirrus_hook_write_gr(s
, 0x00, value
);
1844 case (CIRRUS_MMIO_BLTBGCOLOR
+ 1):
1845 cirrus_hook_write_gr(s
, 0x10, value
);
1847 case (CIRRUS_MMIO_BLTBGCOLOR
+ 2):
1848 cirrus_hook_write_gr(s
, 0x12, value
);
1850 case (CIRRUS_MMIO_BLTBGCOLOR
+ 3):
1851 cirrus_hook_write_gr(s
, 0x14, value
);
1853 case (CIRRUS_MMIO_BLTFGCOLOR
+ 0):
1854 cirrus_hook_write_gr(s
, 0x01, value
);
1856 case (CIRRUS_MMIO_BLTFGCOLOR
+ 1):
1857 cirrus_hook_write_gr(s
, 0x11, value
);
1859 case (CIRRUS_MMIO_BLTFGCOLOR
+ 2):
1860 cirrus_hook_write_gr(s
, 0x13, value
);
1862 case (CIRRUS_MMIO_BLTFGCOLOR
+ 3):
1863 cirrus_hook_write_gr(s
, 0x15, value
);
1865 case (CIRRUS_MMIO_BLTWIDTH
+ 0):
1866 cirrus_hook_write_gr(s
, 0x20, value
);
1868 case (CIRRUS_MMIO_BLTWIDTH
+ 1):
1869 cirrus_hook_write_gr(s
, 0x21, value
);
1871 case (CIRRUS_MMIO_BLTHEIGHT
+ 0):
1872 cirrus_hook_write_gr(s
, 0x22, value
);
1874 case (CIRRUS_MMIO_BLTHEIGHT
+ 1):
1875 cirrus_hook_write_gr(s
, 0x23, value
);
1877 case (CIRRUS_MMIO_BLTDESTPITCH
+ 0):
1878 cirrus_hook_write_gr(s
, 0x24, value
);
1880 case (CIRRUS_MMIO_BLTDESTPITCH
+ 1):
1881 cirrus_hook_write_gr(s
, 0x25, value
);
1883 case (CIRRUS_MMIO_BLTSRCPITCH
+ 0):
1884 cirrus_hook_write_gr(s
, 0x26, value
);
1886 case (CIRRUS_MMIO_BLTSRCPITCH
+ 1):
1887 cirrus_hook_write_gr(s
, 0x27, value
);
1889 case (CIRRUS_MMIO_BLTDESTADDR
+ 0):
1890 cirrus_hook_write_gr(s
, 0x28, value
);
1892 case (CIRRUS_MMIO_BLTDESTADDR
+ 1):
1893 cirrus_hook_write_gr(s
, 0x29, value
);
1895 case (CIRRUS_MMIO_BLTDESTADDR
+ 2):
1896 cirrus_hook_write_gr(s
, 0x2a, value
);
1898 case (CIRRUS_MMIO_BLTDESTADDR
+ 3):
1901 case (CIRRUS_MMIO_BLTSRCADDR
+ 0):
1902 cirrus_hook_write_gr(s
, 0x2c, value
);
1904 case (CIRRUS_MMIO_BLTSRCADDR
+ 1):
1905 cirrus_hook_write_gr(s
, 0x2d, value
);
1907 case (CIRRUS_MMIO_BLTSRCADDR
+ 2):
1908 cirrus_hook_write_gr(s
, 0x2e, value
);
1910 case CIRRUS_MMIO_BLTWRITEMASK
:
1911 cirrus_hook_write_gr(s
, 0x2f, value
);
1913 case CIRRUS_MMIO_BLTMODE
:
1914 cirrus_hook_write_gr(s
, 0x30, value
);
1916 case CIRRUS_MMIO_BLTROP
:
1917 cirrus_hook_write_gr(s
, 0x32, value
);
1919 case CIRRUS_MMIO_BLTMODEEXT
:
1920 cirrus_hook_write_gr(s
, 0x33, value
);
1922 case (CIRRUS_MMIO_BLTTRANSPARENTCOLOR
+ 0):
1923 cirrus_hook_write_gr(s
, 0x34, value
);
1925 case (CIRRUS_MMIO_BLTTRANSPARENTCOLOR
+ 1):
1926 cirrus_hook_write_gr(s
, 0x35, value
);
1928 case (CIRRUS_MMIO_BLTTRANSPARENTCOLORMASK
+ 0):
1929 cirrus_hook_write_gr(s
, 0x38, value
);
1931 case (CIRRUS_MMIO_BLTTRANSPARENTCOLORMASK
+ 1):
1932 cirrus_hook_write_gr(s
, 0x39, value
);
1934 case CIRRUS_MMIO_BLTSTATUS
:
1935 cirrus_hook_write_gr(s
, 0x31, value
);
1939 printf("cirrus: mmio write - addr 0x%04x val 0x%02x (ignored)\n",
1946 /***************************************
1950 * assume TARGET_PAGE_SIZE >= 16
1952 ***************************************/
1954 static void cirrus_mem_writeb_mode4and5_8bpp(CirrusVGAState
* s
,
1960 unsigned val
= mem_value
;
1963 dst
= s
->vram_ptr
+ (offset
&= s
->cirrus_addr_mask
);
1964 for (x
= 0; x
< 8; x
++) {
1966 *dst
= s
->cirrus_shadow_gr1
;
1967 } else if (mode
== 5) {
1968 *dst
= s
->cirrus_shadow_gr0
;
1973 cpu_physical_memory_set_dirty(s
->vram_offset
+ offset
);
1974 cpu_physical_memory_set_dirty(s
->vram_offset
+ offset
+ 7);
1977 static void cirrus_mem_writeb_mode4and5_16bpp(CirrusVGAState
* s
,
1983 unsigned val
= mem_value
;
1986 dst
= s
->vram_ptr
+ (offset
&= s
->cirrus_addr_mask
);
1987 for (x
= 0; x
< 8; x
++) {
1989 *dst
= s
->cirrus_shadow_gr1
;
1990 *(dst
+ 1) = s
->gr
[0x11];
1991 } else if (mode
== 5) {
1992 *dst
= s
->cirrus_shadow_gr0
;
1993 *(dst
+ 1) = s
->gr
[0x10];
1998 cpu_physical_memory_set_dirty(s
->vram_offset
+ offset
);
1999 cpu_physical_memory_set_dirty(s
->vram_offset
+ offset
+ 15);
2002 /***************************************
2004 * memory access between 0xa0000-0xbffff
2006 ***************************************/
2008 static uint32_t cirrus_vga_mem_readb(void *opaque
, target_phys_addr_t addr
)
2010 CirrusVGAState
*s
= opaque
;
2011 unsigned bank_index
;
2012 unsigned bank_offset
;
2015 if ((s
->sr
[0x07] & 0x01) == 0) {
2016 return vga_mem_readb(s
, addr
);
2021 if (addr
< 0x10000) {
2022 /* XXX handle bitblt */
2024 bank_index
= addr
>> 15;
2025 bank_offset
= addr
& 0x7fff;
2026 if (bank_offset
< s
->cirrus_bank_limit
[bank_index
]) {
2027 bank_offset
+= s
->cirrus_bank_base
[bank_index
];
2028 if ((s
->gr
[0x0B] & 0x14) == 0x14) {
2030 } else if (s
->gr
[0x0B] & 0x02) {
2033 bank_offset
&= s
->cirrus_addr_mask
;
2034 val
= *(s
->vram_ptr
+ bank_offset
);
2037 } else if (addr
>= 0x18000 && addr
< 0x18100) {
2038 /* memory-mapped I/O */
2040 if ((s
->sr
[0x17] & 0x44) == 0x04) {
2041 val
= cirrus_mmio_blt_read(s
, addr
& 0xff);
2046 printf("cirrus: mem_readb %06x\n", addr
);
2052 static uint32_t cirrus_vga_mem_readw(void *opaque
, target_phys_addr_t addr
)
2055 #ifdef TARGET_WORDS_BIGENDIAN
2056 v
= cirrus_vga_mem_readb(opaque
, addr
) << 8;
2057 v
|= cirrus_vga_mem_readb(opaque
, addr
+ 1);
2059 v
= cirrus_vga_mem_readb(opaque
, addr
);
2060 v
|= cirrus_vga_mem_readb(opaque
, addr
+ 1) << 8;
2065 static uint32_t cirrus_vga_mem_readl(void *opaque
, target_phys_addr_t addr
)
2068 #ifdef TARGET_WORDS_BIGENDIAN
2069 v
= cirrus_vga_mem_readb(opaque
, addr
) << 24;
2070 v
|= cirrus_vga_mem_readb(opaque
, addr
+ 1) << 16;
2071 v
|= cirrus_vga_mem_readb(opaque
, addr
+ 2) << 8;
2072 v
|= cirrus_vga_mem_readb(opaque
, addr
+ 3);
2074 v
= cirrus_vga_mem_readb(opaque
, addr
);
2075 v
|= cirrus_vga_mem_readb(opaque
, addr
+ 1) << 8;
2076 v
|= cirrus_vga_mem_readb(opaque
, addr
+ 2) << 16;
2077 v
|= cirrus_vga_mem_readb(opaque
, addr
+ 3) << 24;
2082 static void cirrus_vga_mem_writeb(void *opaque
, target_phys_addr_t addr
,
2085 CirrusVGAState
*s
= opaque
;
2086 unsigned bank_index
;
2087 unsigned bank_offset
;
2090 if ((s
->sr
[0x07] & 0x01) == 0) {
2091 vga_mem_writeb(s
, addr
, mem_value
);
2097 if (addr
< 0x10000) {
2098 if (s
->cirrus_srcptr
!= s
->cirrus_srcptr_end
) {
2100 *s
->cirrus_srcptr
++ = (uint8_t) mem_value
;
2101 if (s
->cirrus_srcptr
>= s
->cirrus_srcptr_end
) {
2102 cirrus_bitblt_cputovideo_next(s
);
2106 bank_index
= addr
>> 15;
2107 bank_offset
= addr
& 0x7fff;
2108 if (bank_offset
< s
->cirrus_bank_limit
[bank_index
]) {
2109 bank_offset
+= s
->cirrus_bank_base
[bank_index
];
2110 if ((s
->gr
[0x0B] & 0x14) == 0x14) {
2112 } else if (s
->gr
[0x0B] & 0x02) {
2115 bank_offset
&= s
->cirrus_addr_mask
;
2116 mode
= s
->gr
[0x05] & 0x7;
2117 if (mode
< 4 || mode
> 5 || ((s
->gr
[0x0B] & 0x4) == 0)) {
2118 *(s
->vram_ptr
+ bank_offset
) = mem_value
;
2119 cpu_physical_memory_set_dirty(s
->vram_offset
+
2122 if ((s
->gr
[0x0B] & 0x14) != 0x14) {
2123 cirrus_mem_writeb_mode4and5_8bpp(s
, mode
,
2127 cirrus_mem_writeb_mode4and5_16bpp(s
, mode
,
2134 } else if (addr
>= 0x18000 && addr
< 0x18100) {
2135 /* memory-mapped I/O */
2136 if ((s
->sr
[0x17] & 0x44) == 0x04) {
2137 cirrus_mmio_blt_write(s
, addr
& 0xff, mem_value
);
2141 printf("cirrus: mem_writeb %06x value %02x\n", addr
, mem_value
);
2146 static void cirrus_vga_mem_writew(void *opaque
, target_phys_addr_t addr
, uint32_t val
)
2148 #ifdef TARGET_WORDS_BIGENDIAN
2149 cirrus_vga_mem_writeb(opaque
, addr
, (val
>> 8) & 0xff);
2150 cirrus_vga_mem_writeb(opaque
, addr
+ 1, val
& 0xff);
2152 cirrus_vga_mem_writeb(opaque
, addr
, val
& 0xff);
2153 cirrus_vga_mem_writeb(opaque
, addr
+ 1, (val
>> 8) & 0xff);
2157 static void cirrus_vga_mem_writel(void *opaque
, target_phys_addr_t addr
, uint32_t val
)
2159 #ifdef TARGET_WORDS_BIGENDIAN
2160 cirrus_vga_mem_writeb(opaque
, addr
, (val
>> 24) & 0xff);
2161 cirrus_vga_mem_writeb(opaque
, addr
+ 1, (val
>> 16) & 0xff);
2162 cirrus_vga_mem_writeb(opaque
, addr
+ 2, (val
>> 8) & 0xff);
2163 cirrus_vga_mem_writeb(opaque
, addr
+ 3, val
& 0xff);
2165 cirrus_vga_mem_writeb(opaque
, addr
, val
& 0xff);
2166 cirrus_vga_mem_writeb(opaque
, addr
+ 1, (val
>> 8) & 0xff);
2167 cirrus_vga_mem_writeb(opaque
, addr
+ 2, (val
>> 16) & 0xff);
2168 cirrus_vga_mem_writeb(opaque
, addr
+ 3, (val
>> 24) & 0xff);
2172 static CPUReadMemoryFunc
*cirrus_vga_mem_read
[3] = {
2173 cirrus_vga_mem_readb
,
2174 cirrus_vga_mem_readw
,
2175 cirrus_vga_mem_readl
,
2178 static CPUWriteMemoryFunc
*cirrus_vga_mem_write
[3] = {
2179 cirrus_vga_mem_writeb
,
2180 cirrus_vga_mem_writew
,
2181 cirrus_vga_mem_writel
,
2184 /***************************************
2188 ***************************************/
2190 static inline void invalidate_cursor1(CirrusVGAState
*s
)
2192 if (s
->last_hw_cursor_size
) {
2193 vga_invalidate_scanlines((VGAState
*)s
,
2194 s
->last_hw_cursor_y
+ s
->last_hw_cursor_y_start
,
2195 s
->last_hw_cursor_y
+ s
->last_hw_cursor_y_end
);
2199 static inline void cirrus_cursor_compute_yrange(CirrusVGAState
*s
)
2203 int y
, y_min
, y_max
;
2205 src
= s
->vram_ptr
+ s
->real_vram_size
- 16 * 1024;
2206 if (s
->sr
[0x12] & CIRRUS_CURSOR_LARGE
) {
2207 src
+= (s
->sr
[0x13] & 0x3c) * 256;
2210 for(y
= 0; y
< 64; y
++) {
2211 content
= ((uint32_t *)src
)[0] |
2212 ((uint32_t *)src
)[1] |
2213 ((uint32_t *)src
)[2] |
2214 ((uint32_t *)src
)[3];
2224 src
+= (s
->sr
[0x13] & 0x3f) * 256;
2227 for(y
= 0; y
< 32; y
++) {
2228 content
= ((uint32_t *)src
)[0] |
2229 ((uint32_t *)(src
+ 128))[0];
2239 if (y_min
> y_max
) {
2240 s
->last_hw_cursor_y_start
= 0;
2241 s
->last_hw_cursor_y_end
= 0;
2243 s
->last_hw_cursor_y_start
= y_min
;
2244 s
->last_hw_cursor_y_end
= y_max
+ 1;
2248 /* NOTE: we do not currently handle the cursor bitmap change, so we
2249 update the cursor only if it moves. */
2250 static void cirrus_cursor_invalidate(VGAState
*s1
)
2252 CirrusVGAState
*s
= (CirrusVGAState
*)s1
;
2255 if (!s
->sr
[0x12] & CIRRUS_CURSOR_SHOW
) {
2258 if (s
->sr
[0x12] & CIRRUS_CURSOR_LARGE
)
2263 /* invalidate last cursor and new cursor if any change */
2264 if (s
->last_hw_cursor_size
!= size
||
2265 s
->last_hw_cursor_x
!= s
->hw_cursor_x
||
2266 s
->last_hw_cursor_y
!= s
->hw_cursor_y
) {
2268 invalidate_cursor1(s
);
2270 s
->last_hw_cursor_size
= size
;
2271 s
->last_hw_cursor_x
= s
->hw_cursor_x
;
2272 s
->last_hw_cursor_y
= s
->hw_cursor_y
;
2273 /* compute the real cursor min and max y */
2274 cirrus_cursor_compute_yrange(s
);
2275 invalidate_cursor1(s
);
2279 static void cirrus_cursor_draw_line(VGAState
*s1
, uint8_t *d1
, int scr_y
)
2281 CirrusVGAState
*s
= (CirrusVGAState
*)s1
;
2282 int w
, h
, bpp
, x1
, x2
, poffset
;
2283 unsigned int color0
, color1
;
2284 const uint8_t *palette
, *src
;
2287 if (!(s
->sr
[0x12] & CIRRUS_CURSOR_SHOW
))
2289 /* fast test to see if the cursor intersects with the scan line */
2290 if (s
->sr
[0x12] & CIRRUS_CURSOR_LARGE
) {
2295 if (scr_y
< s
->hw_cursor_y
||
2296 scr_y
>= (s
->hw_cursor_y
+ h
))
2299 src
= s
->vram_ptr
+ s
->real_vram_size
- 16 * 1024;
2300 if (s
->sr
[0x12] & CIRRUS_CURSOR_LARGE
) {
2301 src
+= (s
->sr
[0x13] & 0x3c) * 256;
2302 src
+= (scr_y
- s
->hw_cursor_y
) * 16;
2304 content
= ((uint32_t *)src
)[0] |
2305 ((uint32_t *)src
)[1] |
2306 ((uint32_t *)src
)[2] |
2307 ((uint32_t *)src
)[3];
2309 src
+= (s
->sr
[0x13] & 0x3f) * 256;
2310 src
+= (scr_y
- s
->hw_cursor_y
) * 4;
2312 content
= ((uint32_t *)src
)[0] |
2313 ((uint32_t *)(src
+ 128))[0];
2315 /* if nothing to draw, no need to continue */
2320 x1
= s
->hw_cursor_x
;
2321 if (x1
>= s
->last_scr_width
)
2323 x2
= s
->hw_cursor_x
+ w
;
2324 if (x2
> s
->last_scr_width
)
2325 x2
= s
->last_scr_width
;
2327 palette
= s
->cirrus_hidden_palette
;
2328 color0
= s
->rgb_to_pixel(c6_to_8(palette
[0x0 * 3]),
2329 c6_to_8(palette
[0x0 * 3 + 1]),
2330 c6_to_8(palette
[0x0 * 3 + 2]));
2331 color1
= s
->rgb_to_pixel(c6_to_8(palette
[0xf * 3]),
2332 c6_to_8(palette
[0xf * 3 + 1]),
2333 c6_to_8(palette
[0xf * 3 + 2]));
2334 bpp
= ((s
->ds
->depth
+ 7) >> 3);
2336 switch(s
->ds
->depth
) {
2340 vga_draw_cursor_line_8(d1
, src
, poffset
, w
, color0
, color1
, 0xff);
2343 vga_draw_cursor_line_16(d1
, src
, poffset
, w
, color0
, color1
, 0x7fff);
2346 vga_draw_cursor_line_16(d1
, src
, poffset
, w
, color0
, color1
, 0xffff);
2349 vga_draw_cursor_line_32(d1
, src
, poffset
, w
, color0
, color1
, 0xffffff);
2354 /***************************************
2358 ***************************************/
2360 static uint32_t cirrus_linear_readb(void *opaque
, target_phys_addr_t addr
)
2362 CirrusVGAState
*s
= (CirrusVGAState
*) opaque
;
2365 addr
&= s
->cirrus_addr_mask
;
2367 if (((s
->sr
[0x17] & 0x44) == 0x44) &&
2368 ((addr
& s
->linear_mmio_mask
) == s
->linear_mmio_mask
)) {
2369 /* memory-mapped I/O */
2370 ret
= cirrus_mmio_blt_read(s
, addr
& 0xff);
2372 /* XXX handle bitblt */
2376 if ((s
->gr
[0x0B] & 0x14) == 0x14) {
2378 } else if (s
->gr
[0x0B] & 0x02) {
2381 addr
&= s
->cirrus_addr_mask
;
2382 ret
= *(s
->vram_ptr
+ addr
);
2388 static uint32_t cirrus_linear_readw(void *opaque
, target_phys_addr_t addr
)
2391 #ifdef TARGET_WORDS_BIGENDIAN
2392 v
= cirrus_linear_readb(opaque
, addr
) << 8;
2393 v
|= cirrus_linear_readb(opaque
, addr
+ 1);
2395 v
= cirrus_linear_readb(opaque
, addr
);
2396 v
|= cirrus_linear_readb(opaque
, addr
+ 1) << 8;
2401 static uint32_t cirrus_linear_readl(void *opaque
, target_phys_addr_t addr
)
2404 #ifdef TARGET_WORDS_BIGENDIAN
2405 v
= cirrus_linear_readb(opaque
, addr
) << 24;
2406 v
|= cirrus_linear_readb(opaque
, addr
+ 1) << 16;
2407 v
|= cirrus_linear_readb(opaque
, addr
+ 2) << 8;
2408 v
|= cirrus_linear_readb(opaque
, addr
+ 3);
2410 v
= cirrus_linear_readb(opaque
, addr
);
2411 v
|= cirrus_linear_readb(opaque
, addr
+ 1) << 8;
2412 v
|= cirrus_linear_readb(opaque
, addr
+ 2) << 16;
2413 v
|= cirrus_linear_readb(opaque
, addr
+ 3) << 24;
2418 static void cirrus_linear_writeb(void *opaque
, target_phys_addr_t addr
,
2421 CirrusVGAState
*s
= (CirrusVGAState
*) opaque
;
2424 addr
&= s
->cirrus_addr_mask
;
2426 if (((s
->sr
[0x17] & 0x44) == 0x44) &&
2427 ((addr
& s
->linear_mmio_mask
) == s
->linear_mmio_mask
)) {
2428 /* memory-mapped I/O */
2429 cirrus_mmio_blt_write(s
, addr
& 0xff, val
);
2430 } else if (s
->cirrus_srcptr
!= s
->cirrus_srcptr_end
) {
2432 *s
->cirrus_srcptr
++ = (uint8_t) val
;
2433 if (s
->cirrus_srcptr
>= s
->cirrus_srcptr_end
) {
2434 cirrus_bitblt_cputovideo_next(s
);
2438 if ((s
->gr
[0x0B] & 0x14) == 0x14) {
2440 } else if (s
->gr
[0x0B] & 0x02) {
2443 addr
&= s
->cirrus_addr_mask
;
2445 mode
= s
->gr
[0x05] & 0x7;
2446 if (mode
< 4 || mode
> 5 || ((s
->gr
[0x0B] & 0x4) == 0)) {
2447 *(s
->vram_ptr
+ addr
) = (uint8_t) val
;
2448 cpu_physical_memory_set_dirty(s
->vram_offset
+ addr
);
2450 if ((s
->gr
[0x0B] & 0x14) != 0x14) {
2451 cirrus_mem_writeb_mode4and5_8bpp(s
, mode
, addr
, val
);
2453 cirrus_mem_writeb_mode4and5_16bpp(s
, mode
, addr
, val
);
2459 static void cirrus_linear_writew(void *opaque
, target_phys_addr_t addr
,
2462 #ifdef TARGET_WORDS_BIGENDIAN
2463 cirrus_linear_writeb(opaque
, addr
, (val
>> 8) & 0xff);
2464 cirrus_linear_writeb(opaque
, addr
+ 1, val
& 0xff);
2466 cirrus_linear_writeb(opaque
, addr
, val
& 0xff);
2467 cirrus_linear_writeb(opaque
, addr
+ 1, (val
>> 8) & 0xff);
2471 static void cirrus_linear_writel(void *opaque
, target_phys_addr_t addr
,
2474 #ifdef TARGET_WORDS_BIGENDIAN
2475 cirrus_linear_writeb(opaque
, addr
, (val
>> 24) & 0xff);
2476 cirrus_linear_writeb(opaque
, addr
+ 1, (val
>> 16) & 0xff);
2477 cirrus_linear_writeb(opaque
, addr
+ 2, (val
>> 8) & 0xff);
2478 cirrus_linear_writeb(opaque
, addr
+ 3, val
& 0xff);
2480 cirrus_linear_writeb(opaque
, addr
, val
& 0xff);
2481 cirrus_linear_writeb(opaque
, addr
+ 1, (val
>> 8) & 0xff);
2482 cirrus_linear_writeb(opaque
, addr
+ 2, (val
>> 16) & 0xff);
2483 cirrus_linear_writeb(opaque
, addr
+ 3, (val
>> 24) & 0xff);
2488 static CPUReadMemoryFunc
*cirrus_linear_read
[3] = {
2489 cirrus_linear_readb
,
2490 cirrus_linear_readw
,
2491 cirrus_linear_readl
,
2494 static CPUWriteMemoryFunc
*cirrus_linear_write
[3] = {
2495 cirrus_linear_writeb
,
2496 cirrus_linear_writew
,
2497 cirrus_linear_writel
,
2500 static void cirrus_linear_mem_writeb(void *opaque
, target_phys_addr_t addr
,
2503 CirrusVGAState
*s
= (CirrusVGAState
*) opaque
;
2505 addr
&= s
->cirrus_addr_mask
;
2506 *(s
->vram_ptr
+ addr
) = val
;
2507 cpu_physical_memory_set_dirty(s
->vram_offset
+ addr
);
2510 static void cirrus_linear_mem_writew(void *opaque
, target_phys_addr_t addr
,
2513 CirrusVGAState
*s
= (CirrusVGAState
*) opaque
;
2515 addr
&= s
->cirrus_addr_mask
;
2516 cpu_to_le16w((uint16_t *)(s
->vram_ptr
+ addr
), val
);
2517 cpu_physical_memory_set_dirty(s
->vram_offset
+ addr
);
2520 static void cirrus_linear_mem_writel(void *opaque
, target_phys_addr_t addr
,
2523 CirrusVGAState
*s
= (CirrusVGAState
*) opaque
;
2525 addr
&= s
->cirrus_addr_mask
;
2526 cpu_to_le32w((uint32_t *)(s
->vram_ptr
+ addr
), val
);
2527 cpu_physical_memory_set_dirty(s
->vram_offset
+ addr
);
2530 /***************************************
2532 * system to screen memory access
2534 ***************************************/
2537 static uint32_t cirrus_linear_bitblt_readb(void *opaque
, target_phys_addr_t addr
)
2541 /* XXX handle bitblt */
2546 static uint32_t cirrus_linear_bitblt_readw(void *opaque
, target_phys_addr_t addr
)
2549 #ifdef TARGET_WORDS_BIGENDIAN
2550 v
= cirrus_linear_bitblt_readb(opaque
, addr
) << 8;
2551 v
|= cirrus_linear_bitblt_readb(opaque
, addr
+ 1);
2553 v
= cirrus_linear_bitblt_readb(opaque
, addr
);
2554 v
|= cirrus_linear_bitblt_readb(opaque
, addr
+ 1) << 8;
2559 static uint32_t cirrus_linear_bitblt_readl(void *opaque
, target_phys_addr_t addr
)
2562 #ifdef TARGET_WORDS_BIGENDIAN
2563 v
= cirrus_linear_bitblt_readb(opaque
, addr
) << 24;
2564 v
|= cirrus_linear_bitblt_readb(opaque
, addr
+ 1) << 16;
2565 v
|= cirrus_linear_bitblt_readb(opaque
, addr
+ 2) << 8;
2566 v
|= cirrus_linear_bitblt_readb(opaque
, addr
+ 3);
2568 v
= cirrus_linear_bitblt_readb(opaque
, addr
);
2569 v
|= cirrus_linear_bitblt_readb(opaque
, addr
+ 1) << 8;
2570 v
|= cirrus_linear_bitblt_readb(opaque
, addr
+ 2) << 16;
2571 v
|= cirrus_linear_bitblt_readb(opaque
, addr
+ 3) << 24;
2576 static void cirrus_linear_bitblt_writeb(void *opaque
, target_phys_addr_t addr
,
2579 CirrusVGAState
*s
= (CirrusVGAState
*) opaque
;
2581 if (s
->cirrus_srcptr
!= s
->cirrus_srcptr_end
) {
2583 *s
->cirrus_srcptr
++ = (uint8_t) val
;
2584 if (s
->cirrus_srcptr
>= s
->cirrus_srcptr_end
) {
2585 cirrus_bitblt_cputovideo_next(s
);
2590 static void cirrus_linear_bitblt_writew(void *opaque
, target_phys_addr_t addr
,
2593 #ifdef TARGET_WORDS_BIGENDIAN
2594 cirrus_linear_bitblt_writeb(opaque
, addr
, (val
>> 8) & 0xff);
2595 cirrus_linear_bitblt_writeb(opaque
, addr
+ 1, val
& 0xff);
2597 cirrus_linear_bitblt_writeb(opaque
, addr
, val
& 0xff);
2598 cirrus_linear_bitblt_writeb(opaque
, addr
+ 1, (val
>> 8) & 0xff);
2602 static void cirrus_linear_bitblt_writel(void *opaque
, target_phys_addr_t addr
,
2605 #ifdef TARGET_WORDS_BIGENDIAN
2606 cirrus_linear_bitblt_writeb(opaque
, addr
, (val
>> 24) & 0xff);
2607 cirrus_linear_bitblt_writeb(opaque
, addr
+ 1, (val
>> 16) & 0xff);
2608 cirrus_linear_bitblt_writeb(opaque
, addr
+ 2, (val
>> 8) & 0xff);
2609 cirrus_linear_bitblt_writeb(opaque
, addr
+ 3, val
& 0xff);
2611 cirrus_linear_bitblt_writeb(opaque
, addr
, val
& 0xff);
2612 cirrus_linear_bitblt_writeb(opaque
, addr
+ 1, (val
>> 8) & 0xff);
2613 cirrus_linear_bitblt_writeb(opaque
, addr
+ 2, (val
>> 16) & 0xff);
2614 cirrus_linear_bitblt_writeb(opaque
, addr
+ 3, (val
>> 24) & 0xff);
2619 static CPUReadMemoryFunc
*cirrus_linear_bitblt_read
[3] = {
2620 cirrus_linear_bitblt_readb
,
2621 cirrus_linear_bitblt_readw
,
2622 cirrus_linear_bitblt_readl
,
2625 static CPUWriteMemoryFunc
*cirrus_linear_bitblt_write
[3] = {
2626 cirrus_linear_bitblt_writeb
,
2627 cirrus_linear_bitblt_writew
,
2628 cirrus_linear_bitblt_writel
,
2631 void *set_vram_mapping(unsigned long begin
, unsigned long end
)
2633 void *vram_pointer
= NULL
;
2635 /* align begin and end address */
2636 begin
= begin
& TARGET_PAGE_MASK
;
2637 end
= begin
+ VGA_RAM_SIZE
;
2638 end
= (end
+ TARGET_PAGE_SIZE
-1 ) & TARGET_PAGE_MASK
;
2641 vram_pointer
= kvm_cpu_create_phys_mem(begin
, end
- begin
, 1, 1);
2643 if (vram_pointer
== NULL
) {
2644 printf("set_vram_mapping: cannot allocate memory: %m\n");
2648 memset(vram_pointer
, 0, end
- begin
);
2650 return vram_pointer
;
2653 int unset_vram_mapping(unsigned long begin
, unsigned long end
)
2655 /* align begin and end address */
2656 end
= begin
+ VGA_RAM_SIZE
;
2657 begin
= begin
& TARGET_PAGE_MASK
;
2658 end
= (end
+ TARGET_PAGE_SIZE
-1 ) & TARGET_PAGE_MASK
;
2661 kvm_cpu_destroy_phys_mem(begin
, end
- begin
);
2666 static void kvm_update_vga_alias(CirrusVGAState
*s
, int ok
, int bank
)
2668 unsigned limit
, base
;
2670 if (!ok
&& !s
->aliases_enabled
)
2672 limit
= s
->cirrus_bank_limit
[bank
];
2675 base
= s
->cirrus_lfb_addr
+ s
->cirrus_bank_base
[bank
];
2677 if (!s
->aliases_enabled
2678 || base
!= s
->aliased_bank_base
[bank
]
2679 || limit
!= s
->aliased_bank_limit
[bank
]) {
2680 kvm_create_memory_alias(kvm_context
,
2681 0xa0000 + bank
* 0x8000,
2683 s
->aliased_bank_base
[bank
] = base
;
2684 s
->aliased_bank_limit
[bank
] = limit
;
2687 kvm_destroy_memory_alias(kvm_context
, 0xa0000 + bank
* 0x8000);
2691 static void kvm_update_vga_aliases(CirrusVGAState
*s
, int ok
)
2693 if (kvm_enabled()) {
2694 kvm_update_vga_alias(s
, ok
, 0);
2695 kvm_update_vga_alias(s
, ok
, 1);
2697 s
->aliases_enabled
= ok
;
2701 /* Compute the memory access functions */
2702 static void cirrus_update_memory_access(CirrusVGAState
*s
)
2706 int want_vga_alias
= 0;
2709 if ((s
->sr
[0x17] & 0x44) == 0x44) {
2711 } else if (s
->cirrus_srcptr
!= s
->cirrus_srcptr_end
) {
2714 if ((s
->gr
[0x0B] & 0x14) == 0x14) {
2716 } else if (s
->gr
[0x0B] & 0x02) {
2720 mode
= s
->gr
[0x05] & 0x7;
2721 if (mode
< 4 || mode
> 5 || ((s
->gr
[0x0B] & 0x4) == 0)) {
2722 if (kvm_enabled() && s
->cirrus_lfb_addr
&& s
->cirrus_lfb_end
&&
2724 void *vram_pointer
, *old_vram
;
2726 vram_pointer
= set_vram_mapping(s
->cirrus_lfb_addr
,
2729 fprintf(stderr
, "NULL vram_pointer\n");
2731 old_vram
= vga_update_vram((VGAState
*)s
, vram_pointer
,
2733 qemu_free(old_vram
);
2735 s
->map_addr
= s
->cirrus_lfb_addr
;
2736 s
->map_end
= s
->cirrus_lfb_end
;
2740 && !(s
->cirrus_srcptr
!= s
->cirrus_srcptr_end
)
2741 && !((s
->sr
[0x07] & 0x01) == 0)
2742 && !((s
->gr
[0x0B] & 0x14) == 0x14)
2743 && !(s
->gr
[0x0B] & 0x02))
2746 s
->cirrus_linear_write
[0] = cirrus_linear_mem_writeb
;
2747 s
->cirrus_linear_write
[1] = cirrus_linear_mem_writew
;
2748 s
->cirrus_linear_write
[2] = cirrus_linear_mem_writel
;
2751 if (kvm_enabled() && s
->cirrus_lfb_addr
&& s
->cirrus_lfb_end
&&
2754 void *old_vram
= NULL
;
2756 error
= unset_vram_mapping(s
->cirrus_lfb_addr
,
2759 old_vram
= vga_update_vram((VGAState
*)s
, NULL
,
2762 munmap(old_vram
, s
->map_end
- s
->map_addr
);
2763 s
->map_addr
= s
->map_end
= 0;
2765 s
->cirrus_linear_write
[0] = cirrus_linear_writeb
;
2766 s
->cirrus_linear_write
[1] = cirrus_linear_writew
;
2767 s
->cirrus_linear_write
[2] = cirrus_linear_writel
;
2770 #if defined(CONFIG_X86)
2771 kvm_update_vga_aliases(s
, want_vga_alias
);
2779 static uint32_t vga_ioport_read(void *opaque
, uint32_t addr
)
2781 CirrusVGAState
*s
= opaque
;
2784 /* check port range access depending on color/monochrome mode */
2785 if ((addr
>= 0x3b0 && addr
<= 0x3bf && (s
->msr
& MSR_COLOR_EMULATION
))
2786 || (addr
>= 0x3d0 && addr
<= 0x3df
2787 && !(s
->msr
& MSR_COLOR_EMULATION
))) {
2792 if (s
->ar_flip_flop
== 0) {
2799 index
= s
->ar_index
& 0x1f;
2812 if (cirrus_hook_read_sr(s
, s
->sr_index
, &val
))
2814 val
= s
->sr
[s
->sr_index
];
2815 #ifdef DEBUG_VGA_REG
2816 printf("vga: read SR%x = 0x%02x\n", s
->sr_index
, val
);
2820 cirrus_read_hidden_dac(s
, &val
);
2826 val
= s
->dac_write_index
;
2827 s
->cirrus_hidden_dac_lockindex
= 0;
2830 if (cirrus_hook_read_palette(s
, &val
))
2832 val
= s
->palette
[s
->dac_read_index
* 3 + s
->dac_sub_index
];
2833 if (++s
->dac_sub_index
== 3) {
2834 s
->dac_sub_index
= 0;
2835 s
->dac_read_index
++;
2848 if (cirrus_hook_read_gr(s
, s
->gr_index
, &val
))
2850 val
= s
->gr
[s
->gr_index
];
2851 #ifdef DEBUG_VGA_REG
2852 printf("vga: read GR%x = 0x%02x\n", s
->gr_index
, val
);
2861 if (cirrus_hook_read_cr(s
, s
->cr_index
, &val
))
2863 val
= s
->cr
[s
->cr_index
];
2864 #ifdef DEBUG_VGA_REG
2865 printf("vga: read CR%x = 0x%02x\n", s
->cr_index
, val
);
2870 /* just toggle to fool polling */
2871 s
->st01
^= ST01_V_RETRACE
| ST01_DISP_ENABLE
;
2873 s
->ar_flip_flop
= 0;
2880 #if defined(DEBUG_VGA)
2881 printf("VGA: read addr=0x%04x data=0x%02x\n", addr
, val
);
2886 static void vga_ioport_write(void *opaque
, uint32_t addr
, uint32_t val
)
2888 CirrusVGAState
*s
= opaque
;
2891 /* check port range access depending on color/monochrome mode */
2892 if ((addr
>= 0x3b0 && addr
<= 0x3bf && (s
->msr
& MSR_COLOR_EMULATION
))
2893 || (addr
>= 0x3d0 && addr
<= 0x3df
2894 && !(s
->msr
& MSR_COLOR_EMULATION
)))
2898 printf("VGA: write addr=0x%04x data=0x%02x\n", addr
, val
);
2903 if (s
->ar_flip_flop
== 0) {
2907 index
= s
->ar_index
& 0x1f;
2910 s
->ar
[index
] = val
& 0x3f;
2913 s
->ar
[index
] = val
& ~0x10;
2919 s
->ar
[index
] = val
& ~0xc0;
2922 s
->ar
[index
] = val
& ~0xf0;
2925 s
->ar
[index
] = val
& ~0xf0;
2931 s
->ar_flip_flop
^= 1;
2934 s
->msr
= val
& ~0x10;
2940 if (cirrus_hook_write_sr(s
, s
->sr_index
, val
))
2942 #ifdef DEBUG_VGA_REG
2943 printf("vga: write SR%x = 0x%02x\n", s
->sr_index
, val
);
2945 s
->sr
[s
->sr_index
] = val
& sr_mask
[s
->sr_index
];
2948 cirrus_write_hidden_dac(s
, val
);
2951 s
->dac_read_index
= val
;
2952 s
->dac_sub_index
= 0;
2956 s
->dac_write_index
= val
;
2957 s
->dac_sub_index
= 0;
2961 if (cirrus_hook_write_palette(s
, val
))
2963 s
->dac_cache
[s
->dac_sub_index
] = val
;
2964 if (++s
->dac_sub_index
== 3) {
2965 memcpy(&s
->palette
[s
->dac_write_index
* 3], s
->dac_cache
, 3);
2966 s
->dac_sub_index
= 0;
2967 s
->dac_write_index
++;
2974 if (cirrus_hook_write_gr(s
, s
->gr_index
, val
))
2976 #ifdef DEBUG_VGA_REG
2977 printf("vga: write GR%x = 0x%02x\n", s
->gr_index
, val
);
2979 s
->gr
[s
->gr_index
] = val
& gr_mask
[s
->gr_index
];
2987 if (cirrus_hook_write_cr(s
, s
->cr_index
, val
))
2989 #ifdef DEBUG_VGA_REG
2990 printf("vga: write CR%x = 0x%02x\n", s
->cr_index
, val
);
2992 /* handle CR0-7 protection */
2993 if ((s
->cr
[0x11] & 0x80) && s
->cr_index
<= 7) {
2994 /* can always write bit 4 of CR7 */
2995 if (s
->cr_index
== 7)
2996 s
->cr
[7] = (s
->cr
[7] & ~0x10) | (val
& 0x10);
2999 switch (s
->cr_index
) {
3000 case 0x01: /* horizontal display end */
3005 case 0x12: /* vertical display end */
3006 s
->cr
[s
->cr_index
] = val
;
3010 s
->cr
[s
->cr_index
] = val
;
3016 s
->fcr
= val
& 0x10;
3021 /***************************************
3023 * memory-mapped I/O access
3025 ***************************************/
3027 static uint32_t cirrus_mmio_readb(void *opaque
, target_phys_addr_t addr
)
3029 CirrusVGAState
*s
= (CirrusVGAState
*) opaque
;
3031 addr
&= CIRRUS_PNPMMIO_SIZE
- 1;
3033 if (addr
>= 0x100) {
3034 return cirrus_mmio_blt_read(s
, addr
- 0x100);
3036 return vga_ioport_read(s
, addr
+ 0x3c0);
3040 static uint32_t cirrus_mmio_readw(void *opaque
, target_phys_addr_t addr
)
3043 #ifdef TARGET_WORDS_BIGENDIAN
3044 v
= cirrus_mmio_readb(opaque
, addr
) << 8;
3045 v
|= cirrus_mmio_readb(opaque
, addr
+ 1);
3047 v
= cirrus_mmio_readb(opaque
, addr
);
3048 v
|= cirrus_mmio_readb(opaque
, addr
+ 1) << 8;
3053 static uint32_t cirrus_mmio_readl(void *opaque
, target_phys_addr_t addr
)
3056 #ifdef TARGET_WORDS_BIGENDIAN
3057 v
= cirrus_mmio_readb(opaque
, addr
) << 24;
3058 v
|= cirrus_mmio_readb(opaque
, addr
+ 1) << 16;
3059 v
|= cirrus_mmio_readb(opaque
, addr
+ 2) << 8;
3060 v
|= cirrus_mmio_readb(opaque
, addr
+ 3);
3062 v
= cirrus_mmio_readb(opaque
, addr
);
3063 v
|= cirrus_mmio_readb(opaque
, addr
+ 1) << 8;
3064 v
|= cirrus_mmio_readb(opaque
, addr
+ 2) << 16;
3065 v
|= cirrus_mmio_readb(opaque
, addr
+ 3) << 24;
3070 static void cirrus_mmio_writeb(void *opaque
, target_phys_addr_t addr
,
3073 CirrusVGAState
*s
= (CirrusVGAState
*) opaque
;
3075 addr
&= CIRRUS_PNPMMIO_SIZE
- 1;
3077 if (addr
>= 0x100) {
3078 cirrus_mmio_blt_write(s
, addr
- 0x100, val
);
3080 vga_ioport_write(s
, addr
+ 0x3c0, val
);
3084 static void cirrus_mmio_writew(void *opaque
, target_phys_addr_t addr
,
3087 #ifdef TARGET_WORDS_BIGENDIAN
3088 cirrus_mmio_writeb(opaque
, addr
, (val
>> 8) & 0xff);
3089 cirrus_mmio_writeb(opaque
, addr
+ 1, val
& 0xff);
3091 cirrus_mmio_writeb(opaque
, addr
, val
& 0xff);
3092 cirrus_mmio_writeb(opaque
, addr
+ 1, (val
>> 8) & 0xff);
3096 static void cirrus_mmio_writel(void *opaque
, target_phys_addr_t addr
,
3099 #ifdef TARGET_WORDS_BIGENDIAN
3100 cirrus_mmio_writeb(opaque
, addr
, (val
>> 24) & 0xff);
3101 cirrus_mmio_writeb(opaque
, addr
+ 1, (val
>> 16) & 0xff);
3102 cirrus_mmio_writeb(opaque
, addr
+ 2, (val
>> 8) & 0xff);
3103 cirrus_mmio_writeb(opaque
, addr
+ 3, val
& 0xff);
3105 cirrus_mmio_writeb(opaque
, addr
, val
& 0xff);
3106 cirrus_mmio_writeb(opaque
, addr
+ 1, (val
>> 8) & 0xff);
3107 cirrus_mmio_writeb(opaque
, addr
+ 2, (val
>> 16) & 0xff);
3108 cirrus_mmio_writeb(opaque
, addr
+ 3, (val
>> 24) & 0xff);
3113 static CPUReadMemoryFunc
*cirrus_mmio_read
[3] = {
3119 static CPUWriteMemoryFunc
*cirrus_mmio_write
[3] = {
3125 /* load/save state */
3127 static void cirrus_vga_save(QEMUFile
*f
, void *opaque
)
3129 CirrusVGAState
*s
= opaque
;
3132 pci_device_save(s
->pci_dev
, f
);
3134 qemu_put_be32s(f
, &s
->latch
);
3135 qemu_put_8s(f
, &s
->sr_index
);
3136 qemu_put_buffer(f
, s
->sr
, 256);
3137 qemu_put_8s(f
, &s
->gr_index
);
3138 qemu_put_8s(f
, &s
->cirrus_shadow_gr0
);
3139 qemu_put_8s(f
, &s
->cirrus_shadow_gr1
);
3140 qemu_put_buffer(f
, s
->gr
+ 2, 254);
3141 qemu_put_8s(f
, &s
->ar_index
);
3142 qemu_put_buffer(f
, s
->ar
, 21);
3143 qemu_put_be32(f
, s
->ar_flip_flop
);
3144 qemu_put_8s(f
, &s
->cr_index
);
3145 qemu_put_buffer(f
, s
->cr
, 256);
3146 qemu_put_8s(f
, &s
->msr
);
3147 qemu_put_8s(f
, &s
->fcr
);
3148 qemu_put_8s(f
, &s
->st00
);
3149 qemu_put_8s(f
, &s
->st01
);
3151 qemu_put_8s(f
, &s
->dac_state
);
3152 qemu_put_8s(f
, &s
->dac_sub_index
);
3153 qemu_put_8s(f
, &s
->dac_read_index
);
3154 qemu_put_8s(f
, &s
->dac_write_index
);
3155 qemu_put_buffer(f
, s
->dac_cache
, 3);
3156 qemu_put_buffer(f
, s
->palette
, 768);
3158 qemu_put_be32(f
, s
->bank_offset
);
3160 qemu_put_8s(f
, &s
->cirrus_hidden_dac_lockindex
);
3161 qemu_put_8s(f
, &s
->cirrus_hidden_dac_data
);
3163 qemu_put_be32s(f
, &s
->hw_cursor_x
);
3164 qemu_put_be32s(f
, &s
->hw_cursor_y
);
3165 /* XXX: we do not save the bitblt state - we assume we do not save
3166 the state when the blitter is active */
3168 if (kvm_enabled()) { /* XXX: KVM images ought to be loadable in QEMU */
3169 qemu_put_be32s(f
, &s
->real_vram_size
);
3170 qemu_put_buffer(f
, s
->vram_ptr
, s
->real_vram_size
);
3174 static int cirrus_vga_load(QEMUFile
*f
, void *opaque
, int version_id
)
3176 CirrusVGAState
*s
= opaque
;
3182 if (s
->pci_dev
&& version_id
>= 2) {
3183 ret
= pci_device_load(s
->pci_dev
, f
);
3188 qemu_get_be32s(f
, &s
->latch
);
3189 qemu_get_8s(f
, &s
->sr_index
);
3190 qemu_get_buffer(f
, s
->sr
, 256);
3191 qemu_get_8s(f
, &s
->gr_index
);
3192 qemu_get_8s(f
, &s
->cirrus_shadow_gr0
);
3193 qemu_get_8s(f
, &s
->cirrus_shadow_gr1
);
3194 s
->gr
[0x00] = s
->cirrus_shadow_gr0
& 0x0f;
3195 s
->gr
[0x01] = s
->cirrus_shadow_gr1
& 0x0f;
3196 qemu_get_buffer(f
, s
->gr
+ 2, 254);
3197 qemu_get_8s(f
, &s
->ar_index
);
3198 qemu_get_buffer(f
, s
->ar
, 21);
3199 s
->ar_flip_flop
=qemu_get_be32(f
);
3200 qemu_get_8s(f
, &s
->cr_index
);
3201 qemu_get_buffer(f
, s
->cr
, 256);
3202 qemu_get_8s(f
, &s
->msr
);
3203 qemu_get_8s(f
, &s
->fcr
);
3204 qemu_get_8s(f
, &s
->st00
);
3205 qemu_get_8s(f
, &s
->st01
);
3207 qemu_get_8s(f
, &s
->dac_state
);
3208 qemu_get_8s(f
, &s
->dac_sub_index
);
3209 qemu_get_8s(f
, &s
->dac_read_index
);
3210 qemu_get_8s(f
, &s
->dac_write_index
);
3211 qemu_get_buffer(f
, s
->dac_cache
, 3);
3212 qemu_get_buffer(f
, s
->palette
, 768);
3214 s
->bank_offset
=qemu_get_be32(f
);
3216 qemu_get_8s(f
, &s
->cirrus_hidden_dac_lockindex
);
3217 qemu_get_8s(f
, &s
->cirrus_hidden_dac_data
);
3219 qemu_get_be32s(f
, &s
->hw_cursor_x
);
3220 qemu_get_be32s(f
, &s
->hw_cursor_y
);
3222 if (kvm_enabled()) {
3224 qemu_get_be32s(f
, &real_vram_size
);
3225 if (real_vram_size
!= s
->real_vram_size
) {
3226 if (real_vram_size
> s
->real_vram_size
)
3227 real_vram_size
= s
->real_vram_size
;
3228 printf("%s: REAL_VRAM_SIZE MISMATCH !!!!!! SAVED=%d CURRENT=%d",
3229 __FUNCTION__
, real_vram_size
, s
->real_vram_size
);
3231 qemu_get_buffer(f
, s
->vram_ptr
, real_vram_size
);
3232 cirrus_update_memory_access(s
);
3237 s
->graphic_mode
= -1;
3238 cirrus_update_bank_ptr(s
, 0);
3239 cirrus_update_bank_ptr(s
, 1);
3243 /***************************************
3247 ***************************************/
3249 static void cirrus_init_common(CirrusVGAState
* s
, int device_id
, int is_pci
)
3251 int vga_io_memory
, i
;
3256 for(i
= 0;i
< 256; i
++)
3257 rop_to_index
[i
] = CIRRUS_ROP_NOP_INDEX
; /* nop rop */
3258 rop_to_index
[CIRRUS_ROP_0
] = 0;
3259 rop_to_index
[CIRRUS_ROP_SRC_AND_DST
] = 1;
3260 rop_to_index
[CIRRUS_ROP_NOP
] = 2;
3261 rop_to_index
[CIRRUS_ROP_SRC_AND_NOTDST
] = 3;
3262 rop_to_index
[CIRRUS_ROP_NOTDST
] = 4;
3263 rop_to_index
[CIRRUS_ROP_SRC
] = 5;
3264 rop_to_index
[CIRRUS_ROP_1
] = 6;
3265 rop_to_index
[CIRRUS_ROP_NOTSRC_AND_DST
] = 7;
3266 rop_to_index
[CIRRUS_ROP_SRC_XOR_DST
] = 8;
3267 rop_to_index
[CIRRUS_ROP_SRC_OR_DST
] = 9;
3268 rop_to_index
[CIRRUS_ROP_NOTSRC_OR_NOTDST
] = 10;
3269 rop_to_index
[CIRRUS_ROP_SRC_NOTXOR_DST
] = 11;
3270 rop_to_index
[CIRRUS_ROP_SRC_OR_NOTDST
] = 12;
3271 rop_to_index
[CIRRUS_ROP_NOTSRC
] = 13;
3272 rop_to_index
[CIRRUS_ROP_NOTSRC_OR_DST
] = 14;
3273 rop_to_index
[CIRRUS_ROP_NOTSRC_AND_NOTDST
] = 15;
3276 register_ioport_write(0x3c0, 16, 1, vga_ioport_write
, s
);
3278 register_ioport_write(0x3b4, 2, 1, vga_ioport_write
, s
);
3279 register_ioport_write(0x3d4, 2, 1, vga_ioport_write
, s
);
3280 register_ioport_write(0x3ba, 1, 1, vga_ioport_write
, s
);
3281 register_ioport_write(0x3da, 1, 1, vga_ioport_write
, s
);
3283 register_ioport_read(0x3c0, 16, 1, vga_ioport_read
, s
);
3285 register_ioport_read(0x3b4, 2, 1, vga_ioport_read
, s
);
3286 register_ioport_read(0x3d4, 2, 1, vga_ioport_read
, s
);
3287 register_ioport_read(0x3ba, 1, 1, vga_ioport_read
, s
);
3288 register_ioport_read(0x3da, 1, 1, vga_ioport_read
, s
);
3290 vga_io_memory
= cpu_register_io_memory(0, cirrus_vga_mem_read
,
3291 cirrus_vga_mem_write
, s
);
3292 cpu_register_physical_memory(isa_mem_base
+ 0x000a0000, 0x20000,
3295 qemu_kvm_register_coalesced_mmio(isa_mem_base
+ 0x000a0000, 0x20000);
3298 if (device_id
== CIRRUS_ID_CLGD5446
) {
3299 /* 4MB 64 bit memory config, always PCI */
3300 s
->sr
[0x1F] = 0x2d; // MemClock
3301 s
->gr
[0x18] = 0x0f; // fastest memory configuration
3305 s
->sr
[0x15] = 0x04; /* memory size, 3=2MB, 4=4MB */
3306 s
->real_vram_size
= 4096 * 1024;
3310 s
->sr
[0x15] = 0x03; /* memory size, 3=2MB, 4=4MB */
3311 s
->real_vram_size
= 2048 * 1024;
3314 s
->sr
[0x1F] = 0x22; // MemClock
3315 s
->sr
[0x0F] = CIRRUS_MEMSIZE_2M
;
3317 s
->sr
[0x17] = CIRRUS_BUSTYPE_PCI
;
3319 s
->sr
[0x17] = CIRRUS_BUSTYPE_ISA
;
3320 s
->real_vram_size
= 2048 * 1024;
3321 s
->sr
[0x15] = 0x03; /* memory size, 3=2MB, 4=4MB */
3323 s
->cr
[0x27] = device_id
;
3325 /* Win2K seems to assume that the pattern buffer is at 0xff
3327 memset(s
->vram_ptr
, 0xff, s
->real_vram_size
);
3329 s
->cirrus_hidden_dac_lockindex
= 5;
3330 s
->cirrus_hidden_dac_data
= 0;
3332 /* I/O handler for LFB */
3333 s
->cirrus_linear_io_addr
=
3334 cpu_register_io_memory(0, cirrus_linear_read
, cirrus_linear_write
,
3336 s
->cirrus_linear_write
= cpu_get_io_memory_write(s
->cirrus_linear_io_addr
);
3338 /* I/O handler for LFB */
3339 s
->cirrus_linear_bitblt_io_addr
=
3340 cpu_register_io_memory(0, cirrus_linear_bitblt_read
, cirrus_linear_bitblt_write
,
3343 /* I/O handler for memory-mapped I/O */
3344 s
->cirrus_mmio_io_addr
=
3345 cpu_register_io_memory(0, cirrus_mmio_read
, cirrus_mmio_write
, s
);
3347 /* XXX: s->vram_size must be a power of two */
3348 s
->cirrus_addr_mask
= s
->real_vram_size
- 1;
3349 s
->linear_mmio_mask
= s
->real_vram_size
- 256;
3351 s
->get_bpp
= cirrus_get_bpp
;
3352 s
->get_offsets
= cirrus_get_offsets
;
3353 s
->get_resolution
= cirrus_get_resolution
;
3354 s
->cursor_invalidate
= cirrus_cursor_invalidate
;
3355 s
->cursor_draw_line
= cirrus_cursor_draw_line
;
3357 register_savevm("cirrus_vga", 0, 2, cirrus_vga_save
, cirrus_vga_load
, s
);
3360 /***************************************
3364 ***************************************/
3366 void isa_cirrus_vga_init(DisplayState
*ds
, uint8_t *vga_ram_base
,
3367 unsigned long vga_ram_offset
, int vga_ram_size
)
3371 s
= qemu_mallocz(sizeof(CirrusVGAState
));
3373 vga_common_init((VGAState
*)s
,
3374 ds
, vga_ram_base
, vga_ram_offset
, vga_ram_size
);
3375 cirrus_init_common(s
, CIRRUS_ID_CLGD5430
, 0);
3376 /* XXX ISA-LFB support */
3379 /***************************************
3383 ***************************************/
3385 static void cirrus_pci_lfb_map(PCIDevice
*d
, int region_num
,
3386 uint32_t addr
, uint32_t size
, int type
)
3388 CirrusVGAState
*s
= &((PCICirrusVGAState
*)d
)->cirrus_vga
;
3390 /* XXX: add byte swapping apertures */
3391 cpu_register_physical_memory(addr
, s
->vram_size
,
3392 s
->cirrus_linear_io_addr
);
3393 if (kvm_enabled()) {
3394 s
->cirrus_lfb_addr
= addr
;
3395 s
->cirrus_lfb_end
= addr
+ VGA_RAM_SIZE
;
3397 if (s
->map_addr
&& (s
->cirrus_lfb_addr
!= s
->map_addr
) &&
3398 (s
->cirrus_lfb_end
!= s
->map_end
))
3399 printf("cirrus vga map change while on lfb mode\n");
3402 cpu_register_physical_memory(addr
+ 0x1000000, 0x400000,
3403 s
->cirrus_linear_bitblt_io_addr
);
3406 static void cirrus_pci_mmio_map(PCIDevice
*d
, int region_num
,
3407 uint32_t addr
, uint32_t size
, int type
)
3409 CirrusVGAState
*s
= &((PCICirrusVGAState
*)d
)->cirrus_vga
;
3411 cpu_register_physical_memory(addr
, CIRRUS_PNPMMIO_SIZE
,
3412 s
->cirrus_mmio_io_addr
);
3415 void pci_cirrus_vga_init(PCIBus
*bus
, DisplayState
*ds
, uint8_t *vga_ram_base
,
3416 unsigned long vga_ram_offset
, int vga_ram_size
)
3418 PCICirrusVGAState
*d
;
3423 device_id
= CIRRUS_ID_CLGD5446
;
3425 /* setup PCI configuration registers */
3426 d
= (PCICirrusVGAState
*)pci_register_device(bus
, "Cirrus VGA",
3427 sizeof(PCICirrusVGAState
),
3429 pci_conf
= d
->dev
.config
;
3430 pci_conf
[0x00] = (uint8_t) (PCI_VENDOR_CIRRUS
& 0xff);
3431 pci_conf
[0x01] = (uint8_t) (PCI_VENDOR_CIRRUS
>> 8);
3432 pci_conf
[0x02] = (uint8_t) (device_id
& 0xff);
3433 pci_conf
[0x03] = (uint8_t) (device_id
>> 8);
3434 pci_conf
[0x04] = PCI_COMMAND_IOACCESS
| PCI_COMMAND_MEMACCESS
;
3435 pci_conf
[0x0a] = PCI_CLASS_SUB_VGA
;
3436 pci_conf
[0x0b] = PCI_CLASS_BASE_DISPLAY
;
3437 pci_conf
[0x0e] = PCI_CLASS_HEADERTYPE_00h
;
3441 vga_common_init((VGAState
*)s
,
3442 ds
, vga_ram_base
, vga_ram_offset
, vga_ram_size
);
3443 cirrus_init_common(s
, device_id
, 1);
3445 s
->console
= graphic_console_init(s
->ds
, s
->update
, s
->invalidate
,
3446 s
->screen_dump
, s
->text_update
, s
);
3448 s
->pci_dev
= (PCIDevice
*)d
;
3450 /* setup memory space */
3452 /* memory #1 memory-mapped I/O */
3453 /* XXX: s->vram_size must be a power of two */
3454 pci_register_io_region((PCIDevice
*)d
, 0, 0x2000000,
3455 PCI_ADDRESS_SPACE_MEM_PREFETCH
, cirrus_pci_lfb_map
);
3456 if (device_id
== CIRRUS_ID_CLGD5446
) {
3457 pci_register_io_region((PCIDevice
*)d
, 1, CIRRUS_PNPMMIO_SIZE
,
3458 PCI_ADDRESS_SPACE_MEM
, cirrus_pci_mmio_map
);