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