sel4/arch/riscv/
user_context.rs

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
//
// Copyright 2023, Colias Group, LLC
//
// SPDX-License-Identifier: MIT
//

use crate::{newtype_methods, sys, Word};

/// Corresponds to `seL4_UserContext`.
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct UserContext(sys::seL4_UserContext);

impl UserContext {
    newtype_methods!(pub sys::seL4_UserContext);

    pub fn pc(&self) -> &Word {
        &self.0.pc
    }

    pub fn pc_mut(&mut self) -> &mut Word {
        &mut self.0.pc
    }

    pub fn sp(&self) -> &Word {
        &self.0.sp
    }

    pub fn sp_mut(&mut self) -> &mut Word {
        &mut self.0.sp
    }

    pub fn gpr_a(&self, ix: usize) -> &Word {
        match ix {
            0 => &self.inner().a0,
            1 => &self.inner().a1,
            2 => &self.inner().a2,
            3 => &self.inner().a3,
            4 => &self.inner().a4,
            5 => &self.inner().a5,
            6 => &self.inner().a6,
            7 => &self.inner().a7,
            _ => panic!(),
        }
    }

    pub fn gpr_a_mut(&mut self, ix: usize) -> &mut Word {
        match ix {
            0 => &mut self.inner_mut().a0,
            1 => &mut self.inner_mut().a1,
            2 => &mut self.inner_mut().a2,
            3 => &mut self.inner_mut().a3,
            4 => &mut self.inner_mut().a4,
            5 => &mut self.inner_mut().a5,
            6 => &mut self.inner_mut().a6,
            7 => &mut self.inner_mut().a7,
            _ => panic!(),
        }
    }

    pub fn c_param(&self, ix: usize) -> &Word {
        self.gpr_a(ix)
    }

    pub fn c_param_mut(&mut self, ix: usize) -> &mut Word {
        self.gpr_a_mut(ix)
    }
}