iPXE
comboot_call.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2008 Daniel Verkamp <daniel@drv.nu>.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License as
00006  * published by the Free Software Foundation; either version 2 of the
00007  * License, or any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017  * 02110-1301, USA.
00018  */
00019 
00020 /**
00021  * @file SYSLINUX COMBOOT API
00022  *
00023  */
00024 
00025 FILE_LICENCE ( GPL2_OR_LATER );
00026 
00027 #include <errno.h>
00028 #include <realmode.h>
00029 #include <biosint.h>
00030 #include <ipxe/console.h>
00031 #include <stdlib.h>
00032 #include <comboot.h>
00033 #include <bzimage.h>
00034 #include <pxe_call.h>
00035 #include <rmsetjmp.h>
00036 #include <string.h>
00037 #include <ipxe/posix_io.h>
00038 #include <ipxe/process.h>
00039 #include <ipxe/serial.h>
00040 #include <ipxe/init.h>
00041 #include <ipxe/image.h>
00042 #include <ipxe/version.h>
00043 #include <usr/imgmgmt.h>
00044 
00045 /** The "SYSLINUX" version string */
00046 static char __bss16_array ( syslinux_version, [32] );
00047 #define syslinux_version __use_data16 ( syslinux_version )
00048 
00049 /** The "SYSLINUX" copyright string */
00050 static char __data16_array ( syslinux_copyright, [] ) = " http://ipxe.org";
00051 #define syslinux_copyright __use_data16 ( syslinux_copyright )
00052 
00053 static char __data16_array ( syslinux_configuration_file, [] ) = "";
00054 #define syslinux_configuration_file __use_data16 ( syslinux_configuration_file )
00055 
00056 /** Feature flags */
00057 static uint8_t __data16 ( comboot_feature_flags ) = COMBOOT_FEATURE_IDLE_LOOP;
00058 #define comboot_feature_flags __use_data16 ( comboot_feature_flags )
00059 
00060 typedef union {
00061         syslinux_pm_regs pm; syslinux_rm_regs rm;
00062 } syslinux_regs;
00063 
00064 /** Initial register values for INT 22h AX=1Ah and 1Bh */
00065 static syslinux_regs __text16 ( comboot_initial_regs );
00066 #define comboot_initial_regs __use_text16 ( comboot_initial_regs )
00067 
00068 static struct segoff __text16 ( int20_vector );
00069 #define int20_vector __use_text16 ( int20_vector )
00070 
00071 static struct segoff __text16 ( int21_vector );
00072 #define int21_vector __use_text16 ( int21_vector )
00073 
00074 static struct segoff __text16 ( int22_vector );
00075 #define int22_vector __use_text16 ( int22_vector )
00076 
00077 extern void int20_wrapper ( void );
00078 extern void int21_wrapper ( void );
00079 extern void int22_wrapper ( void );
00080 
00081 /* setjmp/longjmp context buffer used to return after loading an image */
00082 rmjmp_buf comboot_return;
00083 
00084 /* Mode flags set by INT 22h AX=0017h */
00085 static uint16_t comboot_graphics_mode = 0;
00086 
00087 /**
00088  * Print a string with a particular terminator
00089  */
00090 static void print_user_string ( unsigned int segment, unsigned int offset, char terminator ) {
00091         int i = 0;
00092         char c;
00093         userptr_t str = real_to_user ( segment, offset );
00094         for ( ; ; ) {
00095                 copy_from_user ( &c, str, i, 1 );
00096                 if ( c == terminator ) break;
00097                 putchar ( c );
00098                 i++;
00099         }
00100 }
00101 
00102 
00103 /**
00104  * Perform a series of memory copies from a list in low memory
00105  */
00106 static void shuffle ( unsigned int list_segment, unsigned int list_offset, unsigned int count )
00107 {
00108         comboot_shuffle_descriptor shuf[COMBOOT_MAX_SHUFFLE_DESCRIPTORS];
00109         unsigned int i;
00110 
00111         /* Copy shuffle descriptor list so it doesn't get overwritten */
00112         copy_from_user ( shuf, real_to_user ( list_segment, list_offset ), 0,
00113                          count * sizeof( comboot_shuffle_descriptor ) );
00114 
00115         /* Do the copies */
00116         for ( i = 0; i < count; i++ ) {
00117                 userptr_t src_u = phys_to_user ( shuf[ i ].src );
00118                 userptr_t dest_u = phys_to_user ( shuf[ i ].dest );
00119 
00120                 if ( shuf[ i ].src == 0xFFFFFFFF ) {
00121                         /* Fill with 0 instead of copying */
00122                         memset_user ( dest_u, 0, 0, shuf[ i ].len );
00123                 } else if ( shuf[ i ].dest == 0xFFFFFFFF ) {
00124                         /* Copy new list of descriptors */
00125                         count = shuf[ i ].len / sizeof( comboot_shuffle_descriptor );
00126                         assert ( count <= COMBOOT_MAX_SHUFFLE_DESCRIPTORS );
00127                         copy_from_user ( shuf, src_u, 0, shuf[ i ].len );
00128                         i = -1;
00129                 } else {
00130                         /* Regular copy */
00131                         memmove_user ( dest_u, 0, src_u, 0, shuf[ i ].len );
00132                 }
00133         }
00134 }
00135 
00136 
00137 /**
00138  * Set default text mode
00139  */
00140 void comboot_force_text_mode ( void ) {
00141         if ( comboot_graphics_mode & COMBOOT_VIDEO_VESA ) {
00142                 /* Set VGA mode 3 via VESA VBE mode set */
00143                 __asm__ __volatile__ (
00144                         REAL_CODE (
00145                                 "mov $0x4F02, %%ax\n\t"
00146                                 "mov $0x03, %%bx\n\t"
00147                                 "int $0x10\n\t"
00148                         )
00149                 : : );
00150         } else if ( comboot_graphics_mode & COMBOOT_VIDEO_GRAPHICS ) {
00151                 /* Set VGA mode 3 via standard VGA mode set */
00152                 __asm__ __volatile__ (
00153                         REAL_CODE (
00154                                 "mov $0x03, %%ax\n\t"
00155                                 "int $0x10\n\t"
00156                         )
00157                 : : );
00158         }
00159 
00160         comboot_graphics_mode = 0;
00161 }
00162 
00163 
00164 /**
00165  * Fetch kernel and optional initrd
00166  */
00167 static int comboot_fetch_kernel ( char *kernel_file, char *cmdline ) {
00168         struct image *kernel;
00169         struct image *initrd;
00170         char *initrd_file;
00171         int rc;
00172 
00173         /* Find initrd= parameter, if any */
00174         if ( ( initrd_file = strstr ( cmdline, "initrd=" ) ) != NULL ) {
00175                 char *initrd_end;
00176 
00177                 /* skip "initrd=" */
00178                 initrd_file += 7;
00179 
00180                 /* Find terminating space, if any, and replace with NUL */
00181                 initrd_end = strchr ( initrd_file, ' ' );
00182                 if ( initrd_end )
00183                         *initrd_end = '\0';
00184 
00185                 DBG ( "COMBOOT: fetching initrd '%s'\n", initrd_file );
00186 
00187                 /* Fetch initrd */
00188                 if ( ( rc = imgdownload_string ( initrd_file, 0,
00189                                                  &initrd ) ) != 0 ) {
00190                         DBG ( "COMBOOT: could not fetch initrd: %s\n",
00191                               strerror ( rc ) );
00192                         return rc;
00193                 }
00194 
00195                 /* Restore space after initrd name, if applicable */
00196                 if ( initrd_end )
00197                         *initrd_end = ' ';
00198         }
00199 
00200         DBG ( "COMBOOT: fetching kernel '%s'\n", kernel_file );
00201 
00202         /* Fetch kernel */
00203         if ( ( rc = imgdownload_string ( kernel_file, 0, &kernel ) ) != 0 ) {
00204                 DBG ( "COMBOOT: could not fetch kernel: %s\n",
00205                       strerror ( rc ) );
00206                 return rc;
00207         }
00208 
00209         /* Replace comboot image with kernel */
00210         if ( ( rc = image_replace ( kernel ) ) != 0 ) {
00211                 DBG ( "COMBOOT: could not replace with kernel: %s\n",
00212                       strerror ( rc ) );
00213                 return rc;
00214         }
00215 
00216         return 0;
00217 }
00218 
00219 
00220 /**
00221  * Terminate program interrupt handler
00222  */
00223 static __asmcall void int20 ( struct i386_all_regs *ix86 __unused ) {
00224         rmlongjmp ( comboot_return, COMBOOT_EXIT );
00225 }
00226 
00227 
00228 /**
00229  * DOS-compatible API
00230  */
00231 static __asmcall void int21 ( struct i386_all_regs *ix86 ) {
00232         ix86->flags |= CF;
00233 
00234         switch ( ix86->regs.ah ) {
00235         case 0x00:
00236         case 0x4C: /* Terminate program */
00237                 rmlongjmp ( comboot_return, COMBOOT_EXIT );
00238                 break;
00239 
00240         case 0x01: /* Get Key with Echo */
00241         case 0x08: /* Get Key without Echo */
00242                 /* TODO: handle extended characters? */
00243                 ix86->regs.al = getchar( );
00244 
00245                 /* Enter */
00246                 if ( ix86->regs.al == 0x0A )
00247                         ix86->regs.al = 0x0D;
00248 
00249                 if ( ix86->regs.ah == 0x01 )
00250                         putchar ( ix86->regs.al );
00251 
00252                 ix86->flags &= ~CF;
00253                 break;
00254 
00255         case 0x02: /* Write Character */
00256                 putchar ( ix86->regs.dl );
00257                 ix86->flags &= ~CF;
00258                 break;
00259 
00260         case 0x04: /* Write Character to Serial Port */
00261                 if ( serial_console.base ) {
00262                         uart_transmit ( &serial_console, ix86->regs.dl );
00263                         ix86->flags &= ~CF;
00264                 }
00265                 break;
00266 
00267         case 0x09: /* Write DOS String to Console */
00268                 print_user_string ( ix86->segs.ds, ix86->regs.dx, '$' );
00269                 ix86->flags &= ~CF;
00270                 break;
00271 
00272         case 0x0B: /* Check Keyboard */
00273                 if ( iskey() )
00274                         ix86->regs.al = 0xFF;
00275                 else
00276                         ix86->regs.al = 0x00;
00277 
00278                 ix86->flags &= ~CF;
00279                 break;
00280 
00281         case 0x30: /* Check DOS Version */
00282                 /* Bottom halves all 0; top halves spell "SYSLINUX" */
00283                 ix86->regs.eax = 0x59530000;
00284                 ix86->regs.ebx = 0x4C530000;
00285                 ix86->regs.ecx = 0x4E490000;
00286                 ix86->regs.edx = 0x58550000;
00287                 ix86->flags &= ~CF;
00288                 break;
00289 
00290         default:
00291                 DBG ( "COMBOOT unknown int21 function %02x\n", ix86->regs.ah );
00292                 break;
00293         }
00294 }
00295 
00296 
00297 /**
00298  * Dispatch PXE API call weakly
00299  *
00300  * @v ix86              Registers for PXE call
00301  * @ret present         Zero if the PXE stack is present, nonzero if not
00302  *
00303  * A successful return only indicates that the PXE stack was available
00304  * for dispatching the call; it says nothing about the success of
00305  * whatever the call asked for.
00306  */
00307 __weak int pxe_api_call_weak ( struct i386_all_regs *ix86 __unused ) {
00308         return -1;
00309 }
00310 
00311 /**
00312  * SYSLINUX API
00313  */
00314 static __asmcall void int22 ( struct i386_all_regs *ix86 ) {
00315         ix86->flags |= CF;
00316 
00317         switch ( ix86->regs.ax ) {
00318         case 0x0001: /* Get Version */
00319 
00320                 /* Number of INT 22h API functions available */
00321                 ix86->regs.ax = 0x001D;
00322 
00323                 /* SYSLINUX version number */
00324                 ix86->regs.ch = 0; /* major */
00325                 ix86->regs.cl = 0; /* minor */
00326 
00327                 /* SYSLINUX derivative ID */
00328                 ix86->regs.dl = BZI_LOADER_TYPE_IPXE;
00329 
00330                 /* SYSLINUX version */
00331                 snprintf ( syslinux_version, sizeof ( syslinux_version ),
00332                            "\r\niPXE %s", product_version );
00333 
00334                 /* SYSLINUX version and copyright strings */
00335                 ix86->segs.es = rm_ds;
00336                 ix86->regs.si = ( ( unsigned ) __from_data16 ( syslinux_version ) );
00337                 ix86->regs.di = ( ( unsigned ) __from_data16 ( syslinux_copyright ) );
00338 
00339                 ix86->flags &= ~CF;
00340                 break;
00341 
00342         case 0x0002: /* Write String */
00343                 print_user_string ( ix86->segs.es, ix86->regs.bx, '\0' );
00344                 ix86->flags &= ~CF;
00345                 break;
00346 
00347         case 0x0003: /* Run command */
00348                 {
00349                         userptr_t cmd_u = real_to_user ( ix86->segs.es, ix86->regs.bx );
00350                         int len = strlen_user ( cmd_u, 0 );
00351                         char cmd[len + 1];
00352                         copy_from_user ( cmd, cmd_u, 0, len + 1 );
00353                         DBG ( "COMBOOT: executing command '%s'\n", cmd );
00354                         system ( cmd );
00355                         DBG ( "COMBOOT: exiting after executing command...\n" );
00356                         rmlongjmp ( comboot_return, COMBOOT_EXIT_COMMAND );
00357                 }
00358                 break;
00359 
00360         case 0x0004: /* Run default command */
00361                 /* FIXME: just exit for now */
00362                 rmlongjmp ( comboot_return, COMBOOT_EXIT_COMMAND );
00363                 break;
00364 
00365         case 0x0005: /* Force text mode */
00366                 comboot_force_text_mode ( );
00367                 ix86->flags &= ~CF;
00368                 break;
00369 
00370         case 0x0006: /* Open file */
00371                 {
00372                         int fd;
00373                         userptr_t file_u = real_to_user ( ix86->segs.es, ix86->regs.si );
00374                         int len = strlen_user ( file_u, 0 );
00375                         char file[len + 1];
00376 
00377                         copy_from_user ( file, file_u, 0, len + 1 );
00378 
00379                         if ( file[0] == '\0' ) {
00380                                 DBG ( "COMBOOT: attempted open with empty file name\n" );
00381                                 break;
00382                         }
00383 
00384                         DBG ( "COMBOOT: opening file '%s'\n", file );
00385 
00386                         fd = open ( file );
00387 
00388                         if ( fd < 0 ) {
00389                                 DBG ( "COMBOOT: error opening file %s\n", file );
00390                                 break;
00391                         }
00392 
00393                         /* This relies on the fact that a iPXE POSIX fd will
00394                          * always fit in 16 bits.
00395                          */
00396 #if (POSIX_FD_MAX > 65535)
00397 #error POSIX_FD_MAX too large
00398 #endif
00399                         ix86->regs.si = (uint16_t) fd;
00400 
00401                         ix86->regs.cx = COMBOOT_FILE_BLOCKSZ;
00402                         ix86->regs.eax = fsize ( fd );
00403                         ix86->flags &= ~CF;
00404                 }
00405                 break;
00406 
00407         case 0x0007: /* Read file */
00408                 {
00409                         int fd = ix86->regs.si;
00410                         int len = ix86->regs.cx * COMBOOT_FILE_BLOCKSZ;
00411                         int rc;
00412                         fd_set fds;
00413                         userptr_t buf = real_to_user ( ix86->segs.es, ix86->regs.bx );
00414 
00415                         /* Wait for data ready to read */
00416                         FD_ZERO ( &fds );
00417                         FD_SET ( fd, &fds );
00418 
00419                         select ( &fds, 1 );
00420 
00421                         rc = read_user ( fd, buf, 0, len );
00422                         if ( rc < 0 ) {
00423                                 DBG ( "COMBOOT: read failed\n" );
00424                                 ix86->regs.si = 0;
00425                                 break;
00426                         }
00427 
00428                         ix86->regs.ecx = rc;
00429                         ix86->flags &= ~CF;
00430                 }
00431                 break;
00432 
00433         case 0x0008: /* Close file */
00434                 {
00435                         int fd = ix86->regs.si;
00436                         close ( fd );
00437                         ix86->flags &= ~CF;
00438                 }
00439                 break;
00440 
00441         case 0x0009: /* Call PXE Stack */
00442                 if ( pxe_api_call_weak ( ix86 ) != 0 )
00443                         ix86->flags |= CF;
00444                 else
00445                         ix86->flags &= ~CF;
00446                 break;
00447 
00448         case 0x000A: /* Get Derivative-Specific Information */
00449 
00450                 /* iPXE has its own derivative ID, so there is no defined
00451                  * output here; just return AL for now */
00452                 ix86->regs.al = BZI_LOADER_TYPE_IPXE;
00453                 ix86->flags &= ~CF;
00454                 break;
00455 
00456         case 0x000B: /* Get Serial Console Configuration */
00457                 if ( serial_console.base ) {
00458                         ix86->regs.dx = ( ( intptr_t ) serial_console.base );
00459                         ix86->regs.cx = serial_console.divisor;
00460                         ix86->regs.bx = 0;
00461                         ix86->flags &= ~CF;
00462                 }
00463                 break;
00464 
00465         case 0x000C: /* Perform final cleanup */
00466                 shutdown_boot();
00467                 break;
00468 
00469         case 0x000E: /* Get configuration file name */
00470                 /* FIXME: stub */
00471                 ix86->segs.es = rm_ds;
00472                 ix86->regs.bx = ( ( unsigned ) __from_data16 ( syslinux_configuration_file ) );
00473                 ix86->flags &= ~CF;
00474                 break;
00475 
00476         case 0x000F: /* Get IPAPPEND strings */
00477                 /* FIXME: stub */
00478                 ix86->regs.cx = 0;
00479                 ix86->segs.es = 0;
00480                 ix86->regs.bx = 0;
00481                 ix86->flags &= ~CF;
00482                 break;
00483 
00484         case 0x0010: /* Resolve hostname */
00485                 {
00486                         userptr_t hostname_u = real_to_user ( ix86->segs.es, ix86->regs.bx );
00487                         int len = strlen_user ( hostname_u, 0 );
00488                         char hostname[len];
00489                         struct in_addr addr;
00490 
00491                         copy_from_user ( hostname, hostname_u, 0, len + 1 );
00492 
00493                         /* TODO:
00494                          * "If the hostname does not contain a dot (.), the
00495                          * local domain name is automatically appended."
00496                          */
00497 
00498                         comboot_resolv ( hostname, &addr );
00499 
00500                         ix86->regs.eax = addr.s_addr;
00501                         ix86->flags &= ~CF;
00502                 }
00503                 break;
00504 
00505         case 0x0011: /* Maximum number of shuffle descriptors */
00506                 ix86->regs.cx = COMBOOT_MAX_SHUFFLE_DESCRIPTORS;
00507                 ix86->flags &= ~CF;
00508                 break;
00509 
00510         case 0x0012: /* Cleanup, shuffle and boot */
00511                 if ( ix86->regs.cx > COMBOOT_MAX_SHUFFLE_DESCRIPTORS )
00512                         break;
00513 
00514                 /* Perform final cleanup */
00515                 shutdown_boot();
00516 
00517                 /* Perform sequence of copies */
00518                 shuffle ( ix86->segs.es, ix86->regs.di, ix86->regs.cx );
00519 
00520                 /* Jump to real-mode entry point */
00521                 __asm__ __volatile__ (
00522                         REAL_CODE (
00523                                 "pushw %0\n\t"
00524                                 "popw %%ds\n\t"
00525                                 "pushl %1\n\t"
00526                                 "lret\n\t"
00527                         )
00528                         :
00529                         : "r" ( ix86->segs.ds ),
00530                           "r" ( ix86->regs.ebp ),
00531                           "d" ( ix86->regs.ebx ),
00532                           "S" ( ix86->regs.esi ) );
00533 
00534                 assert ( 0 ); /* Execution should never reach this point */
00535 
00536                 break;
00537 
00538         case 0x0013: /* Idle loop call */
00539                 step ( );
00540                 ix86->flags &= ~CF;
00541                 break;
00542 
00543         case 0x0015: /* Get feature flags */
00544                 ix86->segs.es = rm_ds;
00545                 ix86->regs.bx = ( ( unsigned ) __from_data16 ( &comboot_feature_flags ) );
00546                 ix86->regs.cx = 1; /* Number of feature flag bytes */
00547                 ix86->flags &= ~CF;
00548                 break;
00549 
00550         case 0x0016: /* Run kernel image */
00551                 {
00552                         userptr_t file_u = real_to_user ( ix86->segs.ds, ix86->regs.si );
00553                         userptr_t cmd_u = real_to_user ( ix86->segs.es, ix86->regs.bx );
00554                         int file_len = strlen_user ( file_u, 0 );
00555                         int cmd_len = strlen_user ( cmd_u, 0 );
00556                         char file[file_len + 1];
00557                         char cmd[cmd_len + 1];
00558 
00559                         copy_from_user ( file, file_u, 0, file_len + 1 );
00560                         copy_from_user ( cmd, cmd_u, 0, cmd_len + 1 );
00561 
00562                         DBG ( "COMBOOT: run kernel %s %s\n", file, cmd );
00563                         comboot_fetch_kernel ( file, cmd );
00564                         /* Technically, we should return if we
00565                          * couldn't load the kernel, but it's not safe
00566                          * to do that since we have just overwritten
00567                          * part of the COMBOOT program's memory space.
00568                          */
00569                         DBG ( "COMBOOT: exiting to run kernel...\n" );
00570                         rmlongjmp ( comboot_return, COMBOOT_EXIT_RUN_KERNEL );
00571                 }
00572                 break;
00573 
00574         case 0x0017: /* Report video mode change */
00575                 comboot_graphics_mode = ix86->regs.bx;
00576                 ix86->flags &= ~CF;
00577                 break;
00578 
00579         case 0x0018: /* Query custom font */
00580                 /* FIXME: stub */
00581                 ix86->regs.al = 0;
00582                 ix86->segs.es = 0;
00583                 ix86->regs.bx = 0;
00584                 ix86->flags &= ~CF;
00585                 break;
00586 
00587         case 0x001B: /* Cleanup, shuffle and boot to real mode */
00588                 if ( ix86->regs.cx > COMBOOT_MAX_SHUFFLE_DESCRIPTORS )
00589                         break;
00590 
00591                 /* Perform final cleanup */
00592                 shutdown_boot();
00593 
00594                 /* Perform sequence of copies */
00595                 shuffle ( ix86->segs.es, ix86->regs.di, ix86->regs.cx );
00596 
00597                 /* Copy initial register values to .text16 */
00598                 memcpy_user ( real_to_user ( rm_cs, (unsigned) __from_text16 ( &comboot_initial_regs ) ), 0,
00599                               real_to_user ( ix86->segs.ds, ix86->regs.si ), 0,
00600                               sizeof(syslinux_rm_regs) );
00601 
00602                 /* Load initial register values */
00603                 __asm__ __volatile__ (
00604                         REAL_CODE (
00605                                 /* Point SS:SP at the register value structure */
00606                                 "pushw %%cs\n\t"
00607                                 "popw %%ss\n\t"
00608                                 "movw $comboot_initial_regs, %%sp\n\t"
00609 
00610                                 /* Segment registers */
00611                                 "popw %%es\n\t"
00612                                 "popw %%ax\n\t" /* Skip CS */
00613                                 "popw %%ds\n\t"
00614                                 "popw %%ax\n\t" /* Skip SS for now */
00615                                 "popw %%fs\n\t"
00616                                 "popw %%gs\n\t"
00617 
00618                                 /* GP registers */
00619                                 "popl %%eax\n\t"
00620                                 "popl %%ecx\n\t"
00621                                 "popl %%edx\n\t"
00622                                 "popl %%ebx\n\t"
00623                                 "popl %%ebp\n\t" /* Skip ESP for now */
00624                                 "popl %%ebp\n\t"
00625                                 "popl %%esi\n\t"
00626                                 "popl %%edi\n\t"
00627 
00628                                 /* Load correct SS:ESP */
00629                                 "movw $(comboot_initial_regs + 6), %%sp\n\t"
00630                                 "popw %%ss\n\t"
00631                                 "movl %%cs:(comboot_initial_regs + 28), %%esp\n\t"
00632 
00633                                 "ljmp *%%cs:(comboot_initial_regs + 44)\n\t"
00634                         )
00635                         : : );
00636 
00637                 break;
00638 
00639         case 0x001C: /* Get pointer to auxilliary data vector */
00640                 /* FIXME: stub */
00641                 ix86->regs.cx = 0; /* Size of the ADV */
00642                 ix86->flags &= ~CF;
00643                 break;
00644 
00645         case 0x001D: /* Write auxilliary data vector */
00646                 /* FIXME: stub */
00647                 ix86->flags &= ~CF;
00648                 break;
00649 
00650         default:
00651                 DBG ( "COMBOOT unknown int22 function %04x\n", ix86->regs.ax );
00652                 break;
00653         }
00654 }
00655 
00656 /**
00657  * Hook BIOS interrupts related to COMBOOT API (INT 20h, 21h, 22h)
00658  */
00659 void hook_comboot_interrupts ( ) {
00660 
00661         __asm__ __volatile__ (
00662                 TEXT16_CODE ( "\nint20_wrapper:\n\t"
00663                               VIRT_CALL ( int20 )
00664                               "clc\n\t"
00665                               "call patch_cf\n\t"
00666                               "iret\n\t" ) : );
00667 
00668         hook_bios_interrupt ( 0x20, ( intptr_t ) int20_wrapper, &int20_vector );
00669 
00670         __asm__ __volatile__ (
00671                 TEXT16_CODE ( "\nint21_wrapper:\n\t"
00672                               VIRT_CALL ( int21 )
00673                               "clc\n\t"
00674                               "call patch_cf\n\t"
00675                               "iret\n\t" ) : );
00676 
00677         hook_bios_interrupt ( 0x21, ( intptr_t ) int21_wrapper, &int21_vector );
00678 
00679         __asm__  __volatile__ (
00680                 TEXT16_CODE ( "\nint22_wrapper:\n\t"
00681                               VIRT_CALL ( int22 )
00682                               "clc\n\t"
00683                               "call patch_cf\n\t"
00684                               "iret\n\t" ) : );
00685 
00686         hook_bios_interrupt ( 0x22, ( intptr_t ) int22_wrapper, &int22_vector );
00687 }
00688 
00689 /**
00690  * Unhook BIOS interrupts related to COMBOOT API (INT 20h, 21h, 22h)
00691  */
00692 void unhook_comboot_interrupts ( ) {
00693 
00694         unhook_bios_interrupt ( 0x20, ( intptr_t ) int20_wrapper,
00695                                 &int20_vector );
00696 
00697         unhook_bios_interrupt ( 0x21, ( intptr_t ) int21_wrapper,
00698                                 &int21_vector );
00699 
00700         unhook_bios_interrupt ( 0x22, ( intptr_t ) int22_wrapper,
00701                                 &int22_vector );
00702 }
00703 
00704 /* Avoid dragging in serial console support unconditionally */
00705 struct uart serial_console __attribute__ (( weak ));