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/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 (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 uart serial_console
 Serial console UART. More...
 

Macro Definition Documentation

◆ syslinux_version

#define syslinux_version   __use_data16 ( syslinux_version )

Definition at line 47 of file comboot_call.c.

◆ syslinux_copyright

#define syslinux_copyright   __use_data16 ( syslinux_copyright )

Definition at line 51 of file comboot_call.c.

◆ syslinux_configuration_file

#define syslinux_configuration_file   __use_data16 ( syslinux_configuration_file )

Definition at line 54 of file comboot_call.c.

◆ comboot_feature_flags

#define comboot_feature_flags   __use_data16 ( comboot_feature_flags )

Definition at line 58 of file comboot_call.c.

◆ comboot_initial_regs

#define comboot_initial_regs   __use_text16 ( comboot_initial_regs )

Definition at line 66 of file comboot_call.c.

◆ int20_vector

#define int20_vector   __use_text16 ( int20_vector )

Definition at line 69 of file comboot_call.c.

◆ int21_vector

#define int21_vector   __use_text16 ( int21_vector )

Definition at line 72 of file comboot_call.c.

◆ int22_vector

#define int22_vector   __use_text16 ( int22_vector )

Definition at line 75 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 90 of file comboot_call.c.

90  {
91  int i = 0;
92  char c;
94  for ( ; ; ) {
95  copy_from_user ( &c, str, i, 1 );
96  if ( c == terminator ) break;
97  putchar ( c );
98  i++;
99  }
100 }
uint32_t c
Definition: md4.c:30
uint16_t segment
Code segment.
Definition: librm.h:252
static __always_inline void copy_from_user(void *dest, userptr_t src, off_t src_off, size_t len)
Copy data from user buffer.
Definition: uaccess.h:337
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
static __always_inline userptr_t real_to_user(unsigned int segment, unsigned int offset)
Convert segment:offset address to user buffer.
Definition: realmode.h:75
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
unsigned long userptr_t
A pointer to a user buffer.
Definition: uaccess.h:33

References c, copy_from_user(), offset, putchar(), real_to_user(), 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 106 of file comboot_call.c.

107 {
109  unsigned int i;
110 
111  /* Copy shuffle descriptor list so it doesn't get overwritten */
112  copy_from_user ( shuf, real_to_user ( list_segment, list_offset ), 0,
113  count * sizeof( comboot_shuffle_descriptor ) );
114 
115  /* Do the copies */
116  for ( i = 0; i < count; i++ ) {
117  userptr_t src_u = phys_to_user ( shuf[ i ].src );
118  userptr_t dest_u = phys_to_user ( shuf[ i ].dest );
119 
120  if ( shuf[ i ].src == 0xFFFFFFFF ) {
121  /* Fill with 0 instead of copying */
122  memset_user ( dest_u, 0, 0, shuf[ i ].len );
123  } else if ( shuf[ i ].dest == 0xFFFFFFFF ) {
124  /* Copy new list of descriptors */
125  count = shuf[ i ].len / sizeof( comboot_shuffle_descriptor );
127  copy_from_user ( shuf, src_u, 0, shuf[ i ].len );
128  i = -1;
129  } else {
130  /* Regular copy */
131  memmove_user ( dest_u, 0, src_u, 0, shuf[ i ].len );
132  }
133  }
134 }
static __always_inline void copy_from_user(void *dest, userptr_t src, off_t src_off, size_t len)
Copy data from user buffer.
Definition: uaccess.h:337
static void const void * src
Definition: crypto.h:244
userptr_t phys_to_user(unsigned long phys_addr)
Convert physical address to user pointer.
void memset_user(userptr_t userptr, off_t offset, int c, size_t len)
Fill user buffer with a constant byte.
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static void * dest
Definition: strings.h:176
uint32_t len
Length.
Definition: ena.h:14
uint16_t count
Number of entries.
Definition: ena.h:22
#define COMBOOT_MAX_SHUFFLE_DESCRIPTORS
Maximum number of shuffle descriptors for shuffle and boot functions (INT 22h AX=0012h,...
Definition: comboot.h:36
void memmove_user(userptr_t dest, off_t dest_off, userptr_t src, off_t src_off, size_t len)
Copy data between user buffers, allowing for overlap.
static __always_inline userptr_t real_to_user(unsigned int segment, unsigned int offset)
Convert segment:offset address to user buffer.
Definition: realmode.h:75
unsigned long userptr_t
A pointer to a user buffer.
Definition: uaccess.h:33

References assert(), COMBOOT_MAX_SHUFFLE_DESCRIPTORS, copy_from_user(), count, dest, len, comboot_shuffle_descriptor::len, memmove_user(), memset_user(), phys_to_user(), real_to_user(), and src.

Referenced by int22().

◆ comboot_force_text_mode()

void comboot_force_text_mode ( void  )

Set default text mode.

Definition at line 140 of file comboot_call.c.

140  {
142  /* Set VGA mode 3 via VESA VBE mode set */
144  REAL_CODE (
145  "mov $0x4F02, %%ax\n\t"
146  "mov $0x03, %%bx\n\t"
147  "int $0x10\n\t"
148  )
149  : : );
151  /* Set VGA mode 3 via standard VGA mode set */
153  REAL_CODE (
154  "mov $0x03, %%ax\n\t"
155  "int $0x10\n\t"
156  )
157  : : );
158  }
159 
161 }
#define COMBOOT_VIDEO_VESA
Definition: comboot.h:127
static uint16_t comboot_graphics_mode
Definition: comboot_call.c:85
__asm__ __volatile__("\n1:\n\t" "movb -1(%3,%1), %%al\n\t" "stosb\n\t" "loop 1b\n\t" "xorl %%eax, %%eax\n\t" "mov %4, %1\n\t" "rep stosb\n\t" :"=&D"(discard_D), "=&c"(discard_c), "+m"(*value) :"r"(data), "g"(pad_len), "0"(value0), "1"(len) :"eax")
__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 ( char *  kernel_file,
char *  cmdline 
)
static

Fetch kernel and optional initrd.

Definition at line 167 of file comboot_call.c.

167  {
168  struct image *kernel;
169  struct image *initrd;
170  char *initrd_file;
171  int rc;
172 
173  /* Find initrd= parameter, if any */
174  if ( ( initrd_file = strstr ( cmdline, "initrd=" ) ) != NULL ) {
175  char *initrd_end;
176 
177  /* skip "initrd=" */
178  initrd_file += 7;
179 
180  /* Find terminating space, if any, and replace with NUL */
181  initrd_end = strchr ( initrd_file, ' ' );
182  if ( initrd_end )
183  *initrd_end = '\0';
184 
185  DBG ( "COMBOOT: fetching initrd '%s'\n", initrd_file );
186 
187  /* Fetch initrd */
188  if ( ( rc = imgdownload_string ( initrd_file, 0,
189  &initrd ) ) != 0 ) {
190  DBG ( "COMBOOT: could not fetch initrd: %s\n",
191  strerror ( rc ) );
192  return rc;
193  }
194 
195  /* Restore space after initrd name, if applicable */
196  if ( initrd_end )
197  *initrd_end = ' ';
198  }
199 
200  DBG ( "COMBOOT: fetching kernel '%s'\n", kernel_file );
201 
202  /* Fetch kernel */
203  if ( ( rc = imgdownload_string ( kernel_file, 0, &kernel ) ) != 0 ) {
204  DBG ( "COMBOOT: could not fetch kernel: %s\n",
205  strerror ( rc ) );
206  return rc;
207  }
208 
209  /* Replace comboot image with kernel */
210  if ( ( rc = image_replace ( kernel ) ) != 0 ) {
211  DBG ( "COMBOOT: could not replace with kernel: %s\n",
212  strerror ( rc ) );
213  return rc;
214  }
215 
216  return 0;
217 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
An executable image.
Definition: image.h:24
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:470
int imgdownload_string(const char *uri_string, unsigned long timeout, struct image **image)
Download a new image.
Definition: imgmgmt.c:119
#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(), 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 223 of file comboot_call.c.

223  {
225 }
#define COMBOOT_EXIT
Definition: comboot.h:119
rmjmp_buf comboot_return
Definition: comboot_call.c:82
#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 231 of file comboot_call.c.

231  {
232  ix86->flags |= CF;
233 
234  switch ( ix86->regs.ah ) {
235  case 0x00:
236  case 0x4C: /* Terminate program */
238  break;
239 
240  case 0x01: /* Get Key with Echo */
241  case 0x08: /* Get Key without Echo */
242  /* TODO: handle extended characters? */
243  ix86->regs.al = getchar( );
244 
245  /* Enter */
246  if ( ix86->regs.al == 0x0A )
247  ix86->regs.al = 0x0D;
248 
249  if ( ix86->regs.ah == 0x01 )
250  putchar ( ix86->regs.al );
251 
252  ix86->flags &= ~CF;
253  break;
254 
255  case 0x02: /* Write Character */
256  putchar ( ix86->regs.dl );
257  ix86->flags &= ~CF;
258  break;
259 
260  case 0x04: /* Write Character to Serial Port */
261  if ( serial_console.base ) {
262  uart_transmit ( &serial_console, ix86->regs.dl );
263  ix86->flags &= ~CF;
264  }
265  break;
266 
267  case 0x09: /* Write DOS String to Console */
268  print_user_string ( ix86->segs.ds, ix86->regs.dx, '$' );
269  ix86->flags &= ~CF;
270  break;
271 
272  case 0x0B: /* Check Keyboard */
273  if ( iskey() )
274  ix86->regs.al = 0xFF;
275  else
276  ix86->regs.al = 0x00;
277 
278  ix86->flags &= ~CF;
279  break;
280 
281  case 0x30: /* Check DOS Version */
282  /* Bottom halves all 0; top halves spell "SYSLINUX" */
283  ix86->regs.eax = 0x59530000;
284  ix86->regs.ebx = 0x4C530000;
285  ix86->regs.ecx = 0x4E490000;
286  ix86->regs.edx = 0x58550000;
287  ix86->flags &= ~CF;
288  break;
289 
290  default:
291  DBG ( "COMBOOT unknown int21 function %02x\n", ix86->regs.ah );
292  break;
293  }
294 }
static void print_user_string(unsigned int segment, unsigned int offset, char terminator)
Print a string with a particular terminator.
Definition: comboot_call.c:90
#define CF
Definition: registers.h:181
struct i386_seg_regs segs
Definition: registers.h:175
void uart_transmit(struct uart *uart, uint8_t data)
Transmit data.
Definition: uart.c:48
uint32_t flags
Definition: registers.h:177
void * base
I/O port base address.
Definition: uart.h:82
uint32_t eax
Definition: registers.h:109
#define COMBOOT_EXIT
Definition: comboot.h:119
rmjmp_buf comboot_return
Definition: comboot_call.c:82
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
struct uart serial_console
Serial console UART.
Definition: comboot_call.c:705
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, uart::base, 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, serial_console, and uart_transmit().

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 307 of file comboot_call.c.

307  {
308  return -1;
309 }

Referenced by int22().

◆ int22()

static __asmcall __used void int22 ( struct i386_all_regs ix86)
static

SYSLINUX API.

Definition at line 314 of file comboot_call.c.

314  {
315  ix86->flags |= CF;
316 
317  switch ( ix86->regs.ax ) {
318  case 0x0001: /* Get Version */
319 
320  /* Number of INT 22h API functions available */
321  ix86->regs.ax = 0x001D;
322 
323  /* SYSLINUX version number */
324  ix86->regs.ch = 0; /* major */
325  ix86->regs.cl = 0; /* minor */
326 
327  /* SYSLINUX derivative ID */
328  ix86->regs.dl = BZI_LOADER_TYPE_IPXE;
329 
330  /* SYSLINUX version */
332  "\r\niPXE %s", product_version );
333 
334  /* SYSLINUX version and copyright strings */
335  ix86->segs.es = rm_ds;
336  ix86->regs.si = ( ( unsigned ) __from_data16 ( syslinux_version ) );
337  ix86->regs.di = ( ( unsigned ) __from_data16 ( syslinux_copyright ) );
338 
339  ix86->flags &= ~CF;
340  break;
341 
342  case 0x0002: /* Write String */
343  print_user_string ( ix86->segs.es, ix86->regs.bx, '\0' );
344  ix86->flags &= ~CF;
345  break;
346 
347  case 0x0003: /* Run command */
348  {
349  userptr_t cmd_u = real_to_user ( ix86->segs.es, ix86->regs.bx );
350  int len = strlen_user ( cmd_u, 0 );
351  char cmd[len + 1];
352  copy_from_user ( cmd, cmd_u, 0, len + 1 );
353  DBG ( "COMBOOT: executing command '%s'\n", cmd );
354  system ( cmd );
355  DBG ( "COMBOOT: exiting after executing command...\n" );
357  }
358  break;
359 
360  case 0x0004: /* Run default command */
361  /* FIXME: just exit for now */
363  break;
364 
365  case 0x0005: /* Force text mode */
367  ix86->flags &= ~CF;
368  break;
369 
370  case 0x0006: /* Open file */
371  {
372  int fd;
373  userptr_t file_u = real_to_user ( ix86->segs.es, ix86->regs.si );
374  int len = strlen_user ( file_u, 0 );
375  char file[len + 1];
376 
377  copy_from_user ( file, file_u, 0, len + 1 );
378 
379  if ( file[0] == '\0' ) {
380  DBG ( "COMBOOT: attempted open with empty file name\n" );
381  break;
382  }
383 
384  DBG ( "COMBOOT: opening file '%s'\n", file );
385 
386  fd = open ( file );
387 
388  if ( fd < 0 ) {
389  DBG ( "COMBOOT: error opening file %s\n", file );
390  break;
391  }
392 
393  /* This relies on the fact that a iPXE POSIX fd will
394  * always fit in 16 bits.
395  */
396 #if (POSIX_FD_MAX > 65535)
397 #error POSIX_FD_MAX too large
398 #endif
399  ix86->regs.si = (uint16_t) fd;
400 
401  ix86->regs.cx = COMBOOT_FILE_BLOCKSZ;
402  ix86->regs.eax = fsize ( fd );
403  ix86->flags &= ~CF;
404  }
405  break;
406 
407  case 0x0007: /* Read file */
408  {
409  int fd = ix86->regs.si;
410  int len = ix86->regs.cx * COMBOOT_FILE_BLOCKSZ;
411  int rc;
412  fd_set fds;
413  userptr_t buf = real_to_user ( ix86->segs.es, ix86->regs.bx );
414 
415  /* Wait for data ready to read */
416  FD_ZERO ( &fds );
417  FD_SET ( fd, &fds );
418 
419  select ( &fds, 1 );
420 
421  rc = read_user ( fd, buf, 0, len );
422  if ( rc < 0 ) {
423  DBG ( "COMBOOT: read failed\n" );
424  ix86->regs.si = 0;
425  break;
426  }
427 
428  ix86->regs.ecx = rc;
429  ix86->flags &= ~CF;
430  }
431  break;
432 
433  case 0x0008: /* Close file */
434  {
435  int fd = ix86->regs.si;
436  close ( fd );
437  ix86->flags &= ~CF;
438  }
439  break;
440 
441  case 0x0009: /* Call PXE Stack */
442  if ( pxe_api_call_weak ( ix86 ) != 0 )
443  ix86->flags |= CF;
444  else
445  ix86->flags &= ~CF;
446  break;
447 
448  case 0x000A: /* Get Derivative-Specific Information */
449 
450  /* iPXE has its own derivative ID, so there is no defined
451  * output here; just return AL for now */
452  ix86->regs.al = BZI_LOADER_TYPE_IPXE;
453  ix86->flags &= ~CF;
454  break;
455 
456  case 0x000B: /* Get Serial Console Configuration */
457  if ( serial_console.base ) {
458  ix86->regs.dx = ( ( intptr_t ) serial_console.base );
459  ix86->regs.cx = serial_console.divisor;
460  ix86->regs.bx = 0;
461  ix86->flags &= ~CF;
462  }
463  break;
464 
465  case 0x000C: /* Perform final cleanup */
466  shutdown_boot();
467  break;
468 
469  case 0x000E: /* Get configuration file name */
470  /* FIXME: stub */
471  ix86->segs.es = rm_ds;
472  ix86->regs.bx = ( ( unsigned ) __from_data16 ( syslinux_configuration_file ) );
473  ix86->flags &= ~CF;
474  break;
475 
476  case 0x000F: /* Get IPAPPEND strings */
477  /* FIXME: stub */
478  ix86->regs.cx = 0;
479  ix86->segs.es = 0;
480  ix86->regs.bx = 0;
481  ix86->flags &= ~CF;
482  break;
483 
484  case 0x0010: /* Resolve hostname */
485  {
486  userptr_t hostname_u = real_to_user ( ix86->segs.es, ix86->regs.bx );
487  int len = strlen_user ( hostname_u, 0 );
488  char hostname[len];
489  struct in_addr addr;
490 
491  copy_from_user ( hostname, hostname_u, 0, len + 1 );
492 
493  /* TODO:
494  * "If the hostname does not contain a dot (.), the
495  * local domain name is automatically appended."
496  */
497 
498  comboot_resolv ( hostname, &addr );
499 
500  ix86->regs.eax = addr.s_addr;
501  ix86->flags &= ~CF;
502  }
503  break;
504 
505  case 0x0011: /* Maximum number of shuffle descriptors */
507  ix86->flags &= ~CF;
508  break;
509 
510  case 0x0012: /* Cleanup, shuffle and boot */
512  break;
513 
514  /* Perform final cleanup */
515  shutdown_boot();
516 
517  /* Perform sequence of copies */
518  shuffle ( ix86->segs.es, ix86->regs.di, ix86->regs.cx );
519 
520  /* Jump to real-mode entry point */
522  REAL_CODE (
523  "pushw %0\n\t"
524  "popw %%ds\n\t"
525  "pushl %1\n\t"
526  "lret\n\t"
527  )
528  :
529  : "r" ( ix86->segs.ds ),
530  "r" ( ix86->regs.ebp ),
531  "d" ( ix86->regs.ebx ),
532  "S" ( ix86->regs.esi ) );
533 
534  assert ( 0 ); /* Execution should never reach this point */
535 
536  break;
537 
538  case 0x0013: /* Idle loop call */
539  step ( );
540  ix86->flags &= ~CF;
541  break;
542 
543  case 0x0015: /* Get feature flags */
544  ix86->segs.es = rm_ds;
545  ix86->regs.bx = ( ( unsigned ) __from_data16 ( &comboot_feature_flags ) );
546  ix86->regs.cx = 1; /* Number of feature flag bytes */
547  ix86->flags &= ~CF;
548  break;
549 
550  case 0x0016: /* Run kernel image */
551  {
552  userptr_t file_u = real_to_user ( ix86->segs.ds, ix86->regs.si );
553  userptr_t cmd_u = real_to_user ( ix86->segs.es, ix86->regs.bx );
554  int file_len = strlen_user ( file_u, 0 );
555  int cmd_len = strlen_user ( cmd_u, 0 );
556  char file[file_len + 1];
557  char cmd[cmd_len + 1];
558 
559  copy_from_user ( file, file_u, 0, file_len + 1 );
560  copy_from_user ( cmd, cmd_u, 0, cmd_len + 1 );
561 
562  DBG ( "COMBOOT: run kernel %s %s\n", file, cmd );
563  comboot_fetch_kernel ( file, cmd );
564  /* Technically, we should return if we
565  * couldn't load the kernel, but it's not safe
566  * to do that since we have just overwritten
567  * part of the COMBOOT program's memory space.
568  */
569  DBG ( "COMBOOT: exiting to run kernel...\n" );
571  }
572  break;
573 
574  case 0x0017: /* Report video mode change */
575  comboot_graphics_mode = ix86->regs.bx;
576  ix86->flags &= ~CF;
577  break;
578 
579  case 0x0018: /* Query custom font */
580  /* FIXME: stub */
581  ix86->regs.al = 0;
582  ix86->segs.es = 0;
583  ix86->regs.bx = 0;
584  ix86->flags &= ~CF;
585  break;
586 
587  case 0x001B: /* Cleanup, shuffle and boot to real mode */
589  break;
590 
591  /* Perform final cleanup */
592  shutdown_boot();
593 
594  /* Perform sequence of copies */
595  shuffle ( ix86->segs.es, ix86->regs.di, ix86->regs.cx );
596 
597  /* Copy initial register values to .text16 */
599  real_to_user ( ix86->segs.ds, ix86->regs.si ), 0,
600  sizeof(syslinux_rm_regs) );
601 
602  /* Load initial register values */
604  REAL_CODE (
605  /* Point SS:SP at the register value structure */
606  "pushw %%cs\n\t"
607  "popw %%ss\n\t"
608  "movw $comboot_initial_regs, %%sp\n\t"
609 
610  /* Segment registers */
611  "popw %%es\n\t"
612  "popw %%ax\n\t" /* Skip CS */
613  "popw %%ds\n\t"
614  "popw %%ax\n\t" /* Skip SS for now */
615  "popw %%fs\n\t"
616  "popw %%gs\n\t"
617 
618  /* GP registers */
619  "popl %%eax\n\t"
620  "popl %%ecx\n\t"
621  "popl %%edx\n\t"
622  "popl %%ebx\n\t"
623  "popl %%ebp\n\t" /* Skip ESP for now */
624  "popl %%ebp\n\t"
625  "popl %%esi\n\t"
626  "popl %%edi\n\t"
627 
628  /* Load correct SS:ESP */
629  "movw $(comboot_initial_regs + 6), %%sp\n\t"
630  "popw %%ss\n\t"
631  "movl %%cs:(comboot_initial_regs + 28), %%esp\n\t"
632 
633  "ljmp *%%cs:(comboot_initial_regs + 44)\n\t"
634  )
635  : : );
636 
637  break;
638 
639  case 0x001C: /* Get pointer to auxilliary data vector */
640  /* FIXME: stub */
641  ix86->regs.cx = 0; /* Size of the ADV */
642  ix86->flags &= ~CF;
643  break;
644 
645  case 0x001D: /* Write auxilliary data vector */
646  /* FIXME: stub */
647  ix86->flags &= ~CF;
648  break;
649 
650  default:
651  DBG ( "COMBOOT unknown int22 function %04x\n", ix86->regs.ax );
652  break;
653  }
654 }
#define syslinux_configuration_file
Definition: comboot_call.c:54
static void print_user_string(unsigned int segment, unsigned int offset, char terminator)
Print a string with a particular terminator.
Definition: comboot_call.c:90
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:51
uint16_t divisor
Baud rate divisor.
Definition: uart.h:84
uint16_t es
Definition: registers.h:142
#define __from_text16(pointer)
Definition: libkir.h:23
ssize_t read_user(int fd, userptr_t buffer, off_t offset, size_t max_len)
Read data from file.
Definition: posix_io.c:265
static __always_inline void copy_from_user(void *dest, userptr_t src, off_t src_off, size_t len)
Copy data from user buffer.
Definition: uaccess.h:337
uint32_t flags
Definition: registers.h:177
void * base
I/O port base address.
Definition: uart.h:82
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:307
ssize_t fsize(int fd)
Determine file size.
Definition: posix_io.c:311
uint32_t esi
Definition: registers.h:69
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
rmjmp_buf comboot_return
Definition: comboot_call.c:82
struct i386_regs regs
Definition: registers.h:176
void comboot_force_text_mode(void)
Set default text mode.
Definition: comboot_call.c:140
uint16_t cx
Definition: registers.h:100
#define BZI_LOADER_TYPE_IPXE
bzImage boot loader identifier for iPXE
Definition: bzimage.h:93
uint16_t dx
Definition: registers.h:92
static uint16_t comboot_graphics_mode
Definition: comboot_call.c:85
uint16_t bx
Definition: registers.h:84
uint32_t fd_set
File descriptor set as used for select()
Definition: posix_io.h:22
IP address structure.
Definition: in.h:39
#define comboot_feature_flags
Definition: comboot_call.c:58
uint16_t ds
Definition: registers.h:141
u32 addr
Definition: sky2.h:8
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
__asm__ __volatile__("\n1:\n\t" "movb -1(%3,%1), %%al\n\t" "stosb\n\t" "loop 1b\n\t" "xorl %%eax, %%eax\n\t" "mov %4, %1\n\t" "rep stosb\n\t" :"=&D"(discard_D), "=&c"(discard_c), "+m"(*value) :"r"(data), "g"(pad_len), "0"(value0), "1"(len) :"eax")
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:106
#define COMBOOT_EXIT_RUN_KERNEL
Definition: comboot.h:120
size_t strlen_user(userptr_t userptr, off_t offset)
Find length of NUL-terminated string in user buffer.
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")
struct uart serial_console
Serial console UART.
Definition: comboot_call.c:705
uint32_t len
Length.
Definition: ena.h:14
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:47
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
static int comboot_fetch_kernel(char *kernel_file, char *cmdline)
Fetch kernel and optional initrd.
Definition: comboot_call.c:167
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition: vsprintf.c:382
static __always_inline userptr_t real_to_user(unsigned int segment, unsigned int offset)
Convert segment:offset address to user buffer.
Definition: realmode.h:75
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:66
static void shutdown_boot(void)
Shut down system for OS boot.
Definition: init.h:76
#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
void memcpy_user(userptr_t dest, off_t dest_off, userptr_t src, off_t src_off, size_t len)
Copy data between user buffers.
unsigned long userptr_t
A pointer to a user buffer.
Definition: uaccess.h:33
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, 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, copy_from_user(), i386_regs::cx, DBG, i386_regs::di, 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_user(), open(), print_user_string(), product_version, pxe_api_call_weak(), rc, read_user(), REAL_CODE, real_to_user(), i386_all_regs::regs, rm_cs, rm_ds, rmlongjmp, i386_all_regs::segs, select(), serial_console, shuffle(), shutdown_boot(), i386_regs::si, snprintf(), step(), strlen_user(), 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 659 of file comboot_call.c.

659  {
660 
662  TEXT16_CODE ( "\nint20_wrapper:\n\t"
663  VIRT_CALL ( int20 )
664  "clc\n\t"
665  "call patch_cf\n\t"
666  "iret\n\t" ) : );
667 
669 
671  TEXT16_CODE ( "\nint21_wrapper:\n\t"
672  VIRT_CALL ( int21 )
673  "clc\n\t"
674  "call patch_cf\n\t"
675  "iret\n\t" ) : );
676 
678 
680  TEXT16_CODE ( "\nint22_wrapper:\n\t"
681  VIRT_CALL ( int22 )
682  "clc\n\t"
683  "call patch_cf\n\t"
684  "iret\n\t" ) : );
685 
687 }
#define VIRT_CALL(function)
Call C function from real-mode code.
Definition: librm.h:78
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:24
void int22_wrapper(void)
__asm__ __volatile__("\n1:\n\t" "movb -1(%3,%1), %%al\n\t" "stosb\n\t" "loop 1b\n\t" "xorl %%eax, %%eax\n\t" "mov %4, %1\n\t" "rep stosb\n\t" :"=&D"(discard_D), "=&c"(discard_c), "+m"(*value) :"r"(data), "g"(pad_len), "0"(value0), "1"(len) :"eax")
#define int21_vector
Definition: comboot_call.c:72
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:69
static __asmcall __used void int22(struct i386_all_regs *ix86)
SYSLINUX API.
Definition: comboot_call.c:314
void int20_wrapper(void)
static __asmcall __used void int20(struct i386_all_regs *ix86 __unused)
Terminate program interrupt handler.
Definition: comboot_call.c:223
static __asmcall __used void int21(struct i386_all_regs *ix86)
DOS-compatible API.
Definition: comboot_call.c:231
#define int22_vector
Definition: comboot_call.c:75
#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 692 of file comboot_call.c.

692  {
693 
695  &int20_vector );
696 
698  &int21_vector );
699 
701  &int22_vector );
702 }
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:69
void int22_wrapper(void)
#define int21_vector
Definition: comboot_call.c:72
void int21_wrapper(void)
#define int20_vector
Definition: comboot_call.c:69
void int20_wrapper(void)
#define int22_vector
Definition: comboot_call.c:75

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 82 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 85 of file comboot_call.c.

Referenced by comboot_force_text_mode(), and int22().

◆ serial_console

struct uart serial_console

Serial console UART.

Definition at line 705 of file comboot_call.c.

Referenced by int21(), and int22().