home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 4 / DATAFILE_PDCD4.iso / unix / riscbsd / datafile / _btriscbsd / booter / h / swiv < prev   
Encoding:
Text File  |  1993-12-17  |  3.4 KB  |  81 lines

  1. /* SWI veneers:
  2.  *  Written by Edward Nevill and Jonathan Roach in an idle moment between projects.
  3.  *  Hacked by BDB to add flag returning 
  4.  */
  5.  
  6. /* Anonymous Error type */
  7.  
  8. struct Error { int num; char msg[4]; };
  9.  
  10. typedef struct Error Error;
  11.  
  12. /* Generic SWI interface
  13.  *  swi(swino,mask,regs...)
  14.  *   swino = SWI number to call as defined in h.swis, X bit set if you wish the
  15.  *           X form of the SWI to be called, clear if you want the non X form.
  16.  *   reg_mask = mask of in / out registers
  17.  *              bits 0-9:   Bit N set => Register N specified on input
  18.  *                          Bit N clear => Register N unspecified on input
  19.  *              bits 22-31: Bit N set => Register N-22 on output stored
  20.  *                              in address specified in varargs list.
  21.  *   ...        In order, input registers followed by output registers,
  22.  *                      starting at r0 and going up.
  23.  *   returns 0 or errorblock pointer if X-bit set
  24.  *   returns r0 if X-bit clear
  25.  *  swix(swino,mask,regs...)
  26.  *   This behaves identically to 'swi' except that it always calls the X form.
  27.  *
  28.  * Eg:
  29.  *   swi(OS_SWINumberToString, IN(R0|R1|R2), n, buf, 255);
  30.  *   e = swi(XOS_SWINumberFromString, IN(R1)|OUT(R0), str, &n);
  31.  *       - Error block pointer (or 0) is returned so must get returned R0
  32.  *       - via argument list.
  33.  *   e = swix(OS_SWINumberFromString, IN(R1)|OUT(R0), str, &n);
  34.  *       - As above but uses the swix function rather that setting the X bit
  35.  *         explicitly (saves one instruction on SWI call).
  36.  *   e = swi(OS_File, IN(R0|R1|R2|R3)|OUT(R4), 255, name, buff, 0, &len);
  37.  *       - We don't care about the load, exec or attrs so don't specify
  38.  *         them in the output registers.
  39.  */
  40.  
  41. extern Error *swix(int swino, int reg_mask, ...);
  42. extern int swi(int swino, int reg_mask, ...);
  43.  
  44. /* Register mask macros
  45.  *  The bits in the register mask are arranged as follows:
  46.  *  31 30 29 ... 22 ...  8 ...  2  1  0
  47.  *  O0 O1 O2 ... O9     I9 ... I2 I1 I0  I(N) = bit set if R(N) used on entry
  48.  *                                       O(N) = bit set if R(N) written on exit
  49.  *  The bits are arranged like this to optimise the case where a SWI is being
  50.  *  called with a small number of input and output registers. For example, a SWI
  51.  *  call which uses R0-R5 on entry and R0-R1 on exit will have a register mask
  52.  *  of 0xC000003f which can be loaded into an ARM register in one instruction
  53.  *  (the compiler performs this optimisation, even when the constant wraps
  54.  *  around between bits 0 and 31). Using the more obvious coding of I0-I9 in bits
  55.  *  0 - 9 and O0-O9 in bits 16-23 leads to a constant of 0x0003003f which require
  56.  *  two instructions.
  57.  */
  58. #define IN(m) (m)
  59. /* old, incorrect version
  60. #define OUT(m) ((unsigned)(m&1)<<31|(m&2)<<29|(m&4)<<27|(m&8)<<25|(m&16)<<23|\
  61.                 (m&32)<<21|(m&64)<<19|(m&128)<<17|(m&256)<<15|(m&512)<<13)
  62. */
  63. #define OUT(m) ((unsigned)((m)&1)<<31|((m)&2)<<29|((m)&4)<<27|\
  64.                 ((m)&8)<<25|((m)&16)<<23|((m)&32)<<21|((m)&64)<<19|\
  65.                 ((m)&128)<<17|((m)&256)<<15|((m)&512)<<13|((m)&1024)<<11)
  66.  
  67. /* The register names
  68.  *  Change these to use different names if you use R0 - R9 elsewhere in your program
  69.  */
  70. #define PSW 0x400       /* Use only in OUT, orders BEFORE others */
  71. #define R0 0x001
  72. #define R1 0x002
  73. #define R2 0x004
  74. #define R3 0x008
  75. #define R4 0x010
  76. #define R5 0x020
  77. #define R6 0x040
  78. #define R7 0x080
  79. #define R8 0x100
  80. #define R9 0x200
  81.