Added magic macro
This commit is contained in:
parent
4ee70bf53c
commit
5aa762e101
|
@ -1,13 +1,13 @@
|
|||
#ifndef _LINKED_LIST_H_
|
||||
#define _LINKED_LIST_H_
|
||||
#include "../../../kdef.h"
|
||||
typedef struct __attribute__((packed)) _linked_list_node_t
|
||||
typedef struct _linked_list_node_t
|
||||
{
|
||||
struct _linked_list_node_t * prev;
|
||||
struct _linked_list_node_t * next;
|
||||
} linked_list_node_t;
|
||||
|
||||
typedef struct __attribute__((packed))
|
||||
typedef struct
|
||||
{
|
||||
linked_list_node_t * head;
|
||||
int size;
|
||||
|
@ -23,8 +23,6 @@ linked_list_node_t * NATIVE64 linked_list_get(linked_list_t * list, int index);
|
|||
|
||||
void NATIVE64 linked_list_remove(linked_list_t *list, int index);
|
||||
|
||||
|
||||
|
||||
int NATIVE64 linked_list_node_size(linked_list_node_t * head);
|
||||
|
||||
void NATIVE64 linked_list_node_init(linked_list_node_t * node);
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#define _AVL_TREE_H_
|
||||
#include "../../../kdef.h"
|
||||
|
||||
typedef struct __attribute__((packed)) _avl_tree_node_t
|
||||
typedef struct _avl_tree_node_t
|
||||
{
|
||||
struct _avl_tree_node_t * left;
|
||||
struct _avl_tree_node_t * right;
|
||||
|
@ -10,7 +10,7 @@ typedef struct __attribute__((packed)) _avl_tree_node_t
|
|||
int height;
|
||||
} avl_tree_node_t;
|
||||
|
||||
typedef struct __attribute__((packed))
|
||||
typedef struct
|
||||
{
|
||||
avl_tree_node_t * root;
|
||||
int size;
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
#ifndef _UTIL_H_
|
||||
#define _UTIL_H_
|
||||
#include "../type.h"
|
||||
#define OBTAIN_STRUCT_ADDR(member_addr, member_name, struct_name) ((struct_name*)((char*)(member_addr)-(uint64_t)(&(((struct_name*)0)->member_name))))
|
||||
|
||||
#endif
|
|
@ -5,6 +5,7 @@
|
|||
#include "io.h"
|
||||
#include "var.h"
|
||||
#include "../common/util/list/linked_list/linked_list.h"
|
||||
#include "../common/util/util.h"
|
||||
|
||||
void NATIVE64 hal_init(multiboot_info_t* m_info)
|
||||
{
|
||||
|
@ -46,7 +47,7 @@ void NATIVE64 hal_init(multiboot_info_t* m_info)
|
|||
each_desc->type = MEMORY_AVAILABLE;
|
||||
total_available_mem += (mem_map + i)->len;
|
||||
}
|
||||
linked_list_add(&mem_desc, (linked_list_node_t*)each_desc);
|
||||
linked_list_add(&mem_desc, &each_desc->list_node);
|
||||
}
|
||||
// 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,
|
||||
|
@ -56,7 +57,7 @@ void NATIVE64 hal_init(multiboot_info_t* m_info)
|
|||
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);
|
||||
memory_descriptor_node_t* each_node = OBTAIN_STRUCT_ADDR(linked_list_get(&mem_desc,i), list_node, memory_descriptor_node_t);
|
||||
hal_printf("%d - %d - %s", each_node->base_addr, each_node->size, each_node->type == MEMORY_AVAILABLE ? "Available" : "Reserved");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,12 +87,12 @@ typedef struct __attribute__((packed))
|
|||
#define MEMORY_OCCUPIED 0
|
||||
#define MEMORY_AVAILABLE 1
|
||||
#define MEMORY_RESERVED 2
|
||||
typedef struct __attribute__((packed))
|
||||
typedef struct
|
||||
{
|
||||
linked_list_node_t list_node;
|
||||
uint64_t base_addr;
|
||||
uint64_t size;
|
||||
uint32_t type;
|
||||
linked_list_node_t list_node;
|
||||
} memory_descriptor_node_t;
|
||||
|
||||
void*NATIVE64 hal_halloc(size_t const size);
|
||||
|
|
Loading…
Reference in New Issue