slide-resources
-
+**/.~lock*
workspace
dump*
-build/
\ No newline at end of file
+build/
+.vscode/settings.json
+++ /dev/null
-{
- "files.associations": {
- "string.h": "c",
- "stdint.h": "c"
- }
-}
\ No newline at end of file
call _kernel_init
subl $0x6, %esp
+
movl $_gdt, 2(%esp)
movw _gdt_limit, %ax
movw %ax, (%esp)
lgdt (%esp)
+
+ movl $_idt, 2(%esp)
+ movw _idt_limit, %ax
+ movw %ax, (%esp)
+ lidt (%esp)
+
addl $0x6, %esp
movw $0x10, %cx
#define GDT_ENTRY 5
uint64_t _gdt[GDT_ENTRY];
-uint16_t _gdt_limit = sizeof(_gdt);
+uint16_t _gdt_limit = sizeof(_gdt) - 1;
void _set_gdt_entry(uint32_t index, uint32_t base, uint32_t limit, uint32_t flags) {
_gdt[index] = SEG_BASE_H(base) | flags | SEG_LIM_H(limit) | SEG_BASE_M(base);
--- /dev/null
+#include <lunaix/arch/idt.h>
+#include <lunaix/interrupts/interrupts.h>
+#include <lunaix/interrupts/types.h>
+#include <stdint.h>
+
+#define IDT_ENTRY 32
+
+uint64_t _idt[IDT_ENTRY];
+uint16_t _idt_limit = sizeof(_idt) - 1;
+
+void _set_idt_entry(uint32_t vector, uint16_t seg_selector, void (*isr)(), uint8_t dpl) {
+ uintptr_t offset = (uintptr_t)isr;
+ _idt[vector] = (offset & 0xffff0000) | IDT_ATTR(dpl);
+ _idt[vector] <<= 32;
+ _idt[vector] |= (seg_selector << 16) | (offset & 0x0000ffff);
+}
+
+
+void
+_init_idt() {
+ _set_idt_entry(FAULT_DIVISION_ERROR, 0x08, _asm_isr0, 0);
+}
\ No newline at end of file
--- /dev/null
+.macro isr_template vector, no_error_code=1
+ .global _asm_isr\vector
+ .type _asm_isr\vector, @function
+ _asm_isr\vector:
+ .if \no_error_code
+ pushl $0x0
+ .endif
+ pushl $\vector
+ jmp interrupt_wrapper
+.endm
+
+.section .text
+ isr_template 0
+
+ interrupt_wrapper:
+
+ movl %esp, %eax
+ andl $0xfffffff0, %esp
+ subl $16, %esp
+ movl %eax, (%esp)
+
+ call interrupt_handler
+ pop %eax
+ movl %eax, %esp
+ addl $8, %esp
+
+ iret
\ No newline at end of file
--- /dev/null
+#define IDT_ATTR(dpl) ((0x70 << 5) | (dpl & 3) << 13 | 1 << 15)
+
+void
+_init_idt();
\ No newline at end of file
--- /dev/null
+#pragma pack(push, 1)
+typedef struct {
+ unsigned int vector;
+ unsigned int err_code;
+ unsigned int eip;
+ unsigned short cs;
+ unsigned int eflags;
+} isr_param;
+#pragma pack(pop)
+
+void
+_asm_isr0();
+
+void
+interrupt_handler(isr_param* param);
\ No newline at end of file
--- /dev/null
+// Ref: Intel Manuel Vol.3 Figure 6-1
+#define FAULT_DIVISION_ERROR 0x0
+#define FAULT_TRAP_DEBUG_EXCEPTION 0x1
+#define INT_NMI 0x2
+#define TRAP_BREAKPOINT 0x3
+#define TRAP_OVERFLOW 0x4
+#define FAULT_BOUND_EXCEED 0x5
+#define FAULT_INVALID_OPCODE 0x6
+#define FAULT_NO_MATH_PROCESSOR 0x7
+#define ABORT_DOUBLE_FAULT 0x8
+#define FAULT_RESERVED_0 0x9
+#define FAULT_INVALID_TSS 0xa
+#define FAULT_SEG_NOT_PRESENT 0xb
+#define FAULT_STACK_SEG_FAULT 0xc
+#define FAULT_GENERAL_PROTECTION 0xd
+#define FAULT_PAGE_FAULT 0xe
+#define FAULT_RESERVED_1 0xf
+#define FAULT_X87_FAULT 0x10
+#define FAULT_ALIGNMENT_CHECK 0x11
+#define ABORT_MACHINE_CHECK 0x12
+#define FAULT_SIMD_FP_EXCEPTION 0x13
+#define FAULT_VIRTUALIZATION_EXCEPTION 0x14
+#define FAULT_CONTROL_PROTECTION 0x15
\ No newline at end of file
--- /dev/null
+#include "interrupts.h"
+#include <lunaix/tty/tty.h>
+
+void isr0 (isr_param* param) {
+ tty_clear();
+ tty_put_str("!!PANIC!!");
+}
+
+void
+interrupt_handler(isr_param* param) {
+ switch (param->vector)
+ {
+ case 0:
+ isr0(param);
+ break;
+ }
+}
\ No newline at end of file
#include <lunaix/tty/tty.h>
#include <lunaix/arch/gdt.h>
+#include <lunaix/arch/idt.h>
void
_kernel_init()
{
// TODO
_init_gdt();
+ _init_idt();
}
void
for (uint32_t i = 0; i < TTY_WIDTH * TTY_HEIGHT; i++) {
*(buffer + i) = theme_color;
}
+ tty_x = 0;
+ tty_y = 0;
}
\ No newline at end of file
$(OBJECT_DIR)/%.S.o: %.S
@mkdir -p $(@D)
- $(CC) -c $< -o $@
+ $(CC) $(INCLUDES) -c $< -o $@
$(OBJECT_DIR)/%.c.o: %.c
@mkdir -p $(@D)
+++ /dev/null
-,lxsky,lunaixsky-PC,12.02.2022 15:08,file:///home/lxsky/.config/libreoffice/4;
\ No newline at end of file