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