1. Refactored the file structure.
2. Refactored all include directories. 3. The Integrated linked_list and salloc are working. Need to write test for AVL tree and salloc.
This commit is contained in:
parent
cd5d08fa1d
commit
44602ecf29
|
@ -1,6 +1,23 @@
|
|||
cmake_minimum_required(VERSION 2.8.4)
|
||||
project(Workspace)
|
||||
|
||||
MACRO(HEADER_DIRECTORIES return_list)
|
||||
FILE(GLOB_RECURSE new_list ./x64/*.h)
|
||||
SET(dir_list "")
|
||||
FOREACH(file_path ${new_list})
|
||||
GET_FILENAME_COMPONENT(dir_path ${file_path} PATH)
|
||||
SET(dir_list ${dir_list} ${dir_path})
|
||||
ENDFOREACH()
|
||||
LIST(REMOVE_DUPLICATES dir_list)
|
||||
SET(${return_list} ${dir_list})
|
||||
ENDMACRO()
|
||||
|
||||
HEADER_DIRECTORIES(header_dirs)
|
||||
|
||||
include_directories(${header_dirs})
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
||||
file(GLOB_RECURSE SOURCE_FILES ./x64/src/c/*)
|
||||
add_executable(Workspace ${SOURCE_FILES} x64/src/c/common/lib/alloc/salloc/salloc.h)
|
||||
|
||||
file(GLOB_RECURSE SOURCE_FILES ./x64/*.h ./x64/*.c)
|
||||
|
||||
add_executable(Workspace ${SOURCE_FILES} x64/src/c/common/lib/salloc/inc/salloc.h)
|
|
@ -1,84 +0,0 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <time.h>
|
||||
#include "avl_tree.h"
|
||||
typedef struct __attribute__ ((packed))
|
||||
{
|
||||
avl_tree_node node;
|
||||
int val;
|
||||
} int_node;
|
||||
|
||||
int compare(void* a, void* b)
|
||||
{
|
||||
int_node* aa = (int_node*)a;
|
||||
int_node* bb = (int_node*)b;
|
||||
if(aa->val > bb->val)
|
||||
return 1;
|
||||
else if(aa->val < bb->val)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void in_order_print(avl_tree_node *tree)
|
||||
{
|
||||
if (tree == NULL)
|
||||
return;
|
||||
avl_tree_node* node = avl_tree_node_largest(tree);
|
||||
while(node != NULL)
|
||||
{
|
||||
printf("%d ", ((int_node*)node)->val);
|
||||
node = avl_tree_node_prev(node);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
int_node* create_int_node(int val)
|
||||
{
|
||||
int_node* node = (int_node*)malloc(sizeof(int_node));
|
||||
avl_tree_node_init(&node->node);
|
||||
node->val = val;
|
||||
return node;
|
||||
}
|
||||
|
||||
int main (void)
|
||||
{
|
||||
int_node* val[1000];
|
||||
srand((unsigned int)time(NULL));
|
||||
avl_tree* avlTree = (avl_tree*)malloc(sizeof(avl_tree));
|
||||
avl_tree_init(avlTree);
|
||||
//test INSERT general
|
||||
int i = 0;
|
||||
for(i = 0; i < 1000; i++)
|
||||
{
|
||||
val[i] = create_int_node(rand()%10000);
|
||||
avl_tree_insert(avlTree,(avl_tree_node*)val[i],compare);
|
||||
assert(avl_tree_node_test(avlTree->root,compare));
|
||||
}
|
||||
//test Delete general
|
||||
for(i = 0; i < 1000; i++)
|
||||
{
|
||||
avl_tree_delete(avlTree,val[i],compare);
|
||||
assert(avl_tree_node_test(avlTree->root,compare));
|
||||
free(val[i]);
|
||||
}
|
||||
|
||||
//test delete visualized
|
||||
for(i = 0; i < 20; i++)
|
||||
{
|
||||
val[i] = create_int_node(rand()%2000);
|
||||
avl_tree_insert(avlTree,(avl_tree_node*)val[i],compare);
|
||||
assert(avl_tree_node_test(avlTree->root,compare));
|
||||
}
|
||||
in_order_print(avlTree->root);
|
||||
for(i = 0; i < 20; i++)
|
||||
{
|
||||
avl_tree_delete(avlTree,(avl_tree_node*)val[i],compare);
|
||||
printf("\nDeleting: %d\n",val[i]->val);
|
||||
in_order_print(avlTree->root);
|
||||
assert(avl_tree_node_test(avlTree->root,compare));
|
||||
free(val[i]);
|
||||
}
|
||||
free(avlTree);
|
||||
return 0;
|
||||
}
|
10
makefile
10
makefile
|
@ -7,7 +7,7 @@ LD = ld
|
|||
#Recursive Wildcard
|
||||
rwildcard=$(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d))
|
||||
rdircard=$(sort $(dir $(call rwildcard,$1,*)))
|
||||
|
||||
rdircardex=$(sort $(dir $(call rwildcard,$1,$2)))
|
||||
#x86 vars
|
||||
|
||||
C_SRC_PATH_32 := x86/src/c
|
||||
|
@ -24,11 +24,17 @@ LD_SCRIPT_32 := build/link32.ld
|
|||
|
||||
#x64 vars
|
||||
|
||||
#64 header files
|
||||
|
||||
HEADER_DIRS_64 := $(call rdircardex, *,*.h)
|
||||
|
||||
HEADER_DIRS_OPTION_64 := $(addprefix -I, $(HEADER_DIRS_64))
|
||||
|
||||
C_SRC_PATH_64 := x64/src/c
|
||||
|
||||
ASM_SRC_PATH_64 := x64/src/asm
|
||||
|
||||
C_FLAGS_64 := -m64 -std=c11 -g -c -fno-stack-protector -fno-builtin -mno-red-zone -mno-mmx -mno-sse -mno-sse2 -masm=intel -Wall -Wextra
|
||||
C_FLAGS_64 := -m64 -std=c11 -g -c $(HEADER_DIRS_OPTION_64) -fno-stack-protector -fno-builtin -mno-red-zone -mno-mmx -mno-sse -mno-sse2 -masm=intel -Wall -Wextra
|
||||
|
||||
ASM_FLAGS_64 := -f elf64 -I $(ASM_SRC_PATH_64)/
|
||||
|
||||
|
|
|
@ -23,10 +23,6 @@ dd 0
|
|||
dd entry_32
|
||||
MULTIBOOT_HEADER_SIZE equ ($ - MULTIBOOT_HEADER)
|
||||
|
||||
align 4096 ;4k alignment
|
||||
times 4096 db 0
|
||||
KERNEL_STACK:
|
||||
|
||||
align 4096 ;4k alignment
|
||||
; temporary page table
|
||||
PML4_BASE:
|
||||
|
@ -191,3 +187,7 @@ hlt
|
|||
BOCHS_MAGIC_BREAKPOINT:
|
||||
xchg bx,bx
|
||||
ret
|
||||
|
||||
align 4096 ;4k alignment
|
||||
times 8192 db 0
|
||||
KERNEL_STACK:
|
|
@ -0,0 +1,11 @@
|
|||
#ifndef _K_DEF_H_
|
||||
#define _K_DEF_H_
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdarg.h>
|
||||
#include "k_type.h"
|
||||
|
||||
#define SAPI __attribute__((sysv_abi))
|
||||
#define UAPI __attribute__((sysv_abi))
|
||||
|
||||
#endif
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef _SYS_INFO_H_
|
||||
#define _SYS_INFO_H_
|
||||
#include "type.h"
|
||||
#include "../lib/list/linked_list/linked_list.h"
|
||||
#ifndef _K_SYS_INFO_H_
|
||||
#define _K_SYS_INFO_H_
|
||||
#include "k_type.h"
|
||||
#include "linked_list.h"
|
||||
|
||||
#define MEMORY_OCCUPIED 0
|
||||
#define MEMORY_AVAILABLE 1
|
|
@ -0,0 +1,5 @@
|
|||
#ifndef _K_TYPE_H_
|
||||
#define _K_TYPE_H_
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#endif
|
|
@ -1,12 +1,11 @@
|
|||
#include "../../../sys/kdef.h"
|
||||
#include "avl_tree.h"
|
||||
|
||||
static int SAPI _avl_tree_node_get_height(avl_tree_entry_t *node)
|
||||
static inline int32_t SAPI _avl_tree_node_get_height(avl_tree_entry_t *node)
|
||||
{
|
||||
return node == NULL ? -1 : node->height;
|
||||
}
|
||||
|
||||
static int SAPI _avl_tree_node_get_balance_factor(avl_tree_entry_t *node)
|
||||
static inline int32_t SAPI _avl_tree_node_get_balance_factor(avl_tree_entry_t *node)
|
||||
{
|
||||
if (node == NULL)
|
||||
return 0;
|
||||
|
@ -49,11 +48,11 @@ static avl_tree_entry_t *SAPI _avl_tree_node_left_rotate(avl_tree_entry_t *root)
|
|||
|
||||
static avl_tree_entry_t *SAPI _avl_tree_node_balance(avl_tree_entry_t *node)
|
||||
{
|
||||
const int bf = _avl_tree_node_get_balance_factor(node);
|
||||
const int32_t bf = _avl_tree_node_get_balance_factor(node);
|
||||
|
||||
if (bf > 1)
|
||||
{
|
||||
const int left_bf = _avl_tree_node_get_balance_factor(node->left);
|
||||
const int32_t left_bf = _avl_tree_node_get_balance_factor(node->left);
|
||||
if (left_bf >= 0)
|
||||
//left left
|
||||
return _avl_tree_node_right_rotate(node);
|
||||
|
@ -66,7 +65,7 @@ static avl_tree_entry_t *SAPI _avl_tree_node_balance(avl_tree_entry_t *node)
|
|||
}
|
||||
else if (bf < -1)
|
||||
{
|
||||
const int right_bf = _avl_tree_node_get_balance_factor(node->right);
|
||||
const int32_t right_bf = _avl_tree_node_get_balance_factor(node->right);
|
||||
if (right_bf <= 0)
|
||||
{
|
||||
// right right
|
||||
|
@ -84,9 +83,9 @@ static avl_tree_entry_t *SAPI _avl_tree_node_balance(avl_tree_entry_t *node)
|
|||
|
||||
}
|
||||
|
||||
static avl_tree_entry_t *SAPI _avl_tree_node_insert(avl_tree_entry_t *root, avl_tree_entry_t *node, int(*compare)(avl_tree_entry_t *, avl_tree_entry_t *), avl_tree_entry_t *parent)
|
||||
static avl_tree_entry_t *SAPI _avl_tree_node_insert(avl_tree_entry_t *root, avl_tree_entry_t *node, int32_t(*compare)(avl_tree_entry_t *, avl_tree_entry_t *), avl_tree_entry_t *parent)
|
||||
{
|
||||
if (node == NULL)
|
||||
if (node == NULL || compare == NULL)
|
||||
return root;
|
||||
if (root == NULL)
|
||||
{
|
||||
|
@ -94,7 +93,7 @@ static avl_tree_entry_t *SAPI _avl_tree_node_insert(avl_tree_entry_t *root, avl_
|
|||
return node;
|
||||
}
|
||||
|
||||
const int comp = compare(root, node);
|
||||
const int32_t comp = compare(root, node);
|
||||
if (comp < 0)
|
||||
root->right = _avl_tree_node_insert(root->right, node, compare, root);
|
||||
else if (comp == 0)
|
||||
|
@ -223,18 +222,18 @@ static void _avl_tree_swap_nodes(avl_tree_entry_t *node1, avl_tree_entry_t *node
|
|||
}
|
||||
|
||||
//swap height
|
||||
int height = node1->height;
|
||||
int32_t height = node1->height;
|
||||
node1->height = node2->height;
|
||||
node2->height = height;
|
||||
return;
|
||||
}
|
||||
|
||||
static avl_tree_entry_t *SAPI _avl_tree_node_delete(avl_tree_entry_t *root, avl_tree_entry_t *node,
|
||||
int (*compare)(avl_tree_entry_t *, avl_tree_entry_t *))
|
||||
int32_t (*compare)(avl_tree_entry_t *, avl_tree_entry_t *))
|
||||
{
|
||||
if (root == NULL || node == NULL)
|
||||
if (root == NULL || node == NULL || compare == NULL)
|
||||
return root;
|
||||
const int comp = compare(root, node);
|
||||
const int32_t comp = compare(root, node);
|
||||
if (comp < 0)
|
||||
root->right = _avl_tree_node_delete(root->right, node, compare);
|
||||
else if(comp > 0)
|
||||
|
@ -280,11 +279,11 @@ static avl_tree_entry_t *SAPI _avl_tree_node_delete(avl_tree_entry_t *root, avl_
|
|||
}
|
||||
|
||||
static avl_tree_entry_t *SAPI _avl_tree_node_search(avl_tree_entry_t *root, avl_tree_entry_t *node,
|
||||
int(*compare)(avl_tree_entry_t *, avl_tree_entry_t *))
|
||||
int32_t(*compare)(avl_tree_entry_t *, avl_tree_entry_t *))
|
||||
{
|
||||
if(root == NULL)
|
||||
if(root == NULL || compare == NULL)
|
||||
return NULL;
|
||||
const int comp = compare(root, node);
|
||||
const int32_t comp = compare(root, node);
|
||||
if (comp < 0)
|
||||
return _avl_tree_node_search(root->right, node, compare);
|
||||
else if (comp == 0)
|
||||
|
@ -301,13 +300,12 @@ static void SAPI _avl_tree_node_init(avl_tree_entry_t * it)
|
|||
it->left = NULL;
|
||||
it->right = NULL;
|
||||
it->parent = NULL;
|
||||
linked_list_init(&it->element_list);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
avl_tree_entry_t *SAPI _avl_tree_smallest(avl_tree_t *tree)
|
||||
avl_tree_entry_t *SAPI avl_tree_smallest(avl_tree_t *tree)
|
||||
{
|
||||
if (tree == NULL)
|
||||
return NULL;
|
||||
|
@ -380,32 +378,26 @@ avl_tree_entry_t *SAPI avl_tree_smaller(avl_tree_entry_t *it)
|
|||
}
|
||||
}
|
||||
|
||||
avl_tree_entry_t * SAPI avl_tree_search(avl_tree_t *tree, avl_tree_entry_t * node, int (*compare)(avl_tree_entry_t *, avl_tree_entry_t *))
|
||||
avl_tree_entry_t * SAPI avl_tree_search(avl_tree_t *tree, avl_tree_entry_t * node)
|
||||
{
|
||||
return _avl_tree_node_search(tree->root, node, compare);
|
||||
return _avl_tree_node_search(tree->root, node, tree->compare);
|
||||
}
|
||||
|
||||
|
||||
void SAPI avl_tree_insert(avl_tree_t *tree, void *data, int (*compare)(avl_tree_entry_t *, avl_tree_entry_t *))
|
||||
void SAPI avl_tree_insert(avl_tree_t *tree, avl_tree_entry_t* data)
|
||||
{
|
||||
if(tree != NULL && data != NULL && compare != NULL)
|
||||
if(tree != NULL && data != NULL)
|
||||
{
|
||||
if(avl_tree_search(tree, data, compare) == NULL)
|
||||
{
|
||||
tree->root = _avl_tree_node_insert(tree->root, data, compare, NULL);
|
||||
}
|
||||
tree->root = _avl_tree_node_insert(tree->root, data, tree->compare, NULL);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void SAPI avl_tree_delete(avl_tree_t *tree, void *data, int (*compare)(avl_tree_entry_t *, avl_tree_entry_t *))
|
||||
void SAPI avl_tree_delete(avl_tree_t *tree, avl_tree_entry_t *data)
|
||||
{
|
||||
if(tree != NULL && data != NULL && compare != NULL)
|
||||
if(tree != NULL && data != NULL)
|
||||
{
|
||||
if(avl_tree_search(tree, data, compare) != NULL)
|
||||
{
|
||||
tree->root = _avl_tree_node_delete(tree->root, data, compare);
|
||||
}
|
||||
tree->root = _avl_tree_node_delete(tree->root, data, tree->compare);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -426,44 +418,12 @@ int32_t SAPI avl_tree_size(avl_tree_t *tree)
|
|||
return size;
|
||||
}
|
||||
|
||||
void SAPI avl_tree_init(avl_tree_t * tree)
|
||||
void SAPI avl_tree_init(avl_tree_t * tree, int32_t (*compare)(avl_tree_entry_t*, avl_tree_entry_t*))
|
||||
{
|
||||
if(tree != NULL)
|
||||
{
|
||||
tree->root = NULL;
|
||||
tree->compare = compare;
|
||||
}
|
||||
return;
|
||||
}
|
||||
// TESTS
|
||||
|
||||
static int SAPI avl_tree_node_calculate_height(avl_tree_entry_t *tree)
|
||||
{
|
||||
if (tree == NULL)
|
||||
return -1;
|
||||
return max_32(avl_tree_node_calculate_height(tree->left), avl_tree_node_calculate_height(tree->right)) + 1;
|
||||
}
|
||||
|
||||
static int SAPI avl_tree_node_test(avl_tree_entry_t *tree, int (*compare)(void*, void*))
|
||||
{
|
||||
if (tree == NULL)
|
||||
return 1;
|
||||
if (_avl_tree_node_get_balance_factor(tree) < -1 || _avl_tree_node_get_balance_factor(tree) > 1 || avl_tree_node_calculate_height(tree) != tree->height)
|
||||
return 0;
|
||||
if(tree->left != NULL)
|
||||
{
|
||||
if(tree->left->parent != tree)
|
||||
return 0;
|
||||
}
|
||||
if(tree->right != NULL)
|
||||
{
|
||||
if(tree->right->parent != tree)
|
||||
return 0;
|
||||
}
|
||||
if(compare != NULL)
|
||||
{
|
||||
if((tree->right != NULL && compare(tree,tree->right) > 0) || (tree->left != NULL && compare(tree,tree->left) < 0))
|
||||
return 0;
|
||||
}
|
||||
return avl_tree_node_test(tree->left,compare) && avl_tree_node_test(tree->right,compare);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,31 +1,30 @@
|
|||
#ifndef _AVL_TREE_H_
|
||||
#define _AVL_TREE_H_
|
||||
#include "../../../sys/kdef.h"
|
||||
#include "../../../sys/sys_info.h"
|
||||
#include "k_def.h"
|
||||
#include "std_lib.h"
|
||||
|
||||
typedef struct _avl_tree_entry_t
|
||||
{
|
||||
struct _avl_tree_entry_t * left;
|
||||
struct _avl_tree_entry_t * right;
|
||||
struct _avl_tree_entry_t * parent;
|
||||
linked_list_t element_list;
|
||||
linked_list_entry_t list_entry;
|
||||
int height;
|
||||
} avl_tree_entry_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
avl_tree_entry_t * root;
|
||||
int32_t (*compare)(avl_tree_entry_t *, avl_tree_entry_t *);
|
||||
} avl_tree_t;
|
||||
|
||||
|
||||
avl_tree_entry_t * SAPI avl_tree_search(avl_tree_t *tree, avl_tree_entry_t * node, int (*compare)(avl_tree_entry_t *, avl_tree_entry_t *));
|
||||
avl_tree_entry_t * SAPI avl_tree_search(avl_tree_t *tree, avl_tree_entry_t * entry);
|
||||
|
||||
void SAPI avl_tree_insert(avl_tree_t *tree, void *data, int (*compare)(avl_tree_entry_t *, avl_tree_entry_t *));
|
||||
void SAPI avl_tree_insert(avl_tree_t *tree, avl_tree_entry_t *entry);
|
||||
|
||||
void SAPI avl_tree_delete(avl_tree_t *tree, void *data, int (*compare)(avl_tree_entry_t *, avl_tree_entry_t *));
|
||||
void SAPI avl_tree_delete(avl_tree_t *tree, avl_tree_entry_t *entry);
|
||||
|
||||
void SAPI avl_tree_init(avl_tree_t * tree);
|
||||
void SAPI avl_tree_init(avl_tree_t * tree, int32_t (*compare)(avl_tree_entry_t *, avl_tree_entry_t *));
|
||||
|
||||
avl_tree_entry_t* SAPI avl_tree_largest(avl_tree_t *tree);
|
||||
|
||||
|
@ -35,4 +34,4 @@ avl_tree_entry_t* SAPI avl_tree_larger(avl_tree_entry_t* entry);
|
|||
|
||||
avl_tree_entry_t* SAPI avl_tree_smaller(avl_tree_entry_t* entry);
|
||||
|
||||
#endif
|
||||
#endif
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef _LINKED_LIST_H_
|
||||
#define _LINKED_LIST_H_
|
||||
|
||||
#include "../../../sys/kdef.h"
|
||||
#include "k_def.h"
|
||||
|
||||
typedef struct _linked_list_entry_t
|
||||
{
|
|
@ -1,4 +1,4 @@
|
|||
#include "linked_list.h"
|
||||
#include "inc/linked_list.h"
|
||||
|
||||
static void SAPI _init_linked_list_node(linked_list_entry_t *node)
|
||||
{
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef _SALLOC_H_
|
||||
#define _SALLOC_H_
|
||||
|
||||
#include "../../../sys/kdef.h"
|
||||
#include "k_def.h"
|
||||
|
||||
void salloc_init(void *base, uint32_t size);
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
#include "../../../sys/kdef.h"
|
||||
#include "../../../sys/bit_ops.h"
|
||||
#include "k_def.h"
|
||||
#include "bit_ops.h"
|
||||
|
||||
typedef union {
|
||||
uint32_t size;
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef _BIT_OPERATION_H_
|
||||
#define _BIT_OPERATION_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include "k_type.h"
|
||||
|
||||
static inline uint64_t bit_mask_64(uint32_t bit)
|
||||
{
|
|
@ -1,13 +1,18 @@
|
|||
#ifndef _KDEF_H_
|
||||
#define _KDEF_H_
|
||||
#ifndef _STD_LIB_H_
|
||||
#define _STD_LIB_H_
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include "type.h"
|
||||
#include "k_def.h"
|
||||
#include "k_type.h"
|
||||
|
||||
#define SAPI __attribute__((sysv_abi))
|
||||
#define UAPI __attribute__((sysv_abi))
|
||||
uint64_t SAPI str_len(char const *str);
|
||||
|
||||
uint64_t SAPI str_cmp(char const *str1, char const *str2);
|
||||
|
||||
void SAPI mem_cpy(void *src, void *dst, uint64_t size);
|
||||
|
||||
void SAPI mem_move(void *src, void *dst, uint64_t size);
|
||||
|
||||
void SAPI mem_set(void *src, int8_t const val, uint64_t size);
|
||||
|
||||
static inline uint64_t align_down(uint64_t val, uint64_t alignment)
|
||||
{
|
||||
|
@ -44,11 +49,6 @@ static inline int32_t min_32(int32_t a, int32_t b)
|
|||
return (a) < (b) ? a : b;
|
||||
}
|
||||
|
||||
static inline uint32_t seg_selector(uint32_t index, uint32_t rpl)
|
||||
{
|
||||
return (index << 3) + rpl;
|
||||
}
|
||||
|
||||
#define OBTAIN_STRUCT_ADDR(member_addr, member_name, struct_name) ((struct_name*)((void*)(member_addr)-(void*)(&(((struct_name*)0)->member_name))))
|
||||
|
||||
#endif
|
||||
#endif
|
|
@ -1,8 +1,8 @@
|
|||
#include "../../sys/type.h"
|
||||
#include "../../sys/kdef.h"
|
||||
#include "mem.h"
|
||||
#include "k_type.h"
|
||||
#include "k_def.h"
|
||||
#include "std_lib.h"
|
||||
|
||||
void SAPI mem_copy(void *src, void *dst, uint64_t size)
|
||||
void SAPI mem_cpy(void *src, void *dst, uint64_t size)
|
||||
{
|
||||
if (src == NULL || dst == NULL)
|
||||
return;
|
||||
|
@ -28,7 +28,7 @@ void SAPI mem_move(void *src, void *dst, uint64_t size)
|
|||
return;
|
||||
if (src >= dst)
|
||||
{
|
||||
return mem_copy(src, dst, size);
|
||||
return mem_cpy(src, dst, size);
|
||||
}
|
||||
src += size;
|
||||
dst += size;
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
#ifndef _HAL_MEM_H_
|
||||
#define _HAL_MEM_H_
|
||||
|
||||
#include "../../sys/type.h"
|
||||
#include "../../sys/kdef.h"
|
||||
|
||||
void SAPI mem_copy(void *src, void *dst, uint64_t size);
|
||||
|
||||
void SAPI mem_move(void *src, void *dst, uint64_t size);
|
||||
|
||||
void SAPI mem_set(void *src, int8_t const val, uint64_t size);
|
||||
|
||||
#endif
|
|
@ -1,4 +1,4 @@
|
|||
#include "str.h"
|
||||
#include "std_lib.h"
|
||||
|
||||
uint64_t SAPI str_len(char const *str)
|
||||
{
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
#ifndef _STR_H_
|
||||
#define _STR_H_
|
||||
|
||||
#include "../../sys/kdef.h"
|
||||
#include "../../sys/type.h"
|
||||
|
||||
uint64_t SAPI str_len(char const *str);
|
||||
uint64_t SAPI str_cmp(char const *str1, char const *str2);
|
||||
|
||||
#endif
|
|
@ -1,4 +0,0 @@
|
|||
#ifndef _TYPE_H_
|
||||
#define _TYPE_H_
|
||||
#include <stdint.h>
|
||||
#endif
|
|
@ -1,16 +1,18 @@
|
|||
#include "hal.h"
|
||||
#include "print.h"
|
||||
#include "mem.h"
|
||||
#include "io.h"
|
||||
#include "var.h"
|
||||
#include "../common/lib/std/str.h"
|
||||
#include "../common/lib/std/mem.h"
|
||||
#include "../common/sys/sys_info.h"
|
||||
#include "hal_print.h"
|
||||
#include "hal_mem.h"
|
||||
#include "hal_io.h"
|
||||
#include "hal_var.h"
|
||||
#include "std_lib.h"
|
||||
|
||||
boot_info_t *SAPI hal_init(multiboot_info_t *m_info)
|
||||
{
|
||||
if (m_info == NULL)
|
||||
return NULL;
|
||||
|
||||
// set up kernel heap;
|
||||
hal_alloc_init();
|
||||
|
||||
boot_info_t *boot_info = (boot_info_t *) hal_alloc(sizeof(boot_info_t));
|
||||
text_pos = get_pos(0, 0);
|
||||
|
||||
|
@ -46,9 +48,6 @@ boot_info_t *SAPI hal_init(multiboot_info_t *m_info)
|
|||
g_idt_ptr.limit = 21 * 16 - 1;
|
||||
hal_flush_idt(&g_idt_ptr);
|
||||
|
||||
// set up kernel heap;
|
||||
hal_alloc_init();
|
||||
|
||||
mem_set(boot_info, 0, sizeof(boot_info_t));
|
||||
// obtain boot information
|
||||
// memory info
|
||||
|
@ -68,7 +67,7 @@ boot_info_t *SAPI hal_init(multiboot_info_t *m_info)
|
|||
uint64_t mem_map_size = m_info->mmap_length / sizeof(multiboot_memory_map_t);
|
||||
for (uint64_t i = 0; i < mem_map_size; i++)
|
||||
{
|
||||
hal_printf("\n==Base: 0x%X, Length: %u, Type: %s==", (mem_map + i)->addr, (mem_map + i)->len,
|
||||
hal_printf("==Base: 0x%X, Length: %u, Type: %s==\n", (mem_map + i)->addr, (mem_map + i)->len,
|
||||
(mem_map + i)->type == MULTIBOOT_MEMORY_AVAILABLE ? "AVL" : "RSV");
|
||||
if ((mem_map + i)->type == MULTIBOOT_MEMORY_AVAILABLE)
|
||||
{
|
||||
|
@ -151,8 +150,8 @@ boot_info_t *SAPI hal_init(multiboot_info_t *m_info)
|
|||
each_module->size = (mods_list + i)->mod_end - (mods_list + i)->mod_start;
|
||||
each_module->name = (char *) hal_alloc((size_t) str_len((char *) (uint64_t)(mods_list + i)->cmdline) + 1);
|
||||
hal_assert(each_module->name != NULL, "Unable to allocate memory for module name string.");
|
||||
mem_copy((void *)(uint64_t)(mods_list + i)->cmdline, each_module->name,
|
||||
str_len((char *)(uint64_t)(mods_list + i)->cmdline) + 1);
|
||||
mem_cpy((void *) (uint64_t) (mods_list + i)->cmdline, each_module->name,
|
||||
str_len((char *) (uint64_t) (mods_list + i)->cmdline) + 1);
|
||||
linked_list_push_back(boot_info->module_info->module_list, &each_module->list_node);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "io.h"
|
||||
#include "print.h"
|
||||
#include "hal_io.h"
|
||||
#include "hal_print.h"
|
||||
#include "hal_mem.h"
|
||||
|
||||
void hal_interrupt_handler_dummy(void)
|
||||
{
|
||||
|
@ -49,4 +50,4 @@ void SAPI hal_assert(int64_t expression,
|
|||
hal_halt_cpu();
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
#include "../common/sys/kdef.h"
|
||||
#include "../common/sys/type.h"
|
||||
#include "mem.h"
|
||||
#include "../common/lib/alloc/salloc/salloc.h"
|
||||
#include "k_def.h"
|
||||
#include "k_type.h"
|
||||
#include "hal_mem.h"
|
||||
#include "salloc.h"
|
||||
|
||||
#define KERNEL_HEAP_SIZE 4096
|
||||
|
||||
|
@ -97,11 +97,12 @@ void* SAPI hal_alloc(uint32_t size)
|
|||
|
||||
void SAPI hal_free(void *ptr)
|
||||
{
|
||||
return sfree(kernel_heap, ptr);
|
||||
sfree(kernel_heap, ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
void SAPI hal_alloc_init()
|
||||
{
|
||||
salloc_init(kernel_heap, KERNEL_HEAP_SIZE);
|
||||
return;
|
||||
}
|
||||
}
|
|
@ -1,8 +1,7 @@
|
|||
#include "../common/sys/kdef.h"
|
||||
#include "../common/sys/type.h"
|
||||
#include "../common/lib/std/mem.h"
|
||||
#include "print.h"
|
||||
#include "var.h"
|
||||
#include "k_def.h"
|
||||
#include "std_lib.h"
|
||||
#include "hal_print.h"
|
||||
#include "hal_var.h"
|
||||
|
||||
void SAPI _hal_print_scroll()
|
||||
{
|
|
@ -1,5 +1,4 @@
|
|||
#include <stdint.h>
|
||||
#include "var.h"
|
||||
#include "hal_var.h"
|
||||
|
||||
uint8_t g_gdt[8*9];
|
||||
uint8_t g_idt[21*16];
|
|
@ -1,9 +1,9 @@
|
|||
#ifndef _HAL_HAL_H_
|
||||
#define _HAL_HAL_H_
|
||||
#include "../common/sys/kdef.h"
|
||||
#include "../common/sys/type.h"
|
||||
#include "multiboot.h"
|
||||
#include "../common/sys/sys_info.h"
|
||||
#ifndef _HAL_H_
|
||||
#define _HAL_H_
|
||||
#include "k_def.h"
|
||||
#include "k_type.h"
|
||||
#include "hal_multiboot.h"
|
||||
#include "k_sys_info.h"
|
||||
|
||||
// concurrency
|
||||
void SAPI hal_spin_lock(uint64_t * lock);
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef _HAL_IO_H_
|
||||
#define _HAL_IO_H_
|
||||
#include "../common/sys/kdef.h"
|
||||
#include "../common/sys/type.h"
|
||||
#include "k_def.h"
|
||||
#include "k_type.h"
|
||||
|
||||
#define GATE_DPL_0 (0ull << 13)
|
||||
#define GATE_DPL_1 (1ull << 13)
|
|
@ -1,9 +1,16 @@
|
|||
#ifndef _MM_H_
|
||||
#define _MM_H_
|
||||
#ifndef _HAL_MEM_H_
|
||||
#define _HAL_MEM_H_
|
||||
|
||||
#include "k_def.h"
|
||||
#include "k_type.h"
|
||||
#include "linked_list.h"
|
||||
|
||||
|
||||
static inline uint32_t seg_selector(uint32_t index, uint32_t rpl)
|
||||
{
|
||||
return (index << 3) + rpl;
|
||||
}
|
||||
|
||||
#include "../common/sys/kdef.h"
|
||||
#include "../common/sys/type.h"
|
||||
#include "../common/lib/list/linked_list/linked_list.h"
|
||||
|
||||
#define PML4_PRESENT (1ull << 0)
|
||||
#define PML4_WRITE (1ull << 1)
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef _PRINT_H_
|
||||
#define _PRINT_H_
|
||||
#include "../common/sys/kdef.h"
|
||||
#include "../common/sys/type.h"
|
||||
#ifndef _HAL_PRINT_H_
|
||||
#define _HAL_PRINT_H_
|
||||
#include "k_def.h"
|
||||
#include "k_type.h"
|
||||
|
||||
#define get_column(pos) (pos % 80)
|
||||
#define get_row(pos) (pos / 80)
|
|
@ -1,8 +1,8 @@
|
|||
#ifndef _VAR_H_
|
||||
#define _VAR_H_
|
||||
#ifndef _HAL_VAR_H_
|
||||
#define _HAL_VAR_H_
|
||||
|
||||
#include "mem.h"
|
||||
#include "../common/lib/list/linked_list/linked_list.h"
|
||||
#include "hal_mem.h"
|
||||
#include "linked_list.h"
|
||||
|
||||
extern uint8_t g_gdt[8*9];
|
||||
extern uint8_t g_idt[21*16];
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef _PMM_H_
|
||||
#define _PMM_H_
|
||||
#ifndef _K_PMM_H_
|
||||
#define _K_PMM_H_
|
||||
|
||||
#include "../common/lib/list/linked_list/linked_list.h"
|
||||
#include "linked_list.h"
|
||||
|
||||
void pmm_init(linked_list_t* occupied, linked_list_t* available);
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
#define _PROC_H
|
||||
|
||||
|
||||
#include "../common/sys/kdef.h"
|
||||
#include "k_def.h"
|
||||
|
||||
typedef struct __attribute__((packed))
|
||||
{
|
|
@ -1,7 +1,9 @@
|
|||
#include "../common/sys/kdef.h"
|
||||
#include "../hal/hal.h"
|
||||
#include "../hal/print.h"
|
||||
#include "../hal/io.h"
|
||||
#include "k_def.h"
|
||||
#include "std_lib.h"
|
||||
#include "k_lib_test.h"
|
||||
#include "hal.h"
|
||||
#include "hal_print.h"
|
||||
#include "hal_io.h"
|
||||
|
||||
|
||||
void SAPI kmain(multiboot_info_t *multiboot_info)
|
||||
|
@ -10,6 +12,10 @@ void SAPI kmain(multiboot_info_t *multiboot_info)
|
|||
|
||||
hal_printf("Kernel Loaded at 0x%X. Size: %uB, %uKB\n\n",kernel_start,(kernel_end-kernel_start),(kernel_end-kernel_start)/1024);
|
||||
|
||||
linked_list_test();
|
||||
|
||||
//avl_tree_test();
|
||||
|
||||
if(boot_info->mem_info != NULL)
|
||||
{
|
||||
hal_printf("Installed Memory: %uB\n", boot_info->mem_info->mem_installed);
|
||||
|
@ -48,4 +54,4 @@ void SAPI kmain(multiboot_info_t *multiboot_info)
|
|||
|
||||
hal_printf("KRNL: Kernel task finished.");
|
||||
hal_halt_cpu();
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
#include "pmm.h"
|
||||
#include "../common/sys/sys_info.h"
|
||||
#include "../hal/io.h"
|
||||
#include "k_pmm.h"
|
||||
#include "k_sys_info.h"
|
||||
#include "hal_io.h"
|
||||
#include "std_lib.h"
|
||||
|
||||
linked_list_t* occupied_mem;
|
||||
linked_list_t* available_mem;
|
|
@ -0,0 +1 @@
|
|||
#include "k_proc.h"
|
|
@ -1 +0,0 @@
|
|||
#include "proc.h"
|
|
@ -0,0 +1,8 @@
|
|||
#ifndef _LIB_TEST_H_
|
||||
#define _LIB_TEST_H_
|
||||
|
||||
int linked_list_test(void);
|
||||
|
||||
//int avl_tree_test(void);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,122 @@
|
|||
//#include "avl_tree.h"
|
||||
//#include "std_lib.h"
|
||||
//#include "k_lib_test.h"
|
||||
//
|
||||
//typedef struct __attribute__ ((packed))
|
||||
//{
|
||||
// avl_tree_entry_t node;
|
||||
// int val;
|
||||
//} int_node;
|
||||
//
|
||||
//
|
||||
//// TESTS
|
||||
//
|
||||
//static int SAPI avl_tree_node_calculate_height(avl_tree_entry_t *tree)
|
||||
//{
|
||||
// if (tree == NULL)
|
||||
// return -1;
|
||||
// return max_32(avl_tree_node_calculate_height(tree->left), avl_tree_node_calculate_height(tree->right)) + 1;
|
||||
//}
|
||||
//
|
||||
//static int SAPI _avl_tree_node_get_balance_factor(avl_tree_entry_t* entry)
|
||||
//{
|
||||
// return entry == NULL ? -1 : entry->height;
|
||||
//}
|
||||
//
|
||||
//static int SAPI avl_tree_node_test(avl_tree_entry_t *tree, int (*compare)(void*, void*))
|
||||
//{
|
||||
// if (tree == NULL)
|
||||
// return 1;
|
||||
// if (_avl_tree_node_get_balance_factor(tree) < -1 || _avl_tree_node_get_balance_factor(tree) > 1 || avl_tree_node_calculate_height(tree) != tree->height)
|
||||
// return 0;
|
||||
// if(tree->left != NULL)
|
||||
// {
|
||||
// if(tree->left->parent != tree)
|
||||
// return 0;
|
||||
// }
|
||||
// if(tree->right != NULL)
|
||||
// {
|
||||
// if(tree->right->parent != tree)
|
||||
// return 0;
|
||||
// }
|
||||
// if(compare != NULL)
|
||||
// {
|
||||
// if((tree->right != NULL && compare(tree,tree->right) > 0) || (tree->left != NULL && compare(tree,tree->left) < 0))
|
||||
// return 0;
|
||||
// }
|
||||
// return avl_tree_node_test(tree->left,compare) && avl_tree_node_test(tree->right,compare);
|
||||
//}
|
||||
//
|
||||
//int compare(void* a, void* b)
|
||||
//{
|
||||
// int_node* aa = (int_node*)a;
|
||||
// int_node* bb = (int_node*)b;
|
||||
// if(aa->val > bb->val)
|
||||
// return 1;
|
||||
// else if(aa->val < bb->val)
|
||||
// return -1;
|
||||
// return 0;
|
||||
//}
|
||||
//
|
||||
//void in_order_print(avl_tree_entry_t *tree)
|
||||
//{
|
||||
// if (tree == NULL)
|
||||
// return;
|
||||
// avl_tree_entry_t* node = avl_tree_entry_t(tree);
|
||||
// while(node != NULL)
|
||||
// {
|
||||
// printf("%d ", ((int_node*)node)->val);
|
||||
// node = avl_tree_node_prev(node);
|
||||
// }
|
||||
// return;
|
||||
//}
|
||||
//
|
||||
//int_node* create_int_node(int val)
|
||||
//{
|
||||
// int_node* node = (int_node*)malloc(sizeof(int_node));
|
||||
// avl_tree_node_init(&node->node);
|
||||
// node->val = val;
|
||||
// return node;
|
||||
//}
|
||||
//
|
||||
//int avl_tree_test (void)
|
||||
//{
|
||||
// int_node* val[1000];
|
||||
// srand((unsigned int)time(NULL));
|
||||
// avl_tree* avlTree = (avl_tree*)malloc(sizeof(avl_tree));
|
||||
// avl_tree_init(avlTree);
|
||||
// //test INSERT general
|
||||
// int i = 0;
|
||||
// for(i = 0; i < 1000; i++)
|
||||
// {
|
||||
// val[i] = create_int_node(rand()%10000);
|
||||
// avl_tree_insert(avlTree,(avl_tree_node*)val[i],compare);
|
||||
// assert(avl_tree_node_test(avlTree->root,compare));
|
||||
// }
|
||||
// //test Delete general
|
||||
// for(i = 0; i < 1000; i++)
|
||||
// {
|
||||
// avl_tree_delete(avlTree,val[i],compare);
|
||||
// assert(avl_tree_node_test(avlTree->root,compare));
|
||||
// free(val[i]);
|
||||
// }
|
||||
//
|
||||
// //test delete visualized
|
||||
// for(i = 0; i < 20; i++)
|
||||
// {
|
||||
// val[i] = create_int_node(rand()%2000);
|
||||
// avl_tree_insert(avlTree,(avl_tree_node*)val[i],compare);
|
||||
// assert(avl_tree_node_test(avlTree->root,compare));
|
||||
// }
|
||||
// in_order_print(avlTree->root);
|
||||
// for(i = 0; i < 20; i++)
|
||||
// {
|
||||
// avl_tree_delete(avlTree,(avl_tree_node*)val[i],compare);
|
||||
// printf("\nDeleting: %d\n",val[i]->val);
|
||||
// in_order_print(avlTree->root);
|
||||
// assert(avl_tree_node_test(avlTree->root,compare));
|
||||
// free(val[i]);
|
||||
// }
|
||||
// free(avlTree);
|
||||
// return 0;
|
||||
//}
|
|
@ -1,28 +1,30 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include "k_type.h"
|
||||
#include "linked_list.h"
|
||||
#include "k_lib_test.h"
|
||||
#include "hal_print.h"
|
||||
#include "std_lib.h"
|
||||
#include "hal_mem.h"
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
linked_list_node_t lnode;
|
||||
linked_list_entry_t lnode;
|
||||
int val;
|
||||
} my_list_node;
|
||||
|
||||
#define GLOBAL_ALLOC_TABLE_SIZE 256
|
||||
#define GLOBAL_ALLOC_TABLE_SIZE 64
|
||||
my_list_node* g_gat[GLOBAL_ALLOC_TABLE_SIZE];
|
||||
|
||||
void delete_list(linked_list_t* list)
|
||||
{
|
||||
if(list != NULL)
|
||||
{
|
||||
linked_list_node_t* node = linked_list_first(list);
|
||||
linked_list_entry_t* node = linked_list_first(list);
|
||||
while(node != NULL)
|
||||
{
|
||||
my_list_node *mnode = OBTAIN_STRUCT_ADDR(node, lnode, my_list_node);
|
||||
node = linked_list_next(node);
|
||||
free(mnode);
|
||||
hal_free(mnode);
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
@ -44,7 +46,7 @@ void clear_gat()
|
|||
for(i = 0; i < GLOBAL_ALLOC_TABLE_SIZE; i++)
|
||||
{
|
||||
if(g_gat[i] != NULL)
|
||||
free(g_gat[i]);
|
||||
hal_free(g_gat[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -76,7 +78,7 @@ bool validate_list(linked_list_t* list)
|
|||
|
||||
bool assert_list(linked_list_t* list, int val[], int size)
|
||||
{
|
||||
linked_list_node_t* node = linked_list_first(list);
|
||||
linked_list_entry_t * node = linked_list_first(list);
|
||||
unsigned int i = 0;
|
||||
|
||||
if(!validate_list(list))
|
||||
|
@ -118,26 +120,26 @@ bool assert_list(linked_list_t* list, int val[], int size)
|
|||
// my_list_node* node = (my_list_node*) linked_list_first(list);
|
||||
// while(node != NULL)
|
||||
// {
|
||||
// printf("%d", node->val);
|
||||
// hal_printf("%d", node->val);
|
||||
// node = (my_list_node*) linked_list_next((linked_list_node_t *) node);
|
||||
// }
|
||||
//
|
||||
// printf("======");
|
||||
// hal_printf("======");
|
||||
// node = (my_list_node*) linked_list_last(list);
|
||||
// while(node != NULL)
|
||||
// {
|
||||
// printf("%d", node->val);
|
||||
// hal_printf("%d", node->val);
|
||||
// node = (my_list_node*) linked_list_prev((linked_list_node_t *) node);
|
||||
// }
|
||||
//
|
||||
// validate_list(list);
|
||||
// printf("\n");
|
||||
// hal_printf("\n");
|
||||
// return;
|
||||
//}
|
||||
|
||||
void insert_val(linked_list_t* list, int index, int val)
|
||||
{
|
||||
my_list_node *a = (my_list_node*)malloc(sizeof(my_list_node));
|
||||
my_list_node *a = (my_list_node*)hal_alloc(sizeof(my_list_node));
|
||||
a->val = val;
|
||||
linked_list_insert_idx(list, index, &a->lnode);
|
||||
push_gat(a);
|
||||
|
@ -145,7 +147,7 @@ void insert_val(linked_list_t* list, int index, int val)
|
|||
|
||||
void push_back_val(linked_list_t* list, int val)
|
||||
{
|
||||
my_list_node *a = (my_list_node*)malloc(sizeof(my_list_node));
|
||||
my_list_node *a = (my_list_node*)hal_alloc(sizeof(my_list_node));
|
||||
a->val = val;
|
||||
linked_list_push_back(list, &a->lnode);
|
||||
push_gat(a);
|
||||
|
@ -153,7 +155,7 @@ void push_back_val(linked_list_t* list, int val)
|
|||
|
||||
void push_front_val(linked_list_t* list, int val)
|
||||
{
|
||||
my_list_node *a = (my_list_node*)malloc(sizeof(my_list_node));
|
||||
my_list_node *a = (my_list_node*)hal_alloc(sizeof(my_list_node));
|
||||
a->val = val;
|
||||
linked_list_push_front(list, &a->lnode);
|
||||
push_gat(a);
|
||||
|
@ -171,7 +173,7 @@ void insert_test_beginning()
|
|||
|
||||
// 3210==0123
|
||||
int val[4] = {3,2,1,0};
|
||||
printf("insert_test_beginning %s\n",assert_list(&list, val, 4) ? "PASS" : "FAIL");
|
||||
hal_printf("insert_test_beginning %s\n",assert_list(&list, val, 4) ? "PASS" : "FAIL");
|
||||
}
|
||||
|
||||
void insert_test_middle()
|
||||
|
@ -188,7 +190,7 @@ void insert_test_middle()
|
|||
insert_val(&list, 2, 6);
|
||||
|
||||
int val[] = {2,5,6,4,1,0};
|
||||
printf("insert_test_middle %s\n",assert_list(&list, val, 6) ? "PASS" : "FAIL");
|
||||
hal_printf("insert_test_middle %s\n",assert_list(&list, val, 6) ? "PASS" : "FAIL");
|
||||
}
|
||||
|
||||
void insert_test_end()
|
||||
|
@ -202,7 +204,7 @@ void insert_test_end()
|
|||
insert_val(&list, 3, 3);
|
||||
|
||||
int val[] = {0,1,2,3};
|
||||
printf("insert_test_end %s\n",assert_list(&list, val, 4) ? "PASS" : "FAIL");
|
||||
hal_printf("insert_test_end %s\n",assert_list(&list, val, 4) ? "PASS" : "FAIL");
|
||||
}
|
||||
|
||||
void insert_test_invalid()
|
||||
|
@ -231,7 +233,7 @@ void insert_test_invalid()
|
|||
linked_list_insert_ref(&list, list.head, NULL);
|
||||
|
||||
int val[] = {0,1,2,3};
|
||||
printf("insert_test_invalid %s\n",assert_list(&list, val, 4) ? "PASS" : "FAIL");
|
||||
hal_printf("insert_test_invalid %s\n",assert_list(&list, val, 4) ? "PASS" : "FAIL");
|
||||
}
|
||||
|
||||
|
||||
|
@ -249,7 +251,7 @@ void remove_test_beginning()
|
|||
|
||||
// 10==01
|
||||
int val[] = {1,0};
|
||||
printf("remove_test_beginning %s\n",assert_list(&list, val, 2) ? "PASS" : "FAIL");
|
||||
hal_printf("remove_test_beginning %s\n",assert_list(&list, val, 2) ? "PASS" : "FAIL");
|
||||
}
|
||||
|
||||
void remove_test_middle()
|
||||
|
@ -270,7 +272,7 @@ void remove_test_middle()
|
|||
|
||||
// 5310=====0135
|
||||
int val[] = {5,3,1,0};
|
||||
printf("remove_test_middle %s\n",assert_list(&list, val, 4) ? "PASS" : "FAIL");
|
||||
hal_printf("remove_test_middle %s\n",assert_list(&list, val, 4) ? "PASS" : "FAIL");
|
||||
}
|
||||
|
||||
void remove_test_end()
|
||||
|
@ -287,7 +289,7 @@ void remove_test_end()
|
|||
linked_list_remove_idx(&list, 2);
|
||||
|
||||
int val[] = {0,1};
|
||||
printf("remove_test_all %s\n",assert_list(&list, val, 2) ? "PASS" : "FAIL");
|
||||
hal_printf("remove_test_all %s\n",assert_list(&list, val, 2) ? "PASS" : "FAIL");
|
||||
}
|
||||
|
||||
void remove_test_all()
|
||||
|
@ -332,7 +334,7 @@ void remove_test_all()
|
|||
|
||||
result = result && assert_list(&list, NULL, 0);
|
||||
|
||||
printf("remove_test_end %s\n",result ? "PASS" : "FAIL");
|
||||
hal_printf("remove_test_end %s\n",result ? "PASS" : "FAIL");
|
||||
}
|
||||
|
||||
void remove_test_invalid()
|
||||
|
@ -362,7 +364,7 @@ void remove_test_invalid()
|
|||
|
||||
// 0123=====3210
|
||||
int val[] = {0,1,2,3};
|
||||
printf("remove_test_invalid %s\n",assert_list(&list, val, 4) ? "PASS" : "FAIL");
|
||||
hal_printf("remove_test_invalid %s\n",assert_list(&list, val, 4) ? "PASS" : "FAIL");
|
||||
}
|
||||
|
||||
void size_test()
|
||||
|
@ -381,7 +383,7 @@ void size_test()
|
|||
result = result && (linked_list_size(&list) == 4 && linked_list_size(&list2) == 0 && linked_list_size(NULL) == -1);
|
||||
int val[] = {0,1,2,3};
|
||||
result = result && assert_list(&list, val, 4);
|
||||
printf("size_test %s\n", result ? "PASS" : "FAIL");
|
||||
hal_printf("size_test %s\n", result ? "PASS" : "FAIL");
|
||||
}
|
||||
|
||||
void push_pop_front_test()
|
||||
|
@ -409,7 +411,7 @@ void push_pop_front_test()
|
|||
linked_list_pop_front(&list);
|
||||
|
||||
result = result && assert_list(&list, NULL, 0);
|
||||
printf("push_pop_front_test %s\n", result ? "PASS" : "FAIL");
|
||||
hal_printf("push_pop_front_test %s\n", result ? "PASS" : "FAIL");
|
||||
}
|
||||
|
||||
void push_pop_back_test()
|
||||
|
@ -437,10 +439,10 @@ void push_pop_back_test()
|
|||
linked_list_pop_back(&list);
|
||||
|
||||
result = result && assert_list(&list, NULL, 0);
|
||||
printf("push_pop_back_test %s\n", result ? "PASS" : "FAIL");
|
||||
hal_printf("push_pop_back_test %s\n", result ? "PASS" : "FAIL");
|
||||
}
|
||||
|
||||
bool equals(linked_list_node_t* a, linked_list_node_t* b)
|
||||
bool equals(linked_list_entry_t* a, linked_list_entry_t* b)
|
||||
{
|
||||
return (int)a == OBTAIN_STRUCT_ADDR(b, lnode, my_list_node)->val;
|
||||
}
|
||||
|
@ -467,17 +469,17 @@ void search_test()
|
|||
result = result && (linked_list_search(&list, NULL ,equals) == -1);
|
||||
result = result && (linked_list_search(NULL, 1 ,equals) == -1);
|
||||
|
||||
linked_list_node_t* node = linked_list_get(&list, 1);
|
||||
linked_list_entry_t* node = linked_list_get(&list, 1);
|
||||
result = result && (linked_list_search(&list, node , NULL) == 1);
|
||||
|
||||
|
||||
result = result && assert_list(&list, val1, 4);
|
||||
|
||||
printf("search_test %s\n", result ? "PASS" : "FAIL");
|
||||
hal_printf("search_test %s\n", result ? "PASS" : "FAIL");
|
||||
}
|
||||
|
||||
|
||||
int main(void)
|
||||
int linked_list_test(void)
|
||||
{
|
||||
int i = 0;
|
||||
for(i = 0; i < GLOBAL_ALLOC_TABLE_SIZE; i++)
|
Loading…
Reference in New Issue