Skip to content

Commit 3c0103a

Browse files
committed
tool: Allow SDF structures to be created from outside the structs
1 parent 3664106 commit 3c0103a

1 file changed

Lines changed: 114 additions & 0 deletions

File tree

tool/microkit/src/sdf.rs

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,15 @@ impl SysMapPerms {
336336
}
337337

338338
impl SysMap {
339+
pub fn new(mr: String, vaddr: u64, perms: u8, cached: bool) -> Result<SysMap, String> {
340+
Ok(SysMap {
341+
mr,
342+
vaddr,
343+
perms,
344+
cached,
345+
text_pos: None,
346+
})
347+
}
339348
fn from_xml(
340349
xml_sdf: &XmlSystemDescription,
341350
node: &roxmltree::Node,
@@ -439,6 +448,52 @@ impl ProtectionDomain {
439448
ioports
440449
}
441450

451+
pub fn new(
452+
id: Option<u64>,
453+
name: String,
454+
priority: u8,
455+
budget: u64,
456+
period: u64,
457+
passive: bool,
458+
stack_size: u64,
459+
smc: bool,
460+
cpu: CpuCore,
461+
program_image: PathBuf,
462+
maps: Vec<SysMap>,
463+
irqs: Vec<SysIrq>,
464+
ioports: Vec<IOPort>,
465+
setvars: Vec<SysSetVar>,
466+
virtual_machine: Option<VirtualMachine>,
467+
child_pds: Vec<ProtectionDomain>,
468+
has_children: bool,
469+
setvar_id: Option<String>,
470+
) -> Result<ProtectionDomain, String> {
471+
Ok(ProtectionDomain {
472+
id,
473+
name,
474+
// This downcast is safe as we have checked that this is less than
475+
// the maximum PD priority, which fits in a u8.
476+
priority,
477+
budget,
478+
period,
479+
passive,
480+
stack_size,
481+
smc,
482+
cpu,
483+
program_image,
484+
maps,
485+
irqs,
486+
ioports,
487+
setvars,
488+
child_pds,
489+
virtual_machine,
490+
has_children,
491+
parent: None,
492+
setvar_id,
493+
text_pos: None,
494+
})
495+
}
496+
442497
fn from_xml(
443498
config: &Config,
444499
xml_sdf: &XmlSystemDescription,
@@ -1078,6 +1133,23 @@ impl ProtectionDomain {
10781133
}
10791134

10801135
impl VirtualMachine {
1136+
pub fn new(
1137+
vcpus: Vec<VirtualCpu>,
1138+
name: String,
1139+
maps: Vec<SysMap>,
1140+
priority: u8,
1141+
budget: u64,
1142+
period: u64,
1143+
) -> Result<VirtualMachine, String> {
1144+
Ok(VirtualMachine {
1145+
vcpus,
1146+
name,
1147+
maps,
1148+
priority,
1149+
budget,
1150+
period,
1151+
})
1152+
}
10811153
fn from_xml(
10821154
config: &Config,
10831155
xml_sdf: &XmlSystemDescription,
@@ -1204,6 +1276,26 @@ impl VirtualMachine {
12041276
}
12051277

12061278
impl SysMemoryRegion {
1279+
pub fn new(
1280+
name: String,
1281+
size: u64,
1282+
page_size: PageSize,
1283+
page_size_specified_by_user: bool,
1284+
phys_addr: SysMemoryRegionPaddr,
1285+
kind: SysMemoryRegionKind,
1286+
) -> Result<SysMemoryRegion, String> {
1287+
Ok(SysMemoryRegion {
1288+
name,
1289+
size,
1290+
page_size,
1291+
page_size_specified_by_user,
1292+
page_count,
1293+
phys_addr,
1294+
text_pos: None,
1295+
kind,
1296+
})
1297+
}
1298+
12071299
fn from_xml(
12081300
config: &Config,
12091301
xml_sdf: &XmlSystemDescription,
@@ -1272,6 +1364,22 @@ impl SysMemoryRegion {
12721364
}
12731365

12741366
impl ChannelEnd {
1367+
pub fn new(
1368+
pd_idx: usize,
1369+
id: u64,
1370+
notify: bool,
1371+
pp: bool,
1372+
setvar_id: Option<String>,
1373+
) -> Result<ChannelEnd, String> {
1374+
Ok(ChannelEnd {
1375+
pd: pd_idx,
1376+
id: id,
1377+
notify,
1378+
pp,
1379+
setvar_id,
1380+
})
1381+
}
1382+
12751383
fn from_xml<'a>(
12761384
xml_sdf: &'a XmlSystemDescription,
12771385
node: &'a roxmltree::Node,
@@ -1343,6 +1451,12 @@ impl ChannelEnd {
13431451
}
13441452

13451453
impl Channel {
1454+
pub fn new(end_a: ChannelEnd, end_b: ChannelEnd) -> Result<Channel, String> {
1455+
Ok(Channel {
1456+
end_a: end_a,
1457+
end_b: end_b,
1458+
})
1459+
}
13461460
/// It should be noted that this function assumes that `pds` is populated
13471461
/// with all the Protection Domains that could potentially be connected with
13481462
/// the channel.

0 commit comments

Comments
 (0)