vga_int.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /*
  2. * QEMU internal VGA defines.
  3. *
  4. * Copyright (c) 2003-2004 Fabrice Bellard
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. * THE SOFTWARE.
  23. */
  24. #define MSR_COLOR_EMULATION 0x01
  25. #define MSR_PAGE_SELECT 0x20
  26. #define ST01_V_RETRACE 0x08
  27. #define ST01_DISP_ENABLE 0x01
  28. /* bochs VBE support */
  29. #define CONFIG_BOCHS_VBE
  30. #define VBE_DISPI_MAX_XRES 1600
  31. #define VBE_DISPI_MAX_YRES 1200
  32. #define VBE_DISPI_MAX_BPP 32
  33. #define VBE_DISPI_INDEX_ID 0x0
  34. #define VBE_DISPI_INDEX_XRES 0x1
  35. #define VBE_DISPI_INDEX_YRES 0x2
  36. #define VBE_DISPI_INDEX_BPP 0x3
  37. #define VBE_DISPI_INDEX_ENABLE 0x4
  38. #define VBE_DISPI_INDEX_BANK 0x5
  39. #define VBE_DISPI_INDEX_VIRT_WIDTH 0x6
  40. #define VBE_DISPI_INDEX_VIRT_HEIGHT 0x7
  41. #define VBE_DISPI_INDEX_X_OFFSET 0x8
  42. #define VBE_DISPI_INDEX_Y_OFFSET 0x9
  43. #define VBE_DISPI_INDEX_NB 0xa
  44. #define VBE_DISPI_ID0 0xB0C0
  45. #define VBE_DISPI_ID1 0xB0C1
  46. #define VBE_DISPI_ID2 0xB0C2
  47. #define VBE_DISPI_ID3 0xB0C3
  48. #define VBE_DISPI_ID4 0xB0C4
  49. #define VBE_DISPI_DISABLED 0x00
  50. #define VBE_DISPI_ENABLED 0x01
  51. #define VBE_DISPI_GETCAPS 0x02
  52. #define VBE_DISPI_8BIT_DAC 0x20
  53. #define VBE_DISPI_LFB_ENABLED 0x40
  54. #define VBE_DISPI_NOCLEARMEM 0x80
  55. #define VBE_DISPI_LFB_PHYSICAL_ADDRESS 0xE0000000
  56. #ifdef CONFIG_BOCHS_VBE
  57. #define VGA_STATE_COMMON_BOCHS_VBE \
  58. uint16_t vbe_index; \
  59. uint16_t vbe_regs[VBE_DISPI_INDEX_NB]; \
  60. uint32_t vbe_start_addr; \
  61. uint32_t vbe_line_offset; \
  62. uint32_t vbe_bank_mask;
  63. #else
  64. #define VGA_STATE_COMMON_BOCHS_VBE
  65. #endif /* !CONFIG_BOCHS_VBE */
  66. #define CH_ATTR_SIZE (160 * 100)
  67. #define VGA_MAX_HEIGHT 2048
  68. struct vga_precise_retrace {
  69. int64_t ticks_per_char;
  70. int64_t total_chars;
  71. int htotal;
  72. int hstart;
  73. int hend;
  74. int vstart;
  75. int vend;
  76. int freq;
  77. };
  78. union vga_retrace {
  79. struct vga_precise_retrace precise;
  80. };
  81. struct VGAState;
  82. typedef uint8_t (* vga_retrace_fn)(struct VGAState *s);
  83. typedef void (* vga_update_retrace_info_fn)(struct VGAState *s);
  84. #define VGA_STATE_COMMON \
  85. uint8_t *vram_ptr; \
  86. ram_addr_t vram_offset; \
  87. unsigned int vram_size; \
  88. uint32_t lfb_addr; \
  89. uint32_t lfb_end; \
  90. uint32_t map_addr; \
  91. uint32_t map_end; \
  92. uint32_t lfb_vram_mapped; /* whether 0xa0000 is mapped as ram */ \
  93. unsigned long bios_offset; \
  94. unsigned int bios_size; \
  95. int it_shift; \
  96. PCIDevice *pci_dev; \
  97. uint32_t latch; \
  98. uint8_t sr_index; \
  99. uint8_t sr[256]; \
  100. uint8_t gr_index; \
  101. uint8_t gr[256]; \
  102. uint8_t ar_index; \
  103. uint8_t ar[21]; \
  104. int ar_flip_flop; \
  105. uint8_t cr_index; \
  106. uint8_t cr[256]; /* CRT registers */ \
  107. uint8_t msr; /* Misc Output Register */ \
  108. uint8_t fcr; /* Feature Control Register */ \
  109. uint8_t st00; /* status 0 */ \
  110. uint8_t st01; /* status 1 */ \
  111. uint8_t dac_state; \
  112. uint8_t dac_sub_index; \
  113. uint8_t dac_read_index; \
  114. uint8_t dac_write_index; \
  115. uint8_t dac_cache[3]; /* used when writing */ \
  116. int dac_8bit; \
  117. uint8_t palette[768]; \
  118. int32_t bank_offset; \
  119. int vga_io_memory; \
  120. int (*get_bpp)(struct VGAState *s); \
  121. void (*get_offsets)(struct VGAState *s, \
  122. uint32_t *pline_offset, \
  123. uint32_t *pstart_addr, \
  124. uint32_t *pline_compare); \
  125. void (*get_resolution)(struct VGAState *s, \
  126. int *pwidth, \
  127. int *pheight); \
  128. VGA_STATE_COMMON_BOCHS_VBE \
  129. /* display refresh support */ \
  130. DisplayState *ds; \
  131. uint32_t font_offsets[2]; \
  132. int graphic_mode; \
  133. uint8_t shift_control; \
  134. uint8_t double_scan; \
  135. uint32_t line_offset; \
  136. uint32_t line_compare; \
  137. uint32_t start_addr; \
  138. uint32_t plane_updated; \
  139. uint32_t last_line_offset; \
  140. uint8_t last_cw, last_ch; \
  141. uint32_t last_width, last_height; /* in chars or pixels */ \
  142. uint32_t last_scr_width, last_scr_height; /* in pixels */ \
  143. uint32_t last_depth; /* in bits */ \
  144. uint8_t cursor_start, cursor_end; \
  145. uint32_t cursor_offset; \
  146. unsigned int (*rgb_to_pixel)(unsigned int r, \
  147. unsigned int g, unsigned b); \
  148. vga_hw_update_ptr update; \
  149. vga_hw_invalidate_ptr invalidate; \
  150. vga_hw_screen_dump_ptr screen_dump; \
  151. vga_hw_text_update_ptr text_update; \
  152. /* hardware mouse cursor support */ \
  153. uint32_t invalidated_y_table[VGA_MAX_HEIGHT / 32]; \
  154. void (*cursor_invalidate)(struct VGAState *s); \
  155. void (*cursor_draw_line)(struct VGAState *s, uint8_t *d, int y); \
  156. /* tell for each page if it has been updated since the last time */ \
  157. uint32_t last_palette[256]; \
  158. uint32_t last_ch_attr[CH_ATTR_SIZE]; /* XXX: make it dynamic */ \
  159. /* retrace */ \
  160. vga_retrace_fn retrace; \
  161. vga_update_retrace_info_fn update_retrace_info; \
  162. union vga_retrace retrace_info;
  163. typedef struct VGAState {
  164. VGA_STATE_COMMON
  165. } VGAState;
  166. static inline int c6_to_8(int v)
  167. {
  168. int b;
  169. v &= 0x3f;
  170. b = v & 1;
  171. return (v << 2) | (b << 1) | b;
  172. }
  173. void vga_common_init(VGAState *s, uint8_t *vga_ram_base,
  174. ram_addr_t vga_ram_offset, int vga_ram_size);
  175. void vga_init(VGAState *s);
  176. void vga_reset(void *s);
  177. void vga_dirty_log_start(VGAState *s);
  178. void vga_dirty_log_stop(VGAState *s);
  179. uint32_t vga_mem_readb(void *opaque, target_phys_addr_t addr);
  180. void vga_mem_writeb(void *opaque, target_phys_addr_t addr, uint32_t val);
  181. void vga_invalidate_scanlines(VGAState *s, int y1, int y2);
  182. int ppm_save(const char *filename, struct DisplaySurface *ds);
  183. void vga_draw_cursor_line_8(uint8_t *d1, const uint8_t *src1,
  184. int poffset, int w,
  185. unsigned int color0, unsigned int color1,
  186. unsigned int color_xor);
  187. void vga_draw_cursor_line_16(uint8_t *d1, const uint8_t *src1,
  188. int poffset, int w,
  189. unsigned int color0, unsigned int color1,
  190. unsigned int color_xor);
  191. void vga_draw_cursor_line_32(uint8_t *d1, const uint8_t *src1,
  192. int poffset, int w,
  193. unsigned int color0, unsigned int color1,
  194. unsigned int color_xor);
  195. extern const uint8_t sr_mask[8];
  196. extern const uint8_t gr_mask[16];