blob: 5fd11b59a52c6b7364e731daec8892486205a0a8 [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.
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 Reinauer6c641ee2009-09-23 21:52:45 +000018 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000019 */
20
21#include <device/pci.h>
22#include <string.h>
23
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000024#include <arch/io.h>
Stefan Reinauer42dc7212009-10-24 00:47:07 +000025#include <arch/registers.h>
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000026#include <console/console.h>
Libra Lic1436932009-12-23 19:16:47 +000027#include <arch/interrupt.h>
Stefan Reinauerc1efb902011-10-12 14:30:59 -070028#include <cbfs.h>
29#include <delay.h>
Stefan Reinauerb6b88712011-10-12 14:35:54 -070030#include <pc80/i8259.h>
Stefan Reinauer216fa462011-10-12 14:25:07 -070031#include "x86.h"
Stefan Reinauerc1efb902011-10-12 14:30:59 -070032#include "vbe.h"
Patrick Georgi3e77eb62012-11-22 10:39:16 +010033#include <lib/jpeg.h>
Patrick Georgi199b09c2012-11-22 12:46:12 +010034/* we use x86emu's register file representation */
35#include <x86emu/regs.h>
Stefan Reinauer69e432e2013-02-07 18:19:23 -080036#include <boot/coreboot_tables.h>
Stefan Reinauer22ae2b92013-02-08 08:48:20 -080037#include <device/pci_ids.h>
Patrick Georgi199b09c2012-11-22 12:46:12 +010038
39/* to have a common register file for interrupt handlers */
40X86EMU_sysEnv _X86EMU_env;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000041
Stefan Reinauer841af5e2010-05-11 15:39:20 +000042void (*realmode_call)(u32 addr, u32 eax, u32 ebx, u32 ecx, u32 edx,
Stefan Reinauer399486e2012-12-06 13:54:29 -080043 u32 esi, u32 edi) asmlinkage =
Stefan Reinauerc1efb902011-10-12 14:30:59 -070044 (void *)&__realmode_call;
Stefan Reinauer841af5e2010-05-11 15:39:20 +000045
Stefan Reinauer5ff7c132011-10-31 12:56:45 -070046void (*realmode_interrupt)(u32 intno, u32 eax, u32 ebx, u32 ecx, u32 edx,
Stefan Reinauer399486e2012-12-06 13:54:29 -080047 u32 esi, u32 edi) asmlinkage =
Stefan Reinauerc1efb902011-10-12 14:30:59 -070048 (void *)&__realmode_interrupt;
Stefan Reinauer841af5e2010-05-11 15:39:20 +000049
Stefan Reinauer841af5e2010-05-11 15:39:20 +000050static void setup_rombios(void)
51{
52 const char date[] = "06/11/99";
53 memcpy((void *)0xffff5, &date, 8);
54
55 const char ident[] = "PCI_ISA";
56 memcpy((void *)0xfffd9, &ident, 7);
57
58 /* system model: IBM-AT */
59 write8(0xffffe, 0xfc);
60}
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000061
Patrick Georgi199b09c2012-11-22 12:46:12 +010062static int (*intXX_handler[256])(void) = { NULL };
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000063
Patrick Georgi199b09c2012-11-22 12:46:12 +010064static int intXX_exception_handler(void)
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000065{
Patrick Georgi199b09c2012-11-22 12:46:12 +010066 /* compatibility shim */
67 struct eregs reg_info = {
68 .eax=X86_EAX,
69 .ecx=X86_ECX,
70 .edx=X86_EDX,
71 .ebx=X86_EBX,
72 .esp=X86_ESP,
73 .ebp=X86_EBP,
74 .esi=X86_ESI,
75 .edi=X86_EDI,
76 .vector=M.x86.intno,
77 .error_code=0, // FIXME: fill in
78 .eip=X86_EIP,
79 .cs=X86_CS,
80 .eflags=X86_EFLAGS
81 };
82 struct eregs *regs = &reg_info;
83
Stefan Reinauer14e22772010-04-27 06:56:47 +000084 printk(BIOS_INFO, "Oops, exception %d while executing option rom\n",
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000085 regs->vector);
Stefan Reinauer14e22772010-04-27 06:56:47 +000086 x86_exception(regs); // Call coreboot exception handler
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000087
Stefan Reinauerb6b88712011-10-12 14:35:54 -070088 return 0; // Never really returns
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000089}
90
Patrick Georgi199b09c2012-11-22 12:46:12 +010091static int intXX_unknown_handler(void)
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000092{
Myles Watsonf53eaa32010-09-09 14:42:58 +000093 printk(BIOS_INFO, "Unsupported software interrupt #0x%x eax 0x%x\n",
Patrick Georgi199b09c2012-11-22 12:46:12 +010094 M.x86.intno, X86_EAX);
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000095
96 return -1;
97}
98
Libra Lic1436932009-12-23 19:16:47 +000099/* setup interrupt handlers for mainboard */
100void mainboard_interrupt_handlers(int intXX, void *intXX_func)
101{
102 intXX_handler[intXX] = intXX_func;
103}
104
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000105static void setup_interrupt_handlers(void)
106{
107 int i;
108
Stefan Reinauer14e22772010-04-27 06:56:47 +0000109 /* The first 16 intXX functions are not BIOS services,
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000110 * but the CPU-generated exceptions ("hardware interrupts")
111 */
112 for (i = 0; i < 0x10; i++)
113 intXX_handler[i] = &intXX_exception_handler;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000114
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000115 /* Mark all other intXX calls as unknown first */
116 for (i = 0x10; i < 0x100; i++)
Libra Lic1436932009-12-23 19:16:47 +0000117 {
118 /* If the mainboard_interrupt_handler isn't called first.
119 */
120 if(!intXX_handler[i])
121 {
122 /* Now set the default functions that are actually
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700123 * needed to initialize the option roms. This is
124 * very slick, as it allows us to implement mainboard
125 * specific interrupt handlers, such as the int15.
Libra Lic1436932009-12-23 19:16:47 +0000126 */
127 switch (i) {
Myles Watsonf53eaa32010-09-09 14:42:58 +0000128 case 0x10:
129 intXX_handler[0x10] = &int10_handler;
130 break;
Libra Lic1436932009-12-23 19:16:47 +0000131 case 0x12:
132 intXX_handler[0x12] = &int12_handler;
133 break;
Myles Watsonf53eaa32010-09-09 14:42:58 +0000134 case 0x16:
135 intXX_handler[0x16] = &int16_handler;
136 break;
Libra Lic1436932009-12-23 19:16:47 +0000137 case 0x1a:
138 intXX_handler[0x1a] = &int1a_handler;
139 break;
140 default:
141 intXX_handler[i] = &intXX_unknown_handler;
142 break;
143 }
144 }
145 }
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000146}
147
148static void write_idt_stub(void *target, u8 intnum)
149{
150 unsigned char *codeptr;
151 codeptr = (unsigned char *) target;
152 memcpy(codeptr, &__idt_handler, (size_t)&__idt_handler_size);
153 codeptr[3] = intnum; /* modify int# in the code stub. */
154}
155
156static void setup_realmode_idt(void)
157{
158 struct realmode_idt *idts = (struct realmode_idt *) 0;
159 int i;
160
161 /* Copy IDT stub code for each interrupt. This might seem wasteful
162 * but it is really simple
163 */
164 for (i = 0; i < 256; i++) {
165 idts[i].cs = 0;
166 idts[i].offset = 0x1000 + (i * (u32)&__idt_handler_size);
167 write_idt_stub((void *)((u32 )idts[i].offset), i);
168 }
169
170 /* Many option ROMs use the hard coded interrupt entry points in the
Stefan Reinauer14e22772010-04-27 06:56:47 +0000171 * system bios. So install them at the known locations.
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000172 */
Stefan Reinauer14e22772010-04-27 06:56:47 +0000173
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000174 /* int42 is the relocated int10 */
Stefan Reinauer714e2a12010-04-24 23:15:23 +0000175 write_idt_stub((void *)0xff065, 0x42);
Stefan Reinauer841af5e2010-05-11 15:39:20 +0000176 /* BIOS Int 11 Handler F000:F84D */
177 write_idt_stub((void *)0xff84d, 0x11);
178 /* BIOS Int 12 Handler F000:F841 */
179 write_idt_stub((void *)0xff841, 0x12);
180 /* BIOS Int 13 Handler F000:EC59 */
181 write_idt_stub((void *)0xfec59, 0x13);
182 /* BIOS Int 14 Handler F000:E739 */
183 write_idt_stub((void *)0xfe739, 0x14);
184 /* BIOS Int 15 Handler F000:F859 */
Stefan Reinauer14e22772010-04-27 06:56:47 +0000185 write_idt_stub((void *)0xff859, 0x15);
Stefan Reinauer841af5e2010-05-11 15:39:20 +0000186 /* BIOS Int 16 Handler F000:E82E */
187 write_idt_stub((void *)0xfe82e, 0x16);
188 /* BIOS Int 17 Handler F000:EFD2 */
189 write_idt_stub((void *)0xfefd2, 0x17);
190 /* ROM BIOS Int 1A Handler F000:FE6E */
191 write_idt_stub((void *)0xffe6e, 0x1a);
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000192}
193
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700194#if CONFIG_FRAMEBUFFER_SET_VESA_MODE
Gabe Blackfb8632a2012-09-30 04:47:48 -0700195vbe_mode_info_t mode_info;
196static int mode_info_valid;
197
198int vbe_mode_info_valid(void)
199{
200 return mode_info_valid;
201}
202
203static u8 vbe_get_mode_info(vbe_mode_info_t * mi)
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700204{
Stefan Reinauer01c3de92012-08-29 09:28:52 -0700205 printk(BIOS_DEBUG, "VBE: Getting information about VESA mode %04x\n",
Gabe Blackfb8632a2012-09-30 04:47:48 -0700206 mi->video_mode);
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700207 char *buffer = (char *)&__buffer;
208 u16 buffer_seg = (((unsigned long)buffer) >> 4) & 0xff00;
209 u16 buffer_adr = ((unsigned long)buffer) & 0xffff;
210 realmode_interrupt(0x10, VESA_GET_MODE_INFO, 0x0000,
Gabe Blackfb8632a2012-09-30 04:47:48 -0700211 mi->video_mode, 0x0000, buffer_seg, buffer_adr);
212 memcpy(mi->mode_info_block, buffer, sizeof(vbe_mode_info_t));
213 mode_info_valid = 1;
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700214 return 0;
215}
216
Gabe Blackfb8632a2012-09-30 04:47:48 -0700217static u8 vbe_set_mode(vbe_mode_info_t * mi)
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700218{
Gabe Blackfb8632a2012-09-30 04:47:48 -0700219 printk(BIOS_DEBUG, "VBE: Setting VESA mode %04x\n", mi->video_mode);
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700220 // request linear framebuffer mode
Gabe Blackfb8632a2012-09-30 04:47:48 -0700221 mi->video_mode |= (1 << 14);
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700222 // request clearing of framebuffer
Gabe Blackfb8632a2012-09-30 04:47:48 -0700223 mi->video_mode &= ~(1 << 15);
224 realmode_interrupt(0x10, VESA_SET_MODE, mi->video_mode,
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700225 0x0000, 0x0000, 0x0000, 0x0000);
226 return 0;
227}
228
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700229/* These two functions could probably even be generic between
230 * yabel and x86 native. TBD later.
231 */
232void vbe_set_graphics(void)
233{
234 mode_info.video_mode = (1 << 14) | CONFIG_FRAMEBUFFER_VESA_MODE;
235 vbe_get_mode_info(&mode_info);
236 unsigned char *framebuffer =
Stefan Reinauerb6b88712011-10-12 14:35:54 -0700237 (unsigned char *)mode_info.vesa.phys_base_ptr;
Stefan Reinauer01c3de92012-08-29 09:28:52 -0700238 printk(BIOS_DEBUG, "VBE: resolution: %dx%d@%d\n",
239 le16_to_cpu(mode_info.vesa.x_resolution),
240 le16_to_cpu(mode_info.vesa.y_resolution),
241 mode_info.vesa.bits_per_pixel);
242 printk(BIOS_DEBUG, "VBE: framebuffer: %p\n", framebuffer);
243 if (!framebuffer) {
244 printk(BIOS_DEBUG, "VBE: Mode does not support linear "
245 "framebuffer\n");
246 return;
247 }
248
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700249 vbe_set_mode(&mode_info);
250#if CONFIG_BOOTSPLASH
251 struct jpeg_decdata *decdata;
252 decdata = malloc(sizeof(*decdata));
Hung-Te Lin6fe0cab2013-01-22 18:57:56 +0800253 unsigned char *jpeg = cbfs_get_file_content(CBFS_DEFAULT_MEDIA,
254 "bootsplash.jpg",
255 CBFS_TYPE_BOOTSPLASH);
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700256 if (!jpeg) {
Stefan Reinauer01c3de92012-08-29 09:28:52 -0700257 printk(BIOS_DEBUG, "VBE: No bootsplash found.\n");
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700258 return;
259 }
260 int ret = 0;
261 ret = jpeg_decode(jpeg, framebuffer, 1024, 768, 16, decdata);
262#endif
263}
264
265void vbe_textmode_console(void)
266{
267 delay(2);
268 realmode_interrupt(0x10, 0x0003, 0x0000, 0x0000,
269 0x0000, 0x0000, 0x0000);
270}
271
272void fill_lb_framebuffer(struct lb_framebuffer *framebuffer)
273{
Stefan Reinauerb6b88712011-10-12 14:35:54 -0700274 framebuffer->physical_address = mode_info.vesa.phys_base_ptr;
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700275
276 framebuffer->x_resolution = le16_to_cpu(mode_info.vesa.x_resolution);
277 framebuffer->y_resolution = le16_to_cpu(mode_info.vesa.y_resolution);
278 framebuffer->bytes_per_line =
279 le16_to_cpu(mode_info.vesa.bytes_per_scanline);
280 framebuffer->bits_per_pixel = mode_info.vesa.bits_per_pixel;
281
282 framebuffer->red_mask_pos = mode_info.vesa.red_mask_pos;
283 framebuffer->red_mask_size = mode_info.vesa.red_mask_size;
284
285 framebuffer->green_mask_pos = mode_info.vesa.green_mask_pos;
286 framebuffer->green_mask_size = mode_info.vesa.green_mask_size;
287
288 framebuffer->blue_mask_pos = mode_info.vesa.blue_mask_pos;
289 framebuffer->blue_mask_size = mode_info.vesa.blue_mask_size;
290
291 framebuffer->reserved_mask_pos = mode_info.vesa.reserved_mask_pos;
292 framebuffer->reserved_mask_size = mode_info.vesa.reserved_mask_size;
293}
294#endif
295
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000296void run_bios(struct device *dev, unsigned long addr)
297{
Stefan Reinauer841af5e2010-05-11 15:39:20 +0000298 u32 num_dev = (dev->bus->secondary << 8) | dev->path.pci.devfn;
299
Stefan Reinauerb6b88712011-10-12 14:35:54 -0700300 /* Setting up required hardware.
301 * Removing this will cause random illegal instruction exceptions
302 * in some option roms.
303 */
304 setup_i8259();
305
Stefan Reinauer841af5e2010-05-11 15:39:20 +0000306 /* Set up some legacy information in the F segment */
307 setup_rombios();
Libra Lic1436932009-12-23 19:16:47 +0000308
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000309 /* Set up C interrupt handlers */
310 setup_interrupt_handlers();
311
Stefan Reinauer841af5e2010-05-11 15:39:20 +0000312 /* Set up real-mode IDT */
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000313 setup_realmode_idt();
314
315 memcpy(REALMODE_BASE, &__realmode_code, (size_t)&__realmode_code_size);
316 printk(BIOS_SPEW, "Real mode stub @%p: %d bytes\n", REALMODE_BASE,
317 (u32)&__realmode_code_size);
318
319 printk(BIOS_DEBUG, "Calling Option ROM...\n");
Stefan Reinauer841af5e2010-05-11 15:39:20 +0000320 /* TODO ES:DI Pointer to System BIOS PnP Installation Check Structure */
321 /* Option ROM entry point is at OPROM start + 3 */
322 realmode_call(addr + 0x0003, num_dev, 0xffff, 0x0000, 0xffff, 0x0, 0x0);
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000323 printk(BIOS_DEBUG, "... Option ROM returned.\n");
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700324
325#if CONFIG_FRAMEBUFFER_SET_VESA_MODE
Stefan Reinauer22ae2b92013-02-08 08:48:20 -0800326 if ((dev->class >> 8)== PCI_CLASS_DISPLAY_VGA)
327 vbe_set_graphics();
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700328#endif
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000329}
330
Stefan Reinauerd4814bd2011-04-21 20:45:45 +0000331#if CONFIG_GEODE_VSA
Stefan Reinauer9839cbd2010-04-21 20:06:10 +0000332#include <cpu/amd/lxdef.h>
333#include <cpu/amd/vr.h>
334#include <cbfs.h>
335
336#define VSA2_BUFFER 0x60000
337#define VSA2_ENTRY_POINT 0x60020
338
339// TODO move to a header file.
340void do_vsmbios(void);
341
342/* VSA virtual register helper */
343static u32 VSA_vrRead(u16 classIndex)
344{
345 u32 eax, ebx, ecx, edx;
346 asm volatile (
347 "movw $0x0AC1C, %%dx\n"
348 "orl $0x0FC530000, %%eax\n"
349 "outl %%eax, %%dx\n"
350 "addb $2, %%dl\n"
351 "inw %%dx, %%ax\n"
Stefan Reinauer14e22772010-04-27 06:56:47 +0000352 : "=a" (eax), "=b"(ebx), "=c"(ecx), "=d"(edx)
Stefan Reinauer9839cbd2010-04-21 20:06:10 +0000353 : "a"(classIndex)
354 );
355
356 return eax;
357}
358
359void do_vsmbios(void)
360{
361 printk(BIOS_DEBUG, "Preparing for VSA...\n");
362
Stefan Reinauer9839cbd2010-04-21 20:06:10 +0000363 /* Set up C interrupt handlers */
364 setup_interrupt_handlers();
365
366 /* Setting up realmode IDT */
367 setup_realmode_idt();
368
369 memcpy(REALMODE_BASE, &__realmode_code, (size_t)&__realmode_code_size);
370 printk(BIOS_SPEW, "VSA: Real mode stub @%p: %d bytes\n", REALMODE_BASE,
371 (u32)&__realmode_code_size);
372
Hung-Te Lin6fe0cab2013-01-22 18:57:56 +0800373 if ((unsigned int)cbfs_load_stage(CBFS_DEFAULT_MEDIA, "vsa") !=
374 VSA2_ENTRY_POINT) {
Stefan Reinauer9839cbd2010-04-21 20:06:10 +0000375 printk(BIOS_ERR, "Failed to load VSA.\n");
376 return;
377 }
378
379 unsigned char *buf = (unsigned char *)VSA2_BUFFER;
380 printk(BIOS_DEBUG, "VSA: Buffer @%p *[0k]=%02x\n", buf, buf[0]);
381 printk(BIOS_DEBUG, "VSA: Signature *[0x20-0x23] is %02x:%02x:%02x:%02x\n",
382 buf[0x20], buf[0x21], buf[0x22], buf[0x23]);
383
384 /* Check for code to emit POST code at start of VSA. */
385 if ((buf[0x20] != 0xb0) || (buf[0x21] != 0x10) ||
386 (buf[0x22] != 0xe6) || (buf[0x23] != 0x80)) {
387 printk(BIOS_WARNING, "VSA: Signature incorrect. Install failed.\n");
388 return;
389 }
390
391 printk(BIOS_DEBUG, "Calling VSA module...\n");
Stefan Reinauer841af5e2010-05-11 15:39:20 +0000392
Stefan Reinauer9839cbd2010-04-21 20:06:10 +0000393 /* ECX gets SMM, EDX gets SYSMEM */
Stefan Reinauer5ff7c132011-10-31 12:56:45 -0700394 realmode_call(VSA2_ENTRY_POINT, 0x0, 0x0, MSR_GLIU0_SMM,
Stefan Reinauer841af5e2010-05-11 15:39:20 +0000395 MSR_GLIU0_SYSMEM, 0x0, 0x0);
396
Stefan Reinauer9839cbd2010-04-21 20:06:10 +0000397 printk(BIOS_DEBUG, "... VSA module returned.\n");
398
399 /* Restart timer 1 */
400 outb(0x56, 0x43);
401 outb(0x12, 0x41);
402
403 /* Check that VSA is running OK */
404 if (VSA_vrRead(SIGNATURE) == VSA2_SIGNATURE)
405 printk(BIOS_DEBUG, "VSM: VSA2 VR signature verified.\n");
406 else
407 printk(BIOS_ERR, "VSM: VSA2 VR signature not valid. Install failed.\n");
408}
409#endif
410
Stefan Reinauer14e22772010-04-27 06:56:47 +0000411/* interrupt_handler() is called from assembler code only,
Stefan Reinauer9839cbd2010-04-21 20:06:10 +0000412 * so there is no use in putting the prototype into a header file.
413 */
Stefan Reinauer399486e2012-12-06 13:54:29 -0800414int asmlinkage interrupt_handler(u32 intnumber,
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000415 u32 gsfs, u32 dses,
416 u32 edi, u32 esi,
417 u32 ebp, u32 esp,
418 u32 ebx, u32 edx,
419 u32 ecx, u32 eax,
Uwe Hermann312673c2009-10-27 21:49:33 +0000420 u32 cs_ip, u16 stackflags);
421
Stefan Reinauer399486e2012-12-06 13:54:29 -0800422int asmlinkage interrupt_handler(u32 intnumber,
Uwe Hermann312673c2009-10-27 21:49:33 +0000423 u32 gsfs, u32 dses,
424 u32 edi, u32 esi,
425 u32 ebp, u32 esp,
426 u32 ebx, u32 edx,
427 u32 ecx, u32 eax,
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000428 u32 cs_ip, u16 stackflags)
429{
430 u32 ip;
431 u32 cs;
432 u32 flags;
Patrick Georgi503af722012-11-22 10:48:18 +0100433 int ret = 0;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000434
435 ip = cs_ip & 0xffff;
436 cs = cs_ip >> 16;
437 flags = stackflags;
438
Myles Watson6c9bc012010-09-07 22:30:15 +0000439#if CONFIG_REALMODE_DEBUG
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000440 printk(BIOS_DEBUG, "oprom: INT# 0x%x\n", intnumber);
441 printk(BIOS_DEBUG, "oprom: eax: %08x ebx: %08x ecx: %08x edx: %08x\n",
442 eax, ebx, ecx, edx);
443 printk(BIOS_DEBUG, "oprom: ebp: %08x esp: %08x edi: %08x esi: %08x\n",
444 ebp, esp, edi, esi);
445 printk(BIOS_DEBUG, "oprom: ip: %04x cs: %04x flags: %08x\n",
446 ip, cs, flags);
Myles Watson6c9bc012010-09-07 22:30:15 +0000447#endif
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000448
Patrick Georgi199b09c2012-11-22 12:46:12 +0100449 // Fetch arguments from the stack and put them to a place
450 // suitable for the interrupt handlers
451 X86_EAX = eax;
452 X86_ECX = ecx;
453 X86_EDX = edx;
454 X86_EBX = ebx;
455 X86_ESP = esp;
456 X86_EBP = ebp;
457 X86_ESI = esi;
458 X86_EDI = edi;
459 M.x86.intno = intnumber;
460 /* TODO: error_code must be stored somewhere */
461 X86_EIP = ip;
462 X86_CS = cs;
463 X86_EFLAGS = flags;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000464
465 // Call the interrupt handler for this int#
Patrick Georgi199b09c2012-11-22 12:46:12 +0100466 ret = intXX_handler[intnumber]();
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000467
468 // Put registers back on the stack. The assembler code
469 // will later pop them.
470 // What happens here is that we force (volatile!) changing
471 // the values of the parameters of this function. We do this
Stefan Reinauer14e22772010-04-27 06:56:47 +0000472 // because we know that they stay alive on the stack after
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000473 // we leave this function. Don't say this is bollocks.
Patrick Georgi199b09c2012-11-22 12:46:12 +0100474 *(volatile u32 *)&eax = X86_EAX;
475 *(volatile u32 *)&ecx = X86_ECX;
476 *(volatile u32 *)&edx = X86_EDX;
477 *(volatile u32 *)&ebx = X86_EBX;
478 *(volatile u32 *)&esi = X86_ESI;
479 *(volatile u32 *)&edi = X86_EDI;
480 flags = X86_EFLAGS;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000481
Patrick Georgi503af722012-11-22 10:48:18 +0100482 /* Pass success or error back to our caller via the CARRY flag */
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000483 if (ret) {
Patrick Georgi503af722012-11-22 10:48:18 +0100484 flags &= ~1; // no error: clear carry
485 }else{
Stefan Reinauerf75b19a2010-04-22 18:15:32 +0000486 printk(BIOS_DEBUG,"int%02x call returned error.\n", intnumber);
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000487 flags |= 1; // error: set carry
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000488 }
489 *(volatile u16 *)&stackflags = flags;
490
Patrick Georgi503af722012-11-22 10:48:18 +0100491 /* The assembler code doesn't actually care for the return value,
492 * but keep it around so its expectations are met */
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000493 return ret;
494}
495