PageRenderTime 27ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/src/arch/x86/interface/syslinux/comboot_call.c

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