summaryrefslogtreecommitdiff
path: root/lume-legacy/include/kernel/proc_def.h
blob: 50f27d79efab86a5e3236af54eff4bd5331f4384 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * Copyright (C) 2026 Richard QIn
 */

#pragma once
#include "common/types.h"
#include "common/fcntl.h"

struct cpu;
struct Trapframe;
class Inode;
struct file;

enum ProcState
{
    UNUSED,
    USED,
    SLEEPING,
    RUNNABLE,
    RUNNING,
    ZOMBIE,
};

#define PRIO_MAX 0
#define PRIO_MIN 3
#define N_PRIO 4

// Context structure
struct Context
{
    uint64 ra;
    uint64 sp;
    uint64 s0;
    uint64 s1;
    uint64 s2;
    uint64 s3;
    uint64 s4;
    uint64 s5;
    uint64 s6;
    uint64 s7;
    uint64 s8;
    uint64 s9;
    uint64 s10;
    uint64 s11;
};

struct Proc
{
    struct Context context;
    struct Trapframe *tf;
    uint64 *pagetable;
    enum ProcState state;
    int pid;
    void *kstack;
    char name[16];
    uint64 sz;
    struct Proc *parent;
    void *chan;
    int xstate;
    int killed;

    Inode *cwd;
    struct file *ofile[NOFILE];

    struct Proc *next;
    struct Proc *prev;

    struct Proc *all_next;
    struct Proc *all_prev;

    int priority;
    int ticks;
    struct cpu *cpu;
};