Added generic AVL tree implementation.

Changed calling convention to NATIVEXX(XX = 64/32)
Changed ignore file to not ignore stuff in x64.
This commit is contained in:
HyperAssembler 2015-02-21 02:47:24 -08:00
parent 4271c61388
commit efb2ea6a60
16 changed files with 317 additions and 67 deletions

2
.gitignore vendored
View File

@ -45,8 +45,6 @@ local.properties
[Dd]ebug/
[Rr]elease/
x64/
build/
[Bb]in/
[Oo]bj/

228
x64/src/c/avl_tree.c Normal file
View File

@ -0,0 +1,228 @@
#include <stdint.h>
#include "kdef.h"
#include "avl_tree.h"
int64_t NATIVE64 _max(int64_t a, int64_t b)
{
return (a > b)? a : b;
}
int64_t NATIVE64 _get_height(void * root, int64_t (*get_height)(void*))
{
if(root == NULL)
return -1;
return get_height(root);
}
void *NATIVE64 _right_rotate(void *y,
void *(*get_left)(void *),
void (*set_left)(void *, void *),
void *(*get_right)(void *),
void(*set_right)(void *, void *),
int64_t (*get_height)(void *),
void(*set_height)(void *, int64_t))
{
void *x = get_left(y);
void *T2 = get_right(x);
// Perform rotation
set_right(x,y);
set_left(y,T2);
// Update heights
set_height(y,_max(_get_height(get_left(y),get_height), _get_height(get_right(y),get_height))+1);
set_height(x,_max(_get_height(get_left(x),get_height), _get_height(get_right(x),get_height))+1);
// Return new root
return x;
}
void *NATIVE64 _left_rotate(void *x,
void *(*get_left)(void *),
void (*set_left)(void *, void *),
void *(*get_right)(void *),
void(*set_right)(void *, void *),
int64_t (*get_height)(void *),
void(*set_height)(void *, int64_t))
{
void *y = get_right(x);
void *T2 = get_left(y);
// Perform rotation
set_left(y,x);
set_right(x,T2);
// Update heights
set_height(x, _max(_get_height(get_left(x),get_height), _get_height(get_right(x),get_height))+1);
set_height(y, _max(_get_height(get_left(y),get_height), _get_height(get_right(y),get_height))+1);
// Return new root
return y;
}
// Get Balance factor of node N
int64_t NATIVE64 _get_balance_factor(void *node,
void *(*get_left)(void *),
void *(*get_right)(void *),
int64_t (*get_height)(void *))
{
if (node == NULL)
return 0;
return _get_height(get_left(node),get_height) - _get_height(get_right(node),get_height);
}
void*NATIVE64 insert_node(void *node, void *key,
void *(*get_left)(void *),
void (*set_left)(void *, void *),
void *(*get_right)(void *),
void(*set_right)(void *, void *),
int64_t (*get_height)(void *),
void(*set_height)(void *, int64_t),
int (*compare)(void *, void *))
{
/* 1. Perform the normal BST rotation */
if (node == NULL)
return key;
if (compare(key,node) < 0)
set_left(node, insert_node(get_left(node), key, get_left, set_left, get_right, set_right, get_height, set_height, compare));
else if (compare(key,node) == 0)
return node;
else
set_right(node, insert_node(get_right(node), key, get_left, set_left, get_right, set_right, get_height, set_height, compare));
/* 2. Update height of this ancestor node */
set_height(node, _max(_get_height(get_left(node),get_height), _get_height(get_right(node),get_height)) + 1);
/* 3. Get the balance factor of this ancestor node to check whether
this node became unbalanced */
int64_t balance = _get_balance_factor(node, get_left, get_right, get_height);
// If this node becomes unbalanced, then there are 4 cases
// Left Left Case
if (balance > 1 && compare(key, get_left(node)) < 0)
return _right_rotate(node,get_left,set_left,get_right,set_right,get_height,set_height);
// Right Right Case
if (balance < -1 && compare(key, get_right(node)) > 0)
return _left_rotate(node,get_left,set_left,get_right,set_right,get_height,set_height);
// Left Right Case
if (balance > 1 && compare(key, get_left(node)) > 0)
{
set_left(node, _left_rotate(get_left(node),get_left,set_left,get_right,set_right,get_height,set_height));
return _right_rotate(node,get_left,set_left,get_right,set_right,get_height,set_height);
}
// Right Left Case
if (balance < -1 && compare(key, get_right(node)) < 0)
{
set_right(node, _right_rotate(get_right(node),get_left,set_left,get_right,set_right,get_height,set_height));
return _left_rotate(node,get_left,set_left,get_right,set_right,get_height,set_height);
}
/* return the (unchanged) node pointer */
return node;
}
void*NATIVE64 delete_node(void *root, void *key,
void *(*get_left)(void *),
void (*set_left)(void *, void *),
void *(*get_right)(void *),
void(*set_right)(void *, void *),
int64_t (*get_height)(void *),
void(*set_height)(void *, int64_t),
int (*compare)(void *, void *),
void (*set_data)(void *, void *))
{
// STEP 1: PERFORM STANDARD BST DELETE
if (root == NULL)
return root;
// If the key to be deleted is smaller than the root's key,
// then it lies in left subtree
if ( compare(key,root) < 0 )
set_left(root, delete_node(get_left(root), key, get_left, set_left, get_right, set_right, get_height, set_height, compare, set_data));
// If the key to be deleted is greater than the root's key,
// then it lies in right subtree
else if(compare(key,root) > 0)
set_right(root, delete_node(get_right(root), key, get_left, set_left, get_right, set_right, get_height, set_height, compare, set_data));
// if key is same as root's key, then This is the node
// to be deleted
else
{
// node with only one child or no child
if( (get_left(root) == NULL) || (get_right(root) == NULL) )
{
void *temp = get_left(root) != NULL ? get_left(root) : get_right(root);
// No child case
if(temp == NULL)
{
temp = root;
root = NULL;
}
else // One child case
{
set_height(root,_get_height(temp,get_height));
set_left(root, get_left(temp));
set_right(root,get_right(temp));
set_data(root, temp);
}
//free(temp);
}
else
{
// node with two children: Get the inorder successor (smallest
// in the right subtree)
void* temp = get_right(root);
while(get_left(temp) != NULL)
temp = get_left(temp);
// Copy the inorder successor's data to this node
set_data(root, temp);
// Delete the inorder successor
set_right(root, delete_node(get_right(root), temp, get_left, set_left, get_right, set_right, get_height, set_height, compare, set_data));
}
}
// If the tree had only one node then return
if (root == NULL)
return root;
// STEP 2: UPDATE HEIGHT OF THE CURRENT NODE
set_height(root, _max(_get_height(get_left(root),get_height), _get_height(get_right(root),get_height)) + 1);
// STEP 3: GET THE BALANCE FACTOR OF THIS NODE (to check whether
// this node became unbalanced)
int64_t balance = _get_balance_factor(root,get_left,get_right,get_height);
// If this node becomes unbalanced, then there are 4 cases
// Left Left Case
if (balance > 1 && _get_balance_factor(get_left(root),get_left,get_right,get_height) >= 0)
return _right_rotate(root,get_left,set_left,get_right,set_right,get_height,set_height);
// Left Right Case
if (balance > 1 && _get_balance_factor(get_left(root),get_left,get_right,get_height) < 0)
{
set_left(root,_left_rotate(get_left(root),get_left,set_left,get_right,set_right,get_height,set_height));
return _right_rotate(root,get_left,set_left,get_right,set_right,get_height,set_height);
}
// Right Right Case
if (balance < -1 && _get_balance_factor(get_right(root),get_left,get_right,get_height) <= 0)
return _left_rotate(root,get_left,set_left,get_right,set_right,get_height,set_height);
// Right Left Case
if (balance < -1 && _get_balance_factor(get_right(root),get_left,get_right,get_height) > 0)
{
set_right(root, _right_rotate(get_right(root),get_left,set_left,get_right,set_right,get_height,set_height));
return _left_rotate(root,get_left,set_left,get_right,set_right,get_height,set_height);
}
return root;
}

24
x64/src/c/avl_tree.h Normal file
View File

@ -0,0 +1,24 @@
#ifndef _AVL_TREE_H_
#define _AVL_TREE_H_
#include <stdint.h>
#include "kdef.h"
void*NATIVE64 insert_node(void *node, void *key,
void *(*get_left)(void *),
void (*set_left)(void *, void *),
void *(*get_right)(void *),
void(*set_right)(void *, void *),
int64_t (*get_height)(void *),
void(*set_height)(void *, int64_t),
int (*compare)(void *, void *));
void*NATIVE64 delete_node(void *root, void *key,
void *(*get_left)(void *),
void (*set_left)(void *, void *),
void *(*get_right)(void *),
void(*set_right)(void *, void *),
int64_t (*get_height)(void *),
void(*set_height)(void *, int64_t),
int (*compare)(void *, void *),
void (*set_data)(void *, void *));
#endif

View File

@ -8,10 +8,10 @@ gdt_ptr_t g_gdt_ptr;
extern uint64_t text_pos;
extern char kernel_start[];
extern char kernel_end[];
extern void HYPKERNEL64 HLT_CPU(void);
extern void HYPKERNEL64 BOCHS_MAGIC_BREAKPOINT();
extern void HYPKERNEL64 hk_flush_gdt(gdt_ptr_t* gdt_ptr, uint64_t code_slct, uint64_t data_slct);
void HYPKERNEL64 hk_main(multiboot_info_t* multiboot_info)
extern void NATIVE64 HLT_CPU(void);
extern void NATIVE64 BOCHS_MAGIC_BREAKPOINT();
extern void NATIVE64 hk_flush_gdt(gdt_ptr_t* gdt_ptr, uint64_t code_slct, uint64_t data_slct);
void NATIVE64 hk_main(multiboot_info_t* multiboot_info)
{
text_pos = get_pos(3, 0);
hk_printf("Kernel Start: 0x%X. End: 0x%X. Size: %dB, %dKB\n\n", (uint64_t)kernel_start, (uint64_t)kernel_end, (uint64_t)kernel_end - (uint64_t)kernel_start,((uint64_t)kernel_end - (uint64_t)kernel_start)/1024);

View File

@ -2,6 +2,6 @@
#define _IO_H_
#include "kdef.h"
#include "type.h"
extern void HYPKERNEL64 hk_write_port(uint64_t port, int64_t data);
extern int64_t HYPKERNEL64 hk_read_port(uint64_t port);
extern void NATIVE64 hk_write_port(uint64_t port, int64_t data);
extern int64_t NATIVE64 hk_read_port(uint64_t port);
#endif

View File

@ -1,7 +1,7 @@
#ifndef _KDEF_H_
#define _KDEF_H_
#define HYPKERNEL64 __attribute__((sysv_abi))
#define NATIVE64 __attribute__((sysv_abi))
#define SEG_SELECTOR(Index,RPL) (((Index) << 3) + (RPL))

View File

@ -6,7 +6,7 @@
char* _cur_heap = NULL;
extern char kernel_heap[kernel_heap_size];
void HYPKERNEL64 hk_write_pt_entry(void * const base, uint64_t const p_addr, uint64_t const attr)
void NATIVE64 hk_write_pt_entry(void * const base, uint64_t const p_addr, uint64_t const attr)
{
if(base == NULL)
return;
@ -22,7 +22,7 @@ void HYPKERNEL64 hk_write_pt_entry(void * const base, uint64_t const p_addr, uin
return;
}
void HYPKERNEL64 hk_write_pd_entry(void * const base, uint64_t const pt_addr, uint64_t const attr)
void NATIVE64 hk_write_pd_entry(void * const base, uint64_t const pt_addr, uint64_t const attr)
{
if(base == NULL)
return;
@ -38,7 +38,7 @@ void HYPKERNEL64 hk_write_pd_entry(void * const base, uint64_t const pt_addr, ui
return;
}
void HYPKERNEL64 hk_write_pdpt_entry(void * const base, uint64_t const pd_addr, uint64_t const attr)
void NATIVE64 hk_write_pdpt_entry(void * const base, uint64_t const pd_addr, uint64_t const attr)
{
if(base == NULL)
return;
@ -54,7 +54,7 @@ void HYPKERNEL64 hk_write_pdpt_entry(void * const base, uint64_t const pd_addr,
return;
}
void HYPKERNEL64 hk_write_pml4_entry(void * const base, uint64_t const pdpt_addr, uint64_t const attr)
void NATIVE64 hk_write_pml4_entry(void * const base, uint64_t const pdpt_addr, uint64_t const attr)
{
if(base == NULL)
return;
@ -70,7 +70,7 @@ void HYPKERNEL64 hk_write_pml4_entry(void * const base, uint64_t const pdpt_addr
return;
}
void HYPKERNEL64 hk_write_segment_descriptor(void * const gdt, uint32_t const base, uint32_t const limit, uint64_t const attr)
void NATIVE64 hk_write_segment_descriptor(void * const gdt, uint32_t const base, uint32_t const limit, uint64_t const attr)
{
if (gdt == NULL)
return;
@ -86,7 +86,7 @@ void HYPKERNEL64 hk_write_segment_descriptor(void * const gdt, uint32_t const ba
return;
}
uint64_t HYPKERNEL64 hk_map_page(void * const base, uint64_t const p_addr, uint64_t const v_addr, uint64_t const attr, uint64_t const availableRam)
uint64_t NATIVE64 hk_map_page(void * const base, uint64_t const p_addr, uint64_t const v_addr, uint64_t const attr, uint64_t const availableRam)
{
//wait a sec, we actually need maximum memory information here for effectively map crap
if(base == NULL || p_addr << 52 || v_addr << 52)
@ -126,7 +126,7 @@ uint64_t HYPKERNEL64 hk_map_page(void * const base, uint64_t const p_addr, uint6
return 0;
}
void HYPKERNEL64 hk_mem_cpy(void* src, void* dst, uint64_t size)
void NATIVE64 hk_mem_cpy(void* src, void* dst, uint64_t size)
{
if (src == NULL || dst == NULL)
return;
@ -137,7 +137,7 @@ void HYPKERNEL64 hk_mem_cpy(void* src, void* dst, uint64_t size)
return;
}
void HYPKERNEL64 hk_mem_set(void* src, int8_t const val,uint64_t size)
void NATIVE64 hk_mem_set(void* src, int8_t const val,uint64_t size)
{
if (src == NULL)
return;
@ -146,7 +146,7 @@ void HYPKERNEL64 hk_mem_set(void* src, int8_t const val,uint64_t size)
return;
}
void HYPKERNEL64 hk_mem_move(void* src, void* dst, uint64_t size)
void NATIVE64 hk_mem_move(void* src, void* dst, uint64_t size)
{
if (src == NULL || dst == NULL)
return;
@ -161,7 +161,7 @@ void HYPKERNEL64 hk_mem_move(void* src, void* dst, uint64_t size)
return;
}
void* HYPKERNEL64 hk_heap_alloc(uint64_t const size)
void*NATIVE64 hk_heap_alloc(uint64_t const size)
{
if(_cur_heap == NULL)
_cur_heap = kernel_heap;

View File

@ -77,24 +77,24 @@ typedef struct __attribute__((packed)) _mem_block
struct _mem_block * next;
} mem_block;
void* HYPKERNEL64 hk_heap_alloc(uint64_t const size);
void*NATIVE64 hk_heap_alloc(uint64_t const size);
void HYPKERNEL64 hk_write_segment_descriptor(void *const gdt, uint32_t const base, uint32_t const limit, uint64_t const attr);
void NATIVE64 hk_write_segment_descriptor(void *const gdt, uint32_t const base, uint32_t const limit, uint64_t const attr);
//extern void HYPKERNEL64 hk_load_gdt(gdt_ptr_t const *const ptr, uint16_t const sel_code, uint16_t const sel_data);
//extern void NATIVE64 hk_load_gdt(gdt_ptr_t const *const ptr, uint16_t const sel_code, uint16_t const sel_data);
void HYPKERNEL64 hk_mem_cpy(void *src, void *dst, uint64_t size);
void NATIVE64 hk_mem_cpy(void *src, void *dst, uint64_t size);
void HYPKERNEL64 hk_mem_move(void *src, void *dst, uint64_t size);
void NATIVE64 hk_mem_move(void *src, void *dst, uint64_t size);
void HYPKERNEL64 hk_mem_set(void *src, int8_t const val, uint64_t size);
void NATIVE64 hk_mem_set(void *src, int8_t const val, uint64_t size);
void HYPKERNEL64 hk_write_pml4_entry(void *const base, uint64_t const pdpt_addr, uint64_t const attr);
void NATIVE64 hk_write_pml4_entry(void *const base, uint64_t const pdpt_addr, uint64_t const attr);
void HYPKERNEL64 hk_write_pdpt_entry(void *const base, uint64_t const pd_addr, uint64_t const attr);
void NATIVE64 hk_write_pdpt_entry(void *const base, uint64_t const pd_addr, uint64_t const attr);
void HYPKERNEL64 hk_write_pd_entry(void *const base, uint64_t const pt_addr, uint64_t const attr);
void NATIVE64 hk_write_pd_entry(void *const base, uint64_t const pt_addr, uint64_t const attr);
void HYPKERNEL64 hk_write_pt_entry(void *const base, uint64_t const p_addr, uint64_t const attr);
void NATIVE64 hk_write_pt_entry(void *const base, uint64_t const p_addr, uint64_t const attr);
#endif

View File

@ -6,7 +6,7 @@
uint64_t text_pos;
uint64_t HYPKERNEL64 hk_str_len(char const * str)
uint64_t NATIVE64 hk_str_len(char const * str)
{
uint64_t length = 0;
if(str == NULL)
@ -19,7 +19,7 @@ uint64_t HYPKERNEL64 hk_str_len(char const * str)
return length;
}
uint64_t HYPKERNEL64 hk_str_cmp(char const * str1,char const * str2)
uint64_t NATIVE64 hk_str_cmp(char const * str1,char const * str2)
{
if(str1 == NULL || str2 == NULL)
return 0;
@ -34,13 +34,13 @@ uint64_t HYPKERNEL64 hk_str_cmp(char const * str1,char const * str2)
return 1;
}
void HYPKERNEL64 hk_print_scroll()
void NATIVE64 hk_print_scroll()
{
hk_mem_move((void*)(0xb8000 + get_pos(1,0) * 2), (void*)(0xb8000 + get_pos(0,0) * 2), (80*24)*2);
return;
}
void HYPKERNEL64 _print_str(char const *str)
void NATIVE64 _print_str(char const *str)
{
if(str == NULL)
return;
@ -75,7 +75,7 @@ void HYPKERNEL64 _print_str(char const *str)
return;
}
void HYPKERNEL64 _print_uint(uint64_t number)
void NATIVE64 _print_uint(uint64_t number)
{
char arr[21]; // do not need to initialize
arr[20] = 0; //zero-terminated
@ -94,7 +94,7 @@ void HYPKERNEL64 _print_uint(uint64_t number)
return;
}
void HYPKERNEL64 _print_int(int64_t number)
void NATIVE64 _print_int(int64_t number)
{
char arr[21]; // do not need to initialize
arr[20] = 0; //zero-terminated
@ -123,7 +123,7 @@ void HYPKERNEL64 _print_int(int64_t number)
return;
}
void HYPKERNEL64 _print_hex(uint64_t number, uint64_t capital)
void NATIVE64 _print_hex(uint64_t number, uint64_t capital)
{
char const lookup_table_cap[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
char const lookup_table[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
@ -145,14 +145,14 @@ void HYPKERNEL64 _print_hex(uint64_t number, uint64_t capital)
return;
}
void HYPKERNEL64 hk_clear_screen(void)
void NATIVE64 hk_clear_screen(void)
{
text_pos = 0; // reset text_pos
hk_mem_set((void*)0xb8000, 0, 25*80*2);
return;
}
void HYPKERNEL64 hk_printf(char const *format, ...)
void NATIVE64 hk_printf(char const *format, ...)
{
va_list args;
va_start(args, format);

View File

@ -7,9 +7,9 @@
#define get_row(pos) (pos / 80)
#define get_pos(row,col) ((row) * 80 + (col))
void HYPKERNEL64 hk_clear_screen(void);
uint64_t HYPKERNEL64 hk_str_len(char const * str);
uint64_t HYPKERNEL64 hk_str_cmp(char const * str1,char const * str2);
void HYPKERNEL64 hk_printf(char const *format, ...);
void NATIVE64 hk_clear_screen(void);
uint64_t NATIVE64 hk_str_len(char const * str);
uint64_t NATIVE64 hk_str_cmp(char const * str1,char const * str2);
void NATIVE64 hk_printf(char const *format, ...);
#endif

View File

@ -15,7 +15,7 @@ extern void HLT_CPU(void);
extern char kernel_start[];
extern char kernel_end[];
void HYPKERNEL32 hk_main(multiboot_info_t* multiboot_info)
void NATIVE32 hk_main(multiboot_info_t* multiboot_info)
{
//init text_position
text_pos = 0;

View File

@ -1,7 +1,7 @@
#ifndef _KDEF_H_
#define _KDEF_H_
#define HYPKERNEL32 __attribute__((cdecl))
#define NATIVE32 __attribute__((cdecl))
#define NULL ((void*)0)

View File

@ -1,7 +1,7 @@
#include "kdef.h"
#include "mem.h"
void HYPKERNEL32 hk_write_segment_descriptor(void * const gdt, uint32_t const base, uint32_t const limit, uint64_t const attr)
void NATIVE32 hk_write_segment_descriptor(void * const gdt, uint32_t const base, uint32_t const limit, uint64_t const attr)
{
if (gdt == NULL)
return;
@ -17,7 +17,7 @@ void HYPKERNEL32 hk_write_segment_descriptor(void * const gdt, uint32_t const ba
return;
}
void HYPKERNEL32 hk_mem_cpy(void* src, void* dst, uint32_t size)
void NATIVE32 hk_mem_cpy(void* src, void* dst, uint32_t size)
{
if (src == NULL || dst == NULL)
return;
@ -28,7 +28,7 @@ void HYPKERNEL32 hk_mem_cpy(void* src, void* dst, uint32_t size)
return;
}
void HYPKERNEL32 hk_mem_set(void* src, int8_t const val,uint32_t size)
void NATIVE32 hk_mem_set(void* src, int8_t const val,uint32_t size)
{
if (src == NULL)
return;
@ -38,7 +38,7 @@ void HYPKERNEL32 hk_mem_set(void* src, int8_t const val,uint32_t size)
return;
}
void HYPKERNEL32 hk_mem_move(void* src, void* dst, uint32_t size)
void NATIVE32 hk_mem_move(void* src, void* dst, uint32_t size)
{
if (src == NULL || dst == NULL)
return;

View File

@ -38,12 +38,12 @@ typedef struct __attribute__ ((packed))
uint32_t base;
} idt_ptr_t;
void HYPKERNEL32 hk_write_segment_descriptor(void *const gdt, uint32_t const base, uint32_t const limit, uint64_t const attr);
extern void HYPKERNEL32 hk_load_gdt(gdt_ptr_t const * const ptr, uint16_t const sel_code, uint16_t const sel_data);
void HYPKERNEL32 hk_mem_cpy(void* src, void* dst, uint32_t size);
void HYPKERNEL32 hk_mem_move(void* src, void* dst, uint32_t size);
extern int32_t HYPKERNEL32 hk_support_x64(void);
void NATIVE32 hk_write_segment_descriptor(void *const gdt, uint32_t const base, uint32_t const limit, uint64_t const attr);
extern void NATIVE32 hk_load_gdt(gdt_ptr_t const * const ptr, uint16_t const sel_code, uint16_t const sel_data);
void NATIVE32 hk_mem_cpy(void* src, void* dst, uint32_t size);
void NATIVE32 hk_mem_move(void* src, void* dst, uint32_t size);
extern int32_t NATIVE32 hk_support_x64(void);
extern void hk_disable_paging(void);
extern void hk_enable_paging(void);
void HYPKERNEL32 hk_mem_set(void* src, int8_t const val,uint32_t size);
void NATIVE32 hk_mem_set(void* src, int8_t const val,uint32_t size);
#endif

View File

@ -6,7 +6,7 @@
uint32_t text_pos;
uint32_t HYPKERNEL32 hk_str_len(char const *str)
uint32_t NATIVE32 hk_str_len(char const *str)
{
uint32_t length = 0;
if (str == NULL)
@ -19,7 +19,7 @@ uint32_t HYPKERNEL32 hk_str_len(char const *str)
return length;
}
uint32_t HYPKERNEL32 hk_str_cmp(char const *str1, char const *str2)
uint32_t NATIVE32 hk_str_cmp(char const *str1, char const *str2)
{
if (str1 == NULL || str2 == NULL)
return 0;
@ -34,13 +34,13 @@ uint32_t HYPKERNEL32 hk_str_cmp(char const *str1, char const *str2)
return 1;
}
void HYPKERNEL32 hk_print_scroll()
void NATIVE32 hk_print_scroll()
{
hk_mem_move((void *) (0xb8000 + get_pos(1, 0) * 2), (void *) (0xb8000 + get_pos(0, 0) * 2), (80 * 24) * 2);
return;
}
void HYPKERNEL32 _print_str(char const *str)
void NATIVE32 _print_str(char const *str)
{
if (str == NULL)
return;
@ -75,7 +75,7 @@ void HYPKERNEL32 _print_str(char const *str)
return;
}
void HYPKERNEL32 _print_uint(uint32_t number)
void NATIVE32 _print_uint(uint32_t number)
{
char arr[11]; // do not need to initialize
arr[10] = 0; //zero-terminated
@ -96,7 +96,7 @@ void HYPKERNEL32 _print_uint(uint32_t number)
}
void HYPKERNEL32 _print_int(int32_t number)
void NATIVE32 _print_int(int32_t number)
{
char arr[12]; // do not need to initialize
arr[11] = 0; //zero-terminated
@ -128,7 +128,7 @@ void HYPKERNEL32 _print_int(int32_t number)
return;
}
void HYPKERNEL32 _print_hex(uint32_t number, uint32_t captial)
void NATIVE32 _print_hex(uint32_t number, uint32_t captial)
{
char const lookup_table_cap[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
char const lookup_table[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
@ -151,7 +151,7 @@ void HYPKERNEL32 _print_hex(uint32_t number, uint32_t captial)
}
void HYPKERNEL32 hk_clear_screen(void)
void NATIVE32 hk_clear_screen(void)
{
text_pos = 0; // reset text_pos
hk_mem_set((void *) 0xb8000, 0, 25 * 80 * 2);
@ -159,7 +159,7 @@ void HYPKERNEL32 hk_clear_screen(void)
}
void HYPKERNEL32 hk_printf(char const *format, ...)
void NATIVE32 hk_printf(char const *format, ...)
{
va_list args;
va_start(args, format);

View File

@ -7,8 +7,8 @@
#define get_row(pos) (pos / 80)
#define get_pos(row,col) ((row) * 80 + (col))
void HYPKERNEL32 hk_printf(char const *format, ...);
uint32_t HYPKERNEL32 hk_str_len(char const * str);
uint32_t HYPKERNEL32 hk_str_cmp(char const * str1,char const * str2);
void HYPKERNEL32 hk_clear_screen(void);
void NATIVE32 hk_printf(char const *format, ...);
uint32_t NATIVE32 hk_str_len(char const * str);
uint32_t NATIVE32 hk_str_cmp(char const * str1,char const * str2);
void NATIVE32 hk_clear_screen(void);
#endif