SKB: Adapt decoding net scripts to use struct notation
[barrelfish] / usr / skb / programs / decodingNetQueries.pl
1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 % Copyright (c) 2017, ETH Zurich.
3 % All rights reserved.
4 %
5 % This file is distributed under the terms in the attached LICENSE file.
6 % If you do not find this file, copies can be found by writing to:
7 % ETH Zurich D-INFK, Universitaetsstrasse 6, CH-8092 Zurich.
8 % Attn: Systems Group.
9 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
10
11 :- module(decodingNetQueries).
12 :- export findTargetRegion/2.
13 :- export findOriginRegion/2.
14 :- export findDeviceRegion/3.
15 :- export findMemoryRegion/3.
16 :- export findSharedMemoryRegion/3.
17 :- export findDeviceId/3.
18 :- export findInterruptLine/3.
19
20 :- use_module(decodingNet).
21
22
23 %%%%%%%%%%%%%%%%%%%%%%%
24 %% Helper predicates %%
25 %%%%%%%%%%%%%%%%%%%%%%%
26 resolveToRegion(SrcName,DestName,SrcRegion,DestRegion) :-
27     resolve(SrcName,DestName),
28     toRegion(SrcName,SrcRegion),
29     toRegion(DestName,DestRegion).
30
31
32 %%%%%%%%%%%%%
33 %% Queries %%
34 %%%%%%%%%%%%%
35 findTargetRegion(NodeId,Result) :-
36     SrcName = name{nodeId:NodeId},
37     resolveToRegion(SrcName,_,SrcRegion,DestRegion),
38     Result = (SrcRegion,DestRegion).
39
40 findOriginRegion(NodeId,Result) :-
41     DestName = name{nodeId:NodeId},
42     resolveToRegion(_,DestName,SrcRegion,DestRegion),
43     Result = (SrcRegion,DestRegion).
44
45 %% Address space queries
46 findDeviceRegion(NodeId,DeviceId,Result) :-
47     SrcName = name{nodeId:NodeId},
48     DestName = name{nodeId:DeviceId},
49     node{
50         id:DeviceId,
51         type:device
52     },
53     resolveToRegion(SrcName,DestName,SrcRegion,DestRegion),
54     Result = (SrcRegion,DestRegion).
55
56 findMemoryRegion(NodeId,MemoryId,Result) :-
57     SrcName = name{nodeId:NodeId},
58     DestName = name{nodeId:MemoryId},
59     node{
60         id:MemoryId,
61         type:memory
62     },
63     resolveToRegion(SrcName,DestName,SrcRegion,DestRegion),
64     Result = (SrcRegion,DestRegion).
65
66 findSharedMemoryRegion(NodeId,DeviceId,Result) :-
67     NodeName = name{nodeId:NodeId},
68     DeviceName = name{nodeId:DeviceId},
69     SharedName = name{nodeId:SharedId},
70     node{
71         id:SharedId,
72         type:memory
73     },
74     resolve(NodeName,SharedName),
75     resolve(DeviceName,SharedName),
76     toRegion(NodeName,NodeRegion),
77     toRegion(SharedName,SharedRegion),
78     toRegion(DeviceName,DeviceRegion),
79     Result = (NodeRegion,DeviceRegion,SharedRegion).
80
81 findDeviceId(NodeId,Addr,Result) :-
82     SrcName = name{
83         nodeId:NodeId,
84         address:Addr
85     },
86     DestName = name{nodeId:DeviceId},
87     resolve(SrcName,DestName),
88     Result = DeviceId.
89
90 %% Interrupt queries
91 findInterruptLine(NodeId,DeviceId,Result) :-
92     SrcName = name{nodeId:DeviceId},
93     DestName = name{nodeId:NodeId},
94     resolveToRegion(SrcName,DestName,SrcRegion,DestRegion),
95     Result = (SrcRegion,DestRegion).