neptune/kern/proc.h

92 lines
2.2 KiB
C

#ifndef PROC_H
#define PROC_H
#include <config.h>
#include <riscv.h>
#include <stdint.h>
typedef enum {
UNUSED,
USED,
SLEEPING,
RUNNABLE,
RUNNING,
ZOMBIE,
} ProcessState;
/** Saved registers for kernel context switches. */
typedef struct Context {
uint64_t ra;
uint64_t sp;
// callee-saved
uint64_t s0;
uint64_t s1;
uint64_t s2;
uint64_t s3;
uint64_t s4;
uint64_t s5;
uint64_t s6;
uint64_t s7;
uint64_t s8;
uint64_t s9;
uint64_t s10;
uint64_t s11;
} Context;
/** Per-CPU state. */
typedef struct cpu_t {
struct Process *proc; // The process running on this cpu, or null.
struct Context context; // swtch() here to enter scheduler().
int noff; // Depth of push_off() nesting.
int intena; // Were interrupts enabled before push_off()?
} Cpu;
/** Saved registers for kernel context switches. */
typedef struct TrapFrame_t {
/* 0 */ uint64_t kernel_satp; // kernel page table
/* 8 */ uint64_t kernel_sp; // top of process's kernel stack
/* 16 */ uint64_t kernel_trap; // usertrap()
/* 24 */ uint64_t epc; // saved user program counter
/* 32 */ uint64_t kernel_hartid; // saved kernel tp
/* 40 */ uint64_t ra;
/* 48 */ uint64_t sp;
/* 56 */ uint64_t gp;
/* 64 */ uint64_t tp;
/* 72 */ uint64_t t0;
/* 80 */ uint64_t t1;
/* 88 */ uint64_t t2;
/* 96 */ uint64_t s0;
/* 104 */ uint64_t s1;
/* 112 */ uint64_t a0;
/* 120 */ uint64_t a1;
/* 128 */ uint64_t a2;
/* 136 */ uint64_t a3;
/* 144 */ uint64_t a4;
/* 152 */ uint64_t a5;
/* 160 */ uint64_t a6;
/* 168 */ uint64_t a7;
/* 176 */ uint64_t s2;
/* 184 */ uint64_t s3;
/* 192 */ uint64_t s4;
/* 200 */ uint64_t s5;
/* 208 */ uint64_t s6;
/* 216 */ uint64_t s7;
/* 224 */ uint64_t s8;
/* 232 */ uint64_t s9;
/* 240 */ uint64_t s10;
/* 248 */ uint64_t s11;
/* 256 */ uint64_t t3;
/* 264 */ uint64_t t4;
/* 272 */ uint64_t t5;
/* 280 */ uint64_t t6;
} TrapFrame;
Cpu *mycpu(void);
extern Cpu cpus[NCPU];
/** Per-process state */
struct Proc {};
#endif // PROC_H