debuggers.hg

view tools/ioemu/patches/shadow-vram @ 0:7d21f7218375

Exact replica of unstable on 051908 + README-this
author Mukesh Rathor
date Mon May 19 15:34:57 2008 -0700 (2008-05-19)
parents
children
line source
1 Index: ioemu/hw/vga.c
2 ===================================================================
3 --- ioemu.orig/hw/vga.c 2007-05-03 19:15:06.000000000 +0100
4 +++ ioemu/hw/vga.c 2007-05-03 19:15:57.000000000 +0100
5 @@ -1373,6 +1373,105 @@
6 }
7 }
9 +static inline int cmp_vram(VGAState *s, int offset, int n)
10 +{
11 + long *vp, *sp;
12 +
13 + if (s->vram_shadow == NULL)
14 + return 1;
15 + vp = (long *)(s->vram_ptr + offset);
16 + sp = (long *)(s->vram_shadow + offset);
17 + while ((n -= sizeof(*vp)) >= 0) {
18 + if (*vp++ != *sp++) {
19 + memcpy(sp - 1, vp - 1, n + sizeof(*vp));
20 + return 1;
21 + }
22 + }
23 + return 0;
24 +}
25 +
26 +#ifdef USE_SSE2
27 +
28 +#include <signal.h>
29 +#include <setjmp.h>
30 +#include <emmintrin.h>
31 +
32 +int sse2_ok = 1;
33 +
34 +static inline unsigned int cpuid_edx(unsigned int op)
35 +{
36 + unsigned int eax, edx;
37 +
38 +#ifdef __x86_64__
39 +#define __bx "rbx"
40 +#else
41 +#define __bx "ebx"
42 +#endif
43 + __asm__("push %%"__bx"; cpuid; pop %%"__bx
44 + : "=a" (eax), "=d" (edx)
45 + : "0" (op)
46 + : "cx");
47 +#undef __bx
48 +
49 + return edx;
50 +}
51 +
52 +jmp_buf sse_jbuf;
53 +
54 +void intr(int sig)
55 +{
56 + sse2_ok = 0;
57 + longjmp(sse_jbuf, 1);
58 +}
59 +
60 +void check_sse2(void)
61 +{
62 + /* Check 1: What does CPUID say? */
63 + if ((cpuid_edx(1) & 0x4000000) == 0) {
64 + sse2_ok = 0;
65 + return;
66 + }
67 +
68 + /* Check 2: Can we use SSE2 in anger? */
69 + signal(SIGILL, intr);
70 + if (setjmp(sse_jbuf) == 0)
71 + __asm__("xorps %xmm0,%xmm0\n");
72 +}
73 +
74 +int vram_dirty(VGAState *s, int offset, int n)
75 +{
76 + __m128i *sp, *vp;
77 +
78 + if (s->vram_shadow == NULL)
79 + return 1;
80 + if (sse2_ok == 0)
81 + return cmp_vram(s, offset, n);
82 + vp = (__m128i *)(s->vram_ptr + offset);
83 + sp = (__m128i *)(s->vram_shadow + offset);
84 + while ((n -= sizeof(*vp)) >= 0) {
85 + if (_mm_movemask_epi8(_mm_cmpeq_epi8(*sp, *vp)) != 0xffff) {
86 + while (n >= 0) {
87 + _mm_store_si128(sp++, _mm_load_si128(vp++));
88 + n -= sizeof(*vp);
89 + }
90 + return 1;
91 + }
92 + sp++;
93 + vp++;
94 + }
95 + return 0;
96 +}
97 +#else /* !USE_SSE2 */
98 +int vram_dirty(VGAState *s, int offset, int n)
99 +{
100 + return cmp_vram(s, offset, n);
101 +}
102 +
103 +void check_sse2(void)
104 +{
105 +}
106 +#endif /* !USE_SSE2 */
107 +
108 /*
109 * graphic modes
110 */
111 @@ -1468,6 +1567,11 @@
112 printf("w=%d h=%d v=%d line_offset=%d cr[0x09]=0x%02x cr[0x17]=0x%02x linecmp=%d sr[0x01]=0x%02x\n",
113 width, height, v, line_offset, s->cr[9], s->cr[0x17], s->line_compare, s->sr[0x01]);
114 #endif
115 +
116 + for (y = 0; y < s->vram_size; y += TARGET_PAGE_SIZE)
117 + if (vram_dirty(s, y, TARGET_PAGE_SIZE))
118 + cpu_physical_memory_set_dirty(s->vram_offset + y);
119 +
120 addr1 = (s->start_addr * 4);
121 bwidth = width * 4;
122 y_start = -1;
123 @@ -1918,7 +2022,18 @@
125 vga_reset(s);
127 - s->vram_ptr = qemu_malloc(vga_ram_size);
128 + check_sse2();
129 + s->vram_shadow = qemu_malloc(vga_ram_size+TARGET_PAGE_SIZE+1);
130 + if (s->vram_shadow == NULL)
131 + fprintf(stderr, "Cannot allocate %d bytes for VRAM shadow, "
132 + "mouse will be slow\n", vga_ram_size);
133 + s->vram_shadow = (uint8_t *)((long)(s->vram_shadow + TARGET_PAGE_SIZE - 1)
134 + & ~(TARGET_PAGE_SIZE - 1));
135 +
136 + /* Video RAM must be 128-bit aligned for SSE optimizations later */
137 + s->vram_alloc = qemu_malloc(vga_ram_size + 15);
138 + s->vram_ptr = (uint8_t *)((long)(s->vram_alloc + 15) & ~15L);
139 +
140 s->vram_offset = vga_ram_offset;
141 s->vram_size = vga_ram_size;
142 s->ds = ds;
143 @@ -2058,7 +2173,7 @@
144 }
146 if (!vga_ram_base) {
147 - vga_ram_base = qemu_malloc(vga_ram_size);
148 + vga_ram_base = qemu_malloc(vga_ram_size + TARGET_PAGE_SIZE + 1);
149 if (!vga_ram_base) {
150 fprintf(stderr, "reallocate error\n");
151 return NULL;
152 @@ -2066,8 +2181,10 @@
153 }
155 /* XXX lock needed? */
156 + old_pointer = s->vram_alloc;
157 + s->vram_alloc = vga_ram_base;
158 + vga_ram_base = (uint8_t *)((long)(vga_ram_base + 15) & ~15L);
159 memcpy(vga_ram_base, s->vram_ptr, vga_ram_size);
160 - old_pointer = s->vram_ptr;
161 s->vram_ptr = vga_ram_base;
163 return old_pointer;
164 Index: ioemu/hw/vga_int.h
165 ===================================================================
166 --- ioemu.orig/hw/vga_int.h 2007-05-03 19:15:06.000000000 +0100
167 +++ ioemu/hw/vga_int.h 2007-05-03 19:15:57.000000000 +0100
168 @@ -80,7 +80,9 @@
169 #define VGA_MAX_HEIGHT 2048
171 #define VGA_STATE_COMMON \
172 + uint8_t *vram_alloc; \
173 uint8_t *vram_ptr; \
174 + uint8_t *vram_shadow; \
175 unsigned long vram_offset; \
176 unsigned int vram_size; \
177 unsigned long bios_offset; \