mirror of
https://gitee.com/anod/open_agb_firm.git
synced 2025-05-06 13:54:09 +08:00
经过了review,这批次的kernel文件有小改动,主要包括内存块的引用由void*变成了u8*,另外两种情况是把字面量的掩码变成inline函数增加可读性,还有把noreturn标记由宏改为装饰器……TMD你跟我说C++23都用上装饰器了!!!简直难以接受
This commit is contained in:
parent
98b2c783e9
commit
1afd6e2cd7
@ -24,10 +24,10 @@
|
||||
/*
|
||||
* Maximum number of objects we can create (Slabheap).
|
||||
*/
|
||||
#define MAX_TASKS (3) // Including main and idle task.
|
||||
#define MAX_EVENTS (10)
|
||||
#define MAX_MUTEXES (3)
|
||||
#define MAX_SEMAPHORES (0)
|
||||
#define MAX_TASKS (4) // Including main and idle task.
|
||||
#define MAX_EVENTS (16)
|
||||
#define MAX_MUTEXES (8)
|
||||
#define MAX_SEMAPHORES (2)
|
||||
#define MAX_TIMERS (0)
|
||||
|
||||
#define IDLE_STACK_SIZE (0x1000) // Keep in mind this stack is used in interrupt contex! TODO: Change this.
|
||||
|
@ -1,17 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
// Based on https://github.com/torvalds/linux/blob/master/include/linux/list.h
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
// Based on https://github.com/torvalds/linux/blob/master/include/linux/list.h
|
||||
|
||||
#define LIST_INIT_VAL(name) ((ListNode){&(name), &(name)})
|
||||
|
||||
#define LIST_ENTRY(ptr, type, member) \
|
||||
({ \
|
||||
void *__mptr = (void*)(ptr); \
|
||||
u8 *__mptr = (void*)(ptr); \
|
||||
(type*)(__mptr - (size_t)&((type*)0)->member); \
|
||||
})
|
||||
|
||||
@ -101,3 +104,7 @@ static inline ListNode* listRemoveHead(ListNode *start)
|
||||
#define listPop(start) listRemoveTail((start))
|
||||
#define listPushTail(start, node) listAddAfter((start), (node))
|
||||
#define listPopHead(start) listRemoveHead((start))
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of open_agb_firm
|
||||
* Copyright (C) 2021 derrek, profi200
|
||||
* This file is part of libn3ds
|
||||
* Copyright (C) 2024 derrek, profi200
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -17,13 +17,12 @@
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdnoreturn.h>
|
||||
#include <string.h>
|
||||
#include "types.h"
|
||||
#include "kernel.h"
|
||||
#include "internal/config.h"
|
||||
#include "internal/kernel_private.h"
|
||||
#include "internal/kmemcpy_set.h"
|
||||
#include "memory.h"
|
||||
#include "internal/slabheap.h"
|
||||
#include "internal/util.h"
|
||||
#include "internal/list.h"
|
||||
@ -41,7 +40,7 @@ static TaskCb *g_curDeadTask = NULL; // TODO: Improve dead task handling.
|
||||
|
||||
|
||||
static KRes scheduler(TaskState curTaskState);
|
||||
noreturn static void kernelIdleTask(void);
|
||||
[[noreturn]] static void kernelIdleTask(void);
|
||||
|
||||
static void initKernelState(void)
|
||||
{
|
||||
@ -66,7 +65,7 @@ void kernelInit(uint8_t priority)
|
||||
initKernelState();
|
||||
|
||||
TaskCb *const idleT = (TaskCb*)slabAlloc(&g_taskSlab);
|
||||
void *const iStack = malloc(IDLE_STACK_SIZE);
|
||||
u8 *const iStack = malloc(IDLE_STACK_SIZE);
|
||||
TaskCb *const mainT = (TaskCb*)slabCalloc(&g_taskSlab, sizeof(TaskCb));
|
||||
if(idleT == NULL || iStack == NULL || mainT == NULL)
|
||||
{
|
||||
@ -88,7 +87,7 @@ void kernelInit(uint8_t priority)
|
||||
mainT->prio = priority;
|
||||
|
||||
g_curTask = mainT;
|
||||
g_readyBitmap = 1u<<1; // The idle task has priority 1 and is always ready.
|
||||
g_readyBitmap = BIT(1); // The idle task has priority 1 and is always ready.
|
||||
listPush(&g_runQueues[1], &idleT->node);
|
||||
g_numTasks = 2;
|
||||
}
|
||||
@ -102,7 +101,7 @@ KHandle createTask(size_t stackSize, uint8_t priority, TaskFunc entry, void *tas
|
||||
|
||||
SlabHeap *const taskSlabPtr = &g_taskSlab;
|
||||
TaskCb *const newT = (TaskCb*)slabAlloc(taskSlabPtr);
|
||||
void *const stack = malloc(stackSize);
|
||||
u8 *const stack = malloc(stackSize);
|
||||
if(newT == NULL || stack == NULL)
|
||||
{
|
||||
slabFree(taskSlabPtr, newT);
|
||||
@ -111,7 +110,7 @@ KHandle createTask(size_t stackSize, uint8_t priority, TaskFunc entry, void *tas
|
||||
}
|
||||
|
||||
cpuRegs *const regs = (cpuRegs*)(stack + stackSize - sizeof(cpuRegs));
|
||||
kmemset((u32*)regs, 0, sizeof(cpuRegs));
|
||||
clear32((u32*)regs, 0, sizeof(cpuRegs));
|
||||
regs->lr = (u32)entry;
|
||||
newT->prio = priority;
|
||||
newT->id = g_numTasks; // TODO: Make this more sophisticated.
|
||||
@ -123,7 +122,7 @@ KHandle createTask(size_t stackSize, uint8_t priority, TaskFunc entry, void *tas
|
||||
|
||||
kernelLock();
|
||||
listPush(&g_runQueues[priority], &newT->node);
|
||||
g_readyBitmap |= 1u<<priority;
|
||||
g_readyBitmap |= BIT(priority);
|
||||
g_numTasks++;
|
||||
kernelUnlock();
|
||||
|
||||
@ -180,7 +179,7 @@ bool waitQueueWakeN(ListNode *waitQueue, u32 wakeCount, KRes res, bool reschedul
|
||||
TaskCb *const curTask = g_curTask;
|
||||
const u8 curPrio = curTask->prio;
|
||||
listPushTail(&runQueues[curPrio], &curTask->node);
|
||||
readyBitmap = 1u<<curPrio;
|
||||
readyBitmap = BIT(curPrio);
|
||||
}
|
||||
|
||||
do
|
||||
@ -199,7 +198,7 @@ bool waitQueueWakeN(ListNode *waitQueue, u32 wakeCount, KRes res, bool reschedul
|
||||
*/
|
||||
//TaskCb *task = LIST_ENTRY(listPopHead(waitQueue), TaskCb, node);
|
||||
TaskCb *task = LIST_ENTRY(listPop(waitQueue), TaskCb, node);
|
||||
readyBitmap |= 1u<<task->prio;
|
||||
readyBitmap |= BIT(task->prio);
|
||||
task->res = res;
|
||||
listPushTail(&runQueues[task->prio], &task->node);
|
||||
} while(!listEmpty(waitQueue) && --wakeCount);
|
||||
@ -240,7 +239,7 @@ static KRes scheduler(TaskState curTaskState)
|
||||
}
|
||||
|
||||
listPush(&runQueues[curPrio], &curTask->node);
|
||||
readyBitmap |= 1u<<curPrio;
|
||||
readyBitmap |= BIT(curPrio);
|
||||
}
|
||||
else if(UNLIKELY(curTaskState == TASK_STATE_DEAD))
|
||||
{
|
||||
@ -249,7 +248,7 @@ static KRes scheduler(TaskState curTaskState)
|
||||
}
|
||||
|
||||
TaskCb *newTask = LIST_ENTRY(listPop(&runQueues[readyPrio]), TaskCb, node);
|
||||
if(listEmpty(&runQueues[readyPrio])) readyBitmap &= ~(1u<<readyPrio);
|
||||
if(listEmpty(&runQueues[readyPrio])) readyBitmap &= ~BIT(readyPrio);
|
||||
g_readyBitmap = readyBitmap;
|
||||
|
||||
TaskCb *oldTask = curTask;
|
||||
@ -261,7 +260,7 @@ static KRes scheduler(TaskState curTaskState)
|
||||
}
|
||||
|
||||
// TODO: Cleanup deleted tasks in here? Or create a worker task?
|
||||
noreturn static void kernelIdleTask(void)
|
||||
[[noreturn]] static void kernelIdleTask(void)
|
||||
{
|
||||
do
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of open_agb_firm
|
||||
* Copyright (C) 2021 derrek, profi200
|
||||
* Copyright (C) 2024 derrek, profi200
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -19,7 +19,7 @@
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include "internal/slabheap.h"
|
||||
#include "internal/kmemcpy_set.h"
|
||||
#include "memory.h"
|
||||
|
||||
|
||||
|
||||
@ -29,7 +29,7 @@ void slabInit(SlabHeap *slab, size_t objSize, size_t num)
|
||||
|
||||
listInit(slab);
|
||||
|
||||
void *pool = malloc(objSize * num);
|
||||
u8 *pool = malloc(objSize * num);
|
||||
if(!pool) return;
|
||||
do
|
||||
{
|
||||
@ -48,7 +48,7 @@ void* slabAlloc(SlabHeap *slab)
|
||||
void* slabCalloc(SlabHeap *slab, size_t clrSize)
|
||||
{
|
||||
void *const ptr = slabAlloc(slab);
|
||||
if(ptr) kmemset(ptr, 0, clrSize);
|
||||
if(ptr) clear32(ptr, 0, clrSize);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user