4 ; Environment handling for SAIL
9 ;----- Standard header ------------------------------------------------------
16 ;----- External dependencies ------------------------------------------------
20 ;----- Main code ------------------------------------------------------------
22 AREA |Sapphire$$Code|,CODE,READONLY
24 ; --- sail_createEnv ---
26 ; On entry: R0 == parent environment handle or 0
27 ; R1 == address of CALL table
29 ; On exit: R0 == environment handle
32 ; Use: Creates an environment.
34 ; The CALL tabe format is as follows:
38 ; word size of data for this prefix
41 ; word address to call
49 STMFD R13!,{R1,R2,R14} ;Stach registers
51 MOV R2,R0 ;Look after handle
52 MOV R0,#sEnv__size ;Get the size
53 BL sub_alloc ;Allocate it then
54 BVS %90 ;Jump ahead with glum
56 STR R2,[R0,#sEnv__parent] ;Store the parent handle
57 STR R1,[R0,#sEnv__table] ;Store call table address
58 MOV R14,#0 ;I like this value
59 STR R14,[R0,#sEnv__next] ;No next block yet
60 90 LDMFD R13!,{R1,R2,R14} ;Load back registers
61 ORRVSS PC,R14,#V_flag ;Return with error
62 BICVCS PC,R14,#V_flag ;Return without error
66 ; --- sail_addCalls ---
68 ; On entry: R0 == environment handle
69 ; R1 == address of new call table
71 ; On exit: May return an error
73 ; Use: Adds an extra CALL table to an environment. Useful
79 ASSERT sEnv__next=sCall__next
80 ASSERT sEnv__table=sCall__table
82 STMFD R13!,{R0-R3,R14} ;Stack register
83 MOV R3,R1 ;Look after the call table
84 ADD R2,R0,#sEnv__next ;Point to the next entry
85 00 LDR R14,[R2,#sCall__next] ;Load the next pointer
86 CMP R14,#0 ;Is there one?
87 MOVNE R2,R14 ;No -- point to next one
88 BNE %b00 ;...and do this lots
90 MOV R0,#sEnv__callSize ;Get the size to allocate
91 BL sub_alloc ;Allocate it then
92 BVS %95 ;Report possible error
94 STR R0,[R2,#sCall__next] ;Store this as next pointer
95 STR R3,[R0,#sCall__table] ;Store the table pointer
96 MOV R14,#0 ;A NULL word
97 STR R14,[R0,#sCall__next] ;No next pointer yet
99 LDMFD R13!,{R0-R3,R14} ;Load back register
100 BICS PC,R14,#V_flag ;Return without error
102 90 LDMFD R13!,{R0-R3,R14} ;Load back register
103 ORRS PC,R14,#V_flag ;Return with error
107 ;----- Workspace ------------------------------------------------------------
109 ; --- Environment block ---
113 sEnv__next # 4 ;Pointer to next call table
114 sEnv__table # 4 ;Pointer to the call table
115 sEnv__parent # 4 ;Parent environment
116 sEnv__size # 0 ;Size of the structure
118 ; --- The call block ---
125 ;----- That's all, folks ----------------------------------------------------