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