1/*
2 * Copyright 2017, Data61
3 * Commonwealth Scientific and Industrial Research Organisation (CSIRO)
4 * ABN 41 687 119 230.
5 *
6 * This software may be distributed and modified according to the terms of
7 * the BSD 2-Clause license. Note that NO WARRANTY is provided.
8 * See "LICENSE_BSD2.txt" for details.
9 *
10 * @TAG(DATA61_BSD)
11 */
12
13#ifndef __LIBSEL4_ARCH_FUNCTIONS_H
14#define __LIBSEL4_ARCH_FUNCTIONS_H
15
16#include <sel4/types.h>
17#include <sel4/sel4_arch/functions.h>
18
19LIBSEL4_INLINE_FUNC seL4_Word
20seL4_GetMR(int i)
21{
22    seL4_Word mr;
23    SEL4_GET_IPCBUF_SCALE(msg, i, mr);
24    return mr;
25}
26
27LIBSEL4_INLINE_FUNC void
28seL4_SetMR(int i, seL4_Word mr)
29{
30    SEL4_SET_IPCBUF_SCALE(msg, i, mr);
31}
32
33LIBSEL4_INLINE_FUNC seL4_Word
34seL4_GetUserData(void)
35{
36    seL4_Word data;
37    SEL4_GET_IPCBUF(userData, data);
38    return data;
39}
40
41LIBSEL4_INLINE_FUNC void
42seL4_SetUserData(seL4_Word data)
43{
44    SEL4_SET_IPCBUF(userData, data);
45}
46
47LIBSEL4_INLINE_FUNC seL4_Word
48seL4_GetBadge(int i)
49{
50    seL4_Word badge;
51    SEL4_GET_IPCBUF_SCALE(caps_or_badges, i, badge);
52    return badge;
53}
54
55LIBSEL4_INLINE_FUNC seL4_CPtr
56seL4_GetCap(int i)
57{
58    seL4_CPtr cap;
59    SEL4_GET_IPCBUF_SCALE(caps_or_badges, i, cap);
60    return cap;
61}
62
63LIBSEL4_INLINE_FUNC void
64seL4_SetCap(int i, seL4_CPtr cptr)
65{
66    SEL4_SET_IPCBUF_SCALE(caps_or_badges, i, cptr);
67}
68
69LIBSEL4_INLINE_FUNC void
70seL4_GetCapReceivePath(seL4_CPtr* receiveCNode, seL4_CPtr* receiveIndex, seL4_Word* receiveDepth)
71{
72    if (receiveCNode != seL4_Null) {
73        SEL4_GET_IPCBUF(receiveCNode, *receiveCNode);
74    }
75
76    if (receiveIndex != seL4_Null) {
77        SEL4_GET_IPCBUF(receiveIndex, *receiveIndex);
78    }
79
80    if (receiveDepth != seL4_Null) {
81        SEL4_GET_IPCBUF(receiveDepth, *receiveDepth);
82    }
83}
84
85LIBSEL4_INLINE_FUNC void
86seL4_SetCapReceivePath(seL4_CPtr receiveCNode, seL4_CPtr receiveIndex, seL4_Word receiveDepth)
87{
88    SEL4_SET_IPCBUF(receiveCNode, receiveCNode);
89    SEL4_SET_IPCBUF(receiveIndex, receiveIndex);
90    SEL4_SET_IPCBUF(receiveDepth, receiveDepth);
91}
92
93LIBSEL4_INLINE_FUNC seL4_IPCBuffer*
94seL4_GetIPCBuffer(void)
95{
96    /* Assume that the address of our IPC buffer is in the user data word. Our
97     * parent (or seL4_InitBootInfo in the case of the root task) should have
98     * ensured this is true. The user is free to overwrite this data with
99     * something else, but should then be aware they lose the functionality of
100     * this function.
101     */
102    return (seL4_IPCBuffer*)seL4_GetUserData();
103}
104
105#endif
106