1 /*
2  * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)
3  * Copyright 2015, 2016 Hesham Almatary <heshamelmatary@gmail.com>
4  *
5  * SPDX-License-Identifier: BSD-2-Clause
6  */
7 
8 #pragma once
9 
10 #include <sel4/types.h>
11 #include <sel4/syscalls.h>
12 
13 extern __thread seL4_IPCBuffer *__sel4_ipc_buffer;
14 
15 #ifdef CONFIG_KERNEL_INVOCATION_REPORT_ERROR_IPC
16 extern __thread char __sel4_print_error;
17 
seL4_GetDebugError(void)18 LIBSEL4_INLINE_FUNC char *seL4_GetDebugError(void)
19 {
20     return (char *)(__sel4_ipc_buffer->msg + DEBUG_MESSAGE_START);
21 }
22 
seL4_SetPrintError(char print_error)23 LIBSEL4_INLINE_FUNC void seL4_SetPrintError(char print_error)
24 {
25     __sel4_print_error = print_error;
26     return;
27 }
28 
seL4_CanPrintError(void)29 LIBSEL4_INLINE_FUNC char seL4_CanPrintError(void)
30 {
31     return __sel4_print_error;
32 }
33 #endif
34 
seL4_SetIPCBuffer(seL4_IPCBuffer * ipc_buffer)35 LIBSEL4_INLINE_FUNC void seL4_SetIPCBuffer(seL4_IPCBuffer *ipc_buffer)
36 {
37     __sel4_ipc_buffer = ipc_buffer;
38     return;
39 }
40 
seL4_GetIPCBuffer(void)41 LIBSEL4_INLINE_FUNC seL4_IPCBuffer *seL4_GetIPCBuffer(void)
42 {
43     return __sel4_ipc_buffer;
44 }
45 
seL4_GetMR(int i)46 LIBSEL4_INLINE_FUNC seL4_Word seL4_GetMR(int i)
47 {
48     return seL4_GetIPCBuffer()->msg[i];
49 }
50 
seL4_SetMR(int i,seL4_Word mr)51 LIBSEL4_INLINE_FUNC void seL4_SetMR(int i, seL4_Word mr)
52 {
53     seL4_GetIPCBuffer()->msg[i] = mr;
54 }
55 
seL4_GetUserData(void)56 LIBSEL4_INLINE_FUNC seL4_Word seL4_GetUserData(void)
57 {
58     return seL4_GetIPCBuffer()->userData;
59 }
60 
seL4_SetUserData(seL4_Word data)61 LIBSEL4_INLINE_FUNC void seL4_SetUserData(seL4_Word data)
62 {
63     seL4_GetIPCBuffer()->userData = data;
64 }
65 
seL4_GetBadge(int i)66 LIBSEL4_INLINE_FUNC seL4_Word seL4_GetBadge(int i)
67 {
68     return seL4_GetIPCBuffer()->caps_or_badges[i];
69 }
70 
seL4_GetCap(int i)71 LIBSEL4_INLINE_FUNC seL4_CPtr seL4_GetCap(int i)
72 {
73     return (seL4_CPtr)seL4_GetIPCBuffer()->caps_or_badges[i];
74 }
75 
seL4_SetCap(int i,seL4_CPtr cptr)76 LIBSEL4_INLINE_FUNC void seL4_SetCap(int i, seL4_CPtr cptr)
77 {
78     seL4_GetIPCBuffer()->caps_or_badges[i] = (seL4_Word)cptr;
79 }
80 
seL4_GetCapReceivePath(seL4_CPtr * receiveCNode,seL4_CPtr * receiveIndex,seL4_Word * receiveDepth)81 LIBSEL4_INLINE_FUNC void seL4_GetCapReceivePath(seL4_CPtr *receiveCNode, seL4_CPtr *receiveIndex,
82                                                 seL4_Word *receiveDepth)
83 {
84     seL4_IPCBuffer *ipcbuffer = seL4_GetIPCBuffer();
85     if (receiveCNode != (void *)0) {
86         *receiveCNode = ipcbuffer->receiveCNode;
87     }
88 
89     if (receiveIndex != (void *)0) {
90         *receiveIndex = ipcbuffer->receiveIndex;
91     }
92 
93     if (receiveDepth != (void *)0) {
94         *receiveDepth = ipcbuffer->receiveDepth;
95     }
96 }
97 
seL4_SetCapReceivePath(seL4_CPtr receiveCNode,seL4_CPtr receiveIndex,seL4_Word receiveDepth)98 LIBSEL4_INLINE_FUNC void seL4_SetCapReceivePath(seL4_CPtr receiveCNode, seL4_CPtr receiveIndex, seL4_Word receiveDepth)
99 {
100     seL4_IPCBuffer *ipcbuffer = seL4_GetIPCBuffer();
101     ipcbuffer->receiveCNode = receiveCNode;
102     ipcbuffer->receiveIndex = receiveIndex;
103     ipcbuffer->receiveDepth = receiveDepth;
104 }
105 
106