huh
This commit is contained in:
parent
e797cc29c2
commit
4032174150
|
@ -5,4 +5,6 @@
|
|||
|
||||
extern uint64_t KAPI k_interlocked_exchange(uint64_t* target, uint64_t val);
|
||||
|
||||
extern void KAPI k_interlocked_increment(uint64_t* target);
|
||||
|
||||
#endif
|
|
@ -86,6 +86,13 @@ lock xchg qword [rdi], rsi
|
|||
mov rax, rsi
|
||||
ret
|
||||
|
||||
; ============================
|
||||
; uint64_t KAPI hal_interlocked_increment(uint64_t* dst);
|
||||
global hal_interlocked_increment
|
||||
hal_interlocked_increment:
|
||||
lock inc qword [rdi]
|
||||
ret
|
||||
|
||||
; ============================
|
||||
; extern void KAPI hal_cpuid(uint32_t* eax, uint32_t* ebx, uint32_t* ecx, uint32_t* edx);
|
||||
global hal_cpuid
|
||||
|
|
|
@ -4,6 +4,11 @@
|
|||
#include "s_context.h"
|
||||
#include "s_intr.h"
|
||||
|
||||
void KAPI k_interlocked_increment(uint64_t* target)
|
||||
{
|
||||
return hal_interlocked_increment(target);
|
||||
}
|
||||
|
||||
uint64_t KAPI k_interlocked_exchange(uint64_t* target, uint64_t val)
|
||||
{
|
||||
return hal_interlocked_exchange(target, val);
|
||||
|
|
|
@ -16,11 +16,12 @@ typedef struct
|
|||
{
|
||||
uint16_t limit;
|
||||
uint64_t base;
|
||||
|
||||
} __attribute__ ((packed)) hal_idt_ptr_t;
|
||||
|
||||
extern uint64_t KAPI hal_interlocked_exchange(uint64_t *dst, uint64_t val);
|
||||
extern void KAPI hal_interlocked_increment(uint64_t* dst);
|
||||
|
||||
extern uint64_t KAPI hal_interlocked_compare_exchange(uint64_t *dst, uint64_t val, uint64_t compare);
|
||||
extern uint64_t KAPI hal_interlocked_exchange(uint64_t *dst, uint64_t val);
|
||||
|
||||
extern void KAPI hal_cpuid(uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx);
|
||||
|
||||
|
|
|
@ -22,27 +22,17 @@
|
|||
// uint32_t attr;
|
||||
//} k_physical_page_attr_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
avl_tree_t active_tree;
|
||||
linked_list_t free_list;
|
||||
k_spin_lock_t lock;
|
||||
_Bool initialized;
|
||||
} k_pmm_descriptor_t;
|
||||
int32_t KAPI k_pmm_init(k_pmm_info_t *info);
|
||||
|
||||
int32_t KAPI k_pmm_init(k_pmm_info_t *info, k_pmm_descriptor_t *desc);
|
||||
int32_t KAPI k_alloc_page(k_physical_addr_t *out);
|
||||
|
||||
int32_t KAPI k_alloc_page(k_pmm_descriptor_t *desc, k_physical_addr_t *out);
|
||||
|
||||
int32_t KAPI k_free_page(k_pmm_descriptor_t *desc, k_physical_addr_t base);
|
||||
int32_t KAPI k_free_page(k_physical_addr_t base);
|
||||
|
||||
// TODO: implement these somehow, i might just reserve the first 16MB for these
|
||||
int32_t KAPI k_alloc_contiguous_pages(k_pmm_descriptor_t *desc,
|
||||
uint64_t num_of_page,
|
||||
int32_t KAPI k_alloc_contiguous_pages(uint64_t num_of_page,
|
||||
k_physical_addr_t highest_p_addr,
|
||||
k_physical_addr_t *out);
|
||||
|
||||
int32_t KAPI k_free_contiguous_pages(k_pmm_descriptor_t *desc,
|
||||
k_physical_addr_t base);
|
||||
int32_t KAPI k_free_contiguous_pages(k_physical_addr_t base);
|
||||
|
||||
#endif
|
|
@ -1,15 +1,31 @@
|
|||
#ifndef _K_REF_H_
|
||||
#define _K_REF_H_
|
||||
|
||||
#include "g_abi.h"
|
||||
#include "g_type.h"
|
||||
#include "avl_tree.h"
|
||||
#include "k_atomic.h"
|
||||
|
||||
typedef void (*k_ref_callback_func_t)(void* ptr, void* context);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
avl_tree_node_t* tree_node;
|
||||
void* ref_ptr;
|
||||
uint32_t ref_count;
|
||||
} k_ref_;
|
||||
avl_tree_t* avl_tree;
|
||||
_Bool initialized;
|
||||
k_spin_lock_t lock;
|
||||
} k_ref_desc_t;
|
||||
|
||||
void k_ref();
|
||||
#define K_REF_STATUS_SUCCESS 0
|
||||
#define K_REF_STATUS_INVALID_ARGUMENTS 1
|
||||
#define K_REF_STATUS_CANNOT_ALLOCATE_MEM 2
|
||||
#define K_REF_STATUS_REF_NOT_FOUND 3
|
||||
|
||||
int32_t KAPI k_ref_init(k_ref_desc_t* desc);
|
||||
|
||||
int32_t KAPI k_ref_create(void* ptr, k_ref_callback_func_t callback, void* context);
|
||||
|
||||
int32_t KAPI k_ref_inc(void* ptr);
|
||||
|
||||
int32_t KAPI k_ref_dec(void* ptr);
|
||||
|
||||
#endif
|
|
@ -10,21 +10,21 @@ static uint8_t _k_alloc_heap[K_KERNEL_HEAP_SIZE];
|
|||
|
||||
void KAPI k_alloc_init()
|
||||
{
|
||||
if(!_k_alloc_initialized)
|
||||
if (!_k_alloc_initialized)
|
||||
{
|
||||
salloc_init(_k_alloc_heap, K_KERNEL_HEAP_SIZE);
|
||||
_k_alloc_initialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
void* KAPI k_alloc(uint32_t size)
|
||||
void *KAPI k_alloc(uint32_t size)
|
||||
{
|
||||
return _k_alloc_initialized ? salloc(_k_alloc_heap, size) : NULL;
|
||||
}
|
||||
|
||||
void KAPI k_free(void* ptr)
|
||||
void KAPI k_free(void *ptr)
|
||||
{
|
||||
if(_k_alloc_initialized)
|
||||
if (_k_alloc_initialized)
|
||||
{
|
||||
sfree(_k_alloc_heap, ptr);
|
||||
}
|
||||
|
|
|
@ -10,6 +10,16 @@ typedef struct
|
|||
//k_physical_page_attr_t attr;
|
||||
} k_physical_page_descriptor_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
avl_tree_t active_tree;
|
||||
linked_list_t free_list;
|
||||
k_spin_lock_t lock;
|
||||
_Bool initialized;
|
||||
} k_pmm_descriptor_t;
|
||||
|
||||
static k_pmm_descriptor_t _pmm_desc;
|
||||
|
||||
/*
|
||||
* A comparison function between tree_node and your_node
|
||||
* Returns:
|
||||
|
@ -33,7 +43,7 @@ static int32_t _avl_compare(avl_tree_node_t *tree_node, avl_tree_node_t *my_node
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t KAPI k_pmm_init(k_pmm_info_t *info, k_pmm_descriptor_t *desc)
|
||||
int32_t KAPI k_pmm_init(k_pmm_info_t *info)
|
||||
{
|
||||
if (info == NULL || desc == NULL || desc->initialized)
|
||||
{
|
||||
|
|
|
@ -1,2 +1,57 @@
|
|||
#include "k_ref.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
avl_tree_node_t tree_node;
|
||||
void* ref_ptr;
|
||||
uint32_t ref_count;
|
||||
k_ref_callback_func_t callback;
|
||||
} k_ref_node_t;
|
||||
|
||||
/*
|
||||
* A comparison function between tree_node and your_node
|
||||
* Returns:
|
||||
* < 0 if tree_node < your_node
|
||||
* = 0 if tree_node == your_node
|
||||
* > 0 if tree_node > your_node
|
||||
*/
|
||||
static int32_t _avl_compare(avl_tree_node_t *tree_node, avl_tree_node_t *my_node)
|
||||
{
|
||||
k_physical_addr_t tree_base = OBTAIN_STRUCT_ADDR(tree_node,
|
||||
k_physical_page_descriptor_t,
|
||||
avl_tree_node)->base;
|
||||
k_physical_addr_t my_base = OBTAIN_STRUCT_ADDR(my_node,
|
||||
k_physical_page_descriptor_t,
|
||||
avl_tree_node)->base;
|
||||
if (tree_base > my_base)
|
||||
return 1;
|
||||
else if (tree_base < my_base)
|
||||
return -1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t KAPI k_ref_init(k_ref_desc_t *desc)
|
||||
{
|
||||
if(desc == NULL)
|
||||
return K_REF_STATUS_INVALID_ARGUMENTS;
|
||||
|
||||
avl_tree_init(&desc->avl_tree);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int32_t KAPI k_ref_create(void *ptr, k_ref_callback_func_t callback, void *context)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t KAPI k_ref_inc(void *ptr)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t KAPI k_ref_dec(void *ptr)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue