diff --git a/autodebug.sh b/autodebug.sh index 8c84c80..7199ded 100755 --- a/autodebug.sh +++ b/autodebug.sh @@ -9,7 +9,7 @@ shift 2 qemu-system-x86_64 "$@" & -wait 1 +sleep 1 "$termname" -e gdb -ex 'target remote localhost:1234' -ex 'break _start' -ex 'continue' build/SFB25.elf diff --git a/slaballoc.c b/slaballoc.c new file mode 100644 index 0000000..e7a37b5 --- /dev/null +++ b/slaballoc.c @@ -0,0 +1,64 @@ +#include +#include +#include "slaballoc.h" + +char memory[4096 * 10]; + +int cnt = 0; + +struct ma_kcache *head = NULL; // create standard sizes + + +uint64_t *alloc_contigious_pages(int num){ + uint64_t *ret = (uint64_t*)(memory + cnt*4096); + cnt+=num; + return ret; +} + + +struct ma_slab *_ma_alloc_initial_slab(struct ma_kcache *kcache){ + uint64_t *p = alloc_contigious_pages(1); + + int bufnum = (4096 - sizeof(struct ma_slab)) / kcache->objsize; // Calculate the number of buffers in this slab + + for(int i = 0; i < bufnum; i++){ + (uint64_t*)((uint64_t)p + i * kcache->objsize) + } + +} + +struct ma_kcache *ma_cache_create(char *name, size_t size, uint32_t flags, void (*constructor)(void *, size_t), void (*destructor)(void *, size_t)){ + + struct ma_kcache *kcache = (struct ma_kcache*)alloc_contigious_pages(1); + + head->next = kcache; + kcache->prev = head; + head = kcache; + + int bufnum = (4096 - sizeof(struct ma_slab)) / size; // Calculate the number of buffers in this slab + + struct ma_slab *slab_structure = (struct ma_slab*)((uint64_t)kcache - sizeof(struct ma_slab)); + + kcache->slabs_free = slab_structure; + + return kcache; + + +} + +void *ma_cache_alloc(struct ma_kcache *cache, uint64_t flags){ + + if(cache->slabs_free == NULL){ + if(cache->slabs_partial == NULL){ + + } + } + + common: + + +} + +int main(){ + +} diff --git a/slaballoc.h b/slaballoc.h new file mode 100644 index 0000000..9d4da4e --- /dev/null +++ b/slaballoc.h @@ -0,0 +1,38 @@ +#include +#include +#include +#define KCACHE_NAME_LEN 5 + + +struct ma_bufctrl { + struct ma_bufctrl *next; + size_t *startaddr; +}; + + +struct ma_slab { + struct ma_slab *next; + struct ma_slab *prev; + + struct ma_bufctrl *buf_list; + + uint32_t refcount; + +}; + +struct ma_kcache { + struct ma_kcache *next; + struct ma_kcache *prev; + + uint32_t objsize; + uint32_t flags; + uint32_t num; + + struct ma_slab *slabs_free; + struct ma_slab *slabs_partial; + struct ma_slab *slabs_used; + + struct ma_bufctrl *bufctrl_arr; + + char name[KCACHE_NAME_LEN]; +}; \ No newline at end of file