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 17KB

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