2019-01-21 15:00:04 +01:00
|
|
|
//----------------------------------------------------------------------------//
|
2020-09-27 17:33:48 +02:00
|
|
|
// OS on Kaleid //
|
2019-01-21 15:00:04 +01:00
|
|
|
// //
|
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
|
|
|
// //
|
2020-02-06 14:23:26 +01:00
|
|
|
// Copyright © 2018-2020 The OS/K Team //
|
2019-02-16 23:36:33 +01:00
|
|
|
// //
|
|
|
|
// 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
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
|
2019-05-13 23:22:27 +02:00
|
|
|
#ifndef _LIBC_H
|
|
|
|
#include <libc.h>
|
2019-01-21 15:00:04 +01:00
|
|
|
#endif
|
|
|
|
|
2019-05-13 23:22:27 +02:00
|
|
|
#ifndef _KERNEL_H
|
|
|
|
#define _KERNEL_H
|
2019-01-21 15:00:04 +01:00
|
|
|
|
2019-05-01 14:17:16 +02:00
|
|
|
//----------------------------------------------------------------------------//
|
2019-01-21 15:00:04 +01:00
|
|
|
|
2019-05-13 23:22:27 +02:00
|
|
|
typedef volatile ulong Spinlock_t;
|
|
|
|
|
|
|
|
typedef Spinlock_t Lock_t;
|
|
|
|
//typedef struct Lock_t Lock_t;
|
|
|
|
|
2019-05-14 11:48:07 +02:00
|
|
|
typedef struct Time_t Time_t;
|
2019-11-15 00:09:20 +01:00
|
|
|
typedef struct Timer_t Timer_t;
|
2019-05-01 14:17:16 +02:00
|
|
|
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;
|
2019-05-09 21:57:54 +02:00
|
|
|
typedef struct CpuCore_t CpuCore_t;
|
|
|
|
typedef struct CpuInfo_t CpuInfo_t;
|
2019-05-01 14:17:16 +02:00
|
|
|
typedef struct ISRFrame_t ISRFrame_t;
|
2019-05-09 21:57:54 +02:00
|
|
|
typedef enum ProcState_t ProcState_t;
|
2019-05-01 14:17:16 +02:00
|
|
|
|
|
|
|
typedef struct IdtDescriptor_t IdtDescriptor_t;
|
|
|
|
typedef struct IdtEntry_t IdtEntry_t;
|
|
|
|
typedef struct IdtPtr_t IdtPtr_t;
|
2019-05-06 22:04:22 +02:00
|
|
|
typedef struct ISRList_t ISRList_t;
|
2019-05-01 14:17:16 +02:00
|
|
|
typedef struct ISRFrame_t ISRFrame_t;
|
|
|
|
|
2020-02-09 16:52:41 +01:00
|
|
|
typedef struct RSDPDescriptor_t RSDPDescriptor_t;
|
|
|
|
typedef struct SDTHeader_t SDTHeader_t;
|
|
|
|
typedef struct FADT_t FADT_t;
|
2020-02-13 13:40:07 +01:00
|
|
|
typedef struct MCFG_t MCFG_t;
|
2020-02-03 11:58:34 +01:00
|
|
|
|
2019-05-01 14:17:16 +02:00
|
|
|
typedef struct MemoryMap_t MemoryMap_t;
|
|
|
|
typedef struct MapEntry_t MapEntry_t;
|
|
|
|
typedef struct GdtEntry_t GdtEntry_t;
|
|
|
|
typedef struct GdtPtr_t GdtPtr_t;
|
2019-11-11 23:57:31 +01:00
|
|
|
typedef struct Tss_t Tss_t;
|
2019-05-13 18:07:45 +02:00
|
|
|
typedef struct TssDescriptor_t TssDescriptor_t;
|
2019-03-24 14:44:59 +01:00
|
|
|
|
2020-02-12 23:55:54 +01:00
|
|
|
typedef struct PciDev_t PciDev_t;
|
|
|
|
|
2019-05-01 14:17:16 +02: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-05-09 21:57:54 +02:00
|
|
|
struct CpuCore_t
|
2019-03-08 09:00:55 +01:00
|
|
|
{
|
|
|
|
// 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-05-09 21:57:54 +02:00
|
|
|
CpuInfo_t *infos;
|
2019-03-25 23:10:06 +01:00
|
|
|
|
2019-03-08 09:00:55 +01:00
|
|
|
// Number of ticks since boot time
|
2019-05-09 21:57:54 +02:00
|
|
|
ulong ticks; // XXX I/O APIC
|
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-05-09 21:57:54 +02:00
|
|
|
struct CpuInfo_t
|
|
|
|
{
|
|
|
|
// CPU Vendor String (always 12 characters)
|
|
|
|
char vendorStr[12];
|
|
|
|
|
|
|
|
// CPU Model code (enum in cpu.h)
|
|
|
|
int modelCode;
|
|
|
|
|
|
|
|
// CPU Features flag
|
|
|
|
uint featureFlag;
|
2019-11-15 00:09:20 +01:00
|
|
|
|
|
|
|
// CPU Frequency (Hz)
|
|
|
|
double frequency;
|
2019-05-09 21:57:54 +02:00
|
|
|
};
|
|
|
|
|
2019-04-27 00:04:27 +02:00
|
|
|
struct ISRFrame_t {
|
2019-05-18 20:31:02 +02:00
|
|
|
/* The registers */
|
|
|
|
ulong efer;
|
|
|
|
ulong cr0;
|
|
|
|
ulong cr2;
|
|
|
|
ulong cr3;
|
|
|
|
ulong cr4;
|
|
|
|
ulong cr8;
|
|
|
|
ulong r15;
|
|
|
|
ulong r14;
|
|
|
|
ulong r13;
|
|
|
|
ulong r12;
|
|
|
|
ulong r11;
|
|
|
|
ulong r10;
|
|
|
|
ulong r9;
|
|
|
|
ulong r8;
|
|
|
|
ulong rbp;
|
|
|
|
ulong rdi;
|
|
|
|
ulong rsi;
|
|
|
|
ulong rdx;
|
|
|
|
ulong rcx;
|
|
|
|
ulong rbx;
|
|
|
|
ulong rax;
|
2019-05-06 21:08:16 +02:00
|
|
|
|
|
|
|
/* The error code and interrupt id */
|
|
|
|
ulong intNo;
|
|
|
|
ulong ErrorCode;
|
|
|
|
|
|
|
|
/* These are pushed automatically by the CPU */
|
|
|
|
ulong rip;
|
|
|
|
ulong cs;
|
|
|
|
ulong rflags;
|
|
|
|
ulong rsp;
|
|
|
|
ulong ss;
|
2019-04-27 00:04:27 +02:00
|
|
|
} __attribute__((__packed__));
|
|
|
|
|
2019-05-01 14:17:16 +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-05-09 21:57:54 +02:00
|
|
|
extern int KeCPUCount;
|
|
|
|
extern volatile CpuCore_t *KeCurCPU;
|
|
|
|
extern CpuCore_t _KeCPUTable[NCPUS];
|
2019-03-24 14:44:59 +01:00
|
|
|
|
2019-05-01 14:17:16 +02:00
|
|
|
//----------------------------------------------------------------------------//
|
2019-03-08 09:00:55 +01:00
|
|
|
|
2019-05-13 23:22:27 +02:00
|
|
|
#define KeCurProc (KeCurCPU->process)
|
|
|
|
#define KeCurThread (KeCurCPU->thread)
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
|
2019-05-29 14:34:37 +02:00
|
|
|
#ifndef _ASM_H
|
2019-05-13 23:22:27 +02:00
|
|
|
#include <asm.h>
|
2019-05-29 14:34:37 +02:00
|
|
|
#endif
|
2019-05-13 23:22:27 +02: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-05-01 14:17:16 +02:00
|
|
|
//----------------------------------------------------------------------------//
|
2019-02-06 14:07:38 +01:00
|
|
|
|
2019-05-13 20:34:41 +02:00
|
|
|
#ifdef NDEBUG
|
|
|
|
#define DEBUG if(0)
|
|
|
|
#else
|
|
|
|
#define DEBUG if(1)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
|
2019-04-06 07:53:58 +02:00
|
|
|
error_t KernLog(const char *, ...);
|
|
|
|
|
2019-05-27 20:45:05 +02:00
|
|
|
#ifndef NDEBUG
|
2019-04-06 07:53:58 +02:00
|
|
|
void DebugLog(const char *, ...);
|
|
|
|
#else
|
|
|
|
#define DebugLog(fmt, ...) ((void)0)
|
|
|
|
#endif
|
|
|
|
|
2019-05-01 14:17:16 +02:00
|
|
|
//----------------------------------------------------------------------------//
|
2019-04-06 07:53:58 +02:00
|
|
|
|
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
|
|
|
|
2019-05-01 14:17:16 +02:00
|
|
|
//----------------------------------------------------------------------------//
|
2019-01-21 15:00:04 +01:00
|
|
|
|
2019-04-23 11:32:45 +02:00
|
|
|
#define XBUG(c) do { \
|
|
|
|
volatile ushort *_vga \
|
|
|
|
=(volatile ushort*)0xB8000; \
|
2019-05-01 14:17:16 +02:00
|
|
|
while(_vga<(volatile ushort*)(0xB8000+(80*25*2))) \
|
2019-04-23 11:32:45 +02:00
|
|
|
*_vga++=(c|(0xf<<8)); \
|
|
|
|
asm volatile("cli\nhlt"); \
|
2020-02-02 13:37:26 +01:00
|
|
|
}while(1)
|
2019-04-23 11:32:45 +02:00
|
|
|
#define BUG() XBUG('B')
|
|
|
|
#define BUGON(x) if(x)BUG()
|
2019-05-01 14:17:16 +02:00
|
|
|
|
2019-05-07 23:16:56 +02:00
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
|
2019-05-07 22:32:17 +02:00
|
|
|
#define __GET_GETRIP() \
|
|
|
|
__attribute__((__noinline__)) \
|
|
|
|
static ulong __getrip() \
|
|
|
|
{ return (size_t)__builtin_return_address(0); }
|
|
|
|
|
|
|
|
#define __PRINT_RIP() \
|
|
|
|
DebugLog("%s.RIP=%p\n",__func__,__getrip())
|
|
|
|
|
2019-05-01 14:17:16 +02:00
|
|
|
//----------------------------------------------------------------------------//
|
2019-04-23 11:32:45 +02:00
|
|
|
|
2019-01-21 15:00:04 +01:00
|
|
|
#endif
|
2019-03-08 09:00:55 +01:00
|
|
|
|