Compare commits
2 Commits
d47709b03c
...
7c8c2e2dc2
| Author | SHA1 | Date | |
|---|---|---|---|
| 7c8c2e2dc2 | |||
| 9163857e83 |
@ -17,6 +17,15 @@ void *memset(void* s, int c, unsigned long n) {
|
|||||||
}
|
}
|
||||||
#endif // !MEMSET_DEFINED
|
#endif // !MEMSET_DEFINED
|
||||||
|
|
||||||
|
#ifndef _STRLEN_DEFINED
|
||||||
|
#define _STRLEN_DEFINED
|
||||||
|
int strlen(char* s) {
|
||||||
|
int len = 0;
|
||||||
|
for(;s[len] != 0; ++len);
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
#endif // !_STRLEN_DEFINED
|
||||||
|
|
||||||
#ifndef _START_DEFINED
|
#ifndef _START_DEFINED
|
||||||
#define _START_DEFINED
|
#define _START_DEFINED
|
||||||
// Generic _start implementation. Can't access any args
|
// Generic _start implementation. Can't access any args
|
||||||
|
|||||||
@ -1,8 +1,25 @@
|
|||||||
#if defined(__x86_64__)
|
#if defined(__x86_64__)
|
||||||
#include "../int.h"
|
#include "../int.h"
|
||||||
|
#include "../sys.h"
|
||||||
|
|
||||||
|
// Start code
|
||||||
|
#ifndef _START_DEFINED
|
||||||
|
#define _START_DEFINED
|
||||||
|
extern int main(int argc, char** argv);
|
||||||
|
void _start() {
|
||||||
|
void* fp = __builtin_frame_address(0);
|
||||||
|
register int argc asm("rdi") = *(uint64_t*)(fp+8);
|
||||||
|
register char** argv asm("rsi") = fp+16;
|
||||||
|
exit(main(argc, argv));
|
||||||
|
}
|
||||||
|
#endif /* ifndef _START_DEFINED */
|
||||||
|
|
||||||
|
//include other generic functions
|
||||||
#include "generic.h"
|
#include "generic.h"
|
||||||
|
|
||||||
|
//
|
||||||
|
// syscall functions
|
||||||
|
|
||||||
#define SYS_EXIT 60
|
#define SYS_EXIT 60
|
||||||
void exit(int8_t status) {
|
void exit(int8_t status) {
|
||||||
asm volatile(
|
asm volatile(
|
||||||
@ -243,4 +260,17 @@ int clock_nanosleep(clockid_t clockid, int flags, const struct timespec *t, stru
|
|||||||
return rtn;
|
return rtn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define SYS_RT_SIGACTION 13
|
||||||
|
int rt_sigaction(int signum, const void* act, void* oldact, size_t sigset_len) {
|
||||||
|
int rtn;
|
||||||
|
asm volatile(
|
||||||
|
"mov %5, %%r10\n"
|
||||||
|
"syscall\n"
|
||||||
|
: "=a"(rtn)
|
||||||
|
: "a"(SYS_RT_SIGACTION), "D"(signum), "S"(act), "d"(oldact), "r"(sigset_len)
|
||||||
|
: "rcx", "r11", "memory"
|
||||||
|
);
|
||||||
|
return rtn;
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* ifdef __x86_64__ */
|
#endif /* ifdef __x86_64__ */
|
||||||
|
|||||||
@ -2,11 +2,18 @@
|
|||||||
#include "sys.h"
|
#include "sys.h"
|
||||||
|
|
||||||
|
|
||||||
int main() {
|
int main(int argc, char* argv[]) {
|
||||||
// Test the write syscall
|
// Test the write syscall
|
||||||
intptr_t n = write(STDOUT, "Hello\n", 6);
|
intptr_t n = write(STDOUT, "Hello\n", 6);
|
||||||
if(n != 6) return n;
|
if(n != 6) return n;
|
||||||
|
|
||||||
|
// Test argc
|
||||||
|
for(int i = 0; i < argc; ++i){
|
||||||
|
int len = strlen(argv[i]);
|
||||||
|
write(STDOUT, argv[i], len);
|
||||||
|
write(STDOUT, "\n", 1);
|
||||||
|
}
|
||||||
|
|
||||||
// Test the fork syscall
|
// Test the fork syscall
|
||||||
uint64_t pid = fork();
|
uint64_t pid = fork();
|
||||||
// Print the pid in hex
|
// Print the pid in hex
|
||||||
|
|||||||
1
sys.h
1
sys.h
@ -143,5 +143,6 @@ int clock_nanosleep(clockid_t clockid, int flags, const struct timespec *t, stru
|
|||||||
uint32_t fork();
|
uint32_t fork();
|
||||||
|
|
||||||
void *memset(void* s, int c, unsigned long n);
|
void *memset(void* s, int c, unsigned long n);
|
||||||
|
int strlen(char* s);
|
||||||
|
|
||||||
#endif // !MINIMALSYS_H
|
#endif // !MINIMALSYS_H
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user