diff --git a/kernel/Makefile b/kernel/Makefile index eaf4ce7..4195708 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -17,6 +17,10 @@ SRCS = kernel.asm \ .PHONY: all all: $(KERNEL) +PHONY: const.inc +const.inc: const.inc.in + $(TOOLSDIR)/version.sh $< $@ + $(KERNEL): $(SRCS) $(AS) kernel.asm $@ diff --git a/kernel/const.inc b/kernel/const.inc.in similarity index 62% rename from kernel/const.inc rename to kernel/const.inc.in index 299beb3..8aa4da9 100644 --- a/kernel/const.inc +++ b/kernel/const.inc.in @@ -7,9 +7,11 @@ PSIZE = 0x1000 STPDBOOT_MAGIC = 0x53545044 ; --------- VERSION ------------- -VERSION_MAJOR = 1 -VERSION_MINOR = 0 -VERSION_COMMIT = "@COMMIT@" +VERSION_MAJOR = @MAJOR@ +VERSION_MINOR = @MINOR@ +VERSION_COMMIT equ "@COMMIT@" +VERSION_FULL equ "@FULLVERSION@" +BUILD_DATE equ "@DATE@" ; ------------- OTHER ----------- CR = 0x0D diff --git a/kernel/irq.inc b/kernel/irq.inc index 03c007e..e69de29 100644 --- a/kernel/irq.inc +++ b/kernel/irq.inc @@ -1,3 +0,0 @@ -irq_timer: - iret - diff --git a/kernel/isr.inc b/kernel/isr.inc index ddf3f08..9874fee 100644 --- a/kernel/isr.inc +++ b/kernel/isr.inc @@ -1,9 +1,14 @@ macro ISR [name,error] { forward dd isr_#name +forward + local szIntName + szIntName db `name#, 0 forward isr_#name#: cli + mov esi, szIntName + call klog if error eq 0 push 0 end if @@ -25,6 +30,17 @@ idt_setup: inc ecx cmp ecx, 32 jb @b +@@: + mov eax, irq_dummy + 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 + inc ecx + cmp ecx, 0x30 + jb @b mov ecx, 0x42 mov eax, isr_syscall @@ -49,6 +65,9 @@ aInterruptGate: .end: +irq_dummy: + iret + isr_common: pusha @@ -61,6 +80,9 @@ isr_common: mov fs, ax mov gs, ax + mov eax, [esp+IntFrame.intno] + push eax + mov esi, szMsgInterrupt call klog @@ -110,4 +132,4 @@ ISR \ security_exception, 0, \ reserved31, 0 -szMsgInterrupt db "Interrupt", 0 +szMsgInterrupt db "Interrupt (int: %x)", 0 diff --git a/kernel/kernel.asm b/kernel/kernel.asm index 30b08e4..c487854 100644 --- a/kernel/kernel.asm +++ b/kernel/kernel.asm @@ -63,7 +63,7 @@ kmain: call idt_setup - int 0x42 + ;int 0x42 .halt: hlt @@ -84,7 +84,7 @@ kmain: include 'pic.inc' -szMsgKernelAlive db "Kernel is alive", 0 +szMsgKernelAlive db "Kernel (", VERSION_FULL , ") is alive", 0 szErrorBootProtocol db "Error: wrong magic number", 0 boot_structure BootInfo diff --git a/kernel/pic.inc b/kernel/pic.inc index fcaae5d..8998321 100644 --- a/kernel/pic.inc +++ b/kernel/pic.inc @@ -50,6 +50,20 @@ pic_init: ret + ;; Function: pic_eoi + ;; + ;; In: + ;; EAX - irq +pic_eoi: + cmp eax, 8 + jb @f + mov al, PIC_EOI + out PIC2_COMMAND, al +@@: + mov al, PIC_EOI + out PIC1_COMMAND, al + ret + pic_disable: mov al, 0xFF out PIC1_DATA, al diff --git a/kernel/sys/cpu.inc b/kernel/sys/cpu.inc index e11de06..922bbf2 100644 --- a/kernel/sys/cpu.inc +++ b/kernel/sys/cpu.inc @@ -133,7 +133,7 @@ struc IDTGate { ;; > +--------------- |----------------+-----------------|-----------------+ -struc intframe { +struc IntFrame { ;; registers .edi dd ? .esi dd ? @@ -161,3 +161,7 @@ struc intframe { .useresp dd ? .ss dd ? } +virtual at 0 + IntFrame IntFrame + sizeof.IntFrame: +end virtual diff --git a/kernel/syscall.inc b/kernel/syscall.inc index d4ad6a0..c21550b 100644 --- a/kernel/syscall.inc +++ b/kernel/syscall.inc @@ -1,5 +1,7 @@ -SYSCALL_EXIT = 0x01 -SYSCALL_FORK = 0x02 +SYSCALL_EXIT = 0x01 +SYSCALL_FORK = 0x02 +SYSCALL_READ = 0x03 +SYSCALL_WRITE = 0x04 isr_syscall: push eax