View Javadoc

1   package com.tapina.robe.swi.clib.roslib;
2   
3   import com.tapina.robe.swi.clib.Stub;
4   import com.tapina.robe.runtime.Environment;
5   import com.tapina.robe.runtime.Condition;
6   import com.tapina.robe.runtime.UnknownSWIException;
7   import com.tapina.robe.runtime.CPU;
8   import com.tapina.robe.runtime.instruction.SWI;
9   
10  /***
11   * This function calls a SWI , whose number is given in a1.
12   * The registers R0-R9 are set to and returned in the values in a2.
13   * If an error occurs it is returned by the function and not reported by the operating system.
14   * Returns: Pointer to an error, or NULL if none.
15   */
16  public class SWIX extends Stub {
17      public final void executeStub(Environment environment) {
18          final CPU cpu = environment.getCpu();
19          final int[] R = cpu.R;
20          final int registerAddress = R[1];
21          final int[] R4to9save = new int[6];
22          final int[] R0to9in = environment.getMemoryMap().getWords(registerAddress, 10);
23          final int[] R0to9out = new int[10];
24          System.arraycopy(R, 4, R4to9save, 0, 6); // Save R4-R9
25          System.arraycopy(R0to9in, 0, R, 0, 10); // Load R0-R9 from register set
26          try {
27              SWI swi = new SWI(Condition.AL, getSWINumber(R));
28              swi.checkAndExecute(environment); // Sets R[0] to error block if there is one
29              System.arraycopy(R, 0, R0to9out, 0, 10); // Store R0-R9 in register set
30              environment.getMemoryMap().storeWords(registerAddress, R0to9out); // Save register set
31              if (!cpu.getV()) {
32                  // No error returned
33                  R[0] = 0;
34              }
35          } catch (UnknownSWIException e) {
36              environment.returnError(e);
37          } finally {
38              System.arraycopy(R4to9save, 0, R, 4, 6); // Always restore R4-R9, APCS requirement
39          }
40      }
41  
42      int getSWINumber(final int[] R) {
43          return R[0] | SWI.X_BIT;
44      }
45  }