void exit(int status) { while (i--) dtors[i](); SYSCALL1(SYSCNUM_TASK_EXIT, status); }
int device_exists(const char *name) { int ret; SYSCALL1(SYS_DEVICE_EXISTS, name, ret); return ret; }
void printf(char* fmt, ...) { va_list list; va_start(list, fmt); char buf[1000] = {0}; vsprintf(buf, fmt, list); va_end(list); SYSCALL1(2, buf); }
void exit(int status) { int ret; close_streams(); SYSCALL1(SYS_EXIT, status, ret); while (1) ; }
//this "int" is a short, dont return anything longer than 2 bytes°!!!! int open(const char *name, int flags, ...) { int file_i = 0; while (file_ptrs[file_i].fs_node && file_i < MAX_FILES) file_i++; //find next free file buffer if (file_i +1 >= MAX_FILES) //MAX_FILES reached return -1; char* dir_path = NULL,* file_name = name,* last_slash; size_t dir_path_l = 0; DIR* dir; if (strchr(name, '/')) { //get directory path last_slash = strrchr(name, '/') +1; dir_path_l = last_slash - name; dir_path = (char*)malloc(dir_path_l +1); strncpy(dir_path, name, dir_path_l); dir_path[dir_path_l] = '\0'; file_name += dir_path_l; dir = opendir(dir_path); free(dir_path); } else { dir = opendir("."); } if (!dir) return -1; //dirent_t* ent; LPTR fs_node; SYSCALL_RET2(SYSCNUM_VFS_FIND_DIR, fs_node, dir->fs_node, file_name); closedir(dir); if (!fs_node) //is the file in the directory? { return -1; //no } else //yee, lets open it { SYSCALL1(SYSCNUM_VFS_OPEN, fs_node); file_ptrs[file_i].fs_node = fs_node; file_ptrs[file_i].off = 0; return file_i; } }
int main(void) { unsigned char string[256]; struct md5_ctx ctx; unsigned int size; int ret; #ifdef REPEAT do { #else print_string("This is the emulated program. Will try to calculate MD5...\n"); #endif md5_init(&ctx); /* pass the string address above */ #ifdef TEST #define STR "A long text to hash, and hash, and hash and hash..." size = sizeof(STR)-1; memcpy(string, STR, size); md5_update(&ctx, size, string); md5_digest(&ctx, 16, string); return 0; #else ret = SYSCALL2(USER_SYSCALL(1), (unsigned int)string, sizeof(string)); if (ret > 0) { size = ret; md5_update(&ctx, size, string); md5_digest(&ctx, 16, string); #ifndef REPEAT ret = SYSCALL2(USER_SYSCALL(2), (unsigned int)string, 16); if (ret == 0) return 0; #endif } #endif #ifdef REPEAT } while(SYSCALL1(USER_SYSCALL(0),0)==0); #endif return 1; }
int fork () { uint64_t ret; SYSCALL1(ret, (uint64_t)0xA, (uint64_t)0x0); return ret; }
int brk(void *addr) { return (int)SYSCALL1(SYSCALL_BRK, addr); }
// Increase the allocated process memory void* sbrk(ptrdiff_t incr) { int result; SYSCALL1(SYSCALL_SBRK, result, incr); return (caddr_t)result; }
void interrupt_unregister(int interrupt) { int ret; SYSCALL1(SYS_INTERRUPT_UNREGISTER, interrupt, ret); }
void exit(int status) { SYSCALL1(SYS_Exit, status); while(1) {} }
s64 Close(s64 fd) { SYSCALL1(SYS_CLOSE, fd); }
s64 MSleep(s64 ms) { SYSCALL1(SYS_MSLEEP, ms); }
s64 ProcessCreate(char* cmdline) { SYSCALL1(SYS_PROCESSCREATE, cmdline); }
s64 LoadSysModule(char* cmdline) { SYSCALL1(SYS_LOADSYSMODULE, cmdline); }
s64 Exit(s64 code) { SYSCALL1(SYS_EXIT, code); }