1 * H316 SAFE SOFTWARE STACK, REV. 0.1
6 * PHILIPP HACHTMANN, 2007
10 * 0.1 - INITIAL REVISION (22.12.2007)
14 * TO PROVIDE A MULTI-PURPOSE STACK MECHANISM
15 * TO PROVIDE A SPECIAL-PURPOSE STACK MECHANISM FOR RECURSIVE
18 * THEORY OF OPERATION:
20 * THE STACK ROUTINES MAINTAIN AN UPWARDS GROWING STACK.
21 * EVERY USAGE CONTEXT OF THE STACK NEEDS TO RESERVE THE SPACE FOR
22 * ITS STACK'S DATA. THIS ENABLES THE PROGRAMMER TO CHOOSE THE STACK
23 * SIZE AND USE MULTIPLE STACKS IN MULTIPLE PLACES INDEPENDENTLY.
24 * ALL STACK RELATED ROUTINES TAKE A POINTER TO THE STACK'S INTERNAL
25 * DATA AS FIRST ARGUMENT.
27 * THE DATA LAYOUT OF THE STACK DATA IS AS FOLLOWING:
29 * SIZE OCT '1000 SIZE OF THE STACK IN MACHINE WORDS
30 * PTR DAC ** THE STACK POINTER
31 * FILL DAC ** THE FILL COUNTER
32 * OVER DAC OFL OPTIONAL POINTER TO OVERFLOW ERROR ROUTINE
33 * UNDR DAC UFL OPTIONAL POINTER TO UNDERFLOW ERROR ROUTINE
34 * STCK BSS '1000 THE STACK DATA
36 * IF CUSTOM ERROR HANDLING ROUTINES ARE NOT TO BE USED, SET THE TWO
37 * POINTER LOCATIONS TO ZERO. THEN, INTERNAL ERROR ROUTINES WILL BE
38 * USED. SIZE AND THE FUNCTION POINTERS HAVE TO BE INITIALISED. THE
39 * OTHER LOCATIONS ARE INITIALISED BY THE STACK ROUTINES.
43 * INITIALISING STACK POINTER:
46 * DAC SDATA STACK DATA
47 * DAC SSIZ DATA SIZE (NOT STACK DEPTH!!!)
50 * PUSHING AND POPPING THE A-REGISTER FROM AND TO THE STACK:
52 * CALL S$PUSH VALUE IN A REGISTER IS PUSHED.
55 * CALL $$POP VALUE FROM STACK IS POPPED INTO A-REGISTER.
58 * PUSHING AND POPPING ARBITRARY DATA FROM AND TO THE STACK:
71 * MAKING A RECURSIVE CALL FROM FORTRAN IV TO A FORTRAN IV OR OTHER ROUTINE:
73 * THE ROUTINE S$CALL SAVES A SET OF LOCAL VARIABLES ONTO THE STACK.
74 * IT ALSO SAVES THE RETURN ADDRESS AND ITS OWN PARAMETERS.
75 * S$LLAC DOES EVERYTHING IN REVERSE ORDER.
77 * HERE IS AN EXAMPLE HOW TO USE THE TWO ROUTINES IN FORTRAN IV:
79 * C LOCAL VARIABLES I(3),A,Z TO SAVE
81 * CALL S$CALL(3,I,3,A,2,Z,2)
82 * RETURN <-- FOR THE RETURN ADDRESS OF THE CURRENT ROUTINE
86 * ASSEMBLER CALLING SEQUENCE:
89 * DAC VARNO NO OF LOCAL VARIABLES TO SAVE ON THE STACK
90 * DAC VAR1 POINTER TO FIRST VARIABLE
91 * DAC SIZE1 WORD SIZE OF VARIABLE
93 * DAC VARN POINTER TO LAST VARIABLE
94 * DAC SIZEN WORD SIZE OF LAST VARIABLE
95 * DAC 0 FORTRAN IV COMPILER GENERATED
97 * JMP* PROC RETURN JUMP, GENERATED BY THE "RETURN" STATEMENT
105 ********************************************************************************
108 **** SYMBOL DECLARATIONS
110 SUBR STACK,SBUF JUST A LABEL FOR THE OBJECT TAPE
111 SUBR S$INIT,INIT INITIALIZATION
112 SUBR S$PUSH,PUSH SINGLE WORD PUSH
113 SUBR S$POP,POP SINGLE WORD POP
114 SUBR S$PUSM,PUSM MEMORY RANGE PUSH
115 SUBR S$POPM,POPM MEMORY RANGE POP
116 SUBR S$PTR,SPTR STACK POINTER ACCESS
121 ********************************************************************************
124 REL RELOCATEABLE OBJECT
127 ********************************************************************************
129 * *** PUSH MEMORY RANGE TO STACK
131 PUSM DAC ** ENTRY POINT TO PUSH ROUTINE
132 STA ATM1 SAVE A-REGISTER
134 LDA* PUSM LOAD DATA BASE
136 STA DPT SAVE FOR LATER USE
138 LDA* PUSM LOAD POINTER
139 STA PTR STORE TO TRANSFER POINTER
140 IRS PUSM GO TO NEXT ARGUMENT
141 LDA* PUSM LOAD TRANSFER SIZE
142 IRS PUSM CORRECT RETURN ADDRESS
144 TCA NEGATE WORD COUNT
145 STA CNT STORE TO COUNTER
147 PULP LDA* PTR GET DATA
151 IRS PTR INCREMENT POINTER
152 IRS CNT INCREMENT BYTE COUNTER
153 JMP PULP DO IT AGAIN!
155 LDA ATM1 RESTORE A-REG
159 ********************************************************************************
162 **** POP MEMORY RANGE FROM STACK
164 POPM DAC ** ENTRY POINT TO PUSH ROUTINE
165 STA ATM1 SAVE A-REGISTER
167 LDA* POPM GET DATA POINTER
169 STA DPTR STORE FOR LATER USE
171 LDA* POPM LOAD POINTER
172 IRS POPM GO TO NEXT ARGUMENT
173 ADD* POPM ADD TRANSFER SIZE
174 SUB =1 SUBSTRACT 1 TO GET HIGH ADDRESS
175 STA PTR STORE TO TRANSFER POINTER
176 LDA* POPM LOAD TRANSFER SIZE
177 IRS POPM CORRECT RETURN ADDRESS
179 TCA NEGATE WORD COUNT
180 STA CNT STORE TO COUNTER
182 POLP JST POP POP DATA FROM THE STACK
189 IRS CNT INCREMENT BYTE COUNTER
190 JMP POLP DO IT AGAIN!
192 LDA ATM1 RESTORE A-REG
196 ********************************************************************************
199 **** PUSH SINGLE WORD ONTO STACK
202 PUSH DAC ** REAL PUSH ROUTINE - PUSH AC TO STACK.
204 STX XTM SAVE X REGISTER
205 STA ATM2 SAVE A REGISTER
207 LDX* PUSH LOAD INDEX REGISTER WITH DATA BASE
210 LDA FILL,1 LOAD FILL SIZE
211 CAS SSIZ,1 COMPARE STACK SIZE
216 STA* SPTR,1 NO OVERFLOW, PUT DATA ONTO STACK
217 IRS SPTR,1 INCREMENT STACK POINTER
218 IRS FILL,1 INCREMENT FILL SIZE
220 LDX XTM RESTORE X REGISTER
222 JMP* PUSH RETURN WITH A-REG UNALTERED.
225 ********************************************************************************
228 **** POP SINGLE WORD FROM STACK
230 POP DAC ** REAL POP ROUTINE - POP AC FROM STACK.
232 STX XTM SAVE X REGISTER
233 LDX* POP LOAD INDEX REGISTER WITH DATA BASE
238 JST UFLO NOTHING INSIDE? SKIP!
240 LDA SPTR,1 LOAD STACK POINTER
241 SUB =1 DECREMENT IT TO LAST USED LOCATION
242 STA SPTR,1 SAVE IT BACK
245 STA FILL,1 DECREMENT FILL SIZE
247 LDA* SPTR,1 LOAD VALUE FROM THE STACK
248 LDX XTM RESTORE INDEX REGISTER
252 ********************************************************************************
257 INIT DAC ** INITIALIZE STACK
263 LDA VARS SIZE OF MANAGEMENT VARIABLES
264 ADD* INIT BASE ADDRESS
265 STA SPTR,1 SAVE TO STACK POINTER
268 LDA* INIT LOAD DATA POOL SIZE POINTER
269 STA PTR DEREFERENCE POINTER
270 LDA* PTR LOAD DATA POOL SIZE
271 SUB VARS VARIABLE SIZE
272 STA SSIZ,1 SAVE TO STACK DEPTH
280 IRS INIT FOR FORTRAN COMPATIBILITY
284 ********************************************************************************
287 **** ERROR HANDLING ROUTINES
290 OFLO DAC ** STACK OVERFLOW ROUTINE
291 LDA OMSP LOAD OVERFLOW MESSAGE POINTER
292 JST TYPE TYPE IT OUT.
294 HLT WHAT WE DO: HALT THE MACHINE.
295 JMP *-1 YOU CANNOT SIMPLY LEAVE THIS, IT'S SERIOUS!
298 ****************************************
302 UFLO DAC ** STACK OVERFLOW ROUTINE
303 LDA UMSP LOAD OVERFLOW MESSAGE POINTER
304 JST TYPE TYPE IT OUT.
306 HLT WHAT WE DO: HALT THE MACHINE.
307 JMP *-1 YOU CANNOT SIMPLY LEAVE THIS, IT'S SERIOUS!
310 ****************************************
315 SKS '104 TEST ASR READY
316 JMP *-1 WAIT TO BECOME READY
317 OCP '104 SET TO OUTPUT MODE
319 STA PTR STORE POINTER
321 TLOP LDA* PTR TYPE LOOP
330 SKS '104 ADDITIONAL TEST FOR READY
336 ********************************************************************************
342 PTR DEC 0 TRANSFER POINTER TO USER BUFFERS
343 CNT DEC 0 TRANSFER COUNTER
345 ATM1 DEC 0 A-REGISTER BACKUP
346 ATM2 DEC 0 A-REGISTER BACKUP
347 XTM DEC 0 X-REGISTER BACKUP
352 VARS DEC 3 SIZE OF VARIABLES AT BEGINNING OF DATA
358 OMSP DAC OMSG POINTER TO MESSAGE
359 UMSP DAC UMSG POINTER TO MESSAGE
360 OMSG OCT '006412 CR/LF CHARACTERS
361 BCI 16,STACK OVERFLOW, YOUR'RE SCREWED!
362 DEC 0 TERMINATION CHARACTER
363 UMSG OCT '006412 CR/LF CHARACTERS
364 BCI 17,STACK UNDERFLOW, YOUR'RE SCREWED!
365 DEC 0 TERMINATION CHARACTER
368 ********************************************************************************