2 * QEMU Cirrus CLGD 54xx VGA Emulator.
4 * Copyright (c) 2004 Fabrice Bellard
5 * Copyright (c) 2004 Makoto Suzuki (suzu)
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26 * Reference: Finn Thogersons' VGADOC4b
27 * available at http://home.worldonline.dk/~finth/
34 * - add support for WRITEMASK (GR2F)
35 * - add support for scanline modulo in pattern fill
36 * - optimize linear mappings
37 * - optimize bitblt functions
40 //#define DEBUG_CIRRUS
41 //#define DEBUG_BITBLT
43 /***************************************
47 ***************************************/
49 #define qemu_MIN(a,b) ((a) < (b) ? (a) : (b))
52 #define CIRRUS_ID_CLGD5422 (0x23<<2)
53 #define CIRRUS_ID_CLGD5426 (0x24<<2)
54 #define CIRRUS_ID_CLGD5424 (0x25<<2)
55 #define CIRRUS_ID_CLGD5428 (0x26<<2)
56 #define CIRRUS_ID_CLGD5430 (0x28<<2)
57 #define CIRRUS_ID_CLGD5434 (0x2A<<2)
58 #define CIRRUS_ID_CLGD5436 (0x2B<<2)
59 #define CIRRUS_ID_CLGD5446 (0x2E<<2)
62 #define CIRRUS_SR7_BPP_VGA 0x00
63 #define CIRRUS_SR7_BPP_SVGA 0x01
64 #define CIRRUS_SR7_BPP_MASK 0x0e
65 #define CIRRUS_SR7_BPP_8 0x00
66 #define CIRRUS_SR7_BPP_16_DOUBLEVCLK 0x02
67 #define CIRRUS_SR7_BPP_24 0x04
68 #define CIRRUS_SR7_BPP_16 0x06
69 #define CIRRUS_SR7_BPP_32 0x08
70 #define CIRRUS_SR7_ISAADDR_MASK 0xe0
73 #define CIRRUS_MEMSIZE_512k 0x08
74 #define CIRRUS_MEMSIZE_1M 0x10
75 #define CIRRUS_MEMSIZE_2M 0x18
76 #define CIRRUS_MEMFLAGS_BANKSWITCH 0x80 // bank switching is enabled.
79 #define CIRRUS_CURSOR_SHOW 0x01
80 #define CIRRUS_CURSOR_HIDDENPEL 0x02
81 #define CIRRUS_CURSOR_LARGE 0x04 // 64x64 if set, 32x32 if clear
84 #define CIRRUS_BUSTYPE_VLBFAST 0x10
85 #define CIRRUS_BUSTYPE_PCI 0x20
86 #define CIRRUS_BUSTYPE_VLBSLOW 0x30
87 #define CIRRUS_BUSTYPE_ISA 0x38
88 #define CIRRUS_MMIO_ENABLE 0x04
89 #define CIRRUS_MMIO_USE_PCIADDR 0x40 // 0xb8000 if cleared.
90 #define CIRRUS_MEMSIZEEXT_DOUBLE 0x80
93 #define CIRRUS_BANKING_DUAL 0x01
94 #define CIRRUS_BANKING_GRANULARITY_16K 0x20 // set:16k, clear:4k
97 #define CIRRUS_BLTMODE_BACKWARDS 0x01
98 #define CIRRUS_BLTMODE_MEMSYSDEST 0x02
99 #define CIRRUS_BLTMODE_MEMSYSSRC 0x04
100 #define CIRRUS_BLTMODE_TRANSPARENTCOMP 0x08
101 #define CIRRUS_BLTMODE_PATTERNCOPY 0x40
102 #define CIRRUS_BLTMODE_COLOREXPAND 0x80
103 #define CIRRUS_BLTMODE_PIXELWIDTHMASK 0x30
104 #define CIRRUS_BLTMODE_PIXELWIDTH8 0x00
105 #define CIRRUS_BLTMODE_PIXELWIDTH16 0x10
106 #define CIRRUS_BLTMODE_PIXELWIDTH24 0x20
107 #define CIRRUS_BLTMODE_PIXELWIDTH32 0x30
110 #define CIRRUS_BLT_BUSY 0x01
111 #define CIRRUS_BLT_START 0x02
112 #define CIRRUS_BLT_RESET 0x04
113 #define CIRRUS_BLT_FIFOUSED 0x10
114 #define CIRRUS_BLT_AUTOSTART 0x80
117 #define CIRRUS_ROP_0 0x00
118 #define CIRRUS_ROP_SRC_AND_DST 0x05
119 #define CIRRUS_ROP_NOP 0x06
120 #define CIRRUS_ROP_SRC_AND_NOTDST 0x09
121 #define CIRRUS_ROP_NOTDST 0x0b
122 #define CIRRUS_ROP_SRC 0x0d
123 #define CIRRUS_ROP_1 0x0e
124 #define CIRRUS_ROP_NOTSRC_AND_DST 0x50
125 #define CIRRUS_ROP_SRC_XOR_DST 0x59
126 #define CIRRUS_ROP_SRC_OR_DST 0x6d
127 #define CIRRUS_ROP_NOTSRC_OR_NOTDST 0x90
128 #define CIRRUS_ROP_SRC_NOTXOR_DST 0x95
129 #define CIRRUS_ROP_SRC_OR_NOTDST 0xad
130 #define CIRRUS_ROP_NOTSRC 0xd0
131 #define CIRRUS_ROP_NOTSRC_OR_DST 0xd6
132 #define CIRRUS_ROP_NOTSRC_AND_NOTDST 0xda
134 #define CIRRUS_ROP_NOP_INDEX 2
135 #define CIRRUS_ROP_SRC_INDEX 5
138 #define CIRRUS_BLTMODEEXT_SOLIDFILL 0x04
139 #define CIRRUS_BLTMODEEXT_DWORDGRANULARITY 0x01
142 #define CIRRUS_MMIO_BLTBGCOLOR 0x00 // dword
143 #define CIRRUS_MMIO_BLTFGCOLOR 0x04 // dword
144 #define CIRRUS_MMIO_BLTWIDTH 0x08 // word
145 #define CIRRUS_MMIO_BLTHEIGHT 0x0a // word
146 #define CIRRUS_MMIO_BLTDESTPITCH 0x0c // word
147 #define CIRRUS_MMIO_BLTSRCPITCH 0x0e // word
148 #define CIRRUS_MMIO_BLTDESTADDR 0x10 // dword
149 #define CIRRUS_MMIO_BLTSRCADDR 0x14 // dword
150 #define CIRRUS_MMIO_BLTWRITEMASK 0x17 // byte
151 #define CIRRUS_MMIO_BLTMODE 0x18 // byte
152 #define CIRRUS_MMIO_BLTROP 0x1a // byte
153 #define CIRRUS_MMIO_BLTMODEEXT 0x1b // byte
154 #define CIRRUS_MMIO_BLTTRANSPARENTCOLOR 0x1c // word?
155 #define CIRRUS_MMIO_BLTTRANSPARENTCOLORMASK 0x20 // word?
156 #define CIRRUS_MMIO_LINEARDRAW_START_X 0x24 // word
157 #define CIRRUS_MMIO_LINEARDRAW_START_Y 0x26 // word
158 #define CIRRUS_MMIO_LINEARDRAW_END_X 0x28 // word
159 #define CIRRUS_MMIO_LINEARDRAW_END_Y 0x2a // word
160 #define CIRRUS_MMIO_LINEARDRAW_LINESTYLE_INC 0x2c // byte
161 #define CIRRUS_MMIO_LINEARDRAW_LINESTYLE_ROLLOVER 0x2d // byte
162 #define CIRRUS_MMIO_LINEARDRAW_LINESTYLE_MASK 0x2e // byte
163 #define CIRRUS_MMIO_LINEARDRAW_LINESTYLE_ACCUM 0x2f // byte
164 #define CIRRUS_MMIO_BRESENHAM_K1 0x30 // word
165 #define CIRRUS_MMIO_BRESENHAM_K3 0x32 // word
166 #define CIRRUS_MMIO_BRESENHAM_ERROR 0x34 // word
167 #define CIRRUS_MMIO_BRESENHAM_DELTA_MAJOR 0x36 // word
168 #define CIRRUS_MMIO_BRESENHAM_DIRECTION 0x38 // byte
169 #define CIRRUS_MMIO_LINEDRAW_MODE 0x39 // byte
170 #define CIRRUS_MMIO_BLTSTATUS 0x40 // byte
172 // PCI 0x00: vendor, 0x02: device
173 #define PCI_VENDOR_CIRRUS 0x1013
174 #define PCI_DEVICE_CLGD5462 0x00d0
175 #define PCI_DEVICE_CLGD5465 0x00d6
177 // PCI 0x04: command(word), 0x06(word): status
178 #define PCI_COMMAND_IOACCESS 0x0001
179 #define PCI_COMMAND_MEMACCESS 0x0002
180 #define PCI_COMMAND_BUSMASTER 0x0004
181 #define PCI_COMMAND_SPECIALCYCLE 0x0008
182 #define PCI_COMMAND_MEMWRITEINVALID 0x0010
183 #define PCI_COMMAND_PALETTESNOOPING 0x0020
184 #define PCI_COMMAND_PARITYDETECTION 0x0040
185 #define PCI_COMMAND_ADDRESSDATASTEPPING 0x0080
186 #define PCI_COMMAND_SERR 0x0100
187 #define PCI_COMMAND_BACKTOBACKTRANS 0x0200
188 // PCI 0x08, 0xff000000 (0x09-0x0b:class,0x08:rev)
189 #define PCI_CLASS_BASE_DISPLAY 0x03
190 // PCI 0x08, 0x00ff0000
191 #define PCI_CLASS_SUB_VGA 0x00
192 // PCI 0x0c, 0x00ff0000 (0x0c:cacheline,0x0d:latency,0x0e:headertype,0x0f:Built-in self test)
193 #define PCI_CLASS_HEADERTYPE_00h 0x00
194 // 0x10-0x3f (headertype 00h)
195 // PCI 0x10,0x14,0x18,0x1c,0x20,0x24: base address mapping registers
196 // 0x10: MEMBASE, 0x14: IOBASE(hard-coded in XFree86 3.x)
197 #define PCI_MAP_MEM 0x0
198 #define PCI_MAP_IO 0x1
199 #define PCI_MAP_MEM_ADDR_MASK (~0xf)
200 #define PCI_MAP_IO_ADDR_MASK (~0x3)
201 #define PCI_MAP_MEMFLAGS_32BIT 0x0
202 #define PCI_MAP_MEMFLAGS_32BIT_1M 0x1
203 #define PCI_MAP_MEMFLAGS_64BIT 0x4
204 #define PCI_MAP_MEMFLAGS_CACHEABLE 0x8
205 // PCI 0x28: cardbus CIS pointer
206 // PCI 0x2c: subsystem vendor id, 0x2e: subsystem id
207 // PCI 0x30: expansion ROM base address
208 #define PCI_ROMBIOS_ENABLED 0x1
209 // PCI 0x34: 0xffffff00=reserved, 0x000000ff=capabilities pointer
210 // PCI 0x38: reserved
211 // PCI 0x3c: 0x3c=int-line, 0x3d=int-pin, 0x3e=min-gnt, 0x3f=maax-lat
213 #define CIRRUS_PNPMMIO_SIZE 0x1000
216 /* I/O and memory hook */
217 #define CIRRUS_HOOK_NOT_HANDLED 0
218 #define CIRRUS_HOOK_HANDLED 1
220 struct CirrusVGAState
;
221 typedef void (*cirrus_bitblt_rop_t
) (struct CirrusVGAState
*s
,
222 uint8_t * dst
, const uint8_t * src
,
223 int dstpitch
, int srcpitch
,
224 int bltwidth
, int bltheight
);
225 typedef void (*cirrus_fill_t
)(struct CirrusVGAState
*s
,
226 uint8_t *dst
, int dst_pitch
, int width
, int height
);
228 typedef struct CirrusVGAState
{
231 int cirrus_linear_io_addr
;
232 int cirrus_linear_bitblt_io_addr
;
233 int cirrus_mmio_io_addr
;
234 uint32_t cirrus_addr_mask
;
235 uint8_t cirrus_shadow_gr0
;
236 uint8_t cirrus_shadow_gr1
;
237 uint8_t cirrus_hidden_dac_lockindex
;
238 uint8_t cirrus_hidden_dac_data
;
239 uint32_t cirrus_bank_base
[2];
240 uint32_t cirrus_bank_limit
[2];
241 uint8_t cirrus_hidden_palette
[48];
242 uint32_t hw_cursor_x
;
243 uint32_t hw_cursor_y
;
244 int cirrus_blt_pixelwidth
;
245 int cirrus_blt_width
;
246 int cirrus_blt_height
;
247 int cirrus_blt_dstpitch
;
248 int cirrus_blt_srcpitch
;
249 uint32_t cirrus_blt_fgcol
;
250 uint32_t cirrus_blt_bgcol
;
251 uint32_t cirrus_blt_dstaddr
;
252 uint32_t cirrus_blt_srcaddr
;
253 uint8_t cirrus_blt_mode
;
254 uint8_t cirrus_blt_modeext
;
255 cirrus_bitblt_rop_t cirrus_rop
;
256 #define CIRRUS_BLTBUFSIZE (2048 * 4) /* one line width */
257 uint8_t cirrus_bltbuf
[CIRRUS_BLTBUFSIZE
];
258 uint8_t *cirrus_srcptr
;
259 uint8_t *cirrus_srcptr_end
;
260 uint32_t cirrus_srccounter
;
261 uint8_t *cirrus_dstptr
;
262 uint8_t *cirrus_dstptr_end
;
263 uint32_t cirrus_dstcounter
;
264 /* hwcursor display state */
265 int last_hw_cursor_size
;
266 int last_hw_cursor_x
;
267 int last_hw_cursor_y
;
268 int last_hw_cursor_y_start
;
269 int last_hw_cursor_y_end
;
272 typedef struct PCICirrusVGAState
{
274 CirrusVGAState cirrus_vga
;
277 static uint8_t rop_to_index
[256];
279 /***************************************
283 ***************************************/
286 static void cirrus_bitblt_reset(CirrusVGAState
* s
);
288 /***************************************
292 ***************************************/
294 static void cirrus_bitblt_rop_nop(CirrusVGAState
*s
,
295 uint8_t *dst
,const uint8_t *src
,
296 int dstpitch
,int srcpitch
,
297 int bltwidth
,int bltheight
)
301 static void cirrus_bitblt_fill_nop(CirrusVGAState
*s
,
303 int dstpitch
, int bltwidth
,int bltheight
)
308 #define ROP_OP(d, s) d = 0
309 #include "cirrus_vga_rop.h"
311 #define ROP_NAME src_and_dst
312 #define ROP_OP(d, s) d = (s) & (d)
313 #include "cirrus_vga_rop.h"
315 #define ROP_NAME src_and_notdst
316 #define ROP_OP(d, s) d = (s) & (~(d))
317 #include "cirrus_vga_rop.h"
319 #define ROP_NAME notdst
320 #define ROP_OP(d, s) d = ~(d)
321 #include "cirrus_vga_rop.h"
324 #define ROP_OP(d, s) d = s
325 #include "cirrus_vga_rop.h"
328 #define ROP_OP(d, s) d = 0xff
329 #include "cirrus_vga_rop.h"
331 #define ROP_NAME notsrc_and_dst
332 #define ROP_OP(d, s) d = (~(s)) & (d)
333 #include "cirrus_vga_rop.h"
335 #define ROP_NAME src_xor_dst
336 #define ROP_OP(d, s) d = (s) ^ (d)
337 #include "cirrus_vga_rop.h"
339 #define ROP_NAME src_or_dst
340 #define ROP_OP(d, s) d = (s) | (d)
341 #include "cirrus_vga_rop.h"
343 #define ROP_NAME notsrc_or_notdst
344 #define ROP_OP(d, s) d = (~(s)) | (~(d))
345 #include "cirrus_vga_rop.h"
347 #define ROP_NAME src_notxor_dst
348 #define ROP_OP(d, s) d = ~((s) ^ (d))
349 #include "cirrus_vga_rop.h"
351 #define ROP_NAME src_or_notdst
352 #define ROP_OP(d, s) d = (s) | (~(d))
353 #include "cirrus_vga_rop.h"
355 #define ROP_NAME notsrc
356 #define ROP_OP(d, s) d = (~(s))
357 #include "cirrus_vga_rop.h"
359 #define ROP_NAME notsrc_or_dst
360 #define ROP_OP(d, s) d = (~(s)) | (d)
361 #include "cirrus_vga_rop.h"
363 #define ROP_NAME notsrc_and_notdst
364 #define ROP_OP(d, s) d = (~(s)) & (~(d))
365 #include "cirrus_vga_rop.h"
367 static const cirrus_bitblt_rop_t cirrus_fwd_rop
[16] = {
368 cirrus_bitblt_rop_fwd_0
,
369 cirrus_bitblt_rop_fwd_src_and_dst
,
370 cirrus_bitblt_rop_nop
,
371 cirrus_bitblt_rop_fwd_src_and_notdst
,
372 cirrus_bitblt_rop_fwd_notdst
,
373 cirrus_bitblt_rop_fwd_src
,
374 cirrus_bitblt_rop_fwd_1
,
375 cirrus_bitblt_rop_fwd_notsrc_and_dst
,
376 cirrus_bitblt_rop_fwd_src_xor_dst
,
377 cirrus_bitblt_rop_fwd_src_or_dst
,
378 cirrus_bitblt_rop_fwd_notsrc_or_notdst
,
379 cirrus_bitblt_rop_fwd_src_notxor_dst
,
380 cirrus_bitblt_rop_fwd_src_or_notdst
,
381 cirrus_bitblt_rop_fwd_notsrc
,
382 cirrus_bitblt_rop_fwd_notsrc_or_dst
,
383 cirrus_bitblt_rop_fwd_notsrc_and_notdst
,
386 static const cirrus_bitblt_rop_t cirrus_bkwd_rop
[16] = {
387 cirrus_bitblt_rop_bkwd_0
,
388 cirrus_bitblt_rop_bkwd_src_and_dst
,
389 cirrus_bitblt_rop_nop
,
390 cirrus_bitblt_rop_bkwd_src_and_notdst
,
391 cirrus_bitblt_rop_bkwd_notdst
,
392 cirrus_bitblt_rop_bkwd_src
,
393 cirrus_bitblt_rop_bkwd_1
,
394 cirrus_bitblt_rop_bkwd_notsrc_and_dst
,
395 cirrus_bitblt_rop_bkwd_src_xor_dst
,
396 cirrus_bitblt_rop_bkwd_src_or_dst
,
397 cirrus_bitblt_rop_bkwd_notsrc_or_notdst
,
398 cirrus_bitblt_rop_bkwd_src_notxor_dst
,
399 cirrus_bitblt_rop_bkwd_src_or_notdst
,
400 cirrus_bitblt_rop_bkwd_notsrc
,
401 cirrus_bitblt_rop_bkwd_notsrc_or_dst
,
402 cirrus_bitblt_rop_bkwd_notsrc_and_notdst
,
405 #define ROP2(name) {\
412 #define ROP_NOP2(func) {\
419 static const cirrus_bitblt_rop_t cirrus_colorexpand_transp
[16][4] = {
420 ROP2(cirrus_colorexpand_transp_0
),
421 ROP2(cirrus_colorexpand_transp_src_and_dst
),
422 ROP_NOP2(cirrus_bitblt_rop_nop
),
423 ROP2(cirrus_colorexpand_transp_src_and_notdst
),
424 ROP2(cirrus_colorexpand_transp_notdst
),
425 ROP2(cirrus_colorexpand_transp_src
),
426 ROP2(cirrus_colorexpand_transp_1
),
427 ROP2(cirrus_colorexpand_transp_notsrc_and_dst
),
428 ROP2(cirrus_colorexpand_transp_src_xor_dst
),
429 ROP2(cirrus_colorexpand_transp_src_or_dst
),
430 ROP2(cirrus_colorexpand_transp_notsrc_or_notdst
),
431 ROP2(cirrus_colorexpand_transp_src_notxor_dst
),
432 ROP2(cirrus_colorexpand_transp_src_or_notdst
),
433 ROP2(cirrus_colorexpand_transp_notsrc
),
434 ROP2(cirrus_colorexpand_transp_notsrc_or_dst
),
435 ROP2(cirrus_colorexpand_transp_notsrc_and_notdst
),
438 static const cirrus_bitblt_rop_t cirrus_colorexpand
[16][4] = {
439 ROP2(cirrus_colorexpand_0
),
440 ROP2(cirrus_colorexpand_src_and_dst
),
441 ROP_NOP2(cirrus_bitblt_rop_nop
),
442 ROP2(cirrus_colorexpand_src_and_notdst
),
443 ROP2(cirrus_colorexpand_notdst
),
444 ROP2(cirrus_colorexpand_src
),
445 ROP2(cirrus_colorexpand_1
),
446 ROP2(cirrus_colorexpand_notsrc_and_dst
),
447 ROP2(cirrus_colorexpand_src_xor_dst
),
448 ROP2(cirrus_colorexpand_src_or_dst
),
449 ROP2(cirrus_colorexpand_notsrc_or_notdst
),
450 ROP2(cirrus_colorexpand_src_notxor_dst
),
451 ROP2(cirrus_colorexpand_src_or_notdst
),
452 ROP2(cirrus_colorexpand_notsrc
),
453 ROP2(cirrus_colorexpand_notsrc_or_dst
),
454 ROP2(cirrus_colorexpand_notsrc_and_notdst
),
457 static const cirrus_fill_t cirrus_fill
[16][4] = {
459 ROP2(cirrus_fill_src_and_dst
),
460 ROP_NOP2(cirrus_bitblt_fill_nop
),
461 ROP2(cirrus_fill_src_and_notdst
),
462 ROP2(cirrus_fill_notdst
),
463 ROP2(cirrus_fill_src
),
465 ROP2(cirrus_fill_notsrc_and_dst
),
466 ROP2(cirrus_fill_src_xor_dst
),
467 ROP2(cirrus_fill_src_or_dst
),
468 ROP2(cirrus_fill_notsrc_or_notdst
),
469 ROP2(cirrus_fill_src_notxor_dst
),
470 ROP2(cirrus_fill_src_or_notdst
),
471 ROP2(cirrus_fill_notsrc
),
472 ROP2(cirrus_fill_notsrc_or_dst
),
473 ROP2(cirrus_fill_notsrc_and_notdst
),
476 static inline void cirrus_bitblt_fgcol(CirrusVGAState
*s
)
479 switch (s
->cirrus_blt_pixelwidth
) {
481 s
->cirrus_blt_fgcol
= s
->cirrus_shadow_gr1
;
484 color
= s
->cirrus_shadow_gr1
| (s
->gr
[0x11] << 8);
485 s
->cirrus_blt_fgcol
= le16_to_cpu(color
);
488 s
->cirrus_blt_fgcol
= s
->cirrus_shadow_gr1
|
489 (s
->gr
[0x11] << 8) | (s
->gr
[0x13] << 16);
493 color
= s
->cirrus_shadow_gr1
| (s
->gr
[0x11] << 8) |
494 (s
->gr
[0x13] << 16) | (s
->gr
[0x15] << 24);
495 s
->cirrus_blt_fgcol
= le32_to_cpu(color
);
500 static inline void cirrus_bitblt_bgcol(CirrusVGAState
*s
)
503 switch (s
->cirrus_blt_pixelwidth
) {
505 s
->cirrus_blt_bgcol
= s
->cirrus_shadow_gr0
;
508 color
= s
->cirrus_shadow_gr0
| (s
->gr
[0x10] << 8);
509 s
->cirrus_blt_bgcol
= le16_to_cpu(color
);
512 s
->cirrus_blt_bgcol
= s
->cirrus_shadow_gr0
|
513 (s
->gr
[0x10] << 8) | (s
->gr
[0x12] << 16);
517 color
= s
->cirrus_shadow_gr0
| (s
->gr
[0x10] << 8) |
518 (s
->gr
[0x12] << 16) | (s
->gr
[0x14] << 24);
519 s
->cirrus_blt_bgcol
= le32_to_cpu(color
);
524 static void cirrus_invalidate_region(CirrusVGAState
* s
, int off_begin
,
525 int off_pitch
, int bytesperline
,
532 for (y
= 0; y
< lines
; y
++) {
534 off_cur_end
= off_cur
+ bytesperline
;
535 off_cur
&= TARGET_PAGE_MASK
;
536 while (off_cur
< off_cur_end
) {
537 cpu_physical_memory_set_dirty(s
->vram_offset
+ off_cur
);
538 off_cur
+= TARGET_PAGE_SIZE
;
540 off_begin
+= off_pitch
;
544 static int cirrus_bitblt_common_patterncopy(CirrusVGAState
* s
,
547 uint8_t work_colorexp
[256];
551 int tilewidth
, tileheight
;
552 int patternbytes
= s
->cirrus_blt_pixelwidth
* 8;
554 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_COLOREXPAND
) {
555 cirrus_bitblt_rop_t rop_func
;
556 cirrus_bitblt_fgcol(s
);
557 cirrus_bitblt_bgcol(s
);
558 rop_func
= cirrus_colorexpand
[CIRRUS_ROP_SRC_INDEX
][s
->cirrus_blt_pixelwidth
- 1];
559 rop_func(s
, work_colorexp
, src
, patternbytes
, 1, patternbytes
, 8);
561 s
->cirrus_blt_mode
&= ~CIRRUS_BLTMODE_COLOREXPAND
;
563 if (s
->cirrus_blt_mode
& ~CIRRUS_BLTMODE_PATTERNCOPY
) {
565 printf("cirrus: blt mode %02x (pattercopy) - unimplemented\n",
571 dst
= s
->vram_ptr
+ s
->cirrus_blt_dstaddr
;
572 for (y
= 0; y
< s
->cirrus_blt_height
; y
+= 8) {
574 tileheight
= qemu_MIN(8, s
->cirrus_blt_height
- y
);
575 for (x
= 0; x
< s
->cirrus_blt_width
; x
+= patternbytes
) {
576 tilewidth
= qemu_MIN(patternbytes
, s
->cirrus_blt_width
- x
);
577 (*s
->cirrus_rop
) (s
, dstc
, src
,
578 s
->cirrus_blt_dstpitch
, patternbytes
,
579 tilewidth
, tileheight
);
580 dstc
+= patternbytes
;
582 dst
+= s
->cirrus_blt_dstpitch
* 8;
584 cirrus_invalidate_region(s
, s
->cirrus_blt_dstaddr
,
585 s
->cirrus_blt_dstpitch
, s
->cirrus_blt_width
,
586 s
->cirrus_blt_height
);
592 static int cirrus_bitblt_solidfill(CirrusVGAState
*s
, int blt_rop
)
594 cirrus_fill_t rop_func
;
596 rop_func
= cirrus_fill
[rop_to_index
[blt_rop
]][s
->cirrus_blt_pixelwidth
- 1];
597 rop_func(s
, s
->vram_ptr
+ s
->cirrus_blt_dstaddr
,
598 s
->cirrus_blt_dstpitch
,
599 s
->cirrus_blt_width
, s
->cirrus_blt_height
);
600 cirrus_invalidate_region(s
, s
->cirrus_blt_dstaddr
,
601 s
->cirrus_blt_dstpitch
, s
->cirrus_blt_width
,
602 s
->cirrus_blt_height
);
603 cirrus_bitblt_reset(s
);
607 /***************************************
609 * bitblt (video-to-video)
611 ***************************************/
613 static int cirrus_bitblt_videotovideo_patterncopy(CirrusVGAState
* s
)
615 return cirrus_bitblt_common_patterncopy(s
,
617 s
->cirrus_blt_srcaddr
);
620 static int cirrus_bitblt_videotovideo_copy(CirrusVGAState
* s
)
622 (*s
->cirrus_rop
) (s
, s
->vram_ptr
+ s
->cirrus_blt_dstaddr
,
623 s
->vram_ptr
+ s
->cirrus_blt_srcaddr
,
624 s
->cirrus_blt_dstpitch
, s
->cirrus_blt_srcpitch
,
625 s
->cirrus_blt_width
, s
->cirrus_blt_height
);
626 cirrus_invalidate_region(s
, s
->cirrus_blt_dstaddr
,
627 s
->cirrus_blt_dstpitch
, s
->cirrus_blt_width
,
628 s
->cirrus_blt_height
);
632 /***************************************
634 * bitblt (cpu-to-video)
636 ***************************************/
638 static void cirrus_bitblt_cputovideo_next(CirrusVGAState
* s
)
643 if (s
->cirrus_srccounter
> 0) {
644 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_PATTERNCOPY
) {
645 cirrus_bitblt_common_patterncopy(s
, s
->cirrus_bltbuf
);
647 s
->cirrus_srccounter
= 0;
648 cirrus_bitblt_reset(s
);
650 /* at least one scan line */
652 (*s
->cirrus_rop
)(s
, s
->vram_ptr
+ s
->cirrus_blt_dstaddr
,
653 s
->cirrus_bltbuf
, 0, 0, s
->cirrus_blt_width
, 1);
654 cirrus_invalidate_region(s
, s
->cirrus_blt_dstaddr
, 0,
655 s
->cirrus_blt_width
, 1);
656 s
->cirrus_blt_dstaddr
+= s
->cirrus_blt_dstpitch
;
657 s
->cirrus_srccounter
-= s
->cirrus_blt_srcpitch
;
658 if (s
->cirrus_srccounter
<= 0)
660 /* more bytes than needed can be transfered because of
661 word alignment, so we keep them for the next line */
662 /* XXX: keep alignment to speed up transfer */
663 end_ptr
= s
->cirrus_bltbuf
+ s
->cirrus_blt_srcpitch
;
664 copy_count
= s
->cirrus_srcptr_end
- end_ptr
;
665 memmove(s
->cirrus_bltbuf
, end_ptr
, copy_count
);
666 s
->cirrus_srcptr
= s
->cirrus_bltbuf
+ copy_count
;
667 s
->cirrus_srcptr_end
= s
->cirrus_bltbuf
+ s
->cirrus_blt_srcpitch
;
668 } while (s
->cirrus_srcptr
>= s
->cirrus_srcptr_end
);
673 /***************************************
677 ***************************************/
679 static void cirrus_bitblt_reset(CirrusVGAState
* s
)
682 ~(CIRRUS_BLT_START
| CIRRUS_BLT_BUSY
| CIRRUS_BLT_FIFOUSED
);
683 s
->cirrus_srcptr
= &s
->cirrus_bltbuf
[0];
684 s
->cirrus_srcptr_end
= &s
->cirrus_bltbuf
[0];
685 s
->cirrus_srccounter
= 0;
686 s
->cirrus_dstptr
= &s
->cirrus_bltbuf
[0];
687 s
->cirrus_dstptr_end
= &s
->cirrus_bltbuf
[0];
688 s
->cirrus_dstcounter
= 0;
691 static int cirrus_bitblt_cputovideo(CirrusVGAState
* s
)
695 s
->cirrus_blt_mode
&= ~CIRRUS_BLTMODE_MEMSYSSRC
;
696 s
->cirrus_srcptr
= &s
->cirrus_bltbuf
[0];
697 s
->cirrus_srcptr_end
= &s
->cirrus_bltbuf
[0];
699 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_PATTERNCOPY
) {
700 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_COLOREXPAND
) {
701 s
->cirrus_blt_srcpitch
= 8;
703 s
->cirrus_blt_srcpitch
= 8 * 8 * s
->cirrus_blt_pixelwidth
;
705 s
->cirrus_srccounter
= s
->cirrus_blt_srcpitch
;
707 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_COLOREXPAND
) {
708 w
= s
->cirrus_blt_width
/ s
->cirrus_blt_pixelwidth
;
709 if (s
->cirrus_blt_modeext
& CIRRUS_BLTMODEEXT_DWORDGRANULARITY
)
710 s
->cirrus_blt_srcpitch
= ((w
+ 31) >> 5);
712 s
->cirrus_blt_srcpitch
= ((w
+ 7) >> 3);
714 s
->cirrus_blt_srcpitch
= s
->cirrus_blt_width
;
716 s
->cirrus_srccounter
= s
->cirrus_blt_srcpitch
* s
->cirrus_blt_height
;
718 s
->cirrus_srcptr
= s
->cirrus_bltbuf
;
719 s
->cirrus_srcptr_end
= s
->cirrus_bltbuf
+ s
->cirrus_blt_srcpitch
;
723 static int cirrus_bitblt_videotocpu(CirrusVGAState
* s
)
727 printf("cirrus: bitblt (video to cpu) is not implemented yet\n");
732 static int cirrus_bitblt_videotovideo(CirrusVGAState
* s
)
736 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_PATTERNCOPY
) {
737 ret
= cirrus_bitblt_videotovideo_patterncopy(s
);
739 ret
= cirrus_bitblt_videotovideo_copy(s
);
742 cirrus_bitblt_reset(s
);
746 static void cirrus_bitblt_start(CirrusVGAState
* s
)
750 s
->gr
[0x31] |= CIRRUS_BLT_BUSY
;
752 s
->cirrus_blt_width
= (s
->gr
[0x20] | (s
->gr
[0x21] << 8)) + 1;
753 s
->cirrus_blt_height
= (s
->gr
[0x22] | (s
->gr
[0x23] << 8)) + 1;
754 s
->cirrus_blt_dstpitch
= (s
->gr
[0x24] | (s
->gr
[0x25] << 8));
755 s
->cirrus_blt_srcpitch
= (s
->gr
[0x26] | (s
->gr
[0x27] << 8));
756 s
->cirrus_blt_dstaddr
=
757 (s
->gr
[0x28] | (s
->gr
[0x29] << 8) | (s
->gr
[0x2a] << 16));
758 s
->cirrus_blt_srcaddr
=
759 (s
->gr
[0x2c] | (s
->gr
[0x2d] << 8) | (s
->gr
[0x2e] << 16));
760 s
->cirrus_blt_mode
= s
->gr
[0x30];
761 s
->cirrus_blt_modeext
= s
->gr
[0x33];
762 blt_rop
= s
->gr
[0x32];
765 printf("rop=0x%02x mode=0x%02x modeext=0x%02x w=%d h=%d dpitch=%d spicth=%d daddr=0x%08x saddr=0x%08x writemask=0x%02x\n",
768 s
->cirrus_blt_modeext
,
770 s
->cirrus_blt_height
,
771 s
->cirrus_blt_dstpitch
,
772 s
->cirrus_blt_srcpitch
,
773 s
->cirrus_blt_dstaddr
,
774 s
->cirrus_blt_srcaddr
,
778 switch (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_PIXELWIDTHMASK
) {
779 case CIRRUS_BLTMODE_PIXELWIDTH8
:
780 s
->cirrus_blt_pixelwidth
= 1;
782 case CIRRUS_BLTMODE_PIXELWIDTH16
:
783 s
->cirrus_blt_pixelwidth
= 2;
785 case CIRRUS_BLTMODE_PIXELWIDTH24
:
786 s
->cirrus_blt_pixelwidth
= 3;
788 case CIRRUS_BLTMODE_PIXELWIDTH32
:
789 s
->cirrus_blt_pixelwidth
= 4;
793 printf("cirrus: bitblt - pixel width is unknown\n");
797 s
->cirrus_blt_mode
&= ~CIRRUS_BLTMODE_PIXELWIDTHMASK
;
800 cirrus_blt_mode
& (CIRRUS_BLTMODE_MEMSYSSRC
|
801 CIRRUS_BLTMODE_MEMSYSDEST
))
802 == (CIRRUS_BLTMODE_MEMSYSSRC
| CIRRUS_BLTMODE_MEMSYSDEST
)) {
804 printf("cirrus: bitblt - memory-to-memory copy is requested\n");
809 if ((s
->cirrus_blt_modeext
& CIRRUS_BLTMODEEXT_SOLIDFILL
) &&
810 (s
->cirrus_blt_mode
& (CIRRUS_BLTMODE_MEMSYSDEST
|
811 CIRRUS_BLTMODE_TRANSPARENTCOMP
|
812 CIRRUS_BLTMODE_PATTERNCOPY
|
813 CIRRUS_BLTMODE_COLOREXPAND
)) ==
814 (CIRRUS_BLTMODE_PATTERNCOPY
| CIRRUS_BLTMODE_COLOREXPAND
)) {
815 cirrus_bitblt_fgcol(s
);
816 cirrus_bitblt_solidfill(s
, blt_rop
);
818 if ((s
->cirrus_blt_mode
& (CIRRUS_BLTMODE_COLOREXPAND
|
819 CIRRUS_BLTMODE_PATTERNCOPY
)) ==
820 CIRRUS_BLTMODE_COLOREXPAND
) {
822 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_TRANSPARENTCOMP
) {
823 cirrus_bitblt_fgcol(s
);
824 s
->cirrus_rop
= cirrus_colorexpand_transp
[rop_to_index
[blt_rop
]][s
->cirrus_blt_pixelwidth
- 1];
826 cirrus_bitblt_fgcol(s
);
827 cirrus_bitblt_bgcol(s
);
828 s
->cirrus_rop
= cirrus_colorexpand
[rop_to_index
[blt_rop
]][s
->cirrus_blt_pixelwidth
- 1];
831 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_BACKWARDS
) {
832 s
->cirrus_blt_dstpitch
= -s
->cirrus_blt_dstpitch
;
833 s
->cirrus_blt_srcpitch
= -s
->cirrus_blt_srcpitch
;
834 s
->cirrus_rop
= cirrus_bkwd_rop
[rop_to_index
[blt_rop
]];
836 s
->cirrus_rop
= cirrus_fwd_rop
[rop_to_index
[blt_rop
]];
840 // setup bitblt engine.
841 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_MEMSYSSRC
) {
842 if (!cirrus_bitblt_cputovideo(s
))
844 } else if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_MEMSYSDEST
) {
845 if (!cirrus_bitblt_videotocpu(s
))
848 if (!cirrus_bitblt_videotovideo(s
))
854 cirrus_bitblt_reset(s
);
857 static void cirrus_write_bitblt(CirrusVGAState
* s
, unsigned reg_value
)
861 old_value
= s
->gr
[0x31];
862 s
->gr
[0x31] = reg_value
;
864 if (((old_value
& CIRRUS_BLT_RESET
) != 0) &&
865 ((reg_value
& CIRRUS_BLT_RESET
) == 0)) {
866 cirrus_bitblt_reset(s
);
867 } else if (((old_value
& CIRRUS_BLT_START
) == 0) &&
868 ((reg_value
& CIRRUS_BLT_START
) != 0)) {
869 cirrus_bitblt_start(s
);
874 /***************************************
878 ***************************************/
880 static void cirrus_get_offsets(VGAState
*s1
,
881 uint32_t *pline_offset
,
882 uint32_t *pstart_addr
)
884 CirrusVGAState
* s
= (CirrusVGAState
*)s1
;
886 uint32_t line_offset
;
888 line_offset
= s
->cr
[0x13]
889 | ((s
->cr
[0x1b] & 0x10) << 4);
891 *pline_offset
= line_offset
;
893 start_addr
= (s
->cr
[0x0c] << 8)
895 | ((s
->cr
[0x1b] & 0x01) << 16)
896 | ((s
->cr
[0x1b] & 0x0c) << 15)
897 | ((s
->cr
[0x1d] & 0x80) << 12);
898 *pstart_addr
= start_addr
;
901 static uint32_t cirrus_get_bpp16_depth(CirrusVGAState
* s
)
905 switch (s
->cirrus_hidden_dac_data
& 0xf) {
908 break; /* Sierra HiColor */
911 break; /* XGA HiColor */
914 printf("cirrus: invalid DAC value %x in 16bpp\n",
915 (s
->cirrus_hidden_dac_data
& 0xf));
923 static int cirrus_get_bpp(VGAState
*s1
)
925 CirrusVGAState
* s
= (CirrusVGAState
*)s1
;
928 if ((s
->sr
[0x07] & 0x01) != 0) {
930 switch (s
->sr
[0x07] & CIRRUS_SR7_BPP_MASK
) {
931 case CIRRUS_SR7_BPP_8
:
934 case CIRRUS_SR7_BPP_16_DOUBLEVCLK
:
935 ret
= cirrus_get_bpp16_depth(s
);
937 case CIRRUS_SR7_BPP_24
:
940 case CIRRUS_SR7_BPP_16
:
941 ret
= cirrus_get_bpp16_depth(s
);
943 case CIRRUS_SR7_BPP_32
:
948 printf("cirrus: unknown bpp - sr7=%x\n", s
->sr
[0x7]);
961 /***************************************
965 ***************************************/
967 static void cirrus_update_bank_ptr(CirrusVGAState
* s
, unsigned bank_index
)
972 if ((s
->gr
[0x0b] & 0x01) != 0) /* dual bank */
973 offset
= s
->gr
[0x09 + bank_index
];
974 else /* single bank */
975 offset
= s
->gr
[0x09];
977 if ((s
->gr
[0x0b] & 0x20) != 0)
982 if (s
->vram_size
<= offset
)
985 limit
= s
->vram_size
- offset
;
987 if (((s
->gr
[0x0b] & 0x01) == 0) && (bank_index
!= 0)) {
988 if (limit
> 0x8000) {
997 s
->cirrus_bank_base
[bank_index
] = offset
;
998 s
->cirrus_bank_limit
[bank_index
] = limit
;
1000 s
->cirrus_bank_base
[bank_index
] = 0;
1001 s
->cirrus_bank_limit
[bank_index
] = 0;
1005 /***************************************
1007 * I/O access between 0x3c4-0x3c5
1009 ***************************************/
1012 cirrus_hook_read_sr(CirrusVGAState
* s
, unsigned reg_index
, int *reg_value
)
1014 switch (reg_index
) {
1015 case 0x00: // Standard VGA
1016 case 0x01: // Standard VGA
1017 case 0x02: // Standard VGA
1018 case 0x03: // Standard VGA
1019 case 0x04: // Standard VGA
1020 return CIRRUS_HOOK_NOT_HANDLED
;
1021 case 0x06: // Unlock Cirrus extensions
1022 *reg_value
= s
->sr
[reg_index
];
1027 case 0x70: // Graphics Cursor X
1031 case 0xf0: // Graphics Cursor X
1032 *reg_value
= s
->sr
[0x10];
1037 case 0x71: // Graphics Cursor Y
1041 case 0xf1: // Graphics Cursor Y
1042 *reg_value
= s
->sr
[0x11];
1045 case 0x07: // Extended Sequencer Mode
1046 case 0x08: // EEPROM Control
1047 case 0x09: // Scratch Register 0
1048 case 0x0a: // Scratch Register 1
1049 case 0x0b: // VCLK 0
1050 case 0x0c: // VCLK 1
1051 case 0x0d: // VCLK 2
1052 case 0x0e: // VCLK 3
1053 case 0x0f: // DRAM Control
1054 case 0x12: // Graphics Cursor Attribute
1055 case 0x13: // Graphics Cursor Pattern Address
1056 case 0x14: // Scratch Register 2
1057 case 0x15: // Scratch Register 3
1058 case 0x16: // Performance Tuning Register
1059 case 0x17: // Configuration Readback and Extended Control
1060 case 0x18: // Signature Generator Control
1061 case 0x19: // Signal Generator Result
1062 case 0x1a: // Signal Generator Result
1063 case 0x1b: // VCLK 0 Denominator & Post
1064 case 0x1c: // VCLK 1 Denominator & Post
1065 case 0x1d: // VCLK 2 Denominator & Post
1066 case 0x1e: // VCLK 3 Denominator & Post
1067 case 0x1f: // BIOS Write Enable and MCLK select
1069 printf("cirrus: handled inport sr_index %02x\n", reg_index
);
1071 *reg_value
= s
->sr
[reg_index
];
1075 printf("cirrus: inport sr_index %02x\n", reg_index
);
1081 return CIRRUS_HOOK_HANDLED
;
1085 cirrus_hook_write_sr(CirrusVGAState
* s
, unsigned reg_index
, int reg_value
)
1087 switch (reg_index
) {
1088 case 0x00: // Standard VGA
1089 case 0x01: // Standard VGA
1090 case 0x02: // Standard VGA
1091 case 0x03: // Standard VGA
1092 case 0x04: // Standard VGA
1093 return CIRRUS_HOOK_NOT_HANDLED
;
1094 case 0x06: // Unlock Cirrus extensions
1096 if (reg_value
== 0x12) {
1097 s
->sr
[reg_index
] = 0x12;
1099 s
->sr
[reg_index
] = 0x0f;
1105 case 0x70: // Graphics Cursor X
1109 case 0xf0: // Graphics Cursor X
1110 s
->sr
[0x10] = reg_value
;
1111 s
->hw_cursor_x
= (reg_value
<< 3) | (reg_index
>> 5);
1116 case 0x71: // Graphics Cursor Y
1120 case 0xf1: // Graphics Cursor Y
1121 s
->sr
[0x11] = reg_value
;
1122 s
->hw_cursor_y
= (reg_value
<< 3) | (reg_index
>> 5);
1124 case 0x07: // Extended Sequencer Mode
1125 case 0x08: // EEPROM Control
1126 case 0x09: // Scratch Register 0
1127 case 0x0a: // Scratch Register 1
1128 case 0x0b: // VCLK 0
1129 case 0x0c: // VCLK 1
1130 case 0x0d: // VCLK 2
1131 case 0x0e: // VCLK 3
1132 case 0x0f: // DRAM Control
1133 case 0x12: // Graphics Cursor Attribute
1134 case 0x13: // Graphics Cursor Pattern Address
1135 case 0x14: // Scratch Register 2
1136 case 0x15: // Scratch Register 3
1137 case 0x16: // Performance Tuning Register
1138 case 0x17: // Configuration Readback and Extended Control
1139 case 0x18: // Signature Generator Control
1140 case 0x19: // Signature Generator Result
1141 case 0x1a: // Signature Generator Result
1142 case 0x1b: // VCLK 0 Denominator & Post
1143 case 0x1c: // VCLK 1 Denominator & Post
1144 case 0x1d: // VCLK 2 Denominator & Post
1145 case 0x1e: // VCLK 3 Denominator & Post
1146 case 0x1f: // BIOS Write Enable and MCLK select
1147 s
->sr
[reg_index
] = reg_value
;
1149 printf("cirrus: handled outport sr_index %02x, sr_value %02x\n",
1150 reg_index
, reg_value
);
1155 printf("cirrus: outport sr_index %02x, sr_value %02x\n", reg_index
,
1161 return CIRRUS_HOOK_HANDLED
;
1164 /***************************************
1166 * I/O access at 0x3c6
1168 ***************************************/
1170 static void cirrus_read_hidden_dac(CirrusVGAState
* s
, int *reg_value
)
1173 if (++s
->cirrus_hidden_dac_lockindex
== 5) {
1174 *reg_value
= s
->cirrus_hidden_dac_data
;
1175 s
->cirrus_hidden_dac_lockindex
= 0;
1179 static void cirrus_write_hidden_dac(CirrusVGAState
* s
, int reg_value
)
1181 if (s
->cirrus_hidden_dac_lockindex
== 4) {
1182 s
->cirrus_hidden_dac_data
= reg_value
;
1183 #if defined(DEBUG_CIRRUS)
1184 printf("cirrus: outport hidden DAC, value %02x\n", reg_value
);
1187 s
->cirrus_hidden_dac_lockindex
= 0;
1190 /***************************************
1192 * I/O access at 0x3c9
1194 ***************************************/
1196 static int cirrus_hook_read_palette(CirrusVGAState
* s
, int *reg_value
)
1198 if (!(s
->sr
[0x12] & CIRRUS_CURSOR_HIDDENPEL
))
1199 return CIRRUS_HOOK_NOT_HANDLED
;
1201 s
->cirrus_hidden_palette
[(s
->dac_read_index
& 0x0f) * 3 +
1203 if (++s
->dac_sub_index
== 3) {
1204 s
->dac_sub_index
= 0;
1205 s
->dac_read_index
++;
1207 return CIRRUS_HOOK_HANDLED
;
1210 static int cirrus_hook_write_palette(CirrusVGAState
* s
, int reg_value
)
1212 if (!(s
->sr
[0x12] & CIRRUS_CURSOR_HIDDENPEL
))
1213 return CIRRUS_HOOK_NOT_HANDLED
;
1214 s
->dac_cache
[s
->dac_sub_index
] = reg_value
;
1215 if (++s
->dac_sub_index
== 3) {
1216 memcpy(&s
->cirrus_hidden_palette
[(s
->dac_write_index
& 0x0f) * 3],
1218 /* XXX update cursor */
1219 s
->dac_sub_index
= 0;
1220 s
->dac_write_index
++;
1222 return CIRRUS_HOOK_HANDLED
;
1225 /***************************************
1227 * I/O access between 0x3ce-0x3cf
1229 ***************************************/
1232 cirrus_hook_read_gr(CirrusVGAState
* s
, unsigned reg_index
, int *reg_value
)
1234 switch (reg_index
) {
1235 case 0x00: // Standard VGA, BGCOLOR 0x000000ff
1236 *reg_value
= s
->cirrus_shadow_gr0
;
1237 return CIRRUS_HOOK_HANDLED
;
1238 case 0x01: // Standard VGA, FGCOLOR 0x000000ff
1239 *reg_value
= s
->cirrus_shadow_gr1
;
1240 return CIRRUS_HOOK_HANDLED
;
1241 case 0x02: // Standard VGA
1242 case 0x03: // Standard VGA
1243 case 0x04: // Standard VGA
1244 case 0x06: // Standard VGA
1245 case 0x07: // Standard VGA
1246 case 0x08: // Standard VGA
1247 return CIRRUS_HOOK_NOT_HANDLED
;
1248 case 0x05: // Standard VGA, Cirrus extended mode
1253 if (reg_index
< 0x3a) {
1254 *reg_value
= s
->gr
[reg_index
];
1257 printf("cirrus: inport gr_index %02x\n", reg_index
);
1262 return CIRRUS_HOOK_HANDLED
;
1266 cirrus_hook_write_gr(CirrusVGAState
* s
, unsigned reg_index
, int reg_value
)
1268 #if defined(DEBUG_BITBLT) && 0
1269 printf("gr%02x: %02x\n", reg_index
, reg_value
);
1271 switch (reg_index
) {
1272 case 0x00: // Standard VGA, BGCOLOR 0x000000ff
1273 s
->cirrus_shadow_gr0
= reg_value
;
1274 return CIRRUS_HOOK_NOT_HANDLED
;
1275 case 0x01: // Standard VGA, FGCOLOR 0x000000ff
1276 s
->cirrus_shadow_gr1
= reg_value
;
1277 return CIRRUS_HOOK_NOT_HANDLED
;
1278 case 0x02: // Standard VGA
1279 case 0x03: // Standard VGA
1280 case 0x04: // Standard VGA
1281 case 0x06: // Standard VGA
1282 case 0x07: // Standard VGA
1283 case 0x08: // Standard VGA
1284 return CIRRUS_HOOK_NOT_HANDLED
;
1285 case 0x05: // Standard VGA, Cirrus extended mode
1286 s
->gr
[reg_index
] = reg_value
& 0x7f;
1288 case 0x09: // bank offset #0
1289 case 0x0A: // bank offset #1
1291 s
->gr
[reg_index
] = reg_value
;
1292 cirrus_update_bank_ptr(s
, 0);
1293 cirrus_update_bank_ptr(s
, 1);
1295 case 0x10: // BGCOLOR 0x0000ff00
1296 case 0x11: // FGCOLOR 0x0000ff00
1297 case 0x12: // BGCOLOR 0x00ff0000
1298 case 0x13: // FGCOLOR 0x00ff0000
1299 case 0x14: // BGCOLOR 0xff000000
1300 case 0x15: // FGCOLOR 0xff000000
1301 case 0x20: // BLT WIDTH 0x0000ff
1302 case 0x22: // BLT HEIGHT 0x0000ff
1303 case 0x24: // BLT DEST PITCH 0x0000ff
1304 case 0x26: // BLT SRC PITCH 0x0000ff
1305 case 0x28: // BLT DEST ADDR 0x0000ff
1306 case 0x29: // BLT DEST ADDR 0x00ff00
1307 case 0x2c: // BLT SRC ADDR 0x0000ff
1308 case 0x2d: // BLT SRC ADDR 0x00ff00
1309 case 0x2f: // BLT WRITEMASK
1310 case 0x30: // BLT MODE
1311 case 0x32: // RASTER OP
1312 case 0x33: // BLT MODEEXT
1313 case 0x34: // BLT TRANSPARENT COLOR 0x00ff
1314 case 0x35: // BLT TRANSPARENT COLOR 0xff00
1315 case 0x38: // BLT TRANSPARENT COLOR MASK 0x00ff
1316 case 0x39: // BLT TRANSPARENT COLOR MASK 0xff00
1317 s
->gr
[reg_index
] = reg_value
;
1319 case 0x21: // BLT WIDTH 0x001f00
1320 case 0x23: // BLT HEIGHT 0x001f00
1321 case 0x25: // BLT DEST PITCH 0x001f00
1322 case 0x27: // BLT SRC PITCH 0x001f00
1323 s
->gr
[reg_index
] = reg_value
& 0x1f;
1325 case 0x2a: // BLT DEST ADDR 0x3f0000
1326 s
->gr
[reg_index
] = reg_value
& 0x3f;
1327 /* if auto start mode, starts bit blt now */
1328 if (s
->gr
[0x31] & CIRRUS_BLT_AUTOSTART
) {
1329 cirrus_bitblt_start(s
);
1332 case 0x2e: // BLT SRC ADDR 0x3f0000
1333 s
->gr
[reg_index
] = reg_value
& 0x3f;
1335 case 0x31: // BLT STATUS/START
1336 cirrus_write_bitblt(s
, reg_value
);
1340 printf("cirrus: outport gr_index %02x, gr_value %02x\n", reg_index
,
1346 return CIRRUS_HOOK_HANDLED
;
1349 /***************************************
1351 * I/O access between 0x3d4-0x3d5
1353 ***************************************/
1356 cirrus_hook_read_cr(CirrusVGAState
* s
, unsigned reg_index
, int *reg_value
)
1358 switch (reg_index
) {
1359 case 0x00: // Standard VGA
1360 case 0x01: // Standard VGA
1361 case 0x02: // Standard VGA
1362 case 0x03: // Standard VGA
1363 case 0x04: // Standard VGA
1364 case 0x05: // Standard VGA
1365 case 0x06: // Standard VGA
1366 case 0x07: // Standard VGA
1367 case 0x08: // Standard VGA
1368 case 0x09: // Standard VGA
1369 case 0x0a: // Standard VGA
1370 case 0x0b: // Standard VGA
1371 case 0x0c: // Standard VGA
1372 case 0x0d: // Standard VGA
1373 case 0x0e: // Standard VGA
1374 case 0x0f: // Standard VGA
1375 case 0x10: // Standard VGA
1376 case 0x11: // Standard VGA
1377 case 0x12: // Standard VGA
1378 case 0x13: // Standard VGA
1379 case 0x14: // Standard VGA
1380 case 0x15: // Standard VGA
1381 case 0x16: // Standard VGA
1382 case 0x17: // Standard VGA
1383 case 0x18: // Standard VGA
1384 return CIRRUS_HOOK_NOT_HANDLED
;
1385 case 0x19: // Interlace End
1386 case 0x1a: // Miscellaneous Control
1387 case 0x1b: // Extended Display Control
1388 case 0x1c: // Sync Adjust and Genlock
1389 case 0x1d: // Overlay Extended Control
1390 case 0x22: // Graphics Data Latches Readback (R)
1391 case 0x24: // Attribute Controller Toggle Readback (R)
1392 case 0x25: // Part Status
1393 case 0x27: // Part ID (R)
1394 *reg_value
= s
->cr
[reg_index
];
1396 case 0x26: // Attribute Controller Index Readback (R)
1397 *reg_value
= s
->ar_index
& 0x3f;
1401 printf("cirrus: inport cr_index %02x\n", reg_index
);
1407 return CIRRUS_HOOK_HANDLED
;
1411 cirrus_hook_write_cr(CirrusVGAState
* s
, unsigned reg_index
, int reg_value
)
1413 switch (reg_index
) {
1414 case 0x00: // Standard VGA
1415 case 0x01: // Standard VGA
1416 case 0x02: // Standard VGA
1417 case 0x03: // Standard VGA
1418 case 0x04: // Standard VGA
1419 case 0x05: // Standard VGA
1420 case 0x06: // Standard VGA
1421 case 0x07: // Standard VGA
1422 case 0x08: // Standard VGA
1423 case 0x09: // Standard VGA
1424 case 0x0a: // Standard VGA
1425 case 0x0b: // Standard VGA
1426 case 0x0c: // Standard VGA
1427 case 0x0d: // Standard VGA
1428 case 0x0e: // Standard VGA
1429 case 0x0f: // Standard VGA
1430 case 0x10: // Standard VGA
1431 case 0x11: // Standard VGA
1432 case 0x12: // Standard VGA
1433 case 0x13: // Standard VGA
1434 case 0x14: // Standard VGA
1435 case 0x15: // Standard VGA
1436 case 0x16: // Standard VGA
1437 case 0x17: // Standard VGA
1438 case 0x18: // Standard VGA
1439 return CIRRUS_HOOK_NOT_HANDLED
;
1440 case 0x19: // Interlace End
1441 case 0x1a: // Miscellaneous Control
1442 case 0x1b: // Extended Display Control
1443 case 0x1c: // Sync Adjust and Genlock
1444 s
->cr
[reg_index
] = reg_value
;
1446 printf("cirrus: handled outport cr_index %02x, cr_value %02x\n",
1447 reg_index
, reg_value
);
1450 case 0x22: // Graphics Data Latches Readback (R)
1451 case 0x24: // Attribute Controller Toggle Readback (R)
1452 case 0x26: // Attribute Controller Index Readback (R)
1453 case 0x27: // Part ID (R)
1455 case 0x1d: // Overlay Extended Control
1456 case 0x25: // Part Status
1459 printf("cirrus: outport cr_index %02x, cr_value %02x\n", reg_index
,
1465 return CIRRUS_HOOK_HANDLED
;
1468 /***************************************
1470 * memory-mapped I/O (bitblt)
1472 ***************************************/
1474 static uint8_t cirrus_mmio_blt_read(CirrusVGAState
* s
, unsigned address
)
1479 case (CIRRUS_MMIO_BLTBGCOLOR
+ 0):
1480 cirrus_hook_read_gr(s
, 0x00, &value
);
1482 case (CIRRUS_MMIO_BLTBGCOLOR
+ 1):
1483 cirrus_hook_read_gr(s
, 0x10, &value
);
1485 case (CIRRUS_MMIO_BLTBGCOLOR
+ 2):
1486 cirrus_hook_read_gr(s
, 0x12, &value
);
1488 case (CIRRUS_MMIO_BLTBGCOLOR
+ 3):
1489 cirrus_hook_read_gr(s
, 0x14, &value
);
1491 case (CIRRUS_MMIO_BLTFGCOLOR
+ 0):
1492 cirrus_hook_read_gr(s
, 0x01, &value
);
1494 case (CIRRUS_MMIO_BLTFGCOLOR
+ 1):
1495 cirrus_hook_read_gr(s
, 0x11, &value
);
1497 case (CIRRUS_MMIO_BLTFGCOLOR
+ 2):
1498 cirrus_hook_read_gr(s
, 0x13, &value
);
1500 case (CIRRUS_MMIO_BLTFGCOLOR
+ 3):
1501 cirrus_hook_read_gr(s
, 0x15, &value
);
1503 case (CIRRUS_MMIO_BLTWIDTH
+ 0):
1504 cirrus_hook_read_gr(s
, 0x20, &value
);
1506 case (CIRRUS_MMIO_BLTWIDTH
+ 1):
1507 cirrus_hook_read_gr(s
, 0x21, &value
);
1509 case (CIRRUS_MMIO_BLTHEIGHT
+ 0):
1510 cirrus_hook_read_gr(s
, 0x22, &value
);
1512 case (CIRRUS_MMIO_BLTHEIGHT
+ 1):
1513 cirrus_hook_read_gr(s
, 0x23, &value
);
1515 case (CIRRUS_MMIO_BLTDESTPITCH
+ 0):
1516 cirrus_hook_read_gr(s
, 0x24, &value
);
1518 case (CIRRUS_MMIO_BLTDESTPITCH
+ 1):
1519 cirrus_hook_read_gr(s
, 0x25, &value
);
1521 case (CIRRUS_MMIO_BLTSRCPITCH
+ 0):
1522 cirrus_hook_read_gr(s
, 0x26, &value
);
1524 case (CIRRUS_MMIO_BLTSRCPITCH
+ 1):
1525 cirrus_hook_read_gr(s
, 0x27, &value
);
1527 case (CIRRUS_MMIO_BLTDESTADDR
+ 0):
1528 cirrus_hook_read_gr(s
, 0x28, &value
);
1530 case (CIRRUS_MMIO_BLTDESTADDR
+ 1):
1531 cirrus_hook_read_gr(s
, 0x29, &value
);
1533 case (CIRRUS_MMIO_BLTDESTADDR
+ 2):
1534 cirrus_hook_read_gr(s
, 0x2a, &value
);
1536 case (CIRRUS_MMIO_BLTSRCADDR
+ 0):
1537 cirrus_hook_read_gr(s
, 0x2c, &value
);
1539 case (CIRRUS_MMIO_BLTSRCADDR
+ 1):
1540 cirrus_hook_read_gr(s
, 0x2d, &value
);
1542 case (CIRRUS_MMIO_BLTSRCADDR
+ 2):
1543 cirrus_hook_read_gr(s
, 0x2e, &value
);
1545 case CIRRUS_MMIO_BLTWRITEMASK
:
1546 cirrus_hook_read_gr(s
, 0x2f, &value
);
1548 case CIRRUS_MMIO_BLTMODE
:
1549 cirrus_hook_read_gr(s
, 0x30, &value
);
1551 case CIRRUS_MMIO_BLTROP
:
1552 cirrus_hook_read_gr(s
, 0x32, &value
);
1554 case CIRRUS_MMIO_BLTMODEEXT
:
1555 cirrus_hook_read_gr(s
, 0x33, &value
);
1557 case (CIRRUS_MMIO_BLTTRANSPARENTCOLOR
+ 0):
1558 cirrus_hook_read_gr(s
, 0x34, &value
);
1560 case (CIRRUS_MMIO_BLTTRANSPARENTCOLOR
+ 1):
1561 cirrus_hook_read_gr(s
, 0x35, &value
);
1563 case (CIRRUS_MMIO_BLTTRANSPARENTCOLORMASK
+ 0):
1564 cirrus_hook_read_gr(s
, 0x38, &value
);
1566 case (CIRRUS_MMIO_BLTTRANSPARENTCOLORMASK
+ 1):
1567 cirrus_hook_read_gr(s
, 0x39, &value
);
1569 case CIRRUS_MMIO_BLTSTATUS
:
1570 cirrus_hook_read_gr(s
, 0x31, &value
);
1574 printf("cirrus: mmio read - address 0x%04x\n", address
);
1579 return (uint8_t) value
;
1582 static void cirrus_mmio_blt_write(CirrusVGAState
* s
, unsigned address
,
1586 case (CIRRUS_MMIO_BLTBGCOLOR
+ 0):
1587 cirrus_hook_write_gr(s
, 0x00, value
);
1589 case (CIRRUS_MMIO_BLTBGCOLOR
+ 1):
1590 cirrus_hook_write_gr(s
, 0x10, value
);
1592 case (CIRRUS_MMIO_BLTBGCOLOR
+ 2):
1593 cirrus_hook_write_gr(s
, 0x12, value
);
1595 case (CIRRUS_MMIO_BLTBGCOLOR
+ 3):
1596 cirrus_hook_write_gr(s
, 0x14, value
);
1598 case (CIRRUS_MMIO_BLTFGCOLOR
+ 0):
1599 cirrus_hook_write_gr(s
, 0x01, value
);
1601 case (CIRRUS_MMIO_BLTFGCOLOR
+ 1):
1602 cirrus_hook_write_gr(s
, 0x11, value
);
1604 case (CIRRUS_MMIO_BLTFGCOLOR
+ 2):
1605 cirrus_hook_write_gr(s
, 0x13, value
);
1607 case (CIRRUS_MMIO_BLTFGCOLOR
+ 3):
1608 cirrus_hook_write_gr(s
, 0x15, value
);
1610 case (CIRRUS_MMIO_BLTWIDTH
+ 0):
1611 cirrus_hook_write_gr(s
, 0x20, value
);
1613 case (CIRRUS_MMIO_BLTWIDTH
+ 1):
1614 cirrus_hook_write_gr(s
, 0x21, value
);
1616 case (CIRRUS_MMIO_BLTHEIGHT
+ 0):
1617 cirrus_hook_write_gr(s
, 0x22, value
);
1619 case (CIRRUS_MMIO_BLTHEIGHT
+ 1):
1620 cirrus_hook_write_gr(s
, 0x23, value
);
1622 case (CIRRUS_MMIO_BLTDESTPITCH
+ 0):
1623 cirrus_hook_write_gr(s
, 0x24, value
);
1625 case (CIRRUS_MMIO_BLTDESTPITCH
+ 1):
1626 cirrus_hook_write_gr(s
, 0x25, value
);
1628 case (CIRRUS_MMIO_BLTSRCPITCH
+ 0):
1629 cirrus_hook_write_gr(s
, 0x26, value
);
1631 case (CIRRUS_MMIO_BLTSRCPITCH
+ 1):
1632 cirrus_hook_write_gr(s
, 0x27, value
);
1634 case (CIRRUS_MMIO_BLTDESTADDR
+ 0):
1635 cirrus_hook_write_gr(s
, 0x28, value
);
1637 case (CIRRUS_MMIO_BLTDESTADDR
+ 1):
1638 cirrus_hook_write_gr(s
, 0x29, value
);
1640 case (CIRRUS_MMIO_BLTDESTADDR
+ 2):
1641 cirrus_hook_write_gr(s
, 0x2a, value
);
1643 case (CIRRUS_MMIO_BLTDESTADDR
+ 3):
1646 case (CIRRUS_MMIO_BLTSRCADDR
+ 0):
1647 cirrus_hook_write_gr(s
, 0x2c, value
);
1649 case (CIRRUS_MMIO_BLTSRCADDR
+ 1):
1650 cirrus_hook_write_gr(s
, 0x2d, value
);
1652 case (CIRRUS_MMIO_BLTSRCADDR
+ 2):
1653 cirrus_hook_write_gr(s
, 0x2e, value
);
1655 case CIRRUS_MMIO_BLTWRITEMASK
:
1656 cirrus_hook_write_gr(s
, 0x2f, value
);
1658 case CIRRUS_MMIO_BLTMODE
:
1659 cirrus_hook_write_gr(s
, 0x30, value
);
1661 case CIRRUS_MMIO_BLTROP
:
1662 cirrus_hook_write_gr(s
, 0x32, value
);
1664 case CIRRUS_MMIO_BLTMODEEXT
:
1665 cirrus_hook_write_gr(s
, 0x33, value
);
1667 case (CIRRUS_MMIO_BLTTRANSPARENTCOLOR
+ 0):
1668 cirrus_hook_write_gr(s
, 0x34, value
);
1670 case (CIRRUS_MMIO_BLTTRANSPARENTCOLOR
+ 1):
1671 cirrus_hook_write_gr(s
, 0x35, value
);
1673 case (CIRRUS_MMIO_BLTTRANSPARENTCOLORMASK
+ 0):
1674 cirrus_hook_write_gr(s
, 0x38, value
);
1676 case (CIRRUS_MMIO_BLTTRANSPARENTCOLORMASK
+ 1):
1677 cirrus_hook_write_gr(s
, 0x39, value
);
1679 case CIRRUS_MMIO_BLTSTATUS
:
1680 cirrus_hook_write_gr(s
, 0x31, value
);
1684 printf("cirrus: mmio write - addr 0x%04x val 0x%02x (ignored)\n",
1691 /***************************************
1695 * assume TARGET_PAGE_SIZE >= 16
1697 ***************************************/
1699 static void cirrus_mem_writeb_mode4and5_8bpp(CirrusVGAState
* s
,
1705 unsigned val
= mem_value
;
1708 dst
= s
->vram_ptr
+ offset
;
1709 for (x
= 0; x
< 8; x
++) {
1711 *dst
++ = s
->cirrus_shadow_gr1
;
1712 } else if (mode
== 5) {
1713 *dst
++ = s
->cirrus_shadow_gr0
;
1717 cpu_physical_memory_set_dirty(s
->vram_offset
+ offset
);
1718 cpu_physical_memory_set_dirty(s
->vram_offset
+ offset
+ 7);
1721 static void cirrus_mem_writeb_mode4and5_16bpp(CirrusVGAState
* s
,
1727 unsigned val
= mem_value
;
1730 dst
= s
->vram_ptr
+ offset
;
1731 for (x
= 0; x
< 8; x
++) {
1733 *dst
++ = s
->cirrus_shadow_gr1
;
1734 *dst
++ = s
->gr
[0x11];
1735 } else if (mode
== 5) {
1736 *dst
++ = s
->cirrus_shadow_gr0
;
1737 *dst
++ = s
->gr
[0x10];
1741 cpu_physical_memory_set_dirty(s
->vram_offset
+ offset
);
1742 cpu_physical_memory_set_dirty(s
->vram_offset
+ offset
+ 15);
1745 /***************************************
1747 * memory access between 0xa0000-0xbffff
1749 ***************************************/
1751 static uint32_t cirrus_vga_mem_readb(void *opaque
, target_phys_addr_t addr
)
1753 CirrusVGAState
*s
= opaque
;
1754 unsigned bank_index
;
1755 unsigned bank_offset
;
1758 if ((s
->sr
[0x07] & 0x01) == 0) {
1759 return vga_mem_readb(s
, addr
);
1764 if (addr
< 0x10000) {
1765 /* XXX handle bitblt */
1767 bank_index
= addr
>> 15;
1768 bank_offset
= addr
& 0x7fff;
1769 if (bank_offset
< s
->cirrus_bank_limit
[bank_index
]) {
1770 bank_offset
+= s
->cirrus_bank_base
[bank_index
];
1771 if ((s
->gr
[0x0B] & 0x14) == 0x14) {
1773 } else if (s
->gr
[0x0B] & 0x02) {
1776 bank_offset
&= s
->cirrus_addr_mask
;
1777 val
= *(s
->vram_ptr
+ bank_offset
);
1780 } else if (addr
>= 0x18000 && addr
< 0x18100) {
1781 /* memory-mapped I/O */
1783 if ((s
->sr
[0x17] & 0x44) == 0x04) {
1784 val
= cirrus_mmio_blt_read(s
, addr
& 0xff);
1789 printf("cirrus: mem_readb %06x\n", addr
);
1795 static uint32_t cirrus_vga_mem_readw(void *opaque
, target_phys_addr_t addr
)
1798 #ifdef TARGET_WORDS_BIGENDIAN
1799 v
= cirrus_vga_mem_readb(opaque
, addr
) << 8;
1800 v
|= cirrus_vga_mem_readb(opaque
, addr
+ 1);
1802 v
= cirrus_vga_mem_readb(opaque
, addr
);
1803 v
|= cirrus_vga_mem_readb(opaque
, addr
+ 1) << 8;
1808 static uint32_t cirrus_vga_mem_readl(void *opaque
, target_phys_addr_t addr
)
1811 #ifdef TARGET_WORDS_BIGENDIAN
1812 v
= cirrus_vga_mem_readb(opaque
, addr
) << 24;
1813 v
|= cirrus_vga_mem_readb(opaque
, addr
+ 1) << 16;
1814 v
|= cirrus_vga_mem_readb(opaque
, addr
+ 2) << 8;
1815 v
|= cirrus_vga_mem_readb(opaque
, addr
+ 3);
1817 v
= cirrus_vga_mem_readb(opaque
, addr
);
1818 v
|= cirrus_vga_mem_readb(opaque
, addr
+ 1) << 8;
1819 v
|= cirrus_vga_mem_readb(opaque
, addr
+ 2) << 16;
1820 v
|= cirrus_vga_mem_readb(opaque
, addr
+ 3) << 24;
1825 static void cirrus_vga_mem_writeb(void *opaque
, target_phys_addr_t addr
,
1828 CirrusVGAState
*s
= opaque
;
1829 unsigned bank_index
;
1830 unsigned bank_offset
;
1833 if ((s
->sr
[0x07] & 0x01) == 0) {
1834 vga_mem_writeb(s
, addr
, mem_value
);
1840 if (addr
< 0x10000) {
1841 if (s
->cirrus_srcptr
!= s
->cirrus_srcptr_end
) {
1843 *s
->cirrus_srcptr
++ = (uint8_t) mem_value
;
1844 if (s
->cirrus_srcptr
>= s
->cirrus_srcptr_end
) {
1845 cirrus_bitblt_cputovideo_next(s
);
1849 bank_index
= addr
>> 15;
1850 bank_offset
= addr
& 0x7fff;
1851 if (bank_offset
< s
->cirrus_bank_limit
[bank_index
]) {
1852 bank_offset
+= s
->cirrus_bank_base
[bank_index
];
1853 if ((s
->gr
[0x0B] & 0x14) == 0x14) {
1855 } else if (s
->gr
[0x0B] & 0x02) {
1858 bank_offset
&= s
->cirrus_addr_mask
;
1859 mode
= s
->gr
[0x05] & 0x7;
1860 if (mode
< 4 || mode
> 5 || ((s
->gr
[0x0B] & 0x4) == 0)) {
1861 *(s
->vram_ptr
+ bank_offset
) = mem_value
;
1862 cpu_physical_memory_set_dirty(s
->vram_offset
+
1865 if ((s
->gr
[0x0B] & 0x14) != 0x14) {
1866 cirrus_mem_writeb_mode4and5_8bpp(s
, mode
,
1870 cirrus_mem_writeb_mode4and5_16bpp(s
, mode
,
1877 } else if (addr
>= 0x18000 && addr
< 0x18100) {
1878 /* memory-mapped I/O */
1879 if ((s
->sr
[0x17] & 0x44) == 0x04) {
1880 cirrus_mmio_blt_write(s
, addr
& 0xff, mem_value
);
1884 printf("cirrus: mem_writeb %06x value %02x\n", addr
, mem_value
);
1889 static void cirrus_vga_mem_writew(void *opaque
, target_phys_addr_t addr
, uint32_t val
)
1891 #ifdef TARGET_WORDS_BIGENDIAN
1892 cirrus_vga_mem_writeb(opaque
, addr
, (val
>> 8) & 0xff);
1893 cirrus_vga_mem_writeb(opaque
, addr
+ 1, val
& 0xff);
1895 cirrus_vga_mem_writeb(opaque
, addr
, val
& 0xff);
1896 cirrus_vga_mem_writeb(opaque
, addr
+ 1, (val
>> 8) & 0xff);
1900 static void cirrus_vga_mem_writel(void *opaque
, target_phys_addr_t addr
, uint32_t val
)
1902 #ifdef TARGET_WORDS_BIGENDIAN
1903 cirrus_vga_mem_writeb(opaque
, addr
, (val
>> 24) & 0xff);
1904 cirrus_vga_mem_writeb(opaque
, addr
+ 1, (val
>> 16) & 0xff);
1905 cirrus_vga_mem_writeb(opaque
, addr
+ 2, (val
>> 8) & 0xff);
1906 cirrus_vga_mem_writeb(opaque
, addr
+ 3, val
& 0xff);
1908 cirrus_vga_mem_writeb(opaque
, addr
, val
& 0xff);
1909 cirrus_vga_mem_writeb(opaque
, addr
+ 1, (val
>> 8) & 0xff);
1910 cirrus_vga_mem_writeb(opaque
, addr
+ 2, (val
>> 16) & 0xff);
1911 cirrus_vga_mem_writeb(opaque
, addr
+ 3, (val
>> 24) & 0xff);
1915 static CPUReadMemoryFunc
*cirrus_vga_mem_read
[3] = {
1916 cirrus_vga_mem_readb
,
1917 cirrus_vga_mem_readw
,
1918 cirrus_vga_mem_readl
,
1921 static CPUWriteMemoryFunc
*cirrus_vga_mem_write
[3] = {
1922 cirrus_vga_mem_writeb
,
1923 cirrus_vga_mem_writew
,
1924 cirrus_vga_mem_writel
,
1927 /***************************************
1931 ***************************************/
1933 static inline void invalidate_cursor1(CirrusVGAState
*s
)
1935 if (s
->last_hw_cursor_size
) {
1936 vga_invalidate_scanlines((VGAState
*)s
,
1937 s
->last_hw_cursor_y
+ s
->last_hw_cursor_y_start
,
1938 s
->last_hw_cursor_y
+ s
->last_hw_cursor_y_end
);
1942 static inline void cirrus_cursor_compute_yrange(CirrusVGAState
*s
)
1946 int y
, y_min
, y_max
;
1948 src
= s
->vram_ptr
+ 0x200000 - 16 * 1024;
1949 if (s
->sr
[0x12] & CIRRUS_CURSOR_LARGE
) {
1950 src
+= (s
->sr
[0x13] & 0x3c) * 256;
1953 for(y
= 0; y
< 64; y
++) {
1954 content
= ((uint32_t *)src
)[0] |
1955 ((uint32_t *)src
)[1] |
1956 ((uint32_t *)src
)[2] |
1957 ((uint32_t *)src
)[3];
1967 src
+= (s
->sr
[0x13] & 0x3f) * 256;
1970 for(y
= 0; y
< 32; y
++) {
1971 content
= ((uint32_t *)src
)[0] |
1972 ((uint32_t *)(src
+ 128))[0];
1982 if (y_min
> y_max
) {
1983 s
->last_hw_cursor_y_start
= 0;
1984 s
->last_hw_cursor_y_end
= 0;
1986 s
->last_hw_cursor_y_start
= y_min
;
1987 s
->last_hw_cursor_y_end
= y_max
+ 1;
1991 /* NOTE: we do not currently handle the cursor bitmap change, so we
1992 update the cursor only if it moves. */
1993 static void cirrus_cursor_invalidate(VGAState
*s1
)
1995 CirrusVGAState
*s
= (CirrusVGAState
*)s1
;
1998 if (!s
->sr
[0x12] & CIRRUS_CURSOR_SHOW
) {
2001 if (s
->sr
[0x12] & CIRRUS_CURSOR_LARGE
)
2006 /* invalidate last cursor and new cursor if any change */
2007 if (s
->last_hw_cursor_size
!= size
||
2008 s
->last_hw_cursor_x
!= s
->hw_cursor_x
||
2009 s
->last_hw_cursor_y
!= s
->hw_cursor_y
) {
2011 invalidate_cursor1(s
);
2013 s
->last_hw_cursor_size
= size
;
2014 s
->last_hw_cursor_x
= s
->hw_cursor_x
;
2015 s
->last_hw_cursor_y
= s
->hw_cursor_y
;
2016 /* compute the real cursor min and max y */
2017 cirrus_cursor_compute_yrange(s
);
2018 invalidate_cursor1(s
);
2022 static void cirrus_cursor_draw_line(VGAState
*s1
, uint8_t *d1
, int scr_y
)
2024 CirrusVGAState
*s
= (CirrusVGAState
*)s1
;
2025 int w
, h
, bpp
, x1
, x2
, poffset
;
2026 unsigned int color0
, color1
;
2027 const uint8_t *palette
, *src
;
2030 if (!(s
->sr
[0x12] & CIRRUS_CURSOR_SHOW
))
2032 /* fast test to see if the cursor intersects with the scan line */
2033 if (s
->sr
[0x12] & CIRRUS_CURSOR_LARGE
) {
2038 if (scr_y
< s
->hw_cursor_y
||
2039 scr_y
>= (s
->hw_cursor_y
+ h
))
2042 src
= s
->vram_ptr
+ 0x200000 - 16 * 1024;
2043 if (s
->sr
[0x12] & CIRRUS_CURSOR_LARGE
) {
2044 src
+= (s
->sr
[0x13] & 0x3c) * 256;
2045 src
+= (scr_y
- s
->hw_cursor_y
) * 16;
2047 content
= ((uint32_t *)src
)[0] |
2048 ((uint32_t *)src
)[1] |
2049 ((uint32_t *)src
)[2] |
2050 ((uint32_t *)src
)[3];
2052 src
+= (s
->sr
[0x13] & 0x3f) * 256;
2053 src
+= (scr_y
- s
->hw_cursor_y
) * 4;
2055 content
= ((uint32_t *)src
)[0] |
2056 ((uint32_t *)(src
+ 128))[0];
2058 /* if nothing to draw, no need to continue */
2063 x1
= s
->hw_cursor_x
;
2064 if (x1
>= s
->last_scr_width
)
2066 x2
= s
->hw_cursor_x
+ w
;
2067 if (x2
> s
->last_scr_width
)
2068 x2
= s
->last_scr_width
;
2070 palette
= s
->cirrus_hidden_palette
;
2071 color0
= s
->rgb_to_pixel(c6_to_8(palette
[0x0 * 3]),
2072 c6_to_8(palette
[0x0 * 3 + 1]),
2073 c6_to_8(palette
[0x0 * 3 + 2]));
2074 color1
= s
->rgb_to_pixel(c6_to_8(palette
[0xf * 3]),
2075 c6_to_8(palette
[0xf * 3 + 1]),
2076 c6_to_8(palette
[0xf * 3 + 2]));
2077 bpp
= ((s
->ds
->depth
+ 7) >> 3);
2079 switch(s
->ds
->depth
) {
2083 vga_draw_cursor_line_8(d1
, src
, poffset
, w
, color0
, color1
, 0xff);
2086 vga_draw_cursor_line_16(d1
, src
, poffset
, w
, color0
, color1
, 0x7fff);
2089 vga_draw_cursor_line_16(d1
, src
, poffset
, w
, color0
, color1
, 0xffff);
2092 vga_draw_cursor_line_32(d1
, src
, poffset
, w
, color0
, color1
, 0xffffff);
2097 /***************************************
2101 ***************************************/
2103 static uint32_t cirrus_linear_readb(void *opaque
, target_phys_addr_t addr
)
2105 CirrusVGAState
*s
= (CirrusVGAState
*) opaque
;
2108 /* XXX: s->vram_size must be a power of two */
2109 addr
&= s
->cirrus_addr_mask
;
2111 if (((s
->sr
[0x17] & 0x44) == 0x44) && ((addr
& 0x1fff00) == 0x1fff00)) {
2112 /* memory-mapped I/O */
2113 ret
= cirrus_mmio_blt_read(s
, addr
& 0xff);
2115 /* XXX handle bitblt */
2119 if ((s
->gr
[0x0B] & 0x14) == 0x14) {
2121 } else if (s
->gr
[0x0B] & 0x02) {
2124 addr
&= s
->cirrus_addr_mask
;
2125 ret
= *(s
->vram_ptr
+ addr
);
2131 static uint32_t cirrus_linear_readw(void *opaque
, target_phys_addr_t addr
)
2134 #ifdef TARGET_WORDS_BIGENDIAN
2135 v
= cirrus_linear_readb(opaque
, addr
) << 8;
2136 v
|= cirrus_linear_readb(opaque
, addr
+ 1);
2138 v
= cirrus_linear_readb(opaque
, addr
);
2139 v
|= cirrus_linear_readb(opaque
, addr
+ 1) << 8;
2144 static uint32_t cirrus_linear_readl(void *opaque
, target_phys_addr_t addr
)
2147 #ifdef TARGET_WORDS_BIGENDIAN
2148 v
= cirrus_linear_readb(opaque
, addr
) << 24;
2149 v
|= cirrus_linear_readb(opaque
, addr
+ 1) << 16;
2150 v
|= cirrus_linear_readb(opaque
, addr
+ 2) << 8;
2151 v
|= cirrus_linear_readb(opaque
, addr
+ 3);
2153 v
= cirrus_linear_readb(opaque
, addr
);
2154 v
|= cirrus_linear_readb(opaque
, addr
+ 1) << 8;
2155 v
|= cirrus_linear_readb(opaque
, addr
+ 2) << 16;
2156 v
|= cirrus_linear_readb(opaque
, addr
+ 3) << 24;
2161 static void cirrus_linear_writeb(void *opaque
, target_phys_addr_t addr
,
2164 CirrusVGAState
*s
= (CirrusVGAState
*) opaque
;
2167 addr
&= s
->cirrus_addr_mask
;
2169 if (((s
->sr
[0x17] & 0x44) == 0x44) && ((addr
& 0x1fff00) == 0x1fff00)) {
2170 /* memory-mapped I/O */
2171 cirrus_mmio_blt_write(s
, addr
& 0xff, val
);
2172 } else if (s
->cirrus_srcptr
!= s
->cirrus_srcptr_end
) {
2174 *s
->cirrus_srcptr
++ = (uint8_t) val
;
2175 if (s
->cirrus_srcptr
>= s
->cirrus_srcptr_end
) {
2176 cirrus_bitblt_cputovideo_next(s
);
2180 if ((s
->gr
[0x0B] & 0x14) == 0x14) {
2182 } else if (s
->gr
[0x0B] & 0x02) {
2185 addr
&= s
->cirrus_addr_mask
;
2187 mode
= s
->gr
[0x05] & 0x7;
2188 if (mode
< 4 || mode
> 5 || ((s
->gr
[0x0B] & 0x4) == 0)) {
2189 *(s
->vram_ptr
+ addr
) = (uint8_t) val
;
2190 cpu_physical_memory_set_dirty(s
->vram_offset
+ addr
);
2192 if ((s
->gr
[0x0B] & 0x14) != 0x14) {
2193 cirrus_mem_writeb_mode4and5_8bpp(s
, mode
, addr
, val
);
2195 cirrus_mem_writeb_mode4and5_16bpp(s
, mode
, addr
, val
);
2201 static void cirrus_linear_writew(void *opaque
, target_phys_addr_t addr
,
2204 #ifdef TARGET_WORDS_BIGENDIAN
2205 cirrus_linear_writeb(opaque
, addr
, (val
>> 8) & 0xff);
2206 cirrus_linear_writeb(opaque
, addr
+ 1, val
& 0xff);
2208 cirrus_linear_writeb(opaque
, addr
, val
& 0xff);
2209 cirrus_linear_writeb(opaque
, addr
+ 1, (val
>> 8) & 0xff);
2213 static void cirrus_linear_writel(void *opaque
, target_phys_addr_t addr
,
2216 #ifdef TARGET_WORDS_BIGENDIAN
2217 cirrus_linear_writeb(opaque
, addr
, (val
>> 24) & 0xff);
2218 cirrus_linear_writeb(opaque
, addr
+ 1, (val
>> 16) & 0xff);
2219 cirrus_linear_writeb(opaque
, addr
+ 2, (val
>> 8) & 0xff);
2220 cirrus_linear_writeb(opaque
, addr
+ 3, val
& 0xff);
2222 cirrus_linear_writeb(opaque
, addr
, val
& 0xff);
2223 cirrus_linear_writeb(opaque
, addr
+ 1, (val
>> 8) & 0xff);
2224 cirrus_linear_writeb(opaque
, addr
+ 2, (val
>> 16) & 0xff);
2225 cirrus_linear_writeb(opaque
, addr
+ 3, (val
>> 24) & 0xff);
2230 static CPUReadMemoryFunc
*cirrus_linear_read
[3] = {
2231 cirrus_linear_readb
,
2232 cirrus_linear_readw
,
2233 cirrus_linear_readl
,
2236 static CPUWriteMemoryFunc
*cirrus_linear_write
[3] = {
2237 cirrus_linear_writeb
,
2238 cirrus_linear_writew
,
2239 cirrus_linear_writel
,
2242 /***************************************
2244 * system to screen memory access
2246 ***************************************/
2249 static uint32_t cirrus_linear_bitblt_readb(void *opaque
, target_phys_addr_t addr
)
2253 /* XXX handle bitblt */
2258 static uint32_t cirrus_linear_bitblt_readw(void *opaque
, target_phys_addr_t addr
)
2261 #ifdef TARGET_WORDS_BIGENDIAN
2262 v
= cirrus_linear_bitblt_readb(opaque
, addr
) << 8;
2263 v
|= cirrus_linear_bitblt_readb(opaque
, addr
+ 1);
2265 v
= cirrus_linear_bitblt_readb(opaque
, addr
);
2266 v
|= cirrus_linear_bitblt_readb(opaque
, addr
+ 1) << 8;
2271 static uint32_t cirrus_linear_bitblt_readl(void *opaque
, target_phys_addr_t addr
)
2274 #ifdef TARGET_WORDS_BIGENDIAN
2275 v
= cirrus_linear_bitblt_readb(opaque
, addr
) << 24;
2276 v
|= cirrus_linear_bitblt_readb(opaque
, addr
+ 1) << 16;
2277 v
|= cirrus_linear_bitblt_readb(opaque
, addr
+ 2) << 8;
2278 v
|= cirrus_linear_bitblt_readb(opaque
, addr
+ 3);
2280 v
= cirrus_linear_bitblt_readb(opaque
, addr
);
2281 v
|= cirrus_linear_bitblt_readb(opaque
, addr
+ 1) << 8;
2282 v
|= cirrus_linear_bitblt_readb(opaque
, addr
+ 2) << 16;
2283 v
|= cirrus_linear_bitblt_readb(opaque
, addr
+ 3) << 24;
2288 static void cirrus_linear_bitblt_writeb(void *opaque
, target_phys_addr_t addr
,
2291 CirrusVGAState
*s
= (CirrusVGAState
*) opaque
;
2293 if (s
->cirrus_srcptr
!= s
->cirrus_srcptr_end
) {
2295 *s
->cirrus_srcptr
++ = (uint8_t) val
;
2296 if (s
->cirrus_srcptr
>= s
->cirrus_srcptr_end
) {
2297 cirrus_bitblt_cputovideo_next(s
);
2302 static void cirrus_linear_bitblt_writew(void *opaque
, target_phys_addr_t addr
,
2305 #ifdef TARGET_WORDS_BIGENDIAN
2306 cirrus_linear_bitblt_writeb(opaque
, addr
, (val
>> 8) & 0xff);
2307 cirrus_linear_bitblt_writeb(opaque
, addr
+ 1, val
& 0xff);
2309 cirrus_linear_bitblt_writeb(opaque
, addr
, val
& 0xff);
2310 cirrus_linear_bitblt_writeb(opaque
, addr
+ 1, (val
>> 8) & 0xff);
2314 static void cirrus_linear_bitblt_writel(void *opaque
, target_phys_addr_t addr
,
2317 #ifdef TARGET_WORDS_BIGENDIAN
2318 cirrus_linear_bitblt_writeb(opaque
, addr
, (val
>> 24) & 0xff);
2319 cirrus_linear_bitblt_writeb(opaque
, addr
+ 1, (val
>> 16) & 0xff);
2320 cirrus_linear_bitblt_writeb(opaque
, addr
+ 2, (val
>> 8) & 0xff);
2321 cirrus_linear_bitblt_writeb(opaque
, addr
+ 3, val
& 0xff);
2323 cirrus_linear_bitblt_writeb(opaque
, addr
, val
& 0xff);
2324 cirrus_linear_bitblt_writeb(opaque
, addr
+ 1, (val
>> 8) & 0xff);
2325 cirrus_linear_bitblt_writeb(opaque
, addr
+ 2, (val
>> 16) & 0xff);
2326 cirrus_linear_bitblt_writeb(opaque
, addr
+ 3, (val
>> 24) & 0xff);
2331 static CPUReadMemoryFunc
*cirrus_linear_bitblt_read
[3] = {
2332 cirrus_linear_bitblt_readb
,
2333 cirrus_linear_bitblt_readw
,
2334 cirrus_linear_bitblt_readl
,
2337 static CPUWriteMemoryFunc
*cirrus_linear_bitblt_write
[3] = {
2338 cirrus_linear_bitblt_writeb
,
2339 cirrus_linear_bitblt_writew
,
2340 cirrus_linear_bitblt_writel
,
2345 static uint32_t vga_ioport_read(void *opaque
, uint32_t addr
)
2347 CirrusVGAState
*s
= opaque
;
2350 /* check port range access depending on color/monochrome mode */
2351 if ((addr
>= 0x3b0 && addr
<= 0x3bf && (s
->msr
& MSR_COLOR_EMULATION
))
2352 || (addr
>= 0x3d0 && addr
<= 0x3df
2353 && !(s
->msr
& MSR_COLOR_EMULATION
))) {
2358 if (s
->ar_flip_flop
== 0) {
2365 index
= s
->ar_index
& 0x1f;
2378 if (cirrus_hook_read_sr(s
, s
->sr_index
, &val
))
2380 val
= s
->sr
[s
->sr_index
];
2381 #ifdef DEBUG_VGA_REG
2382 printf("vga: read SR%x = 0x%02x\n", s
->sr_index
, val
);
2386 cirrus_read_hidden_dac(s
, &val
);
2392 if (cirrus_hook_read_palette(s
, &val
))
2394 val
= s
->palette
[s
->dac_read_index
* 3 + s
->dac_sub_index
];
2395 if (++s
->dac_sub_index
== 3) {
2396 s
->dac_sub_index
= 0;
2397 s
->dac_read_index
++;
2410 if (cirrus_hook_read_gr(s
, s
->gr_index
, &val
))
2412 val
= s
->gr
[s
->gr_index
];
2413 #ifdef DEBUG_VGA_REG
2414 printf("vga: read GR%x = 0x%02x\n", s
->gr_index
, val
);
2423 if (cirrus_hook_read_cr(s
, s
->cr_index
, &val
))
2425 val
= s
->cr
[s
->cr_index
];
2426 #ifdef DEBUG_VGA_REG
2427 printf("vga: read CR%x = 0x%02x\n", s
->cr_index
, val
);
2432 /* just toggle to fool polling */
2433 s
->st01
^= ST01_V_RETRACE
| ST01_DISP_ENABLE
;
2435 s
->ar_flip_flop
= 0;
2442 #if defined(DEBUG_VGA)
2443 printf("VGA: read addr=0x%04x data=0x%02x\n", addr
, val
);
2448 static void vga_ioport_write(void *opaque
, uint32_t addr
, uint32_t val
)
2450 CirrusVGAState
*s
= opaque
;
2453 /* check port range access depending on color/monochrome mode */
2454 if ((addr
>= 0x3b0 && addr
<= 0x3bf && (s
->msr
& MSR_COLOR_EMULATION
))
2455 || (addr
>= 0x3d0 && addr
<= 0x3df
2456 && !(s
->msr
& MSR_COLOR_EMULATION
)))
2460 printf("VGA: write addr=0x%04x data=0x%02x\n", addr
, val
);
2465 if (s
->ar_flip_flop
== 0) {
2469 index
= s
->ar_index
& 0x1f;
2472 s
->ar
[index
] = val
& 0x3f;
2475 s
->ar
[index
] = val
& ~0x10;
2481 s
->ar
[index
] = val
& ~0xc0;
2484 s
->ar
[index
] = val
& ~0xf0;
2487 s
->ar
[index
] = val
& ~0xf0;
2493 s
->ar_flip_flop
^= 1;
2496 s
->msr
= val
& ~0x10;
2502 if (cirrus_hook_write_sr(s
, s
->sr_index
, val
))
2504 #ifdef DEBUG_VGA_REG
2505 printf("vga: write SR%x = 0x%02x\n", s
->sr_index
, val
);
2507 s
->sr
[s
->sr_index
] = val
& sr_mask
[s
->sr_index
];
2510 cirrus_write_hidden_dac(s
, val
);
2513 s
->dac_read_index
= val
;
2514 s
->dac_sub_index
= 0;
2518 s
->dac_write_index
= val
;
2519 s
->dac_sub_index
= 0;
2523 if (cirrus_hook_write_palette(s
, val
))
2525 s
->dac_cache
[s
->dac_sub_index
] = val
;
2526 if (++s
->dac_sub_index
== 3) {
2527 memcpy(&s
->palette
[s
->dac_write_index
* 3], s
->dac_cache
, 3);
2528 s
->dac_sub_index
= 0;
2529 s
->dac_write_index
++;
2536 if (cirrus_hook_write_gr(s
, s
->gr_index
, val
))
2538 #ifdef DEBUG_VGA_REG
2539 printf("vga: write GR%x = 0x%02x\n", s
->gr_index
, val
);
2541 s
->gr
[s
->gr_index
] = val
& gr_mask
[s
->gr_index
];
2549 if (cirrus_hook_write_cr(s
, s
->cr_index
, val
))
2551 #ifdef DEBUG_VGA_REG
2552 printf("vga: write CR%x = 0x%02x\n", s
->cr_index
, val
);
2554 /* handle CR0-7 protection */
2555 if ((s
->cr
[11] & 0x80) && s
->cr_index
<= 7) {
2556 /* can always write bit 4 of CR7 */
2557 if (s
->cr_index
== 7)
2558 s
->cr
[7] = (s
->cr
[7] & ~0x10) | (val
& 0x10);
2561 switch (s
->cr_index
) {
2562 case 0x01: /* horizontal display end */
2567 case 0x12: /* veritcal display end */
2568 s
->cr
[s
->cr_index
] = val
;
2572 s
->cr
[s
->cr_index
] = val
;
2578 s
->fcr
= val
& 0x10;
2583 /***************************************
2585 * memory-mapped I/O access
2587 ***************************************/
2589 static uint32_t cirrus_mmio_readb(void *opaque
, target_phys_addr_t addr
)
2591 CirrusVGAState
*s
= (CirrusVGAState
*) opaque
;
2593 addr
&= CIRRUS_PNPMMIO_SIZE
- 1;
2595 if (addr
>= 0x100) {
2596 return cirrus_mmio_blt_read(s
, addr
- 0x100);
2598 return vga_ioport_read(s
, addr
+ 0x3c0);
2602 static uint32_t cirrus_mmio_readw(void *opaque
, target_phys_addr_t addr
)
2605 #ifdef TARGET_WORDS_BIGENDIAN
2606 v
= cirrus_mmio_readb(opaque
, addr
) << 8;
2607 v
|= cirrus_mmio_readb(opaque
, addr
+ 1);
2609 v
= cirrus_mmio_readb(opaque
, addr
);
2610 v
|= cirrus_mmio_readb(opaque
, addr
+ 1) << 8;
2615 static uint32_t cirrus_mmio_readl(void *opaque
, target_phys_addr_t addr
)
2618 #ifdef TARGET_WORDS_BIGENDIAN
2619 v
= cirrus_mmio_readb(opaque
, addr
) << 24;
2620 v
|= cirrus_mmio_readb(opaque
, addr
+ 1) << 16;
2621 v
|= cirrus_mmio_readb(opaque
, addr
+ 2) << 8;
2622 v
|= cirrus_mmio_readb(opaque
, addr
+ 3);
2624 v
= cirrus_mmio_readb(opaque
, addr
);
2625 v
|= cirrus_mmio_readb(opaque
, addr
+ 1) << 8;
2626 v
|= cirrus_mmio_readb(opaque
, addr
+ 2) << 16;
2627 v
|= cirrus_mmio_readb(opaque
, addr
+ 3) << 24;
2632 static void cirrus_mmio_writeb(void *opaque
, target_phys_addr_t addr
,
2635 CirrusVGAState
*s
= (CirrusVGAState
*) opaque
;
2637 addr
&= CIRRUS_PNPMMIO_SIZE
- 1;
2639 if (addr
>= 0x100) {
2640 cirrus_mmio_blt_write(s
, addr
- 0x100, val
);
2642 vga_ioport_write(s
, addr
+ 0x3c0, val
);
2646 static void cirrus_mmio_writew(void *opaque
, target_phys_addr_t addr
,
2649 #ifdef TARGET_WORDS_BIGENDIAN
2650 cirrus_mmio_writeb(opaque
, addr
, (val
>> 8) & 0xff);
2651 cirrus_mmio_writeb(opaque
, addr
+ 1, val
& 0xff);
2653 cirrus_mmio_writeb(opaque
, addr
, val
& 0xff);
2654 cirrus_mmio_writeb(opaque
, addr
+ 1, (val
>> 8) & 0xff);
2658 static void cirrus_mmio_writel(void *opaque
, target_phys_addr_t addr
,
2661 #ifdef TARGET_WORDS_BIGENDIAN
2662 cirrus_mmio_writeb(opaque
, addr
, (val
>> 24) & 0xff);
2663 cirrus_mmio_writeb(opaque
, addr
+ 1, (val
>> 16) & 0xff);
2664 cirrus_mmio_writeb(opaque
, addr
+ 2, (val
>> 8) & 0xff);
2665 cirrus_mmio_writeb(opaque
, addr
+ 3, val
& 0xff);
2667 cirrus_mmio_writeb(opaque
, addr
, val
& 0xff);
2668 cirrus_mmio_writeb(opaque
, addr
+ 1, (val
>> 8) & 0xff);
2669 cirrus_mmio_writeb(opaque
, addr
+ 2, (val
>> 16) & 0xff);
2670 cirrus_mmio_writeb(opaque
, addr
+ 3, (val
>> 24) & 0xff);
2675 static CPUReadMemoryFunc
*cirrus_mmio_read
[3] = {
2681 static CPUWriteMemoryFunc
*cirrus_mmio_write
[3] = {
2687 /***************************************
2691 ***************************************/
2693 static void cirrus_init_common(CirrusVGAState
* s
, int device_id
)
2695 int vga_io_memory
, i
;
2700 for(i
= 0;i
< 256; i
++)
2701 rop_to_index
[i
] = CIRRUS_ROP_NOP_INDEX
; /* nop rop */
2702 rop_to_index
[CIRRUS_ROP_0
] = 0;
2703 rop_to_index
[CIRRUS_ROP_SRC_AND_DST
] = 1;
2704 rop_to_index
[CIRRUS_ROP_NOP
] = 2;
2705 rop_to_index
[CIRRUS_ROP_SRC_AND_NOTDST
] = 3;
2706 rop_to_index
[CIRRUS_ROP_NOTDST
] = 4;
2707 rop_to_index
[CIRRUS_ROP_SRC
] = 5;
2708 rop_to_index
[CIRRUS_ROP_1
] = 6;
2709 rop_to_index
[CIRRUS_ROP_NOTSRC_AND_DST
] = 7;
2710 rop_to_index
[CIRRUS_ROP_SRC_XOR_DST
] = 8;
2711 rop_to_index
[CIRRUS_ROP_SRC_OR_DST
] = 9;
2712 rop_to_index
[CIRRUS_ROP_NOTSRC_OR_NOTDST
] = 10;
2713 rop_to_index
[CIRRUS_ROP_SRC_NOTXOR_DST
] = 11;
2714 rop_to_index
[CIRRUS_ROP_SRC_OR_NOTDST
] = 12;
2715 rop_to_index
[CIRRUS_ROP_NOTSRC
] = 13;
2716 rop_to_index
[CIRRUS_ROP_NOTSRC_OR_DST
] = 14;
2717 rop_to_index
[CIRRUS_ROP_NOTSRC_AND_NOTDST
] = 15;
2720 register_ioport_write(0x3c0, 16, 1, vga_ioport_write
, s
);
2722 register_ioport_write(0x3b4, 2, 1, vga_ioport_write
, s
);
2723 register_ioport_write(0x3d4, 2, 1, vga_ioport_write
, s
);
2724 register_ioport_write(0x3ba, 1, 1, vga_ioport_write
, s
);
2725 register_ioport_write(0x3da, 1, 1, vga_ioport_write
, s
);
2727 register_ioport_read(0x3c0, 16, 1, vga_ioport_read
, s
);
2729 register_ioport_read(0x3b4, 2, 1, vga_ioport_read
, s
);
2730 register_ioport_read(0x3d4, 2, 1, vga_ioport_read
, s
);
2731 register_ioport_read(0x3ba, 1, 1, vga_ioport_read
, s
);
2732 register_ioport_read(0x3da, 1, 1, vga_ioport_read
, s
);
2734 vga_io_memory
= cpu_register_io_memory(0, cirrus_vga_mem_read
,
2735 cirrus_vga_mem_write
, s
);
2736 cpu_register_physical_memory(isa_mem_base
+ 0x000a0000, 0x20000,
2740 s
->sr
[0x0F] = CIRRUS_MEMSIZE_2M
;
2741 s
->sr
[0x1F] = 0x22; // MemClock
2743 s
->cr
[0x27] = device_id
;
2745 s
->cirrus_hidden_dac_lockindex
= 5;
2746 s
->cirrus_hidden_dac_data
= 0;
2748 /* I/O handler for LFB */
2749 s
->cirrus_linear_io_addr
=
2750 cpu_register_io_memory(0, cirrus_linear_read
, cirrus_linear_write
,
2752 /* I/O handler for LFB */
2753 s
->cirrus_linear_bitblt_io_addr
=
2754 cpu_register_io_memory(0, cirrus_linear_bitblt_read
, cirrus_linear_bitblt_write
,
2757 /* I/O handler for memory-mapped I/O */
2758 s
->cirrus_mmio_io_addr
=
2759 cpu_register_io_memory(0, cirrus_mmio_read
, cirrus_mmio_write
, s
);
2761 /* XXX: s->vram_size must be a power of two */
2762 s
->cirrus_addr_mask
= s
->vram_size
- 1;
2764 s
->get_bpp
= cirrus_get_bpp
;
2765 s
->get_offsets
= cirrus_get_offsets
;
2766 s
->cursor_invalidate
= cirrus_cursor_invalidate
;
2767 s
->cursor_draw_line
= cirrus_cursor_draw_line
;
2770 /***************************************
2774 ***************************************/
2776 void isa_cirrus_vga_init(DisplayState
*ds
, uint8_t *vga_ram_base
,
2777 unsigned long vga_ram_offset
, int vga_ram_size
)
2781 s
= qemu_mallocz(sizeof(CirrusVGAState
));
2783 vga_common_init((VGAState
*)s
,
2784 ds
, vga_ram_base
, vga_ram_offset
, vga_ram_size
);
2785 cirrus_init_common(s
, CIRRUS_ID_CLGD5430
);
2786 s
->sr
[0x17] = CIRRUS_BUSTYPE_ISA
;
2787 /* XXX ISA-LFB support */
2790 /***************************************
2794 ***************************************/
2796 static void cirrus_pci_lfb_map(PCIDevice
*d
, int region_num
,
2797 uint32_t addr
, uint32_t size
, int type
)
2799 CirrusVGAState
*s
= &((PCICirrusVGAState
*)d
)->cirrus_vga
;
2801 /* XXX: add byte swapping apertures */
2802 cpu_register_physical_memory(addr
, s
->vram_size
,
2803 s
->cirrus_linear_io_addr
);
2804 cpu_register_physical_memory(addr
+ 0x1000000, 0x400000,
2805 s
->cirrus_linear_bitblt_io_addr
);
2808 static void cirrus_pci_mmio_map(PCIDevice
*d
, int region_num
,
2809 uint32_t addr
, uint32_t size
, int type
)
2811 CirrusVGAState
*s
= &((PCICirrusVGAState
*)d
)->cirrus_vga
;
2813 cpu_register_physical_memory(addr
, CIRRUS_PNPMMIO_SIZE
,
2814 s
->cirrus_mmio_io_addr
);
2817 void pci_cirrus_vga_init(DisplayState
*ds
, uint8_t *vga_ram_base
,
2818 unsigned long vga_ram_offset
, int vga_ram_size
)
2820 PCICirrusVGAState
*d
;
2825 device_id
= CIRRUS_ID_CLGD5446
;
2827 /* setup PCI configuration registers */
2828 d
= (PCICirrusVGAState
*)pci_register_device("Cirrus VGA",
2829 sizeof(PCICirrusVGAState
),
2831 pci_conf
= d
->dev
.config
;
2832 pci_conf
[0x00] = (uint8_t) (PCI_VENDOR_CIRRUS
& 0xff);
2833 pci_conf
[0x01] = (uint8_t) (PCI_VENDOR_CIRRUS
>> 8);
2834 pci_conf
[0x02] = (uint8_t) (device_id
& 0xff);
2835 pci_conf
[0x03] = (uint8_t) (device_id
>> 8);
2836 pci_conf
[0x04] = PCI_COMMAND_IOACCESS
| PCI_COMMAND_MEMACCESS
;
2837 pci_conf
[0x0a] = PCI_CLASS_SUB_VGA
;
2838 pci_conf
[0x0b] = PCI_CLASS_BASE_DISPLAY
;
2839 pci_conf
[0x0e] = PCI_CLASS_HEADERTYPE_00h
;
2843 vga_common_init((VGAState
*)s
,
2844 ds
, vga_ram_base
, vga_ram_offset
, vga_ram_size
);
2845 cirrus_init_common(s
, device_id
);
2846 s
->sr
[0x17] = CIRRUS_BUSTYPE_PCI
;
2848 /* setup memory space */
2850 /* memory #1 memory-mapped I/O */
2851 /* XXX: s->vram_size must be a power of two */
2852 pci_register_io_region((PCIDevice
*)d
, 0, 0x2000000,
2853 PCI_ADDRESS_SPACE_MEM_PREFETCH
, cirrus_pci_lfb_map
);
2854 if (device_id
== CIRRUS_ID_CLGD5446
) {
2855 pci_register_io_region((PCIDevice
*)d
, 1, CIRRUS_PNPMMIO_SIZE
,
2856 PCI_ADDRESS_SPACE_MEM
, cirrus_pci_mmio_map
);