iPXE
Data Structures | Macros | Functions
comboot.c File Reference

SYSLINUX COMBOOT (16-bit) image format. More...

#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <errno.h>
#include <assert.h>
#include <realmode.h>
#include <basemem.h>
#include <comboot.h>
#include <ipxe/image.h>
#include <ipxe/segment.h>
#include <ipxe/init.h>
#include <ipxe/features.h>
#include <ipxe/console.h>

Go to the source code of this file.

Data Structures

struct  comboot_psp
 COMBOOT PSP, copied to offset 0 of code segment. More...
 

Macros

#define COMBOOT_PSP_CMDLINE_OFFSET   0x81
 Offset in PSP of command line. More...
 
#define COMBOOT_MAX_CMDLINE_LEN   125
 Maximum length of command line in PSP (127 bytes minus space and CR) More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER)
 
 FEATURE (FEATURE_IMAGE, "COMBOOT", DHCP_EB_FEATURE_COMBOOT, 1)
 
static void comboot_copy_cmdline (struct image *image, void *seg)
 Copy command line to PSP. More...
 
static void comboot_init_psp (struct image *image, void *seg)
 Initialize PSP. More...
 
static int comboot_exec_loop (struct image *image)
 Execute COMBOOT image. More...
 
static int comboot_identify (struct image *image)
 Check image name extension. More...
 
static int comboot_prepare_segment (struct image *image)
 Load COMBOOT image into memory, preparing a segment and returning it. More...
 
static int comboot_probe (struct image *image)
 Probe COMBOOT image. More...
 
static int comboot_exec (struct image *image)
 Execute COMBOOT image. More...
 
struct image_type comboot_image_type __image_type (PROBE_NORMAL)
 SYSLINUX COMBOOT (16-bit) image type. More...
 

Detailed Description

SYSLINUX COMBOOT (16-bit) image format.

Definition in file comboot.c.

Macro Definition Documentation

◆ COMBOOT_PSP_CMDLINE_OFFSET

#define COMBOOT_PSP_CMDLINE_OFFSET   0x81

Offset in PSP of command line.

Definition at line 57 of file comboot.c.

◆ COMBOOT_MAX_CMDLINE_LEN

#define COMBOOT_MAX_CMDLINE_LEN   125

Maximum length of command line in PSP (127 bytes minus space and CR)

Definition at line 61 of file comboot.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER  )

◆ FEATURE()

FEATURE ( FEATURE_IMAGE  ,
"COMBOOT"  ,
DHCP_EB_FEATURE_COMBOOT  ,
 
)

◆ comboot_copy_cmdline()

static void comboot_copy_cmdline ( struct image image,
void *  seg 
)
static

Copy command line to PSP.

Parameters
imageCOMBOOT image

Definition at line 69 of file comboot.c.

69  {
70  const char *cmdline = ( image->cmdline ? image->cmdline : "" );
71  int cmdline_len = strlen ( cmdline );
72  uint8_t *psp_cmdline;
73 
74  /* Limit length of command line */
75  if( cmdline_len > COMBOOT_MAX_CMDLINE_LEN )
76  cmdline_len = COMBOOT_MAX_CMDLINE_LEN;
77 
78  /* Copy length to byte before command line */
79  psp_cmdline = ( seg + COMBOOT_PSP_CMDLINE_OFFSET );
80  psp_cmdline[-1] = cmdline_len;
81 
82  /* Command line starts with space */
83  psp_cmdline[0] = ' ';
84 
85  /* Copy command line */
86  memcpy ( &psp_cmdline[1], cmdline, cmdline_len );
87 
88  /* Command line ends with CR */
89  psp_cmdline[ 1 + cmdline_len ] = '\r';
90 }
#define COMBOOT_PSP_CMDLINE_OFFSET
Offset in PSP of command line.
Definition: comboot.c:57
#define COMBOOT_MAX_CMDLINE_LEN
Maximum length of command line in PSP (127 bytes minus space and CR)
Definition: comboot.c:61
An executable image.
Definition: image.h:23
char * cmdline
Command line to pass to image.
Definition: image.h:42
void * memcpy(void *dest, const void *src, size_t len) __nonnull
size_t strlen(const char *src)
Get length of string.
Definition: string.c:243
unsigned char uint8_t
Definition: stdint.h:10
struct golan_mkey_seg seg
Definition: CIB_PRM.h:28
uint32_t cmdline
Definition: multiboot.h:16

References cmdline, image::cmdline, COMBOOT_MAX_CMDLINE_LEN, COMBOOT_PSP_CMDLINE_OFFSET, memcpy(), seg, and strlen().

Referenced by comboot_init_psp().

◆ comboot_init_psp()

static void comboot_init_psp ( struct image image,
void *  seg 
)
static

Initialize PSP.

Parameters
imageCOMBOOT image
segsegment to initialize

Definition at line 98 of file comboot.c.

98  {
99  struct comboot_psp *psp;
100 
101  /* Fill PSP */
102  psp = seg;
103 
104  /* INT 20h instruction, byte order reversed */
105  psp->int20 = 0x20CD;
106 
107  /* get_fbms() returns BIOS free base memory counter, which is in
108  * kilobytes; x * 1024 / 16 == x * 64 == x << 6 */
109  psp->first_non_free_para = get_fbms() << 6;
110 
111  DBGC ( image, "COMBOOT %s: first non-free paragraph = 0x%x\n",
112  image->name, psp->first_non_free_para );
113 
114  /* Copy the command line to the PSP */
116 }
uint16_t int20
INT 20 instruction, executed if COMBOOT image returns with RET.
Definition: comboot.c:51
static unsigned int get_fbms(void)
Read the BIOS free base memory counter.
Definition: basemem.h:21
#define DBGC(...)
Definition: compiler.h:505
An executable image.
Definition: image.h:23
uint16_t first_non_free_para
Segment of first non-free paragraph of memory.
Definition: comboot.c:53
static void comboot_copy_cmdline(struct image *image, void *seg)
Copy command line to PSP.
Definition: comboot.c:69
COMBOOT PSP, copied to offset 0 of code segment.
Definition: comboot.c:49
struct golan_mkey_seg seg
Definition: CIB_PRM.h:28
char * name
Name.
Definition: image.h:37

References comboot_copy_cmdline(), DBGC, comboot_psp::first_non_free_para, get_fbms(), comboot_psp::int20, image::name, and seg.

Referenced by comboot_exec_loop().

◆ comboot_exec_loop()

static int comboot_exec_loop ( struct image image)
static

Execute COMBOOT image.

Parameters
imageCOMBOOT image
Return values
rcReturn status code

Definition at line 124 of file comboot.c.

124  {
125  void *seg = real_to_virt ( COMBOOT_PSP_SEG, 0 );
126  int state;
127 
129 
130  switch ( state ) {
131  case 0: /* First time through; invoke COMBOOT program */
132 
133  /* Initialize PSP */
135 
136  /* Hook COMBOOT API interrupts */
138 
139  DBGC ( image, "executing 16-bit COMBOOT image at %4x:0100\n",
140  COMBOOT_PSP_SEG );
141 
142  /* Unregister image, so that a "boot" command doesn't
143  * throw us into an execution loop. We never
144  * reregister ourselves; COMBOOT images expect to be
145  * removed on exit.
146  */
148 
149  /* Store stack segment at 0x38 and stack pointer at 0x3A
150  * in the PSP and jump to the image */
152  REAL_CODE ( /* Save return address with segment on old stack */
153  "popw %%ax\n\t"
154  "pushw %%cs\n\t"
155  "pushw %%ax\n\t"
156  /* Set DS=ES=segment with image */
157  "movw %w0, %%ds\n\t"
158  "movw %w0, %%es\n\t"
159  /* Set SS:SP to new stack (end of image segment) */
160  "movw %w0, %%ss\n\t"
161  "xor %%sp, %%sp\n\t"
162  "pushw $0\n\t"
163  "pushw %w0\n\t"
164  "pushw $0x100\n\t"
165  /* Zero registers (some COM files assume GP regs are 0) */
166  "xorw %%ax, %%ax\n\t"
167  "xorw %%bx, %%bx\n\t"
168  "xorw %%cx, %%cx\n\t"
169  "xorw %%dx, %%dx\n\t"
170  "xorw %%si, %%si\n\t"
171  "xorw %%di, %%di\n\t"
172  "xorw %%bp, %%bp\n\t"
173  "lret\n\t" )
174  : : "R" ( COMBOOT_PSP_SEG ) : "eax" );
175  DBGC ( image, "COMBOOT %s: returned\n", image->name );
176  break;
177 
178  case COMBOOT_EXIT:
179  DBGC ( image, "COMBOOT %s: exited\n", image->name );
180  break;
181 
183  assert ( image->replacement );
184  DBGC ( image, "COMBOOT %s: exited to run kernel %s\n",
186  break;
187 
189  DBGC ( image, "COMBOOT %s: exited after executing command\n",
190  image->name );
191  break;
192 
193  default:
194  assert ( 0 );
195  break;
196  }
197 
200 
201  return 0;
202 }
uint8_t state
State.
Definition: eth_slow.h:47
#define COMBOOT_PSP_SEG
Segment used for COMBOOT PSP and image.
Definition: comboot.h:17
#define DBGC(...)
Definition: compiler.h:505
An executable image.
Definition: image.h:23
static __always_inline void * real_to_virt(unsigned int segment, unsigned int offset)
Convert segment:offset address to virtual address.
Definition: realmode.h:77
#define COMBOOT_EXIT
Definition: comboot.h:119
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
rmjmp_buf comboot_return
Definition: comboot_call.c:83
static void comboot_init_psp(struct image *image, void *seg)
Initialize PSP.
Definition: comboot.c:98
void comboot_force_text_mode(void)
Set default text mode.
Definition: comboot_call.c:136
void unhook_comboot_interrupts()
Unhook BIOS interrupts related to COMBOOT API (INT 20h, 21h, 22h)
Definition: comboot_call.c:678
__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 COMBOOT_EXIT_RUN_KERNEL
Definition: comboot.h:120
void unregister_image(struct image *image)
Unregister executable image.
Definition: image.c:357
__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")
void hook_comboot_interrupts()
Hook BIOS interrupts related to COMBOOT API (INT 20h, 21h, 22h)
Definition: comboot_call.c:645
#define COMBOOT_EXIT_COMMAND
Definition: comboot.h:121
#define rmsetjmp(_env)
Definition: rmsetjmp.h:17
struct image * replacement
Replacement image.
Definition: image.h:72
struct golan_mkey_seg seg
Definition: CIB_PRM.h:28
#define REAL_CODE(asm_code_str)
Definition: libkir.h:226
char * name
Name.
Definition: image.h:37

References __asm__(), __volatile__(), assert(), COMBOOT_EXIT, COMBOOT_EXIT_COMMAND, COMBOOT_EXIT_RUN_KERNEL, comboot_force_text_mode(), comboot_init_psp(), COMBOOT_PSP_SEG, comboot_return, DBGC, hook_comboot_interrupts(), image::name, REAL_CODE, real_to_virt(), image::replacement, rmsetjmp, seg, state, unhook_comboot_interrupts(), and unregister_image().

Referenced by comboot_exec().

◆ comboot_identify()

static int comboot_identify ( struct image image)
static

Check image name extension.

Parameters
imageCOMBOOT image
Return values
rcReturn status code

Definition at line 210 of file comboot.c.

210  {
211  const char *ext;
212 
213  ext = strrchr( image->name, '.' );
214 
215  if ( ! ext ) {
216  DBGC ( image, "COMBOOT %s: no extension\n",
217  image->name );
218  return -ENOEXEC;
219  }
220 
221  ++ext;
222 
223  if ( strcasecmp( ext, "cbt" ) ) {
224  DBGC ( image, "COMBOOT %s: unrecognized extension %s\n",
225  image->name, ext );
226  return -ENOEXEC;
227  }
228 
229  return 0;
230 }
char * strrchr(const char *src, int character)
Find rightmost character within a string.
Definition: string.c:289
#define ENOEXEC
Exec format error.
Definition: errno.h:519
#define DBGC(...)
Definition: compiler.h:505
int strcasecmp(const char *first, const char *second)
Compare case-insensitive strings.
Definition: string.c:208
An executable image.
Definition: image.h:23
uint16_t ext
Extended status.
Definition: ena.h:20
char * name
Name.
Definition: image.h:37

References DBGC, ENOEXEC, ext, image::name, strcasecmp(), and strrchr().

Referenced by comboot_probe().

◆ comboot_prepare_segment()

static int comboot_prepare_segment ( struct image image)
static

Load COMBOOT image into memory, preparing a segment and returning it.

Parameters
imageCOMBOOT image
Return values
rcReturn status code

Definition at line 237 of file comboot.c.

238 {
239  void *seg;
240  size_t filesz, memsz;
241  int rc;
242 
243  /* Load image in segment */
245 
246  /* Allow etra 0x100 bytes before image for PSP */
247  filesz = image->len + 0x100;
248 
249  /* Ensure the entire 64k segment is free */
250  memsz = 0xFFFF;
251 
252  /* Prepare, verify, and load the real-mode segment */
253  if ( ( rc = prep_segment ( seg, filesz, memsz ) ) != 0 ) {
254  DBGC ( image, "COMBOOT %s: could not prepare segment: %s\n",
255  image->name, strerror ( rc ) );
256  return rc;
257  }
258 
259  /* Zero PSP */
260  memset ( seg, 0, 0x100 );
261 
262  /* Copy image to segment:0100 */
263  memcpy ( ( seg + 0x100 ), image->data, image->len );
264 
265  return 0;
266 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
const void * data
Read-only data.
Definition: image.h:50
#define COMBOOT_PSP_SEG
Segment used for COMBOOT PSP and image.
Definition: comboot.h:17
#define DBGC(...)
Definition: compiler.h:505
An executable image.
Definition: image.h:23
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
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
size_t len
Length of raw file image.
Definition: image.h:55
static size_t memsz
Definition: fdtmem.c:51
int prep_segment(void *segment, size_t filesz, size_t memsz)
Prepare segment for loading.
Definition: segment.c:61
struct golan_mkey_seg seg
Definition: CIB_PRM.h:28
char * name
Name.
Definition: image.h:37
void * memset(void *dest, int character, size_t len) __nonnull

References COMBOOT_PSP_SEG, image::data, DBGC, image::len, memcpy(), memset(), memsz, image::name, prep_segment(), rc, real_to_virt(), seg, and strerror().

Referenced by comboot_exec().

◆ comboot_probe()

static int comboot_probe ( struct image image)
static

Probe COMBOOT image.

Parameters
imageCOMBOOT image
Return values
rcReturn status code

Definition at line 274 of file comboot.c.

274  {
275  int rc;
276 
277  /* Check if this is a COMBOOT image */
278  if ( ( rc = comboot_identify ( image ) ) != 0 ) {
279 
280  return rc;
281  }
282 
283  return 0;
284 }
static int comboot_identify(struct image *image)
Check image name extension.
Definition: comboot.c:210
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
An executable image.
Definition: image.h:23

References comboot_identify(), and rc.

◆ comboot_exec()

static int comboot_exec ( struct image image)
static

Execute COMBOOT image.

Parameters
imageCOMBOOT image
Return values
rcReturn status code

Definition at line 292 of file comboot.c.

292  {
293  int rc;
294 
295  /* Sanity check for filesize */
296  if( image->len >= 0xFF00 ) {
297  DBGC( image, "COMBOOT %s: image too large\n",
298  image->name );
299  return -ENOEXEC;
300  }
301 
302  /* Prepare segment and load image */
303  if ( ( rc = comboot_prepare_segment ( image ) ) != 0 ) {
304  return rc;
305  }
306 
307  /* Reset console */
308  console_reset();
309 
310  return comboot_exec_loop ( image );
311 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define ENOEXEC
Exec format error.
Definition: errno.h:519
#define DBGC(...)
Definition: compiler.h:505
An executable image.
Definition: image.h:23
static int comboot_exec_loop(struct image *image)
Execute COMBOOT image.
Definition: comboot.c:124
size_t len
Length of raw file image.
Definition: image.h:55
static int comboot_prepare_segment(struct image *image)
Load COMBOOT image into memory, preparing a segment and returning it.
Definition: comboot.c:237
static void console_reset(void)
Reset console.
Definition: console.h:214
char * name
Name.
Definition: image.h:37

References comboot_exec_loop(), comboot_prepare_segment(), console_reset(), DBGC, ENOEXEC, image::len, image::name, and rc.

◆ __image_type()

struct image_type comboot_image_type __image_type ( PROBE_NORMAL  )

SYSLINUX COMBOOT (16-bit) image type.