summaryrefslogtreecommitdiff
path: root/src/user/include/pland.h
blob: f174a51329a338f925f496a2a88ee86f3579ac95 (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#ifndef PLAND_H
#define PLAND_H

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

typedef uint8_t fs_handle;
typedef uint8_t task_handle;

static inline void exit() __attribute__ ((noreturn)) {
  asm volatile ("int $0x30");
  __builtin_unreachable();
}

static inline void yield() {
  asm volatile ("int $0x31");
}

static inline uint32_t data_extend(uint32_t amount) {
  uint32_t actual_amount;
  asm volatile (
    "int $0x33"
  : "eax" (actual_amount) : "eax" (amount));
  return actual_amount;
}

static inline void vga_blank() {
  asm volatile (
    "xor %%eax, %%eax\n"
    "int $0x32"
  : : : "eax");
}

static inline void vga_set_color(uint8_t color) {
  asm volatile (
    "mov $0x1, %%eax\n"
    "int $0x32"
  : : "ebx" (color) : "eax");
}

static inline void vga_printch(uint8_t ch) {
  asm volatile (
    "mov $0x2, %%eax\n"
    "int $0x32"
  : : "ebx" (ch) : "eax");
}

static inline void vga_printsz(uint8_t *sz) {
  asm volatile (
    "mov $0x3, %%eax\n"
    "int $0x32"
  : : "ebx" (sz) : "eax");
}

static inline void vga_printsn(uint8_t *sn, uint8_t length) {
  asm volatile (
    "mov $0x4, %%eax\n"
    "int $0x32"
  : : "ebx" (sn), "ecx" (length) : "eax");
}

static inline fs_handle fs_open(uint8_t *path) {
  fs_handle handle;
  asm volatile (
    "mov $0x5, %%eax\n"
    "int $0x32"
  : "eax" (handle) : "ebx" (path));
  return handle;
}

static inline fs_handle fs_open_root() {
  fs_handle handle;
  asm volatile (
    "mov $0x6, %%eax\n"
    "int $0x32"
  : "eax" (handle));
  return handle;
}

static inline fs_handle fs_new(uint8_t *path) {
  fs_handle handle;
  asm volatile (
    "mov $0x7, %%eax\n"
    "int $0x32"
  : "eax" (handle) : "ebx" (path));
  return handle;
}

static inline void fs_close(fs_handle handle) {
  asm volatile (
    "mov $0x8, %%eax\n"
    "int $0x32"
  : : "ebx" (handle) : "eax");
}

static inline void fs_delete(uint8_t *path) {
  asm volatile (
    "mov $0x9, %%eax\n"
    "int $0x32"
  : : "ebx" (path) : "eax");
}

static inline bool fs_exists(uint8_t *path) {
  bool does;
  asm volatile (
    "mov $0xa, %%eax\n"
    "int $0x32"
  : "eax" (does) : "ebx" (path));
  return does;
}

static inline int32_t fs_seek(fs_handle handle, int32_t by) {
  int32_t seeked_by;
  asm volatile (
    "mov $0xb, %%eax\n"
    "int $0x32"
  : "eax" (seeked_by) : "ebx" (handle), "ecx" (by));
  return seeked_by;
}

static inline uint32_t fs_tell(fs_handle handle) {
  uint32_t position;
  asm volatile (
    "mov $0xc, %%eax\n"
    "int $0x32"
  : "eax" (position) : "ebx" (handle));
  return position;
}

static inline uint32_t fs_read(fs_handle handle, uint32_t max, void *buffer) {
  uint32_t read;
  asm volatile (
    "mov %0xd, %%eax\n"
    "int $0x32"
  : "eax" (read) : "ebx" (handle), "ecx" (max), "edx" (buffer) : "memory");
  return read;
}

static inline uint32_t fs_write(fs_handle handle, uint32_t max, void *buffer) {
  uint32_t written;
  asm volatile (
    "mov %0xe, %%eax\n"
    "int $0x32"
  : "eax" (written) : "ebx" (handle), "ecx" (max), "edx" (buffer));
  return written;
}

static inline task_handle plef_run(uint8_t *image_path) {
  task_handle handle;
  asm volatile (
    "mov %0xf, %%eax\n"
    "int $0x32"
  : "eax" (handle) : "ebx" (image_path));
  return handle;
}

#endif