patch-2.1.44 linux/arch/mips/kernel/process.c

Next file: linux/arch/mips/kernel/ptrace.c
Previous file: linux/arch/mips/kernel/proc.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.1.43/linux/arch/mips/kernel/process.c linux/arch/mips/kernel/process.c
@@ -2,10 +2,14 @@
  *  linux/arch/mips/kernel/process.c
  *
  *  Copyright (C) 1995 Ralf Baechle
- *  written by Ralf Baechle
  *
- * This file handles the architecture-dependent parts of initialization
+ *  Modified for R3000/DECStation support by Paul M. Antoine 1995, 1996
+ *
+ * This file handles the architecture-dependent parts of initialization,
+ * though it does not yet currently fully support the DECStation,
+ * or R3000 - PMA.
  */
+#include <linux/config.h>
 #include <linux/errno.h>
 #include <linux/sched.h>
 #include <linux/kernel.h>
@@ -14,144 +18,83 @@
 #include <linux/unistd.h>
 #include <linux/ptrace.h>
 #include <linux/malloc.h>
-#include <linux/ldt.h>
 #include <linux/mman.h>
 #include <linux/sys.h>
 #include <linux/user.h>
 #include <linux/a.out.h>
 
 #include <asm/bootinfo.h>
-#include <asm/segment.h>
 #include <asm/pgtable.h>
 #include <asm/system.h>
 #include <asm/mipsregs.h>
 #include <asm/processor.h>
 #include <asm/stackframe.h>
+#include <asm/uaccess.h>
 #include <asm/io.h>
+#include <asm/elf.h>
+#ifdef CONFIG_SGI
+#include <asm/sgialib.h>
+#endif
 
-/*
- * Initial task structure. Make this a per-architecture thing,
- * because different architectures tend to have different
- * alignment requirements and potentially different initial
- * setup.
- */
-static unsigned long init_kernel_stack[1024] = { STACK_MAGIC, };
-unsigned long init_user_stack[1024] = { STACK_MAGIC, };
-static struct vm_area_struct init_mmap = INIT_MMAP;
-static struct fs_struct init_fs = INIT_FS;
-static struct files_struct init_files = INIT_FILES;
-static struct signal_struct init_signals = INIT_SIGNALS;
-
-struct mm_struct init_mm = INIT_MM;
-struct task_struct init_task = INIT_TASK;
+int active_ds = USER_DS;
 
 asmlinkage void ret_from_sys_call(void);
 
 /*
- * This routine reboots the machine by asking the keyboard
- * controller to pulse the reset-line low. We try that for a while,
- * and if it doesn't work, we do some other stupid things.
- * Should be ok for Deskstation Tynes. Reseting others needs to be
- * investigated...
+ * Do necessary setup to start up a newly executed thread.
  */
-static inline void kb_wait(void)
-{
-	int i;
-
-	for (i=0; i<0x10000; i++)
-		if ((inb_p(0x64) & 0x02) == 0)
-			break;
-}
-
-/*
- * Hard reset for Deskstation Tyne
- * No hint how this works on Pica boards.
- */
-void hard_reset_now(void)
-{
-	int i, j;
-
-	sti();
-	for (;;) {
-		for (i=0; i<100; i++) {
-			kb_wait();
-			for(j = 0; j < 100000 ; j++)
-				/* nothing */;
-			outb(0xfe,0x64);	 /* pulse reset low */
-		}
-	}
-}
-
-void show_regs(struct pt_regs * regs)
+void start_thread(struct pt_regs * regs, unsigned long pc, unsigned long sp)
 {
-	/*
-	 * Saved main processor registers
-	 */
-	printk("$0 : %08x %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
-	       0, regs->reg1, regs->reg2, regs->reg3,
-               regs->reg4, regs->reg5, regs->reg6, regs->reg7);
-	printk("$8 : %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
-	       regs->reg8, regs->reg9, regs->reg10, regs->reg11,
-               regs->reg12, regs->reg13, regs->reg14, regs->reg15);
-	printk("$16: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
-	       regs->reg16, regs->reg17, regs->reg18, regs->reg19,
-               regs->reg20, regs->reg21, regs->reg22, regs->reg23);
-	printk("$24: %08lx %08lx                   %08lx %08lx %08lx %08lx\n",
-	       regs->reg24, regs->reg25, regs->reg28, regs->reg29,
-               regs->reg30, regs->reg31);
-
-	/*
-	 * Saved cp0 registers
-	 */
-	printk("epc  : %08lx\nStatus: %08lx\nCause : %08lx\n",
-	       regs->cp0_epc, regs->cp0_status, regs->cp0_cause);
+	/* New thread looses kernel privileges. */
+	regs->cp0_status = (regs->cp0_status & ~(ST0_CU0|ST0_KSU)) | KSU_USER;
+	regs->cp0_epc = pc;
+	regs->regs[29] = sp;
+	current->tss.current_ds = USER_DS;
 }
 
-/*
- * Free current thread data structures etc..
- */
 void exit_thread(void)
 {
-	/*
-	 * Nothing to do
-	 */
 }
 
 void flush_thread(void)
 {
-	/*
-	 * Nothing to do
-	 */
 }
 
 void release_thread(struct task_struct *dead_task)
 {
-	/*
-	 * Nothing to do
-	 */
 }
-  
+
 int copy_thread(int nr, unsigned long clone_flags, unsigned long usp,
                  struct task_struct * p, struct pt_regs * regs)
 {
 	struct pt_regs * childregs;
-	unsigned long childksp;
+	long childksp;
 
-	childksp = p->kernel_stack_page + PAGE_SIZE - 8;
-	/*
-	 * set up new TSS
-	 */
-	childregs = ((struct pt_regs *) (p->kernel_stack_page + PAGE_SIZE)) - 1;
+	childksp = (unsigned long)p + KERNEL_STACK_SIZE - 8;
+
+	/* set up new TSS. */
+	childregs = ((struct pt_regs *) ((unsigned long)p + KERNEL_STACK_SIZE)) - 1;
 	*childregs = *regs;
-	childregs->reg2 = 0;		/* Child gets zero as return value */
-	childregs->reg7 = 0;		/* Clear error flag */
-	regs->reg2 = p->pid;
-	if (childregs->cp0_status & ST0_CU0)
-		childregs->reg29 = childksp;
-	else
-		childregs->reg29 = usp;
+	childregs->regs[7] = 0;	/* Clear error flag */
+	if(current->personality == PER_LINUX) {
+		childregs->regs[2] = 0;	/* Child gets zero as return value */
+		regs->regs[2] = p->pid;
+	} else {
+		/* Under IRIX things are a little different. */
+		childregs->regs[2] = 0;
+		childregs->regs[3] = 1;
+		regs->regs[2] = p->pid;
+		regs->regs[3] = 0;
+	}
+	if (childregs->cp0_status & ST0_CU0) {
+		childregs->regs[29] = childksp;
+		p->tss.current_ds = KERNEL_DS;
+	} else {
+		childregs->regs[29] = usp;
+		p->tss.current_ds = USER_DS;
+	}
 	p->tss.ksp = childksp;
-	p->tss.reg29 = (unsigned long) childregs;	/* new sp */
+	p->tss.reg29 = (unsigned long) childregs;
 	p->tss.reg31 = (unsigned long) ret_from_sys_call;
 
 	/*
@@ -161,31 +104,35 @@
 	p->tss.cp0_status = read_32bit_cp0_register(CP0_STATUS) &
                             ~(ST0_CU3|ST0_CU2|ST0_CU1|ST0_KSU|ST0_ERL|ST0_EXL);
 	childregs->cp0_status &= ~(ST0_CU3|ST0_CU2|ST0_CU1);
+	p->mm->context = 0;
 
 	return 0;
 }
 
-/*
- * fill in the fpu structure for a core dump..
- *
- * Actually this is "int dump_fpu (struct elf_fpregset_t *fpu)"
- */
-int dump_fpu (int shutup_the_gcc_warning_about_elf_fpregset_t)
+/* Fill in the fpu structure for a core dump.. */
+int dump_fpu(struct pt_regs *regs, elf_fpregset_t *r)
 {
-	int fpvalid = 0;
-	/*
-	 * To do...
+	/* We actually store the FPU info in the task->tss
+	 * area.
 	 */
-
-	return fpvalid;
+	if(regs->cp0_status & ST0_CU1) {
+		memcpy(r, &current->tss.fpu, sizeof(current->tss.fpu));
+		return 1;
+	}
+	return 0; /* Task didn't use the fpu at all. */
 }
 
-/*
- * fill in the user structure for a core dump..
- */
-void dump_thread(struct pt_regs * regs, struct user * dump)
+/* Fill in the user structure for a core dump.. */
+void dump_thread(struct pt_regs *regs, struct user *dump)
 {
-	/*
-	 * To do...
-	 */
+	dump->magic = CMAGIC;
+	dump->start_code  = current->mm->start_code;
+	dump->start_data  = current->mm->start_data;
+	dump->start_stack = regs->regs[29] & ~(PAGE_SIZE - 1);
+	dump->u_tsize = (current->mm->end_code - dump->start_code) >> PAGE_SHIFT;
+	dump->u_dsize = (current->mm->brk + (PAGE_SIZE - 1) - dump->start_data) >> PAGE_SHIFT;
+	dump->u_ssize =
+		(current->mm->start_stack - dump->start_stack + PAGE_SIZE - 1) >> PAGE_SHIFT;
+	memcpy(&dump->regs[0], regs, sizeof(struct pt_regs));
+	memcpy(&dump->regs[EF_SIZE/4], &current->tss.fpu, sizeof(current->tss.fpu));
 }

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov