Added errno support
authorAndrew Waterman <waterman@ubuntu.(none)>
Sun, 3 Jan 2010 01:02:07 +0000 (17:02 -0800)
committerAndrew Waterman <waterman@ubuntu.(none)>
Sun, 3 Jan 2010 01:02:07 +0000 (17:02 -0800)
kern/arch/sparc/console.c
kern/arch/sparc/frontend.c
kern/arch/sparc/frontend.h
kern/arch/sparc/trap.c
kern/arch/sparc/trap.h

index e466b2f..d2ca4c2 100644 (file)
@@ -11,7 +11,8 @@ cons_init(void)
 void
 cputbuf(const char*COUNT(len) buf, int len)
 {
-       frontend_syscall(0,RAMP_SYSCALL_write,1,PADDR((int32_t)buf),len);
+       int32_t errno;
+       frontend_syscall(0,RAMP_SYSCALL_write,1,PADDR((int32_t)buf),len,&errno);
 }
 
 // Low-level console I/O
@@ -42,8 +43,11 @@ int
 cons_getc()
 {
        char ch;
-       int32_t ret = frontend_syscall(0,RAMP_SYSCALL_read,0,(int32_t)&ch,1);
-       return ret < 0 ? 0 : ch;
+       int32_t errno;
+       int32_t ret = frontend_syscall(0,RAMP_SYSCALL_read,0,PADDR((int32_t)&ch),1,&errno);
+       if(ch == 0x7F)
+               ch = '\b';
+       return ret <= 0 ? 0 : ch;
        //int ret = sys_nbgetch();
        //return ret < 0 ? 0 : ret;
 }
index 92d442b..d91f1e1 100644 (file)
@@ -36,12 +36,15 @@ int32_t frontend_syscall_from_user(env_t* p, int32_t syscall_num, uint32_t arg0,
                }
        }
 
-       int32_t ret = frontend_syscall(p->pid,syscall_num,arg[0],arg[1],arg[2]);
+       int32_t errno;
+       int32_t ret = frontend_syscall(p->pid,syscall_num,arg[0],arg[1],arg[2],&errno);
+       set_errno(current_tf,errno);
+
        spin_unlock_irqsave(&lock);
        return ret;
 }
 
-int32_t frontend_syscall(pid_t pid, int32_t syscall_num, uint32_t arg0, uint32_t arg1, uint32_t arg2)
+int32_t frontend_syscall(pid_t pid, int32_t syscall_num, uint32_t arg0, uint32_t arg1, uint32_t arg2, int32_t* errno)
 {
        static spinlock_t lock = SPINLOCK_INITIALIZER;
        int32_t ret;
@@ -65,6 +68,7 @@ int32_t frontend_syscall(pid_t pid, int32_t syscall_num, uint32_t arg0, uint32_t
                ;
 
        ret = magic_mem[1];
+       *errno = magic_mem[2];
 
        spin_unlock_irqsave(&lock);
 
@@ -105,7 +109,8 @@ int32_t sys_nbgetch()
 
 void __diediedie(trapframe_t* tf, uint32_t srcid, uint32_t code, uint32_t a1, uint32_t a2)
 {
-       frontend_syscall(0,RAMP_SYSCALL_exit,(int)code,0,0);
+       int32_t errno;
+       frontend_syscall(0,RAMP_SYSCALL_exit,(int)code,0,0,&errno);
        while(1);
 }
 
index 8d9de6a..83ebd5a 100644 (file)
@@ -7,7 +7,7 @@
 
 #include <env.h>
 int32_t frontend_syscall_from_user(env_t* p, int32_t syscall_num, uint32_t arg0, uint32_t arg1, uint32_t arg2, uint32_t translate_args);
-int32_t frontend_syscall(pid_t pid, int32_t syscall_num, uint32_t arg0, uint32_t arg1, uint32_t arg2);
+int32_t frontend_syscall(pid_t pid, int32_t syscall_num, uint32_t arg0, uint32_t arg1, uint32_t arg2, int32_t* errno);
 
 int32_t sys_nbgetch();
 int32_t sys_nbputch(char ch);
@@ -24,10 +24,16 @@ int32_t sys_nbputch(char ch);
 #define RAMP_SYSCALL_link              9
 #define RAMP_SYSCALL_unlink            10
 #define RAMP_SYSCALL_chdir             12
+#define RAMP_SYSCALL_chmod             15
 #define RAMP_SYSCALL_brk               17
 #define RAMP_SYSCALL_stat              18
 #define RAMP_SYSCALL_lseek             19
 #define RAMP_SYSCALL_fstat             28
+#define RAMP_SYSCALL_utime             30
+#define RAMP_SYSCALL_access            33
+#define RAMP_SYSCALL_dup               41
+#define RAMP_SYSCALL_umask             60
+#define RAMP_SYSCALL_fcntl             62
 #define RAMP_SYSCALL_lstat             88
 #define RAMP_SYSCALL_closedir          91
 #define RAMP_SYSCALL_rewinddir         92
index d860203..865a716 100644 (file)
@@ -280,6 +280,11 @@ handle_syscall(trapframe_t* state)
        //if(current->vcoremap[0] == core_id())
        //      env_push_ancillary_state(current); // remove this if you don't need it
 
+       // some syscalls don't return this way if they succed,
+       // e.g. run_binary.  so by default set the return value to success
+       state->gpr[8] = 0;
+       set_errno(current_tf,0);
+
        // syscall code wants an edible reference for current
        proc_incref(current, 1);
        state->gpr[8] = syscall(current,num,a1,a2,a3,a4,a5);
index 5f583f1..c13ec69 100644 (file)
@@ -37,6 +37,11 @@ void save_fp_state(ancillary_state_t* silly);
 void restore_fp_state(ancillary_state_t* silly);
 void emulate_fpu(trapframe_t* state, ancillary_state_t* astate);
 
+static inline void set_errno(trapframe_t* tf, uint32_t errno)
+{
+       tf->gpr[9] = errno;
+}
+
 #endif /* !__ASSEMBLER__ */
 
 #endif /* !ROS_INC_ARCH_TRAP_H */