1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
use super::sel4_config::seL4_MsgMaxLength;
use crate::plus_define_bitfield;

#[derive(Eq, PartialEq, Debug, Clone, Copy, PartialOrd, Ord)]
pub enum MessageLabel {
    InvalidInvocation                       = 0,
    UntypedRetype,
    TCBReadRegisters,
    TCBWriteRegisters,
    TCBCopyRegisters,
    TCBConfigure,
    TCBSetPriority,
    TCBSetMCPriority,
    TCBSetSchedParams,
    TCBSetIPCBuffer,
    TCBSetSpace,
    TCBSuspend,
    TCBResume,
    TCBBindNotification,
    TCBUnbindNotification,
    #[cfg(feature = "ENABLE_SMP")]
    TCBSetAffinity,
    TCBSetTLSBase,
    CNodeRevoke,
    CNodeDelete,
    CNodeCancelBadgedSends,
    CNodeCopy,
    CNodeMint,
    CNodeMove,
    CNodeMutate,
    CNodeRotate,
    CNodeSaveCaller,
    IRQIssueIRQHandler,
    IRQAckIRQ,
    IRQSetIRQHandler,
    IRQClearIRQHandler,
    DomainSetSet,
    RISCVPageTableMap,
    RISCVPageTableUnmap,
    RISCVPageMap,
    RISCVPageUnmap,
    RISCVPageGetAddress,
    RISCVASIDControlMakePool,
    RISCVASIDPoolAssign,
    RISCVIRQIssueIRQHandlerTrigger,
    nArchInvocationLabels,
}

plus_define_bitfield! {
    seL4_MessageInfo_t, 1, 0, 0, 0 => {
        new, 0 => {
            label, get_usize_label, set_label, 0, 12, 52, 0, false,
            capsUnwrapped, get_caps_unwrapped, set_caps_unwrapped, 0, 9, 3, 0, false,
            extraCaps, get_extra_caps, set_extra_caps, 0, 7, 2, 0, false,
            length, get_length, set_length, 0, 0, 7, 0, false
        }
    }
}

impl seL4_MessageInfo_t {
    #[inline]
    pub fn from_word(w: usize) -> Self {
        Self {
            words: [w]
        }
    }

    #[inline]
    pub fn from_word_security(w: usize) -> Self {
        let mut mi = Self::from_word(w);
        if mi.get_length() > seL4_MsgMaxLength {
            mi.set_length(seL4_MsgMaxLength);
        }
        mi
    }

    #[inline]
    pub fn to_word(&self) -> usize {
        self.words[0]
    }

    #[inline]
    pub fn get_label(&self) -> MessageLabel {
        unsafe {
            core::mem::transmute::<u8, MessageLabel>(self.get_usize_label() as u8)
        }
    }
}