fic/base/env.rs
1//! The declarations resolution fixes and typing never changes, in every
2//! layer's environment: a channel's ends, its buffer and the buffer's
3//! mappings, a program's mappings, the `System =` composition, event and
4//! process signatures, and the platform entry points. Memory regions and
5//! protection domains are the AST's own nodes.
6
7use std::ops::Range;
8
9use serde::Serialize;
10
11use crate::ast::{Permission, SecurityLabel};
12
13use super::id::{MappingId, MrId, PdId, ProcId};
14use super::types::{ArrayLen, TypeRef};
15
16/// One end of a channel.
17#[derive(Debug, Clone, Copy, Serialize)]
18pub struct ChannelEnd {
19 /// The protection domain at this end.
20 pub pd: PdId,
21 /// This end's channel id in that PD: what its `notified(ch)` receives.
22 /// Deprecated, with `mkids.rs`: Microkit's, not the language's.
23 pub id: u32,
24}
25
26/// Which endpoint of a channel a protection domain holds (Microkit's
27/// word). On a bidirectional channel both endpoints send and receive; the
28/// endpoint records which was written.
29#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
30pub enum Endpoint {
31 /// The channel's sending end.
32 Sender,
33 /// The channel's receiving end.
34 Receiver,
35}
36
37/// A channel's shared buffer, and its mapping at each end, in
38/// the environment's `mappings`.
39#[derive(Debug, Clone, Serialize)]
40pub struct Buffer {
41 /// The memory region backing it.
42 pub region: MrId,
43 /// The payload type, `Σ(c)`.
44 pub payload: TypeRef,
45 /// The declared capacity, `<T, N>`; `None`: as many slots as fit.
46 pub capacity: Option<ArrayLen>,
47 /// Its mapping in the sender's protection domain.
48 pub sender: MappingId,
49 /// Its mapping in the receiver's protection domain.
50 pub receiver: MappingId,
51}
52
53impl Buffer {
54 /// The permissions of the buffer's mapping at either end: `rw` at both,
55 /// the sender writing the slots and `tail`, the receiver `head` (filib's
56 /// ring). Each word has one writer by the ring's code, not by these
57 /// permissions, as in sDDF's queues.
58 pub const PERMS: Permission = Permission::RW;
59
60 /// Its mapping at `end`.
61 #[must_use]
62 pub fn mapping(&self, end: Endpoint) -> MappingId {
63 match end {
64 Endpoint::Sender => self.sender,
65 Endpoint::Receiver => self.receiver,
66 }
67 }
68}
69
70/// A memory mapping: a region in one protection domain's address space.
71#[derive(Debug, Clone, Serialize)]
72pub struct Mapping {
73 /// The protection domain whose address space it is in.
74 pub pd: PdId,
75 /// Its name.
76 pub name: String,
77 /// The region it maps.
78 pub region: MrId,
79 /// Its virtual address, written or allocated (`vaddr.rs`).
80 pub vaddr: u64,
81 /// Whether the vaddr was written, and so is checked, not allocated.
82 pub pinned: bool,
83 /// Access permissions.
84 pub perms: Permission,
85 /// Whether the mapping is cached.
86 pub cached: bool,
87 /// Security label.
88 pub label: SecurityLabel,
89 /// Whether a body reads `m.paddr`: the loader then patches the region's
90 /// physical address into the PD, under `<m>_paddr`. What the C unit
91 /// defines and the SDF patches; deprecated with them.
92 pub paddr_read: bool,
93 /// Byte span: the mapping's in the `.fi`, a channel buffer's channel's
94 /// in the `.fis`.
95 pub span: Range<usize>,
96}
97
98/// `System = pd1 ||| pd2 ...`.
99#[derive(Debug, Clone, Serialize)]
100pub struct Composition {
101 /// The members, in order.
102 pub pds: Vec<PdId>,
103 /// Byte span in the `.fis`.
104 pub span: Range<usize>,
105}
106
107/// An event's signature, `evt name(carriers)`; its body is an
108/// `EventBody`.
109#[derive(Debug, Clone, Serialize)]
110pub struct EventDecl {
111 /// Its name.
112 pub name: String,
113 /// The carriers' types, in order; the carriers are the body's first
114 /// vars.
115 pub carriers: Vec<TypeRef>,
116 /// Byte span in the `.fi`.
117 pub span: Range<usize>,
118}
119
120/// A process's signature, `proc Name(params)`; its body is a `ProcBody`.
121#[derive(Debug, Clone, Serialize)]
122pub struct ProcessDecl {
123 /// Its name.
124 pub name: String,
125 /// The parameters' types, in order; the parameters are the body's
126 /// first vars.
127 pub params: Vec<TypeRef>,
128 /// Byte span in the `.fi`.
129 pub span: Range<usize>,
130}
131
132/// `@bind(platform.entry)` on a process.
133#[derive(Debug, Clone, Serialize)]
134pub struct Entry {
135 /// Platform namespace, e.g. `microkit`.
136 pub platform: String,
137 /// Entry point within it, e.g. `notified`.
138 pub entry: String,
139 /// The bound process.
140 pub process: ProcId,
141}