23
23
#include <stdio.h>
24
24
#include <stdlib.h>
25
25
#include <time.h>
26
+ #include <string.h>
26
27
27
28
#include "tossystem.h"
28
29
#include "cpu.h"
32
33
#define GEMDOS_TRACE_CONTEXT
33
34
#include "config.h"
34
35
36
+ /* GEMDOS return values */
37
+
38
+ #define E_OK (0)
39
+ #define EINVFN (32)
40
+ #define EFILNF (33)
41
+ #define EPTHNF (34)
42
+ #define ENHNDL (35)
43
+ #define EACCDN (36)
44
+ #define EIHNDL (37)
45
+ #define ENSMEM (39)
46
+ #define EIMBA (40)
47
+ #define EDRIVE (46)
48
+ #define ECWD (47)
49
+ #define ENSAME (48)
50
+ #define ENMFIL (49)
51
+ #define ELOCKED (58)
52
+ #define ENSLOCK (59)
53
+ #define ERANGE (64)
54
+ #define EINTRN (65)
55
+ #define EPLFMT (66)
56
+ #define EGSBF (67)
57
+ #define EBREAK (68)
58
+ #define EXCPT (69)
59
+ #define EPTHOV (70)
60
+ #define ELOOP (80)
61
+ #define EPIPE (81)
62
+
35
63
/* GEMDOS functions */
36
64
37
65
/* Console I/O functions *****************************************************/
@@ -111,6 +139,26 @@ uint32_t GEMDOS_Pterm0()
111
139
112
140
/* Memory management functions ***********************************************/
113
141
142
+ struct GEMDOS_mem_area ;
143
+ struct GEMDOS_mem_area {
144
+ uint32_t base , len ;
145
+ struct GEMDOS_mem_area * next ;
146
+ };
147
+ struct GEMDOS_mem_area * GEMDOS_mem_list ;
148
+
149
+ struct GEMDOS_mem_area * find_mem_area (uint32_t base )
150
+ {
151
+ struct GEMDOS_mem_area * ptr = GEMDOS_mem_list ;
152
+ while (ptr )
153
+ {
154
+ if (ptr -> base == base )
155
+ break ;
156
+ ptr = ptr -> next ;
157
+ }
158
+
159
+ return ptr ;
160
+ }
161
+
114
162
uint32_t GEMDOS_Mshrink ()
115
163
{
116
164
uint32_t newsiz = peek_u32 (8 );
@@ -119,11 +167,23 @@ uint32_t GEMDOS_Mshrink()
119
167
FUNC_TRACE_ENTER_ARGS {
120
168
printf (" ns: 0x%x, b: 0x%x\n" , newsiz , block );
121
169
}
170
+
171
+ struct GEMDOS_mem_area * ma = find_mem_area (block );
172
+ if (!ma )
173
+ return - EIMBA ;
174
+ if (ma -> len < newsiz )
175
+ return - EGSBF ;
176
+
177
+ ma -> len = newsiz ;
122
178
123
- /* TODO currently, we do not react to this */
124
179
return 0 ;
125
180
}
126
181
182
+ /* uint32_t GEMDOS_Malloc()
183
+ uint32_t GEMDOS_Mfree()
184
+ uint32_t GEMDOS_addalt()
185
+ uint32_t GEMDOS_xalloc() */
186
+
127
187
/* Date/time functions *******************************************************/
128
188
129
189
uint32_t GEMDOS_Tgetdate ()
@@ -456,6 +516,25 @@ struct GEMDOS_function GEMDOS_functions[] = {
456
516
457
517
void gemdos_init (struct tos_environment * te )
458
518
{
519
+ struct GEMDOS_mem_area * ma = malloc (sizeof (struct GEMDOS_mem_area ));
520
+ memset (ma , 0 , sizeof (struct GEMDOS_mem_area ));
521
+
522
+ /* The initial area is by convention and relates to the binary loading and
523
+ * base page setup from tossystem */
524
+ ma -> base = 0x800 ;
525
+ ma -> len = te -> size + 0x100 ; /* Size + basepage */
526
+
527
+ GEMDOS_mem_list = ma ;
528
+ }
529
+
530
+ void gemdos_free ()
531
+ {
532
+ while (GEMDOS_mem_list )
533
+ {
534
+ struct GEMDOS_mem_area * n = GEMDOS_mem_list -> next ;
535
+ free (GEMDOS_mem_list );
536
+ GEMDOS_mem_list = n ;
537
+ }
459
538
}
460
539
461
540
void gemdos_trap ()
0 commit comments