Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1 | // VGA bios implementation |
| 2 | // |
| 3 | // Copyright (C) 2009 Kevin O'Connor <kevin@koconnor.net> |
| 4 | // Copyright (C) 2001-2008 the LGPL VGABios developers Team |
| 5 | // |
| 6 | // This file may be distributed under the terms of the GNU LGPLv3 license. |
| 7 | |
| 8 | |
| 9 | // TODO: |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 10 | // * review correctness of converted asm by comparing with RBIL |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 11 | // |
Kevin O'Connor | 6ace78f | 2009-05-14 19:24:49 -0400 | [diff] [blame] | 12 | // * convert vbe/clext code |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 13 | |
| 14 | #include "bregs.h" // struct bregs |
| 15 | #include "biosvar.h" // GET_BDA |
| 16 | #include "util.h" // memset |
Kevin O'Connor | c0c7df6 | 2009-05-17 18:11:33 -0400 | [diff] [blame] | 17 | #include "vgatables.h" // find_vga_entry |
Julian Pidancet | 7c6509c | 2011-12-19 05:07:55 +0000 | [diff] [blame^] | 18 | #include "optionroms.h" // struct pci_data |
| 19 | #include "config.h" // CONFIG_* |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 20 | |
| 21 | // XXX |
Julian Pidancet | 677631f | 2011-12-19 05:07:53 +0000 | [diff] [blame] | 22 | #define CONFIG_VGA_BOCHS 0 |
| 23 | #define CONFIG_VGA_CIRRUS 0 |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 24 | |
| 25 | // XXX |
| 26 | #define DEBUG_VGA_POST 1 |
| 27 | #define DEBUG_VGA_10 3 |
| 28 | |
Kevin O'Connor | d113a99 | 2009-05-16 21:05:02 -0400 | [diff] [blame] | 29 | #define SET_VGA(var, val) SET_FARVAR(get_global_seg(), (var), (val)) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 30 | |
Julian Pidancet | 7c6509c | 2011-12-19 05:07:55 +0000 | [diff] [blame^] | 31 | /**************************************************************** |
| 32 | * PCI Data |
| 33 | ****************************************************************/ |
| 34 | #if CONFIG_VGA_PCI == 1 |
| 35 | struct pci_data rom_pci_data VAR16VISIBLE = { |
| 36 | .signature = PCI_ROM_SIGNATURE, |
| 37 | .vendor = CONFIG_VGA_VID, |
| 38 | .device = CONFIG_VGA_DID, |
| 39 | .dlen = 0x18, |
| 40 | .class_hi = 0x300, |
| 41 | .irevision = 1, |
| 42 | .type = PCIROM_CODETYPE_X86, |
| 43 | .indicator = 0x80, |
| 44 | }; |
| 45 | #endif |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 46 | |
| 47 | /**************************************************************** |
| 48 | * Helper functions |
| 49 | ****************************************************************/ |
| 50 | |
Kevin O'Connor | 217f2bc | 2009-05-31 00:46:47 -0400 | [diff] [blame] | 51 | static inline void |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 52 | call16_vgaint(u32 eax, u32 ebx) |
| 53 | { |
| 54 | asm volatile( |
| 55 | "int $0x10\n" |
| 56 | "cli\n" |
| 57 | "cld" |
| 58 | : |
| 59 | : "a"(eax), "b"(ebx) |
| 60 | : "cc", "memory"); |
| 61 | } |
| 62 | |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 63 | static void |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 64 | perform_gray_scale_summing(u16 start, u16 count) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 65 | { |
Kevin O'Connor | a0ecb05 | 2009-05-18 23:34:00 -0400 | [diff] [blame] | 66 | vgahw_screen_disable(); |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 67 | int i; |
| 68 | for (i = start; i < start+count; i++) { |
Kevin O'Connor | a0ecb05 | 2009-05-18 23:34:00 -0400 | [diff] [blame] | 69 | u8 rgb[3]; |
| 70 | vgahw_get_dac_regs(GET_SEG(SS), rgb, i, 1); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 71 | |
| 72 | // intensity = ( 0.3 * Red ) + ( 0.59 * Green ) + ( 0.11 * Blue ) |
Kevin O'Connor | a0ecb05 | 2009-05-18 23:34:00 -0400 | [diff] [blame] | 73 | u16 intensity = ((77 * rgb[0] + 151 * rgb[1] + 28 * rgb[2]) + 0x80) >> 8; |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 74 | if (intensity > 0x3f) |
| 75 | intensity = 0x3f; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 76 | |
Kevin O'Connor | a0ecb05 | 2009-05-18 23:34:00 -0400 | [diff] [blame] | 77 | vgahw_set_dac_regs(GET_SEG(SS), rgb, i, 1); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 78 | } |
Kevin O'Connor | a0ecb05 | 2009-05-18 23:34:00 -0400 | [diff] [blame] | 79 | vgahw_screen_enable(); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 80 | } |
| 81 | |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 82 | static void |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 83 | set_cursor_shape(u8 start, u8 end) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 84 | { |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 85 | start &= 0x3f; |
| 86 | end &= 0x1f; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 87 | |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 88 | u16 curs = (start << 8) + end; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 89 | SET_BDA(cursor_type, curs); |
| 90 | |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 91 | u8 modeset_ctl = GET_BDA(modeset_ctl); |
| 92 | u16 cheight = GET_BDA(char_height); |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 93 | if ((modeset_ctl & 0x01) && (cheight > 8) && (end < 8) && (start < 0x20)) { |
| 94 | if (end != (start + 1)) |
| 95 | start = ((start + 1) * cheight / 8) - 1; |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 96 | else |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 97 | start = ((end + 1) * cheight / 8) - 2; |
| 98 | end = ((end + 1) * cheight / 8) - 1; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 99 | } |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 100 | vgahw_set_cursor_shape(start, end); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 101 | } |
| 102 | |
Kevin O'Connor | 0818e1a | 2009-05-16 18:00:19 -0400 | [diff] [blame] | 103 | static u16 |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 104 | get_cursor_shape(u8 page) |
Kevin O'Connor | 0818e1a | 2009-05-16 18:00:19 -0400 | [diff] [blame] | 105 | { |
| 106 | if (page > 7) |
| 107 | return 0; |
| 108 | // FIXME should handle VGA 14/16 lines |
| 109 | return GET_BDA(cursor_type); |
| 110 | } |
| 111 | |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 112 | static void |
Kevin O'Connor | 918b156 | 2009-05-25 11:05:18 -0400 | [diff] [blame] | 113 | set_cursor_pos(struct cursorpos cp) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 114 | { |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 115 | // Should not happen... |
Kevin O'Connor | 918b156 | 2009-05-25 11:05:18 -0400 | [diff] [blame] | 116 | if (cp.page > 7) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 117 | return; |
| 118 | |
| 119 | // Bios cursor pos |
Kevin O'Connor | 918b156 | 2009-05-25 11:05:18 -0400 | [diff] [blame] | 120 | SET_BDA(cursor_pos[cp.page], (cp.y << 8) | cp.x); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 121 | |
| 122 | // Set the hardware cursor |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 123 | u8 current = GET_BDA(video_page); |
Kevin O'Connor | 918b156 | 2009-05-25 11:05:18 -0400 | [diff] [blame] | 124 | if (cp.page != current) |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 125 | return; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 126 | |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 127 | // Get the dimensions |
| 128 | u16 nbcols = GET_BDA(video_cols); |
| 129 | u16 nbrows = GET_BDA(video_rows) + 1; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 130 | |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 131 | // Calculate the address knowing nbcols nbrows and page num |
Kevin O'Connor | 918b156 | 2009-05-25 11:05:18 -0400 | [diff] [blame] | 132 | u16 address = (SCREEN_IO_START(nbcols, nbrows, cp.page) |
| 133 | + cp.x + cp.y * nbcols); |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 134 | |
Kevin O'Connor | a0ecb05 | 2009-05-18 23:34:00 -0400 | [diff] [blame] | 135 | vgahw_set_cursor_pos(address); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 136 | } |
| 137 | |
Kevin O'Connor | 217f2bc | 2009-05-31 00:46:47 -0400 | [diff] [blame] | 138 | static struct cursorpos |
Kevin O'Connor | 918b156 | 2009-05-25 11:05:18 -0400 | [diff] [blame] | 139 | get_cursor_pos(u8 page) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 140 | { |
Kevin O'Connor | 918b156 | 2009-05-25 11:05:18 -0400 | [diff] [blame] | 141 | if (page == 0xff) |
| 142 | // special case - use current page |
| 143 | page = GET_BDA(video_page); |
| 144 | if (page > 7) { |
| 145 | struct cursorpos cp = { 0, 0, 0xfe }; |
| 146 | return cp; |
| 147 | } |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 148 | // FIXME should handle VGA 14/16 lines |
Kevin O'Connor | 918b156 | 2009-05-25 11:05:18 -0400 | [diff] [blame] | 149 | u16 xy = GET_BDA(cursor_pos[page]); |
| 150 | struct cursorpos cp = {xy, xy>>8, page}; |
| 151 | return cp; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 152 | } |
| 153 | |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 154 | static void |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 155 | set_active_page(u8 page) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 156 | { |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 157 | if (page > 7) |
| 158 | return; |
| 159 | |
| 160 | // Get the mode |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 161 | struct vgamode_s *vmode_g = find_vga_entry(GET_BDA(video_mode)); |
| 162 | if (!vmode_g) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 163 | return; |
| 164 | |
| 165 | // Get pos curs pos for the right page |
Kevin O'Connor | 918b156 | 2009-05-25 11:05:18 -0400 | [diff] [blame] | 166 | struct cursorpos cp = get_cursor_pos(page); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 167 | |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 168 | u16 address; |
Kevin O'Connor | e4f220f | 2009-05-25 23:37:13 -0400 | [diff] [blame] | 169 | if (GET_GLOBAL(vmode_g->memmodel) & TEXT) { |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 170 | // Get the dimensions |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 171 | u16 nbcols = GET_BDA(video_cols); |
| 172 | u16 nbrows = GET_BDA(video_rows) + 1; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 173 | |
| 174 | // Calculate the address knowing nbcols nbrows and page num |
| 175 | address = SCREEN_MEM_START(nbcols, nbrows, page); |
| 176 | SET_BDA(video_pagestart, address); |
| 177 | |
| 178 | // Start address |
| 179 | address = SCREEN_IO_START(nbcols, nbrows, page); |
| 180 | } else { |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 181 | struct VideoParam_s *vparam_g = GET_GLOBAL(vmode_g->vparam); |
| 182 | address = page * GET_GLOBAL(vparam_g->slength); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 183 | } |
| 184 | |
Kevin O'Connor | a0ecb05 | 2009-05-18 23:34:00 -0400 | [diff] [blame] | 185 | vgahw_set_active_page(address); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 186 | |
| 187 | // And change the BIOS page |
| 188 | SET_BDA(video_page, page); |
| 189 | |
Kevin O'Connor | a12c215 | 2009-05-13 22:06:16 -0400 | [diff] [blame] | 190 | dprintf(1, "Set active page %02x address %04x\n", page, address); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 191 | |
| 192 | // Display the cursor, now the page is active |
Kevin O'Connor | 918b156 | 2009-05-25 11:05:18 -0400 | [diff] [blame] | 193 | set_cursor_pos(cp); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 194 | } |
| 195 | |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 196 | static void |
| 197 | set_scan_lines(u8 lines) |
| 198 | { |
| 199 | vgahw_set_scan_lines(lines); |
| 200 | if (lines == 8) |
| 201 | set_cursor_shape(0x06, 0x07); |
| 202 | else |
| 203 | set_cursor_shape(lines - 4, lines - 3); |
| 204 | SET_BDA(char_height, lines); |
| 205 | u16 vde = vgahw_get_vde(); |
| 206 | u8 rows = vde / lines; |
| 207 | SET_BDA(video_rows, rows - 1); |
| 208 | u16 cols = GET_BDA(video_cols); |
| 209 | SET_BDA(video_pagesize, rows * cols * 2); |
| 210 | } |
| 211 | |
| 212 | |
| 213 | /**************************************************************** |
| 214 | * Character writing |
| 215 | ****************************************************************/ |
| 216 | |
Kevin O'Connor | afb287d | 2009-05-31 21:15:33 -0400 | [diff] [blame] | 217 | // Scroll the screen one line. This function is designed to be called |
| 218 | // tail-recursive to reduce stack usage. |
| 219 | static void noinline |
| 220 | scroll_one(u16 nbrows, u16 nbcols, u8 page) |
Kevin O'Connor | 0926241 | 2009-05-25 11:44:11 -0400 | [diff] [blame] | 221 | { |
Kevin O'Connor | afb287d | 2009-05-31 21:15:33 -0400 | [diff] [blame] | 222 | struct cursorpos ul = {0, 0, page}; |
| 223 | struct cursorpos lr = {nbcols-1, nbrows-1, page}; |
| 224 | vgafb_scroll(1, -1, ul, lr); |
| 225 | } |
| 226 | |
| 227 | // Write a character to the screen at a given position. Implement |
| 228 | // special characters and scroll the screen if necessary. |
| 229 | static void |
| 230 | write_teletype(struct cursorpos *pcp, struct carattr ca) |
| 231 | { |
| 232 | struct cursorpos cp = *pcp; |
| 233 | |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 234 | // Get the dimensions |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 235 | u16 nbrows = GET_BDA(video_rows) + 1; |
| 236 | u16 nbcols = GET_BDA(video_cols); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 237 | |
Kevin O'Connor | 2e86c6a | 2009-05-31 20:43:06 -0400 | [diff] [blame] | 238 | switch (ca.car) { |
| 239 | case 7: |
| 240 | //FIXME should beep |
| 241 | break; |
| 242 | case 8: |
| 243 | if (cp.x > 0) |
| 244 | cp.x--; |
| 245 | break; |
| 246 | case '\r': |
| 247 | cp.x = 0; |
| 248 | break; |
| 249 | case '\n': |
| 250 | cp.y++; |
| 251 | break; |
| 252 | case '\t': |
| 253 | do { |
| 254 | struct carattr dummyca = {' ', ca.attr, ca.use_attr}; |
| 255 | vgafb_write_char(cp, dummyca); |
| 256 | cp.x++; |
| 257 | } while (cp.x < nbcols && cp.x % 8); |
| 258 | break; |
| 259 | default: |
| 260 | vgafb_write_char(cp, ca); |
| 261 | cp.x++; |
| 262 | } |
| 263 | |
Kevin O'Connor | 82221b2 | 2009-05-26 00:20:40 -0400 | [diff] [blame] | 264 | // Do we need to wrap ? |
| 265 | if (cp.x == nbcols) { |
| 266 | cp.x = 0; |
| 267 | cp.y++; |
| 268 | } |
| 269 | // Do we need to scroll ? |
Kevin O'Connor | afb287d | 2009-05-31 21:15:33 -0400 | [diff] [blame] | 270 | if (cp.y < nbrows) { |
| 271 | *pcp = cp; |
| 272 | return; |
Kevin O'Connor | 82221b2 | 2009-05-26 00:20:40 -0400 | [diff] [blame] | 273 | } |
Kevin O'Connor | afb287d | 2009-05-31 21:15:33 -0400 | [diff] [blame] | 274 | // Scroll screen |
| 275 | cp.y--; |
| 276 | *pcp = cp; |
| 277 | scroll_one(nbrows, nbcols, cp.page); |
Kevin O'Connor | 82221b2 | 2009-05-26 00:20:40 -0400 | [diff] [blame] | 278 | } |
| 279 | |
Kevin O'Connor | afb287d | 2009-05-31 21:15:33 -0400 | [diff] [blame] | 280 | // Write out a buffer of alternating characters and attributes. |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 281 | static void |
Kevin O'Connor | afb287d | 2009-05-31 21:15:33 -0400 | [diff] [blame] | 282 | write_attr_string(struct cursorpos *pcp, u16 count, u16 seg, u8 *offset_far) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 283 | { |
Kevin O'Connor | 2e86c6a | 2009-05-31 20:43:06 -0400 | [diff] [blame] | 284 | while (count--) { |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 285 | u8 car = GET_FARVAR(seg, *offset_far); |
| 286 | offset_far++; |
Kevin O'Connor | afb287d | 2009-05-31 21:15:33 -0400 | [diff] [blame] | 287 | u8 attr = GET_FARVAR(seg, *offset_far); |
| 288 | offset_far++; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 289 | |
Kevin O'Connor | 0926241 | 2009-05-25 11:44:11 -0400 | [diff] [blame] | 290 | struct carattr ca = {car, attr, 1}; |
Kevin O'Connor | afb287d | 2009-05-31 21:15:33 -0400 | [diff] [blame] | 291 | write_teletype(pcp, ca); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 292 | } |
Kevin O'Connor | afb287d | 2009-05-31 21:15:33 -0400 | [diff] [blame] | 293 | } |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 294 | |
Kevin O'Connor | afb287d | 2009-05-31 21:15:33 -0400 | [diff] [blame] | 295 | // Write out a buffer of characters. |
| 296 | static void |
| 297 | write_string(struct cursorpos *pcp, u8 attr, u16 count, u16 seg, u8 *offset_far) |
| 298 | { |
| 299 | while (count--) { |
| 300 | u8 car = GET_FARVAR(seg, *offset_far); |
| 301 | offset_far++; |
| 302 | |
| 303 | struct carattr ca = {car, attr, 1}; |
| 304 | write_teletype(pcp, ca); |
| 305 | } |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 306 | } |
| 307 | |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 308 | |
| 309 | /**************************************************************** |
| 310 | * Save and restore bda state |
| 311 | ****************************************************************/ |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 312 | |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 313 | static void |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 314 | save_bda_state(u16 seg, struct saveBDAstate *info) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 315 | { |
Kevin O'Connor | ca66864 | 2009-05-21 23:06:08 -0400 | [diff] [blame] | 316 | SET_FARVAR(seg, info->video_mode, GET_BDA(video_mode)); |
| 317 | SET_FARVAR(seg, info->video_cols, GET_BDA(video_cols)); |
| 318 | SET_FARVAR(seg, info->video_pagesize, GET_BDA(video_pagesize)); |
| 319 | SET_FARVAR(seg, info->crtc_address, GET_BDA(crtc_address)); |
| 320 | SET_FARVAR(seg, info->video_rows, GET_BDA(video_rows)); |
| 321 | SET_FARVAR(seg, info->char_height, GET_BDA(char_height)); |
| 322 | SET_FARVAR(seg, info->video_ctl, GET_BDA(video_ctl)); |
| 323 | SET_FARVAR(seg, info->video_switches, GET_BDA(video_switches)); |
| 324 | SET_FARVAR(seg, info->modeset_ctl, GET_BDA(modeset_ctl)); |
| 325 | SET_FARVAR(seg, info->cursor_type, GET_BDA(cursor_type)); |
| 326 | u16 i; |
| 327 | for (i=0; i<8; i++) |
| 328 | SET_FARVAR(seg, info->cursor_pos[i], GET_BDA(cursor_pos[i])); |
| 329 | SET_FARVAR(seg, info->video_pagestart, GET_BDA(video_pagestart)); |
| 330 | SET_FARVAR(seg, info->video_page, GET_BDA(video_page)); |
| 331 | /* current font */ |
Kevin O'Connor | 9f98542 | 2009-09-09 11:34:39 -0400 | [diff] [blame] | 332 | SET_FARVAR(seg, info->font0, GET_IVT(0x1f)); |
| 333 | SET_FARVAR(seg, info->font1, GET_IVT(0x43)); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 334 | } |
| 335 | |
Kevin O'Connor | ca66864 | 2009-05-21 23:06:08 -0400 | [diff] [blame] | 336 | static void |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 337 | restore_bda_state(u16 seg, struct saveBDAstate *info) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 338 | { |
Kevin O'Connor | ca66864 | 2009-05-21 23:06:08 -0400 | [diff] [blame] | 339 | SET_BDA(video_mode, GET_FARVAR(seg, info->video_mode)); |
| 340 | SET_BDA(video_cols, GET_FARVAR(seg, info->video_cols)); |
| 341 | SET_BDA(video_pagesize, GET_FARVAR(seg, info->video_pagesize)); |
| 342 | SET_BDA(crtc_address, GET_FARVAR(seg, info->crtc_address)); |
| 343 | SET_BDA(video_rows, GET_FARVAR(seg, info->video_rows)); |
| 344 | SET_BDA(char_height, GET_FARVAR(seg, info->char_height)); |
| 345 | SET_BDA(video_ctl, GET_FARVAR(seg, info->video_ctl)); |
| 346 | SET_BDA(video_switches, GET_FARVAR(seg, info->video_switches)); |
| 347 | SET_BDA(modeset_ctl, GET_FARVAR(seg, info->modeset_ctl)); |
| 348 | SET_BDA(cursor_type, GET_FARVAR(seg, info->cursor_type)); |
| 349 | u16 i; |
| 350 | for (i = 0; i < 8; i++) |
| 351 | SET_BDA(cursor_pos[i], GET_FARVAR(seg, info->cursor_pos[i])); |
| 352 | SET_BDA(video_pagestart, GET_FARVAR(seg, info->video_pagestart)); |
| 353 | SET_BDA(video_page, GET_FARVAR(seg, info->video_page)); |
| 354 | /* current font */ |
Kevin O'Connor | 9f98542 | 2009-09-09 11:34:39 -0400 | [diff] [blame] | 355 | SET_IVT(0x1f, GET_FARVAR(seg, info->font0)); |
| 356 | SET_IVT(0x43, GET_FARVAR(seg, info->font1)); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | |
| 360 | /**************************************************************** |
| 361 | * VGA int 10 handler |
| 362 | ****************************************************************/ |
| 363 | |
Kevin O'Connor | 85ea07e | 2009-05-25 09:41:07 -0400 | [diff] [blame] | 364 | // set video mode |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 365 | static void |
| 366 | handle_1000(struct bregs *regs) |
| 367 | { |
Kevin O'Connor | 85ea07e | 2009-05-25 09:41:07 -0400 | [diff] [blame] | 368 | u8 noclearmem = regs->al & 0x80; |
| 369 | u8 mode = regs->al & 0x7f; |
| 370 | |
Kevin O'Connor | 918b156 | 2009-05-25 11:05:18 -0400 | [diff] [blame] | 371 | // Set regs->al |
| 372 | if (mode > 7) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 373 | regs->al = 0x20; |
Kevin O'Connor | 918b156 | 2009-05-25 11:05:18 -0400 | [diff] [blame] | 374 | else if (mode == 6) |
| 375 | regs->al = 0x3f; |
| 376 | else |
| 377 | regs->al = 0x30; |
Kevin O'Connor | 85ea07e | 2009-05-25 09:41:07 -0400 | [diff] [blame] | 378 | |
Julian Pidancet | 677631f | 2011-12-19 05:07:53 +0000 | [diff] [blame] | 379 | if (CONFIG_VGA_CIRRUS) |
Kevin O'Connor | 85ea07e | 2009-05-25 09:41:07 -0400 | [diff] [blame] | 380 | cirrus_set_video_mode(mode); |
| 381 | |
Julian Pidancet | 677631f | 2011-12-19 05:07:53 +0000 | [diff] [blame] | 382 | if (CONFIG_VGA_BOCHS) |
| 383 | if (bochs_has_vbe_display()) |
Kevin O'Connor | 85ea07e | 2009-05-25 09:41:07 -0400 | [diff] [blame] | 384 | dispi_set_enable(VBE_DISPI_DISABLED); |
| 385 | |
| 386 | // find the entry in the video modes |
| 387 | struct vgamode_s *vmode_g = find_vga_entry(mode); |
| 388 | dprintf(1, "mode search %02x found %p\n", mode, vmode_g); |
| 389 | if (!vmode_g) |
| 390 | return; |
| 391 | |
| 392 | // Read the bios mode set control |
| 393 | u8 modeset_ctl = GET_BDA(modeset_ctl); |
| 394 | |
| 395 | // Then we know the number of lines |
| 396 | // FIXME |
| 397 | |
| 398 | // if palette loading (bit 3 of modeset ctl = 0) |
| 399 | if ((modeset_ctl & 0x08) == 0) { // Set the PEL mask |
| 400 | vgahw_set_pel_mask(GET_GLOBAL(vmode_g->pelmask)); |
| 401 | |
| 402 | // From which palette |
| 403 | u8 *palette_g = GET_GLOBAL(vmode_g->dac); |
| 404 | u16 palsize = GET_GLOBAL(vmode_g->dacsize) / 3; |
| 405 | |
| 406 | // Always 256*3 values |
| 407 | vgahw_set_dac_regs(get_global_seg(), palette_g, 0, palsize); |
| 408 | u16 i; |
| 409 | for (i = palsize; i < 0x0100; i++) { |
| 410 | static u8 rgb[3] VAR16; |
| 411 | vgahw_set_dac_regs(get_global_seg(), rgb, i, 1); |
| 412 | } |
| 413 | |
| 414 | if ((modeset_ctl & 0x02) == 0x02) |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 415 | perform_gray_scale_summing(0x00, 0x100); |
Kevin O'Connor | 85ea07e | 2009-05-25 09:41:07 -0400 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | struct VideoParam_s *vparam_g = GET_GLOBAL(vmode_g->vparam); |
| 419 | vgahw_set_mode(vparam_g); |
| 420 | |
| 421 | if (noclearmem == 0x00) |
| 422 | clear_screen(vmode_g); |
| 423 | |
| 424 | // Set CRTC address VGA or MDA |
| 425 | u16 crtc_addr = VGAREG_VGA_CRTC_ADDRESS; |
| 426 | if (GET_GLOBAL(vmode_g->memmodel) == MTEXT) |
| 427 | crtc_addr = VGAREG_MDA_CRTC_ADDRESS; |
| 428 | |
| 429 | // Set the BIOS mem |
| 430 | u16 cheight = GET_GLOBAL(vparam_g->cheight); |
| 431 | SET_BDA(video_mode, mode); |
| 432 | SET_BDA(video_cols, GET_GLOBAL(vparam_g->twidth)); |
| 433 | SET_BDA(video_pagesize, GET_GLOBAL(vparam_g->slength)); |
| 434 | SET_BDA(crtc_address, crtc_addr); |
| 435 | SET_BDA(video_rows, GET_GLOBAL(vparam_g->theightm1)); |
| 436 | SET_BDA(char_height, cheight); |
| 437 | SET_BDA(video_ctl, (0x60 | noclearmem)); |
| 438 | SET_BDA(video_switches, 0xF9); |
| 439 | SET_BDA(modeset_ctl, GET_BDA(modeset_ctl) & 0x7f); |
| 440 | |
| 441 | // FIXME We nearly have the good tables. to be reworked |
| 442 | SET_BDA(dcc_index, 0x08); // 8 is VGA should be ok for now |
Kevin O'Connor | 9f98542 | 2009-09-09 11:34:39 -0400 | [diff] [blame] | 443 | SET_BDA(video_savetable |
| 444 | , SEGOFF(get_global_seg(), (u32)video_save_pointer_table)); |
Kevin O'Connor | 85ea07e | 2009-05-25 09:41:07 -0400 | [diff] [blame] | 445 | |
| 446 | // FIXME |
| 447 | SET_BDA(video_msr, 0x00); // Unavailable on vanilla vga, but... |
| 448 | SET_BDA(video_pal, 0x00); // Unavailable on vanilla vga, but... |
| 449 | |
| 450 | // Set cursor shape |
Kevin O'Connor | e4f220f | 2009-05-25 23:37:13 -0400 | [diff] [blame] | 451 | if (GET_GLOBAL(vmode_g->memmodel) & TEXT) |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 452 | set_cursor_shape(0x06, 0x07); |
Kevin O'Connor | 85ea07e | 2009-05-25 09:41:07 -0400 | [diff] [blame] | 453 | // Set cursor pos for page 0..7 |
| 454 | int i; |
Kevin O'Connor | 918b156 | 2009-05-25 11:05:18 -0400 | [diff] [blame] | 455 | for (i = 0; i < 8; i++) { |
| 456 | struct cursorpos cp = {0, 0, i}; |
| 457 | set_cursor_pos(cp); |
| 458 | } |
Kevin O'Connor | 85ea07e | 2009-05-25 09:41:07 -0400 | [diff] [blame] | 459 | |
| 460 | // Set active page 0 |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 461 | set_active_page(0x00); |
Kevin O'Connor | 85ea07e | 2009-05-25 09:41:07 -0400 | [diff] [blame] | 462 | |
| 463 | // Write the fonts in memory |
Kevin O'Connor | e4f220f | 2009-05-25 23:37:13 -0400 | [diff] [blame] | 464 | if (GET_GLOBAL(vmode_g->memmodel) & TEXT) { |
Kevin O'Connor | 85ea07e | 2009-05-25 09:41:07 -0400 | [diff] [blame] | 465 | call16_vgaint(0x1104, 0); |
| 466 | call16_vgaint(0x1103, 0); |
| 467 | } |
| 468 | // Set the ints 0x1F and 0x43 |
Kevin O'Connor | 9f98542 | 2009-09-09 11:34:39 -0400 | [diff] [blame] | 469 | SET_IVT(0x1f, SEGOFF(get_global_seg(), (u32)&vgafont8[128 * 8])); |
Kevin O'Connor | 85ea07e | 2009-05-25 09:41:07 -0400 | [diff] [blame] | 470 | |
| 471 | switch (cheight) { |
| 472 | case 8: |
Kevin O'Connor | 9f98542 | 2009-09-09 11:34:39 -0400 | [diff] [blame] | 473 | SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont8)); |
Kevin O'Connor | 85ea07e | 2009-05-25 09:41:07 -0400 | [diff] [blame] | 474 | break; |
| 475 | case 14: |
Kevin O'Connor | 9f98542 | 2009-09-09 11:34:39 -0400 | [diff] [blame] | 476 | SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont14)); |
Kevin O'Connor | 85ea07e | 2009-05-25 09:41:07 -0400 | [diff] [blame] | 477 | break; |
| 478 | case 16: |
Kevin O'Connor | 9f98542 | 2009-09-09 11:34:39 -0400 | [diff] [blame] | 479 | SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont16)); |
Kevin O'Connor | 85ea07e | 2009-05-25 09:41:07 -0400 | [diff] [blame] | 480 | break; |
| 481 | } |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | static void |
| 485 | handle_1001(struct bregs *regs) |
| 486 | { |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 487 | set_cursor_shape(regs->ch, regs->cl); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 488 | } |
| 489 | |
| 490 | static void |
| 491 | handle_1002(struct bregs *regs) |
| 492 | { |
Kevin O'Connor | 918b156 | 2009-05-25 11:05:18 -0400 | [diff] [blame] | 493 | struct cursorpos cp = {regs->dl, regs->dh, regs->bh}; |
| 494 | set_cursor_pos(cp); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | static void |
| 498 | handle_1003(struct bregs *regs) |
| 499 | { |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 500 | regs->cx = get_cursor_shape(regs->bh); |
Kevin O'Connor | 918b156 | 2009-05-25 11:05:18 -0400 | [diff] [blame] | 501 | struct cursorpos cp = get_cursor_pos(regs->bh); |
| 502 | regs->dl = cp.x; |
| 503 | regs->dh = cp.y; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | // Read light pen pos (unimplemented) |
| 507 | static void |
| 508 | handle_1004(struct bregs *regs) |
| 509 | { |
| 510 | debug_stub(regs); |
| 511 | regs->ax = regs->bx = regs->cx = regs->dx = 0; |
| 512 | } |
| 513 | |
| 514 | static void |
| 515 | handle_1005(struct bregs *regs) |
| 516 | { |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 517 | set_active_page(regs->al); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | static void |
Kevin O'Connor | 217f2bc | 2009-05-31 00:46:47 -0400 | [diff] [blame] | 521 | verify_scroll(struct bregs *regs, int dir) |
| 522 | { |
| 523 | u8 page = GET_BDA(video_page); |
| 524 | struct cursorpos ul = {regs->cl, regs->ch, page}; |
| 525 | struct cursorpos lr = {regs->dl, regs->dh, page}; |
| 526 | |
Kevin O'Connor | 217f2bc | 2009-05-31 00:46:47 -0400 | [diff] [blame] | 527 | u16 nbrows = GET_BDA(video_rows) + 1; |
Kevin O'Connor | 217f2bc | 2009-05-31 00:46:47 -0400 | [diff] [blame] | 528 | if (lr.y >= nbrows) |
| 529 | lr.y = nbrows - 1; |
Kevin O'Connor | c3e1587 | 2009-05-31 01:37:54 -0400 | [diff] [blame] | 530 | u16 nbcols = GET_BDA(video_cols); |
Kevin O'Connor | 217f2bc | 2009-05-31 00:46:47 -0400 | [diff] [blame] | 531 | if (lr.x >= nbcols) |
| 532 | lr.x = nbcols - 1; |
| 533 | |
Kevin O'Connor | c3e1587 | 2009-05-31 01:37:54 -0400 | [diff] [blame] | 534 | if (ul.x > lr.x || ul.y > lr.y) |
| 535 | return; |
| 536 | |
| 537 | u16 nblines = regs->al; |
| 538 | if (!nblines || nblines > lr.y - ul.y + 1) |
| 539 | nblines = lr.y - ul.y + 1; |
| 540 | |
| 541 | vgafb_scroll(dir * nblines, regs->bh, ul, lr); |
Kevin O'Connor | 217f2bc | 2009-05-31 00:46:47 -0400 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | static void |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 545 | handle_1006(struct bregs *regs) |
| 546 | { |
Kevin O'Connor | 217f2bc | 2009-05-31 00:46:47 -0400 | [diff] [blame] | 547 | verify_scroll(regs, 1); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | static void |
| 551 | handle_1007(struct bregs *regs) |
| 552 | { |
Kevin O'Connor | 217f2bc | 2009-05-31 00:46:47 -0400 | [diff] [blame] | 553 | verify_scroll(regs, -1); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | static void |
| 557 | handle_1008(struct bregs *regs) |
| 558 | { |
Kevin O'Connor | d3b3815 | 2009-05-26 00:05:37 -0400 | [diff] [blame] | 559 | struct carattr ca = vgafb_read_char(get_cursor_pos(regs->bh)); |
Kevin O'Connor | 0926241 | 2009-05-25 11:44:11 -0400 | [diff] [blame] | 560 | regs->al = ca.car; |
| 561 | regs->ah = ca.attr; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 562 | } |
| 563 | |
Kevin O'Connor | 0ad77f0 | 2009-05-31 20:46:43 -0400 | [diff] [blame] | 564 | static void noinline |
Kevin O'Connor | d3b3815 | 2009-05-26 00:05:37 -0400 | [diff] [blame] | 565 | write_chars(u8 page, struct carattr ca, u16 count) |
| 566 | { |
| 567 | struct cursorpos cp = get_cursor_pos(page); |
| 568 | while (count--) { |
| 569 | vgafb_write_char(cp, ca); |
| 570 | cp.x++; |
| 571 | } |
| 572 | } |
| 573 | |
| 574 | static void |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 575 | handle_1009(struct bregs *regs) |
| 576 | { |
Kevin O'Connor | 0926241 | 2009-05-25 11:44:11 -0400 | [diff] [blame] | 577 | struct carattr ca = {regs->al, regs->bl, 1}; |
Kevin O'Connor | d3b3815 | 2009-05-26 00:05:37 -0400 | [diff] [blame] | 578 | write_chars(regs->bh, ca, regs->cx); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 579 | } |
| 580 | |
| 581 | static void |
| 582 | handle_100a(struct bregs *regs) |
| 583 | { |
Kevin O'Connor | 0926241 | 2009-05-25 11:44:11 -0400 | [diff] [blame] | 584 | struct carattr ca = {regs->al, regs->bl, 0}; |
Kevin O'Connor | d3b3815 | 2009-05-26 00:05:37 -0400 | [diff] [blame] | 585 | write_chars(regs->bh, ca, regs->cx); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 586 | } |
| 587 | |
| 588 | |
| 589 | static void |
| 590 | handle_100b00(struct bregs *regs) |
| 591 | { |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 592 | vgahw_set_border_color(regs->bl); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | static void |
| 596 | handle_100b01(struct bregs *regs) |
| 597 | { |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 598 | vgahw_set_palette(regs->bl); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | static void |
| 602 | handle_100bXX(struct bregs *regs) |
| 603 | { |
| 604 | debug_stub(regs); |
| 605 | } |
| 606 | |
| 607 | static void |
| 608 | handle_100b(struct bregs *regs) |
| 609 | { |
| 610 | switch (regs->bh) { |
| 611 | case 0x00: handle_100b00(regs); break; |
| 612 | case 0x01: handle_100b01(regs); break; |
| 613 | default: handle_100bXX(regs); break; |
| 614 | } |
| 615 | } |
| 616 | |
| 617 | |
| 618 | static void |
| 619 | handle_100c(struct bregs *regs) |
| 620 | { |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 621 | // XXX - page (regs->bh) is unused |
| 622 | vgafb_write_pixel(regs->al, regs->cx, regs->dx); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | static void |
| 626 | handle_100d(struct bregs *regs) |
| 627 | { |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 628 | // XXX - page (regs->bh) is unused |
| 629 | regs->al = vgafb_read_pixel(regs->cx, regs->dx); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 630 | } |
| 631 | |
Kevin O'Connor | 0ad77f0 | 2009-05-31 20:46:43 -0400 | [diff] [blame] | 632 | static void noinline |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 633 | handle_100e(struct bregs *regs) |
| 634 | { |
| 635 | // Ralf Brown Interrupt list is WRONG on bh(page) |
| 636 | // We do output only on the current page ! |
Kevin O'Connor | 0926241 | 2009-05-25 11:44:11 -0400 | [diff] [blame] | 637 | struct carattr ca = {regs->al, regs->bl, 0}; |
Kevin O'Connor | 116a044 | 2009-05-26 00:47:32 -0400 | [diff] [blame] | 638 | struct cursorpos cp = get_cursor_pos(0xff); |
Kevin O'Connor | afb287d | 2009-05-31 21:15:33 -0400 | [diff] [blame] | 639 | write_teletype(&cp, ca); |
Kevin O'Connor | 116a044 | 2009-05-26 00:47:32 -0400 | [diff] [blame] | 640 | set_cursor_pos(cp); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | static void |
| 644 | handle_100f(struct bregs *regs) |
| 645 | { |
Kevin O'Connor | e713204 | 2009-05-25 00:10:35 -0400 | [diff] [blame] | 646 | regs->bh = GET_BDA(video_page); |
| 647 | regs->al = GET_BDA(video_mode) | (GET_BDA(video_ctl) & 0x80); |
| 648 | regs->ah = GET_BDA(video_cols); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | |
| 652 | static void |
| 653 | handle_101000(struct bregs *regs) |
| 654 | { |
| 655 | if (regs->bl > 0x14) |
| 656 | return; |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 657 | vgahw_set_single_palette_reg(regs->bl, regs->bh); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | static void |
| 661 | handle_101001(struct bregs *regs) |
| 662 | { |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 663 | vgahw_set_overscan_border_color(regs->bh); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 664 | } |
| 665 | |
| 666 | static void |
| 667 | handle_101002(struct bregs *regs) |
| 668 | { |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 669 | vgahw_set_all_palette_reg(regs->es, (u8*)(regs->dx + 0)); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | static void |
| 673 | handle_101003(struct bregs *regs) |
| 674 | { |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 675 | vgahw_toggle_intensity(regs->bl); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 676 | } |
| 677 | |
| 678 | static void |
| 679 | handle_101007(struct bregs *regs) |
| 680 | { |
| 681 | if (regs->bl > 0x14) |
| 682 | return; |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 683 | regs->bh = vgahw_get_single_palette_reg(regs->bl); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | static void |
| 687 | handle_101008(struct bregs *regs) |
| 688 | { |
Kevin O'Connor | 3862b2d | 2010-01-03 17:53:58 -0500 | [diff] [blame] | 689 | regs->bh = vgahw_get_overscan_border_color(); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | static void |
| 693 | handle_101009(struct bregs *regs) |
| 694 | { |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 695 | vgahw_get_all_palette_reg(regs->es, (u8*)(regs->dx + 0)); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 696 | } |
| 697 | |
Kevin O'Connor | 0ad77f0 | 2009-05-31 20:46:43 -0400 | [diff] [blame] | 698 | static void noinline |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 699 | handle_101010(struct bregs *regs) |
| 700 | { |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 701 | u8 rgb[3] = {regs->dh, regs->ch, regs->cl}; |
| 702 | vgahw_set_dac_regs(GET_SEG(SS), rgb, regs->bx, 1); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 703 | } |
| 704 | |
| 705 | static void |
| 706 | handle_101012(struct bregs *regs) |
| 707 | { |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 708 | vgahw_set_dac_regs(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | static void |
| 712 | handle_101013(struct bregs *regs) |
| 713 | { |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 714 | vgahw_select_video_dac_color_page(regs->bl, regs->bh); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 715 | } |
| 716 | |
Kevin O'Connor | 0ad77f0 | 2009-05-31 20:46:43 -0400 | [diff] [blame] | 717 | static void noinline |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 718 | handle_101015(struct bregs *regs) |
| 719 | { |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 720 | u8 rgb[3]; |
| 721 | vgahw_get_dac_regs(GET_SEG(SS), rgb, regs->bx, 1); |
| 722 | regs->dh = rgb[0]; |
| 723 | regs->ch = rgb[1]; |
| 724 | regs->cl = rgb[2]; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 725 | } |
| 726 | |
| 727 | static void |
| 728 | handle_101017(struct bregs *regs) |
| 729 | { |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 730 | vgahw_get_dac_regs(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 731 | } |
| 732 | |
| 733 | static void |
| 734 | handle_101018(struct bregs *regs) |
| 735 | { |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 736 | vgahw_set_pel_mask(regs->bl); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 737 | } |
| 738 | |
| 739 | static void |
| 740 | handle_101019(struct bregs *regs) |
| 741 | { |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 742 | regs->bl = vgahw_get_pel_mask(); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | static void |
| 746 | handle_10101a(struct bregs *regs) |
| 747 | { |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 748 | vgahw_read_video_dac_state(®s->bl, ®s->bh); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 749 | } |
| 750 | |
| 751 | static void |
| 752 | handle_10101b(struct bregs *regs) |
| 753 | { |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 754 | perform_gray_scale_summing(regs->bx, regs->cx); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 755 | } |
| 756 | |
| 757 | static void |
| 758 | handle_1010XX(struct bregs *regs) |
| 759 | { |
| 760 | debug_stub(regs); |
| 761 | } |
| 762 | |
| 763 | static void |
| 764 | handle_1010(struct bregs *regs) |
| 765 | { |
| 766 | switch (regs->al) { |
| 767 | case 0x00: handle_101000(regs); break; |
| 768 | case 0x01: handle_101001(regs); break; |
| 769 | case 0x02: handle_101002(regs); break; |
| 770 | case 0x03: handle_101003(regs); break; |
| 771 | case 0x07: handle_101007(regs); break; |
| 772 | case 0x08: handle_101008(regs); break; |
| 773 | case 0x09: handle_101009(regs); break; |
| 774 | case 0x10: handle_101010(regs); break; |
| 775 | case 0x12: handle_101012(regs); break; |
| 776 | case 0x13: handle_101013(regs); break; |
| 777 | case 0x15: handle_101015(regs); break; |
| 778 | case 0x17: handle_101017(regs); break; |
| 779 | case 0x18: handle_101018(regs); break; |
| 780 | case 0x19: handle_101019(regs); break; |
| 781 | case 0x1a: handle_10101a(regs); break; |
| 782 | case 0x1b: handle_10101b(regs); break; |
| 783 | default: handle_1010XX(regs); break; |
| 784 | } |
| 785 | } |
| 786 | |
| 787 | |
| 788 | static void |
| 789 | handle_101100(struct bregs *regs) |
| 790 | { |
Kevin O'Connor | deb9cb9 | 2009-05-25 09:06:50 -0400 | [diff] [blame] | 791 | vgafb_load_font(regs->es, (void*)(regs->bp+0), regs->cx |
| 792 | , regs->dx, regs->bl, regs->bh); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 793 | } |
| 794 | |
| 795 | static void |
| 796 | handle_101101(struct bregs *regs) |
| 797 | { |
Kevin O'Connor | deb9cb9 | 2009-05-25 09:06:50 -0400 | [diff] [blame] | 798 | vgafb_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 799 | } |
| 800 | |
| 801 | static void |
| 802 | handle_101102(struct bregs *regs) |
| 803 | { |
Kevin O'Connor | deb9cb9 | 2009-05-25 09:06:50 -0400 | [diff] [blame] | 804 | vgafb_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 805 | } |
| 806 | |
| 807 | static void |
| 808 | handle_101103(struct bregs *regs) |
| 809 | { |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 810 | vgahw_set_text_block_specifier(regs->bl); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 811 | } |
| 812 | |
| 813 | static void |
| 814 | handle_101104(struct bregs *regs) |
| 815 | { |
Kevin O'Connor | deb9cb9 | 2009-05-25 09:06:50 -0400 | [diff] [blame] | 816 | vgafb_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 817 | } |
| 818 | |
| 819 | static void |
| 820 | handle_101110(struct bregs *regs) |
| 821 | { |
Kevin O'Connor | deb9cb9 | 2009-05-25 09:06:50 -0400 | [diff] [blame] | 822 | vgafb_load_font(regs->es, (void*)(regs->bp+0), regs->cx |
| 823 | , regs->dx, regs->bl, regs->bh); |
Kevin O'Connor | c0c7df6 | 2009-05-17 18:11:33 -0400 | [diff] [blame] | 824 | set_scan_lines(regs->bh); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 825 | } |
| 826 | |
| 827 | static void |
| 828 | handle_101111(struct bregs *regs) |
| 829 | { |
Kevin O'Connor | deb9cb9 | 2009-05-25 09:06:50 -0400 | [diff] [blame] | 830 | vgafb_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14); |
Kevin O'Connor | c0c7df6 | 2009-05-17 18:11:33 -0400 | [diff] [blame] | 831 | set_scan_lines(14); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 832 | } |
| 833 | |
| 834 | static void |
| 835 | handle_101112(struct bregs *regs) |
| 836 | { |
Kevin O'Connor | deb9cb9 | 2009-05-25 09:06:50 -0400 | [diff] [blame] | 837 | vgafb_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8); |
Kevin O'Connor | c0c7df6 | 2009-05-17 18:11:33 -0400 | [diff] [blame] | 838 | set_scan_lines(8); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 839 | } |
| 840 | |
| 841 | static void |
| 842 | handle_101114(struct bregs *regs) |
| 843 | { |
Kevin O'Connor | deb9cb9 | 2009-05-25 09:06:50 -0400 | [diff] [blame] | 844 | vgafb_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16); |
Kevin O'Connor | c0c7df6 | 2009-05-17 18:11:33 -0400 | [diff] [blame] | 845 | set_scan_lines(16); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 846 | } |
| 847 | |
| 848 | static void |
| 849 | handle_101130(struct bregs *regs) |
| 850 | { |
Kevin O'Connor | e713204 | 2009-05-25 00:10:35 -0400 | [diff] [blame] | 851 | switch (regs->bh) { |
| 852 | case 0x00: { |
Kevin O'Connor | c9d3c2d | 2010-01-01 12:53:32 -0500 | [diff] [blame] | 853 | struct segoff_s so = GET_IVT(0x1f); |
| 854 | regs->es = so.seg; |
| 855 | regs->bp = so.offset; |
Kevin O'Connor | e713204 | 2009-05-25 00:10:35 -0400 | [diff] [blame] | 856 | break; |
| 857 | } |
| 858 | case 0x01: { |
Kevin O'Connor | c9d3c2d | 2010-01-01 12:53:32 -0500 | [diff] [blame] | 859 | struct segoff_s so = GET_IVT(0x43); |
| 860 | regs->es = so.seg; |
| 861 | regs->bp = so.offset; |
Kevin O'Connor | e713204 | 2009-05-25 00:10:35 -0400 | [diff] [blame] | 862 | break; |
| 863 | } |
| 864 | case 0x02: |
| 865 | regs->es = get_global_seg(); |
| 866 | regs->bp = (u32)vgafont14; |
| 867 | break; |
| 868 | case 0x03: |
| 869 | regs->es = get_global_seg(); |
| 870 | regs->bp = (u32)vgafont8; |
| 871 | break; |
| 872 | case 0x04: |
| 873 | regs->es = get_global_seg(); |
| 874 | regs->bp = (u32)vgafont8 + 128 * 8; |
| 875 | break; |
| 876 | case 0x05: |
| 877 | regs->es = get_global_seg(); |
| 878 | regs->bp = (u32)vgafont14alt; |
| 879 | break; |
| 880 | case 0x06: |
| 881 | regs->es = get_global_seg(); |
| 882 | regs->bp = (u32)vgafont16; |
| 883 | break; |
| 884 | case 0x07: |
| 885 | regs->es = get_global_seg(); |
| 886 | regs->bp = (u32)vgafont16alt; |
| 887 | break; |
| 888 | default: |
| 889 | dprintf(1, "Get font info BH(%02x) was discarded\n", regs->bh); |
| 890 | return; |
| 891 | } |
| 892 | // Set byte/char of on screen font |
| 893 | regs->cx = GET_BDA(char_height) & 0xff; |
| 894 | |
| 895 | // Set Highest char row |
| 896 | regs->dx = GET_BDA(video_rows); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 897 | } |
| 898 | |
| 899 | static void |
| 900 | handle_1011XX(struct bregs *regs) |
| 901 | { |
| 902 | debug_stub(regs); |
| 903 | } |
| 904 | |
| 905 | static void |
| 906 | handle_1011(struct bregs *regs) |
| 907 | { |
| 908 | switch (regs->al) { |
| 909 | case 0x00: handle_101100(regs); break; |
| 910 | case 0x01: handle_101101(regs); break; |
| 911 | case 0x02: handle_101102(regs); break; |
| 912 | case 0x03: handle_101103(regs); break; |
| 913 | case 0x04: handle_101104(regs); break; |
| 914 | case 0x10: handle_101110(regs); break; |
| 915 | case 0x11: handle_101111(regs); break; |
| 916 | case 0x12: handle_101112(regs); break; |
| 917 | case 0x14: handle_101114(regs); break; |
| 918 | case 0x30: handle_101130(regs); break; |
| 919 | default: handle_1011XX(regs); break; |
| 920 | } |
| 921 | } |
| 922 | |
| 923 | |
| 924 | static void |
| 925 | handle_101210(struct bregs *regs) |
| 926 | { |
Kevin O'Connor | e713204 | 2009-05-25 00:10:35 -0400 | [diff] [blame] | 927 | u16 crtc_addr = GET_BDA(crtc_address); |
| 928 | if (crtc_addr == VGAREG_MDA_CRTC_ADDRESS) |
| 929 | regs->bx = 0x0103; |
| 930 | else |
| 931 | regs->bx = 0x0003; |
| 932 | regs->cx = GET_BDA(video_switches) & 0x0f; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 933 | } |
| 934 | |
| 935 | static void |
| 936 | handle_101230(struct bregs *regs) |
| 937 | { |
Kevin O'Connor | e713204 | 2009-05-25 00:10:35 -0400 | [diff] [blame] | 938 | u8 mctl = GET_BDA(modeset_ctl); |
| 939 | u8 vswt = GET_BDA(video_switches); |
| 940 | switch (regs->al) { |
| 941 | case 0x00: |
| 942 | // 200 lines |
| 943 | mctl = (mctl & ~0x10) | 0x80; |
| 944 | vswt = (vswt & ~0x0f) | 0x08; |
| 945 | break; |
| 946 | case 0x01: |
| 947 | // 350 lines |
| 948 | mctl &= ~0x90; |
| 949 | vswt = (vswt & ~0x0f) | 0x09; |
| 950 | break; |
| 951 | case 0x02: |
| 952 | // 400 lines |
| 953 | mctl = (mctl & ~0x80) | 0x10; |
| 954 | vswt = (vswt & ~0x0f) | 0x09; |
| 955 | break; |
| 956 | default: |
| 957 | dprintf(1, "Select vert res (%02x) was discarded\n", regs->al); |
| 958 | break; |
| 959 | } |
| 960 | SET_BDA(modeset_ctl, mctl); |
| 961 | SET_BDA(video_switches, vswt); |
| 962 | regs->al = 0x12; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 963 | } |
| 964 | |
| 965 | static void |
| 966 | handle_101231(struct bregs *regs) |
| 967 | { |
Kevin O'Connor | e713204 | 2009-05-25 00:10:35 -0400 | [diff] [blame] | 968 | u8 v = (regs->al & 0x01) << 3; |
| 969 | u8 mctl = GET_BDA(video_ctl) & ~0x08; |
| 970 | SET_BDA(video_ctl, mctl | v); |
| 971 | regs->al = 0x12; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 972 | } |
| 973 | |
| 974 | static void |
| 975 | handle_101232(struct bregs *regs) |
| 976 | { |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 977 | vgahw_enable_video_addressing(regs->al); |
| 978 | regs->al = 0x12; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 979 | } |
| 980 | |
| 981 | static void |
| 982 | handle_101233(struct bregs *regs) |
| 983 | { |
Kevin O'Connor | e713204 | 2009-05-25 00:10:35 -0400 | [diff] [blame] | 984 | u8 v = ((regs->al << 1) & 0x02) ^ 0x02; |
| 985 | u8 v2 = GET_BDA(modeset_ctl) & ~0x02; |
| 986 | SET_BDA(modeset_ctl, v | v2); |
| 987 | regs->al = 0x12; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 988 | } |
| 989 | |
| 990 | static void |
| 991 | handle_101234(struct bregs *regs) |
| 992 | { |
Kevin O'Connor | e713204 | 2009-05-25 00:10:35 -0400 | [diff] [blame] | 993 | u8 v = (regs->al & 0x01) ^ 0x01; |
| 994 | u8 v2 = GET_BDA(modeset_ctl) & ~0x01; |
| 995 | SET_BDA(modeset_ctl, v | v2); |
| 996 | regs->al = 0x12; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 997 | } |
| 998 | |
| 999 | static void |
| 1000 | handle_101235(struct bregs *regs) |
| 1001 | { |
| 1002 | debug_stub(regs); |
| 1003 | regs->al = 0x12; |
| 1004 | } |
| 1005 | |
| 1006 | static void |
| 1007 | handle_101236(struct bregs *regs) |
| 1008 | { |
| 1009 | debug_stub(regs); |
| 1010 | regs->al = 0x12; |
| 1011 | } |
| 1012 | |
| 1013 | static void |
| 1014 | handle_1012XX(struct bregs *regs) |
| 1015 | { |
| 1016 | debug_stub(regs); |
| 1017 | } |
| 1018 | |
| 1019 | static void |
| 1020 | handle_1012(struct bregs *regs) |
| 1021 | { |
| 1022 | switch (regs->bl) { |
| 1023 | case 0x10: handle_101210(regs); break; |
| 1024 | case 0x30: handle_101230(regs); break; |
| 1025 | case 0x31: handle_101231(regs); break; |
| 1026 | case 0x32: handle_101232(regs); break; |
| 1027 | case 0x33: handle_101233(regs); break; |
| 1028 | case 0x34: handle_101234(regs); break; |
| 1029 | case 0x35: handle_101235(regs); break; |
| 1030 | case 0x36: handle_101236(regs); break; |
| 1031 | default: handle_1012XX(regs); break; |
| 1032 | } |
| 1033 | |
| 1034 | // XXX - cirrus has 1280, 1281, 1282, 1285, 129a, 12a0, 12a1, 12a2, 12ae |
| 1035 | } |
| 1036 | |
| 1037 | |
Kevin O'Connor | afb287d | 2009-05-31 21:15:33 -0400 | [diff] [blame] | 1038 | // Write string |
Kevin O'Connor | 0ad77f0 | 2009-05-31 20:46:43 -0400 | [diff] [blame] | 1039 | static void noinline |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1040 | handle_1013(struct bregs *regs) |
| 1041 | { |
Kevin O'Connor | 918b156 | 2009-05-25 11:05:18 -0400 | [diff] [blame] | 1042 | struct cursorpos cp = {regs->dl, regs->dh, regs->bh}; |
Kevin O'Connor | 2e86c6a | 2009-05-31 20:43:06 -0400 | [diff] [blame] | 1043 | // if row=0xff special case : use current cursor position |
| 1044 | if (cp.y == 0xff) |
| 1045 | cp = get_cursor_pos(cp.page); |
Kevin O'Connor | afb287d | 2009-05-31 21:15:33 -0400 | [diff] [blame] | 1046 | u8 flag = regs->al; |
| 1047 | if (flag & 2) |
| 1048 | write_attr_string(&cp, regs->cx, regs->es, (void*)(regs->bp + 0)); |
| 1049 | else |
| 1050 | write_string(&cp, regs->bl, regs->cx, regs->es, (void*)(regs->bp + 0)); |
| 1051 | |
| 1052 | if (flag & 1) |
| 1053 | set_cursor_pos(cp); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1054 | } |
| 1055 | |
| 1056 | |
| 1057 | static void |
| 1058 | handle_101a00(struct bregs *regs) |
| 1059 | { |
Kevin O'Connor | e713204 | 2009-05-25 00:10:35 -0400 | [diff] [blame] | 1060 | regs->bx = GET_BDA(dcc_index); |
| 1061 | regs->al = 0x1a; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1062 | } |
| 1063 | |
| 1064 | static void |
| 1065 | handle_101a01(struct bregs *regs) |
| 1066 | { |
Kevin O'Connor | e713204 | 2009-05-25 00:10:35 -0400 | [diff] [blame] | 1067 | SET_BDA(dcc_index, regs->bl); |
| 1068 | dprintf(1, "Alternate Display code (%02x) was discarded\n", regs->bh); |
| 1069 | regs->al = 0x1a; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1070 | } |
| 1071 | |
| 1072 | static void |
| 1073 | handle_101aXX(struct bregs *regs) |
| 1074 | { |
| 1075 | debug_stub(regs); |
| 1076 | } |
| 1077 | |
| 1078 | static void |
| 1079 | handle_101a(struct bregs *regs) |
| 1080 | { |
| 1081 | switch (regs->al) { |
| 1082 | case 0x00: handle_101a00(regs); break; |
| 1083 | case 0x01: handle_101a01(regs); break; |
| 1084 | default: handle_101aXX(regs); break; |
| 1085 | } |
| 1086 | } |
| 1087 | |
| 1088 | |
Kevin O'Connor | ca66864 | 2009-05-21 23:06:08 -0400 | [diff] [blame] | 1089 | struct funcInfo { |
| 1090 | u16 static_functionality_off; |
| 1091 | u16 static_functionality_seg; |
| 1092 | u8 bda_0x49[30]; |
| 1093 | u8 bda_0x84[3]; |
| 1094 | u8 dcc_index; |
| 1095 | u8 dcc_alt; |
| 1096 | u16 colors; |
| 1097 | u8 pages; |
| 1098 | u8 scan_lines; |
| 1099 | u8 primary_char; |
| 1100 | u8 secondar_char; |
| 1101 | u8 misc; |
| 1102 | u8 non_vga_mode; |
| 1103 | u8 reserved_2f[2]; |
| 1104 | u8 video_mem; |
| 1105 | u8 save_flags; |
| 1106 | u8 disp_info; |
| 1107 | u8 reserved_34[12]; |
| 1108 | }; |
| 1109 | |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1110 | static void |
| 1111 | handle_101b(struct bregs *regs) |
| 1112 | { |
Kevin O'Connor | ca66864 | 2009-05-21 23:06:08 -0400 | [diff] [blame] | 1113 | u16 seg = regs->es; |
| 1114 | struct funcInfo *info = (void*)(regs->di+0); |
| 1115 | memset_far(seg, info, 0, sizeof(*info)); |
| 1116 | // Address of static functionality table |
| 1117 | SET_FARVAR(seg, info->static_functionality_off, (u32)static_functionality); |
| 1118 | SET_FARVAR(seg, info->static_functionality_seg, get_global_seg()); |
| 1119 | |
| 1120 | // Hard coded copy from BIOS area. Should it be cleaner ? |
Kevin O'Connor | 9f98542 | 2009-09-09 11:34:39 -0400 | [diff] [blame] | 1121 | memcpy_far(seg, info->bda_0x49, SEG_BDA, (void*)0x49 |
| 1122 | , sizeof(info->bda_0x49)); |
| 1123 | memcpy_far(seg, info->bda_0x84, SEG_BDA, (void*)0x84 |
| 1124 | , sizeof(info->bda_0x84)); |
Kevin O'Connor | ca66864 | 2009-05-21 23:06:08 -0400 | [diff] [blame] | 1125 | |
| 1126 | SET_FARVAR(seg, info->dcc_index, GET_BDA(dcc_index)); |
| 1127 | SET_FARVAR(seg, info->colors, 16); |
| 1128 | SET_FARVAR(seg, info->pages, 8); |
| 1129 | SET_FARVAR(seg, info->scan_lines, 2); |
| 1130 | SET_FARVAR(seg, info->video_mem, 3); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1131 | regs->al = 0x1B; |
| 1132 | } |
| 1133 | |
| 1134 | |
| 1135 | static void |
| 1136 | handle_101c00(struct bregs *regs) |
| 1137 | { |
Kevin O'Connor | ca66864 | 2009-05-21 23:06:08 -0400 | [diff] [blame] | 1138 | u16 flags = regs->cx; |
| 1139 | u16 size = 0; |
| 1140 | if (flags & 1) |
| 1141 | size += sizeof(struct saveVideoHardware); |
| 1142 | if (flags & 2) |
| 1143 | size += sizeof(struct saveBDAstate); |
| 1144 | if (flags & 4) |
| 1145 | size += sizeof(struct saveDACcolors); |
| 1146 | regs->bx = size; |
| 1147 | regs->al = 0x1c; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1148 | } |
| 1149 | |
| 1150 | static void |
| 1151 | handle_101c01(struct bregs *regs) |
| 1152 | { |
Kevin O'Connor | ca66864 | 2009-05-21 23:06:08 -0400 | [diff] [blame] | 1153 | u16 flags = regs->cx; |
| 1154 | u16 seg = regs->es; |
| 1155 | void *data = (void*)(regs->bx+0); |
| 1156 | if (flags & 1) { |
| 1157 | vgahw_save_state(seg, data); |
| 1158 | data += sizeof(struct saveVideoHardware); |
| 1159 | } |
| 1160 | if (flags & 2) { |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 1161 | save_bda_state(seg, data); |
Kevin O'Connor | ca66864 | 2009-05-21 23:06:08 -0400 | [diff] [blame] | 1162 | data += sizeof(struct saveBDAstate); |
| 1163 | } |
| 1164 | if (flags & 4) |
| 1165 | vgahw_save_dac_state(seg, data); |
| 1166 | regs->al = 0x1c; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1167 | } |
| 1168 | |
| 1169 | static void |
| 1170 | handle_101c02(struct bregs *regs) |
| 1171 | { |
Kevin O'Connor | ca66864 | 2009-05-21 23:06:08 -0400 | [diff] [blame] | 1172 | u16 flags = regs->cx; |
| 1173 | u16 seg = regs->es; |
| 1174 | void *data = (void*)(regs->bx+0); |
| 1175 | if (flags & 1) { |
| 1176 | vgahw_restore_state(seg, data); |
| 1177 | data += sizeof(struct saveVideoHardware); |
| 1178 | } |
| 1179 | if (flags & 2) { |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 1180 | restore_bda_state(seg, data); |
Kevin O'Connor | ca66864 | 2009-05-21 23:06:08 -0400 | [diff] [blame] | 1181 | data += sizeof(struct saveBDAstate); |
| 1182 | } |
| 1183 | if (flags & 4) |
| 1184 | vgahw_restore_dac_state(seg, data); |
| 1185 | regs->al = 0x1c; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1186 | } |
| 1187 | |
| 1188 | static void |
| 1189 | handle_101cXX(struct bregs *regs) |
| 1190 | { |
| 1191 | debug_stub(regs); |
| 1192 | } |
| 1193 | |
| 1194 | static void |
| 1195 | handle_101c(struct bregs *regs) |
| 1196 | { |
| 1197 | switch (regs->al) { |
| 1198 | case 0x00: handle_101c00(regs); break; |
| 1199 | case 0x01: handle_101c01(regs); break; |
| 1200 | case 0x02: handle_101c02(regs); break; |
| 1201 | default: handle_101cXX(regs); break; |
| 1202 | } |
| 1203 | } |
| 1204 | |
| 1205 | |
| 1206 | static void |
| 1207 | handle_104f00(struct bregs *regs) |
| 1208 | { |
| 1209 | // XXX - vbe_biosfn_return_controller_information(&AX,ES,DI); |
| 1210 | // XXX - OR cirrus_vesa_00h |
| 1211 | } |
| 1212 | |
| 1213 | static void |
| 1214 | handle_104f01(struct bregs *regs) |
| 1215 | { |
| 1216 | // XXX - vbe_biosfn_return_mode_information(&AX,CX,ES,DI); |
| 1217 | // XXX - OR cirrus_vesa_01h |
| 1218 | } |
| 1219 | |
| 1220 | static void |
| 1221 | handle_104f02(struct bregs *regs) |
| 1222 | { |
| 1223 | // XXX - vbe_biosfn_set_mode(&AX,BX,ES,DI); |
| 1224 | // XXX - OR cirrus_vesa_02h |
| 1225 | } |
| 1226 | |
| 1227 | static void |
| 1228 | handle_104f03(struct bregs *regs) |
| 1229 | { |
| 1230 | // XXX - vbe_biosfn_return_current_mode |
| 1231 | // XXX - OR cirrus_vesa_03h |
| 1232 | } |
| 1233 | |
| 1234 | static void |
| 1235 | handle_104f04(struct bregs *regs) |
| 1236 | { |
| 1237 | // XXX - vbe_biosfn_save_restore_state(&AX, CX, DX, ES, &BX); |
| 1238 | } |
| 1239 | |
| 1240 | static void |
| 1241 | handle_104f05(struct bregs *regs) |
| 1242 | { |
| 1243 | // XXX - vbe_biosfn_display_window_control |
| 1244 | // XXX - OR cirrus_vesa_05h |
| 1245 | } |
| 1246 | |
| 1247 | static void |
| 1248 | handle_104f06(struct bregs *regs) |
| 1249 | { |
| 1250 | // XXX - vbe_biosfn_set_get_logical_scan_line_length |
| 1251 | // XXX - OR cirrus_vesa_06h |
| 1252 | } |
| 1253 | |
| 1254 | static void |
| 1255 | handle_104f07(struct bregs *regs) |
| 1256 | { |
| 1257 | // XXX - vbe_biosfn_set_get_display_start |
| 1258 | // XXX - OR cirrus_vesa_07h |
| 1259 | } |
| 1260 | |
| 1261 | static void |
| 1262 | handle_104f08(struct bregs *regs) |
| 1263 | { |
| 1264 | // XXX - vbe_biosfn_set_get_dac_palette_format |
| 1265 | } |
| 1266 | |
| 1267 | static void |
| 1268 | handle_104f0a(struct bregs *regs) |
| 1269 | { |
| 1270 | // XXX - vbe_biosfn_return_protected_mode_interface |
| 1271 | } |
| 1272 | |
| 1273 | static void |
| 1274 | handle_104fXX(struct bregs *regs) |
| 1275 | { |
| 1276 | debug_stub(regs); |
| 1277 | regs->ax = 0x0100; |
| 1278 | } |
| 1279 | |
| 1280 | static void |
| 1281 | handle_104f(struct bregs *regs) |
| 1282 | { |
Julian Pidancet | 677631f | 2011-12-19 05:07:53 +0000 | [diff] [blame] | 1283 | if (! CONFIG_VGA_BOCHS || !bochs_has_vbe_display()) { |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1284 | handle_104fXX(regs); |
| 1285 | return; |
| 1286 | } |
| 1287 | |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1288 | switch (regs->al) { |
| 1289 | case 0x00: handle_104f00(regs); break; |
| 1290 | case 0x01: handle_104f01(regs); break; |
| 1291 | case 0x02: handle_104f02(regs); break; |
| 1292 | case 0x03: handle_104f03(regs); break; |
| 1293 | case 0x04: handle_104f04(regs); break; |
| 1294 | case 0x05: handle_104f05(regs); break; |
| 1295 | case 0x06: handle_104f06(regs); break; |
| 1296 | case 0x07: handle_104f07(regs); break; |
| 1297 | case 0x08: handle_104f08(regs); break; |
| 1298 | case 0x0a: handle_104f0a(regs); break; |
| 1299 | default: handle_104fXX(regs); break; |
| 1300 | } |
| 1301 | } |
| 1302 | |
| 1303 | |
| 1304 | static void |
| 1305 | handle_10XX(struct bregs *regs) |
| 1306 | { |
| 1307 | debug_stub(regs); |
| 1308 | } |
| 1309 | |
| 1310 | // INT 10h Video Support Service Entry Point |
| 1311 | void VISIBLE16 |
| 1312 | handle_10(struct bregs *regs) |
| 1313 | { |
| 1314 | debug_enter(regs, DEBUG_VGA_10); |
| 1315 | switch (regs->ah) { |
| 1316 | case 0x00: handle_1000(regs); break; |
| 1317 | case 0x01: handle_1001(regs); break; |
| 1318 | case 0x02: handle_1002(regs); break; |
| 1319 | case 0x03: handle_1003(regs); break; |
| 1320 | case 0x04: handle_1004(regs); break; |
| 1321 | case 0x05: handle_1005(regs); break; |
| 1322 | case 0x06: handle_1006(regs); break; |
| 1323 | case 0x07: handle_1007(regs); break; |
| 1324 | case 0x08: handle_1008(regs); break; |
| 1325 | case 0x09: handle_1009(regs); break; |
| 1326 | case 0x0a: handle_100a(regs); break; |
| 1327 | case 0x0b: handle_100b(regs); break; |
| 1328 | case 0x0c: handle_100c(regs); break; |
| 1329 | case 0x0d: handle_100d(regs); break; |
| 1330 | case 0x0e: handle_100e(regs); break; |
| 1331 | case 0x0f: handle_100f(regs); break; |
| 1332 | case 0x10: handle_1010(regs); break; |
| 1333 | case 0x11: handle_1011(regs); break; |
| 1334 | case 0x12: handle_1012(regs); break; |
| 1335 | case 0x13: handle_1013(regs); break; |
| 1336 | case 0x1a: handle_101a(regs); break; |
| 1337 | case 0x1b: handle_101b(regs); break; |
| 1338 | case 0x1c: handle_101c(regs); break; |
| 1339 | case 0x4f: handle_104f(regs); break; |
| 1340 | default: handle_10XX(regs); break; |
| 1341 | } |
| 1342 | } |
| 1343 | |
| 1344 | |
| 1345 | /**************************************************************** |
| 1346 | * VGA post |
| 1347 | ****************************************************************/ |
| 1348 | |
| 1349 | static void |
Kevin O'Connor | 1ca05b0 | 2010-01-03 17:43:37 -0500 | [diff] [blame] | 1350 | init_bios_area(void) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1351 | { |
| 1352 | // init detected hardware BIOS Area |
| 1353 | // set 80x25 color (not clear from RBIL but usual) |
| 1354 | u16 eqf = GET_BDA(equipment_list_flags); |
| 1355 | SET_BDA(equipment_list_flags, (eqf & 0xffcf) | 0x20); |
| 1356 | |
| 1357 | // Just for the first int10 find its children |
| 1358 | |
| 1359 | // the default char height |
| 1360 | SET_BDA(char_height, 0x10); |
| 1361 | |
| 1362 | // Clear the screen |
| 1363 | SET_BDA(video_ctl, 0x60); |
| 1364 | |
| 1365 | // Set the basic screen we have |
| 1366 | SET_BDA(video_switches, 0xf9); |
| 1367 | |
| 1368 | // Set the basic modeset options |
| 1369 | SET_BDA(modeset_ctl, 0x51); |
| 1370 | |
| 1371 | // Set the default MSR |
| 1372 | SET_BDA(video_msr, 0x09); |
| 1373 | } |
| 1374 | |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1375 | void VISIBLE16 |
| 1376 | vga_post(struct bregs *regs) |
| 1377 | { |
| 1378 | debug_enter(regs, DEBUG_VGA_POST); |
| 1379 | |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 1380 | vgahw_init(); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1381 | |
| 1382 | init_bios_area(); |
| 1383 | |
Julian Pidancet | 677631f | 2011-12-19 05:07:53 +0000 | [diff] [blame] | 1384 | if (CONFIG_VGA_BOCHS) |
| 1385 | bochs_init(); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1386 | |
| 1387 | extern void entry_10(void); |
Kevin O'Connor | 9f98542 | 2009-09-09 11:34:39 -0400 | [diff] [blame] | 1388 | SET_IVT(0x10, SEGOFF(get_global_seg(), (u32)entry_10)); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1389 | |
Julian Pidancet | 677631f | 2011-12-19 05:07:53 +0000 | [diff] [blame] | 1390 | if (CONFIG_VGA_CIRRUS) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1391 | cirrus_init(); |
| 1392 | |
| 1393 | // XXX - clear screen and display info |
| 1394 | |
| 1395 | // XXX: fill it |
| 1396 | SET_VGA(video_save_pointer_table[0], (u32)video_param_table); |
Kevin O'Connor | d113a99 | 2009-05-16 21:05:02 -0400 | [diff] [blame] | 1397 | SET_VGA(video_save_pointer_table[1], get_global_seg()); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1398 | |
| 1399 | // Fixup checksum |
| 1400 | extern u8 _rom_header_size, _rom_header_checksum; |
| 1401 | SET_VGA(_rom_header_checksum, 0); |
Kevin O'Connor | d113a99 | 2009-05-16 21:05:02 -0400 | [diff] [blame] | 1402 | u8 sum = -checksum_far(get_global_seg(), 0, _rom_header_size * 512); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1403 | SET_VGA(_rom_header_checksum, sum); |
| 1404 | } |