(* * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230) * * SPDX-License-Identifier: GPL-2.0-only *) chapter \\label{h:abbreviations}Convenience Definitions\ (*<*) theory Abbreviations imports Types begin (*>*) text \ This section defines static functionality that the generated glue code semantics relies on. It provides the basic building blocks for the \camkes communication mechanisms. They can also be used as building blocks for users describing the behaviour of trusted components. \ subsection \\label{sec:componentlocal}Local Component Operations\ subsubsection \\label{ssec:univc}UNIV$_c$\ text \ The set of all possible states a component can be in. This is essentially any local state with the exception of the states representing events and shared memory. \ definition UNIV\<^sub>c :: "'component_state local_state set" where "UNIV\<^sub>c \ {x. case x of Component _ \ True | _ \ False}" subsubsection \\label{ssec:internal}Internal Step\ text \ An internal step in a component that arbitrarily modifies its own local state. Note that it is not possible for an event or shared memory component to take this step. \ definition internal :: "'component_state local_state \ 'component_state local_state set" where "internal s \ case s of Component _ \ UNIV\<^sub>c | _ \ {}" subsubsection \\label{ssec:userstep}User Steps\ text \ A representation of @{term internal} in the concurrent imperative language. That is, an arbitrary local step. \ definition UserStep :: "('channel, 'component_state) comp" where "UserStep \ LocalOp internal" subsection \\label{sec:componentcommunication}Communication Component Operations\ subsubsection \\label{ssec:discard}Discard Messages\ text \ Receive a @{term Void} message and do nothing in reaction. \ definition discard :: "'channel answer \ 'component_state local_state \ 'component_state local_state set" where "discard a s \ if a_data a = Void then {s} else {}" subsubsection \\label{ssec:arbitraryrequest}Arbitrary Requests\ text \ Non-deterministically send any message on a given channel. This provides a way of specifying unconstrained behaviour of a component given access to a particular channel. The command produces the set of all messages on a given channel as possible questions and receives any response with a fully nondeterministic local state update. \ definition ArbitraryRequest :: "'channel \ ('channel, 'component_state) comp" where "ArbitraryRequest c \ Request (\_. {x. q_channel x = c}) (\_ _. UNIV\<^sub>c)" subsubsection \\label{ssec:arbitraryresponse}Arbitrary Responses\ text \ Non-deterministically receive any message on a given channel. The command receives any message, makes a nondeterministic local state update, and returns the set of all possible responses @{text \} on the given channel. \ definition ArbitraryResponse :: "'channel \ ('channel, 'component_state) comp" where "ArbitraryResponse c \ Response (\_ _. {(s',\). s' \ UNIV\<^sub>c \ a_channel \ = c})" subsubsection \\label{ssec:eventemit}Event Emit\ text \ Emit an event. The command sends the message @{const Set} on the given channel and discards any response to model asynchronous behaviour with respect to the event buffer components. The message is independent of the local state @{text s}. \ definition EventEmit :: "'channel \ ('channel, 'component_state) comp" where "EventEmit c \ Request (\s. {\q_channel = c, q_data = Set\}) discard" subsubsection \\label{ssec:eventpoll}Event Poll\ text \ Poll for a pending event from an asynchronous buffer component. The command sends a @{const Poll} message to the buffer component, and expects a message @{term a} back that has the form @{term "Pending b"} with a boolean payload @{term b}. This payload is embedded in the local state of the component using the user-provided function @{text embed_data}. \ definition EventPoll :: "'channel \ ('component_state local_state \ bool \ 'component_state local_state) \ ('channel, 'component_state) comp" where "EventPoll c embed_data \ Request (\_. {\q_channel = c, q_data = Poll\}) (\a s. case a_data a of Pending b \ {embed_data s b} | _ \ {})" subsubsection \\label{ssec:eventwait}Event Wait\ text \ Wait for a pending event. The command takes a channel @{text c}, and embedding function @{text embed} (see above). Because the set of target states is only non-empty when the pending bit of the polled event is set, this has the effect of blocking the component's execution until the event is available. \ definition EventWait :: "'channel \ ('component_state local_state \ bool \ 'component_state local_state) \ ('channel, 'component_state) comp" where "EventWait c embed_data \ Request (\_. {\q_channel = c, q_data = Poll\}) (\a s. case a_data a of Pending b \ if b then {embed_data s b} else {} | _ \ {})" subsubsection \\label{ssec:memoryread}Memory Read\ text \ Read from a shared memory location. As mentioned above, shared memory is modelled as a separate process in our glue code semantics. The command below issues a @{const Read} request message to this process with a specified address, and expects an immediate response of the form @{term "Value v"} back, which is embedded into the local state with the same mechanism as above. \ definition MemoryRead :: "'channel \ ('component_state local_state \ nat) \ ('component_state local_state \ variable \ 'component_state local_state) \ ('channel, 'component_state) comp" where "MemoryRead c addr embed_data \ Request (\s. {\q_channel = c, q_data = Read (addr s)\}) (\a s. case a_data a of Value v \ {embed_data s v} | _ \ {})" subsubsection \\label{ssec:memorywrite}Memory Write\ text \ Write to a shared memory location. The command sends a @{const Write} message to the memory component with specified address and value (which are extracted from the local state) and does not expect a response. \ definition MemoryWrite :: "'channel \ ('component_state local_state \ nat) \ ('component_state local_state \ variable) \ ('channel, 'component_state) comp" where "MemoryWrite c addr val \ Request (\s. {\q_channel = c, q_data = Write (addr s) (val s)\}) discard" text \ This concludes the list of the basic operations from which the glue code is composed. We now proceed to define the intermediate communication components for events and shared memory. \ (*<*) end (*>*)