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_* |
Julian Pidancet | 87879e2 | 2011-12-19 05:08:00 +0000 | [diff] [blame] | 20 | #include "vbe.h" // vbe_* |
Kevin O'Connor | 4c52fb4 | 2011-12-24 00:44:07 -0500 | [diff] [blame] | 21 | #include "geodelx.h" // geodelx_init |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 22 | |
| 23 | // XXX |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 24 | #define DEBUG_VGA_POST 1 |
| 25 | #define DEBUG_VGA_10 3 |
| 26 | |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 27 | |
Julian Pidancet | 7c6509c | 2011-12-19 05:07:55 +0000 | [diff] [blame] | 28 | /**************************************************************** |
| 29 | * PCI Data |
| 30 | ****************************************************************/ |
| 31 | #if CONFIG_VGA_PCI == 1 |
| 32 | struct pci_data rom_pci_data VAR16VISIBLE = { |
| 33 | .signature = PCI_ROM_SIGNATURE, |
| 34 | .vendor = CONFIG_VGA_VID, |
| 35 | .device = CONFIG_VGA_DID, |
| 36 | .dlen = 0x18, |
| 37 | .class_hi = 0x300, |
| 38 | .irevision = 1, |
| 39 | .type = PCIROM_CODETYPE_X86, |
| 40 | .indicator = 0x80, |
| 41 | }; |
| 42 | #endif |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 43 | |
| 44 | /**************************************************************** |
| 45 | * Helper functions |
| 46 | ****************************************************************/ |
| 47 | |
Kevin O'Connor | 217f2bc | 2009-05-31 00:46:47 -0400 | [diff] [blame] | 48 | static inline void |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 49 | call16_vgaint(u32 eax, u32 ebx) |
| 50 | { |
| 51 | asm volatile( |
| 52 | "int $0x10\n" |
| 53 | "cli\n" |
| 54 | "cld" |
| 55 | : |
| 56 | : "a"(eax), "b"(ebx) |
| 57 | : "cc", "memory"); |
| 58 | } |
| 59 | |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 60 | static void |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 61 | perform_gray_scale_summing(u16 start, u16 count) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 62 | { |
Kevin O'Connor | a0ecb05 | 2009-05-18 23:34:00 -0400 | [diff] [blame] | 63 | vgahw_screen_disable(); |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 64 | int i; |
| 65 | for (i = start; i < start+count; i++) { |
Kevin O'Connor | a0ecb05 | 2009-05-18 23:34:00 -0400 | [diff] [blame] | 66 | u8 rgb[3]; |
| 67 | vgahw_get_dac_regs(GET_SEG(SS), rgb, i, 1); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 68 | |
| 69 | // intensity = ( 0.3 * Red ) + ( 0.59 * Green ) + ( 0.11 * Blue ) |
Kevin O'Connor | a0ecb05 | 2009-05-18 23:34:00 -0400 | [diff] [blame] | 70 | 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] | 71 | if (intensity > 0x3f) |
| 72 | intensity = 0x3f; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 73 | |
Kevin O'Connor | a0ecb05 | 2009-05-18 23:34:00 -0400 | [diff] [blame] | 74 | vgahw_set_dac_regs(GET_SEG(SS), rgb, i, 1); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 75 | } |
Kevin O'Connor | a0ecb05 | 2009-05-18 23:34:00 -0400 | [diff] [blame] | 76 | vgahw_screen_enable(); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 77 | } |
| 78 | |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 79 | static void |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 80 | set_cursor_shape(u8 start, u8 end) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 81 | { |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 82 | start &= 0x3f; |
| 83 | end &= 0x1f; |
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 | u16 curs = (start << 8) + end; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 86 | SET_BDA(cursor_type, curs); |
| 87 | |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 88 | u8 modeset_ctl = GET_BDA(modeset_ctl); |
| 89 | u16 cheight = GET_BDA(char_height); |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 90 | if ((modeset_ctl & 0x01) && (cheight > 8) && (end < 8) && (start < 0x20)) { |
| 91 | if (end != (start + 1)) |
| 92 | start = ((start + 1) * cheight / 8) - 1; |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 93 | else |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 94 | start = ((end + 1) * cheight / 8) - 2; |
| 95 | end = ((end + 1) * cheight / 8) - 1; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 96 | } |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 97 | vgahw_set_cursor_shape(start, end); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 98 | } |
| 99 | |
Kevin O'Connor | 0818e1a | 2009-05-16 18:00:19 -0400 | [diff] [blame] | 100 | static u16 |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 101 | get_cursor_shape(u8 page) |
Kevin O'Connor | 0818e1a | 2009-05-16 18:00:19 -0400 | [diff] [blame] | 102 | { |
| 103 | if (page > 7) |
| 104 | return 0; |
| 105 | // FIXME should handle VGA 14/16 lines |
| 106 | return GET_BDA(cursor_type); |
| 107 | } |
| 108 | |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 109 | static void |
Kevin O'Connor | 918b156 | 2009-05-25 11:05:18 -0400 | [diff] [blame] | 110 | set_cursor_pos(struct cursorpos cp) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 111 | { |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 112 | // Should not happen... |
Kevin O'Connor | 918b156 | 2009-05-25 11:05:18 -0400 | [diff] [blame] | 113 | if (cp.page > 7) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 114 | return; |
| 115 | |
| 116 | // Bios cursor pos |
Kevin O'Connor | 918b156 | 2009-05-25 11:05:18 -0400 | [diff] [blame] | 117 | SET_BDA(cursor_pos[cp.page], (cp.y << 8) | cp.x); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 118 | |
| 119 | // Set the hardware cursor |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 120 | u8 current = GET_BDA(video_page); |
Kevin O'Connor | 918b156 | 2009-05-25 11:05:18 -0400 | [diff] [blame] | 121 | if (cp.page != current) |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 122 | return; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 123 | |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 124 | // Get the dimensions |
| 125 | u16 nbcols = GET_BDA(video_cols); |
| 126 | u16 nbrows = GET_BDA(video_rows) + 1; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 127 | |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 128 | // Calculate the address knowing nbcols nbrows and page num |
Kevin O'Connor | 918b156 | 2009-05-25 11:05:18 -0400 | [diff] [blame] | 129 | u16 address = (SCREEN_IO_START(nbcols, nbrows, cp.page) |
| 130 | + cp.x + cp.y * nbcols); |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 131 | |
Kevin O'Connor | a0ecb05 | 2009-05-18 23:34:00 -0400 | [diff] [blame] | 132 | vgahw_set_cursor_pos(address); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 133 | } |
| 134 | |
Kevin O'Connor | 217f2bc | 2009-05-31 00:46:47 -0400 | [diff] [blame] | 135 | static struct cursorpos |
Kevin O'Connor | 918b156 | 2009-05-25 11:05:18 -0400 | [diff] [blame] | 136 | get_cursor_pos(u8 page) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 137 | { |
Kevin O'Connor | 918b156 | 2009-05-25 11:05:18 -0400 | [diff] [blame] | 138 | if (page == 0xff) |
| 139 | // special case - use current page |
| 140 | page = GET_BDA(video_page); |
| 141 | if (page > 7) { |
| 142 | struct cursorpos cp = { 0, 0, 0xfe }; |
| 143 | return cp; |
| 144 | } |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 145 | // FIXME should handle VGA 14/16 lines |
Kevin O'Connor | 918b156 | 2009-05-25 11:05:18 -0400 | [diff] [blame] | 146 | u16 xy = GET_BDA(cursor_pos[page]); |
| 147 | struct cursorpos cp = {xy, xy>>8, page}; |
| 148 | return cp; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 149 | } |
| 150 | |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 151 | static void |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 152 | set_active_page(u8 page) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 153 | { |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 154 | if (page > 7) |
| 155 | return; |
| 156 | |
| 157 | // Get the mode |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 158 | struct vgamode_s *vmode_g = find_vga_entry(GET_BDA(video_mode)); |
| 159 | if (!vmode_g) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 160 | return; |
| 161 | |
| 162 | // Get pos curs pos for the right page |
Kevin O'Connor | 918b156 | 2009-05-25 11:05:18 -0400 | [diff] [blame] | 163 | struct cursorpos cp = get_cursor_pos(page); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 164 | |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 165 | u16 address; |
Kevin O'Connor | e4f220f | 2009-05-25 23:37:13 -0400 | [diff] [blame] | 166 | if (GET_GLOBAL(vmode_g->memmodel) & TEXT) { |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 167 | // Get the dimensions |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 168 | u16 nbcols = GET_BDA(video_cols); |
| 169 | u16 nbrows = GET_BDA(video_rows) + 1; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 170 | |
| 171 | // Calculate the address knowing nbcols nbrows and page num |
| 172 | address = SCREEN_MEM_START(nbcols, nbrows, page); |
| 173 | SET_BDA(video_pagestart, address); |
| 174 | |
| 175 | // Start address |
| 176 | address = SCREEN_IO_START(nbcols, nbrows, page); |
| 177 | } else { |
Kevin O'Connor | 87233e9 | 2011-12-23 21:40:34 -0500 | [diff] [blame] | 178 | address = page * GET_GLOBAL(vmode_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 |
Julian Pidancet | 87879e2 | 2011-12-19 05:08:00 +0000 | [diff] [blame] | 361 | void |
| 362 | vga_set_mode(u8 mode, u8 noclearmem) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 363 | { |
Kevin O'Connor | 85ea07e | 2009-05-25 09:41:07 -0400 | [diff] [blame] | 364 | // find the entry in the video modes |
| 365 | struct vgamode_s *vmode_g = find_vga_entry(mode); |
| 366 | dprintf(1, "mode search %02x found %p\n", mode, vmode_g); |
| 367 | if (!vmode_g) |
| 368 | return; |
| 369 | |
| 370 | // Read the bios mode set control |
| 371 | u8 modeset_ctl = GET_BDA(modeset_ctl); |
| 372 | |
| 373 | // Then we know the number of lines |
| 374 | // FIXME |
| 375 | |
| 376 | // if palette loading (bit 3 of modeset ctl = 0) |
| 377 | if ((modeset_ctl & 0x08) == 0) { // Set the PEL mask |
| 378 | vgahw_set_pel_mask(GET_GLOBAL(vmode_g->pelmask)); |
| 379 | |
| 380 | // From which palette |
| 381 | u8 *palette_g = GET_GLOBAL(vmode_g->dac); |
| 382 | u16 palsize = GET_GLOBAL(vmode_g->dacsize) / 3; |
| 383 | |
| 384 | // Always 256*3 values |
| 385 | vgahw_set_dac_regs(get_global_seg(), palette_g, 0, palsize); |
| 386 | u16 i; |
| 387 | for (i = palsize; i < 0x0100; i++) { |
| 388 | static u8 rgb[3] VAR16; |
| 389 | vgahw_set_dac_regs(get_global_seg(), rgb, i, 1); |
| 390 | } |
| 391 | |
| 392 | if ((modeset_ctl & 0x02) == 0x02) |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 393 | perform_gray_scale_summing(0x00, 0x100); |
Kevin O'Connor | 85ea07e | 2009-05-25 09:41:07 -0400 | [diff] [blame] | 394 | } |
| 395 | |
Kevin O'Connor | 87233e9 | 2011-12-23 21:40:34 -0500 | [diff] [blame] | 396 | vgahw_set_mode(vmode_g); |
Kevin O'Connor | 85ea07e | 2009-05-25 09:41:07 -0400 | [diff] [blame] | 397 | |
| 398 | if (noclearmem == 0x00) |
| 399 | clear_screen(vmode_g); |
| 400 | |
| 401 | // Set CRTC address VGA or MDA |
| 402 | u16 crtc_addr = VGAREG_VGA_CRTC_ADDRESS; |
| 403 | if (GET_GLOBAL(vmode_g->memmodel) == MTEXT) |
| 404 | crtc_addr = VGAREG_MDA_CRTC_ADDRESS; |
| 405 | |
| 406 | // Set the BIOS mem |
Kevin O'Connor | 87233e9 | 2011-12-23 21:40:34 -0500 | [diff] [blame] | 407 | u16 cheight = GET_GLOBAL(vmode_g->cheight); |
Kevin O'Connor | 85ea07e | 2009-05-25 09:41:07 -0400 | [diff] [blame] | 408 | SET_BDA(video_mode, mode); |
Kevin O'Connor | 87233e9 | 2011-12-23 21:40:34 -0500 | [diff] [blame] | 409 | SET_BDA(video_cols, GET_GLOBAL(vmode_g->twidth)); |
| 410 | SET_BDA(video_pagesize, GET_GLOBAL(vmode_g->slength)); |
Kevin O'Connor | 85ea07e | 2009-05-25 09:41:07 -0400 | [diff] [blame] | 411 | SET_BDA(crtc_address, crtc_addr); |
Kevin O'Connor | 87233e9 | 2011-12-23 21:40:34 -0500 | [diff] [blame] | 412 | SET_BDA(video_rows, GET_GLOBAL(vmode_g->theight)-1); |
Kevin O'Connor | 85ea07e | 2009-05-25 09:41:07 -0400 | [diff] [blame] | 413 | SET_BDA(char_height, cheight); |
| 414 | SET_BDA(video_ctl, (0x60 | noclearmem)); |
| 415 | SET_BDA(video_switches, 0xF9); |
| 416 | SET_BDA(modeset_ctl, GET_BDA(modeset_ctl) & 0x7f); |
| 417 | |
| 418 | // FIXME We nearly have the good tables. to be reworked |
| 419 | 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] | 420 | SET_BDA(video_savetable |
Kevin O'Connor | 815e447 | 2011-12-21 09:05:32 -0500 | [diff] [blame] | 421 | , SEGOFF(get_global_seg(), (u32)&video_save_pointer_table)); |
Kevin O'Connor | 85ea07e | 2009-05-25 09:41:07 -0400 | [diff] [blame] | 422 | |
| 423 | // FIXME |
| 424 | SET_BDA(video_msr, 0x00); // Unavailable on vanilla vga, but... |
| 425 | SET_BDA(video_pal, 0x00); // Unavailable on vanilla vga, but... |
| 426 | |
| 427 | // Set cursor shape |
Kevin O'Connor | e4f220f | 2009-05-25 23:37:13 -0400 | [diff] [blame] | 428 | if (GET_GLOBAL(vmode_g->memmodel) & TEXT) |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 429 | set_cursor_shape(0x06, 0x07); |
Kevin O'Connor | 85ea07e | 2009-05-25 09:41:07 -0400 | [diff] [blame] | 430 | // Set cursor pos for page 0..7 |
| 431 | int i; |
Kevin O'Connor | 918b156 | 2009-05-25 11:05:18 -0400 | [diff] [blame] | 432 | for (i = 0; i < 8; i++) { |
| 433 | struct cursorpos cp = {0, 0, i}; |
| 434 | set_cursor_pos(cp); |
| 435 | } |
Kevin O'Connor | 85ea07e | 2009-05-25 09:41:07 -0400 | [diff] [blame] | 436 | |
| 437 | // Set active page 0 |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 438 | set_active_page(0x00); |
Kevin O'Connor | 85ea07e | 2009-05-25 09:41:07 -0400 | [diff] [blame] | 439 | |
| 440 | // Write the fonts in memory |
Kevin O'Connor | e4f220f | 2009-05-25 23:37:13 -0400 | [diff] [blame] | 441 | if (GET_GLOBAL(vmode_g->memmodel) & TEXT) { |
Kevin O'Connor | 85ea07e | 2009-05-25 09:41:07 -0400 | [diff] [blame] | 442 | call16_vgaint(0x1104, 0); |
| 443 | call16_vgaint(0x1103, 0); |
| 444 | } |
| 445 | // Set the ints 0x1F and 0x43 |
Kevin O'Connor | 9f98542 | 2009-09-09 11:34:39 -0400 | [diff] [blame] | 446 | SET_IVT(0x1f, SEGOFF(get_global_seg(), (u32)&vgafont8[128 * 8])); |
Kevin O'Connor | 85ea07e | 2009-05-25 09:41:07 -0400 | [diff] [blame] | 447 | |
| 448 | switch (cheight) { |
| 449 | case 8: |
Kevin O'Connor | 9f98542 | 2009-09-09 11:34:39 -0400 | [diff] [blame] | 450 | SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont8)); |
Kevin O'Connor | 85ea07e | 2009-05-25 09:41:07 -0400 | [diff] [blame] | 451 | break; |
| 452 | case 14: |
Kevin O'Connor | 9f98542 | 2009-09-09 11:34:39 -0400 | [diff] [blame] | 453 | SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont14)); |
Kevin O'Connor | 85ea07e | 2009-05-25 09:41:07 -0400 | [diff] [blame] | 454 | break; |
| 455 | case 16: |
Kevin O'Connor | 9f98542 | 2009-09-09 11:34:39 -0400 | [diff] [blame] | 456 | SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont16)); |
Kevin O'Connor | 85ea07e | 2009-05-25 09:41:07 -0400 | [diff] [blame] | 457 | break; |
| 458 | } |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | static void |
Julian Pidancet | 87879e2 | 2011-12-19 05:08:00 +0000 | [diff] [blame] | 462 | handle_1000(struct bregs *regs) |
| 463 | { |
| 464 | u8 noclearmem = regs->al & 0x80; |
| 465 | u8 mode = regs->al & 0x7f; |
| 466 | |
| 467 | // Set regs->al |
| 468 | if (mode > 7) |
| 469 | regs->al = 0x20; |
| 470 | else if (mode == 6) |
| 471 | regs->al = 0x3f; |
| 472 | else |
| 473 | regs->al = 0x30; |
| 474 | |
Kevin O'Connor | e48a537 | 2011-12-20 23:56:14 -0500 | [diff] [blame] | 475 | if (CONFIG_VGA_CIRRUS) { |
| 476 | int ret = cirrus_set_video_mode(mode, noclearmem); |
| 477 | if (ret) |
| 478 | return; |
| 479 | } |
Julian Pidancet | 87879e2 | 2011-12-19 05:08:00 +0000 | [diff] [blame] | 480 | |
| 481 | if (vbe_enabled()) |
| 482 | vbe_hires_enable(0); |
| 483 | |
| 484 | vga_set_mode(mode, noclearmem); |
| 485 | } |
| 486 | |
| 487 | static void |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 488 | handle_1001(struct bregs *regs) |
| 489 | { |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 490 | set_cursor_shape(regs->ch, regs->cl); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | static void |
| 494 | handle_1002(struct bregs *regs) |
| 495 | { |
Kevin O'Connor | 918b156 | 2009-05-25 11:05:18 -0400 | [diff] [blame] | 496 | struct cursorpos cp = {regs->dl, regs->dh, regs->bh}; |
| 497 | set_cursor_pos(cp); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | static void |
| 501 | handle_1003(struct bregs *regs) |
| 502 | { |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 503 | regs->cx = get_cursor_shape(regs->bh); |
Kevin O'Connor | 918b156 | 2009-05-25 11:05:18 -0400 | [diff] [blame] | 504 | struct cursorpos cp = get_cursor_pos(regs->bh); |
| 505 | regs->dl = cp.x; |
| 506 | regs->dh = cp.y; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | // Read light pen pos (unimplemented) |
| 510 | static void |
| 511 | handle_1004(struct bregs *regs) |
| 512 | { |
| 513 | debug_stub(regs); |
| 514 | regs->ax = regs->bx = regs->cx = regs->dx = 0; |
| 515 | } |
| 516 | |
| 517 | static void |
| 518 | handle_1005(struct bregs *regs) |
| 519 | { |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 520 | set_active_page(regs->al); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | static void |
Kevin O'Connor | 217f2bc | 2009-05-31 00:46:47 -0400 | [diff] [blame] | 524 | verify_scroll(struct bregs *regs, int dir) |
| 525 | { |
| 526 | u8 page = GET_BDA(video_page); |
| 527 | struct cursorpos ul = {regs->cl, regs->ch, page}; |
| 528 | struct cursorpos lr = {regs->dl, regs->dh, page}; |
| 529 | |
Kevin O'Connor | 217f2bc | 2009-05-31 00:46:47 -0400 | [diff] [blame] | 530 | u16 nbrows = GET_BDA(video_rows) + 1; |
Kevin O'Connor | 217f2bc | 2009-05-31 00:46:47 -0400 | [diff] [blame] | 531 | if (lr.y >= nbrows) |
| 532 | lr.y = nbrows - 1; |
Kevin O'Connor | c3e1587 | 2009-05-31 01:37:54 -0400 | [diff] [blame] | 533 | u16 nbcols = GET_BDA(video_cols); |
Kevin O'Connor | 217f2bc | 2009-05-31 00:46:47 -0400 | [diff] [blame] | 534 | if (lr.x >= nbcols) |
| 535 | lr.x = nbcols - 1; |
| 536 | |
Kevin O'Connor | c3e1587 | 2009-05-31 01:37:54 -0400 | [diff] [blame] | 537 | if (ul.x > lr.x || ul.y > lr.y) |
| 538 | return; |
| 539 | |
| 540 | u16 nblines = regs->al; |
| 541 | if (!nblines || nblines > lr.y - ul.y + 1) |
| 542 | nblines = lr.y - ul.y + 1; |
| 543 | |
| 544 | vgafb_scroll(dir * nblines, regs->bh, ul, lr); |
Kevin O'Connor | 217f2bc | 2009-05-31 00:46:47 -0400 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | static void |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 548 | handle_1006(struct bregs *regs) |
| 549 | { |
Kevin O'Connor | 217f2bc | 2009-05-31 00:46:47 -0400 | [diff] [blame] | 550 | verify_scroll(regs, 1); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | static void |
| 554 | handle_1007(struct bregs *regs) |
| 555 | { |
Kevin O'Connor | 217f2bc | 2009-05-31 00:46:47 -0400 | [diff] [blame] | 556 | verify_scroll(regs, -1); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | static void |
| 560 | handle_1008(struct bregs *regs) |
| 561 | { |
Kevin O'Connor | d3b3815 | 2009-05-26 00:05:37 -0400 | [diff] [blame] | 562 | struct carattr ca = vgafb_read_char(get_cursor_pos(regs->bh)); |
Kevin O'Connor | 0926241 | 2009-05-25 11:44:11 -0400 | [diff] [blame] | 563 | regs->al = ca.car; |
| 564 | regs->ah = ca.attr; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 565 | } |
| 566 | |
Kevin O'Connor | 0ad77f0 | 2009-05-31 20:46:43 -0400 | [diff] [blame] | 567 | static void noinline |
Kevin O'Connor | d3b3815 | 2009-05-26 00:05:37 -0400 | [diff] [blame] | 568 | write_chars(u8 page, struct carattr ca, u16 count) |
| 569 | { |
| 570 | struct cursorpos cp = get_cursor_pos(page); |
| 571 | while (count--) { |
| 572 | vgafb_write_char(cp, ca); |
| 573 | cp.x++; |
| 574 | } |
| 575 | } |
| 576 | |
| 577 | static void |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 578 | handle_1009(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, 1}; |
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 | static void |
| 585 | handle_100a(struct bregs *regs) |
| 586 | { |
Kevin O'Connor | 0926241 | 2009-05-25 11:44:11 -0400 | [diff] [blame] | 587 | struct carattr ca = {regs->al, regs->bl, 0}; |
Kevin O'Connor | d3b3815 | 2009-05-26 00:05:37 -0400 | [diff] [blame] | 588 | write_chars(regs->bh, ca, regs->cx); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 589 | } |
| 590 | |
| 591 | |
| 592 | static void |
| 593 | handle_100b00(struct bregs *regs) |
| 594 | { |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 595 | vgahw_set_border_color(regs->bl); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | static void |
| 599 | handle_100b01(struct bregs *regs) |
| 600 | { |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 601 | vgahw_set_palette(regs->bl); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | static void |
| 605 | handle_100bXX(struct bregs *regs) |
| 606 | { |
| 607 | debug_stub(regs); |
| 608 | } |
| 609 | |
| 610 | static void |
| 611 | handle_100b(struct bregs *regs) |
| 612 | { |
| 613 | switch (regs->bh) { |
| 614 | case 0x00: handle_100b00(regs); break; |
| 615 | case 0x01: handle_100b01(regs); break; |
| 616 | default: handle_100bXX(regs); break; |
| 617 | } |
| 618 | } |
| 619 | |
| 620 | |
| 621 | static void |
| 622 | handle_100c(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 | vgafb_write_pixel(regs->al, regs->cx, regs->dx); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | static void |
| 629 | handle_100d(struct bregs *regs) |
| 630 | { |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 631 | // XXX - page (regs->bh) is unused |
| 632 | regs->al = vgafb_read_pixel(regs->cx, regs->dx); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 633 | } |
| 634 | |
Kevin O'Connor | 0ad77f0 | 2009-05-31 20:46:43 -0400 | [diff] [blame] | 635 | static void noinline |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 636 | handle_100e(struct bregs *regs) |
| 637 | { |
| 638 | // Ralf Brown Interrupt list is WRONG on bh(page) |
| 639 | // We do output only on the current page ! |
Kevin O'Connor | 0926241 | 2009-05-25 11:44:11 -0400 | [diff] [blame] | 640 | struct carattr ca = {regs->al, regs->bl, 0}; |
Kevin O'Connor | 116a044 | 2009-05-26 00:47:32 -0400 | [diff] [blame] | 641 | struct cursorpos cp = get_cursor_pos(0xff); |
Kevin O'Connor | afb287d | 2009-05-31 21:15:33 -0400 | [diff] [blame] | 642 | write_teletype(&cp, ca); |
Kevin O'Connor | 116a044 | 2009-05-26 00:47:32 -0400 | [diff] [blame] | 643 | set_cursor_pos(cp); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 644 | } |
| 645 | |
| 646 | static void |
| 647 | handle_100f(struct bregs *regs) |
| 648 | { |
Kevin O'Connor | e713204 | 2009-05-25 00:10:35 -0400 | [diff] [blame] | 649 | regs->bh = GET_BDA(video_page); |
| 650 | regs->al = GET_BDA(video_mode) | (GET_BDA(video_ctl) & 0x80); |
| 651 | regs->ah = GET_BDA(video_cols); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | |
| 655 | static void |
| 656 | handle_101000(struct bregs *regs) |
| 657 | { |
| 658 | if (regs->bl > 0x14) |
| 659 | return; |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 660 | vgahw_set_single_palette_reg(regs->bl, regs->bh); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | static void |
| 664 | handle_101001(struct bregs *regs) |
| 665 | { |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 666 | vgahw_set_overscan_border_color(regs->bh); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | static void |
| 670 | handle_101002(struct bregs *regs) |
| 671 | { |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 672 | vgahw_set_all_palette_reg(regs->es, (u8*)(regs->dx + 0)); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | static void |
| 676 | handle_101003(struct bregs *regs) |
| 677 | { |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 678 | vgahw_toggle_intensity(regs->bl); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 679 | } |
| 680 | |
| 681 | static void |
| 682 | handle_101007(struct bregs *regs) |
| 683 | { |
| 684 | if (regs->bl > 0x14) |
| 685 | return; |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 686 | regs->bh = vgahw_get_single_palette_reg(regs->bl); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | static void |
| 690 | handle_101008(struct bregs *regs) |
| 691 | { |
Kevin O'Connor | 3862b2d | 2010-01-03 17:53:58 -0500 | [diff] [blame] | 692 | regs->bh = vgahw_get_overscan_border_color(); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | static void |
| 696 | handle_101009(struct bregs *regs) |
| 697 | { |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 698 | vgahw_get_all_palette_reg(regs->es, (u8*)(regs->dx + 0)); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 699 | } |
| 700 | |
Kevin O'Connor | 0ad77f0 | 2009-05-31 20:46:43 -0400 | [diff] [blame] | 701 | static void noinline |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 702 | handle_101010(struct bregs *regs) |
| 703 | { |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 704 | u8 rgb[3] = {regs->dh, regs->ch, regs->cl}; |
| 705 | vgahw_set_dac_regs(GET_SEG(SS), rgb, regs->bx, 1); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 706 | } |
| 707 | |
| 708 | static void |
| 709 | handle_101012(struct bregs *regs) |
| 710 | { |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 711 | 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] | 712 | } |
| 713 | |
| 714 | static void |
| 715 | handle_101013(struct bregs *regs) |
| 716 | { |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 717 | vgahw_select_video_dac_color_page(regs->bl, regs->bh); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 718 | } |
| 719 | |
Kevin O'Connor | 0ad77f0 | 2009-05-31 20:46:43 -0400 | [diff] [blame] | 720 | static void noinline |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 721 | handle_101015(struct bregs *regs) |
| 722 | { |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 723 | u8 rgb[3]; |
| 724 | vgahw_get_dac_regs(GET_SEG(SS), rgb, regs->bx, 1); |
| 725 | regs->dh = rgb[0]; |
| 726 | regs->ch = rgb[1]; |
| 727 | regs->cl = rgb[2]; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 728 | } |
| 729 | |
| 730 | static void |
| 731 | handle_101017(struct bregs *regs) |
| 732 | { |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 733 | 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] | 734 | } |
| 735 | |
| 736 | static void |
| 737 | handle_101018(struct bregs *regs) |
| 738 | { |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 739 | vgahw_set_pel_mask(regs->bl); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | static void |
| 743 | handle_101019(struct bregs *regs) |
| 744 | { |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 745 | regs->bl = vgahw_get_pel_mask(); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 746 | } |
| 747 | |
| 748 | static void |
| 749 | handle_10101a(struct bregs *regs) |
| 750 | { |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 751 | vgahw_read_video_dac_state(®s->bl, ®s->bh); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 752 | } |
| 753 | |
| 754 | static void |
| 755 | handle_10101b(struct bregs *regs) |
| 756 | { |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 757 | perform_gray_scale_summing(regs->bx, regs->cx); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 758 | } |
| 759 | |
| 760 | static void |
| 761 | handle_1010XX(struct bregs *regs) |
| 762 | { |
| 763 | debug_stub(regs); |
| 764 | } |
| 765 | |
| 766 | static void |
| 767 | handle_1010(struct bregs *regs) |
| 768 | { |
| 769 | switch (regs->al) { |
| 770 | case 0x00: handle_101000(regs); break; |
| 771 | case 0x01: handle_101001(regs); break; |
| 772 | case 0x02: handle_101002(regs); break; |
| 773 | case 0x03: handle_101003(regs); break; |
| 774 | case 0x07: handle_101007(regs); break; |
| 775 | case 0x08: handle_101008(regs); break; |
| 776 | case 0x09: handle_101009(regs); break; |
| 777 | case 0x10: handle_101010(regs); break; |
| 778 | case 0x12: handle_101012(regs); break; |
| 779 | case 0x13: handle_101013(regs); break; |
| 780 | case 0x15: handle_101015(regs); break; |
| 781 | case 0x17: handle_101017(regs); break; |
| 782 | case 0x18: handle_101018(regs); break; |
| 783 | case 0x19: handle_101019(regs); break; |
| 784 | case 0x1a: handle_10101a(regs); break; |
| 785 | case 0x1b: handle_10101b(regs); break; |
| 786 | default: handle_1010XX(regs); break; |
| 787 | } |
| 788 | } |
| 789 | |
| 790 | |
| 791 | static void |
| 792 | handle_101100(struct bregs *regs) |
| 793 | { |
Kevin O'Connor | deb9cb9 | 2009-05-25 09:06:50 -0400 | [diff] [blame] | 794 | vgafb_load_font(regs->es, (void*)(regs->bp+0), regs->cx |
| 795 | , regs->dx, regs->bl, regs->bh); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | static void |
| 799 | handle_101101(struct bregs *regs) |
| 800 | { |
Kevin O'Connor | deb9cb9 | 2009-05-25 09:06:50 -0400 | [diff] [blame] | 801 | 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] | 802 | } |
| 803 | |
| 804 | static void |
| 805 | handle_101102(struct bregs *regs) |
| 806 | { |
Kevin O'Connor | deb9cb9 | 2009-05-25 09:06:50 -0400 | [diff] [blame] | 807 | 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] | 808 | } |
| 809 | |
| 810 | static void |
| 811 | handle_101103(struct bregs *regs) |
| 812 | { |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 813 | vgahw_set_text_block_specifier(regs->bl); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 814 | } |
| 815 | |
| 816 | static void |
| 817 | handle_101104(struct bregs *regs) |
| 818 | { |
Kevin O'Connor | deb9cb9 | 2009-05-25 09:06:50 -0400 | [diff] [blame] | 819 | 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] | 820 | } |
| 821 | |
| 822 | static void |
| 823 | handle_101110(struct bregs *regs) |
| 824 | { |
Kevin O'Connor | deb9cb9 | 2009-05-25 09:06:50 -0400 | [diff] [blame] | 825 | vgafb_load_font(regs->es, (void*)(regs->bp+0), regs->cx |
| 826 | , regs->dx, regs->bl, regs->bh); |
Kevin O'Connor | c0c7df6 | 2009-05-17 18:11:33 -0400 | [diff] [blame] | 827 | set_scan_lines(regs->bh); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 828 | } |
| 829 | |
| 830 | static void |
| 831 | handle_101111(struct bregs *regs) |
| 832 | { |
Kevin O'Connor | deb9cb9 | 2009-05-25 09:06:50 -0400 | [diff] [blame] | 833 | 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] | 834 | set_scan_lines(14); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 835 | } |
| 836 | |
| 837 | static void |
| 838 | handle_101112(struct bregs *regs) |
| 839 | { |
Kevin O'Connor | deb9cb9 | 2009-05-25 09:06:50 -0400 | [diff] [blame] | 840 | 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] | 841 | set_scan_lines(8); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 842 | } |
| 843 | |
| 844 | static void |
| 845 | handle_101114(struct bregs *regs) |
| 846 | { |
Kevin O'Connor | deb9cb9 | 2009-05-25 09:06:50 -0400 | [diff] [blame] | 847 | 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] | 848 | set_scan_lines(16); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 849 | } |
| 850 | |
| 851 | static void |
| 852 | handle_101130(struct bregs *regs) |
| 853 | { |
Kevin O'Connor | e713204 | 2009-05-25 00:10:35 -0400 | [diff] [blame] | 854 | switch (regs->bh) { |
| 855 | case 0x00: { |
Kevin O'Connor | c9d3c2d | 2010-01-01 12:53:32 -0500 | [diff] [blame] | 856 | struct segoff_s so = GET_IVT(0x1f); |
| 857 | regs->es = so.seg; |
| 858 | regs->bp = so.offset; |
Kevin O'Connor | e713204 | 2009-05-25 00:10:35 -0400 | [diff] [blame] | 859 | break; |
| 860 | } |
| 861 | case 0x01: { |
Kevin O'Connor | c9d3c2d | 2010-01-01 12:53:32 -0500 | [diff] [blame] | 862 | struct segoff_s so = GET_IVT(0x43); |
| 863 | regs->es = so.seg; |
| 864 | regs->bp = so.offset; |
Kevin O'Connor | e713204 | 2009-05-25 00:10:35 -0400 | [diff] [blame] | 865 | break; |
| 866 | } |
| 867 | case 0x02: |
| 868 | regs->es = get_global_seg(); |
| 869 | regs->bp = (u32)vgafont14; |
| 870 | break; |
| 871 | case 0x03: |
| 872 | regs->es = get_global_seg(); |
| 873 | regs->bp = (u32)vgafont8; |
| 874 | break; |
| 875 | case 0x04: |
| 876 | regs->es = get_global_seg(); |
| 877 | regs->bp = (u32)vgafont8 + 128 * 8; |
| 878 | break; |
| 879 | case 0x05: |
| 880 | regs->es = get_global_seg(); |
| 881 | regs->bp = (u32)vgafont14alt; |
| 882 | break; |
| 883 | case 0x06: |
| 884 | regs->es = get_global_seg(); |
| 885 | regs->bp = (u32)vgafont16; |
| 886 | break; |
| 887 | case 0x07: |
| 888 | regs->es = get_global_seg(); |
| 889 | regs->bp = (u32)vgafont16alt; |
| 890 | break; |
| 891 | default: |
| 892 | dprintf(1, "Get font info BH(%02x) was discarded\n", regs->bh); |
| 893 | return; |
| 894 | } |
| 895 | // Set byte/char of on screen font |
| 896 | regs->cx = GET_BDA(char_height) & 0xff; |
| 897 | |
| 898 | // Set Highest char row |
| 899 | regs->dx = GET_BDA(video_rows); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 900 | } |
| 901 | |
| 902 | static void |
| 903 | handle_1011XX(struct bregs *regs) |
| 904 | { |
| 905 | debug_stub(regs); |
| 906 | } |
| 907 | |
| 908 | static void |
| 909 | handle_1011(struct bregs *regs) |
| 910 | { |
| 911 | switch (regs->al) { |
| 912 | case 0x00: handle_101100(regs); break; |
| 913 | case 0x01: handle_101101(regs); break; |
| 914 | case 0x02: handle_101102(regs); break; |
| 915 | case 0x03: handle_101103(regs); break; |
| 916 | case 0x04: handle_101104(regs); break; |
| 917 | case 0x10: handle_101110(regs); break; |
| 918 | case 0x11: handle_101111(regs); break; |
| 919 | case 0x12: handle_101112(regs); break; |
| 920 | case 0x14: handle_101114(regs); break; |
| 921 | case 0x30: handle_101130(regs); break; |
| 922 | default: handle_1011XX(regs); break; |
| 923 | } |
| 924 | } |
| 925 | |
| 926 | |
| 927 | static void |
| 928 | handle_101210(struct bregs *regs) |
| 929 | { |
Kevin O'Connor | e713204 | 2009-05-25 00:10:35 -0400 | [diff] [blame] | 930 | u16 crtc_addr = GET_BDA(crtc_address); |
| 931 | if (crtc_addr == VGAREG_MDA_CRTC_ADDRESS) |
| 932 | regs->bx = 0x0103; |
| 933 | else |
| 934 | regs->bx = 0x0003; |
| 935 | regs->cx = GET_BDA(video_switches) & 0x0f; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 936 | } |
| 937 | |
| 938 | static void |
| 939 | handle_101230(struct bregs *regs) |
| 940 | { |
Kevin O'Connor | e713204 | 2009-05-25 00:10:35 -0400 | [diff] [blame] | 941 | u8 mctl = GET_BDA(modeset_ctl); |
| 942 | u8 vswt = GET_BDA(video_switches); |
| 943 | switch (regs->al) { |
| 944 | case 0x00: |
| 945 | // 200 lines |
| 946 | mctl = (mctl & ~0x10) | 0x80; |
| 947 | vswt = (vswt & ~0x0f) | 0x08; |
| 948 | break; |
| 949 | case 0x01: |
| 950 | // 350 lines |
| 951 | mctl &= ~0x90; |
| 952 | vswt = (vswt & ~0x0f) | 0x09; |
| 953 | break; |
| 954 | case 0x02: |
| 955 | // 400 lines |
| 956 | mctl = (mctl & ~0x80) | 0x10; |
| 957 | vswt = (vswt & ~0x0f) | 0x09; |
| 958 | break; |
| 959 | default: |
| 960 | dprintf(1, "Select vert res (%02x) was discarded\n", regs->al); |
| 961 | break; |
| 962 | } |
| 963 | SET_BDA(modeset_ctl, mctl); |
| 964 | SET_BDA(video_switches, vswt); |
| 965 | regs->al = 0x12; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 966 | } |
| 967 | |
| 968 | static void |
| 969 | handle_101231(struct bregs *regs) |
| 970 | { |
Kevin O'Connor | e713204 | 2009-05-25 00:10:35 -0400 | [diff] [blame] | 971 | u8 v = (regs->al & 0x01) << 3; |
| 972 | u8 mctl = GET_BDA(video_ctl) & ~0x08; |
| 973 | SET_BDA(video_ctl, mctl | v); |
| 974 | regs->al = 0x12; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 975 | } |
| 976 | |
| 977 | static void |
| 978 | handle_101232(struct bregs *regs) |
| 979 | { |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 980 | vgahw_enable_video_addressing(regs->al); |
| 981 | regs->al = 0x12; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 982 | } |
| 983 | |
| 984 | static void |
| 985 | handle_101233(struct bregs *regs) |
| 986 | { |
Kevin O'Connor | e713204 | 2009-05-25 00:10:35 -0400 | [diff] [blame] | 987 | u8 v = ((regs->al << 1) & 0x02) ^ 0x02; |
| 988 | u8 v2 = GET_BDA(modeset_ctl) & ~0x02; |
| 989 | SET_BDA(modeset_ctl, v | v2); |
| 990 | regs->al = 0x12; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 991 | } |
| 992 | |
| 993 | static void |
| 994 | handle_101234(struct bregs *regs) |
| 995 | { |
Kevin O'Connor | e713204 | 2009-05-25 00:10:35 -0400 | [diff] [blame] | 996 | u8 v = (regs->al & 0x01) ^ 0x01; |
| 997 | u8 v2 = GET_BDA(modeset_ctl) & ~0x01; |
| 998 | SET_BDA(modeset_ctl, v | v2); |
| 999 | regs->al = 0x12; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1000 | } |
| 1001 | |
| 1002 | static void |
| 1003 | handle_101235(struct bregs *regs) |
| 1004 | { |
| 1005 | debug_stub(regs); |
| 1006 | regs->al = 0x12; |
| 1007 | } |
| 1008 | |
| 1009 | static void |
| 1010 | handle_101236(struct bregs *regs) |
| 1011 | { |
| 1012 | debug_stub(regs); |
| 1013 | regs->al = 0x12; |
| 1014 | } |
| 1015 | |
| 1016 | static void |
| 1017 | handle_1012XX(struct bregs *regs) |
| 1018 | { |
| 1019 | debug_stub(regs); |
| 1020 | } |
| 1021 | |
| 1022 | static void |
| 1023 | handle_1012(struct bregs *regs) |
| 1024 | { |
| 1025 | switch (regs->bl) { |
| 1026 | case 0x10: handle_101210(regs); break; |
| 1027 | case 0x30: handle_101230(regs); break; |
| 1028 | case 0x31: handle_101231(regs); break; |
| 1029 | case 0x32: handle_101232(regs); break; |
| 1030 | case 0x33: handle_101233(regs); break; |
| 1031 | case 0x34: handle_101234(regs); break; |
| 1032 | case 0x35: handle_101235(regs); break; |
| 1033 | case 0x36: handle_101236(regs); break; |
| 1034 | default: handle_1012XX(regs); break; |
| 1035 | } |
| 1036 | |
| 1037 | // XXX - cirrus has 1280, 1281, 1282, 1285, 129a, 12a0, 12a1, 12a2, 12ae |
| 1038 | } |
| 1039 | |
| 1040 | |
Kevin O'Connor | afb287d | 2009-05-31 21:15:33 -0400 | [diff] [blame] | 1041 | // Write string |
Kevin O'Connor | 0ad77f0 | 2009-05-31 20:46:43 -0400 | [diff] [blame] | 1042 | static void noinline |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1043 | handle_1013(struct bregs *regs) |
| 1044 | { |
Kevin O'Connor | 918b156 | 2009-05-25 11:05:18 -0400 | [diff] [blame] | 1045 | struct cursorpos cp = {regs->dl, regs->dh, regs->bh}; |
Kevin O'Connor | 2e86c6a | 2009-05-31 20:43:06 -0400 | [diff] [blame] | 1046 | // if row=0xff special case : use current cursor position |
| 1047 | if (cp.y == 0xff) |
| 1048 | cp = get_cursor_pos(cp.page); |
Kevin O'Connor | afb287d | 2009-05-31 21:15:33 -0400 | [diff] [blame] | 1049 | u8 flag = regs->al; |
| 1050 | if (flag & 2) |
| 1051 | write_attr_string(&cp, regs->cx, regs->es, (void*)(regs->bp + 0)); |
| 1052 | else |
| 1053 | write_string(&cp, regs->bl, regs->cx, regs->es, (void*)(regs->bp + 0)); |
| 1054 | |
| 1055 | if (flag & 1) |
| 1056 | set_cursor_pos(cp); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1057 | } |
| 1058 | |
| 1059 | |
| 1060 | static void |
| 1061 | handle_101a00(struct bregs *regs) |
| 1062 | { |
Kevin O'Connor | e713204 | 2009-05-25 00:10:35 -0400 | [diff] [blame] | 1063 | regs->bx = GET_BDA(dcc_index); |
| 1064 | regs->al = 0x1a; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1065 | } |
| 1066 | |
| 1067 | static void |
| 1068 | handle_101a01(struct bregs *regs) |
| 1069 | { |
Kevin O'Connor | e713204 | 2009-05-25 00:10:35 -0400 | [diff] [blame] | 1070 | SET_BDA(dcc_index, regs->bl); |
| 1071 | dprintf(1, "Alternate Display code (%02x) was discarded\n", regs->bh); |
| 1072 | regs->al = 0x1a; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1073 | } |
| 1074 | |
| 1075 | static void |
| 1076 | handle_101aXX(struct bregs *regs) |
| 1077 | { |
| 1078 | debug_stub(regs); |
| 1079 | } |
| 1080 | |
| 1081 | static void |
| 1082 | handle_101a(struct bregs *regs) |
| 1083 | { |
| 1084 | switch (regs->al) { |
| 1085 | case 0x00: handle_101a00(regs); break; |
| 1086 | case 0x01: handle_101a01(regs); break; |
| 1087 | default: handle_101aXX(regs); break; |
| 1088 | } |
| 1089 | } |
| 1090 | |
| 1091 | |
Kevin O'Connor | ca66864 | 2009-05-21 23:06:08 -0400 | [diff] [blame] | 1092 | struct funcInfo { |
Kevin O'Connor | 87dfad3 | 2011-12-23 21:18:49 -0500 | [diff] [blame] | 1093 | struct segoff_s static_functionality; |
Kevin O'Connor | ca66864 | 2009-05-21 23:06:08 -0400 | [diff] [blame] | 1094 | u8 bda_0x49[30]; |
| 1095 | u8 bda_0x84[3]; |
| 1096 | u8 dcc_index; |
| 1097 | u8 dcc_alt; |
| 1098 | u16 colors; |
| 1099 | u8 pages; |
| 1100 | u8 scan_lines; |
| 1101 | u8 primary_char; |
| 1102 | u8 secondar_char; |
| 1103 | u8 misc; |
| 1104 | u8 non_vga_mode; |
| 1105 | u8 reserved_2f[2]; |
| 1106 | u8 video_mem; |
| 1107 | u8 save_flags; |
| 1108 | u8 disp_info; |
| 1109 | u8 reserved_34[12]; |
| 1110 | }; |
| 1111 | |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1112 | static void |
| 1113 | handle_101b(struct bregs *regs) |
| 1114 | { |
Kevin O'Connor | ca66864 | 2009-05-21 23:06:08 -0400 | [diff] [blame] | 1115 | u16 seg = regs->es; |
| 1116 | struct funcInfo *info = (void*)(regs->di+0); |
| 1117 | memset_far(seg, info, 0, sizeof(*info)); |
| 1118 | // Address of static functionality table |
Kevin O'Connor | 87dfad3 | 2011-12-23 21:18:49 -0500 | [diff] [blame] | 1119 | SET_FARVAR(seg, info->static_functionality |
| 1120 | , SEGOFF(get_global_seg(), (u32)static_functionality)); |
Kevin O'Connor | ca66864 | 2009-05-21 23:06:08 -0400 | [diff] [blame] | 1121 | |
| 1122 | // Hard coded copy from BIOS area. Should it be cleaner ? |
Kevin O'Connor | 9f98542 | 2009-09-09 11:34:39 -0400 | [diff] [blame] | 1123 | memcpy_far(seg, info->bda_0x49, SEG_BDA, (void*)0x49 |
| 1124 | , sizeof(info->bda_0x49)); |
| 1125 | memcpy_far(seg, info->bda_0x84, SEG_BDA, (void*)0x84 |
| 1126 | , sizeof(info->bda_0x84)); |
Kevin O'Connor | ca66864 | 2009-05-21 23:06:08 -0400 | [diff] [blame] | 1127 | |
| 1128 | SET_FARVAR(seg, info->dcc_index, GET_BDA(dcc_index)); |
| 1129 | SET_FARVAR(seg, info->colors, 16); |
| 1130 | SET_FARVAR(seg, info->pages, 8); |
| 1131 | SET_FARVAR(seg, info->scan_lines, 2); |
| 1132 | SET_FARVAR(seg, info->video_mem, 3); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1133 | regs->al = 0x1B; |
| 1134 | } |
| 1135 | |
| 1136 | |
| 1137 | static void |
| 1138 | handle_101c00(struct bregs *regs) |
| 1139 | { |
Kevin O'Connor | ca66864 | 2009-05-21 23:06:08 -0400 | [diff] [blame] | 1140 | u16 flags = regs->cx; |
| 1141 | u16 size = 0; |
| 1142 | if (flags & 1) |
| 1143 | size += sizeof(struct saveVideoHardware); |
| 1144 | if (flags & 2) |
| 1145 | size += sizeof(struct saveBDAstate); |
| 1146 | if (flags & 4) |
| 1147 | size += sizeof(struct saveDACcolors); |
| 1148 | regs->bx = size; |
| 1149 | regs->al = 0x1c; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1150 | } |
| 1151 | |
| 1152 | static void |
| 1153 | handle_101c01(struct bregs *regs) |
| 1154 | { |
Kevin O'Connor | ca66864 | 2009-05-21 23:06:08 -0400 | [diff] [blame] | 1155 | u16 flags = regs->cx; |
| 1156 | u16 seg = regs->es; |
| 1157 | void *data = (void*)(regs->bx+0); |
| 1158 | if (flags & 1) { |
| 1159 | vgahw_save_state(seg, data); |
| 1160 | data += sizeof(struct saveVideoHardware); |
| 1161 | } |
| 1162 | if (flags & 2) { |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 1163 | save_bda_state(seg, data); |
Kevin O'Connor | ca66864 | 2009-05-21 23:06:08 -0400 | [diff] [blame] | 1164 | data += sizeof(struct saveBDAstate); |
| 1165 | } |
| 1166 | if (flags & 4) |
| 1167 | vgahw_save_dac_state(seg, data); |
| 1168 | regs->al = 0x1c; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1169 | } |
| 1170 | |
| 1171 | static void |
| 1172 | handle_101c02(struct bregs *regs) |
| 1173 | { |
Kevin O'Connor | ca66864 | 2009-05-21 23:06:08 -0400 | [diff] [blame] | 1174 | u16 flags = regs->cx; |
| 1175 | u16 seg = regs->es; |
| 1176 | void *data = (void*)(regs->bx+0); |
| 1177 | if (flags & 1) { |
| 1178 | vgahw_restore_state(seg, data); |
| 1179 | data += sizeof(struct saveVideoHardware); |
| 1180 | } |
| 1181 | if (flags & 2) { |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 1182 | restore_bda_state(seg, data); |
Kevin O'Connor | ca66864 | 2009-05-21 23:06:08 -0400 | [diff] [blame] | 1183 | data += sizeof(struct saveBDAstate); |
| 1184 | } |
| 1185 | if (flags & 4) |
| 1186 | vgahw_restore_dac_state(seg, data); |
| 1187 | regs->al = 0x1c; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1188 | } |
| 1189 | |
| 1190 | static void |
| 1191 | handle_101cXX(struct bregs *regs) |
| 1192 | { |
| 1193 | debug_stub(regs); |
| 1194 | } |
| 1195 | |
| 1196 | static void |
| 1197 | handle_101c(struct bregs *regs) |
| 1198 | { |
| 1199 | switch (regs->al) { |
| 1200 | case 0x00: handle_101c00(regs); break; |
| 1201 | case 0x01: handle_101c01(regs); break; |
| 1202 | case 0x02: handle_101c02(regs); break; |
| 1203 | default: handle_101cXX(regs); break; |
| 1204 | } |
| 1205 | } |
| 1206 | |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1207 | static void |
| 1208 | handle_104f00(struct bregs *regs) |
| 1209 | { |
Julian Pidancet | 87879e2 | 2011-12-19 05:08:00 +0000 | [diff] [blame] | 1210 | u16 seg = regs->es; |
| 1211 | struct vbe_info *info = (void*)(regs->di+0); |
| 1212 | |
| 1213 | if (GET_FARVAR(seg, info->signature) == VBE2_SIGNATURE) { |
| 1214 | dprintf(4, "Get VBE Controller: VBE2 Signature found\n"); |
| 1215 | } else if (GET_FARVAR(seg, info->signature) == VESA_SIGNATURE) { |
| 1216 | dprintf(4, "Get VBE Controller: VESA Signature found\n"); |
| 1217 | } else { |
| 1218 | dprintf(4, "Get VBE Controller: Invalid Signature\n"); |
| 1219 | } |
| 1220 | |
| 1221 | memset_far(seg, info, 0, sizeof(*info)); |
| 1222 | |
| 1223 | SET_FARVAR(seg, info->signature, VESA_SIGNATURE); |
| 1224 | |
| 1225 | SET_FARVAR(seg, info->version, 0x0200); |
| 1226 | |
| 1227 | SET_FARVAR(seg, info->oem_string, |
| 1228 | SEGOFF(get_global_seg(), (u32)VBE_OEM_STRING)); |
| 1229 | SET_FARVAR(seg, info->capabilities[0], 0x1); /* 8BIT DAC */ |
| 1230 | |
| 1231 | /* We generate our mode list in the reserved field of the info block */ |
| 1232 | SET_FARVAR(seg, info->video_mode, SEGOFF(seg, regs->di + 34)); |
| 1233 | |
| 1234 | /* Total memory (in 64 blocks) */ |
| 1235 | SET_FARVAR(seg, info->total_memory, vbe_total_mem()); |
| 1236 | |
| 1237 | SET_FARVAR(seg, info->oem_vendor_string, |
| 1238 | SEGOFF(get_global_seg(), (u32)VBE_VENDOR_STRING)); |
| 1239 | SET_FARVAR(seg, info->oem_product_string, |
| 1240 | SEGOFF(get_global_seg(), (u32)VBE_PRODUCT_STRING)); |
| 1241 | SET_FARVAR(seg, info->oem_revision_string, |
| 1242 | SEGOFF(get_global_seg(), (u32)VBE_REVISION_STRING)); |
| 1243 | |
| 1244 | /* Fill list of modes */ |
| 1245 | vbe_list_modes(seg, regs->di + 32); |
| 1246 | |
| 1247 | regs->al = regs->ah; /* 0x4F, Function supported */ |
| 1248 | regs->ah = 0x0; /* 0x0, Function call successful */ |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1249 | } |
| 1250 | |
| 1251 | static void |
| 1252 | handle_104f01(struct bregs *regs) |
| 1253 | { |
Julian Pidancet | 87879e2 | 2011-12-19 05:08:00 +0000 | [diff] [blame] | 1254 | u16 seg = regs->es; |
| 1255 | struct vbe_mode_info *info = (void*)(regs->di+0); |
| 1256 | u16 mode = regs->cx; |
| 1257 | struct vbe_modeinfo modeinfo; |
| 1258 | int rc; |
| 1259 | |
| 1260 | dprintf(1, "VBE mode info request: %x\n", mode); |
| 1261 | |
| 1262 | rc = vbe_mode_info(mode, &modeinfo); |
| 1263 | if (rc) { |
| 1264 | dprintf(1, "VBE mode %x not found\n", mode); |
| 1265 | regs->ax = 0x100; |
| 1266 | return; |
| 1267 | } |
| 1268 | |
| 1269 | u16 mode_attr = VBE_MODE_ATTRIBUTE_SUPPORTED | |
| 1270 | VBE_MODE_ATTRIBUTE_EXTENDED_INFORMATION_AVAILABLE | |
| 1271 | VBE_MODE_ATTRIBUTE_COLOR_MODE | |
| 1272 | VBE_MODE_ATTRIBUTE_GRAPHICS_MODE; |
| 1273 | if (modeinfo.depth == 4) |
| 1274 | mode_attr |= VBE_MODE_ATTRIBUTE_TTY_BIOS_SUPPORT; |
| 1275 | else |
| 1276 | mode_attr |= VBE_MODE_ATTRIBUTE_LINEAR_FRAME_BUFFER_MODE; |
| 1277 | SET_FARVAR(seg, info->mode_attributes, mode_attr); |
| 1278 | SET_FARVAR(seg, info->winA_attributes, |
| 1279 | VBE_WINDOW_ATTRIBUTE_RELOCATABLE | |
| 1280 | VBE_WINDOW_ATTRIBUTE_READABLE | |
| 1281 | VBE_WINDOW_ATTRIBUTE_WRITEABLE); |
| 1282 | SET_FARVAR(seg, info->winB_attributes, 0); |
| 1283 | SET_FARVAR(seg, info->win_granularity, 64); /* Bank size 64K */ |
| 1284 | SET_FARVAR(seg, info->win_size, 64); /* Bank size 64K */ |
| 1285 | SET_FARVAR(seg, info->winA_seg, 0xA000); |
| 1286 | SET_FARVAR(seg, info->winB_seg, 0x0); |
| 1287 | SET_FARVAR(seg, info->win_func_ptr, 0x0); |
| 1288 | SET_FARVAR(seg, info->bytes_per_scanline, modeinfo.linesize); |
| 1289 | SET_FARVAR(seg, info->xres, modeinfo.width); |
| 1290 | SET_FARVAR(seg, info->yres, modeinfo.height); |
| 1291 | SET_FARVAR(seg, info->xcharsize, 8); |
| 1292 | SET_FARVAR(seg, info->ycharsize, 16); |
| 1293 | if (modeinfo.depth == 4) |
| 1294 | SET_FARVAR(seg, info->planes, 4); |
| 1295 | else |
| 1296 | SET_FARVAR(seg, info->planes, 1); |
| 1297 | SET_FARVAR(seg, info->bits_per_pixel, modeinfo.depth); |
| 1298 | SET_FARVAR(seg, info->banks, |
| 1299 | (modeinfo.linesize * modeinfo.height + 65535) / 65536); |
| 1300 | if (modeinfo.depth == 4) |
| 1301 | SET_FARVAR(seg, info->mem_model, VBE_MEMORYMODEL_PLANAR); |
| 1302 | else if (modeinfo.depth == 8) |
| 1303 | SET_FARVAR(seg, info->mem_model, VBE_MEMORYMODEL_PACKED_PIXEL); |
| 1304 | else |
| 1305 | SET_FARVAR(seg, info->mem_model, VBE_MEMORYMODEL_DIRECT_COLOR); |
| 1306 | SET_FARVAR(seg, info->bank_size, 0); |
| 1307 | u32 pages = modeinfo.vram_size / (modeinfo.height * modeinfo.linesize); |
| 1308 | if (modeinfo.depth == 4) |
| 1309 | SET_FARVAR(seg, info->pages, (pages / 4) - 1); |
| 1310 | else |
| 1311 | SET_FARVAR(seg, info->pages, pages - 1); |
| 1312 | SET_FARVAR(seg, info->reserved0, 1); |
| 1313 | |
| 1314 | u8 r_size, r_pos, g_size, g_pos, b_size, b_pos, a_size, a_pos; |
| 1315 | |
| 1316 | switch (modeinfo.depth) { |
| 1317 | case 15: r_size = 5; r_pos = 10; g_size = 5; g_pos = 5; |
| 1318 | b_size = 5; b_pos = 0; a_size = 1; a_pos = 15; break; |
| 1319 | case 16: r_size = 5; r_pos = 11; g_size = 6; g_pos = 5; |
| 1320 | b_size = 5; b_pos = 0; a_size = 0; a_pos = 0; break; |
| 1321 | case 24: r_size = 8; r_pos = 16; g_size = 8; g_pos = 8; |
| 1322 | b_size = 8; b_pos = 0; a_size = 0; a_pos = 0; break; |
| 1323 | case 32: r_size = 8; r_pos = 16; g_size = 8; g_pos = 8; |
| 1324 | b_size = 8; b_pos = 0; a_size = 8; a_pos = 24; break; |
| 1325 | default: r_size = 0; r_pos = 0; g_size = 0; g_pos = 0; |
| 1326 | b_size = 0; b_pos = 0; a_size = 0; a_pos = 0; break; |
| 1327 | } |
| 1328 | |
| 1329 | SET_FARVAR(seg, info->red_size, r_size); |
| 1330 | SET_FARVAR(seg, info->red_pos, r_pos); |
| 1331 | SET_FARVAR(seg, info->green_size, g_size); |
| 1332 | SET_FARVAR(seg, info->green_pos, g_pos); |
| 1333 | SET_FARVAR(seg, info->blue_size, b_size); |
| 1334 | SET_FARVAR(seg, info->blue_pos, b_pos); |
| 1335 | SET_FARVAR(seg, info->alpha_size, a_size); |
| 1336 | SET_FARVAR(seg, info->alpha_pos, a_pos); |
| 1337 | |
| 1338 | if (modeinfo.depth == 32) |
| 1339 | SET_FARVAR(seg, info->directcolor_info, |
| 1340 | VBE_DIRECTCOLOR_RESERVED_BITS_AVAILABLE); |
| 1341 | else |
| 1342 | SET_FARVAR(seg, info->directcolor_info, 0); |
| 1343 | |
| 1344 | if (modeinfo.depth > 4) |
| 1345 | SET_FARVAR(seg, info->phys_base, modeinfo.phys_base); |
| 1346 | else |
| 1347 | SET_FARVAR(seg, info->phys_base, 0); |
| 1348 | |
| 1349 | SET_FARVAR(seg, info->reserved1, 0); |
| 1350 | SET_FARVAR(seg, info->reserved2, 0); |
| 1351 | SET_FARVAR(seg, info->linear_bytes_per_scanline, modeinfo.linesize); |
| 1352 | SET_FARVAR(seg, info->bank_pages, 0); |
| 1353 | SET_FARVAR(seg, info->linear_pages, 0); |
| 1354 | SET_FARVAR(seg, info->linear_red_size, r_size); |
| 1355 | SET_FARVAR(seg, info->linear_red_pos, r_pos); |
| 1356 | SET_FARVAR(seg, info->linear_green_size, g_size); |
| 1357 | SET_FARVAR(seg, info->linear_green_pos, g_pos); |
| 1358 | SET_FARVAR(seg, info->linear_blue_size, b_size); |
| 1359 | SET_FARVAR(seg, info->linear_blue_pos, b_pos); |
| 1360 | SET_FARVAR(seg, info->linear_alpha_size, a_size); |
| 1361 | SET_FARVAR(seg, info->linear_alpha_pos, a_pos); |
| 1362 | SET_FARVAR(seg, info->pixclock_max, 0); |
| 1363 | |
| 1364 | regs->al = regs->ah; /* 0x4F, Function supported */ |
| 1365 | regs->ah = 0x0; /* 0x0, Function call successful */ |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1366 | } |
| 1367 | |
| 1368 | static void |
| 1369 | handle_104f02(struct bregs *regs) |
| 1370 | { |
Julian Pidancet | 87879e2 | 2011-12-19 05:08:00 +0000 | [diff] [blame] | 1371 | //u16 seg = regs->es; |
| 1372 | //struct vbe_crtc_info *crtc_info = (void*)(regs->di+0); |
| 1373 | u16 mode = regs->bx; |
| 1374 | struct vbe_modeinfo modeinfo; |
| 1375 | int rc; |
| 1376 | |
| 1377 | dprintf(1, "VBE mode set: %x\n", mode); |
| 1378 | |
| 1379 | if (mode < 0x100) { /* VGA */ |
| 1380 | dprintf(1, "set VGA mode %x\n", mode); |
| 1381 | |
| 1382 | vbe_hires_enable(0); |
| 1383 | vga_set_mode(mode, 0); |
| 1384 | } else { /* VBE */ |
| 1385 | rc = vbe_mode_info(mode & 0x1ff, &modeinfo); |
| 1386 | if (rc) { |
| 1387 | dprintf(1, "VBE mode %x not found\n", mode & 0x1ff); |
| 1388 | regs->ax = 0x100; |
| 1389 | return; |
| 1390 | } |
| 1391 | vbe_hires_enable(1); |
| 1392 | vbe_set_mode(mode & 0x1ff, &modeinfo); |
| 1393 | |
| 1394 | if (mode & 0x4000) { |
| 1395 | /* Linear frame buffer */ |
| 1396 | /* XXX: ??? */ |
| 1397 | } |
| 1398 | if (!(mode & 0x8000)) { |
| 1399 | vbe_clear_scr(); |
| 1400 | } |
| 1401 | } |
| 1402 | |
| 1403 | regs->al = regs->ah; /* 0x4F, Function supported */ |
| 1404 | regs->ah = 0x0; /* 0x0, Function call successful */ |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1405 | } |
| 1406 | |
| 1407 | static void |
| 1408 | handle_104f03(struct bregs *regs) |
| 1409 | { |
Julian Pidancet | 87879e2 | 2011-12-19 05:08:00 +0000 | [diff] [blame] | 1410 | if (!vbe_hires_enabled()) { |
| 1411 | regs->bx = GET_BDA(video_mode); |
| 1412 | } else { |
| 1413 | regs->bx = vbe_curr_mode(); |
| 1414 | } |
| 1415 | |
| 1416 | dprintf(1, "VBE current mode=%x\n", regs->bx); |
| 1417 | |
| 1418 | regs->al = regs->ah; /* 0x4F, Function supported */ |
| 1419 | regs->ah = 0x0; /* 0x0, Function call successful */ |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1420 | } |
| 1421 | |
| 1422 | static void |
| 1423 | handle_104f04(struct bregs *regs) |
| 1424 | { |
Julian Pidancet | 87879e2 | 2011-12-19 05:08:00 +0000 | [diff] [blame] | 1425 | debug_enter(regs, DEBUG_VGA_10); |
| 1426 | regs->ax = 0x0100; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1427 | } |
| 1428 | |
| 1429 | static void |
| 1430 | handle_104f05(struct bregs *regs) |
| 1431 | { |
Julian Pidancet | 87879e2 | 2011-12-19 05:08:00 +0000 | [diff] [blame] | 1432 | debug_enter(regs, DEBUG_VGA_10); |
| 1433 | regs->ax = 0x0100; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1434 | } |
| 1435 | |
| 1436 | static void |
| 1437 | handle_104f06(struct bregs *regs) |
| 1438 | { |
Julian Pidancet | 87879e2 | 2011-12-19 05:08:00 +0000 | [diff] [blame] | 1439 | debug_enter(regs, DEBUG_VGA_10); |
| 1440 | regs->ax = 0x0100; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1441 | } |
| 1442 | |
| 1443 | static void |
| 1444 | handle_104f07(struct bregs *regs) |
| 1445 | { |
Julian Pidancet | 87879e2 | 2011-12-19 05:08:00 +0000 | [diff] [blame] | 1446 | debug_enter(regs, DEBUG_VGA_10); |
| 1447 | regs->ax = 0x0100; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1448 | } |
| 1449 | |
| 1450 | static void |
| 1451 | handle_104f08(struct bregs *regs) |
| 1452 | { |
Julian Pidancet | 87879e2 | 2011-12-19 05:08:00 +0000 | [diff] [blame] | 1453 | debug_enter(regs, DEBUG_VGA_10); |
| 1454 | regs->ax = 0x0100; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1455 | } |
| 1456 | |
| 1457 | static void |
| 1458 | handle_104f0a(struct bregs *regs) |
| 1459 | { |
Julian Pidancet | 87879e2 | 2011-12-19 05:08:00 +0000 | [diff] [blame] | 1460 | debug_enter(regs, DEBUG_VGA_10); |
| 1461 | regs->ax = 0x0100; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1462 | } |
| 1463 | |
| 1464 | static void |
| 1465 | handle_104fXX(struct bregs *regs) |
| 1466 | { |
| 1467 | debug_stub(regs); |
| 1468 | regs->ax = 0x0100; |
| 1469 | } |
| 1470 | |
| 1471 | static void |
| 1472 | handle_104f(struct bregs *regs) |
| 1473 | { |
Julian Pidancet | 87879e2 | 2011-12-19 05:08:00 +0000 | [diff] [blame] | 1474 | if (!vbe_enabled()) { |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1475 | handle_104fXX(regs); |
| 1476 | return; |
| 1477 | } |
| 1478 | |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1479 | switch (regs->al) { |
| 1480 | case 0x00: handle_104f00(regs); break; |
| 1481 | case 0x01: handle_104f01(regs); break; |
| 1482 | case 0x02: handle_104f02(regs); break; |
| 1483 | case 0x03: handle_104f03(regs); break; |
| 1484 | case 0x04: handle_104f04(regs); break; |
| 1485 | case 0x05: handle_104f05(regs); break; |
| 1486 | case 0x06: handle_104f06(regs); break; |
| 1487 | case 0x07: handle_104f07(regs); break; |
| 1488 | case 0x08: handle_104f08(regs); break; |
| 1489 | case 0x0a: handle_104f0a(regs); break; |
| 1490 | default: handle_104fXX(regs); break; |
| 1491 | } |
| 1492 | } |
| 1493 | |
| 1494 | |
| 1495 | static void |
| 1496 | handle_10XX(struct bregs *regs) |
| 1497 | { |
| 1498 | debug_stub(regs); |
| 1499 | } |
| 1500 | |
| 1501 | // INT 10h Video Support Service Entry Point |
| 1502 | void VISIBLE16 |
| 1503 | handle_10(struct bregs *regs) |
| 1504 | { |
| 1505 | debug_enter(regs, DEBUG_VGA_10); |
| 1506 | switch (regs->ah) { |
| 1507 | case 0x00: handle_1000(regs); break; |
| 1508 | case 0x01: handle_1001(regs); break; |
| 1509 | case 0x02: handle_1002(regs); break; |
| 1510 | case 0x03: handle_1003(regs); break; |
| 1511 | case 0x04: handle_1004(regs); break; |
| 1512 | case 0x05: handle_1005(regs); break; |
| 1513 | case 0x06: handle_1006(regs); break; |
| 1514 | case 0x07: handle_1007(regs); break; |
| 1515 | case 0x08: handle_1008(regs); break; |
| 1516 | case 0x09: handle_1009(regs); break; |
| 1517 | case 0x0a: handle_100a(regs); break; |
| 1518 | case 0x0b: handle_100b(regs); break; |
| 1519 | case 0x0c: handle_100c(regs); break; |
| 1520 | case 0x0d: handle_100d(regs); break; |
| 1521 | case 0x0e: handle_100e(regs); break; |
| 1522 | case 0x0f: handle_100f(regs); break; |
| 1523 | case 0x10: handle_1010(regs); break; |
| 1524 | case 0x11: handle_1011(regs); break; |
| 1525 | case 0x12: handle_1012(regs); break; |
| 1526 | case 0x13: handle_1013(regs); break; |
| 1527 | case 0x1a: handle_101a(regs); break; |
| 1528 | case 0x1b: handle_101b(regs); break; |
| 1529 | case 0x1c: handle_101c(regs); break; |
| 1530 | case 0x4f: handle_104f(regs); break; |
| 1531 | default: handle_10XX(regs); break; |
| 1532 | } |
| 1533 | } |
| 1534 | |
| 1535 | |
| 1536 | /**************************************************************** |
| 1537 | * VGA post |
| 1538 | ****************************************************************/ |
| 1539 | |
| 1540 | static void |
Kevin O'Connor | 1ca05b0 | 2010-01-03 17:43:37 -0500 | [diff] [blame] | 1541 | init_bios_area(void) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1542 | { |
| 1543 | // init detected hardware BIOS Area |
| 1544 | // set 80x25 color (not clear from RBIL but usual) |
| 1545 | u16 eqf = GET_BDA(equipment_list_flags); |
| 1546 | SET_BDA(equipment_list_flags, (eqf & 0xffcf) | 0x20); |
| 1547 | |
| 1548 | // Just for the first int10 find its children |
| 1549 | |
| 1550 | // the default char height |
| 1551 | SET_BDA(char_height, 0x10); |
| 1552 | |
| 1553 | // Clear the screen |
| 1554 | SET_BDA(video_ctl, 0x60); |
| 1555 | |
| 1556 | // Set the basic screen we have |
| 1557 | SET_BDA(video_switches, 0xf9); |
| 1558 | |
| 1559 | // Set the basic modeset options |
| 1560 | SET_BDA(modeset_ctl, 0x51); |
| 1561 | |
| 1562 | // Set the default MSR |
| 1563 | SET_BDA(video_msr, 0x09); |
| 1564 | } |
| 1565 | |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1566 | void VISIBLE16 |
| 1567 | vga_post(struct bregs *regs) |
| 1568 | { |
| 1569 | debug_enter(regs, DEBUG_VGA_POST); |
| 1570 | |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 1571 | vgahw_init(); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1572 | |
Kevin O'Connor | 4c52fb4 | 2011-12-24 00:44:07 -0500 | [diff] [blame] | 1573 | if (CONFIG_VGA_GEODELX) |
| 1574 | geodelx_init(); |
| 1575 | |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1576 | init_bios_area(); |
| 1577 | |
Julian Pidancet | 87879e2 | 2011-12-19 05:08:00 +0000 | [diff] [blame] | 1578 | vbe_init(regs->ah, regs->al); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1579 | |
| 1580 | extern void entry_10(void); |
Kevin O'Connor | 9f98542 | 2009-09-09 11:34:39 -0400 | [diff] [blame] | 1581 | SET_IVT(0x10, SEGOFF(get_global_seg(), (u32)entry_10)); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1582 | |
Julian Pidancet | 677631f | 2011-12-19 05:07:53 +0000 | [diff] [blame] | 1583 | if (CONFIG_VGA_CIRRUS) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1584 | cirrus_init(); |
| 1585 | |
| 1586 | // XXX - clear screen and display info |
| 1587 | |
Kevin O'Connor | f376037 | 2011-12-23 22:41:08 -0500 | [diff] [blame] | 1588 | build_video_param(); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1589 | |
| 1590 | // Fixup checksum |
| 1591 | extern u8 _rom_header_size, _rom_header_checksum; |
| 1592 | SET_VGA(_rom_header_checksum, 0); |
Kevin O'Connor | d113a99 | 2009-05-16 21:05:02 -0400 | [diff] [blame] | 1593 | 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] | 1594 | SET_VGA(_rom_header_checksum, sum); |
| 1595 | } |