Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / ipxe / src / arch / i386 / interface / syslinux / comboot_call.c
1 /*
2  * Copyright (C) 2008 Daniel Verkamp <daniel@drv.nu>.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.
18  */
19
20 /**
21  * @file SYSLINUX COMBOOT API
22  *
23  */
24
25 FILE_LICENCE ( GPL2_OR_LATER );
26
27 #include <errno.h>
28 #include <realmode.h>
29 #include <biosint.h>
30 #include <ipxe/console.h>
31 #include <stdlib.h>
32 #include <comboot.h>
33 #include <bzimage.h>
34 #include <pxe_call.h>
35 #include <setjmp.h>
36 #include <string.h>
37 #include <ipxe/posix_io.h>
38 #include <ipxe/process.h>
39 #include <ipxe/serial.h>
40 #include <ipxe/init.h>
41 #include <ipxe/image.h>
42 #include <ipxe/version.h>
43 #include <usr/imgmgmt.h>
44 #include "config/console.h"
45 #include "config/serial.h"
46
47 /** The "SYSLINUX" version string */
48 static char __bss16_array ( syslinux_version, [32] );
49 #define syslinux_version __use_data16 ( syslinux_version )
50
51 /** The "SYSLINUX" copyright string */
52 static char __data16_array ( syslinux_copyright, [] ) = " http://ipxe.org";
53 #define syslinux_copyright __use_data16 ( syslinux_copyright )
54
55 static char __data16_array ( syslinux_configuration_file, [] ) = "";
56 #define syslinux_configuration_file __use_data16 ( syslinux_configuration_file )
57
58 /** Feature flags */
59 static uint8_t __data16 ( comboot_feature_flags ) = COMBOOT_FEATURE_IDLE_LOOP;
60 #define comboot_feature_flags __use_data16 ( comboot_feature_flags )
61
62 typedef union {
63         syslinux_pm_regs pm; syslinux_rm_regs rm;
64 } syslinux_regs;
65
66 /** Initial register values for INT 22h AX=1Ah and 1Bh */
67 static syslinux_regs __text16 ( comboot_initial_regs );
68 #define comboot_initial_regs __use_text16 ( comboot_initial_regs )
69
70 static struct segoff __text16 ( int20_vector );
71 #define int20_vector __use_text16 ( int20_vector )
72
73 static struct segoff __text16 ( int21_vector );
74 #define int21_vector __use_text16 ( int21_vector )
75
76 static struct segoff __text16 ( int22_vector );
77 #define int22_vector __use_text16 ( int22_vector )
78
79 extern void int20_wrapper ( void );
80 extern void int21_wrapper ( void );
81 extern void int22_wrapper ( void );
82
83 /* setjmp/longjmp context buffer used to return after loading an image */
84 rmjmp_buf comboot_return;
85
86 /* Mode flags set by INT 22h AX=0017h */
87 static uint16_t comboot_graphics_mode = 0;
88
89
90 /**
91  * Print a string with a particular terminator
92  */
93 static void print_user_string ( unsigned int segment, unsigned int offset, char terminator ) {
94         int i = 0;
95         char c;
96         userptr_t str = real_to_user ( segment, offset );
97         for ( ; ; ) {
98                 copy_from_user ( &c, str, i, 1 );
99                 if ( c == terminator ) break;
100                 putchar ( c );
101                 i++;
102         }
103 }
104
105
106 /**
107  * Perform a series of memory copies from a list in low memory
108  */
109 static void shuffle ( unsigned int list_segment, unsigned int list_offset, unsigned int count )
110 {
111         comboot_shuffle_descriptor shuf[COMBOOT_MAX_SHUFFLE_DESCRIPTORS];
112         unsigned int i;
113
114         /* Copy shuffle descriptor list so it doesn't get overwritten */
115         copy_from_user ( shuf, real_to_user ( list_segment, list_offset ), 0,
116                          count * sizeof( comboot_shuffle_descriptor ) );
117
118         /* Do the copies */
119         for ( i = 0; i < count; i++ ) {
120                 userptr_t src_u = phys_to_user ( shuf[ i ].src );
121                 userptr_t dest_u = phys_to_user ( shuf[ i ].dest );
122
123                 if ( shuf[ i ].src == 0xFFFFFFFF ) {
124                         /* Fill with 0 instead of copying */
125                         memset_user ( dest_u, 0, 0, shuf[ i ].len );
126                 } else if ( shuf[ i ].dest == 0xFFFFFFFF ) {
127                         /* Copy new list of descriptors */
128                         count = shuf[ i ].len / sizeof( comboot_shuffle_descriptor );
129                         assert ( count <= COMBOOT_MAX_SHUFFLE_DESCRIPTORS );
130                         copy_from_user ( shuf, src_u, 0, shuf[ i ].len );
131                         i = -1;
132                 } else {
133                         /* Regular copy */
134                         memmove_user ( dest_u, 0, src_u, 0, shuf[ i ].len );
135                 }
136         }
137 }
138
139
140 /**
141  * Set default text mode
142  */
143 void comboot_force_text_mode ( void ) {
144         if ( comboot_graphics_mode & COMBOOT_VIDEO_VESA ) {
145                 /* Set VGA mode 3 via VESA VBE mode set */
146                 __asm__ __volatile__ (
147                         REAL_CODE (
148                                 "mov $0x4F02, %%ax\n\t"
149                                 "mov $0x03, %%bx\n\t"
150                                 "int $0x10\n\t"
151                         )
152                 : : );
153         } else if ( comboot_graphics_mode & COMBOOT_VIDEO_GRAPHICS ) {
154                 /* Set VGA mode 3 via standard VGA mode set */
155                 __asm__ __volatile__ (
156                         REAL_CODE (
157                                 "mov $0x03, %%ax\n\t"
158                                 "int $0x10\n\t"
159                         )
160                 : : );
161         }
162
163         comboot_graphics_mode = 0;
164 }
165
166
167 /**
168  * Fetch kernel and optional initrd
169  */
170 static int comboot_fetch_kernel ( char *kernel_file, char *cmdline ) {
171         struct image *kernel;
172         struct image *initrd;
173         char *initrd_file;
174         int rc;
175
176         /* Find initrd= parameter, if any */
177         if ( ( initrd_file = strstr ( cmdline, "initrd=" ) ) != NULL ) {
178                 char *initrd_end;
179
180                 /* skip "initrd=" */
181                 initrd_file += 7;
182
183                 /* Find terminating space, if any, and replace with NUL */
184                 initrd_end = strchr ( initrd_file, ' ' );
185                 if ( initrd_end )
186                         *initrd_end = '\0';
187
188                 DBG ( "COMBOOT: fetching initrd '%s'\n", initrd_file );
189
190                 /* Fetch initrd */
191                 if ( ( rc = imgdownload_string ( initrd_file, 0,
192                                                  &initrd ) ) != 0 ) {
193                         DBG ( "COMBOOT: could not fetch initrd: %s\n",
194                               strerror ( rc ) );
195                         return rc;
196                 }
197
198                 /* Restore space after initrd name, if applicable */
199                 if ( initrd_end )
200                         *initrd_end = ' ';
201         }
202
203         DBG ( "COMBOOT: fetching kernel '%s'\n", kernel_file );
204
205         /* Fetch kernel */
206         if ( ( rc = imgdownload_string ( kernel_file, 0, &kernel ) ) != 0 ) {
207                 DBG ( "COMBOOT: could not fetch kernel: %s\n",
208                       strerror ( rc ) );
209                 return rc;
210         }
211
212         /* Replace comboot image with kernel */
213         if ( ( rc = image_replace ( kernel ) ) != 0 ) {
214                 DBG ( "COMBOOT: could not replace with kernel: %s\n",
215                       strerror ( rc ) );
216                 return rc;
217         }
218
219         return 0;
220 }
221
222
223 /**
224  * Terminate program interrupt handler
225  */
226 static __asmcall void int20 ( struct i386_all_regs *ix86 __unused ) {
227         rmlongjmp ( comboot_return, COMBOOT_EXIT );
228 }
229
230
231 /**
232  * DOS-compatible API
233  */
234 static __asmcall void int21 ( struct i386_all_regs *ix86 ) {
235         ix86->flags |= CF;
236
237         switch ( ix86->regs.ah ) {
238         case 0x00:
239         case 0x4C: /* Terminate program */
240                 rmlongjmp ( comboot_return, COMBOOT_EXIT );
241                 break;
242
243         case 0x01: /* Get Key with Echo */
244         case 0x08: /* Get Key without Echo */
245                 /* TODO: handle extended characters? */
246                 ix86->regs.al = getchar( );
247
248                 /* Enter */
249                 if ( ix86->regs.al == 0x0A )
250                         ix86->regs.al = 0x0D;
251
252                 if ( ix86->regs.ah == 0x01 )
253                         putchar ( ix86->regs.al );
254
255                 ix86->flags &= ~CF;
256                 break;
257
258         case 0x02: /* Write Character */
259                 putchar ( ix86->regs.dl );
260                 ix86->flags &= ~CF;
261                 break;
262
263         case 0x04: /* Write Character to Serial Port */
264                 serial_putc ( ix86->regs.dl );
265                 ix86->flags &= ~CF;
266                 break;
267
268         case 0x09: /* Write DOS String to Console */
269                 print_user_string ( ix86->segs.ds, ix86->regs.dx, '$' );
270                 ix86->flags &= ~CF;
271                 break;
272
273         case 0x0B: /* Check Keyboard */
274                 if ( iskey() )
275                         ix86->regs.al = 0xFF;
276                 else
277                         ix86->regs.al = 0x00;
278
279                 ix86->flags &= ~CF;
280                 break;
281
282         case 0x30: /* Check DOS Version */
283                 /* Bottom halves all 0; top halves spell "SYSLINUX" */
284                 ix86->regs.eax = 0x59530000;
285                 ix86->regs.ebx = 0x4C530000;
286                 ix86->regs.ecx = 0x4E490000;
287                 ix86->regs.edx = 0x58550000;
288                 ix86->flags &= ~CF;
289                 break;
290
291         default:
292                 DBG ( "COMBOOT unknown int21 function %02x\n", ix86->regs.ah );
293                 break;
294         }
295 }
296
297
298 /**
299  * Dispatch PXE API call weakly
300  *
301  * @v ix86              Registers for PXE call
302  * @ret present         Zero if the PXE stack is present, nonzero if not
303  *
304  * A successful return only indicates that the PXE stack was available
305  * for dispatching the call; it says nothing about the success of
306  * whatever the call asked for.
307  */
308 __weak int pxe_api_call_weak ( struct i386_all_regs *ix86 __unused ) {
309         return -1;
310 }
311
312 /**
313  * SYSLINUX API
314  */
315 static __asmcall void int22 ( struct i386_all_regs *ix86 ) {
316         ix86->flags |= CF;
317
318         switch ( ix86->regs.ax ) {
319         case 0x0001: /* Get Version */
320
321                 /* Number of INT 22h API functions available */
322                 ix86->regs.ax = 0x001D;
323
324                 /* SYSLINUX version number */
325                 ix86->regs.ch = 0; /* major */
326                 ix86->regs.cl = 0; /* minor */
327
328                 /* SYSLINUX derivative ID */
329                 ix86->regs.dl = BZI_LOADER_TYPE_IPXE;
330
331                 /* SYSLINUX version */
332                 snprintf ( syslinux_version, sizeof ( syslinux_version ),
333                            "\r\niPXE %s", product_version );
334
335                 /* SYSLINUX version and copyright strings */
336                 ix86->segs.es = rm_ds;
337                 ix86->regs.si = ( ( unsigned ) __from_data16 ( syslinux_version ) );
338                 ix86->regs.di = ( ( unsigned ) __from_data16 ( syslinux_copyright ) );
339
340                 ix86->flags &= ~CF;
341                 break;
342
343         case 0x0002: /* Write String */
344                 print_user_string ( ix86->segs.es, ix86->regs.bx, '\0' );
345                 ix86->flags &= ~CF;
346                 break;
347
348         case 0x0003: /* Run command */
349                 {
350                         userptr_t cmd_u = real_to_user ( ix86->segs.es, ix86->regs.bx );
351                         int len = strlen_user ( cmd_u, 0 );
352                         char cmd[len + 1];
353                         copy_from_user ( cmd, cmd_u, 0, len + 1 );
354                         DBG ( "COMBOOT: executing command '%s'\n", cmd );
355                         system ( cmd );
356                         DBG ( "COMBOOT: exiting after executing command...\n" );
357                         rmlongjmp ( comboot_return, COMBOOT_EXIT_COMMAND );
358                 }
359                 break;
360
361         case 0x0004: /* Run default command */
362                 /* FIXME: just exit for now */
363                 rmlongjmp ( comboot_return, COMBOOT_EXIT_COMMAND );
364                 break;
365
366         case 0x0005: /* Force text mode */
367                 comboot_force_text_mode ( );
368                 ix86->flags &= ~CF;
369                 break;
370
371         case 0x0006: /* Open file */
372                 {
373                         int fd;
374                         userptr_t file_u = real_to_user ( ix86->segs.es, ix86->regs.si );
375                         int len = strlen_user ( file_u, 0 );
376                         char file[len + 1];
377
378                         copy_from_user ( file, file_u, 0, len + 1 );
379
380                         if ( file[0] == '\0' ) {
381                                 DBG ( "COMBOOT: attempted open with empty file name\n" );
382                                 break;
383                         }
384
385                         DBG ( "COMBOOT: opening file '%s'\n", file );
386
387                         fd = open ( file );
388
389                         if ( fd < 0 ) {
390                                 DBG ( "COMBOOT: error opening file %s\n", file );
391                                 break;
392                         }
393
394                         /* This relies on the fact that a iPXE POSIX fd will
395                          * always fit in 16 bits.
396                          */
397 #if (POSIX_FD_MAX > 65535)
398 #error POSIX_FD_MAX too large
399 #endif
400                         ix86->regs.si = (uint16_t) fd;
401
402                         ix86->regs.cx = COMBOOT_FILE_BLOCKSZ;
403                         ix86->regs.eax = fsize ( fd );
404                         ix86->flags &= ~CF;
405                 }
406                 break;
407
408         case 0x0007: /* Read file */
409                 {
410                         int fd = ix86->regs.si;
411                         int len = ix86->regs.cx * COMBOOT_FILE_BLOCKSZ;
412                         int rc;
413                         fd_set fds;
414                         userptr_t buf = real_to_user ( ix86->segs.es, ix86->regs.bx );
415
416                         /* Wait for data ready to read */
417                         FD_ZERO ( &fds );
418                         FD_SET ( fd, &fds );
419
420                         select ( &fds, 1 );
421
422                         rc = read_user ( fd, buf, 0, len );
423                         if ( rc < 0 ) {
424                                 DBG ( "COMBOOT: read failed\n" );
425                                 ix86->regs.si = 0;
426                                 break;
427                         }
428
429                         ix86->regs.ecx = rc;
430                         ix86->flags &= ~CF;
431                 }
432                 break;
433
434         case 0x0008: /* Close file */
435                 {
436                         int fd = ix86->regs.si;
437                         close ( fd );
438                         ix86->flags &= ~CF;
439                 }
440                 break;
441
442         case 0x0009: /* Call PXE Stack */
443                 if ( pxe_api_call_weak ( ix86 ) != 0 )
444                         ix86->flags |= CF;
445                 else
446                         ix86->flags &= ~CF;
447                 break;
448
449         case 0x000A: /* Get Derivative-Specific Information */
450
451                 /* iPXE has its own derivative ID, so there is no defined
452                  * output here; just return AL for now */
453                 ix86->regs.al = BZI_LOADER_TYPE_IPXE;
454                 ix86->flags &= ~CF;
455                 break;
456
457         case 0x000B: /* Get Serial Console Configuration */
458 #if defined(CONSOLE_SERIAL) && !defined(COMPRESERVE)
459                 ix86->regs.dx = COMCONSOLE;
460                 ix86->regs.cx = 115200 / COMSPEED;
461                 ix86->regs.bx = 0;
462 #else
463                 ix86->regs.dx = 0;
464 #endif
465
466                 ix86->flags &= ~CF;
467                 break;
468
469         case 0x000E: /* Get configuration file name */
470                 /* FIXME: stub */
471                 ix86->segs.es = rm_ds;
472                 ix86->regs.bx = ( ( unsigned ) __from_data16 ( syslinux_configuration_file ) );
473                 ix86->flags &= ~CF;
474                 break;
475
476         case 0x000F: /* Get IPAPPEND strings */
477                 /* FIXME: stub */
478                 ix86->regs.cx = 0;
479                 ix86->segs.es = 0;
480                 ix86->regs.bx = 0;
481                 ix86->flags &= ~CF;
482                 break;
483
484         case 0x0010: /* Resolve hostname */
485                 {
486                         userptr_t hostname_u = real_to_user ( ix86->segs.es, ix86->regs.bx );
487                         int len = strlen_user ( hostname_u, 0 );
488                         char hostname[len];
489                         struct in_addr addr;
490
491                         copy_from_user ( hostname, hostname_u, 0, len + 1 );
492                         
493                         /* TODO:
494                          * "If the hostname does not contain a dot (.), the
495                          * local domain name is automatically appended."
496                          */
497
498                         comboot_resolv ( hostname, &addr );
499
500                         ix86->regs.eax = addr.s_addr;
501                         ix86->flags &= ~CF;
502                 }
503                 break;
504
505         case 0x0011: /* Maximum number of shuffle descriptors */
506                 ix86->regs.cx = COMBOOT_MAX_SHUFFLE_DESCRIPTORS;
507                 ix86->flags &= ~CF;
508                 break;
509
510         case 0x0012: /* Cleanup, shuffle and boot */
511                 if ( ix86->regs.cx > COMBOOT_MAX_SHUFFLE_DESCRIPTORS )
512                         break;
513
514                 /* Perform final cleanup */
515                 shutdown_boot();
516
517                 /* Perform sequence of copies */
518                 shuffle ( ix86->segs.es, ix86->regs.di, ix86->regs.cx );
519
520                 /* Jump to real-mode entry point */
521                 __asm__ __volatile__ (
522                         REAL_CODE ( 
523                                 "pushw %0\n\t"
524                                 "popw %%ds\n\t"
525                                 "pushl %1\n\t"
526                                 "lret\n\t"
527                         )
528                         :
529                         : "r" ( ix86->segs.ds ),
530                           "r" ( ix86->regs.ebp ),
531                           "d" ( ix86->regs.ebx ),
532                           "S" ( ix86->regs.esi ) );
533
534                 assert ( 0 ); /* Execution should never reach this point */
535
536                 break;
537
538         case 0x0013: /* Idle loop call */
539                 step ( );
540                 ix86->flags &= ~CF;
541                 break;
542
543         case 0x0015: /* Get feature flags */
544                 ix86->segs.es = rm_ds;
545                 ix86->regs.bx = ( ( unsigned ) __from_data16 ( &comboot_feature_flags ) );
546                 ix86->regs.cx = 1; /* Number of feature flag bytes */
547                 ix86->flags &= ~CF;
548                 break;
549
550         case 0x0016: /* Run kernel image */
551                 {
552                         userptr_t file_u = real_to_user ( ix86->segs.ds, ix86->regs.si );
553                         userptr_t cmd_u = real_to_user ( ix86->segs.es, ix86->regs.bx );
554                         int file_len = strlen_user ( file_u, 0 );
555                         int cmd_len = strlen_user ( cmd_u, 0 );
556                         char file[file_len + 1];
557                         char cmd[cmd_len + 1];
558
559                         copy_from_user ( file, file_u, 0, file_len + 1 );
560                         copy_from_user ( cmd, cmd_u, 0, cmd_len + 1 );
561
562                         DBG ( "COMBOOT: run kernel %s %s\n", file, cmd );
563                         comboot_fetch_kernel ( file, cmd );
564                         /* Technically, we should return if we
565                          * couldn't load the kernel, but it's not safe
566                          * to do that since we have just overwritten
567                          * part of the COMBOOT program's memory space.
568                          */
569                         DBG ( "COMBOOT: exiting to run kernel...\n" );
570                         rmlongjmp ( comboot_return, COMBOOT_EXIT_RUN_KERNEL );
571                 }
572                 break;
573
574         case 0x0017: /* Report video mode change */
575                 comboot_graphics_mode = ix86->regs.bx;
576                 ix86->flags &= ~CF;
577                 break;
578
579         case 0x0018: /* Query custom font */
580                 /* FIXME: stub */
581                 ix86->regs.al = 0;
582                 ix86->segs.es = 0;
583                 ix86->regs.bx = 0;
584                 ix86->flags &= ~CF;
585                 break;
586
587         case 0x001B: /* Cleanup, shuffle and boot to real mode */
588                 if ( ix86->regs.cx > COMBOOT_MAX_SHUFFLE_DESCRIPTORS )
589                         break;
590
591                 /* Perform final cleanup */
592                 shutdown_boot();
593
594                 /* Perform sequence of copies */
595                 shuffle ( ix86->segs.es, ix86->regs.di, ix86->regs.cx );
596
597                 /* Copy initial register values to .text16 */
598                 memcpy_user ( real_to_user ( rm_cs, (unsigned) __from_text16 ( &comboot_initial_regs ) ), 0,
599                               real_to_user ( ix86->segs.ds, ix86->regs.si ), 0,
600                               sizeof(syslinux_rm_regs) );
601
602                 /* Load initial register values */
603                 __asm__ __volatile__ (
604                         REAL_CODE (
605                                 /* Point SS:SP at the register value structure */
606                                 "pushw %%cs\n\t"
607                                 "popw %%ss\n\t"
608                                 "movw $comboot_initial_regs, %%sp\n\t"
609
610                                 /* Segment registers */
611                                 "popw %%es\n\t"
612                                 "popw %%ax\n\t" /* Skip CS */
613                                 "popw %%ds\n\t"
614                                 "popw %%ax\n\t" /* Skip SS for now */
615                                 "popw %%fs\n\t"
616                                 "popw %%gs\n\t"
617
618                                 /* GP registers */
619                                 "popl %%eax\n\t"
620                                 "popl %%ecx\n\t"
621                                 "popl %%edx\n\t"
622                                 "popl %%ebx\n\t"
623                                 "popl %%ebp\n\t" /* Skip ESP for now */
624                                 "popl %%ebp\n\t"
625                                 "popl %%esi\n\t"
626                                 "popl %%edi\n\t"
627
628                                 /* Load correct SS:ESP */
629                                 "movw $(comboot_initial_regs + 6), %%sp\n\t"
630                                 "popw %%ss\n\t"
631                                 "movl %%cs:(comboot_initial_regs + 28), %%esp\n\t"
632
633                                 "ljmp *%%cs:(comboot_initial_regs + 44)\n\t"
634                         )
635                         : : );
636
637                 break;
638
639         case 0x001C: /* Get pointer to auxilliary data vector */
640                 /* FIXME: stub */
641                 ix86->regs.cx = 0; /* Size of the ADV */
642                 ix86->flags &= ~CF;
643                 break;
644
645         case 0x001D: /* Write auxilliary data vector */
646                 /* FIXME: stub */
647                 ix86->flags &= ~CF;
648                 break;
649
650         default:
651                 DBG ( "COMBOOT unknown int22 function %04x\n", ix86->regs.ax );
652                 break;
653         }
654 }
655
656 /**
657  * Hook BIOS interrupts related to COMBOOT API (INT 20h, 21h, 22h)
658  */
659 void hook_comboot_interrupts ( ) {
660
661         __asm__ __volatile__ (
662                 TEXT16_CODE ( "\nint20_wrapper:\n\t"
663                               "pushl %0\n\t"
664                               "pushw %%cs\n\t"
665                               "call prot_call\n\t"
666                               "addw $4, %%sp\n\t"
667                               "call patch_cf\n\t"
668                               "iret\n\t" )
669                           : : "i" ( int20 ) );
670
671         hook_bios_interrupt ( 0x20, ( unsigned int ) int20_wrapper,
672                                       &int20_vector );
673
674         __asm__ __volatile__ (
675                 TEXT16_CODE ( "\nint21_wrapper:\n\t"
676                               "pushl %0\n\t"
677                               "pushw %%cs\n\t"
678                               "call prot_call\n\t"
679                               "addw $4, %%sp\n\t"
680                               "call patch_cf\n\t"
681                               "iret\n\t" )
682                           : : "i" ( int21 ) );
683
684         hook_bios_interrupt ( 0x21, ( unsigned int ) int21_wrapper,
685                               &int21_vector );
686
687         __asm__  __volatile__ (
688                 TEXT16_CODE ( "\nint22_wrapper:\n\t"
689                               "pushl %0\n\t"
690                               "pushw %%cs\n\t"
691                               "call prot_call\n\t"
692                               "addw $4, %%sp\n\t"
693                               "call patch_cf\n\t"
694                               "iret\n\t" )
695                           : : "i" ( int22) );
696
697         hook_bios_interrupt ( 0x22, ( unsigned int ) int22_wrapper,
698                               &int22_vector );
699 }
700
701 /**
702  * Unhook BIOS interrupts related to COMBOOT API (INT 20h, 21h, 22h)
703  */
704 void unhook_comboot_interrupts ( ) {
705
706         unhook_bios_interrupt ( 0x20, ( unsigned int ) int20_wrapper,
707                                 &int20_vector );
708
709         unhook_bios_interrupt ( 0x21, ( unsigned int ) int21_wrapper,
710                                 &int21_vector );
711
712         unhook_bios_interrupt ( 0x22, ( unsigned int ) int22_wrapper,
713                                 &int22_vector );
714 }