diff --git a/kernel/dev/vga_console.inc b/kernel/dev/vga_console.inc index 28b0992..bba8992 100644 --- a/kernel/dev/vga_console.inc +++ b/kernel/dev/vga_console.inc @@ -16,3 +16,7 @@ vga_console_clear: rep stosb ret +vga_console_putc: + + ret + diff --git a/kernel/fs/fat.inc b/kernel/fs/fat.inc new file mode 100644 index 0000000..265b401 --- /dev/null +++ b/kernel/fs/fat.inc @@ -0,0 +1 @@ + ;; File: fat.inc diff --git a/kernel/fs/stpdfs.inc b/kernel/fs/stpdfs.inc new file mode 100644 index 0000000..23fcd11 --- /dev/null +++ b/kernel/fs/stpdfs.inc @@ -0,0 +1,5 @@ + ;; File: stpdfs.inc + +STPDFS_SB_MAGIC = 0x44505453 +STPDFS_SB_REV = 1 + diff --git a/kernel/gdt.inc b/kernel/gdt.inc index c798514..b68ad50 100644 --- a/kernel/gdt.inc +++ b/kernel/gdt.inc @@ -21,9 +21,9 @@ gdt: db 0x00, 0xF2, 0xCF, 0x00 ; Tss -;.tss: -; dw ? -; dd ? +.tss: + dw ? + dd ? .end: diff --git a/kernel/irq.inc b/kernel/irq.inc new file mode 100644 index 0000000..03c007e --- /dev/null +++ b/kernel/irq.inc @@ -0,0 +1,3 @@ +irq_timer: + iret + diff --git a/kernel/isr.inc b/kernel/isr.inc index 3fb21e6..ddf3f08 100644 --- a/kernel/isr.inc +++ b/kernel/isr.inc @@ -26,6 +26,15 @@ idt_setup: cmp ecx, 32 jb @b + mov ecx, 0x42 + mov eax, isr_syscall + mov [aInterruptGate + (ecx * 8)], ax + mov [aInterruptGate + (ecx * 8) + 2], word 0x08 + + mov [aInterruptGate + (ecx * 8) + 5], word 0x8E + shr eax, 16 + mov [aInterruptGate + (ecx * 8) + 6], ax + lidt [pIDT] sti ret diff --git a/kernel/kernel.asm b/kernel/kernel.asm index f48549d..30b08e4 100644 --- a/kernel/kernel.asm +++ b/kernel/kernel.asm @@ -2,6 +2,8 @@ format binary include 'const.inc' + include 'sys/bootinfo.inc' + include 'sys/cpu.inc' org KBASE use32 @@ -52,15 +54,16 @@ kmain: add ebx, KERNEL_VIRT_BASE call pmm_free_range + call pic_init + ; load kernel gdt lgdt [pGDT] ; I don't think i need to reload segment cuz their value are already correct - xchg bx, bx - call pic_disable call idt_setup + int 0x42 .halt: hlt @@ -71,20 +74,23 @@ kmain: call klog jmp .halt - include 'sys/bootinfo.inc' include 'klog.inc' include 'dev/vga_console.inc' include 'mm/mm.inc' include 'lock.inc' include 'gdt.inc' + include 'syscall.inc' include 'isr.inc' include 'pic.inc' + szMsgKernelAlive db "Kernel is alive", 0 szErrorBootProtocol db "Error: wrong magic number", 0 boot_structure BootInfo +kTSS TSS + align 4096 stack_bottom: rb 0x4000 diff --git a/kernel/pic.inc b/kernel/pic.inc index 2e75469..fcaae5d 100644 --- a/kernel/pic.inc +++ b/kernel/pic.inc @@ -6,10 +6,47 @@ PIC1_DATA = 0x21 PIC2_COMMAND = 0xA0 PIC2_DATA = 0xA1 +PIC_ICW1 = 0x10 +PIC_ICW1_IC4 = 0x01 +PIC_ICW1_SNGL = 0x02 +PIC_ICW1_ADI = 0x04 +PIC_ICW1_LTIM = 0x08 + +PIC_ICW4_8086 = 0x01 +PIC_ICW4_AEOI = 0x02 +PIC_ICW4_MSTR = 0x04 +PIC_ICW4_BUF = 0x08 +PIC_ICW4_SFNM = 0x10 + PIC_EOI = 0x20 pic_init: + ; ICW 1 + mov al, PIC_ICW1 or PIC_ICW1_IC4 + out PIC1_COMMAND, al + out PIC2_COMMAND, al + + ; ICW 2 + mov al, 0x20 + out PIC1_DATA, al + mov al, 0x28 + out PIC2_DATA, al + + ; ICW 3 + mov al, 0x4 + out PIC1_DATA, al + mov al, 0x2 + out PIC2_DATA, al + + ; ICW 4 + mov al, PIC_ICW4_8086 + out PIC1_DATA, al + out PIC2_DATA, al + + xor al, al + out PIC1_DATA, al + out PIC2_DATA, al ret diff --git a/kernel/sys/cpu.inc b/kernel/sys/cpu.inc index cd390b2..e11de06 100644 --- a/kernel/sys/cpu.inc +++ b/kernel/sys/cpu.inc @@ -88,21 +88,24 @@ struc TSS { .iomap dw ? } - ;; Structure: idt_gate +struc GDTGate { + +} + + ;; Structure: IDTGate ;; .offset_low - TODO ;; .selector - TODO ;; .zero - TODO ;; .attributes - TODO ;; .offset_high - TODO ;; -struc idt_gate - .offset_low: resw 1 - .selector: resw 1 - .zero: resb 1 - .attributes: resb 1 - .offset_high: resw 1 -endstruc -defn idt_gate +struc IDTGate { + .offset_low dw ? + .selector dw ? + .zero db 0 + .attributes db ? + .offset_high dw ? +} ;; About: Gates ;; - Task Gate @@ -130,31 +133,31 @@ defn idt_gate ;; > +--------------- |----------------+-----------------|-----------------+ -struc intframe +struc intframe { ;; registers - .edi: resd 1 - .esi: resd 1 - .ebp: resd 1 - .esp: resd 1 - .ebx: resd 1 - .edx: resd 1 - .ecx: resd 1 - .eax: resd 1 + .edi dd ? + .esi dd ? + .ebp dd ? + .esp dd ? + .ebx dd ? + .edx dd ? + .ecx dd ? + .eax dd ? ;; - .gs: resd 1 - .fs: resd 1 - .es: resd 1 - .ds: resd 1 - .intno: resd 1 + .gs dd ? + .fs dd ? + .es dd ? + .ds dd ? + .intno dd ? ;; by x86 hardware - .err: resd 1 - .eip: resd 1 - .cs: resd 1 - .eflags: resd 1 + .err dd ? + .eip dd ? + .cs dd ? + .eflags dd ? ;; crossring - .useresp: resd 1 - .ss: resd 1 -endstruc + .useresp dd ? + .ss dd ? +} diff --git a/kernel/syscall.inc b/kernel/syscall.inc new file mode 100644 index 0000000..d4ad6a0 --- /dev/null +++ b/kernel/syscall.inc @@ -0,0 +1,10 @@ +SYSCALL_EXIT = 0x01 +SYSCALL_FORK = 0x02 + +isr_syscall: + push eax + mov esi, szMsgSyscall + call klog + iret + +szMsgSyscall db "syscall %x", 0