|
18 | 18 |
|
19 | 19 | import java.util.List; |
20 | 20 | import java.util.Map; |
| 21 | +import vadl.utils.SourceLocation; |
21 | 22 |
|
22 | 23 | public class UserModeEmulation extends Definition { |
23 | | - private final int sysReg; // e.g., 17 for RISC-V a7 (syscall number) |
24 | | - private final int retReg; // e.g., 10 for RISC-V a0 (return value) |
25 | | - private final int spReg; // Stack Pointer (e.g., 2 for RISC-V) |
26 | | - private final int raReg; // Return Address (e.g., 1 for RISC-V) |
27 | | - private final int tpReg; // Thread Pointer |
28 | | - private final List<Integer> args; // Argument registers (e.g., [10, 11, 12, 13, 14, 15]) |
29 | | - private final Map<String, Integer> excIds; // Exception IDs mapping |
| 24 | + /** |
| 25 | + * Returns a map representation of this UserModeEmulation for template rendering. |
| 26 | + */ |
| 27 | + public Map<String, Object> asMap() { |
| 28 | + return Map.ofEntries( |
| 29 | + Map.entry("sysReg", sysReg), |
| 30 | + Map.entry("retReg", retReg), |
| 31 | + Map.entry("spReg", spReg), |
| 32 | + Map.entry("raReg", raReg), |
| 33 | + Map.entry("tpReg", tpReg), |
| 34 | + Map.entry("args", args), |
| 35 | + Map.entry("excIds", excIds), |
| 36 | + Map.entry("SYSCALL_NAME", syscallExcName), |
| 37 | + Map.entry("BREAKPOINT_NAME", breakpointExcName), |
| 38 | + Map.entry("ILLEGAL_INSTR_NAME", illegalInstrExcName), |
| 39 | + // NEW FIELDS FOR CPU_LOOP.C: |
| 40 | + Map.entry("ptRegPc", ptRegPc), |
| 41 | + Map.entry("ptRegSp", ptRegSp), |
| 42 | + Map.entry("excCauseVar", excCauseVar), |
| 43 | + Map.entry("hasIcacheFlush", hasIcacheFlush) |
| 44 | + ); |
| 45 | + } |
| 46 | + |
| 47 | + private final int sysReg; |
| 48 | + private final int retReg; |
| 49 | + private final int spReg; |
| 50 | + private final int raReg; |
| 51 | + private final int tpReg; |
| 52 | + private final List<Integer> args; |
| 53 | + private final Map<String, Integer> excIds; |
| 54 | + private final String syscallExcName; |
| 55 | + private final String breakpointExcName; |
| 56 | + private final String illegalInstrExcName; |
| 57 | + // NEW FIELDS: |
| 58 | + private final String ptRegPc; |
| 59 | + private final String ptRegSp; |
| 60 | + private final String excCauseVar; |
| 61 | + private final boolean hasIcacheFlush; |
30 | 62 |
|
31 | 63 | /** |
32 | 64 | * Constructs a UserModeEmulation configuration. |
33 | 65 | */ |
34 | 66 | public UserModeEmulation( |
35 | 67 | Identifier identifier, |
36 | | - int sysReg, |
37 | | - int retReg, |
38 | | - int spReg, |
39 | | - int raReg, |
40 | | - int tpReg, |
41 | | - List<Integer> args, |
42 | | - Map<String, Integer> excIds) { |
| 68 | + int sysReg, int retReg, int spReg, int raReg, int tpReg, |
| 69 | + List<Integer> args, Map<String, Integer> excIds, |
| 70 | + String syscallExcName, String breakpointExcName, String illegalInstrExcName, |
| 71 | + String ptRegPc, String ptRegSp, String excCauseVar, boolean hasIcacheFlush) { |
43 | 72 | super(identifier); |
| 73 | + if (args == null || args.isEmpty()) throw new IllegalArgumentException("args must not be null/empty"); |
| 74 | + if (excIds == null || excIds.isEmpty()) throw new IllegalArgumentException("excIds must not be null/empty"); |
| 75 | + |
44 | 76 | this.sysReg = sysReg; |
45 | 77 | this.retReg = retReg; |
46 | 78 | this.spReg = spReg; |
47 | 79 | this.raReg = raReg; |
48 | 80 | this.tpReg = tpReg; |
49 | 81 | this.args = args; |
50 | 82 | this.excIds = excIds; |
| 83 | + this.syscallExcName = syscallExcName; |
| 84 | + this.breakpointExcName = breakpointExcName; |
| 85 | + this.illegalInstrExcName = illegalInstrExcName; |
| 86 | + this.ptRegPc = ptRegPc; |
| 87 | + this.ptRegSp = ptRegSp; |
| 88 | + this.excCauseVar = excCauseVar; |
| 89 | + this.hasIcacheFlush = hasIcacheFlush; |
| 90 | + } |
| 91 | + |
| 92 | + public static UserModeEmulation createDefault() { |
| 93 | + Identifier identifier = new Identifier(new String[]{"ume"}, SourceLocation.INVALID_SOURCE_LOCATION); |
| 94 | + Map<String, Integer> excIds = Map.of("ILLEGAL_INSTR", 2, "BREAKPOINT", 3, "ECALL", 11); |
| 95 | + |
| 96 | + return new UserModeEmulation( |
| 97 | + identifier, |
| 98 | + 17, 10, 2, 1, 4, |
| 99 | + List.of(10, 11, 12, 13, 14, 15), |
| 100 | + excIds, |
| 101 | + "ECALL", "BREAKPOINT", "ILLEGAL_INSTR", |
| 102 | + "sepc", "sp", "arg_exc_cause", true |
| 103 | + ); |
| 104 | + } |
| 105 | + |
| 106 | + public String getPtRegPc() { |
| 107 | + return ptRegPc; |
| 108 | + } |
| 109 | + |
| 110 | + public String getPtRegSp() { |
| 111 | + return ptRegSp; |
| 112 | + } |
| 113 | + |
| 114 | + public String getExcCauseVar() { |
| 115 | + return excCauseVar; |
| 116 | + } |
| 117 | + |
| 118 | + public boolean hasIcacheFlush() { |
| 119 | + return hasIcacheFlush; |
| 120 | + } |
| 121 | + |
| 122 | + public String getSyscallExcName() { |
| 123 | + return syscallExcName; |
| 124 | + } |
| 125 | + |
| 126 | + public String getBreakpointExcName() { |
| 127 | + return breakpointExcName; |
| 128 | + } |
| 129 | + |
| 130 | + public String getIllegalInstrExcName() { |
| 131 | + return illegalInstrExcName; |
51 | 132 | } |
52 | 133 |
|
53 | | - public int sysReg() { |
| 134 | + public int getSysReg() { |
54 | 135 | return sysReg; |
55 | 136 | } |
56 | 137 |
|
57 | | - public int retReg() { |
| 138 | + public int getRetReg() { |
58 | 139 | return retReg; |
59 | 140 | } |
60 | 141 |
|
61 | | - public int spReg() { |
| 142 | + public int getSpReg() { |
62 | 143 | return spReg; |
63 | 144 | } |
64 | 145 |
|
65 | | - public int raReg() { |
| 146 | + public int getRaReg() { |
66 | 147 | return raReg; |
67 | 148 | } |
68 | 149 |
|
69 | | - public int tpReg() { |
| 150 | + public int getTpReg() { |
70 | 151 | return tpReg; |
71 | 152 | } |
72 | 153 |
|
73 | | - public List<Integer> args() { |
| 154 | + public List<Integer> getArgs() { |
74 | 155 | return args; |
75 | 156 | } |
76 | 157 |
|
77 | | - public Map<String, Integer> excIds() { |
| 158 | + public Map<String, Integer> getExcIds() { |
78 | 159 | return excIds; |
79 | 160 | } |
80 | 161 |
|
|
0 commit comments