summaryrefslogtreecommitdiffstats
path: root/sw/z80/kernel/process.c
blob: 049c88c1a100d859fa6d9b87efcf25ca3ab33686 (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
#include "process.h"

static struct process proc_table[PID_COUNT_MAX];
static struct process *current_proc;

pid_t newpid(void)
{
    int i;
    static pid_t last_pid = 0;

    for (i = 0; i < PID_COUNT_MAX; i++, last_pid++) {
        if (last_pid == PID_COUNT_MAX) {
            last_pid = 0;
            continue;            
        }

        if (!proc_table[last_pid].running)
            break;
    }

    if (i >= PID_COUNT_MAX)
        return 0;

    return last_pid;
}

int fork(void)
{
    int i, p;
    pid_t child_pid = newpid();

    if (child_pid == 0)
        return -1;


    for (i = 0; i < current_proc.pages; i++) {
        p = page_new();

        if (p == -1) {
            
            return -2;
        }

        proc_table[child_pid].page[i] = p;
    }
}

int exec(char *path, char *args)
{
    
}

int spawn(char *path, char *args)
{
    
}