From 9b4672d8ca64f37e0aad1df4e6327a0023cc91df Mon Sep 17 00:00:00 2001 From: Julian Barathieu Date: Sun, 24 Mar 2019 14:44:59 +0100 Subject: [PATCH] Prefixes --- boot/loader/loader.asm | 4 +- kaleid/include/extras/argv.h | 2 +- kaleid/include/extras/list.h | 28 ++++----- kaleid/include/extras/locks.h | 27 +++------ kaleid/include/kernel/base.h | 18 +++--- kaleid/include/kernel/cpu.h | 2 +- kaleid/include/kernel/heap.h | 16 ++--- kaleid/include/kernel/iomisc.h | 6 +- kaleid/include/kernel/mm.h | 4 +- kaleid/include/kernel/panic.h | 14 ++--- kaleid/include/kernel/proc.h | 4 +- kaleid/include/kernel/sched.h | 30 +++++----- kaleid/include/kernel/term.h | 4 +- kaleid/kernel/init/init.c | 106 ++++++++++++++++----------------- kaleid/kernel/init/table.c | 2 +- kaleid/kernel/io/term.c | 16 ++--- kaleid/kernel/io/vga.c | 16 ++--- kaleid/kernel/ke/panic.c | 28 ++++----- kaleid/kernel/mm/heap.c | 28 ++++----- kaleid/kernel/mm/malloc.c | 10 ++-- kaleid/kernel/mm/map.c | 12 ++-- 21 files changed, 186 insertions(+), 191 deletions(-) diff --git a/boot/loader/loader.asm b/boot/loader/loader.asm index a15920c..0e56cdc 100644 --- a/boot/loader/loader.asm +++ b/boot/loader/loader.asm @@ -33,7 +33,7 @@ global MB_start global MB_header -extern StartKern +extern BtStartKern [BITS 32] [section .multiboot] @@ -164,7 +164,7 @@ _loader64: mov rdi, [mbInfo] mov rsi, [mbMagic] - call StartKern + call BtStartKern ;; We must never reach this point ------------------------------------------- ;; call tritemporize ; Let time to see diff --git a/kaleid/include/extras/argv.h b/kaleid/include/extras/argv.h index 84b2954..6a6f78b 100644 --- a/kaleid/include/extras/argv.h +++ b/kaleid/include/extras/argv.h @@ -79,7 +79,7 @@ enum CmdOptionFlag_t // enum CmdParserFlags_t { - // Don't exit on errors= + // Don't exit on errors KALOPT_NO_EXIT = (1 << 0), // Don't react to --help diff --git a/kaleid/include/extras/list.h b/kaleid/include/extras/list.h index c8c62c6..fea7f2a 100644 --- a/kaleid/include/extras/list.h +++ b/kaleid/include/extras/list.h @@ -72,7 +72,7 @@ struct ListNode_t // Create a list head with an extern lock // static inline ListHead_t -*CreateListHeadWithLock(Lock_t *lock) +*ExCreateListHeadWithLock(Lock_t *lock) { ListHead_t *head = KalAllocMemory(sizeof(ListHead_t)); @@ -90,16 +90,16 @@ static inline ListHead_t // Create a list head // static inline ListHead_t -*CreateListHead(void) +*ExCreateListHead(void) { - return CreateListHeadWithLock(NULL); + return ExCreateListHeadWithLock(NULL); } // // Create a node // static inline ListNode_t -*CreateNode(void *data) +*ExCreateNode(void *data) { ListNode_t *node = KalAllocMemory(sizeof(ListNode_t)); @@ -116,7 +116,7 @@ static inline ListNode_t // Prepend node at beginning of list // static inline ListHead_t -*PrependNode(ListHead_t *head, ListNode_t *node) +*ExPrependNode(ListHead_t *head, ListNode_t *node) { KalAssert(head && node); @@ -144,7 +144,7 @@ static inline ListHead_t // Append node at end of list // static inline ListHead_t -*AppendNode(ListHead_t *head, ListNode_t *node) +*ExAppendNode(ListHead_t *head, ListNode_t *node) { KalAssert(head && node); @@ -172,12 +172,12 @@ static inline ListHead_t // Insert node2 before node1 // static inline ListHead_t -*AddNodeBefore(ListHead_t *head, ListNode_t *node1, ListNode_t *node2) +*ExAddNodeBefore(ListHead_t *head, ListNode_t *node1, ListNode_t *node2) { KalAssert(head && node1 && node2 && node1->head == head); if (head->first == node1) { - return PrependNode(head, node2); + return ExPrependNode(head, node2); } node2->head = head; @@ -198,12 +198,12 @@ static inline ListHead_t // Insert node2 after node1 // static inline ListHead_t -*AddNodeAfter(ListHead_t *head, ListNode_t *node1, ListNode_t *node2) +*ExAddNodeAfter(ListHead_t *head, ListNode_t *node1, ListNode_t *node2) { KalAssert(head && node1 && node2 && node1->head == head); if (head->last == node1) { - return AppendNode(head, node2); + return ExAppendNode(head, node2); } node2->head = head; @@ -222,7 +222,7 @@ static inline ListHead_t // Remove node of list (and frees it) // static inline ListHead_t -*RemoveNode(ListHead_t *head, ListNode_t *node) +*ExRemoveNode(ListHead_t *head, ListNode_t *node) { KalAssert(head && node && head->length > 0 && node->head == head); @@ -257,7 +257,7 @@ leave: // Free a node // static inline void -DestroyNode(ListNode_t *node) +ExDestroyNode(ListNode_t *node) { KalAssert(node); KalFreeMemory(node); @@ -267,7 +267,7 @@ DestroyNode(ListNode_t *node) // Free a list head // static inline void -DestroyListHead(ListHead_t *head) +ExDestroyListHead(ListHead_t *head) { KalAssert(head); KalFreeMemory(head); @@ -276,7 +276,7 @@ DestroyListHead(ListHead_t *head) // // Access a node's data // -#define GetNodeData(node, type) ((type)(node)->data) +#define ExGetNodeData(node, type) ((type)(node)->data) //------------------------------------------// diff --git a/kaleid/include/extras/locks.h b/kaleid/include/extras/locks.h index 9248094..af41152 100644 --- a/kaleid/include/extras/locks.h +++ b/kaleid/include/extras/locks.h @@ -73,22 +73,15 @@ struct Lock_t //------------------------------------------// -// -// Linux syscall vs unimplemented syscall... -// #ifndef _KALEID_KERNEL -#ifdef _OSK_SOURCE int KalYieldCPU(void), -#else -int sched_yield(void); -#endif #endif // // Initialize a lock // static inline -void InitLock(Lock_t *lock, LockType_t type) +void ExInitLock(Lock_t *lock, LockType_t type) { lock->type = type; lock->locked = FALSE; @@ -103,16 +96,16 @@ void InitLock(Lock_t *lock, LockType_t type) // Alternative way to initalize a lock // #ifdef _KALEID_KERNEL -# define INITLOCK(type) { INITOK, FALSE, (type), /* NULL, NULL */ } +# define ExINITLOCK(type) { INITOK, FALSE, (type), /* NULL, NULL */ } #else -# define INITLOCK(type) { INITOK, FALSE, (type) } +# define ExINITLOCK(type) { INITOK, FALSE, (type) } #endif // // Destroy a lock // static inline -void DestroyLock(Lock_t *lock) +void ExDestroyLock(Lock_t *lock) { KalAssert(lock->initDone); @@ -126,20 +119,16 @@ void DestroyLock(Lock_t *lock) // until we have at least a basic scheduler // static inline -void AcquireLock(Lock_t *lock) +void ExAcquireLock(Lock_t *lock) { KalAssert(lock->initDone == INITOK); while (!__sync_bool_compare_and_swap(&lock->locked, 0, 1)) { #ifdef _KALEID_KERNEL - StartPanic("AcquireLock on an already locked object"); + KeStartPanic("AcquireLock on an already locked object"); #else if likely (lock->type == KLOCK_SPINLOCK) continue; -#ifdef _OSK_SOURCE else (void)KalYieldCPU(); -#else - else (void)sched_yield(); -#endif #endif } __sync_synchronize(); @@ -150,7 +139,7 @@ void AcquireLock(Lock_t *lock) // Panic if the lock was never acquired // static inline -void ReleaseLock(Lock_t *lock) +void ExReleaseLock(Lock_t *lock) { /*#ifdef _KALEID_KERNEL KalAssert(lock->ownerThread == GetCurThread()); @@ -164,7 +153,7 @@ void ReleaseLock(Lock_t *lock) // Tries to acquire lock // static inline -bool AttemptLock(Lock_t *lock) +bool ExAttemptLock(Lock_t *lock) { KalAssert(lock->initDone == INITOK); diff --git a/kaleid/include/kernel/base.h b/kaleid/include/kernel/base.h index e6efe12..2965398 100644 --- a/kaleid/include/kernel/base.h +++ b/kaleid/include/kernel/base.h @@ -57,13 +57,14 @@ typedef enum TermColor_t TermColor_t; // Current CPU number // Will return a CPU-local variable later -#define _GetCurCPU() 0 +#define _KeGetCurCPU() 0 // Get Process_t structure of current CPU -#define GetCurCPU() (cpuTable[_GetCurCPU()]) +#define KeGetCurCPU() (cpuTable[_KeGetCurCPU()]) //Get the BootInfo_t structure -#define GetBootInfo(x) bootTab.x +#define BtGetBootInfo(x) (bootTab.x) + //------------------------------------------// // @@ -98,6 +99,7 @@ struct Processor_t #define FB_INDEXED 0 #define FB_RGB 1 #define BINFO_SIZE 4096 + struct BootInfo_t { // The Bootloader infos (GRUB in our case) @@ -165,13 +167,15 @@ struct BootInfo_t //------------------------------------------// extern int cpuCount; -extern Processor_t cpuTable[NCPUS]; extern BootInfo_t bootTab; +extern Processor_t cpuTable[NCPUS]; + //------------------------------------------// -#define DEC_PER_CPU(name, field, type) \ - static inline type Get##name() { return GetCurCPU().field; } \ - static inline void _Set##name(type __val) { GetCurCPU().field = __val; } +#define DEC_PER_CPU(pref, name, field, type) \ + static inline type pref##Get##name() { return KeGetCurCPU().field; } \ + static inline void _##pref##Set##name(type __val) \ + { KeGetCurCPU().field = __val; } //------------------------------------------// diff --git a/kaleid/include/kernel/cpu.h b/kaleid/include/kernel/cpu.h index ebb5268..ae2c7b9 100644 --- a/kaleid/include/kernel/cpu.h +++ b/kaleid/include/kernel/cpu.h @@ -31,7 +31,7 @@ //------------------------------------------// -#define cpuid(in, a, b, c, d) asm("cpuid" \ +#define KeCPUID(in, a, b, c, d) asm("cpuid" \ : "=a" (a), "=b" (b), "=c" (c), "=d" (d) \ : "a" (in) \ ); diff --git a/kaleid/include/kernel/heap.h b/kaleid/include/kernel/heap.h index 40b4e19..9783c36 100644 --- a/kaleid/include/kernel/heap.h +++ b/kaleid/include/kernel/heap.h @@ -33,17 +33,17 @@ #define _HEAP_START (4 * MB) -void InitHeap(void); +void MmInitHeap(void); -void LockHeap(void); -void UnlockHeap(void); +void MmLockHeap(void); +void MmUnlockHeap(void); -size_t GetHeapSize(void); -size_t GetMaxHeapSize(void); -error_t SetMaxHeapSize(size_t); +size_t MmGetHeapSize(void); +size_t MmGetMaxHeapSize(void); +error_t MmSetMaxHeapSize(size_t); -error_t GrowHeap(size_t); -error_t ShrinkHeap(size_t); +error_t MmGrowHeap(size_t); +error_t MmShrinkHeap(size_t); //------------------------------------------// diff --git a/kaleid/include/kernel/iomisc.h b/kaleid/include/kernel/iomisc.h index 615875d..ceea5f0 100644 --- a/kaleid/include/kernel/iomisc.h +++ b/kaleid/include/kernel/iomisc.h @@ -32,7 +32,7 @@ //------------------------------------------// static inline -void WriteByteOnPort(port_t port, port_t val) +void IoWriteByteOnPort(port_t port, port_t val) { KalAssert(FALSE && ENOSYS); (void)port; @@ -40,7 +40,7 @@ void WriteByteOnPort(port_t port, port_t val) } static inline -uchar ReadByteFromPort(port_t port) +uchar IoReadByteFromPort(port_t port) { KalAssert(FALSE && ENOSYS); (void)port; @@ -48,7 +48,7 @@ uchar ReadByteFromPort(port_t port) } static inline -ushort ReadWordFromPort(port_t port) +ushort IoReadWordFromPort(port_t port) { KalAssert(FALSE && ENOSYS); (void)port; diff --git a/kaleid/include/kernel/mm.h b/kaleid/include/kernel/mm.h index 49072e0..8db7237 100644 --- a/kaleid/include/kernel/mm.h +++ b/kaleid/include/kernel/mm.h @@ -30,11 +30,11 @@ // // Returns a pointer to the first entry of the memory map // -void *GetMemoryMap(void); +void *MmGetMemoryMap(void); // // Initializes the memory map structure // -error_t InitMemoryMap(void); +error_t MmInitMemoryMap(void); // -------------------------------------------------------------------------- // diff --git a/kaleid/include/kernel/panic.h b/kaleid/include/kernel/panic.h index cdb53be..5d97862 100644 --- a/kaleid/include/kernel/panic.h +++ b/kaleid/include/kernel/panic.h @@ -32,35 +32,35 @@ //------------------------------------------// #define PANICSTR_SIZE 1024 -extern volatile char PanicStr[PANICSTR_SIZE]; +extern volatile char KePanicStr[PANICSTR_SIZE]; //------------------------------------------// // // Disable IRQs // -#define DisableIRQs() asm volatile ("cli") +#define KeDisableIRQs() asm volatile ("cli") // // Enable IRQs // -#define EnableIRQs() asm volatile ("sti") +#define KeEnableIRQs() asm volatile ("sti") // // Pause CPU until next interuption // !!! Enables IRQs !!! // -#define PauseCPU() asm volatile ("sti\n\thlt") +#define KePauseCPU() asm volatile ("sti\n\thlt") // // Halt the CPU indefinitely // -#define HaltCPU() do { asm volatile ("hlt"); } while (1) +#define KeHaltCPU() do { asm volatile ("hlt"); } while (1) //------------------------------------------// -noreturn void StartPanic(const char *, ...); -noreturn void CrashSystem(void); +noreturn void KeStartPanic(const char *, ...); +noreturn void KeCrashSystem(void); //------------------------------------------// #endif diff --git a/kaleid/include/kernel/proc.h b/kaleid/include/kernel/proc.h index e7de0b7..68b4770 100644 --- a/kaleid/include/kernel/proc.h +++ b/kaleid/include/kernel/proc.h @@ -77,8 +77,8 @@ struct Process_t //------------------------------------------// -DEC_PER_CPU(CurProc, process, Process_t *); -DEC_PER_CPU(CurThread, thread, Thread_t *); +DEC_PER_CPU(Ps, CurProc, process, Process_t *); +DEC_PER_CPU(Ps, CurThread, thread, Thread_t *); //------------------------------------------// diff --git a/kaleid/include/kernel/sched.h b/kaleid/include/kernel/sched.h index 27ad978..694aaff 100644 --- a/kaleid/include/kernel/sched.h +++ b/kaleid/include/kernel/sched.h @@ -53,17 +53,17 @@ enum }; // Names of the priority classes -extern const char *PrioClassesNames[]; +extern const char *PsPrioClassesNames[]; //------------------------------------------// -DEC_PER_CPU(ReSchedFlag, needReSched, bool); -DEC_PER_CPU(PreemptCount, preemptCount, ulong); +DEC_PER_CPU(Ps, ReSchedFlag, needReSched, bool); +DEC_PER_CPU(Ps, PreemptCount, preemptCount, ulong); -DEC_PER_CPU(IdlePrioProcs, idlePrioProcs, ListHead_t *); -DEC_PER_CPU(ReglPrioProcs, reglPrioProcs, ListHead_t *); -DEC_PER_CPU(ServPrioProcs, servPrioProcs, ListHead_t *); -DEC_PER_CPU(TimeCritProcs, timeCritProcs, ListHead_t *); +DEC_PER_CPU(Ps, IdlePrioProcs, idlePrioProcs, ListHead_t *); +DEC_PER_CPU(Ps, ReglPrioProcs, reglPrioProcs, ListHead_t *); +DEC_PER_CPU(Ps, ServPrioProcs, servPrioProcs, ListHead_t *); +DEC_PER_CPU(Ps, TimeCritProcs, timeCritProcs, ListHead_t *); //------------------------------------------// @@ -71,18 +71,18 @@ DEC_PER_CPU(TimeCritProcs, timeCritProcs, ListHead_t *); // Re-scheduling and preemption // XXX atomic operations // -#define SetReSchedFlag(x) _SetReSchedFlag(x) -#define DisablePreemption() _SetPreemptCount(GetPreemptCount()+1) -#define EnablePreemption() do { KalAssert(GetPreemptCount() > 0); \ - _SetPreemptCount(GetPreemptCount()-1); } while(0) +#define PsSetReSchedFlag(x) _PsSetReSchedFlag(x) +#define PsDisablePreemption() _PsSetPreemptCount(GetPreemptCount()+1) +#define PsEnablePreemption() do { KalAssert(GetPreemptCount() > 0); \ + _PsSetPreemptCount(GetPreemptCount()-1); } while(0) //------------------------------------------// -void SchedInit(void); -void SchedFini(void); +void PsInitSched(void); +void PsFiniSched(void); -void SchedThisProc(Process_t *); -void SchedOnTick(void); +void PsSchedThisProc(Process_t *); +void PsSchedOnTick(void); //------------------------------------------// diff --git a/kaleid/include/kernel/term.h b/kaleid/include/kernel/term.h index e35b129..9e65916 100644 --- a/kaleid/include/kernel/term.h +++ b/kaleid/include/kernel/term.h @@ -106,9 +106,9 @@ extern Terminal_t *StdDbg; //------------------------------------------// #ifndef _NO_DEBUG -error_t DebugLog(const char *, ...); +error_t DebugLog(const char *, ...); #else // _NO_DEBUG -#define DebugLog(fmt, ...) EOK +#define DebugLog(fmt, ...) EOK #endif //------------------------------------------// diff --git a/kaleid/kernel/init/init.c b/kaleid/kernel/init/init.c index 94c8034..bc38cd4 100644 --- a/kaleid/kernel/init/init.c +++ b/kaleid/kernel/init/init.c @@ -30,7 +30,7 @@ // BootInfo_t initialization. It is necessary because grub will potentially be // wiped since it is below 1MB.... And we must reorganize all that stuff. // -void InitBootInfo(multiboot_info_t *mbi) +void BtInitBootInfo(multiboot_info_t *mbi) { extern void MB_header(void); @@ -38,68 +38,68 @@ void InitBootInfo(multiboot_info_t *mbi) KalAlwaysAssert(mbi); //Retrieves the bootloader flags to ensure infos are valid - GetBootInfo(btldr).grubFlags = mbi->flags; + BtGetBootInfo(btldr).grubFlags = mbi->flags; - if (GetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_BOOT_LOADER_NAME) { - GetBootInfo(btldr).grubName = (char*)(ullong)(mbi->boot_loader_name); - GetBootInfo(btldr).kernelAddr = (void*)&MB_header; - GetBootInfo(btldr).valid = 1; + if (BtGetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_BOOT_LOADER_NAME) { + BtGetBootInfo(btldr).grubName = (char*)(ullong)(mbi->boot_loader_name); + BtGetBootInfo(btldr).kernelAddr = (void*)&MB_header; + BtGetBootInfo(btldr).valid = 1; } - if (GetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_MODS) { - GetBootInfo(btldr).modulesCount = mbi->mods_count; - GetBootInfo(btldr).modulesAddr = (void*)(ullong)mbi->mods_addr; + if (BtGetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_MODS) { + BtGetBootInfo(btldr).modulesCount = mbi->mods_count; + BtGetBootInfo(btldr).modulesAddr = (void*)(ullong)mbi->mods_addr; } //Retrieves the drives informations - if (GetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_DRIVE_INFO) { - GetBootInfo(drives).bufferLength = mbi->drives_length; - GetBootInfo(drives).bufferAddr = (void*)(ullong)mbi->drives_addr; - GetBootInfo(drives).bufferValid = 1; + if (BtGetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_DRIVE_INFO) { + BtGetBootInfo(drives).bufferLength = mbi->drives_length; + BtGetBootInfo(drives).bufferAddr = (void*)(ullong)mbi->drives_addr; + BtGetBootInfo(drives).bufferValid = 1; } - if (GetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_BOOTDEV) { - GetBootInfo(drives).bootDrv = mbi->boot_device; - GetBootInfo(drives).drvValid = 1; + if (BtGetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_BOOTDEV) { + BtGetBootInfo(drives).bootDrv = mbi->boot_device; + BtGetBootInfo(drives).drvValid = 1; } //Retrieves the memory informations - if (GetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_MEMORY) { - GetBootInfo(memory).lowMemory = mbi->mem_lower; - GetBootInfo(memory).upMemory = mbi->mem_upper; - GetBootInfo(memory).memValid = 1; + if (BtGetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_MEMORY) { + BtGetBootInfo(memory).lowMemory = mbi->mem_lower; + BtGetBootInfo(memory).upMemory = mbi->mem_upper; + BtGetBootInfo(memory).memValid = 1; } - if (GetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_MEM_MAP) { - GetBootInfo(memory).mapAddr = (void*)(ullong)mbi->mmap_addr; - GetBootInfo(memory).mapLength = mbi->mmap_length; - GetBootInfo(memory).mapValid = 1; + if (BtGetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_MEM_MAP) { + BtGetBootInfo(memory).mapAddr = (void*)(ullong)mbi->mmap_addr; + BtGetBootInfo(memory).mapLength = mbi->mmap_length; + BtGetBootInfo(memory).mapValid = 1; } // Retrieves video mode informations - if (GetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_VBE_INFO) { - GetBootInfo(video).vbeControl = (void*)(ullong)mbi->vbe_control_info; - GetBootInfo(video).vbeModeInfo = (void*)(ullong)mbi->vbe_mode_info; - GetBootInfo(video).vbeMode = mbi->vbe_mode; - GetBootInfo(video).vbeInterfaceSeg = mbi->vbe_interface_seg; - GetBootInfo(video).vbeInterfaceOff = mbi->vbe_interface_off; - GetBootInfo(video).vbeInterfaceLen = mbi->vbe_interface_len; - GetBootInfo(video).vbeValid = 1; + if (BtGetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_VBE_INFO) { + BtGetBootInfo(video).vbeControl = (void*)(ullong)mbi->vbe_control_info; + BtGetBootInfo(video).vbeModeInfo = (void*)(ullong)mbi->vbe_mode_info; + BtGetBootInfo(video).vbeMode = mbi->vbe_mode; + BtGetBootInfo(video).vbeInterfaceSeg = mbi->vbe_interface_seg; + BtGetBootInfo(video).vbeInterfaceOff = mbi->vbe_interface_off; + BtGetBootInfo(video).vbeInterfaceLen = mbi->vbe_interface_len; + BtGetBootInfo(video).vbeValid = 1; } - if (GetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_FRAMEBUFFER_INFO) { - GetBootInfo(video).framebufferAddr = (void*)(ullong)mbi->framebuffer_addr; - GetBootInfo(video).framebufferPitch = mbi->framebuffer_pitch; - GetBootInfo(video).framebufferWidth = mbi->framebuffer_width; - GetBootInfo(video).framebufferHeight= mbi->framebuffer_height; - GetBootInfo(video).framebufferBpp = mbi->framebuffer_bpp; - GetBootInfo(video).framebufferType = mbi->framebuffer_type; - GetBootInfo(video).fbuValid = 1; + if (BtGetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_FRAMEBUFFER_INFO) { + BtGetBootInfo(video).framebufferAddr = (void*)(ullong)mbi->framebuffer_addr; + BtGetBootInfo(video).framebufferPitch = mbi->framebuffer_pitch; + BtGetBootInfo(video).framebufferWidth = mbi->framebuffer_width; + BtGetBootInfo(video).framebufferHeight= mbi->framebuffer_height; + BtGetBootInfo(video).framebufferBpp = mbi->framebuffer_bpp; + BtGetBootInfo(video).framebufferType = mbi->framebuffer_type; + BtGetBootInfo(video).fbuValid = 1; } // Retrieves the firmware infos - if (GetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_CONFIG_TABLE) { - GetBootInfo(firmware).romTable = mbi->config_table; - GetBootInfo(firmware).romValid = 1; + if (BtGetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_CONFIG_TABLE) { + BtGetBootInfo(firmware).romTable = mbi->config_table; + BtGetBootInfo(firmware).romValid = 1; } - if (GetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_APM_TABLE) { - GetBootInfo(firmware).apmTable = mbi->apm_table; - GetBootInfo(firmware).apmValid = 1; + if (BtGetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_APM_TABLE) { + BtGetBootInfo(firmware).apmTable = mbi->apm_table; + BtGetBootInfo(firmware).apmValid = 1; } } @@ -107,15 +107,15 @@ void InitBootInfo(multiboot_info_t *mbi) // // Entry point of the Kaleid kernel // -noreturn void StartKern(multiboot_info_t *mbInfo, int mbMagic) +noreturn void BtStartKern(multiboot_info_t *mbInfo, int mbMagic) { error_t mapBad; // We're not ready to deal with interrupts - DisableIRQs(); + KeDisableIRQs(); //Initialize the BootInfo_t structure - InitBootInfo(mbInfo); + BtInitBootInfo(mbInfo); // Kernel terminals InitTerms(); @@ -125,17 +125,17 @@ noreturn void StartKern(multiboot_info_t *mbInfo, int mbMagic) KalAlwaysAssert(mbMagic == MULTIBOOT_BOOTLOADER_MAGIC); KernLog("[Init] Kernel successfully loaded at %p with %x magic\n\n", - GetBootInfo(btldr).kernelAddr, + BtGetBootInfo(btldr).kernelAddr, mbMagic ); //Memory mapping - if ((mapBad = InitMemoryMap())) - StartPanic("[Init] The memory map failed to initialize. Error : %d", + if ((mapBad = MmInitMemoryMap())) + KeStartPanic("[Init] The memory map failed to initialize. Error : %d", mapBad ); // We're out KernLog("\n[Init] Evil never dies !\n"); - CrashSystem(); //yay + KeCrashSystem(); //yay } diff --git a/kaleid/kernel/init/table.c b/kaleid/kernel/init/table.c index bc32fdb..3a36c08 100644 --- a/kaleid/kernel/init/table.c +++ b/kaleid/kernel/init/table.c @@ -30,5 +30,5 @@ Processor_t cpuTable[NCPUS] = {0}; BootInfo_t bootTab = {0}; Terminal_t *StdOut = 0, *StdDbg = 0; -volatile char PanicStr[PANICSTR_SIZE] = {0}; +volatile char KePanicStr[PANICSTR_SIZE] = {0}; diff --git a/kaleid/kernel/io/term.c b/kaleid/kernel/io/term.c index e7cd176..c7608f2 100644 --- a/kaleid/kernel/io/term.c +++ b/kaleid/kernel/io/term.c @@ -52,9 +52,9 @@ error_t ClearTerm(Terminal_t *term) if (term == NULL) return EINVAL; KalAssert(term->initDone == INITOK); - AcquireLock(&term->lock); + ExAcquireLock(&term->lock); retcode = term->clear(term); - ReleaseLock(&term->lock); + ExReleaseLock(&term->lock); return retcode; } @@ -70,12 +70,12 @@ error_t ChTermColor(Terminal_t *term, TermColor_t fgColor, TermColor_t bgColor) if (term == NULL) return EINVAL; - AcquireLock(&term->lock); + ExAcquireLock(&term->lock); term->fgColor = fgColor; term->bgColor = bgColor; - ReleaseLock(&term->lock); + ExReleaseLock(&term->lock); return EOK; } @@ -138,9 +138,9 @@ error_t PutOnTerm(Terminal_t *term, char ch) if (term == NULL) return EINVAL; KalAssert(term->initDone == INITOK); - AcquireLock(&term->lock); + ExAcquireLock(&term->lock); rc = PutOnTermUnlocked(term, ch); - ReleaseLock(&term->lock); + ExReleaseLock(&term->lock); return rc; } @@ -169,9 +169,9 @@ error_t PrintOnTerm(Terminal_t *term, const char *str) if (term == NULL) return EINVAL; KalAssert(term->initDone == INITOK); - AcquireLock(&term->lock); + ExAcquireLock(&term->lock); rc = PrintOnTermUnlocked(term, str); - ReleaseLock(&term->lock); + ExReleaseLock(&term->lock); return rc; } diff --git a/kaleid/kernel/io/vga.c b/kaleid/kernel/io/vga.c index b24f876..2311844 100644 --- a/kaleid/kernel/io/vga.c +++ b/kaleid/kernel/io/vga.c @@ -59,9 +59,11 @@ error_t VGA_ClearTermUnlocked(Terminal_t *term) // error_t VGA_PutOnTermUnlocked(Terminal_t *term, char ch) { - ushort *buffer = (ushort *)term->data; - const size_t offset = VGA_ComputeOffset(term, term->currentX, term->currentY); - buffer[offset] = VGA_ComputeEntry(ch, VGA_ComputeColorCode(term->fgColor, term->bgColor)); + ushort *buffer = (ushort *)term->data; + const size_t offset = + VGA_ComputeOffset(term, term->currentX, term->currentY); + buffer[offset] = VGA_ComputeEntry(ch, + VGA_ComputeColorCode(term->fgColor, term->bgColor)); return EOK; } @@ -71,7 +73,7 @@ error_t VGA_PutOnTermUnlocked(Terminal_t *term, char ch) // Terminal_t VGA_Terminal = { .initDone = FALSE, - .lock = INITLOCK(KLOCK_MUTEX), + .lock = ExINITLOCK(KLOCK_MUTEX), .name = "VGA Output Terminal", .type = "VGA", @@ -98,9 +100,9 @@ void VGA_Init(void) KalAssert(VGA_Terminal.initDone != INITOK); //Use the infos provided in the BootInfo_t structure - VGA_Terminal.data = GetBootInfo(video).framebufferAddr; - VGA_Terminal.width = GetBootInfo(video).framebufferWidth; - VGA_Terminal.height = GetBootInfo(video).framebufferHeight; + VGA_Terminal.data = BtGetBootInfo(video).framebufferAddr; + VGA_Terminal.width = BtGetBootInfo(video).framebufferWidth; + VGA_Terminal.height = BtGetBootInfo(video).framebufferHeight; VGA_Terminal.initDone = INITOK; } diff --git a/kaleid/kernel/ke/panic.c b/kaleid/kernel/ke/panic.c index 134ab33..9c9f56b 100644 --- a/kaleid/kernel/ke/panic.c +++ b/kaleid/kernel/ke/panic.c @@ -33,11 +33,11 @@ noreturn void __assert_handler(const char *msg, int line, const char *func) { - DisableIRQs(); + KeDisableIRQs(); (void)file; (void)line; (void)func; - StartPanic("In function '%s', from %s line %d - assertion failed: '%s'", + KeStartPanic("In function '%s', from %s line %d - assertion failed: '%s'", func, file, line, msg); } @@ -45,42 +45,42 @@ noreturn void __assert_handler(const char *msg, // Your best boy panic() // This is CPU local... // -noreturn void StartPanic(const char *fmt, ...) +noreturn void KeStartPanic(const char *fmt, ...) { va_list ap; - DisableIRQs(); + KeDisableIRQs(); - if (GetCurProc()) _SetCurProc(NULL); - if (StdOut == NULL) CrashSystem(); + if (PsGetCurProc()) _PsSetCurProc(NULL); + if (StdOut == NULL) KeCrashSystem(); if (fmt == NULL) { fmt = "(no message given)"; } - if (PanicStr[0] != 0) { + if (KePanicStr[0] != 0) { PrintOnTermUnlocked(StdOut, "\nDouble panic!"); - HaltCPU(); + KeHaltCPU(); } va_start(ap, fmt); - vsnprintf((char *)PanicStr, PANICSTR_SIZE, fmt, ap); + vsnprintf((char *)KePanicStr, PANICSTR_SIZE, fmt, ap); va_end(ap); PrintOnTermUnlocked(StdOut, "\nPanic!\n\n"); - PrintOnTermUnlocked(StdOut, (char *)PanicStr); + PrintOnTermUnlocked(StdOut, (char *)KePanicStr); - HaltCPU(); + KeHaltCPU(); } // // Oh well // -noreturn void CrashSystem(void) +noreturn void KeCrashSystem(void) { while (1) { - DisableIRQs(); - HaltCPU(); + KeDisableIRQs(); + KeHaltCPU(); } } diff --git a/kaleid/kernel/mm/heap.c b/kaleid/kernel/mm/heap.c index 06dbf9c..f4db181 100644 --- a/kaleid/kernel/mm/heap.c +++ b/kaleid/kernel/mm/heap.c @@ -31,41 +31,41 @@ static void *_heap_end; static size_t _heap_max; // Lock NOT used internally, but used by KalAllocMemory() & co. -static Lock_t _heap_lock = INITLOCK(KLOCK_SPINLOCK); +static Lock_t _heap_lock = ExINITLOCK(KLOCK_SPINLOCK); // Debugging stub -size_t GetAvailZoneSize(void *x) { (void)x; return 8 * MB; } +size_t MmGetAvailZoneSize(void *x) { (void)x; return 8 * MB; } // // Initializes heap managment // -void InitHeap(void) +void MmInitHeap(void) { assert(_heap_end == NULL); _heap_end = (void *)_HEAP_START; - _heap_max = lmin(8 * MB, GetAvailZoneSize((void *)_HEAP_START)); + _heap_max = lmin(8 * MB, MmGetAvailZoneSize((void *)_HEAP_START)); } // // Acquires control of the heap's lock // -void LockHeap(void) +void MmLockHeap(void) { - AcquireLock(&_heap_lock); + ExAcquireLock(&_heap_lock); } // // Releases control of the heap's lock // -void UnlockHeap(void) +void MmUnlockHeap(void) { - ReleaseLock(&_heap_lock); + ExReleaseLock(&_heap_lock); } // // Returns the heap's current size // -size_t GetHeapSize(void) +size_t MmGetHeapSize(void) { return (size_t)_heap_end - _HEAP_START; } @@ -73,7 +73,7 @@ size_t GetHeapSize(void) // // Returns the heap's maximum size // -size_t GetMaxHeapSize(void) +size_t MmGetMaxHeapSize(void) { return _heap_max; } @@ -81,9 +81,9 @@ size_t GetMaxHeapSize(void) // // Changes the heap's maximal size // -error_t SetMaxHeapSize(size_t new) +error_t MmSetMaxHeapSize(size_t new) { - if (new > GetAvailZoneSize((void *)_HEAP_START)) { + if (new > MmGetAvailZoneSize((void *)_HEAP_START)) { return ENOMEM; } @@ -99,7 +99,7 @@ error_t SetMaxHeapSize(size_t new) // // Extends the heap's size // -error_t GrowHeap(size_t req) +error_t MmGrowHeap(size_t req) { assert(req % alignof(QWORD)); @@ -115,7 +115,7 @@ error_t GrowHeap(size_t req) // // Reduces the heap's size // -error_t ShrinkHeap(size_t req) +error_t MmShrinkHeap(size_t req) { assert(req % alignof(QWORD)); diff --git a/kaleid/kernel/mm/malloc.c b/kaleid/kernel/mm/malloc.c index 58f8bf3..1c699a2 100644 --- a/kaleid/kernel/mm/malloc.c +++ b/kaleid/kernel/mm/malloc.c @@ -36,19 +36,19 @@ error_t KalAllocMemory(void **ptr, size_t req, int flags, size_t align) return EALIGN; } - LockHeap(); + MmLockHeap(); - brk = _HEAP_START + GetHeapSize(); + brk = _HEAP_START + MmGetHeapSize(); req = _ALIGN_UP(req + brk, align) - brk; - rc = GrowHeap(req); + rc = MmGrowHeap(req); - UnlockHeap(); + MmUnlockHeap(); if (rc) { if ((flags & M_CANFAIL) != 0) return rc; - StartPanic("Out of memory"); + KeStartPanic("Out of memory"); } if (flags & M_ZEROED) { diff --git a/kaleid/kernel/mm/map.c b/kaleid/kernel/mm/map.c index d84f662..72e36b1 100644 --- a/kaleid/kernel/mm/map.c +++ b/kaleid/kernel/mm/map.c @@ -25,22 +25,22 @@ #include #include -error_t InitMemoryMap(void) +error_t MmInitMemoryMap(void) { - if (!GetBootInfo(memory).memValid && GetBootInfo(memory).mapValid) + if (!BtGetBootInfo(memory).memValid && BtGetBootInfo(memory).mapValid) return ENXIO; DebugLog("[InitMemoryMap] Memory map address : %p, length : %d\n", - GetBootInfo(memory).mapAddr, GetBootInfo(memory).mapLength); + BtGetBootInfo(memory).mapAddr, BtGetBootInfo(memory).mapLength); - if ((GetBootInfo(memory).upMemory / (MB/KB)) <= MINIMUM_RAM_SIZE) + if ((BtGetBootInfo(memory).upMemory / (MB/KB)) <= MINIMUM_RAM_SIZE) return ENOMEM; DebugLog("[InitMemoryMap] Low memory : %d Kio, Up memory : %d Mio\n", - GetBootInfo(memory).lowMemory, GetBootInfo(memory).upMemory / (MB/KB)); + BtGetBootInfo(memory).lowMemory, BtGetBootInfo(memory).upMemory / (MB/KB)); return EOK; } -void *GetMemoryMap(void) +void *MmGetMemoryMap(void) { return (void*)0; }