merging
This commit is contained in:
commit
8cb110059a
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
||||
//------------------------------------------//
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
@ -166,13 +168,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; }
|
||||
|
||||
//------------------------------------------//
|
||||
|
||||
|
|
|
@ -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) \
|
||||
);
|
||||
|
|
|
@ -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);
|
||||
|
||||
//------------------------------------------//
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -54,6 +54,7 @@ struct MemoryMap_t {
|
|||
MapEntry_t entry[MAX_ENTRIES];
|
||||
} __attribute__((packed));
|
||||
|
||||
<<<<<<< HEAD
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------- //
|
||||
|
@ -61,15 +62,15 @@ struct MemoryMap_t {
|
|||
//
|
||||
// Initializes the memory map structure
|
||||
//
|
||||
error_t InitMemoryMap(void);
|
||||
error_t MmInitMemoryMap(void);
|
||||
|
||||
//
|
||||
// Returns the size of the first available memory zone from the start address pointer
|
||||
//
|
||||
size_t GetAvailZoneSize(void *start);
|
||||
size_t MmGetAvailZoneSize(void *start);
|
||||
|
||||
//
|
||||
// Returns the first available memory zone from the start address pointer
|
||||
void *GetFirstAvailZone(void *start);
|
||||
void MmGetFirstAvailZone(void *start);
|
||||
|
||||
// -------------------------------------------------------------------------- //
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 *);
|
||||
|
||||
//------------------------------------------//
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
//------------------------------------------//
|
||||
|
||||
|
|
|
@ -31,7 +31,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 ullong MB_header;
|
||||
extern ullong kernelEnd;
|
||||
|
@ -40,7 +40,7 @@ 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);
|
||||
|
@ -48,61 +48,61 @@ void InitBootInfo(multiboot_info_t *mbi)
|
|||
GetBootInfo(btldr).kernelEndAddr = (void*)&kernelEnd;
|
||||
GetBootInfo(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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -110,15 +110,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();
|
||||
|
@ -128,13 +128,13 @@ 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
|
||||
);
|
||||
|
||||
|
@ -145,5 +145,5 @@ noreturn void StartKern(multiboot_info_t *mbInfo, int mbMagic)
|
|||
|
||||
// We're out
|
||||
KernLog("\n[Init] Evil never dies !\n");
|
||||
CrashSystem(); //yay
|
||||
KeCrashSystem(); //yay
|
||||
}
|
||||
|
|
|
@ -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};
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -60,8 +60,10 @@ 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));
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,38 +32,39 @@ 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);
|
||||
|
||||
|
||||
//
|
||||
// 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;
|
||||
}
|
||||
|
@ -71,7 +72,7 @@ size_t GetHeapSize(void)
|
|||
//
|
||||
// Returns the heap's maximum size
|
||||
//
|
||||
size_t GetMaxHeapSize(void)
|
||||
size_t MmGetMaxHeapSize(void)
|
||||
{
|
||||
return _heap_max;
|
||||
}
|
||||
|
@ -79,9 +80,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;
|
||||
}
|
||||
|
||||
|
@ -97,7 +98,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));
|
||||
|
||||
|
@ -113,7 +114,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));
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -26,33 +26,33 @@
|
|||
#include <kernel/term.h>
|
||||
#include <kernel/multiboot.h>
|
||||
|
||||
MemoryMap_t memoryMap = { 0 };
|
||||
|
||||
MemoryMap_t memoryMap = { 0 };
|
||||
|
||||
|
||||
//
|
||||
// Initilization of the memory map, and computation of the available ram size
|
||||
//
|
||||
error_t InitMemoryMap(void)
|
||||
error_t MmInitMemoryMap(void)
|
||||
{
|
||||
multiboot_memory_map_t *currentEntry;
|
||||
multiboot_memory_map_t *mapEnd;
|
||||
uint i = 0;
|
||||
|
||||
// sanity checks
|
||||
if (!GetBootInfo(memory).memValid && GetBootInfo(memory).mapValid)
|
||||
if (!BtGetBootInfo(memory).memValid && BtGetBootInfo(memory).mapValid)
|
||||
return ENXIO;
|
||||
|
||||
if ((GetBootInfo(memory).upMemory / (MB/KB)) <= MINIMUM_RAM_SIZE)
|
||||
if ((BtGetBootInfo(memory).upMemory / (MB/KB)) <= MINIMUM_RAM_SIZE)
|
||||
return ENOMEM;
|
||||
|
||||
// Ok then we can work ------------------------------------------------------ //
|
||||
|
||||
// the memory map provided by GRUB via the BIOS
|
||||
currentEntry = (multiboot_memory_map_t*)GetBootInfo(memory).mapAddr;
|
||||
currentEntry = (multiboot_memory_map_t*)BtGetBootInfo(memory).mapAddr;
|
||||
// End address of the map
|
||||
mapEnd = (multiboot_memory_map_t*)
|
||||
((ullong)currentEntry + (ullong)GetBootInfo(memory).mapLength);
|
||||
((ullong)currentEntry + (ullong)BtGetBootInfo(memory).mapLength);
|
||||
|
||||
// fill the map
|
||||
while (currentEntry < mapEnd) {
|
||||
|
@ -96,11 +96,11 @@ error_t InitMemoryMap(void)
|
|||
return EOK;
|
||||
}
|
||||
|
||||
size_t GetAvailZoneSize(void *start) {
|
||||
size_t MmGetAvailZoneSize(void *start) {
|
||||
uint i;
|
||||
|
||||
// Because the kernel is the kernel
|
||||
if (start < GetBootInfo(btldr).kernelEndAddr)
|
||||
if (start < BtGetBootInfo(btldr).kernelEndAddr)
|
||||
return 0;
|
||||
|
||||
// Search the zone where the start address is
|
||||
|
@ -120,13 +120,13 @@ size_t GetAvailZoneSize(void *start) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
void *GetFirstAvailZone(void *start) {
|
||||
void *MmGetFirstAvailZone(void *start) {
|
||||
uint i;
|
||||
void *current = 0;
|
||||
|
||||
// Because the kernel is the kernel
|
||||
if ((ullong)start < (ullong)GetBootInfo(btldr).kernelEndAddr) {
|
||||
return GetFirstAvailZone(GetBootInfo(btldr).kernelEndAddr);
|
||||
if ((ullong)start < (ullong)BtGetBootInfo(btldr).kernelEndAddr) {
|
||||
return GetFirstAvailZone(BtGetBootInfo(btldr).kernelEndAddr);
|
||||
}
|
||||
|
||||
// Search the zone where the start address is
|
||||
|
|
Loading…
Reference in New Issue