Just renaming some functions.
This commit is contained in:
parent
efb2ea6a60
commit
3f7297a2a7
|
@ -1,4 +1,4 @@
|
|||
extern hk_main
|
||||
extern kmain
|
||||
global HLT_CPU
|
||||
global BOCHS_MAGIC_BREAKPOINT
|
||||
global kernel_heap
|
||||
|
@ -113,7 +113,7 @@ mov ss,ax
|
|||
|
||||
; align 16 bytes like this for now
|
||||
mov rsp,KERNEL_STACK
|
||||
call hk_main
|
||||
call kmain
|
||||
hlt
|
||||
|
||||
HLT_CPU:
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
global hk_write_port
|
||||
global hk_read_port
|
||||
global write_port
|
||||
global read_port
|
||||
[SECTION .text]
|
||||
[BITS 64]
|
||||
hk_write_port:
|
||||
write_port:
|
||||
mov rdx,rdi
|
||||
mov rax,rsi
|
||||
out dx,eax
|
||||
|
@ -10,7 +10,7 @@ nop
|
|||
nop
|
||||
ret
|
||||
|
||||
hk_read_port:
|
||||
read_port:
|
||||
mov rdx,rdi
|
||||
xor rax,rax
|
||||
in eax,dx
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
global hk_flush_gdt
|
||||
global hk_flush_tlb
|
||||
global flush_gdt
|
||||
global flush_tlb
|
||||
;Functions preserve the registers rbx, rsp, rbp, r12, r13, r14, and 15
|
||||
;rax, rdi, rsi, rdx, rcx, r8, r9, r10, r11 are scratch registers.
|
||||
|
||||
[SECTION .text]
|
||||
[BITS 64]
|
||||
hk_flush_gdt:
|
||||
flush_gdt:
|
||||
push rbp
|
||||
mov rbp,rsp
|
||||
lgdt [rdi]
|
||||
|
@ -19,7 +19,7 @@ pop rax
|
|||
push rax ; eflags
|
||||
|
||||
push rsi ; cs
|
||||
push qword hk_flush_gdt.reload ;eip
|
||||
push qword flush_gdt.reload ;eip
|
||||
iretq
|
||||
.reload:
|
||||
mov es,dx
|
||||
|
@ -30,8 +30,8 @@ mov rsp,rbp
|
|||
pop rbp
|
||||
ret
|
||||
|
||||
;void hk_flush_tlb(void)
|
||||
hk_flush_tlb:
|
||||
;void flush_tlb(void)
|
||||
flush_tlb:
|
||||
mov rax,cr3
|
||||
mov cr3,rax
|
||||
ret
|
|
@ -1,4 +1,4 @@
|
|||
#include <stdint.h>
|
||||
#include "type.h"
|
||||
#include "kdef.h"
|
||||
#include "avl_tree.h"
|
||||
|
||||
|
@ -71,7 +71,7 @@ int64_t NATIVE64 _get_balance_factor(void *node,
|
|||
return _get_height(get_left(node),get_height) - _get_height(get_right(node),get_height);
|
||||
}
|
||||
|
||||
void*NATIVE64 insert_node(void *node, void *key,
|
||||
void*NATIVE64 avl_insert_node(void *node, void *key,
|
||||
void *(*get_left)(void *),
|
||||
void (*set_left)(void *, void *),
|
||||
void *(*get_right)(void *),
|
||||
|
@ -84,11 +84,11 @@ void*NATIVE64 insert_node(void *node, void *key,
|
|||
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));
|
||||
set_left(node, avl_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));
|
||||
set_right(node, avl_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);
|
||||
|
@ -124,7 +124,7 @@ void*NATIVE64 insert_node(void *node, void *key,
|
|||
return node;
|
||||
}
|
||||
|
||||
void*NATIVE64 delete_node(void *root, void *key,
|
||||
void*NATIVE64 avl_delete_node(void *root, void *key,
|
||||
void *(*get_left)(void *),
|
||||
void (*set_left)(void *, void *),
|
||||
void *(*get_right)(void *),
|
||||
|
@ -141,12 +141,12 @@ void*NATIVE64 delete_node(void *root, void *key,
|
|||
// 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));
|
||||
set_left(root, avl_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));
|
||||
set_right(root, avl_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
|
||||
|
@ -185,7 +185,7 @@ void*NATIVE64 delete_node(void *root, void *key,
|
|||
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));
|
||||
set_right(root, avl_delete_node(get_right(root), temp, get_left, set_left, get_right, set_right, get_height, set_height, compare, set_data));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include <stdint.h>
|
||||
#include "kdef.h"
|
||||
|
||||
void*NATIVE64 insert_node(void *node, void *key,
|
||||
void*NATIVE64 avl_insert_node(void *node, void *key,
|
||||
void *(*get_left)(void *),
|
||||
void (*set_left)(void *, void *),
|
||||
void *(*get_right)(void *),
|
||||
|
@ -12,7 +12,7 @@ void*NATIVE64 insert_node(void *node, void *key,
|
|||
void(*set_height)(void *, int64_t),
|
||||
int (*compare)(void *, void *));
|
||||
|
||||
void*NATIVE64 delete_node(void *root, void *key,
|
||||
void*NATIVE64 avl_delete_node(void *root, void *key,
|
||||
void *(*get_left)(void *),
|
||||
void (*set_left)(void *, void *),
|
||||
void *(*get_right)(void *),
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "type.h"
|
||||
#include "kdef.h"
|
||||
#include "print.h"
|
||||
#include "mem.h"
|
||||
#include "mm.h"
|
||||
#include "multiboot.h"
|
||||
uint8_t g_gdt[8*9];
|
||||
gdt_ptr_t g_gdt_ptr;
|
||||
|
@ -10,39 +10,39 @@ extern char kernel_start[];
|
|||
extern char kernel_end[];
|
||||
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)
|
||||
extern void NATIVE64 flush_gdt(gdt_ptr_t *gdt_ptr, uint64_t code_slct, uint64_t data_slct);
|
||||
void NATIVE64 kmain(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);
|
||||
hk_printf("*Setting up GDT...");
|
||||
hk_write_segment_descriptor((void*)&g_gdt[0], 0, 0, 0);
|
||||
hk_write_segment_descriptor((void*)&g_gdt[8], 0, 0, SEG_DPL_0 | SEG_CODE_DATA | SEG_PRESENT | SEG_LONG | SEG_TYPE_CODE_X);
|
||||
hk_write_segment_descriptor((void*)&g_gdt[16], 0, 0, SEG_DPL_0 | SEG_CODE_DATA | SEG_PRESENT | SEG_LONG | SEG_TYPE_DATA_RW);
|
||||
hk_write_segment_descriptor((void*)&g_gdt[24], 0, 0, SEG_DPL_3 | SEG_CODE_DATA | SEG_PRESENT | SEG_LONG | SEG_TYPE_CODE_X);
|
||||
hk_write_segment_descriptor((void*)&g_gdt[32], 0, 0, SEG_DPL_3 | SEG_CODE_DATA | SEG_PRESENT | SEG_LONG | SEG_TYPE_DATA_RW);
|
||||
kprintf("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);
|
||||
kprintf("*Setting up GDT...");
|
||||
write_segment_descriptor((void *) &g_gdt[0], 0, 0, 0);
|
||||
write_segment_descriptor((void *) &g_gdt[8], 0, 0, SEG_DPL_0 | SEG_CODE_DATA | SEG_PRESENT | SEG_LONG | SEG_TYPE_CODE_X);
|
||||
write_segment_descriptor((void *) &g_gdt[16], 0, 0, SEG_DPL_0 | SEG_CODE_DATA | SEG_PRESENT | SEG_LONG | SEG_TYPE_DATA_RW);
|
||||
write_segment_descriptor((void *) &g_gdt[24], 0, 0, SEG_DPL_3 | SEG_CODE_DATA | SEG_PRESENT | SEG_LONG | SEG_TYPE_CODE_X);
|
||||
write_segment_descriptor((void *) &g_gdt[32], 0, 0, SEG_DPL_3 | SEG_CODE_DATA | SEG_PRESENT | SEG_LONG | SEG_TYPE_DATA_RW);
|
||||
|
||||
hk_write_segment_descriptor((void*)&g_gdt[40], 0, 0xFFFFF, SEG_DPL_0 | SEG_GRANULARITY | SEG_CODE_DATA | SEG_PRESENT | SEG_32_BITS | SEG_TYPE_CODE_X);
|
||||
hk_write_segment_descriptor((void*)&g_gdt[48], 0, 0xFFFFF, SEG_DPL_0 | SEG_GRANULARITY | SEG_CODE_DATA | SEG_PRESENT | SEG_32_BITS | SEG_TYPE_DATA_RW);
|
||||
hk_write_segment_descriptor((void*)&g_gdt[56], 0, 0xFFFFF, SEG_DPL_3 | SEG_GRANULARITY | SEG_CODE_DATA | SEG_PRESENT | SEG_32_BITS | SEG_TYPE_CODE_X);
|
||||
hk_write_segment_descriptor((void*)&g_gdt[64], 0, 0xFFFFF, SEG_DPL_3 | SEG_GRANULARITY | SEG_CODE_DATA | SEG_PRESENT | SEG_32_BITS | SEG_TYPE_DATA_RW);
|
||||
write_segment_descriptor((void *) &g_gdt[40], 0, 0xFFFFF, SEG_DPL_0 | SEG_GRANULARITY | SEG_CODE_DATA | SEG_PRESENT | SEG_32_BITS | SEG_TYPE_CODE_X);
|
||||
write_segment_descriptor((void *) &g_gdt[48], 0, 0xFFFFF, SEG_DPL_0 | SEG_GRANULARITY | SEG_CODE_DATA | SEG_PRESENT | SEG_32_BITS | SEG_TYPE_DATA_RW);
|
||||
write_segment_descriptor((void *) &g_gdt[56], 0, 0xFFFFF, SEG_DPL_3 | SEG_GRANULARITY | SEG_CODE_DATA | SEG_PRESENT | SEG_32_BITS | SEG_TYPE_CODE_X);
|
||||
write_segment_descriptor((void *) &g_gdt[64], 0, 0xFFFFF, SEG_DPL_3 | SEG_GRANULARITY | SEG_CODE_DATA | SEG_PRESENT | SEG_32_BITS | SEG_TYPE_DATA_RW);
|
||||
|
||||
g_gdt_ptr.base = (uint64_t)g_gdt;
|
||||
g_gdt_ptr.limit = 8*9-1;
|
||||
hk_flush_gdt(&g_gdt_ptr, SEG_SELECTOR(1, 0), SEG_SELECTOR(2, 0));
|
||||
hk_printf("Done.\n\n");
|
||||
flush_gdt(&g_gdt_ptr, SEG_SELECTOR(1, 0), SEG_SELECTOR(2, 0));
|
||||
kprintf("Done.\n\n");
|
||||
|
||||
hk_printf("*Checking memory information...\n");
|
||||
kprintf("*Checking memory information...\n");
|
||||
if(multiboot_info->flags & (1 << 6))
|
||||
{
|
||||
multiboot_memory_map_t const *mem_map = (multiboot_memory_map_t *) multiboot_info->mmap_addr;
|
||||
uint64_t const mem_map_size = multiboot_info->mmap_length / sizeof(multiboot_memory_map_t);
|
||||
hk_printf("BaseAddr - Length - Type\n");
|
||||
kprintf("BaseAddr - Length - Type\n");
|
||||
uint64_t total_available_mem = 0;
|
||||
uint64_t total_reserved_mem = 0;
|
||||
for (uint64_t i = 0; i < mem_map_size; i++)
|
||||
{
|
||||
hk_printf("0x%X - 0x%X - 0x%x\n",(mem_map + i)->addr,(mem_map + i)->len,(mem_map + i)->type);
|
||||
kprintf("0x%X - 0x%X - 0x%x\n", (mem_map + i)->addr, (mem_map + i)->len, (mem_map + i)->type);
|
||||
if((mem_map + i)->type == MULTIBOOT_MEMORY_RESERVED)
|
||||
{
|
||||
total_reserved_mem += (mem_map + i)->len;
|
||||
|
@ -52,12 +52,12 @@ void NATIVE64 hk_main(multiboot_info_t* multiboot_info)
|
|||
total_available_mem += (mem_map + i)->len;
|
||||
}
|
||||
}
|
||||
hk_printf("Total available memory: %uB, %uKB, %uMB.\n",total_available_mem,total_available_mem/1024,total_available_mem/1024/1024);
|
||||
hk_printf("Total reserved memory: %uB, %uKB, %uMB.\n\n", total_reserved_mem, total_reserved_mem/1024, total_reserved_mem/1024/1024);
|
||||
kprintf("Total available memory: %uB, %uKB, %uMB.\n", total_available_mem, total_available_mem / 1024, total_available_mem / 1024 / 1024);
|
||||
kprintf("Total reserved memory: %uB, %uKB, %uMB.\n\n", total_reserved_mem, total_reserved_mem / 1024, total_reserved_mem / 1024 / 1024);
|
||||
}
|
||||
else
|
||||
{
|
||||
hk_printf("Memory information is currently unavailable.\n\n");
|
||||
kprintf("Memory information is currently unavailable.\n\n");
|
||||
}
|
||||
HLT_CPU();
|
||||
}
|
||||
|
|
|
@ -2,6 +2,6 @@
|
|||
#define _IO_H_
|
||||
#include "kdef.h"
|
||||
#include "type.h"
|
||||
extern void NATIVE64 hk_write_port(uint64_t port, int64_t data);
|
||||
extern int64_t NATIVE64 hk_read_port(uint64_t port);
|
||||
extern void NATIVE64 write_port(uint64_t port, int64_t data);
|
||||
extern int64_t NATIVE64 read_port(uint64_t port);
|
||||
#endif
|
|
@ -1,12 +1,11 @@
|
|||
#include "kdef.h"
|
||||
#include "mem.h"
|
||||
|
||||
#include "mm.h"
|
||||
|
||||
#define kernel_heap_size 4096
|
||||
char* _cur_heap = NULL;
|
||||
extern char kernel_heap[kernel_heap_size];
|
||||
|
||||
void NATIVE64 hk_write_pt_entry(void * const base, uint64_t const p_addr, uint64_t const attr)
|
||||
void NATIVE64 write_pt_entry(void *const base, uint64_t const p_addr, uint64_t const attr)
|
||||
{
|
||||
if(base == NULL)
|
||||
return;
|
||||
|
@ -22,7 +21,7 @@ void NATIVE64 hk_write_pt_entry(void * const base, uint64_t const p_addr, uint64
|
|||
return;
|
||||
}
|
||||
|
||||
void NATIVE64 hk_write_pd_entry(void * const base, uint64_t const pt_addr, uint64_t const attr)
|
||||
void NATIVE64 write_pd_entry(void *const base, uint64_t const pt_addr, uint64_t const attr)
|
||||
{
|
||||
if(base == NULL)
|
||||
return;
|
||||
|
@ -38,7 +37,7 @@ void NATIVE64 hk_write_pd_entry(void * const base, uint64_t const pt_addr, uint6
|
|||
return;
|
||||
}
|
||||
|
||||
void NATIVE64 hk_write_pdpt_entry(void * const base, uint64_t const pd_addr, uint64_t const attr)
|
||||
void NATIVE64 write_pdpt_entry(void *const base, uint64_t const pd_addr, uint64_t const attr)
|
||||
{
|
||||
if(base == NULL)
|
||||
return;
|
||||
|
@ -54,7 +53,7 @@ void NATIVE64 hk_write_pdpt_entry(void * const base, uint64_t const pd_addr, uin
|
|||
return;
|
||||
}
|
||||
|
||||
void NATIVE64 hk_write_pml4_entry(void * const base, uint64_t const pdpt_addr, uint64_t const attr)
|
||||
void NATIVE64 write_pml4_entry(void *const base, uint64_t const pdpt_addr, uint64_t const attr)
|
||||
{
|
||||
if(base == NULL)
|
||||
return;
|
||||
|
@ -70,7 +69,7 @@ void NATIVE64 hk_write_pml4_entry(void * const base, uint64_t const pdpt_addr, u
|
|||
return;
|
||||
}
|
||||
|
||||
void NATIVE64 hk_write_segment_descriptor(void * const gdt, uint32_t const base, uint32_t const limit, uint64_t const attr)
|
||||
void NATIVE64 write_segment_descriptor(void *const gdt, uint32_t const base, uint32_t const limit, uint64_t const attr)
|
||||
{
|
||||
if (gdt == NULL)
|
||||
return;
|
||||
|
@ -86,11 +85,11 @@ void NATIVE64 hk_write_segment_descriptor(void * const gdt, uint32_t const base,
|
|||
return;
|
||||
}
|
||||
|
||||
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)
|
||||
uint64_t NATIVE64 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)
|
||||
return;
|
||||
return 0;
|
||||
//ASSUME: little endian
|
||||
//All of the following should be 4K-aliened
|
||||
|
||||
|
@ -103,30 +102,30 @@ uint64_t NATIVE64 hk_map_page(void * const base, uint64_t const p_addr, uint64_t
|
|||
// if(!(*(uint64_t*)pml4_entry_addr & PML4_PRESENT))
|
||||
// {
|
||||
// //PML4 does not exist
|
||||
// hk_write_pml4_entry(pml4_entry_addr, (uint64_t)((uint64_t*)pdpt_base + pml4_index * 512), PML4_PRESENT | PML4_WRITE);
|
||||
// write_pml4_entry(pml4_entry_addr, (uint64_t)((uint64_t*)pdpt_base + pml4_index * 512), PML4_PRESENT | PML4_WRITE);
|
||||
// }
|
||||
// uint64_t const pml4_entry = *(uint64_t*)pml4_entry_addr;
|
||||
//
|
||||
// void * const pdpt_entry_addr = (void*)((uint64_t*) PAGE_ENTRY_BASE(pml4_entry) + pdpt_index);
|
||||
// if(!(*(uint64_t*) pdpt_entry_addr & PDPT_PRESENT))
|
||||
// {
|
||||
// hk_write_pdpt_entry(pdpt_entry_addr, (uint64_t)((uint64_t*)pd_base + pml4_index * 512 * 512 + pdpt_index * 512), PDPT_PRESENT | PDPT_WRITE);
|
||||
// write_pdpt_entry(pdpt_entry_addr, (uint64_t)((uint64_t*)pd_base + pml4_index * 512 * 512 + pdpt_index * 512), PDPT_PRESENT | PDPT_WRITE);
|
||||
// }
|
||||
// uint64_t const pdpt_entry = *(uint64_t*)pdpt_entry_addr;
|
||||
//
|
||||
// void * const pd_entry_addr = (void*)((uint64_t*) PAGE_ENTRY_BASE(pdpt_entry) + pd_index);
|
||||
// if(!(*(uint64_t*) pd_entry_addr & PD_PRESENT))
|
||||
// {
|
||||
// hk_write_pd_entry(pd_entry_addr, (uint64_t)((uint64_t*)pt_base + pml4_index * 512 * 512 * 512 + pdpt_index * 512 * 512 + pd_index*512), PD_PRESENT | PD_WRITE);
|
||||
// write_pd_entry(pd_entry_addr, (uint64_t)((uint64_t*)pt_base + pml4_index * 512 * 512 * 512 + pdpt_index * 512 * 512 + pd_index*512), PD_PRESENT | PD_WRITE);
|
||||
// }
|
||||
// uint64_t const pd_entry = *(uint64_t*)pd_entry_addr;
|
||||
//
|
||||
// void * const pt_entry_addr = (void*)((uint64_t*) PAGE_ENTRY_BASE(pd_entry) + pt_index);
|
||||
// hk_write_pt_entry(pt_entry_addr, p_addr, attr);
|
||||
// write_pt_entry(pt_entry_addr, p_addr, attr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void NATIVE64 hk_mem_cpy(void* src, void* dst, uint64_t size)
|
||||
void NATIVE64 mem_cpy(void *src, void *dst, uint64_t size)
|
||||
{
|
||||
if (src == NULL || dst == NULL)
|
||||
return;
|
||||
|
@ -137,7 +136,7 @@ void NATIVE64 hk_mem_cpy(void* src, void* dst, uint64_t size)
|
|||
return;
|
||||
}
|
||||
|
||||
void NATIVE64 hk_mem_set(void* src, int8_t const val,uint64_t size)
|
||||
void NATIVE64 mem_set(void *src, int8_t const val, uint64_t size)
|
||||
{
|
||||
if (src == NULL)
|
||||
return;
|
||||
|
@ -146,13 +145,13 @@ void NATIVE64 hk_mem_set(void* src, int8_t const val,uint64_t size)
|
|||
return;
|
||||
}
|
||||
|
||||
void NATIVE64 hk_mem_move(void* src, void* dst, uint64_t size)
|
||||
void NATIVE64 mem_move(void *src, void *dst, uint64_t size)
|
||||
{
|
||||
if (src == NULL || dst == NULL)
|
||||
return;
|
||||
if (src >= dst)
|
||||
{
|
||||
return hk_mem_cpy(src,dst,size);
|
||||
return mem_cpy(src, dst, size);
|
||||
}
|
||||
src += size;
|
||||
dst += size;
|
||||
|
@ -161,7 +160,7 @@ void NATIVE64 hk_mem_move(void* src, void* dst, uint64_t size)
|
|||
return;
|
||||
}
|
||||
|
||||
void*NATIVE64 hk_heap_alloc(uint64_t const size)
|
||||
void*NATIVE64 dum_heap_alloc(uint64_t const size)
|
||||
{
|
||||
if(_cur_heap == NULL)
|
||||
_cur_heap = kernel_heap;
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef _MEM_H_
|
||||
#define _MEM_H_
|
||||
#ifndef _MM_H_
|
||||
#define _MM_H_
|
||||
|
||||
#include "type.h"
|
||||
#include "kdef.h"
|
||||
|
@ -68,33 +68,24 @@ typedef struct __attribute__ ((packed))
|
|||
uint64_t base;
|
||||
} gdt_ptr_t;
|
||||
|
||||
typedef struct __attribute__((packed)) _mem_block
|
||||
{
|
||||
struct _mem_block * prev;
|
||||
uint64_t start_addr;
|
||||
uint64_t end_addr;
|
||||
uint64_t size;
|
||||
struct _mem_block * next;
|
||||
} mem_block;
|
||||
void*NATIVE64 dum_heap_alloc(uint64_t const size);
|
||||
|
||||
void*NATIVE64 hk_heap_alloc(uint64_t const size);
|
||||
|
||||
void NATIVE64 hk_write_segment_descriptor(void *const gdt, uint32_t const base, uint32_t const limit, uint64_t const attr);
|
||||
void NATIVE64 write_segment_descriptor(void *const gdt, uint32_t const base, uint32_t const limit, uint64_t const attr);
|
||||
|
||||
//extern void NATIVE64 hk_load_gdt(gdt_ptr_t const *const ptr, uint16_t const sel_code, uint16_t const sel_data);
|
||||
|
||||
void NATIVE64 hk_mem_cpy(void *src, void *dst, uint64_t size);
|
||||
void NATIVE64 mem_cpy(void *src, void *dst, uint64_t size);
|
||||
|
||||
void NATIVE64 hk_mem_move(void *src, void *dst, uint64_t size);
|
||||
void NATIVE64 mem_move(void *src, void *dst, uint64_t size);
|
||||
|
||||
void NATIVE64 hk_mem_set(void *src, int8_t const val, uint64_t size);
|
||||
void NATIVE64 mem_set(void *src, int8_t const val, uint64_t size);
|
||||
|
||||
void NATIVE64 hk_write_pml4_entry(void *const base, uint64_t const pdpt_addr, uint64_t const attr);
|
||||
void NATIVE64 write_pml4_entry(void *const base, uint64_t const pdpt_addr, uint64_t const attr);
|
||||
|
||||
void NATIVE64 hk_write_pdpt_entry(void *const base, uint64_t const pd_addr, uint64_t const attr);
|
||||
void NATIVE64 write_pdpt_entry(void *const base, uint64_t const pd_addr, uint64_t const attr);
|
||||
|
||||
void NATIVE64 hk_write_pd_entry(void *const base, uint64_t const pt_addr, uint64_t const attr);
|
||||
void NATIVE64 write_pd_entry(void *const base, uint64_t const pt_addr, uint64_t const attr);
|
||||
|
||||
void NATIVE64 hk_write_pt_entry(void *const base, uint64_t const p_addr, uint64_t const attr);
|
||||
void NATIVE64 write_pt_entry(void *const base, uint64_t const p_addr, uint64_t const attr);
|
||||
|
||||
#endif
|
|
@ -1,12 +1,12 @@
|
|||
#include <stdarg.h>
|
||||
#include "kdef.h"
|
||||
#include "type.h"
|
||||
#include "mem.h"
|
||||
#include "mm.h"
|
||||
#include "print.h"
|
||||
|
||||
uint64_t text_pos;
|
||||
|
||||
uint64_t NATIVE64 hk_str_len(char const * str)
|
||||
uint64_t NATIVE64 str_len(char const *str)
|
||||
{
|
||||
uint64_t length = 0;
|
||||
if(str == NULL)
|
||||
|
@ -19,12 +19,12 @@ uint64_t NATIVE64 hk_str_len(char const * str)
|
|||
return length;
|
||||
}
|
||||
|
||||
uint64_t NATIVE64 hk_str_cmp(char const * str1,char const * str2)
|
||||
uint64_t NATIVE64 str_cmp(char const *str1, char const *str2)
|
||||
{
|
||||
if(str1 == NULL || str2 == NULL)
|
||||
return 0;
|
||||
uint64_t length = hk_str_len(str1);
|
||||
if(length != hk_str_len(str2))
|
||||
uint64_t length = str_len(str1);
|
||||
if(length != str_len(str2))
|
||||
return 0;
|
||||
while(length--)
|
||||
{
|
||||
|
@ -34,9 +34,9 @@ uint64_t NATIVE64 hk_str_cmp(char const * str1,char const * str2)
|
|||
return 1;
|
||||
}
|
||||
|
||||
void NATIVE64 hk_print_scroll()
|
||||
void NATIVE64 _print_scroll()
|
||||
{
|
||||
hk_mem_move((void*)(0xb8000 + get_pos(1,0) * 2), (void*)(0xb8000 + get_pos(0,0) * 2), (80*24)*2);
|
||||
mem_move((void *) (0xb8000 + get_pos(1, 0) * 2), (void *) (0xb8000 + get_pos(0, 0) * 2), (80 * 24) * 2);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -52,8 +52,8 @@ void NATIVE64 _print_str(char const *str)
|
|||
if(text_pos > 80 * 25 - 1)
|
||||
{
|
||||
//can't hold
|
||||
hk_print_scroll();
|
||||
hk_mem_set((void*)(0xb8000 + 80*24*2), 0, 80 * 2); // clear last row
|
||||
_print_scroll();
|
||||
mem_set((void *) (0xb8000 + 80 * 24 * 2), 0, 80 * 2); // clear last row
|
||||
text_pos = 80 * 24;
|
||||
}
|
||||
str++;
|
||||
|
@ -63,7 +63,7 @@ void NATIVE64 _print_str(char const *str)
|
|||
if (text_pos > 80 * 25 - 1)
|
||||
{
|
||||
//can't hold
|
||||
hk_print_scroll();
|
||||
_print_scroll();
|
||||
text_pos = 80 * 24;
|
||||
}
|
||||
*((char*)(0xb8000) + text_pos*2) = *str;
|
||||
|
@ -145,14 +145,14 @@ void NATIVE64 _print_hex(uint64_t number, uint64_t capital)
|
|||
return;
|
||||
}
|
||||
|
||||
void NATIVE64 hk_clear_screen(void)
|
||||
void NATIVE64 clear_screen(void)
|
||||
{
|
||||
text_pos = 0; // reset text_pos
|
||||
hk_mem_set((void*)0xb8000, 0, 25*80*2);
|
||||
mem_set((void *) 0xb8000, 0, 25 * 80 * 2);
|
||||
return;
|
||||
}
|
||||
|
||||
void NATIVE64 hk_printf(char const *format, ...)
|
||||
void NATIVE64 kprintf(char const *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
|
|
|
@ -7,9 +7,9 @@
|
|||
#define get_row(pos) (pos / 80)
|
||||
#define get_pos(row,col) ((row) * 80 + (col))
|
||||
|
||||
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, ...);
|
||||
void NATIVE64 clear_screen(void);
|
||||
uint64_t NATIVE64 str_len(char const *str);
|
||||
uint64_t NATIVE64 str_cmp(char const *str1, char const *str2);
|
||||
void NATIVE64 kprintf(char const *format, ...);
|
||||
|
||||
#endif
|
|
@ -1,11 +1,4 @@
|
|||
#ifndef _TYPE_H_
|
||||
#define _TYPE_H_
|
||||
typedef unsigned int uint32_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef unsigned long long uint64_t;
|
||||
typedef unsigned char uint8_t;
|
||||
typedef signed int int32_t;
|
||||
typedef signed short int16_t;
|
||||
typedef signed long long int64_t;
|
||||
typedef char int8_t;
|
||||
#include <stdint.h>
|
||||
#endif
|
|
@ -2,11 +2,10 @@ global kernel_stack
|
|||
global kernel_addr
|
||||
global BOCHS_MAGIC_BREAKPOINT
|
||||
global HLT_CPU
|
||||
global hk_init_x64
|
||||
extern hk_main
|
||||
extern hk_printf
|
||||
extern hk_enable_paging
|
||||
extern hk_disable_paging
|
||||
global init_x64
|
||||
extern kmain
|
||||
extern enable_paging
|
||||
extern disable_paging
|
||||
|
||||
[SECTION .entry]
|
||||
[BITS 32]
|
||||
|
@ -23,16 +22,16 @@ dd MULTIBOOT_HEADER
|
|||
dd MULTIBOOT_HEADER
|
||||
dd 0
|
||||
dd 0
|
||||
dd hk_entry_32
|
||||
dd entry_32
|
||||
|
||||
times 4096 db 0
|
||||
kernel_stack:
|
||||
|
||||
hk_entry_32:
|
||||
entry_32:
|
||||
cli
|
||||
|
||||
cmp eax,GRUB_MAGIC
|
||||
jmp hk_entry_32.loaded_by_grub
|
||||
jmp entry_32.loaded_by_grub
|
||||
hlt
|
||||
.loaded_by_grub:
|
||||
|
||||
|
@ -43,7 +42,7 @@ push dword 0
|
|||
popfd
|
||||
|
||||
push ebx
|
||||
call hk_main
|
||||
call kmain
|
||||
add esp,4 ; We are actually not coming back here. But out of courtesy...
|
||||
hlt
|
||||
|
||||
|
@ -55,7 +54,7 @@ HLT_CPU:
|
|||
hlt
|
||||
|
||||
;multiboot_info on stack
|
||||
hk_init_x64:
|
||||
init_x64:
|
||||
push ebp
|
||||
mov ebp,esp
|
||||
cli
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
global hk_read_port
|
||||
global hk_write_port
|
||||
global read_port
|
||||
global write_port
|
||||
[SECTION .text]
|
||||
[BITS 32]
|
||||
hk_write_port:
|
||||
write_port:
|
||||
mov edx, [esp + 4]
|
||||
mov al, [esp + 4 + 4]
|
||||
out dx, al
|
||||
|
@ -10,7 +10,7 @@ hk_write_port:
|
|||
nop
|
||||
ret
|
||||
|
||||
hk_read_port:
|
||||
read_port:
|
||||
mov edx, [esp + 4]
|
||||
xor eax, eax
|
||||
in al, dx
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
global hk_load_gdt
|
||||
global hk_support_x64
|
||||
global hk_disable_paging
|
||||
global hk_enable_paging
|
||||
global load_gdt
|
||||
global support_x64
|
||||
global disable_paging
|
||||
global enable_paging
|
||||
[SECTION .text]
|
||||
[BITS 32]
|
||||
;void hk_load_gdt(gdt_ptr* ptr, uint16 SLCT_CODE, uint16 SLCT_DATA)
|
||||
hk_load_gdt:
|
||||
;void load_gdt(gdt_ptr* ptr, uint16 SLCT_CODE, uint16 SLCT_DATA)
|
||||
load_gdt:
|
||||
push ebp
|
||||
mov ebp,esp
|
||||
push eax
|
||||
|
@ -28,8 +28,8 @@ mov esp,ebp
|
|||
pop ebp
|
||||
ret
|
||||
|
||||
;int hk_support_x64(void)
|
||||
hk_support_x64:
|
||||
;int support_x64(void)
|
||||
support_x64:
|
||||
push ebp
|
||||
mov ebp,esp
|
||||
pushfd
|
||||
|
@ -62,22 +62,22 @@ pop ebp
|
|||
ret
|
||||
|
||||
|
||||
;void hk_disable_paging(void)
|
||||
hk_disable_paging:
|
||||
;void disable_paging(void)
|
||||
disable_paging:
|
||||
mov eax, cr0 ; Set the A-register to control register 0.
|
||||
and eax, 01111111111111111111111111111111b ; Clear the PG-bit, which is bit 31.
|
||||
mov cr0, eax ; Set control register 0 to the A-register.
|
||||
ret
|
||||
|
||||
;void hk_enable_paging(void)
|
||||
hk_enable_paging:
|
||||
;void enable_paging(void)
|
||||
enable_paging:
|
||||
mov eax, cr0 ; Set the A-register to control register 0.
|
||||
or eax, 1 << 31 ; Set the PG-bit, which is bit 31.
|
||||
mov cr0, eax ; Set control register 0 to the A-register.
|
||||
ret
|
||||
|
||||
;void hk_flush_tlb(void)
|
||||
hk_flush_tlb:
|
||||
;void flush_tlb(void)
|
||||
flush_tlb:
|
||||
mov eax,cr3
|
||||
mov cr3,eax
|
||||
ret
|
|
@ -9,53 +9,53 @@ uint8_t g_idt[8 * 256];
|
|||
idt_ptr_t g_idt_ptr;
|
||||
|
||||
extern uint32_t text_pos;
|
||||
extern void hk_init_x64(multiboot_info_t* multiboot_info);
|
||||
extern void init_x64(multiboot_info_t* multiboot_info);
|
||||
extern void BOCHS_MAGIC_BREAKPOINT(void);
|
||||
extern void HLT_CPU(void);
|
||||
extern char kernel_start[];
|
||||
extern char kernel_end[];
|
||||
|
||||
void NATIVE32 hk_main(multiboot_info_t* multiboot_info)
|
||||
void NATIVE32 kmain(multiboot_info_t *multiboot_info)
|
||||
{
|
||||
//init text_position
|
||||
text_pos = 0;
|
||||
|
||||
//detect architecture
|
||||
hk_printf("*Checking architecture...\n");
|
||||
if (hk_support_x64() == 1)
|
||||
kprintf("*Checking architecture...\n");
|
||||
if (support_x64() == 1)
|
||||
{
|
||||
hk_printf("Arch: x86_64.\n\n");
|
||||
hk_init_x64(multiboot_info);
|
||||
kprintf("Arch: x86_64.\n\n");
|
||||
init_x64(multiboot_info);
|
||||
}
|
||||
hk_printf("Arch: x86.\n\n");
|
||||
hk_printf("Kernel Start: 0x%X. End: 0x%X. Size: 0x%X.\n\n", (uint32_t)kernel_start, (uint32_t)kernel_end, (uint32_t)kernel_end - (uint32_t)kernel_start);
|
||||
hk_printf("*Setting up GDT...");
|
||||
kprintf("Arch: x86.\n\n");
|
||||
kprintf("Kernel Start: 0x%X. End: 0x%X. Size: 0x%X.\n\n", (uint32_t) kernel_start, (uint32_t) kernel_end, (uint32_t) kernel_end - (uint32_t) kernel_start);
|
||||
kprintf("*Setting up GDT...");
|
||||
//dummy descriptor
|
||||
hk_write_segment_descriptor((void*)(&g_gdt[0]), 0, 0, 0);
|
||||
write_segment_descriptor((void *) (&g_gdt[0]), 0, 0, 0);
|
||||
//ring 0 code seg, non-conforming
|
||||
hk_write_segment_descriptor((void*)(&g_gdt[8]), 0, 0xFFFFF, SEG_TYPE_CODE_XR | SEG_CODE_DATA | SEG_32_BITS | SEG_GRANULARITY | SEG_PRESENT | SEG_DPL_0);
|
||||
write_segment_descriptor((void *) (&g_gdt[8]), 0, 0xFFFFF, SEG_TYPE_CODE_XR | SEG_CODE_DATA | SEG_32_BITS | SEG_GRANULARITY | SEG_PRESENT | SEG_DPL_0);
|
||||
//ring 3 code seg
|
||||
hk_write_segment_descriptor((void*)(&g_gdt[16]), 0, 0xFFFFF, SEG_TYPE_CODE_XR | SEG_CODE_DATA | SEG_32_BITS | SEG_GRANULARITY | SEG_PRESENT | SEG_DPL_3);
|
||||
write_segment_descriptor((void *) (&g_gdt[16]), 0, 0xFFFFF, SEG_TYPE_CODE_XR | SEG_CODE_DATA | SEG_32_BITS | SEG_GRANULARITY | SEG_PRESENT | SEG_DPL_3);
|
||||
//ring 0 data RW
|
||||
hk_write_segment_descriptor((void*)(&g_gdt[24]), 0, 0xFFFFF, SEG_TYPE_DATA_RW | SEG_CODE_DATA | SEG_32_BITS | SEG_GRANULARITY | SEG_PRESENT | SEG_DPL_0);
|
||||
write_segment_descriptor((void *) (&g_gdt[24]), 0, 0xFFFFF, SEG_TYPE_DATA_RW | SEG_CODE_DATA | SEG_32_BITS | SEG_GRANULARITY | SEG_PRESENT | SEG_DPL_0);
|
||||
//ring 3 data
|
||||
hk_write_segment_descriptor((void*)(&g_gdt[32]), 0, 0xFFFFF, SEG_TYPE_DATA_RW | SEG_CODE_DATA | SEG_32_BITS | SEG_GRANULARITY | SEG_PRESENT | SEG_DPL_3);
|
||||
write_segment_descriptor((void *) (&g_gdt[32]), 0, 0xFFFFF, SEG_TYPE_DATA_RW | SEG_CODE_DATA | SEG_32_BITS | SEG_GRANULARITY | SEG_PRESENT | SEG_DPL_3);
|
||||
g_gdt_ptr.limit = 8 * 8 - 1;
|
||||
g_gdt_ptr.base = (uint32_t) g_gdt;
|
||||
hk_load_gdt(&g_gdt_ptr, SEG_SELECTOR(1, 0), SEG_SELECTOR(3, 0));
|
||||
hk_printf(" - Done.\n\n");
|
||||
load_gdt(&g_gdt_ptr, SEG_SELECTOR(1, 0), SEG_SELECTOR(3, 0));
|
||||
kprintf(" - Done.\n\n");
|
||||
//check memory, definitely < 32 so we assume that
|
||||
hk_printf("*Checking memory information...\n");
|
||||
kprintf("*Checking memory information...\n");
|
||||
if(multiboot_info->flags & (1 << 6))
|
||||
{
|
||||
multiboot_memory_map_t const *mem_map = (multiboot_memory_map_t *) multiboot_info->mmap_addr;
|
||||
uint32_t const mem_map_size = multiboot_info->mmap_length / sizeof(multiboot_memory_map_t);
|
||||
hk_printf("BaseAddr - Length - Type\n");
|
||||
kprintf("BaseAddr - Length - Type\n");
|
||||
uint32_t total_available_mem = 0;
|
||||
uint32_t total_reserved_mem = 0;
|
||||
for (uint32_t i = 0; i < mem_map_size; i++)
|
||||
{
|
||||
hk_printf("0x%x - 0x%X - 0x%x\n",((uint32_t)(mem_map + i)->addr),(uint32_t)((mem_map + i)->len),(uint32_t)(mem_map + i)->type);
|
||||
kprintf("0x%x - 0x%X - 0x%x\n", ((uint32_t) (mem_map + i)->addr), (uint32_t) ((mem_map + i)->len), (uint32_t) (mem_map + i)->type);
|
||||
if((mem_map + i)->type == MULTIBOOT_MEMORY_RESERVED)
|
||||
{
|
||||
total_reserved_mem += (uint32_t) ((mem_map + i)->len);
|
||||
|
@ -65,31 +65,31 @@ void NATIVE32 hk_main(multiboot_info_t* multiboot_info)
|
|||
total_available_mem += (uint32_t) ((mem_map + i)->len);
|
||||
}
|
||||
}
|
||||
hk_printf("Total available memory: %uB, %uKB, %uMB.\n",total_available_mem,total_available_mem/1024,total_available_mem/1024/1024);
|
||||
hk_printf("Total reserved memory: %uB, %uKB, %uMB.\n\n", total_reserved_mem, total_reserved_mem/1024, total_reserved_mem/1024/1024);
|
||||
kprintf("Total available memory: %uB, %uKB, %uMB.\n", total_available_mem, total_available_mem / 1024, total_available_mem / 1024 / 1024);
|
||||
kprintf("Total reserved memory: %uB, %uKB, %uMB.\n\n", total_reserved_mem, total_reserved_mem / 1024, total_reserved_mem / 1024 / 1024);
|
||||
}
|
||||
else
|
||||
{
|
||||
hk_printf("Memory information is currently unavailable.\n\n");
|
||||
kprintf("Memory information is currently unavailable.\n\n");
|
||||
}
|
||||
|
||||
//check modules
|
||||
hk_printf("*Checking loaded kernel modules...\n");
|
||||
kprintf("*Checking loaded kernel modules...\n");
|
||||
if(multiboot_info->flags & (1 << 3))
|
||||
{
|
||||
multiboot_module_t const * mods_list = (multiboot_module_t *)multiboot_info->mods_addr;
|
||||
uint32_t const mods_count = multiboot_info->mods_count;
|
||||
hk_printf("%u module(s) loaded:\n", mods_count);
|
||||
hk_printf("Name - StartAddr - EndAddr\n");
|
||||
kprintf("%u module(s) loaded:\n", mods_count);
|
||||
kprintf("Name - StartAddr - EndAddr\n");
|
||||
for (uint64_t i = 0; i < mods_count; i++)
|
||||
{
|
||||
hk_printf("%s - 0x%X - 0x%X\n",(char *) (mods_list + i)->cmdline,(mods_list + i)->mod_start,(mods_list + i)->mod_end);
|
||||
kprintf("%s - 0x%X - 0x%X\n", (char *) (mods_list + i)->cmdline, (mods_list + i)->mod_start, (mods_list + i)->mod_end);
|
||||
}
|
||||
hk_printf("\n");
|
||||
kprintf("\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
hk_printf("Module information is currently unavailable.\n\n");
|
||||
kprintf("Module information is currently unavailable.\n\n");
|
||||
}
|
||||
HLT_CPU();
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "kdef.h"
|
||||
#include "mem.h"
|
||||
|
||||
void NATIVE32 hk_write_segment_descriptor(void * const gdt, uint32_t const base, uint32_t const limit, uint64_t const attr)
|
||||
void NATIVE32 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 NATIVE32 hk_write_segment_descriptor(void * const gdt, uint32_t const base,
|
|||
return;
|
||||
}
|
||||
|
||||
void NATIVE32 hk_mem_cpy(void* src, void* dst, uint32_t size)
|
||||
void NATIVE32 mem_cpy(void* src, void* dst, uint32_t size)
|
||||
{
|
||||
if (src == NULL || dst == NULL)
|
||||
return;
|
||||
|
@ -28,7 +28,7 @@ void NATIVE32 hk_mem_cpy(void* src, void* dst, uint32_t size)
|
|||
return;
|
||||
}
|
||||
|
||||
void NATIVE32 hk_mem_set(void* src, int8_t const val,uint32_t size)
|
||||
void NATIVE32 mem_set(void* src, int8_t const val,uint32_t size)
|
||||
{
|
||||
if (src == NULL)
|
||||
return;
|
||||
|
@ -38,7 +38,7 @@ void NATIVE32 hk_mem_set(void* src, int8_t const val,uint32_t size)
|
|||
return;
|
||||
}
|
||||
|
||||
void NATIVE32 hk_mem_move(void* src, void* dst, uint32_t size)
|
||||
void NATIVE32 mem_move(void* src, void* dst, uint32_t size)
|
||||
{
|
||||
if (src == NULL || dst == NULL)
|
||||
return;
|
||||
|
@ -46,7 +46,7 @@ void NATIVE32 hk_mem_move(void* src, void* dst, uint32_t size)
|
|||
char* cDst = (char*)dst;
|
||||
if (cSrc >= cDst)
|
||||
{
|
||||
return hk_mem_cpy(src,dst,size);
|
||||
return mem_cpy(src, dst, size);
|
||||
}
|
||||
cSrc += size;
|
||||
cDst += size;
|
||||
|
|
|
@ -38,12 +38,12 @@ typedef struct __attribute__ ((packed))
|
|||
uint32_t base;
|
||||
} idt_ptr_t;
|
||||
|
||||
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 NATIVE32 hk_mem_set(void* src, int8_t const val,uint32_t size);
|
||||
void NATIVE32 write_segment_descriptor(void *const gdt, uint32_t const base, uint32_t const limit, uint64_t const attr);
|
||||
extern void NATIVE32 load_gdt(gdt_ptr_t const * const ptr, uint16_t const sel_code, uint16_t const sel_data);
|
||||
void NATIVE32 mem_cpy(void* src, void* dst, uint32_t size);
|
||||
void NATIVE32 mem_move(void* src, void* dst, uint32_t size);
|
||||
extern int32_t NATIVE32 support_x64(void);
|
||||
extern void disable_paging(void);
|
||||
extern void enable_paging(void);
|
||||
void NATIVE32 mem_set(void* src, int8_t const val,uint32_t size);
|
||||
#endif
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
uint32_t text_pos;
|
||||
|
||||
uint32_t NATIVE32 hk_str_len(char const *str)
|
||||
uint32_t NATIVE32 str_len(char const *str)
|
||||
{
|
||||
uint32_t length = 0;
|
||||
if (str == NULL)
|
||||
|
@ -19,12 +19,12 @@ uint32_t NATIVE32 hk_str_len(char const *str)
|
|||
return length;
|
||||
}
|
||||
|
||||
uint32_t NATIVE32 hk_str_cmp(char const *str1, char const *str2)
|
||||
uint32_t NATIVE32 str_cmp(char const *str1, char const *str2)
|
||||
{
|
||||
if (str1 == NULL || str2 == NULL)
|
||||
return 0;
|
||||
uint32_t length = hk_str_len(str1);
|
||||
if (length != hk_str_len(str2))
|
||||
uint32_t length = str_len(str1);
|
||||
if (length != str_len(str2))
|
||||
return 0;
|
||||
while (length--)
|
||||
{
|
||||
|
@ -34,9 +34,9 @@ uint32_t NATIVE32 hk_str_cmp(char const *str1, char const *str2)
|
|||
return 1;
|
||||
}
|
||||
|
||||
void NATIVE32 hk_print_scroll()
|
||||
void NATIVE32 _print_scroll()
|
||||
{
|
||||
hk_mem_move((void *) (0xb8000 + get_pos(1, 0) * 2), (void *) (0xb8000 + get_pos(0, 0) * 2), (80 * 24) * 2);
|
||||
mem_move((void *) (0xb8000 + get_pos(1, 0) * 2), (void *) (0xb8000 + get_pos(0, 0) * 2), (80 * 24) * 2);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -52,8 +52,8 @@ void NATIVE32 _print_str(char const *str)
|
|||
if (text_pos > 80 * 25 - 1)
|
||||
{
|
||||
//can't hold
|
||||
hk_print_scroll();
|
||||
hk_mem_set((void *) (0xb8000 + 80 * 24 * 2), 0, 80 * 2); // clear last row
|
||||
_print_scroll();
|
||||
mem_set((void *) (0xb8000 + 80 * 24 * 2), 0, 80 * 2); // clear last row
|
||||
text_pos = 80 * 24;
|
||||
}
|
||||
str++;
|
||||
|
@ -63,7 +63,7 @@ void NATIVE32 _print_str(char const *str)
|
|||
if (text_pos > 80 * 25 - 1)
|
||||
{
|
||||
//can't hold
|
||||
hk_print_scroll();
|
||||
_print_scroll();
|
||||
text_pos = 80 * 24;
|
||||
}
|
||||
*((char *) (0xb8000) + text_pos * 2) = *str;
|
||||
|
@ -151,15 +151,15 @@ void NATIVE32 _print_hex(uint32_t number, uint32_t captial)
|
|||
}
|
||||
|
||||
|
||||
void NATIVE32 hk_clear_screen(void)
|
||||
void NATIVE32 clear_screen(void)
|
||||
{
|
||||
text_pos = 0; // reset text_pos
|
||||
hk_mem_set((void *) 0xb8000, 0, 25 * 80 * 2);
|
||||
mem_set((void *) 0xb8000, 0, 25 * 80 * 2);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void NATIVE32 hk_printf(char const *format, ...)
|
||||
void NATIVE32 kprintf(char const *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
#define get_row(pos) (pos / 80)
|
||||
#define get_pos(row,col) ((row) * 80 + (col))
|
||||
|
||||
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);
|
||||
void NATIVE32 kprintf(char const *format, ...);
|
||||
uint32_t NATIVE32 str_len(char const *str);
|
||||
uint32_t NATIVE32 str_cmp(char const *str1, char const *str2);
|
||||
void NATIVE32 clear_screen(void);
|
||||
#endif
|
|
@ -1,11 +1,4 @@
|
|||
#ifndef _TYPE_H_
|
||||
#define _TYPE_H_
|
||||
typedef unsigned int uint32_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef unsigned long long uint64_t;
|
||||
typedef unsigned char uint8_t;
|
||||
typedef signed int int32_t;
|
||||
typedef signed short int16_t;
|
||||
typedef signed long long int64_t;
|
||||
typedef char int8_t;
|
||||
#include <stdint.h>
|
||||
#endif
|
Loading…
Reference in New Issue