@@ -275,7 +275,7 @@ pub struct ProtectionDomain {
275275 /// Location in the parsed SDF file
276276 text_pos : Option < roxmltree:: TextPos > ,
277277 /// Index into the domain schedule vector if the system is using domain scheduling
278- /// Defaults to domain 0 if not set.
278+ pub domain_name : Option < String > ,
279279 pub domain_id : Option < u8 > ,
280280}
281281
@@ -603,28 +603,12 @@ impl ProtectionDomain {
603603 ) ) ;
604604 }
605605
606- let mut domain_id: Option < u8 > = None ;
607- match ( domain_schedule, checked_lookup ( xml_sdf, node, "domain" ) ) {
608- ( Some ( domain_schedule) , Ok ( domain_name) ) => {
609- let domain_id_get = domain_schedule. domain_ids . get ( domain_name) ;
610- if domain_id_get. is_none ( ) {
611- return Err ( format ! ( "Protection domain {name} specifies a domain {domain_name} that is not in the domain schedule" ) ) ;
612- }
613- domain_id = Some ( * domain_id_get. unwrap ( ) ) ;
614- }
615- ( Some ( _) , _) => {
616- return Err ( format ! ( "System specifies a domain schedule but protection domain {name} does not specify a domain" ) )
617- }
618- ( _, Ok ( domain) ) => {
619- if config. num_domain_schedules > 1 {
620- return Err ( format ! ( "Protection domain {name} specifies a domain {domain} but system does not specify a domain schedule" ) ) ;
621- } else {
622- return Err ( "Assigning PDs to domains is only supported when built with a config that supports domains" . to_string ( ) ) ;
623- }
624- }
625- ( _, _) => { }
626- }
627-
606+ let domain_name = if let Some ( xml_domain_name) = node. attribute ( "domain" ) {
607+ Some ( xml_domain_name. to_string ( ) )
608+ } else {
609+ None
610+ } ;
611+ let domain_id: Option < u8 > = None ;
628612 let mut maps = Vec :: new ( ) ;
629613 let mut irqs = Vec :: new ( ) ;
630614 let mut ioports = Vec :: new ( ) ;
@@ -1116,6 +1100,7 @@ impl ProtectionDomain {
11161100 parent : None ,
11171101 setvar_id,
11181102 text_pos : Some ( xml_sdf. doc . text_pos_at ( node. range ( ) . start ) ) ,
1103+ domain_name,
11191104 domain_id,
11201105 } )
11211106 }
@@ -1127,10 +1112,6 @@ impl DomainSchedule {
11271112 config : & Config ,
11281113 node : & roxmltree:: Node ,
11291114 ) -> Result < DomainSchedule , String > {
1130- if config. num_domains <= 1 {
1131- return Err ( "Error: Attempting to set a domain schedule when kernel config does not support more than 1 domain" . to_string ( ) ) ;
1132- }
1133-
11341115 let pos = xml_sdf. doc . text_pos_at ( node. range ( ) . start ) ;
11351116
11361117 check_attributes ( xml_sdf, node, & [ "index_shift" , "start_index" ] ) ?;
@@ -1805,18 +1786,19 @@ pub fn parse(filename: &str, xml: &str, config: &Config) -> Result<SystemDescrip
18051786 ) ) ;
18061787 }
18071788 "domain_schedule" => {
1808- if config. num_domain_schedules > 1 {
1809- if let Some ( domain_schedule_node) = system
1810- . children ( )
1811- . filter ( |& child| child. is_element ( ) )
1812- . find ( |& child| child. tag_name ( ) . name ( ) == "domain_schedule" )
1813- {
1814- domain_schedule = Some ( DomainSchedule :: from_xml (
1815- & xml_sdf,
1816- config,
1817- & domain_schedule_node,
1818- ) ?) ;
1819- }
1789+ if config. num_domains <= 1 {
1790+ return Err ( "Error: Attempting to set a domain schedule when kernel config does not support more than 1 domain" . to_string ( ) ) ;
1791+ }
1792+ if let Some ( domain_schedule_node) = system
1793+ . children ( )
1794+ . filter ( |& child| child. is_element ( ) )
1795+ . find ( |& child| child. tag_name ( ) . name ( ) == "domain_schedule" )
1796+ {
1797+ domain_schedule = Some ( DomainSchedule :: from_xml (
1798+ & xml_sdf,
1799+ config,
1800+ & domain_schedule_node,
1801+ ) ?) ;
18201802 }
18211803 }
18221804 _ => {
@@ -2197,6 +2179,42 @@ pub fn parse(filename: &str, xml: &str, config: &Config) -> Result<SystemDescrip
21972179 schedule_len, dom_shift, config. num_domain_schedules,
21982180 ) ) ;
21992181 }
2182+
2183+ // Resolve the domain names to id's
2184+ for pd in pds. iter_mut ( ) {
2185+ if let Some ( domain_name) = & pd. domain_name {
2186+ let domain_id_get = dom_sched. domain_ids . get ( domain_name) ;
2187+ if domain_id_get. is_none ( ) {
2188+ return Err ( format ! ( "Protection domain {} specifies a domain {} that is not in the domain schedule" ,
2189+ pd. name,
2190+ domain_name
2191+ ) ) ;
2192+ }
2193+ pd. domain_id = Some ( * domain_id_get. unwrap ( ) ) ;
2194+ } else {
2195+ return Err ( format ! ( "Protection domain {} doesn't specify a domain, but user has declared a domain schedule" ,
2196+ pd. name,
2197+ ) ) ;
2198+ }
2199+ }
2200+ } else {
2201+ // If no domain schedule is defined, check that no PD has specified a domain.
2202+ for pd in pds. iter ( ) {
2203+ if let Some ( domain_name) = & pd. domain_name {
2204+ if config. num_domains > 1 {
2205+ return Err ( format ! ( "Protection domain {} specifies a domain '{}', but user has not declared a domain schedule" ,
2206+ pd. name,
2207+ domain_name
2208+ ) ) ;
2209+ } else {
2210+ return Err ( format ! ( "Protection domain {} specifies a domain '{}', but Microkit config does not support domains." ,
2211+ pd. name,
2212+ domain_name
2213+ ) ) ;
2214+ }
2215+
2216+ }
2217+ }
22002218 }
22012219
22022220 Ok ( SystemDescription {
0 commit comments