Compare commits
No commits in common. "bee58d964282c7fc5f198d14b8bca3fa923179fc" and "b0a192ce7c0f7bd92beed22abdbd8b23ebdac5c7" have entirely different histories.
bee58d9642
...
b0a192ce7c
@ -22,8 +22,8 @@ int syscallExecute(int syscallId, const struct cpu_state *userCtx)
|
||||
assert(0);
|
||||
break;
|
||||
}
|
||||
case SYSCALL_ID_HELO:
|
||||
ret = printf("HELLO FROM USERSPACE\n");
|
||||
case SYSCALL_ID_YOLO:
|
||||
ret = printf("YOLO FROM USERSPACE\n");
|
||||
break;
|
||||
case SYSCALL_ID_PUTC: {
|
||||
unsigned int c;
|
||||
|
@ -4,7 +4,7 @@
|
||||
#endif
|
||||
|
||||
#define SYSCALL_ID_EXIT 1
|
||||
#define SYSCALL_ID_HELO 2
|
||||
#define SYSCALL_ID_YOLO 2
|
||||
#define SYSCALL_ID_PUTC 3
|
||||
#define SYSCALL_ID_READ 4
|
||||
#define SYSCALL_ID_TEST 5
|
||||
|
@ -399,7 +399,7 @@ static void userProgramm()
|
||||
"int %5\n"
|
||||
"movl %%eax, %0"
|
||||
: "=g"(ret)
|
||||
: "g"(SYSCALL_ID_HELO), "g"(0), "g"(0), "g"(0), "i"(SYSCALL_INTR_NB)
|
||||
: "g"(SYSCALL_ID_YOLO), "g"(0), "g"(0), "g"(0), "i"(SYSCALL_INTR_NB)
|
||||
: "eax", "ebx", "ecx", "edx");
|
||||
asm volatile("movl %1,%%eax \n"
|
||||
"movl %2,%%ebx \n"
|
||||
|
@ -4,7 +4,7 @@
|
||||
#endif
|
||||
|
||||
#define SYSCALL_ID_EXIT 1
|
||||
#define SYSCALL_ID_HELO 2
|
||||
#define SYSCALL_ID_YOLO 2
|
||||
#define SYSCALL_ID_PUTC 3
|
||||
#define SYSCALL_ID_READ 4
|
||||
#define SYSCALL_ID_TEST 5
|
||||
|
@ -449,19 +449,16 @@ int vasprintf(char **strp, const char *fmt, va_list ap)
|
||||
|
||||
n = vsnprintf(p, size, fmt, ap);
|
||||
|
||||
if (n < 0){
|
||||
free(p);
|
||||
if (n < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* One extra byte for '\0' */
|
||||
|
||||
size = min(256U, (size_t)n + 1);
|
||||
size = min(256U,(size_t)n + 1);
|
||||
|
||||
n = vsnprintf(p, size, fmt, ap);
|
||||
|
||||
if (n < 0) {
|
||||
free(p);
|
||||
return -1;
|
||||
}
|
||||
*strp = p;
|
||||
@ -524,9 +521,9 @@ int putc(const int c){
|
||||
return syscall1(SYSCALL_ID_PUTC, c);
|
||||
}
|
||||
|
||||
void helo()
|
||||
void yolo()
|
||||
{
|
||||
syscall0(SYSCALL_ID_HELO);
|
||||
syscall0(SYSCALL_ID_YOLO);
|
||||
}
|
||||
|
||||
int testSycall5(uint arg1, uint arg2, uint arg3, uint arg4, uint arg5)
|
||||
@ -574,38 +571,23 @@ void *brk(void *addr)
|
||||
return (void *)syscall1(SYSCALL_ID_BRK, (unsigned int)addr);
|
||||
}
|
||||
|
||||
static char *heapTop = 0;
|
||||
static char *heapFree = 0;
|
||||
static char *lastAlloc = 0;
|
||||
|
||||
void *malloc(size_t size)
|
||||
{
|
||||
void *heapTop = 0;
|
||||
static void *free = 0;
|
||||
|
||||
if (heapTop == 0) {
|
||||
heapTop = heapFree = brk(0);
|
||||
heapTop = brk(0);
|
||||
free = heapTop;
|
||||
} else {
|
||||
heapTop = brk(0);
|
||||
}
|
||||
|
||||
if (heapFree + size + sizeof(size) > heapTop) {
|
||||
if (brk(heapTop + size + sizeof(size)))
|
||||
if (free + size > heapTop) {
|
||||
if (brk(heapTop + size))
|
||||
return NULL;
|
||||
}
|
||||
|
||||
*((size_t *)heapFree) = size;
|
||||
heapFree += sizeof(size);
|
||||
lastAlloc = heapFree;
|
||||
heapFree += size;
|
||||
return lastAlloc;
|
||||
}
|
||||
|
||||
void free(void *ptr)
|
||||
{
|
||||
void *size_addr = ((char *)ptr - sizeof(size_t));
|
||||
size_t size = *(size_t *)size_addr;
|
||||
if (heapFree - size == ptr) {
|
||||
heapFree = size_addr;
|
||||
}
|
||||
//TODO ELSE
|
||||
|
||||
return;
|
||||
free += size;
|
||||
return (free - size);
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ int vsnprintf(char *str, size_t size, const char *format, va_list ap) __attribut
|
||||
int vprintf(const char *format, va_list ap) __attribute__ ((__format__ (printf, 1, 0)));
|
||||
int printf(const char *format, ...) __attribute__ ((__format__ (printf, 1, 2)));
|
||||
|
||||
// Could be used after malloc is available
|
||||
int asprintf(char **strp, const char *fmt, ...) __attribute__ ((__format__ (printf, 2, 3)));
|
||||
int vasprintf(char **strp, const char *fmt, va_list ap) __attribute__ ((__format__ (printf, 2, 0)));
|
||||
|
||||
@ -41,11 +42,10 @@ int syscall1(int id, unsigned int arg1);
|
||||
int syscall0(int id);
|
||||
|
||||
void _exit(int status);
|
||||
void helo();
|
||||
void yolo();
|
||||
int testSycall5(uint arg1, uint arg2, uint arg3, uint arg4, uint arg5);
|
||||
char readc();
|
||||
char getchar();
|
||||
int readline(char *buf, int size);
|
||||
void *brk(void *addr);
|
||||
void *malloc(size_t size);
|
||||
void free(void *ptr);
|
||||
|
Loading…
x
Reference in New Issue
Block a user