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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  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 <ipxe/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. /* 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. char *initrd_file;
  143. int rc;
  144. /* Find initrd= parameter, if any */
  145. if ( ( initrd_file = strstr ( cmdline, "initrd=" ) ) != NULL ) {
  146. char *initrd_end;
  147. /* skip "initrd=" */
  148. initrd_file += 7;
  149. /* Find terminating space, if any, and replace with NUL */
  150. initrd_end = strchr ( initrd_file, ' ' );
  151. if ( initrd_end )
  152. *initrd_end = '\0';
  153. DBG ( "COMBOOT: fetching initrd '%s'\n", initrd_file );
  154. /* Fetch initrd */
  155. if ( ( rc = imgdownload_string ( initrd_file, NULL, NULL,
  156. register_and_put_image ))!=0){
  157. DBG ( "COMBOOT: could not fetch initrd: %s\n",
  158. strerror ( rc ) );
  159. return rc;
  160. }
  161. /* Restore space after initrd name, if applicable */
  162. if ( initrd_end )
  163. *initrd_end = ' ';
  164. }
  165. DBG ( "COMBOOT: fetching kernel '%s'\n", kernel_file );
  166. /* Allocate and fetch kernel */
  167. if ( ( rc = imgdownload_string ( kernel_file, NULL, cmdline,
  168. register_and_replace_image ) ) != 0 ) {
  169. DBG ( "COMBOOT: could not fetch kernel: %s\n",
  170. strerror ( rc ) );
  171. return rc;
  172. }
  173. return 0;
  174. }
  175. /**
  176. * Terminate program interrupt handler
  177. */
  178. static __asmcall void int20 ( struct i386_all_regs *ix86 __unused ) {
  179. rmlongjmp ( comboot_return, COMBOOT_EXIT );
  180. }
  181. /**
  182. * DOS-compatible API
  183. */
  184. static __asmcall void int21 ( struct i386_all_regs *ix86 ) {
  185. ix86->flags |= CF;
  186. switch ( ix86->regs.ah ) {
  187. case 0x00:
  188. case 0x4C: /* Terminate program */
  189. rmlongjmp ( comboot_return, COMBOOT_EXIT );
  190. break;
  191. case 0x01: /* Get Key with Echo */
  192. case 0x08: /* Get Key without Echo */
  193. /* TODO: handle extended characters? */
  194. ix86->regs.al = getchar( );
  195. /* Enter */
  196. if ( ix86->regs.al == 0x0A )
  197. ix86->regs.al = 0x0D;
  198. if ( ix86->regs.ah == 0x01 )
  199. putchar ( ix86->regs.al );
  200. ix86->flags &= ~CF;
  201. break;
  202. case 0x02: /* Write Character */
  203. putchar ( ix86->regs.dl );
  204. ix86->flags &= ~CF;
  205. break;
  206. case 0x04: /* Write Character to Serial Port */
  207. serial_putc ( ix86->regs.dl );
  208. ix86->flags &= ~CF;
  209. break;
  210. case 0x09: /* Write DOS String to Console */
  211. print_user_string ( ix86->segs.ds, ix86->regs.dx, '$' );
  212. ix86->flags &= ~CF;
  213. break;
  214. case 0x0B: /* Check Keyboard */
  215. if ( iskey() )
  216. ix86->regs.al = 0xFF;
  217. else
  218. ix86->regs.al = 0x00;
  219. ix86->flags &= ~CF;
  220. break;
  221. case 0x30: /* Check DOS Version */
  222. /* Bottom halves all 0; top halves spell "SYSLINUX" */
  223. ix86->regs.eax = 0x59530000;
  224. ix86->regs.ebx = 0x4C530000;
  225. ix86->regs.ecx = 0x4E490000;
  226. ix86->regs.edx = 0x58550000;
  227. ix86->flags &= ~CF;
  228. break;
  229. default:
  230. DBG ( "COMBOOT unknown int21 function %02x\n", ix86->regs.ah );
  231. break;
  232. }
  233. }
  234. /**
  235. * Dispatch PXE API call weakly
  236. *
  237. * @v ix86 Registers for PXE call
  238. * @ret present Zero if the PXE stack is present, nonzero if not
  239. *
  240. * A successful return only indicates that the PXE stack was available
  241. * for dispatching the call; it says nothing about the success of
  242. * whatever the call asked for.
  243. */
  244. __weak int pxe_api_call_weak ( struct i386_all_regs *ix86 __unused ) {
  245. return -1;
  246. }
  247. /**
  248. * SYSLINUX API
  249. */
  250. static __asmcall void int22 ( struct i386_all_regs *ix86 ) {
  251. ix86->flags |= CF;
  252. switch ( ix86->regs.ax ) {
  253. case 0x0001: /* Get Version */
  254. /* Number of INT 22h API functions available */
  255. ix86->regs.ax = 0x001D;
  256. /* SYSLINUX version number */
  257. ix86->regs.ch = 0; /* major */
  258. ix86->regs.cl = 0; /* minor */
  259. /* SYSLINUX derivative ID */
  260. ix86->regs.dl = BZI_LOADER_TYPE_IPXE;
  261. /* SYSLINUX version and copyright strings */
  262. ix86->segs.es = rm_ds;
  263. ix86->regs.si = ( ( unsigned ) __from_data16 ( syslinux_version ) );
  264. ix86->regs.di = ( ( unsigned ) __from_data16 ( syslinux_copyright ) );
  265. ix86->flags &= ~CF;
  266. break;
  267. case 0x0002: /* Write String */
  268. print_user_string ( ix86->segs.es, ix86->regs.bx, '\0' );
  269. ix86->flags &= ~CF;
  270. break;
  271. case 0x0003: /* Run command */
  272. {
  273. userptr_t cmd_u = real_to_user ( ix86->segs.es, ix86->regs.bx );
  274. int len = strlen_user ( cmd_u, 0 );
  275. char cmd[len + 1];
  276. copy_from_user ( cmd, cmd_u, 0, len + 1 );
  277. DBG ( "COMBOOT: executing command '%s'\n", cmd );
  278. system ( cmd );
  279. DBG ( "COMBOOT: exiting after executing command...\n" );
  280. rmlongjmp ( comboot_return, COMBOOT_EXIT_COMMAND );
  281. }
  282. break;
  283. case 0x0004: /* Run default command */
  284. /* FIXME: just exit for now */
  285. rmlongjmp ( comboot_return, COMBOOT_EXIT_COMMAND );
  286. break;
  287. case 0x0005: /* Force text mode */
  288. comboot_force_text_mode ( );
  289. ix86->flags &= ~CF;
  290. break;
  291. case 0x0006: /* Open file */
  292. {
  293. int fd;
  294. userptr_t file_u = real_to_user ( ix86->segs.es, ix86->regs.si );
  295. int len = strlen_user ( file_u, 0 );
  296. char file[len + 1];
  297. copy_from_user ( file, file_u, 0, len + 1 );
  298. if ( file[0] == '\0' ) {
  299. DBG ( "COMBOOT: attempted open with empty file name\n" );
  300. break;
  301. }
  302. DBG ( "COMBOOT: opening file '%s'\n", file );
  303. fd = open ( file );
  304. if ( fd < 0 ) {
  305. DBG ( "COMBOOT: error opening file %s\n", file );
  306. break;
  307. }
  308. /* This relies on the fact that a iPXE POSIX fd will
  309. * always fit in 16 bits.
  310. */
  311. #if (POSIX_FD_MAX > 65535)
  312. #error POSIX_FD_MAX too large
  313. #endif
  314. ix86->regs.si = (uint16_t) fd;
  315. ix86->regs.cx = COMBOOT_FILE_BLOCKSZ;
  316. ix86->regs.eax = fsize ( fd );
  317. ix86->flags &= ~CF;
  318. }
  319. break;
  320. case 0x0007: /* Read file */
  321. {
  322. int fd = ix86->regs.si;
  323. int len = ix86->regs.cx * COMBOOT_FILE_BLOCKSZ;
  324. int rc;
  325. fd_set fds;
  326. userptr_t buf = real_to_user ( ix86->segs.es, ix86->regs.bx );
  327. /* Wait for data ready to read */
  328. FD_ZERO ( &fds );
  329. FD_SET ( fd, &fds );
  330. select ( &fds, 1 );
  331. rc = read_user ( fd, buf, 0, len );
  332. if ( rc < 0 ) {
  333. DBG ( "COMBOOT: read failed\n" );
  334. ix86->regs.si = 0;
  335. break;
  336. }
  337. ix86->regs.ecx = rc;
  338. ix86->flags &= ~CF;
  339. }
  340. break;
  341. case 0x0008: /* Close file */
  342. {
  343. int fd = ix86->regs.si;
  344. close ( fd );
  345. ix86->flags &= ~CF;
  346. }
  347. break;
  348. case 0x0009: /* Call PXE Stack */
  349. if ( pxe_api_call_weak ( ix86 ) != 0 )
  350. ix86->flags |= CF;
  351. else
  352. ix86->flags &= ~CF;
  353. break;
  354. case 0x000A: /* Get Derivative-Specific Information */
  355. /* iPXE has its own derivative ID, so there is no defined
  356. * output here; just return AL for now */
  357. ix86->regs.al = BZI_LOADER_TYPE_IPXE;
  358. ix86->flags &= ~CF;
  359. break;
  360. case 0x000B: /* Get Serial Console Configuration */
  361. #if defined(CONSOLE_SERIAL) && !defined(COMPRESERVE)
  362. ix86->regs.dx = COMCONSOLE;
  363. ix86->regs.cx = 115200 / COMSPEED;
  364. ix86->regs.bx = 0;
  365. #else
  366. ix86->regs.dx = 0;
  367. #endif
  368. ix86->flags &= ~CF;
  369. break;
  370. case 0x000E: /* Get configuration file name */
  371. /* FIXME: stub */
  372. ix86->segs.es = rm_ds;
  373. ix86->regs.bx = ( ( unsigned ) __from_data16 ( syslinux_configuration_file ) );
  374. ix86->flags &= ~CF;
  375. break;
  376. case 0x000F: /* Get IPAPPEND strings */
  377. /* FIXME: stub */
  378. ix86->regs.cx = 0;
  379. ix86->segs.es = 0;
  380. ix86->regs.bx = 0;
  381. ix86->flags &= ~CF;
  382. break;
  383. case 0x0010: /* Resolve hostname */
  384. {
  385. userptr_t hostname_u = real_to_user ( ix86->segs.es, ix86->regs.bx );
  386. int len = strlen_user ( hostname_u, 0 );
  387. char hostname[len];
  388. struct in_addr addr;
  389. copy_from_user ( hostname, hostname_u, 0, len + 1 );
  390. /* TODO:
  391. * "If the hostname does not contain a dot (.), the
  392. * local domain name is automatically appended."
  393. */
  394. comboot_resolv ( hostname, &addr );
  395. ix86->regs.eax = addr.s_addr;
  396. ix86->flags &= ~CF;
  397. }
  398. break;
  399. case 0x0011: /* Maximum number of shuffle descriptors */
  400. ix86->regs.cx = COMBOOT_MAX_SHUFFLE_DESCRIPTORS;
  401. ix86->flags &= ~CF;
  402. break;
  403. case 0x0012: /* Cleanup, shuffle and boot */
  404. if ( ix86->regs.cx > COMBOOT_MAX_SHUFFLE_DESCRIPTORS )
  405. break;
  406. /* Perform final cleanup */
  407. shutdown_boot();
  408. /* Perform sequence of copies */
  409. shuffle ( ix86->segs.es, ix86->regs.di, ix86->regs.cx );
  410. /* Jump to real-mode entry point */
  411. __asm__ __volatile__ (
  412. REAL_CODE (
  413. "pushw %0\n\t"
  414. "popw %%ds\n\t"
  415. "pushl %1\n\t"
  416. "lret\n\t"
  417. )
  418. :
  419. : "r" ( ix86->segs.ds ),
  420. "r" ( ix86->regs.ebp ),
  421. "d" ( ix86->regs.ebx ),
  422. "S" ( ix86->regs.esi ) );
  423. assert ( 0 ); /* Execution should never reach this point */
  424. break;
  425. case 0x0013: /* Idle loop call */
  426. step ( );
  427. ix86->flags &= ~CF;
  428. break;
  429. case 0x0015: /* Get feature flags */
  430. ix86->segs.es = rm_ds;
  431. ix86->regs.bx = ( ( unsigned ) __from_data16 ( &comboot_feature_flags ) );
  432. ix86->regs.cx = 1; /* Number of feature flag bytes */
  433. ix86->flags &= ~CF;
  434. break;
  435. case 0x0016: /* Run kernel image */
  436. {
  437. userptr_t file_u = real_to_user ( ix86->segs.ds, ix86->regs.si );
  438. userptr_t cmd_u = real_to_user ( ix86->segs.es, ix86->regs.bx );
  439. int file_len = strlen_user ( file_u, 0 );
  440. int cmd_len = strlen_user ( cmd_u, 0 );
  441. char file[file_len + 1];
  442. char cmd[cmd_len + 1];
  443. copy_from_user ( file, file_u, 0, file_len + 1 );
  444. copy_from_user ( cmd, cmd_u, 0, cmd_len + 1 );
  445. DBG ( "COMBOOT: run kernel %s %s\n", file, cmd );
  446. comboot_fetch_kernel ( file, cmd );
  447. /* Technically, we should return if we
  448. * couldn't load the kernel, but it's not safe
  449. * to do that since we have just overwritten
  450. * part of the COMBOOT program's memory space.
  451. */
  452. DBG ( "COMBOOT: exiting to run kernel...\n" );
  453. rmlongjmp ( comboot_return, COMBOOT_EXIT_RUN_KERNEL );
  454. }
  455. break;
  456. case 0x0017: /* Report video mode change */
  457. comboot_graphics_mode = ix86->regs.bx;
  458. ix86->flags &= ~CF;
  459. break;
  460. case 0x0018: /* Query custom font */
  461. /* FIXME: stub */
  462. ix86->regs.al = 0;
  463. ix86->segs.es = 0;
  464. ix86->regs.bx = 0;
  465. ix86->flags &= ~CF;
  466. break;
  467. case 0x001B: /* Cleanup, shuffle and boot to real mode */
  468. if ( ix86->regs.cx > COMBOOT_MAX_SHUFFLE_DESCRIPTORS )
  469. break;
  470. /* Perform final cleanup */
  471. shutdown_boot();
  472. /* Perform sequence of copies */
  473. shuffle ( ix86->segs.es, ix86->regs.di, ix86->regs.cx );
  474. /* Copy initial register values to .text16 */
  475. memcpy_user ( real_to_user ( rm_cs, (unsigned) __from_text16 ( &comboot_initial_regs ) ), 0,
  476. real_to_user ( ix86->segs.ds, ix86->regs.si ), 0,
  477. sizeof(syslinux_rm_regs) );
  478. /* Load initial register values */
  479. __asm__ __volatile__ (
  480. REAL_CODE (
  481. /* Point SS:SP at the register value structure */
  482. "pushw %%cs\n\t"
  483. "popw %%ss\n\t"
  484. "movw $comboot_initial_regs, %%sp\n\t"
  485. /* Segment registers */
  486. "popw %%es\n\t"
  487. "popw %%ax\n\t" /* Skip CS */
  488. "popw %%ds\n\t"
  489. "popw %%ax\n\t" /* Skip SS for now */
  490. "popw %%fs\n\t"
  491. "popw %%gs\n\t"
  492. /* GP registers */
  493. "popl %%eax\n\t"
  494. "popl %%ecx\n\t"
  495. "popl %%edx\n\t"
  496. "popl %%ebx\n\t"
  497. "popl %%ebp\n\t" /* Skip ESP for now */
  498. "popl %%ebp\n\t"
  499. "popl %%esi\n\t"
  500. "popl %%edi\n\t"
  501. /* Load correct SS:ESP */
  502. "movw $(comboot_initial_regs + 6), %%sp\n\t"
  503. "popw %%ss\n\t"
  504. "movl %%cs:(comboot_initial_regs + 28), %%esp\n\t"
  505. "ljmp *%%cs:(comboot_initial_regs + 44)\n\t"
  506. )
  507. : : );
  508. break;
  509. case 0x001C: /* Get pointer to auxilliary data vector */
  510. /* FIXME: stub */
  511. ix86->regs.cx = 0; /* Size of the ADV */
  512. ix86->flags &= ~CF;
  513. break;
  514. case 0x001D: /* Write auxilliary data vector */
  515. /* FIXME: stub */
  516. ix86->flags &= ~CF;
  517. break;
  518. default:
  519. DBG ( "COMBOOT unknown int22 function %04x\n", ix86->regs.ax );
  520. break;
  521. }
  522. }
  523. /**
  524. * Hook BIOS interrupts related to COMBOOT API (INT 20h, 21h, 22h)
  525. */
  526. void hook_comboot_interrupts ( ) {
  527. __asm__ __volatile__ (
  528. TEXT16_CODE ( "\nint20_wrapper:\n\t"
  529. "pushl %0\n\t"
  530. "pushw %%cs\n\t"
  531. "call prot_call\n\t"
  532. "addw $4, %%sp\n\t"
  533. "call patch_cf\n\t"
  534. "iret\n\t" )
  535. : : "i" ( int20 ) );
  536. hook_bios_interrupt ( 0x20, ( unsigned int ) int20_wrapper,
  537. &int20_vector );
  538. __asm__ __volatile__ (
  539. TEXT16_CODE ( "\nint21_wrapper:\n\t"
  540. "pushl %0\n\t"
  541. "pushw %%cs\n\t"
  542. "call prot_call\n\t"
  543. "addw $4, %%sp\n\t"
  544. "call patch_cf\n\t"
  545. "iret\n\t" )
  546. : : "i" ( int21 ) );
  547. hook_bios_interrupt ( 0x21, ( unsigned int ) int21_wrapper,
  548. &int21_vector );
  549. __asm__ __volatile__ (
  550. TEXT16_CODE ( "\nint22_wrapper:\n\t"
  551. "pushl %0\n\t"
  552. "pushw %%cs\n\t"
  553. "call prot_call\n\t"
  554. "addw $4, %%sp\n\t"
  555. "call patch_cf\n\t"
  556. "iret\n\t" )
  557. : : "i" ( int22) );
  558. hook_bios_interrupt ( 0x22, ( unsigned int ) int22_wrapper,
  559. &int22_vector );
  560. }
  561. /**
  562. * Unhook BIOS interrupts related to COMBOOT API (INT 20h, 21h, 22h)
  563. */
  564. void unhook_comboot_interrupts ( ) {
  565. unhook_bios_interrupt ( 0x20, ( unsigned int ) int20_wrapper,
  566. &int20_vector );
  567. unhook_bios_interrupt ( 0x21, ( unsigned int ) int21_wrapper,
  568. &int21_vector );
  569. unhook_bios_interrupt ( 0x22, ( unsigned int ) int22_wrapper,
  570. &int22_vector );
  571. }