/[projet1]/public/pc/tools/osdk/main/Osdk/_final_/lib2/header.s
Defence Force logotype

Contents of /public/pc/tools/osdk/main/Osdk/_final_/lib2/header.s

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1154 - (show annotations)
Sun Aug 10 18:19:54 2014 UTC (5 years, 7 months ago) by dbug
File size: 5208 byte(s)


1
2
3
4 .zero
5
6 *= $50
7
8 ;
9 ; Most of the documentation/comments in this file are from 'Another Approach to Instruction Set Architecture—VAX'
10 ;
11 ap .dsb 2 ; Argument pointer - points to the base of the list of arguments or parameters in memory that are passed to the procedure
12 fp .dsb 2 ; Frame pointer - points to the base of the local variables of the procedure that are kept in memory (the stack frame)
13 sp .dsb 2 ; Stack pointer - points to the top of the stack
14
15 tmp0 .dsb 2
16 tmp1 .dsb 2
17 tmp2 .dsb 2
18 tmp3 .dsb 2
19 tmp4 .dsb 2
20 tmp5 .dsb 2
21 tmp6 .dsb 2
22 tmp7 .dsb 2
23
24 op1 .dsb 2
25 op2 .dsb 2
26
27 tmp .dsb 2
28
29 reg0 .dsb 2
30 reg1 .dsb 2
31 reg2 .dsb 2
32 reg3 .dsb 2
33 reg4 .dsb 2
34 reg5 .dsb 2
35 reg6 .dsb 2
36 reg7 .dsb 2
37
38
39 .text
40
41 osdk_start
42 ;jmp osdk_start ; Comment out to not autostart the system
43
44 ;#include "adress.tmp"
45 ;*=$800
46
47 ;
48 ; Needs to clear the BSS section
49 ;
50
51
52
53
54 tsx
55 lda #<osdk_stack
56 sta sp
57 lda #>osdk_stack
58 sta sp+1
59 ldy #0
60 stx retstack
61 jmp _main
62 retstack
63 .byt 0
64
65 /*
66 Preserving Registers Across Procedure Invocation of
67 swap
68 The VAX has a pair of instructions that preserve registers calls and ret. This
69 example shows how they work.
70 The VAX C compiler uses a form of callee convention. Examining the code
71 above, we see that the values in registers r0, r1, r2, and r3 must be saved so
72 that they can later be restored. The calls instruction expects a 16-bit mask at
73 the beginning of the procedure to determine which registers are saved: if bit i
74 is set in the mask, then register i is saved on the stack by the calls instruction.
75 In addition, calls saves this mask on the stack to allow the return instruction
76 (ret) to restore the proper registers. Thus the calls executed by the caller
77 does the saving, but the callee sets the call mask to indicate what should be
78 saved.
79 One of the operands for calls gives the number of parameters being
80 passed, so that calls can adjust the pointers associated with the stack: the argument
81 pointer (ap), frame pointer (fp), and stack pointer (sp). Of course,
82 calls also saves the program counter so that the procedure can return!
83 Thus, to preserve these four registers for swap, we just add the mask at the
84 beginning of the procedure, letting the calls instruction in the caller do all the
85 work:
86 .word ^m<r0,r1,r2,r3>; set bits in mask for 0,1,2,3
87 This directive tells the assembler to place a 16-bit constant with the proper bits
88 set to save registers r0 though r3.
89 */
90
91
92 ; Code is called this way:
93 ;
94 ; ldx #6 <- ?
95 ; lda #1 <- Sometimes "4" or "5" <- Number of registers to save?
96 ; jsr enter
97 ;
98 ; Y=The routine that calls a subfunction puts in Y the number of parameters*2 in Y. Example is CALLV_C(_drawbox,6)
99 ; X=
100 ; A=Number of registers to save (registers being adresses from 'reg0' to 'reg7'
101 enter
102 sty tmp ; Save the number of bytes reserved for parameters
103 stx tmp+1
104
105 ; Save the registers
106 asl ; Number of registers to save x2
107 sta op2 ; =number of bytes to save
108 tax
109 beq noregstosave
110 savereg
111 lda reg0-1,x
112 sta (sp),y
113 iny
114 dex
115 bne savereg
116
117 noregstosave
118 sty op2+1 ; New stack offset after the registers have been saved
119
120 ; Save the argument pointer
121 lda ap
122 sta (sp),y
123 iny
124 lda ap+1
125 sta (sp),y
126 iny
127
128 ; Save the frame pointer
129 lda fp
130 sta (sp),y
131 iny
132 lda fp+1
133 sta (sp),y
134 iny
135
136 ; Save the number of bytes saved for the registers
137 lda op2
138 sta (sp),y
139 iny
140 lda tmp ; Previously saved number of bytes for parameters
141 sta (sp),y
142
143 ; Update the argument pointer
144 ; AP=SP
145 ; FP=SP+stack offset
146 clc
147 lda sp
148 sta ap
149 adc op2+1
150 sta fp
151 lda sp+1
152 sta ap+1
153 adc #0
154 sta fp+1
155
156 ; SP=FP+X
157 lda tmp+1
158 adc fp
159 sta sp
160 lda fp+1
161 adc #0
162 sta sp+1
163 rts
164
165
166 /*
167 The return instruction undoes the work of calls. When finished, ret sets
168 the stack pointer from the current frame pointer to pop everything calls
169 placed on the stack. Along the way, it restores the register values saved by
170 calls, including those marked by the mask and old values of the fp, ap, and
171 pc.
172 To complete the procedure swap, we just add one instruction:
173 ret ; restore registers and return
174 */
175 leave
176 stx op2 ; Save X
177 sta op2+1 ; Save A
178
179 ; Restore sp from ap
180 lda ap
181 sta sp
182 lda ap+1
183 sta sp+1
184
185 ldy #4
186 lda (fp),y
187 tax
188 iny
189 lda (fp),y
190 tay
191 txa
192 beq noregstorestore
193
194 restorereg
195 lda (sp),y
196 sta reg0-1,x
197 iny
198 dex
199 bne restorereg
200
201 noregstorestore
202 ; Restore AP
203 ldy #0
204 lda (fp),y
205 sta ap
206 iny
207 lda (fp),y
208 sta ap+1
209
210 ; Restore FP
211 iny
212 lda (fp),y
213 sta tmp+0
214 tax
215 iny
216 lda (fp),y
217 sta fp+1
218 stx fp
219
220 ldx op2 ; Restore X
221 lda op2+1 ; Restore A
222 rts
223
224 jsrvect
225 jmp (0000)
226
227 _exit
228 ldx retstack
229 txs
230 rts
231
232 reterr
233 lda #$ff ; return -1
234 tax
235 rts
236
237 retzero
238 false
239 lda #0 ;return 0
240 tax
241 rts
242
243 true
244 ldx #1 ;return 1
245 lda #0
246 rts
247
248
249 #define load_acc1 $DE7B
250 #define load_acc2 $DD51
251 #define store_acc $DEAD
252 #define fadd $DB25
253 #define fsub $DB0E
254 #define fmul $DCF0
255 #define fdiv $DDE7
256 #define fneg $E271
257 #define fcomp $DF4C
258 #define cif $DF24
259
260 cfi
261 jsr $DF8C
262 ldx $D3
263 lda $D4
264 rts
265

  ViewVC Help
Powered by ViewVC 1.1.26