Merge branch 'working' of ssh://github.com/op52/ukern into working

This commit is contained in:
Op52 2018-12-05 05:51:42 -05:00
commit 8df0a67f9a
16 changed files with 255 additions and 184 deletions

View File

@ -72,16 +72,9 @@ PREP_FLAGS = -E \
-I$(INC_COMMON) \
$(C_FLAGS_$(MOD))
# generic generate dependency flags used for target
# each submodule can append to this flag
GDEP_FLAGS = $(PREP_FLAGS) \
-MMD \
-MT $@
MKDIR = mkdir -p $(dir $@)
COMP = $(CC) $(C_FLAGS) -o $@ $<
COMPAS = $(AS) $(AS_FLAGS) -o $@ $<
PREP = $(CC) $(PREP_FLAGS) $< > $@
GDEP = $(CC) $(GDEP_FLAGS) -MF $(addsuffix .d, $@) $< > /dev/null
include Rules.top

View File

@ -46,7 +46,7 @@ iso: $(TGT) $(GRUB_CFG)
mkdir -p $(OUT)/temp/boot/grub
cp $(TGT) $(OUT)/temp/secX/
cp $(GRUB_CFG) $(OUT)/temp/boot/grub/
grub-mkrescue -o $(ISO) $(OUT)/temp
grub-mkrescue -d /usr/lib/grub/i386-pc -o $(ISO) $(OUT)/temp
.PHONY: clean
clean:

View File

@ -13,6 +13,7 @@ typedef uint16_t uint16;
typedef int16_t int16;
typedef uint8_t uint8;
typedef int8_t int8;
typedef size_t usize;
typedef _Bool bool;
#define TRUE (1)

View File

@ -19,7 +19,7 @@ struct atree_node
*/
typedef int32 (*atree_cmp_fp)(struct atree_node *tree_node, struct atree_node *self);
struct atree
struct a_tree
{
atree_cmp_fp cmpf;
struct atree_node *root;
@ -27,39 +27,39 @@ struct atree
struct atree_node *
lb_atree_search(struct atree *tree, struct atree_node *entry);
lb_atree_search(struct a_tree *tree, struct atree_node *entry);
struct atree_node *
lb_atree_insert(struct atree *tree, struct atree_node *entry);
lb_atree_insert(struct a_tree *tree, struct atree_node *entry);
struct atree_node *
lb_atree_delete(struct atree *tree, struct atree_node *entry);
lb_atree_delete(struct a_tree *tree, struct atree_node *entry);
void
lb_atree_init(struct atree *tree, atree_cmp_fp compare);
lb_atree_init(struct a_tree *tree, atree_cmp_fp compare);
struct atree_node *
lb_atree_max(struct atree *tree);
lb_atree_max(struct a_tree *tree);
struct atree_node *
lb_atree_min(struct atree *tree);
lb_atree_min(struct a_tree *tree);
struct atree_node *
lb_atree_next(struct atree *tree, struct atree_node *entry);
lb_atree_next(struct a_tree *tree, struct atree_node *entry);
struct atree_node *
lb_atree_prev(struct atree *tree, struct atree_node *entry);
lb_atree_prev(struct a_tree *tree, struct atree_node *entry);
bool
lb_atree_validate(struct atree *tree);
lb_atree_validate(struct a_tree *tree);
uint32
lb_atree_size(struct atree *tree);
lb_atree_size(struct a_tree *tree);

43
kernel/inc/lb/htable.h Normal file
View File

@ -0,0 +1,43 @@
#include "cdef.h"
#include "llist.h"
struct htable_node;
typedef uint32 (*htable_cmp_fp)(struct htable_node* table_node, struct htable_node* self);
typedef uint32 (*htable_hash_fp)(struct htable_node* self);
struct htable_node
{
struct dlist_node list_node;
};
struct htable
{
uint32 bkts;
struct llist *buf;
htable_cmp_fp cmp_fp;
htable_hash_fp hash_fp;
};
void
htable_init(struct htable* table, htable_cmp_fp cmp_fp, htable_hash_fp hash_fp, struct llist *buf, uint32 bkts);
/**
* returns the overwritten object
* returns NULL if no duplicates are overwritten
*/
struct htable_node*
htable_insert(struct htable* table, struct htable_node* entry);
/**
* returns the removed node
* NULL if doesn't exist
*/
struct htable_node*
htable_remove(struct htable* table, struct htable_node* entry);
struct htable_node*
htable_contains(struct htable* table, struct htable_node* entry);

View File

@ -2,16 +2,16 @@
#include "cdef.h"
struct llist_node
struct dlist_node
{
struct llist_node *prev;
struct llist_node *next;
struct dlist_node *prev;
struct dlist_node *next;
};
struct llist
{
struct llist_node *head;
struct llist_node *tail;
struct dlist_node *head;
struct dlist_node *tail;
uint32 size;
};
@ -22,48 +22,24 @@ uint32
lb_llist_size(struct llist *list);
void
lb_llist_push_front(struct llist *list, struct llist_node *node);
void
lb_llist_push_back(struct llist *list, struct llist_node *node);
struct llist_node *
lb_llist_pop_front(struct llist *list);
lb_llist_insert(struct llist *list, struct dlist_node *cur_node, struct dlist_node *new_node);
struct llist_node *
lb_llist_pop_back(struct llist *list);
void
lb_llist_insert_by_idx(struct llist *list, uint32 index, struct llist_node *node);
struct llist_node *
lb_llist_remove_by_idx(struct llist *list, uint32 index);
struct dlist_node *
lb_llist_remove(struct llist *list, struct dlist_node *node);
struct llist_node *
lb_llist_get(struct llist *list, uint32 index);
struct dlist_node *
lb_llist_next(struct dlist_node *node);
void
lb_llist_insert_by_ref(struct llist *list, struct llist_node *cur_node, struct llist_node *new_node);
struct dlist_node *
lb_llist_prev(struct dlist_node *node);
struct llist_node *
lb_llist_remove_by_ref(struct llist *list, struct llist_node *node);
struct llist_node *
lb_llist_next(struct llist_node *node);
struct llist_node *
lb_llist_prev(struct llist_node *node);
struct llist_node *
struct dlist_node *
lb_llist_first(struct llist *list);
struct llist_node *
struct dlist_node *
lb_llist_last(struct llist *list);

0
kernel/inc/lb/sl_list.c Normal file
View File

View File

@ -21,7 +21,7 @@ kmain(struct boot_info *boot_info)
}
// initialize memory manager
status = mm_pmm_init(boot_info);
//status = mm_pmm_init(boot_info);
if (!SX_SUCCESS(status))
{
goto end;

View File

@ -336,21 +336,21 @@ atree_node_delete(struct atree_node *node, struct atree_node *entry, atree_cmp_f
struct atree_node *
lb_atree_min(struct atree *tree)
lb_atree_min(struct a_tree *tree)
{
return atree_node_min(tree->root);
}
struct atree_node *
lb_atree_max(struct atree *tree)
lb_atree_max(struct a_tree *tree)
{
return atree_node_max(tree->root);
}
struct atree_node *
lb_atree_next(struct atree *tree, struct atree_node *entry)
lb_atree_next(struct a_tree *tree, struct atree_node *entry)
{
struct atree_node *succ;
struct atree_node *node;
@ -390,7 +390,7 @@ lb_atree_next(struct atree *tree, struct atree_node *entry)
struct atree_node *
lb_atree_prev(struct atree *tree, struct atree_node *entry)
lb_atree_prev(struct a_tree *tree, struct atree_node *entry)
{
struct atree_node *prev;
struct atree_node *node;
@ -430,14 +430,14 @@ lb_atree_prev(struct atree *tree, struct atree_node *entry)
struct atree_node *
lb_atree_search(struct atree *tree, struct atree_node *entry)
lb_atree_search(struct a_tree *tree, struct atree_node *entry)
{
return atree_node_search(tree->root, entry, tree->cmpf, NULL);
}
struct atree_node *
lb_atree_insert(struct atree *tree, struct atree_node *entry)
lb_atree_insert(struct a_tree *tree, struct atree_node *entry)
{
struct atree_node *old;
@ -448,7 +448,7 @@ lb_atree_insert(struct atree *tree, struct atree_node *entry)
struct atree_node *
lb_atree_delete(struct atree *tree, struct atree_node *entry)
lb_atree_delete(struct a_tree *tree, struct atree_node *entry)
{
struct atree_node *node;
@ -459,7 +459,7 @@ lb_atree_delete(struct atree *tree, struct atree_node *entry)
uint32
lb_atree_size(struct atree *tree)
lb_atree_size(struct a_tree *tree)
{
uint32 size;
struct atree_node *node;
@ -479,7 +479,7 @@ lb_atree_size(struct atree *tree)
void
lb_atree_init(struct atree *tree, atree_cmp_fp compare)
lb_atree_init(struct a_tree *tree, atree_cmp_fp compare)
{
tree->cmpf = compare;
tree->root = NULL;
@ -538,7 +538,7 @@ atree_node_test(struct atree_node *tree, atree_cmp_fp compare)
bool
lb_atree_validate(struct atree *tree)
lb_atree_validate(struct a_tree *tree)
{
if (tree == NULL)
{

49
kernel/lb/htable.c Normal file
View File

@ -0,0 +1,49 @@
#include "clib.h"
#include "cdef.h"
#include "lb/htable.h"
#include "lb/llist.h"
void
htable_init(struct htable *table, htable_cmp_fp cmp_fp, htable_hash_fp hash_fp, struct llist *buf, uint32 bkts)
{
table->hash_fp = hash_fp;
table->cmp_fp = cmp_fp;
table->buf = buf;
table->bkts = bkts;
for (uint32 i = 0; i < bkts; i++)
{
lb_llist_init(&buf[i]);
}
}
struct htable_node *
htable_insert(struct htable *table, struct htable_node *entry)
{
uint32 hash = table->hash_fp(entry) % table->bkts;
struct llist *hlist = &table->buf[hash];
struct htable_node *ret = NULL;
struct dlist_node *lnode = lb_llist_first(hlist);
while(lnode != NULL)
{
struct htable_node *each = OBTAIN_STRUCT_ADDR(lnode, struct htable_node, list_node);
if (table->cmp_fp(each, entry) == 0)
{
ret = each;
break;
}
lnode = lb_llist_next(lnode);
}
if(ret != NULL)
{
lb_llist_remove(hlist, &ret->list_node);
}
/*
* insert to the head
*/
lb_llist_insert(hlist, NULL, &entry->list_node);
return ret;
}

View File

@ -1,7 +1,7 @@
#include "lb/llist.h"
static void
llist_node_init(struct llist_node *node)
llist_node_init(struct dlist_node *node)
{
node->next = NULL;
node->prev = NULL;
@ -23,52 +23,11 @@ lb_llist_size(struct llist *list)
return list->size;
}
void
lb_llist_push_front(struct llist *list, struct llist_node *node)
lb_llist_insert(struct llist *list, struct dlist_node *cur_node, struct dlist_node *new_node)
{
llist_node_init(node);
lb_llist_insert_by_ref(list, NULL, node);
}
void
lb_llist_push_back(struct llist *list, struct llist_node *node)
{
llist_node_init(node);
lb_llist_insert_by_ref(list, list->tail, node);
}
struct llist_node *
lb_llist_pop_front(struct llist *list)
{
struct llist_node *ret;
ret = list->head;
lb_llist_remove_by_ref(list, list->head);
return ret;
}
struct llist_node *
lb_llist_pop_back(struct llist *list)
{
struct llist_node *ret;
ret = list->tail;
lb_llist_remove_by_ref(list, list->tail);
return ret;
}
void
lb_llist_insert_by_ref(struct llist *list, struct llist_node *cur_node, struct llist_node *new_node)
{
struct llist_node *left_node;
struct llist_node *right_node;
struct dlist_node *left_node;
struct dlist_node *right_node;
if (list == NULL || new_node == NULL)
{
@ -129,52 +88,13 @@ lb_llist_insert_by_ref(struct llist *list, struct llist_node *cur_node, struct l
list->size++;
}
void
lb_llist_insert_by_idx(struct llist *list, uint32 index, struct llist_node *node)
{
struct llist_node *prev_node;
prev_node = lb_llist_get(list, index - 1);
llist_node_init(node);
if (prev_node == NULL)
{
if (index == 0)
{
lb_llist_insert_by_ref(list, NULL, node);
}
}
else
{
lb_llist_insert_by_ref(list, prev_node, node);
}
}
struct llist_node *
lb_llist_remove_by_idx(struct llist *list, uint32 index)
{
struct llist_node *cur_node;
cur_node = lb_llist_get(list, index);
if (cur_node == NULL)
{
return NULL;
}
return lb_llist_remove_by_ref(list, cur_node);
}
/**
* returns the next node
*/
struct llist_node *
lb_llist_remove_by_ref(struct llist *list, struct llist_node *node)
struct dlist_node *
lb_llist_remove(struct llist *list, struct dlist_node *node)
{
struct llist_node *ret;
struct dlist_node *ret;
/*
* Adjust the left and treenode node
@ -207,42 +127,28 @@ lb_llist_remove_by_ref(struct llist *list, struct llist_node *node)
}
struct llist_node *
lb_llist_get(struct llist *list, uint32 index)
{
if (list->head == NULL)
{
return NULL;
}
struct llist_node *cur_node = list->head;
while (index-- && (cur_node = cur_node->next) != NULL)
{}
return cur_node;
}
struct llist_node *
lb_llist_next(struct llist_node *node)
struct dlist_node *
lb_llist_next(struct dlist_node *node)
{
return node->next;
}
struct llist_node *
lb_llist_prev(struct llist_node *node)
struct dlist_node *
lb_llist_prev(struct dlist_node *node)
{
return node->prev;
}
struct llist_node *
struct dlist_node *
lb_llist_first(struct llist *list)
{
return list->head;
}
struct llist_node *
struct dlist_node *
lb_llist_last(struct llist *list)
{
return list->tail;

104
kernel/lb/ssalloc.c Normal file
View File

@ -0,0 +1,104 @@
#include "cdef.h"
#include "mlayout.h"
#include "lb/llist.h"
/**
* Simplified Slab Allocator
*/
#define LARGE_THRESHOLD (8)
struct ssalloc_page_desc
{
struct dlist_node node;
uint32 used_obj_num;
uint8 free_list[0]; /* free list inside each slab */
};
struct ssalloc_obj_desc
{
struct llist free_list;
struct llist full_list;
struct llist empty_list;
usize obj_size;
uint32 align;
};
struct ssalloc_desc
{
uint32 chunk_size;
void* malloc_chunk(void); // allocate a chunk
void* free_chunk(void); // free a chunk
};
static void* scalloc_large(struct ssalloc_desc* desc, struct ssalloc_obj_desc* obj_desc)
{
}
static void scfree_large(struct ssalloc_desc* desc, struct ssalloc_obj_desc* obj_desc, void* addr)
{
}
static void* scalloc_small(struct ssalloc_desc* desc, struct ssalloc_obj_desc* obj_desc)
{
// check the current free list first
if (lb_dlist_size(&obj_desc->free_list) > 0)
{
// if it exists then we grab something from the list
struct llist_node* node = lb_dlist_first(node);
}
else
{
}
}
static void scfree_small(struct ssalloc_desc* desc, struct ssalloc_obj_desc* obj_desc, void* addr)
{
}
void ssalloc_desc_init(struct ssalloc_desc* desc)
{
}
void ssalloc_obj_desc_init(struct ssalloc_obj_desc* obj_desc, usize obj_size, uint32 align)
{
obj_desc->obj_size = obj_size;
obj_desc->align = align;
lb_dlist_init(&obj_desc->empty_list);
lb_dlist_init(&obj_desc->full_list);
lb_dlist_init(&obj_desc->free_list);
}
void* scalloc(struct ssalloc_desc* desc, struct ssalloc_obj_desc* obj_desc)
{
void* ret = NULL;
if(obj_desc->obj_size < desc->chunk_size / LARGE_THRESHOLD)
{
ret = scalloc_small(desc, obj_desc);
}
else
{
// large objects
ret = scalloc_large(desc, obj_desc);
}
return ret;
}
void scfree(struct ssalloc_desc* desc, struct ssalloc_obj_desc* obj_desc, void* address)
{
if(obj_desc->obj_size < desc->chunk_size)
{
scfree_small(desc, obj_desc, address);
}
else
{
// large objects
scfree_large(desc, obj_desc, address);
}
}

View File

@ -1,6 +1,7 @@
include $(MK)/prologue.mk
SRC_$(d) := $(d)/pmm.c
SRC_$(d) :=
#$(d)/pmm.c
include $(MK)/stdrules.mk

View File

@ -8,13 +8,13 @@
struct phys_page_desc
{
struct llist_node free_list_node;
struct dlist_node free_list_node;
struct atree_node tree_node;
uintptr base;
int32 attr;
};
static struct atree active_tree;
static struct a_tree active_tree;
static struct llist free_list;
static struct rww_lock lock;
@ -109,9 +109,9 @@ k_status mm_alloc_page(uintptr *out)
irql = ke_raise_irql(IRQL_HIGH);
ke_rww_w_lock(&lock);
struct llist_node *node = NULL;
struct dlist_node *node = NULL;
struct phys_page_desc *page_info = NULL;
node = lb_llist_pop_front(&free_list);
//node = lb_dlist_pop_front(&free_list);
if (node != NULL)
{
page_info = OBTAIN_STRUCT_ADDR(node,
@ -186,7 +186,7 @@ k_status mm_free_page(uintptr base)
if (node != NULL)
{
page_info = OBTAIN_STRUCT_ADDR(node, struct phys_page_desc, tree_node);
lb_llist_push_back(&free_list, &page_info->free_list_node);
//lb_llist_push_back(&free_list, &page_info->free_list_node);
}
else
{

View File

@ -7,7 +7,7 @@
#define K_IDENT_BASE (0x80000000ul)
static struct atree ident_tree;
static struct a_tree ident_tree;
static struct spin_lock ident_tree_lock;
static uint32 ident_base;

View File

@ -16,7 +16,6 @@ $(OUT)/$(d)/%.o: MOD:=$(MOD)
$(OBJ_$(d)): $(OUT)/$(d)/%.o: $(d)/%.c
$(MKDIR)
$(COMP)
$(GDEP)
$(OUT)/$(d)/%.a: MOD:=$(MOD)
@ -27,7 +26,6 @@ $(OBJAS_$(d)): $(OUT)/$(d)/%.a: $(d)/%.asm
$(OBJIN_$(d)): $(OUT)/$(d)/%: $(d)/%.in
$(MKDIR)
$(PREP)
$(GDEP)
# append all OBJECTS to OBJ
OBJ := $(OBJ) $(OBJ_$(d)) $(OBJAS_$(d))