You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

comboot_call.c 18KB

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