iPXE
Data Structures | Defines | Enumerations | Functions | Variables
librm.h File Reference

Go to the source code of this file.

Data Structures

struct  idtr32
 A 32-bit interrupt descriptor table register. More...
struct  idtr64
 A 64-bit interrupt descriptor table register. More...
struct  interrupt32_descriptor
 A 32-bit interrupt descriptor table entry. More...
struct  interrupt64_descriptor
 A 64-bit interrupt descriptor table entry. More...
struct  interrupt_vector
 An interrupt vector. More...
struct  interrupt_frame32
 32-bit interrupt wrapper stack frame More...
struct  interrupt_frame64
 64-bit interrupt wrapper stack frame More...
struct  page_table
 A page table. More...

Defines

#define VIRTUAL_CS   0x08
#define VIRTUAL_DS   0x10
#define PHYSICAL_CS   0x18
#define PHYSICAL_DS   0x20
#define REAL_CS   0x28
#define REAL_DS   0x30
#define P2R_DS   0x38
#define LONG_CS   0x40
#define VIRTUAL(address)   (address)
#define UACCESS_PREFIX_librm   __librm_
#define VIRT_CALL(function)
 Call C function from real-mode code.
#define __data16(variable)
#define __data16_array(variable, array)
#define __bss16(variable)
#define __bss16_array(variable, array)
#define __text16(variable)
#define __text16_array(variable, array)
#define __use_data16(variable)
#define __use_text16(variable)
#define __from_data16(pointer)
#define __from_text16(pointer)
#define rm_cs   __use_text16 ( rm_cs )
#define rm_ds   __use_text16 ( rm_ds )
#define CODE_DEFAULT   ".code32"
#define LINE_SYMBOL   _S2 ( OBJECT ) "__line_" _S2 ( __LINE__ ) "__%=:"
#define TEXT16_CODE(asm_code_str)
#define REAL_CODE(asm_code_str)
#define PHYS_CODE(asm_code_str)
#define NUM_INT   256
 Number of interrupts.
#define IDTE_PRESENT   0x80
 Interrupt descriptor is present.
#define IDTE_TYPE_IRQ32   0x0e
 Interrupt descriptor 32-bit interrupt gate type.
#define IDTE_TYPE_IRQ64   0x0e
 Interrupt descriptor 64-bit interrupt gate type.
#define PUSH_INSN   0x50
 "push %eax" instruction
#define MOVB_INSN   0xb0
 "movb" instruction
#define JMP_INSN   0xe9
 "jmp" instruction
#define IO_PAGE_SIZE   0x200000UL
 I/O page size.
#define IO_BASE   ( ( void * ) 0x100000000ULL )
 I/O page base address.

Enumerations

enum  page_flags {
  PAGE_P = 0x01, PAGE_RW = 0x02, PAGE_US = 0x04, PAGE_PWT = 0x08,
  PAGE_PCD = 0x10, PAGE_PS = 0x80, PAGE_LAST = 0x800
}
 Page flags. More...

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
static __always_inline userptr_t UACCESS_INLINE (librm, phys_to_user)(unsigned long phys_addr)
 Convert physical address to user pointer.
static __always_inline
unsigned long 
UACCESS_INLINE (librm, user_to_phys)(userptr_t userptr
 Convert user buffer to physical address.
const uint16_t __text16 (rm_cs)
const uint16_t __text16 (rm_ds)
uint16_t copy_user_to_rm_stack (userptr_t data, size_t size)
 Allocate space on the real-mode stack and copy data there from a user buffer.
void remove_user_from_rm_stack (userptr_t data, size_t size)
 Deallocate space on the real-mode stack, optionally copying back data to a user buffer.
struct idtr32 __attribute__ ((packed))
void set_interrupt_vector (unsigned int intr, void *vector)
 Set interrupt vector.

Variables

const unsigned long virt_offset
char *const text16
uint16_t rm_sp
uint16_t rm_ss
uint16_t limit
 Limit.
uint32_t base
 Base.
uint16_t low
 Low 16 bits of address.
uint16_t segment
 Code segment.
uint8_t unused
 Unused.
uint8_t attr
 Type and attributes.
uint16_t high
 High 16 bits of address.
uint16_t mid
 Middle 16 bits of address.
uint32_t reserved
 Reserved.
uint8_t push
 "push" instruction
uint8_t movb
 "movb" instruction
uint8_t intr
 Interrupt number.
uint8_t jmp
 "jmp" instruction
uint32_t offset
 Interrupt wrapper address offset.
uint8_t next [0]
 Next instruction after jump.
uint32_t esp
uint32_t ss
uint32_t gs
uint32_t fs
uint32_t es
uint32_t ds
uint32_t ebp
uint32_t edi
uint32_t esi
uint32_t edx
uint32_t ecx
uint32_t ebx
uint32_t eax
uint32_t eip
uint32_t cs
uint32_t eflags
uint64_t r15
uint64_t r14
uint64_t r13
uint64_t r12
uint64_t r11
uint64_t r10
uint64_t r9
uint64_t r8
uint64_t rbp
uint64_t rdi
uint64_t rsi
uint64_t rdx
uint64_t rcx
uint64_t rbx
uint64_t rax
uint64_t rip
uint64_t rflags
uint64_t rsp
struct page_table __attribute__
struct page_table io_pages
 The I/O space page table.

Define Documentation

#define VIRTUAL_CS   0x08

Definition at line 10 of file librm.h.

Referenced by set_interrupt_vector().

#define VIRTUAL_DS   0x10

Definition at line 11 of file librm.h.

#define PHYSICAL_CS   0x18

Definition at line 12 of file librm.h.

#define PHYSICAL_DS   0x20

Definition at line 13 of file librm.h.

#define REAL_CS   0x28

Definition at line 14 of file librm.h.

#define REAL_DS   0x30

Definition at line 15 of file librm.h.

#define P2R_DS   0x38

Definition at line 16 of file librm.h.

#define LONG_CS   0x40

Definition at line 17 of file librm.h.

Referenced by set_interrupt_vector().

#define VIRTUAL (   address)    (address)

Definition at line 50 of file librm.h.

#define UACCESS_PREFIX_librm   __librm_

Definition at line 70 of file librm.h.

#define VIRT_CALL (   function)
Value:
"pushl $( " _S2 ( VIRTUAL ( function ) ) " )\n\t"               \
        "call virt_call\n\t"

Call C function from real-mode code.

Parameters:
functionC function

Definition at line 78 of file librm.h.

Referenced by _dump_regs(), bios_inject_startup(), hook_comboot_interrupts(), int13_hook_vector(), and librm_test_exec().

#define __data16 (   variable)
Value:
__attribute__ (( section ( ".data16" ) ))                       \
        _data16_ ## variable __asm__ ( #variable )

Definition at line 199 of file librm.h.

#define __data16_array (   variable,
  array 
)
Value:
__attribute__ (( section ( ".data16" ) ))                       \
        _data16_ ## variable array __asm__ ( #variable )

Definition at line 203 of file librm.h.

#define __bss16 (   variable)
Value:
__attribute__ (( section ( ".bss16" ) ))                        \
        _data16_ ## variable __asm__ ( #variable )

Definition at line 207 of file librm.h.

#define __bss16_array (   variable,
  array 
)
Value:
__attribute__ (( section ( ".bss16" ) ))                        \
        _data16_ ## variable array __asm__ ( #variable )

Definition at line 211 of file librm.h.

#define __text16 (   variable)
Value:
__attribute__ (( section ( ".text16.data" ) ))                  \
        _text16_ ## variable __asm__ ( #variable )

Definition at line 215 of file librm.h.

#define __text16_array (   variable,
  array 
)
Value:
__attribute__ (( section ( ".text16.data" ) ))                  \
        _text16_ ## variable array __asm__ ( #variable )

Definition at line 219 of file librm.h.

#define __use_data16 (   variable)
Value:
( * ( ( typeof ( _data16_ ## variable ) * )                     \
              & ( data16 [ ( size_t ) & ( _data16_ ## variable ) ] ) ) )

Definition at line 223 of file librm.h.

#define __use_text16 (   variable)
Value:
( * ( ( typeof ( _text16_ ## variable ) * )                     \
              & ( text16 [ ( size_t ) & ( _text16_ ## variable ) ] ) ) )

Definition at line 227 of file librm.h.

#define __from_data16 (   pointer)
Value:
( ( unsigned int )                                              \
          ( ( ( void * ) (pointer) ) - ( ( void * ) data16 ) ) )

Definition at line 231 of file librm.h.

#define __from_text16 (   pointer)
Value:
( ( unsigned int )                                              \
          ( ( ( void * ) (pointer) ) - ( ( void * ) text16 ) ) )

Definition at line 235 of file librm.h.

#define rm_cs   __use_text16 ( rm_cs )

Definition at line 243 of file librm.h.

#define rm_ds   __use_text16 ( rm_ds )

Definition at line 245 of file librm.h.

#define CODE_DEFAULT   ".code32"

Definition at line 254 of file librm.h.

#define LINE_SYMBOL   _S2 ( OBJECT ) "__line_" _S2 ( __LINE__ ) "__%=:"

Definition at line 258 of file librm.h.

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

Definition at line 261 of file librm.h.

#define REAL_CODE (   asm_code_str)
Value:
"push $1f\n\t"                                  \
        "call real_call\n\t"                            \
        TEXT16_CODE ( "\n1:\n\t"                        \
                      asm_code_str                      \
                      "\n\t"                            \
                      "ret\n\t" )

Definition at line 270 of file librm.h.

#define PHYS_CODE (   asm_code_str)
Value:
"push $1f\n\t"                                  \
        "call phys_call\n\t"                            \
        ".section \".text.phys\", \"ax\", @progbits\n\t"\
        "\n" LINE_SYMBOL "\n\t"                         \
        ".code32\n\t"                                   \
        "\n1:\n\t"                                      \
        asm_code_str                                    \
        "\n\t"                                          \
        "ret\n\t"                                       \
        CODE_DEFAULT "\n\t"                             \
        ".previous\n\t"

Definition at line 279 of file librm.h.

Referenced by com32_exec_loop(), elfboot_exec(), multiboot_exec(), and nbi_boot32().

#define NUM_INT   256

Number of interrupts.

Definition at line 293 of file librm.h.

Referenced by init_idt().

#define IDTE_PRESENT   0x80

Interrupt descriptor is present.

Definition at line 344 of file librm.h.

Referenced by set_interrupt_vector().

#define IDTE_TYPE_IRQ32   0x0e

Interrupt descriptor 32-bit interrupt gate type.

Definition at line 347 of file librm.h.

Referenced by set_interrupt_vector().

#define IDTE_TYPE_IRQ64   0x0e

Interrupt descriptor 64-bit interrupt gate type.

Definition at line 350 of file librm.h.

Referenced by set_interrupt_vector().

#define PUSH_INSN   0x50

"push %eax" instruction

Definition at line 376 of file librm.h.

Referenced by init_idt().

#define MOVB_INSN   0xb0

"movb" instruction

Definition at line 379 of file librm.h.

Referenced by init_idt().

#define JMP_INSN   0xe9

"jmp" instruction

Definition at line 382 of file librm.h.

Referenced by init_idt().

#define IO_PAGE_SIZE   0x200000UL

I/O page size.

We choose to use 2MB pages for I/O space, to minimise the number of page table entries required.

Definition at line 466 of file librm.h.

Referenced by ioremap_pages(), and iounmap_pages().

#define IO_BASE   ( ( void * ) 0x100000000ULL )

I/O page base address.

We choose to place I/O space immediately above the identity-mapped 32-bit address space.

Definition at line 473 of file librm.h.

Referenced by ioremap_pages(), and iounmap_pages().


Enumeration Type Documentation

enum page_flags

Page flags.

Enumerator:
PAGE_P 

Page is present.

PAGE_RW 

Page is writable.

PAGE_US 

Page is accessible by user code.

PAGE_PWT 

Page-level write-through.

PAGE_PCD 

Page-level cache disable.

PAGE_PS 

Page is a large page.

PAGE_LAST 

Page is the last page in an allocation.

This bit is ignored by the hardware. We use it to track the size of allocations made by ioremap().

Definition at line 437 of file librm.h.

                {
        /** Page is present */
        PAGE_P = 0x01,
        /** Page is writable */
        PAGE_RW = 0x02,
        /** Page is accessible by user code */
        PAGE_US = 0x04,
        /** Page-level write-through */
        PAGE_PWT = 0x08,
        /** Page-level cache disable */
        PAGE_PCD = 0x10,
        /** Page is a large page */
        PAGE_PS = 0x80,
        /** Page is the last page in an allocation
         *
         * This bit is ignored by the hardware.  We use it to track
         * the size of allocations made by ioremap().
         */
        PAGE_LAST = 0x800,
};

Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
static __always_inline userptr_t UACCESS_INLINE ( librm  ,
phys_to_user   
) [inline, static]

Convert physical address to user pointer.

Parameters:
phys_addrPhysical address
Return values:
userptrUser pointer

Definition at line 92 of file librm.h.

                                                                   {

        /* In a 64-bit build, any valid physical address is directly
         * usable as a virtual address, since the low 4GB is
         * identity-mapped.
         */
        if ( sizeof ( physaddr_t ) > sizeof ( uint32_t ) )
                return phys_addr;

        /* In a 32-bit build, subtract virt_offset */
        return ( phys_addr - virt_offset );
}
static __always_inline unsigned long UACCESS_INLINE ( librm  ,
user_to_phys   
) [inline, static]

Convert user buffer to physical address.

Parameters:
userptrUser pointer
offsetOffset from user pointer
Return values:
phys_addrPhysical address
const uint16_t __text16 ( rm_cs  )
const uint16_t __text16 ( rm_ds  )

Allocate space on the real-mode stack and copy data there from a user buffer.

Parameters:
dataUser buffer
sizeSize of stack data
Return values:
spNew value of real-mode stack pointer

Definition at line 64 of file librm_mgmt.c.

References memcpy_user(), real_to_user(), rm_sp, rm_ss, and size.

Referenced by com32_cfarcall().

                                                               {
        userptr_t rm_stack;
        rm_sp -= size;
        rm_stack = real_to_user ( rm_ss, rm_sp );
        memcpy_user ( rm_stack, 0, data, 0, size );
        return rm_sp;
};
void remove_user_from_rm_stack ( userptr_t  data,
size_t  size 
)

Deallocate space on the real-mode stack, optionally copying back data to a user buffer.

Parameters:
dataUser buffer
sizeSize of stack data

Definition at line 79 of file librm_mgmt.c.

References memcpy_user(), real_to_user(), rm_sp, rm_ss, and size.

Referenced by com32_cfarcall().

                                                               {
        if ( data ) {
                userptr_t rm_stack = real_to_user ( rm_ss, rm_sp );
                memcpy_user ( rm_stack, 0, data, 0, size );
        }
        rm_sp += size;
};
struct idtr32 __attribute__ ( (packed)  )
void set_interrupt_vector ( unsigned int  intr,
void *  vector 
)

Set interrupt vector.

Parameters:
intrInterrupt number
vectorInterrupt vector, or NULL to disable

Definition at line 93 of file librm_mgmt.c.

References addr, interrupt32_descriptor::attr, interrupt64_descriptor::attr, interrupt32_descriptor::high, interrupt64_descriptor::high, idt32, idt64, IDTE_PRESENT, IDTE_TYPE_IRQ32, IDTE_TYPE_IRQ64, intr, LONG_CS, interrupt32_descriptor::low, interrupt64_descriptor::low, interrupt64_descriptor::mid, interrupt32_descriptor::segment, interrupt64_descriptor::segment, and VIRTUAL_CS.

Referenced by gdbmach_init(), and init_idt().

                                                              {
        struct interrupt32_descriptor *idte32;
        struct interrupt64_descriptor *idte64;
        intptr_t addr = ( ( intptr_t ) vector );

        /* Populate 32-bit interrupt descriptor */
        idte32 = &idt32[intr];
        idte32->segment = VIRTUAL_CS;
        idte32->attr = ( vector ? ( IDTE_PRESENT | IDTE_TYPE_IRQ32 ) : 0 );
        idte32->low = ( addr >> 0 );
        idte32->high = ( addr >> 16 );

        /* Populate 64-bit interrupt descriptor, if applicable */
        if ( sizeof ( physaddr_t ) > sizeof ( uint32_t ) ) {
                idte64 = &idt64[intr];
                idte64->segment = LONG_CS;
                idte64->attr = ( vector ?
                                 ( IDTE_PRESENT | IDTE_TYPE_IRQ64 ) : 0 );
                idte64->low = ( addr >> 0 );
                idte64->mid = ( addr >> 16 );
                idte64->high = ( ( ( uint64_t ) addr ) >> 32 );
        }
}

Variable Documentation

const unsigned long virt_offset
char* const text16

Base.

Definition at line 305 of file librm.h.

Low 16 bits of address.

Definition at line 325 of file librm.h.

Unused.

Definition at line 329 of file librm.h.

High 16 bits of address.

High 32 bits of address.

Definition at line 333 of file librm.h.

Middle 16 bits of address.

Definition at line 351 of file librm.h.

Referenced by peerblk_raw_rx(), and prep_segment().

Reserved.

Definition at line 355 of file librm.h.

"push" instruction

Definition at line 375 of file librm.h.

"movb" instruction

Definition at line 377 of file librm.h.

Interrupt number.

Definition at line 379 of file librm.h.

"jmp" instruction

Definition at line 381 of file librm.h.

Referenced by pxe_start_nbp().

Interrupt wrapper address offset.

Definition at line 383 of file librm.h.

Next instruction after jump.

Definition at line 385 of file librm.h.

Definition at line 403 of file librm.h.

Referenced by interrupt_dump().

Definition at line 404 of file librm.h.

Referenced by ath9k_hw_get_gain_boundaries_pdadcs(), and memsetw().

Definition at line 405 of file librm.h.

Definition at line 406 of file librm.h.

Referenced by efi_local_open_root().

Definition at line 407 of file librm.h.

Definition at line 409 of file librm.h.

Definition at line 410 of file librm.h.

Referenced by __attribute__().

Definition at line 411 of file librm.h.

Referenced by __attribute__().

Definition at line 412 of file librm.h.

Referenced by hv_map_hypercall(), and hvm_cpuid_base().

Definition at line 413 of file librm.h.

Definition at line 414 of file librm.h.

Definition at line 415 of file librm.h.

Definition at line 416 of file librm.h.

Definition at line 417 of file librm.h.

Referenced by __attribute__().

Definition at line 418 of file librm.h.

Definition at line 427 of file librm.h.

Definition at line 428 of file librm.h.

Definition at line 429 of file librm.h.

Definition at line 430 of file librm.h.

Definition at line 431 of file librm.h.

Definition at line 432 of file librm.h.

Definition at line 433 of file librm.h.

Definition at line 434 of file librm.h.

Definition at line 435 of file librm.h.

Definition at line 436 of file librm.h.

Definition at line 437 of file librm.h.

Definition at line 438 of file librm.h.

Definition at line 439 of file librm.h.

Definition at line 440 of file librm.h.

Definition at line 441 of file librm.h.

Definition at line 442 of file librm.h.

Definition at line 444 of file librm.h.

The I/O space page table.

Referenced by ioremap_pages(), and iounmap_pages().