summaryrefslogtreecommitdiff
path: root/src/kernel/task.h
blob: 643c88e5d628e17772c3c50c0e70996d0ca87310 (plain) (blame)
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
#ifndef TASK_H
#define TASK_H

#include <stdbool.h>
#include <stdint.h>

#define TASK_NAME_LEN 86
#define MAX_WAITS 16
#define MAX_TASKS 64

struct wait {
  enum {
    NONE,
    PROCESS_END,
    WINDOW_ACTION,
    IPC_SENT,
    IPC_SENT_ANY,
    IPC_READ
  } mode;
  union {
    struct task_state *task;
  };
};

struct task_state {
  uint32_t ret_addr;
  void *page_directory;

  uint32_t ebx;
  uint32_t ecx;
  uint32_t edx;
  uint32_t esi;
  uint32_t edi;
  uint32_t ebp;
  uint32_t esp;

  uint32_t stack_bottom;

  struct wait waits[MAX_WAITS];
  bool waiting;

  char name[TASK_NAME_LEN + 1];
} __attribute__ ((packed));

void add_wait(struct wait wait);
void unwait_any(struct wait wait);
void unwait(struct task_state *task, struct wait wait);

extern struct task_state tasks[];
extern struct task_state *active_task;

void init_tasks();

//puts the handle into ecx
uint32_t new_task(struct task_state state);
void advance_active_task();

void delete_task(struct task_state *state);

uint32_t ipc_send(uint32_t reader_handle, uint32_t count, const void *buffer);
uint32_t ipc_read(uint32_t sender_handle, uint32_t count, void *buffer);

uint32_t find_unread_ipc() __attribute__ ((pure));

#endif