Non-recursive make + compiled + set up QEMU + GDB.
This commit is contained in:
parent
2c58926308
commit
243e4cb1fe
|
@ -1,2 +1,8 @@
|
||||||
.idea
|
.idea
|
||||||
cmake-build-debug
|
cmake-build-debug
|
||||||
|
*.o
|
||||||
|
*.a
|
||||||
|
CMakeLists.txt
|
||||||
|
*.iso
|
||||||
|
*.elf
|
||||||
|
*.dmp
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
cmake_minimum_required(VERSION 2.8.4)
|
|
||||||
project(Workspace)
|
|
||||||
|
|
||||||
include_directories(src/include)
|
|
||||||
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
|
||||||
|
|
||||||
file(GLOB_RECURSE SOURCE_FILES ./*.h ./*.c)
|
|
||||||
|
|
||||||
add_executable(Workspace ${SOURCE_FILES})
|
|
40
LICENSE
40
LICENSE
|
@ -1,21 +1,21 @@
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2018 secXsQuared
|
Copyright (c) 2018 secXsQuared
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
in the Software without restriction, including without limitation the rights
|
in the Software without restriction, including without limitation the rights
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
furnished to do so, subject to the following conditions:
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
SOFTWARE.
|
SOFTWARE.
|
39
Makefile
39
Makefile
|
@ -1,17 +1,16 @@
|
||||||
ASM := nasm
|
CROSS_DIR = ~/opt/cross/bin
|
||||||
CC := /opt/x86_64-elf-gcc
|
AS = nasm
|
||||||
LD := /opt/x86_64-elf-gcc
|
CC = $(CROSS_DIR)/x86_64-elf-gcc
|
||||||
DUMP := /opt/x86_64-elf-objdump
|
LD = $(CROSS_DIR)/x86_64-elf-gcc
|
||||||
|
DAS = $(CROSS_DIR)/x86_64-elf-objdump
|
||||||
|
|
||||||
LD_SCRIPT := linker.ld
|
INCLUDE_DIR = include
|
||||||
|
MK = mk
|
||||||
|
|
||||||
GRUB_CFG := grub.cfg
|
LD_SCRIPT = $(MK)/linker.ld
|
||||||
|
GRUB_CFG = $(MK)/grub.cfg
|
||||||
|
|
||||||
INCLUDE_DIR := include
|
C_WARNINGS = -Wall \
|
||||||
|
|
||||||
MK := mk
|
|
||||||
|
|
||||||
C_WARNINGS := -Wall \
|
|
||||||
-Werror \
|
-Werror \
|
||||||
-Wextra \
|
-Wextra \
|
||||||
-Wpedantic \
|
-Wpedantic \
|
||||||
|
@ -26,7 +25,7 @@ C_WARNINGS := -Wall \
|
||||||
-Wpointer-arith \
|
-Wpointer-arith \
|
||||||
-Wno-comment
|
-Wno-comment
|
||||||
|
|
||||||
C_FLAGS := -std=c11 \
|
C_FLAGS = -std=c11 \
|
||||||
-g \
|
-g \
|
||||||
-c \
|
-c \
|
||||||
-O2 \
|
-O2 \
|
||||||
|
@ -41,22 +40,22 @@ C_FLAGS := -std=c11 \
|
||||||
$(C_WARNINGS) \
|
$(C_WARNINGS) \
|
||||||
$(addprefix -I, $(INCLUDE_DIR))
|
$(addprefix -I, $(INCLUDE_DIR))
|
||||||
|
|
||||||
ASM_FLAGS := -w+all \
|
AS_FLAGS = -w+all \
|
||||||
-f elf64 \
|
-f elf64 \
|
||||||
-F dwarf \
|
-F dwarf \
|
||||||
-g \
|
-g \
|
||||||
$(addprefix -I, $(ASM_HEADER_DIRS))
|
$(addprefix -I, $(INCLUDE_DIR)/)
|
||||||
|
|
||||||
LD_FLAGS := -lgcc \
|
LD_FLAGS = -lgcc \
|
||||||
-nodefaultlibs \
|
-nodefaultlibs \
|
||||||
-nostartfiles \
|
-nostartfiles \
|
||||||
-nostdlib \
|
-nostdlib \
|
||||||
-Wl,-n \
|
-Wl,-n \
|
||||||
-Wl,--build-id=none
|
-Wl,--build-id=none
|
||||||
|
|
||||||
COMP :=
|
COMP = $(CC) $(C_FLAGS) $^ -o $@
|
||||||
LINK :=
|
COMPAS = $(AS) $(AS_FLAGS) $^ -o $@
|
||||||
COMPAS :=
|
LINK = $(LD) $(LD_FLAGS) $^ -o $@
|
||||||
PACK :=
|
DUMP = $(DAS) -M intel -D $^ > $@
|
||||||
|
|
||||||
include Rules.mk
|
include Rules.top
|
Binary file not shown.
14
Rules.mk
14
Rules.mk
|
@ -1,14 +0,0 @@
|
||||||
include $(MK)/prologue.mk
|
|
||||||
|
|
||||||
#OBJ var holds all object files
|
|
||||||
|
|
||||||
dir := $(d)/hal
|
|
||||||
include $(dir)/Rules.mk
|
|
||||||
dir := $(d)/kernel
|
|
||||||
include $(dir)/Rules.mk
|
|
||||||
dir := $(d)/lib
|
|
||||||
include $(dir)/Rules.mk
|
|
||||||
|
|
||||||
TGT :=
|
|
||||||
|
|
||||||
include $(MK)/epilogue.mk
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
include $(MK)/prologue.mk
|
||||||
|
|
||||||
|
.DEFAULT_GOAL := all
|
||||||
|
|
||||||
|
#OBJ var holds all object files
|
||||||
|
|
||||||
|
dir := hal
|
||||||
|
include $(dir)/Rules.mk
|
||||||
|
dir := kernel
|
||||||
|
include $(dir)/Rules.mk
|
||||||
|
dir := lib
|
||||||
|
include $(dir)/Rules.mk
|
||||||
|
dir := test
|
||||||
|
include $(dir)/Rules.mk
|
||||||
|
|
||||||
|
TGT := secxkrnl.elf
|
||||||
|
DMP := secxkrnl.dmp
|
||||||
|
ISO := secxkrnl.iso
|
||||||
|
|
||||||
|
$(TGT): $(OBJ)
|
||||||
|
$(LINK) -T $(LD_SCRIPT)
|
||||||
|
|
||||||
|
$(DMP): $(TGT)
|
||||||
|
$(DUMP)
|
||||||
|
|
||||||
|
.PHONY: clean
|
||||||
|
clean:
|
||||||
|
rm $(OBJ) $(TGT) $(DMP) $(ISO)
|
||||||
|
|
||||||
|
.PHONY: compile
|
||||||
|
compile: $(TGT)
|
||||||
|
|
||||||
|
.PHONY: dump
|
||||||
|
dump: $(DMP)
|
||||||
|
|
||||||
|
.PHONY: iso
|
||||||
|
iso: $(TGT)
|
||||||
|
mkdir -p temp/secX
|
||||||
|
mkdir -p temp/boot
|
||||||
|
mkdir -p temp/boot/grub
|
||||||
|
cp $(TGT) temp/secX/
|
||||||
|
cp $(GRUB_CFG) temp/boot/grub/
|
||||||
|
grub-mkrescue -o $(ISO) temp
|
||||||
|
rm -r temp
|
||||||
|
|
||||||
|
.PHONY: all
|
||||||
|
all: compile dump iso
|
||||||
|
|
||||||
|
include $(MK)/epilogue.mk
|
|
@ -0,0 +1 @@
|
||||||
|
qemu-system-x86_64 -bios OVMF_x86-64_bios.bin -cdrom secxkrnl.iso -s -S
|
|
@ -0,0 +1,3 @@
|
||||||
|
target remote localhost:1234
|
||||||
|
symbol-file secxkrnl.elf
|
||||||
|
break *0x1003000
|
|
@ -13,7 +13,9 @@ SRCAS_$(d) := boot.asm \
|
||||||
cpu.asm \
|
cpu.asm \
|
||||||
intr.asm
|
intr.asm
|
||||||
|
|
||||||
OBJAS_$(d) := $(SRCAS_$(d):.c=.a)
|
SRCAS_$(d) := $(addprefix $(d)/, $(SRCAS_$(d)))
|
||||||
|
|
||||||
|
OBJAS_$(d) := $(SRCAS_$(d):.asm=.a)
|
||||||
|
|
||||||
$(OBJ_$(d)): %.o: %.c
|
$(OBJ_$(d)): %.o: %.c
|
||||||
$(COMP)
|
$(COMP)
|
||||||
|
|
10
hal/boot.asm
10
hal/boot.asm
|
@ -11,9 +11,10 @@ MULTIBOOT_MAGIC_NUMBER equ 0xE85250D6
|
||||||
MULTIBOOT_ARCH equ 0
|
MULTIBOOT_ARCH equ 0
|
||||||
; NASM does not like
|
; NASM does not like
|
||||||
MULTIBOOT_CHECK_SUM equ (0xFFFFFFFF - (MULTIBOOT_MAGIC_NUMBER + MULTIBOOT_HEADER_SIZE + MULTIBOOT_ARCH) + 1)
|
MULTIBOOT_CHECK_SUM equ (0xFFFFFFFF - (MULTIBOOT_MAGIC_NUMBER + MULTIBOOT_HEADER_SIZE + MULTIBOOT_ARCH) + 1)
|
||||||
MULTIBOOT_REQ_MINFO equ 4
|
MULTIBOOT_REQ_LOADERNAME equ 2
|
||||||
MULTIBOOT_REQ_MMAP equ 6
|
MULTIBOOT_REQ_MMAP equ 6
|
||||||
MULTIBOOT_REQ_APM equ 10
|
MULTIBOOT_REQ_EFI_64 equ 12
|
||||||
|
MULTIBOOT_REQ_EFI_MMAP equ 17
|
||||||
|
|
||||||
[SECTION .multiboot_header]
|
[SECTION .multiboot_header]
|
||||||
[BITS 32]
|
[BITS 32]
|
||||||
|
@ -32,9 +33,10 @@ multiboot_info_tag:
|
||||||
dw 0x1 ; type=1
|
dw 0x1 ; type=1
|
||||||
dw 0x0 ; flag=0
|
dw 0x0 ; flag=0
|
||||||
dd MULTIBOOT_INFO_TAG_SIZE
|
dd MULTIBOOT_INFO_TAG_SIZE
|
||||||
;dd MULTIBOOT_REQ_MINFO
|
dd MULTIBOOT_REQ_LOADERNAME
|
||||||
dd MULTIBOOT_REQ_MMAP
|
dd MULTIBOOT_REQ_MMAP
|
||||||
dd MULTIBOOT_REQ_APM
|
dd MULTIBOOT_REQ_EFI_64
|
||||||
|
dd MULTIBOOT_REQ_EFI_MMAP
|
||||||
MULTIBOOT_INFO_TAG_SIZE equ ($ - multiboot_info_tag)
|
MULTIBOOT_INFO_TAG_SIZE equ ($ - multiboot_info_tag)
|
||||||
;====================
|
;====================
|
||||||
;MODULE ALIGNMENT TAG
|
;MODULE ALIGNMENT TAG
|
||||||
|
|
|
@ -14,6 +14,7 @@ static exc_handler_t _exc_handler_table[HAL_CORE_COUNT][IDT_ENTRY_NUM];
|
||||||
|
|
||||||
irql_t KABI hal_set_irql(irql_t irql)
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -105,7 +106,7 @@ void KABI hal_deregister_exception_handler(uint32_t coreid, uint32_t index)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void KABI hal_interrupt_dispatcher(uint64_t int_vec, hal_interrupt_context_t *context)
|
void KABI hal_interrupt_dispatcher(uint64_t int_vec, hal_interrupt_context_t *context)
|
||||||
{
|
{
|
||||||
uint32_t coreid = hal_get_core_id();
|
uint32_t coreid = hal_get_core_id();
|
||||||
if (_intr_handler_table[int_vec] == NULL)
|
if (_intr_handler_table[int_vec] == NULL)
|
||||||
|
@ -119,7 +120,7 @@ static void KABI hal_interrupt_dispatcher(uint64_t int_vec, hal_interrupt_contex
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static 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();
|
uint32_t coreid = hal_get_core_id();
|
||||||
if (_exc_handler_table[exc_vec] == NULL)
|
if (_exc_handler_table[exc_vec] == NULL)
|
||||||
|
@ -133,7 +134,7 @@ static void KABI hal_exception_dispatcher(uint64_t exc_vec, hal_interrupt_contex
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void KABI halp_populate_idt()
|
static void KABI halp_populate_idt(void)
|
||||||
{
|
{
|
||||||
hal_set_interrupt_handler(0, hal_interrupt_handler_0);
|
hal_set_interrupt_handler(0, hal_interrupt_handler_0);
|
||||||
hal_set_interrupt_handler(1, hal_interrupt_handler_1);
|
hal_set_interrupt_handler(1, hal_interrupt_handler_1);
|
||||||
|
@ -439,6 +440,7 @@ int32_t KABI hal_interrupt_init(void)
|
||||||
hal_read_msr(&ecx, &edx, &eax);
|
hal_read_msr(&ecx, &edx, &eax);
|
||||||
apic_base_reg = ((uint64_t) edx << 32) + (uint64_t) eax;
|
apic_base_reg = ((uint64_t) edx << 32) + (uint64_t) eax;
|
||||||
apic_base = apic_base_reg & lb_bit_field_mask(12, 35);
|
apic_base = apic_base_reg & lb_bit_field_mask(12, 35);
|
||||||
|
UNREFERENCED(apic_base);
|
||||||
|
|
||||||
//hal_printf("APIC Base: 0x%X\n", apic_base);
|
//hal_printf("APIC Base: 0x%X\n", apic_base);
|
||||||
//hal_printf("APIC Enabled: %s\n", apic_base_reg & bit_mask_64(11) ? "Yes" : "No");
|
//hal_printf("APIC Enabled: %s\n", apic_base_reg & bit_mask_64(11) ? "Yes" : "No");
|
||||||
|
|
|
@ -106,7 +106,7 @@ void KABI hfree(void *ptr)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void KABI _hal_init_gdt()
|
static void KABI _hal_init_gdt(void)
|
||||||
{
|
{
|
||||||
uint32_t coreid = hal_get_core_id();
|
uint32_t coreid = hal_get_core_id();
|
||||||
// get gdt ready
|
// get gdt ready
|
||||||
|
@ -135,7 +135,7 @@ static void KABI _hal_init_gdt()
|
||||||
_gdt_ptrs[coreid].base = (uint64_t) &_gdts[coreid];
|
_gdt_ptrs[coreid].base = (uint64_t) &_gdts[coreid];
|
||||||
_gdt_ptrs[coreid].limit = GDT_ENTRY_NUM * GDT_ENTRY_SIZE - 1;
|
_gdt_ptrs[coreid].limit = GDT_ENTRY_NUM * GDT_ENTRY_SIZE - 1;
|
||||||
hal_flush_gdt(&_gdt_ptrs[coreid], seg_selector(1, 0), seg_selector(2, 0));
|
hal_flush_gdt(&_gdt_ptrs[coreid], seg_selector(1, 0), seg_selector(2, 0));
|
||||||
};
|
}
|
||||||
|
|
||||||
void KABI hal_mem_init()
|
void KABI hal_mem_init()
|
||||||
{
|
{
|
||||||
|
|
11
hal/print.c
11
hal/print.c
|
@ -14,12 +14,12 @@
|
||||||
|
|
||||||
static uint64_t text_pos;
|
static uint64_t text_pos;
|
||||||
|
|
||||||
static void KABI hal_print_init()
|
void KABI hal_print_init(void)
|
||||||
{
|
{
|
||||||
text_pos = 0;
|
text_pos = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void KABI halp_print_scroll()
|
static void KABI halp_print_scroll(void)
|
||||||
{
|
{
|
||||||
lb_mem_move((void *) (0xb8000 + get_pos(1, 0) * 2), (void *) (0xb8000 + get_pos(0, 0) * 2), (80 * 24) * 2);
|
lb_mem_move((void *) (0xb8000 + get_pos(1, 0) * 2), (void *) (0xb8000 + get_pos(0, 0) * 2), (80 * 24) * 2);
|
||||||
return;
|
return;
|
||||||
|
@ -139,10 +139,9 @@ void KABI hal_clear_screen(void)
|
||||||
|
|
||||||
void KABI hal_vprintf(char const * format, va_list args)
|
void KABI hal_vprintf(char const * format, va_list args)
|
||||||
{
|
{
|
||||||
va_start(args, format);
|
|
||||||
char buf[2] = {0, 0};
|
char buf[2] = {0, 0};
|
||||||
int32_t d;
|
int64_t d;
|
||||||
uint32_t u;
|
uint64_t u;
|
||||||
char* s;
|
char* s;
|
||||||
char c;
|
char c;
|
||||||
for(;*format != '\0';format++)
|
for(;*format != '\0';format++)
|
||||||
|
@ -169,7 +168,7 @@ void KABI hal_vprintf(char const * format, va_list args)
|
||||||
halp_print_str(s);
|
halp_print_str(s);
|
||||||
break;
|
break;
|
||||||
case 'c':
|
case 'c':
|
||||||
c = va_arg(args, int64_t);
|
c = (char)va_arg(args, int64_t);
|
||||||
buf[0] = c;
|
buf[0] = c;
|
||||||
halp_print_str(buf);
|
halp_print_str(buf);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -98,6 +98,6 @@ void *KABI halloc(uint32_t size);
|
||||||
|
|
||||||
void KABI hfree(void *ptr);
|
void KABI hfree(void *ptr);
|
||||||
|
|
||||||
void KABI hal_mem_init();
|
void KABI hal_mem_init(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -8,8 +8,8 @@ void KABI hal_assert(uint32_t expression, char *message);
|
||||||
|
|
||||||
void KABI hal_printf(const char *str, ...);
|
void KABI hal_printf(const char *str, ...);
|
||||||
|
|
||||||
void KABI hal_clear_screen();
|
void KABI hal_clear_screen(void);
|
||||||
|
|
||||||
void KABI hal_print_init();
|
void KABI hal_print_init(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
#include "type.h"
|
#include "type.h"
|
||||||
|
|
||||||
void KABI ke_alloc_init();
|
void KABI ke_alloc_init(void);
|
||||||
|
|
||||||
void* KABI ke_alloc(uint32_t size);
|
void* KABI ke_alloc(uint32_t size);
|
||||||
|
|
||||||
|
|
|
@ -8,10 +8,8 @@ irql_t KABI ke_raise_irql(irql_t irql);
|
||||||
|
|
||||||
irql_t KABI ke_lower_irql(irql_t irql);
|
irql_t KABI ke_lower_irql(irql_t irql);
|
||||||
|
|
||||||
int KABI ke_get_current_core();
|
int KABI ke_get_current_core(void);
|
||||||
|
|
||||||
irql_t KABI ke_get_irql();
|
irql_t KABI ke_get_irql(void);
|
||||||
|
|
||||||
void KABI ke_halt_cpu();
|
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -19,7 +19,7 @@ typedef struct
|
||||||
// specifying where the allocations take place
|
// specifying where the allocations take place
|
||||||
//
|
//
|
||||||
|
|
||||||
status_t KABI rf_reference_setup();
|
status_t KABI rf_reference_setup(void);
|
||||||
|
|
||||||
status_t KABI rf_reference_create(ref_node_t *ref,
|
status_t KABI rf_reference_create(ref_node_t *ref,
|
||||||
callback_func_t free_func);
|
callback_func_t free_func);
|
||||||
|
|
|
@ -8,11 +8,11 @@
|
||||||
|
|
||||||
#include "type.h"
|
#include "type.h"
|
||||||
|
|
||||||
uint32_t KABI rand( void );
|
uint32_t KABI lb_rand(void);
|
||||||
|
|
||||||
void KABI srand(uint32_t _seed );
|
void KABI lb_srand(uint32_t _seed);
|
||||||
|
|
||||||
void KABI mrand(uint32_t max);
|
void KABI lb_mrand(uint32_t max);
|
||||||
|
|
||||||
uint64_t KABI lb_str_len(char const *str);
|
uint64_t KABI lb_str_len(char const *str);
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ void KABI lb_mem_copy(void *src, void *dst, uint64_t size);
|
||||||
|
|
||||||
void KABI lb_mem_move(void *src, void *dst, uint64_t size);
|
void KABI lb_mem_move(void *src, void *dst, uint64_t size);
|
||||||
|
|
||||||
void KABI lb_mem_set(void *src, int8_t const val, uint64_t size);
|
void KABI lb_mem_set(void *src, uint8_t const val, uint64_t size);
|
||||||
|
|
||||||
static inline uint64_t KABI lb_align_down(uint64_t val, uint64_t alignment)
|
static inline uint64_t KABI lb_align_down(uint64_t val, uint64_t alignment)
|
||||||
{
|
{
|
||||||
|
@ -61,32 +61,34 @@ static inline int32_t KABI lb_min_32(int32_t a, int32_t b)
|
||||||
return (a) < (b) ? a : b;
|
return (a) < (b) ? a : b;
|
||||||
}
|
}
|
||||||
|
|
||||||
//static inline uint64_t KAPI round_up_power_of_2(uint64_t num)
|
/*
|
||||||
//{
|
static inline uint64_t KAPI round_up_power_of_2(uint64_t num)
|
||||||
// num--;
|
{
|
||||||
// num |= num >> 1;
|
num--;
|
||||||
// num |= num >> 2;
|
num |= num >> 1;
|
||||||
// num |= num >> 4;
|
num |= num >> 2;
|
||||||
// num |= num >> 8;
|
num |= num >> 4;
|
||||||
// num |= num >> 16;
|
num |= num >> 8;
|
||||||
// num |= num >> 32;
|
num |= num >> 16;
|
||||||
// num++;
|
num |= num >> 32;
|
||||||
// return (uint64_t)num;
|
num++;
|
||||||
//}
|
return (uint64_t)num;
|
||||||
//
|
}
|
||||||
//static inline uint32_t KAPI log_base_2(uint64_t num)
|
|
||||||
//{
|
|
||||||
// uint32_t result = 0;
|
|
||||||
//
|
|
||||||
// while (num >>= 1)
|
|
||||||
// {
|
|
||||||
// result++;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return result;
|
|
||||||
//}
|
|
||||||
|
|
||||||
#define OBTAIN_STRUCT_ADDR(member_addr, struct_name, member_name) ((struct_name*)((void*)(member_addr)-(void*)(&(((struct_name*)0)->member_name))))
|
static inline uint32_t KAPI log_base_2(uint64_t num)
|
||||||
|
{
|
||||||
|
uint32_t result = 0;
|
||||||
|
|
||||||
|
while (num >>= 1)
|
||||||
|
{
|
||||||
|
result++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define OBTAIN_STRUCT_ADDR(member_addr, struct_name, member_name) ((struct_name*)((uintptr_t)(member_addr) - (uintptr_t)(&(((struct_name*)0)->member_name))))
|
||||||
|
|
||||||
static inline uint64_t KABI lb_bit_mask(uint32_t bit)
|
static inline uint64_t KABI lb_bit_mask(uint32_t bit)
|
||||||
{
|
{
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
void KABI test_begin(char *name);
|
void KABI test_begin(char *name);
|
||||||
|
|
||||||
void KABI test_end();
|
void KABI test_end(void);
|
||||||
|
|
||||||
void *KABI talloc(uint32_t size);
|
void *KABI talloc(uint32_t size);
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
include $(MK)/prologue.mk
|
include $(MK)/prologue.mk
|
||||||
|
|
||||||
SRC_$(d) := allo.c \
|
SRC_$(d) := alloc.c \
|
||||||
assert.c \
|
assert.c \
|
||||||
atomic.c \
|
atomic.c \
|
||||||
boot.c \
|
boot.c \
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
static _Bool alloc_initialized;
|
static _Bool alloc_initialized;
|
||||||
static uint8_t alloc_heap[K_KERNEL_HEAP_SIZE];
|
static uint8_t alloc_heap[K_KERNEL_HEAP_SIZE];
|
||||||
|
|
||||||
void KABI ke_alloc_init()
|
void KABI ke_alloc_init(void)
|
||||||
{
|
{
|
||||||
if (!alloc_initialized)
|
if (!alloc_initialized)
|
||||||
{
|
{
|
||||||
|
|
|
@ -14,12 +14,12 @@ irql_t KABI ke_lower_irql(irql_t irql)
|
||||||
return hal_set_irql(irql);
|
return hal_set_irql(irql);
|
||||||
}
|
}
|
||||||
|
|
||||||
irql_t KABI ke_get_irql()
|
irql_t KABI ke_get_irql(void)
|
||||||
{
|
{
|
||||||
return hal_get_irql();
|
return hal_get_irql();
|
||||||
}
|
}
|
||||||
|
|
||||||
int KABI ke_get_current_core()
|
int KABI ke_get_current_core(void)
|
||||||
{
|
{
|
||||||
return hal_get_core_id();
|
return hal_get_core_id();
|
||||||
}
|
}
|
|
@ -51,7 +51,7 @@ static handle_node_t *rfp_search_handle_node(handle_t handle)
|
||||||
return result == NULL ? NULL : OBTAIN_STRUCT_ADDR(result, handle_node_t, tree_node);
|
return result == NULL ? NULL : OBTAIN_STRUCT_ADDR(result, handle_node_t, tree_node);
|
||||||
}
|
}
|
||||||
|
|
||||||
status_t KABI rf_reference_setup()
|
status_t KABI rf_reference_setup(void)
|
||||||
{
|
{
|
||||||
if (!initialized)
|
if (!initialized)
|
||||||
{
|
{
|
||||||
|
|
|
@ -2,8 +2,6 @@
|
||||||
* Distributed under GPL license
|
* Distributed under GPL license
|
||||||
* See COPYING under root for details
|
* See COPYING under root for details
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "abi.h"
|
|
||||||
#include "type.h"
|
#include "type.h"
|
||||||
#include "lib/sxtdlib.h"
|
#include "lib/sxtdlib.h"
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "type.h"
|
#include "type.h"
|
||||||
#include "abi.h"
|
|
||||||
#include "lib/sxtdlib.h"
|
#include "lib/sxtdlib.h"
|
||||||
|
|
||||||
void KABI lb_mem_copy(void *src, void *dst, uint64_t size)
|
void KABI lb_mem_copy(void *src, void *dst, uint64_t size)
|
||||||
|
@ -22,7 +21,7 @@ void KABI lb_mem_copy(void *src, void *dst, uint64_t size)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KABI lb_mem_set(void *src, int8_t const val, uint64_t size)
|
void KABI lb_mem_set(void *src, uint8_t const val, uint64_t size)
|
||||||
{
|
{
|
||||||
if (src == NULL)
|
if (src == NULL)
|
||||||
{
|
{
|
||||||
|
@ -30,7 +29,8 @@ void KABI lb_mem_set(void *src, int8_t const val, uint64_t size)
|
||||||
}
|
}
|
||||||
while (size--)
|
while (size--)
|
||||||
{
|
{
|
||||||
*((int8_t *) src++) = val;
|
*(uint8_t *)src = val;
|
||||||
|
src = (void*)((uintptr_t)src + 1);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -43,13 +43,16 @@ void KABI lb_mem_move(void *src, void *dst, uint64_t size)
|
||||||
}
|
}
|
||||||
if (src >= dst)
|
if (src >= dst)
|
||||||
{
|
{
|
||||||
return lb_mem_copy(src, dst, size);
|
lb_mem_copy(src, dst, size);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
src += size;
|
src = (void*)((uintptr_t)src + size - 1);
|
||||||
dst += size;
|
dst = (void*)((uintptr_t)dst + size - 1);
|
||||||
while (size--)
|
while (size--)
|
||||||
{
|
{
|
||||||
*((char *) --dst) = *((char *) --src);
|
*(char*)dst = *(char*)src;
|
||||||
|
dst = (void*)((uintptr_t)dst - 1);
|
||||||
|
src = (void*)((uintptr_t)src - 1);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -60,18 +63,18 @@ void KABI lb_mem_move(void *src, void *dst, uint64_t size)
|
||||||
static uint32_t seed = 1;
|
static uint32_t seed = 1;
|
||||||
static uint32_t max = 16777215;
|
static uint32_t max = 16777215;
|
||||||
|
|
||||||
uint32_t KABI rand(void)
|
uint32_t KABI lb_rand(void)
|
||||||
{
|
{
|
||||||
seed = seed * 1103512986 + 29865;
|
seed = seed * 1103512986 + 29865;
|
||||||
return (unsigned int) (seed / 65536) % (max + 1);
|
return (unsigned int) (seed / 65536) % (max + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KABI srand(uint32_t _seed)
|
void KABI lb_srand(uint32_t _seed)
|
||||||
{
|
{
|
||||||
seed = _seed;
|
seed = _seed;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KABI mrand(uint32_t _max)
|
void KABI lb_mrand(uint32_t _max)
|
||||||
{
|
{
|
||||||
max = _max;
|
max = _max;
|
||||||
}
|
}
|
||||||
|
@ -95,7 +98,7 @@ uint64_t KABI lb_str_len(char const *str)
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t KABI rtl_str_cmp(char const *str1, char const *str2)
|
uint64_t KABI lb_str_cmp(char const *str1, char const *str2)
|
||||||
{
|
{
|
||||||
if (str1 == NULL || str2 == NULL)
|
if (str1 == NULL || str2 == NULL)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,67 +0,0 @@
|
||||||
/* Copyright 2016 secXsQuared
|
|
||||||
* Distributed under GPL license
|
|
||||||
* See COPYING under root for details
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "balloc.h"
|
|
||||||
#include "std_lib.h"
|
|
||||||
#include "bit_ops.h"
|
|
||||||
|
|
||||||
int32_t balloc_init(balloc_desc_t *desc,
|
|
||||||
uint64_t base,
|
|
||||||
uint64_t end,
|
|
||||||
uint64_t page_size,
|
|
||||||
balloc_alloc_func alloc,
|
|
||||||
balloc_free_func free,
|
|
||||||
balloc_lock_func lock,
|
|
||||||
balloc_unlock_func unlock)
|
|
||||||
{
|
|
||||||
if(desc == NULL || base >= end || page_size == 0 || alloc == 0
|
|
||||||
|| free == 0 || lock == 0 || unlock == 0)
|
|
||||||
return BALLOC_STATUS_INVALID_ARGUMENTS;
|
|
||||||
|
|
||||||
if(((end - base) % page_size) != 0)
|
|
||||||
return BALLOC_STATUS_INVALID_ALIGNMENT;
|
|
||||||
|
|
||||||
desc->alloc = alloc;
|
|
||||||
desc->free = free;
|
|
||||||
desc->lock = lock;
|
|
||||||
desc->unlock = unlock;
|
|
||||||
|
|
||||||
desc->base = base;
|
|
||||||
desc->page_size = page_size;
|
|
||||||
uint64_t quot = (end-base) / page_size;
|
|
||||||
uint32_t order = log_base_2(quot);
|
|
||||||
if(quot & bit_mask_64(order) != 0)
|
|
||||||
{
|
|
||||||
order++;
|
|
||||||
}
|
|
||||||
desc->order = order;
|
|
||||||
|
|
||||||
// allocate linked lists and bit maps
|
|
||||||
desc->free_lists = (linked_list_t*)desc->alloc((order + 1) * sizeof(linked_list_t));
|
|
||||||
if(desc->free_lists == NULL || desc->bit_map == NULL)
|
|
||||||
return BALLOC_STATUS_CANT_ALLOC_MEM;
|
|
||||||
|
|
||||||
return BALLOC_STATUS_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t balloc_alloc(balloc_desc_t* desc, uint32_t page_num, uint64_t* out)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t balloc_free(balloc_desc_t* desc, uint64_t addr)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t balloc_mark_used(balloc_desc_t* desc, uint64_t start, uint64_t end)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t balloc_mark_free(balloc_desc_t* desc, uint64_t start, uint64_t end)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,59 +0,0 @@
|
||||||
#ifndef _BALLOC_H_
|
|
||||||
#define _BALLOC_H_
|
|
||||||
|
|
||||||
#include "linked_list.h"
|
|
||||||
#include "avl_tree.h"
|
|
||||||
|
|
||||||
/*
|
|
||||||
* A tree allocator for page-size allocation
|
|
||||||
* All
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define BALLOC_STATUS_SUCCESS 0
|
|
||||||
#define BALLOC_STATUS_INVALID_ARGUMENTS 1
|
|
||||||
#define BALLOC_STATUS_NO_AVAILABLE_MEM 2
|
|
||||||
#define BALLOC_STATUS_CANT_ALLOC_MEM 3
|
|
||||||
#define BALLOC_STATUS_INVALID_ALIGNMENT 4
|
|
||||||
|
|
||||||
typedef void *(*balloc_alloc_func)(uint64_t size);
|
|
||||||
|
|
||||||
typedef void (*balloc_free_func)(void *ptr);
|
|
||||||
|
|
||||||
typedef void (*balloc_lock_func)(void);
|
|
||||||
|
|
||||||
typedef void (*balloc_unlock_func)(void);
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
uint64_t base;
|
|
||||||
uint64_t order;
|
|
||||||
uint64_t page_size;
|
|
||||||
|
|
||||||
linked_list_t *free_lists;
|
|
||||||
uint8_t *bit_map;
|
|
||||||
|
|
||||||
balloc_alloc_func alloc;
|
|
||||||
balloc_free_func free;
|
|
||||||
balloc_lock_func lock;
|
|
||||||
balloc_unlock_func unlock;
|
|
||||||
} balloc_desc_t;
|
|
||||||
|
|
||||||
|
|
||||||
int32_t balloc_init(balloc_desc_t *desc,
|
|
||||||
uint64_t base,
|
|
||||||
uint64_t end,
|
|
||||||
uint64_t page_size,
|
|
||||||
balloc_alloc_func alloc,
|
|
||||||
balloc_free_func free,
|
|
||||||
balloc_lock_func lock,
|
|
||||||
balloc_unlock_func unlock);
|
|
||||||
|
|
||||||
int32_t balloc_alloc(balloc_desc_t* desc, uint32_t page_num, uint64_t* out);
|
|
||||||
|
|
||||||
int32_t balloc_free(balloc_desc_t* desc, uint64_t addr);
|
|
||||||
|
|
||||||
int32_t balloc_mark_used(balloc_desc_t* desc, uint64_t start, uint64_t end);
|
|
||||||
|
|
||||||
int32_t balloc_mark_free(balloc_desc_t* desc, uint64_t start, uint64_t end);
|
|
||||||
|
|
||||||
#endif
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,50 +0,0 @@
|
||||||
# configuration file generated by Bochs
|
|
||||||
plugin_ctrl: unmapped=1, biosdev=1, speaker=1, extfpuirq=1, parallel=1, serial=1, gameport=1
|
|
||||||
config_interface: win32config
|
|
||||||
display_library: win32, options="gui_debug"
|
|
||||||
memory: host=256, guest=256
|
|
||||||
romimage: file="C:\Program Files (x86)\Bochs-2.6.8\BIOS-bochs-latest"
|
|
||||||
vgaromimage: file="C:\Program Files (x86)\Bochs-2.6.8\VGABIOS-lgpl-latest"
|
|
||||||
boot: cdrom
|
|
||||||
magic_break: enabled=1
|
|
||||||
floppy_bootsig_check: disabled=0
|
|
||||||
debug_symbols: file="target\kernel.sym"
|
|
||||||
# no floppya
|
|
||||||
# no floppyb
|
|
||||||
ata0: enabled=1, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14
|
|
||||||
ata0-master: type=cdrom, path="target\secX.iso", status=inserted, model="Generic 1234", biosdetect=auto
|
|
||||||
ata0-slave: type=none
|
|
||||||
ata1: enabled=1, ioaddr1=0x170, ioaddr2=0x370, irq=15
|
|
||||||
ata1-master: type=none
|
|
||||||
ata1-slave: type=none
|
|
||||||
ata2: enabled=0
|
|
||||||
ata3: enabled=0
|
|
||||||
pci: enabled=1, chipset=i440fx
|
|
||||||
vga: extension=vbe, update_freq=5
|
|
||||||
cpu: count=1, ips=4000000, model=bx_generic, reset_on_triple_fault=0, cpuid_limit_winnt=0, ignore_bad_msrs=1, mwait_is_nop=0
|
|
||||||
cpuid: level=6, stepping=3, model=3, family=6, vendor_string="GenuineIntel", brand_string=" Intel(R) Pentium(R) 4 CPU "
|
|
||||||
cpuid: mmx=1, apic=xapic, simd=sse2, sse4a=0, misaligned_sse=0, sep=1, movbe=0, adx=0
|
|
||||||
cpuid: aes=0, sha=0, xsave=0, xsaveopt=0, x86_64=1, 1g_pages=1, pcid=0, fsgsbase=1
|
|
||||||
cpuid: smep=0, smap=0, mwait=1, vmx=1
|
|
||||||
print_timestamps: enabled=0
|
|
||||||
port_e9_hack: enabled=0
|
|
||||||
private_colormap: enabled=0
|
|
||||||
clock: sync=none, time0=local, rtc_sync=0
|
|
||||||
# no cmosimage
|
|
||||||
# no loader
|
|
||||||
log: -
|
|
||||||
logprefix: %t%e%d
|
|
||||||
debug: action=ignore
|
|
||||||
info: action=report
|
|
||||||
error: action=report
|
|
||||||
panic: action=ask
|
|
||||||
keyboard: type=mf, serial_delay=250, paste_delay=100000, user_shortcut=none
|
|
||||||
mouse: type=ps2, enabled=0, toggle=ctrl+mbutton
|
|
||||||
sound: driver="default", waveout=none, wavein=none
|
|
||||||
speaker: enabled=1, mode=sound
|
|
||||||
parport1: enabled=1, file=none
|
|
||||||
parport2: enabled=0
|
|
||||||
com1: enabled=1, mode=null
|
|
||||||
com2: enabled=0
|
|
||||||
com3: enabled=0
|
|
||||||
com4: enabled=0
|
|
|
@ -1,3 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
export PATH="~/opt/cross/bin:$PATH"
|
|
|
@ -1,20 +0,0 @@
|
||||||
cd src
|
|
||||||
./configure --enable-cpu-level=6 \
|
|
||||||
--enable-all-optimizations \
|
|
||||||
--enable-x86-64 \
|
|
||||||
--enable-pci \
|
|
||||||
--enable-vmx \
|
|
||||||
--enable-disasm \
|
|
||||||
--enable-logging \
|
|
||||||
--enable-fpu \
|
|
||||||
--enable-3dnow \
|
|
||||||
--enable-sb16=dummy \
|
|
||||||
--enable-cdrom \
|
|
||||||
--enable-iodebug \
|
|
||||||
--disable-plugins \
|
|
||||||
--disable-docbook \
|
|
||||||
--enable-gdb-stub \
|
|
||||||
--with-x --with-x11 --with-term --with-sdl
|
|
||||||
|
|
||||||
make
|
|
||||||
|
|
|
@ -1,23 +0,0 @@
|
||||||
cd src
|
|
||||||
./configure --enable-smp \
|
|
||||||
--enable-cpu-level=6 \
|
|
||||||
--enable-all-optimizations \
|
|
||||||
--enable-x86-64 \
|
|
||||||
--enable-pci \
|
|
||||||
--enable-vmx \
|
|
||||||
--enable-debugger \
|
|
||||||
--enable-disasm \
|
|
||||||
--enable-debugger-gui \
|
|
||||||
--enable-logging \
|
|
||||||
--enable-fpu \
|
|
||||||
--enable-3dnow \
|
|
||||||
--enable-sb16=dummy \
|
|
||||||
--enable-cdrom \
|
|
||||||
--enable-x86-debugger \
|
|
||||||
--enable-iodebug \
|
|
||||||
--disable-plugins \
|
|
||||||
--disable-docbook \
|
|
||||||
--with-x --with-x11 --with-term --with-sdl
|
|
||||||
|
|
||||||
make
|
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
nop
|
|
||||||
BS_OEMName DB 'HYPERASM'
|
|
||||||
BPB_BytsPerSec DW 512
|
|
||||||
BPB_SecPerClus DB 1
|
|
||||||
BPB_RsvdSecCnt DW 1
|
|
||||||
BPB_NumFATs DB 2
|
|
||||||
BPB_RootEntCnt DW 224
|
|
||||||
BPB_TotSec16 DW 2880
|
|
||||||
BPB_Media DB 0xF0
|
|
||||||
BPB_FATSz16 DW 9
|
|
||||||
BPB_SecPerTrk DW 18
|
|
||||||
BPB_NumHeads DW 2
|
|
||||||
BPB_HiddSec DD 0
|
|
||||||
BPB_TotSec32 DD 0
|
|
||||||
BS_DrvNum DB 0
|
|
||||||
BS_Reserved1 DB 0
|
|
||||||
BS_BootSig DB 29h
|
|
||||||
BS_VolID DD 0
|
|
||||||
BS_VolLab DB 'HYPER_ASM '
|
|
||||||
BS_FileSysType DB 'FAT12 '
|
|
||||||
|
|
||||||
RootDirSectors equ 14
|
|
||||||
SectorNoOfRootDirectory equ 19
|
|
||||||
SectorNoOfFAT1 equ 1
|
|
||||||
DeltaSectorNo equ 17
|
|
|
@ -1,25 +0,0 @@
|
||||||
org 07c00h
|
|
||||||
|
|
||||||
BaseOfStack equ 07c00h
|
|
||||||
BaseOfLoader equ 09000h
|
|
||||||
OffsetOfLoader equ 0100h
|
|
||||||
jmp short START
|
|
||||||
%include "FAT12Header.inc"
|
|
||||||
|
|
||||||
START:
|
|
||||||
mov ax, cs
|
|
||||||
mov ds, ax
|
|
||||||
mov es, ax
|
|
||||||
mov ss, ax
|
|
||||||
mov sp, BaseOfStack
|
|
||||||
;FAT12ReadFile(ULONG16 Base,ULONG16 Offset,ULONG16 OffsetFileName)
|
|
||||||
push LoaderFileName
|
|
||||||
push OffsetOfLoader
|
|
||||||
push BaseOfLoader
|
|
||||||
call near FAT12ReadFile
|
|
||||||
add sp,6
|
|
||||||
jmp BaseOfLoader:OffsetOfLoader
|
|
||||||
%include "fat12readfile.lib"
|
|
||||||
LoaderFileName: db 'LOADER BIN',0
|
|
||||||
times 510-($-$$) db 0
|
|
||||||
dw 0xaa55
|
|
|
@ -1,248 +0,0 @@
|
||||||
org 0100h
|
|
||||||
jmp BEGIN
|
|
||||||
%include "pm.inc"
|
|
||||||
;GDT
|
|
||||||
DESC_VOID: Descriptor 0,0,0
|
|
||||||
DESC_GRAPH: Descriptor 0b8000h,0ffffh,DA_DRW | DA_DPL3
|
|
||||||
DESC_FLAT_C: Descriptor 0,0fffffh,DA_CR | DA_32 | DA_LIMIT_4K
|
|
||||||
DESC_FLAT_RW: Descriptor 0,0fffffh,DA_DRW | DA_32 | DA_LIMIT_4K
|
|
||||||
DESC_FLAT_USER_C: Descriptor 0,0fffffh,DA_CR | DA_32| DA_LIMIT_4K | DA_DPL3
|
|
||||||
DESC_FLAT_USER_RW: Descriptor 0,0fffffh,DA_DRW | DA_32 | DA_LIMIT_4K | DA_DPL3
|
|
||||||
|
|
||||||
GDTLEN equ $ - DESC_VOID
|
|
||||||
|
|
||||||
GDTPTR: dw GDTLEN - 1
|
|
||||||
dd LOADERINFLAT + DESC_VOID
|
|
||||||
|
|
||||||
;Paging
|
|
||||||
PDEBASE equ 100000h
|
|
||||||
PTEBASE equ 101000h
|
|
||||||
|
|
||||||
;kernel
|
|
||||||
LOADERBASE equ 09000h
|
|
||||||
LOADEROFFSET equ 0100h
|
|
||||||
LOADERINFLAT equ LOADERBASE*10h
|
|
||||||
|
|
||||||
KERNELFILENAME db 'KERNEL BIN',0
|
|
||||||
KERNELBASE equ 03000h
|
|
||||||
KERNELOFFSET equ 0000h
|
|
||||||
KERNELINFLAT equ KERNELBASE*10h + KERNELOFFSET
|
|
||||||
|
|
||||||
;Selectors
|
|
||||||
SLCT_FLAT_C equ DESC_FLAT_C - DESC_VOID
|
|
||||||
SLCT_GRAPH equ DESC_GRAPH - DESC_VOID
|
|
||||||
SLCT_FLAT_RW equ DESC_FLAT_RW - DESC_VOID
|
|
||||||
|
|
||||||
;==================Section .DATA==============================
|
|
||||||
;Variables
|
|
||||||
;Operating System Information
|
|
||||||
;OS:
|
|
||||||
OSINFO1: db 'Hyper-Assembler Operating System 1.0',0
|
|
||||||
OSINFO2: db "Loader written by Orange'S, Kernel written by Hyper-Assembler",0
|
|
||||||
KERNELFILELOADCOMPLETE db 'Kernel.bin Loaded to 0x30000',0
|
|
||||||
|
|
||||||
;GETMEMORY
|
|
||||||
RAMINFO1: db "Memory Information:",0
|
|
||||||
RAMTABLE16: db ' BASE L BASE H Length L Length H Type ',0
|
|
||||||
RAMSIZE: db 'RAM SIZE:',0
|
|
||||||
GETMEMFAIL: db 'Failed to Get The Memory',0
|
|
||||||
RAMAVAILABLE: db ' - Available',0
|
|
||||||
RAMRESERVED: db ' - Reserved',0
|
|
||||||
|
|
||||||
;Protected Mode:
|
|
||||||
PMINFO: db 'Protected Mode Entered...',0
|
|
||||||
PMINFO32 equ PMINFO + LOADERINFLAT
|
|
||||||
|
|
||||||
;PAGING:
|
|
||||||
PGINFO: db 'Paging Started...',0
|
|
||||||
PGINFO32 equ PGINFO + LOADERINFLAT
|
|
||||||
PTEINFO: db 'PTE Table BASE: ',0
|
|
||||||
PTEINFO32 equ PTEINFO + LOADERINFLAT
|
|
||||||
PDEINFO: db 'PDE Table BASE: ',0
|
|
||||||
PDEINFO32 equ PDEINFO + LOADERINFLAT
|
|
||||||
CR3INFO: db 'cr3: ',0
|
|
||||||
CR3INFO32 equ CR3INFO + LOADERINFLAT
|
|
||||||
|
|
||||||
;Variables Used in Functions
|
|
||||||
IO16_SPACE: db ' ',0
|
|
||||||
IO32_SPACE equ IO16_SPACE + LOADERINFLAT
|
|
||||||
IO16_RETURN: db 0Ah,0
|
|
||||||
IO32_RETURN equ IO16_RETURN + LOADERINFLAT
|
|
||||||
GRAPHPOS: dd 0
|
|
||||||
GRAPHPOS_32 equ GRAPHPOS + LOADERINFLAT
|
|
||||||
GETMEMBUFF: times 1024 db 0
|
|
||||||
GETMEMNUM: dd 0
|
|
||||||
GETMEMNUM_32 equ GETMEMBUFF + LOADERINFLAT
|
|
||||||
DISPMEMTOTAL: dd 0
|
|
||||||
DISPMEMTOTAL_32 equ DISPMEMTOTAL + LOADERINFLAT
|
|
||||||
KERNELLOADED: db 'KERNEL LOADED IN MEM.',0
|
|
||||||
KERNELLOADED_32 equ KERNELLOADED + LOADERINFLAT
|
|
||||||
%include "FAT12Header.inc"
|
|
||||||
;=========================STACK32=============================
|
|
||||||
[bits 32]
|
|
||||||
STACK32BASE:
|
|
||||||
times 1024 db 0
|
|
||||||
TOP:
|
|
||||||
STACK32TOP equ LOADERINFLAT + TOP
|
|
||||||
|
|
||||||
;==========================CODE16==============================
|
|
||||||
[bits 16]
|
|
||||||
%include "io16.lib"
|
|
||||||
%include "fat12readfile.lib"
|
|
||||||
BEGIN:
|
|
||||||
mov ax,cs
|
|
||||||
mov ds,ax
|
|
||||||
mov ss,ax
|
|
||||||
mov es,ax
|
|
||||||
|
|
||||||
mov ax,0003h
|
|
||||||
int 10h ;clear
|
|
||||||
|
|
||||||
xor eax,eax
|
|
||||||
mov eax,OSINFO1
|
|
||||||
push eax
|
|
||||||
call DISPSTR16
|
|
||||||
add esp,4
|
|
||||||
|
|
||||||
call DISPRETURN16
|
|
||||||
|
|
||||||
xor eax,eax
|
|
||||||
mov eax,OSINFO2
|
|
||||||
push eax
|
|
||||||
call DISPSTR16
|
|
||||||
add esp,4
|
|
||||||
|
|
||||||
call DISPRETURN16
|
|
||||||
|
|
||||||
call DISPRETURN16
|
|
||||||
|
|
||||||
xor eax,eax
|
|
||||||
mov eax,RAMINFO1
|
|
||||||
push eax
|
|
||||||
call DISPSTR16
|
|
||||||
add esp,4
|
|
||||||
|
|
||||||
call DISPRETURN16
|
|
||||||
|
|
||||||
call GETMEM16
|
|
||||||
|
|
||||||
mov eax,dword [ds:GETMEMNUM]
|
|
||||||
cmp eax,0
|
|
||||||
jne GETMEMSUCCESSFUL
|
|
||||||
xor eax,eax
|
|
||||||
mov eax,GETMEMFAIL
|
|
||||||
push eax
|
|
||||||
call DISPSTR16
|
|
||||||
pop eax
|
|
||||||
|
|
||||||
GETMEMSUCCESSFUL:
|
|
||||||
|
|
||||||
call DISPMEM16
|
|
||||||
call DISPRETURN16
|
|
||||||
|
|
||||||
;FAT12ReadFile(ULONG16 Base,ULONG16 Offset,ULONG16 OffsetFileName)
|
|
||||||
push KERNELFILENAME
|
|
||||||
push KERNELOFFSET
|
|
||||||
push KERNELBASE
|
|
||||||
call FAT12ReadFile
|
|
||||||
add esp,6
|
|
||||||
|
|
||||||
xor eax,eax
|
|
||||||
mov eax,KERNELFILELOADCOMPLETE
|
|
||||||
push eax
|
|
||||||
call DISPSTR16
|
|
||||||
add esp,4
|
|
||||||
|
|
||||||
call DISPRETURN16
|
|
||||||
|
|
||||||
;load gdt
|
|
||||||
lgdt [GDTPTR]
|
|
||||||
|
|
||||||
;close interupt
|
|
||||||
cli
|
|
||||||
|
|
||||||
;open A20
|
|
||||||
in al,92h
|
|
||||||
or al,00000010b
|
|
||||||
out 92h,al
|
|
||||||
|
|
||||||
;prepare to switch to the protected mode
|
|
||||||
mov eax,cr0
|
|
||||||
or eax,1
|
|
||||||
mov cr0,eax
|
|
||||||
|
|
||||||
jmp dword SLCT_FLAT_C:(CODE32_START + LOADERINFLAT)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
;===================CODE32======================
|
|
||||||
[bits 32]
|
|
||||||
%include "mem32.lib"
|
|
||||||
%include "io32.lib"
|
|
||||||
CODE32_START:
|
|
||||||
mov ax,SLCT_FLAT_RW
|
|
||||||
mov ss,ax
|
|
||||||
mov ds,ax
|
|
||||||
mov es,ax
|
|
||||||
mov gs,ax
|
|
||||||
|
|
||||||
mov ax,SLCT_GRAPH
|
|
||||||
mov gs,ax
|
|
||||||
|
|
||||||
mov sp,STACK32TOP
|
|
||||||
|
|
||||||
mov eax,PMINFO32
|
|
||||||
push eax
|
|
||||||
call near DISPSTR32
|
|
||||||
pop eax
|
|
||||||
|
|
||||||
|
|
||||||
;Setup paging
|
|
||||||
call PAGINGINIT32
|
|
||||||
|
|
||||||
call DISPRETURN32
|
|
||||||
|
|
||||||
mov eax,PGINFO32
|
|
||||||
push eax
|
|
||||||
call near DISPSTR32
|
|
||||||
pop eax
|
|
||||||
|
|
||||||
call DISPRETURN32
|
|
||||||
;Print PDE Table Base
|
|
||||||
mov eax,PDEINFO32
|
|
||||||
push eax
|
|
||||||
call DISPSTR32
|
|
||||||
pop eax
|
|
||||||
|
|
||||||
mov eax,PDEBASE
|
|
||||||
push eax
|
|
||||||
call DISPINTEAX32
|
|
||||||
pop eax
|
|
||||||
|
|
||||||
call DISPRETURN32
|
|
||||||
;Print PTE table base
|
|
||||||
mov eax,PTEINFO32
|
|
||||||
push eax
|
|
||||||
call DISPSTR32
|
|
||||||
pop eax
|
|
||||||
|
|
||||||
mov eax,PTEBASE
|
|
||||||
push eax
|
|
||||||
call DISPINTEAX32
|
|
||||||
pop eax
|
|
||||||
|
|
||||||
call DISPRETURN32
|
|
||||||
;Print cr3
|
|
||||||
mov eax,CR3INFO32
|
|
||||||
push eax
|
|
||||||
call DISPSTR32
|
|
||||||
pop eax
|
|
||||||
|
|
||||||
mov eax,cr3
|
|
||||||
push eax
|
|
||||||
call DISPINTEAX32
|
|
||||||
pop eax
|
|
||||||
|
|
||||||
;Jump to The Kernel
|
|
||||||
|
|
||||||
jmp SLCT_FLAT_C:KERNELINFLAT
|
|
|
@ -1,324 +0,0 @@
|
||||||
|
|
||||||
; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
||||||
; pm.inc
|
|
||||||
; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
||||||
; Forrest Yu, 2005
|
|
||||||
; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
||||||
|
|
||||||
|
|
||||||
; 描述符图示
|
|
||||||
|
|
||||||
; 图示一
|
|
||||||
;
|
|
||||||
; ------ ┏━━┳━━┓高地址
|
|
||||||
; ┃ 7 ┃ 段 ┃
|
|
||||||
; ┣━━┫ ┃
|
|
||||||
; 基
|
|
||||||
; 字节 7 ┆ ┆ ┆
|
|
||||||
; 址
|
|
||||||
; ┣━━┫ ② ┃
|
|
||||||
; ┃ 0 ┃ ┃
|
|
||||||
; ------ ┣━━╋━━┫
|
|
||||||
; ┃ 7 ┃ G ┃
|
|
||||||
; ┣━━╉──┨
|
|
||||||
; ┃ 6 ┃ D ┃
|
|
||||||
; ┣━━╉──┨
|
|
||||||
; ┃ 5 ┃ 0 ┃
|
|
||||||
; ┣━━╉──┨
|
|
||||||
; ┃ 4 ┃ AVL┃
|
|
||||||
; 字节 6 ┣━━╉──┨
|
|
||||||
; ┃ 3 ┃ ┃
|
|
||||||
; ┣━━┫ 段 ┃
|
|
||||||
; ┃ 2 ┃ 界 ┃
|
|
||||||
; ┣━━┫ 限 ┃
|
|
||||||
; ┃ 1 ┃ ┃
|
|
||||||
; ┣━━┫ ② ┃
|
|
||||||
; ┃ 0 ┃ ┃
|
|
||||||
; ------ ┣━━╋━━┫
|
|
||||||
; ┃ 7 ┃ P ┃
|
|
||||||
; ┣━━╉──┨
|
|
||||||
; ┃ 6 ┃ ┃
|
|
||||||
; ┣━━┫ DPL┃
|
|
||||||
; ┃ 5 ┃ ┃
|
|
||||||
; ┣━━╉──┨
|
|
||||||
; ┃ 4 ┃ S ┃
|
|
||||||
; 字节 5 ┣━━╉──┨
|
|
||||||
; ┃ 3 ┃ ┃
|
|
||||||
; ┣━━┫ T ┃
|
|
||||||
; ┃ 2 ┃ Y ┃
|
|
||||||
; ┣━━┫ P ┃
|
|
||||||
; ┃ 1 ┃ E ┃
|
|
||||||
; ┣━━┫ ┃
|
|
||||||
; ┃ 0 ┃ ┃
|
|
||||||
; ------ ┣━━╋━━┫
|
|
||||||
; ┃ 23 ┃ ┃
|
|
||||||
; ┣━━┫ ┃
|
|
||||||
; ┃ 22 ┃ ┃
|
|
||||||
; ┣━━┫ 段 ┃
|
|
||||||
;
|
|
||||||
; 字节 ┆ ┆ 基 ┆
|
|
||||||
; 2, 3, 4
|
|
||||||
; ┣━━┫ 址 ┃
|
|
||||||
; ┃ 1 ┃ ① ┃
|
|
||||||
; ┣━━┫ ┃
|
|
||||||
; ┃ 0 ┃ ┃
|
|
||||||
; ------ ┣━━╋━━┫
|
|
||||||
; ┃ 15 ┃ ┃
|
|
||||||
; ┣━━┫ ┃
|
|
||||||
; ┃ 14 ┃ ┃
|
|
||||||
; ┣━━┫ 段 ┃
|
|
||||||
;
|
|
||||||
; 字节 0,1┆ ┆ 界 ┆
|
|
||||||
;
|
|
||||||
; ┣━━┫ 限 ┃
|
|
||||||
; ┃ 1 ┃ ① ┃
|
|
||||||
; ┣━━┫ ┃
|
|
||||||
; ┃ 0 ┃ ┃
|
|
||||||
; ------ ┗━━┻━━┛低地址
|
|
||||||
;
|
|
||||||
|
|
||||||
|
|
||||||
; 图示二
|
|
||||||
|
|
||||||
; 高地址………………………………………………………………………低地址
|
|
||||||
|
|
||||||
; | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
|
|
||||||
; |7654321076543210765432107654321076543210765432107654321076543210| <- 共 8 字节
|
|
||||||
; |--------========--------========--------========--------========|
|
|
||||||
; ┏━━━┳━━━━━━━┳━━━━━━━━━━━┳━━━━━━━┓
|
|
||||||
; ┃31..24┃ (见下图) ┃ 段基址(23..0) ┃ 段界限(15..0)┃
|
|
||||||
; ┃ ┃ ┃ ┃ ┃
|
|
||||||
; ┃ 基址2┃③│②│ ①┃基址1b│ 基址1a ┃ 段界限1 ┃
|
|
||||||
; ┣━━━╋━━━┳━━━╋━━━━━━━━━━━╋━━━━━━━┫
|
|
||||||
; ┃ %6 ┃ %5 ┃ %4 ┃ %3 ┃ %2 ┃ %1 ┃
|
|
||||||
; ┗━━━┻━━━┻━━━┻━━━┻━━━━━━━┻━━━━━━━┛
|
|
||||||
; │ \_________
|
|
||||||
; │ \__________________
|
|
||||||
; │ \________________________________________________
|
|
||||||
; │ \
|
|
||||||
; ┏━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┓
|
|
||||||
; ┃ 7 ┃ 6 ┃ 5 ┃ 4 ┃ 3 ┃ 2 ┃ 1 ┃ 0 ┃ 7 ┃ 6 ┃ 5 ┃ 4 ┃ 3 ┃ 2 ┃ 1 ┃ 0 ┃
|
|
||||||
; ┣━━╋━━╋━━╋━━╋━━┻━━┻━━┻━━╋━━╋━━┻━━╋━━╋━━┻━━┻━━┻━━┫
|
|
||||||
; ┃ G ┃ D ┃ 0 ┃ AVL┃ 段界限 2 (19..16) ┃ P ┃ DPL ┃ S ┃ TYPE ┃
|
|
||||||
; ┣━━┻━━┻━━┻━━╋━━━━━━━━━━━╋━━┻━━━━━┻━━┻━━━━━━━━━━━┫
|
|
||||||
; ┃ ③: 属性 2 ┃ ②: 段界限 2 ┃ ①: 属性1 ┃
|
|
||||||
; ┗━━━━━━━━━━━┻━━━━━━━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━┛
|
|
||||||
; 高地址 低地址
|
|
||||||
;
|
|
||||||
;
|
|
||||||
|
|
||||||
; 说明:
|
|
||||||
;
|
|
||||||
; (1) P: 存在(Present)位。
|
|
||||||
; P=1 表示描述符对地址转换是有效的,或者说该描述符所描述的段存在,即在内存中;
|
|
||||||
; P=0 表示描述符对地址转换无效,即该段不存在。使用该描述符进行内存访问时会引起异常。
|
|
||||||
;
|
|
||||||
; (2) DPL: 表示描述符特权级(Descriptor Privilege level),共2位。它规定了所描述段的特权级,用于特权检查,以决定对该段能否访问。
|
|
||||||
;
|
|
||||||
; (3) S: 说明描述符的类型。
|
|
||||||
; 对于存储段描述符而言,S=1,以区别与系统段描述符和门描述符(S=0)。
|
|
||||||
;
|
|
||||||
; (4) TYPE: 说明存储段描述符所描述的存储段的具体属性。
|
|
||||||
;
|
|
||||||
;
|
|
||||||
; 数据段类型 类型值 说明
|
|
||||||
; ----------------------------------
|
|
||||||
; 0 只读
|
|
||||||
; 1 只读、已访问
|
|
||||||
; 2 读/写
|
|
||||||
; 3 读/写、已访问
|
|
||||||
; 4 只读、向下扩展
|
|
||||||
; 5 只读、向下扩展、已访问
|
|
||||||
; 6 读/写、向下扩展
|
|
||||||
; 7 读/写、向下扩展、已访问
|
|
||||||
;
|
|
||||||
;
|
|
||||||
; 类型值 说明
|
|
||||||
; 代码段类型 ----------------------------------
|
|
||||||
; 8 只执行
|
|
||||||
; 9 只执行、已访问
|
|
||||||
; A 执行/读
|
|
||||||
; B 执行/读、已访问
|
|
||||||
; C 只执行、一致码段
|
|
||||||
; D 只执行、一致码段、已访问
|
|
||||||
; E 执行/读、一致码段
|
|
||||||
; F 执行/读、一致码段、已访问
|
|
||||||
;
|
|
||||||
;
|
|
||||||
; 系统段类型 类型编码 说明
|
|
||||||
; ----------------------------------
|
|
||||||
; 0 <未定义>
|
|
||||||
; 1 可用286TSS
|
|
||||||
; 2 LDT
|
|
||||||
; 3 忙的286TSS
|
|
||||||
; 4 286调用门
|
|
||||||
; 5 任务门
|
|
||||||
; 6 286中断门
|
|
||||||
; 7 286陷阱门
|
|
||||||
; 8 未定义
|
|
||||||
; 9 可用386TSS
|
|
||||||
; A <未定义>
|
|
||||||
; B 忙的386TSS
|
|
||||||
; C 386调用门
|
|
||||||
; D <未定义>
|
|
||||||
; E 386中断门
|
|
||||||
; F 386陷阱门
|
|
||||||
;
|
|
||||||
; (5) G: 段界限粒度(Granularity)位。
|
|
||||||
; G=0 表示界限粒度为字节;
|
|
||||||
; G=1 表示界限粒度为4K 字节。
|
|
||||||
; 注意,界限粒度只对段界限有效,对段基地址无效,段基地址总是以字节为单位。
|
|
||||||
;
|
|
||||||
; (6) D: D位是一个很特殊的位,在描述可执行段、向下扩展数据段或由SS寄存器寻址的段(通常是堆栈段)的三种描述符中的意义各不相同。
|
|
||||||
; ⑴ 在描述可执行段的描述符中,D位决定了指令使用的地址及操作数所默认的大小。
|
|
||||||
; ① D=1表示默认情况下指令使用32位地址及32位或8位操作数,这样的代码段也称为32位代码段;
|
|
||||||
; ② D=0 表示默认情况下,使用16位地址及16位或8位操作数,这样的代码段也称为16位代码段,它与80286兼容。可以使用地址大小前缀和操作数大小前缀分别改变默认的地址或操作数的大小。
|
|
||||||
; ⑵ 在向下扩展数据段的描述符中,D位决定段的上部边界。
|
|
||||||
; ① D=1表示段的上部界限为4G;
|
|
||||||
; ② D=0表示段的上部界限为64K,这是为了与80286兼容。
|
|
||||||
; ⑶ 在描述由SS寄存器寻址的段描述符中,D位决定隐式的堆栈访问指令(如PUSH和POP指令)使用何种堆栈指针寄存器。
|
|
||||||
; ① D=1表示使用32位堆栈指针寄存器ESP;
|
|
||||||
; ② D=0表示使用16位堆栈指针寄存器SP,这与80286兼容。
|
|
||||||
;
|
|
||||||
; (7) AVL: 软件可利用位。80386对该位的使用未左规定,Intel公司也保证今后开发生产的处理器只要与80386兼容,就不会对该位的使用做任何定义或规定。
|
|
||||||
;
|
|
||||||
|
|
||||||
|
|
||||||
;----------------------------------------------------------------------------
|
|
||||||
; 描述符类型值说明
|
|
||||||
; 其中:
|
|
||||||
; DA_ : Descriptor Attribute
|
|
||||||
; D : 数据段
|
|
||||||
; C : 代码段
|
|
||||||
; S : 系统段
|
|
||||||
; R : 只读
|
|
||||||
; RW : 读写
|
|
||||||
; A : 已访问
|
|
||||||
; 其它 : 可按照字面意思理解
|
|
||||||
;----------------------------------------------------------------------------
|
|
||||||
DA_32 EQU 4000h ; 32 位段
|
|
||||||
DA_LIMIT_4K EQU 8000h ; 段界限粒度为 4K 字节
|
|
||||||
|
|
||||||
DA_DPL0 EQU 00h ; DPL = 0
|
|
||||||
DA_DPL1 EQU 20h ; DPL = 1
|
|
||||||
DA_DPL2 EQU 40h ; DPL = 2
|
|
||||||
DA_DPL3 EQU 60h ; DPL = 3
|
|
||||||
;----------------------------------------------------------------------------
|
|
||||||
; 存储段描述符类型值说明
|
|
||||||
;----------------------------------------------------------------------------
|
|
||||||
DA_DR EQU 90h ; 存在的只读数据段类型值
|
|
||||||
DA_DRW EQU 92h ; 存在的可读写数据段属性值
|
|
||||||
DA_DRWA EQU 93h ; 存在的已访问可读写数据段类型值
|
|
||||||
DA_C EQU 98h ; 存在的只执行代码段属性值
|
|
||||||
DA_CR EQU 9Ah ; 存在的可执行可读代码段属性值
|
|
||||||
DA_CCO EQU 9Ch ; 存在的只执行一致代码段属性值
|
|
||||||
DA_CCOR EQU 9Eh ; 存在的可执行可读一致代码段属性值
|
|
||||||
;----------------------------------------------------------------------------
|
|
||||||
; 系统段描述符类型值说明
|
|
||||||
;----------------------------------------------------------------------------
|
|
||||||
DA_LDT EQU 82h ; 局部描述符表段类型值
|
|
||||||
DA_TaskGate EQU 85h ; 任务门类型值
|
|
||||||
DA_386TSS EQU 89h ; 可用 386 任务状态段类型值
|
|
||||||
DA_386CGate EQU 8Ch ; 386 调用门类型值
|
|
||||||
DA_386IGate EQU 8Eh ; 386 中断门类型值
|
|
||||||
DA_386TGate EQU 8Fh ; 386 陷阱门类型值
|
|
||||||
;----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
; 选择子图示:
|
|
||||||
; ┏━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┓
|
|
||||||
; ┃ 15 ┃ 14 ┃ 13 ┃ 12 ┃ 11 ┃ 10 ┃ 9 ┃ 8 ┃ 7 ┃ 6 ┃ 5 ┃ 4 ┃ 3 ┃ 2 ┃ 1 ┃ 0 ┃
|
|
||||||
; ┣━━┻━━┻━━┻━━┻━━┻━━┻━━┻━━┻━━┻━━┻━━┻━━┻━━╋━━╋━━┻━━┫
|
|
||||||
; ┃ 描述符索引 ┃ TI ┃ RPL ┃
|
|
||||||
; ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┻━━┻━━━━━┛
|
|
||||||
;
|
|
||||||
; RPL(Requested Privilege Level): 请求特权级,用于特权检查。
|
|
||||||
;
|
|
||||||
; TI(Table Indicator): 引用描述符表指示位
|
|
||||||
; TI=0 指示从全局描述符表GDT中读取描述符;
|
|
||||||
; TI=1 指示从局部描述符表LDT中读取描述符。
|
|
||||||
;
|
|
||||||
|
|
||||||
;----------------------------------------------------------------------------
|
|
||||||
; 选择子类型值说明
|
|
||||||
; 其中:
|
|
||||||
; SA_ : Selector Attribute
|
|
||||||
|
|
||||||
SA_RPL0 EQU 0 ; ┓
|
|
||||||
SA_RPL1 EQU 1 ; ┣ RPL
|
|
||||||
SA_RPL2 EQU 2 ; ┃
|
|
||||||
SA_RPL3 EQU 3 ; ┛
|
|
||||||
|
|
||||||
SA_TIG EQU 0 ; ┓TI
|
|
||||||
SA_TIL EQU 4 ; ┛
|
|
||||||
;----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
;----------------------------------------------------------------------------
|
|
||||||
; 分页机制使用的常量说明
|
|
||||||
;----------------------------------------------------------------------------
|
|
||||||
PG_P EQU 1 ; 页存在属性位
|
|
||||||
PG_RWR EQU 0 ; R/W 属性位值, 读/执行
|
|
||||||
PG_RWW EQU 2 ; R/W 属性位值, 读/写/执行
|
|
||||||
PG_USS EQU 0 ; U/S 属性位值, 系统级
|
|
||||||
PG_USU EQU 4 ; U/S 属性位值, 用户级
|
|
||||||
;----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
; =========================================
|
|
||||||
; FLAGS - Intel 8086 Family Flags Register
|
|
||||||
; =========================================
|
|
||||||
;
|
|
||||||
; |11|10|F|E|D|C|B|A|9|8|7|6|5|4|3|2|1|0|
|
|
||||||
; | | | | | | | | | | | | | | | | | '--- CF……Carry Flag
|
|
||||||
; | | | | | | | | | | | | | | | | '--- 1
|
|
||||||
; | | | | | | | | | | | | | | | '--- PF……Parity Flag
|
|
||||||
; | | | | | | | | | | | | | | '--- 0
|
|
||||||
; | | | | | | | | | | | | | '--- AF……Auxiliary Flag
|
|
||||||
; | | | | | | | | | | | | '--- 0
|
|
||||||
; | | | | | | | | | | | '--- ZF……Zero Flag
|
|
||||||
; | | | | | | | | | | '--- SF……Sign Flag
|
|
||||||
; | | | | | | | | | '--- TF……Trap Flag (Single Step)
|
|
||||||
; | | | | | | | | '--- IF……Interrupt Flag
|
|
||||||
; | | | | | | | '--- DF……Direction Flag
|
|
||||||
; | | | | | | '--- OF……Overflow flag
|
|
||||||
; | | | | '----- IOPL……I/O Privilege Level (286+ only)
|
|
||||||
; | | | '----- NT……Nested Task Flag (286+ only)
|
|
||||||
; | | '----- 0
|
|
||||||
; | '----- RF……Resume Flag (386+ only)
|
|
||||||
; '------ VM……Virtual Mode Flag (386+ only)
|
|
||||||
;
|
|
||||||
; 注: see PUSHF POPF STI CLI STD CLD
|
|
||||||
;
|
|
||||||
|
|
||||||
|
|
||||||
; 宏 ------------------------------------------------------------------------------------------------------
|
|
||||||
;
|
|
||||||
; 描述符
|
|
||||||
; usage: Descriptor Base, Limit, Attr
|
|
||||||
; Base: dd
|
|
||||||
; Limit: dd (low 20 bits available)
|
|
||||||
; Attr: dw (lower 4 bits of higher byte are always 0)
|
|
||||||
%macro Descriptor 3
|
|
||||||
dw %2 & 0FFFFh ; 段界限 1 (2 字节)
|
|
||||||
dw %1 & 0FFFFh ; 段基址 1 (2 字节)
|
|
||||||
db (%1 >> 16) & 0FFh ; 段基址 2 (1 字节)
|
|
||||||
dw ((%2 >> 8) & 0F00h) | (%3 & 0F0FFh) ; 属性 1 + 段界限 2 + 属性 2 (2 字节)
|
|
||||||
db (%1 >> 24) & 0FFh ; 段基址 3 (1 字节)
|
|
||||||
%endmacro ; 共 8 字节
|
|
||||||
;
|
|
||||||
; 门
|
|
||||||
; usage: Gate Selector, Offset, DCount, Attr
|
|
||||||
; Selector: dw
|
|
||||||
; Offset: dd
|
|
||||||
; DCount: db
|
|
||||||
; Attr: db
|
|
||||||
%macro Gate 4
|
|
||||||
dw (%2 & 0FFFFh) ; 偏移 1 (2 字节)
|
|
||||||
dw %1 ; 选择子 (2 字节)
|
|
||||||
dw (%3 & 1Fh) | ((%4 << 8) & 0FF00h) ; 属性 (2 字节)
|
|
||||||
dw ((%2 >> 16) & 0FFFFh) ; 偏移 2 (2 字节)
|
|
||||||
%endmacro ; 共 8 字节
|
|
||||||
; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
@ -1,318 +0,0 @@
|
||||||
;===================================================================32 BITS=============================================================
|
|
||||||
|
|
||||||
global __asm_KePrintHex32 ;VOID __asm_KePrintHex32(ULONG32 Hex)
|
|
||||||
global __asm_KePrintStr32 ;VOID __asm_KePrintStr32(PCHAR *OffsetStr)
|
|
||||||
global __asm_KeSetGraphPosition32; ULONG32 __asm_KeSetGraphPosition32(ULONG32 Row,ULONG32 Column)
|
|
||||||
global __asm_KeClearGraph32;VOID __asm_KeClearGraph32()
|
|
||||||
global __asm_KeGraphRowOverflow;ULONG32 _asm_KeGraphRowOverflow32(ULONG32 GraphPosition)
|
|
||||||
global __asm_KeGetCurrentGraphPosition32; ULONG32 _asm_KeGetCurrentGraphPosition32(VOID);
|
|
||||||
|
|
||||||
extern _KeCheckGraphRowForPrint
|
|
||||||
extern _KeCheckGraphRowForReturn
|
|
||||||
|
|
||||||
SLCT_GRAPH equ 8
|
|
||||||
SLCT_FLAT_C equ 16
|
|
||||||
SLCT_FLAT_RW equ 24
|
|
||||||
|
|
||||||
KeGraphPosition_32 dd 0
|
|
||||||
|
|
||||||
DOSGRAPHROW equ 25
|
|
||||||
DOSGRAPHCOLUMN equ 80
|
|
||||||
|
|
||||||
__asm_KeGetCurrentGraphPosition32:
|
|
||||||
mov eax, dword [ds:KeGraphPosition_32]
|
|
||||||
ret
|
|
||||||
|
|
||||||
__asm_KeSetGraphPosition32:
|
|
||||||
push ebp
|
|
||||||
mov ebp,esp
|
|
||||||
push esi
|
|
||||||
push edi
|
|
||||||
push ebx
|
|
||||||
push edx
|
|
||||||
|
|
||||||
mov eax,dword [ss:ebp+8]
|
|
||||||
mov ebx,dword [ss:ebp+12]
|
|
||||||
cmp eax,DOSGRAPHROW-1
|
|
||||||
ja .fault
|
|
||||||
cmp ebx,DOSGRAPHCOLUMN-1
|
|
||||||
ja .fault
|
|
||||||
|
|
||||||
mov dl,2*DOSGRAPHCOLUMN
|
|
||||||
mul dl
|
|
||||||
|
|
||||||
mov esi,eax
|
|
||||||
|
|
||||||
xor eax,eax
|
|
||||||
|
|
||||||
mov al,bl
|
|
||||||
mov dl,2
|
|
||||||
mul dl
|
|
||||||
|
|
||||||
add eax,esi
|
|
||||||
|
|
||||||
mov dword [ds:KeGraphPosition_32],eax
|
|
||||||
jmp .return
|
|
||||||
.fault:
|
|
||||||
mov dword [ds:KeGraphPosition_32],0
|
|
||||||
xor eax,eax
|
|
||||||
.return:
|
|
||||||
pop edx
|
|
||||||
pop ebx
|
|
||||||
pop edi
|
|
||||||
pop esi
|
|
||||||
mov esp,ebp
|
|
||||||
pop ebp
|
|
||||||
ret
|
|
||||||
|
|
||||||
__asm_KeClearGraph32:
|
|
||||||
push ecx
|
|
||||||
push esi
|
|
||||||
mov ecx,2*DOSGRAPHROW*DOSGRAPHCOLUMN-1
|
|
||||||
xor esi,esi
|
|
||||||
.loop:
|
|
||||||
mov byte [gs:esi],0
|
|
||||||
dec ecx
|
|
||||||
inc esi
|
|
||||||
cmp ecx,0
|
|
||||||
jne .loop
|
|
||||||
mov dword [KeGraphPosition_32],0
|
|
||||||
pop esi
|
|
||||||
pop ecx
|
|
||||||
ret
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
__asm_KePrintHex32:
|
|
||||||
;Entrance: push HEX
|
|
||||||
push ebp
|
|
||||||
mov ebp,esp
|
|
||||||
push eax
|
|
||||||
|
|
||||||
mov eax,dword [ss:ebp+8]
|
|
||||||
shr eax,24
|
|
||||||
mov ah,0Fh
|
|
||||||
push ax
|
|
||||||
call near DISPINTAL32
|
|
||||||
pop ax
|
|
||||||
|
|
||||||
mov eax,dword [ss:ebp+8]
|
|
||||||
shr eax,16
|
|
||||||
mov ah,0Fh
|
|
||||||
push ax
|
|
||||||
call near DISPINTAL32
|
|
||||||
pop ax
|
|
||||||
|
|
||||||
mov eax,dword [ss:ebp+8]
|
|
||||||
shr eax,8
|
|
||||||
mov ah,0Fh
|
|
||||||
push ax
|
|
||||||
call near DISPINTAL32
|
|
||||||
pop ax
|
|
||||||
|
|
||||||
mov eax,dword [ss:ebp+8]
|
|
||||||
mov ah,0Fh
|
|
||||||
push ax
|
|
||||||
call near DISPINTAL32
|
|
||||||
pop ax
|
|
||||||
|
|
||||||
pop eax
|
|
||||||
mov esp,ebp
|
|
||||||
pop ebp
|
|
||||||
ret
|
|
||||||
|
|
||||||
__asm_KePrintStr32:
|
|
||||||
;Entrance: push offset
|
|
||||||
;ds:offset = String
|
|
||||||
push ebp
|
|
||||||
mov ebp,esp
|
|
||||||
push esi
|
|
||||||
push edi
|
|
||||||
push eax
|
|
||||||
push ebx
|
|
||||||
push gs
|
|
||||||
|
|
||||||
mov ax,SLCT_GRAPH
|
|
||||||
mov gs,ax
|
|
||||||
mov esi,dword [ss:ebp+8]
|
|
||||||
mov edi,dword [ds:KeGraphPosition_32]
|
|
||||||
.loop1:
|
|
||||||
mov al,byte [ds:esi]
|
|
||||||
cmp al,0
|
|
||||||
je .end
|
|
||||||
cmp al,0Ah
|
|
||||||
jne .loop2
|
|
||||||
;Check For OverFlow
|
|
||||||
push eax
|
|
||||||
push edi
|
|
||||||
call _KeCheckGraphRowForReturn
|
|
||||||
add esp,4
|
|
||||||
mov edi,eax
|
|
||||||
pop eax
|
|
||||||
;let edi point to the next row
|
|
||||||
;edi/(80*2) - every row:80 chars, each char takes 2 bytes.
|
|
||||||
push eax
|
|
||||||
mov eax,edi
|
|
||||||
mov bl,2*DOSGRAPHCOLUMN
|
|
||||||
div bl
|
|
||||||
;only keep the low 8 of eax(al,aka quotion)
|
|
||||||
and eax, 0FFh
|
|
||||||
inc eax
|
|
||||||
;calculate the edi now
|
|
||||||
mov bl,2*DOSGRAPHCOLUMN
|
|
||||||
mul bl
|
|
||||||
mov edi,eax
|
|
||||||
pop eax
|
|
||||||
inc esi
|
|
||||||
jmp .loop1
|
|
||||||
.loop2:
|
|
||||||
;Check For OverFlow
|
|
||||||
push eax
|
|
||||||
|
|
||||||
push edi
|
|
||||||
call _KeCheckGraphRowForPrint
|
|
||||||
add esp,4
|
|
||||||
|
|
||||||
mov edi,eax
|
|
||||||
pop eax
|
|
||||||
;======
|
|
||||||
mov ah,0Fh
|
|
||||||
mov word [gs:edi],ax
|
|
||||||
add edi,2
|
|
||||||
inc esi
|
|
||||||
jmp .loop1
|
|
||||||
.end:
|
|
||||||
mov dword [ds:KeGraphPosition_32],edi
|
|
||||||
|
|
||||||
pop gs
|
|
||||||
pop ebx
|
|
||||||
pop eax
|
|
||||||
pop edi
|
|
||||||
pop esi
|
|
||||||
mov esp,ebp
|
|
||||||
pop ebp
|
|
||||||
ret
|
|
||||||
|
|
||||||
DISPINTAL32:
|
|
||||||
;Entrance: push ax ,AH=ATTR, AL=Char
|
|
||||||
push ebp
|
|
||||||
mov ebp,esp
|
|
||||||
push eax
|
|
||||||
push gs
|
|
||||||
push ecx
|
|
||||||
push edi
|
|
||||||
push ebx
|
|
||||||
|
|
||||||
mov edi,dword [ds:KeGraphPosition_32]
|
|
||||||
mov ax,SLCT_GRAPH
|
|
||||||
mov gs,ax
|
|
||||||
xor eax,eax
|
|
||||||
mov ax, word [ss:ebp+8]
|
|
||||||
mov bx,ax
|
|
||||||
;keep high 4 bits of al
|
|
||||||
and al,0F0H
|
|
||||||
mov cl,4
|
|
||||||
shr al,cl
|
|
||||||
call near CHANGEAL
|
|
||||||
;Check For OverFlow
|
|
||||||
push eax
|
|
||||||
|
|
||||||
push edi
|
|
||||||
call _KeCheckGraphRowForPrint
|
|
||||||
add esp,4
|
|
||||||
|
|
||||||
mov edi,eax
|
|
||||||
pop eax
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
||||||
mov word [gs:edi],ax
|
|
||||||
add edi,2
|
|
||||||
mov dword [ds:KeGraphPosition_32],edi
|
|
||||||
;keep low 4 bits of al
|
|
||||||
mov ax,bx
|
|
||||||
and al,0Fh
|
|
||||||
call near CHANGEAL
|
|
||||||
mov ah,bh
|
|
||||||
mov word [gs:edi],ax
|
|
||||||
add edi,2
|
|
||||||
mov dword [ds:KeGraphPosition_32],edi
|
|
||||||
|
|
||||||
pop ebx
|
|
||||||
pop edi
|
|
||||||
pop ecx
|
|
||||||
pop gs
|
|
||||||
pop eax
|
|
||||||
pop ebp
|
|
||||||
ret
|
|
||||||
|
|
||||||
CHANGEAL:
|
|
||||||
;Entrance:void
|
|
||||||
cmp al,09h
|
|
||||||
jna .l2
|
|
||||||
add al,37h
|
|
||||||
jmp .end
|
|
||||||
.l2:
|
|
||||||
add al,30h
|
|
||||||
.end:
|
|
||||||
ret
|
|
||||||
|
|
||||||
__asm_KeGraphRowOverflow:
|
|
||||||
push ebp
|
|
||||||
mov ebp,esp
|
|
||||||
push esi
|
|
||||||
push edi
|
|
||||||
push edx
|
|
||||||
push ecx
|
|
||||||
push ebx
|
|
||||||
|
|
||||||
mov eax,[ss:ebp+8]
|
|
||||||
xor esi,esi
|
|
||||||
xor edi,edi
|
|
||||||
|
|
||||||
mov esi,2*DOSGRAPHCOLUMN
|
|
||||||
|
|
||||||
mov ebx,DOSGRAPHROW
|
|
||||||
|
|
||||||
.loop1:
|
|
||||||
mov ecx,2*DOSGRAPHCOLUMN-1
|
|
||||||
.loop2:
|
|
||||||
mov dl,byte [gs:esi]
|
|
||||||
mov byte [gs:edi],dl
|
|
||||||
inc edi
|
|
||||||
inc esi
|
|
||||||
dec ecx
|
|
||||||
cmp ecx,0
|
|
||||||
jne .loop2
|
|
||||||
|
|
||||||
dec ebx
|
|
||||||
cmp ebx,0
|
|
||||||
jne .loop1
|
|
||||||
|
|
||||||
push 0
|
|
||||||
push 24
|
|
||||||
call __asm_KeSetGraphPosition32
|
|
||||||
add esp,8
|
|
||||||
|
|
||||||
mov ecx,2*DOSGRAPHCOLUMN
|
|
||||||
.loop3:
|
|
||||||
mov byte [gs:eax],0
|
|
||||||
inc eax
|
|
||||||
dec ecx
|
|
||||||
cmp ecx,0
|
|
||||||
jne .loop3
|
|
||||||
|
|
||||||
|
|
||||||
push 0
|
|
||||||
push 24
|
|
||||||
call __asm_KeSetGraphPosition32
|
|
||||||
add esp,8
|
|
||||||
|
|
||||||
pop ebx
|
|
||||||
pop ecx
|
|
||||||
pop edx
|
|
||||||
pop edi
|
|
||||||
pop esi
|
|
||||||
mov esp,ebp
|
|
||||||
pop ebp
|
|
||||||
ret
|
|
||||||
|
|
||||||
|
|
|
@ -1,257 +0,0 @@
|
||||||
global __asm_KeWritePort;VOID _asm_KeWritePort(ULONG16 Port,ULONG8 Value);
|
|
||||||
global __asm_KeReadPort;ULONG8 _asm_KeReadPort(ULONG16 Port);
|
|
||||||
global __asm_KeLoadIDT;VOID _asm_KeLoadIDT(VOID)
|
|
||||||
global __asm_KeWriteGDT; VOID _asm_KeWriteGDT(PGDT_DESCRIPTOR DescBase ,PWrite_GDT_DESCRIPTOR PDescriptor, ULONG32 index);
|
|
||||||
;IDT DESC
|
|
||||||
global __asm_KeDivideError
|
|
||||||
global __asm_KeSingleStepException
|
|
||||||
global __asm_KeNMI
|
|
||||||
global __asm_KeBreakpointException
|
|
||||||
global __asm_KeOverflow
|
|
||||||
global __asm_KeBoundsCheck
|
|
||||||
global __asm_KeInvalidOpcode
|
|
||||||
global __asm_KeCoprNotAvailable
|
|
||||||
global __asm_KeDoubleFault
|
|
||||||
global __asm_KeCoprSegmentOverrun
|
|
||||||
global __asm_KeInvalidTSS
|
|
||||||
global __asm_KeSegmentNotPresent
|
|
||||||
global __asm_KeStackException
|
|
||||||
global __asm_KeGeneralProtection
|
|
||||||
global __asm_KePageFault
|
|
||||||
global __asm_KeCoprError
|
|
||||||
;8259A Interrupts
|
|
||||||
global __asm_KeIrqInt00
|
|
||||||
global __asm_KeIrqInt01
|
|
||||||
global __asm_KeIrqInt02
|
|
||||||
global __asm_KeIrqInt03
|
|
||||||
global __asm_KeIrqInt04
|
|
||||||
global __asm_KeIrqInt05
|
|
||||||
global __asm_KeIrqInt06
|
|
||||||
global __asm_KeIrqInt07
|
|
||||||
global __asm_KeIrqInt08
|
|
||||||
global __asm_KeIrqInt09
|
|
||||||
global __asm_KeIrqInt10
|
|
||||||
global __asm_KeIrqInt11
|
|
||||||
global __asm_KeIrqInt12
|
|
||||||
global __asm_KeIrqInt13
|
|
||||||
global __asm_KeIrqInt14
|
|
||||||
global __asm_KeIrqInt15
|
|
||||||
|
|
||||||
global __asm_EIP2EAX
|
|
||||||
|
|
||||||
extern _KeIrqIntHandler
|
|
||||||
extern _KeIDTPtr
|
|
||||||
extern _KeExceptionHandler
|
|
||||||
|
|
||||||
SLCT_FLAT_C equ 16
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
__asm_EIP2EAX:
|
|
||||||
mov eax, [esp]
|
|
||||||
ret
|
|
||||||
|
|
||||||
__asm_KeReadPort:
|
|
||||||
mov edx, [esp + 4]
|
|
||||||
xor eax, eax
|
|
||||||
in al, dx
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
ret
|
|
||||||
;push ebp
|
|
||||||
;mov ebp,esp
|
|
||||||
;push edx
|
|
||||||
;mov edx,[ss:ebp+8]
|
|
||||||
;xor eax,eax
|
|
||||||
;in al,dx
|
|
||||||
;nop
|
|
||||||
;nop
|
|
||||||
;nop
|
|
||||||
;pop edx
|
|
||||||
;pop ebp
|
|
||||||
;ret
|
|
||||||
|
|
||||||
__asm_KeWritePort:
|
|
||||||
mov edx, [esp + 4]
|
|
||||||
mov al, [esp + 4 + 4]
|
|
||||||
out dx, al
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
ret
|
|
||||||
|
|
||||||
;push ebp
|
|
||||||
;mov ebp,esp
|
|
||||||
;push edx
|
|
||||||
;push eax
|
|
||||||
;mov edx,[ss:ebp+8]
|
|
||||||
;mov eax,[ss:ebp+12]
|
|
||||||
;out dx,al
|
|
||||||
;nop
|
|
||||||
;nop
|
|
||||||
;nop
|
|
||||||
;pop eax
|
|
||||||
;pop edx
|
|
||||||
;ret
|
|
||||||
|
|
||||||
__asm_KeLoadIDT:
|
|
||||||
lidt [_KeIDTPtr]
|
|
||||||
jmp SLCT_FLAT_C:.force
|
|
||||||
.force:
|
|
||||||
sti
|
|
||||||
ret
|
|
||||||
|
|
||||||
__asm_KeDivideError:
|
|
||||||
push 0xFFFFFFFF
|
|
||||||
push 0
|
|
||||||
jmp exception
|
|
||||||
|
|
||||||
__asm_KeSingleStepException:
|
|
||||||
push 0xFFFFFFFF
|
|
||||||
push 1
|
|
||||||
jmp exception
|
|
||||||
|
|
||||||
__asm_KeNMI:
|
|
||||||
push 0xFFFFFFFF
|
|
||||||
push 2
|
|
||||||
jmp exception
|
|
||||||
|
|
||||||
__asm_KeBreakpointException:
|
|
||||||
push 0xFFFFFFFF
|
|
||||||
push 3
|
|
||||||
jmp exception
|
|
||||||
|
|
||||||
__asm_KeOverflow:
|
|
||||||
push 0xFFFFFFFF
|
|
||||||
push 4
|
|
||||||
jmp exception
|
|
||||||
|
|
||||||
__asm_KeBoundsCheck:
|
|
||||||
push 0xFFFFFFFF
|
|
||||||
push 5
|
|
||||||
jmp exception
|
|
||||||
|
|
||||||
__asm_KeInvalidOpcode:
|
|
||||||
push 0xFFFFFFFF
|
|
||||||
push 6
|
|
||||||
jmp exception
|
|
||||||
|
|
||||||
__asm_KeCoprNotAvailable:
|
|
||||||
push 0xFFFFFFFF
|
|
||||||
push 7
|
|
||||||
jmp exception
|
|
||||||
|
|
||||||
__asm_KeDoubleFault:
|
|
||||||
push 0xFFFFFFFF
|
|
||||||
push 8
|
|
||||||
jmp exception
|
|
||||||
|
|
||||||
__asm_KeCoprSegmentOverrun:
|
|
||||||
push 0xFFFFFFFF
|
|
||||||
push 9
|
|
||||||
jmp exception
|
|
||||||
|
|
||||||
__asm_KeInvalidTSS:
|
|
||||||
push 0xFFFFFFFF
|
|
||||||
push 10
|
|
||||||
jmp exception
|
|
||||||
|
|
||||||
__asm_KeSegmentNotPresent:
|
|
||||||
push 0xFFFFFFFF
|
|
||||||
push 11
|
|
||||||
jmp exception
|
|
||||||
|
|
||||||
__asm_KeStackException:
|
|
||||||
push 0xFFFFFFFF
|
|
||||||
push 12
|
|
||||||
jmp exception
|
|
||||||
|
|
||||||
__asm_KeGeneralProtection:
|
|
||||||
push 0xFFFFFFFF
|
|
||||||
push 13
|
|
||||||
jmp exception
|
|
||||||
|
|
||||||
__asm_KePageFault:
|
|
||||||
push 0xFFFFFFFF
|
|
||||||
push 14
|
|
||||||
jmp exception
|
|
||||||
|
|
||||||
__asm_KeCoprError:
|
|
||||||
push 0xFFFFFFFF
|
|
||||||
push 15
|
|
||||||
jmp exception
|
|
||||||
|
|
||||||
exception:
|
|
||||||
call _KeExceptionHandler
|
|
||||||
add esp,8
|
|
||||||
hlt
|
|
||||||
|
|
||||||
__asm_KeIrqInt00:
|
|
||||||
push 0
|
|
||||||
jmp interrupt
|
|
||||||
|
|
||||||
__asm_KeIrqInt01:
|
|
||||||
push 1
|
|
||||||
jmp interrupt
|
|
||||||
|
|
||||||
__asm_KeIrqInt02:
|
|
||||||
push 2
|
|
||||||
jmp interrupt
|
|
||||||
|
|
||||||
__asm_KeIrqInt03:
|
|
||||||
push 3
|
|
||||||
jmp interrupt
|
|
||||||
|
|
||||||
__asm_KeIrqInt04:
|
|
||||||
push 4
|
|
||||||
jmp interrupt
|
|
||||||
|
|
||||||
__asm_KeIrqInt05:
|
|
||||||
push 5
|
|
||||||
jmp interrupt
|
|
||||||
|
|
||||||
__asm_KeIrqInt06:
|
|
||||||
push 6
|
|
||||||
jmp interrupt
|
|
||||||
|
|
||||||
__asm_KeIrqInt07:
|
|
||||||
push 7
|
|
||||||
jmp interrupt
|
|
||||||
|
|
||||||
__asm_KeIrqInt08:
|
|
||||||
push 8
|
|
||||||
jmp interrupt
|
|
||||||
|
|
||||||
__asm_KeIrqInt09:
|
|
||||||
push 9
|
|
||||||
jmp interrupt
|
|
||||||
|
|
||||||
__asm_KeIrqInt10:
|
|
||||||
push 10
|
|
||||||
jmp interrupt
|
|
||||||
|
|
||||||
__asm_KeIrqInt11:
|
|
||||||
push 11
|
|
||||||
jmp interrupt
|
|
||||||
|
|
||||||
__asm_KeIrqInt12:
|
|
||||||
push 12
|
|
||||||
jmp interrupt
|
|
||||||
|
|
||||||
__asm_KeIrqInt13:
|
|
||||||
push 13
|
|
||||||
jmp interrupt
|
|
||||||
|
|
||||||
__asm_KeIrqInt14:
|
|
||||||
push 14
|
|
||||||
jmp interrupt
|
|
||||||
|
|
||||||
__asm_KeIrqInt15:
|
|
||||||
push 15
|
|
||||||
jmp interrupt
|
|
||||||
|
|
||||||
interrupt:
|
|
||||||
call _KeIrqIntHandler
|
|
||||||
add esp,4
|
|
||||||
hlt
|
|
||||||
|
|
|
@ -1,34 +0,0 @@
|
||||||
SLCT_GRAPH equ 8
|
|
||||||
SLCT_FLAT_C equ 16
|
|
||||||
SLCT_FLAT_RW equ 24
|
|
||||||
global __asm_KeMemoryCopy;PVOID _asm_KeMemoryCopy(PVOID src,PVOID dst,ULONG32 size)
|
|
||||||
__asm_KeMemoryCopy:
|
|
||||||
push ebp
|
|
||||||
mov ebp,esp
|
|
||||||
push esi
|
|
||||||
push edi
|
|
||||||
push ecx
|
|
||||||
|
|
||||||
mov ax,SLCT_FLAT_RW
|
|
||||||
mov es,ax
|
|
||||||
mov esi,dword [ss:ebp+8]
|
|
||||||
mov edi,dword [ss:ebp+12]
|
|
||||||
mov ecx,dword [ss:ebp+16]
|
|
||||||
|
|
||||||
.loop:
|
|
||||||
mov al,byte [es:esi]
|
|
||||||
mov byte [ds:edi],al
|
|
||||||
inc esi
|
|
||||||
inc edi
|
|
||||||
dec ecx
|
|
||||||
cmp ecx,0
|
|
||||||
je .end
|
|
||||||
jmp .loop
|
|
||||||
.end:
|
|
||||||
mov eax,dword [ss:ebp+8]
|
|
||||||
|
|
||||||
pop ecx
|
|
||||||
pop edi
|
|
||||||
pop esi
|
|
||||||
pop ebp
|
|
||||||
ret
|
|
|
@ -1,56 +0,0 @@
|
||||||
P_STACKBASE equ 0
|
|
||||||
GSREG equ P_STACKBASE
|
|
||||||
FSREG equ GSREG + 4
|
|
||||||
ESREG equ FSREG + 4
|
|
||||||
DSREG equ ESREG + 4
|
|
||||||
EDIREG equ DSREG + 4
|
|
||||||
ESIREG equ EDIREG + 4
|
|
||||||
EBPREG equ ESIREG + 4
|
|
||||||
KERNELESPREG equ EBPREG + 4
|
|
||||||
EBXREG equ KERNELESPREG + 4
|
|
||||||
EDXREG equ EBXREG + 4
|
|
||||||
ECXREG equ EDXREG + 4
|
|
||||||
EAXREG equ ECXREG + 4
|
|
||||||
RETADR equ EAXREG + 4
|
|
||||||
EIPREG equ RETADR + 4
|
|
||||||
CSREG equ EIPREG + 4
|
|
||||||
EFLAGSREG equ CSREG + 4
|
|
||||||
ESPREG equ EFLAGSREG + 4
|
|
||||||
SSREG equ ESPREG + 4
|
|
||||||
P_STACKTOP equ SSREG + 4
|
|
||||||
P_LDT_SEL equ P_STACKTOP
|
|
||||||
P_LDT equ P_LDT_SEL + 2
|
|
||||||
TSS3_S_SP0 equ 4
|
|
||||||
|
|
||||||
extern _KeTSS
|
|
||||||
extern _PStartProcess
|
|
||||||
|
|
||||||
|
|
||||||
global __asm_KeLoadTSS;
|
|
||||||
global __asm_Restart;
|
|
||||||
|
|
||||||
__asm_KeLoadTSS:
|
|
||||||
push ebp
|
|
||||||
mov ebp,esp
|
|
||||||
push eax
|
|
||||||
;mov eax,dword [ss:ebp+8]
|
|
||||||
mov eax,56
|
|
||||||
ltr ax
|
|
||||||
pop eax
|
|
||||||
mov esp,ebp
|
|
||||||
pop ebp
|
|
||||||
ret
|
|
||||||
|
|
||||||
|
|
||||||
__asm_Restart:
|
|
||||||
mov esp,[_PStartProcess]
|
|
||||||
lea eax,[esp+P_STACKTOP]
|
|
||||||
mov dword [_KeTSS+TSS3_S_SP0],eax
|
|
||||||
|
|
||||||
pop gs
|
|
||||||
pop fs
|
|
||||||
pop es
|
|
||||||
pop ds
|
|
||||||
popad
|
|
||||||
add esp,4
|
|
||||||
iretd
|
|
|
@ -1,23 +0,0 @@
|
||||||
global _HkWritePort32 ; void HkWritePort32(uint16 port ,uint16 data)
|
|
||||||
push ebp
|
|
||||||
mov ebp,esp
|
|
||||||
mov edx,[ ebp + 8 ]
|
|
||||||
mov eax,[ ebp + 12 ]
|
|
||||||
out dx,ax
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
mov esp,ebp
|
|
||||||
pop ebp
|
|
||||||
ret
|
|
||||||
|
|
||||||
global _HkReadPort32 ; void HkWritePort32(uint16 port ,uint16 data)
|
|
||||||
push ebp
|
|
||||||
mov ebp,esp
|
|
||||||
mov edx,[ ebp + 8]
|
|
||||||
mov eax,[ ebp + 12]
|
|
||||||
in ax,dx
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
mov esp,ebp
|
|
||||||
pop ebp
|
|
||||||
ret
|
|
|
@ -1,36 +0,0 @@
|
||||||
extern _KeSystemInit
|
|
||||||
extern _KeGDTPtr
|
|
||||||
extern _KeSwitchGDT
|
|
||||||
extern _KeIDTPtr
|
|
||||||
global _start
|
|
||||||
;GDT
|
|
||||||
SLCT_GRAPH equ 8
|
|
||||||
SLCT_FLAT_C equ 16
|
|
||||||
SLCT_FLAT_RW equ 24
|
|
||||||
;Stack
|
|
||||||
[section .bss]
|
|
||||||
[BITS 32]
|
|
||||||
resb 2 * 1024
|
|
||||||
KernelStackTop:
|
|
||||||
[section .text]
|
|
||||||
[BITS 32]
|
|
||||||
_start:
|
|
||||||
mov esp,KernelStackTop
|
|
||||||
|
|
||||||
sgdt [_KeGDTPtr]
|
|
||||||
call _KeSwitchGDT
|
|
||||||
lgdt [_KeGDTPtr]
|
|
||||||
jmp SLCT_FLAT_C:GDT_COMPLETE
|
|
||||||
GDT_COMPLETE:
|
|
||||||
|
|
||||||
mov ax,SLCT_GRAPH
|
|
||||||
mov gs,ax
|
|
||||||
mov ax,SLCT_FLAT_RW
|
|
||||||
mov ds,ax
|
|
||||||
mov ss,ax
|
|
||||||
|
|
||||||
push 0
|
|
||||||
popfd
|
|
||||||
|
|
||||||
|
|
||||||
call _KeSystemInit
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
menuentry "secX" {
|
||||||
|
multiboot2 /secX/secxkrnl.elf
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
include $(MK)/prologue.mk
|
||||||
|
|
||||||
|
SRC_$(d) := avl_tree_test.c \
|
||||||
|
driver.c \
|
||||||
|
linked_list_test.c \
|
||||||
|
salloc_test.c
|
||||||
|
|
||||||
|
SRC_$(d) := $(addprefix $(d)/, $(SRC_$(d)))
|
||||||
|
|
||||||
|
OBJ_$(d) := $(SRC_$(d):.c=.o)
|
||||||
|
|
||||||
|
$(OBJ_$(d)): %.o: %.c
|
||||||
|
$(COMP)
|
||||||
|
|
||||||
|
# append all OBJECTS to clean
|
||||||
|
OBJ := $(OBJ) $(OBJ_$(d))
|
||||||
|
|
||||||
|
include $(MK)/epilogue.mk
|
|
@ -69,7 +69,7 @@ static bool pre_order_assert(avl_tree_t *node, int order[], int size)
|
||||||
|
|
||||||
//////// TESTS/////////
|
//////// TESTS/////////
|
||||||
|
|
||||||
static bool insert_simple_l()
|
static bool insert_simple_l(void)
|
||||||
{
|
{
|
||||||
//1 2
|
//1 2
|
||||||
// \ / \
|
// \ / \
|
||||||
|
@ -93,7 +93,7 @@ static bool insert_simple_l()
|
||||||
return result && lb_avl_tree_validate(&tree);
|
return result && lb_avl_tree_validate(&tree);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool insert_simple_r()
|
static bool insert_simple_r(void)
|
||||||
{
|
{
|
||||||
// 3 2
|
// 3 2
|
||||||
// / / \
|
// / / \
|
||||||
|
@ -117,7 +117,7 @@ static bool insert_simple_r()
|
||||||
return result && lb_avl_tree_validate(&tree);
|
return result && lb_avl_tree_validate(&tree);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool insert_simple_ll()
|
static bool insert_simple_ll(void)
|
||||||
{
|
{
|
||||||
//2 3
|
//2 3
|
||||||
// \ / \
|
// \ / \
|
||||||
|
@ -140,7 +140,7 @@ static bool insert_simple_ll()
|
||||||
return result && lb_avl_tree_validate(&tree);
|
return result && lb_avl_tree_validate(&tree);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool insert_simple_rr()
|
static bool insert_simple_rr(void)
|
||||||
{
|
{
|
||||||
// 4 3
|
// 4 3
|
||||||
// / / \
|
// / / \
|
||||||
|
@ -163,7 +163,7 @@ static bool insert_simple_rr()
|
||||||
return result && lb_avl_tree_validate(&tree);
|
return result && lb_avl_tree_validate(&tree);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool insert_complex_1()
|
static bool insert_complex_1(void)
|
||||||
{
|
{
|
||||||
// 20+ 20++ 20++ 9
|
// 20+ 20++ 20++ 9
|
||||||
// / \ / \ / \ / \
|
// / \ / \ / \ / \
|
||||||
|
@ -191,7 +191,7 @@ static bool insert_complex_1()
|
||||||
return result && lb_avl_tree_validate(&tree);
|
return result && lb_avl_tree_validate(&tree);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool insert_complex_2()
|
static bool insert_complex_2(void)
|
||||||
{
|
{
|
||||||
// 20+ 20++ 20++ 9
|
// 20+ 20++ 20++ 9
|
||||||
// / \ / \ / \ / \
|
// / \ / \ / \ / \
|
||||||
|
@ -219,7 +219,7 @@ static bool insert_complex_2()
|
||||||
return result && lb_avl_tree_validate(&tree);
|
return result && lb_avl_tree_validate(&tree);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool insert_complex_3()
|
static bool insert_complex_3(void)
|
||||||
{
|
{
|
||||||
// __20+__ _20++_ __20++_ ___9___
|
// __20+__ _20++_ __20++_ ___9___
|
||||||
// / \ / \ / \ / \
|
// / \ / \ / \ / \
|
||||||
|
@ -254,7 +254,7 @@ static bool insert_complex_3()
|
||||||
return result && lb_avl_tree_validate(&tree);
|
return result && lb_avl_tree_validate(&tree);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool insert_complex_4()
|
static bool insert_complex_4(void)
|
||||||
{
|
{
|
||||||
// __20+__ _20++_ __20++_ ___9___
|
// __20+__ _20++_ __20++_ ___9___
|
||||||
// / \ / \ / \ / \
|
// / \ / \ / \ / \
|
||||||
|
@ -289,7 +289,7 @@ static bool insert_complex_4()
|
||||||
return result && lb_avl_tree_validate(&tree);
|
return result && lb_avl_tree_validate(&tree);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool insert_duplicate()
|
static bool insert_duplicate(void)
|
||||||
{
|
{
|
||||||
// __20+__ _20++_ __20++_ ___9___
|
// __20+__ _20++_ __20++_ ___9___
|
||||||
// / \ / \ / \ / \
|
// / \ / \ / \ / \
|
||||||
|
@ -327,7 +327,7 @@ static bool insert_duplicate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool delete_simple_l()
|
static bool delete_simple_l(void)
|
||||||
{
|
{
|
||||||
// 2 3
|
// 2 3
|
||||||
// x \ / \
|
// x \ / \
|
||||||
|
@ -355,7 +355,7 @@ static bool delete_simple_l()
|
||||||
return result && lb_avl_tree_validate(&tree);
|
return result && lb_avl_tree_validate(&tree);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool delete_simple_r()
|
static bool delete_simple_r(void)
|
||||||
{
|
{
|
||||||
// 3 2
|
// 3 2
|
||||||
// / x / \
|
// / x / \
|
||||||
|
@ -383,7 +383,7 @@ static bool delete_simple_r()
|
||||||
return result && lb_avl_tree_validate(&tree);
|
return result && lb_avl_tree_validate(&tree);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool delete_simple_ll()
|
static bool delete_simple_ll(void)
|
||||||
{
|
{
|
||||||
// 2 3
|
// 2 3
|
||||||
// x \ / \
|
// x \ / \
|
||||||
|
@ -410,7 +410,7 @@ static bool delete_simple_ll()
|
||||||
return result && lb_avl_tree_validate(&tree);
|
return result && lb_avl_tree_validate(&tree);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool delete_simple_rr()
|
static bool delete_simple_rr(void)
|
||||||
{
|
{
|
||||||
// 3 2
|
// 3 2
|
||||||
// / x / \
|
// / x / \
|
||||||
|
@ -437,7 +437,7 @@ static bool delete_simple_rr()
|
||||||
return result && lb_avl_tree_validate(&tree);
|
return result && lb_avl_tree_validate(&tree);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool delete_complex_1()
|
static bool delete_complex_1(void)
|
||||||
{
|
{
|
||||||
// Test Case #1
|
// Test Case #1
|
||||||
// - A single node tree has its only node removed.
|
// - A single node tree has its only node removed.
|
||||||
|
@ -464,7 +464,7 @@ static bool delete_complex_1()
|
||||||
return result && lb_avl_tree_validate(&tree);
|
return result && lb_avl_tree_validate(&tree);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool delete_complex_2()
|
static bool delete_complex_2(void)
|
||||||
{
|
{
|
||||||
// Test Case #2
|
// Test Case #2
|
||||||
// - A small tree has its root removed.
|
// - A small tree has its root removed.
|
||||||
|
@ -507,7 +507,7 @@ static bool delete_complex_2()
|
||||||
return result && lb_avl_tree_validate(&tree);
|
return result && lb_avl_tree_validate(&tree);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool delete_complex_3()
|
static bool delete_complex_3(void)
|
||||||
{
|
{
|
||||||
// Test Case #3
|
// Test Case #3
|
||||||
// - A small tree has a node with 2 children removed
|
// - A small tree has a node with 2 children removed
|
||||||
|
@ -547,7 +547,7 @@ static bool delete_complex_3()
|
||||||
return result && lb_avl_tree_validate(&tree);
|
return result && lb_avl_tree_validate(&tree);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool delete_complex_4()
|
static bool delete_complex_4(void)
|
||||||
{
|
{
|
||||||
// Test Case #4
|
// Test Case #4
|
||||||
// - A small tree has all nodes but the root removed from the bottom up.
|
// - A small tree has all nodes but the root removed from the bottom up.
|
||||||
|
@ -596,7 +596,7 @@ static bool delete_complex_4()
|
||||||
return result && lb_avl_tree_validate(&tree);
|
return result && lb_avl_tree_validate(&tree);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool delete_complex_single_rotation()
|
static bool delete_complex_single_rotation(void)
|
||||||
{
|
{
|
||||||
// Test case single rotation
|
// Test case single rotation
|
||||||
//
|
//
|
||||||
|
@ -651,7 +651,7 @@ static bool delete_complex_single_rotation()
|
||||||
return result && lb_avl_tree_validate(&tree);
|
return result && lb_avl_tree_validate(&tree);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool delete_complex_double_rotation()
|
static bool delete_complex_double_rotation(void)
|
||||||
{
|
{
|
||||||
// Test case double rotation
|
// Test case double rotation
|
||||||
//
|
//
|
||||||
|
@ -706,7 +706,7 @@ static bool delete_complex_double_rotation()
|
||||||
return result && lb_avl_tree_validate(&tree);
|
return result && lb_avl_tree_validate(&tree);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool delete_complex_multiple_rotation()
|
static bool delete_complex_multiple_rotation(void)
|
||||||
{
|
{
|
||||||
// Test case multiple rotation
|
// Test case multiple rotation
|
||||||
//
|
//
|
||||||
|
@ -761,7 +761,7 @@ static bool delete_complex_multiple_rotation()
|
||||||
return result && lb_avl_tree_validate(&tree);
|
return result && lb_avl_tree_validate(&tree);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool delete_DNE()
|
static bool delete_DNE(void)
|
||||||
{
|
{
|
||||||
// Test case DNE
|
// Test case DNE
|
||||||
// Delete a node that does not exist
|
// Delete a node that does not exist
|
||||||
|
@ -808,7 +808,7 @@ static bool delete_DNE()
|
||||||
#define AVL_APOCALYPSE_ITER 2
|
#define AVL_APOCALYPSE_ITER 2
|
||||||
static int_tree_node apocalypse[AVL_APOCALYPSE_NUM];
|
static int_tree_node apocalypse[AVL_APOCALYPSE_NUM];
|
||||||
|
|
||||||
static bool test_apocalypse()
|
static bool test_apocalypse(void)
|
||||||
{
|
{
|
||||||
bool result = true;
|
bool result = true;
|
||||||
avl_tree_t tree;
|
avl_tree_t tree;
|
||||||
|
@ -817,10 +817,10 @@ static bool test_apocalypse()
|
||||||
// insert test
|
// insert test
|
||||||
for(int i = 0; i < AVL_APOCALYPSE_NUM; i++)
|
for(int i = 0; i < AVL_APOCALYPSE_NUM; i++)
|
||||||
{
|
{
|
||||||
apocalypse[i].val = rand();
|
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 += rand() % 32765;
|
apocalypse[i].val += lb_rand() % 32765;
|
||||||
}
|
}
|
||||||
lb_avl_tree_insert(&tree, &apocalypse[i].tree_entry);
|
lb_avl_tree_insert(&tree, &apocalypse[i].tree_entry);
|
||||||
}
|
}
|
||||||
|
@ -927,7 +927,7 @@ void avl_tree_test(void)
|
||||||
// delete non-existing
|
// delete non-existing
|
||||||
run_case("delete_DNE", delete_DNE());
|
run_case("delete_DNE", delete_DNE());
|
||||||
|
|
||||||
srand(2986);
|
lb_srand(2986);
|
||||||
// ultimate apocalypse
|
// ultimate apocalypse
|
||||||
for(int i = 0; i < AVL_APOCALYPSE_ITER; i++)
|
for(int i = 0; i < AVL_APOCALYPSE_ITER; i++)
|
||||||
{
|
{
|
||||||
|
|
|
@ -16,17 +16,17 @@ static case_info ginfo[CASE_NUM];
|
||||||
static void *gat[GAT_SIZE];
|
static void *gat[GAT_SIZE];
|
||||||
static char *test_name;
|
static char *test_name;
|
||||||
|
|
||||||
static void test_info()
|
static void test_info(void)
|
||||||
{
|
{
|
||||||
ke_printf("[TD-INFO][%s] - ", test_name);
|
ke_printf("[TD-INFO][%s] - ", test_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_warning()
|
static void test_warning(void)
|
||||||
{
|
{
|
||||||
ke_printf("[TD-WARN][%s] - ", test_name);
|
ke_printf("[TD-WARN][%s] - ", test_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_error()
|
static void test_error(void)
|
||||||
{
|
{
|
||||||
ke_printf("[TD-ERR][%s] - ", test_name);
|
ke_printf("[TD-ERR][%s] - ", test_name);
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ static void gat_push(void *ptr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool gat_full()
|
static bool gat_full(void)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < GAT_SIZE; i++)
|
for (int i = 0; i < GAT_SIZE; i++)
|
||||||
{
|
{
|
||||||
|
@ -55,7 +55,7 @@ static bool gat_full()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gat_free()
|
static void gat_free(void)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < GAT_SIZE; i++)
|
for (int i = 0; i < GAT_SIZE; i++)
|
||||||
{
|
{
|
||||||
|
@ -97,7 +97,7 @@ void KABI test_begin(char *name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void KABI test_end()
|
void KABI test_end(void)
|
||||||
{
|
{
|
||||||
gat_free();
|
gat_free();
|
||||||
int32_t total = 0, failed = 0, success = 0;
|
int32_t total = 0, failed = 0, success = 0;
|
||||||
|
|
|
@ -118,7 +118,7 @@ static void push_front_val(linked_list_t *list, int val)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool insert_test_beginning()
|
static bool insert_test_beginning(void)
|
||||||
{
|
{
|
||||||
linked_list_t list;
|
linked_list_t list;
|
||||||
lb_linked_list_init(&list);
|
lb_linked_list_init(&list);
|
||||||
|
@ -132,7 +132,7 @@ static bool insert_test_beginning()
|
||||||
return assert_list(&list, val, 4);
|
return assert_list(&list, val, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool insert_test_middle()
|
static bool insert_test_middle(void)
|
||||||
{
|
{
|
||||||
linked_list_t list;
|
linked_list_t list;
|
||||||
lb_linked_list_init(&list);
|
lb_linked_list_init(&list);
|
||||||
|
@ -149,7 +149,7 @@ static bool insert_test_middle()
|
||||||
return assert_list(&list, val, 6);
|
return assert_list(&list, val, 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool insert_test_end()
|
static bool insert_test_end(void)
|
||||||
{
|
{
|
||||||
linked_list_t list;
|
linked_list_t list;
|
||||||
lb_linked_list_init(&list);
|
lb_linked_list_init(&list);
|
||||||
|
@ -163,7 +163,7 @@ static bool insert_test_end()
|
||||||
return assert_list(&list, val, 4);
|
return assert_list(&list, val, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool insert_test_invalid()
|
static bool insert_test_invalid(void)
|
||||||
{
|
{
|
||||||
linked_list_t list;
|
linked_list_t list;
|
||||||
lb_linked_list_init(&list);
|
lb_linked_list_init(&list);
|
||||||
|
@ -193,7 +193,7 @@ static bool insert_test_invalid()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool remove_test_beginning()
|
static bool remove_test_beginning(void)
|
||||||
{
|
{
|
||||||
linked_list_t list;
|
linked_list_t list;
|
||||||
lb_linked_list_init(&list);
|
lb_linked_list_init(&list);
|
||||||
|
@ -210,7 +210,7 @@ static bool remove_test_beginning()
|
||||||
return assert_list(&list, val, 2);
|
return assert_list(&list, val, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool remove_test_middle()
|
static bool remove_test_middle(void)
|
||||||
{
|
{
|
||||||
linked_list_t list;
|
linked_list_t list;
|
||||||
lb_linked_list_init(&list);
|
lb_linked_list_init(&list);
|
||||||
|
@ -231,7 +231,7 @@ static bool remove_test_middle()
|
||||||
return assert_list(&list, val, 4);
|
return assert_list(&list, val, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool remove_test_end()
|
static bool remove_test_end(void)
|
||||||
{
|
{
|
||||||
linked_list_t list;
|
linked_list_t list;
|
||||||
lb_linked_list_init(&list);
|
lb_linked_list_init(&list);
|
||||||
|
@ -248,7 +248,7 @@ static bool remove_test_end()
|
||||||
return assert_list(&list, val, 2);
|
return assert_list(&list, val, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool remove_test_all()
|
static bool remove_test_all(void)
|
||||||
{
|
{
|
||||||
bool result = true;
|
bool result = true;
|
||||||
linked_list_t list;
|
linked_list_t list;
|
||||||
|
@ -293,7 +293,7 @@ static bool remove_test_all()
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool remove_test_invalid()
|
static bool remove_test_invalid(void)
|
||||||
{
|
{
|
||||||
linked_list_t list;
|
linked_list_t list;
|
||||||
lb_linked_list_init(&list);
|
lb_linked_list_init(&list);
|
||||||
|
@ -323,7 +323,7 @@ static bool remove_test_invalid()
|
||||||
return assert_list(&list, val, 4);
|
return assert_list(&list, val, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool size_test()
|
static bool size_test(void)
|
||||||
{
|
{
|
||||||
bool result = true;
|
bool result = true;
|
||||||
linked_list_t list;
|
linked_list_t list;
|
||||||
|
@ -343,7 +343,7 @@ static bool size_test()
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool push_pop_front_test()
|
static bool push_pop_front_test(void)
|
||||||
{
|
{
|
||||||
bool result = true;
|
bool result = true;
|
||||||
linked_list_t list;
|
linked_list_t list;
|
||||||
|
@ -371,7 +371,7 @@ static bool push_pop_front_test()
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool push_pop_back_test()
|
static bool push_pop_back_test(void)
|
||||||
{
|
{
|
||||||
bool result = true;
|
bool result = true;
|
||||||
linked_list_t list;
|
linked_list_t list;
|
||||||
|
@ -405,7 +405,7 @@ static int32_t equals(void *a, void *b)
|
||||||
OBTAIN_STRUCT_ADDR((linked_list_node_t*)a, my_list_node, lnode)->val;
|
OBTAIN_STRUCT_ADDR((linked_list_node_t*)a, my_list_node, lnode)->val;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool search_test()
|
static bool search_test(void)
|
||||||
{
|
{
|
||||||
bool result = true;
|
bool result = true;
|
||||||
linked_list_t list;
|
linked_list_t list;
|
||||||
|
|
|
@ -11,7 +11,7 @@ const uint32_t salloc_header_size = sizeof(_salloc_header);
|
||||||
|
|
||||||
static char buffer[1024];
|
static char buffer[1024];
|
||||||
|
|
||||||
static bool salloc_init_test()
|
static bool salloc_init_test(void)
|
||||||
{
|
{
|
||||||
lb_salloc_init(buffer, 1024);
|
lb_salloc_init(buffer, 1024);
|
||||||
uint32_t blk_size[] = {1024};
|
uint32_t blk_size[] = {1024};
|
||||||
|
@ -19,7 +19,7 @@ static bool salloc_init_test()
|
||||||
return lb_salloc_assert(buffer, blk_size, blk_free, 1);
|
return lb_salloc_assert(buffer, blk_size, blk_free, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool salloc_basic_alloc()
|
static bool salloc_basic_alloc(void)
|
||||||
{
|
{
|
||||||
bool result = true;
|
bool result = true;
|
||||||
lb_salloc_init(buffer, 1024);
|
lb_salloc_init(buffer, 1024);
|
||||||
|
@ -30,7 +30,7 @@ static bool salloc_basic_alloc()
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool salloc_full_alloc()
|
static bool salloc_full_alloc(void)
|
||||||
{
|
{
|
||||||
bool result = true;
|
bool result = true;
|
||||||
lb_salloc_init(buffer, 1024);
|
lb_salloc_init(buffer, 1024);
|
||||||
|
@ -41,7 +41,7 @@ static bool salloc_full_alloc()
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool salloc_overflow_alloc()
|
static bool salloc_overflow_alloc(void)
|
||||||
{
|
{
|
||||||
bool result = true;
|
bool result = true;
|
||||||
lb_salloc_init(buffer, 1024);
|
lb_salloc_init(buffer, 1024);
|
||||||
|
@ -52,7 +52,7 @@ static bool salloc_overflow_alloc()
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool salloc_multiple_alloc()
|
static bool salloc_multiple_alloc(void)
|
||||||
{
|
{
|
||||||
bool result = true;
|
bool result = true;
|
||||||
lb_salloc_init(buffer, 1024);
|
lb_salloc_init(buffer, 1024);
|
||||||
|
@ -68,7 +68,7 @@ static bool salloc_multiple_alloc()
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool salloc_alloc_not_enough()
|
static bool salloc_alloc_not_enough(void)
|
||||||
{
|
{
|
||||||
void* ptr;
|
void* ptr;
|
||||||
bool result = true;
|
bool result = true;
|
||||||
|
@ -82,7 +82,7 @@ static bool salloc_alloc_not_enough()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool salloc_basic_free()
|
static bool salloc_basic_free(void)
|
||||||
{
|
{
|
||||||
void* ptr;
|
void* ptr;
|
||||||
bool result = true;
|
bool result = true;
|
||||||
|
@ -97,7 +97,7 @@ static bool salloc_basic_free()
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool salloc_full_free()
|
static bool salloc_full_free(void)
|
||||||
{
|
{
|
||||||
void* ptr;
|
void* ptr;
|
||||||
bool result = true;
|
bool result = true;
|
||||||
|
@ -112,7 +112,7 @@ static bool salloc_full_free()
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool salloc_multiple_free()
|
static bool salloc_multiple_free(void)
|
||||||
{
|
{
|
||||||
void* ptr1, *ptr2, *ptr3, *ptr4;
|
void* ptr1, *ptr2, *ptr3, *ptr4;
|
||||||
bool result = true;
|
bool result = true;
|
||||||
|
@ -135,7 +135,7 @@ static bool salloc_multiple_free()
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool salloc_free_join_tail()
|
static bool salloc_free_join_tail(void)
|
||||||
{
|
{
|
||||||
void* ptr1, *ptr2, *ptr3, *ptr4;
|
void* ptr1, *ptr2, *ptr3, *ptr4;
|
||||||
bool result = true;
|
bool result = true;
|
||||||
|
@ -156,7 +156,7 @@ static bool salloc_free_join_tail()
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool salloc_free_join_head()
|
static bool salloc_free_join_head(void)
|
||||||
{
|
{
|
||||||
void* ptr1, *ptr2, *ptr3, *ptr4;
|
void* ptr1, *ptr2, *ptr3, *ptr4;
|
||||||
bool result = true;
|
bool result = true;
|
||||||
|
@ -178,7 +178,7 @@ static bool salloc_free_join_head()
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool salloc_free_join_mid()
|
static bool salloc_free_join_mid(void)
|
||||||
{
|
{
|
||||||
void* ptr1, *ptr2, *ptr3, *ptr4;
|
void* ptr1, *ptr2, *ptr3, *ptr4;
|
||||||
bool result = true;
|
bool result = true;
|
||||||
|
@ -200,7 +200,7 @@ static bool salloc_free_join_mid()
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool salloc_free_join_consecutive()
|
static bool salloc_free_join_consecutive(void)
|
||||||
{
|
{
|
||||||
void* ptr1, *ptr2, *ptr3, *ptr4, *ptr5;
|
void* ptr1, *ptr2, *ptr3, *ptr4, *ptr5;
|
||||||
bool result = true;
|
bool result = true;
|
||||||
|
@ -234,7 +234,7 @@ static bool salloc_free_join_consecutive()
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool salloc_free_all()
|
static bool salloc_free_all(void)
|
||||||
{
|
{
|
||||||
void* ptr1, *ptr2, *ptr3, *ptr4;
|
void* ptr1, *ptr2, *ptr3, *ptr4;
|
||||||
bool result = true;
|
bool result = true;
|
||||||
|
@ -256,7 +256,7 @@ static bool salloc_free_all()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void KABI salloc_test()
|
void KABI salloc_test(void)
|
||||||
{
|
{
|
||||||
test_begin("salloc test");
|
test_begin("salloc test");
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue