CoolPotOS/apps/libs/syscall.c

55 lines
1.7 KiB
C
Raw Normal View History

2024-08-30 16:12:44 +08:00
#include "../include/syscall.h"
2024-08-31 12:36:49 +08:00
void syscall_print(char* c){
uint32_t rets;
uint32_t __arg1 = c;
register uint32_t ebx asm("ebx") = __arg1;
asm volatile("int $31\n\t" : "=a"(rets) : "0"(SYSCALL_PRINT), "r"(ebx) : "memory", "cc");
}
void syscall_putchar(char c){
uint32_t rets;
uint32_t __arg1 = (uint32_t)(c);
register uint32_t ebx asm("ebx") = __arg1;
asm volatile("int $31\n\t" : "=a"(rets) : "0"(SYSCALL_PUTC), "r"(ebx) : "memory", "cc");
}
2024-09-01 11:56:39 +08:00
char syscall_getch(){
2024-08-31 12:36:49 +08:00
uint32_t rets;
2024-09-01 11:56:39 +08:00
asm volatile("int $31\n\t" : "=a"(rets) : "0"(SYSCALL_GETCH) : "memory", "cc");
2024-08-31 12:36:49 +08:00
return rets;
}
void* syscall_malloc(size_t size){
uint32_t rets;
uint32_t __arg1 = (uint32_t)(size);
register uint32_t ebx asm("ebx") = __arg1;
asm volatile("int $31\n\t" : "=a"(rets) : "0"(SYSCALL_MALLOC), "r"(ebx) : "memory", "cc");
return rets;
}
void syscall_free(void *ptr){
uint32_t rets;
uint32_t __arg1 = (uint32_t)(ptr);
register uint32_t ebx asm("ebx") = __arg1;
asm volatile("int $31\n\t" : "=a"(rets) : "0"(SYSCALL_FREE), "r"(ebx) : "memory", "cc");
}
void syscall_exit(int code){
uint32_t rets;
uint32_t __arg1 = (uint32_t)(code);
register uint32_t ebx asm("ebx") = __arg1;
asm volatile("int $31\n\t" : "=a"(rets) : "0"(SYSCALL_EXIT), "r"(ebx) : "memory", "cc");\
}
void syscall_g_clean(){
uint32_t rets;
asm volatile("int $31\n\t" : "=a"(rets) : "0"(SYSCALL_G_CLEAN) : "memory", "cc");
2024-09-01 11:56:39 +08:00
}
void syscall_get_cd(char *buffer){
uint32_t rets;
uint32_t __arg1 = (uint32_t)(buffer);
register uint32_t ebx asm("ebx") = __arg1;
asm volatile("int $31\n\t" : "=a"(rets) : "0"(SYSCALL_GET_CD), "r"(ebx) : "memory", "cc");
2024-08-31 12:36:49 +08:00
}