L4Re Operating System Framework
Interface and Usage Documentation
Loading...
Searching...
No Matches
utcb.h
Go to the documentation of this file.
1
6/*
7 * Copyright (C) 2021, 2024 Kernkonzept GmbH.
8 * Author(s): Georg Kotheimer <georg.kotheimer@kernkonzept.com>
9 *
10 * License: see LICENSE.spdx (in this directory or the directories above)
11 */
12#pragma once
13
14#include <l4/sys/types.h>
15
20
21enum L4_riscv_exc_cause
22{
23 L4_riscv_exc_inst_misaligned = 0,
24 L4_riscv_exc_inst_access = 1,
25 L4_riscv_exc_illegal_inst = 2,
26 L4_riscv_exc_breakpoint = 3,
27 L4_riscv_exc_load_access = 5,
28 L4_riscv_exc_store_access = 7,
29 L4_riscv_exc_ecall = 8,
30 L4_riscv_exc_hcall = 10,
31 L4_riscv_exc_inst_page_fault = 12,
32 L4_riscv_exc_load_page_fault = 13,
33 L4_riscv_exc_store_page_fault = 15,
34 L4_riscv_exc_guest_inst_page_fault = 20,
35 L4_riscv_exc_guest_load_page_fault = 21,
36 L4_riscv_exc_virtual_inst = 22,
37 L4_riscv_exc_guest_store_page_fault = 23,
38
39 L4_riscv_ec_l4_ipc_upcall = 0x18,
40 L4_riscv_ec_l4_exregs_exception = 0x19,
41 L4_riscv_ec_l4_debug_ipi = 0x1a,
42 L4_riscv_ec_l4_alien_after_syscall = 0x1b,
43};
44
49struct l4_exc_regs_t
50{
51 l4_umword_t eret_work;
52 union
53 {
54 l4_umword_t r[31];
55 struct
56 {
57 l4_umword_t ra;
59 l4_umword_t gp;
60 l4_umword_t tp;
61 l4_umword_t t0, t1, t2;
62 l4_umword_t s0, s1;
63 l4_umword_t a0, a1, a2, a3, a4, a5, a6, a7;
64 l4_umword_t s2, s3, s4, s5, s6, s7, s8, s9, s10, s11;
65 l4_umword_t t3, t4, t5, t6;
66 };
67 };
68
69 union { l4_umword_t pc; l4_umword_t ip; };
70 l4_umword_t status;
71 l4_umword_t cause;
72 union { l4_umword_t tval; l4_umword_t pfa; };
73
74 l4_umword_t hstatus; // only if virtualization is enabled
75};
76
77#define L4_UTCB_EXCEPTION_REGS_SIZE (sizeof(l4_exc_regs_t) / sizeof(l4_umword_t))
78#define L4_UTCB_GENERIC_DATA_SIZE 63
79#define L4_UTCB_GENERIC_BUFFERS_SIZE 58
80
81#define L4_UTCB_MSG_REGS_OFFSET 0
82#define L4_UTCB_BUF_REGS_OFFSET (64 * sizeof(l4_umword_t))
83#define L4_UTCB_THREAD_REGS_OFFSET (123 * sizeof(l4_umword_t))
84
85#define L4_UTCB_INHERIT_FPU (1UL << 24)
86
87#define L4_UTCB_OFFSET (128 * sizeof(l4_umword_t))
88
89/*
90 * ==================================================================
91 * Implementations.
92 */
93
94L4_INLINE l4_utcb_t *l4_utcb_direct(void) L4_NOTHROW
95{
96 // We store the UTCB pointer immediately before the TCB.
97 l4_addr_t tp;
98 __asm__ ("mv %0, tp" : "=r" (tp));
99 return *(l4_utcb_t **)(tp - 3 * sizeof(void*));
100}
101
103{
104 return u->pc;
105}
106
108{
109 u->pc = pc;
110}
111
113{
114 return u->cause;
115}
116
118{
119 switch(u->cause)
120 {
121 case L4_riscv_exc_inst_access:
122 case L4_riscv_exc_load_access:
123 case L4_riscv_exc_store_access:
124 case L4_riscv_exc_inst_page_fault:
125 case L4_riscv_exc_load_page_fault:
126 case L4_riscv_exc_store_page_fault:
127 return 1;
128 default:
129 return 0;
130 }
131}
132
134{
135 return u->tval | (u->cause == L4_riscv_exc_store_page_fault ? 2 : 0);
136}
137
139{
140 return l4_utcb_exc_typeval(u) == L4_riscv_ec_l4_exregs_exception;
141}
unsigned long l4_umword_t
Unsigned machine word.
Definition l4int.h:40
unsigned long l4_addr_t
Address type.
Definition l4int.h:34
struct l4_utcb_t l4_utcb_t
Opaque type for the UTCB.
Definition utcb.h:56
l4_addr_t l4_utcb_exc_pfa(l4_exc_regs_t const *u) L4_NOTHROW
Function to get the L4 style page fault address out of an exception.
Definition utcb.h:102
int l4_utcb_exc_is_ex_regs_exception(l4_exc_regs_t const *u) L4_NOTHROW
Check whether an exception IPC was triggered via l4_thread_ex_regs().
Definition utcb.h:107
int l4_utcb_exc_is_pf(l4_exc_regs_t const *u) L4_NOTHROW
Check whether an exception IPC is a page fault.
Definition utcb.h:97
l4_umword_t l4_utcb_exc_pc(l4_exc_regs_t const *u) L4_NOTHROW
Access function to get the program counter of the exception state.
Definition utcb.h:82
l4_umword_t l4_utcb_exc_typeval(l4_exc_regs_t const *u) L4_NOTHROW
Get the value out of an exception UTCB that describes the type of exception.
Definition utcb.h:92
void l4_utcb_exc_pc_set(l4_exc_regs_t *u, l4_addr_t pc) L4_NOTHROW
Set the program counter register in the exception state.
Definition utcb.h:87
#define L4_NOTHROW
Mark a function declaration and definition as never throwing an exception.
Definition compiler.h:167
#define L4_INLINE
L4 Inline function attribute.
Definition compiler.h:51
Common L4 ABI Data Types.
UTCB structure for exceptions.
Definition utcb.h:28
l4_umword_t r[13]
registers
Definition utcb.h:32
l4_umword_t sp
stack pointer
Definition utcb.h:33
l4_umword_t pfa
page fault address
Definition utcb.h:29
l4_umword_t ip
instruction pointer
Definition utcb.h:36