diff --git a/include/extras/buf.h b/include/extras/buf.h index 2920ac6..2d17d93 100644 --- a/include/extras/buf.h +++ b/include/extras/buf.h @@ -144,6 +144,8 @@ error_t BPutOnBuf(Buffer_t *, uchar); error_t BPrintOnBuf(Buffer_t *, const char *fmt, ...); error_t BPrintOnBufV(Buffer_t *, const char *fmt, va_list); +// Internal, non-locking functions; don't use unless you +// have a good reason why error_t bputc(Buffer_t *buf, uchar ch); error_t bprintf(Buffer_t *buf, const char *fmt, ...); error_t vbprintf(Buffer_t *buf, const char *fmt, va_list ap); diff --git a/include/kalbase.h b/include/kalbase.h index b91f710..504bd6d 100644 --- a/include/kalbase.h +++ b/include/kalbase.h @@ -33,12 +33,6 @@ #endif #endif -#if !defined(_OSK_SOURCE) && !defined(_KALEID_UNMASKED) -#ifndef _KALBASE_MASKS_H -#include -#endif -#endif - //------------------------------------------// #ifndef _KALBASE_BDEFS_H diff --git a/include/kernel/base.h b/include/kernel/base.h index 4778a54..b15326d 100644 --- a/include/kernel/base.h +++ b/include/kernel/base.h @@ -33,20 +33,32 @@ #ifndef _KALKERN_BASE_H #define _KALKERN_BASE_H -//------------------------------------------// +//----------------------------------------------------------------------------// -typedef struct Lock_t Lock_t; -typedef struct Buffer_t Buffer_t; -typedef struct Thread_t Thread_t; -typedef struct Process_t Process_t; -typedef struct BootInfo_t BootInfo_t; -typedef struct ListHead_t ListHead_t; -typedef struct ListNode_t ListNode_t; -typedef struct Processor_t Processor_t; -typedef struct ISRFrame_t ISRFrame_t; -typedef enum ProcState_t ProcState_t; +typedef struct Lock_t Lock_t; +typedef struct Buffer_t Buffer_t; +typedef struct ListHead_t ListHead_t; +typedef struct ListNode_t ListNode_t; -//------------------------------------------// +typedef struct Thread_t Thread_t; +typedef struct Process_t Process_t; +typedef struct BootInfo_t BootInfo_t; +typedef struct Processor_t Processor_t; +typedef struct ISRFrame_t ISRFrame_t; +typedef enum ProcState_t ProcState_t; + +typedef struct IdtDescriptor_t IdtDescriptor_t; +typedef struct IdtEntry_t IdtEntry_t; +typedef struct IdtPtr_t IdtPtr_t; +typedef struct IRQList_t IRQList_t; +typedef struct ISRFrame_t ISRFrame_t; + +typedef struct MemoryMap_t MemoryMap_t; +typedef struct MapEntry_t MapEntry_t; +typedef struct GdtEntry_t GdtEntry_t; +typedef struct GdtPtr_t GdtPtr_t; + +//----------------------------------------------------------------------------// // // Holds all CPU-local variables @@ -105,7 +117,7 @@ struct ISRFrame_t { } __attribute__((__packed__)); -//------------------------------------------// +//----------------------------------------------------------------------------// #ifndef NCPUS #define NCPUS 1 @@ -118,7 +130,7 @@ extern int KeCPUCount; extern volatile Processor_t *KeCurCPU; extern Processor_t _KeCPUTable[NCPUS]; -//------------------------------------------// +//----------------------------------------------------------------------------// #define DEC_PER_CPU(pref, name, field, type) \ static inline type pref##Get##name() { return KeGetCurCPU()->field; } \ @@ -131,7 +143,7 @@ extern Processor_t _KeCPUTable[NCPUS]; __sync_synchronize(); \ } while(0) -//------------------------------------------// +//----------------------------------------------------------------------------// error_t KernLog(const char *, ...); @@ -141,23 +153,24 @@ void DebugLog(const char *, ...); #define DebugLog(fmt, ...) ((void)0) #endif -//------------------------------------------// +//----------------------------------------------------------------------------// extern volatile bool KeIsPanicking; noreturn void KeStartPanic(const char *, ...); -//------------------------------------------// +//----------------------------------------------------------------------------// #define XBUG(c) do { \ volatile ushort *_vga \ =(volatile ushort*)0xB8000; \ - while(_vga<(volatile ushort*)(0xB8000+(80*25*2)) ) \ + while(_vga<(volatile ushort*)(0xB8000+(80*25*2))) \ *_vga++=(c|(0xf<<8)); \ asm volatile("cli\nhlt"); \ }while(0) #define BUG() XBUG('B') #define BUGON(x) if(x)BUG() -//------------------------------------------// + +//----------------------------------------------------------------------------// #endif diff --git a/include/kernel/boot.h b/include/kernel/boot.h index 6be8bef..8609e3d 100644 --- a/include/kernel/boot.h +++ b/include/kernel/boot.h @@ -29,7 +29,7 @@ #ifndef _KALKERN_BOOT_H #define _KALKERN_BOOT_H -//------------------------------------------// +//----------------------------------------------------------------------------// #define FB_EGA_TEXT 2 #define FB_INDEXED 0 @@ -102,7 +102,7 @@ struct BootInfo_t } firmware; }; -//------------------------------------------// +//----------------------------------------------------------------------------// extern volatile BootInfo_t BtBootTab; @@ -112,6 +112,6 @@ extern volatile BootInfo_t BtBootTab; #define BtVideoInfo (BtBootTab.video) #define BtFirmwareInfo (BtBootTab.firmware) -//------------------------------------------// +//----------------------------------------------------------------------------// #endif diff --git a/include/kernel/heap.h b/include/kernel/heap.h index 9ff7028..5b389d6 100644 --- a/include/kernel/heap.h +++ b/include/kernel/heap.h @@ -29,7 +29,7 @@ #ifndef _KALKERN_HEAP_H #define _KALKERN_HEAP_H -//------------------------------------------// +//----------------------------------------------------------------------------// // Address of the heap void *_heap_start; @@ -46,7 +46,7 @@ error_t MmSetMaxHeapSize(size_t); error_t MmGrowHeap(size_t); error_t MmShrinkHeap(size_t); -//------------------------------------------// +//----------------------------------------------------------------------------// #endif diff --git a/include/kernel/idt.h b/include/kernel/idt.h index d59e31c..e3c1202 100644 --- a/include/kernel/idt.h +++ b/include/kernel/idt.h @@ -1,3 +1,27 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Desc: Interrupt related functions // +// // +// // +// Copyright © 2018-2019 The OS/K Team // +// // +// This file is part of OS/K. // +// // +// OS/K is free software: you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation, either version 3 of the License, or // +// any later version. // +// // +// OS/K is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY//without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with OS/K. If not, see . // +//----------------------------------------------------------------------------// + #ifndef _KALKERN_BASE_H #include #endif @@ -5,22 +29,13 @@ #ifndef _KALKERN_IDT_H #define _KALKERN_IDT_H -typedef struct IdtDescriptor_t IdtDescriptor_t; -typedef struct IdtEntry_t IdtEntry_t; -typedef struct IdtPtr_t IdtPtr_t; -typedef struct IRQList_t IRQList_t; -typedef struct ISRFrame_t ISRFrame_t; +//----------------------------------------------------------------------------// -// -------------------------------------------------------------------------- // - -#define interrupt(n) asm volatile ("int %0" : : "N" (n) : "cc", "memory") - -// -------------------------------------------------------------------------- // - -struct IdtDescriptor_t { +struct IdtDescriptor_t +{ ushort limit; ulong base; -} __attribute__((packed)) ; +} __attribute__((packed)); struct IdtEntry_t { @@ -55,111 +70,32 @@ typedef struct } __attribute__((__packed__)) cpu_state_t; -static char *IsrExceptions[32] = { - "Divide Error Fault", - "Debug Exception Trap", - "Non-maskable Interrupt", - "Breakpoint Trap", - "Overflow Trap", - "Bound Range Exceeded Fault", - "Invalid Opcode Fault", - "Device Not Available or No Math Coprocessor Fault", - "Double Fault Abort", - "Coprocessor Segment Overrun Fault (Legacy)", - "Invalid TSS Fault", - "Segment Not Present Fault", - "Stack Segment fault", - "General Protection Fault", - "Page Fault", - "Intel Reserved", - "x87 FPU Floating Point or Math Fault", - "Alignment Check Fault", - "Machine Check Abort", - "SIMD Floating Point Fault", - "Virtualization Exception Fault", - "Intel Reserved", - "Intel Reserved", - "Intel Reserved", - "Intel Reserved", - "Intel Reserved", - "Intel Reserved", - "Intel Reserved", - "Intel Reserved", - "Intel Reserved", - "Security Exception", - "Intel Reserved" -}; +extern char *IsrExceptions[32]; -// -------------------------------------------------------------------------- // +//----------------------------------------------------------------------------// -void IdtRegisterIrq(void (*isr)(ISRFrame_t *regs), uchar irq, uchar flags); +void IdtInit(void); void IdtSetup(void); -void IdtSetGate(uchar rank, ulong base, ushort selector, uchar flags); -void IdtExceptionHandler(ISRFrame_t *regs); -static void EnablePIC(void); -void SendEOItoPIC(uchar isr); -extern void IdtInit(); -extern void isr0(); -extern void isr1(); -extern void isr2(); -extern void isr3(); -extern void isr4(); -extern void isr5(); -extern void isr6(); -extern void isr7(); -extern void isr8(); -extern void isr9(); -extern void isr10(); -extern void isr11(); -extern void isr12(); -extern void isr13(); -extern void isr14(); -extern void isr15(); -extern void isr16(); -extern void isr17(); -extern void isr18(); -extern void isr19(); -extern void isr20(); -extern void isr21(); -extern void isr22(); -extern void isr23(); -extern void isr24(); -extern void isr25(); -extern void isr26(); -extern void isr27(); -extern void isr28(); -extern void isr29(); -extern void isr30(); -extern void isr31(); -extern void isr32(); -extern void isr33(); -extern void isr34(); -extern void isr35(); -extern void isr36(); -extern void isr37(); -extern void isr38(); -extern void isr39(); -extern void isr40(); -extern void isr41(); -extern void isr42(); -extern void isr43(); -extern void isr44(); -extern void isr45(); -extern void isr46(); -extern void isr47(); -extern void isr48(); -extern void isr49(); -extern void isr50(); -extern void isr51(); -extern void isr52(); -extern void isr53(); -extern void isr54(); -extern void isr55(); -extern void isr56(); -extern void isr57(); -extern void isr58(); -extern void isr59(); -extern void isr60(); +void IoSendEOItoPIC(uchar isr); +void IdtExceptionHandler(ISRFrame_t *regs); +void IdtSetGate(uchar rank, ulong base, ushort selector, uchar flags); +void IdtRegisterIrq(void (*isr)(ISRFrame_t *regs), uchar irq, uchar flags); + +//----------------------------------------------------------------------------// + +#define _isr0(a,b,c,d,e) \ + void isr##a(); void isr##b(); void isr##c(); void isr##d(); void isr##e() + +#define _isr1(a,b,c,d,e,f,g,h,i,j) _isr0(a,b,c,d,e); _isr0(f,g,h,i,j) + +_isr1(0,1,2,3,4,5,6,7,8,9); _isr1(10,11,12,13,14,15,16,17,18,19); +_isr1(20,21,22,23,24,25,26,27,28,29); _isr1(30,31,32,33,34,35,36,37,38,39); +_isr1(40,41,42,43,44,45,46,47,48,49); _isr1(50,51,52,53,54,55,56,57,58,59); + +#undef _isr1 +#undef _isr0 + +//----------------------------------------------------------------------------// #endif diff --git a/include/kernel/mm.h b/include/kernel/mm.h index 0acf551..ec1ce6a 100644 --- a/include/kernel/mm.h +++ b/include/kernel/mm.h @@ -40,11 +40,6 @@ #define BADRAM_ZONE 5 // Invalid zone because material problem... #define MAX_ENTRIES 2048 // Max number of memory map entries -typedef struct MemoryMap_t MemoryMap_t; -typedef struct MapEntry_t MapEntry_t; -typedef struct GdtEntry_t GdtEntry_t; -typedef struct GdtPtr_t GdtPtr_t; - //----------------------------------------------------------------------------// // The entry structure of the map diff --git a/include/kernel/proc.h b/include/kernel/proc.h index a8930e9..11fbfde 100644 --- a/include/kernel/proc.h +++ b/include/kernel/proc.h @@ -29,7 +29,7 @@ #ifndef _KALKERN_PROC_H #define _KALKERN_PROC_H -//------------------------------------------// +//----------------------------------------------------------------------------// // States for a process enum ProcState_t @@ -72,7 +72,7 @@ struct Process_t ListNode_t *schedNode; }; -//------------------------------------------// +//----------------------------------------------------------------------------// #define PsCurProc (KeCurCPU->process) #define PsCurThread (KeCurCPU->thread) @@ -80,7 +80,7 @@ struct Process_t //DEC_PER_CPU(Ps, CurProc, process, Process_t *); //DEC_PER_CPU(Ps, CurThread, thread, Thread_t *); -//------------------------------------------// +//----------------------------------------------------------------------------// #endif diff --git a/include/kernel/sched.h b/include/kernel/sched.h index 9c3ae35..ad63802 100644 --- a/include/kernel/sched.h +++ b/include/kernel/sched.h @@ -29,7 +29,7 @@ #ifndef _KALKERN_SCHED_H #define _KALKERN_SCHED_H -//------------------------------------------// +//----------------------------------------------------------------------------// // // Value of the preemption count indicating that preemption is activated @@ -55,7 +55,7 @@ enum // Names of the priority classes extern const char *PsPrioClassesNames[]; -//------------------------------------------// +//----------------------------------------------------------------------------// // // Re-scheduling and preemption @@ -66,7 +66,7 @@ extern const char *PsPrioClassesNames[]; #define PsEnablePreemption() do { assert(KeCurCPU->preemptCount > 0); \ --KeCurCPU->preemptCount; } while(0) -//------------------------------------------// +//----------------------------------------------------------------------------// void PsInitSched(void); void PsFiniSched(void); @@ -74,7 +74,7 @@ void PsFiniSched(void); void PsSchedThisProc(Process_t *); void PsSchedOnTick(void); -//------------------------------------------// +//----------------------------------------------------------------------------// #endif diff --git a/kaleid/kernel/cpu/idt.c b/kaleid/kernel/cpu/idt.c index 5141104..c500df7 100644 --- a/kaleid/kernel/cpu/idt.c +++ b/kaleid/kernel/cpu/idt.c @@ -33,6 +33,44 @@ IdtPtr_t idtPtr; IRQList_t irqList = { 0 }; +char *IsrExceptions[32] = { + "Divide Error Fault", + "Debug Exception Trap", + "Non-maskable Interrupt", + "Breakpoint Trap", + "Overflow Trap", + "Bound Range Exceeded Fault", + "Invalid Opcode Fault", + "Device Not Available or No Math Coprocessor Fault", + "Double Fault Abort", + "Coprocessor Segment Overrun Fault (Legacy)", + "Invalid TSS Fault", + "Segment Not Present Fault", + "Stack Segment fault", + "General Protection Fault", + "Page Fault", + "Intel Reserved", + "x87 FPU Floating Point or Math Fault", + "Alignment Check Fault", + "Machine Check Abort", + "SIMD Floating Point Fault", + "Virtualization Exception Fault", + "Intel Reserved", + "Intel Reserved", + "Intel Reserved", + "Intel Reserved", + "Intel Reserved", + "Intel Reserved", + "Intel Reserved", + "Intel Reserved", + "Intel Reserved", + "Security Exception", + "Intel Reserved" +}; + +static void EnablePIC(void); + +#define interrupt(n) asm volatile ("int %0" : : "N" (n) : "cc", "memory") // // Registers an isr with his IRQ to handle driver interrupts @@ -263,7 +301,7 @@ void IdtExceptionHandler(ISRFrame_t *regs) regs->rflags, regs->rsp, regs->ss - ); + ); } else { bprintf(BStdOut, "[ISR 0x%x] %s\n", regs->intNo, exceptionMsg); } diff --git a/kaleid/kernel/init/info.c b/kaleid/kernel/init/info.c index 861d90f..3202992 100644 --- a/kaleid/kernel/init/info.c +++ b/kaleid/kernel/init/info.c @@ -37,7 +37,7 @@ void BtInitBootInfo(multiboot_info_t *mbi, void *codeSeg) // We need the multiboot structure KalAlwaysAssert(mbi); - //Retrieves the bootloader flags to ensure infos are valid + // Retrieves the bootloader flags to ensure infos are valid BtLoaderInfo.grubFlags = mbi->flags; if (BtLoaderInfo.grubFlags & MULTIBOOT_INFO_BOOT_LOADER_NAME) { @@ -51,7 +51,7 @@ void BtInitBootInfo(multiboot_info_t *mbi, void *codeSeg) BtLoaderInfo.modulesCount = mbi->mods_count; BtLoaderInfo.modulesAddr = (void*)(ulong)mbi->mods_addr; } - //Retrieves the drives informations + // Retrieves the drives informations if (BtLoaderInfo.grubFlags & MULTIBOOT_INFO_DRIVE_INFO) { BtBootTab.drives.bufferLength = mbi->drives_length; BtBootTab.drives.bufferAddr = (void*)(ulong)mbi->drives_addr; @@ -62,7 +62,7 @@ void BtInitBootInfo(multiboot_info_t *mbi, void *codeSeg) BtBootTab.drives.drvValid = 1; } - //Retrieves the memory informations + // Retrieves the memory informations if (BtLoaderInfo.grubFlags & MULTIBOOT_INFO_MEMORY) { BtMemoryInfo.lowMemory = mbi->mem_lower; BtMemoryInfo.upMemory = mbi->mem_upper; diff --git a/kaleid/kernel/init/init.c b/kaleid/kernel/init/init.c index 3778576..3b86bbb 100644 --- a/kaleid/kernel/init/init.c +++ b/kaleid/kernel/init/init.c @@ -93,10 +93,7 @@ noreturn void BtStartKern(multiboot_info_t *mbInfo, uint mbMagic, void *codeSeg) i++; } - //divideByZero(); - KernLog("Goodbye after %d ticks\n", IoGetRtcTicks()); // End this machine's suffering - BFlushBuf(BStdOut); KeCrashSystem(); }