From eec052bafae53d7163a2fe15b03cb0c98c3a79e4 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Mon, 1 Sep 2025 23:41:00 +0200 Subject: [PATCH] Typedef some common structs --- kern/libkern/proc.c | 8 ++++---- kern/proc.h | 22 +++++++++++++--------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/kern/libkern/proc.c b/kern/libkern/proc.c index 66bca67..bebf1a5 100644 --- a/kern/libkern/proc.c +++ b/kern/libkern/proc.c @@ -1,6 +1,6 @@ #include -struct Cpu cpus[NCPU]; +Cpu cpus[NCPU]; /** * Must be called with interrupts disabled, to prevent race with process being @@ -14,8 +14,8 @@ int cpuid() { /** * Return this CPU's cpu struct. Interrupts must be disabled. */ -struct Cpu *mycpu(void) { - int id = cpuid(); - struct Cpu *c = &cpus[id]; +Cpu *mycpu(void) { + int id = cpuid(); + Cpu *c = &cpus[id]; return c; } diff --git a/kern/proc.h b/kern/proc.h index 37ab333..ac5a46d 100644 --- a/kern/proc.h +++ b/kern/proc.h @@ -1,6 +1,8 @@ +#ifndef PROC_H +#define PROC_H + #include #include -#include #include typedef enum { @@ -13,7 +15,7 @@ typedef enum { } ProcessState; /** Saved registers for kernel context switches. */ -struct Context { +typedef struct Context { uint64_t ra; uint64_t sp; @@ -30,18 +32,18 @@ struct Context { uint64_t s9; uint64_t s10; uint64_t s11; -}; +} Context; /** Per-CPU state. */ -struct Cpu { +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 { +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() @@ -78,11 +80,13 @@ typedef struct { /* 264 */ uint64_t t4; /* 272 */ uint64_t t5; /* 280 */ uint64_t t6; -} TrapFrame_t; +} TrapFrame; -struct Cpu *mycpu(void); +Cpu *mycpu(void); -extern struct Cpu cpus[NCPU]; +extern Cpu cpus[NCPU]; /** Per-process state */ struct Proc {}; + +#endif