iPXE
Data Structures | Macros | Functions | Variables
comboot_call.c File Reference
#include <errno.h>
#include <realmode.h>
#include <biosint.h>
#include <ipxe/console.h>
#include <stdlib.h>
#include <comboot.h>
#include <bzimage.h>
#include <pxe_call.h>
#include <rmsetjmp.h>
#include <string.h>
#include <ipxe/posix_io.h>
#include <ipxe/process.h>
#include <ipxe/serial.h>
#include <ipxe/ns16550.h>
#include <ipxe/init.h>
#include <ipxe/image.h>
#include <ipxe/version.h>
#include <usr/imgmgmt.h>

Go to the source code of this file.

Data Structures

union  syslinux_regs
 

Macros

#define syslinux_version   __use_data16 ( syslinux_version )
 
#define syslinux_copyright   __use_data16 ( syslinux_copyright )
 
#define syslinux_configuration_file   __use_data16 ( syslinux_configuration_file )
 
#define comboot_feature_flags   __use_data16 ( comboot_feature_flags )
 
#define comboot_initial_regs   __use_text16 ( comboot_initial_regs )
 
#define int20_vector   __use_text16 ( int20_vector )
 
#define int21_vector   __use_text16 ( int21_vector )
 
#define int22_vector   __use_text16 ( int22_vector )
 

Functions

 FILE_LICENCE (GPL2_OR_LATER)
 
static char __bss16_array (syslinux_version, [32])
 The "SYSLINUX" version string. More...
 
static char __data16_array (syslinux_copyright, [])
 The "SYSLINUX" copyright string. More...
 
static char __data16_array (syslinux_configuration_file, [])
 
static uint8_t __data16 (comboot_feature_flags)
 Feature flags. More...
 
static syslinux_regs __text16 (comboot_initial_regs)
 Initial register values for INT 22h AX=1Ah and 1Bh. More...
 
static struct segoff __text16 (int20_vector)
 
static struct segoff __text16 (int21_vector)
 
static struct segoff __text16 (int22_vector)
 
void int20_wrapper (void)
 
void int21_wrapper (void)
 
void int22_wrapper (void)
 
static void print_user_string (unsigned int segment, unsigned int offset, char terminator)
 Print a string with a particular terminator. More...
 
static void shuffle (unsigned int list_segment, unsigned int list_offset, unsigned int count)
 Perform a series of memory copies from a list in low memory. More...
 
void comboot_force_text_mode (void)
 Set default text mode. More...
 
static int comboot_fetch_kernel (const char *kernel_file, char *cmdline)
 Fetch kernel and optional initrd. More...
 
static __asmcall __used void int20 (struct i386_all_regs *ix86 __unused)
 Terminate program interrupt handler. More...
 
static __asmcall __used void int21 (struct i386_all_regs *ix86)
 DOS-compatible API. More...
 
__weak int pxe_api_call_weak (struct i386_all_regs *ix86 __unused)
 Dispatch PXE API call weakly. More...
 
static __asmcall __used void int22 (struct i386_all_regs *ix86)
 SYSLINUX API. More...
 
void hook_comboot_interrupts ()
 Hook BIOS interrupts related to COMBOOT API (INT 20h, 21h, 22h) More...
 
void unhook_comboot_interrupts ()
 Unhook BIOS interrupts related to COMBOOT API (INT 20h, 21h, 22h) More...
 

Variables

rmjmp_buf comboot_return
 
static uint16_t comboot_graphics_mode = 0
 
struct uartserial_console
 Active serial console UART. More...
 

Macro Definition Documentation

◆ syslinux_version

#define syslinux_version   __use_data16 ( syslinux_version )

Definition at line 48 of file comboot_call.c.

◆ syslinux_copyright

#define syslinux_copyright   __use_data16 ( syslinux_copyright )

Definition at line 52 of file comboot_call.c.

◆ syslinux_configuration_file

#define syslinux_configuration_file   __use_data16 ( syslinux_configuration_file )

Definition at line 55 of file comboot_call.c.

◆ comboot_feature_flags

#define comboot_feature_flags   __use_data16 ( comboot_feature_flags )

Definition at line 59 of file comboot_call.c.

◆ comboot_initial_regs

#define comboot_initial_regs   __use_text16 ( comboot_initial_regs )

Definition at line 67 of file comboot_call.c.

◆ int20_vector

#define int20_vector   __use_text16 ( int20_vector )

Definition at line 70 of file comboot_call.c.

◆ int21_vector

#define int21_vector   __use_text16 ( int21_vector )

Definition at line 73 of file comboot_call.c.

◆ int22_vector

#define int22_vector   __use_text16 ( int22_vector )

Definition at line 76 of file comboot_call.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER  )

◆ __bss16_array()

static char __bss16_array ( syslinux_version  )
static

The "SYSLINUX" version string.

◆ __data16_array() [1/2]

static char __data16_array ( syslinux_copyright  )
static

The "SYSLINUX" copyright string.

◆ __data16_array() [2/2]

static char __data16_array ( syslinux_configuration_file  )
static

◆ __data16()

static uint8_t __data16 ( comboot_feature_flags  )
static

Feature flags.

◆ __text16() [1/4]

static syslinux_regs __text16 ( comboot_initial_regs  )
static

Initial register values for INT 22h AX=1Ah and 1Bh.

◆ __text16() [2/4]

static struct segoff __text16 ( int20_vector  )
static

◆ __text16() [3/4]

static struct segoff __text16 ( int21_vector  )
static

◆ __text16() [4/4]

static struct segoff __text16 ( int22_vector  )
static

◆ int20_wrapper()

void int20_wrapper ( void  )

◆ int21_wrapper()

void int21_wrapper ( void  )

◆ int22_wrapper()

void int22_wrapper ( void  )

◆ print_user_string()

static void print_user_string ( unsigned int  segment,
unsigned int  offset,
char  terminator 
)
static

Print a string with a particular terminator.

Definition at line 91 of file comboot_call.c.

91  {
92  char *c;
93  for ( c = real_to_virt ( segment, offset ) ; *c != terminator ; c++ ) {
94  putchar ( *c );
95  }
96 }
uint16_t segment
Code segment.
Definition: librm.h:138
static __always_inline void * real_to_virt(unsigned int segment, unsigned int offset)
Convert segment:offset address to virtual address.
Definition: realmode.h:77
uint16_t offset
Offset to command line.
Definition: bzimage.h:8
struct eth_slow_terminator_tlv terminator
Terminator.
Definition: eth_slow.h:20
int putchar(int character)
Write a single character to each console device.
Definition: console.c:28

References offset, putchar(), real_to_virt(), segment, and terminator.

Referenced by int21(), and int22().

◆ shuffle()

static void shuffle ( unsigned int  list_segment,
unsigned int  list_offset,
unsigned int  count 
)
static

Perform a series of memory copies from a list in low memory.

Definition at line 102 of file comboot_call.c.

103 {
105  unsigned int i;
106 
107  /* Copy shuffle descriptor list so it doesn't get overwritten */
108  memcpy ( shuf, real_to_virt ( list_segment, list_offset ),
109  count * sizeof( comboot_shuffle_descriptor ) );
110 
111  /* Do the copies */
112  for ( i = 0; i < count; i++ ) {
113  const void *src = phys_to_virt ( shuf[ i ].src );
114  void *dest = phys_to_virt ( shuf[ i ].dest );
115 
116  if ( shuf[ i ].src == 0xFFFFFFFF ) {
117  /* Fill with 0 instead of copying */
118  memset ( dest, 0, shuf[ i ].len );
119  } else if ( shuf[ i ].dest == 0xFFFFFFFF ) {
120  /* Copy new list of descriptors */
121  count = shuf[ i ].len / sizeof( comboot_shuffle_descriptor );
123  memcpy ( shuf, src, shuf[ i ].len );
124  i = -1;
125  } else {
126  /* Regular copy */
127  memmove ( dest, src, shuf[ i ].len );
128  }
129  }
130 }
static __always_inline void * real_to_virt(unsigned int segment, unsigned int offset)
Convert segment:offset address to virtual address.
Definition: realmode.h:77
void * memcpy(void *dest, const void *src, size_t len) __nonnull
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static const void * src
Definition: string.h:47
ring len
Length.
Definition: dwmac.h:231
static unsigned int count
Number of entries.
Definition: dwmac.h:225
void * memmove(void *dest, const void *src, size_t len) __nonnull
if(len >=6 *4) __asm__ __volatile__("movsl" if(len >=5 *4) __asm__ __volatile__("movsl" if(len >=4 *4) __asm__ __volatile__("movsl" if(len >=3 *4) __asm__ __volatile__("movsl" if(len >=2 *4) __asm__ __volatile__("movsl" if(len >=1 *4) __asm__ __volatile__("movsl" if((len % 4) >=2) __asm__ __volatile__("movsw" if((len % 2) >=1) __asm__ __volatile__("movsb" return dest
Definition: string.h:150
#define COMBOOT_MAX_SHUFFLE_DESCRIPTORS
Maximum number of shuffle descriptors for shuffle and boot functions (INT 22h AX=0012h,...
Definition: comboot.h:36
void * memset(void *dest, int character, size_t len) __nonnull

References assert(), COMBOOT_MAX_SHUFFLE_DESCRIPTORS, count, dest, comboot_shuffle_descriptor::len, len, memcpy(), memmove(), memset(), real_to_virt(), and src.

Referenced by int22().

◆ comboot_force_text_mode()

void comboot_force_text_mode ( void  )

Set default text mode.

Definition at line 136 of file comboot_call.c.

136  {
138  /* Set VGA mode 3 via VESA VBE mode set */
140  REAL_CODE (
141  "mov $0x4F02, %%ax\n\t"
142  "mov $0x03, %%bx\n\t"
143  "int $0x10\n\t"
144  )
145  : : );
147  /* Set VGA mode 3 via standard VGA mode set */
149  REAL_CODE (
150  "mov $0x03, %%ax\n\t"
151  "int $0x10\n\t"
152  )
153  : : );
154  }
155 
157 }
#define COMBOOT_VIDEO_VESA
Definition: comboot.h:127
static uint16_t comboot_graphics_mode
Definition: comboot_call.c:86
__asm__ __volatile__("call *%9" :"=a"(result), "=c"(discard_ecx), "=d"(discard_edx) :"d"(0), "a"(code), "b"(0), "c"(in_phys), "D"(0), "S"(out_phys), "m"(hypercall))
__asm__(".section \".rodata\", \"a\", " PROGBITS "\n\t" "\nprivate_key_data:\n\t" ".size private_key_data, ( . - private_key_data )\n\t" ".equ private_key_len, ( . - private_key_data )\n\t" ".previous\n\t")
#define REAL_CODE(asm_code_str)
Definition: libkir.h:226
#define COMBOOT_VIDEO_GRAPHICS
Definition: comboot.h:125

References __asm__(), __volatile__(), comboot_graphics_mode, COMBOOT_VIDEO_GRAPHICS, COMBOOT_VIDEO_VESA, and REAL_CODE.

Referenced by com32_exec_loop(), comboot_exec_loop(), and int22().

◆ comboot_fetch_kernel()

static int comboot_fetch_kernel ( const char *  kernel_file,
char *  cmdline 
)
static

Fetch kernel and optional initrd.

Definition at line 163 of file comboot_call.c.

163  {
164  struct image *kernel;
165  struct image *initrd;
166  char *initrd_file;
167  int rc;
168 
169  /* Find initrd= parameter, if any */
170  if ( ( initrd_file = strstr ( cmdline, "initrd=" ) ) != NULL ) {
171  char *initrd_end;
172 
173  /* skip "initrd=" */
174  initrd_file += 7;
175 
176  /* Find terminating space, if any, and replace with NUL */
177  initrd_end = strchr ( initrd_file, ' ' );
178  if ( initrd_end )
179  *initrd_end = '\0';
180 
181  DBG ( "COMBOOT: fetching initrd '%s'\n", initrd_file );
182 
183  /* Fetch initrd */
184  if ( ( rc = imgdownload_string ( initrd_file, 0,
185  &initrd ) ) != 0 ) {
186  DBG ( "COMBOOT: could not fetch initrd: %s\n",
187  strerror ( rc ) );
188  return rc;
189  }
190 
191  /* Restore space after initrd name, if applicable */
192  if ( initrd_end )
193  *initrd_end = ' ';
194  }
195 
196  DBG ( "COMBOOT: fetching kernel '%s'\n", kernel_file );
197 
198  /* Fetch kernel */
199  if ( ( rc = imgdownload_string ( kernel_file, 0, &kernel ) ) != 0 ) {
200  DBG ( "COMBOOT: could not fetch kernel: %s\n",
201  strerror ( rc ) );
202  return rc;
203  }
204 
205  /* Replace comboot image with kernel */
206  if ( ( rc = image_replace ( kernel ) ) != 0 ) {
207  DBG ( "COMBOOT: could not replace with kernel: %s\n",
208  strerror ( rc ) );
209  return rc;
210  }
211 
212  return 0;
213 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
An executable image.
Definition: image.h:23
static physaddr_t initrd_end
End of reshuffle region.
Definition: initrd.c:42
char * strstr(const char *haystack, const char *needle)
Find substring.
Definition: string.c:309
uint32_t kernel
Kernel version (numeric)
Definition: ena.h:20
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
char * strchr(const char *src, int character)
Find character within a string.
Definition: string.c:271
int image_replace(struct image *replacement)
Set replacement image.
Definition: image.c:528
int imgdownload_string(const char *uri_string, unsigned long timeout, struct image **image)
Download a new image.
Definition: imgmgmt.c:120
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
uint32_t cmdline
Definition: multiboot.h:16
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References cmdline, DBG, image_replace(), imgdownload_string(), initrd_end, kernel, NULL, rc, strchr(), strerror(), and strstr().

Referenced by int22().

◆ int20()

static __asmcall __used void int20 ( struct i386_all_regs *ix86  __unused)
static

Terminate program interrupt handler.

Definition at line 219 of file comboot_call.c.

219  {
221 }
#define COMBOOT_EXIT
Definition: comboot.h:119
rmjmp_buf comboot_return
Definition: comboot_call.c:83
#define rmlongjmp(_env, _val)
Definition: rmsetjmp.h:22

References COMBOOT_EXIT, comboot_return, and rmlongjmp.

Referenced by hook_comboot_interrupts().

◆ int21()

static __asmcall __used void int21 ( struct i386_all_regs ix86)
static

DOS-compatible API.

Definition at line 227 of file comboot_call.c.

227  {
228  ix86->flags |= CF;
229 
230  switch ( ix86->regs.ah ) {
231  case 0x00:
232  case 0x4C: /* Terminate program */
234  break;
235 
236  case 0x01: /* Get Key with Echo */
237  case 0x08: /* Get Key without Echo */
238  /* TODO: handle extended characters? */
239  ix86->regs.al = getchar( );
240 
241  /* Enter */
242  if ( ix86->regs.al == 0x0A )
243  ix86->regs.al = 0x0D;
244 
245  if ( ix86->regs.ah == 0x01 )
246  putchar ( ix86->regs.al );
247 
248  ix86->flags &= ~CF;
249  break;
250 
251  case 0x02: /* Write Character */
252  putchar ( ix86->regs.dl );
253  ix86->flags &= ~CF;
254  break;
255 
256  case 0x04: /* Write Character to Serial Port */
257  if ( serial_console ) {
258  uart_transmit ( serial_console, ix86->regs.dl );
259  ix86->flags &= ~CF;
260  }
261  break;
262 
263  case 0x09: /* Write DOS String to Console */
264  print_user_string ( ix86->segs.ds, ix86->regs.dx, '$' );
265  ix86->flags &= ~CF;
266  break;
267 
268  case 0x0B: /* Check Keyboard */
269  if ( iskey() )
270  ix86->regs.al = 0xFF;
271  else
272  ix86->regs.al = 0x00;
273 
274  ix86->flags &= ~CF;
275  break;
276 
277  case 0x30: /* Check DOS Version */
278  /* Bottom halves all 0; top halves spell "SYSLINUX" */
279  ix86->regs.eax = 0x59530000;
280  ix86->regs.ebx = 0x4C530000;
281  ix86->regs.ecx = 0x4E490000;
282  ix86->regs.edx = 0x58550000;
283  ix86->flags &= ~CF;
284  break;
285 
286  default:
287  DBG ( "COMBOOT unknown int21 function %02x\n", ix86->regs.ah );
288  break;
289  }
290 }
static void print_user_string(unsigned int segment, unsigned int offset, char terminator)
Print a string with a particular terminator.
Definition: comboot_call.c:91
#define CF
Definition: registers.h:181
struct i386_seg_regs segs
Definition: registers.h:175
uint32_t flags
Definition: registers.h:177
uint32_t eax
Definition: registers.h:109
struct uart * serial_console
Active serial console UART.
Definition: comboot_call.c:691
#define COMBOOT_EXIT
Definition: comboot.h:119
rmjmp_buf comboot_return
Definition: comboot_call.c:83
struct i386_regs regs
Definition: registers.h:176
uint16_t dx
Definition: registers.h:92
int getchar(void)
Read a single character from any console.
Definition: console.c:85
uint8_t ah
Definition: registers.h:106
uint16_t ds
Definition: registers.h:141
uint32_t ecx
Definition: registers.h:101
uint32_t ebx
Definition: registers.h:85
uint32_t edx
Definition: registers.h:93
uint8_t al
Definition: registers.h:105
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
#define rmlongjmp(_env, _val)
Definition: rmsetjmp.h:22
int putchar(int character)
Write a single character to each console device.
Definition: console.c:28
int iskey(void)
Check for available input on any console.
Definition: console.c:130
uint8_t dl
Definition: registers.h:89

References i386_regs::ah, i386_regs::al, CF, COMBOOT_EXIT, comboot_return, DBG, i386_regs::dl, i386_seg_regs::ds, i386_regs::dx, i386_regs::eax, i386_regs::ebx, i386_regs::ecx, i386_regs::edx, i386_all_regs::flags, getchar(), iskey(), print_user_string(), putchar(), i386_all_regs::regs, rmlongjmp, i386_all_regs::segs, and serial_console.

Referenced by hook_comboot_interrupts().

◆ pxe_api_call_weak()

__weak int pxe_api_call_weak ( struct i386_all_regs *ix86  __unused)

Dispatch PXE API call weakly.

Parameters
ix86Registers for PXE call
Return values
presentZero if the PXE stack is present, nonzero if not

A successful return only indicates that the PXE stack was available for dispatching the call; it says nothing about the success of whatever the call asked for.

Definition at line 303 of file comboot_call.c.

303  {
304  return -1;
305 }

Referenced by int22().

◆ int22()

static __asmcall __used void int22 ( struct i386_all_regs ix86)
static

SYSLINUX API.

Definition at line 310 of file comboot_call.c.

310  {
311  ix86->flags |= CF;
312 
313  switch ( ix86->regs.ax ) {
314  case 0x0001: /* Get Version */
315 
316  /* Number of INT 22h API functions available */
317  ix86->regs.ax = 0x001D;
318 
319  /* SYSLINUX version number */
320  ix86->regs.ch = 0; /* major */
321  ix86->regs.cl = 0; /* minor */
322 
323  /* SYSLINUX derivative ID */
324  ix86->regs.dl = BZI_LOADER_TYPE_IPXE;
325 
326  /* SYSLINUX version */
328  "\r\niPXE %s", product_version );
329 
330  /* SYSLINUX version and copyright strings */
331  ix86->segs.es = rm_ds;
332  ix86->regs.si = ( ( unsigned ) __from_data16 ( syslinux_version ) );
333  ix86->regs.di = ( ( unsigned ) __from_data16 ( syslinux_copyright ) );
334 
335  ix86->flags &= ~CF;
336  break;
337 
338  case 0x0002: /* Write String */
339  print_user_string ( ix86->segs.es, ix86->regs.bx, '\0' );
340  ix86->flags &= ~CF;
341  break;
342 
343  case 0x0003: /* Run command */
344  {
345  const char *cmd = real_to_virt ( ix86->segs.es,
346  ix86->regs.bx );
347  DBG ( "COMBOOT: executing command '%s'\n", cmd );
348  system ( cmd );
349  DBG ( "COMBOOT: exiting after executing command...\n" );
351  }
352  break;
353 
354  case 0x0004: /* Run default command */
355  /* FIXME: just exit for now */
357  break;
358 
359  case 0x0005: /* Force text mode */
361  ix86->flags &= ~CF;
362  break;
363 
364  case 0x0006: /* Open file */
365  {
366  int fd;
367  const char *file = real_to_virt ( ix86->segs.es,
368  ix86->regs.si );
369 
370  if ( file[0] == '\0' ) {
371  DBG ( "COMBOOT: attempted open with empty file name\n" );
372  break;
373  }
374 
375  DBG ( "COMBOOT: opening file '%s'\n", file );
376 
377  fd = open ( file );
378 
379  if ( fd < 0 ) {
380  DBG ( "COMBOOT: error opening file %s\n", file );
381  break;
382  }
383 
384  /* This relies on the fact that a iPXE POSIX fd will
385  * always fit in 16 bits.
386  */
387 #if (POSIX_FD_MAX > 65535)
388 #error POSIX_FD_MAX too large
389 #endif
390  ix86->regs.si = (uint16_t) fd;
391 
392  ix86->regs.cx = COMBOOT_FILE_BLOCKSZ;
393  ix86->regs.eax = fsize ( fd );
394  ix86->flags &= ~CF;
395  }
396  break;
397 
398  case 0x0007: /* Read file */
399  {
400  int fd = ix86->regs.si;
401  int len = ix86->regs.cx * COMBOOT_FILE_BLOCKSZ;
402  int rc;
403  fd_set fds;
404  void *buf = real_to_virt ( ix86->segs.es,
405  ix86->regs.bx );
406 
407  /* Wait for data ready to read */
408  FD_ZERO ( &fds );
409  FD_SET ( fd, &fds );
410 
411  select ( &fds, 1 );
412 
413  rc = read ( fd, buf, len );
414  if ( rc < 0 ) {
415  DBG ( "COMBOOT: read failed\n" );
416  ix86->regs.si = 0;
417  break;
418  }
419 
420  ix86->regs.ecx = rc;
421  ix86->flags &= ~CF;
422  }
423  break;
424 
425  case 0x0008: /* Close file */
426  {
427  int fd = ix86->regs.si;
428  close ( fd );
429  ix86->flags &= ~CF;
430  }
431  break;
432 
433  case 0x0009: /* Call PXE Stack */
434  if ( pxe_api_call_weak ( ix86 ) != 0 )
435  ix86->flags |= CF;
436  else
437  ix86->flags &= ~CF;
438  break;
439 
440  case 0x000A: /* Get Derivative-Specific Information */
441 
442  /* iPXE has its own derivative ID, so there is no defined
443  * output here; just return AL for now */
444  ix86->regs.al = BZI_LOADER_TYPE_IPXE;
445  ix86->flags &= ~CF;
446  break;
447 
448  case 0x000B: /* Get Serial Console Configuration */
449  if ( serial_console ) {
450  struct ns16550_uart *comport = serial_console->priv;
451 
452  ix86->regs.dx = ( ( intptr_t ) comport->base );
453  ix86->regs.cx = comport->divisor;
454  ix86->regs.bx = 0;
455  ix86->flags &= ~CF;
456  }
457  break;
458 
459  case 0x000C: /* Perform final cleanup */
460  shutdown_boot();
461  break;
462 
463  case 0x000E: /* Get configuration file name */
464  /* FIXME: stub */
465  ix86->segs.es = rm_ds;
466  ix86->regs.bx = ( ( unsigned ) __from_data16 ( syslinux_configuration_file ) );
467  ix86->flags &= ~CF;
468  break;
469 
470  case 0x000F: /* Get IPAPPEND strings */
471  /* FIXME: stub */
472  ix86->regs.cx = 0;
473  ix86->segs.es = 0;
474  ix86->regs.bx = 0;
475  ix86->flags &= ~CF;
476  break;
477 
478  case 0x0010: /* Resolve hostname */
479  {
480  const char *hostname = real_to_virt ( ix86->segs.es,
481  ix86->regs.bx );
482  struct in_addr addr;
483 
484  /* TODO:
485  * "If the hostname does not contain a dot (.), the
486  * local domain name is automatically appended."
487  */
488 
489  comboot_resolv ( hostname, &addr );
490 
491  ix86->regs.eax = addr.s_addr;
492  ix86->flags &= ~CF;
493  }
494  break;
495 
496  case 0x0011: /* Maximum number of shuffle descriptors */
498  ix86->flags &= ~CF;
499  break;
500 
501  case 0x0012: /* Cleanup, shuffle and boot */
503  break;
504 
505  /* Perform final cleanup */
506  shutdown_boot();
507 
508  /* Perform sequence of copies */
509  shuffle ( ix86->segs.es, ix86->regs.di, ix86->regs.cx );
510 
511  /* Jump to real-mode entry point */
513  REAL_CODE (
514  "pushw %0\n\t"
515  "popw %%ds\n\t"
516  "pushl %1\n\t"
517  "lret\n\t"
518  )
519  :
520  : "R" ( ix86->segs.ds ),
521  "R" ( ix86->regs.ebp ),
522  "d" ( ix86->regs.ebx ),
523  "S" ( ix86->regs.esi ) );
524 
525  assert ( 0 ); /* Execution should never reach this point */
526 
527  break;
528 
529  case 0x0013: /* Idle loop call */
530  step ( );
531  ix86->flags &= ~CF;
532  break;
533 
534  case 0x0015: /* Get feature flags */
535  ix86->segs.es = rm_ds;
536  ix86->regs.bx = ( ( unsigned ) __from_data16 ( &comboot_feature_flags ) );
537  ix86->regs.cx = 1; /* Number of feature flag bytes */
538  ix86->flags &= ~CF;
539  break;
540 
541  case 0x0016: /* Run kernel image */
542  {
543  const char *file = real_to_virt ( ix86->segs.ds,
544  ix86->regs.si );
545  char *cmd = real_to_virt ( ix86->segs.es,
546  ix86->regs.bx );
547 
548  DBG ( "COMBOOT: run kernel %s %s\n", file, cmd );
549  comboot_fetch_kernel ( file, cmd );
550  /* Technically, we should return if we
551  * couldn't load the kernel, but it's not safe
552  * to do that since we have just overwritten
553  * part of the COMBOOT program's memory space.
554  */
555  DBG ( "COMBOOT: exiting to run kernel...\n" );
557  }
558  break;
559 
560  case 0x0017: /* Report video mode change */
561  comboot_graphics_mode = ix86->regs.bx;
562  ix86->flags &= ~CF;
563  break;
564 
565  case 0x0018: /* Query custom font */
566  /* FIXME: stub */
567  ix86->regs.al = 0;
568  ix86->segs.es = 0;
569  ix86->regs.bx = 0;
570  ix86->flags &= ~CF;
571  break;
572 
573  case 0x001B: /* Cleanup, shuffle and boot to real mode */
575  break;
576 
577  /* Perform final cleanup */
578  shutdown_boot();
579 
580  /* Perform sequence of copies */
581  shuffle ( ix86->segs.es, ix86->regs.di, ix86->regs.cx );
582 
583  /* Copy initial register values to .text16 */
585  real_to_virt ( ix86->segs.ds, ix86->regs.si ),
586  sizeof(syslinux_rm_regs) );
587 
588  /* Load initial register values */
590  REAL_CODE (
591  /* Point SS:SP at the register value structure */
592  "pushw %%cs\n\t"
593  "popw %%ss\n\t"
594  "movw $comboot_initial_regs, %%sp\n\t"
595 
596  /* Segment registers */
597  "popw %%es\n\t"
598  "popw %%ax\n\t" /* Skip CS */
599  "popw %%ds\n\t"
600  "popw %%ax\n\t" /* Skip SS for now */
601  "popw %%fs\n\t"
602  "popw %%gs\n\t"
603 
604  /* GP registers */
605  "popl %%eax\n\t"
606  "popl %%ecx\n\t"
607  "popl %%edx\n\t"
608  "popl %%ebx\n\t"
609  "popl %%ebp\n\t" /* Skip ESP for now */
610  "popl %%ebp\n\t"
611  "popl %%esi\n\t"
612  "popl %%edi\n\t"
613 
614  /* Load correct SS:ESP */
615  "movw $(comboot_initial_regs + 6), %%sp\n\t"
616  "popw %%ss\n\t"
617  "movl %%cs:(comboot_initial_regs + 28), %%esp\n\t"
618 
619  "ljmp *%%cs:(comboot_initial_regs + 44)\n\t"
620  )
621  : : );
622 
623  break;
624 
625  case 0x001C: /* Get pointer to auxilliary data vector */
626  /* FIXME: stub */
627  ix86->regs.cx = 0; /* Size of the ADV */
628  ix86->flags &= ~CF;
629  break;
630 
631  case 0x001D: /* Write auxilliary data vector */
632  /* FIXME: stub */
633  ix86->flags &= ~CF;
634  break;
635 
636  default:
637  DBG ( "COMBOOT unknown int22 function %04x\n", ix86->regs.ax );
638  break;
639  }
640 }
#define syslinux_configuration_file
Definition: comboot_call.c:55
static void print_user_string(unsigned int segment, unsigned int offset, char terminator)
Print a string with a particular terminator.
Definition: comboot_call.c:91
struct option_descriptor read[1]
Definition: nvo_cmd.c:115
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
unsigned short uint16_t
Definition: stdint.h:11
#define CF
Definition: registers.h:181
struct i386_seg_regs segs
Definition: registers.h:175
uint32_t ebp
Definition: registers.h:73
#define syslinux_copyright
Definition: comboot_call.c:52
uint16_t es
Definition: registers.h:142
void * base
Register base address.
Definition: ns16550.h:82
#define __from_text16(pointer)
Definition: libkir.h:23
uint32_t flags
Definition: registers.h:177
uint32_t eax
Definition: registers.h:109
#define rm_ds
Definition: libkir.h:39
unsigned long intptr_t
Definition: stdint.h:21
__weak int pxe_api_call_weak(struct i386_all_regs *ix86 __unused)
Dispatch PXE API call weakly.
Definition: comboot_call.c:303
static __always_inline void * real_to_virt(unsigned int segment, unsigned int offset)
Convert segment:offset address to virtual address.
Definition: realmode.h:77
ssize_t fsize(int fd)
Determine file size.
Definition: posix_io.c:310
struct uart * serial_console
Active serial console UART.
Definition: comboot_call.c:691
void * memcpy(void *dest, const void *src, size_t len) __nonnull
uint32_t esi
Definition: registers.h:69
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
rmjmp_buf comboot_return
Definition: comboot_call.c:83
struct i386_regs regs
Definition: registers.h:176
ring len
Length.
Definition: dwmac.h:231
void comboot_force_text_mode(void)
Set default text mode.
Definition: comboot_call.c:136
uint16_t cx
Definition: registers.h:100
#define BZI_LOADER_TYPE_IPXE
bzImage boot loader identifier for iPXE
Definition: bzimage.h:93
uint16_t divisor
Baud rate divisor.
Definition: ns16550.h:88
uint16_t dx
Definition: registers.h:92
static uint16_t comboot_graphics_mode
Definition: comboot_call.c:86
uint16_t bx
Definition: registers.h:84
uint32_t fd_set
File descriptor set as used for select()
Definition: posix_io.h:21
static int comboot_fetch_kernel(const char *kernel_file, char *cmdline)
Fetch kernel and optional initrd.
Definition: comboot_call.c:163
IP address structure.
Definition: in.h:41
void * priv
Driver-private data.
Definition: uart.h:31
A 16550-compatible UART.
Definition: ns16550.h:80
uint32_t addr
Buffer address.
Definition: dwmac.h:20
#define comboot_feature_flags
Definition: comboot_call.c:59
__asm__ __volatile__("call *%9" :"=a"(result), "=c"(discard_ecx), "=d"(discard_edx) :"d"(0), "a"(code), "b"(0), "c"(in_phys), "D"(0), "S"(out_phys), "m"(hypercall))
uint16_t ds
Definition: registers.h:141
const char product_version[]
Product version string.
Definition: version.c:70
int select(fd_set *readfds, int wait)
Check file descriptors for readiness.
Definition: posix_io.c:229
uint32_t ecx
Definition: registers.h:101
static void shuffle(unsigned int list_segment, unsigned int list_offset, unsigned int count)
Perform a series of memory copies from a list in low memory.
Definition: comboot_call.c:102
#define COMBOOT_EXIT_RUN_KERNEL
Definition: comboot.h:120
int comboot_resolv(const char *name, struct in_addr *address)
__asm__(".section \".rodata\", \"a\", " PROGBITS "\n\t" "\nprivate_key_data:\n\t" ".size private_key_data, ( . - private_key_data )\n\t" ".equ private_key_len, ( . - private_key_data )\n\t" ".previous\n\t")
uint8_t cl
Definition: registers.h:97
uint16_t di
Definition: registers.h:64
uint32_t ebx
Definition: registers.h:85
#define __from_data16(pointer)
Definition: libkir.h:22
uint16_t ax
Definition: registers.h:108
#define COMBOOT_EXIT_COMMAND
Definition: comboot.h:121
void step(void)
Single-step a single process.
Definition: process.c:98
#define syslinux_version
Definition: comboot_call.c:48
int open(const char *uri_string)
Open file.
Definition: posix_io.c:176
#define rm_cs
Definition: libkir.h:38
#define COMBOOT_MAX_SHUFFLE_DESCRIPTORS
Maximum number of shuffle descriptors for shuffle and boot functions (INT 22h AX=0012h,...
Definition: comboot.h:36
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition: vsprintf.c:382
static struct evtchn_close * close
Definition: xenevent.h:23
uint16_t si
Definition: registers.h:68
uint8_t al
Definition: registers.h:105
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
#define rmlongjmp(_env, _val)
Definition: rmsetjmp.h:22
#define comboot_initial_regs
Definition: comboot_call.c:67
static void shutdown_boot(void)
Shut down system for OS boot.
Definition: init.h:77
#define REAL_CODE(asm_code_str)
Definition: libkir.h:226
struct golan_eqe_cmd cmd
Definition: CIB_PRM.h:29
uint8_t ch
Definition: registers.h:98
#define COMBOOT_FILE_BLOCKSZ
Size of SYSLINUX file block in bytes.
Definition: comboot.h:26
uint8_t system[ETH_ALEN]
System identifier.
Definition: eth_slow.h:24
uint8_t dl
Definition: registers.h:89

References __asm__(), __from_data16, __from_text16, __volatile__(), addr, i386_regs::al, assert(), i386_regs::ax, ns16550_uart::base, i386_regs::bx, BZI_LOADER_TYPE_IPXE, CF, i386_regs::ch, i386_regs::cl, close, cmd, COMBOOT_EXIT_COMMAND, COMBOOT_EXIT_RUN_KERNEL, comboot_feature_flags, comboot_fetch_kernel(), COMBOOT_FILE_BLOCKSZ, comboot_force_text_mode(), comboot_graphics_mode, comboot_initial_regs, COMBOOT_MAX_SHUFFLE_DESCRIPTORS, comboot_resolv(), comboot_return, i386_regs::cx, DBG, i386_regs::di, ns16550_uart::divisor, i386_regs::dl, i386_seg_regs::ds, i386_regs::dx, i386_regs::eax, i386_regs::ebp, i386_regs::ebx, i386_regs::ecx, i386_seg_regs::es, i386_regs::esi, i386_all_regs::flags, fsize(), len, memcpy(), open(), print_user_string(), uart::priv, product_version, pxe_api_call_weak(), rc, read, REAL_CODE, real_to_virt(), i386_all_regs::regs, rm_cs, rm_ds, rmlongjmp, i386_all_regs::segs, select(), serial_console, shuffle(), shutdown_boot(), i386_regs::si, snprintf(), step(), syslinux_configuration_file, syslinux_copyright, syslinux_version, and system.

Referenced by hook_comboot_interrupts().

◆ hook_comboot_interrupts()

void hook_comboot_interrupts ( )

Hook BIOS interrupts related to COMBOOT API (INT 20h, 21h, 22h)

Definition at line 645 of file comboot_call.c.

645  {
646 
648  TEXT16_CODE ( "\nint20_wrapper:\n\t"
649  VIRT_CALL ( int20 )
650  "clc\n\t"
651  "call patch_cf\n\t"
652  "iret\n\t" ) : );
653 
655 
657  TEXT16_CODE ( "\nint21_wrapper:\n\t"
658  VIRT_CALL ( int21 )
659  "clc\n\t"
660  "call patch_cf\n\t"
661  "iret\n\t" ) : );
662 
664 
666  TEXT16_CODE ( "\nint22_wrapper:\n\t"
667  VIRT_CALL ( int22 )
668  "clc\n\t"
669  "call patch_cf\n\t"
670  "iret\n\t" ) : );
671 
673 }
#define VIRT_CALL(function)
Call C function from real-mode code.
Definition: librm.h:72
unsigned long intptr_t
Definition: stdint.h:21
void hook_bios_interrupt(unsigned int interrupt, unsigned int handler, struct segoff *chain_vector)
Hook INT vector.
Definition: biosint.c:25
void int22_wrapper(void)
__asm__ __volatile__("call *%9" :"=a"(result), "=c"(discard_ecx), "=d"(discard_edx) :"d"(0), "a"(code), "b"(0), "c"(in_phys), "D"(0), "S"(out_phys), "m"(hypercall))
#define int21_vector
Definition: comboot_call.c:73
void int21_wrapper(void)
__asm__(".section \".rodata\", \"a\", " PROGBITS "\n\t" "\nprivate_key_data:\n\t" ".size private_key_data, ( . - private_key_data )\n\t" ".equ private_key_len, ( . - private_key_data )\n\t" ".previous\n\t")
#define int20_vector
Definition: comboot_call.c:70
static __asmcall __used void int22(struct i386_all_regs *ix86)
SYSLINUX API.
Definition: comboot_call.c:310
void int20_wrapper(void)
static __asmcall __used void int20(struct i386_all_regs *ix86 __unused)
Terminate program interrupt handler.
Definition: comboot_call.c:219
static __asmcall __used void int21(struct i386_all_regs *ix86)
DOS-compatible API.
Definition: comboot_call.c:227
#define int22_vector
Definition: comboot_call.c:76
#define TEXT16_CODE(asm_code_str)
Definition: libkir.h:217

References __asm__(), __volatile__(), hook_bios_interrupt(), int20(), int20_vector, int20_wrapper(), int21(), int21_vector, int21_wrapper(), int22(), int22_vector, int22_wrapper(), TEXT16_CODE, and VIRT_CALL.

Referenced by com32_exec_loop(), and comboot_exec_loop().

◆ unhook_comboot_interrupts()

void unhook_comboot_interrupts ( )

Unhook BIOS interrupts related to COMBOOT API (INT 20h, 21h, 22h)

Definition at line 678 of file comboot_call.c.

678  {
679 
681  &int20_vector );
682 
684  &int21_vector );
685 
687  &int22_vector );
688 }
unsigned long intptr_t
Definition: stdint.h:21
int unhook_bios_interrupt(unsigned int interrupt, unsigned int handler, struct segoff *chain_vector)
Unhook INT vector.
Definition: biosint.c:70
void int22_wrapper(void)
#define int21_vector
Definition: comboot_call.c:73
void int21_wrapper(void)
#define int20_vector
Definition: comboot_call.c:70
void int20_wrapper(void)
#define int22_vector
Definition: comboot_call.c:76

References int20_vector, int20_wrapper(), int21_vector, int21_wrapper(), int22_vector, int22_wrapper(), and unhook_bios_interrupt().

Referenced by com32_exec_loop(), and comboot_exec_loop().

Variable Documentation

◆ comboot_return

rmjmp_buf comboot_return

Definition at line 83 of file comboot_call.c.

Referenced by com32_exec_loop(), comboot_exec_loop(), int20(), int21(), and int22().

◆ comboot_graphics_mode

uint16_t comboot_graphics_mode = 0
static

Definition at line 86 of file comboot_call.c.

Referenced by comboot_force_text_mode(), and int22().

◆ serial_console

struct uart* serial_console

Active serial console UART.

Explicitly initialised to NULL since this variable may be accessed before .bss has been zeroed.

Definition at line 691 of file comboot_call.c.

Referenced by int21(), and int22().