blob: 83d068bcd6df05ad732a431f30aedf38bbc9f876 [file] [log] [blame]
Stefan Reinauer38cd29e2009-08-11 21:28:25 +00001/*
2 * This file is part of the coreboot project.
3 *
Stefan Reinauer9839cbd2010-04-21 20:06:10 +00004 * Copyright (C) 2007 Advanced Micro Devices, Inc.
5 * Copyright (C) 2009-2010 coresystems GmbH
Stefan Reinauer38cd29e2009-08-11 21:28:25 +00006 *
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.
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000015 */
16
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000017#include <arch/io.h>
Edward O'Callaghan91810dd2014-07-30 13:53:04 +100018#include <arch/interrupt.h>
Stefan Reinauer42dc7212009-10-24 00:47:07 +000019#include <arch/registers.h>
Edward O'Callaghan91810dd2014-07-30 13:53:04 +100020#include <boot/coreboot_tables.h>
Edward O'Callaghan7842eb22014-07-29 22:28:19 +100021#include <cbfs.h>
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000022#include <console/console.h>
Edward O'Callaghan91810dd2014-07-30 13:53:04 +100023#include <cpu/amd/lxdef.h>
24#include <cpu/amd/vr.h>
Stefan Reinauerc1efb902011-10-12 14:30:59 -070025#include <delay.h>
Edward O'Callaghan91810dd2014-07-30 13:53:04 +100026#include <device/pci.h>
27#include <device/pci_ids.h>
Patrick Georgi3e77eb62012-11-22 10:39:16 +010028#include <lib/jpeg.h>
Edward O'Callaghan91810dd2014-07-30 13:53:04 +100029#include <pc80/i8259.h>
zbao741a0dd2015-06-25 16:58:53 -040030#include <pc80/i8254.h>
Edward O'Callaghan91810dd2014-07-30 13:53:04 +100031#include <string.h>
32#include <vbe.h>
33
Patrick Georgi199b09c2012-11-22 12:46:12 +010034/* we use x86emu's register file representation */
35#include <x86emu/regs.h>
Edward O'Callaghan91810dd2014-07-30 13:53:04 +100036
37#include "x86.h"
Patrick Georgi199b09c2012-11-22 12:46:12 +010038
Aaron Durbina146d582013-02-08 16:56:51 -060039/* The following symbols cannot be used directly. They need to be fixed up
40 * to point to the correct address location after the code has been copied
41 * to REALMODE_BASE. Absolute symbols are not used because those symbols are
42 * relocated when a relocatable ramstage is enabled.
43 */
44extern unsigned char __realmode_call, __realmode_interrupt;
45extern unsigned char __realmode_buffer;
46
47#define PTR_TO_REAL_MODE(sym)\
48 (void *)(REALMODE_BASE + ((char *)&(sym) - (char *)&__realmode_code))
49
Patrick Georgi199b09c2012-11-22 12:46:12 +010050/* to have a common register file for interrupt handlers */
51X86EMU_sysEnv _X86EMU_env;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000052
Stefan Reinauer841af5e2010-05-11 15:39:20 +000053void (*realmode_call)(u32 addr, u32 eax, u32 ebx, u32 ecx, u32 edx,
Aaron Durbina146d582013-02-08 16:56:51 -060054 u32 esi, u32 edi) asmlinkage;
Stefan Reinauer841af5e2010-05-11 15:39:20 +000055
Stefan Reinauer5ff7c132011-10-31 12:56:45 -070056void (*realmode_interrupt)(u32 intno, u32 eax, u32 ebx, u32 ecx, u32 edx,
Aaron Durbina146d582013-02-08 16:56:51 -060057 u32 esi, u32 edi) asmlinkage;
58
59static void setup_realmode_code(void)
60{
61 memcpy(REALMODE_BASE, &__realmode_code, __realmode_code_size);
62
63 /* Ensure the global pointers are relocated properly. */
64 realmode_call = PTR_TO_REAL_MODE(__realmode_call);
65 realmode_interrupt = PTR_TO_REAL_MODE(__realmode_interrupt);
66
67 printk(BIOS_SPEW, "Real mode stub @%p: %d bytes\n", REALMODE_BASE,
68 __realmode_code_size);
69}
Stefan Reinauer841af5e2010-05-11 15:39:20 +000070
Stefan Reinauer841af5e2010-05-11 15:39:20 +000071static void setup_rombios(void)
72{
73 const char date[] = "06/11/99";
74 memcpy((void *)0xffff5, &date, 8);
75
76 const char ident[] = "PCI_ISA";
77 memcpy((void *)0xfffd9, &ident, 7);
78
79 /* system model: IBM-AT */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080080 write8((void *)0xffffe, 0xfc);
Stefan Reinauer841af5e2010-05-11 15:39:20 +000081}
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000082
Patrick Georgi199b09c2012-11-22 12:46:12 +010083static int (*intXX_handler[256])(void) = { NULL };
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000084
Patrick Georgi199b09c2012-11-22 12:46:12 +010085static int intXX_exception_handler(void)
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000086{
Patrick Georgi199b09c2012-11-22 12:46:12 +010087 /* compatibility shim */
88 struct eregs reg_info = {
89 .eax=X86_EAX,
90 .ecx=X86_ECX,
91 .edx=X86_EDX,
92 .ebx=X86_EBX,
93 .esp=X86_ESP,
94 .ebp=X86_EBP,
95 .esi=X86_ESI,
96 .edi=X86_EDI,
97 .vector=M.x86.intno,
98 .error_code=0, // FIXME: fill in
99 .eip=X86_EIP,
100 .cs=X86_CS,
101 .eflags=X86_EFLAGS
102 };
103 struct eregs *regs = &reg_info;
104
Stefan Reinauer14e22772010-04-27 06:56:47 +0000105 printk(BIOS_INFO, "Oops, exception %d while executing option rom\n",
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000106 regs->vector);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000107 x86_exception(regs); // Call coreboot exception handler
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000108
Stefan Reinauerb6b88712011-10-12 14:35:54 -0700109 return 0; // Never really returns
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000110}
111
Patrick Georgi199b09c2012-11-22 12:46:12 +0100112static int intXX_unknown_handler(void)
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000113{
Myles Watsonf53eaa32010-09-09 14:42:58 +0000114 printk(BIOS_INFO, "Unsupported software interrupt #0x%x eax 0x%x\n",
Patrick Georgi199b09c2012-11-22 12:46:12 +0100115 M.x86.intno, X86_EAX);
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000116
117 return -1;
118}
119
Libra Lic1436932009-12-23 19:16:47 +0000120/* setup interrupt handlers for mainboard */
Aaron Durbin4d7a4c52013-04-23 10:25:34 -0500121void mainboard_interrupt_handlers(int intXX, int (*intXX_func)(void))
Libra Lic1436932009-12-23 19:16:47 +0000122{
123 intXX_handler[intXX] = intXX_func;
124}
125
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000126static void setup_interrupt_handlers(void)
127{
128 int i;
129
Stefan Reinauer14e22772010-04-27 06:56:47 +0000130 /* The first 16 intXX functions are not BIOS services,
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000131 * but the CPU-generated exceptions ("hardware interrupts")
132 */
133 for (i = 0; i < 0x10; i++)
134 intXX_handler[i] = &intXX_exception_handler;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000135
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000136 /* Mark all other intXX calls as unknown first */
137 for (i = 0x10; i < 0x100; i++)
Libra Lic1436932009-12-23 19:16:47 +0000138 {
139 /* If the mainboard_interrupt_handler isn't called first.
140 */
141 if(!intXX_handler[i])
142 {
143 /* Now set the default functions that are actually
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700144 * needed to initialize the option roms. This is
145 * very slick, as it allows us to implement mainboard
146 * specific interrupt handlers, such as the int15.
Libra Lic1436932009-12-23 19:16:47 +0000147 */
148 switch (i) {
Myles Watsonf53eaa32010-09-09 14:42:58 +0000149 case 0x10:
150 intXX_handler[0x10] = &int10_handler;
151 break;
Libra Lic1436932009-12-23 19:16:47 +0000152 case 0x12:
153 intXX_handler[0x12] = &int12_handler;
154 break;
Myles Watsonf53eaa32010-09-09 14:42:58 +0000155 case 0x16:
156 intXX_handler[0x16] = &int16_handler;
157 break;
Libra Lic1436932009-12-23 19:16:47 +0000158 case 0x1a:
159 intXX_handler[0x1a] = &int1a_handler;
160 break;
161 default:
162 intXX_handler[i] = &intXX_unknown_handler;
163 break;
164 }
165 }
166 }
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000167}
168
169static void write_idt_stub(void *target, u8 intnum)
170{
171 unsigned char *codeptr;
172 codeptr = (unsigned char *) target;
Aaron Durbina146d582013-02-08 16:56:51 -0600173 memcpy(codeptr, &__idt_handler, __idt_handler_size);
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000174 codeptr[3] = intnum; /* modify int# in the code stub. */
175}
176
177static void setup_realmode_idt(void)
178{
179 struct realmode_idt *idts = (struct realmode_idt *) 0;
180 int i;
181
182 /* Copy IDT stub code for each interrupt. This might seem wasteful
183 * but it is really simple
184 */
185 for (i = 0; i < 256; i++) {
186 idts[i].cs = 0;
Aaron Durbina146d582013-02-08 16:56:51 -0600187 idts[i].offset = 0x1000 + (i * __idt_handler_size);
Stefan Reinauer83fa1692015-06-18 22:01:07 -0700188 write_idt_stub((void *)((uintptr_t)idts[i].offset), i);
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000189 }
190
191 /* Many option ROMs use the hard coded interrupt entry points in the
Stefan Reinauer14e22772010-04-27 06:56:47 +0000192 * system bios. So install them at the known locations.
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000193 */
Stefan Reinauer14e22772010-04-27 06:56:47 +0000194
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000195 /* int42 is the relocated int10 */
Stefan Reinauer714e2a12010-04-24 23:15:23 +0000196 write_idt_stub((void *)0xff065, 0x42);
Stefan Reinauer841af5e2010-05-11 15:39:20 +0000197 /* BIOS Int 11 Handler F000:F84D */
198 write_idt_stub((void *)0xff84d, 0x11);
199 /* BIOS Int 12 Handler F000:F841 */
200 write_idt_stub((void *)0xff841, 0x12);
201 /* BIOS Int 13 Handler F000:EC59 */
202 write_idt_stub((void *)0xfec59, 0x13);
203 /* BIOS Int 14 Handler F000:E739 */
204 write_idt_stub((void *)0xfe739, 0x14);
205 /* BIOS Int 15 Handler F000:F859 */
Stefan Reinauer14e22772010-04-27 06:56:47 +0000206 write_idt_stub((void *)0xff859, 0x15);
Stefan Reinauer841af5e2010-05-11 15:39:20 +0000207 /* BIOS Int 16 Handler F000:E82E */
208 write_idt_stub((void *)0xfe82e, 0x16);
209 /* BIOS Int 17 Handler F000:EFD2 */
210 write_idt_stub((void *)0xfefd2, 0x17);
211 /* ROM BIOS Int 1A Handler F000:FE6E */
212 write_idt_stub((void *)0xffe6e, 0x1a);
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000213}
214
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700215#if CONFIG_FRAMEBUFFER_SET_VESA_MODE
Gabe Blackfb8632a2012-09-30 04:47:48 -0700216vbe_mode_info_t mode_info;
217static int mode_info_valid;
218
219int vbe_mode_info_valid(void)
220{
221 return mode_info_valid;
222}
223
224static u8 vbe_get_mode_info(vbe_mode_info_t * mi)
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700225{
Stefan Reinauer01c3de92012-08-29 09:28:52 -0700226 printk(BIOS_DEBUG, "VBE: Getting information about VESA mode %04x\n",
Gabe Blackfb8632a2012-09-30 04:47:48 -0700227 mi->video_mode);
Aaron Durbina146d582013-02-08 16:56:51 -0600228 char *buffer = PTR_TO_REAL_MODE(__realmode_buffer);
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700229 u16 buffer_seg = (((unsigned long)buffer) >> 4) & 0xff00;
230 u16 buffer_adr = ((unsigned long)buffer) & 0xffff;
231 realmode_interrupt(0x10, VESA_GET_MODE_INFO, 0x0000,
Gabe Blackfb8632a2012-09-30 04:47:48 -0700232 mi->video_mode, 0x0000, buffer_seg, buffer_adr);
Zhuo-Hao Lee29445dc2014-12-24 11:13:34 +0800233 memcpy(mi->mode_info_block, buffer, sizeof(mi->mode_info_block));
Gabe Blackfb8632a2012-09-30 04:47:48 -0700234 mode_info_valid = 1;
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700235 return 0;
236}
237
Gabe Blackfb8632a2012-09-30 04:47:48 -0700238static u8 vbe_set_mode(vbe_mode_info_t * mi)
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700239{
Gabe Blackfb8632a2012-09-30 04:47:48 -0700240 printk(BIOS_DEBUG, "VBE: Setting VESA mode %04x\n", mi->video_mode);
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700241 // request linear framebuffer mode
Gabe Blackfb8632a2012-09-30 04:47:48 -0700242 mi->video_mode |= (1 << 14);
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700243 // request clearing of framebuffer
Gabe Blackfb8632a2012-09-30 04:47:48 -0700244 mi->video_mode &= ~(1 << 15);
245 realmode_interrupt(0x10, VESA_SET_MODE, mi->video_mode,
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700246 0x0000, 0x0000, 0x0000, 0x0000);
247 return 0;
248}
249
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700250/* These two functions could probably even be generic between
251 * yabel and x86 native. TBD later.
252 */
253void vbe_set_graphics(void)
254{
255 mode_info.video_mode = (1 << 14) | CONFIG_FRAMEBUFFER_VESA_MODE;
256 vbe_get_mode_info(&mode_info);
257 unsigned char *framebuffer =
Stefan Reinauerb6b88712011-10-12 14:35:54 -0700258 (unsigned char *)mode_info.vesa.phys_base_ptr;
Stefan Reinauer01c3de92012-08-29 09:28:52 -0700259 printk(BIOS_DEBUG, "VBE: resolution: %dx%d@%d\n",
260 le16_to_cpu(mode_info.vesa.x_resolution),
261 le16_to_cpu(mode_info.vesa.y_resolution),
262 mode_info.vesa.bits_per_pixel);
263 printk(BIOS_DEBUG, "VBE: framebuffer: %p\n", framebuffer);
264 if (!framebuffer) {
265 printk(BIOS_DEBUG, "VBE: Mode does not support linear "
266 "framebuffer\n");
267 return;
268 }
269
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700270 vbe_set_mode(&mode_info);
271#if CONFIG_BOOTSPLASH
272 struct jpeg_decdata *decdata;
Aaron Durbin899d13d2015-05-15 23:39:23 -0500273 unsigned char *jpeg = cbfs_boot_map_with_leak("bootsplash.jpg",
274 CBFS_TYPE_BOOTSPLASH,
275 NULL);
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700276 if (!jpeg) {
Stefan Reinauer01c3de92012-08-29 09:28:52 -0700277 printk(BIOS_DEBUG, "VBE: No bootsplash found.\n");
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700278 return;
279 }
Daniele Forsif9ce88e2014-07-26 11:32:16 +0200280 decdata = malloc(sizeof(*decdata));
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700281 int ret = 0;
282 ret = jpeg_decode(jpeg, framebuffer, 1024, 768, 16, decdata);
283#endif
284}
285
286void vbe_textmode_console(void)
287{
288 delay(2);
289 realmode_interrupt(0x10, 0x0003, 0x0000, 0x0000,
290 0x0000, 0x0000, 0x0000);
291}
292
293void fill_lb_framebuffer(struct lb_framebuffer *framebuffer)
294{
Stefan Reinauerb6b88712011-10-12 14:35:54 -0700295 framebuffer->physical_address = mode_info.vesa.phys_base_ptr;
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700296
297 framebuffer->x_resolution = le16_to_cpu(mode_info.vesa.x_resolution);
298 framebuffer->y_resolution = le16_to_cpu(mode_info.vesa.y_resolution);
299 framebuffer->bytes_per_line =
300 le16_to_cpu(mode_info.vesa.bytes_per_scanline);
301 framebuffer->bits_per_pixel = mode_info.vesa.bits_per_pixel;
302
303 framebuffer->red_mask_pos = mode_info.vesa.red_mask_pos;
304 framebuffer->red_mask_size = mode_info.vesa.red_mask_size;
305
306 framebuffer->green_mask_pos = mode_info.vesa.green_mask_pos;
307 framebuffer->green_mask_size = mode_info.vesa.green_mask_size;
308
309 framebuffer->blue_mask_pos = mode_info.vesa.blue_mask_pos;
310 framebuffer->blue_mask_size = mode_info.vesa.blue_mask_size;
311
312 framebuffer->reserved_mask_pos = mode_info.vesa.reserved_mask_pos;
313 framebuffer->reserved_mask_size = mode_info.vesa.reserved_mask_size;
314}
Vladimir Serbinenkod7374512015-10-10 13:50:30 +0200315
316#else
317
318int vbe_mode_info_valid(void)
319{
320 return 0;
321}
322
323void fill_lb_framebuffer(struct lb_framebuffer *framebuffer)
324{
325}
326
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700327#endif
328
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000329void run_bios(struct device *dev, unsigned long addr)
330{
Stefan Reinauer841af5e2010-05-11 15:39:20 +0000331 u32 num_dev = (dev->bus->secondary << 8) | dev->path.pci.devfn;
332
Stefan Reinauerb6b88712011-10-12 14:35:54 -0700333 /* Setting up required hardware.
334 * Removing this will cause random illegal instruction exceptions
335 * in some option roms.
336 */
337 setup_i8259();
zbao741a0dd2015-06-25 16:58:53 -0400338 setup_i8254();
Stefan Reinauerb6b88712011-10-12 14:35:54 -0700339
Stefan Reinauer841af5e2010-05-11 15:39:20 +0000340 /* Set up some legacy information in the F segment */
341 setup_rombios();
Libra Lic1436932009-12-23 19:16:47 +0000342
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000343 /* Set up C interrupt handlers */
344 setup_interrupt_handlers();
345
Stefan Reinauer841af5e2010-05-11 15:39:20 +0000346 /* Set up real-mode IDT */
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000347 setup_realmode_idt();
348
Aaron Durbina146d582013-02-08 16:56:51 -0600349 /* Make sure the code is placed. */
350 setup_realmode_code();
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000351
352 printk(BIOS_DEBUG, "Calling Option ROM...\n");
Stefan Reinauer841af5e2010-05-11 15:39:20 +0000353 /* TODO ES:DI Pointer to System BIOS PnP Installation Check Structure */
354 /* Option ROM entry point is at OPROM start + 3 */
355 realmode_call(addr + 0x0003, num_dev, 0xffff, 0x0000, 0xffff, 0x0, 0x0);
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000356 printk(BIOS_DEBUG, "... Option ROM returned.\n");
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700357
358#if CONFIG_FRAMEBUFFER_SET_VESA_MODE
Stefan Reinauer22ae2b92013-02-08 08:48:20 -0800359 if ((dev->class >> 8)== PCI_CLASS_DISPLAY_VGA)
360 vbe_set_graphics();
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700361#endif
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000362}
363
Stefan Reinauerd4814bd2011-04-21 20:45:45 +0000364#if CONFIG_GEODE_VSA
Stefan Reinauer9839cbd2010-04-21 20:06:10 +0000365
366#define VSA2_BUFFER 0x60000
367#define VSA2_ENTRY_POINT 0x60020
368
369// TODO move to a header file.
370void do_vsmbios(void);
371
372/* VSA virtual register helper */
373static u32 VSA_vrRead(u16 classIndex)
374{
375 u32 eax, ebx, ecx, edx;
376 asm volatile (
377 "movw $0x0AC1C, %%dx\n"
378 "orl $0x0FC530000, %%eax\n"
379 "outl %%eax, %%dx\n"
380 "addb $2, %%dl\n"
381 "inw %%dx, %%ax\n"
Stefan Reinauer14e22772010-04-27 06:56:47 +0000382 : "=a" (eax), "=b"(ebx), "=c"(ecx), "=d"(edx)
Stefan Reinauer9839cbd2010-04-21 20:06:10 +0000383 : "a"(classIndex)
384 );
385
386 return eax;
387}
388
389void do_vsmbios(void)
390{
391 printk(BIOS_DEBUG, "Preparing for VSA...\n");
392
Stefan Reinauer9839cbd2010-04-21 20:06:10 +0000393 /* Set up C interrupt handlers */
394 setup_interrupt_handlers();
395
396 /* Setting up realmode IDT */
397 setup_realmode_idt();
398
Aaron Durbina146d582013-02-08 16:56:51 -0600399 /* Make sure the code is placed. */
400 setup_realmode_code();
Stefan Reinauer9839cbd2010-04-21 20:06:10 +0000401
Aaron Durbin899d13d2015-05-15 23:39:23 -0500402 if ((uintptr_t)cbfs_boot_load_stage_by_name("vsa") !=
Hung-Te Lin6fe0cab2013-01-22 18:57:56 +0800403 VSA2_ENTRY_POINT) {
Stefan Reinauer9839cbd2010-04-21 20:06:10 +0000404 printk(BIOS_ERR, "Failed to load VSA.\n");
405 return;
406 }
407
408 unsigned char *buf = (unsigned char *)VSA2_BUFFER;
409 printk(BIOS_DEBUG, "VSA: Buffer @%p *[0k]=%02x\n", buf, buf[0]);
410 printk(BIOS_DEBUG, "VSA: Signature *[0x20-0x23] is %02x:%02x:%02x:%02x\n",
411 buf[0x20], buf[0x21], buf[0x22], buf[0x23]);
412
413 /* Check for code to emit POST code at start of VSA. */
414 if ((buf[0x20] != 0xb0) || (buf[0x21] != 0x10) ||
415 (buf[0x22] != 0xe6) || (buf[0x23] != 0x80)) {
416 printk(BIOS_WARNING, "VSA: Signature incorrect. Install failed.\n");
417 return;
418 }
419
420 printk(BIOS_DEBUG, "Calling VSA module...\n");
Stefan Reinauer841af5e2010-05-11 15:39:20 +0000421
Stefan Reinauer9839cbd2010-04-21 20:06:10 +0000422 /* ECX gets SMM, EDX gets SYSMEM */
Stefan Reinauer5ff7c132011-10-31 12:56:45 -0700423 realmode_call(VSA2_ENTRY_POINT, 0x0, 0x0, MSR_GLIU0_SMM,
Stefan Reinauer841af5e2010-05-11 15:39:20 +0000424 MSR_GLIU0_SYSMEM, 0x0, 0x0);
425
Stefan Reinauer9839cbd2010-04-21 20:06:10 +0000426 printk(BIOS_DEBUG, "... VSA module returned.\n");
427
428 /* Restart timer 1 */
429 outb(0x56, 0x43);
430 outb(0x12, 0x41);
431
432 /* Check that VSA is running OK */
433 if (VSA_vrRead(SIGNATURE) == VSA2_SIGNATURE)
434 printk(BIOS_DEBUG, "VSM: VSA2 VR signature verified.\n");
435 else
436 printk(BIOS_ERR, "VSM: VSA2 VR signature not valid. Install failed.\n");
437}
438#endif
439
Stefan Reinauer14e22772010-04-27 06:56:47 +0000440/* interrupt_handler() is called from assembler code only,
Stefan Reinauer9839cbd2010-04-21 20:06:10 +0000441 * so there is no use in putting the prototype into a header file.
442 */
Stefan Reinauer399486e2012-12-06 13:54:29 -0800443int asmlinkage interrupt_handler(u32 intnumber,
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000444 u32 gsfs, u32 dses,
445 u32 edi, u32 esi,
446 u32 ebp, u32 esp,
447 u32 ebx, u32 edx,
448 u32 ecx, u32 eax,
Uwe Hermann312673c2009-10-27 21:49:33 +0000449 u32 cs_ip, u16 stackflags);
450
Stefan Reinauer399486e2012-12-06 13:54:29 -0800451int asmlinkage interrupt_handler(u32 intnumber,
Uwe Hermann312673c2009-10-27 21:49:33 +0000452 u32 gsfs, u32 dses,
453 u32 edi, u32 esi,
454 u32 ebp, u32 esp,
455 u32 ebx, u32 edx,
456 u32 ecx, u32 eax,
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000457 u32 cs_ip, u16 stackflags)
458{
459 u32 ip;
460 u32 cs;
461 u32 flags;
Patrick Georgi503af722012-11-22 10:48:18 +0100462 int ret = 0;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000463
464 ip = cs_ip & 0xffff;
465 cs = cs_ip >> 16;
466 flags = stackflags;
467
Myles Watson6c9bc012010-09-07 22:30:15 +0000468#if CONFIG_REALMODE_DEBUG
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000469 printk(BIOS_DEBUG, "oprom: INT# 0x%x\n", intnumber);
470 printk(BIOS_DEBUG, "oprom: eax: %08x ebx: %08x ecx: %08x edx: %08x\n",
471 eax, ebx, ecx, edx);
472 printk(BIOS_DEBUG, "oprom: ebp: %08x esp: %08x edi: %08x esi: %08x\n",
473 ebp, esp, edi, esi);
474 printk(BIOS_DEBUG, "oprom: ip: %04x cs: %04x flags: %08x\n",
475 ip, cs, flags);
Myles Watson6c9bc012010-09-07 22:30:15 +0000476#endif
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000477
Patrick Georgi199b09c2012-11-22 12:46:12 +0100478 // Fetch arguments from the stack and put them to a place
479 // suitable for the interrupt handlers
480 X86_EAX = eax;
481 X86_ECX = ecx;
482 X86_EDX = edx;
483 X86_EBX = ebx;
484 X86_ESP = esp;
485 X86_EBP = ebp;
486 X86_ESI = esi;
487 X86_EDI = edi;
488 M.x86.intno = intnumber;
489 /* TODO: error_code must be stored somewhere */
490 X86_EIP = ip;
491 X86_CS = cs;
492 X86_EFLAGS = flags;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000493
494 // Call the interrupt handler for this int#
Patrick Georgi199b09c2012-11-22 12:46:12 +0100495 ret = intXX_handler[intnumber]();
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000496
497 // Put registers back on the stack. The assembler code
498 // will later pop them.
499 // What happens here is that we force (volatile!) changing
500 // the values of the parameters of this function. We do this
Stefan Reinauer14e22772010-04-27 06:56:47 +0000501 // because we know that they stay alive on the stack after
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000502 // we leave this function. Don't say this is bollocks.
Patrick Georgi199b09c2012-11-22 12:46:12 +0100503 *(volatile u32 *)&eax = X86_EAX;
504 *(volatile u32 *)&ecx = X86_ECX;
505 *(volatile u32 *)&edx = X86_EDX;
506 *(volatile u32 *)&ebx = X86_EBX;
507 *(volatile u32 *)&esi = X86_ESI;
508 *(volatile u32 *)&edi = X86_EDI;
509 flags = X86_EFLAGS;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000510
Patrick Georgi503af722012-11-22 10:48:18 +0100511 /* Pass success or error back to our caller via the CARRY flag */
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000512 if (ret) {
Patrick Georgi503af722012-11-22 10:48:18 +0100513 flags &= ~1; // no error: clear carry
514 }else{
Stefan Reinauerf75b19a2010-04-22 18:15:32 +0000515 printk(BIOS_DEBUG,"int%02x call returned error.\n", intnumber);
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000516 flags |= 1; // error: set carry
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000517 }
518 *(volatile u16 *)&stackflags = flags;
519
Patrick Georgi503af722012-11-22 10:48:18 +0100520 /* The assembler code doesn't actually care for the return value,
521 * but keep it around so its expectations are met */
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000522 return ret;
523}