Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Stefan Reinauer | 9839cbd | 2010-04-21 20:06:10 +0000 | [diff] [blame] | 4 | * Copyright (C) 2007 Advanced Micro Devices, Inc. |
| 5 | * Copyright (C) 2009-2010 coresystems GmbH |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
Stefan Reinauer | 6c641ee | 2009-09-23 21:52:45 +0000 | [diff] [blame] | 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | #include <device/pci.h> |
| 22 | #include <string.h> |
| 23 | |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 24 | #include <arch/io.h> |
Stefan Reinauer | 42dc721 | 2009-10-24 00:47:07 +0000 | [diff] [blame] | 25 | #include <arch/registers.h> |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 26 | #include <console/console.h> |
Libra Li | c143693 | 2009-12-23 19:16:47 +0000 | [diff] [blame] | 27 | #include <arch/interrupt.h> |
Stefan Reinauer | c1efb90 | 2011-10-12 14:30:59 -0700 | [diff] [blame] | 28 | #include <cbfs.h> |
| 29 | #include <delay.h> |
Stefan Reinauer | b6b8871 | 2011-10-12 14:35:54 -0700 | [diff] [blame] | 30 | #include <pc80/i8259.h> |
Stefan Reinauer | 216fa46 | 2011-10-12 14:25:07 -0700 | [diff] [blame] | 31 | #include "x86.h" |
Stefan Reinauer | c1efb90 | 2011-10-12 14:30:59 -0700 | [diff] [blame] | 32 | #include "vbe.h" |
Patrick Georgi | 3e77eb6 | 2012-11-22 10:39:16 +0100 | [diff] [blame] | 33 | #include <lib/jpeg.h> |
Patrick Georgi | 199b09c | 2012-11-22 12:46:12 +0100 | [diff] [blame] | 34 | /* we use x86emu's register file representation */ |
| 35 | #include <x86emu/regs.h> |
| 36 | |
| 37 | /* to have a common register file for interrupt handlers */ |
| 38 | X86EMU_sysEnv _X86EMU_env; |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 39 | |
Stefan Reinauer | 841af5e | 2010-05-11 15:39:20 +0000 | [diff] [blame] | 40 | void (*realmode_call)(u32 addr, u32 eax, u32 ebx, u32 ecx, u32 edx, |
Stefan Reinauer | c1efb90 | 2011-10-12 14:30:59 -0700 | [diff] [blame] | 41 | u32 esi, u32 edi) __attribute__((regparm(0))) = |
| 42 | (void *)&__realmode_call; |
Stefan Reinauer | 841af5e | 2010-05-11 15:39:20 +0000 | [diff] [blame] | 43 | |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 44 | void (*realmode_interrupt)(u32 intno, u32 eax, u32 ebx, u32 ecx, u32 edx, |
Stefan Reinauer | c1efb90 | 2011-10-12 14:30:59 -0700 | [diff] [blame] | 45 | u32 esi, u32 edi) __attribute__((regparm(0))) = |
| 46 | (void *)&__realmode_interrupt; |
Stefan Reinauer | 841af5e | 2010-05-11 15:39:20 +0000 | [diff] [blame] | 47 | |
Stefan Reinauer | 841af5e | 2010-05-11 15:39:20 +0000 | [diff] [blame] | 48 | static void setup_rombios(void) |
| 49 | { |
| 50 | const char date[] = "06/11/99"; |
| 51 | memcpy((void *)0xffff5, &date, 8); |
| 52 | |
| 53 | const char ident[] = "PCI_ISA"; |
| 54 | memcpy((void *)0xfffd9, &ident, 7); |
| 55 | |
| 56 | /* system model: IBM-AT */ |
| 57 | write8(0xffffe, 0xfc); |
| 58 | } |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 59 | |
Patrick Georgi | 199b09c | 2012-11-22 12:46:12 +0100 | [diff] [blame] | 60 | static int (*intXX_handler[256])(void) = { NULL }; |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 61 | |
Patrick Georgi | 199b09c | 2012-11-22 12:46:12 +0100 | [diff] [blame] | 62 | static int intXX_exception_handler(void) |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 63 | { |
Patrick Georgi | 199b09c | 2012-11-22 12:46:12 +0100 | [diff] [blame] | 64 | /* compatibility shim */ |
| 65 | struct eregs reg_info = { |
| 66 | .eax=X86_EAX, |
| 67 | .ecx=X86_ECX, |
| 68 | .edx=X86_EDX, |
| 69 | .ebx=X86_EBX, |
| 70 | .esp=X86_ESP, |
| 71 | .ebp=X86_EBP, |
| 72 | .esi=X86_ESI, |
| 73 | .edi=X86_EDI, |
| 74 | .vector=M.x86.intno, |
| 75 | .error_code=0, // FIXME: fill in |
| 76 | .eip=X86_EIP, |
| 77 | .cs=X86_CS, |
| 78 | .eflags=X86_EFLAGS |
| 79 | }; |
| 80 | struct eregs *regs = ®_info; |
| 81 | |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 82 | printk(BIOS_INFO, "Oops, exception %d while executing option rom\n", |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 83 | regs->vector); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 84 | x86_exception(regs); // Call coreboot exception handler |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 85 | |
Stefan Reinauer | b6b8871 | 2011-10-12 14:35:54 -0700 | [diff] [blame] | 86 | return 0; // Never really returns |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 87 | } |
| 88 | |
Patrick Georgi | 199b09c | 2012-11-22 12:46:12 +0100 | [diff] [blame] | 89 | static int intXX_unknown_handler(void) |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 90 | { |
Myles Watson | f53eaa3 | 2010-09-09 14:42:58 +0000 | [diff] [blame] | 91 | printk(BIOS_INFO, "Unsupported software interrupt #0x%x eax 0x%x\n", |
Patrick Georgi | 199b09c | 2012-11-22 12:46:12 +0100 | [diff] [blame] | 92 | M.x86.intno, X86_EAX); |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 93 | |
| 94 | return -1; |
| 95 | } |
| 96 | |
Libra Li | c143693 | 2009-12-23 19:16:47 +0000 | [diff] [blame] | 97 | /* setup interrupt handlers for mainboard */ |
| 98 | void mainboard_interrupt_handlers(int intXX, void *intXX_func) |
| 99 | { |
| 100 | intXX_handler[intXX] = intXX_func; |
| 101 | } |
| 102 | |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 103 | static void setup_interrupt_handlers(void) |
| 104 | { |
| 105 | int i; |
| 106 | |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 107 | /* The first 16 intXX functions are not BIOS services, |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 108 | * but the CPU-generated exceptions ("hardware interrupts") |
| 109 | */ |
| 110 | for (i = 0; i < 0x10; i++) |
| 111 | intXX_handler[i] = &intXX_exception_handler; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 112 | |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 113 | /* Mark all other intXX calls as unknown first */ |
| 114 | for (i = 0x10; i < 0x100; i++) |
Libra Li | c143693 | 2009-12-23 19:16:47 +0000 | [diff] [blame] | 115 | { |
| 116 | /* If the mainboard_interrupt_handler isn't called first. |
| 117 | */ |
| 118 | if(!intXX_handler[i]) |
| 119 | { |
| 120 | /* Now set the default functions that are actually |
Stefan Reinauer | c1efb90 | 2011-10-12 14:30:59 -0700 | [diff] [blame] | 121 | * needed to initialize the option roms. This is |
| 122 | * very slick, as it allows us to implement mainboard |
| 123 | * specific interrupt handlers, such as the int15. |
Libra Li | c143693 | 2009-12-23 19:16:47 +0000 | [diff] [blame] | 124 | */ |
| 125 | switch (i) { |
Myles Watson | f53eaa3 | 2010-09-09 14:42:58 +0000 | [diff] [blame] | 126 | case 0x10: |
| 127 | intXX_handler[0x10] = &int10_handler; |
| 128 | break; |
Libra Li | c143693 | 2009-12-23 19:16:47 +0000 | [diff] [blame] | 129 | case 0x12: |
| 130 | intXX_handler[0x12] = &int12_handler; |
| 131 | break; |
Myles Watson | f53eaa3 | 2010-09-09 14:42:58 +0000 | [diff] [blame] | 132 | case 0x16: |
| 133 | intXX_handler[0x16] = &int16_handler; |
| 134 | break; |
Libra Li | c143693 | 2009-12-23 19:16:47 +0000 | [diff] [blame] | 135 | case 0x1a: |
| 136 | intXX_handler[0x1a] = &int1a_handler; |
| 137 | break; |
| 138 | default: |
| 139 | intXX_handler[i] = &intXX_unknown_handler; |
| 140 | break; |
| 141 | } |
| 142 | } |
| 143 | } |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | static void write_idt_stub(void *target, u8 intnum) |
| 147 | { |
| 148 | unsigned char *codeptr; |
| 149 | codeptr = (unsigned char *) target; |
| 150 | memcpy(codeptr, &__idt_handler, (size_t)&__idt_handler_size); |
| 151 | codeptr[3] = intnum; /* modify int# in the code stub. */ |
| 152 | } |
| 153 | |
| 154 | static void setup_realmode_idt(void) |
| 155 | { |
| 156 | struct realmode_idt *idts = (struct realmode_idt *) 0; |
| 157 | int i; |
| 158 | |
| 159 | /* Copy IDT stub code for each interrupt. This might seem wasteful |
| 160 | * but it is really simple |
| 161 | */ |
| 162 | for (i = 0; i < 256; i++) { |
| 163 | idts[i].cs = 0; |
| 164 | idts[i].offset = 0x1000 + (i * (u32)&__idt_handler_size); |
| 165 | write_idt_stub((void *)((u32 )idts[i].offset), i); |
| 166 | } |
| 167 | |
| 168 | /* Many option ROMs use the hard coded interrupt entry points in the |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 169 | * system bios. So install them at the known locations. |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 170 | */ |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 171 | |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 172 | /* int42 is the relocated int10 */ |
Stefan Reinauer | 714e2a1 | 2010-04-24 23:15:23 +0000 | [diff] [blame] | 173 | write_idt_stub((void *)0xff065, 0x42); |
Stefan Reinauer | 841af5e | 2010-05-11 15:39:20 +0000 | [diff] [blame] | 174 | /* BIOS Int 11 Handler F000:F84D */ |
| 175 | write_idt_stub((void *)0xff84d, 0x11); |
| 176 | /* BIOS Int 12 Handler F000:F841 */ |
| 177 | write_idt_stub((void *)0xff841, 0x12); |
| 178 | /* BIOS Int 13 Handler F000:EC59 */ |
| 179 | write_idt_stub((void *)0xfec59, 0x13); |
| 180 | /* BIOS Int 14 Handler F000:E739 */ |
| 181 | write_idt_stub((void *)0xfe739, 0x14); |
| 182 | /* BIOS Int 15 Handler F000:F859 */ |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 183 | write_idt_stub((void *)0xff859, 0x15); |
Stefan Reinauer | 841af5e | 2010-05-11 15:39:20 +0000 | [diff] [blame] | 184 | /* BIOS Int 16 Handler F000:E82E */ |
| 185 | write_idt_stub((void *)0xfe82e, 0x16); |
| 186 | /* BIOS Int 17 Handler F000:EFD2 */ |
| 187 | write_idt_stub((void *)0xfefd2, 0x17); |
| 188 | /* ROM BIOS Int 1A Handler F000:FE6E */ |
| 189 | write_idt_stub((void *)0xffe6e, 0x1a); |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 190 | } |
| 191 | |
Stefan Reinauer | c1efb90 | 2011-10-12 14:30:59 -0700 | [diff] [blame] | 192 | #if CONFIG_FRAMEBUFFER_SET_VESA_MODE |
Gabe Black | fb8632a | 2012-09-30 04:47:48 -0700 | [diff] [blame] | 193 | vbe_mode_info_t mode_info; |
| 194 | static int mode_info_valid; |
| 195 | |
| 196 | int vbe_mode_info_valid(void) |
| 197 | { |
| 198 | return mode_info_valid; |
| 199 | } |
| 200 | |
| 201 | static u8 vbe_get_mode_info(vbe_mode_info_t * mi) |
Stefan Reinauer | c1efb90 | 2011-10-12 14:30:59 -0700 | [diff] [blame] | 202 | { |
Stefan Reinauer | 01c3de9 | 2012-08-29 09:28:52 -0700 | [diff] [blame] | 203 | printk(BIOS_DEBUG, "VBE: Getting information about VESA mode %04x\n", |
Gabe Black | fb8632a | 2012-09-30 04:47:48 -0700 | [diff] [blame] | 204 | mi->video_mode); |
Stefan Reinauer | c1efb90 | 2011-10-12 14:30:59 -0700 | [diff] [blame] | 205 | char *buffer = (char *)&__buffer; |
| 206 | u16 buffer_seg = (((unsigned long)buffer) >> 4) & 0xff00; |
| 207 | u16 buffer_adr = ((unsigned long)buffer) & 0xffff; |
| 208 | realmode_interrupt(0x10, VESA_GET_MODE_INFO, 0x0000, |
Gabe Black | fb8632a | 2012-09-30 04:47:48 -0700 | [diff] [blame] | 209 | mi->video_mode, 0x0000, buffer_seg, buffer_adr); |
| 210 | memcpy(mi->mode_info_block, buffer, sizeof(vbe_mode_info_t)); |
| 211 | mode_info_valid = 1; |
Stefan Reinauer | c1efb90 | 2011-10-12 14:30:59 -0700 | [diff] [blame] | 212 | return 0; |
| 213 | } |
| 214 | |
Gabe Black | fb8632a | 2012-09-30 04:47:48 -0700 | [diff] [blame] | 215 | static u8 vbe_set_mode(vbe_mode_info_t * mi) |
Stefan Reinauer | c1efb90 | 2011-10-12 14:30:59 -0700 | [diff] [blame] | 216 | { |
Gabe Black | fb8632a | 2012-09-30 04:47:48 -0700 | [diff] [blame] | 217 | printk(BIOS_DEBUG, "VBE: Setting VESA mode %04x\n", mi->video_mode); |
Stefan Reinauer | c1efb90 | 2011-10-12 14:30:59 -0700 | [diff] [blame] | 218 | // request linear framebuffer mode |
Gabe Black | fb8632a | 2012-09-30 04:47:48 -0700 | [diff] [blame] | 219 | mi->video_mode |= (1 << 14); |
Stefan Reinauer | c1efb90 | 2011-10-12 14:30:59 -0700 | [diff] [blame] | 220 | // request clearing of framebuffer |
Gabe Black | fb8632a | 2012-09-30 04:47:48 -0700 | [diff] [blame] | 221 | mi->video_mode &= ~(1 << 15); |
| 222 | realmode_interrupt(0x10, VESA_SET_MODE, mi->video_mode, |
Stefan Reinauer | c1efb90 | 2011-10-12 14:30:59 -0700 | [diff] [blame] | 223 | 0x0000, 0x0000, 0x0000, 0x0000); |
| 224 | return 0; |
| 225 | } |
| 226 | |
Stefan Reinauer | c1efb90 | 2011-10-12 14:30:59 -0700 | [diff] [blame] | 227 | /* These two functions could probably even be generic between |
| 228 | * yabel and x86 native. TBD later. |
| 229 | */ |
| 230 | void vbe_set_graphics(void) |
| 231 | { |
| 232 | mode_info.video_mode = (1 << 14) | CONFIG_FRAMEBUFFER_VESA_MODE; |
| 233 | vbe_get_mode_info(&mode_info); |
| 234 | unsigned char *framebuffer = |
Stefan Reinauer | b6b8871 | 2011-10-12 14:35:54 -0700 | [diff] [blame] | 235 | (unsigned char *)mode_info.vesa.phys_base_ptr; |
Stefan Reinauer | 01c3de9 | 2012-08-29 09:28:52 -0700 | [diff] [blame] | 236 | printk(BIOS_DEBUG, "VBE: resolution: %dx%d@%d\n", |
| 237 | le16_to_cpu(mode_info.vesa.x_resolution), |
| 238 | le16_to_cpu(mode_info.vesa.y_resolution), |
| 239 | mode_info.vesa.bits_per_pixel); |
| 240 | printk(BIOS_DEBUG, "VBE: framebuffer: %p\n", framebuffer); |
| 241 | if (!framebuffer) { |
| 242 | printk(BIOS_DEBUG, "VBE: Mode does not support linear " |
| 243 | "framebuffer\n"); |
| 244 | return; |
| 245 | } |
| 246 | |
Stefan Reinauer | c1efb90 | 2011-10-12 14:30:59 -0700 | [diff] [blame] | 247 | vbe_set_mode(&mode_info); |
| 248 | #if CONFIG_BOOTSPLASH |
| 249 | struct jpeg_decdata *decdata; |
| 250 | decdata = malloc(sizeof(*decdata)); |
| 251 | unsigned char *jpeg = cbfs_find_file("bootsplash.jpg", |
| 252 | CBFS_TYPE_BOOTSPLASH); |
| 253 | if (!jpeg) { |
Stefan Reinauer | 01c3de9 | 2012-08-29 09:28:52 -0700 | [diff] [blame] | 254 | printk(BIOS_DEBUG, "VBE: No bootsplash found.\n"); |
Stefan Reinauer | c1efb90 | 2011-10-12 14:30:59 -0700 | [diff] [blame] | 255 | return; |
| 256 | } |
| 257 | int ret = 0; |
| 258 | ret = jpeg_decode(jpeg, framebuffer, 1024, 768, 16, decdata); |
| 259 | #endif |
| 260 | } |
| 261 | |
| 262 | void vbe_textmode_console(void) |
| 263 | { |
| 264 | delay(2); |
| 265 | realmode_interrupt(0x10, 0x0003, 0x0000, 0x0000, |
| 266 | 0x0000, 0x0000, 0x0000); |
| 267 | } |
| 268 | |
| 269 | void fill_lb_framebuffer(struct lb_framebuffer *framebuffer) |
| 270 | { |
Stefan Reinauer | b6b8871 | 2011-10-12 14:35:54 -0700 | [diff] [blame] | 271 | framebuffer->physical_address = mode_info.vesa.phys_base_ptr; |
Stefan Reinauer | c1efb90 | 2011-10-12 14:30:59 -0700 | [diff] [blame] | 272 | |
| 273 | framebuffer->x_resolution = le16_to_cpu(mode_info.vesa.x_resolution); |
| 274 | framebuffer->y_resolution = le16_to_cpu(mode_info.vesa.y_resolution); |
| 275 | framebuffer->bytes_per_line = |
| 276 | le16_to_cpu(mode_info.vesa.bytes_per_scanline); |
| 277 | framebuffer->bits_per_pixel = mode_info.vesa.bits_per_pixel; |
| 278 | |
| 279 | framebuffer->red_mask_pos = mode_info.vesa.red_mask_pos; |
| 280 | framebuffer->red_mask_size = mode_info.vesa.red_mask_size; |
| 281 | |
| 282 | framebuffer->green_mask_pos = mode_info.vesa.green_mask_pos; |
| 283 | framebuffer->green_mask_size = mode_info.vesa.green_mask_size; |
| 284 | |
| 285 | framebuffer->blue_mask_pos = mode_info.vesa.blue_mask_pos; |
| 286 | framebuffer->blue_mask_size = mode_info.vesa.blue_mask_size; |
| 287 | |
| 288 | framebuffer->reserved_mask_pos = mode_info.vesa.reserved_mask_pos; |
| 289 | framebuffer->reserved_mask_size = mode_info.vesa.reserved_mask_size; |
| 290 | } |
| 291 | #endif |
| 292 | |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 293 | void run_bios(struct device *dev, unsigned long addr) |
| 294 | { |
Stefan Reinauer | 841af5e | 2010-05-11 15:39:20 +0000 | [diff] [blame] | 295 | u32 num_dev = (dev->bus->secondary << 8) | dev->path.pci.devfn; |
| 296 | |
Stefan Reinauer | b6b8871 | 2011-10-12 14:35:54 -0700 | [diff] [blame] | 297 | /* Setting up required hardware. |
| 298 | * Removing this will cause random illegal instruction exceptions |
| 299 | * in some option roms. |
| 300 | */ |
| 301 | setup_i8259(); |
| 302 | |
Stefan Reinauer | 841af5e | 2010-05-11 15:39:20 +0000 | [diff] [blame] | 303 | /* Set up some legacy information in the F segment */ |
| 304 | setup_rombios(); |
Libra Li | c143693 | 2009-12-23 19:16:47 +0000 | [diff] [blame] | 305 | |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 306 | /* Set up C interrupt handlers */ |
| 307 | setup_interrupt_handlers(); |
| 308 | |
Stefan Reinauer | 841af5e | 2010-05-11 15:39:20 +0000 | [diff] [blame] | 309 | /* Set up real-mode IDT */ |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 310 | setup_realmode_idt(); |
| 311 | |
| 312 | memcpy(REALMODE_BASE, &__realmode_code, (size_t)&__realmode_code_size); |
| 313 | printk(BIOS_SPEW, "Real mode stub @%p: %d bytes\n", REALMODE_BASE, |
| 314 | (u32)&__realmode_code_size); |
| 315 | |
| 316 | printk(BIOS_DEBUG, "Calling Option ROM...\n"); |
Stefan Reinauer | 841af5e | 2010-05-11 15:39:20 +0000 | [diff] [blame] | 317 | /* TODO ES:DI Pointer to System BIOS PnP Installation Check Structure */ |
| 318 | /* Option ROM entry point is at OPROM start + 3 */ |
| 319 | realmode_call(addr + 0x0003, num_dev, 0xffff, 0x0000, 0xffff, 0x0, 0x0); |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 320 | printk(BIOS_DEBUG, "... Option ROM returned.\n"); |
Stefan Reinauer | c1efb90 | 2011-10-12 14:30:59 -0700 | [diff] [blame] | 321 | |
| 322 | #if CONFIG_FRAMEBUFFER_SET_VESA_MODE |
| 323 | vbe_set_graphics(); |
| 324 | #endif |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 325 | } |
| 326 | |
Stefan Reinauer | d4814bd | 2011-04-21 20:45:45 +0000 | [diff] [blame] | 327 | #if CONFIG_GEODE_VSA |
Stefan Reinauer | 9839cbd | 2010-04-21 20:06:10 +0000 | [diff] [blame] | 328 | #include <cpu/amd/lxdef.h> |
| 329 | #include <cpu/amd/vr.h> |
| 330 | #include <cbfs.h> |
| 331 | |
| 332 | #define VSA2_BUFFER 0x60000 |
| 333 | #define VSA2_ENTRY_POINT 0x60020 |
| 334 | |
| 335 | // TODO move to a header file. |
| 336 | void do_vsmbios(void); |
| 337 | |
| 338 | /* VSA virtual register helper */ |
| 339 | static u32 VSA_vrRead(u16 classIndex) |
| 340 | { |
| 341 | u32 eax, ebx, ecx, edx; |
| 342 | asm volatile ( |
| 343 | "movw $0x0AC1C, %%dx\n" |
| 344 | "orl $0x0FC530000, %%eax\n" |
| 345 | "outl %%eax, %%dx\n" |
| 346 | "addb $2, %%dl\n" |
| 347 | "inw %%dx, %%ax\n" |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 348 | : "=a" (eax), "=b"(ebx), "=c"(ecx), "=d"(edx) |
Stefan Reinauer | 9839cbd | 2010-04-21 20:06:10 +0000 | [diff] [blame] | 349 | : "a"(classIndex) |
| 350 | ); |
| 351 | |
| 352 | return eax; |
| 353 | } |
| 354 | |
| 355 | void do_vsmbios(void) |
| 356 | { |
| 357 | printk(BIOS_DEBUG, "Preparing for VSA...\n"); |
| 358 | |
Stefan Reinauer | 9839cbd | 2010-04-21 20:06:10 +0000 | [diff] [blame] | 359 | /* Set up C interrupt handlers */ |
| 360 | setup_interrupt_handlers(); |
| 361 | |
| 362 | /* Setting up realmode IDT */ |
| 363 | setup_realmode_idt(); |
| 364 | |
| 365 | memcpy(REALMODE_BASE, &__realmode_code, (size_t)&__realmode_code_size); |
| 366 | printk(BIOS_SPEW, "VSA: Real mode stub @%p: %d bytes\n", REALMODE_BASE, |
| 367 | (u32)&__realmode_code_size); |
| 368 | |
| 369 | if ((unsigned int)cbfs_load_stage("vsa") != VSA2_ENTRY_POINT) { |
| 370 | printk(BIOS_ERR, "Failed to load VSA.\n"); |
| 371 | return; |
| 372 | } |
| 373 | |
| 374 | unsigned char *buf = (unsigned char *)VSA2_BUFFER; |
| 375 | printk(BIOS_DEBUG, "VSA: Buffer @%p *[0k]=%02x\n", buf, buf[0]); |
| 376 | printk(BIOS_DEBUG, "VSA: Signature *[0x20-0x23] is %02x:%02x:%02x:%02x\n", |
| 377 | buf[0x20], buf[0x21], buf[0x22], buf[0x23]); |
| 378 | |
| 379 | /* Check for code to emit POST code at start of VSA. */ |
| 380 | if ((buf[0x20] != 0xb0) || (buf[0x21] != 0x10) || |
| 381 | (buf[0x22] != 0xe6) || (buf[0x23] != 0x80)) { |
| 382 | printk(BIOS_WARNING, "VSA: Signature incorrect. Install failed.\n"); |
| 383 | return; |
| 384 | } |
| 385 | |
| 386 | printk(BIOS_DEBUG, "Calling VSA module...\n"); |
Stefan Reinauer | 841af5e | 2010-05-11 15:39:20 +0000 | [diff] [blame] | 387 | |
Stefan Reinauer | 9839cbd | 2010-04-21 20:06:10 +0000 | [diff] [blame] | 388 | /* ECX gets SMM, EDX gets SYSMEM */ |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 389 | realmode_call(VSA2_ENTRY_POINT, 0x0, 0x0, MSR_GLIU0_SMM, |
Stefan Reinauer | 841af5e | 2010-05-11 15:39:20 +0000 | [diff] [blame] | 390 | MSR_GLIU0_SYSMEM, 0x0, 0x0); |
| 391 | |
Stefan Reinauer | 9839cbd | 2010-04-21 20:06:10 +0000 | [diff] [blame] | 392 | printk(BIOS_DEBUG, "... VSA module returned.\n"); |
| 393 | |
| 394 | /* Restart timer 1 */ |
| 395 | outb(0x56, 0x43); |
| 396 | outb(0x12, 0x41); |
| 397 | |
| 398 | /* Check that VSA is running OK */ |
| 399 | if (VSA_vrRead(SIGNATURE) == VSA2_SIGNATURE) |
| 400 | printk(BIOS_DEBUG, "VSM: VSA2 VR signature verified.\n"); |
| 401 | else |
| 402 | printk(BIOS_ERR, "VSM: VSA2 VR signature not valid. Install failed.\n"); |
| 403 | } |
| 404 | #endif |
| 405 | |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 406 | /* interrupt_handler() is called from assembler code only, |
Stefan Reinauer | 9839cbd | 2010-04-21 20:06:10 +0000 | [diff] [blame] | 407 | * so there is no use in putting the prototype into a header file. |
| 408 | */ |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 409 | int __attribute__((regparm(0))) interrupt_handler(u32 intnumber, |
| 410 | u32 gsfs, u32 dses, |
| 411 | u32 edi, u32 esi, |
| 412 | u32 ebp, u32 esp, |
| 413 | u32 ebx, u32 edx, |
| 414 | u32 ecx, u32 eax, |
Uwe Hermann | 312673c | 2009-10-27 21:49:33 +0000 | [diff] [blame] | 415 | u32 cs_ip, u16 stackflags); |
| 416 | |
| 417 | int __attribute__((regparm(0))) interrupt_handler(u32 intnumber, |
| 418 | u32 gsfs, u32 dses, |
| 419 | u32 edi, u32 esi, |
| 420 | u32 ebp, u32 esp, |
| 421 | u32 ebx, u32 edx, |
| 422 | u32 ecx, u32 eax, |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 423 | u32 cs_ip, u16 stackflags) |
| 424 | { |
| 425 | u32 ip; |
| 426 | u32 cs; |
| 427 | u32 flags; |
Patrick Georgi | 503af72 | 2012-11-22 10:48:18 +0100 | [diff] [blame] | 428 | int ret = 0; |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 429 | |
| 430 | ip = cs_ip & 0xffff; |
| 431 | cs = cs_ip >> 16; |
| 432 | flags = stackflags; |
| 433 | |
Myles Watson | 6c9bc01 | 2010-09-07 22:30:15 +0000 | [diff] [blame] | 434 | #if CONFIG_REALMODE_DEBUG |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 435 | printk(BIOS_DEBUG, "oprom: INT# 0x%x\n", intnumber); |
| 436 | printk(BIOS_DEBUG, "oprom: eax: %08x ebx: %08x ecx: %08x edx: %08x\n", |
| 437 | eax, ebx, ecx, edx); |
| 438 | printk(BIOS_DEBUG, "oprom: ebp: %08x esp: %08x edi: %08x esi: %08x\n", |
| 439 | ebp, esp, edi, esi); |
| 440 | printk(BIOS_DEBUG, "oprom: ip: %04x cs: %04x flags: %08x\n", |
| 441 | ip, cs, flags); |
Myles Watson | 6c9bc01 | 2010-09-07 22:30:15 +0000 | [diff] [blame] | 442 | #endif |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 443 | |
Patrick Georgi | 199b09c | 2012-11-22 12:46:12 +0100 | [diff] [blame] | 444 | // Fetch arguments from the stack and put them to a place |
| 445 | // suitable for the interrupt handlers |
| 446 | X86_EAX = eax; |
| 447 | X86_ECX = ecx; |
| 448 | X86_EDX = edx; |
| 449 | X86_EBX = ebx; |
| 450 | X86_ESP = esp; |
| 451 | X86_EBP = ebp; |
| 452 | X86_ESI = esi; |
| 453 | X86_EDI = edi; |
| 454 | M.x86.intno = intnumber; |
| 455 | /* TODO: error_code must be stored somewhere */ |
| 456 | X86_EIP = ip; |
| 457 | X86_CS = cs; |
| 458 | X86_EFLAGS = flags; |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 459 | |
| 460 | // Call the interrupt handler for this int# |
Patrick Georgi | 199b09c | 2012-11-22 12:46:12 +0100 | [diff] [blame] | 461 | ret = intXX_handler[intnumber](); |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 462 | |
| 463 | // Put registers back on the stack. The assembler code |
| 464 | // will later pop them. |
| 465 | // What happens here is that we force (volatile!) changing |
| 466 | // the values of the parameters of this function. We do this |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 467 | // because we know that they stay alive on the stack after |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 468 | // we leave this function. Don't say this is bollocks. |
Patrick Georgi | 199b09c | 2012-11-22 12:46:12 +0100 | [diff] [blame] | 469 | *(volatile u32 *)&eax = X86_EAX; |
| 470 | *(volatile u32 *)&ecx = X86_ECX; |
| 471 | *(volatile u32 *)&edx = X86_EDX; |
| 472 | *(volatile u32 *)&ebx = X86_EBX; |
| 473 | *(volatile u32 *)&esi = X86_ESI; |
| 474 | *(volatile u32 *)&edi = X86_EDI; |
| 475 | flags = X86_EFLAGS; |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 476 | |
Patrick Georgi | 503af72 | 2012-11-22 10:48:18 +0100 | [diff] [blame] | 477 | /* Pass success or error back to our caller via the CARRY flag */ |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 478 | if (ret) { |
Patrick Georgi | 503af72 | 2012-11-22 10:48:18 +0100 | [diff] [blame] | 479 | flags &= ~1; // no error: clear carry |
| 480 | }else{ |
Stefan Reinauer | f75b19a | 2010-04-22 18:15:32 +0000 | [diff] [blame] | 481 | printk(BIOS_DEBUG,"int%02x call returned error.\n", intnumber); |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 482 | flags |= 1; // error: set carry |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 483 | } |
| 484 | *(volatile u16 *)&stackflags = flags; |
| 485 | |
Patrick Georgi | 503af72 | 2012-11-22 10:48:18 +0100 | [diff] [blame] | 486 | /* The assembler code doesn't actually care for the return value, |
| 487 | * but keep it around so its expectations are met */ |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 488 | return ret; |
| 489 | } |
| 490 | |