fill out _OSThread

This commit is contained in:
red031000
2020-05-17 17:43:10 +01:00
parent 4c3e5d5265
commit fc177ec7c3
7 changed files with 164 additions and 1 deletions

View File

@@ -0,0 +1,18 @@
//
// Created by red031000 on 2020-05-17.
//
#ifndef POKEDIAMOND_CP_CONTEXT_H
#define POKEDIAMOND_CP_CONTEXT_H
#include "types.h"
typedef struct CPContext {
u64 div_numer;
u64 div_denom;
u64 sqrt;
u16 div_mode;
u16 sqrt_mode;
} CPContext;
#endif //POKEDIAMOND_CP_CONTEXT_H

View File

@@ -0,0 +1,27 @@
//
// Created by red031000 on 2020-05-17.
//
#ifndef POKEDIAMOND_OS_ALARM_H
#define POKEDIAMOND_OS_ALARM_H
#include "types.h"
#include "OS_thread.h"
typedef void (*OSAlarmHandler) (void *);
struct OSiAlarm
{
OSAlarmHandler handler;
void *arg;
u32 tag;
OSTick fire;
OSAlarm *prev;
OSAlarm *next;
OSTick period;
OSTick start;
};
#endif //POKEDIAMOND_OS_ALARM_H

View File

@@ -0,0 +1,22 @@
//
// Created by red031000 on 2020-05-17.
//
#ifndef POKEDIAMOND_OS_CONTEXT_H
#define POKEDIAMOND_OS_CONTEXT_H
#include "types.h"
#include "CP_context.h"
typedef struct OSContext
{
u32 cpsr;
u32 r[13];
u32 sp;
u32 lr;
u32 pc_plus4;
u32 sp_svc;
CPContext cp_context;
} OSContext;
#endif //POKEDIAMOND_OS_CONTEXT_H

View File

@@ -9,6 +9,10 @@
#include "consts.h"
#include "OS_tcm.h"
#include "OS_spinLock.h"
#include "OS_context.h"
#include "OS_tick.h"
#include "OS_alarm.h"
#include "OS_mutex.h"
#include "OS_thread.h"
#include "OS_protectionRegion.h"
#include "OS_entropy.h"

View File

@@ -0,0 +1,20 @@
//
// Created by red031000 on 2020-05-17.
//
#ifndef POKEDIAMOND_OS_MUTEX_H
#define POKEDIAMOND_OS_MUTEX_H
#include "types.h"
#include "OS_thread.h"
#pragma warn_padding off //apparently needed?
struct OSMutex {
OSThreadQueue queue;
OSThread *thread;
s32 count;
OSMutexLink link;
};
#pragma warn_padding reset
#endif //POKEDIAMOND_OS_MUTEX_H

View File

@@ -5,7 +5,16 @@
#ifndef POKEDIAMOND_OS_THREAD_H
#define POKEDIAMOND_OS_THREAD_H
#include "types.h"
#include "OS_context.h"
typedef struct OSiAlarm OSAlarm;
typedef struct _OSThread OSThread;
typedef struct _OSThreadLink OSThreadLink;
typedef struct _OSMutexQueue OSMutexQueue;
typedef struct _OSMutexLink OSMutexLink;
typedef struct OSMutex OSMutex;
struct _OSThreadQueue
{
@@ -13,7 +22,26 @@ struct _OSThreadQueue
OSThread *tail;
};
struct _OSThreadLink
{
OSThread *prev;
OSThread *next;
};
struct _OSMutexQueue
{
OSMutex *head;
OSMutex *tail;
};
struct _OSMutexLink
{
OSMutex *next;
OSMutex *prev;
};
typedef struct _OSThreadQueue OSThreadQueue;
typedef struct _OSThreadLink OSThreadLink;
typedef struct OSThreadInfo {
u16 isNeedRescheduling;
@@ -23,9 +51,41 @@ typedef struct OSThreadInfo {
void* switchCallback; // type: OSSwitchThreadCallback
} OSThreadInfo;
typedef enum {
OS_THREAD_STATE_WAITING = 0,
OS_THREAD_STATE_READY = 1,
OS_THREAD_STATE_TERMINATED = 2
} OSThreadState;
typedef void (*OSThreadDestructor) (void *);
struct _OSThread
{
u8 padding[0x80]; //todo: not the correct size but idfk
OSContext context;
OSThreadState state;
OSThread *next;
u32 id;
u32 priority;
void *profiler;
OSThreadQueue *queue;
OSThreadLink link;
OSMutex *mutex;
OSMutexQueue mutexQueue;
u32 stackTop;
u32 stackBottom;
u32 stackWarningOffset;
OSThreadQueue joinQueue;
void *specific[3];
OSAlarm *alarmForSleep;
OSThreadDestructor destructor;
void *userParameter;
u32 systemErrno;
};
void OS_SleepThread(OSThreadQueue * queue);

View File

@@ -0,0 +1,12 @@
//
// Created by red031000 on 2020-05-17.
//
#ifndef POKEDIAMOND_OS_TICK_H
#define POKEDIAMOND_OS_TICK_H
#include "types.h"
typedef u64 OSTick;
#endif //POKEDIAMOND_OS_TICK_H