Somehow works?!
This commit is contained in:
@@ -45,6 +45,34 @@ namespace JabyEngine {
|
||||
extern const Version version;
|
||||
}
|
||||
|
||||
struct TCB {
|
||||
uint32_t status;
|
||||
uint32_t unused;
|
||||
uint32_t reg[32];
|
||||
uint32_t epc;
|
||||
uint32_t hi;
|
||||
uint32_t lo;
|
||||
uint32_t sr;
|
||||
uint32_t cause;
|
||||
uint32_t unused2[6];
|
||||
};
|
||||
|
||||
struct PCB {
|
||||
TCB* current_tcb;
|
||||
};
|
||||
|
||||
static __always_inline TCB* get_tcb_of_th(uint32_t id) {
|
||||
return reinterpret_cast<TCB*>((*reinterpret_cast<uint32_t*>(0x110)) + (id*4));
|
||||
}
|
||||
|
||||
static __always_inline void set_tcb(TCB* adr) {
|
||||
reinterpret_cast<PCB*>(0x108)->current_tcb = adr;
|
||||
}
|
||||
|
||||
static __always_inline TCB& get_current_tcb() {
|
||||
return *reinterpret_cast<PCB*>(0x108)->current_tcb;
|
||||
}
|
||||
|
||||
namespace SysCall {
|
||||
static constexpr const uint32_t Table_A = 0xA0;
|
||||
static constexpr const uint32_t Table_B = 0xB0;
|
||||
@@ -92,6 +120,28 @@ namespace JabyEngine {
|
||||
return __syscall_function_cast(Table_A, void*(*)(void*, const void*, size_t))(dst, src, len);
|
||||
}
|
||||
|
||||
static __always_inline uint32_t OpenTh(void (*thread_func)(), uint32_t* stack_ptr, uint32_t* gp) {
|
||||
register uint32_t FuncID asm("t1") = 0x0E;
|
||||
__asm__ volatile("" : "=r"(FuncID) : "r"(FuncID));
|
||||
|
||||
return __syscall_function_cast(Table_B, uint32_t(*)(void(*)(), uint32_t*, uint32_t*))(thread_func, stack_ptr, gp);
|
||||
}
|
||||
|
||||
static __always_inline uint32_t ChangeTh(uint32_t thread) {
|
||||
register uint32_t FuncID asm("t1") = 0x10;
|
||||
__asm__ volatile("" : "=r"(FuncID) : "r"(FuncID));
|
||||
|
||||
return __syscall_function_cast(Table_B, uint32_t(*)(uint32_t))(thread);
|
||||
}
|
||||
|
||||
static __always_inline int changeThreadSubFunction(uint32_t address) {
|
||||
register int n asm("a0") = 3;
|
||||
register int tcb asm("a1") = address;
|
||||
register int r asm("v0");
|
||||
__asm__ volatile("syscall\n" : "=r"(r) : "r"(n), "r"(tcb) : "memory");
|
||||
return r;
|
||||
}
|
||||
|
||||
static __always_inline void InitPad(uint8_t *portA, uint32_t portASize, uint8_t *portB, uint32_t portBSize) {
|
||||
register uint32_t FuncID asm("t1") = 0x12;
|
||||
__asm__ volatile("" : "=r"(FuncID) : "r"(FuncID));
|
||||
|
Reference in New Issue
Block a user