From c2ef64149849fcae608b1c6010303eca86229d22 Mon Sep 17 00:00:00 2001 From: Miguel Date: Sun, 9 Sep 2018 13:21:47 +0200 Subject: cleaning logs, docs, interrupts --- kernel/gdt.c | 1 - kernel/interrupts.c | 7 ++----- kernel/interrupts.h | 30 +++++++++++++++++++++++++----- kernel/kernel.c | 15 ++++++++++++--- kernel/kernel.h | 14 ++++++++++++-- kernel/log.c | 23 +++-------------------- kernel/log.h | 5 +++-- kernel/smp.c | 6 +++--- 8 files changed, 60 insertions(+), 41 deletions(-) (limited to 'kernel') diff --git a/kernel/gdt.c b/kernel/gdt.c index 48bc284..f72f1ab 100644 --- a/kernel/gdt.c +++ b/kernel/gdt.c @@ -92,7 +92,6 @@ void encodeGdtEntry(uint8_t *target, GDT source) // And... Type /* - 0 1 dw 0xffff ;limit 2 3 dw 0x0 ;base 4 db 0x0 ;base diff --git a/kernel/interrupts.c b/kernel/interrupts.c index 69f5316..d0de5ed 100644 --- a/kernel/interrupts.c +++ b/kernel/interrupts.c @@ -42,7 +42,7 @@ static void int_install_ir(int irq, uint16_t flags, uint16_t sel, void *addr) } /** Installs the interrupt table */ -void int_install() +void interrupts_install() { idtd.size=sizeof(struct int_desc)*INT_MAX; uint32_t addr=(uint32_t)&idt[0]; @@ -100,7 +100,7 @@ uint32_t interrupt_handler(uint32_t esp, uint32_t irq) // if(apicID()!=0)apicIPI(0,170); } - //if(irq==255)kpanic("Unhandled Interrupt!"); + if(irq==255)kpanic("Spurious Interrupt!?"); if(irq!=0x81 && irq!=0x80)apicEOI(); return esp; @@ -261,7 +261,4 @@ void interrupts_init(uint16_t sel) // APIC Timer int_install_ir(0x8C, 0b11101110, 0x08,&int200); - - // install IVT - int_install(); } diff --git a/kernel/interrupts.h b/kernel/interrupts.h index aafd5d4..48e8c20 100644 --- a/kernel/interrupts.h +++ b/kernel/interrupts.h @@ -2,29 +2,49 @@ #define INTERRUPTS_H #include + /** * @file * * Interrupts * ========== + * + * Exceptions + * ---------- * 0x00-0x12 Exceptions + * + * Legacy PIC + * ---------- * 0x20-0x27 disabled pic * 0x28-0x36 disabled pic * - * Hardware - * -------- + * Hardware Interrupts + * ------------------- + * This interrupts are remapped by the IOAPIC + * * 0x0 PIT Timer -> 0x90 * 0x1 Keyboard -> 0x91 * 0xC Mouse -> 0x92 * + * Local Interrupts from LAPICs + * ---------------------- * 0x8C APIC Timer * - * Software - * ======== + * Software Interrupts + * ------------------- * 0x80 System Call * 0x81 IPI */ +#define INTERRUPT_PIT_TIMER 0x90 +#define INTERRUPT_KEYBOARD 0x91 +#define INTERRUPT_MOUSE 0x92 + +#define INTERRUPT_APIC_TIMER 0x8C +#define INTERRUPT_SYSCALL 0x80 +#define INTERRUPT_IPI 0x81 + void interrupts_init(uint16_t sel); -void int_install(); +void interrupts_install(); + #endif diff --git a/kernel/kernel.c b/kernel/kernel.c index 5a17567..724b1a0 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -30,15 +30,24 @@ void kernel_main(uint32_t eax,uint32_t ebx) { serial_init(); - klog("FOOL-OS ver-%s (%s)",GIT_REVISION,__DATE__); + + klog("======================================"); + klog("F00L- 0S / The Fool's Operating System"); + klog("(C) 2018 / Michal Idziorek (m.i@gmx.at)"); + klog("Compiled on: %s at %s",__DATE__,__TIME__); + klog("Version: git-commit: %s",GIT_REVISION); + klog("======================================"); + + klog("Communication Port (COM1) init ..."); //delayed info klog("Global Descriptor Table (GDT) init ..."); gdt_init(); klog("Interrupt Vector Table (IVT) init ..."); interrupts_init(0x08); + interrupts_install(); - klog("Remapping & Disabling PIC ..."); + klog("Remapping & Disabling Programmable Interrupt Controller (PIC) ..."); asm_pic_setup(); klog("Keyboard init ..."); @@ -90,7 +99,7 @@ void kernel_main(uint32_t eax,uint32_t ebx) klog("Programmable Interval Timer (PIT) init ..."); uint64_t unixtime=timer_init(); - klog("Unix Time = %u seconds)",unixtime); + klog("Unix Time = %u seconds",unixtime); klog("Unlock application processors ... "); asm_smp_unlock(); diff --git a/kernel/kernel.h b/kernel/kernel.h index c2befbd..3f74f4a 100644 --- a/kernel/kernel.h +++ b/kernel/kernel.h @@ -9,6 +9,7 @@ #define BIN_INIT "/bin/init" //#define FOOLOS_LOG_OFF +#define FOOLOS_LOG_COLOR true #define FIFO_MAX_RINGBUFFERS 20 #define MAX_FIFOS 20 @@ -27,7 +28,16 @@ #define SMP_MAX_PROC 32 // __FUNCTION__ ? -#define kpanic(...) {log(__FILE__,0," \033[41;37m--PANIC--\033[37;40m " __VA_ARGS__ ); while(1);} -#define klog(...) log(__FILE__ ":" S2(__LINE__), 10, __VA_ARGS__) +#ifndef FOOLOS_LOG_OFF +#define kpanic(...) {log(FOOLOS_LOG_COLOR,__FILE__,0," \033[41;37m [KERNEL PANIC] \033[37;40m " __VA_ARGS__ ); while(1);} +#define klog(...) log(FOOLOS_LOG_COLOR,__FILE__ ":" S2(__LINE__), 10, __VA_ARGS__) +#define fixme(...) log(FOOLOS_LOG_COLOR,__FILE__ ":" S2(__LINE__), 10, "\033[44;37m [FIXME] \033[37;40m " __VA_ARGS__) +#endif + +#ifdef FOOLOS_LOG_OFF +#define kpanic(...) {while(1);} +#define klog(...) {} +#define fixme(...) {} +#endif #endif diff --git a/kernel/log.c b/kernel/log.c index b0eeab5..952c271 100644 --- a/kernel/log.c +++ b/kernel/log.c @@ -24,7 +24,7 @@ static void log_string(char *str) } } -void log(char *module_name, int prio, char *format_string, ...) +void log(bool color,char *module_name, int prio, char *format_string, ...) { #ifdef FOOLOS_LOG_OFF return; @@ -45,27 +45,10 @@ void log(char *module_name, int prio, char *format_string, ...) tfp_vsprintf(buf_info,format_string,va); va_end(va); - tfp_sprintf(buf_log,"\033[36;40m%s\033[31;40m %s:\033[37;40m %s\n",buf_time,module_name,buf_info); + if(color) tfp_sprintf(buf_log,"\033[36;40m%s\033[31;40m %s:\033[37;40m %s\n",buf_time,module_name,buf_info); + else tfp_sprintf(buf_log,"%s %s: %s\n",buf_time,module_name,buf_info); spinlock_spin(SPINLOCK_LOG); log_string(buf_log); spinlock_release(SPINLOCK_LOG); } - -/* -void panic(char *module_name, char *format_string) -{ - char buf_log[256]; - tfp_sprintf(buf_log,"\033[41;37m\n !! KERNEL PANIC !! %s: %s\n\n\033[37;40m",module_name,message); - - //PANIC DIRECTLY TO STDOUT// - syscall_write(1,buf_log,strlen(buf_log)); - log_string(buf_log); - - while(1) - { - asm volatile("cli"); - asm volatile("hlt"); - } -} -*/ diff --git a/kernel/log.h b/kernel/log.h index 38f1219..62fe6ef 100644 --- a/kernel/log.h +++ b/kernel/log.h @@ -1,13 +1,14 @@ #ifndef FOOLOS_LOG_H #define FOOLOS_LOG_H +#include + #define FOOLOS_LOG_ERROR 5 #define FOOLOS_LOG_WARNING 4 #define FOOLOS_LOG_INFO 3 #define FOOLOS_LOG_DEBUG 2 #define FOOLOS_LOG_FINE 1 -void log(char *module_name, int prio, char *format_string, ...); -void panic(char *module_name, char *format_string); +void log(bool color,char *module_name, int prio, char *format_string, ...); #endif diff --git a/kernel/smp.c b/kernel/smp.c index c965b2e..08fe71b 100644 --- a/kernel/smp.c +++ b/kernel/smp.c @@ -153,11 +153,11 @@ void kernel_ap() klog("smp local apic id: 0x%08X",apicID()); apicEnable(); - int_install(); + interrupts_install(); gdt_init(); writeAPIC(APIC_TMRDIV, 0x3); - writeAPIC(APIC_LVT_TMR, 200 | TMR_PERIODIC); + writeAPIC(APIC_LVT_TMR,INTERRUPT_APIC_TIMER | TMR_PERIODIC); writeAPIC(APIC_TMRINITCNT, countdown); x86_sti(); @@ -218,7 +218,7 @@ void smp_start_aps(smp_processors *pros) // setup apic timer countdown=speed/16; // tick once a second writeAPIC(APIC_TMRDIV, 0x3); // divisor 16 - writeAPIC(APIC_LVT_TMR, 200 | TMR_PERIODIC); // on interrupt 200 + writeAPIC(APIC_LVT_TMR, INTERRUPT_APIC_TIMER | TMR_PERIODIC); // on interrupt 200 writeAPIC(APIC_TMRINITCNT, countdown); // setup IO APIC -- cgit v1.2.3