iPXE
Macros | Functions | Variables
pxe_call.h File Reference

PXE API entry point. More...

#include <pxe_api.h>
#include <realmode.h>
#include <rmsetjmp.h>

Go to the source code of this file.

Macros

#define PXE_LOAD_SEGMENT   0
 PXE load address segment. More...
 
#define PXE_LOAD_OFFSET   0x7c00
 PXE load address offset. More...
 
#define PXE_LOAD_PHYS   ( ( PXE_LOAD_SEGMENT << 4 ) + PXE_LOAD_OFFSET )
 PXE physical load address. More...
 
#define ppxe   __use_text16 ( ppxe )
 
#define pxenv   __use_text16 ( pxenv )
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
struct s_PXE __text16 (ppxe)
 !PXE structure More...
 
struct s_PXENV __text16 (pxenv)
 PXENV+ structure. More...
 
void pxe_activate (struct net_device *netdev)
 Activate PXE stack. More...
 
int pxe_deactivate (void)
 Deactivate PXE stack. More...
 
int pxe_start_nbp (void)
 Start PXE NBP at 0000:7c00. More...
 
__asmcall void pxe_api_call (struct i386_all_regs *ix86)
 Dispatch PXE API call. More...
 
int pxe_api_call_weak (struct i386_all_regs *ix86)
 Dispatch weak PXE API call with PXE stack available. More...
 

Variables

rmjmp_buf pxe_restart_nbp
 PXENV_RESTART_TFTP jump buffer. More...
 

Detailed Description

PXE API entry point.

Definition in file pxe_call.h.

Macro Definition Documentation

◆ PXE_LOAD_SEGMENT

#define PXE_LOAD_SEGMENT   0

PXE load address segment.

Definition at line 18 of file pxe_call.h.

◆ PXE_LOAD_OFFSET

#define PXE_LOAD_OFFSET   0x7c00

PXE load address offset.

Definition at line 21 of file pxe_call.h.

◆ PXE_LOAD_PHYS

#define PXE_LOAD_PHYS   ( ( PXE_LOAD_SEGMENT << 4 ) + PXE_LOAD_OFFSET )

PXE physical load address.

Definition at line 24 of file pxe_call.h.

◆ ppxe

#define ppxe   __use_text16 ( ppxe )

Definition at line 28 of file pxe_call.h.

◆ pxenv

#define pxenv   __use_text16 ( pxenv )

Definition at line 32 of file pxe_call.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ __text16() [1/2]

struct s_PXE __text16 ( ppxe  )

!PXE structure

◆ __text16() [2/2]

struct s_PXENV __text16 ( pxenv  )

PXENV+ structure.

◆ pxe_activate()

void pxe_activate ( struct net_device netdev)

Activate PXE stack.

Parameters
netdevNet device to use as PXE net device

Definition at line 276 of file pxe_call.c.

276  {
277  uint32_t discard_a;
278  uint32_t discard_b;
279  uint32_t discard_d;
280 
281  /* Ensure INT 1A is hooked */
282  if ( ! int_1a_hooked ) {
285  devices_get();
286  int_1a_hooked = 1;
287  }
288 
289  /* Set PXE network device */
291 
292  /* Notify BIOS of installation */
293  __asm__ __volatile__ ( REAL_CODE ( "pushw %%cs\n\t"
294  "popw %%es\n\t"
295  "int $0x1a\n\t" )
296  : "=a" ( discard_a ), "=b" ( discard_b ),
297  "=d" ( discard_d )
298  : "0" ( 0x564e ),
299  "1" ( __from_text16 ( &pxenv ) ) );
300 }
#define __from_text16(pointer)
Definition: libkir.h:23
void pxe_int_1a(void)
INT 1A handler.
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
static int int_1a_hooked
INT 1A hooked flag.
Definition: pxe_call.c:55
static void devices_get(void)
Prevent devices from being removed on shutdown.
Definition: device.h:161
#define pxe_int_1a_vector
Definition: pxe_call.c:49
static struct net_device * netdev
Definition: gdbudp.c:52
void pxe_set_netdev(struct net_device *netdev)
Set network device as current PXE network device.
Definition: pxe_undi.c:69
unsigned int uint32_t
Definition: stdint.h:12
__asm__ __volatile__("\n1:\n\t" "movb -1(%2,%1), %%al\n\t" "stosb\n\t" "loop 1b\n\t" "xorl %%eax, %%eax\n\t" "mov %3, %1\n\t" "rep stosb\n\t" :"=&D"(discard_D), "=&c"(discard_c) :"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 pxenv
Definition: pxe_call.h:32
#define REAL_CODE(asm_code_str)
Definition: libkir.h:226

References __asm__(), __from_text16, __volatile__(), devices_get(), hook_bios_interrupt(), int_1a_hooked, netdev, pxe_int_1a(), pxe_int_1a_vector, pxe_set_netdev(), pxenv, and REAL_CODE.

Referenced by pxe_exec(), pxe_notify(), pxenv_start_undi(), and startpxe_payload().

◆ pxe_deactivate()

int pxe_deactivate ( void  )

Deactivate PXE stack.

Return values
rcReturn status code

Definition at line 307 of file pxe_call.c.

307  {
308  int rc;
309 
310  /* Clear PXE network device */
311  pxe_set_netdev ( NULL );
312 
313  /* Ensure INT 1A is unhooked, if possible */
314  if ( int_1a_hooked ) {
315  if ( ( rc = unhook_bios_interrupt ( 0x1a,
316  ( intptr_t ) pxe_int_1a,
317  &pxe_int_1a_vector ))!= 0){
318  DBGC ( &pxe_netdev, "PXE could not unhook INT 1A: %s\n",
319  strerror ( rc ) );
320  return rc;
321  }
322  devices_put();
323  int_1a_hooked = 0;
324  }
325 
326  return 0;
327 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static void devices_put(void)
Allow devices to be removed on shutdown.
Definition: device.h:169
void pxe_int_1a(void)
INT 1A handler.
#define DBGC(...)
Definition: compiler.h:505
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
static int int_1a_hooked
INT 1A hooked flag.
Definition: pxe_call.c:55
#define pxe_int_1a_vector
Definition: pxe_call.c:49
void pxe_set_netdev(struct net_device *netdev)
Set network device as current PXE network device.
Definition: pxe_undi.c:69
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
struct net_device * pxe_netdev
Definition: pxe_undi.c:59
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References DBGC, devices_put(), int_1a_hooked, NULL, pxe_int_1a(), pxe_int_1a_vector, pxe_netdev, pxe_set_netdev(), rc, strerror(), and unhook_bios_interrupt().

Referenced by pxe_exec(), pxe_notify(), pxenv_stop_undi(), and stoppxe_exec().

◆ pxe_start_nbp()

int pxe_start_nbp ( void  )

Start PXE NBP at 0000:7c00.

Return values
rcReturn status code

Definition at line 337 of file pxe_call.c.

337  {
338  int jmp;
339  int discard_b, discard_c, discard_d, discard_D;
341 
342  DBGC ( &pxe_netdev, "PXE NBP starting with netdev %s, code %04x:%04zx, "
343  "data %04x:%04zx\n", ( pxe_netdev ? pxe_netdev->name : "<none>"),
345 
346  /* Allow restarting NBP via PXENV_RESTART_TFTP */
348  if ( jmp )
349  DBGC ( &pxe_netdev, "PXE NBP restarting (%x)\n", jmp );
350 
351  /* Far call to PXE NBP */
352  __asm__ __volatile__ ( REAL_CODE ( "pushl %%ebp\n\t" /* gcc bug */
353  "movw %%cx, %%es\n\t"
354  "pushw %%es\n\t"
355  "pushw %%di\n\t"
356  "sti\n\t"
357  "lcall $0, $0x7c00\n\t"
358  "popl %%ebp\n\t" /* discard */
359  "popl %%ebp\n\t" /* gcc bug */ )
360  : "=a" ( status ), "=b" ( discard_b ),
361  "=c" ( discard_c ), "=d" ( discard_d ),
362  "=D" ( discard_D )
363  : "a" ( 0 ), "b" ( __from_text16 ( &pxenv ) ),
364  "c" ( rm_cs ),
365  "d" ( virt_to_phys ( &pxenv ) ),
366  "D" ( __from_text16 ( &ppxe ) )
367  : "esi", "memory" );
368  if ( status )
369  return -EPXENBP ( status );
370 
371  return 0;
372 }
unsigned short uint16_t
Definition: stdint.h:11
uint8_t jmp
"jmp" instruction
Definition: librm.h:256
#define ppxe
Definition: pxe_call.h:28
#define __from_text16(pointer)
Definition: libkir.h:23
#define DBGC(...)
Definition: compiler.h:505
#define rm_ds
Definition: libkir.h:39
static __always_inline unsigned long virt_to_phys(volatile const void *addr)
Convert virtual address to a physical address.
Definition: uaccess.h:287
#define _data16_memsz
Definition: pxe_call.c:63
uint8_t status
Status.
Definition: ena.h:16
#define _text16_memsz
Definition: pxe_call.c:59
struct net_device * pxe_netdev
Definition: pxe_undi.c:59
void * discard_D
Definition: bigint.h:29
__asm__ __volatile__("\n1:\n\t" "movb -1(%2,%1), %%al\n\t" "stosb\n\t" "loop 1b\n\t" "xorl %%eax, %%eax\n\t" "mov %3, %1\n\t" "rep stosb\n\t" :"=&D"(discard_D), "=&c"(discard_c) :"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")
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:358
#define rmsetjmp(_env)
Definition: rmsetjmp.h:17
#define rm_cs
Definition: libkir.h:38
long discard_c
Definition: bigint.h:30
#define pxenv
Definition: pxe_call.h:32
#define EPXENBP(status)
Definition: pxe_call.c:45
#define REAL_CODE(asm_code_str)
Definition: libkir.h:226
rmjmp_buf pxe_restart_nbp
Jump buffer for PXENV_RESTART_TFTP.
Definition: pxe_call.c:330

References __asm__(), __from_text16, __volatile__(), _data16_memsz, _text16_memsz, DBGC, discard_c, discard_D, EPXENBP, jmp, net_device::name, ppxe, pxe_netdev, pxe_restart_nbp, pxenv, REAL_CODE, rm_cs, rm_ds, rmsetjmp, status, and virt_to_phys().

Referenced by pxe_exec().

◆ pxe_api_call()

__asmcall void pxe_api_call ( struct i386_all_regs ix86)

Dispatch PXE API call.

Parameters
bxPXE opcode
es:diAddress of PXE parameter block
Return values
axPXE exit code

Definition at line 145 of file pxe_call.c.

145  {
146  uint16_t opcode = ix86->regs.bx;
147  userptr_t uparams = real_to_user ( ix86->segs.es, ix86->regs.di );
149  struct pxe_api_call *call;
150  union u_PXENV_ANY params;
151  PXENV_EXIT_t ret;
152 
153  /* Start profiling */
155 
156  /* Locate API call */
157  call = find_pxe_api_call ( opcode );
158  if ( ! call ) {
159  DBGC ( &pxe_netdev, "PXENV_UNKNOWN_%04x\n", opcode );
160  call = &pxenv_unknown_api;
161  }
162 
163  /* Copy parameter block from caller */
164  copy_from_user ( &params, uparams, 0, call->params_len );
165 
166  /* Set default status in case child routine fails to do so */
167  params.Status = PXENV_STATUS_FAILURE;
168 
169  /* Hand off to relevant API routine */
170  ret = call->entry ( &params );
171 
172  /* Copy modified parameter block back to caller and return */
173  copy_to_user ( uparams, 0, &params, call->params_len );
174  ix86->regs.ax = ret;
175 
176  /* Stop profiling, if applicable */
178 }
unsigned short uint16_t
Definition: stdint.h:11
struct i386_seg_regs segs
Definition: registers.h:175
uint8_t opcode
Opcode.
Definition: ena.h:16
uint16_t es
Definition: registers.h:142
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
#define DBGC(...)
Definition: compiler.h:505
A data structure for storing profiling information.
Definition: profile.h:26
static void profile_stop(struct profiler *profiler)
Stop profiling.
Definition: profile.h:171
static struct profiler * pxe_api_profiler(unsigned int opcode)
Determine applicable profiler (for debugging)
Definition: pxe_call.c:123
UINT16_t PXENV_EXIT_t
A PXE exit code.
Definition: pxe_types.h:44
struct i386_regs regs
Definition: registers.h:176
static void profile_start(struct profiler *profiler)
Start profiling.
Definition: profile.h:158
uint16_t bx
Definition: registers.h:84
struct net_device * pxe_netdev
Definition: pxe_undi.c:59
static __always_inline void copy_to_user(userptr_t dest, off_t dest_off, const void *src, size_t len)
Copy data to user buffer.
Definition: uaccess.h:324
uint16_t params_len
Length of parameters.
Definition: pxe.h:89
A PXE API call.
Definition: pxe.h:81
uint16_t di
Definition: registers.h:64
uint16_t ax
Definition: registers.h:108
static struct pxe_api_call * find_pxe_api_call(uint16_t opcode)
Locate PXE API call.
Definition: pxe_call.c:107
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
PXENV_EXIT_t(* entry)(union u_PXENV_ANY *params)
Entry point.
Definition: pxe.h:87
#define PXENV_STATUS_FAILURE
Definition: pxe_error.h:20
unsigned long userptr_t
A pointer to a user buffer.
Definition: uaccess.h:33

References i386_regs::ax, i386_regs::bx, copy_from_user(), copy_to_user(), DBGC, i386_regs::di, pxe_api_call::entry, i386_seg_regs::es, find_pxe_api_call(), opcode, pxe_api_call::params_len, profile_start(), profile_stop(), pxe_api_profiler(), pxe_netdev, PXENV_STATUS_FAILURE, real_to_user(), i386_all_regs::regs, i386_all_regs::segs, and u_PXENV_ANY::Status.

Referenced by pxe_api_call_weak().

◆ pxe_api_call_weak()

int pxe_api_call_weak ( struct i386_all_regs ix86)

Dispatch weak PXE API call with PXE stack available.

Parameters
ix86Registers for PXE call
Return values
presentZero (PXE stack present)

Definition at line 186 of file pxe_call.c.

186  {
187  pxe_api_call ( ix86 );
188  return 0;
189 }
__asmcall void pxe_api_call(struct i386_all_regs *ix86)
Dispatch PXE API call.
Definition: pxe_call.c:145

References pxe_api_call().

Variable Documentation

◆ pxe_restart_nbp

rmjmp_buf pxe_restart_nbp

PXENV_RESTART_TFTP jump buffer.

PXENV_RESTART_TFTP jump buffer.

Definition at line 330 of file pxe_call.c.

Referenced by pxe_start_nbp(), and pxenv_restart_tftp().