Global variable (BootTab/CPU) stuff

This commit is contained in:
Julian Barathieu 2019-04-05 10:20:10 +02:00
parent cd66216847
commit dc1cfa6151
12 changed files with 107 additions and 104 deletions

View File

@ -60,10 +60,7 @@ typedef enum TermColor_t TermColor_t;
#define _KeCurCPU 0 #define _KeCurCPU 0
// Process_t structure of current CPU // Process_t structure of current CPU
#define KeCurCPU (cpuTable[_KeCurCPU]) //#define KeCurCPU (cpuTable[_KeCurCPU])
// Access the BootInfo_t structure
#define BtGetBootInfo(x) (bootTab.x)
//------------------------------------------// //------------------------------------------//
@ -77,10 +74,13 @@ struct Processor_t
// CPU APIC id // CPU APIC id
int apicId; int apicId;
// CPU Vendor String (always 12 characters) // CPU Vendor String (always 12 characters)
char vendorStr[12]; char vendorStr[12];
// CPU Model code (enum in cpu.h) // CPU Model code (enum in cpu.h)
int modelCode; int modelCode;
// CPU Features flag // CPU Features flag
uint featureFlag; uint featureFlag;
@ -176,19 +176,24 @@ struct BootInfo_t
//------------------------------------------// //------------------------------------------//
extern volatile int cpuCount; extern int KeCPUCount;
extern volatile BootInfo_t bootTab; extern Processor_t _KeCPUTable[NCPUS];
extern volatile Processor_t cpuTable[NCPUS];
extern volatile Processor_t *KeCurCPU;
extern volatile BootInfo_t BtBootTab;
//------------------------------------------// //------------------------------------------//
#define DEC_PER_CPU(pref, name, field, type) \ #define DEC_PER_CPU(pref, name, field, type) \
static inline type pref##Get##name() { return KeGetCurCPU().field; } \ static inline type pref##Get##name() { return KeGetCurCPU()->field; } \
static inline void _##pref##Set##name(type __val) \ static inline void _##pref##Set##name(type __val) \
{ KeGetCurCPU().field = __val; } { KeGetCurCPU()->field = __val; }
#define BARRIER() do{\ #define BARRIER() \
asm volatile("": : :"memory");__sync_synchronize();}while(0) do { \
asm volatile("": : :"memory"); \
__sync_synchronize(); \
} while(0)
//------------------------------------------// //------------------------------------------//

View File

@ -66,7 +66,7 @@ struct GdtEntry_t
uchar access; // determine what ring this segment can be used in uchar access; // determine what ring this segment can be used in
uchar granularity; uchar granularity;
uchar highBase; // last 8 bits uchar highBase; // last 8 bits
} __attribute__((packed)); } __attribute__((__packed__));
// The gdt pointer // The gdt pointer
struct GdtPtr_t struct GdtPtr_t
@ -74,7 +74,7 @@ struct GdtPtr_t
uchar limit; // upper 16 bits uchar limit; // upper 16 bits
ushort base; // address of the first entry ushort base; // address of the first entry
} }
__attribute__((packed)); __attribute__((__packed__));
// -------------------------------------------------------------------------- // // -------------------------------------------------------------------------- //

View File

@ -32,7 +32,7 @@
//------------------------------------------// //------------------------------------------//
#define PANICSTR_SIZE 1024 #define PANICSTR_SIZE 1024
extern volatile char KePanicStr[PANICSTR_SIZE]; extern volatile bool KeIsPanicking;
//------------------------------------------// //------------------------------------------//

View File

@ -77,8 +77,8 @@ struct Process_t
//------------------------------------------// //------------------------------------------//
#define PsCurProc (KeCurCPU.process) #define PsCurProc (KeCurCPU->process)
#define PsCurThread (KeCurCPU.thread) #define PsCurThread (KeCurCPU->thread)
//DEC_PER_CPU(Ps, CurProc, process, Process_t *); //DEC_PER_CPU(Ps, CurProc, process, Process_t *);
//DEC_PER_CPU(Ps, CurThread, thread, Thread_t *); //DEC_PER_CPU(Ps, CurThread, thread, Thread_t *);

View File

@ -61,10 +61,10 @@ extern const char *PsPrioClassesNames[];
// Re-scheduling and preemption // Re-scheduling and preemption
// XXX atomic operations // XXX atomic operations
// //
#define PsRequestReSched() (++KeCurCPU.needReSched) #define PsRequestReSched() (++KeCurCPU->needReSched)
#define PsDisablePreemption() (++KeCurCPU.preemptCount) #define PsDisablePreemption() (++KeCurCPU->preemptCount)
#define PsEnablePreemption() do { assert(KeCurCPU.preemptCount > 0); \ #define PsEnablePreemption() do { assert(KeCurCPU->preemptCount > 0); \
--KeCurCPU.preemptCount; } while(0) --KeCurCPU->preemptCount; } while(0)
//------------------------------------------// //------------------------------------------//

View File

@ -24,7 +24,7 @@
#include <kernel/buf.h> #include <kernel/buf.h>
extern error_t bputc(Buffer_t *buf, uchar ch); error_t bputc(Buffer_t *buf, uchar ch);
error_t vbprintf(Buffer_t *buf, const char *fmt, va_list ap); error_t vbprintf(Buffer_t *buf, const char *fmt, va_list ap);
// //
@ -123,7 +123,7 @@ error_t vbprintf(Buffer_t *buf, const char *fmt, va_list ap)
assert(buf && buf->initDone == INITOK); assert(buf && buf->initDone == INITOK);
if (!buf) return EINVAL; if (!buf || !fmt) return EINVAL;
if (buf->state != BS_RDWR && buf->state != BS_WRONLY) { if (buf->state != BS_RDWR && buf->state != BS_WRONLY) {
return EBADF; return EBADF;
} }
@ -241,7 +241,6 @@ error_t vbprintf(Buffer_t *buf, const char *fmt, va_list ap)
// //
// The type field // The type field
// //
type = *fmt++; type = *fmt++;
// Characters // Characters
@ -300,10 +299,10 @@ error_t vbprintf(Buffer_t *buf, const char *fmt, va_list ap)
s = convbuf; s = convbuf;
// FIXME: this works, but is ugly as hell // FIXME: this works, but is ugly as hell
#define bdoconvrt(pref, type, vtype) \ #define bdoconvrt(pref, type, vtype) \
do { \ do { \
type i_##type = (type)va_arg(ap, vtype); \ type i_##type = (type)va_arg(ap, vtype); \
pref##toa(i_##type, s, base); \ pref##toa(i_##type, s, base); \
} while (0) } while (0)
if (!l) { if (!l) {

View File

@ -44,69 +44,69 @@ void BtInitBootInfo(multiboot_info_t *mbi)
KalAlwaysAssert(mbi); KalAlwaysAssert(mbi);
//Retrieves the bootloader flags to ensure infos are valid //Retrieves the bootloader flags to ensure infos are valid
BtGetBootInfo(btldr).grubFlags = mbi->flags; BtBootTab.btldr.grubFlags = mbi->flags;
if (BtGetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_BOOT_LOADER_NAME) { if (BtBootTab.btldr.grubFlags & MULTIBOOT_INFO_BOOT_LOADER_NAME) {
BtGetBootInfo(btldr).grubName = (char*)(ulong)(mbi->boot_loader_name); BtBootTab.btldr.grubName = (char*)(ulong)(mbi->boot_loader_name);
BtGetBootInfo(btldr).kernelAddr = (void*)&MB_header; BtBootTab.btldr.kernelAddr = (void*)&MB_header;
BtGetBootInfo(btldr).kernelEndAddr = (void*)newKernelEnd; BtBootTab.btldr.kernelEndAddr = (void*)newKernelEnd;
BtGetBootInfo(btldr).valid = 1; BtBootTab.btldr.valid = 1;
} }
if (BtGetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_MODS) { if (BtBootTab.btldr.grubFlags & MULTIBOOT_INFO_MODS) {
BtGetBootInfo(btldr).modulesCount = mbi->mods_count; BtBootTab.btldr.modulesCount = mbi->mods_count;
BtGetBootInfo(btldr).modulesAddr = (void*)(ulong)mbi->mods_addr; BtBootTab.btldr.modulesAddr = (void*)(ulong)mbi->mods_addr;
} }
//Retrieves the drives informations //Retrieves the drives informations
if (BtGetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_DRIVE_INFO) { if (BtBootTab.btldr.grubFlags & MULTIBOOT_INFO_DRIVE_INFO) {
BtGetBootInfo(drives).bufferLength = mbi->drives_length; BtBootTab.drives.bufferLength = mbi->drives_length;
BtGetBootInfo(drives).bufferAddr = (void*)(ulong)mbi->drives_addr; BtBootTab.drives.bufferAddr = (void*)(ulong)mbi->drives_addr;
BtGetBootInfo(drives).bufferValid = 1; BtBootTab.drives.bufferValid = 1;
} }
if (BtGetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_BOOTDEV) { if (BtBootTab.btldr.grubFlags & MULTIBOOT_INFO_BOOTDEV) {
BtGetBootInfo(drives).bootDrv = mbi->boot_device; BtBootTab.drives.bootDrv = mbi->boot_device;
BtGetBootInfo(drives).drvValid = 1; BtBootTab.drives.drvValid = 1;
} }
//Retrieves the memory informations //Retrieves the memory informations
if (BtGetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_MEMORY) { if (BtBootTab.btldr.grubFlags & MULTIBOOT_INFO_MEMORY) {
BtGetBootInfo(memory).lowMemory = mbi->mem_lower; BtBootTab.memory.lowMemory = mbi->mem_lower;
BtGetBootInfo(memory).upMemory = mbi->mem_upper; BtBootTab.memory.upMemory = mbi->mem_upper;
BtGetBootInfo(memory).memValid = 1; BtBootTab.memory.memValid = 1;
} }
if (BtGetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_MEM_MAP) { if (BtBootTab.btldr.grubFlags & MULTIBOOT_INFO_MEM_MAP) {
BtGetBootInfo(memory).mapAddr = (void*)(ulong)mbi->mmap_addr; BtBootTab.memory.mapAddr = (void*)(ulong)mbi->mmap_addr;
BtGetBootInfo(memory).mapLength = mbi->mmap_length; BtBootTab.memory.mapLength = mbi->mmap_length;
BtGetBootInfo(memory).mapValid = 1; BtBootTab.memory.mapValid = 1;
} }
// Retrieves video mode informations // Retrieves video mode informations
if (BtGetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_VBE_INFO) { if (BtBootTab.btldr.grubFlags & MULTIBOOT_INFO_VBE_INFO) {
BtGetBootInfo(video).vbeControl = (void*)(ulong)mbi->vbe_control_info; BtBootTab.video.vbeControl = (void*)(ulong)mbi->vbe_control_info;
BtGetBootInfo(video).vbeModeInfo = (void*)(ulong)mbi->vbe_mode_info; BtBootTab.video.vbeModeInfo = (void*)(ulong)mbi->vbe_mode_info;
BtGetBootInfo(video).vbeMode = mbi->vbe_mode; BtBootTab.video.vbeMode = mbi->vbe_mode;
BtGetBootInfo(video).vbeInterfaceSeg = mbi->vbe_interface_seg; BtBootTab.video.vbeInterfaceSeg = mbi->vbe_interface_seg;
BtGetBootInfo(video).vbeInterfaceOff = mbi->vbe_interface_off; BtBootTab.video.vbeInterfaceOff = mbi->vbe_interface_off;
BtGetBootInfo(video).vbeInterfaceLen = mbi->vbe_interface_len; BtBootTab.video.vbeInterfaceLen = mbi->vbe_interface_len;
BtGetBootInfo(video).vbeValid = 1; BtBootTab.video.vbeValid = 1;
} }
if (BtGetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_FRAMEBUFFER_INFO) { if (BtBootTab.btldr.grubFlags & MULTIBOOT_INFO_FRAMEBUFFER_INFO) {
BtGetBootInfo(video).framebufferAddr = (void*)mbi->framebuffer_addr; BtBootTab.video.framebufferAddr = (void*)mbi->framebuffer_addr;
BtGetBootInfo(video).framebufferPitch = mbi->framebuffer_pitch; BtBootTab.video.framebufferPitch = mbi->framebuffer_pitch;
BtGetBootInfo(video).framebufferWidth = mbi->framebuffer_width; BtBootTab.video.framebufferWidth = mbi->framebuffer_width;
BtGetBootInfo(video).framebufferHeight= mbi->framebuffer_height; BtBootTab.video.framebufferHeight= mbi->framebuffer_height;
BtGetBootInfo(video).framebufferBpp = mbi->framebuffer_bpp; BtBootTab.video.framebufferBpp = mbi->framebuffer_bpp;
BtGetBootInfo(video).framebufferType = mbi->framebuffer_type; BtBootTab.video.framebufferType = mbi->framebuffer_type;
BtGetBootInfo(video).fbuValid = 1; BtBootTab.video.fbuValid = 1;
} }
// Retrieves the firmware infos // Retrieves the firmware infos
if (BtGetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_CONFIG_TABLE) { if (BtBootTab.btldr.grubFlags & MULTIBOOT_INFO_CONFIG_TABLE) {
BtGetBootInfo(firmware).romTable = mbi->config_table; BtBootTab.firmware.romTable = mbi->config_table;
BtGetBootInfo(firmware).romValid = 1; BtBootTab.firmware.romValid = 1;
} }
if (BtGetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_APM_TABLE) { if (BtBootTab.btldr.grubFlags & MULTIBOOT_INFO_APM_TABLE) {
BtGetBootInfo(firmware).apmTable = mbi->apm_table; BtBootTab.firmware.apmTable = mbi->apm_table;
BtGetBootInfo(firmware).apmValid = 1; BtBootTab.firmware.apmValid = 1;
} }
} }
@ -118,11 +118,11 @@ void BtInitSanity(uint mbMagic){
if (!(mbMagic == MULTIBOOT_BOOTLOADER_MAGIC)) if (!(mbMagic == MULTIBOOT_BOOTLOADER_MAGIC))
KeStartPanic("[Init] Magic number %x is incorrect\n", mbMagic); KeStartPanic("[Init] Magic number %x is incorrect\n", mbMagic);
tmp = (BtGetBootInfo(btldr).kernelEndAddr tmp = (BtBootTab.btldr.kernelEndAddr
- BtGetBootInfo(btldr).kernelAddr) / KB; - BtBootTab.btldr.kernelAddr) / KB;
DebugLog("[Init] Kernel successfully loaded at %p with %x magic\n" DebugLog("[Init] Kernel successfully loaded at %p with %x magic\n"
" and it uses %d Kio\n\n", " and it uses %d Kio\n\n",
BtGetBootInfo(btldr).kernelAddr, BtBootTab.btldr.kernelAddr,
mbMagic,tmp); mbMagic,tmp);
} }

View File

@ -24,11 +24,10 @@
#include <kernel/base.h> #include <kernel/base.h>
volatile int cpuCount = 1; int KeCPUCount = 1;
volatile Processor_t cpuTable[NCPUS] = {0}; Processor_t _KeCPUTable[NCPUS] = {0};
volatile BootInfo_t bootTab = {0}; volatile BootInfo_t BtBootTab = {0};
Terminal_t *StdOut = 0, *StdDbg = 0; volatile bool KeIsPanicking = 0;
volatile char KePanicStr[PANICSTR_SIZE] = {0};
volatile Processor_t *KeCurCPU = &_KeCPUTable[0];

View File

@ -41,7 +41,7 @@
// //
error_t bvgaflusher(Buffer_t *buf) error_t bvgaflusher(Buffer_t *buf)
{ {
ushort *fbp = BtGetBootInfo(video).framebufferAddr; ushort *fbp = BtBootTab.video.framebufferAddr;
const uchar color = 0xf; const uchar color = 0xf;
uchar *currentLine = buf->wp - buf->lineLen - buf->lastLF; uchar *currentLine = buf->wp - buf->lineLen - buf->lastLF;
@ -54,8 +54,8 @@ error_t bvgaflusher(Buffer_t *buf)
} }
const size_t bufSize = buf->nLines * buf->lineLen; const size_t bufSize = buf->nLines * buf->lineLen;
ushort *fbe = BtGetBootInfo(video).framebufferAddr ushort *fbe = BtBootTab.video.framebufferAddr
+ (bufSize * sizeof(ushort)); + (bufSize * sizeof(ushort));
if (fbp < fbe) { if (fbp < fbe) {
const ushort filler = VGA_ComputeEntry(' ', color); const ushort filler = VGA_ComputeEntry(' ', color);
@ -73,8 +73,8 @@ error_t IoInitVGABuffer(void)
static char bvgabuffer[1 * MB]; static char bvgabuffer[1 * MB];
BStdOut = BOpenLineBuf(bvgabuffer, BS_WRONLY, BStdOut = BOpenLineBuf(bvgabuffer, BS_WRONLY,
BtGetBootInfo(video).framebufferWidth, BtBootTab.video.framebufferWidth,
BtGetBootInfo(video).framebufferHeight, BtBootTab.video.framebufferHeight,
8, bvgaflusher); 8, bvgaflusher);
BStdDbg = BStdOut; BStdDbg = BStdOut;

View File

@ -62,12 +62,12 @@ noreturn void KeStartPanic(const char *fmt, ...)
fmt = "(no message given)"; fmt = "(no message given)";
} }
if (KePanicStr[0] != 0) { if (KeIsPanicking) {
vbprintf(BStdOut, "\nDouble panic!", NULL); vbprintf(BStdOut, "\nDouble panic!", NULL);
KeHaltCPU(); KeHaltCPU();
} }
KePanicStr[0] = 1; KeIsPanicking = 1;
// We don't check vbprintf's output // We don't check vbprintf's output
// If it fails, what could we do anyway? // If it fails, what could we do anyway?

View File

@ -52,19 +52,19 @@ static error_t InitMemoryMap(void)
uint i = 0; uint i = 0;
// sanity checks // sanity checks
if (!BtGetBootInfo(memory).memValid && BtGetBootInfo(memory).mapValid) if (!BtBootTab.memory.memValid && BtBootTab.memory.mapValid)
return ENXIO; return ENXIO;
if ((BtGetBootInfo(memory).upMemory / (MB/KB)) <= MINIMUM_RAM_SIZE) if ((BtBootTab.memory.upMemory / (MB/KB)) <= MINIMUM_RAM_SIZE)
return ENOMEM; return ENOMEM;
// Ok then we can work ------------------------------------------------------ // // Ok then we can work ------------------------------------------------------ //
// the memory map provided by GRUB via the BIOS // the memory map provided by GRUB via the BIOS
currentEntry = (multiboot_memory_map_t*)BtGetBootInfo(memory).mapAddr; currentEntry = (multiboot_memory_map_t*)BtBootTab.memory.mapAddr;
// End address of the map // End address of the map
mapEnd = (multiboot_memory_map_t*) mapEnd = (multiboot_memory_map_t*)
((ulong)currentEntry + (ulong)BtGetBootInfo(memory).mapLength); ((ulong)currentEntry + (ulong)BtBootTab.memory.mapLength);
// fill the map // fill the map
while (currentEntry < mapEnd) { while (currentEntry < mapEnd) {
@ -112,7 +112,7 @@ size_t MmGetAvailZoneSize(void *start) {
uint i; uint i;
// Because the kernel is the kernel // Because the kernel is the kernel
if (start < BtGetBootInfo(btldr).kernelEndAddr) if (start < BtBootTab.btldr.kernelEndAddr)
return 0; return 0;
// Search the zone where the start address is // Search the zone where the start address is
@ -137,8 +137,8 @@ void *MmGetFirstAvailZone(void *start) {
void *current = 0; void *current = 0;
// Because the kernel is the kernel // Because the kernel is the kernel
if ((ulong)start < (ulong)BtGetBootInfo(btldr).kernelEndAddr) { if ((ulong)start < (ulong)BtBootTab.btldr.kernelEndAddr) {
return MmGetFirstAvailZone(BtGetBootInfo(btldr).kernelEndAddr); return MmGetFirstAvailZone(BtBootTab.btldr.kernelEndAddr);
} }
// Search the zone where the start address is // Search the zone where the start address is

View File

@ -46,13 +46,13 @@ Process_t procs[] = {
//------------------------------------------// //------------------------------------------//
#define ReSchedFlag (KeCurCPU.needReSched) #define ReSchedFlag (KeCurCPU->needReSched)
#define PreemptCount (KeCurCPU.preemptCount) #define PreemptCount (KeCurCPU->preemptCount)
#define IdlePrioProcs (KeCurCPU.idlePrioProcs) #define IdlePrioProcs (KeCurCPU->idlePrioProcs)
#define ReglPrioProcs (KeCurCPU.reglPrioProcs) #define ReglPrioProcs (KeCurCPU->reglPrioProcs)
#define ServPrioProcs (KeCurCPU.servPrioProcs) #define ServPrioProcs (KeCurCPU->servPrioProcs)
#define TimeCritProcs (KeCurCPU.timeCritProcs) #define TimeCritProcs (KeCurCPU->timeCritProcs)
//------------------------------------------// //------------------------------------------//