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

Diff of /public/pc/tools/osdk/main/Osdk/_final_/lib/header.s

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.780  
changed lines
  Added in v.781

  ViewVC Help
Powered by ViewVC 1.1.26