iPXE
Macros | Typedefs | Functions | Variables
libkir.h File Reference
#include "realmode.h"

Go to the source code of this file.

Macros

#define __data16(variable)   variable
 
#define __data16_array(variable, array)   variable array
 
#define __bss16(variable)   variable
 
#define __bss16_array(variable, array)   variable array
 
#define __text16(variable)   variable
 
#define __text16_array(variable, array)   variable array
 
#define __use_data16(variable)   variable
 
#define __use_text16(variable)   variable
 
#define __from_data16(pointer)   pointer
 
#define __from_text16(pointer)   pointer
 
#define rm_cs   ( _rm_cs() )
 
#define rm_ds   ( _rm_ds() )
 
#define copy_to_real   copy_to_real_libkir
 
#define copy_from_real   copy_from_real_libkir
 
#define put_real_kir_const_off(var, seg, off)
 
#define put_real_kir_nonconst_off(var, seg, off)
 
#define put_real_kir(var, seg, off)
 
#define get_real_kir_const_off(var, seg, off)
 
#define get_real_kir_nonconst_off(var, seg, off)
 
#define get_real_kir(var, seg, off)
 
#define put_real   put_real_kir
 
#define get_real   get_real_kir
 
#define TEXT16_CODE(asm_code_str)
 
#define REAL_CODE(asm_code_str)
 

Typedefs

typedef uint32_t userptr_t
 A pointer to a user buffer. More...
 

Functions

static __attribute__ ((always_inline)) void copy_to_user(userptr_t buffer
 Copy data to user buffer. More...
 
static void copy_to_real_libkir (unsigned int dest_seg, unsigned int dest_off, const void *src, size_t n)
 
static void copy_from_real_libkir (void *dest, unsigned int src_seg, unsigned int src_off, size_t n)
 

Variables

static off_t offset
 
static off_t const void * src
 
static off_t const void size_t len
 
static userptr_t buffer
 

Macro Definition Documentation

◆ __data16

#define __data16 (   variable)    variable

Definition at line 14 of file libkir.h.

◆ __data16_array

#define __data16_array (   variable,
  array 
)    variable array

Definition at line 15 of file libkir.h.

◆ __bss16

#define __bss16 (   variable)    variable

Definition at line 16 of file libkir.h.

◆ __bss16_array

#define __bss16_array (   variable,
  array 
)    variable array

Definition at line 17 of file libkir.h.

◆ __text16

#define __text16 (   variable)    variable

Definition at line 18 of file libkir.h.

◆ __text16_array

#define __text16_array (   variable,
  array 
)    variable array

Definition at line 19 of file libkir.h.

◆ __use_data16

#define __use_data16 (   variable)    variable

Definition at line 20 of file libkir.h.

◆ __use_text16

#define __use_text16 (   variable)    variable

Definition at line 21 of file libkir.h.

◆ __from_data16

#define __from_data16 (   pointer)    pointer

Definition at line 22 of file libkir.h.

◆ __from_text16

#define __from_text16 (   pointer)    pointer

Definition at line 23 of file libkir.h.

◆ rm_cs

#define rm_cs   ( _rm_cs() )

Definition at line 38 of file libkir.h.

◆ rm_ds

#define rm_ds   ( _rm_ds() )

Definition at line 39 of file libkir.h.

◆ copy_to_real

#define copy_to_real   copy_to_real_libkir

Definition at line 78 of file libkir.h.

◆ copy_from_real

#define copy_from_real   copy_from_real_libkir

Definition at line 79 of file libkir.h.

◆ put_real_kir_const_off

#define put_real_kir_const_off (   var,
  seg,
  off 
)
Value:
__asm__ ( "movw %w1, %%es\n\t" \
"mov %0, %%es:%c2\n\t" \
"pushw %%ds\n\t" /* restore %es */ \
"popw %%es\n\t" \
: \
: "r,r" ( var ), "rm,rm" ( seg ), "i,!r" ( off ) \
)
__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 golan_mkey_seg seg
Definition: CIB_PRM.h:28

Definition at line 98 of file libkir.h.

◆ put_real_kir_nonconst_off

#define put_real_kir_nonconst_off (   var,
  seg,
  off 
)
Value:
__asm__ ( "movw %w1, %%es\n\t" \
"mov %0, %%es:(%2)\n\t" \
"pushw %%ds\n\t" /* restore %es */ \
"popw %%es\n\t" \
: \
: "r" ( var ), "rm" ( seg ), "r" ( off ) \
)
__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 golan_mkey_seg seg
Definition: CIB_PRM.h:28

Definition at line 107 of file libkir.h.

◆ put_real_kir

#define put_real_kir (   var,
  seg,
  off 
)
Value:
do { \
if ( __builtin_constant_p ( off ) ) \
put_real_kir_const_off ( var, seg, off ); \
} while ( 0 )
#define put_real_kir_nonconst_off(var, seg, off)
Definition: libkir.h:107
struct golan_mkey_seg seg
Definition: CIB_PRM.h:28

Definition at line 116 of file libkir.h.

◆ get_real_kir_const_off

#define get_real_kir_const_off (   var,
  seg,
  off 
)
Value:
__asm__ ( "movw %w1, %%es\n\t" \
"mov %%es:%c2, %0\n\t" \
"pushw %%ds\n\t" /* restore %es */ \
"popw %%es\n\t" \
: "=r,r" ( var ) \
: "rm,rm" ( seg ), "i,!r" ( off ) \
)
__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 golan_mkey_seg seg
Definition: CIB_PRM.h:28

Definition at line 124 of file libkir.h.

◆ get_real_kir_nonconst_off

#define get_real_kir_nonconst_off (   var,
  seg,
  off 
)
Value:
__asm__ ( "movw %w1, %%es\n\t" \
"mov %%es:(%2), %0\n\t" \
"pushw %%ds\n\t" /* restore %es */ \
"popw %%es\n\t" \
: "=r" ( var ) \
: "rm" ( seg ), "r" ( off ) \
)
__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 golan_mkey_seg seg
Definition: CIB_PRM.h:28

Definition at line 133 of file libkir.h.

◆ get_real_kir

#define get_real_kir (   var,
  seg,
  off 
)
Value:
do { \
if ( __builtin_constant_p ( off ) ) \
get_real_kir_const_off ( var, seg, off ); \
} while ( 0 )
struct golan_mkey_seg seg
Definition: CIB_PRM.h:28
#define get_real_kir_nonconst_off(var, seg, off)
Definition: libkir.h:133

Definition at line 142 of file libkir.h.

◆ put_real

#define put_real   put_real_kir

Definition at line 150 of file libkir.h.

◆ get_real

#define get_real   get_real_kir

Definition at line 151 of file libkir.h.

◆ TEXT16_CODE

#define TEXT16_CODE (   asm_code_str)
Value:
".section \".text16\", \"ax\", @progbits\n\t" \
".code16\n\t" \
".arch i386\n\t" \
asm_code_str "\n\t" \
".code16gcc\n\t" \
".previous\n\t"

Definition at line 217 of file libkir.h.

◆ REAL_CODE

#define REAL_CODE (   asm_code_str)
Value:
".code16\n\t" \
asm_code_str "\n\t" \
".code16gcc\n\t"

Definition at line 226 of file libkir.h.

Typedef Documentation

◆ userptr_t

A pointer to a user buffer.

This is actually a struct segoff, but encoded as a uint32_t to ensure that gcc passes it around efficiently.

Definition at line 159 of file libkir.h.

Function Documentation

◆ __attribute__()

static __attribute__ ( (always_inline)  )
inlinestatic

Copy data to user buffer.

Convert virtual address to user buffer.

Convert segment:offset address to user buffer.

Copy data from user buffer.

Parameters
bufferUser buffer
offsetOffset within user buffer
srcSource
lenLength
destDestination
bufferUser buffer
offsetOffset within user buffer
lenLength
segmentReal-mode segment
offsetReal-mode offset
Return values
bufferUser buffer
Parameters
virtualVirtual address
Return values
bufferUser buffer

This constructs a user buffer from an ordinary pointer. Use it when you need to pass a pointer to an internal buffer to a function that expects a userptr_t.

Definition at line 26 of file libkir.h.

26  {
27  uint16_t cs;
28  __asm__ __volatile__ ( "movw %%cs, %w0" : "=r" ( cs ) );
29  return cs;
30 }
unsigned short uint16_t
Definition: stdint.h:11
__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")
uint32_t cs
Definition: librm.h:263

References __asm__(), __volatile__(), and cs.

◆ copy_to_real_libkir()

static void copy_to_real_libkir ( unsigned int  dest_seg,
unsigned int  dest_off,
const void *  src,
size_t  n 
)
inlinestatic

Definition at line 43 of file libkir.h.

45  {
46  unsigned int discard_D, discard_S, discard_c;
47 
48  __asm__ __volatile__ ( "pushw %%es\n\t"
49  "movw %3, %%es\n\t"
50  "rep movsb\n\t"
51  "popw %%es\n\t"
52  : "=D" ( discard_D ), "=S" ( discard_S ),
53  "=c" ( discard_c )
54  : "r" ( dest_seg ), "D" ( dest_off ),
55  "S" ( src ),
56  "c" ( n )
57  : "memory" );
58 }
static off_t const void * src
Definition: libkir.h:170
void * discard_S
Definition: bigint.h:57
static __always_inline void off_t dest_off
Definition: efi_uaccess.h:66
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")
long discard_c
Definition: bigint.h:30
unsigned int n
Definition: entropy.h:159

References __asm__(), __volatile__(), dest_off, discard_c, discard_D, discard_S, n, and src.

◆ copy_from_real_libkir()

static void copy_from_real_libkir ( void *  dest,
unsigned int  src_seg,
unsigned int  src_off,
size_t  n 
)
inlinestatic

Definition at line 60 of file libkir.h.

63  {
64  unsigned int discard_D, discard_S, discard_c;
65 
66  __asm__ __volatile__ ( "pushw %%ds\n\t"
67  "movw %4, %%ds\n\t"
68  "rep movsb\n\t"
69  "popw %%ds\n\t"
70  : "=D" ( discard_D ), "=S" ( discard_S ),
71  "=c" ( discard_c )
72  : "D" ( dest ),
73  "r" ( src_seg ), "S" ( src_off ),
74  "c" ( n )
75  : "memory" );
76 }
static __always_inline void off_t userptr_t off_t src_off
Definition: efi_uaccess.h:66
void * discard_S
Definition: bigint.h:57
static void * dest
Definition: strings.h:176
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")
long discard_c
Definition: bigint.h:30
unsigned int n
Definition: entropy.h:159

References __asm__(), __volatile__(), dest, discard_c, discard_D, discard_S, n, and src_off.

Variable Documentation

◆ offset

unsigned int offset
Initial value:
{
return ( ( segment << 16 ) | offset )
uint16_t segment
Code segment.
Definition: librm.h:252
static off_t offset
Definition: libkir.h:170

Definition at line 170 of file libkir.h.

◆ src

off_t const void* src

Definition at line 170 of file libkir.h.

Referenced by copy_to_real_libkir().

◆ len

Initial value:
{
copy_to_real ( ( buffer >> 16 ), ( ( buffer & 0xffff ) + offset ),
src, len )
static off_t const void * src
Definition: libkir.h:170
static off_t const void size_t len
Definition: libkir.h:170
static userptr_t buffer
Definition: libkir.h:184
#define copy_to_real
Definition: libkir.h:78
static off_t offset
Definition: libkir.h:170

Definition at line 170 of file libkir.h.

◆ buffer

userptr_t buffer

Definition at line 184 of file libkir.h.