added mem
This commit is contained in:
parent
8f96a347b1
commit
719e37dd5a
26
sys/include/memory.h
Normal file
26
sys/include/memory.h
Normal 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
|
@ -1,6 +1,8 @@
|
|||||||
#ifndef TYPES_H
|
#ifndef TYPES_H
|
||||||
#define TYPES_H
|
#define TYPES_H
|
||||||
|
|
||||||
|
#define NULL 0x0
|
||||||
|
|
||||||
typedef unsigned int u32;
|
typedef unsigned int u32;
|
||||||
typedef unsigned short u16;
|
typedef unsigned short u16;
|
||||||
typedef unsigned char u8;
|
typedef unsigned char u8;
|
||||||
|
24
sys/memory.c
24
sys/memory.c
@ -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 */
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user