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