⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 process.c

📁 linux-2.4.29操作系统的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* *  linux/arch/ppc64/kernel/process.c * *  Derived from "arch/i386/kernel/process.c" *    Copyright (C) 1995  Linus Torvalds * *  Updated and modified by Cort Dougan (cort@cs.nmt.edu) and *  Paul Mackerras (paulus@cs.anu.edu.au) * *  PowerPC version  *    Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org) * *  VMX/Altivec port from ppc32 (c) IBM 2003 *   Denis Joseph Barrow (dj@de.ibm.com,barrow_dj@yahoo.com) * *  This program is free software; you can redistribute it and/or *  modify it under the terms of the GNU General Public License *  as published by the Free Software Foundation; either version *  2 of the License, or (at your option) any later version. */#include <linux/config.h>#include <linux/errno.h>#include <linux/sched.h>#include <linux/kernel.h>#include <linux/mm.h>#include <linux/smp.h>#include <linux/smp_lock.h>#include <linux/stddef.h>#include <linux/unistd.h>#include <linux/ptrace.h>#include <linux/slab.h>#include <linux/user.h>#include <linux/elf.h>#include <linux/init.h>#include <asm/pgtable.h>#include <asm/uaccess.h>#include <asm/system.h>#include <asm/io.h>#include <asm/processor.h>#include <asm/mmu.h>#include <asm/mmu_context.h>#include <asm/prom.h>#include <asm/ppcdebug.h>#include <asm/machdep.h>#include <asm/iSeries/HvCallHpt.h>#include <asm/cputable.h>int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpregs);#ifndef CONFIG_SMPstruct task_struct *last_task_used_math = NULL;struct task_struct *last_task_used_altivec = NULL;#endif /* CONFIG_SMP */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(init_mm);struct mm_struct ioremap_mm = { pgd             : ioremap_dir                                 ,page_table_lock : SPIN_LOCK_UNLOCKED };/* this is 16-byte aligned because it has a stack in it */union task_union __attribute((aligned(16))) init_task_union = {	INIT_TASK(init_task_union.task)};#ifdef CONFIG_SMPstruct current_set_struct current_set[NR_CPUS] = {{&init_task, 0}, };#endifchar *sysmap = NULL; unsigned long sysmap_size = 0;extern char __toc_start;#undef SHOW_TASK_SWITCHESvoidenable_kernel_fp(void){#ifdef CONFIG_SMP	if (current->thread.regs && (current->thread.regs->msr & MSR_FP))		giveup_fpu(current);	else		giveup_fpu(NULL);	/* just enables FP for kernel */#else	giveup_fpu(last_task_used_math);#endif /* CONFIG_SMP */}intdump_fpu(struct pt_regs *regs, elf_fpregset_t *fpregs){	if (regs->msr & MSR_FP)		giveup_fpu(current);	memcpy(fpregs, &current->thread.fpr[0], sizeof(*fpregs));	return 1;}#ifdef CONFIG_ALTIVECintdump_altivec(struct pt_regs *regs, elf_vrregset_t *vrregs){	if (regs->msr & MSR_VEC)		giveup_altivec(current);	memcpy(vrregs, &current->thread.vr[0], sizeof(*vrregs));	return 1;}voidenable_kernel_altivec(void){#ifdef CONFIG_SMP	if (current->thread.regs && (current->thread.regs->msr & MSR_VEC))		giveup_altivec(current);	else		giveup_altivec(NULL);	/* just enable AltiVec for kernel - force */#else	giveup_altivec(last_task_used_altivec);#endif /* __SMP __ */}#endif /* CONFIG_ALTIVEC */void_switch_to(struct task_struct *prev, struct task_struct *new,	  struct task_struct **last){	struct thread_struct *new_thread, *old_thread;	unsigned long s;		__save_flags(s);	__cli();#ifdef SHOW_TASK_SWITCHES	printk("%s/%d -> %s/%d NIP %08lx cpu %d root %x/%x\n",	       prev->comm,prev->pid,	       new->comm,new->pid,new->thread.regs->nip,new->processor,	       new->fs->root,prev->fs->root);#endif#ifdef CONFIG_SMP	/* avoid complexity of lazy save/restore of fpu	 * by just saving it every time we switch out if	 * this task used the fpu during the last quantum.	 * 	 * If it tries to use the fpu again, it'll trap and	 * reload its fp regs.  So we don't have to do a restore	 * every switch, just a save.	 *  -- Cort	 */	if ( prev->thread.regs && (prev->thread.regs->msr & MSR_FP) )		giveup_fpu(prev);#ifdef CONFIG_ALTIVEC	/*	 * If the previous thread used altivec in the last quantum	 * (thus changing altivec regs) then save them.	 * We used to check the VRSAVE register but not all apps	 * set it, so we don't rely on it now (and in fact we need	 * to save & restore VSCR even if VRSAVE == 0).  -- paulus	 *	 * On SMP we always save/restore altivec regs just to avoid the	 * complexity of changing processors.	 *  -- Cort	 */	if ((prev->thread.regs && (prev->thread.regs->msr & MSR_VEC)))		giveup_altivec(prev);#endif /* CONFIG_ALTIVEC */	/* prev->last_processor = prev->processor; */	current_set[smp_processor_id()].task = new;#endif /* CONFIG_SMP */	new_thread = &new->thread;	old_thread = &current->thread;	*last = _switch(old_thread, new_thread);	__restore_flags(s);}void show_regs(struct pt_regs * regs){	int i;	printk("NIP: %016lX XER: %016lX LR: %016lX REGS: %p TRAP: %04lx    %s\n",	       regs->nip, regs->xer, regs->link, regs,regs->trap, print_tainted());	printk("MSR: %016lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n",	       regs->msr, regs->msr&MSR_EE ? 1 : 0, regs->msr&MSR_PR ? 1 : 0,	       regs->msr & MSR_FP ? 1 : 0,regs->msr&MSR_ME ? 1 : 0,	       regs->msr&MSR_IR ? 1 : 0,	       regs->msr&MSR_DR ? 1 : 0);	printk("TASK = %p[%d] '%s' ",	       current, current->pid, current->comm);	printk("Last syscall: %ld ", current->thread.last_syscall);#ifndef CONFIG_SMP	printk("\nlast math %p last altivec %p", last_task_used_math,	       last_task_used_altivec);#endif#ifdef CONFIG_SMP	/* printk(" CPU: %d last CPU: %d", current->processor,current->last_processor); */#endif /* CONFIG_SMP */		printk("\n");	for (i = 0;  i < 32;  i++)	{		long r;		if ((i % 4) == 0)		{			printk("GPR%02d: ", i);		}		if ( __get_user(r, &(regs->gpr[i])) )		    return;		printk("%016lX ", r);		if ((i % 4) == 3)		{			printk("\n");		}	}}void exit_thread(void){#ifndef CONFIG_SMP	if (last_task_used_math == current)		last_task_used_math = NULL;	if (last_task_used_altivec == current)		last_task_used_altivec = NULL;#endif}void flush_thread(void){#ifndef CONFIG_SMP	if (last_task_used_math == current)		last_task_used_math = NULL;	if (last_task_used_altivec == current)		last_task_used_altivec = NULL;#endif}voidrelease_thread(struct task_struct *t){}/* * Copy a thread.. */intcopy_thread(int nr, unsigned long clone_flags, unsigned long usp,	    unsigned long unused,	    struct task_struct * p, struct pt_regs * regs){	unsigned long msr;	struct pt_regs * childregs, *kregs;	extern void ret_from_fork(void);	/* Copy registers */	childregs = ((struct pt_regs *)		     ((unsigned long)p + sizeof(union task_union)		      - STACK_FRAME_OVERHEAD)) - 2;	*childregs = *regs;	childregs->gpr[3] = 0;  /* Result from fork() */	p->thread.regs = childregs;	p->thread.ksp = (unsigned long) childregs - STACK_FRAME_OVERHEAD;	p->thread.ksp -= sizeof(struct pt_regs ) + STACK_FRAME_OVERHEAD;	kregs = (struct pt_regs *)(p->thread.ksp + STACK_FRAME_OVERHEAD);	/* The PPC64 compiler makes use of a TOC to contain function 	 * pointers.  The function (ret_from_except) is actually a pointer	 * to the TOC entry.  The first entry is a pointer to the actual	 * function. 	 */	kregs->nip = *((unsigned long *)ret_from_fork);	asm volatile("mfmsr %0" : "=r" (msr):);	kregs->msr = msr;	kregs->gpr[1] = (unsigned long)childregs - STACK_FRAME_OVERHEAD;	kregs->gpr[2] = (((unsigned long)&__toc_start) + 0x8000);		if (usp >= (unsigned long) regs) {		/* Stack is in kernel space - must adjust */		childregs->gpr[1] = (unsigned long)(childregs + 1);		*((unsigned long *) childregs->gpr[1]) = 0;	} else {		/* Provided stack is in user space */		childregs->gpr[1] = usp;	}	p->thread.last_syscall = -1;	  	/*	 * copy fpu info - assume lazy fpu switch now always	 *  -- Cort	 */	if (regs->msr & MSR_FP) {		giveup_fpu(current);		childregs->msr &= ~(MSR_FP | MSR_FE0 | MSR_FE1);	}	memcpy(&p->thread.fpr, &current->thread.fpr, sizeof(p->thread.fpr));	p->thread.fpscr = current->thread.fpscr;	p->thread.fpexc_mode = current->thread.fpexc_mode;#ifdef CONFIG_ALTIVEC	/*

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -