summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiguel <m.i@gmx.at>2018-09-09 13:21:47 +0200
committerMiguel <m.i@gmx.at>2018-09-09 13:21:47 +0200
commitc2ef64149849fcae608b1c6010303eca86229d22 (patch)
tree30d69313b6975a7c1bfc80859117124a6a5a10e7
parente85a68e1536a0f6505300e1cb79f06b9743b00f7 (diff)
cleaning logs, docs, interrupts
-rw-r--r--asm/asm_gdt.h9
-rw-r--r--asm/asm_gdt.s4
-rw-r--r--asm/asm_int.h8
-rw-r--r--asm/asm_mp.asm2
-rw-r--r--asm/asm_mp.h10
-rw-r--r--asm/asm_pic.h1
-rw-r--r--asm/asm_start.h9
-rw-r--r--asm/asm_usermode.h1
-rw-r--r--kernel/gdt.c1
-rw-r--r--kernel/interrupts.c7
-rw-r--r--kernel/interrupts.h30
-rw-r--r--kernel/kernel.c15
-rw-r--r--kernel/kernel.h14
-rw-r--r--kernel/log.c23
-rw-r--r--kernel/log.h5
-rw-r--r--kernel/smp.c6
16 files changed, 98 insertions, 47 deletions
diff --git a/asm/asm_gdt.h b/asm/asm_gdt.h
index 128dbf3..c2c35a0 100644
--- a/asm/asm_gdt.h
+++ b/asm/asm_gdt.h
@@ -3,5 +3,12 @@
* http://wiki.osdev.org/GDT_Tutorial
*/
-/** call as asm_setup_gdt(GDT,sizeof(GDT)) */
+/**
+ * Set the Global Descritpor Table from data at _addr_.
+ *
+ * call as asm_setup_gdt(GDT,sizeof(GDT))
+ *
+ * This will jump to 0x8 segment and set 0x10 data selector
+ * also refereshing the tss entry.
+ * */
void asm_setup_gdt(uint32_t addr, uint32_t size);
diff --git a/asm/asm_gdt.s b/asm/asm_gdt.s
index 0e163fc..a35854d 100644
--- a/asm/asm_gdt.s
+++ b/asm/asm_gdt.s
@@ -1,5 +1,9 @@
.global asm_setup_gdt
+gdt_descriptor:
+.int 0
+.int 0
+
asm_setup_gdt:
// re-fill gdt_descriptor with new GDT location and size
diff --git a/asm/asm_int.h b/asm/asm_int.h
index 465b08b..5f32777 100644
--- a/asm/asm_int.h
+++ b/asm/asm_int.h
@@ -1,3 +1,11 @@
+/**
+ * @file
+ *
+ * interrrupt handlers:
+ * * excX() call handle_exception
+ * * excX() call hadnle_interrupt
+ */
+
void int0();
void int1();
void int2();
diff --git a/asm/asm_mp.asm b/asm/asm_mp.asm
index 165dc97..18b9d7e 100644
--- a/asm/asm_mp.asm
+++ b/asm/asm_mp.asm
@@ -1,9 +1,7 @@
global smp_start
extern smp_main
-global gdt_descriptor
global asm_smp_unlock
-
; master boot record for application processors
smp_start:
[bits 16]
diff --git a/asm/asm_mp.h b/asm/asm_mp.h
index f207c12..f36f4f7 100644
--- a/asm/asm_mp.h
+++ b/asm/asm_mp.h
@@ -1,3 +1,11 @@
-/** Application processors */
+/**
+ * @file
+ * Multiprocessing
+ * ===============
+ *
+ * smp_start should be entered by the application processors and calls
+ * the C-function: smp_main() in turn.
+ * */
+
void smp_start();
void asm_smp_unlock();
diff --git a/asm/asm_pic.h b/asm/asm_pic.h
index 0daea2a..7f25515 100644
--- a/asm/asm_pic.h
+++ b/asm/asm_pic.h
@@ -1 +1,2 @@
+/** remap the pic and disable it */
void asm_pic_setup();
diff --git a/asm/asm_start.h b/asm/asm_start.h
index 4b2db16..3315d50 100644
--- a/asm/asm_start.h
+++ b/asm/asm_start.h
@@ -1,13 +1,18 @@
/**
* @file
+ *
+ * START
+ * =====
+ *
* Defines the following sections/functions, some are linked at
* specific addresses in the final ELF kernel binary.
* This is specified in the _linker.ld_ file.
*
- * TODO: THIS IS NOT TRUE ANYMORE (SINCE IT KILLED THE MEMORY IN BETWEEN PROABBLY)
- * * 0x007000 .smp - entry point for application processors (16bit code)
+ * * 0x007000 .smp - entry point for application processors (16bit code) _start_smp() calls finally smp_main()
* * 0x100000 .multiboot - the multiboot header
*
+ * __TODO: Does this not kill the memory in-between?__
+ *
* * .text
* * .bootstrap_stack
* * _start() - main entry point for booting cpu, calls kernel_main().
diff --git a/asm/asm_usermode.h b/asm/asm_usermode.h
index 16597f2..295a64d 100644
--- a/asm/asm_usermode.h
+++ b/asm/asm_usermode.h
@@ -1,5 +1,6 @@
/**
* @file
+ *
* Switch to User Mode and iret to function given by pointer
* provide the address of a void func() that will be called without
* any params via iret.
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 <stdint.h>
+
/**
* @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 <stdbool.h>
+
#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