os-k/kaleid/include/kernel/base.h

201 lines
6.5 KiB
C

//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
// Desc: Kaleid kernel base include file //
// //
// //
// 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/>. //
//----------------------------------------------------------------------------//
#ifndef _KALBASE_H
#include <kalbase.h>
#endif
#ifdef __cplusplus
#error "Kaleid's kernel won't compile in C++"
#endif
#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 Terminal_t Terminal_t;
typedef struct ListHead_t ListHead_t;
typedef struct ListNode_t ListNode_t;
typedef struct Processor_t Processor_t;
typedef struct BootInfo_t BootInfo_t;
typedef enum ProcState_t ProcState_t;
typedef enum TermColor_t TermColor_t;
//------------------------------------------//
// Multiprocessor misc. //
//------------------------------------------//
#ifndef NCPUS
#define NCPUS 1
#endif
// Current CPU number
#define _KeCurCPU 0
// Process_t structure of current CPU
#define KeCurCPU (cpuTable[_KeCurCPU])
// Access the BootInfo_t structure
#define BtGetBootInfo(x) (bootTab.x)
//------------------------------------------//
//
// Holds all CPU-local variables
//
struct Processor_t
{
// CPU number, index in CPU list
int index;
// CPU APIC id
int apicId;
// CPU Vendor String (always 12 characters)
char vendorStr[12];
// CPU Model code (enum in cpu.h)
int modelCode;
// CPU Features flag
uint featureFlag;
// Number of ticks since boot time
ulong ticks;
// 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;
};
#define FB_EGA_TEXT 2
#define FB_INDEXED 0
#define FB_RGB 1
#define BINFO_SIZE 4096
struct BootInfo_t
{
// The Bootloader infos (GRUB in our case)
struct {
ushort valid;
uint grubFlags; //flags
uint modulesCount; //mods_count
void *modulesAddr; //mods_addr
char *grubName; //boot_loader_name
void *kernelAddr;
void *kernelEndAddr;
} btldr;
// Informations about drives
struct {
ushort drvValid;
ushort bufferValid;
uint bootDrv; //boot_device
uint bufferLength; //drives_length
void *bufferAddr; //drives_addr
} drives;
// Informations about memory
struct {
ushort memValid;
ushort mapValid;
//BIOS provided low and up memory
uint lowMemory; //mem_lower
uint upMemory; //mem_upper
//GRUB provided memory map
uint mapLength; //mmap_length
void *mapAddr; //mmap_addr
uint ramSize; //The ram (init by map.c)
} memory;
// Informations about the video drive
struct {
ushort vbeValid;
ushort fbuValid;
void *vbeControl; //vbe_control_info
void *vbeModeInfo; //vbe_mode_info
ushort vbeMode; //vbe_mode
ushort vbeInterfaceSeg; //vbe_interface_seg
ushort vbeInterfaceOff; //vbe_interface_off
ushort vbeInterfaceLen; //vbe_interface_len
void *framebufferAddr; //framebuffer_addr
uint framebufferPitch; //framebuffer_pitch
uint framebufferWidth; //framebuffer_width
uint framebufferHeight; //framebuffer_height
uchar framebufferBpp; //framebuffer_bpp
uchar framebufferType; //framebuffer_type
} video;
// Informations about the microcode firmware (BIOS/EFI)
struct {
ushort apmValid;
ushort romValid;
uint apmTable; //apm_table
uint romTable; //config_table
} firmware;
};
//------------------------------------------//
extern volatile int cpuCount;
extern volatile BootInfo_t bootTab;
extern volatile Processor_t cpuTable[NCPUS];
//------------------------------------------//
#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; }
//------------------------------------------//
// Needed by basically everyone
#ifndef _KALEXTRAS_LOCKS_H
#include <extras/locks.h>
#endif
//------------------------------------------//
#endif