home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / apps / languages / progs / bcplib / swis < prev    next >
Encoding:
Text File  |  1994-03-10  |  13.9 KB  |  401 lines

  1. ;Compiled code conventions ;
  2. ;Registers:
  3. ;
  4. ;RB         8    Called address     ;can be used without saving
  5. ;RL         12   Caller's static
  6. ;RTS        11   Top of stack (empty word above)
  7. ;RP         10   Frame pointer
  8. ;RG         9    Global base
  9. ;RGB        7    Special global base
  10. ;
  11. ;There is an upwards-growing stack, addressed by two registers.  R(F)P is the
  12. ;frame pointer, RTS the top of stack+1 free word pointer.
  13. ;RG points at the base of the global vector; RGB addresses a set of subroutines
  14. ;within the library.
  15. ;
  16. ;On procedure entry, RB holds the address of the called procedure.  It need not
  17. ;be preserved.  RL holds the address of the caller's static data, and must be
  18. ;preserved.  R14 holds the link: this must be written to both PC and PSR on
  19. ;return.  R1 to R4 hold the first four arguments, with others on the stack
  20. ;above RTS in the usual way. Thus, a general procedure would look like:
  21. ;        STMEA   rts!, {rb, rp, rl, r14} ; save linkage
  22. ;        SUB     rp, rts, #16            ; new frame pointer
  23. ;        STMEA   rts!, {a1, ...}         ; arguments
  24. ;           ...
  25. ;
  26. ;R0 to R6 and RB(8) may be used without saving their values; so may R13 and
  27. ;moreover it is accessible from BCPL through the name NIL (assignment to NIL
  28. ;from BCPL has the side-effect of updating R6).  R6 and R13 are guaranteed
  29. ;untouched by the library, and by BCPL code which does not update NIL.
  30. ;
  31. ;On return, a1 holds value received.
  32.  
  33.  
  34.           Result2 = 13 << 2
  35.  
  36.           .include  "regnames"
  37.           .include  "swinames"
  38. Timersw=400         ; <= 0 to remove report
  39.           .AREA     Code
  40. Start:    .ascii     "BCPL"
  41.           .LONG     Globinits-Start
  42.           .ascii    "Byte&SWI"
  43.           .ASCII    "25 Dec 89 00-00-00  "
  44.           .LONG     0
  45.           .long     -1
  46.           .ascic    "OSNewln"
  47. OSNewLine:swi       OS_NewLine
  48.           mov       pc,lr
  49.           .long     -1
  50.           .ascic    "OSRdMdV"
  51. OSReadModeVariable:
  52.           mov       r0, a1
  53.           mov       a1, a2
  54.           swi       OS_ReadModeVariable
  55.           mov       a1, a2
  56.           movcc     r0, #0
  57.           mvncs     r0, #0
  58.           strcc     r0, [ rg, #Result2 ]
  59.           mov       pc, lr
  60.           .long     -1
  61.           .ascic    "OSModeV"
  62. OSCheckModeValid:
  63.           mov       r0, a1
  64.           swi       OS_CheckModeValid
  65.           movcc     a1, #0
  66.           movcc     pc, lr
  67.           str       a1, [ rg, #Result2 ]
  68.           mov       a1, r0
  69.           mov       pc, lr
  70.           .long     -1
  71.           .ascic    "OSGBPB "
  72. OSGBPB:   mov       r0, a1              ; action
  73.           mov       a1, a2              ; handle
  74.           mov       rb, a3, lsl #2      ; Args
  75.           ldmia     rb,{ a2 - r6 }      ; R2-5 from vector
  76.           swi       OS_GBPB+XOS
  77.           stmia     rb,{ a2 - r6 }      ; R2-5 to vector
  78.           mov       a1, #0              ; OK return 0
  79.           mvnvs     a1, #0              ; Error return -1
  80.           mov       pc, lr
  81.           .long     -1
  82.           .ascic    "OSConfm"
  83. OSConfirm:
  84.           swi       OS_Confirm
  85.           str       r0, [rg, #Result2]  ; character returned
  86.           movcs     r1, #1
  87.           movcs     pc, lr              ; returns 1 for escape
  88.           mov       r1, #0              ;  0 No
  89.           mvnvs     r1, #0              ; -1 Yes
  90.           mov       pc, lr
  91.           .long     -1
  92.           .ascic    "OSFSctr"
  93. OSGenerateEvent:
  94.           mov       r0, a1            ; Event no
  95.           mov       a1, a2
  96.           mov       a2, a3
  97.           mov       rb, a4, lsl #2      ; Args 4-6
  98.           ldmia     rb, {a3 - r6}
  99.           swi       OS_GenerateEvent
  100.           mov       pc, lr
  101. OSFSControl:
  102.           stmea     rts!, {rgb, nil}
  103.           mov       nil, a4, lsl #2     ; p4 (Args)
  104.           mov       r0, a1
  105.           mov       a1, a2, lsl #2
  106.           ldrb      a2, [a1], #1        ; string byte base, length; incr a1
  107.           add       a4, a2, a1          ; string byte terminator position
  108.           mov       a2, a3              ; p3
  109.           ldrb      r5, [a4]
  110.           mov       rb, #0
  111.           strb      rb, [a4]
  112.           stmea     rts!, {a4, r5}
  113.           ldmia     nil, {a3-rb}        ; a3 - a8
  114.           swi       OS_FSControl + XOS
  115.           stmia     nil, {a2-a3}         ; returns a2,3
  116.           mov       rb, #0
  117.           mvnvs     rb, #0
  118.           str       rb, [rg, #Result2]  ; returns fault
  119.           ldmea     rts!, {a4, r5}
  120.           strb      r5, [a4]            ; restore terminator
  121.           mov       a4, nil, lsr #2
  122.           ldmea     rts!, {rgb, nil}
  123.           mov       pc, lr
  124.           .long     -1
  125.           .ascic    "OSRdUns"
  126. OSReadUnsigned:
  127.           mov       r0, a1               ; base
  128.           mov       a1, a3
  129.           add       a1, a1, a2, lsl #2  ; bcpl string a2%a3
  130.           mov       a2, a4              ; max val
  131.           swi       OS_ReadUnsigned + XOS
  132.           str       a1, [ rg, #Result2 ]     ; Terminator to Result2
  133.           mov       a1, a2
  134.           mov       pc, lr
  135.           .long     -1
  136.           .ascic    "OSRdvar"
  137. OSReadVarVal:
  138.           ldr       r0, [pc, #rvv-$-8]
  139. rsvv:     str       r0, [pc, #swivv-$-8]
  140.           mov       r0, #1
  141.           add       r0, r0, a1, lsl #2  ; name
  142.           cmp       a2, #0
  143.           movge     a1, #1
  144.           addge     a1, a1, a2, lsl #2  ; BCPL Word buffer if p2 >= 0
  145.           sublt     a2, a2, #1
  146.           mvnlt     a1, a2              ; Byte Buffer if p2 < 0
  147.           mov       rb, a3, lsl #2      ; Args
  148.           ldmia     rb, { a2 - a4 }     ; R2-4 from vector
  149.           cmp       a4, #1              ; Number ?
  150.           subeq     a1, a1, #1
  151. swivv:    .long     0
  152.           stmia     rb, { a2 - a4 }     ; R2-4 to vector
  153.           mov       pc, lr
  154. rvv:      swi       OS_ReadVarVal+XOS
  155.           .long     -1
  156.           .ascic    "OSSetvv"
  157. OSSetVarVal:
  158.           ldr       r0, [pc, #svv-$-8]
  159.           b         rsvv
  160. svv:      swi       OS_SetVarVal
  161.           .long     -1
  162.           .ascic    "OSEvExp"
  163. OSEvaluateExpression:
  164.           mov       r0, #1
  165.           add       r0, r0, a1, lsl #2  ; String
  166.           mov       a1, #1
  167.           add       a1, a1, a2, lsl #2  ; Buffer
  168.           mov       rb, a1
  169.           mov       a2, a3              ; length of Buffer
  170.           swi       OS_EvaluateExpression
  171. res2:     str       a2, [ rg, #Result2 ]     ; Val/Length to Result2
  172.           mov       a1, r0              ; type result
  173.           mov       pc, lr
  174.           .long     -1
  175.           .ascic    "OSWrteN"
  176. OSWriteN: cmp       a2, #0
  177.           movle     pc, lr
  178.           mov       r0, a1              ; String
  179.           mov       a1, a2              ; Length
  180.           SWI       OS_WriteN
  181.           mov       pc, lr
  182.           .long     -1
  183.           .ascic    "OSWrte0"
  184. OSWrite0: mov       r0, a1
  185.           swi       OS_Write0
  186.           mov       a1, r0
  187.           mov       pc, lr
  188.           .long     -1
  189.           .ascic    "OSRdPal"
  190. OSReadPalette:
  191.           mov       r0, a1
  192.           mov       a1, a2
  193.           swi       OS_ReadPalette
  194.           str       a3, [ rg, #Result2 ]
  195.           mov       a1, a2
  196.           mov       pc, lr
  197.           .long     -1
  198.           .ascic    "ADDrive"
  199. ADFSFreeSpace:
  200.           mov       r0, a1              ; Drive
  201.           swi       ADFS_FreeSpace
  202.           str       a1, [ rg, #Result2 ]     ; Largest Single area
  203.           mov       a1, r0
  204.           mov       pc, lr
  205.           .long     -1
  206.           .ascic    "OSRdArg"
  207. OSReadArgs:
  208.           mov       r0, #1
  209.           add       r0, r0, a1, lsl #2  ; Key defn
  210.           mov       a1, #1
  211.           add       a1, a1, a2, lsl #2  ; Input string
  212.           ldr       a2, [a1]
  213.           cmp       a2, #0
  214.           addeq     a1, a1, #1
  215.           mov       a2, a3, lsl #2      ; Output vector
  216.           mov       a3, a4              ; Bytes in ov
  217.           swi       OS_ReadArgs + XOS
  218.           str       r3, [ rg, #Result2 ]
  219.           mov       a1, #0              ; OK return 0
  220.           mvnvs     a1, #0              ; Error return -1
  221.           mov       pc, lr
  222.           .long     -1
  223.           .ascic    "OSBtoA "
  224. OSConvert:
  225.           ldr       r5, [pc, #swi0-$-8]
  226.           cmp       a4, #0
  227.           suble     r5, r5, a4          ; decr -ve a4 -> Byte-addressed buffer
  228.           addgt     r5, r5, a4
  229.           str       r5, [pc, #swid-$-8]
  230.           mov       r0, a1
  231.           movle     a1, a2              ; byte addr
  232.           movgt     a1, a2, lsl #2      ; word addr
  233.           mov       a2, a3
  234. swid:     .long     0
  235.           sub       a1, a1, r0          ; Text length (next 0)
  236.           mov       pc, lr
  237. swi0:     swi       OS_WriteC           ;0
  238.           .long     -1
  239.           .ascic    "OSModul"
  240. OSModule: mov       r0, a1
  241.           mov       a1, a2
  242.           mov       rb, a3, lsl #2
  243.           ldmia     rb, { a2-a3 }
  244.           swi       OS_Module
  245.           stmia     rb, {a2-r5}
  246.           str       a1, [rg, #Result2]
  247.           mov       a1, a2
  248.           mov       pc, lr
  249.           .long     -1
  250.           .ascic    "OSHeap "
  251. OSHeap:   mov       r0, a1
  252.           mov       a1, a2
  253.           mov       a2, a3, lsl #2
  254.           mov       a3, a4
  255.           swi       OS_Heap
  256.           mov       a1, a3
  257.           str       a2, [ rg, #Result2 ]
  258.           mov       pc, lr
  259.           .long     -1
  260.           .ascic    "OSRMTim"
  261. OSReadMonotonicTime:
  262.           swi       OS_ReadMonotonicTime
  263.           mov       a1, r0
  264.           mov       pc, lr
  265.           .long     -1
  266.           .ascic     "OSRemcr"
  267. OSRemoveCursors:
  268.           swi       OS_RemoveCursors
  269.           mov       pc, lr
  270.           .long     -1
  271.           .ascic    "OSRescr"
  272. OSRestoreCursors:
  273.           swi       OS_RestoreCursors
  274.           mov       pc, lr
  275.           .long     -1
  276.           .ascic    "OSPrint"
  277. OSPrintChar:
  278.           mov       r0, a1
  279.           swi       OS_PrintChar
  280.           mov       pc, lr
  281.           .long     -1
  282.           .ascic    "OSRdVdu"
  283. OSReadVduVariables:
  284.           mov       r0, a1, lsl #2
  285.           mov       a1, a2, lsl #2
  286.           swi       OS_ReadVduVariables
  287.           mov       pc, lr
  288.           .long     -1
  289.           .ascic     "OSMouse"
  290. OSMouse:  mov       rb, a1, lsl #2
  291.           swi       OS_Mouse
  292.           stmia     rb, {r0 - a3}
  293.           mov       pc, lr
  294.           .long     -1
  295.           .ascic    "OSSprOp"
  296. OSSpriteOp:
  297.           mov       r0, a1              ; Reason Code
  298.           mov       a1, a2, lsl #2      ; Control Block
  299.           mov       a2, a3, lsl #2
  300.           add       a2, a2, #1          ; Path Name
  301.           str       rgb, [pc, #srgb-$-8]
  302.           ldmia     rb, {a3-rgb }
  303.           swi       OS_SpriteOp
  304.           stmea     rb, {a3-rgb}
  305.           ldr       rgb, [pc, #srgb-$-8]
  306.           mov       pc, lr
  307. srgb:     .long     0
  308.           .long     -1
  309.           .ascic    "OSPlotX"
  310. OSPlot:   mov       r0, a1
  311.           mov       a1, a2
  312.           mov       a2, a3
  313.           swi       OS_Plot
  314.           mov       pc, lr
  315. Globinits:
  316.           .long     23
  317.           .long     OSNewLine-Start
  318.           .long     69
  319.           .long     OSReadModeVariable - Start
  320.           .long     70
  321.           .long     OSCheckModeValid - Start
  322.           .long     107
  323.           .long     OSGBPB-Start
  324.           .long     108
  325.           .long     OSConfirm-Start
  326.           .long     109
  327.           .long     OSGenerateEvent - Start
  328.           .long     114
  329.           .long     OSWriteN-Start
  330.           .long     115
  331.           .long     OSFSControl-Start
  332.           .long     116
  333.           .long     OSSetVarVal-Start
  334.           .long     117
  335.           .long     OSReadVarVal-Start
  336.           .long     120
  337.           .long     OSEvaluateExpression-Start
  338.           .long     121
  339.           .long     OSReadUnsigned-Start
  340.           .long     122
  341.           .long     OSWrite0-Start
  342.           .long     123
  343.           .long     OSReadPalette-Start
  344.           .long     125
  345.           .long     ADFSFreeSpace-Start
  346.           .long     126
  347.           .long     OSReadArgs-Start
  348.           .long     127
  349.           .long     OSConvert-Start
  350.           .long     128
  351.           .long     OSModule-Start
  352.           .long     129
  353.           .long     OSHeap-Start
  354.           .long     130
  355.           .long     OSReadMonotonicTime-Start
  356.           .long     131
  357.           .long     OSRemoveCursors
  358.           .long     132
  359.           .long     OSRestoreCursors
  360.           .long     133
  361.           .long     OSPrintChar
  362.           .long     134
  363.           .long     OSReadVduVariables
  364.           .long     143
  365.           .long     OSMouse-Start
  366.           .long     144
  367.           .long     OSSpriteOp-Start
  368.           .long     145
  369.           .long     OSPlot-Start
  370.           .long     150
  371.           .long     0
  372.           .LONG  0x12345678
  373.           .LONG  Globinits + 4 - Start
  374.           .LONG  Globinits + 12 - Start
  375.           .LONG  Globinits + 20 - Start
  376.           .LONG  Globinits + 28 - Start
  377.           .LONG  Globinits + 36 - Start
  378.           .LONG  Globinits + 44 - Start
  379.           .LONG  Globinits + 52 - Start
  380.           .LONG  Globinits + 60 - Start
  381.           .LONG  Globinits + 68 - Start
  382.           .LONG  Globinits + 76 - Start
  383.           .LONG  Globinits + 84 - Start
  384.           .LONG  Globinits + 92 - Start
  385.           .LONG  Globinits + 100 - Start
  386.           .LONG  Globinits + 108 - Start
  387.           .LONG  Globinits + 116 - Start
  388.           .LONG  Globinits + 124 - Start
  389.           .LONG  Globinits + 132 - Start
  390.           .LONG  Globinits + 140 - Start
  391.           .LONG  Globinits + 148 - Start
  392.           .LONG  Globinits + 156 - Start
  393.           .LONG  Globinits + 164 - Start
  394.           .LONG  Globinits + 172 - Start
  395.           .LONG  Globinits + 180 - Start
  396.           .LONG  Globinits + 188 - Start
  397.           .LONG  Globinits + 196 - Start
  398.           .LONG  Globinits + 204 - Start
  399.           .LONG  Globinits + 212 - Start
  400.           .LONG  0x87654321
  401.