2025-01-13 09:46:09 -05:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "list.h"
|
2025-01-24 06:33:29 -05:00
|
|
|
#include "memory.h"
|
2025-01-27 05:26:15 -05:00
|
|
|
#include "types.h"
|
2025-01-13 09:46:09 -05:00
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2025-01-17 06:56:05 -05:00
|
|
|
extern struct task *current_task;
|
|
|
|
|
2025-02-03 07:11:38 -05:00
|
|
|
enum status { ZOMBIE, THREAD, RUN, WAIT, SLEEP, STOPPED, FORKED };
|
2025-01-17 06:56:05 -05:00
|
|
|
enum owner { OWNER_KERNEL, OWNER_USER };
|
2025-01-13 09:46:09 -05:00
|
|
|
|
2025-01-24 06:33:29 -05:00
|
|
|
#define STACK_SIZE PAGE_SIZE * 4
|
|
|
|
|
2025-01-13 09:46:09 -05:00
|
|
|
struct task {
|
2025-01-29 07:30:42 -05:00
|
|
|
u8 *esp;
|
|
|
|
u8 *esp0;
|
2025-01-27 05:26:15 -05:00
|
|
|
u32 *cr3; // physical
|
|
|
|
u32 *heap; // virtual
|
|
|
|
u32 *eip;
|
|
|
|
u16 pid;
|
|
|
|
u8 status;
|
|
|
|
u8 uid;
|
2025-01-13 09:46:09 -05:00
|
|
|
struct task *daddy;
|
|
|
|
struct task *child;
|
|
|
|
struct list **signals;
|
|
|
|
struct task *next;
|
2025-01-17 06:56:05 -05:00
|
|
|
struct task *prev;
|
2025-01-13 09:46:09 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
void scheduler(void);
|
|
|
|
void switch_to_task(struct task *next_task);
|
2025-01-28 07:38:39 -05:00
|
|
|
struct task *create_task(u8 uid);
|
2025-01-27 05:26:15 -05:00
|
|
|
i8 create_kernel_task(void);
|
2025-01-28 07:38:39 -05:00
|
|
|
void remove_task(struct task *task);
|
2025-02-03 07:11:38 -05:00
|
|
|
struct task *copy_task(const struct task *task);
|
|
|
|
void kfork(struct task *daddy);
|
2025-02-07 05:28:22 -05:00
|
|
|
void zombify_task(struct task *task);
|
2025-02-03 07:11:38 -05:00
|
|
|
|
|
|
|
// utils
|
|
|
|
void exec_fn(void (*fn)(void));
|
2025-01-28 07:38:39 -05:00
|
|
|
u16 fork(void);
|
|
|
|
u16 wait(void);
|