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