1/*
2** Copyright 2001, Travis Geiselbrecht. All rights reserved.
3** Distributed under the terms of the NewOS License.
4*/
5#ifndef KERNEL_ARCH_RISCV64_THREAD_TYPES_H
6#define KERNEL_ARCH_RISCV64_THREAD_TYPES_H
7
8#include <kernel.h>
9
10
11namespace BKernel {
12	struct Thread;
13}
14
15
16struct iframe {
17	uint64 status;
18	uint64 cause;
19	uint64 tval;
20
21	uint64 ra __attribute__((aligned (16)));
22	uint64 t6;
23	uint64 sp;
24	uint64 gp;
25	uint64 tp;
26	uint64 t0;
27	uint64 t1;
28	uint64 t2;
29	uint64 t5;
30	uint64 s1;
31	uint64 a0;
32	uint64 a1;
33	uint64 a2;
34	uint64 a3;
35	uint64 a4;
36	uint64 a5;
37	uint64 a6;
38	uint64 a7;
39	uint64 s2;
40	uint64 s3;
41	uint64 s4;
42	uint64 s5;
43	uint64 s6;
44	uint64 s7;
45	uint64 s8;
46	uint64 s9;
47	uint64 s10;
48	uint64 s11;
49	uint64 t3;
50	uint64 t4;
51	uint64 fp;
52	uint64 epc;
53};
54
55
56struct arch_context {
57	uint64 ra;    //  0
58	uint64 s[12]; // 12
59	uint64 sp;    // 13
60};
61
62struct fpu_context {
63	double f[32];
64	uint64 fcsr;
65};
66
67struct __attribute__((aligned(16))) arch_stack {
68	BKernel::Thread* thread;
69};
70
71struct arch_thread {
72	arch_context context;
73	fpu_context fpuContext;
74	iframe* userFrame;
75	uint64 oldA0;
76};
77
78struct arch_team {
79	// gcc treats empty structures as zero-length in C, but as if they contain
80	// a char in C++. So we have to put a dummy in to be able to use the struct
81	// from both in a consistent way.
82	char	dummy;
83};
84
85struct arch_fork_arg {
86	iframe frame;
87};
88
89
90#ifdef __cplusplus
91extern "C" {
92#endif
93
94void arch_context_switch(arch_context* from, arch_context* to);
95void save_fpu(fpu_context* ctx);
96void restore_fpu(fpu_context* ctx);
97void arch_thread_entry();
98void arch_load_user_iframe(arch_stack* stackHeader, iframe* frame)
99	__attribute__ ((noreturn));
100
101#ifdef __cplusplus
102}
103#endif
104
105
106#endif	/* KERNEL_ARCH_RISCV64_THREAD_TYPES_H */
107