Initial commit
This commit is contained in:
parent
3ba3e98f6b
commit
1dd7b8b07f
3 changed files with 103 additions and 1 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
64
slaballoc.c
Normal file
64
slaballoc.c
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#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(){
|
||||
|
||||
}
|
||||
38
slaballoc.h
Normal file
38
slaballoc.h
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#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];
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue