| 1 |
1624 |
jcastillo |
/* $Id: process.c,v 1.1 2005-12-20 09:50:43 jcastillo Exp $
|
| 2 |
|
|
* linux/arch/sparc/kernel/process.c
|
| 3 |
|
|
*
|
| 4 |
|
|
* Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
|
| 5 |
|
|
*/
|
| 6 |
|
|
|
| 7 |
|
|
/*
|
| 8 |
|
|
* This file handles the architecture-dependent parts of process handling..
|
| 9 |
|
|
*/
|
| 10 |
|
|
|
| 11 |
|
|
#define __KERNEL_SYSCALLS__
|
| 12 |
|
|
#include <stdarg.h>
|
| 13 |
|
|
|
| 14 |
|
|
#include <linux/errno.h>
|
| 15 |
|
|
#include <linux/sched.h>
|
| 16 |
|
|
#include <linux/kernel.h>
|
| 17 |
|
|
#include <linux/mm.h>
|
| 18 |
|
|
#include <linux/stddef.h>
|
| 19 |
|
|
#include <linux/unistd.h>
|
| 20 |
|
|
#include <linux/ptrace.h>
|
| 21 |
|
|
#include <linux/malloc.h>
|
| 22 |
|
|
#include <linux/ldt.h>
|
| 23 |
|
|
#include <linux/user.h>
|
| 24 |
|
|
#include <linux/a.out.h>
|
| 25 |
|
|
|
| 26 |
|
|
#include <asm/auxio.h>
|
| 27 |
|
|
#include <asm/oplib.h>
|
| 28 |
|
|
#include <asm/segment.h>
|
| 29 |
|
|
#include <asm/system.h>
|
| 30 |
|
|
#include <asm/page.h>
|
| 31 |
|
|
#include <asm/pgtable.h>
|
| 32 |
|
|
#include <asm/delay.h>
|
| 33 |
|
|
#include <asm/processor.h>
|
| 34 |
|
|
#include <asm/psr.h>
|
| 35 |
|
|
#include <asm/system.h>
|
| 36 |
|
|
|
| 37 |
|
|
extern void fpsave(unsigned long *, unsigned long *, void *, unsigned long *);
|
| 38 |
|
|
|
| 39 |
|
|
int active_ds = USER_DS;
|
| 40 |
|
|
|
| 41 |
|
|
#ifndef __SMP__
|
| 42 |
|
|
|
| 43 |
|
|
/*
|
| 44 |
|
|
* the idle loop on a Sparc... ;)
|
| 45 |
|
|
*/
|
| 46 |
|
|
asmlinkage int sys_idle(void)
|
| 47 |
|
|
{
|
| 48 |
|
|
if (current->pid != 0)
|
| 49 |
|
|
return -EPERM;
|
| 50 |
|
|
|
| 51 |
|
|
/* endless idle loop with no priority at all */
|
| 52 |
|
|
current->counter = -100;
|
| 53 |
|
|
for (;;) {
|
| 54 |
|
|
schedule();
|
| 55 |
|
|
}
|
| 56 |
|
|
return 0;
|
| 57 |
|
|
}
|
| 58 |
|
|
|
| 59 |
|
|
#else
|
| 60 |
|
|
|
| 61 |
|
|
/*
|
| 62 |
|
|
* the idle loop on a SparcMultiPenguin...
|
| 63 |
|
|
*/
|
| 64 |
|
|
asmlinkage int sys_idle(void)
|
| 65 |
|
|
{
|
| 66 |
|
|
if (current->pid != 0)
|
| 67 |
|
|
return -EPERM;
|
| 68 |
|
|
|
| 69 |
|
|
/* endless idle loop with no priority at all */
|
| 70 |
|
|
current->counter = -100;
|
| 71 |
|
|
schedule();
|
| 72 |
|
|
return 0;
|
| 73 |
|
|
}
|
| 74 |
|
|
|
| 75 |
|
|
/* This is being executed in task 0 'user space'. */
|
| 76 |
|
|
int cpu_idle(void *unused)
|
| 77 |
|
|
{
|
| 78 |
|
|
volatile int *spap = &smp_process_available;
|
| 79 |
|
|
volatile int cval;
|
| 80 |
|
|
|
| 81 |
|
|
while(1) {
|
| 82 |
|
|
if(0==read_smp_counter(spap))
|
| 83 |
|
|
continue;
|
| 84 |
|
|
cli();
|
| 85 |
|
|
/* Acquire exclusive access. */
|
| 86 |
|
|
while((cval = smp_swap(spap, -1)) == -1)
|
| 87 |
|
|
;
|
| 88 |
|
|
if (0==cval) {
|
| 89 |
|
|
/* ho hum, release it. */
|
| 90 |
|
|
smp_process_available = 0;
|
| 91 |
|
|
sti();
|
| 92 |
|
|
continue;
|
| 93 |
|
|
}
|
| 94 |
|
|
/* Something interesting happened, whee... */
|
| 95 |
|
|
smp_swap(spap, (cval - 1));
|
| 96 |
|
|
sti();
|
| 97 |
|
|
idle();
|
| 98 |
|
|
}
|
| 99 |
|
|
}
|
| 100 |
|
|
|
| 101 |
|
|
#endif
|
| 102 |
|
|
|
| 103 |
|
|
extern char saved_command_line[];
|
| 104 |
|
|
|
| 105 |
|
|
void hard_reset_now(void)
|
| 106 |
|
|
{
|
| 107 |
|
|
sti();
|
| 108 |
|
|
udelay(8000);
|
| 109 |
|
|
cli();
|
| 110 |
|
|
prom_feval("reset");
|
| 111 |
|
|
panic("Reboot failed!");
|
| 112 |
|
|
}
|
| 113 |
|
|
|
| 114 |
|
|
void show_regwindow(struct reg_window *rw)
|
| 115 |
|
|
{
|
| 116 |
|
|
printk("l0:%08lx l1:%08lx l2:%08lx l3:%08lx l4:%08lx l5:%08lx l6:%08lx l7:%08lx\n",
|
| 117 |
|
|
rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
|
| 118 |
|
|
rw->locals[4], rw->locals[5], rw->locals[6], rw->locals[7]);
|
| 119 |
|
|
printk("i0:%08lx i1:%08lx i2:%08lx i3:%08lx i4:%08lx i5:%08lx i6:%08lx i7:%08lx\n",
|
| 120 |
|
|
rw->ins[0], rw->ins[1], rw->ins[2], rw->ins[3],
|
| 121 |
|
|
rw->ins[4], rw->ins[5], rw->ins[6], rw->ins[7]);
|
| 122 |
|
|
}
|
| 123 |
|
|
|
| 124 |
|
|
void show_regs(struct pt_regs * regs)
|
| 125 |
|
|
{
|
| 126 |
|
|
printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx\n", regs->psr,
|
| 127 |
|
|
regs->pc, regs->npc, regs->y);
|
| 128 |
|
|
printk("%%g0: %08lx %%g1: %08lx %%g2: %08lx %%g3: %08lx\n",
|
| 129 |
|
|
regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
|
| 130 |
|
|
regs->u_regs[3]);
|
| 131 |
|
|
printk("%%g4: %08lx %%g5: %08lx %%g6: %08lx %%g7: %08lx\n",
|
| 132 |
|
|
regs->u_regs[4], regs->u_regs[5], regs->u_regs[6],
|
| 133 |
|
|
regs->u_regs[7]);
|
| 134 |
|
|
printk("%%o0: %08lx %%o1: %08lx %%o2: %08lx %%o3: %08lx\n",
|
| 135 |
|
|
regs->u_regs[8], regs->u_regs[9], regs->u_regs[10],
|
| 136 |
|
|
regs->u_regs[11]);
|
| 137 |
|
|
printk("%%o4: %08lx %%o5: %08lx %%sp: %08lx %%ret_pc: %08lx\n",
|
| 138 |
|
|
regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
|
| 139 |
|
|
regs->u_regs[15]);
|
| 140 |
|
|
}
|
| 141 |
|
|
|
| 142 |
|
|
/*
|
| 143 |
|
|
* Free current thread data structures etc..
|
| 144 |
|
|
*/
|
| 145 |
|
|
void exit_thread(void)
|
| 146 |
|
|
{
|
| 147 |
|
|
flush_user_windows();
|
| 148 |
|
|
#ifndef __SMP__
|
| 149 |
|
|
if(last_task_used_math == current) {
|
| 150 |
|
|
#else
|
| 151 |
|
|
if(current->flags & PF_USEDFPU) {
|
| 152 |
|
|
#endif
|
| 153 |
|
|
/* Keep process from leaving FPU in a bogon state. */
|
| 154 |
|
|
put_psr(get_psr() | PSR_EF);
|
| 155 |
|
|
fpsave(¤t->tss.float_regs[0], ¤t->tss.fsr,
|
| 156 |
|
|
¤t->tss.fpqueue[0], ¤t->tss.fpqdepth);
|
| 157 |
|
|
#ifndef __SMP__
|
| 158 |
|
|
last_task_used_math = NULL;
|
| 159 |
|
|
#else
|
| 160 |
|
|
current->flags &= ~PF_USEDFPU;
|
| 161 |
|
|
#endif
|
| 162 |
|
|
}
|
| 163 |
|
|
mmu_exit_hook();
|
| 164 |
|
|
}
|
| 165 |
|
|
|
| 166 |
|
|
/*
|
| 167 |
|
|
* Free old dead task when we know it can never be on the cpu again.
|
| 168 |
|
|
*/
|
| 169 |
|
|
void release_thread(struct task_struct *dead_task)
|
| 170 |
|
|
{
|
| 171 |
|
|
}
|
| 172 |
|
|
|
| 173 |
|
|
void flush_thread(void)
|
| 174 |
|
|
{
|
| 175 |
|
|
/* Make sure old user windows don't get in the way. */
|
| 176 |
|
|
flush_user_windows();
|
| 177 |
|
|
current->tss.w_saved = 0;
|
| 178 |
|
|
current->tss.uwinmask = 0;
|
| 179 |
|
|
current->tss.sig_address = 0;
|
| 180 |
|
|
current->tss.sig_desc = 0;
|
| 181 |
|
|
current->tss.sstk_info.cur_status = 0;
|
| 182 |
|
|
current->tss.sstk_info.the_stack = 0;
|
| 183 |
|
|
|
| 184 |
|
|
#ifndef __SMP__
|
| 185 |
|
|
if(last_task_used_math == current) {
|
| 186 |
|
|
#else
|
| 187 |
|
|
if(current->flags & PF_USEDFPU) {
|
| 188 |
|
|
#endif
|
| 189 |
|
|
/* Clean the fpu. */
|
| 190 |
|
|
put_psr(get_psr() | PSR_EF);
|
| 191 |
|
|
fpsave(¤t->tss.float_regs[0], ¤t->tss.fsr,
|
| 192 |
|
|
¤t->tss.fpqueue[0], ¤t->tss.fpqdepth);
|
| 193 |
|
|
#ifndef __SMP__
|
| 194 |
|
|
last_task_used_math = NULL;
|
| 195 |
|
|
#else
|
| 196 |
|
|
current->flags &= ~PF_USEDFPU;
|
| 197 |
|
|
#endif
|
| 198 |
|
|
}
|
| 199 |
|
|
|
| 200 |
|
|
memset(¤t->tss.reg_window[0], 0,
|
| 201 |
|
|
(sizeof(struct reg_window) * NSWINS));
|
| 202 |
|
|
memset(¤t->tss.rwbuf_stkptrs[0], 0,
|
| 203 |
|
|
(sizeof(unsigned long) * NSWINS));
|
| 204 |
|
|
mmu_flush_hook();
|
| 205 |
|
|
/* Now, this task is no longer a kernel thread. */
|
| 206 |
|
|
current->tss.flags &= ~SPARC_FLAG_KTHREAD;
|
| 207 |
|
|
}
|
| 208 |
|
|
|
| 209 |
|
|
/*
|
| 210 |
|
|
* Copy a Sparc thread. The fork() return value conventions
|
| 211 |
|
|
* under SunOS are nothing short of bletcherous:
|
| 212 |
|
|
* Parent --> %o0 == childs pid, %o1 == 0
|
| 213 |
|
|
* Child --> %o0 == parents pid, %o1 == 1
|
| 214 |
|
|
*
|
| 215 |
|
|
* NOTE: We have a separate fork kpsr/kwim because
|
| 216 |
|
|
* the parent could change these values between
|
| 217 |
|
|
* sys_fork invocation and when we reach here
|
| 218 |
|
|
* if the parent should sleep while trying to
|
| 219 |
|
|
* allocate the task_struct and kernel stack in
|
| 220 |
|
|
* do_fork().
|
| 221 |
|
|
*/
|
| 222 |
|
|
extern void ret_sys_call(void);
|
| 223 |
|
|
|
| 224 |
|
|
void copy_thread(int nr, unsigned long clone_flags, unsigned long sp,
|
| 225 |
|
|
struct task_struct *p, struct pt_regs *regs)
|
| 226 |
|
|
{
|
| 227 |
|
|
struct pt_regs *childregs;
|
| 228 |
|
|
struct reg_window *old_stack, *new_stack;
|
| 229 |
|
|
unsigned long stack_offset;
|
| 230 |
|
|
|
| 231 |
|
|
#ifndef __SMP__
|
| 232 |
|
|
if(last_task_used_math == current) {
|
| 233 |
|
|
#else
|
| 234 |
|
|
if(current->flags & PF_USEDFPU) {
|
| 235 |
|
|
#endif
|
| 236 |
|
|
put_psr(get_psr() | PSR_EF);
|
| 237 |
|
|
fpsave(&p->tss.float_regs[0], &p->tss.fsr,
|
| 238 |
|
|
&p->tss.fpqueue[0], &p->tss.fpqdepth);
|
| 239 |
|
|
#ifdef __SMP__
|
| 240 |
|
|
current->flags &= ~PF_USEDFPU;
|
| 241 |
|
|
#endif
|
| 242 |
|
|
}
|
| 243 |
|
|
|
| 244 |
|
|
/* Calculate offset to stack_frame & pt_regs */
|
| 245 |
|
|
if(sparc_cpu_model == sun4c)
|
| 246 |
|
|
stack_offset = ((PAGE_SIZE*3) - TRACEREG_SZ);
|
| 247 |
|
|
else
|
| 248 |
|
|
stack_offset = ((PAGE_SIZE<<2) - TRACEREG_SZ);
|
| 249 |
|
|
|
| 250 |
|
|
if(regs->psr & PSR_PS)
|
| 251 |
|
|
stack_offset -= REGWIN_SZ;
|
| 252 |
|
|
childregs = ((struct pt_regs *) (p->kernel_stack_page + stack_offset));
|
| 253 |
|
|
*childregs = *regs;
|
| 254 |
|
|
new_stack = (((struct reg_window *) childregs) - 1);
|
| 255 |
|
|
old_stack = (((struct reg_window *) regs) - 1);
|
| 256 |
|
|
*new_stack = *old_stack;
|
| 257 |
|
|
p->tss.ksp = p->saved_kernel_stack = (unsigned long) new_stack;
|
| 258 |
|
|
p->tss.kpc = (((unsigned long) ret_sys_call) - 0x8);
|
| 259 |
|
|
p->tss.kpsr = current->tss.fork_kpsr;
|
| 260 |
|
|
p->tss.kwim = current->tss.fork_kwim;
|
| 261 |
|
|
p->tss.kregs = childregs;
|
| 262 |
|
|
childregs->u_regs[UREG_FP] = sp;
|
| 263 |
|
|
|
| 264 |
|
|
if(regs->psr & PSR_PS) {
|
| 265 |
|
|
stack_offset += TRACEREG_SZ;
|
| 266 |
|
|
childregs->u_regs[UREG_FP] = p->kernel_stack_page + stack_offset;
|
| 267 |
|
|
p->tss.flags |= SPARC_FLAG_KTHREAD;
|
| 268 |
|
|
} else
|
| 269 |
|
|
p->tss.flags &= ~SPARC_FLAG_KTHREAD;
|
| 270 |
|
|
|
| 271 |
|
|
/* Set the return value for the child. */
|
| 272 |
|
|
childregs->u_regs[UREG_I0] = current->pid;
|
| 273 |
|
|
childregs->u_regs[UREG_I1] = 1;
|
| 274 |
|
|
|
| 275 |
|
|
/* Set the return value for the parent. */
|
| 276 |
|
|
regs->u_regs[UREG_I1] = 0;
|
| 277 |
|
|
}
|
| 278 |
|
|
|
| 279 |
|
|
/*
|
| 280 |
|
|
* fill in the user structure for a core dump..
|
| 281 |
|
|
*/
|
| 282 |
|
|
void dump_thread(struct pt_regs * regs, struct user * dump)
|
| 283 |
|
|
{
|
| 284 |
|
|
unsigned long first_stack_page;
|
| 285 |
|
|
|
| 286 |
|
|
dump->magic = SUNOS_CORE_MAGIC;
|
| 287 |
|
|
dump->len = sizeof(struct user);
|
| 288 |
|
|
dump->regs.psr = regs->psr;
|
| 289 |
|
|
dump->regs.pc = regs->pc;
|
| 290 |
|
|
dump->regs.npc = regs->npc;
|
| 291 |
|
|
dump->regs.y = regs->y;
|
| 292 |
|
|
/* fuck me plenty */
|
| 293 |
|
|
memcpy(&dump->regs.regs[0], ®s->u_regs[1], (sizeof(unsigned long) * 15));
|
| 294 |
|
|
dump->uexec = current->tss.core_exec;
|
| 295 |
|
|
dump->u_tsize = (((unsigned long) current->mm->end_code) -
|
| 296 |
|
|
((unsigned long) current->mm->start_code)) & ~(PAGE_SIZE - 1);
|
| 297 |
|
|
dump->u_dsize = ((unsigned long) (current->mm->brk + (PAGE_SIZE-1)));
|
| 298 |
|
|
dump->u_dsize -= dump->u_tsize;
|
| 299 |
|
|
dump->u_dsize &= ~(PAGE_SIZE - 1);
|
| 300 |
|
|
first_stack_page = (regs->u_regs[UREG_FP] & ~(PAGE_SIZE - 1));
|
| 301 |
|
|
dump->u_ssize = (TASK_SIZE - first_stack_page) & ~(PAGE_SIZE - 1);
|
| 302 |
|
|
memcpy(&dump->fpu.fpstatus.fregs.regs[0], ¤t->tss.float_regs[0], (sizeof(unsigned long) * 32));
|
| 303 |
|
|
dump->fpu.fpstatus.fsr = current->tss.fsr;
|
| 304 |
|
|
dump->fpu.fpstatus.flags = dump->fpu.fpstatus.extra = 0;
|
| 305 |
|
|
dump->fpu.fpstatus.fpq_count = current->tss.fpqdepth;
|
| 306 |
|
|
memcpy(&dump->fpu.fpstatus.fpq[0], ¤t->tss.fpqueue[0],
|
| 307 |
|
|
((sizeof(unsigned long) * 2) * 16));
|
| 308 |
|
|
dump->sigcode = current->tss.sig_desc;
|
| 309 |
|
|
}
|
| 310 |
|
|
|
| 311 |
|
|
/*
|
| 312 |
|
|
* fill in the fpu structure for a core dump.
|
| 313 |
|
|
*/
|
| 314 |
|
|
int dump_fpu (void *fpu_structure)
|
| 315 |
|
|
{
|
| 316 |
|
|
/* Currently we report that we couldn't dump the fpu structure */
|
| 317 |
|
|
return 0;
|
| 318 |
|
|
}
|
| 319 |
|
|
|
| 320 |
|
|
/*
|
| 321 |
|
|
* sparc_execve() executes a new program after the asm stub has set
|
| 322 |
|
|
* things up for us. This should basically do what I want it to.
|
| 323 |
|
|
*/
|
| 324 |
|
|
asmlinkage int sparc_execve(struct pt_regs *regs)
|
| 325 |
|
|
{
|
| 326 |
|
|
int error;
|
| 327 |
|
|
char *filename;
|
| 328 |
|
|
|
| 329 |
|
|
flush_user_windows();
|
| 330 |
|
|
error = getname((char *) regs->u_regs[UREG_I0], &filename);
|
| 331 |
|
|
if(error)
|
| 332 |
|
|
return error;
|
| 333 |
|
|
error = do_execve(filename, (char **) regs->u_regs[UREG_I1],
|
| 334 |
|
|
(char **) regs->u_regs[UREG_I2], regs);
|
| 335 |
|
|
putname(filename);
|
| 336 |
|
|
return error;
|
| 337 |
|
|
}
|