Skip to content

Commit 3582661

Browse files
committed
Added base for memory mamangement, moved GEMDOS return value defines from header, added sub-system clean up hook
1 parent 9a2f4f2 commit 3582661

File tree

3 files changed

+86
-29
lines changed

3 files changed

+86
-29
lines changed

gemdos.c

+80-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <stdio.h>
2424
#include <stdlib.h>
2525
#include <time.h>
26+
#include <string.h>
2627

2728
#include "tossystem.h"
2829
#include "cpu.h"
@@ -32,6 +33,33 @@
3233
#define GEMDOS_TRACE_CONTEXT
3334
#include "config.h"
3435

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+
3563
/* GEMDOS functions */
3664

3765
/* Console I/O functions *****************************************************/
@@ -111,6 +139,26 @@ uint32_t GEMDOS_Pterm0()
111139

112140
/* Memory management functions ***********************************************/
113141

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+
114162
uint32_t GEMDOS_Mshrink()
115163
{
116164
uint32_t newsiz = peek_u32(8);
@@ -119,11 +167,23 @@ uint32_t GEMDOS_Mshrink()
119167
FUNC_TRACE_ENTER_ARGS {
120168
printf(" ns: 0x%x, b: 0x%x\n", newsiz, block);
121169
}
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;
122178

123-
/* TODO currently, we do not react to this */
124179
return 0;
125180
}
126181

182+
/* uint32_t GEMDOS_Malloc()
183+
uint32_t GEMDOS_Mfree()
184+
uint32_t GEMDOS_addalt()
185+
uint32_t GEMDOS_xalloc() */
186+
127187
/* Date/time functions *******************************************************/
128188

129189
uint32_t GEMDOS_Tgetdate()
@@ -456,6 +516,25 @@ struct GEMDOS_function GEMDOS_functions[] = {
456516

457517
void gemdos_init(struct tos_environment *te)
458518
{
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+
}
459538
}
460539

461540
void gemdos_trap()

gemdos.h

+2-28
Original file line numberDiff line numberDiff line change
@@ -23,36 +23,10 @@
2323

2424
#include "tossystem.h"
2525

26-
/* GEMDOS return values */
27-
28-
#define E_OK (0)
29-
#define EINVFN (32)
30-
#define EFILNF (33)
31-
#define EPTHNF (-34)
32-
#define ENHNDL (-35)
33-
#define EACCDN (-36)
34-
#define EIHNDL (-37)
35-
#define ENSMEM (-39)
36-
#define EIMBA (-40)
37-
#define EDRIVE (-46)
38-
#define ECWD (-47)
39-
#define ENSAME (-48)
40-
#define ENMFIL (-49)
41-
#define ELOCKED (-58)
42-
#define ENSLOCK (-59)
43-
#define ERANGE (-64)
44-
#define EINTRN (-65)
45-
#define EPLFMT (-66)
46-
#define EGSBF (-67)
47-
#define EBREAK (-68)
48-
#define EXCPT (-69)
49-
#define EPTHOV (-70)
50-
#define ELOOP (-80)
51-
#define EPIPE (-81)
52-
53-
/* GEMDOS trap function */
26+
/* GEMDOS functions */
5427

5528
void gemdos_init(struct tos_environment *);
29+
void gemdos_free();
5630
void gemdos_trap();
5731

5832
#endif /* GEMDOS_H */

tossystem.c

+4
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,10 @@ int init_tos_environment(struct tos_environment *te, void *binary, uint64_t size
211211

212212
void free_tos_environment(struct tos_environment *te)
213213
{
214+
/* Clean up sub-systems */
215+
gemdos_free();
216+
/* TODO clean up after other sub-systems here as well */
217+
214218
free(te->bp);
215219
te->bp = 0;
216220

0 commit comments

Comments
 (0)