SimpleOS

LXR

Navigation



Site hébergé par : enix

The LXR Cross Referencer for SOS

source navigation ]
diff markup ]
identifier search ]
general search ]
 
 
Article:1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 6.5 ] [ 7 ] [ 7.5 ] [ 8 ] [ 9 ] [ 9.5 ]

001 /* Copyright (C) 2005  David Decotigny
002 
003    This program is free software; you can redistribute it and/or
004    modify it under the terms of the GNU General Public License
005    as published by the Free Software Foundation; either version 2
006    of the License, or (at your option) any later version.
007    
008    This program is distributed in the hope that it will be useful,
009    but WITHOUT ANY WARRANTY; without even the implied warranty of
010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
011    GNU General Public License for more details.
012    
013    You should have received a copy of the GNU General Public License
014    along with this program; if not, write to the Free Software
015    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
016    USA. 
017 */
018 #include <sos/thread.h>
019 #include <sos/kmalloc.h>
020 #include <sos/klibc.h>
021 #include <drivers/bochs.h>
022 
023 #include <hwcore/cpu_context.h>
024 #include <sos/uaccess.h>
025 #include "syscall.h"
026 
027 
028 /**
029  * THE syscall entry point
030  */
031 sos_ret_t sos_do_syscall(int syscall_id,
032                          const struct sos_cpu_state *user_ctxt)
033 {
034   sos_ret_t retval;
035 
036   switch(syscall_id)
037     {
038     case SOS_SYSCALL_ID_EXIT:
039       {
040         unsigned int status;
041         retval = sos_syscall_get1arg(user_ctxt, & status);
042         if (SOS_OK != retval)
043           break;
044         sos_thread_exit();
045         retval = -SOS_EFATAL; /* Not reached */
046       }
047       break;
048     case SOS_SYSCALL_ID_BOCHS_WRITE:
049       {
050         sos_uaddr_t user_str;
051         sos_size_t len;
052         char * str;
053         retval = sos_syscall_get2args(user_ctxt, & user_str, & len);
054         if (SOS_OK != retval)
055           break;
056 
057         str = (char*)sos_kmalloc(len + 1, 0);
058         if (str)
059           {
060             retval = sos_strzcpy_from_user(str, user_str, len+1);
061             str[len] = '\0';
062             if (SOS_OK == retval)
063               {
064                 sos_bochs_printf("THR 0x%x: ",
065                                  (unsigned)sos_thread_get_current());
066                 retval = sos_bochs_putstring(str);
067                 retval = len;
068               }
069             sos_kfree((sos_vaddr_t)str);
070           }
071         else
072           retval = -SOS_ENOMEM;
073       }
074       break;
075 
076 
077       /* ***********************************************
078        * Debug syscalls (will be removed in the future)
079        */
080 
081 
082       /**
083        * Syscall 4012: hexdump of a user-space memory region
084        * args: addr_start size, retval=ignored
085        */
086     case 4012:
087       {
088         sos_uaddr_t user_str;
089         unsigned int len;
090         unsigned char * str;
091 
092         retval = sos_syscall_get2args(user_ctxt, & user_str, & len);
093         if (SOS_OK != retval)
094           break;
095 
096         str = (char*)sos_kmalloc(len + 1, 0);
097         if (str)
098           {
099             int i;
100             sos_bochs_printf("Hexdump(0x%x, %d):\n", user_str, len);
101             retval = sos_memcpy_from_user((sos_vaddr_t) str, user_str, len);
102             sos_bochs_printf("  (Successfully copied %d out of %d)\n",
103                              retval, len);
104 
105             for (i = 0 ; i < retval ; i++)
106               {
107                 if ((i % 32) == 0)
108                   sos_bochs_printf("%x:", i);
109                 sos_bochs_printf(" %x", str[i]);
110                 if (((i+1) % 32) == 0)
111                   sos_bochs_printf("\n");
112               }
113             if (i % 32)
114               sos_bochs_printf("\n");
115 
116             sos_kfree((sos_vaddr_t)str);
117           }
118         else
119           retval = -SOS_ENOMEM;
120       }
121       break;
122 
123 
124       /**
125        * Syscall 4008: dump the list of processes in the system
126        * args: none, retval=ignored
127        */
128     case 4008:
129       {
130         extern void sos_process_dumplist(void);
131         sos_process_dumplist();
132         retval = SOS_OK;
133       }
134       break;
135 
136     default:
137       sos_bochs_printf("Syscall: UNKNOWN[%d]\n", syscall_id);
138       retval = -SOS_ENOSUP;
139     }
140   
141   return retval;
142 }

source navigation ] diff markup ] identifier search ] general search ]