diff --git a/kernel/Makefile.Module b/kernel/Makefile.Module index dcfd203..9f1a4cb 100644 --- a/kernel/Makefile.Module +++ b/kernel/Makefile.Module @@ -18,10 +18,10 @@ LIB_INCLUDE_DIRS := ../lib/include # Module sources and their object files SRC = $(wildcard $(SRC_DIR)/*.c) -ASM := $(wildcard $(ASM_DIR)/*.s) +ASM := $(wildcard $(ASM_DIR)/*.S) OBJ := $(SRC:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o) -OBJ += $(ASM:$(ASM_DIR)/%.s=$(OBJ_DIR)/%.o) +OBJ += $(ASM:$(ASM_DIR)/%.S=$(OBJ_DIR)/%.o) # Compiler settings @@ -43,7 +43,7 @@ $(MOD_OBJ): $(OBJ) | $(MOBJ_DIR) $(OBJ_DIR)/%.o: $(SRC_DIR)/%.c | $(OBJ_DIR) $(CC) $< -o $@ $(CFLAGS) $(HFLAGS) $(INCFLAGS) -$(OBJ_DIR)/%.o: $(ASM_DIR)/%.s | $(OBJ_DIR) +$(OBJ_DIR)/%.o: $(ASM_DIR)/%.S | $(OBJ_DIR) $(CC) $< -o $@ $(CFLAGS) $(HFLAGS) $(INCFLAGS) $(OBJ_DIR) $(MOBJ_DIR): diff --git a/kernel/include/kernel/log.h b/kernel/include/kernel/log.h new file mode 100644 index 0000000..83f1584 --- /dev/null +++ b/kernel/include/kernel/log.h @@ -0,0 +1,14 @@ +#ifndef LOG_H_ +#define LOG_H_ + +#include + +/* + * reg_dump: + * Dumps the content of general purpose registers on the screen. + * + */ + +void reg_dump(void); + +#endif diff --git a/kernel/log/asm/dump.S b/kernel/log/asm/dump.S new file mode 100644 index 0000000..0d7aef6 --- /dev/null +++ b/kernel/log/asm/dump.S @@ -0,0 +1,122 @@ +.global reg_dump +.extern printf + +.text + +/* + * reg_dump: + * --------- + * + * Save the context of caller in prev_* memory locations and print them. + * + */ + +reg_dump: + + mov %esp, prev_esp + add $0x04, prev_esp + + mov %ebp, prev_ebp + + mov %eax, prev_eax + mov %ecx, prev_ecx + mov %edx, prev_edx + mov %ebx, prev_ebx + mov %esi, prev_esi + mov %edi, prev_edi + + mov (%esp), %eax + mov %eax, prev_eip + + push %ebp + mov %esp, %ebp + + push prev_eax + push $EAX_FMT + call printf + + add $0x08, %esp + + push prev_ecx + push $ECX_FMT + call printf + + add $0x08, %esp + + + push prev_edx + push $EDX_FMT + call printf + + add $0x08, %esp + + + push prev_ebx + push $EBX_FMT + call printf + + add $0x08, %esp + + + push prev_esp + push $ESP_FMT + call printf + + add $0x08, %esp + + + push prev_ebp + push $EBP_FMT + call printf + + add $0x08, %esp + + + push prev_esi + push $ESI_FMT + call printf + + add $0x08, %esp + + + push prev_edi + push $EDI_FMT + call printf + + add $0x08, %esp + + push prev_eip + push $EIP_FMT + call printf + + add $0x08, %esp + + mov %ebp, %esp + pop %ebp + + ret + +.data + + EAX_FMT: .string "eax: 0x%x\n" + ECX_FMT: .string "ecx: 0x%x\n" + EDX_FMT: .string "edx: 0x%x\n" + EBX_FMT: .string "ebx: 0x%x\n" + ESP_FMT: .string "esp: 0x%x\n" + EBP_FMT: .string "ebp: 0x%x\n" + ESI_FMT: .string "esi: 0x%x\n" + EDI_FMT: .string "edi: 0x%x\n" + EIP_FMT: .string "eip: 0x%x\n" + +.bss + + prev_eax: .skip 4 + prev_ecx: .skip 4 + prev_edx: .skip 4 + prev_ebx: .skip 4 + prev_esp: .skip 4 + prev_ebp: .skip 4 + prev_esi: .skip 4 + prev_edi: .skip 4 + prev_eip: .skip 4 +