Skip to content
Snippets Groups Projects
Commit 7b1c7048 authored by ja3-saxby's avatar ja3-saxby
Browse files

Not-quite-working implementation of write()

parent 69dafab7
No related branches found
No related tags found
2 merge requests!22Merge Feature/system calls,!10Implement the write() system call
#ifndef __LIB_KERNEL_STDIO_H
#define __LIB_KERNEL_STDIO_H
#include <stddef.h>
void putbuf (const char *, size_t);
......
......@@ -3,10 +3,29 @@
*
* Authored by Joshua Saxby
*/
#include <stdio.h>
#include "lib/kernel/stdio.h"
#include "system_calls.h"
#include "threads/interrupt.h"
void syscall_write(struct intr_frame *f) {
// TODO: implement me!
(void*)0;
// first argument is syscall code (already handled)
int fd = *((int*)f->esp + 1); // file descriptor is second argument
void* buffer = (void*)(*((int*)f->esp + 2)); // buffer is third argument
unsigned size = *((unsigned*)((int*)f->esp + 3)); // size to write is fourth
printf("syscall_write: fd = %d\n", fd);
printf("syscall_write: buffer = '%s'\n", buffer);
printf("syscall_write: size = %u\n", size);
// writing to stdout or stderr (fd in {1, 2}) is a special case
switch (fd) {
case 1:
// case 2:
// TODO: split up output into reasonable-sized chunks
putbuf((const char*)buffer, size);
f->eax = size;
break;
default:
// XXX: unimplemented for now
break;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment