Adding memory descriptor
This commit is contained in:
parent
97ddb93858
commit
4ee70bf53c
|
@ -1,7 +1,7 @@
|
|||
#include "../../../kdef.h"
|
||||
#include "linked_list.h"
|
||||
|
||||
void NATIVE64 linked_list_node_init(linked_list_node* node)
|
||||
void NATIVE64 linked_list_node_init(linked_list_node_t * node)
|
||||
{
|
||||
if(node != NULL)
|
||||
{
|
||||
|
@ -11,7 +11,7 @@ void NATIVE64 linked_list_node_init(linked_list_node* node)
|
|||
return;
|
||||
}
|
||||
|
||||
linked_list_node* NATIVE64 linked_list_node_get(linked_list_node * head, int index)
|
||||
linked_list_node_t * NATIVE64 linked_list_node_get(linked_list_node_t * head, int index)
|
||||
{
|
||||
if(head == NULL || index < 0)
|
||||
return NULL;
|
||||
|
@ -24,7 +24,7 @@ linked_list_node* NATIVE64 linked_list_node_get(linked_list_node * head, int ind
|
|||
return head;
|
||||
}
|
||||
|
||||
int NATIVE64 linked_list_node_size(linked_list_node* head)
|
||||
int NATIVE64 linked_list_node_size(linked_list_node_t * head)
|
||||
{
|
||||
int i = 0;
|
||||
while(head != NULL)
|
||||
|
@ -36,7 +36,7 @@ int NATIVE64 linked_list_node_size(linked_list_node* head)
|
|||
}
|
||||
|
||||
//returns new head
|
||||
linked_list_node* NATIVE64 linked_list_node_insert(linked_list_node * head, int index, linked_list_node* node)
|
||||
linked_list_node_t * NATIVE64 linked_list_node_insert(linked_list_node_t * head, int index, linked_list_node_t * node)
|
||||
{
|
||||
if(head == NULL)
|
||||
return node;
|
||||
|
@ -53,7 +53,7 @@ linked_list_node* NATIVE64 linked_list_node_insert(linked_list_node * head, int
|
|||
}
|
||||
else
|
||||
{
|
||||
linked_list_node* target = linked_list_node_get(head, index-1);
|
||||
linked_list_node_t * target = linked_list_node_get(head, index-1);
|
||||
if(target == NULL)
|
||||
return NULL;
|
||||
node->prev = target;
|
||||
|
@ -65,7 +65,7 @@ linked_list_node* NATIVE64 linked_list_node_insert(linked_list_node * head, int
|
|||
}
|
||||
}
|
||||
|
||||
void NATIVE64 linked_list_node_add(linked_list_node * head, linked_list_node* node)
|
||||
void NATIVE64 linked_list_node_add(linked_list_node_t * head, linked_list_node_t * node)
|
||||
{
|
||||
if(head == NULL || node == NULL)
|
||||
return;
|
||||
|
@ -75,13 +75,13 @@ void NATIVE64 linked_list_node_add(linked_list_node * head, linked_list_node* no
|
|||
}
|
||||
|
||||
//returns new head
|
||||
linked_list_node* NATIVE64 linked_list_node_remove(linked_list_node *head, int index)
|
||||
linked_list_node_t * NATIVE64 linked_list_node_remove(linked_list_node_t *head, int index)
|
||||
{
|
||||
if(head == NULL || index < 0)
|
||||
return head;
|
||||
if(index == 0)
|
||||
{
|
||||
linked_list_node* next = head->next;
|
||||
linked_list_node_t * next = head->next;
|
||||
head->next = NULL;
|
||||
head->prev = NULL;
|
||||
if(next != NULL)
|
||||
|
@ -90,7 +90,7 @@ linked_list_node* NATIVE64 linked_list_node_remove(linked_list_node *head, int i
|
|||
}
|
||||
else
|
||||
{
|
||||
linked_list_node *target = linked_list_node_get(head, index);
|
||||
linked_list_node_t *target = linked_list_node_get(head, index);
|
||||
if (target->prev != NULL)
|
||||
target->prev->next = target->next;
|
||||
if (target->next != NULL)
|
||||
|
@ -102,7 +102,7 @@ linked_list_node* NATIVE64 linked_list_node_remove(linked_list_node *head, int i
|
|||
}
|
||||
|
||||
|
||||
void NATIVE64 linked_list_init(linked_list* list)
|
||||
void NATIVE64 linked_list_init(linked_list_t * list)
|
||||
{
|
||||
if(list != NULL)
|
||||
{
|
||||
|
@ -112,7 +112,7 @@ void NATIVE64 linked_list_init(linked_list* list)
|
|||
return;
|
||||
}
|
||||
|
||||
void NATIVE64 linked_list_add(linked_list * list, linked_list_node* node)
|
||||
void NATIVE64 linked_list_add(linked_list_t * list, linked_list_node_t * node)
|
||||
{
|
||||
if(list != NULL && node != NULL)
|
||||
{
|
||||
|
@ -128,7 +128,7 @@ void NATIVE64 linked_list_add(linked_list * list, linked_list_node* node)
|
|||
return;
|
||||
}
|
||||
|
||||
void NATIVE64 linked_list_insert(linked_list * list, int index, linked_list_node* node)
|
||||
void NATIVE64 linked_list_insert(linked_list_t * list, int index, linked_list_node_t * node)
|
||||
{
|
||||
if(list != NULL && index > 0 && node != NULL)
|
||||
{
|
||||
|
@ -138,14 +138,14 @@ void NATIVE64 linked_list_insert(linked_list * list, int index, linked_list_node
|
|||
return;
|
||||
}
|
||||
|
||||
linked_list_node* NATIVE64 linked_list_get(linked_list * list, int index)
|
||||
linked_list_node_t * NATIVE64 linked_list_get(linked_list_t * list, int index)
|
||||
{
|
||||
if(list == NULL || index < 0 || index >= list->size)
|
||||
return NULL;
|
||||
return linked_list_node_get(list->head,index);
|
||||
}
|
||||
|
||||
void NATIVE64 linked_list_remove(linked_list *list, int index)
|
||||
void NATIVE64 linked_list_remove(linked_list_t *list, int index)
|
||||
{
|
||||
if(list != NULL && index >= 0 && index < list->size)
|
||||
{
|
||||
|
|
|
@ -1,40 +1,40 @@
|
|||
#ifndef _LINKED_LIST_H_
|
||||
#define _LINKED_LIST_H_
|
||||
#include "../../../kdef.h"
|
||||
typedef struct _linked_list_node
|
||||
typedef struct __attribute__((packed)) _linked_list_node_t
|
||||
{
|
||||
struct _linked_list_node* prev;
|
||||
struct _linked_list_node* next;
|
||||
} linked_list_node;
|
||||
struct _linked_list_node_t * prev;
|
||||
struct _linked_list_node_t * next;
|
||||
} linked_list_node_t;
|
||||
|
||||
typedef struct
|
||||
typedef struct __attribute__((packed))
|
||||
{
|
||||
linked_list_node* head;
|
||||
linked_list_node_t * head;
|
||||
int size;
|
||||
} linked_list;
|
||||
} linked_list_t;
|
||||
|
||||
void NATIVE64 linked_list_init(linked_list* list);
|
||||
void NATIVE64 linked_list_init(linked_list_t * list);
|
||||
|
||||
void NATIVE64 linked_list_add(linked_list * list, linked_list_node* node);
|
||||
void NATIVE64 linked_list_add(linked_list_t * list, linked_list_node_t * node);
|
||||
|
||||
void NATIVE64 linked_list_insert(linked_list * list, int index, linked_list_node* node);
|
||||
void NATIVE64 linked_list_insert(linked_list_t * list, int index, linked_list_node_t * node);
|
||||
|
||||
linked_list_node* NATIVE64 linked_list_get(linked_list * list, int index);
|
||||
linked_list_node_t * NATIVE64 linked_list_get(linked_list_t * list, int index);
|
||||
|
||||
void NATIVE64 linked_list_remove(linked_list *list, int index);
|
||||
void NATIVE64 linked_list_remove(linked_list_t *list, int index);
|
||||
|
||||
|
||||
|
||||
int NATIVE64 linked_list_node_size(linked_list_node* head);
|
||||
int NATIVE64 linked_list_node_size(linked_list_node_t * head);
|
||||
|
||||
void NATIVE64 linked_list_node_init(linked_list_node* node);
|
||||
void NATIVE64 linked_list_node_init(linked_list_node_t * node);
|
||||
|
||||
void NATIVE64 linked_list_node_add(linked_list_node * head, linked_list_node* node);
|
||||
void NATIVE64 linked_list_node_add(linked_list_node_t * head, linked_list_node_t * node);
|
||||
|
||||
linked_list_node* NATIVE64 linked_list_node_insert(linked_list_node * head, int index, linked_list_node* node);
|
||||
linked_list_node_t * NATIVE64 linked_list_node_insert(linked_list_node_t * head, int index, linked_list_node_t * node);
|
||||
|
||||
linked_list_node* NATIVE64 linked_list_node_get(linked_list_node * head, int index);
|
||||
linked_list_node_t * NATIVE64 linked_list_node_get(linked_list_node_t * head, int index);
|
||||
|
||||
linked_list_node* NATIVE64 linked_list_node_remove(linked_list_node *head, int index);
|
||||
linked_list_node_t * NATIVE64 linked_list_node_remove(linked_list_node_t *head, int index);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -3,21 +3,21 @@
|
|||
|
||||
#define MAX(a, b) (((a) > (b) ? (a) : (b)))
|
||||
|
||||
int NATIVE64 _avl_tree_node_get_height(avl_tree_node *node)
|
||||
int NATIVE64 _avl_tree_node_get_height(avl_tree_node_t *node)
|
||||
{
|
||||
return node == NULL ? -1 : node->height;
|
||||
}
|
||||
|
||||
int NATIVE64 _avl_tree_node_get_balance_factor(avl_tree_node *node)
|
||||
int NATIVE64 _avl_tree_node_get_balance_factor(avl_tree_node_t *node)
|
||||
{
|
||||
if (node == NULL)
|
||||
return 0;
|
||||
return _avl_tree_node_get_height(node->left) - _avl_tree_node_get_height(node->right);
|
||||
}
|
||||
|
||||
avl_tree_node * NATIVE64 _avl_tree_node_right_rotate(avl_tree_node *root)
|
||||
avl_tree_node_t * NATIVE64 _avl_tree_node_right_rotate(avl_tree_node_t *root)
|
||||
{
|
||||
avl_tree_node *left_children = root->left;
|
||||
avl_tree_node_t *left_children = root->left;
|
||||
//adjust parents first
|
||||
left_children->parent = root->parent;
|
||||
root->parent = left_children;
|
||||
|
@ -32,9 +32,9 @@ avl_tree_node * NATIVE64 _avl_tree_node_right_rotate(avl_tree_node *root)
|
|||
return left_children;
|
||||
}
|
||||
|
||||
avl_tree_node * NATIVE64 _avl_tree_node_left_rotate(avl_tree_node *root)
|
||||
avl_tree_node_t * NATIVE64 _avl_tree_node_left_rotate(avl_tree_node_t *root)
|
||||
{
|
||||
avl_tree_node *right_children = root->right;
|
||||
avl_tree_node_t *right_children = root->right;
|
||||
//adjust parents
|
||||
right_children->parent = root->parent;
|
||||
root->parent = right_children;
|
||||
|
@ -49,7 +49,7 @@ avl_tree_node * NATIVE64 _avl_tree_node_left_rotate(avl_tree_node *root)
|
|||
return right_children;
|
||||
}
|
||||
|
||||
avl_tree_node * NATIVE64 _avl_tree_node_balance(avl_tree_node *node)
|
||||
avl_tree_node_t * NATIVE64 _avl_tree_node_balance(avl_tree_node_t *node)
|
||||
{
|
||||
const int bf = _avl_tree_node_get_balance_factor(node);
|
||||
|
||||
|
@ -86,7 +86,7 @@ avl_tree_node * NATIVE64 _avl_tree_node_balance(avl_tree_node *node)
|
|||
|
||||
}
|
||||
|
||||
avl_tree_node * NATIVE64 _avl_tree_node_insert(avl_tree_node *root, avl_tree_node *node, int(*compare)(void *, void *), avl_tree_node *parent)
|
||||
avl_tree_node_t * NATIVE64 _avl_tree_node_insert(avl_tree_node_t *root, avl_tree_node_t *node, int(*compare)(void *, void *), avl_tree_node_t *parent)
|
||||
{
|
||||
if (node == NULL)
|
||||
return root;
|
||||
|
@ -109,13 +109,13 @@ avl_tree_node * NATIVE64 _avl_tree_node_insert(avl_tree_node *root, avl_tree_nod
|
|||
return _avl_tree_node_balance(root);
|
||||
}
|
||||
|
||||
void _swap_nodes(avl_tree_node *node1, avl_tree_node *node2)
|
||||
void _swap_nodes(avl_tree_node_t *node1, avl_tree_node_t *node2)
|
||||
{
|
||||
if (node1 == NULL || node2 == NULL)
|
||||
return;
|
||||
avl_tree_node *parent = NULL;
|
||||
avl_tree_node *child = NULL;
|
||||
avl_tree_node *temp = NULL;
|
||||
avl_tree_node_t *parent = NULL;
|
||||
avl_tree_node_t *child = NULL;
|
||||
avl_tree_node_t *temp = NULL;
|
||||
//swap node but does not change anything else other than node1,node2
|
||||
if (node1->parent != NULL && node1->parent == node2)
|
||||
{
|
||||
|
@ -232,12 +232,12 @@ void _swap_nodes(avl_tree_node *node1, avl_tree_node *node2)
|
|||
}
|
||||
|
||||
//Interface
|
||||
avl_tree_node* NATIVE64 avl_tree_node_insert(avl_tree_node* root, avl_tree_node* node, int(*compare)(void*,void*))
|
||||
avl_tree_node_t * NATIVE64 avl_tree_node_insert(avl_tree_node_t * root, avl_tree_node_t * node, int(*compare)(void*,void*))
|
||||
{
|
||||
return _avl_tree_node_insert(root, node, compare, NULL);
|
||||
}
|
||||
|
||||
avl_tree_node* NATIVE64 avl_tree_node_delete(avl_tree_node* root, avl_tree_node* node, int (*compare)(void *, void *))
|
||||
avl_tree_node_t * NATIVE64 avl_tree_node_delete(avl_tree_node_t * root, avl_tree_node_t * node, int (*compare)(void *, void *))
|
||||
{
|
||||
if (root == NULL || node == NULL)
|
||||
return root;
|
||||
|
@ -251,7 +251,7 @@ avl_tree_node* NATIVE64 avl_tree_node_delete(avl_tree_node* root, avl_tree_node*
|
|||
// node with only one child or no child
|
||||
if( (root->left == NULL) || (root->right == NULL) )
|
||||
{
|
||||
avl_tree_node *child = root->left != NULL ? root->left : root->right;
|
||||
avl_tree_node_t *child = root->left != NULL ? root->left : root->right;
|
||||
|
||||
if(child == NULL)
|
||||
{ // 0 child
|
||||
|
@ -267,7 +267,7 @@ avl_tree_node* NATIVE64 avl_tree_node_delete(avl_tree_node* root, avl_tree_node*
|
|||
{
|
||||
// node with two children: Get the inorder successor (smallest
|
||||
// in the right subtree)
|
||||
avl_tree_node *successor = root->right;
|
||||
avl_tree_node_t *successor = root->right;
|
||||
while(successor->left != NULL)
|
||||
successor = successor->left;
|
||||
//swap fields
|
||||
|
@ -286,7 +286,7 @@ avl_tree_node* NATIVE64 avl_tree_node_delete(avl_tree_node* root, avl_tree_node*
|
|||
return root;
|
||||
}
|
||||
|
||||
avl_tree_node* NATIVE64 avl_tree_node_search(avl_tree_node *root, avl_tree_node* node, int(*compare)(void *, void *))
|
||||
avl_tree_node_t * NATIVE64 avl_tree_node_search(avl_tree_node_t *root, avl_tree_node_t * node, int(*compare)(void *, void *))
|
||||
{
|
||||
if(root == NULL)
|
||||
return NULL;
|
||||
|
@ -299,7 +299,7 @@ avl_tree_node* NATIVE64 avl_tree_node_search(avl_tree_node *root, avl_tree_node*
|
|||
return avl_tree_node_search(root->left, node, compare);
|
||||
}
|
||||
|
||||
void NATIVE64 avl_tree_node_init(avl_tree_node* it)
|
||||
void NATIVE64 avl_tree_node_init(avl_tree_node_t * it)
|
||||
{
|
||||
if(it != NULL)
|
||||
{
|
||||
|
@ -312,7 +312,7 @@ void NATIVE64 avl_tree_node_init(avl_tree_node* it)
|
|||
}
|
||||
|
||||
|
||||
avl_tree_node * NATIVE64 avl_tree_node_smallest(avl_tree_node *root)
|
||||
avl_tree_node_t * NATIVE64 avl_tree_node_smallest(avl_tree_node_t *root)
|
||||
{
|
||||
if (root == NULL)
|
||||
return NULL;
|
||||
|
@ -321,7 +321,7 @@ avl_tree_node * NATIVE64 avl_tree_node_smallest(avl_tree_node *root)
|
|||
return root;
|
||||
}
|
||||
|
||||
avl_tree_node * NATIVE64 avl_tree_node_largest(avl_tree_node *root)
|
||||
avl_tree_node_t * NATIVE64 avl_tree_node_largest(avl_tree_node_t *root)
|
||||
{
|
||||
if (root == NULL)
|
||||
return NULL;
|
||||
|
@ -331,11 +331,11 @@ avl_tree_node * NATIVE64 avl_tree_node_largest(avl_tree_node *root)
|
|||
}
|
||||
|
||||
|
||||
avl_tree_node* NATIVE64 avl_tree_node_next(avl_tree_node *it)
|
||||
avl_tree_node_t * NATIVE64 avl_tree_node_next(avl_tree_node_t *it)
|
||||
{
|
||||
if (it == NULL)
|
||||
return NULL;
|
||||
avl_tree_node* root = it;
|
||||
avl_tree_node_t * root = it;
|
||||
if (root->right != NULL)
|
||||
{
|
||||
root = root->right;
|
||||
|
@ -355,11 +355,11 @@ avl_tree_node* NATIVE64 avl_tree_node_next(avl_tree_node *it)
|
|||
}
|
||||
}
|
||||
|
||||
avl_tree_node* NATIVE64 avl_tree_node_prev(avl_tree_node *it)
|
||||
avl_tree_node_t * NATIVE64 avl_tree_node_prev(avl_tree_node_t *it)
|
||||
{
|
||||
if (it == NULL)
|
||||
return NULL;
|
||||
avl_tree_node* root = it;
|
||||
avl_tree_node_t * root = it;
|
||||
if (root->left != NULL)
|
||||
{
|
||||
root = root->left;
|
||||
|
@ -379,13 +379,13 @@ avl_tree_node* NATIVE64 avl_tree_node_prev(avl_tree_node *it)
|
|||
}
|
||||
}
|
||||
|
||||
avl_tree_node* avl_tree_search(avl_tree *tree, avl_tree_node* node, int (*compare)(void *, void *))
|
||||
avl_tree_node_t * avl_tree_search(avl_tree_t *tree, avl_tree_node_t * node, int (*compare)(void *, void *))
|
||||
{
|
||||
return avl_tree_node_search(tree->root,node,compare);
|
||||
}
|
||||
|
||||
|
||||
void NATIVE64 avl_tree_insert(avl_tree *tree, void *data, int (*compare)(void *, void *))
|
||||
void NATIVE64 avl_tree_insert(avl_tree_t *tree, void *data, int (*compare)(void *, void *))
|
||||
{
|
||||
if(tree != NULL && data != NULL && compare != NULL)
|
||||
{
|
||||
|
@ -398,7 +398,7 @@ void NATIVE64 avl_tree_insert(avl_tree *tree, void *data, int (*compare)(void *,
|
|||
return;
|
||||
}
|
||||
|
||||
void NATIVE64 avl_tree_delete(avl_tree *tree, void *data, int (*compare)(void *, void *))
|
||||
void NATIVE64 avl_tree_delete(avl_tree_t *tree, void *data, int (*compare)(void *, void *))
|
||||
{
|
||||
if(tree != NULL && data != NULL && compare != NULL && tree->size != 0)
|
||||
{
|
||||
|
@ -411,7 +411,7 @@ void NATIVE64 avl_tree_delete(avl_tree *tree, void *data, int (*compare)(void *,
|
|||
return;
|
||||
}
|
||||
|
||||
void NATIVE64 avl_tree_init(avl_tree* tree)
|
||||
void NATIVE64 avl_tree_init(avl_tree_t * tree)
|
||||
{
|
||||
if(tree != NULL)
|
||||
{
|
||||
|
@ -422,14 +422,14 @@ void NATIVE64 avl_tree_init(avl_tree* tree)
|
|||
}
|
||||
// TESTS
|
||||
|
||||
int NATIVE64 avl_tree_node_calculate_height(avl_tree_node *tree)
|
||||
int NATIVE64 avl_tree_node_calculate_height(avl_tree_node_t *tree)
|
||||
{
|
||||
if (tree == NULL)
|
||||
return -1;
|
||||
return MAX(avl_tree_node_calculate_height(tree->left), avl_tree_node_calculate_height(tree->right)) + 1;
|
||||
}
|
||||
|
||||
int NATIVE64 avl_tree_node_test(avl_tree_node *tree, int (*compare)(void*,void*))
|
||||
int NATIVE64 avl_tree_node_test(avl_tree_node_t *tree, int (*compare)(void*,void*))
|
||||
{
|
||||
if (tree == NULL)
|
||||
return 1;
|
||||
|
|
|
@ -2,50 +2,50 @@
|
|||
#define _AVL_TREE_H_
|
||||
#include "../../../kdef.h"
|
||||
|
||||
typedef struct __attribute__((packed)) _avl_tree_node
|
||||
typedef struct __attribute__((packed)) _avl_tree_node_t
|
||||
{
|
||||
struct _avl_tree_node * left;
|
||||
struct _avl_tree_node * right;
|
||||
struct _avl_tree_node * parent;
|
||||
struct _avl_tree_node_t * left;
|
||||
struct _avl_tree_node_t * right;
|
||||
struct _avl_tree_node_t * parent;
|
||||
int height;
|
||||
} avl_tree_node;
|
||||
} avl_tree_node_t;
|
||||
|
||||
typedef struct __attribute__((packed))
|
||||
{
|
||||
avl_tree_node * root;
|
||||
avl_tree_node_t * root;
|
||||
int size;
|
||||
} avl_tree;
|
||||
} avl_tree_t;
|
||||
|
||||
avl_tree_node* NATIVE64 avl_tree_node_insert(avl_tree_node* root, avl_tree_node* node, int(*compare)(void*,void*));
|
||||
avl_tree_node_t * NATIVE64 avl_tree_node_insert(avl_tree_node_t * root, avl_tree_node_t * node, int(*compare)(void*,void*));
|
||||
|
||||
avl_tree_node* NATIVE64 avl_tree_node_delete(avl_tree_node* root, avl_tree_node* node, int (*compare)(void *, void *));
|
||||
avl_tree_node_t * NATIVE64 avl_tree_node_delete(avl_tree_node_t * root, avl_tree_node_t * node, int (*compare)(void *, void *));
|
||||
|
||||
avl_tree_node* NATIVE64 avl_tree_node_search(avl_tree_node *root, avl_tree_node* node, int(*compare)(void *, void *));
|
||||
avl_tree_node_t * NATIVE64 avl_tree_node_search(avl_tree_node_t *root, avl_tree_node_t * node, int(*compare)(void *, void *));
|
||||
|
||||
void NATIVE64 avl_tree_node_init(avl_tree_node* it);
|
||||
void NATIVE64 avl_tree_node_init(avl_tree_node_t * it);
|
||||
|
||||
avl_tree_node* NATIVE64 avl_tree_node_next(avl_tree_node *it);
|
||||
avl_tree_node_t * NATIVE64 avl_tree_node_next(avl_tree_node_t *it);
|
||||
|
||||
avl_tree_node* NATIVE64 avl_tree_node_prev(avl_tree_node *it);
|
||||
avl_tree_node_t * NATIVE64 avl_tree_node_prev(avl_tree_node_t *it);
|
||||
|
||||
avl_tree_node * NATIVE64 avl_tree_node_smallest(avl_tree_node *root);
|
||||
avl_tree_node_t * NATIVE64 avl_tree_node_smallest(avl_tree_node_t *root);
|
||||
|
||||
avl_tree_node * NATIVE64 avl_tree_node_largest(avl_tree_node *root);
|
||||
avl_tree_node_t * NATIVE64 avl_tree_node_largest(avl_tree_node_t *root);
|
||||
|
||||
|
||||
|
||||
avl_tree_node* avl_tree_search(avl_tree *tree, avl_tree_node* node, int (*compare)(void *, void *));
|
||||
avl_tree_node_t * avl_tree_search(avl_tree_t *tree, avl_tree_node_t * node, int (*compare)(void *, void *));
|
||||
|
||||
void NATIVE64 avl_tree_insert(avl_tree *tree, void *data, int (*compare)(void *, void *));
|
||||
void NATIVE64 avl_tree_insert(avl_tree_t *tree, void *data, int (*compare)(void *, void *));
|
||||
|
||||
void NATIVE64 avl_tree_delete(avl_tree *tree, void *data, int (*compare)(void *, void *));
|
||||
void NATIVE64 avl_tree_delete(avl_tree_t *tree, void *data, int (*compare)(void *, void *));
|
||||
|
||||
void NATIVE64 avl_tree_init(avl_tree* tree);
|
||||
void NATIVE64 avl_tree_init(avl_tree_t * tree);
|
||||
|
||||
// TESTS
|
||||
|
||||
int NATIVE64 avl_tree_node_calculate_height(avl_tree_node *tree);
|
||||
int NATIVE64 avl_tree_node_calculate_height(avl_tree_node_t *tree);
|
||||
|
||||
int NATIVE64 avl_tree_node_test(avl_tree_node *tree, int(*compare)(void *, void *));
|
||||
int NATIVE64 avl_tree_node_test(avl_tree_node_t *tree, int(*compare)(void *, void *));
|
||||
|
||||
#endif
|
|
@ -3,18 +3,13 @@
|
|||
#include "print.h"
|
||||
#include "mem.h"
|
||||
#include "io.h"
|
||||
|
||||
uint8_t g_gdt[8*9];
|
||||
uint8_t g_idt[21*16];
|
||||
gdt_ptr_t g_gdt_ptr;
|
||||
idt_ptr_t g_idt_ptr;
|
||||
|
||||
extern uint64_t text_pos;
|
||||
#include "var.h"
|
||||
#include "../common/util/list/linked_list/linked_list.h"
|
||||
|
||||
void NATIVE64 hal_init(multiboot_info_t* m_info)
|
||||
{
|
||||
text_pos = get_pos(3, 0);
|
||||
hal_printf("*Setting up GDT...");
|
||||
hal_printf("Setting up GDT...\n");
|
||||
hal_write_segment_descriptor((void *) &g_gdt[0], 0, 0, 0);
|
||||
hal_write_segment_descriptor((void *) &g_gdt[8], 0, 0, SEG_DPL_0 | SEG_CODE_DATA | SEG_PRESENT | SEG_LONG | SEG_TYPE_CODE_X);
|
||||
hal_write_segment_descriptor((void *) &g_gdt[16], 0, 0, SEG_DPL_0 | SEG_CODE_DATA | SEG_PRESENT | SEG_LONG | SEG_TYPE_DATA_RW);
|
||||
|
@ -28,37 +23,47 @@ void NATIVE64 hal_init(multiboot_info_t* m_info)
|
|||
g_gdt_ptr.base = (uint64_t)g_gdt;
|
||||
g_gdt_ptr.limit = 8*9-1;
|
||||
hal_flush_gdt(&g_gdt_ptr, SEG_SELECTOR(1, 0), SEG_SELECTOR(2, 0));
|
||||
hal_printf("Done.\n\n");
|
||||
hal_printf("*Checking memory information...\n");
|
||||
|
||||
if(m_info->flags & (1 << 6))
|
||||
{
|
||||
multiboot_memory_map_t const *mem_map = (multiboot_memory_map_t *) m_info->mmap_addr;
|
||||
uint64_t const mem_map_size = m_info->mmap_length / sizeof(multiboot_memory_map_t);
|
||||
hal_printf("BaseAddr - Length - Type\n");
|
||||
hal_printf("Initializing memory descriptors...\n");
|
||||
uint64_t total_available_mem = 0;
|
||||
uint64_t total_reserved_mem = 0;
|
||||
for (int i = 0; i < mem_map_size; i++)
|
||||
{
|
||||
hal_printf("0x%X - 0x%X - 0x%x\n", (mem_map + i)->addr, (mem_map + i)->len, (mem_map + i)->type);
|
||||
memory_descriptor_node_t* each_desc = (memory_descriptor_node_t*)hal_halloc(sizeof(memory_descriptor_node_t));
|
||||
each_desc->base_addr = (mem_map + i)->addr;
|
||||
each_desc->size = (mem_map + i)->len;
|
||||
if((mem_map + i)->type == MULTIBOOT_MEMORY_RESERVED)
|
||||
{
|
||||
each_desc->type = MEMORY_RESERVED;
|
||||
total_reserved_mem += (mem_map + i)->len;
|
||||
}
|
||||
else if ((mem_map + i)->type == MULTIBOOT_MEMORY_AVAILABLE)
|
||||
{
|
||||
each_desc->type = MEMORY_AVAILABLE;
|
||||
total_available_mem += (mem_map + i)->len;
|
||||
}
|
||||
linked_list_add(&mem_desc, (linked_list_node_t*)each_desc);
|
||||
}
|
||||
// TODO: total RAM should be in memory descriptors list
|
||||
hal_printf("Total available memory: %uB, %uKB, %uMB.\n", total_available_mem, total_available_mem / 1024,
|
||||
total_available_mem / 1024 / 1024);
|
||||
hal_printf("Total reserved memory: %uB, %uKB, %uMB.\n\n", total_reserved_mem, total_reserved_mem / 1024,
|
||||
hal_printf("Total reserved memory: %uB, %uKB, %uMB.\n", total_reserved_mem, total_reserved_mem / 1024,
|
||||
total_reserved_mem / 1024 / 1024);
|
||||
hal_printf("Memory Segments:\nBase - Size - Type");
|
||||
for(int i = 0; i < mem_desc.size; i++)
|
||||
{
|
||||
memory_descriptor_node_t* each_node = (memory_descriptor_node_t *) linked_list_get(&mem_desc,i);
|
||||
hal_printf("%d - %d - %s", each_node->base_addr, each_node->size, each_node->type == MEMORY_AVAILABLE ? "Available" : "Reserved");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
hal_printf("Memory information is currently unavailable.\n\n");
|
||||
hal_printf("Memory information is currently unavailable.\n");
|
||||
}
|
||||
hal_printf("CPUIDing \n");
|
||||
cpuid_t cpuid_info;
|
||||
cpuid_info.eax = 1;
|
||||
cpuid_info.ebx = 0;
|
||||
|
@ -67,7 +72,7 @@ void NATIVE64 hal_init(multiboot_info_t* m_info)
|
|||
hal_cpuid(&cpuid_info.eax,&cpuid_info.ebx,&cpuid_info.ecx,&cpuid_info.edx);
|
||||
if(cpuid_info.edx & 1 << 9)
|
||||
{
|
||||
hal_printf("AIPC detected...");
|
||||
hal_printf("APIC detected...\n");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
#include "../common/kdef.h"
|
||||
#include "../common/type.h"
|
||||
#include "../common/util/list/linked_list/linked_list.h"
|
||||
|
||||
#define PML4_PRESENT (1ull << 0)
|
||||
#define PML4_WRITE (1ull << 1)
|
||||
#define PML4_USER (1ull << 2)
|
||||
|
@ -82,6 +84,17 @@ typedef struct __attribute__((packed))
|
|||
uint64_t edx;
|
||||
} cpuid_t;
|
||||
|
||||
#define MEMORY_OCCUPIED 0
|
||||
#define MEMORY_AVAILABLE 1
|
||||
#define MEMORY_RESERVED 2
|
||||
typedef struct __attribute__((packed))
|
||||
{
|
||||
linked_list_node_t list_node;
|
||||
uint64_t base_addr;
|
||||
uint64_t size;
|
||||
uint32_t type;
|
||||
} memory_descriptor_node_t;
|
||||
|
||||
void*NATIVE64 hal_halloc(size_t const size);
|
||||
|
||||
void NATIVE64 hal_hfree(void *ptr);
|
||||
|
|
|
@ -3,8 +3,7 @@
|
|||
#include "../common/type.h"
|
||||
#include "../common/sys/mem.h"
|
||||
#include "print.h"
|
||||
|
||||
uint64_t text_pos;
|
||||
#include "var.h"
|
||||
|
||||
void NATIVE64 _hal_print_scroll()
|
||||
{
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
#include <stdint.h>
|
||||
#include "var.h"
|
||||
#include "mem.h"
|
||||
#include "../common/util/list/linked_list/linked_list.h"
|
||||
|
||||
uint8_t g_gdt[8*9];
|
||||
uint8_t g_idt[21*16];
|
||||
gdt_ptr_t g_gdt_ptr;
|
||||
idt_ptr_t g_idt_ptr;
|
||||
uint64_t text_pos;
|
||||
linked_list_t mem_desc;
|
|
@ -0,0 +1,14 @@
|
|||
#ifndef _VAR_H_
|
||||
#define _VAR_H_
|
||||
|
||||
#include "mem.h"
|
||||
#include "../common/util/list/linked_list/linked_list.h"
|
||||
|
||||
extern uint8_t g_gdt[8*9];
|
||||
extern uint8_t g_idt[21*16];
|
||||
extern gdt_ptr_t g_gdt_ptr;
|
||||
extern idt_ptr_t g_idt_ptr;
|
||||
extern uint64_t text_pos;
|
||||
extern linked_list_t mem_desc;
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue