📄 process.c
字号:
/* $Id: process.c,v 1.154 2000/10/05 06:12:57 anton Exp $ * linux/arch/sparc/kernel/process.c * * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu) * Copyright (C) 1996 Eddie C. Dost (ecd@skynet.be) *//* * This file handles the architecture-dependent parts of process handling.. */#define __KERNEL_SYSCALLS__#include <stdarg.h>#include <linux/errno.h>#include <linux/sched.h>#include <linux/kernel.h>#include <linux/mm.h>#include <linux/stddef.h>#include <linux/unistd.h>#include <linux/ptrace.h>#include <linux/malloc.h>#include <linux/user.h>#include <linux/a.out.h>#include <linux/config.h>#include <linux/smp.h>#include <linux/smp_lock.h>#include <linux/reboot.h>#include <linux/delay.h>#include <asm/auxio.h>#include <asm/oplib.h>#include <asm/uaccess.h>#include <asm/system.h>#include <asm/page.h>#include <asm/pgalloc.h>#include <asm/pgtable.h>#include <asm/delay.h>#include <asm/processor.h>#include <asm/psr.h>#include <asm/elf.h>extern void fpsave(unsigned long *, unsigned long *, void *, unsigned long *);struct task_struct *last_task_used_math = NULL;struct task_struct *current_set[NR_CPUS] = {&init_task, };#ifndef CONFIG_SMP#define SUN4C_FAULT_HIGH 100/* * the idle loop on a Sparc... ;) */int cpu_idle(void){ int ret = -EPERM; if (current->pid != 0) goto out; /* endless idle loop with no priority at all */ current->nice = 20; current->counter = -100; init_idle(); for (;;) { if (ARCH_SUN4C_SUN4) { static int count = HZ; static unsigned long last_jiffies = 0; static unsigned long last_faults = 0; static unsigned long fps = 0; unsigned long now; unsigned long faults; unsigned long flags; extern unsigned long sun4c_kernel_faults; extern void sun4c_grow_kernel_ring(void); save_and_cli(flags); now = jiffies; count -= (now - last_jiffies); last_jiffies = now; if (count < 0) { count += HZ; faults = sun4c_kernel_faults; fps = (fps + (faults - last_faults)) >> 1; last_faults = faults;#if 0 printk("kernel faults / second = %d\n", fps);#endif if (fps >= SUN4C_FAULT_HIGH) { sun4c_grow_kernel_ring(); } } restore_flags(flags); } check_pgt_cache(); schedule(); } ret = 0;out: return ret;}#else/* This is being executed in task 0 'user space'. */int cpu_idle(void){ /* endless idle loop with no priority at all */ current->nice = 20; current->counter = -100; init_idle(); while(1) { if(current->need_resched) { schedule(); check_pgt_cache(); } barrier(); /* or else gcc optimizes... */ }}#endifextern char reboot_command [];extern int serial_console;#ifdef CONFIG_SUN_CONSOLEextern void (*prom_palette)(int);#endifvoid machine_halt(void){ sti(); mdelay(8); cli();#ifdef CONFIG_SUN_CONSOLE if (!serial_console && prom_palette) prom_palette (1);#endif prom_halt(); panic("Halt failed!");}void machine_restart(char * cmd){ char *p; sti(); mdelay(8); cli(); p = strchr (reboot_command, '\n'); if (p) *p = 0;#ifdef CONFIG_SUN_CONSOLE if (!serial_console && prom_palette) prom_palette (1);#endif if (cmd) prom_reboot(cmd); if (*reboot_command) prom_reboot(reboot_command); prom_feval ("reset"); panic("Reboot failed!");}void machine_power_off(void){#ifdef CONFIG_SUN_AUXIO if (auxio_power_register && !serial_console) *auxio_power_register |= AUXIO_POWER_OFF;#endif machine_halt();}void show_regwindow(struct reg_window *rw){ printk("l0: %08lx l1: %08lx l2: %08lx l3: %08lx " "l4: %08lx l5: %08lx l6: %08lx l7: %08lx\n", rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3], rw->locals[4], rw->locals[5], rw->locals[6], rw->locals[7]); printk("i0: %08lx i1: %08lx i2: %08lx i3: %08lx " "i4: %08lx i5: %08lx fp: %08lx i7: %08lx\n", rw->ins[0], rw->ins[1], rw->ins[2], rw->ins[3], rw->ins[4], rw->ins[5], rw->ins[6], rw->ins[7]);}static spinlock_t sparc_backtrace_lock = SPIN_LOCK_UNLOCKED;void __show_backtrace(unsigned long fp){ struct reg_window *rw; unsigned long flags; int cpu = smp_processor_id(); spin_lock_irqsave(&sparc_backtrace_lock, flags); rw = (struct reg_window *)fp; while(rw && (((unsigned long) rw) >= PAGE_OFFSET) && !(((unsigned long) rw) & 0x7)) { printk("CPU[%d]: ARGS[%08lx,%08lx,%08lx,%08lx,%08lx,%08lx] " "FP[%08lx] CALLER[%08lx]\n", cpu, rw->ins[0], rw->ins[1], rw->ins[2], rw->ins[3], rw->ins[4], rw->ins[5], rw->ins[6], rw->ins[7]); rw = (struct reg_window *) rw->ins[6]; } spin_unlock_irqrestore(&sparc_backtrace_lock, flags);}#define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")#define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")#define __GET_FP(fp) __asm__ __volatile__("mov %%i6, %0" : "=r" (fp))void show_backtrace(void){ unsigned long fp; __SAVE; __SAVE; __SAVE; __SAVE; __SAVE; __SAVE; __SAVE; __SAVE; __RESTORE; __RESTORE; __RESTORE; __RESTORE; __RESTORE; __RESTORE; __RESTORE; __RESTORE; __GET_FP(fp); __show_backtrace(fp);}#ifdef CONFIG_SMPvoid smp_show_backtrace_all_cpus(void){ xc0((smpfunc_t) show_backtrace); show_backtrace();}#endifvoid show_stackframe(struct sparc_stackf *sf){ unsigned long size; unsigned long *stk; int i; printk("l0: %08lx l1: %08lx l2: %08lx l3: %08lx " "l4: %08lx l5: %08lx l6: %08lx l7: %08lx\n", sf->locals[0], sf->locals[1], sf->locals[2], sf->locals[3], sf->locals[4], sf->locals[5], sf->locals[6], sf->locals[7]); printk("i0: %08lx i1: %08lx i2: %08lx i3: %08lx " "i4: %08lx i5: %08lx fp: %08lx i7: %08lx\n", sf->ins[0], sf->ins[1], sf->ins[2], sf->ins[3], sf->ins[4], sf->ins[5], (unsigned long)sf->fp, sf->callers_pc); printk("sp: %08lx x0: %08lx x1: %08lx x2: %08lx " "x3: %08lx x4: %08lx x5: %08lx xx: %08lx\n", (unsigned long)sf->structptr, sf->xargs[0], sf->xargs[1], sf->xargs[2], sf->xargs[3], sf->xargs[4], sf->xargs[5], sf->xxargs[0]); size = ((unsigned long)sf->fp) - ((unsigned long)sf); size -= STACKFRAME_SZ; stk = (unsigned long *)((unsigned long)sf + STACKFRAME_SZ); i = 0; do { printk("s%d: %08lx\n", i++, *stk++); } while ((size -= sizeof(unsigned long)));}void show_regs(struct pt_regs * regs){ printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx\n", regs->psr, regs->pc, regs->npc, regs->y); printk("g0: %08lx g1: %08lx g2: %08lx g3: %08lx ", regs->u_regs[0], regs->u_regs[1], regs->u_regs[2], regs->u_regs[3]); printk("g4: %08lx g5: %08lx g6: %08lx g7: %08lx\n", regs->u_regs[4], regs->u_regs[5], regs->u_regs[6], regs->u_regs[7]); printk("o0: %08lx o1: %08lx o2: %08lx o3: %08lx ", regs->u_regs[8], regs->u_regs[9], regs->u_regs[10], regs->u_regs[11]); printk("o4: %08lx o5: %08lx sp: %08lx o7: %08lx\n", regs->u_regs[12], regs->u_regs[13], regs->u_regs[14], regs->u_regs[15]); show_regwindow((struct reg_window *)regs->u_regs[14]);}#if NOTUSEDvoid show_thread(struct thread_struct *thread){ int i; printk("uwinmask: 0x%08lx kregs: 0x%08lx\n", thread->uwinmask, (unsigned long)thread->kregs); show_regs(thread->kregs); printk("ksp: 0x%08lx kpc: 0x%08lx\n", thread->ksp, thread->kpc); printk("kpsr: 0x%08lx kwim: 0x%08lx\n", thread->kpsr, thread->kwim); printk("fork_kpsr: 0x%08lx fork_kwim: 0x%08lx\n", thread->fork_kpsr, thread->fork_kwim); for (i = 0; i < NSWINS; i++) { if (!thread->rwbuf_stkptrs[i]) continue; printk("reg_window[%d]:\n", i); printk("stack ptr: 0x%08lx\n", thread->rwbuf_stkptrs[i]); show_regwindow(&thread->reg_window[i]); } printk("w_saved: 0x%08lx\n", thread->w_saved); /* XXX missing: float_regs */ printk("fsr: 0x%08lx fpqdepth: 0x%08lx\n", thread->fsr, thread->fpqdepth); /* XXX missing: fpqueue */ printk("flags: 0x%08lx current_ds: 0x%08lx\n", thread->flags, thread->current_ds.seg); show_regwindow((struct reg_window *)thread->ksp); /* XXX missing: core_exec */}#endif/* * Free current thread data structures etc.. */void exit_thread(void){#ifndef CONFIG_SMP if(last_task_used_math == current) {#else if(current->flags & PF_USEDFPU) {#endif /* Keep process from leaving FPU in a bogon state. */ put_psr(get_psr() | PSR_EF); fpsave(¤t->thread.float_regs[0], ¤t->thread.fsr, ¤t->thread.fpqueue[0], ¤t->thread.fpqdepth);#ifndef CONFIG_SMP last_task_used_math = NULL;#else current->flags &= ~PF_USEDFPU;#endif }}void flush_thread(void){ current->thread.w_saved = 0; /* No new signal delivery by default */ current->thread.new_signal = 0;#ifndef CONFIG_SMP if(last_task_used_math == current) {#else if(current->flags & PF_USEDFPU) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -