added mem

This commit is contained in:
spikey 2024-02-17 19:20:00 -05:00
parent 8f96a347b1
commit 719e37dd5a
3 changed files with 54 additions and 10 deletions

26
sys/include/memory.h Normal file
View File

@ -0,0 +1,26 @@
#ifndef MEMORY_H
#define MEMORY_H
#include <types.h>
/*
* Each allocated memory is stored internally like this:
* nnnnssss(u)+
* n represents the address to the next string
* s represents the size of the allocated memory
* c
* u represents the actual string
*
* A struct cannot be plainly used because we would have to store a reference
* so this complicated structure is utilized instead.
*/
#define START 0xb80f1
#define USABLE(m) m + sizeof(s32) + sizeof(void *)
#define NEXT(m) (void *) *m
#define SIZE(m) (s32) m[sizeof(void *)]
void *start = 0x0 ;
#endif

View File

@ -1,11 +1,13 @@
#ifndef TYPES_H #ifndef TYPES_H
#define TYPES_H #define TYPES_H
typedef unsigned int u32; #define NULL 0x0
typedef unsigned short u16;
typedef unsigned char u8; typedef unsigned int u32;
typedef int s32; typedef unsigned short u16;
typedef short s16; typedef unsigned char u8;
typedef char s8; typedef int s32;
typedef short s16;
typedef char s8;
#endif #endif

View File

@ -1,6 +1,22 @@
#include <memory.h> #include <memory.h>
struct linkedlist { void *
u32 node; malloc(s32 size)
linkedlist *next; {
}; s32 actual_size = size + sizeof(s32) + sizeof(void *);
if (start == NULL) {
start = (void *) START;
start[0] = '\0';
start[1] = '\0';
start[2] = '\0';
start[3] = '\0';
SIZE(m) = size;
return USABLE(m);
}
/* TODO */
}