Space to Tab

This commit is contained in:
secXsQuared 2018-02-17 23:06:57 -05:00
parent 362f3d0ce8
commit 0988ae8baf
40 changed files with 3655 additions and 3171 deletions

View File

@ -8,10 +8,12 @@
static void KABI halp_obtain_cpu_info(boot_info_t *hal_info)
{
if(hal_info == NULL)
if (hal_info == NULL)
{
return;
}
uint32_t eax = 0, ebx = 0, ecx = 0, edx = 0;
hal_cpuid(&eax,&ebx,&ecx,&edx);
hal_cpuid(&eax, &ebx, &ecx, &edx);
lb_mem_copy(&ebx, &hal_info->cpu_vd_str[0], sizeof(uint32_t));
lb_mem_copy(&edx, &hal_info->cpu_vd_str[4], sizeof(uint32_t));
lb_mem_copy(&ecx, &hal_info->cpu_vd_str[8], sizeof(uint32_t));
@ -21,20 +23,22 @@ static void KABI halp_obtain_cpu_info(boot_info_t *hal_info)
status_t KABI hal_init(void *m_info)
{
if (m_info == NULL || (uint64_t) m_info & lb_bit_field_mask(0, 2))
{
return STATUS_FAIL;
}
// init HAL infrastructures
hal_print_init();
hal_mem_init();
boot_info_t* boot_info = halloc(sizeof(boot_info_t));
boot_info_t *boot_info = halloc(sizeof(boot_info_t));
// obtain cpu info
halp_obtain_cpu_info(boot_info);
// init interrupt
if(hal_interrupt_init() != 0)
if (hal_interrupt_init() != 0)
{
return STATUS_FAIL;
}

View File

@ -6,22 +6,22 @@
#include "hal/mem.h"
#include "lib/sxtdlib.h"
static uint8_t _idts[HAL_CORE_COUNT][IDT_ENTRY_NUM*IDT_ENTRY_SIZE];
static uint8_t _idts[HAL_CORE_COUNT][IDT_ENTRY_NUM * IDT_ENTRY_SIZE];
static hal_idt_ptr_t _idt_ptrs[HAL_CORE_COUNT];
static intr_handler_t _intr_handler_table[HAL_CORE_COUNT][IDT_ENTRY_NUM];
static void* _intr_handler_context_table[HAL_CORE_COUNT][IDT_ENTRY_NUM];
static void *_intr_handler_context_table[HAL_CORE_COUNT][IDT_ENTRY_NUM];
static exc_handler_t _exc_handler_table[HAL_CORE_COUNT][IDT_ENTRY_NUM];
irql_t KABI hal_set_irql(irql_t irql)
{
UNREFERENCED(irql)
hal_assert(false,"Unimplemented function called.");
hal_assert(false, "Unimplemented function called.");
return 0;
}
irql_t KABI hal_get_irql(void)
{
hal_assert(false,"Unimplemented function called.");
hal_assert(false, "Unimplemented function called.");
return 0;
}
@ -65,11 +65,11 @@ void KABI hal_issue_interrupt(uint32_t target_core, uint32_t vector)
{
UNREFERENCED(target_core);
UNREFERENCED(vector);
hal_assert(false,"Unimplemented function called.");
hal_assert(false, "Unimplemented function called.");
return;
}
void KABI hal_register_interrupt_handler(uint32_t coreid, uint32_t index, intr_handler_t handler, void* context)
void KABI hal_register_interrupt_handler(uint32_t coreid, uint32_t index, intr_handler_t handler, void *context)
{
if (index < IDT_ENTRY_NUM && coreid < HAL_CORE_COUNT)
{
@ -120,7 +120,7 @@ void KABI hal_interrupt_dispatcher(uint64_t int_vec, hal_interrupt_context_t *co
return;
}
void KABI hal_exception_dispatcher(uint64_t exc_vec, hal_interrupt_context_t* context, uint64_t errorcode)
void KABI hal_exception_dispatcher(uint64_t exc_vec, hal_interrupt_context_t *context, uint64_t errorcode)
{
uint32_t coreid = hal_get_core_id();
if (_exc_handler_table[exc_vec] == NULL)

View File

@ -21,7 +21,7 @@ char kernel_heap[KERNEL_HEAP_SIZE];
* @param pt_base page table base paddr
* @param pt_end page table entry paddr
*/
status_t KABI hal_write_initial_page_table(void* multiboot_info)
status_t KABI hal_write_initial_page_table(void *multiboot_info)
{
UNREFERENCED(multiboot_info);
@ -67,7 +67,9 @@ status_t KABI hal_write_initial_page_table(void* multiboot_info)
void KABI hal_write_pt(void *const base, uintptr_t const p_addr, uint64_t const attr)
{
if (base == NULL)
{
return;
}
uint64_t entry = (p_addr & 0xFFFFFFFFFF000) | attr;
((uint8_t *) base)[0] = (uint8_t) (entry & 0xFF);
((uint8_t *) base)[1] = (uint8_t) ((entry >> 8) & 0xFF);
@ -83,7 +85,9 @@ void KABI hal_write_pt(void *const base, uintptr_t const p_addr, uint64_t const
void KABI hal_write_pd(void *const base, uintptr_t const pt_addr, uint64_t const attr)
{
if (base == NULL)
{
return;
}
uint64_t entry = (pt_addr & 0xFFFFFFFFFF000) | attr;
((uint8_t *) base)[0] = (uint8_t) (entry & 0xFF);
((uint8_t *) base)[1] = (uint8_t) ((entry >> 8) & 0xFF);
@ -99,7 +103,9 @@ void KABI hal_write_pd(void *const base, uintptr_t const pt_addr, uint64_t const
void KABI hal_write_pdpt(void *const base, uintptr_t const pd_addr, uint64_t const attr)
{
if (base == NULL)
{
return;
}
uint64_t entry = (pd_addr & 0xFFFFFFFFFF000) | attr;
((uint8_t *) base)[0] = (uint8_t) (entry & 0xFF);
((uint8_t *) base)[1] = (uint8_t) ((entry >> 8) & 0xFF);
@ -115,7 +121,9 @@ void KABI hal_write_pdpt(void *const base, uintptr_t const pd_addr, uint64_t con
void KABI hal_write_pml4(void *const base, uintptr_t const pdpt_addr, uint64_t const attr)
{
if (base == NULL)
{
return;
}
uint64_t const entry = (pdpt_addr & 0xFFFFFFFFFF000) | attr;
((uint8_t *) base)[0] = (uint8_t) (entry & 0xFF);
((uint8_t *) base)[1] = (uint8_t) ((entry >> 8) & 0xFF);
@ -132,7 +140,9 @@ void KABI hal_write_segment_descriptor(void *const gdt, uint32_t const base, uin
uint64_t const attr)
{
if (gdt == NULL)
{
return;
}
uint64_t const seg_desc = (((uint64_t) base & 0xFFFF) << 16) | ((((uint64_t) base >> 16) & 0xFF) << 32) |
((((uint64_t) base >> 24) & 0xFF) << 56) | ((uint64_t) limit & 0xFFFF) |
((((uint64_t) limit >> 16) & 0xF) << 48) | attr;

View File

@ -5,7 +5,7 @@
#define get_column(pos) ((pos) % 80)
#define get_row(pos) ((pos) / 80)
#define get_pos(row,col) ((row) * 80 + (col))
#define get_pos(row, col) ((row) * 80 + (col))
static uint64_t text_pos;
@ -22,14 +22,16 @@ static void KABI halp_print_scroll(void)
static void KABI halp_print_str(char const *str)
{
if(str == NULL)
if (str == NULL)
{
return;
}
while (*str != 0)
{
if(*str == '\n')
if (*str == '\n')
{
text_pos = 80 * (get_row(text_pos) + 1);
if(text_pos > 80 * 25 - 1)
if (text_pos > 80 * 25 - 1)
{
//can't hold
halp_print_scroll();
@ -46,8 +48,8 @@ static void KABI halp_print_str(char const *str)
halp_print_scroll();
text_pos = 80 * 24;
}
*((char*)(0xb8000) + text_pos*2) = *str;
*((char*)(0xb8000) + text_pos*2 + 1) = 7;
*((char *) (0xb8000) + text_pos * 2) = *str;
*((char *) (0xb8000) + text_pos * 2 + 1) = 7;
str++;
text_pos++;
}
@ -68,8 +70,10 @@ static void KABI halp_print_uint(uint64_t number)
number = quo;
arr[index--] = (char) ('0' + rmd);
if (number == 0)
{
break;
}
}
halp_print_str(&(arr[index + 1]));
return;
}
@ -93,8 +97,10 @@ static void KABI halp_print_int(int64_t number)
number = quo;
arr[index--] = (char) ('0' + rmd);
if (number == 0)
{
break;
}
}
if (isNegative)
{
arr[index--] = '-';
@ -107,7 +113,7 @@ static void KABI halp_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'};
char const * const look_up = capital == 1 ? &lookup_table_cap[0] : &lookup_table[0];
char const *const look_up = capital == 1 ? &lookup_table_cap[0] : &lookup_table[0];
char arr[17];
arr[16] = 0; //zero-terminated
uint32_t index = 15;
@ -119,8 +125,10 @@ static void KABI halp_print_hex(uint64_t number, uint64_t capital)
number = quo;
arr[index--] = look_up[rmd];
if (number == 0)
{
break;
}
}
halp_print_str(&(arr[index + 1]));
return;
}
@ -132,14 +140,14 @@ void KABI hal_clear_screen(void)
return;
}
void KABI hal_vprintf(char const * format, va_list args)
void KABI hal_vprintf(char const *format, va_list args)
{
char buf[2] = {0, 0};
int64_t d;
uint64_t u;
char* s;
char *s;
char c;
for(;*format != '\0';format++)
for (; *format != '\0'; format++)
{
if (*format != '%')
{
@ -163,7 +171,7 @@ void KABI hal_vprintf(char const * format, va_list args)
halp_print_str(s);
break;
case 'c':
c = (char)va_arg(args, int64_t);
c = (char) va_arg(args, int64_t);
buf[0] = c;
halp_print_str(buf);
break;

View File

@ -65,6 +65,7 @@ extern void KABI hal_read_idt(hal_idt_ptr_t **idt_ptr);
* Control Register Operations
*/
#define MSR_IA32_APIC_BASE 0x1B
extern void KABI hal_read_msr(uint32_t *ecx, uint32_t *edx, uint32_t *eax);
extern void KABI hal_write_msr(uint32_t *ecx, uint32_t *edx, uint32_t *eax);
@ -78,5 +79,4 @@ extern void KABI hal_write_cr8(uint64_t pri);
extern uint64_t KABI hal_read_cr8(void);
#endif

View File

@ -43,264 +43,518 @@ int32_t KABI hal_interrupt_init(void);
* System exception Handlers
*/
extern void KABI hal_interrupt_handler_0(void);
extern void KABI hal_interrupt_handler_1(void);
extern void KABI hal_interrupt_handler_2(void);
extern void KABI hal_interrupt_handler_3(void);
extern void KABI hal_interrupt_handler_4(void);
extern void KABI hal_interrupt_handler_5(void);
extern void KABI hal_interrupt_handler_6(void);
extern void KABI hal_interrupt_handler_7(void);
extern void KABI hal_interrupt_handler_8(void);
extern void KABI hal_interrupt_handler_9(void);
extern void KABI hal_interrupt_handler_10(void);
extern void KABI hal_interrupt_handler_11(void);
extern void KABI hal_interrupt_handler_12(void);
extern void KABI hal_interrupt_handler_13(void);
extern void KABI hal_interrupt_handler_14(void);
extern void KABI hal_interrupt_handler_15(void);
extern void KABI hal_interrupt_handler_16(void);
extern void KABI hal_interrupt_handler_17(void);
extern void KABI hal_interrupt_handler_18(void);
extern void KABI hal_interrupt_handler_19(void);
extern void KABI hal_interrupt_handler_20(void);
extern void KABI hal_interrupt_handler_21(void);
extern void KABI hal_interrupt_handler_22(void);
extern void KABI hal_interrupt_handler_23(void);
extern void KABI hal_interrupt_handler_24(void);
extern void KABI hal_interrupt_handler_25(void);
extern void KABI hal_interrupt_handler_26(void);
extern void KABI hal_interrupt_handler_27(void);
extern void KABI hal_interrupt_handler_28(void);
extern void KABI hal_interrupt_handler_29(void);
extern void KABI hal_interrupt_handler_30(void);
extern void KABI hal_interrupt_handler_31(void);
/**
* Kernel defined interrupt handlers
*/
extern void KABI hal_interrupt_handler_32(void);
extern void KABI hal_interrupt_handler_33(void);
extern void KABI hal_interrupt_handler_34(void);
extern void KABI hal_interrupt_handler_35(void);
extern void KABI hal_interrupt_handler_36(void);
extern void KABI hal_interrupt_handler_37(void);
extern void KABI hal_interrupt_handler_38(void);
extern void KABI hal_interrupt_handler_39(void);
extern void KABI hal_interrupt_handler_40(void);
extern void KABI hal_interrupt_handler_41(void);
extern void KABI hal_interrupt_handler_42(void);
extern void KABI hal_interrupt_handler_43(void);
extern void KABI hal_interrupt_handler_44(void);
extern void KABI hal_interrupt_handler_45(void);
extern void KABI hal_interrupt_handler_46(void);
extern void KABI hal_interrupt_handler_47(void);
extern void KABI hal_interrupt_handler_48(void);
extern void KABI hal_interrupt_handler_49(void);
extern void KABI hal_interrupt_handler_50(void);
extern void KABI hal_interrupt_handler_51(void);
extern void KABI hal_interrupt_handler_52(void);
extern void KABI hal_interrupt_handler_53(void);
extern void KABI hal_interrupt_handler_54(void);
extern void KABI hal_interrupt_handler_55(void);
extern void KABI hal_interrupt_handler_56(void);
extern void KABI hal_interrupt_handler_57(void);
extern void KABI hal_interrupt_handler_58(void);
extern void KABI hal_interrupt_handler_59(void);
extern void KABI hal_interrupt_handler_60(void);
extern void KABI hal_interrupt_handler_61(void);
extern void KABI hal_interrupt_handler_62(void);
extern void KABI hal_interrupt_handler_63(void);
extern void KABI hal_interrupt_handler_64(void);
extern void KABI hal_interrupt_handler_65(void);
extern void KABI hal_interrupt_handler_66(void);
extern void KABI hal_interrupt_handler_67(void);
extern void KABI hal_interrupt_handler_68(void);
extern void KABI hal_interrupt_handler_69(void);
extern void KABI hal_interrupt_handler_70(void);
extern void KABI hal_interrupt_handler_71(void);
extern void KABI hal_interrupt_handler_72(void);
extern void KABI hal_interrupt_handler_73(void);
extern void KABI hal_interrupt_handler_74(void);
extern void KABI hal_interrupt_handler_75(void);
extern void KABI hal_interrupt_handler_76(void);
extern void KABI hal_interrupt_handler_77(void);
extern void KABI hal_interrupt_handler_78(void);
extern void KABI hal_interrupt_handler_79(void);
extern void KABI hal_interrupt_handler_80(void);
extern void KABI hal_interrupt_handler_81(void);
extern void KABI hal_interrupt_handler_82(void);
extern void KABI hal_interrupt_handler_83(void);
extern void KABI hal_interrupt_handler_84(void);
extern void KABI hal_interrupt_handler_85(void);
extern void KABI hal_interrupt_handler_86(void);
extern void KABI hal_interrupt_handler_87(void);
extern void KABI hal_interrupt_handler_88(void);
extern void KABI hal_interrupt_handler_89(void);
extern void KABI hal_interrupt_handler_90(void);
extern void KABI hal_interrupt_handler_91(void);
extern void KABI hal_interrupt_handler_92(void);
extern void KABI hal_interrupt_handler_93(void);
extern void KABI hal_interrupt_handler_94(void);
extern void KABI hal_interrupt_handler_95(void);
extern void KABI hal_interrupt_handler_96(void);
extern void KABI hal_interrupt_handler_97(void);
extern void KABI hal_interrupt_handler_98(void);
extern void KABI hal_interrupt_handler_99(void);
extern void KABI hal_interrupt_handler_100(void);
extern void KABI hal_interrupt_handler_101(void);
extern void KABI hal_interrupt_handler_102(void);
extern void KABI hal_interrupt_handler_103(void);
extern void KABI hal_interrupt_handler_104(void);
extern void KABI hal_interrupt_handler_105(void);
extern void KABI hal_interrupt_handler_106(void);
extern void KABI hal_interrupt_handler_107(void);
extern void KABI hal_interrupt_handler_108(void);
extern void KABI hal_interrupt_handler_109(void);
extern void KABI hal_interrupt_handler_110(void);
extern void KABI hal_interrupt_handler_111(void);
extern void KABI hal_interrupt_handler_112(void);
extern void KABI hal_interrupt_handler_113(void);
extern void KABI hal_interrupt_handler_114(void);
extern void KABI hal_interrupt_handler_115(void);
extern void KABI hal_interrupt_handler_116(void);
extern void KABI hal_interrupt_handler_117(void);
extern void KABI hal_interrupt_handler_118(void);
extern void KABI hal_interrupt_handler_119(void);
extern void KABI hal_interrupt_handler_120(void);
extern void KABI hal_interrupt_handler_121(void);
extern void KABI hal_interrupt_handler_122(void);
extern void KABI hal_interrupt_handler_123(void);
extern void KABI hal_interrupt_handler_124(void);
extern void KABI hal_interrupt_handler_125(void);
extern void KABI hal_interrupt_handler_126(void);
extern void KABI hal_interrupt_handler_127(void);
extern void KABI hal_interrupt_handler_128(void);
extern void KABI hal_interrupt_handler_129(void);
extern void KABI hal_interrupt_handler_130(void);
extern void KABI hal_interrupt_handler_131(void);
extern void KABI hal_interrupt_handler_132(void);
extern void KABI hal_interrupt_handler_133(void);
extern void KABI hal_interrupt_handler_134(void);
extern void KABI hal_interrupt_handler_135(void);
extern void KABI hal_interrupt_handler_136(void);
extern void KABI hal_interrupt_handler_137(void);
extern void KABI hal_interrupt_handler_138(void);
extern void KABI hal_interrupt_handler_139(void);
extern void KABI hal_interrupt_handler_140(void);
extern void KABI hal_interrupt_handler_141(void);
extern void KABI hal_interrupt_handler_142(void);
extern void KABI hal_interrupt_handler_143(void);
extern void KABI hal_interrupt_handler_144(void);
extern void KABI hal_interrupt_handler_145(void);
extern void KABI hal_interrupt_handler_146(void);
extern void KABI hal_interrupt_handler_147(void);
extern void KABI hal_interrupt_handler_148(void);
extern void KABI hal_interrupt_handler_149(void);
extern void KABI hal_interrupt_handler_150(void);
extern void KABI hal_interrupt_handler_151(void);
extern void KABI hal_interrupt_handler_152(void);
extern void KABI hal_interrupt_handler_153(void);
extern void KABI hal_interrupt_handler_154(void);
extern void KABI hal_interrupt_handler_155(void);
extern void KABI hal_interrupt_handler_156(void);
extern void KABI hal_interrupt_handler_157(void);
extern void KABI hal_interrupt_handler_158(void);
extern void KABI hal_interrupt_handler_159(void);
extern void KABI hal_interrupt_handler_160(void);
extern void KABI hal_interrupt_handler_161(void);
extern void KABI hal_interrupt_handler_162(void);
extern void KABI hal_interrupt_handler_163(void);
extern void KABI hal_interrupt_handler_164(void);
extern void KABI hal_interrupt_handler_165(void);
extern void KABI hal_interrupt_handler_166(void);
extern void KABI hal_interrupt_handler_167(void);
extern void KABI hal_interrupt_handler_168(void);
extern void KABI hal_interrupt_handler_169(void);
extern void KABI hal_interrupt_handler_170(void);
extern void KABI hal_interrupt_handler_171(void);
extern void KABI hal_interrupt_handler_172(void);
extern void KABI hal_interrupt_handler_173(void);
extern void KABI hal_interrupt_handler_174(void);
extern void KABI hal_interrupt_handler_175(void);
extern void KABI hal_interrupt_handler_176(void);
extern void KABI hal_interrupt_handler_177(void);
extern void KABI hal_interrupt_handler_178(void);
extern void KABI hal_interrupt_handler_179(void);
extern void KABI hal_interrupt_handler_180(void);
extern void KABI hal_interrupt_handler_181(void);
extern void KABI hal_interrupt_handler_182(void);
extern void KABI hal_interrupt_handler_183(void);
extern void KABI hal_interrupt_handler_184(void);
extern void KABI hal_interrupt_handler_185(void);
extern void KABI hal_interrupt_handler_186(void);
extern void KABI hal_interrupt_handler_187(void);
extern void KABI hal_interrupt_handler_188(void);
extern void KABI hal_interrupt_handler_189(void);
extern void KABI hal_interrupt_handler_190(void);
extern void KABI hal_interrupt_handler_191(void);
extern void KABI hal_interrupt_handler_192(void);
extern void KABI hal_interrupt_handler_193(void);
extern void KABI hal_interrupt_handler_194(void);
extern void KABI hal_interrupt_handler_195(void);
extern void KABI hal_interrupt_handler_196(void);
extern void KABI hal_interrupt_handler_197(void);
extern void KABI hal_interrupt_handler_198(void);
extern void KABI hal_interrupt_handler_199(void);
extern void KABI hal_interrupt_handler_200(void);
extern void KABI hal_interrupt_handler_201(void);
extern void KABI hal_interrupt_handler_202(void);
extern void KABI hal_interrupt_handler_203(void);
extern void KABI hal_interrupt_handler_204(void);
extern void KABI hal_interrupt_handler_205(void);
extern void KABI hal_interrupt_handler_206(void);
extern void KABI hal_interrupt_handler_207(void);
extern void KABI hal_interrupt_handler_208(void);
extern void KABI hal_interrupt_handler_209(void);
extern void KABI hal_interrupt_handler_210(void);
extern void KABI hal_interrupt_handler_211(void);
extern void KABI hal_interrupt_handler_212(void);
extern void KABI hal_interrupt_handler_213(void);
extern void KABI hal_interrupt_handler_214(void);
extern void KABI hal_interrupt_handler_215(void);
extern void KABI hal_interrupt_handler_216(void);
extern void KABI hal_interrupt_handler_217(void);
extern void KABI hal_interrupt_handler_218(void);
extern void KABI hal_interrupt_handler_219(void);
extern void KABI hal_interrupt_handler_220(void);
extern void KABI hal_interrupt_handler_221(void);
extern void KABI hal_interrupt_handler_222(void);
extern void KABI hal_interrupt_handler_223(void);
extern void KABI hal_interrupt_handler_224(void);
extern void KABI hal_interrupt_handler_225(void);
extern void KABI hal_interrupt_handler_226(void);
extern void KABI hal_interrupt_handler_227(void);
extern void KABI hal_interrupt_handler_228(void);
extern void KABI hal_interrupt_handler_229(void);
extern void KABI hal_interrupt_handler_230(void);
extern void KABI hal_interrupt_handler_231(void);
extern void KABI hal_interrupt_handler_232(void);
extern void KABI hal_interrupt_handler_233(void);
extern void KABI hal_interrupt_handler_234(void);
extern void KABI hal_interrupt_handler_235(void);
extern void KABI hal_interrupt_handler_236(void);
extern void KABI hal_interrupt_handler_237(void);
extern void KABI hal_interrupt_handler_238(void);
extern void KABI hal_interrupt_handler_239(void);
extern void KABI hal_interrupt_handler_240(void);
extern void KABI hal_interrupt_handler_241(void);
extern void KABI hal_interrupt_handler_242(void);
extern void KABI hal_interrupt_handler_243(void);
extern void KABI hal_interrupt_handler_244(void);
extern void KABI hal_interrupt_handler_245(void);
extern void KABI hal_interrupt_handler_246(void);
extern void KABI hal_interrupt_handler_247(void);
extern void KABI hal_interrupt_handler_248(void);
extern void KABI hal_interrupt_handler_249(void);
extern void KABI hal_interrupt_handler_250(void);
extern void KABI hal_interrupt_handler_251(void);
extern void KABI hal_interrupt_handler_252(void);
extern void KABI hal_interrupt_handler_253(void);
extern void KABI hal_interrupt_handler_254(void);
extern void KABI hal_interrupt_handler_255(void);

View File

@ -12,7 +12,7 @@
typedef struct
{
void* krnl_end;
void *krnl_end;
intr_info_t intr_info;
char cpu_vd_str[13];
} boot_info_t;

View File

@ -13,7 +13,9 @@ typedef uint32_t irql_t;
#define IRQL_PASSIVE_LEVEL (1 << 0)
irql_t KABI hal_set_irql(irql_t irql);
irql_t KABI hal_get_irql(void);
uint32_t KABI hal_get_core_id(void);
/**
@ -26,9 +28,9 @@ typedef struct
uint32_t dpc_intr_vec;
} intr_info_t;
typedef void (KABI * intr_handler_t)(void *context, void *intr_stack);
typedef void (KABI *intr_handler_t)(void *context, void *intr_stack);
void KABI hal_register_interrupt_handler(uint32_t coreid, uint32_t index, intr_handler_t handler, void* context);
void KABI hal_register_interrupt_handler(uint32_t coreid, uint32_t index, intr_handler_t handler, void *context);
void KABI hal_deregister_interrupt_handler(uint32_t coreid, uint32_t index);

View File

@ -3,6 +3,6 @@
#include "type.h"
void KABI hal_vprintf(const char* str, va_list args);
void KABI hal_vprintf(const char *str, va_list args);
#endif

View File

@ -5,7 +5,7 @@
void KABI ke_alloc_init(void);
void* KABI ke_alloc(uint32_t size);
void *KABI ke_alloc(uint32_t size);
void KABI ke_free(void *ptr);

View File

@ -3,7 +3,7 @@
#include "type.h"
void KABI ke_assert_ex(const char* expr_str, const char* file, int32_t line, int32_t expr);
void KABI ke_assert_ex(const char *expr_str, const char *file, int32_t line, int32_t expr);
#define ke_assert(expr) ke_assert_ex(#expr, __FILE__, __LINE__, expr)

View File

@ -4,7 +4,8 @@
#include "type.h"
#include "kernel/hal/print.h"
void KABI ke_printf(const char* str, ...);
void KABI ke_vprintf(const char* str, va_list args);
void KABI ke_printf(const char *str, ...);
void KABI ke_vprintf(const char *str, va_list args);
#endif

View File

@ -1,5 +1,6 @@
#ifndef _KERNEL_KE_RWLOCK_H_
#define _KERNEL_KE_RWLOCK_H_
#include "kernel/ke/spin_lock.h"
#include "type.h"

View File

@ -5,7 +5,7 @@
void KABI lb_salloc_init(void *base, uint32_t size);
void* KABI lb_salloc(void *base, uint32_t size);
void *KABI lb_salloc(void *base, uint32_t size);
void KABI lb_sfree(void *base, void *ptr);

View File

@ -87,44 +87,44 @@ static inline uint32_t KAPI log_base_2(uint64_t num)
static inline uint64_t KABI lb_bit_mask(uint32_t bit)
{
return (uint64_t)1 << bit;
return (uint64_t) 1 << bit;
}
static inline uint64_t KABI lb_bit_field_mask(uint32_t low, uint32_t high)
{
return ~(~(uint64_t)0 << high << 1) << low;
return ~(~(uint64_t) 0 << high << 1) << low;
}
static inline void KABI lb_bit_map_set(void *bit_map, uint64_t bit)
{
if(bit_map != NULL)
if (bit_map != NULL)
{
uint64_t quot = bit >> 3;
uint32_t rmd = (uint32_t)(bit & lb_bit_field_mask(0, 2));
uint32_t rmd = (uint32_t) (bit & lb_bit_field_mask(0, 2));
*((uint8_t*)(bit_map) + quot) |= (uint8_t) lb_bit_mask(rmd);
*((uint8_t *) (bit_map) + quot) |= (uint8_t) lb_bit_mask(rmd);
}
}
static inline void KABI lb_bit_map_clear(void *bit_map, uint64_t bit)
{
if(bit_map != NULL)
if (bit_map != NULL)
{
uint64_t quot = bit >> 3;
uint32_t rmd = (uint32_t)(bit & lb_bit_field_mask(0, 2));
uint32_t rmd = (uint32_t) (bit & lb_bit_field_mask(0, 2));
*((uint8_t*)(bit_map) + quot) &= ~(uint8_t) lb_bit_mask(rmd);
*((uint8_t *) (bit_map) + quot) &= ~(uint8_t) lb_bit_mask(rmd);
}
}
static inline uint32_t KABI lb_bit_map_read(void *bit_map, uint64_t bit)
{
if(bit_map != NULL)
if (bit_map != NULL)
{
uint64_t quot = bit >> 3;
uint32_t rmd = (uint32_t)(bit & lb_bit_field_mask(0, 2));
uint32_t rmd = (uint32_t) (bit & lb_bit_field_mask(0, 2));
return (*((uint8_t*)(bit_map) + quot) & (uint8_t) lb_bit_mask(rmd)) == 0 ? 0 : 1;
return (*((uint8_t *) (bit_map) + quot) & (uint8_t) lb_bit_mask(rmd)) == 0 ? 0 : 1;
}
return 0;
}

View File

@ -2,9 +2,9 @@
#include "kernel/ke/assert.h"
#include "kernel/ke/print.h"
void ke_assert_ex(const char* expr_str, const char* file, int32_t line, int32_t expr)
void ke_assert_ex(const char *expr_str, const char *file, int32_t line, int32_t expr)
{
if(!expr)
if (!expr)
{
ke_printf("Assertion \"%s\" failed at %s:%d.\n", expr_str, file, line);
}

View File

@ -4,7 +4,8 @@
void KABI ke_trap(void)
{
while(true){};
while (true)
{};
}
void KABI ke_panic(uint64_t reason)

View File

@ -1,6 +1,6 @@
#include "kernel/ke/print.h"
void KABI ke_printf(const char* str, ...)
void KABI ke_printf(const char *str, ...)
{
va_list args;
va_start(args, str);
@ -9,7 +9,7 @@ void KABI ke_printf(const char* str, ...)
return;
}
void KABI ke_vprintf(const char* str, va_list args)
void KABI ke_vprintf(const char *str, va_list args)
{
hal_vprintf(str, args);
return;

View File

@ -13,7 +13,8 @@ void KABI ke_spin_lock(k_spin_lock_t *lock)
{
if (lock != NULL)
{
while (ke_interlocked_compare_exchange_32(&lock->val, 0, 1) != 0);
while (ke_interlocked_compare_exchange_32(&lock->val, 0, 1) != 0)
{}
}
return;
}

View File

@ -33,11 +33,20 @@ static int32_t mmp_base_paddr_compare(void *tree_node, void *my_node)
physical_page_descriptor_t,
avl_tree_node)->base;
if (tree_base > my_base)
{
return 1;
else if (tree_base < my_base)
return -1;
}
else
{
if (tree_base < my_base)
{
return -1;
}
else
{
return 0;
}
}
}
status_t KABI sx_pmm_init(pmm_info_t *info)
@ -112,7 +121,8 @@ status_t KABI mm_alloc_page(uintptr_t *out)
free_list_node);
lb_avl_tree_insert(&active_tree, &page_info->avl_tree_node);
*out = page_info->base;
} else
}
else
{
result = MM_NOT_ENOUGH_PAGE;
}
@ -147,7 +157,8 @@ status_t KABI mm_query_page_attr(uintptr_t base,
{
page_info = OBTAIN_STRUCT_ADDR(node, physical_page_descriptor_t, avl_tree_node);
*out = page_info->attr;
} else
}
else
{
result = MM_INVALID_ARGUMENTS;
}
@ -177,7 +188,8 @@ status_t KABI mm_free_page(uintptr_t base)
{
page_info = OBTAIN_STRUCT_ADDR(node, physical_page_descriptor_t, avl_tree_node);
lb_linked_list_push_back(&free_list, &page_info->free_list_node);
} else
}
else
{
result = MM_INVALID_ARGUMENTS;
}

View File

@ -36,11 +36,20 @@ static int32_t rfp_handle_compare(void *tree_node, void *my_node)
handle_node_t *my_tcb = OBTAIN_STRUCT_ADDR(my_node, handle_node_t, tree_node);
if ((uintptr_t) tcb->handle > (uintptr_t) my_tcb->handle)
{
return -1;
else if ((uintptr_t) tcb->handle == (uintptr_t) my_tcb->handle)
return 0;
}
else
{
if ((uintptr_t) tcb->handle == (uintptr_t) my_tcb->handle)
{
return 0;
}
else
{
return 1;
}
}
}
static handle_node_t *rfp_search_handle_node(handle_t handle)
@ -70,7 +79,9 @@ status_t KABI rf_reference_create(ref_node_t *ref,
ke_assert(ke_get_irql() <= IRQL_DPC_LEVEL);
if (ref == NULL || free_func == NULL)
{
return RF_INVALID_ARGUMENTS;
}
ref->free_routine = free_func;
ref->ref_count = 1;
@ -83,7 +94,9 @@ status_t KABI rf_reference_obj(ref_node_t *ref_node)
ke_assert(ke_get_irql() <= IRQL_DPC_LEVEL);
if (ref_node == NULL)
{
return RF_INVALID_ARGUMENTS;
}
int32_t old_ref_count = ke_interlocked_increment_32(&ref_node->ref_count, 1);
@ -97,7 +110,9 @@ status_t KABI rf_dereference_obj(ref_node_t *ref_node)
ke_assert(ke_get_irql() <= IRQL_DPC_LEVEL);
if (ref_node == NULL)
{
return RF_INVALID_ARGUMENTS;
}
status_t result = STATUS_SUCCESS;
@ -138,7 +153,8 @@ static status_t KABI rf_open_obj_by_handle(handle_t handle, ref_node_t **out)
if (handle_node == NULL)
{
status = RF_INVALID_HANDLE;
} else
}
else
{
ref = handle_node->ref;
}
@ -164,10 +180,14 @@ static status_t KABI rf_create_handle(ref_node_t *ref,
ke_assert(ke_get_irql() <= IRQL_DPC_LEVEL);
if (!initialized)
{
return RF_UNINITIALIZED;
}
if (ref == NULL || node == NULL || out == NULL)
{
return RF_INVALID_ARGUMENTS;
}
status_t result = STATUS_SUCCESS;
irql_t irql;
@ -183,7 +203,8 @@ static status_t KABI rf_create_handle(ref_node_t *ref,
if (existing_node == NULL)
{
lb_avl_tree_insert(&handle_tree, &node->tree_node);
} else
}
else
{
result = RF_DUPLICATED_HANDLE;
}
@ -196,7 +217,8 @@ static status_t KABI rf_create_handle(ref_node_t *ref,
{
rf_reference_obj(ref);
*out = node->handle;
} else
}
else
{
node->free_routine(node, NULL);
}
@ -209,7 +231,9 @@ static status_t KABI rf_close_handle(handle_t handle)
ke_assert(ke_get_irql() <= IRQL_DPC_LEVEL);
if (!initialized)
{
return RF_UNINITIALIZED;
}
irql_t irql;
status_t status = STATUS_SUCCESS;
@ -221,7 +245,8 @@ static status_t KABI rf_close_handle(handle_t handle)
if (handle_node == NULL)
{
status = RF_INVALID_HANDLE;
} else
}
else
{
ref = handle_node->ref;
lb_avl_tree_delete(&handle_tree, &handle_node->tree_node);
@ -253,7 +278,9 @@ status_t KABI sx_create_handle(ref_node_t *ref, handle_t *out)
ke_assert(ke_get_irql() <= IRQL_DPC_LEVEL);
if (!initialized)
{
return RF_UNINITIALIZED;
}
handle_node_t *node;
node = (handle_node_t *) ke_alloc(sizeof(handle_node_t));
@ -272,7 +299,9 @@ status_t KABI sx_close_handle(handle_t handle)
ke_assert(ke_get_irql() <= IRQL_DPC_LEVEL);
if (!initialized)
{
return RF_UNINITIALIZED;
}
// need to keep sx version since need to do handle check here
@ -284,10 +313,14 @@ status_t KABI sx_open_obj_by_handle(handle_t handle, ref_node_t **out)
ke_assert(ke_get_irql() <= IRQL_DPC_LEVEL);
if (!initialized)
{
return RF_UNINITIALIZED;
}
if (out == NULL)
{
return RF_INVALID_ARGUMENTS;
}
// check special handles first
// if (handle == K_HANDLE_CURRENT_THREAD)

View File

@ -8,7 +8,9 @@ static inline int32_t KABI lbp_avl_tree_node_get_height(avl_tree_node_t *node)
static inline int32_t KABI lbp_avl_tree_node_get_balance_factor(avl_tree_node_t *node)
{
if (node == NULL)
{
return 0;
}
return lbp_avl_tree_node_get_height(node->left) - lbp_avl_tree_node_get_height(node->right);
}
@ -19,7 +21,9 @@ static avl_tree_node_t *KABI lbp_avl_tree_node_right_rotate(avl_tree_node_t *roo
left_children->parent = root->parent;
root->parent = left_children;
if (left_children->right != NULL)
{
left_children->right->parent = root;
}
//perform rotation
root->left = root->left->right;
left_children->right = root;
@ -38,7 +42,9 @@ static avl_tree_node_t *KABI lbp_avl_tree_node_left_rotate(avl_tree_node_t *root
right_children->parent = root->parent;
root->parent = right_children;
if (right_children->left != NULL)
{
right_children->left->parent = root;
}
//perform rotation
root->right = root->right->left;
right_children->left = root;
@ -59,8 +65,10 @@ static avl_tree_node_t *KABI lbp_avl_tree_node_balance(avl_tree_node_t *node)
{
const int32_t left_bf = lbp_avl_tree_node_get_balance_factor(node->left);
if (left_bf >= 0)
{
//left left
return lbp_avl_tree_node_right_rotate(node);
}
else
{
//left right
@ -68,7 +76,9 @@ static avl_tree_node_t *KABI lbp_avl_tree_node_balance(avl_tree_node_t *node)
return lbp_avl_tree_node_right_rotate(node);
}
}
else if (bf < -1)
else
{
if (bf < -1)
{
const int32_t right_bf = lbp_avl_tree_node_get_balance_factor(node->right);
if (right_bf <= 0)
@ -84,7 +94,10 @@ static avl_tree_node_t *KABI lbp_avl_tree_node_balance(avl_tree_node_t *node)
}
}
else
{
return node;
}
}
}
@ -93,7 +106,9 @@ static avl_tree_node_t *KABI lbp_avl_tree_node_insert(avl_tree_node_t *root, avl
avl_tree_node_t *parent)
{
if (node == NULL || compare == NULL)
{
return root;
}
if (root == NULL)
{
node->parent = parent;
@ -102,11 +117,20 @@ static avl_tree_node_t *KABI lbp_avl_tree_node_insert(avl_tree_node_t *root, avl
const int32_t comp = compare(root, node);
if (comp < 0)
{
root->right = lbp_avl_tree_node_insert(root->right, node, compare, root);
else if (comp == 0)
return root;
}
else
{
if (comp == 0)
{
return root;
}
else
{
root->left = lbp_avl_tree_node_insert(root->left, node, compare, root);
}
}
root->height = lb_max_32(lbp_avl_tree_node_get_height(root->left), lbp_avl_tree_node_get_height(root->right)) + 1;
@ -116,7 +140,9 @@ static avl_tree_node_t *KABI lbp_avl_tree_node_insert(avl_tree_node_t *root, avl
static void lbp_avl_tree_swap_nodes(avl_tree_node_t *node1, avl_tree_node_t *node2)
{
if (node1 == NULL || node2 == NULL)
{
return;
}
avl_tree_node_t *parent = NULL;
avl_tree_node_t *child = NULL;
avl_tree_node_t *temp = NULL;
@ -126,11 +152,14 @@ static void lbp_avl_tree_swap_nodes(avl_tree_node_t *node1, avl_tree_node_t *nod
parent = node2;
child = node1;
}
else if (node2->parent != NULL && node2->parent == node1)
else
{
if (node2->parent != NULL && node2->parent == node1)
{
parent = node1;
child = node2;
}
}
if (parent != NULL && child != NULL)
{
@ -138,10 +167,14 @@ static void lbp_avl_tree_swap_nodes(avl_tree_node_t *node1, avl_tree_node_t *nod
if (parent->parent != NULL)
{
if (parent->parent->left == parent)
{
parent->parent->left = child;
}
else
{
parent->parent->right = child;
}
}
//update left/right for parent
if (parent->left != NULL && child != parent->left)
{
@ -153,9 +186,13 @@ static void lbp_avl_tree_swap_nodes(avl_tree_node_t *node1, avl_tree_node_t *nod
}
//update left/right for children
if (child->left != NULL)
{
child->left->parent = parent;
}
if (child->right != NULL)
{
child->right->parent = parent;
}
child->parent = parent->parent;
parent->parent = child;
@ -189,30 +226,46 @@ static void lbp_avl_tree_swap_nodes(avl_tree_node_t *node1, avl_tree_node_t *nod
//not connected case
//adjust all the nodes other than node1,node2
if (node1->left != NULL)
{
node1->left->parent = node2;
}
if (node1->right != NULL)
{
node1->right->parent = node2;
}
if (node2->left != NULL)
{
node2->left->parent = node1;
}
if (node2->right != NULL)
{
node2->right->parent = node1;
}
if (node1->parent != NULL)
{
if (node1->parent->left == node1)
{
node1->parent->left = node2;
}
else
{
node1->parent->right = node2;
}
}
if (node2->parent != NULL)
{
if (node2->parent->left == node2)
{
node2->parent->left = node1;
}
else
{
node2->parent->right = node1;
}
}
//adjust node1,node2
temp = node1->parent;
@ -241,12 +294,20 @@ static avl_tree_node_t *KABI lbp_avl_tree_node_delete(avl_tree_node_t *root,
avl_tree_node_t **deleted_node)
{
if (root == NULL || node == NULL || compare == NULL || deleted_node == NULL)
{
return root;
}
const int32_t comp = compare(root, node);
if (comp < 0)
{
root->right = lbp_avl_tree_node_delete(root->right, node, compare, deleted_node);
else if (comp > 0)
}
else
{
if (comp > 0)
{
root->left = lbp_avl_tree_node_delete(root->left, node, compare, deleted_node);
}
else
{
*deleted_node = root;
@ -279,8 +340,11 @@ static avl_tree_node_t *KABI lbp_avl_tree_node_delete(avl_tree_node_t *root,
root = successor;
}
}
}
if (root == NULL)
{
return root;
}
root->height = lb_max_32(lbp_avl_tree_node_get_height(root->left), lbp_avl_tree_node_get_height(root->right)) + 1;
root = lbp_avl_tree_node_balance(root);
return root;
@ -290,14 +354,25 @@ static avl_tree_node_t *KABI lbp_avl_tree_node_search(avl_tree_node_t *root, avl
callback_func_t compare)
{
if (root == NULL || compare == NULL)
{
return NULL;
}
const int32_t comp = compare(root, node);
if (comp < 0)
{
return lbp_avl_tree_node_search(root->right, node, compare);
else if (comp == 0)
return root;
}
else
{
if (comp == 0)
{
return root;
}
else
{
return lbp_avl_tree_node_search(root->left, node, compare);
}
}
}
@ -317,24 +392,36 @@ static void KABI lbp_avl_tree_node_init(avl_tree_node_t *it)
avl_tree_node_t *KABI lb_avl_tree_smallest(avl_tree_t *tree)
{
if (tree == NULL)
{
return NULL;
}
avl_tree_node_t *entry = tree->root;
if (entry == NULL)
{
return NULL;
}
while (entry->left != NULL)
{
entry = entry->left;
}
return entry;
}
avl_tree_node_t *KABI lb_avl_tree_largest(avl_tree_t *tree)
{
if (tree == NULL)
{
return NULL;
}
avl_tree_node_t *entry = tree->root;
if (entry == NULL)
{
return NULL;
}
while (entry->right != NULL)
{
entry = entry->right;
}
return entry;
}
@ -342,13 +429,17 @@ avl_tree_node_t *KABI lb_avl_tree_largest(avl_tree_t *tree)
avl_tree_node_t *KABI lb_avl_tree_larger(avl_tree_node_t *it)
{
if (it == NULL)
{
return NULL;
}
avl_tree_node_t *root = it;
if (root->right != NULL)
{
root = root->right;
while (root->left != NULL)
{
root = root->left;
}
return root;
}
else
@ -356,7 +447,9 @@ avl_tree_node_t *KABI lb_avl_tree_larger(avl_tree_node_t *it)
while (root->parent != NULL)
{
if (root->parent->left == root)
{
return root->parent;
}
root = root->parent;
}
return NULL;
@ -366,13 +459,17 @@ avl_tree_node_t *KABI lb_avl_tree_larger(avl_tree_node_t *it)
avl_tree_node_t *KABI lb_avl_tree_smaller(avl_tree_node_t *it)
{
if (it == NULL)
{
return NULL;
}
avl_tree_node_t *root = it;
if (root->left != NULL)
{
root = root->left;
while (root->right != NULL)
{
root = root->right;
}
return root;
}
else
@ -380,7 +477,9 @@ avl_tree_node_t *KABI lb_avl_tree_smaller(avl_tree_node_t *it)
while (root->parent != NULL)
{
if (root->parent->right == root)
{
return root->parent;
}
root = root->parent;
}
return NULL;
@ -416,9 +515,13 @@ avl_tree_node_t *KABI lb_avl_tree_delete(avl_tree_t *tree, avl_tree_node_t *data
int32_t KABI lb_avl_tree_size(avl_tree_t *tree)
{
if (tree == NULL)
{
return -1;
}
if (tree->root == NULL)
{
return 0;
}
int32_t size = 0;
avl_tree_node_t *entry = lb_avl_tree_smallest(tree);
while (entry != NULL)
@ -446,39 +549,54 @@ void KABI lb_avl_tree_init(avl_tree_t *tree, callback_func_t compare)
static int32_t KABI lbp_avl_tree_node_calculate_height(avl_tree_node_t *tree)
{
if (tree == NULL)
{
return -1;
return lb_max_32(lbp_avl_tree_node_calculate_height(tree->left), lbp_avl_tree_node_calculate_height(tree->right)) + 1;
}
return lb_max_32(lbp_avl_tree_node_calculate_height(tree->left), lbp_avl_tree_node_calculate_height(tree->right)) +
1;
}
static bool KABI lbp_avl_tree_node_test(avl_tree_node_t *tree, callback_func_t compare)
{
if (tree == NULL)
{
return true;
}
if (lbp_avl_tree_node_get_balance_factor(tree) < -1 || lbp_avl_tree_node_get_balance_factor(tree) > 1 ||
lbp_avl_tree_node_calculate_height(tree) != tree->height)
{
return false;
}
if (tree->left != NULL)
{
if (tree->left->parent != tree)
{
return false;
}
}
if (tree->right != NULL)
{
if (tree->right->parent != tree)
{
return false;
}
}
if (compare != NULL)
{
if ((tree->right != NULL && compare(tree, tree->right) > 0) ||
(tree->left != NULL && compare(tree, tree->left) < 0))
{
return false;
}
}
return lbp_avl_tree_node_test(tree->left, compare) && lbp_avl_tree_node_test(tree->right, compare);
}
bool KABI lb_avl_tree_validate(avl_tree_t *tree)
{
if (tree == NULL)
{
return true;
}
return lbp_avl_tree_node_test(tree->root, tree->compare);
}

View File

@ -12,12 +12,14 @@ static void KABI lbp_init_linked_list_node(linked_list_node_t *node)
static void KABI lbp_append_node(linked_list_node_t *target, linked_list_node_t *node)
{
if(target == NULL || node == NULL)
if (target == NULL || node == NULL)
{
return;
}
linked_list_node_t* next = target->next;
linked_list_node_t *next = target->next;
// update the next node
if(next != NULL)
if (next != NULL)
{
next->prev = node;
}
@ -35,12 +37,14 @@ static void KABI lbp_append_node(linked_list_node_t *target, linked_list_node_t
// link target with node, suppose target is in the current list
static void KABI lbp_prepend_node(linked_list_node_t *target, linked_list_node_t *node)
{
if(target == NULL || node == NULL)
if (target == NULL || node == NULL)
{
return;
}
linked_list_node_t* prev = target->prev;
linked_list_node_t *prev = target->prev;
// update the prev node
if(prev != NULL)
if (prev != NULL)
{
prev->next = node;
}
@ -57,15 +61,17 @@ static void KABI lbp_prepend_node(linked_list_node_t *target, linked_list_node_t
static void KABI lbp_unlink_node(linked_list_node_t *node)
{
if(node == NULL)
if (node == NULL)
{
return;
}
if(node->prev != NULL)
if (node->prev != NULL)
{
node->prev->next = node->next;
}
if(node->next != NULL)
if (node->next != NULL)
{
node->next->prev = node->prev;
}
@ -86,9 +92,13 @@ void KABI lb_linked_list_init(linked_list_t *list)
int32_t KABI lb_linked_list_size(linked_list_t *list)
{
if (list == NULL)
{
return -1;
}
if (list->head == NULL)
{
return 0;
}
int32_t size = 1;
linked_list_node_t *cur_node = list->head;
@ -103,7 +113,9 @@ int32_t KABI lb_linked_list_size(linked_list_t *list)
void KABI lb_linked_list_push_front(linked_list_t *list, linked_list_node_t *node)
{
if (list == NULL || node == NULL)
{
return;
}
lbp_init_linked_list_node(node);
@ -115,7 +127,9 @@ void KABI lb_linked_list_push_front(linked_list_t *list, linked_list_node_t *nod
void KABI lb_linked_list_push_back(linked_list_t *list, linked_list_node_t *node)
{
if (list == NULL || node == NULL)
{
return;
}
lbp_init_linked_list_node(node);
@ -127,14 +141,18 @@ void KABI lb_linked_list_push_back(linked_list_t *list, linked_list_node_t *node
linked_list_node_t *KABI lb_linked_list_pop_front(linked_list_t *list)
{
if (list == NULL)
{
return NULL;
}
return lb_linked_list_remove_ref(list, list->head);
}
linked_list_node_t *KABI lb_linked_list_pop_back(linked_list_t *list)
{
if (list == NULL)
{
return NULL;
}
return lb_linked_list_remove_ref(list, list->tail);
}
@ -143,7 +161,9 @@ linked_list_node_t *KABI lb_linked_list_pop_back(linked_list_t *list)
void KABI lb_linked_list_insert_ref(linked_list_t *list, linked_list_node_t *prev_node, linked_list_node_t *node)
{
if (list == NULL || node == NULL)
{
return;
}
lbp_init_linked_list_node(node);
if (prev_node == NULL)
{
@ -178,7 +198,9 @@ void KABI lb_linked_list_insert_ref(linked_list_t *list, linked_list_node_t *pre
void KABI lb_linked_list_insert(linked_list_t *list, int32_t index, linked_list_node_t *node)
{
if (list == NULL || index < 0 || node == NULL)
{
return;
}
linked_list_node_t *prev_node = lb_linked_list_get(list, index - 1);
lbp_init_linked_list_node(node);
@ -200,11 +222,15 @@ void KABI lb_linked_list_insert(linked_list_t *list, int32_t index, linked_list_
linked_list_node_t *KABI lb_linked_list_remove(linked_list_t *list, int32_t index)
{
if (list == NULL || index < 0)
{
return NULL;
}
linked_list_node_t *cur_node = lb_linked_list_get(list, index);
if (cur_node == NULL)
{
return NULL;
}
return lb_linked_list_remove_ref(list, cur_node);
}
@ -212,16 +238,18 @@ linked_list_node_t *KABI lb_linked_list_remove(linked_list_t *list, int32_t inde
linked_list_node_t *KABI lb_linked_list_remove_ref(linked_list_t *list, linked_list_node_t *node)
{
if (list == NULL || node == NULL)
{
return NULL;
}
lbp_unlink_node(node);
if(node->next == NULL)
if (node->next == NULL)
{
list->tail = node->prev;
}
if(node->prev == NULL)
if (node->prev == NULL)
{
list->head = node->next;
}
@ -234,9 +262,12 @@ linked_list_node_t *KABI lb_linked_list_remove_ref(linked_list_t *list, linked_l
linked_list_node_t *KABI lb_linked_list_get(linked_list_t *list, int32_t index)
{
if (list == NULL || index < 0 || list->head == NULL)
{
return NULL;
}
linked_list_node_t *cur_node = list->head;
while (index-- && (cur_node = cur_node->next) != NULL);
while (index-- && (cur_node = cur_node->next) != NULL)
{}
return cur_node;
}
@ -281,13 +312,15 @@ linked_list_node_t *KABI lb_linked_list_last(linked_list_t *list)
int32_t KABI lb_linked_list_search(linked_list_t *list, linked_list_node_t *target,
callback_func_t equals)
{
if(list == NULL || target == NULL)
return -1;
int32_t result = 0;
linked_list_node_t* node = lb_linked_list_first(list);
while(node != NULL)
if (list == NULL || target == NULL)
{
if(equals != NULL)
return -1;
}
int32_t result = 0;
linked_list_node_t *node = lb_linked_list_first(list);
while (node != NULL)
{
if (equals != NULL)
{
if (equals(node, target))
{
@ -296,7 +329,7 @@ int32_t KABI lb_linked_list_search(linked_list_t *list, linked_list_node_t *targ
}
else
{
if(target->next == node->next && target->prev == node->prev)
if (target->next == node->next && target->prev == node->prev)
{
return result;
}

View File

@ -24,8 +24,8 @@ void KABI lb_mem_set(void *src, uint8_t const val, uint64_t size)
}
while (size--)
{
*(uint8_t *)src = val;
src = (void*)((uintptr_t)src + 1);
*(uint8_t *) src = val;
src = (void *) ((uintptr_t) src + 1);
}
return;
}
@ -41,13 +41,13 @@ void KABI lb_mem_move(void *src, void *dst, uint64_t size)
lb_mem_copy(src, dst, size);
return;
}
src = (void*)((uintptr_t)src + size - 1);
dst = (void*)((uintptr_t)dst + size - 1);
src = (void *) ((uintptr_t) src + size - 1);
dst = (void *) ((uintptr_t) dst + size - 1);
while (size--)
{
*(char*)dst = *(char*)src;
dst = (void*)((uintptr_t)dst - 1);
src = (void*)((uintptr_t)src - 1);
*(char *) dst = *(char *) src;
dst = (void *) ((uintptr_t) dst - 1);
src = (void *) ((uintptr_t) src - 1);
}
return;
}

View File

@ -16,8 +16,8 @@ static int_tree_node *create_tree_node(int val)
static int32_t compare(void *root1, void *node1)
{
avl_tree_node_t *root = (avl_tree_node_t*)node1;
avl_tree_node_t *node = (avl_tree_node_t*)root1;
avl_tree_node_t *root = (avl_tree_node_t *) node1;
avl_tree_node_t *node = (avl_tree_node_t *) root1;
int_tree_node *rooti = OBTAIN_STRUCT_ADDR(root, int_tree_node, tree_entry);
int_tree_node *nodei = OBTAIN_STRUCT_ADDR(node, int_tree_node, tree_entry);
return rooti->val - nodei->val;
@ -45,9 +45,13 @@ static int counter = 0;
static bool _pre_order_assert(avl_tree_node_t *node, int order[], int size)
{
if (node == NULL)
{
return true;
}
if (counter >= size)
{
return false;
}
bool result = true;
int_tree_node *my_node = OBTAIN_STRUCT_ADDR(node, int_tree_node, tree_entry);
@ -815,10 +819,10 @@ static bool test_apocalypse(void)
lb_avl_tree_init(&tree, compare);
// insert test
for(int i = 0; i < AVL_APOCALYPSE_NUM; i++)
for (int i = 0; i < AVL_APOCALYPSE_NUM; i++)
{
apocalypse[i].val = lb_rand();
while(lb_avl_tree_search(&tree, &apocalypse[i].tree_entry) != NULL)
while (lb_avl_tree_search(&tree, &apocalypse[i].tree_entry) != NULL)
{
apocalypse[i].val += lb_rand() % 32765;
}
@ -830,13 +834,13 @@ static bool test_apocalypse(void)
result = result && lb_avl_tree_size(&tree) == AVL_APOCALYPSE_NUM;
// smaller and bigger test
avl_tree_node_t* entry = lb_avl_tree_smallest(&tree);
avl_tree_node_t *entry = lb_avl_tree_smallest(&tree);
uint32_t size = 0;
int32_t prev = -1;
int32_t cur = OBTAIN_STRUCT_ADDR(entry, int_tree_node, tree_entry)->val;
while(entry != NULL)
while (entry != NULL)
{
if(cur < prev)
if (cur < prev)
{
result = false;
break;
@ -844,7 +848,7 @@ static bool test_apocalypse(void)
size++;
entry = lb_avl_tree_larger(entry);
prev = cur;
if(entry != NULL)
if (entry != NULL)
{
cur = OBTAIN_STRUCT_ADDR(entry, int_tree_node, tree_entry)->val;
}
@ -857,9 +861,9 @@ static bool test_apocalypse(void)
size = 0;
cur = OBTAIN_STRUCT_ADDR(entry, int_tree_node, tree_entry)->val;
prev = cur;
while(entry != NULL)
while (entry != NULL)
{
if(cur > prev)
if (cur > prev)
{
result = false;
break;
@ -867,7 +871,7 @@ static bool test_apocalypse(void)
size++;
entry = lb_avl_tree_smaller(entry);
prev = cur;
if(entry != NULL)
if (entry != NULL)
{
cur = OBTAIN_STRUCT_ADDR(entry, int_tree_node, tree_entry)->val;
}
@ -877,7 +881,7 @@ static bool test_apocalypse(void)
// delete and search test
for(int i = 0; i < AVL_APOCALYPSE_NUM; i++)
for (int i = 0; i < AVL_APOCALYPSE_NUM; i++)
{
result = result && (lb_avl_tree_search(&tree, &apocalypse[i].tree_entry) != NULL);
lb_avl_tree_delete(&tree, &apocalypse[i].tree_entry);
@ -929,7 +933,7 @@ void avl_tree_test(void)
lb_srand(2986);
// ultimate apocalypse
for(int i = 0; i < AVL_APOCALYPSE_ITER; i++)
for (int i = 0; i < AVL_APOCALYPSE_ITER; i++)
{
run_case("test_apocalypse", test_apocalypse());
}

View File

@ -41,7 +41,9 @@ static bool assert_list(linked_list_t *list, int val[], int size)
int i = 0;
if (!validate_list(list))
{
return false;
}
while (node != NULL && i < size)
{
@ -401,8 +403,8 @@ static bool push_pop_back_test(void)
static int32_t equals(void *a, void *b)
{
return ((int64_t) (linked_list_node_t*)b) ==
OBTAIN_STRUCT_ADDR((linked_list_node_t*)a, my_list_node, lnode)->val;
return ((int64_t) (linked_list_node_t *) b) ==
OBTAIN_STRUCT_ADDR((linked_list_node_t *) a, my_list_node, lnode)->val;
}
static bool search_test(void)

View File

@ -24,8 +24,8 @@ static bool salloc_basic_alloc(void)
bool result = true;
lb_salloc_init(buffer, 1024);
result = result && (lb_salloc(buffer, 10) != NULL);
uint32_t blk_size[] = {10 + salloc_header_size, 1024-10-salloc_header_size};
bool blk_free[] = {false,true};
uint32_t blk_size[] = {10 + salloc_header_size, 1024 - 10 - salloc_header_size};
bool blk_free[] = {false, true};
result = result && lb_salloc_assert(buffer, blk_size, blk_free, 2);
return result;
}
@ -62,15 +62,15 @@ static bool salloc_multiple_alloc(void)
uint32_t blk_size[] = {10 + salloc_header_size,
10 + salloc_header_size,
10 + salloc_header_size,
1024-3*(10+salloc_header_size)};
bool blk_free[] = {false,false,false,true};
1024 - 3 * (10 + salloc_header_size)};
bool blk_free[] = {false, false, false, true};
result = result && lb_salloc_assert(buffer, blk_size, blk_free, 4);
return result;
}
static bool salloc_alloc_not_enough(void)
{
void* ptr;
void *ptr;
bool result = true;
lb_salloc_init(buffer, salloc_header_size + salloc_header_size + salloc_header_size - 1);
ptr = lb_salloc(buffer, salloc_header_size);
@ -84,7 +84,7 @@ static bool salloc_alloc_not_enough(void)
static bool salloc_basic_free(void)
{
void* ptr;
void *ptr;
bool result = true;
lb_salloc_init(buffer, 1024);
ptr = lb_salloc(buffer, 10);
@ -99,7 +99,7 @@ static bool salloc_basic_free(void)
static bool salloc_full_free(void)
{
void* ptr;
void *ptr;
bool result = true;
lb_salloc_init(buffer, 1024);
ptr = lb_salloc(buffer, 1024 - salloc_header_size);
@ -114,7 +114,7 @@ static bool salloc_full_free(void)
static bool salloc_multiple_free(void)
{
void* ptr1, *ptr2, *ptr3, *ptr4;
void *ptr1, *ptr2, *ptr3, *ptr4;
bool result = true;
lb_salloc_init(buffer, 1024);
ptr1 = lb_salloc(buffer, 10);
@ -129,15 +129,15 @@ static bool salloc_multiple_free(void)
10 + salloc_header_size,
10 + salloc_header_size,
10 + salloc_header_size,
1024-4*(10+salloc_header_size)};
bool blk_free[] = {true,false,true,false,true};
1024 - 4 * (10 + salloc_header_size)};
bool blk_free[] = {true, false, true, false, true};
result = result && lb_salloc_assert(buffer, blk_size, blk_free, 5);
return result;
}
static bool salloc_free_join_tail(void)
{
void* ptr1, *ptr2, *ptr3, *ptr4;
void *ptr1, *ptr2, *ptr3, *ptr4;
bool result = true;
lb_salloc_init(buffer, 1024);
ptr1 = lb_salloc(buffer, 10);
@ -150,15 +150,15 @@ static bool salloc_free_join_tail(void)
uint32_t blk_size[] = {10 + salloc_header_size,
10 + salloc_header_size,
10 + salloc_header_size,
1024-3*(10+salloc_header_size)};
bool blk_free[] = {false,false,false,true};
1024 - 3 * (10 + salloc_header_size)};
bool blk_free[] = {false, false, false, true};
result = result && lb_salloc_assert(buffer, blk_size, blk_free, 4);
return result;
}
static bool salloc_free_join_head(void)
{
void* ptr1, *ptr2, *ptr3, *ptr4;
void *ptr1, *ptr2, *ptr3, *ptr4;
bool result = true;
lb_salloc_init(buffer, 1024);
ptr1 = lb_salloc(buffer, 10);
@ -169,18 +169,18 @@ static bool salloc_free_join_head(void)
lb_sfree(buffer, ptr1);
lb_sfree(buffer, ptr2);
uint32_t blk_size[] = {2*(10 + salloc_header_size),
uint32_t blk_size[] = {2 * (10 + salloc_header_size),
10 + salloc_header_size,
10 + salloc_header_size,
1024-4*(10+salloc_header_size)};
bool blk_free[] = {true,false,false,true};
1024 - 4 * (10 + salloc_header_size)};
bool blk_free[] = {true, false, false, true};
result = result && lb_salloc_assert(buffer, blk_size, blk_free, 4);
return result;
}
static bool salloc_free_join_mid(void)
{
void* ptr1, *ptr2, *ptr3, *ptr4;
void *ptr1, *ptr2, *ptr3, *ptr4;
bool result = true;
lb_salloc_init(buffer, 1024);
ptr1 = lb_salloc(buffer, 10);
@ -192,17 +192,17 @@ static bool salloc_free_join_mid(void)
lb_sfree(buffer, ptr3);
uint32_t blk_size[] = {10 + salloc_header_size,
2*(10 + salloc_header_size),
2 * (10 + salloc_header_size),
10 + salloc_header_size,
1024-4*(10+salloc_header_size)};
bool blk_free[] = {false,true,false,true};
1024 - 4 * (10 + salloc_header_size)};
bool blk_free[] = {false, true, false, true};
result = result && lb_salloc_assert(buffer, blk_size, blk_free, 4);
return result;
}
static bool salloc_free_join_consecutive(void)
{
void* ptr1, *ptr2, *ptr3, *ptr4, *ptr5;
void *ptr1, *ptr2, *ptr3, *ptr4, *ptr5;
bool result = true;
lb_salloc_init(buffer, 1024);
ptr1 = lb_salloc(buffer, 10);
@ -219,24 +219,24 @@ static bool salloc_free_join_consecutive(void)
10 + salloc_header_size,
10 + salloc_header_size,
10 + salloc_header_size,
1024-5*(10+salloc_header_size)};
bool blk_free[] = {false,true,false,true,false,true};
1024 - 5 * (10 + salloc_header_size)};
bool blk_free[] = {false, true, false, true, false, true};
result = result && lb_salloc_assert(buffer, blk_size, blk_free, 6);
lb_sfree(buffer, ptr3);
uint32_t blk_size2[] = {10 + salloc_header_size,
3*(10 + salloc_header_size),
3 * (10 + salloc_header_size),
10 + salloc_header_size,
1024-5*(10+salloc_header_size)};
bool blk_free2[] = {false,true,false,true};
1024 - 5 * (10 + salloc_header_size)};
bool blk_free2[] = {false, true, false, true};
result = result && lb_salloc_assert(buffer, blk_size2, blk_free2, 4);
return result;
}
static bool salloc_free_all(void)
{
void* ptr1, *ptr2, *ptr3, *ptr4;
void *ptr1, *ptr2, *ptr3, *ptr4;
bool result = true;
lb_salloc_init(buffer, 1024);
ptr1 = lb_salloc(buffer, 10);