Fixed uninitialised n_chunks in untested vpcreate
[marionette.git] / kernel / syscall.c
blob55b64b14957d65a307a5b59e0499b629f3535625
1 /*
2 * Copyright (c) 2009 Joshua Phillips. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the
13 * distribution.
15 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
16 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 * DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
19 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
21 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
23 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
25 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #include "syscall.h"
29 #include "string.h"
30 #include "interrupt.h"
31 #include "trace.h"
32 #include "exit.h"
34 static const syscall_t syscall_table[] = {
35 NULL,
36 sys_exit,
39 static const int n_syscalls = sizeof syscall_table / sizeof *syscall_table;
41 static void syscall_handler(int vector, struct interrupt_stack *is)
43 int syscall_n = is->r.eax;
44 struct syscall_args args;
45 if (syscall_n < 0 || syscall_n >= n_syscalls
46 || !syscall_table[syscall_n]){
47 TRACE("Invalid syscall: %d", syscall_n);
48 is->r.eax = -1;
49 // TODO: set errno (HOW? Where?)
50 } else {
51 // get the system call arguments from the registers
52 args.args[0].ui = is->r.ebx;
53 args.args[1].ui = is->r.ecx;
54 args.args[2].ui = is->r.edx;
55 args.args[3].ui = is->r.esi;
56 args.args[4].ui = is->r.edi;
57 is->r.eax = syscall_table[syscall_n](&args);
58 TRACE("Done syscall: returning to %.8X", is->eip);
62 void syscall_init(void)
64 set_interrupt(0x80, syscall_handler);
65 interrupt_flags(0x80, INTR_USER);