2019-01-21 15:00:04 +01:00
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
// GNU GPL OS/K //
|
|
|
|
// //
|
2019-02-16 23:36:33 +01:00
|
|
|
// Desc: Kaleid kernel base include file //
|
2019-01-21 15:00:04 +01:00
|
|
|
// //
|
2019-02-16 23:36:33 +01:00
|
|
|
// //
|
|
|
|
// 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 <https://www.gnu.org/licenses/>. //
|
2019-01-21 15:00:04 +01:00
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
|
|
|
|
#ifndef _KALBASE_H
|
|
|
|
#include <kalbase.h>
|
|
|
|
#endif
|
|
|
|
|
2019-02-16 23:36:33 +01:00
|
|
|
#ifdef __cplusplus
|
2019-03-08 09:00:55 +01:00
|
|
|
#error "Kaleid's kernel won't compile in C++"
|
2019-02-16 23:36:33 +01:00
|
|
|
#endif
|
2019-01-21 15:00:04 +01:00
|
|
|
|
|
|
|
#ifndef _KALKERN_BASE_H
|
|
|
|
#define _KALKERN_BASE_H
|
|
|
|
|
|
|
|
//------------------------------------------//
|
|
|
|
|
2019-02-16 23:36:33 +01:00
|
|
|
typedef struct Lock_t Lock_t;
|
2019-03-29 14:19:29 +01:00
|
|
|
typedef struct Buffer_t Buffer_t;
|
2019-02-16 23:36:33 +01:00
|
|
|
typedef struct Thread_t Thread_t;
|
|
|
|
typedef struct Process_t Process_t;
|
2019-04-06 07:53:58 +02:00
|
|
|
typedef struct BootInfo_t BootInfo_t;
|
2019-02-16 23:36:33 +01:00
|
|
|
typedef struct ListHead_t ListHead_t;
|
|
|
|
typedef struct ListNode_t ListNode_t;
|
2019-03-08 09:00:55 +01:00
|
|
|
typedef struct Processor_t Processor_t;
|
2019-04-24 00:05:03 +02:00
|
|
|
typedef struct IRQList_t IRQList_t;
|
2019-01-21 15:00:04 +01:00
|
|
|
|
2019-02-16 23:36:33 +01:00
|
|
|
typedef enum ProcState_t ProcState_t;
|
2019-03-24 14:44:59 +01:00
|
|
|
|
2019-03-08 09:00:55 +01:00
|
|
|
//------------------------------------------//
|
2019-01-21 15:00:04 +01:00
|
|
|
|
|
|
|
//
|
2019-03-08 09:00:55 +01:00
|
|
|
// Holds all CPU-local variables
|
2019-01-21 15:00:04 +01:00
|
|
|
//
|
2019-03-08 09:00:55 +01:00
|
|
|
struct Processor_t
|
|
|
|
{
|
|
|
|
// CPU number, index in CPU list
|
|
|
|
int index;
|
2019-01-21 15:00:04 +01:00
|
|
|
|
2019-03-25 23:10:06 +01:00
|
|
|
// CPU APIC id
|
|
|
|
int apicId;
|
2019-04-05 10:20:10 +02:00
|
|
|
|
2019-03-25 23:10:06 +01:00
|
|
|
// CPU Vendor String (always 12 characters)
|
|
|
|
char vendorStr[12];
|
2019-04-05 10:20:10 +02:00
|
|
|
|
2019-03-25 23:10:06 +01:00
|
|
|
// CPU Model code (enum in cpu.h)
|
|
|
|
int modelCode;
|
2019-04-05 10:20:10 +02:00
|
|
|
|
2019-03-25 23:10:06 +01:00
|
|
|
// CPU Features flag
|
|
|
|
uint featureFlag;
|
|
|
|
|
2019-03-08 09:00:55 +01:00
|
|
|
// Number of ticks since boot time
|
|
|
|
ulong ticks;
|
2019-01-21 15:00:04 +01:00
|
|
|
|
2019-03-08 09:00:55 +01:00
|
|
|
// Current process & thread
|
|
|
|
Process_t *process;
|
|
|
|
Thread_t *thread;
|
|
|
|
|
|
|
|
// Need re-schedule?
|
|
|
|
bool needReSched;
|
|
|
|
|
|
|
|
// Is preemption ON? ("PREEMPT_ON" in sched.h)
|
|
|
|
ulong preemptCount;
|
|
|
|
|
|
|
|
// List heads for the four priority classes
|
|
|
|
ListHead_t *idlePrioProcs;
|
|
|
|
ListHead_t *reglPrioProcs;
|
|
|
|
ListHead_t *servPrioProcs;
|
|
|
|
ListHead_t *timeCritProcs;
|
|
|
|
};
|
|
|
|
|
2019-04-06 07:53:58 +02:00
|
|
|
//------------------------------------------//
|
2019-03-24 14:44:59 +01:00
|
|
|
|
2019-04-06 07:53:58 +02:00
|
|
|
#ifndef NCPUS
|
|
|
|
#define NCPUS 1
|
|
|
|
#endif
|
2019-03-18 17:43:41 +01:00
|
|
|
|
2019-04-06 07:53:58 +02:00
|
|
|
// Current CPU number
|
|
|
|
#define _KeCurCPU 0
|
2019-03-08 09:00:55 +01:00
|
|
|
|
2019-04-05 10:20:10 +02:00
|
|
|
extern int KeCPUCount;
|
|
|
|
extern volatile Processor_t *KeCurCPU;
|
2019-04-06 07:53:58 +02:00
|
|
|
extern Processor_t _KeCPUTable[NCPUS];
|
2019-03-24 14:44:59 +01:00
|
|
|
|
2019-03-08 09:00:55 +01:00
|
|
|
//------------------------------------------//
|
|
|
|
|
2019-04-05 10:20:10 +02:00
|
|
|
#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; }
|
2019-01-21 15:00:04 +01:00
|
|
|
|
2019-04-05 10:20:10 +02:00
|
|
|
#define BARRIER() \
|
|
|
|
do { \
|
|
|
|
asm volatile("": : :"memory"); \
|
|
|
|
__sync_synchronize(); \
|
|
|
|
} while(0)
|
2019-03-30 14:58:12 +01:00
|
|
|
|
2019-01-21 15:00:04 +01:00
|
|
|
//------------------------------------------//
|
2019-02-06 14:07:38 +01:00
|
|
|
|
2019-04-06 07:53:58 +02:00
|
|
|
error_t KernLog(const char *, ...);
|
|
|
|
|
|
|
|
#ifndef _NO_DEBUG
|
|
|
|
void DebugLog(const char *, ...);
|
|
|
|
#else
|
|
|
|
#define DebugLog(fmt, ...) ((void)0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//------------------------------------------//
|
|
|
|
|
2019-04-21 21:18:13 +02:00
|
|
|
extern volatile bool KeIsPanicking;
|
|
|
|
noreturn void KeStartPanic(const char *, ...);
|
2019-01-21 15:00:04 +01:00
|
|
|
|
|
|
|
//------------------------------------------//
|
|
|
|
|
|
|
|
#endif
|
2019-03-08 09:00:55 +01:00
|
|
|
|