Kevin O'Connor | 4040195 | 2011-12-31 03:43:12 -0500 | [diff] [blame] | 1 | // Video Bios Extensions handlers |
| 2 | // |
Kevin O'Connor | d9211ee | 2012-01-31 22:54:49 -0500 | [diff] [blame] | 3 | // Copyright (C) 2012 Kevin O'Connor <kevin@koconnor.net> |
| 4 | // Copyright (C) 2011 Julian Pidancet <julian.pidancet@citrix.com> |
Kevin O'Connor | 4040195 | 2011-12-31 03:43:12 -0500 | [diff] [blame] | 5 | // Copyright (C) 2001-2008 the LGPL VGABios developers Team |
| 6 | // |
| 7 | // This file may be distributed under the terms of the GNU LGPLv3 license. |
| 8 | |
Kevin O'Connor | 8154113 | 2012-02-12 11:49:25 -0500 | [diff] [blame] | 9 | #include "biosvar.h" // GET_GLOBAL |
Kevin O'Connor | 2d2fa31 | 2013-09-14 21:55:26 -0400 | [diff] [blame] | 10 | #include "bregs.h" // struct bregs |
| 11 | #include "config.h" // CONFIG_* |
| 12 | #include "output.h" // dprintf |
Kevin O'Connor | 2e57c81 | 2013-09-14 22:29:32 -0400 | [diff] [blame] | 13 | #include "std/vbe.h" // struct vbe_info |
Kevin O'Connor | fa9c66a | 2013-09-14 19:10:40 -0400 | [diff] [blame] | 14 | #include "string.h" // memset_far |
Kevin O'Connor | 2d2fa31 | 2013-09-14 21:55:26 -0400 | [diff] [blame] | 15 | #include "vgabios.h" // handle_104f |
| 16 | #include "vgahw.h" // vgahw_set_mode |
Kevin O'Connor | 4040195 | 2011-12-31 03:43:12 -0500 | [diff] [blame] | 17 | |
Kevin O'Connor | 3339c05 | 2012-01-13 20:00:35 -0500 | [diff] [blame] | 18 | u32 VBE_total_memory VAR16 = 256 * 1024; |
| 19 | u32 VBE_capabilities VAR16; |
| 20 | u32 VBE_framebuffer VAR16; |
Kevin O'Connor | 49ddd9e | 2012-09-04 13:16:36 -0400 | [diff] [blame] | 21 | u16 VBE_win_granularity VAR16; |
Kevin O'Connor | 3339c05 | 2012-01-13 20:00:35 -0500 | [diff] [blame] | 22 | |
Kevin O'Connor | 4040195 | 2011-12-31 03:43:12 -0500 | [diff] [blame] | 23 | static void |
| 24 | vbe_104f00(struct bregs *regs) |
| 25 | { |
| 26 | u16 seg = regs->es; |
| 27 | struct vbe_info *info = (void*)(regs->di+0); |
| 28 | |
| 29 | if (GET_FARVAR(seg, info->signature) == VBE2_SIGNATURE) { |
| 30 | dprintf(4, "Get VBE Controller: VBE2 Signature found\n"); |
| 31 | } else if (GET_FARVAR(seg, info->signature) == VESA_SIGNATURE) { |
| 32 | dprintf(4, "Get VBE Controller: VESA Signature found\n"); |
| 33 | } else { |
| 34 | dprintf(4, "Get VBE Controller: Invalid Signature\n"); |
| 35 | } |
| 36 | |
| 37 | memset_far(seg, info, 0, sizeof(*info)); |
| 38 | |
| 39 | SET_FARVAR(seg, info->signature, VESA_SIGNATURE); |
| 40 | |
Kevin O'Connor | 8154113 | 2012-02-12 11:49:25 -0500 | [diff] [blame] | 41 | SET_FARVAR(seg, info->version, 0x0300); |
Kevin O'Connor | 4040195 | 2011-12-31 03:43:12 -0500 | [diff] [blame] | 42 | |
| 43 | SET_FARVAR(seg, info->oem_string, |
| 44 | SEGOFF(get_global_seg(), (u32)VBE_OEM_STRING)); |
Kevin O'Connor | 3339c05 | 2012-01-13 20:00:35 -0500 | [diff] [blame] | 45 | SET_FARVAR(seg, info->capabilities, GET_GLOBAL(VBE_capabilities)); |
Kevin O'Connor | 4040195 | 2011-12-31 03:43:12 -0500 | [diff] [blame] | 46 | |
| 47 | /* We generate our mode list in the reserved field of the info block */ |
Kevin O'Connor | 34203cd | 2012-01-09 20:55:31 -0500 | [diff] [blame] | 48 | u16 *destmode = (void*)info->reserved; |
| 49 | SET_FARVAR(seg, info->video_mode, SEGOFF(seg, (u32)destmode)); |
Kevin O'Connor | 4040195 | 2011-12-31 03:43:12 -0500 | [diff] [blame] | 50 | |
Kevin O'Connor | 8154113 | 2012-02-12 11:49:25 -0500 | [diff] [blame] | 51 | /* Total memory (in 64k blocks) */ |
Kevin O'Connor | 3339c05 | 2012-01-13 20:00:35 -0500 | [diff] [blame] | 52 | SET_FARVAR(seg, info->total_memory |
| 53 | , GET_GLOBAL(VBE_total_memory) / (64*1024)); |
Kevin O'Connor | 4040195 | 2011-12-31 03:43:12 -0500 | [diff] [blame] | 54 | |
| 55 | SET_FARVAR(seg, info->oem_vendor_string, |
| 56 | SEGOFF(get_global_seg(), (u32)VBE_VENDOR_STRING)); |
| 57 | SET_FARVAR(seg, info->oem_product_string, |
| 58 | SEGOFF(get_global_seg(), (u32)VBE_PRODUCT_STRING)); |
| 59 | SET_FARVAR(seg, info->oem_revision_string, |
| 60 | SEGOFF(get_global_seg(), (u32)VBE_REVISION_STRING)); |
| 61 | |
| 62 | /* Fill list of modes */ |
Kevin O'Connor | 34203cd | 2012-01-09 20:55:31 -0500 | [diff] [blame] | 63 | u16 *last = (void*)&info->reserved[sizeof(info->reserved)]; |
| 64 | vgahw_list_modes(seg, destmode, last - 1); |
Kevin O'Connor | 4040195 | 2011-12-31 03:43:12 -0500 | [diff] [blame] | 65 | |
Kevin O'Connor | 3339c05 | 2012-01-13 20:00:35 -0500 | [diff] [blame] | 66 | regs->ax = 0x004f; |
Kevin O'Connor | 4040195 | 2011-12-31 03:43:12 -0500 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | static void |
| 70 | vbe_104f01(struct bregs *regs) |
| 71 | { |
| 72 | u16 seg = regs->es; |
| 73 | struct vbe_mode_info *info = (void*)(regs->di+0); |
| 74 | u16 mode = regs->cx; |
Kevin O'Connor | 4040195 | 2011-12-31 03:43:12 -0500 | [diff] [blame] | 75 | |
| 76 | dprintf(1, "VBE mode info request: %x\n", mode); |
| 77 | |
Kevin O'Connor | ef4f9e1 | 2012-09-03 13:54:28 -0400 | [diff] [blame] | 78 | struct vgamode_s *vmode_g = vgahw_find_mode(mode & ~MF_VBEFLAGS); |
Kevin O'Connor | 3339c05 | 2012-01-13 20:00:35 -0500 | [diff] [blame] | 79 | if (! vmode_g) { |
Kevin O'Connor | 4040195 | 2011-12-31 03:43:12 -0500 | [diff] [blame] | 80 | dprintf(1, "VBE mode %x not found\n", mode); |
Kevin O'Connor | 8154113 | 2012-02-12 11:49:25 -0500 | [diff] [blame] | 81 | regs->ax = 0x014f; |
Kevin O'Connor | 4040195 | 2011-12-31 03:43:12 -0500 | [diff] [blame] | 82 | return; |
| 83 | } |
| 84 | |
Kevin O'Connor | 643290f | 2012-01-13 22:08:52 -0500 | [diff] [blame] | 85 | memset_far(seg, info, 0, sizeof(*info)); |
Kevin O'Connor | 58dd051 | 2012-09-04 18:39:51 -0400 | [diff] [blame] | 86 | |
| 87 | // Basic information about video controller. |
Kevin O'Connor | 49ddd9e | 2012-09-04 13:16:36 -0400 | [diff] [blame] | 88 | u32 win_granularity = GET_GLOBAL(VBE_win_granularity); |
Kevin O'Connor | 4040195 | 2011-12-31 03:43:12 -0500 | [diff] [blame] | 89 | SET_FARVAR(seg, info->winA_attributes, |
Kevin O'Connor | 49ddd9e | 2012-09-04 13:16:36 -0400 | [diff] [blame] | 90 | (win_granularity ? VBE_WINDOW_ATTRIBUTE_RELOCATABLE : 0) | |
Kevin O'Connor | 4040195 | 2011-12-31 03:43:12 -0500 | [diff] [blame] | 91 | VBE_WINDOW_ATTRIBUTE_READABLE | |
| 92 | VBE_WINDOW_ATTRIBUTE_WRITEABLE); |
| 93 | SET_FARVAR(seg, info->winB_attributes, 0); |
Kevin O'Connor | 49ddd9e | 2012-09-04 13:16:36 -0400 | [diff] [blame] | 94 | SET_FARVAR(seg, info->win_granularity, win_granularity); |
Kevin O'Connor | 4040195 | 2011-12-31 03:43:12 -0500 | [diff] [blame] | 95 | SET_FARVAR(seg, info->win_size, 64); /* Bank size 64K */ |
Kevin O'Connor | 0377602 | 2012-01-21 11:00:11 -0500 | [diff] [blame] | 96 | SET_FARVAR(seg, info->winA_seg, GET_GLOBAL(vmode_g->sstart)); |
Kevin O'Connor | 4040195 | 2011-12-31 03:43:12 -0500 | [diff] [blame] | 97 | SET_FARVAR(seg, info->winB_seg, 0x0); |
Kevin O'Connor | 9961f99 | 2012-01-21 11:53:44 -0500 | [diff] [blame] | 98 | extern void entry_104f05(void); |
| 99 | SET_FARVAR(seg, info->win_func_ptr |
| 100 | , SEGOFF(get_global_seg(), (u32)entry_104f05)); |
Kevin O'Connor | 58dd051 | 2012-09-04 18:39:51 -0400 | [diff] [blame] | 101 | // Basic information about mode. |
Kevin O'Connor | 3339c05 | 2012-01-13 20:00:35 -0500 | [diff] [blame] | 102 | int width = GET_GLOBAL(vmode_g->width); |
| 103 | int height = GET_GLOBAL(vmode_g->height); |
Kevin O'Connor | 3524453 | 2012-01-29 11:42:44 -0500 | [diff] [blame] | 104 | int linesize = DIV_ROUND_UP(width * vga_bpp(vmode_g), 8); |
Kevin O'Connor | 3339c05 | 2012-01-13 20:00:35 -0500 | [diff] [blame] | 105 | SET_FARVAR(seg, info->bytes_per_scanline, linesize); |
| 106 | SET_FARVAR(seg, info->xres, width); |
| 107 | SET_FARVAR(seg, info->yres, height); |
Kevin O'Connor | 0377602 | 2012-01-21 11:00:11 -0500 | [diff] [blame] | 108 | SET_FARVAR(seg, info->xcharsize, GET_GLOBAL(vmode_g->cwidth)); |
| 109 | SET_FARVAR(seg, info->ycharsize, GET_GLOBAL(vmode_g->cheight)); |
Kevin O'Connor | 8154113 | 2012-02-12 11:49:25 -0500 | [diff] [blame] | 110 | int depth = GET_GLOBAL(vmode_g->depth); |
Kevin O'Connor | 3339c05 | 2012-01-13 20:00:35 -0500 | [diff] [blame] | 111 | SET_FARVAR(seg, info->bits_per_pixel, depth); |
Kevin O'Connor | 58dd051 | 2012-09-04 18:39:51 -0400 | [diff] [blame] | 112 | u8 memmodel = GET_GLOBAL(vmode_g->memmodel); |
| 113 | SET_FARVAR(seg, info->mem_model, memmodel); |
Kevin O'Connor | 4040195 | 2011-12-31 03:43:12 -0500 | [diff] [blame] | 114 | SET_FARVAR(seg, info->reserved0, 1); |
| 115 | |
Kevin O'Connor | 58dd051 | 2012-09-04 18:39:51 -0400 | [diff] [blame] | 116 | // Mode specific info. |
| 117 | u16 mode_attr = VBE_MODE_ATTRIBUTE_SUPPORTED | |
| 118 | VBE_MODE_ATTRIBUTE_EXTENDED_INFORMATION_AVAILABLE | |
| 119 | VBE_MODE_ATTRIBUTE_COLOR_MODE | |
| 120 | VBE_MODE_ATTRIBUTE_GRAPHICS_MODE | |
| 121 | VBE_MODE_ATTRIBUTE_NOT_VGA_COMPATIBLE; |
| 122 | u32 framebuffer = 0; |
| 123 | int planes = 1, banks = 1; |
| 124 | u32 pages = GET_GLOBAL(VBE_total_memory) / ALIGN(height * linesize, 64*1024); |
| 125 | switch (memmodel) { |
| 126 | case MM_TEXT: |
| 127 | mode_attr &= ~VBE_MODE_ATTRIBUTE_GRAPHICS_MODE; |
| 128 | mode_attr |= VBE_MODE_ATTRIBUTE_TTY_BIOS_SUPPORT; |
| 129 | if (GET_GLOBAL(vmode_g->sstart) == SEG_MTEXT) |
| 130 | mode_attr &= ~VBE_MODE_ATTRIBUTE_COLOR_MODE; |
| 131 | pages = 1; |
| 132 | break; |
| 133 | case MM_CGA: |
| 134 | pages = 1; |
| 135 | banks = 2; |
| 136 | SET_FARVAR(seg, info->bank_size, 8); |
| 137 | break; |
| 138 | case MM_PLANAR: |
| 139 | planes = 4; |
| 140 | pages /= 4; |
| 141 | break; |
| 142 | default: |
| 143 | framebuffer = GET_GLOBAL(VBE_framebuffer); |
| 144 | if (framebuffer) |
| 145 | mode_attr |= VBE_MODE_ATTRIBUTE_LINEAR_FRAME_BUFFER_MODE; |
| 146 | break; |
| 147 | } |
Kevin O'Connor | 0db6988 | 2013-09-13 16:21:10 -0400 | [diff] [blame] | 148 | if (pages > 128) |
| 149 | pages = 128; |
| 150 | if (pages < 2) |
| 151 | pages++; |
Kevin O'Connor | 58dd051 | 2012-09-04 18:39:51 -0400 | [diff] [blame] | 152 | SET_FARVAR(seg, info->mode_attributes, mode_attr); |
| 153 | SET_FARVAR(seg, info->planes, planes); |
| 154 | SET_FARVAR(seg, info->pages, pages - 1); |
| 155 | SET_FARVAR(seg, info->banks, banks); |
Kevin O'Connor | 4040195 | 2011-12-31 03:43:12 -0500 | [diff] [blame] | 156 | |
Kevin O'Connor | 58dd051 | 2012-09-04 18:39:51 -0400 | [diff] [blame] | 157 | // Pixel color breakdown |
| 158 | u8 r_size, r_pos, g_size, g_pos, b_size, b_pos, a_size, a_pos; |
Kevin O'Connor | 3339c05 | 2012-01-13 20:00:35 -0500 | [diff] [blame] | 159 | switch (depth) { |
Kevin O'Connor | 4040195 | 2011-12-31 03:43:12 -0500 | [diff] [blame] | 160 | case 15: r_size = 5; r_pos = 10; g_size = 5; g_pos = 5; |
| 161 | b_size = 5; b_pos = 0; a_size = 1; a_pos = 15; break; |
| 162 | case 16: r_size = 5; r_pos = 11; g_size = 6; g_pos = 5; |
| 163 | b_size = 5; b_pos = 0; a_size = 0; a_pos = 0; break; |
| 164 | case 24: r_size = 8; r_pos = 16; g_size = 8; g_pos = 8; |
| 165 | b_size = 8; b_pos = 0; a_size = 0; a_pos = 0; break; |
| 166 | case 32: r_size = 8; r_pos = 16; g_size = 8; g_pos = 8; |
Kevin O'Connor | 58dd051 | 2012-09-04 18:39:51 -0400 | [diff] [blame] | 167 | b_size = 8; b_pos = 0; a_size = 8; a_pos = 24; |
| 168 | SET_FARVAR(seg, info->directcolor_info, |
| 169 | VBE_DIRECTCOLOR_RESERVED_BITS_AVAILABLE); |
| 170 | break; |
Kevin O'Connor | 4040195 | 2011-12-31 03:43:12 -0500 | [diff] [blame] | 171 | default: r_size = 0; r_pos = 0; g_size = 0; g_pos = 0; |
| 172 | b_size = 0; b_pos = 0; a_size = 0; a_pos = 0; break; |
| 173 | } |
Kevin O'Connor | 4040195 | 2011-12-31 03:43:12 -0500 | [diff] [blame] | 174 | SET_FARVAR(seg, info->red_size, r_size); |
| 175 | SET_FARVAR(seg, info->red_pos, r_pos); |
| 176 | SET_FARVAR(seg, info->green_size, g_size); |
| 177 | SET_FARVAR(seg, info->green_pos, g_pos); |
| 178 | SET_FARVAR(seg, info->blue_size, b_size); |
| 179 | SET_FARVAR(seg, info->blue_pos, b_pos); |
| 180 | SET_FARVAR(seg, info->alpha_size, a_size); |
| 181 | SET_FARVAR(seg, info->alpha_pos, a_pos); |
| 182 | |
Kevin O'Connor | 58dd051 | 2012-09-04 18:39:51 -0400 | [diff] [blame] | 183 | // Linear framebuffer info. |
| 184 | if (framebuffer) { |
| 185 | SET_FARVAR(seg, info->phys_base, framebuffer); |
Kevin O'Connor | 4040195 | 2011-12-31 03:43:12 -0500 | [diff] [blame] | 186 | |
Kevin O'Connor | 58dd051 | 2012-09-04 18:39:51 -0400 | [diff] [blame] | 187 | SET_FARVAR(seg, info->reserved1, 0); |
| 188 | SET_FARVAR(seg, info->reserved2, 0); |
| 189 | SET_FARVAR(seg, info->linear_bytes_per_scanline, linesize); |
| 190 | SET_FARVAR(seg, info->linear_pages, 0); |
| 191 | SET_FARVAR(seg, info->linear_red_size, r_size); |
| 192 | SET_FARVAR(seg, info->linear_red_pos, r_pos); |
| 193 | SET_FARVAR(seg, info->linear_green_size, g_size); |
| 194 | SET_FARVAR(seg, info->linear_green_pos, g_pos); |
| 195 | SET_FARVAR(seg, info->linear_blue_size, b_size); |
| 196 | SET_FARVAR(seg, info->linear_blue_pos, b_pos); |
| 197 | SET_FARVAR(seg, info->linear_alpha_size, a_size); |
| 198 | SET_FARVAR(seg, info->linear_alpha_pos, a_pos); |
| 199 | } |
Kevin O'Connor | 4040195 | 2011-12-31 03:43:12 -0500 | [diff] [blame] | 200 | |
Kevin O'Connor | 3339c05 | 2012-01-13 20:00:35 -0500 | [diff] [blame] | 201 | regs->ax = 0x004f; |
Kevin O'Connor | 4040195 | 2011-12-31 03:43:12 -0500 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | static void |
| 205 | vbe_104f02(struct bregs *regs) |
| 206 | { |
Kevin O'Connor | 5108c69 | 2011-12-31 19:13:45 -0500 | [diff] [blame] | 207 | dprintf(1, "VBE mode set: %x\n", regs->bx); |
Kevin O'Connor | 4040195 | 2011-12-31 03:43:12 -0500 | [diff] [blame] | 208 | |
Kevin O'Connor | e6bc4c1 | 2012-01-21 11:26:37 -0500 | [diff] [blame] | 209 | int mode = regs->bx & ~MF_VBEFLAGS; |
| 210 | int flags = regs->bx & MF_VBEFLAGS; |
| 211 | int ret = vga_set_mode(mode, flags); |
Kevin O'Connor | 4040195 | 2011-12-31 03:43:12 -0500 | [diff] [blame] | 212 | |
Kevin O'Connor | 5108c69 | 2011-12-31 19:13:45 -0500 | [diff] [blame] | 213 | regs->ah = ret; |
| 214 | regs->al = 0x4f; |
Kevin O'Connor | 4040195 | 2011-12-31 03:43:12 -0500 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | static void |
| 218 | vbe_104f03(struct bregs *regs) |
| 219 | { |
Kevin O'Connor | e6bc4c1 | 2012-01-21 11:26:37 -0500 | [diff] [blame] | 220 | regs->bx = GET_BDA(vbe_mode); |
Kevin O'Connor | 4040195 | 2011-12-31 03:43:12 -0500 | [diff] [blame] | 221 | dprintf(1, "VBE current mode=%x\n", regs->bx); |
Kevin O'Connor | 3339c05 | 2012-01-13 20:00:35 -0500 | [diff] [blame] | 222 | regs->ax = 0x004f; |
Kevin O'Connor | 4040195 | 2011-12-31 03:43:12 -0500 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | static void |
| 226 | vbe_104f04(struct bregs *regs) |
| 227 | { |
Kevin O'Connor | 2469f89 | 2012-02-04 12:40:02 -0500 | [diff] [blame] | 228 | u16 seg = regs->es; |
| 229 | void *data = (void*)(regs->bx+0); |
| 230 | u16 states = regs->cx; |
| 231 | if (states & ~0x0f) |
| 232 | goto fail; |
| 233 | int ret; |
| 234 | switch (regs->dl) { |
| 235 | case 0x00: |
| 236 | ret = vgahw_size_state(states); |
| 237 | if (ret < 0) |
| 238 | goto fail; |
| 239 | regs->bx = ret / 64; |
| 240 | break; |
| 241 | case 0x01: |
| 242 | ret = vgahw_save_state(seg, data, states); |
| 243 | if (ret) |
| 244 | goto fail; |
| 245 | break; |
| 246 | case 0x02: |
| 247 | ret = vgahw_restore_state(seg, data, states); |
| 248 | if (ret) |
| 249 | goto fail; |
| 250 | break; |
| 251 | default: |
| 252 | goto fail; |
| 253 | } |
| 254 | regs->ax = 0x004f; |
| 255 | return; |
| 256 | fail: |
| 257 | regs->ax = 0x014f; |
Kevin O'Connor | 4040195 | 2011-12-31 03:43:12 -0500 | [diff] [blame] | 258 | } |
| 259 | |
Kevin O'Connor | 9961f99 | 2012-01-21 11:53:44 -0500 | [diff] [blame] | 260 | void VISIBLE16 |
Kevin O'Connor | 4040195 | 2011-12-31 03:43:12 -0500 | [diff] [blame] | 261 | vbe_104f05(struct bregs *regs) |
| 262 | { |
Kevin O'Connor | 9961f99 | 2012-01-21 11:53:44 -0500 | [diff] [blame] | 263 | if (regs->bh > 1 || regs->bl > 1) |
| 264 | goto fail; |
| 265 | if (GET_BDA(vbe_mode) & MF_LINEARFB) { |
| 266 | regs->ah = VBE_RETURN_STATUS_INVALID; |
| 267 | return; |
| 268 | } |
| 269 | struct vgamode_s *vmode_g = get_current_mode(); |
| 270 | if (! vmode_g) |
| 271 | goto fail; |
| 272 | if (regs->bh) { |
| 273 | int ret = vgahw_get_window(vmode_g, regs->bl); |
| 274 | if (ret < 0) |
| 275 | goto fail; |
| 276 | regs->dx = ret; |
| 277 | regs->ax = 0x004f; |
| 278 | return; |
| 279 | } |
| 280 | int ret = vgahw_set_window(vmode_g, regs->bl, regs->dx); |
| 281 | if (ret) |
| 282 | goto fail; |
| 283 | regs->ax = 0x004f; |
| 284 | return; |
| 285 | fail: |
Kevin O'Connor | 8154113 | 2012-02-12 11:49:25 -0500 | [diff] [blame] | 286 | regs->ax = 0x014f; |
Kevin O'Connor | 4040195 | 2011-12-31 03:43:12 -0500 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | static void |
| 290 | vbe_104f06(struct bregs *regs) |
| 291 | { |
Kevin O'Connor | 3876b53 | 2012-01-24 00:07:44 -0500 | [diff] [blame] | 292 | if (regs->bl > 0x02) |
| 293 | goto fail; |
| 294 | struct vgamode_s *vmode_g = get_current_mode(); |
| 295 | if (! vmode_g) |
| 296 | goto fail; |
| 297 | int bpp = vga_bpp(vmode_g); |
| 298 | |
| 299 | if (regs->bl == 0x00) { |
| 300 | int ret = vgahw_set_linelength(vmode_g, DIV_ROUND_UP(regs->cx * bpp, 8)); |
| 301 | if (ret) |
| 302 | goto fail; |
| 303 | } else if (regs->bl == 0x02) { |
| 304 | int ret = vgahw_set_linelength(vmode_g, regs->cx); |
| 305 | if (ret) |
| 306 | goto fail; |
| 307 | } |
| 308 | int linelength = vgahw_get_linelength(vmode_g); |
| 309 | if (linelength < 0) |
| 310 | goto fail; |
| 311 | |
| 312 | regs->bx = linelength; |
| 313 | regs->cx = (linelength * 8) / bpp; |
| 314 | regs->dx = GET_GLOBAL(VBE_total_memory) / linelength; |
| 315 | regs->ax = 0x004f; |
| 316 | return; |
| 317 | fail: |
| 318 | regs->ax = 0x014f; |
Kevin O'Connor | 4040195 | 2011-12-31 03:43:12 -0500 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | static void |
| 322 | vbe_104f07(struct bregs *regs) |
| 323 | { |
Kevin O'Connor | d61fc53 | 2012-01-27 20:37:45 -0500 | [diff] [blame] | 324 | struct vgamode_s *vmode_g = get_current_mode(); |
| 325 | if (! vmode_g) |
| 326 | goto fail; |
| 327 | int bpp = vga_bpp(vmode_g); |
| 328 | int linelength = vgahw_get_linelength(vmode_g); |
| 329 | if (linelength < 0) |
| 330 | goto fail; |
| 331 | |
| 332 | int ret; |
| 333 | switch (regs->bl) { |
| 334 | case 0x80: |
| 335 | case 0x00: |
| 336 | ret = vgahw_set_displaystart( |
| 337 | vmode_g, DIV_ROUND_UP(regs->cx * bpp, 8) + linelength * regs->dx); |
| 338 | if (ret) |
| 339 | goto fail; |
| 340 | break; |
| 341 | case 0x01: |
| 342 | ret = vgahw_get_displaystart(vmode_g); |
| 343 | if (ret < 0) |
| 344 | goto fail; |
| 345 | regs->dx = ret / linelength; |
| 346 | regs->cx = (ret % linelength) * 8 / bpp; |
| 347 | break; |
| 348 | default: |
| 349 | goto fail; |
| 350 | } |
| 351 | regs->ax = 0x004f; |
| 352 | return; |
| 353 | fail: |
| 354 | regs->ax = 0x014f; |
Kevin O'Connor | 4040195 | 2011-12-31 03:43:12 -0500 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | static void |
| 358 | vbe_104f08(struct bregs *regs) |
| 359 | { |
Kevin O'Connor | e737b17 | 2012-02-04 11:08:39 -0500 | [diff] [blame] | 360 | struct vgamode_s *vmode_g = get_current_mode(); |
| 361 | if (! vmode_g) |
| 362 | goto fail; |
| 363 | u8 memmodel = GET_GLOBAL(vmode_g->memmodel); |
| 364 | if (memmodel == MM_DIRECT || memmodel == MM_YUV) { |
| 365 | regs->ax = 0x034f; |
| 366 | return; |
| 367 | } |
| 368 | if (regs->bl > 1) |
| 369 | goto fail; |
| 370 | if (regs->bl == 0) { |
| 371 | int ret = vgahw_set_dacformat(vmode_g, regs->bh); |
| 372 | if (ret < 0) |
| 373 | goto fail; |
| 374 | } |
| 375 | int ret = vgahw_get_dacformat(vmode_g); |
| 376 | if (ret < 0) |
| 377 | goto fail; |
| 378 | regs->bh = ret; |
| 379 | regs->ax = 0x004f; |
| 380 | return; |
| 381 | fail: |
| 382 | regs->ax = 0x014f; |
Kevin O'Connor | 4040195 | 2011-12-31 03:43:12 -0500 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | static void |
| 386 | vbe_104f0a(struct bregs *regs) |
| 387 | { |
| 388 | debug_stub(regs); |
| 389 | regs->ax = 0x0100; |
| 390 | } |
| 391 | |
| 392 | static void |
Kevin O'Connor | 59f75d4 | 2012-01-27 20:52:29 -0500 | [diff] [blame] | 393 | vbe_104f10(struct bregs *regs) |
| 394 | { |
| 395 | switch (regs->bl) { |
| 396 | case 0x00: |
| 397 | regs->bx = 0x0f30; |
| 398 | break; |
| 399 | case 0x01: |
| 400 | SET_BDA(vbe_flag, regs->bh); |
| 401 | break; |
| 402 | case 0x02: |
| 403 | regs->bh = GET_BDA(vbe_flag); |
| 404 | break; |
| 405 | default: |
| 406 | regs->ax = 0x014f; |
| 407 | return; |
| 408 | } |
| 409 | regs->ax = 0x004f; |
| 410 | } |
| 411 | |
| 412 | static void |
Kevin O'Connor | 4040195 | 2011-12-31 03:43:12 -0500 | [diff] [blame] | 413 | vbe_104fXX(struct bregs *regs) |
| 414 | { |
| 415 | debug_stub(regs); |
| 416 | regs->ax = 0x0100; |
| 417 | } |
| 418 | |
Kevin O'Connor | 6ee837b | 2012-02-13 20:09:02 -0500 | [diff] [blame] | 419 | void noinline |
Kevin O'Connor | 4040195 | 2011-12-31 03:43:12 -0500 | [diff] [blame] | 420 | handle_104f(struct bregs *regs) |
| 421 | { |
Kevin O'Connor | b3df857 | 2012-01-15 02:43:19 -0500 | [diff] [blame] | 422 | if (!CONFIG_VGA_VBE) { |
Kevin O'Connor | 4040195 | 2011-12-31 03:43:12 -0500 | [diff] [blame] | 423 | vbe_104fXX(regs); |
| 424 | return; |
| 425 | } |
| 426 | |
| 427 | switch (regs->al) { |
| 428 | case 0x00: vbe_104f00(regs); break; |
| 429 | case 0x01: vbe_104f01(regs); break; |
| 430 | case 0x02: vbe_104f02(regs); break; |
| 431 | case 0x03: vbe_104f03(regs); break; |
| 432 | case 0x04: vbe_104f04(regs); break; |
| 433 | case 0x05: vbe_104f05(regs); break; |
| 434 | case 0x06: vbe_104f06(regs); break; |
| 435 | case 0x07: vbe_104f07(regs); break; |
| 436 | case 0x08: vbe_104f08(regs); break; |
| 437 | case 0x0a: vbe_104f0a(regs); break; |
Kevin O'Connor | 59f75d4 | 2012-01-27 20:52:29 -0500 | [diff] [blame] | 438 | case 0x10: vbe_104f10(regs); break; |
Kevin O'Connor | 4040195 | 2011-12-31 03:43:12 -0500 | [diff] [blame] | 439 | default: vbe_104fXX(regs); break; |
| 440 | } |
| 441 | } |