-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsyscall.c
More file actions
110 lines (93 loc) · 2.62 KB
/
syscall.c
File metadata and controls
110 lines (93 loc) · 2.62 KB
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
/*******************************************************************************
> File Name: syscall.c
> Author: sillyplus
> Mail: oi_boy@sina.cn
> Created Time: Tue Apr 21 16:27:49 2015
*******************************************************************************/
__asm__(".code16gcc\n");
#include "syscall.h"
#include "utils_32cc.h"
#include "Inori.h"
#define USER_SPACE_START __asm__ volatile(".intel_syntax noprefix; mov di, 0x7d0; mov ds, di; .att_syntax;":::"di");
#define USER_SPACE_END __asm__ volatile(".intel_syntax noprefix; xor di, di; mov ds, di; .att_syntax;":::"di");
int errno;
static ssize_t read_from_stdin(void *buf, size_t len);
static ssize_t write_to_stdout(const void *buff, size_t len);
static time_t mktime(int16_t year0, int8_t mon0, int8_t day, int8_t hour, int8_t min, int8_t sec);
void sys_exit() {
__asm__ volatile(
".intel_syntax noprefix;"
"jmp 0:run_program_cleanup;"
".att_syntax"
);
}
void sys_ouch() {
const char * const ouch = "OUCH!";
write_str(ouch, __builtin_strlen(ouch), 0x0c25);
}
void sys_up2low(char *buf, size_t len, size_t pos) {
USER_SPACE_START
write_str(buf, len, 0x0d23);
USER_SPACE_END
}
void sys_low2up() {
}
void sys_num2str() {
}
void sys_str2num() {
}
void sys_pstr() {
}
// ssize_t sys_read(int fd, void *buf, size_t len) {
// if (fd != 0) {
// errno = EBADF;
// return -1;
// }
// return read_from_stdin(buf, len);
// }
//
// ssize_t sys_write(int fd, const void *buf, size_t len) {
// if (fd != 1 && fd != 2) {
// errno = EBADF;
// return -1;
// }
// return write_to_stdout(buf, len);
// }
//
// time_t sys_time(time_t *t) {
// int16_t hour_minutes, seconds_ds, cen_year, month_day, year;
// int8_t hour, minutes, seconds, month, day, dst;
// time_t ret;
//
// return ret;
// }
//
// static ssize_t read_from_stdin(void *buf, size_t len) {
// ssize_t count = 0;
// char *_buf = (char *)buf, tmp;
// USER_SPACE_START
// while (len--) {
// if (0x04 == (tmp = get_kb_char()))
// break;
// if (tmp == '\r')
// tmp = '\n';
// *(_buf++) = tmp;
// ++count;
// }
// USER_SPACE_END
// return count;
// }
//
// static ssize_t write_to_stdout(const void *buf, size_t len) {
// ssize_t count = 0;
// const char *_buf = (const char *)buf;
// USER_SPACE_START
// while (len--) {
// if (*_buf == '\n')
// write_char('\r');
// write_char(*(_buf++));
// count++;
// }
// USER_SPACE_END
// return count;
// }