summaryrefslogtreecommitdiff
path: root/include/kernel/proc.h
diff options
context:
space:
mode:
authorRichard Qin <richard.qin.x@gmail.com>2025-12-30 14:21:40 +0800
committerRichard Qin <richard.qin.x@gmail.com>2025-12-30 14:21:40 +0800
commit7759eef8cdac79028dd5b468bd9ce0cf1c12b162 (patch)
treecea3f9e1857641d824129828a7a0ca6cb7e84431 /include/kernel/proc.h
parent588884418a2dd0110209ef1673c4ab0c47173254 (diff)
downloadlume-7759eef8cdac79028dd5b468bd9ce0cf1c12b162.tar.gz
lume-7759eef8cdac79028dd5b468bd9ce0cf1c12b162.tar.xz
dev(spinlock): refactoring the implementation of locks
Diffstat (limited to 'include/kernel/proc.h')
-rw-r--r--include/kernel/proc.h22
1 files changed, 19 insertions, 3 deletions
diff --git a/include/kernel/proc.h b/include/kernel/proc.h
index b557267..e77fdc9 100644
--- a/include/kernel/proc.h
+++ b/include/kernel/proc.h
@@ -3,11 +3,13 @@
#include "kernel/trap.h"
#include "kernel/spinlock.h"
+// Context structure, used for context switching
struct Context
{
uint64 ra;
uint64 sp;
+ // Callee-saved registers
uint64 s0;
uint64 s1;
uint64 s2;
@@ -22,7 +24,9 @@ struct Context
uint64 s11;
};
-enum ProcState{
+// Process State Enumeration
+enum ProcState
+{
UNUSED,
USED,
SLEEPING,
@@ -31,6 +35,7 @@ enum ProcState{
ZOMBIE,
};
+// Process Control Block (PCB)
struct Proc
{
struct Context context;
@@ -41,15 +46,25 @@ struct Proc
enum ProcState state;
int pid;
- void* kstack;
+ void *kstack;
char name[16];
uint64 sz;
struct Proc *parent;
void *chan;
int xstate;
+
+ // Implement later
};
+// CPU status structure
+struct cpu
+{
+ struct Proc *proc; // Processes currently running on this CPU
+ struct Context context; // Save the scheduler context here
+ int noff; // Depth of push_off()
+ int intena; // Interrupt enable status before closing
+};
namespace ProcManager
{
@@ -62,7 +77,8 @@ namespace ProcManager
void user_init();
void exit(int status);
int wait(uint64 addr);
- void sleep(void *chan, struct spinlock *lk);
+
+ void sleep(void *chan, Spinlock *lk);
void wakeup(void *chan);
}