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

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