source: trunk/hal/tsar_mips32/hal_do_syscall.c @ 26

Last change on this file since 26 was 1, checked in by alain, 8 years ago

First import

File size: 2.7 KB
Line 
1/*
2 * hal_do_syscall.c - implementation of syscall handler for TSAR-MIPS32
3 *
4 * Author   Ghassan Almaless (2008,2009,2010,2011,2012)
5 *
6 * Copyright (c) UPMC Sorbonne Universites
7 *
8 * This file is part of ALMOS-MKH.
9 *
10 * ALMOS-MKH.is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; version 2.0 of the License.
13 *
14 * ALMOS-MKH.is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with ALMOS-MKH.; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24#include <errno.h>
25#include <syscall.h>
26#include <cpu.h>
27#include <pmm.h>
28#include <thread.h>
29#include <task.h>
30#include <interrupt.h>
31#include <kdmsg.h>
32#include <cpu-regs.h>
33
34extern reg_t do_syscall( reg_t arg0,
35                                     reg_t arg1,
36                                     reg_t arg2,
37                                     reg_t arg3,
38                                     reg_t service_nr );
39
40///////////////////////////
41static void sys_sigreturn()
42{
43        register thread_t * this;
44        register uint32_t   uzone_src;
45 
46        this = CURRENT_THREAD;
47 
48        uzone_src  = this->pws.sigstack_top;
49        uzone_src -= sizeof(this->uzone);
50 
51        hal_copy_from_uspace( &this->uzone, 
52                          (void*)uzone_src, 
53                          sizeof(this->uzone) );
54
55        if(err)
56        {
57                printk(WARNING, "WARNING: %s: CPU %d, Task %d, Thread %d (%x) [ KILLED ]\n", 
58                       __FUNCTION__, 
59                       hal_get_id(), 
60                       this->task->pid, 
61                       this->info.order,
62                       this);
63
64                sys_thread_exit((void*)EINTR);
65        }
66
67        if(current_cpu->fpu_owner == this)
68        {
69                current_cpu->fpu_owner = NULL;
70                hal_fpu_disable();
71        }
72
73        thread_clear_signaled(this);
74
75        this->uzone.regs[V0]   = this->info.retval;
76        this->uzone.regs[V1]   = this->info.errno;
77        this->uzone.regs[EPC] += 4;
78}
79
80/////////////////////////////////////////////
81thread_t * hal_do_syscall( reg_t * regs_tbl )
82{
83        register reg_t      arg0;
84        register reg_t      arg1;
85        register reg_t      arg2;
86        register reg_t      arg3;
87        register reg_t      service_nr;
88        register reg_t      retval;
89        register thread_t * this;
90 
91        service_nr = regs_tbl[V0];
92
93        if(service_nr == SYS_SIGRETURN)
94        {
95                sys_sigreturn();
96                return CURRENT_THREAD;
97        }
98
99        arg0 = regs_tbl[A0];
100        arg1 = regs_tbl[A1];
101        arg2 = regs_tbl[A2];
102        arg3 = regs_tbl[A3];
103 
104        retval = do_syscall( arg0 , arg1 , arg2 , arg3 , service_nr );
105
106        this   = CURRENT_THREAD;
107 
108        this->uzone.regs[V0]   = retval;
109        this->uzone.regs[V1]   = this->info.errno;
110        this->uzone.regs[EPC] += 4;
111
112        return this;
113}
Note: See TracBrowser for help on using the repository browser.