Initial revision
[ssr] / StraySrc / Libraries / Sapphire / sail / s / mem
1 ;
2 ; mem.s
3 ;
4 ; Generic memory allocation for TermScript
5 ;
6 ; © 1995 Straylight
7 ;
8
9 ;----- Standard Header ------------------------------------------------------
10
11 GET libs:header
12 GET libs:swis
13
14 GET libs:stream
15
16 ;----- External dependencies ------------------------------------------------
17
18 GET sh.errNum
19 GET sh.error
20
21 ;----- Main code ------------------------------------------------------------
22
23 AREA |TermScript$$Code|,CODE,READONLY
24
25 ; --- mem_alloc ---
26 ;
27 ; On entry: R0 == size of block to allocate
28 ;
29 ; On exit: R0 == pointer to anchor for that block
30 ; May return an error
31 ;
32 ; Use: Tries to allocate a block of memory, and returns a pointer
33 ; to the anchor for that block. All very unusual really,
34 ; but we blame Wimp_Extension which allocates anchors for
35 ; you in an utterley horrible way.
36
37
38 EXPORT mem_alloc
39 mem_alloc ROUT
40
41 ; --- For now, we will use the RMA ---
42
43 STMFD R13!,{R1-R3,R14}
44 ADD R3,R0,#4
45 MOV R0,#6
46 SWI XOS_Module
47 BVS %99mem_alloc
48 ADD R3,R2,#4
49 STR R3,[R2,#0]
50 MOV R0,R2
51 LDMFD R13!,{R1-R3,PC}^
52
53 99mem_alloc MOV R0,#err_noMem
54 B error_report
55
56 LTORG
57
58 ; --- mem_free ---
59 ;
60 ; On entry: R0 == anchor of the block to free
61 ;
62 ; On exit: --
63 ;
64 ; Use: Frees the block.
65
66 EXPORT mem_free
67 mem_free ROUT
68
69 STMFD R13!,{R0-R2,R14}
70 LDR R2,[R0,#0]
71 SUB R2,R2,#4
72 MOV R0,#7
73 SWI OS_Module
74 LDMFD R13!,{R0-R2,PC}^
75
76 LTORG
77
78 ; --- mem_realloc ---
79 ;
80 ; On entry: R0 == pointer to block anchor
81 ; R1 == new size requested
82 ;
83 ; On exit: May return an error
84 ;
85 ; Use: Resizes a block
86
87 EXPORT mem_realloc
88 mem_realloc ROUT
89
90 MOV R0,#err_realloc
91 B error_report
92
93 LTORG
94
95 ;----- That's all, folks ----------------------------------------------------
96
97 END