Typedef some common structs

This commit is contained in:
Imbus 2025-09-01 23:41:00 +02:00
parent 52f88785c4
commit eec052bafa
2 changed files with 17 additions and 13 deletions

View file

@ -1,6 +1,6 @@
#include <proc.h> #include <proc.h>
struct Cpu cpus[NCPU]; Cpu cpus[NCPU];
/** /**
* Must be called with interrupts disabled, to prevent race with process being * 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. * Return this CPU's cpu struct. Interrupts must be disabled.
*/ */
struct Cpu *mycpu(void) { Cpu *mycpu(void) {
int id = cpuid(); int id = cpuid();
struct Cpu *c = &cpus[id]; Cpu *c = &cpus[id];
return c; return c;
} }

View file

@ -1,6 +1,8 @@
#ifndef PROC_H
#define PROC_H
#include <config.h> #include <config.h>
#include <riscv.h> #include <riscv.h>
#include <spinlock.h>
#include <stdint.h> #include <stdint.h>
typedef enum { typedef enum {
@ -13,7 +15,7 @@ typedef enum {
} ProcessState; } ProcessState;
/** Saved registers for kernel context switches. */ /** Saved registers for kernel context switches. */
struct Context { typedef struct Context {
uint64_t ra; uint64_t ra;
uint64_t sp; uint64_t sp;
@ -30,18 +32,18 @@ struct Context {
uint64_t s9; uint64_t s9;
uint64_t s10; uint64_t s10;
uint64_t s11; uint64_t s11;
}; } Context;
/** Per-CPU state. */ /** Per-CPU state. */
struct Cpu { typedef struct cpu_t {
struct Process *proc; // The process running on this cpu, or null. struct Process *proc; // The process running on this cpu, or null.
struct Context context; // swtch() here to enter scheduler(). struct Context context; // swtch() here to enter scheduler().
int noff; // Depth of push_off() nesting. int noff; // Depth of push_off() nesting.
int intena; // Were interrupts enabled before push_off()? int intena; // Were interrupts enabled before push_off()?
}; } Cpu;
/** Saved registers for kernel context switches. */ /** Saved registers for kernel context switches. */
typedef struct { typedef struct TrapFrame_t {
/* 0 */ uint64_t kernel_satp; // kernel page table /* 0 */ uint64_t kernel_satp; // kernel page table
/* 8 */ uint64_t kernel_sp; // top of process's kernel stack /* 8 */ uint64_t kernel_sp; // top of process's kernel stack
/* 16 */ uint64_t kernel_trap; // usertrap() /* 16 */ uint64_t kernel_trap; // usertrap()
@ -78,11 +80,13 @@ typedef struct {
/* 264 */ uint64_t t4; /* 264 */ uint64_t t4;
/* 272 */ uint64_t t5; /* 272 */ uint64_t t5;
/* 280 */ uint64_t t6; /* 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 */ /** Per-process state */
struct Proc {}; struct Proc {};
#endif