iPXE
Macros | Functions | Variables
librm_mgmt.c File Reference
#include <stdint.h>
#include <strings.h>
#include <assert.h>
#include <ipxe/profile.h>
#include <realmode.h>
#include <pic8259.h>
#include <ipxe/shell.h>

Go to the source code of this file.

Macros

#define STACK_DUMP_LEN   128
 Length of stack dump. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
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. More...
 
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. More...
 
void set_interrupt_vector (unsigned int intr, void *vector)
 Set interrupt vector. More...
 
void init_idt (void)
 Initialise interrupt descriptor table. More...
 
static struct profilerinterrupt_profiler (int intr)
 Determine interrupt profiler (for debugging) More...
 
static void interrupt_dump (int intr, struct interrupt_frame32 *frame32, struct interrupt_frame64 *frame64)
 Display interrupt stack dump (for debugging) More...
 
void interrupt (int intr, struct interrupt_frame32 *frame32, struct interrupt_frame64 *frame64)
 Interrupt handler. More...
 
static void * ioremap_pages (unsigned long bus_addr, size_t len)
 Map pages for I/O. More...
 
static void iounmap_pages (volatile const void *io_addr)
 Unmap pages for I/O. More...
 
 PROVIDE_UACCESS_INLINE (librm, phys_to_user)
 
 PROVIDE_UACCESS_INLINE (librm, user_to_phys)
 
 PROVIDE_UACCESS_INLINE (librm, virt_to_user)
 
 PROVIDE_UACCESS_INLINE (librm, user_to_virt)
 
 PROVIDE_UACCESS_INLINE (librm, userptr_add)
 
 PROVIDE_UACCESS_INLINE (librm, memcpy_user)
 
 PROVIDE_UACCESS_INLINE (librm, memmove_user)
 
 PROVIDE_UACCESS_INLINE (librm, memset_user)
 
 PROVIDE_UACCESS_INLINE (librm, strlen_user)
 
 PROVIDE_UACCESS_INLINE (librm, memchr_user)
 
 PROVIDE_IOMAP_INLINE (pages, io_to_bus)
 
 PROVIDE_IOMAP (pages, ioremap, ioremap_pages)
 
 PROVIDE_IOMAP (pages, iounmap, iounmap_pages)
 

Variables

char interrupt_wrapper []
 The interrupt wrapper. More...
 
static struct interrupt_vector intr_vec [NUM_INT]
 The interrupt vectors. More...
 
static struct interrupt32_descriptor idt32 [NUM_INT]
 The 32-bit interrupt descriptor table. More...
 
struct idtr32 idtr32
 The 32-bit interrupt descriptor table register. More...
 
static struct interrupt64_descriptor idt64 [NUM_INT]
 The 64-bit interrupt descriptor table. More...
 
struct idtr64 idtr64
 The interrupt descriptor table register. More...
 
static struct profiler timer_irq_profiler __profiler = { .name = "irq.timer" }
 Timer interrupt profiler. More...
 

Macro Definition Documentation

◆ STACK_DUMP_LEN

#define STACK_DUMP_LEN   128

Length of stack dump.

Definition at line 48 of file librm_mgmt.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ copy_user_to_rm_stack()

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.

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.

64  {
65  userptr_t rm_stack;
66  rm_sp -= size;
67  rm_stack = real_to_user ( rm_ss, rm_sp );
68  memcpy_user ( rm_stack, 0, data, 0, size );
69  return rm_sp;
70 };
uint16_t rm_ss
uint8_t size
Entry size (in 32-bit words)
Definition: ena.h:16
uint16_t rm_sp
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 arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
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

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

Referenced by com32_cfarcall().

◆ remove_user_from_rm_stack()

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.

79  {
80  if ( data ) {
81  userptr_t rm_stack = real_to_user ( rm_ss, rm_sp );
82  memcpy_user ( rm_stack, 0, data, 0, size );
83  }
84  rm_sp += size;
85 };
uint16_t rm_ss
uint8_t size
Entry size (in 32-bit words)
Definition: ena.h:16
uint16_t rm_sp
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 arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
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

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

Referenced by com32_cfarcall().

◆ set_interrupt_vector()

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.

93  {
94  struct interrupt32_descriptor *idte32;
95  struct interrupt64_descriptor *idte64;
96  intptr_t addr = ( ( intptr_t ) vector );
97 
98  /* Populate 32-bit interrupt descriptor */
99  idte32 = &idt32[intr];
100  idte32->segment = VIRTUAL_CS;
101  idte32->attr = ( vector ? ( IDTE_PRESENT | IDTE_TYPE_IRQ32 ) : 0 );
102  idte32->low = ( addr >> 0 );
103  idte32->high = ( addr >> 16 );
104 
105  /* Populate 64-bit interrupt descriptor, if applicable */
106  if ( sizeof ( physaddr_t ) > sizeof ( uint32_t ) ) {
107  idte64 = &idt64[intr];
108  idte64->segment = LONG_CS;
109  idte64->attr = ( vector ?
110  ( IDTE_PRESENT | IDTE_TYPE_IRQ64 ) : 0 );
111  idte64->low = ( addr >> 0 );
112  idte64->mid = ( addr >> 16 );
113  idte64->high = ( ( ( uint64_t ) addr ) >> 32 );
114  }
115 }
uint16_t mid
Middle 16 bits of address.
Definition: librm.h:336
uint32_t vector
MSI-X vector.
Definition: ena.h:20
#define IDTE_TYPE_IRQ32
Interrupt descriptor 32-bit interrupt gate type.
Definition: librm.h:347
uint16_t high
High 16 bits of address.
Definition: librm.h:322
#define LONG_CS
Definition: librm.h:17
uint8_t attr
Type and attributes.
Definition: librm.h:320
unsigned long long uint64_t
Definition: stdint.h:13
unsigned long intptr_t
Definition: stdint.h:21
uint32_t high
High 32 bits of address.
Definition: librm.h:338
#define IDTE_TYPE_IRQ64
Interrupt descriptor 64-bit interrupt gate type.
Definition: librm.h:350
A 32-bit interrupt descriptor table entry.
Definition: librm.h:312
uint8_t intr
Interrupts enabled.
Definition: ena.h:14
uint16_t low
Low 16 bits of address.
Definition: librm.h:314
#define VIRTUAL_CS
Definition: librm.h:10
u32 addr
Definition: sky2.h:8
uint16_t low
Low 16 bits of address.
Definition: librm.h:328
unsigned int uint32_t
Definition: stdint.h:12
A 64-bit interrupt descriptor table entry.
Definition: librm.h:326
unsigned long physaddr_t
Definition: stdint.h:20
#define IDTE_PRESENT
Interrupt descriptor is present.
Definition: librm.h:344
uint16_t segment
Code segment.
Definition: librm.h:330
static struct interrupt64_descriptor idt64[NUM_INT]
The 64-bit interrupt descriptor table.
Definition: librm_mgmt.c:39
uint8_t attr
Type and attributes.
Definition: librm.h:334
uint16_t segment
Code segment.
Definition: librm.h:316
static struct interrupt32_descriptor idt32[NUM_INT]
The 32-bit interrupt descriptor table.
Definition: librm_mgmt.c:30

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, vector, and VIRTUAL_CS.

Referenced by gdbmach_init(), and init_idt().

◆ init_idt()

void init_idt ( void  )

Initialise interrupt descriptor table.

Definition at line 121 of file librm_mgmt.c.

121  {
122  struct interrupt_vector *vec;
123  unsigned int intr;
124 
125  /* Initialise the interrupt descriptor table and interrupt vectors */
126  for ( intr = 0 ; intr < NUM_INT ; intr++ ) {
127  vec = &intr_vec[intr];
128  vec->push = PUSH_INSN;
129  vec->movb = MOVB_INSN;
130  vec->intr = intr;
131  vec->jmp = JMP_INSN;
132  vec->offset = ( ( intptr_t ) interrupt_wrapper -
133  ( intptr_t ) vec->next );
134  set_interrupt_vector ( intr, vec );
135  }
136  DBGC ( &intr_vec[0], "INTn vector at %p+%zxn (phys %#lx+%zxn)\n",
137  intr_vec, sizeof ( intr_vec[0] ),
138  virt_to_phys ( intr_vec ), sizeof ( intr_vec[0] ) );
139 
140  /* Initialise the 32-bit interrupt descriptor table register */
142 
143  /* Initialise the 64-bit interrupt descriptor table register,
144  * if applicable.
145  */
146  if ( sizeof ( physaddr_t ) > sizeof ( uint32_t ) )
148 }
uint8_t next[0]
Next instruction after jump.
Definition: librm.h:372
uint8_t intr
Interrupt number.
Definition: librm.h:366
#define DBGC(...)
Definition: compiler.h:505
unsigned long intptr_t
Definition: stdint.h:21
static __always_inline unsigned long virt_to_phys(volatile const void *addr)
Convert virtual address to a physical address.
Definition: uaccess.h:287
uint8_t intr
Interrupts enabled.
Definition: ena.h:14
uint8_t movb
"movb" instruction
Definition: librm.h:364
static struct interrupt_vector intr_vec[NUM_INT]
The interrupt vectors.
Definition: librm_mgmt.c:27
#define PUSH_INSN
"push %eax" instruction
Definition: librm.h:376
An interrupt vector.
Definition: librm.h:360
A 32-bit interrupt descriptor table register.
Definition: librm.h:296
uint8_t push
"push" instruction
Definition: librm.h:362
unsigned int uint32_t
Definition: stdint.h:12
#define MOVB_INSN
"movb" instruction
Definition: librm.h:379
unsigned long physaddr_t
Definition: stdint.h:20
uint64_t base
Base.
Definition: librm.h:308
void set_interrupt_vector(unsigned int intr, void *vector)
Set interrupt vector.
Definition: librm_mgmt.c:93
#define JMP_INSN
"jmp" instruction
Definition: librm.h:382
uint32_t base
Base.
Definition: librm.h:300
char interrupt_wrapper[]
The interrupt wrapper.
uint32_t offset
Interrupt wrapper address offset.
Definition: librm.h:370
#define NUM_INT
Number of interrupts.
Definition: librm.h:293
uint8_t jmp
"jmp" instruction
Definition: librm.h:368
static struct interrupt64_descriptor idt64[NUM_INT]
The 64-bit interrupt descriptor table.
Definition: librm_mgmt.c:39
A 64-bit interrupt descriptor table register.
Definition: librm.h:304
static struct interrupt32_descriptor idt32[NUM_INT]
The 32-bit interrupt descriptor table.
Definition: librm_mgmt.c:30

References idtr32::base, idtr64::base, DBGC, idt32, idt64, interrupt_wrapper, intr, interrupt_vector::intr, intr_vec, interrupt_vector::jmp, JMP_INSN, interrupt_vector::movb, MOVB_INSN, interrupt_vector::next, NUM_INT, interrupt_vector::offset, interrupt_vector::push, PUSH_INSN, set_interrupt_vector(), and virt_to_phys().

◆ interrupt_profiler()

static struct profiler* interrupt_profiler ( int  intr)
static

Determine interrupt profiler (for debugging)

Parameters
intrInterrupt number
Return values
profilerProfiler

Definition at line 156 of file librm_mgmt.c.

156  {
157 
158  switch ( intr ) {
159  case IRQ_INT ( 0 ) :
160  return &timer_irq_profiler;
161  default:
162  return &other_irq_profiler;
163  }
164 }
uint8_t intr
Interrupts enabled.
Definition: ena.h:14
#define IRQ_INT(irq)
Definition: pic8259.h:60
return
Definition: natsemi.h:326

References intr, and IRQ_INT.

Referenced by interrupt().

◆ interrupt_dump()

static void interrupt_dump ( int  intr,
struct interrupt_frame32 frame32,
struct interrupt_frame64 frame64 
)
static

Display interrupt stack dump (for debugging)

Parameters
intrInterrupt number
frame3232-bit interrupt wrapper stack frame (or NULL)
frame6464-bit interrupt wrapper stack frame (or NULL)

Definition at line 174 of file librm_mgmt.c.

175  {
176  unsigned long sp;
177  void *stack;
178 
179  /* Do nothing unless debugging is enabled */
180  if ( ! DBG_LOG )
181  return;
182 
183  /* Print register dump */
184  if ( ( sizeof ( physaddr_t ) <= sizeof ( uint32_t ) ) || frame32 ) {
185  sp = ( frame32->esp + sizeof ( *frame32 ) -
186  offsetof ( typeof ( *frame32 ), esp ) );
187  DBGC ( &intr, "INT%d at %04x:%08x (stack %04x:%08lx):\n",
188  intr, frame32->cs, frame32->eip, frame32->ss, sp );
189  DBGC ( &intr, "cs = %04x ds = %04x es = %04x fs = %04x "
190  "gs = %04x ss = %04x\n", frame32->cs, frame32->ds,
191  frame32->es, frame32->fs, frame32->gs, frame32->ss );
192  DBGC ( &intr, "eax = %08x ebx = %08x ecx = %08x "
193  "edx = %08x flg = %08x\n", frame32->eax, frame32->ebx,
194  frame32->ecx, frame32->edx, frame32->eflags );
195  DBGC ( &intr, "esi = %08x edi = %08x ebp = %08x "
196  "esp = %08lx eip = %08x\n", frame32->esi, frame32->edi,
197  frame32->ebp, sp, frame32->eip );
198  stack = ( ( ( void * ) frame32 ) + sizeof ( *frame32 ) );
199  } else {
200  DBGC ( &intr, "INT%d at %04llx:%016llx (stack "
201  "%04llx:%016llx):\n", intr,
202  ( ( unsigned long long ) frame64->cs ),
203  ( ( unsigned long long ) frame64->rip ),
204  ( ( unsigned long long ) frame64->ss ),
205  ( ( unsigned long long ) frame64->rsp ) );
206  DBGC ( &intr, "rax = %016llx rbx = %016llx rcx = %016llx\n",
207  ( ( unsigned long long ) frame64->rax ),
208  ( ( unsigned long long ) frame64->rbx ),
209  ( ( unsigned long long ) frame64->rcx ) );
210  DBGC ( &intr, "rdx = %016llx rsi = %016llx rdi = %016llx\n",
211  ( ( unsigned long long ) frame64->rdx ),
212  ( ( unsigned long long ) frame64->rsi ),
213  ( ( unsigned long long ) frame64->rdi ) );
214  DBGC ( &intr, "rbp = %016llx rsp = %016llx flg = %016llx\n",
215  ( ( unsigned long long ) frame64->rbp ),
216  ( ( unsigned long long ) frame64->rsp ),
217  ( ( unsigned long long ) frame64->rflags ) );
218  DBGC ( &intr, "r8 = %016llx r9 = %016llx r10 = %016llx\n",
219  ( ( unsigned long long ) frame64->r8 ),
220  ( ( unsigned long long ) frame64->r9 ),
221  ( ( unsigned long long ) frame64->r10 ) );
222  DBGC ( &intr, "r11 = %016llx r12 = %016llx r13 = %016llx\n",
223  ( ( unsigned long long ) frame64->r11 ),
224  ( ( unsigned long long ) frame64->r12 ),
225  ( ( unsigned long long ) frame64->r13 ) );
226  DBGC ( &intr, "r14 = %016llx r15 = %016llx\n",
227  ( ( unsigned long long ) frame64->r14 ),
228  ( ( unsigned long long ) frame64->r15 ) );
229  sp = frame64->rsp;
230  stack = phys_to_virt ( sp );
231  }
232 
233  /* Print stack dump */
234  DBGC_HDA ( &intr, sp, stack, STACK_DUMP_LEN );
235 }
uint32_t cs
Definition: librm.h:400
uint64_t rsp
Definition: librm.h:424
uint32_t esp
Definition: librm.h:249
uint64_t r14
Definition: librm.h:407
uint64_t r12
Definition: librm.h:409
uint32_t es
Definition: librm.h:390
uint64_t rsi
Definition: librm.h:416
#define DBGC(...)
Definition: compiler.h:505
uint64_t r10
Definition: librm.h:411
uint32_t eax
Definition: librm.h:398
#define offsetof(type, field)
Get offset of a field within a structure.
Definition: stddef.h:24
uint64_t r13
Definition: librm.h:408
uint64_t ss
Definition: librm.h:425
uint64_t rcx
Definition: librm.h:418
uint32_t ds
Definition: librm.h:391
static __always_inline void * phys_to_virt(unsigned long phys_addr)
Convert physical address to a virtual address.
Definition: uaccess.h:299
uint64_t r8
Definition: librm.h:413
uint32_t edx
Definition: librm.h:395
uint64_t rax
Definition: librm.h:420
uint8_t intr
Interrupts enabled.
Definition: ena.h:14
#define DBGC_HDA(...)
Definition: compiler.h:506
uint32_t fs
Definition: librm.h:389
uint64_t r9
Definition: librm.h:412
uint32_t ecx
Definition: librm.h:396
uint32_t eip
Definition: librm.h:399
uint32_t edi
Definition: librm.h:393
uint32_t esp
Definition: librm.h:386
uint64_t rdx
Definition: librm.h:417
uint64_t r15
Definition: librm.h:406
uint32_t ebp
Definition: librm.h:392
uint32_t eflags
Definition: librm.h:401
unsigned int uint32_t
Definition: stdint.h:12
#define STACK_DUMP_LEN
Length of stack dump.
Definition: librm_mgmt.c:48
uint64_t rbp
Definition: librm.h:414
uint32_t ss
Definition: librm.h:387
unsigned long physaddr_t
Definition: stdint.h:20
uint64_t rflags
Definition: librm.h:423
uint32_t esi
Definition: librm.h:394
uint32_t gs
Definition: librm.h:388
uint32_t ebx
Definition: librm.h:397
uint64_t cs
Definition: librm.h:422
uint64_t rbx
Definition: librm.h:419
uint64_t rip
Definition: librm.h:421
#define DBG_LOG
Definition: compiler.h:317
uint64_t r11
Definition: librm.h:410
uint16_t sp
Definition: registers.h:27
uint64_t rdi
Definition: librm.h:415

References interrupt_frame32::cs, interrupt_frame64::cs, DBG_LOG, DBGC, DBGC_HDA, interrupt_frame32::ds, interrupt_frame32::eax, interrupt_frame32::ebp, interrupt_frame32::ebx, interrupt_frame32::ecx, interrupt_frame32::edi, interrupt_frame32::edx, interrupt_frame32::eflags, interrupt_frame32::eip, interrupt_frame32::es, interrupt_frame32::esi, esp, interrupt_frame32::esp, interrupt_frame32::fs, interrupt_frame32::gs, intr, offsetof, phys_to_virt(), interrupt_frame64::r10, interrupt_frame64::r11, interrupt_frame64::r12, interrupt_frame64::r13, interrupt_frame64::r14, interrupt_frame64::r15, interrupt_frame64::r8, interrupt_frame64::r9, interrupt_frame64::rax, interrupt_frame64::rbp, interrupt_frame64::rbx, interrupt_frame64::rcx, interrupt_frame64::rdi, interrupt_frame64::rdx, interrupt_frame64::rflags, interrupt_frame64::rip, interrupt_frame64::rsi, interrupt_frame64::rsp, sp, interrupt_frame32::ss, interrupt_frame64::ss, and STACK_DUMP_LEN.

Referenced by interrupt().

◆ interrupt()

void interrupt ( int  intr,
struct interrupt_frame32 frame32,
struct interrupt_frame64 frame64 
)

Interrupt handler.

Parameters
intrInterrupt number
frame3232-bit interrupt wrapper stack frame (or NULL)
frame6464-bit interrupt wrapper stack frame (or NULL)
frameInterrupt wrapper stack frame

Definition at line 246 of file librm_mgmt.c.

247  {
249  uint32_t discard_eax;
250 
251  /* Trap CPU exceptions if debugging is enabled. Note that we
252  * cannot treat INT8+ as exceptions, since we are not
253  * permitted to rebase the PIC.
254  */
255  if ( DBG_LOG && ( intr < IRQ_INT ( 0 ) ) ) {
256  interrupt_dump ( intr, frame32, frame64 );
257  DBG ( "CPU exception: dropping to emergency shell\n" );
258  shell();
259  }
260 
261  /* Reissue interrupt in real mode */
263  __asm__ __volatile__ ( REAL_CODE ( "movb %%al, %%cs:(1f + 1)\n\t"
264  "\n1:\n\t"
265  "int $0x00\n\t" )
266  : "=a" ( discard_eax ) : "0" ( intr ) );
269 }
int shell(void)
Start command shell.
Definition: shell.c:84
A data structure for storing profiling information.
Definition: profile.h:26
static void interrupt_dump(int intr, struct interrupt_frame32 *frame32, struct interrupt_frame64 *frame64)
Display interrupt stack dump (for debugging)
Definition: librm_mgmt.c:174
static void profile_stop(struct profiler *profiler)
Stop profiling.
Definition: profile.h:171
uint8_t intr
Interrupts enabled.
Definition: ena.h:14
static void profile_start(struct profiler *profiler)
Start profiling.
Definition: profile.h:158
#define IRQ_INT(irq)
Definition: pic8259.h:60
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")
static struct profiler * interrupt_profiler(int intr)
Determine interrupt profiler (for debugging)
Definition: librm_mgmt.c:156
static void profile_exclude(struct profiler *profiler)
Exclude time from other ongoing profiling results.
Definition: profile.h:184
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
#define DBG_LOG
Definition: compiler.h:317
#define REAL_CODE(asm_code_str)
Definition: libkir.h:226

References __asm__(), __volatile__(), DBG, DBG_LOG, interrupt_dump(), interrupt_profiler(), intr, IRQ_INT, profile_exclude(), profile_start(), profile_stop(), REAL_CODE, and shell().

Referenced by com32_intcall(), hook_bios_interrupt(), and unhook_bios_interrupt().

◆ ioremap_pages()

static void* ioremap_pages ( unsigned long  bus_addr,
size_t  len 
)
static

Map pages for I/O.

Parameters
bus_addrBus address
lenLength of region
Return values
io_addrI/O address

Definition at line 278 of file librm_mgmt.c.

278  {
279  unsigned long start;
280  unsigned int count;
281  unsigned int stride;
282  unsigned int first;
283  unsigned int i;
284  size_t offset;
285  void *io_addr;
286 
287  DBGC ( &io_pages, "IO mapping %08lx+%zx\n", bus_addr, len );
288 
289  /* Sanity check */
290  if ( ! len )
291  return NULL;
292 
293  /* Round down start address to a page boundary */
294  start = ( bus_addr & ~( IO_PAGE_SIZE - 1 ) );
295  offset = ( bus_addr - start );
296  assert ( offset < IO_PAGE_SIZE );
297 
298  /* Calculate number of pages required */
299  count = ( ( offset + len + IO_PAGE_SIZE - 1 ) / IO_PAGE_SIZE );
300  assert ( count != 0 );
301  assert ( count < ( sizeof ( io_pages.page ) /
302  sizeof ( io_pages.page[0] ) ) );
303 
304  /* Round up number of pages to a power of two */
305  stride = ( 1 << ( fls ( count ) - 1 ) );
306  assert ( count <= stride );
307 
308  /* Allocate pages */
309  for ( first = 0 ; first < ( sizeof ( io_pages.page ) /
310  sizeof ( io_pages.page[0] ) ) ;
311  first += stride ) {
312 
313  /* Calculate I/O address */
314  io_addr = ( IO_BASE + ( first * IO_PAGE_SIZE ) + offset );
315 
316  /* Check that page table entries are available */
317  for ( i = first ; i < ( first + count ) ; i++ ) {
318  if ( io_pages.page[i] & PAGE_P ) {
319  io_addr = NULL;
320  break;
321  }
322  }
323  if ( ! io_addr )
324  continue;
325 
326  /* Create page table entries */
327  for ( i = first ; i < ( first + count ) ; i++ ) {
328  io_pages.page[i] = ( start | PAGE_P | PAGE_RW |
330  PAGE_PS );
331  start += IO_PAGE_SIZE;
332  }
333 
334  /* Mark last page as being the last in this allocation */
335  io_pages.page[ i - 1 ] |= PAGE_LAST;
336 
337  /* Return I/O address */
338  DBGC ( &io_pages, "IO mapped %08lx+%zx to %p using PTEs "
339  "[%d-%d]\n", bus_addr, len, io_addr, first,
340  ( first + count - 1 ) );
341  return io_addr;
342  }
343 
344  DBGC ( &io_pages, "IO could not map %08lx+%zx\n", bus_addr, len );
345  return NULL;
346 }
#define IO_PAGE_SIZE
I/O page size.
Definition: librm.h:466
Page-level write-through.
Definition: librm.h:445
#define DBGC(...)
Definition: compiler.h:505
Page-level cache disable.
Definition: librm.h:447
uint32_t start
Starting offset.
Definition: netvsc.h:12
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define IO_BASE
I/O page base address.
Definition: librm.h:473
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
Page is the last page in an allocation.
Definition: librm.h:455
Page is a large page.
Definition: librm.h:449
uint32_t len
Length.
Definition: ena.h:14
uint16_t count
Number of entries.
Definition: ena.h:22
Page is writable.
Definition: librm.h:441
struct page_table io_pages
The I/O space page table.
Page is accessible by user code.
Definition: librm.h:443
uint64_t page[512]
Page address and flags.
Definition: librm.h:433
#define fls(x)
Find last (i.e.
Definition: strings.h:166
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
uint32_t first
Length to skip in first segment.
Definition: pccrc.h:23
Page is present.
Definition: librm.h:439

References assert(), count, DBGC, first, fls, IO_BASE, IO_PAGE_SIZE, io_pages, len, NULL, offset, page_table::page, PAGE_LAST, PAGE_P, PAGE_PCD, PAGE_PS, PAGE_PWT, PAGE_RW, PAGE_US, and start.

◆ iounmap_pages()

static void iounmap_pages ( volatile const void *  io_addr)
static

Unmap pages for I/O.

Parameters
io_addrI/O address

Definition at line 353 of file librm_mgmt.c.

353  {
354  volatile const void *invalidate = io_addr;
355  unsigned int first;
356  unsigned int i;
357  int is_last;
358 
359  DBGC ( &io_pages, "IO unmapping %p\n", io_addr );
360 
361  /* Calculate first page table entry */
362  first = ( ( io_addr - IO_BASE ) / IO_PAGE_SIZE );
363 
364  /* Clear page table entries */
365  for ( i = first ; ; i++ ) {
366 
367  /* Sanity check */
368  assert ( io_pages.page[i] & PAGE_P );
369 
370  /* Check if this is the last page in this allocation */
371  is_last = ( io_pages.page[i] & PAGE_LAST );
372 
373  /* Clear page table entry */
374  io_pages.page[i] = 0;
375 
376  /* Invalidate TLB for this page */
377  __asm__ __volatile__ ( "invlpg (%0)" : : "r" ( invalidate ) );
378  invalidate += IO_PAGE_SIZE;
379 
380  /* Terminate if this was the last page */
381  if ( is_last )
382  break;
383  }
384 
385  DBGC ( &io_pages, "IO unmapped %p using PTEs [%d-%d]\n",
386  io_addr, first, i );
387 }
#define IO_PAGE_SIZE
I/O page size.
Definition: librm.h:466
#define DBGC(...)
Definition: compiler.h:505
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define IO_BASE
I/O page base address.
Definition: librm.h:473
Page is the last page in an allocation.
Definition: librm.h:455
__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")
struct page_table io_pages
The I/O space page table.
uint64_t page[512]
Page address and flags.
Definition: librm.h:433
uint32_t first
Length to skip in first segment.
Definition: pccrc.h:23
Page is present.
Definition: librm.h:439

References __asm__(), __volatile__(), assert(), DBGC, first, IO_BASE, IO_PAGE_SIZE, io_pages, page_table::page, PAGE_LAST, and PAGE_P.

◆ PROVIDE_UACCESS_INLINE() [1/10]

PROVIDE_UACCESS_INLINE ( librm  ,
phys_to_user   
)

◆ PROVIDE_UACCESS_INLINE() [2/10]

PROVIDE_UACCESS_INLINE ( librm  ,
user_to_phys   
)

◆ PROVIDE_UACCESS_INLINE() [3/10]

PROVIDE_UACCESS_INLINE ( librm  ,
virt_to_user   
)

◆ PROVIDE_UACCESS_INLINE() [4/10]

PROVIDE_UACCESS_INLINE ( librm  ,
user_to_virt   
)

◆ PROVIDE_UACCESS_INLINE() [5/10]

PROVIDE_UACCESS_INLINE ( librm  ,
userptr_add   
)

◆ PROVIDE_UACCESS_INLINE() [6/10]

PROVIDE_UACCESS_INLINE ( librm  ,
memcpy_user   
)

◆ PROVIDE_UACCESS_INLINE() [7/10]

PROVIDE_UACCESS_INLINE ( librm  ,
memmove_user   
)

◆ PROVIDE_UACCESS_INLINE() [8/10]

PROVIDE_UACCESS_INLINE ( librm  ,
memset_user   
)

◆ PROVIDE_UACCESS_INLINE() [9/10]

PROVIDE_UACCESS_INLINE ( librm  ,
strlen_user   
)

◆ PROVIDE_UACCESS_INLINE() [10/10]

PROVIDE_UACCESS_INLINE ( librm  ,
memchr_user   
)

◆ PROVIDE_IOMAP_INLINE()

PROVIDE_IOMAP_INLINE ( pages  ,
io_to_bus   
)

◆ PROVIDE_IOMAP() [1/2]

PROVIDE_IOMAP ( pages  ,
ioremap  ,
ioremap_pages   
)

◆ PROVIDE_IOMAP() [2/2]

PROVIDE_IOMAP ( pages  ,
iounmap  ,
iounmap_pages   
)

Variable Documentation

◆ interrupt_wrapper

char interrupt_wrapper[]

The interrupt wrapper.

Referenced by init_idt().

◆ intr_vec

struct interrupt_vector intr_vec[NUM_INT]
static

The interrupt vectors.

Definition at line 27 of file librm_mgmt.c.

Referenced by init_idt().

◆ idt32

struct interrupt32_descriptor idt32[NUM_INT]
static

The 32-bit interrupt descriptor table.

Definition at line 30 of file librm_mgmt.c.

Referenced by init_idt(), and set_interrupt_vector().

◆ idtr32

struct idtr32 idtr32
Initial value:
= {
.limit = ( sizeof ( idt32 ) - 1 ),
}
static struct interrupt32_descriptor idt32[NUM_INT]
The 32-bit interrupt descriptor table.
Definition: librm_mgmt.c:30

The 32-bit interrupt descriptor table register.

Definition at line 34 of file librm_mgmt.c.

◆ idt64

struct interrupt64_descriptor idt64[NUM_INT]
static

The 64-bit interrupt descriptor table.

Definition at line 39 of file librm_mgmt.c.

Referenced by init_idt(), and set_interrupt_vector().

◆ idtr64

struct idtr64 idtr64
Initial value:
= {
.limit = ( sizeof ( idt64 ) - 1 ),
}
static struct interrupt64_descriptor idt64[NUM_INT]
The 64-bit interrupt descriptor table.
Definition: librm_mgmt.c:39

The interrupt descriptor table register.

Definition at line 43 of file librm_mgmt.c.

◆ __profiler

struct profiler other_irq_profiler __profiler = { .name = "irq.timer" }
static

Timer interrupt profiler.

Other interrupt profiler.

Definition at line 51 of file librm_mgmt.c.