forked from ish-app/ish
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Everything to get Hello World working
on both gcc and clang!
- Loading branch information
Showing
13 changed files
with
215 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#include "emu/process.h" | ||
#include "sys/calls.h" | ||
#include "sys/errno.h" | ||
|
||
syscall_t syscall_table[] = { | ||
NULL, // 0 | ||
(syscall_t) sys_exit, // 1 | ||
NULL, // 2 | ||
NULL, // 3 | ||
(syscall_t) _sys_write, // 4 | ||
NULL, // 5 | ||
NULL, // 6 | ||
NULL, // 7 | ||
NULL, // 8 | ||
NULL, // 9 | ||
NULL, // 10 | ||
(syscall_t) _sys_execve, // 11 | ||
}; | ||
|
||
void handle_interrupt(struct cpu_state *cpu, int interrupt) { | ||
if (interrupt == INT_SYSCALL) { | ||
int syscall_num = cpu->eax; | ||
int result; | ||
if (syscall_num >= NUM_SYSCALLS || syscall_table[syscall_num] == NULL) { | ||
result = _ENOSYS; | ||
} else { | ||
result = syscall_table[syscall_num](cpu->ebx, cpu->ecx, cpu->edx, cpu->esi, cpu->edi, cpu->ebp); | ||
} | ||
cpu->eax = result; | ||
} else { | ||
printf("interrupt %d, exiting\n", interrupt); | ||
sys_exit(interrupt); | ||
} | ||
} | ||
|
||
int user_get_string(addr_t addr, char *buf, size_t max) { | ||
size_t i = 0; | ||
while (i < max) { | ||
buf[i] = MEM_GET(¤t->cpu, addr + i, 8); | ||
if (buf[i] == '\0') break; | ||
i++; | ||
} | ||
return i; | ||
} | ||
|
||
int user_get_count(addr_t addr, char *buf, size_t count) { | ||
size_t i = 0; | ||
while (i < count) { | ||
buf[i] = MEM_GET(¤t->cpu, addr + i, 8); | ||
i++; | ||
} | ||
return i; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,20 @@ | ||
#include "emu/cpu.h" | ||
#include "emu/interrupt.h" | ||
#include "misc.h" | ||
|
||
void handle_interrupt(struct cpu_state *cpu, int interrupt); | ||
|
||
int user_get_string(addr_t addr, char *buf, size_t max); | ||
int user_get_count(addr_t addr, char *buf, size_t count); | ||
|
||
int sys_execve(const char *file, char *const argv[], char *const envp[]); | ||
int _sys_execve(addr_t file, addr_t argv, addr_t envp); | ||
|
||
int sys_exit(dword_t status); | ||
|
||
ssize_t sys_write(int fd, const char *buf, size_t count); | ||
dword_t _sys_write(dword_t fd, addr_t data, dword_t count); | ||
|
||
typedef int (*syscall_t)(dword_t,dword_t,dword_t,dword_t,dword_t,dword_t); | ||
|
||
#define NUM_SYSCALLS (sizeof(syscall_table)/sizeof(syscall_table[0])) |
Oops, something went wrong.