cirrus_vga.c 92.7 KB
Newer Older
1
/*
B
bellard 已提交
2
 * QEMU Cirrus CLGD 54xx VGA Emulator.
3
 *
4
 * Copyright (c) 2004 Fabrice Bellard
B
bellard 已提交
5
 * Copyright (c) 2004 Makoto Suzuki (suzu)
6
 *
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
B
bellard 已提交
25 26 27 28
/*
 * Reference: Finn Thogersons' VGADOC4b
 *   available at http://home.worldonline.dk/~finth/
 */
P
Peter Maydell 已提交
29
#include "qemu/osdep.h"
30
#include "qapi/error.h"
31
#include "trace.h"
32 33
#include "hw/hw.h"
#include "hw/pci/pci.h"
34
#include "ui/console.h"
35
#include "ui/pixel_ops.h"
36
#include "vga_int.h"
37
#include "hw/loader.h"
38

39 40
/*
 * TODO:
41
 *    - destination write mask support not complete (bits 5..7)
42 43 44 45
 *    - optimize linear mappings
 *    - optimize bitblt functions
 */

46
//#define DEBUG_CIRRUS
47
//#define DEBUG_BITBLT
48

49 50 51 52 53 54 55 56 57 58 59 60 61
/***************************************
 *
 *  definitions
 *
 ***************************************/

// ID
#define CIRRUS_ID_CLGD5422  (0x23<<2)
#define CIRRUS_ID_CLGD5426  (0x24<<2)
#define CIRRUS_ID_CLGD5424  (0x25<<2)
#define CIRRUS_ID_CLGD5428  (0x26<<2)
#define CIRRUS_ID_CLGD5430  (0x28<<2)
#define CIRRUS_ID_CLGD5434  (0x2A<<2)
62
#define CIRRUS_ID_CLGD5436  (0x2B<<2)
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
#define CIRRUS_ID_CLGD5446  (0x2E<<2)

// sequencer 0x07
#define CIRRUS_SR7_BPP_VGA            0x00
#define CIRRUS_SR7_BPP_SVGA           0x01
#define CIRRUS_SR7_BPP_MASK           0x0e
#define CIRRUS_SR7_BPP_8              0x00
#define CIRRUS_SR7_BPP_16_DOUBLEVCLK  0x02
#define CIRRUS_SR7_BPP_24             0x04
#define CIRRUS_SR7_BPP_16             0x06
#define CIRRUS_SR7_BPP_32             0x08
#define CIRRUS_SR7_ISAADDR_MASK       0xe0

// sequencer 0x0f
#define CIRRUS_MEMSIZE_512k        0x08
#define CIRRUS_MEMSIZE_1M          0x10
#define CIRRUS_MEMSIZE_2M          0x18
#define CIRRUS_MEMFLAGS_BANKSWITCH 0x80	// bank switching is enabled.

// sequencer 0x12
#define CIRRUS_CURSOR_SHOW         0x01
#define CIRRUS_CURSOR_HIDDENPEL    0x02
#define CIRRUS_CURSOR_LARGE        0x04	// 64x64 if set, 32x32 if clear

// sequencer 0x17
#define CIRRUS_BUSTYPE_VLBFAST   0x10
#define CIRRUS_BUSTYPE_PCI       0x20
#define CIRRUS_BUSTYPE_VLBSLOW   0x30
#define CIRRUS_BUSTYPE_ISA       0x38
#define CIRRUS_MMIO_ENABLE       0x04
#define CIRRUS_MMIO_USE_PCIADDR  0x40	// 0xb8000 if cleared.
#define CIRRUS_MEMSIZEEXT_DOUBLE 0x80

// control 0x0b
#define CIRRUS_BANKING_DUAL             0x01
#define CIRRUS_BANKING_GRANULARITY_16K  0x20	// set:16k, clear:4k

// control 0x30
#define CIRRUS_BLTMODE_BACKWARDS        0x01
#define CIRRUS_BLTMODE_MEMSYSDEST       0x02
#define CIRRUS_BLTMODE_MEMSYSSRC        0x04
#define CIRRUS_BLTMODE_TRANSPARENTCOMP  0x08
#define CIRRUS_BLTMODE_PATTERNCOPY      0x40
#define CIRRUS_BLTMODE_COLOREXPAND      0x80
#define CIRRUS_BLTMODE_PIXELWIDTHMASK   0x30
#define CIRRUS_BLTMODE_PIXELWIDTH8      0x00
#define CIRRUS_BLTMODE_PIXELWIDTH16     0x10
#define CIRRUS_BLTMODE_PIXELWIDTH24     0x20
#define CIRRUS_BLTMODE_PIXELWIDTH32     0x30

// control 0x31
#define CIRRUS_BLT_BUSY                 0x01
#define CIRRUS_BLT_START                0x02
#define CIRRUS_BLT_RESET                0x04
#define CIRRUS_BLT_FIFOUSED             0x10
118
#define CIRRUS_BLT_AUTOSTART            0x80
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137

// control 0x32
#define CIRRUS_ROP_0                    0x00
#define CIRRUS_ROP_SRC_AND_DST          0x05
#define CIRRUS_ROP_NOP                  0x06
#define CIRRUS_ROP_SRC_AND_NOTDST       0x09
#define CIRRUS_ROP_NOTDST               0x0b
#define CIRRUS_ROP_SRC                  0x0d
#define CIRRUS_ROP_1                    0x0e
#define CIRRUS_ROP_NOTSRC_AND_DST       0x50
#define CIRRUS_ROP_SRC_XOR_DST          0x59
#define CIRRUS_ROP_SRC_OR_DST           0x6d
#define CIRRUS_ROP_NOTSRC_OR_NOTDST     0x90
#define CIRRUS_ROP_SRC_NOTXOR_DST       0x95
#define CIRRUS_ROP_SRC_OR_NOTDST        0xad
#define CIRRUS_ROP_NOTSRC               0xd0
#define CIRRUS_ROP_NOTSRC_OR_DST        0xd6
#define CIRRUS_ROP_NOTSRC_AND_NOTDST    0xda

138 139 140
#define CIRRUS_ROP_NOP_INDEX 2
#define CIRRUS_ROP_SRC_INDEX 5

141
// control 0x33
142
#define CIRRUS_BLTMODEEXT_SOLIDFILL        0x04
B
bellard 已提交
143
#define CIRRUS_BLTMODEEXT_COLOREXPINV      0x02
144
#define CIRRUS_BLTMODEEXT_DWORDGRANULARITY 0x01
145

146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
// memory-mapped IO
#define CIRRUS_MMIO_BLTBGCOLOR        0x00	// dword
#define CIRRUS_MMIO_BLTFGCOLOR        0x04	// dword
#define CIRRUS_MMIO_BLTWIDTH          0x08	// word
#define CIRRUS_MMIO_BLTHEIGHT         0x0a	// word
#define CIRRUS_MMIO_BLTDESTPITCH      0x0c	// word
#define CIRRUS_MMIO_BLTSRCPITCH       0x0e	// word
#define CIRRUS_MMIO_BLTDESTADDR       0x10	// dword
#define CIRRUS_MMIO_BLTSRCADDR        0x14	// dword
#define CIRRUS_MMIO_BLTWRITEMASK      0x17	// byte
#define CIRRUS_MMIO_BLTMODE           0x18	// byte
#define CIRRUS_MMIO_BLTROP            0x1a	// byte
#define CIRRUS_MMIO_BLTMODEEXT        0x1b	// byte
#define CIRRUS_MMIO_BLTTRANSPARENTCOLOR 0x1c	// word?
#define CIRRUS_MMIO_BLTTRANSPARENTCOLORMASK 0x20	// word?
#define CIRRUS_MMIO_LINEARDRAW_START_X 0x24	// word
#define CIRRUS_MMIO_LINEARDRAW_START_Y 0x26	// word
#define CIRRUS_MMIO_LINEARDRAW_END_X  0x28	// word
#define CIRRUS_MMIO_LINEARDRAW_END_Y  0x2a	// word
#define CIRRUS_MMIO_LINEARDRAW_LINESTYLE_INC 0x2c	// byte
#define CIRRUS_MMIO_LINEARDRAW_LINESTYLE_ROLLOVER 0x2d	// byte
#define CIRRUS_MMIO_LINEARDRAW_LINESTYLE_MASK 0x2e	// byte
#define CIRRUS_MMIO_LINEARDRAW_LINESTYLE_ACCUM 0x2f	// byte
#define CIRRUS_MMIO_BRESENHAM_K1      0x30	// word
#define CIRRUS_MMIO_BRESENHAM_K3      0x32	// word
#define CIRRUS_MMIO_BRESENHAM_ERROR   0x34	// word
#define CIRRUS_MMIO_BRESENHAM_DELTA_MAJOR 0x36	// word
#define CIRRUS_MMIO_BRESENHAM_DIRECTION 0x38	// byte
#define CIRRUS_MMIO_LINEDRAW_MODE     0x39	// byte
#define CIRRUS_MMIO_BLTSTATUS         0x40	// byte

177
#define CIRRUS_PNPMMIO_SIZE         0x1000
178

179 180 181
struct CirrusVGAState;
typedef void (*cirrus_bitblt_rop_t) (struct CirrusVGAState *s,
                                     uint8_t * dst, const uint8_t * src,
182 183
				     int dstpitch, int srcpitch,
				     int bltwidth, int bltheight);
184 185
typedef void (*cirrus_fill_t)(struct CirrusVGAState *s,
                              uint8_t *dst, int dst_pitch, int width, int height);
186 187

typedef struct CirrusVGAState {
188
    VGACommonState vga;
189

190
    MemoryRegion cirrus_vga_io;
191 192 193 194 195 196 197
    MemoryRegion cirrus_linear_io;
    MemoryRegion cirrus_linear_bitblt_io;
    MemoryRegion cirrus_mmio_io;
    MemoryRegion pci_bar;
    bool linear_vram;  /* vga.vram mapped over cirrus_linear_io */
    MemoryRegion low_mem_container; /* container for 0xa0000-0xc0000 */
    MemoryRegion low_mem;           /* always mapped, overridden by: */
198
    MemoryRegion cirrus_bank[2];    /*   aliases at 0xa0000-0xb0000  */
199
    uint32_t cirrus_addr_mask;
200
    uint32_t linear_mmio_mask;
201 202 203 204 205 206 207 208 209 210 211 212
    uint8_t cirrus_shadow_gr0;
    uint8_t cirrus_shadow_gr1;
    uint8_t cirrus_hidden_dac_lockindex;
    uint8_t cirrus_hidden_dac_data;
    uint32_t cirrus_bank_base[2];
    uint32_t cirrus_bank_limit[2];
    uint8_t cirrus_hidden_palette[48];
    int cirrus_blt_pixelwidth;
    int cirrus_blt_width;
    int cirrus_blt_height;
    int cirrus_blt_dstpitch;
    int cirrus_blt_srcpitch;
213 214
    uint32_t cirrus_blt_fgcol;
    uint32_t cirrus_blt_bgcol;
215 216 217
    uint32_t cirrus_blt_dstaddr;
    uint32_t cirrus_blt_srcaddr;
    uint8_t cirrus_blt_mode;
218
    uint8_t cirrus_blt_modeext;
219
    cirrus_bitblt_rop_t cirrus_rop;
220
#define CIRRUS_BLTBUFSIZE (2048 * 4) /* one line width */
221 222 223 224
    uint8_t cirrus_bltbuf[CIRRUS_BLTBUFSIZE];
    uint8_t *cirrus_srcptr;
    uint8_t *cirrus_srcptr_end;
    uint32_t cirrus_srccounter;
225 226 227 228 229 230
    /* hwcursor display state */
    int last_hw_cursor_size;
    int last_hw_cursor_x;
    int last_hw_cursor_y;
    int last_hw_cursor_y_start;
    int last_hw_cursor_y_end;
231
    int real_vram_size; /* XXX: suppress that */
B
blueswir1 已提交
232 233
    int device_id;
    int bustype;
234 235 236 237 238 239 240
} CirrusVGAState;

typedef struct PCICirrusVGAState {
    PCIDevice dev;
    CirrusVGAState cirrus_vga;
} PCICirrusVGAState;

G
Gonglei 已提交
241 242 243 244
#define TYPE_PCI_CIRRUS_VGA "cirrus-vga"
#define PCI_CIRRUS_VGA(obj) \
    OBJECT_CHECK(PCICirrusVGAState, (obj), TYPE_PCI_CIRRUS_VGA)

245 246 247 248
#define TYPE_ISA_CIRRUS_VGA "isa-cirrus-vga"
#define ISA_CIRRUS_VGA(obj) \
    OBJECT_CHECK(ISACirrusVGAState, (obj), TYPE_ISA_CIRRUS_VGA)

249
typedef struct ISACirrusVGAState {
250 251
    ISADevice parent_obj;

252 253 254
    CirrusVGAState cirrus_vga;
} ISACirrusVGAState;

255
static uint8_t rop_to_index[256];
256

257 258 259 260 261 262 263
/***************************************
 *
 *  prototypes.
 *
 ***************************************/


B
bellard 已提交
264 265
static void cirrus_bitblt_reset(CirrusVGAState *s);
static void cirrus_update_memory_access(CirrusVGAState *s);
266 267 268 269 270 271 272

/***************************************
 *
 *  raster operations
 *
 ***************************************/

G
Gerd Hoffmann 已提交
273 274 275 276 277
static bool blit_region_is_unsafe(struct CirrusVGAState *s,
                                  int32_t pitch, int32_t addr)
{
    if (pitch < 0) {
        int64_t min = addr
278 279 280
            + ((int64_t)s->cirrus_blt_height - 1) * pitch
            - s->cirrus_blt_width;
        if (min < -1 || addr >= s->vga.vram_size) {
G
Gerd Hoffmann 已提交
281 282 283 284 285 286
            return true;
        }
    } else {
        int64_t max = addr
            + ((int64_t)s->cirrus_blt_height-1) * pitch
            + s->cirrus_blt_width;
287
        if (max > s->vga.vram_size) {
G
Gerd Hoffmann 已提交
288 289 290 291 292 293
            return true;
        }
    }
    return false;
}

294 295
static bool blit_is_unsafe(struct CirrusVGAState *s, bool dst_only,
                           bool zero_src_pitch_ok)
G
Gerd Hoffmann 已提交
296
{
297 298
    int32_t check_pitch;

G
Gerd Hoffmann 已提交
299 300 301 302
    /* should be the case, see cirrus_bitblt_start */
    assert(s->cirrus_blt_width > 0);
    assert(s->cirrus_blt_height > 0);

303 304 305 306
    if (s->cirrus_blt_width > CIRRUS_BLTBUFSIZE) {
        return true;
    }

307 308 309 310
    if (!s->cirrus_blt_dstpitch) {
        return true;
    }

G
Gerd Hoffmann 已提交
311
    if (blit_region_is_unsafe(s, s->cirrus_blt_dstpitch,
312
                              s->cirrus_blt_dstaddr)) {
G
Gerd Hoffmann 已提交
313 314
        return true;
    }
315 316 317
    if (dst_only) {
        return false;
    }
318 319 320 321 322 323 324

    check_pitch = s->cirrus_blt_srcpitch;
    if (!zero_src_pitch_ok && !check_pitch) {
        check_pitch = s->cirrus_blt_width;
    }

    if (blit_region_is_unsafe(s, check_pitch,
325
                              s->cirrus_blt_srcaddr)) {
G
Gerd Hoffmann 已提交
326 327 328 329 330 331
        return true;
    }

    return false;
}

332 333 334 335 336
static void cirrus_bitblt_rop_nop(CirrusVGAState *s,
                                  uint8_t *dst,const uint8_t *src,
                                  int dstpitch,int srcpitch,
                                  int bltwidth,int bltheight)
{
337 338
}

339 340 341
static void cirrus_bitblt_fill_nop(CirrusVGAState *s,
                                   uint8_t *dst,
                                   int dstpitch, int bltwidth,int bltheight)
342
{
343
}
344

345
#define ROP_NAME 0
B
Blue Swirl 已提交
346
#define ROP_FN(d, s) 0
347
#include "cirrus_vga_rop.h"
348

349
#define ROP_NAME src_and_dst
B
Blue Swirl 已提交
350
#define ROP_FN(d, s) (s) & (d)
351
#include "cirrus_vga_rop.h"
352

353
#define ROP_NAME src_and_notdst
B
Blue Swirl 已提交
354
#define ROP_FN(d, s) (s) & (~(d))
355
#include "cirrus_vga_rop.h"
356

357
#define ROP_NAME notdst
B
Blue Swirl 已提交
358
#define ROP_FN(d, s) ~(d)
359
#include "cirrus_vga_rop.h"
360

361
#define ROP_NAME src
B
Blue Swirl 已提交
362
#define ROP_FN(d, s) s
363
#include "cirrus_vga_rop.h"
364

365
#define ROP_NAME 1
B
Blue Swirl 已提交
366
#define ROP_FN(d, s) ~0
367
#include "cirrus_vga_rop.h"
368 369

#define ROP_NAME notsrc_and_dst
B
Blue Swirl 已提交
370
#define ROP_FN(d, s) (~(s)) & (d)
371
#include "cirrus_vga_rop.h"
372 373

#define ROP_NAME src_xor_dst
B
Blue Swirl 已提交
374
#define ROP_FN(d, s) (s) ^ (d)
375
#include "cirrus_vga_rop.h"
376 377

#define ROP_NAME src_or_dst
B
Blue Swirl 已提交
378
#define ROP_FN(d, s) (s) | (d)
379
#include "cirrus_vga_rop.h"
380 381

#define ROP_NAME notsrc_or_notdst
B
Blue Swirl 已提交
382
#define ROP_FN(d, s) (~(s)) | (~(d))
383
#include "cirrus_vga_rop.h"
384 385

#define ROP_NAME src_notxor_dst
B
Blue Swirl 已提交
386
#define ROP_FN(d, s) ~((s) ^ (d))
387
#include "cirrus_vga_rop.h"
388

389
#define ROP_NAME src_or_notdst
B
Blue Swirl 已提交
390
#define ROP_FN(d, s) (s) | (~(d))
391
#include "cirrus_vga_rop.h"
392 393

#define ROP_NAME notsrc
B
Blue Swirl 已提交
394
#define ROP_FN(d, s) (~(s))
395
#include "cirrus_vga_rop.h"
396 397

#define ROP_NAME notsrc_or_dst
B
Blue Swirl 已提交
398
#define ROP_FN(d, s) (~(s)) | (d)
399
#include "cirrus_vga_rop.h"
400 401

#define ROP_NAME notsrc_and_notdst
B
Blue Swirl 已提交
402
#define ROP_FN(d, s) (~(s)) & (~(d))
403
#include "cirrus_vga_rop.h"
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441

static const cirrus_bitblt_rop_t cirrus_fwd_rop[16] = {
    cirrus_bitblt_rop_fwd_0,
    cirrus_bitblt_rop_fwd_src_and_dst,
    cirrus_bitblt_rop_nop,
    cirrus_bitblt_rop_fwd_src_and_notdst,
    cirrus_bitblt_rop_fwd_notdst,
    cirrus_bitblt_rop_fwd_src,
    cirrus_bitblt_rop_fwd_1,
    cirrus_bitblt_rop_fwd_notsrc_and_dst,
    cirrus_bitblt_rop_fwd_src_xor_dst,
    cirrus_bitblt_rop_fwd_src_or_dst,
    cirrus_bitblt_rop_fwd_notsrc_or_notdst,
    cirrus_bitblt_rop_fwd_src_notxor_dst,
    cirrus_bitblt_rop_fwd_src_or_notdst,
    cirrus_bitblt_rop_fwd_notsrc,
    cirrus_bitblt_rop_fwd_notsrc_or_dst,
    cirrus_bitblt_rop_fwd_notsrc_and_notdst,
};

static const cirrus_bitblt_rop_t cirrus_bkwd_rop[16] = {
    cirrus_bitblt_rop_bkwd_0,
    cirrus_bitblt_rop_bkwd_src_and_dst,
    cirrus_bitblt_rop_nop,
    cirrus_bitblt_rop_bkwd_src_and_notdst,
    cirrus_bitblt_rop_bkwd_notdst,
    cirrus_bitblt_rop_bkwd_src,
    cirrus_bitblt_rop_bkwd_1,
    cirrus_bitblt_rop_bkwd_notsrc_and_dst,
    cirrus_bitblt_rop_bkwd_src_xor_dst,
    cirrus_bitblt_rop_bkwd_src_or_dst,
    cirrus_bitblt_rop_bkwd_notsrc_or_notdst,
    cirrus_bitblt_rop_bkwd_src_notxor_dst,
    cirrus_bitblt_rop_bkwd_src_or_notdst,
    cirrus_bitblt_rop_bkwd_notsrc,
    cirrus_bitblt_rop_bkwd_notsrc_or_dst,
    cirrus_bitblt_rop_bkwd_notsrc_and_notdst,
};
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489

#define TRANSP_ROP(name) {\
    name ## _8,\
    name ## _16,\
        }
#define TRANSP_NOP(func) {\
    func,\
    func,\
        }

static const cirrus_bitblt_rop_t cirrus_fwd_transp_rop[16][2] = {
    TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_0),
    TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_src_and_dst),
    TRANSP_NOP(cirrus_bitblt_rop_nop),
    TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_src_and_notdst),
    TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_notdst),
    TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_src),
    TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_1),
    TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_notsrc_and_dst),
    TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_src_xor_dst),
    TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_src_or_dst),
    TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_notsrc_or_notdst),
    TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_src_notxor_dst),
    TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_src_or_notdst),
    TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_notsrc),
    TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_notsrc_or_dst),
    TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_notsrc_and_notdst),
};

static const cirrus_bitblt_rop_t cirrus_bkwd_transp_rop[16][2] = {
    TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_0),
    TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_src_and_dst),
    TRANSP_NOP(cirrus_bitblt_rop_nop),
    TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_src_and_notdst),
    TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_notdst),
    TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_src),
    TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_1),
    TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_notsrc_and_dst),
    TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_src_xor_dst),
    TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_src_or_dst),
    TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_notsrc_or_notdst),
    TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_src_notxor_dst),
    TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_src_or_notdst),
    TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_notsrc),
    TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_notsrc_or_dst),
    TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_notsrc_and_notdst),
};

490 491 492 493 494 495 496 497 498 499 500 501 502 503
#define ROP2(name) {\
    name ## _8,\
    name ## _16,\
    name ## _24,\
    name ## _32,\
        }

#define ROP_NOP2(func) {\
    func,\
    func,\
    func,\
    func,\
        }

B
bellard 已提交
504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522
static const cirrus_bitblt_rop_t cirrus_patternfill[16][4] = {
    ROP2(cirrus_patternfill_0),
    ROP2(cirrus_patternfill_src_and_dst),
    ROP_NOP2(cirrus_bitblt_rop_nop),
    ROP2(cirrus_patternfill_src_and_notdst),
    ROP2(cirrus_patternfill_notdst),
    ROP2(cirrus_patternfill_src),
    ROP2(cirrus_patternfill_1),
    ROP2(cirrus_patternfill_notsrc_and_dst),
    ROP2(cirrus_patternfill_src_xor_dst),
    ROP2(cirrus_patternfill_src_or_dst),
    ROP2(cirrus_patternfill_notsrc_or_notdst),
    ROP2(cirrus_patternfill_src_notxor_dst),
    ROP2(cirrus_patternfill_src_or_notdst),
    ROP2(cirrus_patternfill_notsrc),
    ROP2(cirrus_patternfill_notsrc_or_dst),
    ROP2(cirrus_patternfill_notsrc_and_notdst),
};

523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560
static const cirrus_bitblt_rop_t cirrus_colorexpand_transp[16][4] = {
    ROP2(cirrus_colorexpand_transp_0),
    ROP2(cirrus_colorexpand_transp_src_and_dst),
    ROP_NOP2(cirrus_bitblt_rop_nop),
    ROP2(cirrus_colorexpand_transp_src_and_notdst),
    ROP2(cirrus_colorexpand_transp_notdst),
    ROP2(cirrus_colorexpand_transp_src),
    ROP2(cirrus_colorexpand_transp_1),
    ROP2(cirrus_colorexpand_transp_notsrc_and_dst),
    ROP2(cirrus_colorexpand_transp_src_xor_dst),
    ROP2(cirrus_colorexpand_transp_src_or_dst),
    ROP2(cirrus_colorexpand_transp_notsrc_or_notdst),
    ROP2(cirrus_colorexpand_transp_src_notxor_dst),
    ROP2(cirrus_colorexpand_transp_src_or_notdst),
    ROP2(cirrus_colorexpand_transp_notsrc),
    ROP2(cirrus_colorexpand_transp_notsrc_or_dst),
    ROP2(cirrus_colorexpand_transp_notsrc_and_notdst),
};

static const cirrus_bitblt_rop_t cirrus_colorexpand[16][4] = {
    ROP2(cirrus_colorexpand_0),
    ROP2(cirrus_colorexpand_src_and_dst),
    ROP_NOP2(cirrus_bitblt_rop_nop),
    ROP2(cirrus_colorexpand_src_and_notdst),
    ROP2(cirrus_colorexpand_notdst),
    ROP2(cirrus_colorexpand_src),
    ROP2(cirrus_colorexpand_1),
    ROP2(cirrus_colorexpand_notsrc_and_dst),
    ROP2(cirrus_colorexpand_src_xor_dst),
    ROP2(cirrus_colorexpand_src_or_dst),
    ROP2(cirrus_colorexpand_notsrc_or_notdst),
    ROP2(cirrus_colorexpand_src_notxor_dst),
    ROP2(cirrus_colorexpand_src_or_notdst),
    ROP2(cirrus_colorexpand_notsrc),
    ROP2(cirrus_colorexpand_notsrc_or_dst),
    ROP2(cirrus_colorexpand_notsrc_and_notdst),
};

B
bellard 已提交
561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598
static const cirrus_bitblt_rop_t cirrus_colorexpand_pattern_transp[16][4] = {
    ROP2(cirrus_colorexpand_pattern_transp_0),
    ROP2(cirrus_colorexpand_pattern_transp_src_and_dst),
    ROP_NOP2(cirrus_bitblt_rop_nop),
    ROP2(cirrus_colorexpand_pattern_transp_src_and_notdst),
    ROP2(cirrus_colorexpand_pattern_transp_notdst),
    ROP2(cirrus_colorexpand_pattern_transp_src),
    ROP2(cirrus_colorexpand_pattern_transp_1),
    ROP2(cirrus_colorexpand_pattern_transp_notsrc_and_dst),
    ROP2(cirrus_colorexpand_pattern_transp_src_xor_dst),
    ROP2(cirrus_colorexpand_pattern_transp_src_or_dst),
    ROP2(cirrus_colorexpand_pattern_transp_notsrc_or_notdst),
    ROP2(cirrus_colorexpand_pattern_transp_src_notxor_dst),
    ROP2(cirrus_colorexpand_pattern_transp_src_or_notdst),
    ROP2(cirrus_colorexpand_pattern_transp_notsrc),
    ROP2(cirrus_colorexpand_pattern_transp_notsrc_or_dst),
    ROP2(cirrus_colorexpand_pattern_transp_notsrc_and_notdst),
};

static const cirrus_bitblt_rop_t cirrus_colorexpand_pattern[16][4] = {
    ROP2(cirrus_colorexpand_pattern_0),
    ROP2(cirrus_colorexpand_pattern_src_and_dst),
    ROP_NOP2(cirrus_bitblt_rop_nop),
    ROP2(cirrus_colorexpand_pattern_src_and_notdst),
    ROP2(cirrus_colorexpand_pattern_notdst),
    ROP2(cirrus_colorexpand_pattern_src),
    ROP2(cirrus_colorexpand_pattern_1),
    ROP2(cirrus_colorexpand_pattern_notsrc_and_dst),
    ROP2(cirrus_colorexpand_pattern_src_xor_dst),
    ROP2(cirrus_colorexpand_pattern_src_or_dst),
    ROP2(cirrus_colorexpand_pattern_notsrc_or_notdst),
    ROP2(cirrus_colorexpand_pattern_src_notxor_dst),
    ROP2(cirrus_colorexpand_pattern_src_or_notdst),
    ROP2(cirrus_colorexpand_pattern_notsrc),
    ROP2(cirrus_colorexpand_pattern_notsrc_or_dst),
    ROP2(cirrus_colorexpand_pattern_notsrc_and_notdst),
};

599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618
static const cirrus_fill_t cirrus_fill[16][4] = {
    ROP2(cirrus_fill_0),
    ROP2(cirrus_fill_src_and_dst),
    ROP_NOP2(cirrus_bitblt_fill_nop),
    ROP2(cirrus_fill_src_and_notdst),
    ROP2(cirrus_fill_notdst),
    ROP2(cirrus_fill_src),
    ROP2(cirrus_fill_1),
    ROP2(cirrus_fill_notsrc_and_dst),
    ROP2(cirrus_fill_src_xor_dst),
    ROP2(cirrus_fill_src_or_dst),
    ROP2(cirrus_fill_notsrc_or_notdst),
    ROP2(cirrus_fill_src_notxor_dst),
    ROP2(cirrus_fill_src_or_notdst),
    ROP2(cirrus_fill_notsrc),
    ROP2(cirrus_fill_notsrc_or_dst),
    ROP2(cirrus_fill_notsrc_and_notdst),
};

static inline void cirrus_bitblt_fgcol(CirrusVGAState *s)
619
{
620 621 622 623 624 625
    unsigned int color;
    switch (s->cirrus_blt_pixelwidth) {
    case 1:
        s->cirrus_blt_fgcol = s->cirrus_shadow_gr1;
        break;
    case 2:
626
        color = s->cirrus_shadow_gr1 | (s->vga.gr[0x11] << 8);
627 628 629
        s->cirrus_blt_fgcol = le16_to_cpu(color);
        break;
    case 3:
630
        s->cirrus_blt_fgcol = s->cirrus_shadow_gr1 |
631
            (s->vga.gr[0x11] << 8) | (s->vga.gr[0x13] << 16);
632 633 634
        break;
    default:
    case 4:
635 636
        color = s->cirrus_shadow_gr1 | (s->vga.gr[0x11] << 8) |
            (s->vga.gr[0x13] << 16) | (s->vga.gr[0x15] << 24);
637 638
        s->cirrus_blt_fgcol = le32_to_cpu(color);
        break;
639 640 641
    }
}

642
static inline void cirrus_bitblt_bgcol(CirrusVGAState *s)
643
{
644
    unsigned int color;
645 646
    switch (s->cirrus_blt_pixelwidth) {
    case 1:
647 648
        s->cirrus_blt_bgcol = s->cirrus_shadow_gr0;
        break;
649
    case 2:
650
        color = s->cirrus_shadow_gr0 | (s->vga.gr[0x10] << 8);
651 652
        s->cirrus_blt_bgcol = le16_to_cpu(color);
        break;
653
    case 3:
654
        s->cirrus_blt_bgcol = s->cirrus_shadow_gr0 |
655
            (s->vga.gr[0x10] << 8) | (s->vga.gr[0x12] << 16);
656
        break;
657
    default:
658
    case 4:
659 660
        color = s->cirrus_shadow_gr0 | (s->vga.gr[0x10] << 8) |
            (s->vga.gr[0x12] << 16) | (s->vga.gr[0x14] << 24);
661 662
        s->cirrus_blt_bgcol = le32_to_cpu(color);
        break;
663 664 665 666 667 668 669 670 671 672 673
    }
}

static void cirrus_invalidate_region(CirrusVGAState * s, int off_begin,
				     int off_pitch, int bytesperline,
				     int lines)
{
    int y;
    int off_cur;
    int off_cur_end;

674 675 676 677
    if (off_pitch < 0) {
        off_begin -= bytesperline - 1;
    }

678 679
    for (y = 0; y < lines; y++) {
	off_cur = off_begin;
680
	off_cur_end = (off_cur + bytesperline) & s->cirrus_addr_mask;
681
        assert(off_cur_end >= off_cur);
682
        memory_region_set_dirty(&s->vga.vram, off_cur, off_cur_end - off_cur);
683 684 685 686
	off_begin += off_pitch;
    }
}

G
Gerd Hoffmann 已提交
687
static int cirrus_bitblt_common_patterncopy(CirrusVGAState *s, bool videosrc)
688
{
G
Gerd Hoffmann 已提交
689
    uint32_t patternsize;
690
    uint8_t *dst;
G
Gerd Hoffmann 已提交
691
    uint8_t *src;
692

693
    dst = s->vga.vram_ptr + s->cirrus_blt_dstaddr;
694

G
Gerd Hoffmann 已提交
695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719
    if (videosrc) {
        switch (s->vga.get_bpp(&s->vga)) {
        case 8:
            patternsize = 64;
            break;
        case 15:
        case 16:
            patternsize = 128;
            break;
        case 24:
        case 32:
        default:
            patternsize = 256;
            break;
        }
        s->cirrus_blt_srcaddr &= ~(patternsize - 1);
        if (s->cirrus_blt_srcaddr + patternsize > s->vga.vram_size) {
            return 0;
        }
        src = s->vga.vram_ptr + s->cirrus_blt_srcaddr;
    } else {
        src = s->cirrus_bltbuf;
    }

    if (blit_is_unsafe(s, true, true)) {
720
        return 0;
721
    }
722

B
bellard 已提交
723
    (*s->cirrus_rop) (s, dst, src,
724
                      s->cirrus_blt_dstpitch, 0,
B
bellard 已提交
725
                      s->cirrus_blt_width, s->cirrus_blt_height);
726
    cirrus_invalidate_region(s, s->cirrus_blt_dstaddr,
B
bellard 已提交
727 728
                             s->cirrus_blt_dstpitch, s->cirrus_blt_width,
                             s->cirrus_blt_height);
729 730 731
    return 1;
}

732 733
/* fill */

734
static int cirrus_bitblt_solidfill(CirrusVGAState *s, int blt_rop)
735
{
736
    cirrus_fill_t rop_func;
737

738
    if (blit_is_unsafe(s, true, true)) {
739
        return 0;
G
Gerd Hoffmann 已提交
740
    }
741
    rop_func = cirrus_fill[rop_to_index[blt_rop]][s->cirrus_blt_pixelwidth - 1];
742
    rop_func(s, s->vga.vram_ptr + s->cirrus_blt_dstaddr,
743 744
             s->cirrus_blt_dstpitch,
             s->cirrus_blt_width, s->cirrus_blt_height);
745 746 747 748 749 750 751
    cirrus_invalidate_region(s, s->cirrus_blt_dstaddr,
			     s->cirrus_blt_dstpitch, s->cirrus_blt_width,
			     s->cirrus_blt_height);
    cirrus_bitblt_reset(s);
    return 1;
}

752 753 754 755 756 757 758 759
/***************************************
 *
 *  bitblt (video-to-video)
 *
 ***************************************/

static int cirrus_bitblt_videotovideo_patterncopy(CirrusVGAState * s)
{
G
Gerd Hoffmann 已提交
760
    return cirrus_bitblt_common_patterncopy(s, true);
761 762
}

763
static int cirrus_do_copy(CirrusVGAState *s, int dst, int src, int w, int h)
764
{
A
Aurelien Jarno 已提交
765 766 767
    int sx = 0, sy = 0;
    int dx = 0, dy = 0;
    int depth = 0;
B
bellard 已提交
768 769
    int notify = 0;

770 771 772
    /* make sure to only copy if it's a plain copy ROP */
    if (*s->cirrus_rop == cirrus_bitblt_rop_fwd_src ||
        *s->cirrus_rop == cirrus_bitblt_rop_bkwd_src) {
B
bellard 已提交
773

774 775 776
        int width, height;

        depth = s->vga.get_bpp(&s->vga) / 8;
777 778 779
        if (!depth) {
            return 0;
        }
780 781 782 783 784 785 786
        s->vga.get_resolution(&s->vga, &width, &height);

        /* extra x, y */
        sx = (src % ABS(s->cirrus_blt_srcpitch)) / depth;
        sy = (src / ABS(s->cirrus_blt_srcpitch));
        dx = (dst % ABS(s->cirrus_blt_dstpitch)) / depth;
        dy = (dst / ABS(s->cirrus_blt_dstpitch));
B
bellard 已提交
787

788 789
        /* normalize width */
        w /= depth;
B
bellard 已提交
790

791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807
        /* if we're doing a backward copy, we have to adjust
           our x/y to be the upper left corner (instead of the lower
           right corner) */
        if (s->cirrus_blt_dstpitch < 0) {
            sx -= (s->cirrus_blt_width / depth) - 1;
            dx -= (s->cirrus_blt_width / depth) - 1;
            sy -= s->cirrus_blt_height - 1;
            dy -= s->cirrus_blt_height - 1;
        }

        /* are we in the visible portion of memory? */
        if (sx >= 0 && sy >= 0 && dx >= 0 && dy >= 0 &&
            (sx + w) <= width && (sy + h) <= height &&
            (dx + w) <= width && (dy + h) <= height) {
            notify = 1;
        }
    }
B
bellard 已提交
808 809 810 811

    /* we have to flush all pending changes so that the copy
       is generated at the appropriate moment in time */
    if (notify)
812
        graphic_hw_update(s->vga.con);
B
bellard 已提交
813

814 815
    (*s->cirrus_rop) (s, s->vga.vram_ptr + s->cirrus_blt_dstaddr,
                      s->vga.vram_ptr + s->cirrus_blt_srcaddr,
816 817
		      s->cirrus_blt_dstpitch, s->cirrus_blt_srcpitch,
		      s->cirrus_blt_width, s->cirrus_blt_height);
B
bellard 已提交
818

819 820
    if (notify) {
        qemu_console_copy(s->vga.con,
821 822 823
			  sx, sy, dx, dy,
			  s->cirrus_blt_width / depth,
			  s->cirrus_blt_height);
824
    }
B
bellard 已提交
825 826

    /* we don't have to notify the display that this portion has
827
       changed since qemu_console_copy implies this */
B
bellard 已提交
828

829 830 831
    cirrus_invalidate_region(s, s->cirrus_blt_dstaddr,
				s->cirrus_blt_dstpitch, s->cirrus_blt_width,
				s->cirrus_blt_height);
832 833

    return 1;
B
bellard 已提交
834 835 836 837
}

static int cirrus_bitblt_videotovideo_copy(CirrusVGAState * s)
{
838
    if (blit_is_unsafe(s, false, false))
839 840
        return 0;

841
    return cirrus_do_copy(s, s->cirrus_blt_dstaddr - s->vga.start_addr,
842
            s->cirrus_blt_srcaddr - s->vga.start_addr,
843
            s->cirrus_blt_width, s->cirrus_blt_height);
844 845 846 847 848 849 850 851 852 853 854
}

/***************************************
 *
 *  bitblt (cpu-to-video)
 *
 ***************************************/

static void cirrus_bitblt_cputovideo_next(CirrusVGAState * s)
{
    int copy_count;
855
    uint8_t *end_ptr;
856

857
    if (s->cirrus_srccounter > 0) {
858
        if (s->cirrus_blt_mode & CIRRUS_BLTMODE_PATTERNCOPY) {
G
Gerd Hoffmann 已提交
859
            cirrus_bitblt_common_patterncopy(s, false);
860 861 862 863 864 865
        the_end:
            s->cirrus_srccounter = 0;
            cirrus_bitblt_reset(s);
        } else {
            /* at least one scan line */
            do {
866
                (*s->cirrus_rop)(s, s->vga.vram_ptr + s->cirrus_blt_dstaddr,
867
                                  s->cirrus_bltbuf, 0, 0, s->cirrus_blt_width, 1);
868 869 870 871 872 873
                cirrus_invalidate_region(s, s->cirrus_blt_dstaddr, 0,
                                         s->cirrus_blt_width, 1);
                s->cirrus_blt_dstaddr += s->cirrus_blt_dstpitch;
                s->cirrus_srccounter -= s->cirrus_blt_srcpitch;
                if (s->cirrus_srccounter <= 0)
                    goto the_end;
D
Dong Xu Wang 已提交
874
                /* more bytes than needed can be transferred because of
875 876 877 878 879 880 881 882 883
                   word alignment, so we keep them for the next line */
                /* XXX: keep alignment to speed up transfer */
                end_ptr = s->cirrus_bltbuf + s->cirrus_blt_srcpitch;
                copy_count = s->cirrus_srcptr_end - end_ptr;
                memmove(s->cirrus_bltbuf, end_ptr, copy_count);
                s->cirrus_srcptr = s->cirrus_bltbuf + copy_count;
                s->cirrus_srcptr_end = s->cirrus_bltbuf + s->cirrus_blt_srcpitch;
            } while (s->cirrus_srcptr >= s->cirrus_srcptr_end);
        }
884 885 886 887 888 889 890 891 892 893 894
    }
}

/***************************************
 *
 *  bitblt wrapper
 *
 ***************************************/

static void cirrus_bitblt_reset(CirrusVGAState * s)
{
895 896
    int need_update;

897
    s->vga.gr[0x31] &=
898
	~(CIRRUS_BLT_START | CIRRUS_BLT_BUSY | CIRRUS_BLT_FIFOUSED);
899 900
    need_update = s->cirrus_srcptr != &s->cirrus_bltbuf[0]
        || s->cirrus_srcptr_end != &s->cirrus_bltbuf[0];
901 902 903
    s->cirrus_srcptr = &s->cirrus_bltbuf[0];
    s->cirrus_srcptr_end = &s->cirrus_bltbuf[0];
    s->cirrus_srccounter = 0;
904 905
    if (!need_update)
        return;
B
bellard 已提交
906
    cirrus_update_memory_access(s);
907 908 909 910
}

static int cirrus_bitblt_cputovideo(CirrusVGAState * s)
{
911 912
    int w;

913 914 915 916 917 918
    s->cirrus_blt_mode &= ~CIRRUS_BLTMODE_MEMSYSSRC;
    s->cirrus_srcptr = &s->cirrus_bltbuf[0];
    s->cirrus_srcptr_end = &s->cirrus_bltbuf[0];

    if (s->cirrus_blt_mode & CIRRUS_BLTMODE_PATTERNCOPY) {
	if (s->cirrus_blt_mode & CIRRUS_BLTMODE_COLOREXPAND) {
919
	    s->cirrus_blt_srcpitch = 8;
920
	} else {
B
bellard 已提交
921
            /* XXX: check for 24 bpp */
922
	    s->cirrus_blt_srcpitch = 8 * 8 * s->cirrus_blt_pixelwidth;
923
	}
924
	s->cirrus_srccounter = s->cirrus_blt_srcpitch;
925 926
    } else {
	if (s->cirrus_blt_mode & CIRRUS_BLTMODE_COLOREXPAND) {
927
            w = s->cirrus_blt_width / s->cirrus_blt_pixelwidth;
928
            if (s->cirrus_blt_modeext & CIRRUS_BLTMODEEXT_DWORDGRANULARITY)
929 930 931
                s->cirrus_blt_srcpitch = ((w + 31) >> 5);
            else
                s->cirrus_blt_srcpitch = ((w + 7) >> 3);
932
	} else {
B
bellard 已提交
933 934
            /* always align input size to 32 bits */
	    s->cirrus_blt_srcpitch = (s->cirrus_blt_width + 3) & ~3;
935
	}
936
        s->cirrus_srccounter = s->cirrus_blt_srcpitch * s->cirrus_blt_height;
937
    }
938 939
    s->cirrus_srcptr = s->cirrus_bltbuf;
    s->cirrus_srcptr_end = s->cirrus_bltbuf + s->cirrus_blt_srcpitch;
B
bellard 已提交
940
    cirrus_update_memory_access(s);
941 942 943 944 945 946
    return 1;
}

static int cirrus_bitblt_videotocpu(CirrusVGAState * s)
{
    /* XXX */
947
#ifdef DEBUG_BITBLT
948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970
    printf("cirrus: bitblt (video to cpu) is not implemented yet\n");
#endif
    return 0;
}

static int cirrus_bitblt_videotovideo(CirrusVGAState * s)
{
    int ret;

    if (s->cirrus_blt_mode & CIRRUS_BLTMODE_PATTERNCOPY) {
	ret = cirrus_bitblt_videotovideo_patterncopy(s);
    } else {
	ret = cirrus_bitblt_videotovideo_copy(s);
    }
    if (ret)
	cirrus_bitblt_reset(s);
    return ret;
}

static void cirrus_bitblt_start(CirrusVGAState * s)
{
    uint8_t blt_rop;

971
    s->vga.gr[0x31] |= CIRRUS_BLT_BUSY;
972

973 974 975 976
    s->cirrus_blt_width = (s->vga.gr[0x20] | (s->vga.gr[0x21] << 8)) + 1;
    s->cirrus_blt_height = (s->vga.gr[0x22] | (s->vga.gr[0x23] << 8)) + 1;
    s->cirrus_blt_dstpitch = (s->vga.gr[0x24] | (s->vga.gr[0x25] << 8));
    s->cirrus_blt_srcpitch = (s->vga.gr[0x26] | (s->vga.gr[0x27] << 8));
977
    s->cirrus_blt_dstaddr =
978
	(s->vga.gr[0x28] | (s->vga.gr[0x29] << 8) | (s->vga.gr[0x2a] << 16));
979
    s->cirrus_blt_srcaddr =
980 981 982 983
	(s->vga.gr[0x2c] | (s->vga.gr[0x2d] << 8) | (s->vga.gr[0x2e] << 16));
    s->cirrus_blt_mode = s->vga.gr[0x30];
    s->cirrus_blt_modeext = s->vga.gr[0x33];
    blt_rop = s->vga.gr[0x32];
984

985 986 987
    s->cirrus_blt_dstaddr &= s->cirrus_addr_mask;
    s->cirrus_blt_srcaddr &= s->cirrus_addr_mask;

988
#ifdef DEBUG_BITBLT
B
bellard 已提交
989
    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",
990
           blt_rop,
991
           s->cirrus_blt_mode,
992
           s->cirrus_blt_modeext,
993 994 995 996 997
           s->cirrus_blt_width,
           s->cirrus_blt_height,
           s->cirrus_blt_dstpitch,
           s->cirrus_blt_srcpitch,
           s->cirrus_blt_dstaddr,
998
           s->cirrus_blt_srcaddr,
999
           s->vga.gr[0x2f]);
1000 1001
#endif

1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015
    switch (s->cirrus_blt_mode & CIRRUS_BLTMODE_PIXELWIDTHMASK) {
    case CIRRUS_BLTMODE_PIXELWIDTH8:
	s->cirrus_blt_pixelwidth = 1;
	break;
    case CIRRUS_BLTMODE_PIXELWIDTH16:
	s->cirrus_blt_pixelwidth = 2;
	break;
    case CIRRUS_BLTMODE_PIXELWIDTH24:
	s->cirrus_blt_pixelwidth = 3;
	break;
    case CIRRUS_BLTMODE_PIXELWIDTH32:
	s->cirrus_blt_pixelwidth = 4;
	break;
    default:
1016
#ifdef DEBUG_BITBLT
1017 1018 1019 1020 1021 1022 1023 1024 1025 1026
	printf("cirrus: bitblt - pixel width is unknown\n");
#endif
	goto bitblt_ignore;
    }
    s->cirrus_blt_mode &= ~CIRRUS_BLTMODE_PIXELWIDTHMASK;

    if ((s->
	 cirrus_blt_mode & (CIRRUS_BLTMODE_MEMSYSSRC |
			    CIRRUS_BLTMODE_MEMSYSDEST))
	== (CIRRUS_BLTMODE_MEMSYSSRC | CIRRUS_BLTMODE_MEMSYSDEST)) {
1027
#ifdef DEBUG_BITBLT
1028 1029 1030 1031 1032
	printf("cirrus: bitblt - memory-to-memory copy is requested\n");
#endif
	goto bitblt_ignore;
    }

1033
    if ((s->cirrus_blt_modeext & CIRRUS_BLTMODEEXT_SOLIDFILL) &&
1034
        (s->cirrus_blt_mode & (CIRRUS_BLTMODE_MEMSYSDEST |
1035
                               CIRRUS_BLTMODE_TRANSPARENTCOMP |
1036 1037
                               CIRRUS_BLTMODE_PATTERNCOPY |
                               CIRRUS_BLTMODE_COLOREXPAND)) ==
1038
         (CIRRUS_BLTMODE_PATTERNCOPY | CIRRUS_BLTMODE_COLOREXPAND)) {
1039 1040
        cirrus_bitblt_fgcol(s);
        cirrus_bitblt_solidfill(s, blt_rop);
1041
    } else {
1042 1043
        if ((s->cirrus_blt_mode & (CIRRUS_BLTMODE_COLOREXPAND |
                                   CIRRUS_BLTMODE_PATTERNCOPY)) ==
1044 1045 1046
            CIRRUS_BLTMODE_COLOREXPAND) {

            if (s->cirrus_blt_mode & CIRRUS_BLTMODE_TRANSPARENTCOMP) {
B
bellard 已提交
1047
                if (s->cirrus_blt_modeext & CIRRUS_BLTMODEEXT_COLOREXPINV)
B
bellard 已提交
1048
                    cirrus_bitblt_bgcol(s);
B
bellard 已提交
1049
                else
B
bellard 已提交
1050
                    cirrus_bitblt_fgcol(s);
B
bellard 已提交
1051
                s->cirrus_rop = cirrus_colorexpand_transp[rop_to_index[blt_rop]][s->cirrus_blt_pixelwidth - 1];
1052 1053 1054 1055 1056
            } else {
                cirrus_bitblt_fgcol(s);
                cirrus_bitblt_bgcol(s);
                s->cirrus_rop = cirrus_colorexpand[rop_to_index[blt_rop]][s->cirrus_blt_pixelwidth - 1];
            }
B
bellard 已提交
1057
        } else if (s->cirrus_blt_mode & CIRRUS_BLTMODE_PATTERNCOPY) {
B
bellard 已提交
1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072
            if (s->cirrus_blt_mode & CIRRUS_BLTMODE_COLOREXPAND) {
                if (s->cirrus_blt_mode & CIRRUS_BLTMODE_TRANSPARENTCOMP) {
                    if (s->cirrus_blt_modeext & CIRRUS_BLTMODEEXT_COLOREXPINV)
                        cirrus_bitblt_bgcol(s);
                    else
                        cirrus_bitblt_fgcol(s);
                    s->cirrus_rop = cirrus_colorexpand_pattern_transp[rop_to_index[blt_rop]][s->cirrus_blt_pixelwidth - 1];
                } else {
                    cirrus_bitblt_fgcol(s);
                    cirrus_bitblt_bgcol(s);
                    s->cirrus_rop = cirrus_colorexpand_pattern[rop_to_index[blt_rop]][s->cirrus_blt_pixelwidth - 1];
                }
            } else {
                s->cirrus_rop = cirrus_patternfill[rop_to_index[blt_rop]][s->cirrus_blt_pixelwidth - 1];
            }
1073
        } else {
1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095
	    if (s->cirrus_blt_mode & CIRRUS_BLTMODE_TRANSPARENTCOMP) {
		if (s->cirrus_blt_pixelwidth > 2) {
		    printf("src transparent without colorexpand must be 8bpp or 16bpp\n");
		    goto bitblt_ignore;
		}
		if (s->cirrus_blt_mode & CIRRUS_BLTMODE_BACKWARDS) {
		    s->cirrus_blt_dstpitch = -s->cirrus_blt_dstpitch;
		    s->cirrus_blt_srcpitch = -s->cirrus_blt_srcpitch;
		    s->cirrus_rop = cirrus_bkwd_transp_rop[rop_to_index[blt_rop]][s->cirrus_blt_pixelwidth - 1];
		} else {
		    s->cirrus_rop = cirrus_fwd_transp_rop[rop_to_index[blt_rop]][s->cirrus_blt_pixelwidth - 1];
		}
	    } else {
		if (s->cirrus_blt_mode & CIRRUS_BLTMODE_BACKWARDS) {
		    s->cirrus_blt_dstpitch = -s->cirrus_blt_dstpitch;
		    s->cirrus_blt_srcpitch = -s->cirrus_blt_srcpitch;
		    s->cirrus_rop = cirrus_bkwd_rop[rop_to_index[blt_rop]];
		} else {
		    s->cirrus_rop = cirrus_fwd_rop[rop_to_index[blt_rop]];
		}
	    }
	}
1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106
        // setup bitblt engine.
        if (s->cirrus_blt_mode & CIRRUS_BLTMODE_MEMSYSSRC) {
            if (!cirrus_bitblt_cputovideo(s))
                goto bitblt_ignore;
        } else if (s->cirrus_blt_mode & CIRRUS_BLTMODE_MEMSYSDEST) {
            if (!cirrus_bitblt_videotocpu(s))
                goto bitblt_ignore;
        } else {
            if (!cirrus_bitblt_videotovideo(s))
                goto bitblt_ignore;
        }
1107 1108 1109 1110 1111 1112 1113 1114 1115 1116
    }
    return;
  bitblt_ignore:;
    cirrus_bitblt_reset(s);
}

static void cirrus_write_bitblt(CirrusVGAState * s, unsigned reg_value)
{
    unsigned old_value;

1117 1118
    old_value = s->vga.gr[0x31];
    s->vga.gr[0x31] = reg_value;
1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135

    if (((old_value & CIRRUS_BLT_RESET) != 0) &&
	((reg_value & CIRRUS_BLT_RESET) == 0)) {
	cirrus_bitblt_reset(s);
    } else if (((old_value & CIRRUS_BLT_START) == 0) &&
	       ((reg_value & CIRRUS_BLT_START) != 0)) {
	cirrus_bitblt_start(s);
    }
}


/***************************************
 *
 *  basic parameters
 *
 ***************************************/

1136
static void cirrus_get_offsets(VGACommonState *s1,
1137 1138 1139
                               uint32_t *pline_offset,
                               uint32_t *pstart_addr,
                               uint32_t *pline_compare)
1140
{
1141
    CirrusVGAState * s = container_of(s1, CirrusVGAState, vga);
1142
    uint32_t start_addr, line_offset, line_compare;
1143

1144 1145
    line_offset = s->vga.cr[0x13]
	| ((s->vga.cr[0x1b] & 0x10) << 4);
1146 1147 1148
    line_offset <<= 3;
    *pline_offset = line_offset;

1149 1150 1151 1152 1153
    start_addr = (s->vga.cr[0x0c] << 8)
	| s->vga.cr[0x0d]
	| ((s->vga.cr[0x1b] & 0x01) << 16)
	| ((s->vga.cr[0x1b] & 0x0c) << 15)
	| ((s->vga.cr[0x1d] & 0x80) << 12);
1154
    *pstart_addr = start_addr;
1155

1156 1157 1158
    line_compare = s->vga.cr[0x18] |
        ((s->vga.cr[0x07] & 0x10) << 4) |
        ((s->vga.cr[0x09] & 0x40) << 3);
1159
    *pline_compare = line_compare;
1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183
}

static uint32_t cirrus_get_bpp16_depth(CirrusVGAState * s)
{
    uint32_t ret = 16;

    switch (s->cirrus_hidden_dac_data & 0xf) {
    case 0:
	ret = 15;
	break;			/* Sierra HiColor */
    case 1:
	ret = 16;
	break;			/* XGA HiColor */
    default:
#ifdef DEBUG_CIRRUS
	printf("cirrus: invalid DAC value %x in 16bpp\n",
	       (s->cirrus_hidden_dac_data & 0xf));
#endif
	ret = 15;		/* XXX */
	break;
    }
    return ret;
}

1184
static int cirrus_get_bpp(VGACommonState *s1)
1185
{
1186
    CirrusVGAState * s = container_of(s1, CirrusVGAState, vga);
1187 1188
    uint32_t ret = 8;

1189
    if ((s->vga.sr[0x07] & 0x01) != 0) {
1190
	/* Cirrus SVGA */
1191
	switch (s->vga.sr[0x07] & CIRRUS_SR7_BPP_MASK) {
1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208
	case CIRRUS_SR7_BPP_8:
	    ret = 8;
	    break;
	case CIRRUS_SR7_BPP_16_DOUBLEVCLK:
	    ret = cirrus_get_bpp16_depth(s);
	    break;
	case CIRRUS_SR7_BPP_24:
	    ret = 24;
	    break;
	case CIRRUS_SR7_BPP_16:
	    ret = cirrus_get_bpp16_depth(s);
	    break;
	case CIRRUS_SR7_BPP_32:
	    ret = 32;
	    break;
	default:
#ifdef DEBUG_CIRRUS
1209
	    printf("cirrus: unknown bpp - sr7=%x\n", s->vga.sr[0x7]);
1210 1211 1212 1213 1214 1215
#endif
	    ret = 8;
	    break;
	}
    } else {
	/* VGA */
B
bellard 已提交
1216
	ret = 0;
1217 1218 1219 1220 1221
    }

    return ret;
}

1222
static void cirrus_get_resolution(VGACommonState *s, int *pwidth, int *pheight)
1223 1224
{
    int width, height;
1225

1226
    width = (s->cr[0x01] + 1) * 8;
1227 1228
    height = s->cr[0x12] |
        ((s->cr[0x07] & 0x02) << 7) |
1229 1230 1231 1232 1233 1234 1235 1236 1237
        ((s->cr[0x07] & 0x40) << 3);
    height = (height + 1);
    /* interlace support */
    if (s->cr[0x1a] & 0x01)
        height = height * 2;
    *pwidth = width;
    *pheight = height;
}

1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248
/***************************************
 *
 * bank memory
 *
 ***************************************/

static void cirrus_update_bank_ptr(CirrusVGAState * s, unsigned bank_index)
{
    unsigned offset;
    unsigned limit;

1249 1250
    if ((s->vga.gr[0x0b] & 0x01) != 0)	/* dual bank */
	offset = s->vga.gr[0x09 + bank_index];
1251
    else			/* single bank */
1252
	offset = s->vga.gr[0x09];
1253

1254
    if ((s->vga.gr[0x0b] & 0x20) != 0)
1255 1256 1257 1258
	offset <<= 14;
    else
	offset <<= 12;

1259
    if (s->real_vram_size <= offset)
1260 1261
	limit = 0;
    else
1262
	limit = s->real_vram_size - offset;
1263

1264
    if (((s->vga.gr[0x0b] & 0x01) == 0) && (bank_index != 0)) {
1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287
	if (limit > 0x8000) {
	    offset += 0x8000;
	    limit -= 0x8000;
	} else {
	    limit = 0;
	}
    }

    if (limit > 0) {
	s->cirrus_bank_base[bank_index] = offset;
	s->cirrus_bank_limit[bank_index] = limit;
    } else {
	s->cirrus_bank_base[bank_index] = 0;
	s->cirrus_bank_limit[bank_index] = 0;
    }
}

/***************************************
 *
 *  I/O access between 0x3c4-0x3c5
 *
 ***************************************/

1288
static int cirrus_vga_read_sr(CirrusVGAState * s)
1289
{
1290
    switch (s->vga.sr_index) {
1291 1292 1293 1294 1295
    case 0x00:			// Standard VGA
    case 0x01:			// Standard VGA
    case 0x02:			// Standard VGA
    case 0x03:			// Standard VGA
    case 0x04:			// Standard VGA
1296
	return s->vga.sr[s->vga.sr_index];
1297
    case 0x06:			// Unlock Cirrus extensions
1298
	return s->vga.sr[s->vga.sr_index];
1299 1300 1301 1302 1303 1304 1305 1306
    case 0x10:
    case 0x30:
    case 0x50:
    case 0x70:			// Graphics Cursor X
    case 0x90:
    case 0xb0:
    case 0xd0:
    case 0xf0:			// Graphics Cursor X
1307
	return s->vga.sr[0x10];
1308 1309 1310 1311 1312 1313 1314
    case 0x11:
    case 0x31:
    case 0x51:
    case 0x71:			// Graphics Cursor Y
    case 0x91:
    case 0xb1:
    case 0xd1:
1315
    case 0xf1:			// Graphics Cursor Y
1316
	return s->vga.sr[0x11];
B
bellard 已提交
1317 1318 1319 1320 1321 1322 1323 1324 1325 1326
    case 0x05:			// ???
    case 0x07:			// Extended Sequencer Mode
    case 0x08:			// EEPROM Control
    case 0x09:			// Scratch Register 0
    case 0x0a:			// Scratch Register 1
    case 0x0b:			// VCLK 0
    case 0x0c:			// VCLK 1
    case 0x0d:			// VCLK 2
    case 0x0e:			// VCLK 3
    case 0x0f:			// DRAM Control
1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341
    case 0x12:			// Graphics Cursor Attribute
    case 0x13:			// Graphics Cursor Pattern Address
    case 0x14:			// Scratch Register 2
    case 0x15:			// Scratch Register 3
    case 0x16:			// Performance Tuning Register
    case 0x17:			// Configuration Readback and Extended Control
    case 0x18:			// Signature Generator Control
    case 0x19:			// Signal Generator Result
    case 0x1a:			// Signal Generator Result
    case 0x1b:			// VCLK 0 Denominator & Post
    case 0x1c:			// VCLK 1 Denominator & Post
    case 0x1d:			// VCLK 2 Denominator & Post
    case 0x1e:			// VCLK 3 Denominator & Post
    case 0x1f:			// BIOS Write Enable and MCLK select
#ifdef DEBUG_CIRRUS
1342
	printf("cirrus: handled inport sr_index %02x\n", s->vga.sr_index);
1343
#endif
1344
	return s->vga.sr[s->vga.sr_index];
1345 1346
    default:
#ifdef DEBUG_CIRRUS
1347
	printf("cirrus: inport sr_index %02x\n", s->vga.sr_index);
1348
#endif
1349
	return 0xff;
1350 1351 1352 1353
	break;
    }
}

1354
static void cirrus_vga_write_sr(CirrusVGAState * s, uint32_t val)
1355
{
1356
    switch (s->vga.sr_index) {
1357 1358 1359 1360 1361
    case 0x00:			// Standard VGA
    case 0x01:			// Standard VGA
    case 0x02:			// Standard VGA
    case 0x03:			// Standard VGA
    case 0x04:			// Standard VGA
1362 1363 1364 1365
	s->vga.sr[s->vga.sr_index] = val & sr_mask[s->vga.sr_index];
	if (s->vga.sr_index == 1)
            s->vga.update_retrace_info(&s->vga);
        break;
1366
    case 0x06:			// Unlock Cirrus extensions
1367 1368 1369
	val &= 0x17;
	if (val == 0x12) {
	    s->vga.sr[s->vga.sr_index] = 0x12;
1370
	} else {
1371
	    s->vga.sr[s->vga.sr_index] = 0x0f;
1372 1373 1374 1375 1376 1377 1378 1379 1380 1381
	}
	break;
    case 0x10:
    case 0x30:
    case 0x50:
    case 0x70:			// Graphics Cursor X
    case 0x90:
    case 0xb0:
    case 0xd0:
    case 0xf0:			// Graphics Cursor X
1382
	s->vga.sr[0x10] = val;
1383
        s->vga.hw_cursor_x = (val << 3) | (s->vga.sr_index >> 5);
1384 1385 1386 1387 1388 1389 1390 1391 1392
	break;
    case 0x11:
    case 0x31:
    case 0x51:
    case 0x71:			// Graphics Cursor Y
    case 0x91:
    case 0xb1:
    case 0xd1:
    case 0xf1:			// Graphics Cursor Y
1393
	s->vga.sr[0x11] = val;
1394
        s->vga.hw_cursor_y = (val << 3) | (s->vga.sr_index >> 5);
1395 1396
	break;
    case 0x07:			// Extended Sequencer Mode
A
aliguori 已提交
1397
    cirrus_update_memory_access(s);
1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417
    case 0x08:			// EEPROM Control
    case 0x09:			// Scratch Register 0
    case 0x0a:			// Scratch Register 1
    case 0x0b:			// VCLK 0
    case 0x0c:			// VCLK 1
    case 0x0d:			// VCLK 2
    case 0x0e:			// VCLK 3
    case 0x0f:			// DRAM Control
    case 0x13:			// Graphics Cursor Pattern Address
    case 0x14:			// Scratch Register 2
    case 0x15:			// Scratch Register 3
    case 0x16:			// Performance Tuning Register
    case 0x18:			// Signature Generator Control
    case 0x19:			// Signature Generator Result
    case 0x1a:			// Signature Generator Result
    case 0x1b:			// VCLK 0 Denominator & Post
    case 0x1c:			// VCLK 1 Denominator & Post
    case 0x1d:			// VCLK 2 Denominator & Post
    case 0x1e:			// VCLK 3 Denominator & Post
    case 0x1f:			// BIOS Write Enable and MCLK select
1418
	s->vga.sr[s->vga.sr_index] = val;
1419 1420
#ifdef DEBUG_CIRRUS
	printf("cirrus: handled outport sr_index %02x, sr_value %02x\n",
1421
	       s->vga.sr_index, val);
1422 1423
#endif
	break;
1424 1425 1426 1427 1428 1429 1430 1431
    case 0x12:			// Graphics Cursor Attribute
	s->vga.sr[0x12] = val;
        s->vga.force_shadow = !!(val & CIRRUS_CURSOR_SHOW);
#ifdef DEBUG_CIRRUS
        printf("cirrus: cursor ctl SR12=%02x (force shadow: %d)\n",
               val, s->vga.force_shadow);
#endif
        break;
B
bellard 已提交
1432
    case 0x17:			// Configuration Readback and Extended Control
1433 1434
	s->vga.sr[s->vga.sr_index] = (s->vga.sr[s->vga.sr_index] & 0x38)
                                   | (val & 0xc7);
B
bellard 已提交
1435 1436
        cirrus_update_memory_access(s);
        break;
1437 1438
    default:
#ifdef DEBUG_CIRRUS
1439 1440
	printf("cirrus: outport sr_index %02x, sr_value %02x\n",
               s->vga.sr_index, val);
1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451
#endif
	break;
    }
}

/***************************************
 *
 *  I/O access at 0x3c6
 *
 ***************************************/

1452
static int cirrus_read_hidden_dac(CirrusVGAState * s)
1453
{
1454
    if (++s->cirrus_hidden_dac_lockindex == 5) {
1455 1456
        s->cirrus_hidden_dac_lockindex = 0;
        return s->cirrus_hidden_dac_data;
1457
    }
1458
    return 0xff;
1459 1460 1461 1462 1463 1464
}

static void cirrus_write_hidden_dac(CirrusVGAState * s, int reg_value)
{
    if (s->cirrus_hidden_dac_lockindex == 4) {
	s->cirrus_hidden_dac_data = reg_value;
1465
#if defined(DEBUG_CIRRUS)
1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477
	printf("cirrus: outport hidden DAC, value %02x\n", reg_value);
#endif
    }
    s->cirrus_hidden_dac_lockindex = 0;
}

/***************************************
 *
 *  I/O access at 0x3c9
 *
 ***************************************/

1478
static int cirrus_vga_read_palette(CirrusVGAState * s)
1479
{
1480 1481 1482 1483 1484 1485 1486 1487
    int val;

    if ((s->vga.sr[0x12] & CIRRUS_CURSOR_HIDDENPEL)) {
        val = s->cirrus_hidden_palette[(s->vga.dac_read_index & 0x0f) * 3 +
                                       s->vga.dac_sub_index];
    } else {
        val = s->vga.palette[s->vga.dac_read_index * 3 + s->vga.dac_sub_index];
    }
1488 1489 1490
    if (++s->vga.dac_sub_index == 3) {
	s->vga.dac_sub_index = 0;
	s->vga.dac_read_index++;
1491
    }
1492
    return val;
1493 1494
}

1495
static void cirrus_vga_write_palette(CirrusVGAState * s, int reg_value)
1496
{
1497 1498
    s->vga.dac_cache[s->vga.dac_sub_index] = reg_value;
    if (++s->vga.dac_sub_index == 3) {
1499 1500 1501 1502 1503 1504
        if ((s->vga.sr[0x12] & CIRRUS_CURSOR_HIDDENPEL)) {
            memcpy(&s->cirrus_hidden_palette[(s->vga.dac_write_index & 0x0f) * 3],
                   s->vga.dac_cache, 3);
        } else {
            memcpy(&s->vga.palette[s->vga.dac_write_index * 3], s->vga.dac_cache, 3);
        }
1505
        /* XXX update cursor */
1506 1507
	s->vga.dac_sub_index = 0;
	s->vga.dac_write_index++;
1508 1509 1510 1511 1512 1513 1514 1515 1516
    }
}

/***************************************
 *
 *  I/O access between 0x3ce-0x3cf
 *
 ***************************************/

1517
static int cirrus_vga_read_gr(CirrusVGAState * s, unsigned reg_index)
1518 1519
{
    switch (reg_index) {
B
bellard 已提交
1520
    case 0x00: // Standard VGA, BGCOLOR 0x000000ff
1521
        return s->cirrus_shadow_gr0;
B
bellard 已提交
1522
    case 0x01: // Standard VGA, FGCOLOR 0x000000ff
1523
        return s->cirrus_shadow_gr1;
1524 1525 1526 1527 1528 1529
    case 0x02:			// Standard VGA
    case 0x03:			// Standard VGA
    case 0x04:			// Standard VGA
    case 0x06:			// Standard VGA
    case 0x07:			// Standard VGA
    case 0x08:			// Standard VGA
1530
        return s->vga.gr[s->vga.gr_index];
1531 1532 1533 1534 1535 1536
    case 0x05:			// Standard VGA, Cirrus extended mode
    default:
	break;
    }

    if (reg_index < 0x3a) {
1537
	return s->vga.gr[reg_index];
1538 1539 1540 1541
    } else {
#ifdef DEBUG_CIRRUS
	printf("cirrus: inport gr_index %02x\n", reg_index);
#endif
1542
	return 0xff;
1543 1544 1545
    }
}

1546 1547
static void
cirrus_vga_write_gr(CirrusVGAState * s, unsigned reg_index, int reg_value)
1548
{
1549 1550 1551
#if defined(DEBUG_BITBLT) && 0
    printf("gr%02x: %02x\n", reg_index, reg_value);
#endif
1552 1553
    switch (reg_index) {
    case 0x00:			// Standard VGA, BGCOLOR 0x000000ff
1554
	s->vga.gr[reg_index] = reg_value & gr_mask[reg_index];
B
bellard 已提交
1555
	s->cirrus_shadow_gr0 = reg_value;
1556
	break;
1557
    case 0x01:			// Standard VGA, FGCOLOR 0x000000ff
1558
	s->vga.gr[reg_index] = reg_value & gr_mask[reg_index];
B
bellard 已提交
1559
	s->cirrus_shadow_gr1 = reg_value;
1560
	break;
1561 1562 1563 1564 1565 1566
    case 0x02:			// Standard VGA
    case 0x03:			// Standard VGA
    case 0x04:			// Standard VGA
    case 0x06:			// Standard VGA
    case 0x07:			// Standard VGA
    case 0x08:			// Standard VGA
1567 1568
	s->vga.gr[reg_index] = reg_value & gr_mask[reg_index];
        break;
1569
    case 0x05:			// Standard VGA, Cirrus extended mode
1570
	s->vga.gr[reg_index] = reg_value & 0x7f;
B
bellard 已提交
1571
        cirrus_update_memory_access(s);
1572 1573 1574
	break;
    case 0x09:			// bank offset #0
    case 0x0A:			// bank offset #1
1575
	s->vga.gr[reg_index] = reg_value;
B
bellard 已提交
1576 1577
	cirrus_update_bank_ptr(s, 0);
	cirrus_update_bank_ptr(s, 1);
A
aliguori 已提交
1578
        cirrus_update_memory_access(s);
B
bellard 已提交
1579
        break;
1580
    case 0x0B:
1581
	s->vga.gr[reg_index] = reg_value;
1582 1583
	cirrus_update_bank_ptr(s, 0);
	cirrus_update_bank_ptr(s, 1);
B
bellard 已提交
1584
        cirrus_update_memory_access(s);
1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599
	break;
    case 0x10:			// BGCOLOR 0x0000ff00
    case 0x11:			// FGCOLOR 0x0000ff00
    case 0x12:			// BGCOLOR 0x00ff0000
    case 0x13:			// FGCOLOR 0x00ff0000
    case 0x14:			// BGCOLOR 0xff000000
    case 0x15:			// FGCOLOR 0xff000000
    case 0x20:			// BLT WIDTH 0x0000ff
    case 0x22:			// BLT HEIGHT 0x0000ff
    case 0x24:			// BLT DEST PITCH 0x0000ff
    case 0x26:			// BLT SRC PITCH 0x0000ff
    case 0x28:			// BLT DEST ADDR 0x0000ff
    case 0x29:			// BLT DEST ADDR 0x00ff00
    case 0x2c:			// BLT SRC ADDR 0x0000ff
    case 0x2d:			// BLT SRC ADDR 0x00ff00
1600
    case 0x2f:                  // BLT WRITEMASK
1601 1602
    case 0x30:			// BLT MODE
    case 0x32:			// RASTER OP
1603
    case 0x33:			// BLT MODEEXT
1604 1605 1606 1607
    case 0x34:			// BLT TRANSPARENT COLOR 0x00ff
    case 0x35:			// BLT TRANSPARENT COLOR 0xff00
    case 0x38:			// BLT TRANSPARENT COLOR MASK 0x00ff
    case 0x39:			// BLT TRANSPARENT COLOR MASK 0xff00
1608
	s->vga.gr[reg_index] = reg_value;
1609 1610 1611 1612 1613
	break;
    case 0x21:			// BLT WIDTH 0x001f00
    case 0x23:			// BLT HEIGHT 0x001f00
    case 0x25:			// BLT DEST PITCH 0x001f00
    case 0x27:			// BLT SRC PITCH 0x001f00
1614
	s->vga.gr[reg_index] = reg_value & 0x1f;
1615 1616
	break;
    case 0x2a:			// BLT DEST ADDR 0x3f0000
1617
	s->vga.gr[reg_index] = reg_value & 0x3f;
1618
        /* if auto start mode, starts bit blt now */
1619
        if (s->vga.gr[0x31] & CIRRUS_BLT_AUTOSTART) {
1620 1621 1622
            cirrus_bitblt_start(s);
        }
	break;
1623
    case 0x2e:			// BLT SRC ADDR 0x3f0000
1624
	s->vga.gr[reg_index] = reg_value & 0x3f;
1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643
	break;
    case 0x31:			// BLT STATUS/START
	cirrus_write_bitblt(s, reg_value);
	break;
    default:
#ifdef DEBUG_CIRRUS
	printf("cirrus: outport gr_index %02x, gr_value %02x\n", reg_index,
	       reg_value);
#endif
	break;
    }
}

/***************************************
 *
 *  I/O access between 0x3d4-0x3d5
 *
 ***************************************/

1644
static int cirrus_vga_read_cr(CirrusVGAState * s, unsigned reg_index)
1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671
{
    switch (reg_index) {
    case 0x00:			// Standard VGA
    case 0x01:			// Standard VGA
    case 0x02:			// Standard VGA
    case 0x03:			// Standard VGA
    case 0x04:			// Standard VGA
    case 0x05:			// Standard VGA
    case 0x06:			// Standard VGA
    case 0x07:			// Standard VGA
    case 0x08:			// Standard VGA
    case 0x09:			// Standard VGA
    case 0x0a:			// Standard VGA
    case 0x0b:			// Standard VGA
    case 0x0c:			// Standard VGA
    case 0x0d:			// Standard VGA
    case 0x0e:			// Standard VGA
    case 0x0f:			// Standard VGA
    case 0x10:			// Standard VGA
    case 0x11:			// Standard VGA
    case 0x12:			// Standard VGA
    case 0x13:			// Standard VGA
    case 0x14:			// Standard VGA
    case 0x15:			// Standard VGA
    case 0x16:			// Standard VGA
    case 0x17:			// Standard VGA
    case 0x18:			// Standard VGA
1672
	return s->vga.cr[s->vga.cr_index];
1673
    case 0x24:			// Attribute Controller Toggle Readback (R)
1674
        return (s->vga.ar_flip_flop << 7);
1675 1676 1677 1678 1679 1680 1681 1682
    case 0x19:			// Interlace End
    case 0x1a:			// Miscellaneous Control
    case 0x1b:			// Extended Display Control
    case 0x1c:			// Sync Adjust and Genlock
    case 0x1d:			// Overlay Extended Control
    case 0x22:			// Graphics Data Latches Readback (R)
    case 0x25:			// Part Status
    case 0x27:			// Part ID (R)
1683
	return s->vga.cr[s->vga.cr_index];
1684
    case 0x26:			// Attribute Controller Index Readback (R)
1685
	return s->vga.ar_index & 0x3f;
1686 1687 1688 1689 1690
	break;
    default:
#ifdef DEBUG_CIRRUS
	printf("cirrus: inport cr_index %02x\n", reg_index);
#endif
1691
	return 0xff;
1692 1693 1694
    }
}

1695
static void cirrus_vga_write_cr(CirrusVGAState * s, int reg_value)
1696
{
1697
    switch (s->vga.cr_index) {
1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722
    case 0x00:			// Standard VGA
    case 0x01:			// Standard VGA
    case 0x02:			// Standard VGA
    case 0x03:			// Standard VGA
    case 0x04:			// Standard VGA
    case 0x05:			// Standard VGA
    case 0x06:			// Standard VGA
    case 0x07:			// Standard VGA
    case 0x08:			// Standard VGA
    case 0x09:			// Standard VGA
    case 0x0a:			// Standard VGA
    case 0x0b:			// Standard VGA
    case 0x0c:			// Standard VGA
    case 0x0d:			// Standard VGA
    case 0x0e:			// Standard VGA
    case 0x0f:			// Standard VGA
    case 0x10:			// Standard VGA
    case 0x11:			// Standard VGA
    case 0x12:			// Standard VGA
    case 0x13:			// Standard VGA
    case 0x14:			// Standard VGA
    case 0x15:			// Standard VGA
    case 0x16:			// Standard VGA
    case 0x17:			// Standard VGA
    case 0x18:			// Standard VGA
1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742
	/* handle CR0-7 protection */
	if ((s->vga.cr[0x11] & 0x80) && s->vga.cr_index <= 7) {
	    /* can always write bit 4 of CR7 */
	    if (s->vga.cr_index == 7)
		s->vga.cr[7] = (s->vga.cr[7] & ~0x10) | (reg_value & 0x10);
	    return;
	}
	s->vga.cr[s->vga.cr_index] = reg_value;
	switch(s->vga.cr_index) {
	case 0x00:
	case 0x04:
	case 0x05:
	case 0x06:
	case 0x07:
	case 0x11:
	case 0x17:
	    s->vga.update_retrace_info(&s->vga);
	    break;
	}
        break;
1743 1744 1745 1746
    case 0x19:			// Interlace End
    case 0x1a:			// Miscellaneous Control
    case 0x1b:			// Extended Display Control
    case 0x1c:			// Sync Adjust and Genlock
1747
    case 0x1d:			// Overlay Extended Control
1748
	s->vga.cr[s->vga.cr_index] = reg_value;
1749 1750
#ifdef DEBUG_CIRRUS
	printf("cirrus: handled outport cr_index %02x, cr_value %02x\n",
1751
	       s->vga.cr_index, reg_value);
1752 1753 1754 1755 1756 1757 1758 1759 1760 1761
#endif
	break;
    case 0x22:			// Graphics Data Latches Readback (R)
    case 0x24:			// Attribute Controller Toggle Readback (R)
    case 0x26:			// Attribute Controller Index Readback (R)
    case 0x27:			// Part ID (R)
	break;
    case 0x25:			// Part Status
    default:
#ifdef DEBUG_CIRRUS
1762 1763
	printf("cirrus: outport cr_index %02x, cr_value %02x\n",
               s->vga.cr_index, reg_value);
1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780
#endif
	break;
    }
}

/***************************************
 *
 *  memory-mapped I/O (bitblt)
 *
 ***************************************/

static uint8_t cirrus_mmio_blt_read(CirrusVGAState * s, unsigned address)
{
    int value = 0xff;

    switch (address) {
    case (CIRRUS_MMIO_BLTBGCOLOR + 0):
1781
	value = cirrus_vga_read_gr(s, 0x00);
1782 1783
	break;
    case (CIRRUS_MMIO_BLTBGCOLOR + 1):
1784
	value = cirrus_vga_read_gr(s, 0x10);
1785 1786
	break;
    case (CIRRUS_MMIO_BLTBGCOLOR + 2):
1787
	value = cirrus_vga_read_gr(s, 0x12);
1788 1789
	break;
    case (CIRRUS_MMIO_BLTBGCOLOR + 3):
1790
	value = cirrus_vga_read_gr(s, 0x14);
1791 1792
	break;
    case (CIRRUS_MMIO_BLTFGCOLOR + 0):
1793
	value = cirrus_vga_read_gr(s, 0x01);
1794 1795
	break;
    case (CIRRUS_MMIO_BLTFGCOLOR + 1):
1796
	value = cirrus_vga_read_gr(s, 0x11);
1797 1798
	break;
    case (CIRRUS_MMIO_BLTFGCOLOR + 2):
1799
	value = cirrus_vga_read_gr(s, 0x13);
1800 1801
	break;
    case (CIRRUS_MMIO_BLTFGCOLOR + 3):
1802
	value = cirrus_vga_read_gr(s, 0x15);
1803 1804
	break;
    case (CIRRUS_MMIO_BLTWIDTH + 0):
1805
	value = cirrus_vga_read_gr(s, 0x20);
1806 1807
	break;
    case (CIRRUS_MMIO_BLTWIDTH + 1):
1808
	value = cirrus_vga_read_gr(s, 0x21);
1809 1810
	break;
    case (CIRRUS_MMIO_BLTHEIGHT + 0):
1811
	value = cirrus_vga_read_gr(s, 0x22);
1812 1813
	break;
    case (CIRRUS_MMIO_BLTHEIGHT + 1):
1814
	value = cirrus_vga_read_gr(s, 0x23);
1815 1816
	break;
    case (CIRRUS_MMIO_BLTDESTPITCH + 0):
1817
	value = cirrus_vga_read_gr(s, 0x24);
1818 1819
	break;
    case (CIRRUS_MMIO_BLTDESTPITCH + 1):
1820
	value = cirrus_vga_read_gr(s, 0x25);
1821 1822
	break;
    case (CIRRUS_MMIO_BLTSRCPITCH + 0):
1823
	value = cirrus_vga_read_gr(s, 0x26);
1824 1825
	break;
    case (CIRRUS_MMIO_BLTSRCPITCH + 1):
1826
	value = cirrus_vga_read_gr(s, 0x27);
1827 1828
	break;
    case (CIRRUS_MMIO_BLTDESTADDR + 0):
1829
	value = cirrus_vga_read_gr(s, 0x28);
1830 1831
	break;
    case (CIRRUS_MMIO_BLTDESTADDR + 1):
1832
	value = cirrus_vga_read_gr(s, 0x29);
1833 1834
	break;
    case (CIRRUS_MMIO_BLTDESTADDR + 2):
1835
	value = cirrus_vga_read_gr(s, 0x2a);
1836 1837
	break;
    case (CIRRUS_MMIO_BLTSRCADDR + 0):
1838
	value = cirrus_vga_read_gr(s, 0x2c);
1839 1840
	break;
    case (CIRRUS_MMIO_BLTSRCADDR + 1):
1841
	value = cirrus_vga_read_gr(s, 0x2d);
1842 1843
	break;
    case (CIRRUS_MMIO_BLTSRCADDR + 2):
1844
	value = cirrus_vga_read_gr(s, 0x2e);
1845 1846
	break;
    case CIRRUS_MMIO_BLTWRITEMASK:
1847
	value = cirrus_vga_read_gr(s, 0x2f);
1848 1849
	break;
    case CIRRUS_MMIO_BLTMODE:
1850
	value = cirrus_vga_read_gr(s, 0x30);
1851 1852
	break;
    case CIRRUS_MMIO_BLTROP:
1853
	value = cirrus_vga_read_gr(s, 0x32);
1854
	break;
1855
    case CIRRUS_MMIO_BLTMODEEXT:
1856
	value = cirrus_vga_read_gr(s, 0x33);
1857
	break;
1858
    case (CIRRUS_MMIO_BLTTRANSPARENTCOLOR + 0):
1859
	value = cirrus_vga_read_gr(s, 0x34);
1860 1861
	break;
    case (CIRRUS_MMIO_BLTTRANSPARENTCOLOR + 1):
1862
	value = cirrus_vga_read_gr(s, 0x35);
1863 1864
	break;
    case (CIRRUS_MMIO_BLTTRANSPARENTCOLORMASK + 0):
1865
	value = cirrus_vga_read_gr(s, 0x38);
1866 1867
	break;
    case (CIRRUS_MMIO_BLTTRANSPARENTCOLORMASK + 1):
1868
	value = cirrus_vga_read_gr(s, 0x39);
1869 1870
	break;
    case CIRRUS_MMIO_BLTSTATUS:
1871
	value = cirrus_vga_read_gr(s, 0x31);
1872 1873 1874 1875 1876 1877 1878 1879
	break;
    default:
#ifdef DEBUG_CIRRUS
	printf("cirrus: mmio read - address 0x%04x\n", address);
#endif
	break;
    }

1880
    trace_vga_cirrus_write_blt(address, value);
1881 1882 1883 1884 1885 1886
    return (uint8_t) value;
}

static void cirrus_mmio_blt_write(CirrusVGAState * s, unsigned address,
				  uint8_t value)
{
1887
    trace_vga_cirrus_write_blt(address, value);
1888 1889
    switch (address) {
    case (CIRRUS_MMIO_BLTBGCOLOR + 0):
1890
	cirrus_vga_write_gr(s, 0x00, value);
1891 1892
	break;
    case (CIRRUS_MMIO_BLTBGCOLOR + 1):
1893
	cirrus_vga_write_gr(s, 0x10, value);
1894 1895
	break;
    case (CIRRUS_MMIO_BLTBGCOLOR + 2):
1896
	cirrus_vga_write_gr(s, 0x12, value);
1897 1898
	break;
    case (CIRRUS_MMIO_BLTBGCOLOR + 3):
1899
	cirrus_vga_write_gr(s, 0x14, value);
1900 1901
	break;
    case (CIRRUS_MMIO_BLTFGCOLOR + 0):
1902
	cirrus_vga_write_gr(s, 0x01, value);
1903 1904
	break;
    case (CIRRUS_MMIO_BLTFGCOLOR + 1):
1905
	cirrus_vga_write_gr(s, 0x11, value);
1906 1907
	break;
    case (CIRRUS_MMIO_BLTFGCOLOR + 2):
1908
	cirrus_vga_write_gr(s, 0x13, value);
1909 1910
	break;
    case (CIRRUS_MMIO_BLTFGCOLOR + 3):
1911
	cirrus_vga_write_gr(s, 0x15, value);
1912 1913
	break;
    case (CIRRUS_MMIO_BLTWIDTH + 0):
1914
	cirrus_vga_write_gr(s, 0x20, value);
1915 1916
	break;
    case (CIRRUS_MMIO_BLTWIDTH + 1):
1917
	cirrus_vga_write_gr(s, 0x21, value);
1918 1919
	break;
    case (CIRRUS_MMIO_BLTHEIGHT + 0):
1920
	cirrus_vga_write_gr(s, 0x22, value);
1921 1922
	break;
    case (CIRRUS_MMIO_BLTHEIGHT + 1):
1923
	cirrus_vga_write_gr(s, 0x23, value);
1924 1925
	break;
    case (CIRRUS_MMIO_BLTDESTPITCH + 0):
1926
	cirrus_vga_write_gr(s, 0x24, value);
1927 1928
	break;
    case (CIRRUS_MMIO_BLTDESTPITCH + 1):
1929
	cirrus_vga_write_gr(s, 0x25, value);
1930 1931
	break;
    case (CIRRUS_MMIO_BLTSRCPITCH + 0):
1932
	cirrus_vga_write_gr(s, 0x26, value);
1933 1934
	break;
    case (CIRRUS_MMIO_BLTSRCPITCH + 1):
1935
	cirrus_vga_write_gr(s, 0x27, value);
1936 1937
	break;
    case (CIRRUS_MMIO_BLTDESTADDR + 0):
1938
	cirrus_vga_write_gr(s, 0x28, value);
1939 1940
	break;
    case (CIRRUS_MMIO_BLTDESTADDR + 1):
1941
	cirrus_vga_write_gr(s, 0x29, value);
1942 1943
	break;
    case (CIRRUS_MMIO_BLTDESTADDR + 2):
1944
	cirrus_vga_write_gr(s, 0x2a, value);
1945 1946 1947 1948 1949
	break;
    case (CIRRUS_MMIO_BLTDESTADDR + 3):
	/* ignored */
	break;
    case (CIRRUS_MMIO_BLTSRCADDR + 0):
1950
	cirrus_vga_write_gr(s, 0x2c, value);
1951 1952
	break;
    case (CIRRUS_MMIO_BLTSRCADDR + 1):
1953
	cirrus_vga_write_gr(s, 0x2d, value);
1954 1955
	break;
    case (CIRRUS_MMIO_BLTSRCADDR + 2):
1956
	cirrus_vga_write_gr(s, 0x2e, value);
1957 1958
	break;
    case CIRRUS_MMIO_BLTWRITEMASK:
1959
	cirrus_vga_write_gr(s, 0x2f, value);
1960 1961
	break;
    case CIRRUS_MMIO_BLTMODE:
1962
	cirrus_vga_write_gr(s, 0x30, value);
1963 1964
	break;
    case CIRRUS_MMIO_BLTROP:
1965
	cirrus_vga_write_gr(s, 0x32, value);
1966
	break;
1967
    case CIRRUS_MMIO_BLTMODEEXT:
1968
	cirrus_vga_write_gr(s, 0x33, value);
1969
	break;
1970
    case (CIRRUS_MMIO_BLTTRANSPARENTCOLOR + 0):
1971
	cirrus_vga_write_gr(s, 0x34, value);
1972 1973
	break;
    case (CIRRUS_MMIO_BLTTRANSPARENTCOLOR + 1):
1974
	cirrus_vga_write_gr(s, 0x35, value);
1975 1976
	break;
    case (CIRRUS_MMIO_BLTTRANSPARENTCOLORMASK + 0):
1977
	cirrus_vga_write_gr(s, 0x38, value);
1978 1979
	break;
    case (CIRRUS_MMIO_BLTTRANSPARENTCOLORMASK + 1):
1980
	cirrus_vga_write_gr(s, 0x39, value);
1981 1982
	break;
    case CIRRUS_MMIO_BLTSTATUS:
1983
	cirrus_vga_write_gr(s, 0x31, value);
1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008
	break;
    default:
#ifdef DEBUG_CIRRUS
	printf("cirrus: mmio write - addr 0x%04x val 0x%02x (ignored)\n",
	       address, value);
#endif
	break;
    }
}

/***************************************
 *
 *  write mode 4/5
 *
 ***************************************/

static void cirrus_mem_writeb_mode4and5_8bpp(CirrusVGAState * s,
					     unsigned mode,
					     unsigned offset,
					     uint32_t mem_value)
{
    int x;
    unsigned val = mem_value;
    uint8_t *dst;

2009
    dst = s->vga.vram_ptr + (offset &= s->cirrus_addr_mask);
2010 2011
    for (x = 0; x < 8; x++) {
	if (val & 0x80) {
B
bellard 已提交
2012
	    *dst = s->cirrus_shadow_gr1;
2013
	} else if (mode == 5) {
B
bellard 已提交
2014
	    *dst = s->cirrus_shadow_gr0;
2015 2016
	}
	val <<= 1;
B
bellard 已提交
2017
	dst++;
2018
    }
2019
    memory_region_set_dirty(&s->vga.vram, offset, 8);
2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030
}

static void cirrus_mem_writeb_mode4and5_16bpp(CirrusVGAState * s,
					      unsigned mode,
					      unsigned offset,
					      uint32_t mem_value)
{
    int x;
    unsigned val = mem_value;
    uint8_t *dst;

2031
    dst = s->vga.vram_ptr + (offset &= s->cirrus_addr_mask);
2032 2033
    for (x = 0; x < 8; x++) {
	if (val & 0x80) {
B
bellard 已提交
2034
	    *dst = s->cirrus_shadow_gr1;
2035
	    *(dst + 1) = s->vga.gr[0x11];
2036
	} else if (mode == 5) {
B
bellard 已提交
2037
	    *dst = s->cirrus_shadow_gr0;
2038
	    *(dst + 1) = s->vga.gr[0x10];
2039 2040
	}
	val <<= 1;
B
bellard 已提交
2041
	dst += 2;
2042
    }
2043
    memory_region_set_dirty(&s->vga.vram, offset, 16);
2044 2045 2046 2047 2048 2049 2050 2051
}

/***************************************
 *
 *  memory access between 0xa0000-0xbffff
 *
 ***************************************/

2052
static uint64_t cirrus_vga_mem_read(void *opaque,
A
Avi Kivity 已提交
2053
                                    hwaddr addr,
2054
                                    uint32_t size)
2055 2056 2057 2058 2059 2060
{
    CirrusVGAState *s = opaque;
    unsigned bank_index;
    unsigned bank_offset;
    uint32_t val;

2061
    if ((s->vga.sr[0x07] & 0x01) == 0) {
2062
        return vga_mem_readb(&s->vga, addr);
2063 2064 2065 2066 2067 2068 2069 2070 2071
    }

    if (addr < 0x10000) {
	/* XXX handle bitblt */
	/* video memory */
	bank_index = addr >> 15;
	bank_offset = addr & 0x7fff;
	if (bank_offset < s->cirrus_bank_limit[bank_index]) {
	    bank_offset += s->cirrus_bank_base[bank_index];
2072
	    if ((s->vga.gr[0x0B] & 0x14) == 0x14) {
2073
		bank_offset <<= 4;
2074
	    } else if (s->vga.gr[0x0B] & 0x02) {
2075 2076 2077
		bank_offset <<= 3;
	    }
	    bank_offset &= s->cirrus_addr_mask;
2078
	    val = *(s->vga.vram_ptr + bank_offset);
2079 2080 2081 2082 2083
	} else
	    val = 0xff;
    } else if (addr >= 0x18000 && addr < 0x18100) {
	/* memory-mapped I/O */
	val = 0xff;
2084
	if ((s->vga.sr[0x17] & 0x44) == 0x04) {
2085 2086 2087 2088 2089
	    val = cirrus_mmio_blt_read(s, addr & 0xff);
	}
    } else {
	val = 0xff;
#ifdef DEBUG_CIRRUS
2090
	printf("cirrus: mem_readb " TARGET_FMT_plx "\n", addr);
2091 2092 2093 2094 2095
#endif
    }
    return val;
}

2096
static void cirrus_vga_mem_write(void *opaque,
A
Avi Kivity 已提交
2097
                                 hwaddr addr,
2098 2099
                                 uint64_t mem_value,
                                 uint32_t size)
2100 2101 2102 2103 2104 2105
{
    CirrusVGAState *s = opaque;
    unsigned bank_index;
    unsigned bank_offset;
    unsigned mode;

2106
    if ((s->vga.sr[0x07] & 0x01) == 0) {
2107
        vga_mem_writeb(&s->vga, addr, mem_value);
2108 2109 2110 2111 2112 2113 2114
        return;
    }

    if (addr < 0x10000) {
	if (s->cirrus_srcptr != s->cirrus_srcptr_end) {
	    /* bitblt */
	    *s->cirrus_srcptr++ = (uint8_t) mem_value;
2115
	    if (s->cirrus_srcptr >= s->cirrus_srcptr_end) {
2116 2117 2118 2119 2120 2121 2122 2123
		cirrus_bitblt_cputovideo_next(s);
	    }
	} else {
	    /* video memory */
	    bank_index = addr >> 15;
	    bank_offset = addr & 0x7fff;
	    if (bank_offset < s->cirrus_bank_limit[bank_index]) {
		bank_offset += s->cirrus_bank_base[bank_index];
2124
		if ((s->vga.gr[0x0B] & 0x14) == 0x14) {
2125
		    bank_offset <<= 4;
2126
		} else if (s->vga.gr[0x0B] & 0x02) {
2127 2128 2129
		    bank_offset <<= 3;
		}
		bank_offset &= s->cirrus_addr_mask;
2130 2131 2132
		mode = s->vga.gr[0x05] & 0x7;
		if (mode < 4 || mode > 5 || ((s->vga.gr[0x0B] & 0x4) == 0)) {
		    *(s->vga.vram_ptr + bank_offset) = mem_value;
2133 2134
                    memory_region_set_dirty(&s->vga.vram, bank_offset,
                                            sizeof(mem_value));
2135
		} else {
2136
		    if ((s->vga.gr[0x0B] & 0x14) != 0x14) {
2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149
			cirrus_mem_writeb_mode4and5_8bpp(s, mode,
							 bank_offset,
							 mem_value);
		    } else {
			cirrus_mem_writeb_mode4and5_16bpp(s, mode,
							  bank_offset,
							  mem_value);
		    }
		}
	    }
	}
    } else if (addr >= 0x18000 && addr < 0x18100) {
	/* memory-mapped I/O */
2150
	if ((s->vga.sr[0x17] & 0x44) == 0x04) {
2151 2152 2153 2154
	    cirrus_mmio_blt_write(s, addr & 0xff, mem_value);
	}
    } else {
#ifdef DEBUG_CIRRUS
2155
        printf("cirrus: mem_writeb " TARGET_FMT_plx " value 0x%02" PRIu64 "\n", addr,
2156
               mem_value);
2157 2158 2159 2160
#endif
    }
}

2161 2162 2163 2164
static const MemoryRegionOps cirrus_vga_mem_ops = {
    .read = cirrus_vga_mem_read,
    .write = cirrus_vga_mem_write,
    .endianness = DEVICE_LITTLE_ENDIAN,
2165 2166 2167 2168
    .impl = {
        .min_access_size = 1,
        .max_access_size = 1,
    },
2169 2170
};

2171 2172 2173 2174 2175 2176 2177 2178 2179
/***************************************
 *
 *  hardware cursor
 *
 ***************************************/

static inline void invalidate_cursor1(CirrusVGAState *s)
{
    if (s->last_hw_cursor_size) {
2180
        vga_invalidate_scanlines(&s->vga,
2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191
                                 s->last_hw_cursor_y + s->last_hw_cursor_y_start,
                                 s->last_hw_cursor_y + s->last_hw_cursor_y_end);
    }
}

static inline void cirrus_cursor_compute_yrange(CirrusVGAState *s)
{
    const uint8_t *src;
    uint32_t content;
    int y, y_min, y_max;

2192 2193 2194
    src = s->vga.vram_ptr + s->real_vram_size - 16 * 1024;
    if (s->vga.sr[0x12] & CIRRUS_CURSOR_LARGE) {
        src += (s->vga.sr[0x13] & 0x3c) * 256;
2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210
        y_min = 64;
        y_max = -1;
        for(y = 0; y < 64; y++) {
            content = ((uint32_t *)src)[0] |
                ((uint32_t *)src)[1] |
                ((uint32_t *)src)[2] |
                ((uint32_t *)src)[3];
            if (content) {
                if (y < y_min)
                    y_min = y;
                if (y > y_max)
                    y_max = y;
            }
            src += 16;
        }
    } else {
2211
        src += (s->vga.sr[0x13] & 0x3f) * 256;
2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236
        y_min = 32;
        y_max = -1;
        for(y = 0; y < 32; y++) {
            content = ((uint32_t *)src)[0] |
                ((uint32_t *)(src + 128))[0];
            if (content) {
                if (y < y_min)
                    y_min = y;
                if (y > y_max)
                    y_max = y;
            }
            src += 4;
        }
    }
    if (y_min > y_max) {
        s->last_hw_cursor_y_start = 0;
        s->last_hw_cursor_y_end = 0;
    } else {
        s->last_hw_cursor_y_start = y_min;
        s->last_hw_cursor_y_end = y_max + 1;
    }
}

/* NOTE: we do not currently handle the cursor bitmap change, so we
   update the cursor only if it moves. */
2237
static void cirrus_cursor_invalidate(VGACommonState *s1)
2238
{
2239
    CirrusVGAState *s = container_of(s1, CirrusVGAState, vga);
2240 2241
    int size;

2242
    if (!(s->vga.sr[0x12] & CIRRUS_CURSOR_SHOW)) {
2243 2244
        size = 0;
    } else {
2245
        if (s->vga.sr[0x12] & CIRRUS_CURSOR_LARGE)
2246 2247 2248 2249 2250 2251
            size = 64;
        else
            size = 32;
    }
    /* invalidate last cursor and new cursor if any change */
    if (s->last_hw_cursor_size != size ||
2252 2253
        s->last_hw_cursor_x != s->vga.hw_cursor_x ||
        s->last_hw_cursor_y != s->vga.hw_cursor_y) {
2254 2255

        invalidate_cursor1(s);
2256

2257
        s->last_hw_cursor_size = size;
2258 2259
        s->last_hw_cursor_x = s->vga.hw_cursor_x;
        s->last_hw_cursor_y = s->vga.hw_cursor_y;
2260 2261 2262 2263 2264 2265
        /* compute the real cursor min and max y */
        cirrus_cursor_compute_yrange(s);
        invalidate_cursor1(s);
    }
}

2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298
static void vga_draw_cursor_line(uint8_t *d1,
                                 const uint8_t *src1,
                                 int poffset, int w,
                                 unsigned int color0,
                                 unsigned int color1,
                                 unsigned int color_xor)
{
    const uint8_t *plane0, *plane1;
    int x, b0, b1;
    uint8_t *d;

    d = d1;
    plane0 = src1;
    plane1 = src1 + poffset;
    for (x = 0; x < w; x++) {
        b0 = (plane0[x >> 3] >> (7 - (x & 7))) & 1;
        b1 = (plane1[x >> 3] >> (7 - (x & 7))) & 1;
        switch (b0 | (b1 << 1)) {
        case 0:
            break;
        case 1:
            ((uint32_t *)d)[0] ^= color_xor;
            break;
        case 2:
            ((uint32_t *)d)[0] = color0;
            break;
        case 3:
            ((uint32_t *)d)[0] = color1;
            break;
        }
        d += 4;
    }
}
2299

2300
static void cirrus_cursor_draw_line(VGACommonState *s1, uint8_t *d1, int scr_y)
2301
{
2302
    CirrusVGAState *s = container_of(s1, CirrusVGAState, vga);
2303
    int w, h, x1, x2, poffset;
2304 2305 2306
    unsigned int color0, color1;
    const uint8_t *palette, *src;
    uint32_t content;
2307

2308
    if (!(s->vga.sr[0x12] & CIRRUS_CURSOR_SHOW))
2309 2310
        return;
    /* fast test to see if the cursor intersects with the scan line */
2311
    if (s->vga.sr[0x12] & CIRRUS_CURSOR_LARGE) {
2312 2313 2314 2315
        h = 64;
    } else {
        h = 32;
    }
2316 2317
    if (scr_y < s->vga.hw_cursor_y ||
        scr_y >= (s->vga.hw_cursor_y + h)) {
2318
        return;
2319
    }
2320

2321 2322 2323
    src = s->vga.vram_ptr + s->real_vram_size - 16 * 1024;
    if (s->vga.sr[0x12] & CIRRUS_CURSOR_LARGE) {
        src += (s->vga.sr[0x13] & 0x3c) * 256;
2324
        src += (scr_y - s->vga.hw_cursor_y) * 16;
2325 2326 2327 2328 2329 2330
        poffset = 8;
        content = ((uint32_t *)src)[0] |
            ((uint32_t *)src)[1] |
            ((uint32_t *)src)[2] |
            ((uint32_t *)src)[3];
    } else {
2331
        src += (s->vga.sr[0x13] & 0x3f) * 256;
2332
        src += (scr_y - s->vga.hw_cursor_y) * 4;
2333 2334


2335 2336 2337 2338 2339 2340 2341 2342 2343
        poffset = 128;
        content = ((uint32_t *)src)[0] |
            ((uint32_t *)(src + 128))[0];
    }
    /* if nothing to draw, no need to continue */
    if (!content)
        return;
    w = h;

2344
    x1 = s->vga.hw_cursor_x;
2345
    if (x1 >= s->vga.last_scr_width)
2346
        return;
2347
    x2 = s->vga.hw_cursor_x + w;
2348 2349
    if (x2 > s->vga.last_scr_width)
        x2 = s->vga.last_scr_width;
2350 2351
    w = x2 - x1;
    palette = s->cirrus_hidden_palette;
2352 2353 2354 2355 2356 2357
    color0 = rgb_to_pixel32(c6_to_8(palette[0x0 * 3]),
                            c6_to_8(palette[0x0 * 3 + 1]),
                            c6_to_8(palette[0x0 * 3 + 2]));
    color1 = rgb_to_pixel32(c6_to_8(palette[0xf * 3]),
                            c6_to_8(palette[0xf * 3 + 1]),
                            c6_to_8(palette[0xf * 3 + 2]));
2358 2359
    d1 += x1 * 4;
    vga_draw_cursor_line(d1, src, poffset, w, color0, color1, 0xffffff);
2360 2361
}

2362 2363 2364 2365 2366 2367
/***************************************
 *
 *  LFB memory access
 *
 ***************************************/

A
Avi Kivity 已提交
2368
static uint64_t cirrus_linear_read(void *opaque, hwaddr addr,
2369
                                   unsigned size)
2370
{
2371
    CirrusVGAState *s = opaque;
2372 2373 2374 2375
    uint32_t ret;

    addr &= s->cirrus_addr_mask;

2376
    if (((s->vga.sr[0x17] & 0x44) == 0x44) &&
2377
        ((addr & s->linear_mmio_mask) == s->linear_mmio_mask)) {
2378 2379 2380 2381 2382 2383 2384
	/* memory-mapped I/O */
	ret = cirrus_mmio_blt_read(s, addr & 0xff);
    } else if (0) {
	/* XXX handle bitblt */
	ret = 0xff;
    } else {
	/* video memory */
2385
	if ((s->vga.gr[0x0B] & 0x14) == 0x14) {
2386
	    addr <<= 4;
2387
	} else if (s->vga.gr[0x0B] & 0x02) {
2388 2389 2390
	    addr <<= 3;
	}
	addr &= s->cirrus_addr_mask;
2391
	ret = *(s->vga.vram_ptr + addr);
2392 2393 2394 2395 2396
    }

    return ret;
}

A
Avi Kivity 已提交
2397
static void cirrus_linear_write(void *opaque, hwaddr addr,
2398
                                uint64_t val, unsigned size)
2399
{
2400
    CirrusVGAState *s = opaque;
2401 2402 2403
    unsigned mode;

    addr &= s->cirrus_addr_mask;
2404

2405
    if (((s->vga.sr[0x17] & 0x44) == 0x44) &&
2406
        ((addr & s->linear_mmio_mask) ==  s->linear_mmio_mask)) {
2407 2408 2409 2410 2411
	/* memory-mapped I/O */
	cirrus_mmio_blt_write(s, addr & 0xff, val);
    } else if (s->cirrus_srcptr != s->cirrus_srcptr_end) {
	/* bitblt */
	*s->cirrus_srcptr++ = (uint8_t) val;
2412
	if (s->cirrus_srcptr >= s->cirrus_srcptr_end) {
2413 2414 2415 2416
	    cirrus_bitblt_cputovideo_next(s);
	}
    } else {
	/* video memory */
2417
	if ((s->vga.gr[0x0B] & 0x14) == 0x14) {
2418
	    addr <<= 4;
2419
	} else if (s->vga.gr[0x0B] & 0x02) {
2420 2421 2422 2423
	    addr <<= 3;
	}
	addr &= s->cirrus_addr_mask;

2424 2425 2426
	mode = s->vga.gr[0x05] & 0x7;
	if (mode < 4 || mode > 5 || ((s->vga.gr[0x0B] & 0x4) == 0)) {
	    *(s->vga.vram_ptr + addr) = (uint8_t) val;
2427
            memory_region_set_dirty(&s->vga.vram, addr, 1);
2428
	} else {
2429
	    if ((s->vga.gr[0x0B] & 0x14) != 0x14) {
2430 2431 2432 2433 2434 2435 2436 2437
		cirrus_mem_writeb_mode4and5_8bpp(s, mode, addr, val);
	    } else {
		cirrus_mem_writeb_mode4and5_16bpp(s, mode, addr, val);
	    }
	}
    }
}

2438 2439 2440 2441 2442 2443 2444
/***************************************
 *
 *  system to screen memory access
 *
 ***************************************/


2445
static uint64_t cirrus_linear_bitblt_read(void *opaque,
A
Avi Kivity 已提交
2446
                                          hwaddr addr,
2447
                                          unsigned size)
2448
{
2449
    CirrusVGAState *s = opaque;
2450 2451 2452
    uint32_t ret;

    /* XXX handle bitblt */
2453
    (void)s;
2454 2455 2456 2457
    ret = 0xff;
    return ret;
}

2458
static void cirrus_linear_bitblt_write(void *opaque,
A
Avi Kivity 已提交
2459
                                       hwaddr addr,
2460 2461
                                       uint64_t val,
                                       unsigned size)
2462
{
2463
    CirrusVGAState *s = opaque;
2464 2465 2466 2467 2468 2469 2470 2471 2472 2473

    if (s->cirrus_srcptr != s->cirrus_srcptr_end) {
	/* bitblt */
	*s->cirrus_srcptr++ = (uint8_t) val;
	if (s->cirrus_srcptr >= s->cirrus_srcptr_end) {
	    cirrus_bitblt_cputovideo_next(s);
	}
    }
}

2474 2475 2476 2477
static const MemoryRegionOps cirrus_linear_bitblt_io_ops = {
    .read = cirrus_linear_bitblt_read,
    .write = cirrus_linear_bitblt_write,
    .endianness = DEVICE_LITTLE_ENDIAN,
2478 2479 2480 2481
    .impl = {
        .min_access_size = 1,
        .max_access_size = 1,
    },
2482 2483
};

2484 2485
static void map_linear_vram_bank(CirrusVGAState *s, unsigned bank)
{
2486 2487
    MemoryRegion *mr = &s->cirrus_bank[bank];
    bool enabled = !(s->cirrus_srcptr != s->cirrus_srcptr_end)
2488 2489
        && !((s->vga.sr[0x07] & 0x01) == 0)
        && !((s->vga.gr[0x0B] & 0x14) == 0x14)
2490 2491 2492 2493
        && !(s->vga.gr[0x0B] & 0x02);

    memory_region_set_enabled(mr, enabled);
    memory_region_set_alias_offset(mr, s->cirrus_bank_base[bank]);
2494
}
A
aliguori 已提交
2495

2496 2497
static void map_linear_vram(CirrusVGAState *s)
{
J
Jan Kiszka 已提交
2498
    if (s->bustype == CIRRUS_BUSTYPE_PCI && !s->linear_vram) {
2499 2500 2501 2502 2503
        s->linear_vram = true;
        memory_region_add_subregion_overlap(&s->pci_bar, 0, &s->vga.vram, 1);
    }
    map_linear_vram_bank(s, 0);
    map_linear_vram_bank(s, 1);
A
aliguori 已提交
2504 2505 2506 2507
}

static void unmap_linear_vram(CirrusVGAState *s)
{
J
Jan Kiszka 已提交
2508
    if (s->bustype == CIRRUS_BUSTYPE_PCI && s->linear_vram) {
2509 2510
        s->linear_vram = false;
        memory_region_del_subregion(&s->pci_bar, &s->vga.vram);
2511
    }
2512 2513
    memory_region_set_enabled(&s->cirrus_bank[0], false);
    memory_region_set_enabled(&s->cirrus_bank[1], false);
A
aliguori 已提交
2514 2515
}

B
bellard 已提交
2516 2517 2518 2519 2520
/* Compute the memory access functions */
static void cirrus_update_memory_access(CirrusVGAState *s)
{
    unsigned mode;

2521
    memory_region_transaction_begin();
2522
    if ((s->vga.sr[0x17] & 0x44) == 0x44) {
B
bellard 已提交
2523 2524 2525 2526
        goto generic_io;
    } else if (s->cirrus_srcptr != s->cirrus_srcptr_end) {
        goto generic_io;
    } else {
2527
	if ((s->vga.gr[0x0B] & 0x14) == 0x14) {
B
bellard 已提交
2528
            goto generic_io;
2529
	} else if (s->vga.gr[0x0B] & 0x02) {
B
bellard 已提交
2530 2531
            goto generic_io;
        }
2532

2533 2534
	mode = s->vga.gr[0x05] & 0x7;
	if (mode < 4 || mode > 5 || ((s->vga.gr[0x0B] & 0x4) == 0)) {
A
aliguori 已提交
2535
            map_linear_vram(s);
B
bellard 已提交
2536 2537
        } else {
        generic_io:
A
aliguori 已提交
2538
            unmap_linear_vram(s);
B
bellard 已提交
2539 2540
        }
    }
2541
    memory_region_transaction_commit();
B
bellard 已提交
2542 2543 2544
}


2545 2546
/* I/O ports */

2547 2548
static uint64_t cirrus_vga_ioport_read(void *opaque, hwaddr addr,
                                       unsigned size)
2549
{
2550 2551
    CirrusVGAState *c = opaque;
    VGACommonState *s = &c->vga;
2552 2553
    int val, index;

2554
    addr += 0x3b0;
2555

2556
    if (vga_ioport_invalid(s, addr)) {
2557 2558 2559 2560
	val = 0xff;
    } else {
	switch (addr) {
	case 0x3c0:
2561 2562
	    if (s->ar_flip_flop == 0) {
		val = s->ar_index;
2563 2564 2565 2566 2567
	    } else {
		val = 0;
	    }
	    break;
	case 0x3c1:
2568
	    index = s->ar_index & 0x1f;
2569
	    if (index < 21)
2570
		val = s->ar[index];
2571 2572 2573 2574
	    else
		val = 0;
	    break;
	case 0x3c2:
2575
	    val = s->st00;
2576 2577
	    break;
	case 0x3c4:
2578
	    val = s->sr_index;
2579 2580
	    break;
	case 0x3c5:
2581 2582
	    val = cirrus_vga_read_sr(c);
            break;
2583
#ifdef DEBUG_VGA_REG
2584
	    printf("vga: read SR%x = 0x%02x\n", s->sr_index, val);
2585 2586 2587
#endif
	    break;
	case 0x3c6:
2588
	    val = cirrus_read_hidden_dac(c);
2589 2590
	    break;
	case 0x3c7:
2591
	    val = s->dac_state;
2592
	    break;
2593
	case 0x3c8:
2594 2595
	    val = s->dac_write_index;
	    c->cirrus_hidden_dac_lockindex = 0;
2596 2597
	    break;
        case 0x3c9:
2598 2599
            val = cirrus_vga_read_palette(c);
            break;
2600
	case 0x3ca:
2601
	    val = s->fcr;
2602 2603
	    break;
	case 0x3cc:
2604
	    val = s->msr;
2605 2606
	    break;
	case 0x3ce:
2607
	    val = s->gr_index;
2608 2609
	    break;
	case 0x3cf:
2610
	    val = cirrus_vga_read_gr(c, s->gr_index);
2611
#ifdef DEBUG_VGA_REG
2612
	    printf("vga: read GR%x = 0x%02x\n", s->gr_index, val);
2613 2614 2615 2616
#endif
	    break;
	case 0x3b4:
	case 0x3d4:
2617
	    val = s->cr_index;
2618 2619 2620
	    break;
	case 0x3b5:
	case 0x3d5:
2621
            val = cirrus_vga_read_cr(c, s->cr_index);
2622
#ifdef DEBUG_VGA_REG
2623
	    printf("vga: read CR%x = 0x%02x\n", s->cr_index, val);
2624 2625 2626 2627 2628
#endif
	    break;
	case 0x3ba:
	case 0x3da:
	    /* just toggle to fool polling */
2629 2630
	    val = s->st01 = s->retrace(s);
	    s->ar_flip_flop = 0;
2631 2632 2633 2634 2635 2636
	    break;
	default:
	    val = 0x00;
	    break;
	}
    }
2637
    trace_vga_cirrus_read_io(addr, val);
2638 2639 2640
    return val;
}

2641 2642
static void cirrus_vga_ioport_write(void *opaque, hwaddr addr, uint64_t val,
                                    unsigned size)
2643
{
2644 2645
    CirrusVGAState *c = opaque;
    VGACommonState *s = &c->vga;
2646 2647
    int index;

2648
    addr += 0x3b0;
2649

2650
    /* check port range access depending on color/monochrome mode */
2651
    if (vga_ioport_invalid(s, addr)) {
2652
	return;
2653
    }
2654
    trace_vga_cirrus_write_io(addr, val);
2655 2656 2657

    switch (addr) {
    case 0x3c0:
2658
	if (s->ar_flip_flop == 0) {
2659
	    val &= 0x3f;
2660
	    s->ar_index = val;
2661
	} else {
2662
	    index = s->ar_index & 0x1f;
2663 2664
	    switch (index) {
	    case 0x00 ... 0x0f:
2665
		s->ar[index] = val & 0x3f;
2666 2667
		break;
	    case 0x10:
2668
		s->ar[index] = val & ~0x10;
2669 2670
		break;
	    case 0x11:
2671
		s->ar[index] = val;
2672 2673
		break;
	    case 0x12:
2674
		s->ar[index] = val & ~0xc0;
2675 2676
		break;
	    case 0x13:
2677
		s->ar[index] = val & ~0xf0;
2678 2679
		break;
	    case 0x14:
2680
		s->ar[index] = val & ~0xf0;
2681 2682 2683 2684 2685
		break;
	    default:
		break;
	    }
	}
2686
	s->ar_flip_flop ^= 1;
2687 2688
	break;
    case 0x3c2:
2689 2690
	s->msr = val & ~0x10;
	s->update_retrace_info(s);
2691 2692
	break;
    case 0x3c4:
2693
	s->sr_index = val;
2694 2695 2696
	break;
    case 0x3c5:
#ifdef DEBUG_VGA_REG
2697
	printf("vga: write SR%x = 0x%02" PRIu64 "\n", s->sr_index, val);
2698
#endif
2699 2700
	cirrus_vga_write_sr(c, val);
        break;
2701
    case 0x3c6:
2702
	cirrus_write_hidden_dac(c, val);
2703 2704
	break;
    case 0x3c7:
2705 2706 2707
	s->dac_read_index = val;
	s->dac_sub_index = 0;
	s->dac_state = 3;
2708 2709
	break;
    case 0x3c8:
2710 2711 2712
	s->dac_write_index = val;
	s->dac_sub_index = 0;
	s->dac_state = 0;
2713 2714
	break;
    case 0x3c9:
2715 2716
        cirrus_vga_write_palette(c, val);
        break;
2717
    case 0x3ce:
2718
	s->gr_index = val;
2719 2720 2721
	break;
    case 0x3cf:
#ifdef DEBUG_VGA_REG
2722
	printf("vga: write GR%x = 0x%02" PRIu64 "\n", s->gr_index, val);
2723
#endif
2724
	cirrus_vga_write_gr(c, s->gr_index, val);
2725 2726 2727
	break;
    case 0x3b4:
    case 0x3d4:
2728
	s->cr_index = val;
2729 2730 2731 2732
	break;
    case 0x3b5:
    case 0x3d5:
#ifdef DEBUG_VGA_REG
2733
	printf("vga: write CR%x = 0x%02"PRIu64"\n", s->cr_index, val);
2734
#endif
2735
	cirrus_vga_write_cr(c, val);
2736 2737 2738
	break;
    case 0x3ba:
    case 0x3da:
2739
	s->fcr = val & 0x10;
2740 2741 2742 2743
	break;
    }
}

2744 2745 2746 2747 2748 2749
/***************************************
 *
 *  memory-mapped I/O access
 *
 ***************************************/

A
Avi Kivity 已提交
2750
static uint64_t cirrus_mmio_read(void *opaque, hwaddr addr,
2751
                                 unsigned size)
2752
{
2753
    CirrusVGAState *s = opaque;
2754 2755 2756 2757

    if (addr >= 0x100) {
        return cirrus_mmio_blt_read(s, addr - 0x100);
    } else {
2758
        return cirrus_vga_ioport_read(s, addr + 0x10, size);
2759 2760 2761
    }
}

A
Avi Kivity 已提交
2762
static void cirrus_mmio_write(void *opaque, hwaddr addr,
2763
                              uint64_t val, unsigned size)
2764
{
2765
    CirrusVGAState *s = opaque;
2766 2767 2768 2769

    if (addr >= 0x100) {
	cirrus_mmio_blt_write(s, addr - 0x100, val);
    } else {
2770
        cirrus_vga_ioport_write(s, addr + 0x10, val, size);
2771 2772 2773
    }
}

2774 2775 2776 2777
static const MemoryRegionOps cirrus_mmio_io_ops = {
    .read = cirrus_mmio_read,
    .write = cirrus_mmio_write,
    .endianness = DEVICE_LITTLE_ENDIAN,
2778 2779 2780 2781
    .impl = {
        .min_access_size = 1,
        .max_access_size = 1,
    },
2782 2783
};

B
bellard 已提交
2784 2785
/* load/save state */

2786
static int cirrus_post_load(void *opaque, int version_id)
B
bellard 已提交
2787 2788 2789
{
    CirrusVGAState *s = opaque;

2790 2791
    s->vga.gr[0x00] = s->cirrus_shadow_gr0 & 0x0f;
    s->vga.gr[0x01] = s->cirrus_shadow_gr1 & 0x0f;
B
bellard 已提交
2792

A
aliguori 已提交
2793
    cirrus_update_memory_access(s);
B
bellard 已提交
2794
    /* force refresh */
2795
    s->vga.graphic_mode = -1;
B
bellard 已提交
2796 2797 2798 2799 2800
    cirrus_update_bank_ptr(s, 0);
    cirrus_update_bank_ptr(s, 1);
    return 0;
}

J
Juan Quintela 已提交
2801 2802 2803 2804 2805
static const VMStateDescription vmstate_cirrus_vga = {
    .name = "cirrus_vga",
    .version_id = 2,
    .minimum_version_id = 1,
    .post_load = cirrus_post_load,
2806
    .fields = (VMStateField[]) {
J
Juan Quintela 已提交
2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831
        VMSTATE_UINT32(vga.latch, CirrusVGAState),
        VMSTATE_UINT8(vga.sr_index, CirrusVGAState),
        VMSTATE_BUFFER(vga.sr, CirrusVGAState),
        VMSTATE_UINT8(vga.gr_index, CirrusVGAState),
        VMSTATE_UINT8(cirrus_shadow_gr0, CirrusVGAState),
        VMSTATE_UINT8(cirrus_shadow_gr1, CirrusVGAState),
        VMSTATE_BUFFER_START_MIDDLE(vga.gr, CirrusVGAState, 2),
        VMSTATE_UINT8(vga.ar_index, CirrusVGAState),
        VMSTATE_BUFFER(vga.ar, CirrusVGAState),
        VMSTATE_INT32(vga.ar_flip_flop, CirrusVGAState),
        VMSTATE_UINT8(vga.cr_index, CirrusVGAState),
        VMSTATE_BUFFER(vga.cr, CirrusVGAState),
        VMSTATE_UINT8(vga.msr, CirrusVGAState),
        VMSTATE_UINT8(vga.fcr, CirrusVGAState),
        VMSTATE_UINT8(vga.st00, CirrusVGAState),
        VMSTATE_UINT8(vga.st01, CirrusVGAState),
        VMSTATE_UINT8(vga.dac_state, CirrusVGAState),
        VMSTATE_UINT8(vga.dac_sub_index, CirrusVGAState),
        VMSTATE_UINT8(vga.dac_read_index, CirrusVGAState),
        VMSTATE_UINT8(vga.dac_write_index, CirrusVGAState),
        VMSTATE_BUFFER(vga.dac_cache, CirrusVGAState),
        VMSTATE_BUFFER(vga.palette, CirrusVGAState),
        VMSTATE_INT32(vga.bank_offset, CirrusVGAState),
        VMSTATE_UINT8(cirrus_hidden_dac_lockindex, CirrusVGAState),
        VMSTATE_UINT8(cirrus_hidden_dac_data, CirrusVGAState),
2832 2833
        VMSTATE_UINT32(vga.hw_cursor_x, CirrusVGAState),
        VMSTATE_UINT32(vga.hw_cursor_y, CirrusVGAState),
J
Juan Quintela 已提交
2834 2835 2836
        /* XXX: we do not save the bitblt state - we assume we do not save
           the state when the blitter is active */
        VMSTATE_END_OF_LIST()
2837
    }
J
Juan Quintela 已提交
2838
};
2839

J
Juan Quintela 已提交
2840 2841 2842 2843
static const VMStateDescription vmstate_pci_cirrus_vga = {
    .name = "cirrus_vga",
    .version_id = 2,
    .minimum_version_id = 2,
2844
    .fields = (VMStateField[]) {
J
Juan Quintela 已提交
2845 2846 2847 2848 2849 2850
        VMSTATE_PCI_DEVICE(dev, PCICirrusVGAState),
        VMSTATE_STRUCT(cirrus_vga, PCICirrusVGAState, 0,
                       vmstate_cirrus_vga, CirrusVGAState),
        VMSTATE_END_OF_LIST()
    }
};
2851

2852 2853 2854 2855 2856 2857
/***************************************
 *
 *  initialize
 *
 ***************************************/

B
blueswir1 已提交
2858
static void cirrus_reset(void *opaque)
2859
{
B
blueswir1 已提交
2860
    CirrusVGAState *s = opaque;
2861

2862
    vga_common_reset(&s->vga);
2863
    unmap_linear_vram(s);
2864
    s->vga.sr[0x06] = 0x0f;
B
blueswir1 已提交
2865
    if (s->device_id == CIRRUS_ID_CLGD5446) {
2866
        /* 4MB 64 bit memory config, always PCI */
2867 2868 2869 2870 2871
        s->vga.sr[0x1F] = 0x2d;		// MemClock
        s->vga.gr[0x18] = 0x0f;             // fastest memory configuration
        s->vga.sr[0x0f] = 0x98;
        s->vga.sr[0x17] = 0x20;
        s->vga.sr[0x15] = 0x04; /* memory size, 3=2MB, 4=4MB */
2872
    } else {
2873 2874 2875 2876
        s->vga.sr[0x1F] = 0x22;		// MemClock
        s->vga.sr[0x0F] = CIRRUS_MEMSIZE_2M;
        s->vga.sr[0x17] = s->bustype;
        s->vga.sr[0x15] = 0x03; /* memory size, 3=2MB, 4=4MB */
2877
    }
2878
    s->vga.cr[0x27] = s->device_id;
2879 2880 2881

    s->cirrus_hidden_dac_lockindex = 5;
    s->cirrus_hidden_dac_data = 0;
B
blueswir1 已提交
2882 2883
}

2884 2885 2886 2887
static const MemoryRegionOps cirrus_linear_io_ops = {
    .read = cirrus_linear_read,
    .write = cirrus_linear_write,
    .endianness = DEVICE_LITTLE_ENDIAN,
2888 2889 2890 2891
    .impl = {
        .min_access_size = 1,
        .max_access_size = 1,
    },
2892 2893
};

2894 2895 2896 2897 2898 2899 2900 2901 2902 2903
static const MemoryRegionOps cirrus_vga_io_ops = {
    .read = cirrus_vga_ioport_read,
    .write = cirrus_vga_ioport_write,
    .endianness = DEVICE_LITTLE_ENDIAN,
    .impl = {
        .min_access_size = 1,
        .max_access_size = 1,
    },
};

2904 2905
static void cirrus_init_common(CirrusVGAState *s, Object *owner,
                               int device_id, int is_pci,
2906 2907
                               MemoryRegion *system_memory,
                               MemoryRegion *system_io)
B
blueswir1 已提交
2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938
{
    int i;
    static int inited;

    if (!inited) {
        inited = 1;
        for(i = 0;i < 256; i++)
            rop_to_index[i] = CIRRUS_ROP_NOP_INDEX; /* nop rop */
        rop_to_index[CIRRUS_ROP_0] = 0;
        rop_to_index[CIRRUS_ROP_SRC_AND_DST] = 1;
        rop_to_index[CIRRUS_ROP_NOP] = 2;
        rop_to_index[CIRRUS_ROP_SRC_AND_NOTDST] = 3;
        rop_to_index[CIRRUS_ROP_NOTDST] = 4;
        rop_to_index[CIRRUS_ROP_SRC] = 5;
        rop_to_index[CIRRUS_ROP_1] = 6;
        rop_to_index[CIRRUS_ROP_NOTSRC_AND_DST] = 7;
        rop_to_index[CIRRUS_ROP_SRC_XOR_DST] = 8;
        rop_to_index[CIRRUS_ROP_SRC_OR_DST] = 9;
        rop_to_index[CIRRUS_ROP_NOTSRC_OR_NOTDST] = 10;
        rop_to_index[CIRRUS_ROP_SRC_NOTXOR_DST] = 11;
        rop_to_index[CIRRUS_ROP_SRC_OR_NOTDST] = 12;
        rop_to_index[CIRRUS_ROP_NOTSRC] = 13;
        rop_to_index[CIRRUS_ROP_NOTSRC_OR_DST] = 14;
        rop_to_index[CIRRUS_ROP_NOTSRC_AND_NOTDST] = 15;
        s->device_id = device_id;
        if (is_pci)
            s->bustype = CIRRUS_BUSTYPE_PCI;
        else
            s->bustype = CIRRUS_BUSTYPE_ISA;
    }

2939
    /* Register ioport 0x3b0 - 0x3df */
2940
    memory_region_init_io(&s->cirrus_vga_io, owner, &cirrus_vga_io_ops, s,
2941
                          "cirrus-io", 0x30);
2942
    memory_region_set_flush_coalesced(&s->cirrus_vga_io);
2943
    memory_region_add_subregion(system_io, 0x3b0, &s->cirrus_vga_io);
B
blueswir1 已提交
2944

2945
    memory_region_init(&s->low_mem_container, owner,
2946 2947 2948
                       "cirrus-lowmem-container",
                       0x20000);

2949
    memory_region_init_io(&s->low_mem, owner, &cirrus_vga_mem_ops, s,
2950 2951
                          "cirrus-low-memory", 0x20000);
    memory_region_add_subregion(&s->low_mem_container, 0, &s->low_mem);
2952 2953 2954
    for (i = 0; i < 2; ++i) {
        static const char *names[] = { "vga.bank0", "vga.bank1" };
        MemoryRegion *bank = &s->cirrus_bank[i];
2955 2956
        memory_region_init_alias(bank, owner, names[i], &s->vga.vram,
                                 0, 0x8000);
2957 2958 2959 2960
        memory_region_set_enabled(bank, false);
        memory_region_add_subregion_overlap(&s->low_mem_container, i * 0x8000,
                                            bank, 1);
    }
2961
    memory_region_add_subregion_overlap(system_memory,
2962
                                        0x000a0000,
2963 2964 2965
                                        &s->low_mem_container,
                                        1);
    memory_region_set_coalescing(&s->low_mem);
B
bellard 已提交
2966

2967
    /* I/O handler for LFB */
2968
    memory_region_init_io(&s->cirrus_linear_io, owner, &cirrus_linear_io_ops, s,
2969 2970
                          "cirrus-linear-io", s->vga.vram_size_mb
                                              * 1024 * 1024);
2971
    memory_region_set_flush_coalesced(&s->cirrus_linear_io);
2972 2973

    /* I/O handler for LFB */
2974
    memory_region_init_io(&s->cirrus_linear_bitblt_io, owner,
2975 2976 2977 2978
                          &cirrus_linear_bitblt_io_ops,
                          s,
                          "cirrus-bitblt-mmio",
                          0x400000);
2979
    memory_region_set_flush_coalesced(&s->cirrus_linear_bitblt_io);
2980 2981

    /* I/O handler for memory-mapped I/O */
2982
    memory_region_init_io(&s->cirrus_mmio_io, owner, &cirrus_mmio_io_ops, s,
2983
                          "cirrus-mmio", CIRRUS_PNPMMIO_SIZE);
2984
    memory_region_set_flush_coalesced(&s->cirrus_mmio_io);
2985 2986 2987 2988

    s->real_vram_size =
        (s->device_id == CIRRUS_ID_CLGD5446) ? 4096 * 1024 : 2048 * 1024;

2989
    /* XXX: s->vga.vram_size must be a power of two */
2990 2991 2992
    s->cirrus_addr_mask = s->real_vram_size - 1;
    s->linear_mmio_mask = s->real_vram_size - 256;

2993 2994 2995 2996 2997
    s->vga.get_bpp = cirrus_get_bpp;
    s->vga.get_offsets = cirrus_get_offsets;
    s->vga.get_resolution = cirrus_get_resolution;
    s->vga.cursor_invalidate = cirrus_cursor_invalidate;
    s->vga.cursor_draw_line = cirrus_cursor_draw_line;
2998

2999
    qemu_register_reset(cirrus_reset, s);
3000 3001 3002 3003 3004 3005 3006 3007
}

/***************************************
 *
 *  ISA bus support
 *
 ***************************************/

3008
static void isa_cirrus_vga_realizefn(DeviceState *dev, Error **errp)
3009
{
3010
    ISADevice *isadev = ISA_DEVICE(dev);
3011
    ISACirrusVGAState *d = ISA_CIRRUS_VGA(dev);
3012 3013
    VGACommonState *s = &d->cirrus_vga.vga;

3014 3015 3016 3017 3018 3019 3020 3021
    /* follow real hardware, cirrus card emulated has 4 MB video memory.
       Also accept 8 MB/16 MB for backward compatibility. */
    if (s->vram_size_mb != 4 && s->vram_size_mb != 8 &&
        s->vram_size_mb != 16) {
        error_setg(errp, "Invalid cirrus_vga ram size '%u'",
                   s->vram_size_mb);
        return;
    }
G
Gerd Hoffmann 已提交
3022
    vga_common_init(s, OBJECT(dev), true);
3023
    cirrus_init_common(&d->cirrus_vga, OBJECT(dev), CIRRUS_ID_CLGD5430, 0,
3024 3025
                       isa_address_space(isadev),
                       isa_address_space_io(isadev));
3026
    s->con = graphic_console_init(dev, 0, s->hw_ops, s);
3027
    rom_add_vga(VGABIOS_CIRRUS_FILENAME);
3028
    /* XXX ISA-LFB support */
3029
    /* FIXME not qdev yet */
3030 3031
}

3032
static Property isa_cirrus_vga_properties[] = {
3033 3034 3035 3036 3037
    DEFINE_PROP_UINT32("vgamem_mb", struct ISACirrusVGAState,
                       cirrus_vga.vga.vram_size_mb, 8),
    DEFINE_PROP_END_OF_LIST(),
};

3038 3039
static void isa_cirrus_vga_class_init(ObjectClass *klass, void *data)
{
3040
    DeviceClass *dc = DEVICE_CLASS(klass);
3041

3042
    dc->vmsd  = &vmstate_cirrus_vga;
3043
    dc->realize = isa_cirrus_vga_realizefn;
3044
    dc->props = isa_cirrus_vga_properties;
3045
    set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories);
3046 3047
}

3048
static const TypeInfo isa_cirrus_vga_info = {
3049
    .name          = TYPE_ISA_CIRRUS_VGA,
3050 3051
    .parent        = TYPE_ISA_DEVICE,
    .instance_size = sizeof(ISACirrusVGAState),
3052
    .class_init = isa_cirrus_vga_class_init,
3053 3054
};

3055 3056 3057 3058 3059 3060
/***************************************
 *
 *  PCI bus support
 *
 ***************************************/

3061
static void pci_cirrus_vga_realize(PCIDevice *dev, Error **errp)
G
Gerd Hoffmann 已提交
3062
{
G
Gonglei 已提交
3063
     PCICirrusVGAState *d = PCI_CIRRUS_VGA(dev);
G
Gerd Hoffmann 已提交
3064
     CirrusVGAState *s = &d->cirrus_vga;
3065 3066
     PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(dev);
     int16_t device_id = pc->device_id;
G
Gerd Hoffmann 已提交
3067

3068 3069 3070 3071
     /* follow real hardware, cirrus card emulated has 4 MB video memory.
       Also accept 8 MB/16 MB for backward compatibility. */
     if (s->vga.vram_size_mb != 4 && s->vga.vram_size_mb != 8 &&
         s->vga.vram_size_mb != 16) {
3072 3073 3074
         error_setg(errp, "Invalid cirrus_vga ram size '%u'",
                    s->vga.vram_size_mb);
         return;
3075
     }
G
Gerd Hoffmann 已提交
3076
     /* setup VGA */
G
Gerd Hoffmann 已提交
3077
     vga_common_init(&s->vga, OBJECT(dev), true);
3078
     cirrus_init_common(s, OBJECT(dev), device_id, 1, pci_address_space(dev),
3079
                        pci_address_space_io(dev));
3080
     s->vga.con = graphic_console_init(DEVICE(dev), 0, s->vga.hw_ops, &s->vga);
G
Gerd Hoffmann 已提交
3081 3082 3083

     /* setup PCI */

3084
    memory_region_init(&s->pci_bar, OBJECT(dev), "cirrus-pci-bar0", 0x2000000);
3085 3086 3087 3088 3089 3090

    /* XXX: add byte swapping apertures */
    memory_region_add_subregion(&s->pci_bar, 0, &s->cirrus_linear_io);
    memory_region_add_subregion(&s->pci_bar, 0x1000000,
                                &s->cirrus_linear_bitblt_io);

G
Gerd Hoffmann 已提交
3091 3092 3093 3094
     /* setup memory space */
     /* memory #0 LFB */
     /* memory #1 memory-mapped I/O */
     /* XXX: s->vga.vram_size must be a power of two */
3095
     pci_register_bar(&d->dev, 0, PCI_BASE_ADDRESS_MEM_PREFETCH, &s->pci_bar);
G
Gerd Hoffmann 已提交
3096
     if (device_id == CIRRUS_ID_CLGD5446) {
3097
         pci_register_bar(&d->dev, 1, 0, &s->cirrus_mmio_io);
G
Gerd Hoffmann 已提交
3098 3099 3100
     }
}

3101 3102 3103 3104 3105 3106
static Property pci_vga_cirrus_properties[] = {
    DEFINE_PROP_UINT32("vgamem_mb", struct PCICirrusVGAState,
                       cirrus_vga.vga.vram_size_mb, 8),
    DEFINE_PROP_END_OF_LIST(),
};

3107 3108
static void cirrus_vga_class_init(ObjectClass *klass, void *data)
{
3109
    DeviceClass *dc = DEVICE_CLASS(klass);
3110 3111
    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);

3112
    k->realize = pci_cirrus_vga_realize;
3113 3114 3115 3116
    k->romfile = VGABIOS_CIRRUS_FILENAME;
    k->vendor_id = PCI_VENDOR_ID_CIRRUS;
    k->device_id = CIRRUS_ID_CLGD5446;
    k->class_id = PCI_CLASS_DISPLAY_VGA;
3117
    set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories);
3118 3119
    dc->desc = "Cirrus CLGD 54xx VGA";
    dc->vmsd = &vmstate_pci_cirrus_vga;
3120
    dc->props = pci_vga_cirrus_properties;
3121
    dc->hotpluggable = false;
3122 3123
}

3124
static const TypeInfo cirrus_vga_info = {
G
Gonglei 已提交
3125
    .name          = TYPE_PCI_CIRRUS_VGA,
3126 3127 3128
    .parent        = TYPE_PCI_DEVICE,
    .instance_size = sizeof(PCICirrusVGAState),
    .class_init    = cirrus_vga_class_init,
G
Gerd Hoffmann 已提交
3129
};
3130

A
Andreas Färber 已提交
3131
static void cirrus_vga_register_types(void)
G
Gerd Hoffmann 已提交
3132
{
A
Andreas Färber 已提交
3133
    type_register_static(&isa_cirrus_vga_info);
3134
    type_register_static(&cirrus_vga_info);
3135
}
A
Andreas Färber 已提交
3136 3137

type_init(cirrus_vga_register_types)