111 lines
3.3 KiB
C
111 lines
3.3 KiB
C
|
|
#ifndef _ESPRESSO_SYSCALL_H
|
||
|
|
#define _ESPRESSO_SYSCALL_H
|
||
|
|
|
||
|
|
/*
|
||
|
|
Use this file to use syscalls in Espresso.
|
||
|
|
do not use kernel/syscall.h, because it has some defiitions which are not used/needed here.
|
||
|
|
*/
|
||
|
|
|
||
|
|
#define SYSCALL_INT 0x30
|
||
|
|
|
||
|
|
enum {
|
||
|
|
SYS_MAP_PAGE = 0, /* void map_page(void* phys_addr, void* virt_addr); */
|
||
|
|
SYS_PMM_ALLOC_PAGE, /* void* pmm_alloc_page(void); */
|
||
|
|
SYS_PMM_FREE_PAGE, /* void pmm_free_page(void* addr); */
|
||
|
|
SYS_SERIAL_WRITE, /* void serial_write(char a); */
|
||
|
|
SYS_SERIAL_READ, /* char serial_read(void); */
|
||
|
|
SYS_SERIAL_PUTS, /* void serial_puts(const char* s); */
|
||
|
|
SYS_USE_SERIAL, /* bool use_serial(void); */
|
||
|
|
SYS_TERMINAL_SCROLL, /* void terminal_scroll(void); */
|
||
|
|
SYS_TERMINAL_CLEAR, /* void terminal_clear(void); */
|
||
|
|
SYS_TERMINAL_SET_CURSOR, /* void terminal_set_cursor(uint16_t row, uint16_t column); */
|
||
|
|
SYS_TERMINAL_GET_CURSOR, /* void terminal_get_cursor(int* row, int* column); */
|
||
|
|
SYS_TERMINAL_WRITE, /* void terminal_write(const char* data, size_t size); */
|
||
|
|
SYS_TERMINAL_WRITESTRING, /* void terminal_writestring(const char* data) */
|
||
|
|
SYS_TERMINAL_DEBUG_WRITESTRING, /* void terminal_debug_writestring(const char* data); */
|
||
|
|
SYS_TERMINAL_PUTCHAR, /* void terminal_putchar(char c); */
|
||
|
|
SYS_TERMINAL_PUTENTRYAT, /* void terminal_putentryat(unsigned char c, uint8_t color, size_t x, size_t y); */
|
||
|
|
SYS_TERMINAL_GETCOLOR, /* uint8_t terminal_getcolor(void); */
|
||
|
|
SYS_TERMINAL_SETCOLOR, /* void terminal_setcolor(uint8_t color); */
|
||
|
|
SYS_READ, /* int read(uint32_t fd, void* data, size_t max_len); */
|
||
|
|
SYS_WRITE, /* int write(uint32_t fd, void* data, size_t len); */
|
||
|
|
__ENUM_END_MARKER__,
|
||
|
|
};
|
||
|
|
|
||
|
|
|
||
|
|
#define syscall0(num) ({ \
|
||
|
|
int ret; \
|
||
|
|
asm volatile ( \
|
||
|
|
"int %1" \
|
||
|
|
: "=a"(ret) \
|
||
|
|
: "i"(SYSCALL_INT), "a"(num) \
|
||
|
|
: "memory" \
|
||
|
|
); \
|
||
|
|
ret; \
|
||
|
|
})
|
||
|
|
|
||
|
|
/* syscall 1 */
|
||
|
|
#define syscall1(num, a) ({ \
|
||
|
|
int ret; \
|
||
|
|
asm volatile ( \
|
||
|
|
"int %1" \
|
||
|
|
: "=a"(ret) \
|
||
|
|
: "i"(SYSCALL_INT), "a"(num), "b"(a) \
|
||
|
|
: "memory" \
|
||
|
|
); \
|
||
|
|
ret; \
|
||
|
|
})
|
||
|
|
|
||
|
|
#define syscall2(num, a, b) ({ \
|
||
|
|
int ret; \
|
||
|
|
asm volatile ( \
|
||
|
|
"int %1" \
|
||
|
|
: "=a"(ret) \
|
||
|
|
: "i"(SYSCALL_INT), "a"(num), "b"(a), "c"(b) \
|
||
|
|
: "memory" \
|
||
|
|
); \
|
||
|
|
ret; \
|
||
|
|
})
|
||
|
|
|
||
|
|
#define syscall3(num, a, b, c) ({ \
|
||
|
|
int ret; \
|
||
|
|
asm volatile ( \
|
||
|
|
"int %1" \
|
||
|
|
: "=a"(ret) \
|
||
|
|
: "i"(SYSCALL_INT), "a"(num), "b"(a), "c"(b), "d"(c) \
|
||
|
|
: "memory" \
|
||
|
|
); \
|
||
|
|
ret; \
|
||
|
|
})
|
||
|
|
|
||
|
|
#define syscall4(num, a, b, c, d) ({ \
|
||
|
|
int ret; \
|
||
|
|
asm volatile ( \
|
||
|
|
"int %1" \
|
||
|
|
: "=a"(ret) \
|
||
|
|
: "i"(SYSCALL_INT), "a"(num), "b"(a), "c"(b), "d"(c), "S"(d) \
|
||
|
|
: "memory" \
|
||
|
|
); \
|
||
|
|
ret; \
|
||
|
|
})
|
||
|
|
|
||
|
|
#define syscall5(num, a, b, c, d, e) ({ \
|
||
|
|
int ret; \
|
||
|
|
asm volatile ( \
|
||
|
|
"int %1" \
|
||
|
|
: "=a"(ret) \
|
||
|
|
: "i"(SYSCALL_INT), "a"(num), "b"(a), "c"(b), "d"(c), "S"(d), "D"(e) \
|
||
|
|
: "memory" \
|
||
|
|
); \
|
||
|
|
ret; \
|
||
|
|
})
|
||
|
|
|
||
|
|
/* some macros for commonly used functions */
|
||
|
|
#define syscall_terminal_writestring(ptr) syscall1(SYS_TERMINAL_WRITESTRING, ptr);
|
||
|
|
#define syscall_terminal_putchar(chr) syscall1(SYS_TERMINAL_PUTCHAR, chr);
|
||
|
|
#define syscall_map_page(phys, virt) syscall2(SYS_MAP_PAGE, phys, virt);
|
||
|
|
#define syscall_pmm_alloc_page() syscall0(SYS_PMM_ALLOC_PAGE);
|
||
|
|
#define syscall_pmm_free_page(addr) syscall1(SYS_PMM_FREE_PAGE, addr);
|
||
|
|
|
||
|
|
#endif
|