blob: 1791a87f141c15d2c37f2e15de305167fbcef85c [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"
33#include "../../src/lib/jpeg.h"
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000034
Stefan Reinauer841af5e2010-05-11 15:39:20 +000035void (*realmode_call)(u32 addr, u32 eax, u32 ebx, u32 ecx, u32 edx,
Stefan Reinauerc1efb902011-10-12 14:30:59 -070036 u32 esi, u32 edi) __attribute__((regparm(0))) =
37 (void *)&__realmode_call;
Stefan Reinauer841af5e2010-05-11 15:39:20 +000038
Stefan Reinauer5ff7c132011-10-31 12:56:45 -070039void (*realmode_interrupt)(u32 intno, u32 eax, u32 ebx, u32 ecx, u32 edx,
Stefan Reinauerc1efb902011-10-12 14:30:59 -070040 u32 esi, u32 edi) __attribute__((regparm(0))) =
41 (void *)&__realmode_interrupt;
Stefan Reinauer841af5e2010-05-11 15:39:20 +000042
Stefan Reinauer841af5e2010-05-11 15:39:20 +000043static void setup_rombios(void)
44{
45 const char date[] = "06/11/99";
46 memcpy((void *)0xffff5, &date, 8);
47
48 const char ident[] = "PCI_ISA";
49 memcpy((void *)0xfffd9, &ident, 7);
50
51 /* system model: IBM-AT */
52 write8(0xffffe, 0xfc);
53}
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000054
55int (*intXX_handler[256])(struct eregs *regs) = { NULL };
56
57static int intXX_exception_handler(struct eregs *regs)
58{
Stefan Reinauer14e22772010-04-27 06:56:47 +000059 printk(BIOS_INFO, "Oops, exception %d while executing option rom\n",
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000060 regs->vector);
Stefan Reinauer14e22772010-04-27 06:56:47 +000061 x86_exception(regs); // Call coreboot exception handler
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000062
Stefan Reinauerb6b88712011-10-12 14:35:54 -070063 return 0; // Never really returns
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000064}
65
66static int intXX_unknown_handler(struct eregs *regs)
67{
Myles Watsonf53eaa32010-09-09 14:42:58 +000068 printk(BIOS_INFO, "Unsupported software interrupt #0x%x eax 0x%x\n",
69 regs->vector, regs->eax);
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000070
71 return -1;
72}
73
Libra Lic1436932009-12-23 19:16:47 +000074/* setup interrupt handlers for mainboard */
75void mainboard_interrupt_handlers(int intXX, void *intXX_func)
76{
77 intXX_handler[intXX] = intXX_func;
78}
79
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000080static void setup_interrupt_handlers(void)
81{
82 int i;
83
Stefan Reinauer14e22772010-04-27 06:56:47 +000084 /* The first 16 intXX functions are not BIOS services,
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000085 * but the CPU-generated exceptions ("hardware interrupts")
86 */
87 for (i = 0; i < 0x10; i++)
88 intXX_handler[i] = &intXX_exception_handler;
Stefan Reinauer14e22772010-04-27 06:56:47 +000089
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000090 /* Mark all other intXX calls as unknown first */
91 for (i = 0x10; i < 0x100; i++)
Libra Lic1436932009-12-23 19:16:47 +000092 {
93 /* If the mainboard_interrupt_handler isn't called first.
94 */
95 if(!intXX_handler[i])
96 {
97 /* Now set the default functions that are actually
Stefan Reinauerc1efb902011-10-12 14:30:59 -070098 * needed to initialize the option roms. This is
99 * very slick, as it allows us to implement mainboard
100 * specific interrupt handlers, such as the int15.
Libra Lic1436932009-12-23 19:16:47 +0000101 */
102 switch (i) {
Myles Watsonf53eaa32010-09-09 14:42:58 +0000103 case 0x10:
104 intXX_handler[0x10] = &int10_handler;
105 break;
Libra Lic1436932009-12-23 19:16:47 +0000106 case 0x12:
107 intXX_handler[0x12] = &int12_handler;
108 break;
Myles Watsonf53eaa32010-09-09 14:42:58 +0000109 case 0x16:
110 intXX_handler[0x16] = &int16_handler;
111 break;
Libra Lic1436932009-12-23 19:16:47 +0000112 case 0x1a:
113 intXX_handler[0x1a] = &int1a_handler;
114 break;
115 default:
116 intXX_handler[i] = &intXX_unknown_handler;
117 break;
118 }
119 }
120 }
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000121}
122
123static void write_idt_stub(void *target, u8 intnum)
124{
125 unsigned char *codeptr;
126 codeptr = (unsigned char *) target;
127 memcpy(codeptr, &__idt_handler, (size_t)&__idt_handler_size);
128 codeptr[3] = intnum; /* modify int# in the code stub. */
129}
130
131static void setup_realmode_idt(void)
132{
133 struct realmode_idt *idts = (struct realmode_idt *) 0;
134 int i;
135
136 /* Copy IDT stub code for each interrupt. This might seem wasteful
137 * but it is really simple
138 */
139 for (i = 0; i < 256; i++) {
140 idts[i].cs = 0;
141 idts[i].offset = 0x1000 + (i * (u32)&__idt_handler_size);
142 write_idt_stub((void *)((u32 )idts[i].offset), i);
143 }
144
145 /* Many option ROMs use the hard coded interrupt entry points in the
Stefan Reinauer14e22772010-04-27 06:56:47 +0000146 * system bios. So install them at the known locations.
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000147 */
Stefan Reinauer14e22772010-04-27 06:56:47 +0000148
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000149 /* int42 is the relocated int10 */
Stefan Reinauer714e2a12010-04-24 23:15:23 +0000150 write_idt_stub((void *)0xff065, 0x42);
Stefan Reinauer841af5e2010-05-11 15:39:20 +0000151 /* BIOS Int 11 Handler F000:F84D */
152 write_idt_stub((void *)0xff84d, 0x11);
153 /* BIOS Int 12 Handler F000:F841 */
154 write_idt_stub((void *)0xff841, 0x12);
155 /* BIOS Int 13 Handler F000:EC59 */
156 write_idt_stub((void *)0xfec59, 0x13);
157 /* BIOS Int 14 Handler F000:E739 */
158 write_idt_stub((void *)0xfe739, 0x14);
159 /* BIOS Int 15 Handler F000:F859 */
Stefan Reinauer14e22772010-04-27 06:56:47 +0000160 write_idt_stub((void *)0xff859, 0x15);
Stefan Reinauer841af5e2010-05-11 15:39:20 +0000161 /* BIOS Int 16 Handler F000:E82E */
162 write_idt_stub((void *)0xfe82e, 0x16);
163 /* BIOS Int 17 Handler F000:EFD2 */
164 write_idt_stub((void *)0xfefd2, 0x17);
165 /* ROM BIOS Int 1A Handler F000:FE6E */
166 write_idt_stub((void *)0xffe6e, 0x1a);
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000167}
168
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700169#if CONFIG_FRAMEBUFFER_SET_VESA_MODE
Gabe Blackfb8632a2012-09-30 04:47:48 -0700170vbe_mode_info_t mode_info;
171static int mode_info_valid;
172
173int vbe_mode_info_valid(void)
174{
175 return mode_info_valid;
176}
177
178static u8 vbe_get_mode_info(vbe_mode_info_t * mi)
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700179{
Stefan Reinauer01c3de92012-08-29 09:28:52 -0700180 printk(BIOS_DEBUG, "VBE: Getting information about VESA mode %04x\n",
Gabe Blackfb8632a2012-09-30 04:47:48 -0700181 mi->video_mode);
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700182 char *buffer = (char *)&__buffer;
183 u16 buffer_seg = (((unsigned long)buffer) >> 4) & 0xff00;
184 u16 buffer_adr = ((unsigned long)buffer) & 0xffff;
185 realmode_interrupt(0x10, VESA_GET_MODE_INFO, 0x0000,
Gabe Blackfb8632a2012-09-30 04:47:48 -0700186 mi->video_mode, 0x0000, buffer_seg, buffer_adr);
187 memcpy(mi->mode_info_block, buffer, sizeof(vbe_mode_info_t));
188 mode_info_valid = 1;
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700189 return 0;
190}
191
Gabe Blackfb8632a2012-09-30 04:47:48 -0700192static u8 vbe_set_mode(vbe_mode_info_t * mi)
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700193{
Gabe Blackfb8632a2012-09-30 04:47:48 -0700194 printk(BIOS_DEBUG, "VBE: Setting VESA mode %04x\n", mi->video_mode);
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700195 // request linear framebuffer mode
Gabe Blackfb8632a2012-09-30 04:47:48 -0700196 mi->video_mode |= (1 << 14);
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700197 // request clearing of framebuffer
Gabe Blackfb8632a2012-09-30 04:47:48 -0700198 mi->video_mode &= ~(1 << 15);
199 realmode_interrupt(0x10, VESA_SET_MODE, mi->video_mode,
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700200 0x0000, 0x0000, 0x0000, 0x0000);
201 return 0;
202}
203
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700204/* These two functions could probably even be generic between
205 * yabel and x86 native. TBD later.
206 */
207void vbe_set_graphics(void)
208{
209 mode_info.video_mode = (1 << 14) | CONFIG_FRAMEBUFFER_VESA_MODE;
210 vbe_get_mode_info(&mode_info);
211 unsigned char *framebuffer =
Stefan Reinauerb6b88712011-10-12 14:35:54 -0700212 (unsigned char *)mode_info.vesa.phys_base_ptr;
Stefan Reinauer01c3de92012-08-29 09:28:52 -0700213 printk(BIOS_DEBUG, "VBE: resolution: %dx%d@%d\n",
214 le16_to_cpu(mode_info.vesa.x_resolution),
215 le16_to_cpu(mode_info.vesa.y_resolution),
216 mode_info.vesa.bits_per_pixel);
217 printk(BIOS_DEBUG, "VBE: framebuffer: %p\n", framebuffer);
218 if (!framebuffer) {
219 printk(BIOS_DEBUG, "VBE: Mode does not support linear "
220 "framebuffer\n");
221 return;
222 }
223
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700224 vbe_set_mode(&mode_info);
225#if CONFIG_BOOTSPLASH
226 struct jpeg_decdata *decdata;
227 decdata = malloc(sizeof(*decdata));
228 unsigned char *jpeg = cbfs_find_file("bootsplash.jpg",
229 CBFS_TYPE_BOOTSPLASH);
230 if (!jpeg) {
Stefan Reinauer01c3de92012-08-29 09:28:52 -0700231 printk(BIOS_DEBUG, "VBE: No bootsplash found.\n");
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700232 return;
233 }
234 int ret = 0;
235 ret = jpeg_decode(jpeg, framebuffer, 1024, 768, 16, decdata);
236#endif
237}
238
239void vbe_textmode_console(void)
240{
241 delay(2);
242 realmode_interrupt(0x10, 0x0003, 0x0000, 0x0000,
243 0x0000, 0x0000, 0x0000);
244}
245
246void fill_lb_framebuffer(struct lb_framebuffer *framebuffer)
247{
Stefan Reinauerb6b88712011-10-12 14:35:54 -0700248 framebuffer->physical_address = mode_info.vesa.phys_base_ptr;
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700249
250 framebuffer->x_resolution = le16_to_cpu(mode_info.vesa.x_resolution);
251 framebuffer->y_resolution = le16_to_cpu(mode_info.vesa.y_resolution);
252 framebuffer->bytes_per_line =
253 le16_to_cpu(mode_info.vesa.bytes_per_scanline);
254 framebuffer->bits_per_pixel = mode_info.vesa.bits_per_pixel;
255
256 framebuffer->red_mask_pos = mode_info.vesa.red_mask_pos;
257 framebuffer->red_mask_size = mode_info.vesa.red_mask_size;
258
259 framebuffer->green_mask_pos = mode_info.vesa.green_mask_pos;
260 framebuffer->green_mask_size = mode_info.vesa.green_mask_size;
261
262 framebuffer->blue_mask_pos = mode_info.vesa.blue_mask_pos;
263 framebuffer->blue_mask_size = mode_info.vesa.blue_mask_size;
264
265 framebuffer->reserved_mask_pos = mode_info.vesa.reserved_mask_pos;
266 framebuffer->reserved_mask_size = mode_info.vesa.reserved_mask_size;
267}
268#endif
269
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000270void run_bios(struct device *dev, unsigned long addr)
271{
Stefan Reinauer841af5e2010-05-11 15:39:20 +0000272 u32 num_dev = (dev->bus->secondary << 8) | dev->path.pci.devfn;
273
Stefan Reinauerb6b88712011-10-12 14:35:54 -0700274 /* Setting up required hardware.
275 * Removing this will cause random illegal instruction exceptions
276 * in some option roms.
277 */
278 setup_i8259();
279
Stefan Reinauer841af5e2010-05-11 15:39:20 +0000280 /* Set up some legacy information in the F segment */
281 setup_rombios();
Libra Lic1436932009-12-23 19:16:47 +0000282
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000283 /* Set up C interrupt handlers */
284 setup_interrupt_handlers();
285
Stefan Reinauer841af5e2010-05-11 15:39:20 +0000286 /* Set up real-mode IDT */
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000287 setup_realmode_idt();
288
289 memcpy(REALMODE_BASE, &__realmode_code, (size_t)&__realmode_code_size);
290 printk(BIOS_SPEW, "Real mode stub @%p: %d bytes\n", REALMODE_BASE,
291 (u32)&__realmode_code_size);
292
293 printk(BIOS_DEBUG, "Calling Option ROM...\n");
Stefan Reinauer841af5e2010-05-11 15:39:20 +0000294 /* TODO ES:DI Pointer to System BIOS PnP Installation Check Structure */
295 /* Option ROM entry point is at OPROM start + 3 */
296 realmode_call(addr + 0x0003, num_dev, 0xffff, 0x0000, 0xffff, 0x0, 0x0);
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000297 printk(BIOS_DEBUG, "... Option ROM returned.\n");
Stefan Reinauerc1efb902011-10-12 14:30:59 -0700298
299#if CONFIG_FRAMEBUFFER_SET_VESA_MODE
300 vbe_set_graphics();
301#endif
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000302}
303
Stefan Reinauerd4814bd2011-04-21 20:45:45 +0000304#if CONFIG_GEODE_VSA
Stefan Reinauer9839cbd2010-04-21 20:06:10 +0000305#include <cpu/amd/lxdef.h>
306#include <cpu/amd/vr.h>
307#include <cbfs.h>
308
309#define VSA2_BUFFER 0x60000
310#define VSA2_ENTRY_POINT 0x60020
311
312// TODO move to a header file.
313void do_vsmbios(void);
314
315/* VSA virtual register helper */
316static u32 VSA_vrRead(u16 classIndex)
317{
318 u32 eax, ebx, ecx, edx;
319 asm volatile (
320 "movw $0x0AC1C, %%dx\n"
321 "orl $0x0FC530000, %%eax\n"
322 "outl %%eax, %%dx\n"
323 "addb $2, %%dl\n"
324 "inw %%dx, %%ax\n"
Stefan Reinauer14e22772010-04-27 06:56:47 +0000325 : "=a" (eax), "=b"(ebx), "=c"(ecx), "=d"(edx)
Stefan Reinauer9839cbd2010-04-21 20:06:10 +0000326 : "a"(classIndex)
327 );
328
329 return eax;
330}
331
332void do_vsmbios(void)
333{
334 printk(BIOS_DEBUG, "Preparing for VSA...\n");
335
Stefan Reinauer9839cbd2010-04-21 20:06:10 +0000336 /* Set up C interrupt handlers */
337 setup_interrupt_handlers();
338
339 /* Setting up realmode IDT */
340 setup_realmode_idt();
341
342 memcpy(REALMODE_BASE, &__realmode_code, (size_t)&__realmode_code_size);
343 printk(BIOS_SPEW, "VSA: Real mode stub @%p: %d bytes\n", REALMODE_BASE,
344 (u32)&__realmode_code_size);
345
346 if ((unsigned int)cbfs_load_stage("vsa") != VSA2_ENTRY_POINT) {
347 printk(BIOS_ERR, "Failed to load VSA.\n");
348 return;
349 }
350
351 unsigned char *buf = (unsigned char *)VSA2_BUFFER;
352 printk(BIOS_DEBUG, "VSA: Buffer @%p *[0k]=%02x\n", buf, buf[0]);
353 printk(BIOS_DEBUG, "VSA: Signature *[0x20-0x23] is %02x:%02x:%02x:%02x\n",
354 buf[0x20], buf[0x21], buf[0x22], buf[0x23]);
355
356 /* Check for code to emit POST code at start of VSA. */
357 if ((buf[0x20] != 0xb0) || (buf[0x21] != 0x10) ||
358 (buf[0x22] != 0xe6) || (buf[0x23] != 0x80)) {
359 printk(BIOS_WARNING, "VSA: Signature incorrect. Install failed.\n");
360 return;
361 }
362
363 printk(BIOS_DEBUG, "Calling VSA module...\n");
Stefan Reinauer841af5e2010-05-11 15:39:20 +0000364
Stefan Reinauer9839cbd2010-04-21 20:06:10 +0000365 /* ECX gets SMM, EDX gets SYSMEM */
Stefan Reinauer5ff7c132011-10-31 12:56:45 -0700366 realmode_call(VSA2_ENTRY_POINT, 0x0, 0x0, MSR_GLIU0_SMM,
Stefan Reinauer841af5e2010-05-11 15:39:20 +0000367 MSR_GLIU0_SYSMEM, 0x0, 0x0);
368
Stefan Reinauer9839cbd2010-04-21 20:06:10 +0000369 printk(BIOS_DEBUG, "... VSA module returned.\n");
370
371 /* Restart timer 1 */
372 outb(0x56, 0x43);
373 outb(0x12, 0x41);
374
375 /* Check that VSA is running OK */
376 if (VSA_vrRead(SIGNATURE) == VSA2_SIGNATURE)
377 printk(BIOS_DEBUG, "VSM: VSA2 VR signature verified.\n");
378 else
379 printk(BIOS_ERR, "VSM: VSA2 VR signature not valid. Install failed.\n");
380}
381#endif
382
Stefan Reinauer14e22772010-04-27 06:56:47 +0000383/* interrupt_handler() is called from assembler code only,
Stefan Reinauer9839cbd2010-04-21 20:06:10 +0000384 * so there is no use in putting the prototype into a header file.
385 */
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000386int __attribute__((regparm(0))) interrupt_handler(u32 intnumber,
387 u32 gsfs, u32 dses,
388 u32 edi, u32 esi,
389 u32 ebp, u32 esp,
390 u32 ebx, u32 edx,
391 u32 ecx, u32 eax,
Uwe Hermann312673c2009-10-27 21:49:33 +0000392 u32 cs_ip, u16 stackflags);
393
394int __attribute__((regparm(0))) interrupt_handler(u32 intnumber,
395 u32 gsfs, u32 dses,
396 u32 edi, u32 esi,
397 u32 ebp, u32 esp,
398 u32 ebx, u32 edx,
399 u32 ecx, u32 eax,
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000400 u32 cs_ip, u16 stackflags)
401{
402 u32 ip;
403 u32 cs;
404 u32 flags;
405 int ret = -1;
406 struct eregs reg_info;
407
408 ip = cs_ip & 0xffff;
409 cs = cs_ip >> 16;
410 flags = stackflags;
411
Myles Watson6c9bc012010-09-07 22:30:15 +0000412#if CONFIG_REALMODE_DEBUG
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000413 printk(BIOS_DEBUG, "oprom: INT# 0x%x\n", intnumber);
414 printk(BIOS_DEBUG, "oprom: eax: %08x ebx: %08x ecx: %08x edx: %08x\n",
415 eax, ebx, ecx, edx);
416 printk(BIOS_DEBUG, "oprom: ebp: %08x esp: %08x edi: %08x esi: %08x\n",
417 ebp, esp, edi, esi);
418 printk(BIOS_DEBUG, "oprom: ip: %04x cs: %04x flags: %08x\n",
419 ip, cs, flags);
Myles Watson6c9bc012010-09-07 22:30:15 +0000420#endif
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000421
422 // Fetch arguments from the stack and put them into
423 // a structure that we want to pass on to our sub interrupt
424 // handlers.
425 reg_info = (struct eregs) {
426 .eax=eax,
427 .ecx=ecx,
428 .edx=edx,
429 .ebx=ebx,
430 .esp=esp,
431 .ebp=ebp,
432 .esi=esi,
433 .edi=edi,
434 .vector=intnumber,
435 .error_code=0, // ??
436 .eip=ip,
437 .cs=cs,
438 .eflags=flags // ??
439 };
440
441 // Call the interrupt handler for this int#
442 ret = intXX_handler[intnumber](&reg_info);
443
444 // Put registers back on the stack. The assembler code
445 // will later pop them.
446 // What happens here is that we force (volatile!) changing
447 // the values of the parameters of this function. We do this
Stefan Reinauer14e22772010-04-27 06:56:47 +0000448 // because we know that they stay alive on the stack after
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000449 // we leave this function. Don't say this is bollocks.
450 *(volatile u32 *)&eax = reg_info.eax;
451 *(volatile u32 *)&ecx = reg_info.ecx;
452 *(volatile u32 *)&edx = reg_info.edx;
453 *(volatile u32 *)&ebx = reg_info.ebx;
454 *(volatile u32 *)&esi = reg_info.esi;
455 *(volatile u32 *)&edi = reg_info.edi;
456 flags = reg_info.eflags;
457
458 /* Pass errors back to our caller via the CARRY flag */
459 if (ret) {
Stefan Reinauerf75b19a2010-04-22 18:15:32 +0000460 printk(BIOS_DEBUG,"int%02x call returned error.\n", intnumber);
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000461 flags |= 1; // error: set carry
462 }else{
463 flags &= ~1; // no error: clear carry
464 }
465 *(volatile u16 *)&stackflags = flags;
466
467 return ret;
468}
469