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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  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. * Dispatch PXE API call weakly
  267. *
  268. * @v ix86 Registers for PXE call
  269. * @ret present Zero if the PXE stack is present, nonzero if not
  270. *
  271. * A successful return only indicates that the PXE stack was available
  272. * for dispatching the call; it says nothing about the success of
  273. * whatever the call asked for.
  274. */
  275. __weak int pxe_api_call_weak ( struct i386_all_regs *ix86 __unused ) {
  276. return -1;
  277. }
  278. /**
  279. * SYSLINUX API
  280. */
  281. static __asmcall void int22 ( struct i386_all_regs *ix86 ) {
  282. ix86->flags |= CF;
  283. switch ( ix86->regs.ax ) {
  284. case 0x0001: /* Get Version */
  285. /* Number of INT 22h API functions available */
  286. ix86->regs.ax = 0x001D;
  287. /* SYSLINUX version number */
  288. ix86->regs.ch = 0; /* major */
  289. ix86->regs.cl = 0; /* minor */
  290. /* SYSLINUX derivative ID */
  291. ix86->regs.dl = BZI_LOADER_TYPE_IPXE;
  292. /* SYSLINUX version and copyright strings */
  293. ix86->segs.es = rm_ds;
  294. ix86->regs.si = ( ( unsigned ) __from_data16 ( syslinux_version ) );
  295. ix86->regs.di = ( ( unsigned ) __from_data16 ( syslinux_copyright ) );
  296. ix86->flags &= ~CF;
  297. break;
  298. case 0x0002: /* Write String */
  299. print_user_string ( ix86->segs.es, ix86->regs.bx, '\0' );
  300. ix86->flags &= ~CF;
  301. break;
  302. case 0x0003: /* Run command */
  303. {
  304. userptr_t cmd_u = real_to_user ( ix86->segs.es, ix86->regs.bx );
  305. int len = strlen_user ( cmd_u, 0 );
  306. char cmd[len + 1];
  307. copy_from_user ( cmd, cmd_u, 0, len + 1 );
  308. DBG ( "COMBOOT: executing command '%s'\n", cmd );
  309. system ( cmd );
  310. DBG ( "COMBOOT: exiting after executing command...\n" );
  311. rmlongjmp ( comboot_return, COMBOOT_EXIT_COMMAND );
  312. }
  313. break;
  314. case 0x0004: /* Run default command */
  315. /* FIXME: just exit for now */
  316. rmlongjmp ( comboot_return, COMBOOT_EXIT_COMMAND );
  317. break;
  318. case 0x0005: /* Force text mode */
  319. comboot_force_text_mode ( );
  320. ix86->flags &= ~CF;
  321. break;
  322. case 0x0006: /* Open file */
  323. {
  324. int fd;
  325. userptr_t file_u = real_to_user ( ix86->segs.es, ix86->regs.si );
  326. int len = strlen_user ( file_u, 0 );
  327. char file[len + 1];
  328. copy_from_user ( file, file_u, 0, len + 1 );
  329. if ( file[0] == '\0' ) {
  330. DBG ( "COMBOOT: attempted open with empty file name\n" );
  331. break;
  332. }
  333. DBG ( "COMBOOT: opening file '%s'\n", file );
  334. fd = open ( file );
  335. if ( fd < 0 ) {
  336. DBG ( "COMBOOT: error opening file %s\n", file );
  337. break;
  338. }
  339. /* This relies on the fact that a iPXE POSIX fd will
  340. * always fit in 16 bits.
  341. */
  342. #if (POSIX_FD_MAX > 65535)
  343. #error POSIX_FD_MAX too large
  344. #endif
  345. ix86->regs.si = (uint16_t) fd;
  346. ix86->regs.cx = COMBOOT_FILE_BLOCKSZ;
  347. ix86->regs.eax = fsize ( fd );
  348. ix86->flags &= ~CF;
  349. }
  350. break;
  351. case 0x0007: /* Read file */
  352. {
  353. int fd = ix86->regs.si;
  354. int len = ix86->regs.cx * COMBOOT_FILE_BLOCKSZ;
  355. int rc;
  356. fd_set fds;
  357. userptr_t buf = real_to_user ( ix86->segs.es, ix86->regs.bx );
  358. /* Wait for data ready to read */
  359. FD_ZERO ( &fds );
  360. FD_SET ( fd, &fds );
  361. select ( &fds, 1 );
  362. rc = read_user ( fd, buf, 0, len );
  363. if ( rc < 0 ) {
  364. DBG ( "COMBOOT: read failed\n" );
  365. ix86->regs.si = 0;
  366. break;
  367. }
  368. ix86->regs.ecx = rc;
  369. ix86->flags &= ~CF;
  370. }
  371. break;
  372. case 0x0008: /* Close file */
  373. {
  374. int fd = ix86->regs.si;
  375. close ( fd );
  376. ix86->flags &= ~CF;
  377. }
  378. break;
  379. case 0x0009: /* Call PXE Stack */
  380. if ( pxe_api_call_weak ( ix86 ) != 0 )
  381. ix86->flags |= CF;
  382. else
  383. ix86->flags &= ~CF;
  384. break;
  385. case 0x000A: /* Get Derivative-Specific Information */
  386. /* iPXE has its own derivative ID, so there is no defined
  387. * output here; just return AL for now */
  388. ix86->regs.al = BZI_LOADER_TYPE_IPXE;
  389. ix86->flags &= ~CF;
  390. break;
  391. case 0x000B: /* Get Serial Console Configuration */
  392. #if defined(CONSOLE_SERIAL) && !defined(COMPRESERVE)
  393. ix86->regs.dx = COMCONSOLE;
  394. ix86->regs.cx = 115200 / COMSPEED;
  395. ix86->regs.bx = 0;
  396. #else
  397. ix86->regs.dx = 0;
  398. #endif
  399. ix86->flags &= ~CF;
  400. break;
  401. case 0x000E: /* Get configuration file name */
  402. /* FIXME: stub */
  403. ix86->segs.es = rm_ds;
  404. ix86->regs.bx = ( ( unsigned ) __from_data16 ( syslinux_configuration_file ) );
  405. ix86->flags &= ~CF;
  406. break;
  407. case 0x000F: /* Get IPAPPEND strings */
  408. /* FIXME: stub */
  409. ix86->regs.cx = 0;
  410. ix86->segs.es = 0;
  411. ix86->regs.bx = 0;
  412. ix86->flags &= ~CF;
  413. break;
  414. case 0x0010: /* Resolve hostname */
  415. {
  416. userptr_t hostname_u = real_to_user ( ix86->segs.es, ix86->regs.bx );
  417. int len = strlen_user ( hostname_u, 0 );
  418. char hostname[len];
  419. struct in_addr addr;
  420. copy_from_user ( hostname, hostname_u, 0, len + 1 );
  421. /* TODO:
  422. * "If the hostname does not contain a dot (.), the
  423. * local domain name is automatically appended."
  424. */
  425. comboot_resolv ( hostname, &addr );
  426. ix86->regs.eax = addr.s_addr;
  427. ix86->flags &= ~CF;
  428. }
  429. break;
  430. case 0x0011: /* Maximum number of shuffle descriptors */
  431. ix86->regs.cx = COMBOOT_MAX_SHUFFLE_DESCRIPTORS;
  432. ix86->flags &= ~CF;
  433. break;
  434. case 0x0012: /* Cleanup, shuffle and boot */
  435. if ( ix86->regs.cx > COMBOOT_MAX_SHUFFLE_DESCRIPTORS )
  436. break;
  437. /* Perform final cleanup */
  438. shutdown ( SHUTDOWN_BOOT );
  439. /* Perform sequence of copies */
  440. shuffle ( ix86->segs.es, ix86->regs.di, ix86->regs.cx );
  441. /* Jump to real-mode entry point */
  442. __asm__ __volatile__ (
  443. REAL_CODE (
  444. "pushw %0\n\t"
  445. "popw %%ds\n\t"
  446. "pushl %1\n\t"
  447. "lret\n\t"
  448. )
  449. :
  450. : "r" ( ix86->segs.ds ),
  451. "r" ( ix86->regs.ebp ),
  452. "d" ( ix86->regs.ebx ),
  453. "S" ( ix86->regs.esi ) );
  454. assert ( 0 ); /* Execution should never reach this point */
  455. break;
  456. case 0x0013: /* Idle loop call */
  457. step ( );
  458. ix86->flags &= ~CF;
  459. break;
  460. case 0x0015: /* Get feature flags */
  461. ix86->segs.es = rm_ds;
  462. ix86->regs.bx = ( ( unsigned ) __from_data16 ( &comboot_feature_flags ) );
  463. ix86->regs.cx = 1; /* Number of feature flag bytes */
  464. ix86->flags &= ~CF;
  465. break;
  466. case 0x0016: /* Run kernel image */
  467. {
  468. userptr_t file_u = real_to_user ( ix86->segs.ds, ix86->regs.si );
  469. userptr_t cmd_u = real_to_user ( ix86->segs.es, ix86->regs.bx );
  470. int file_len = strlen_user ( file_u, 0 );
  471. int cmd_len = strlen_user ( cmd_u, 0 );
  472. char file[file_len + 1];
  473. char cmd[cmd_len + 1];
  474. copy_from_user ( file, file_u, 0, file_len + 1 );
  475. copy_from_user ( cmd, cmd_u, 0, cmd_len + 1 );
  476. DBG ( "COMBOOT: run kernel %s %s\n", file, cmd );
  477. comboot_fetch_kernel ( file, cmd );
  478. /* Technically, we should return if we
  479. * couldn't load the kernel, but it's not safe
  480. * to do that since we have just overwritten
  481. * part of the COMBOOT program's memory space.
  482. */
  483. DBG ( "COMBOOT: exiting to run kernel...\n" );
  484. rmlongjmp ( comboot_return, COMBOOT_EXIT_RUN_KERNEL );
  485. }
  486. break;
  487. case 0x0017: /* Report video mode change */
  488. comboot_graphics_mode = ix86->regs.bx;
  489. ix86->flags &= ~CF;
  490. break;
  491. case 0x0018: /* Query custom font */
  492. /* FIXME: stub */
  493. ix86->regs.al = 0;
  494. ix86->segs.es = 0;
  495. ix86->regs.bx = 0;
  496. ix86->flags &= ~CF;
  497. break;
  498. case 0x001B: /* Cleanup, shuffle and boot to real mode */
  499. if ( ix86->regs.cx > COMBOOT_MAX_SHUFFLE_DESCRIPTORS )
  500. break;
  501. /* Perform final cleanup */
  502. shutdown ( SHUTDOWN_BOOT );
  503. /* Perform sequence of copies */
  504. shuffle ( ix86->segs.es, ix86->regs.di, ix86->regs.cx );
  505. /* Copy initial register values to .text16 */
  506. memcpy_user ( real_to_user ( rm_cs, (unsigned) __from_text16 ( &comboot_initial_regs ) ), 0,
  507. real_to_user ( ix86->segs.ds, ix86->regs.si ), 0,
  508. sizeof(syslinux_rm_regs) );
  509. /* Load initial register values */
  510. __asm__ __volatile__ (
  511. REAL_CODE (
  512. /* Point SS:SP at the register value structure */
  513. "pushw %%cs\n\t"
  514. "popw %%ss\n\t"
  515. "movw $comboot_initial_regs, %%sp\n\t"
  516. /* Segment registers */
  517. "popw %%es\n\t"
  518. "popw %%ax\n\t" /* Skip CS */
  519. "popw %%ds\n\t"
  520. "popw %%ax\n\t" /* Skip SS for now */
  521. "popw %%fs\n\t"
  522. "popw %%gs\n\t"
  523. /* GP registers */
  524. "popl %%eax\n\t"
  525. "popl %%ecx\n\t"
  526. "popl %%edx\n\t"
  527. "popl %%ebx\n\t"
  528. "popl %%ebp\n\t" /* Skip ESP for now */
  529. "popl %%ebp\n\t"
  530. "popl %%esi\n\t"
  531. "popl %%edi\n\t"
  532. /* Load correct SS:ESP */
  533. "movw $(comboot_initial_regs + 6), %%sp\n\t"
  534. "popw %%ss\n\t"
  535. "movl %%cs:(comboot_initial_regs + 28), %%esp\n\t"
  536. "ljmp *%%cs:(comboot_initial_regs + 44)\n\t"
  537. )
  538. : : );
  539. break;
  540. case 0x001C: /* Get pointer to auxilliary data vector */
  541. /* FIXME: stub */
  542. ix86->regs.cx = 0; /* Size of the ADV */
  543. ix86->flags &= ~CF;
  544. break;
  545. case 0x001D: /* Write auxilliary data vector */
  546. /* FIXME: stub */
  547. ix86->flags &= ~CF;
  548. break;
  549. default:
  550. DBG ( "COMBOOT unknown int22 function %04x\n", ix86->regs.ax );
  551. break;
  552. }
  553. }
  554. /**
  555. * Hook BIOS interrupts related to COMBOOT API (INT 20h, 21h, 22h)
  556. */
  557. void hook_comboot_interrupts ( ) {
  558. __asm__ __volatile__ (
  559. TEXT16_CODE ( "\nint20_wrapper:\n\t"
  560. "pushl %0\n\t"
  561. "pushw %%cs\n\t"
  562. "call prot_call\n\t"
  563. "addw $4, %%sp\n\t"
  564. "call patch_cf\n\t"
  565. "iret\n\t" )
  566. : : "i" ( int20 ) );
  567. hook_bios_interrupt ( 0x20, ( unsigned int ) int20_wrapper,
  568. &int20_vector );
  569. __asm__ __volatile__ (
  570. TEXT16_CODE ( "\nint21_wrapper:\n\t"
  571. "pushl %0\n\t"
  572. "pushw %%cs\n\t"
  573. "call prot_call\n\t"
  574. "addw $4, %%sp\n\t"
  575. "call patch_cf\n\t"
  576. "iret\n\t" )
  577. : : "i" ( int21 ) );
  578. hook_bios_interrupt ( 0x21, ( unsigned int ) int21_wrapper,
  579. &int21_vector );
  580. __asm__ __volatile__ (
  581. TEXT16_CODE ( "\nint22_wrapper:\n\t"
  582. "pushl %0\n\t"
  583. "pushw %%cs\n\t"
  584. "call prot_call\n\t"
  585. "addw $4, %%sp\n\t"
  586. "call patch_cf\n\t"
  587. "iret\n\t" )
  588. : : "i" ( int22) );
  589. hook_bios_interrupt ( 0x22, ( unsigned int ) int22_wrapper,
  590. &int22_vector );
  591. }
  592. /**
  593. * Unhook BIOS interrupts related to COMBOOT API (INT 20h, 21h, 22h)
  594. */
  595. void unhook_comboot_interrupts ( ) {
  596. unhook_bios_interrupt ( 0x20, ( unsigned int ) int20_wrapper,
  597. &int20_vector );
  598. unhook_bios_interrupt ( 0x21, ( unsigned int ) int21_wrapper,
  599. &int21_vector );
  600. unhook_bios_interrupt ( 0x22, ( unsigned int ) int22_wrapper,
  601. &int22_vector );
  602. }