📄 process.c
字号:
/* * This file is subject to the terms and conditions of the GNU General Public * License. See the file "COPYING" in the main directory of this archive * for more details. * * arch/sh64/kernel/process.c * * Copyright (C) 2000, 2001 Paolo Alberelli * Copyright (C) 2003 Paul Mundt * Copyright (C) 2003, 2004 Richard Curnow * * Started from SH3/4 version: * Copyright (C) 1999, 2000 Niibe Yutaka & Kaz Kojima * * In turn started from i386 version: * Copyright (C) 1995 Linus Torvalds * *//* * This file handles the architecture-dependent parts of process handling.. *//* Temporary flags/tests. All to be removed/undefined. BEGIN */#define IDLE_TRACE#define VM_SHOW_TABLES#define VM_TEST_FAULT#define VM_TEST_RTLBMISS#define VM_TEST_WTLBMISS#undef VM_SHOW_TABLES#undef IDLE_TRACE/* Temporary flags/tests. All to be removed/undefined. END */#define __KERNEL_SYSCALLS__#include <stdarg.h>#include <linux/config.h>#include <linux/kernel.h>#include <linux/rwsem.h>#include <linux/mm.h>#include <linux/smp.h>#include <linux/smp_lock.h>#include <linux/ptrace.h>#include <linux/slab.h>#include <linux/vmalloc.h>#include <linux/user.h>#include <linux/a.out.h>#include <linux/interrupt.h>#include <linux/unistd.h>#include <linux/delay.h>#include <linux/reboot.h>#include <linux/init.h>#include <asm/uaccess.h>#include <asm/pgtable.h>#include <asm/system.h>#include <asm/io.h>#include <asm/processor.h> /* includes also <asm/registers.h> */#include <asm/mmu_context.h>#include <asm/elf.h>#include <asm/page.h>#include <linux/irq.h>struct task_struct *last_task_used_math = NULL;#ifdef IDLE_TRACE#ifdef VM_SHOW_TABLES/* For testing */static void print_PTE(long base){ int i, skip=0; long long x, y, *p = (long long *) base; for (i=0; i< 512; i++, p++){ if (*p == 0) { if (!skip) { skip++; printk("(0s) "); } } else { skip=0; x = (*p) >> 32; y = (*p) & 0xffffffff; printk("%08Lx%08Lx ", x, y); if (!((i+1)&0x3)) printk("\n"); } }}/* For testing */static void print_DIR(long base){ int i, skip=0; long *p = (long *) base; for (i=0; i< 512; i++, p++){ if (*p == 0) { if (!skip) { skip++; printk("(0s) "); } } else { skip=0; printk("%08lx ", *p); if (!((i+1)&0x7)) printk("\n"); } }}/* For testing */static void print_vmalloc_first_tables(void){#define PRESENT 0x800 /* Bit 11 */ /* * Do it really dirty by looking at raw addresses, * raw offsets, no types. If we used pgtable/pgalloc * macros/definitions we could hide potential bugs. * * Note that pointers are 32-bit for CDC. */ long pgdt, pmdt, ptet; pgdt = (long) &swapper_pg_dir; printk("-->PGD (0x%08lx):\n", pgdt); print_DIR(pgdt); printk("\n"); /* VMALLOC pool is mapped at 0xc0000000, second (pointer) entry in PGD */ pgdt += 4; pmdt = (long) (* (long *) pgdt); if (!(pmdt & PRESENT)) { printk("No PMD\n"); return; } else pmdt &= 0xfffff000; printk("-->PMD (0x%08lx):\n", pmdt); print_DIR(pmdt); printk("\n"); /* Get the pmdt displacement for 0xc0000000 */ pmdt += 2048; /* just look at first two address ranges ... */ /* ... 0xc0000000 ... */ ptet = (long) (* (long *) pmdt); if (!(ptet & PRESENT)) { printk("No PTE0\n"); return; } else ptet &= 0xfffff000; printk("-->PTE0 (0x%08lx):\n", ptet); print_PTE(ptet); printk("\n"); /* ... 0xc0001000 ... */ ptet += 4; if (!(ptet & PRESENT)) { printk("No PTE1\n"); return; } else ptet &= 0xfffff000; printk("-->PTE1 (0x%08lx):\n", ptet); print_PTE(ptet); printk("\n");}#else#define print_vmalloc_first_tables()#endif /* VM_SHOW_TABLES */static void test_VM(void){ void *a, *b, *c;#ifdef VM_SHOW_TABLES printk("Initial PGD/PMD/PTE\n");#endif print_vmalloc_first_tables(); printk("Allocating 2 bytes\n"); a = vmalloc(2); print_vmalloc_first_tables(); printk("Allocating 4100 bytes\n"); b = vmalloc(4100); print_vmalloc_first_tables(); printk("Allocating 20234 bytes\n"); c = vmalloc(20234); print_vmalloc_first_tables();#ifdef VM_TEST_FAULT /* Here you may want to fault ! */#ifdef VM_TEST_RTLBMISS printk("Ready to fault upon read.\n"); if (* (char *) a) { printk("RTLBMISSed on area a !\n"); } printk("RTLBMISSed on area a !\n");#endif#ifdef VM_TEST_WTLBMISS printk("Ready to fault upon write.\n"); *((char *) b) = 'L'; printk("WTLBMISSed on area b !\n");#endif#endif /* VM_TEST_FAULT */ printk("Deallocating the 4100 byte chunk\n"); vfree(b); print_vmalloc_first_tables(); printk("Deallocating the 2 byte chunk\n"); vfree(a); print_vmalloc_first_tables(); printk("Deallocating the last chunk\n"); vfree(c); print_vmalloc_first_tables();}extern unsigned long volatile jiffies;int once = 0;unsigned long old_jiffies;int pid = -1, pgid = -1;void idle_trace(void){ _syscall0(int, getpid) _syscall1(int, getpgid, int, pid) if (!once) { /* VM allocation/deallocation simple test */ test_VM(); pid = getpid(); printk("Got all through to Idle !!\n"); printk("I'm now going to loop forever ...\n"); printk("Any ! below is a timer tick.\n"); printk("Any . below is a getpgid system call from pid = %d.\n", pid); old_jiffies = jiffies; once++; } if (old_jiffies != jiffies) { old_jiffies = jiffies - old_jiffies; switch (old_jiffies) { case 1: printk("!"); break; case 2: printk("!!"); break; case 3: printk("!!!"); break; case 4: printk("!!!!"); break; default: printk("(%d!)", (int) old_jiffies); } old_jiffies = jiffies; } pgid = getpgid(pid); printk(".");}#else#define idle_trace() do { } while (0)#endif /* IDLE_TRACE */static int hlt_counter = 1;#define HARD_IDLE_TIMEOUT (HZ / 3)void disable_hlt(void){ hlt_counter++;}void enable_hlt(void){ hlt_counter--;}static int __init nohlt_setup(char *__unused){ hlt_counter = 1; return 1;}static int __init hlt_setup(char *__unused){ hlt_counter = 0; return 1;}__setup("nohlt", nohlt_setup);__setup("hlt", hlt_setup);static inline void hlt(void){ __asm__ __volatile__ ("sleep" : : : "memory");}/* * The idle loop on a uniprocessor SH.. */void cpu_idle(void){ /* endless idle loop with no priority at all */ while (1) { if (hlt_counter) { while (!need_resched()) cpu_relax(); } else { local_irq_disable(); while (!need_resched()) { local_irq_enable(); idle_trace(); hlt(); local_irq_disable(); } local_irq_enable(); } preempt_enable_no_resched(); schedule(); preempt_disable(); }}void machine_restart(char * __unused){ extern void phys_stext(void); phys_stext();}void machine_halt(void){ for (;;);}void machine_power_off(void){ extern void enter_deep_standby(void); enter_deep_standby();}void show_regs(struct pt_regs * regs){ unsigned long long ah, al, bh, bl, ch, cl; printk("\n"); ah = (regs->pc) >> 32; al = (regs->pc) & 0xffffffff; bh = (regs->regs[18]) >> 32; bl = (regs->regs[18]) & 0xffffffff; ch = (regs->regs[15]) >> 32; cl = (regs->regs[15]) & 0xffffffff; printk("PC : %08Lx%08Lx LINK: %08Lx%08Lx SP : %08Lx%08Lx\n", ah, al, bh, bl, ch, cl); ah = (regs->sr) >> 32; al = (regs->sr) & 0xffffffff; asm volatile ("getcon " __TEA ", %0" : "=r" (bh)); asm volatile ("getcon " __TEA ", %0" : "=r" (bl)); bh = (bh) >> 32; bl = (bl) & 0xffffffff; asm volatile ("getcon " __KCR0 ", %0" : "=r" (ch)); asm volatile ("getcon " __KCR0 ", %0" : "=r" (cl)); ch = (ch) >> 32; cl = (cl) & 0xffffffff; printk("SR : %08Lx%08Lx TEA : %08Lx%08Lx KCR0: %08Lx%08Lx\n", ah, al, bh, bl, ch, cl); ah = (regs->regs[0]) >> 32; al = (regs->regs[0]) & 0xffffffff; bh = (regs->regs[1]) >> 32; bl = (regs->regs[1]) & 0xffffffff; ch = (regs->regs[2]) >> 32; cl = (regs->regs[2]) & 0xffffffff; printk("R0 : %08Lx%08Lx R1 : %08Lx%08Lx R2 : %08Lx%08Lx\n", ah, al, bh, bl, ch, cl); ah = (regs->regs[3]) >> 32; al = (regs->regs[3]) & 0xffffffff; bh = (regs->regs[4]) >> 32; bl = (regs->regs[4]) & 0xffffffff; ch = (regs->regs[5]) >> 32; cl = (regs->regs[5]) & 0xffffffff; printk("R3 : %08Lx%08Lx R4 : %08Lx%08Lx R5 : %08Lx%08Lx\n", ah, al, bh, bl, ch, cl); ah = (regs->regs[6]) >> 32; al = (regs->regs[6]) & 0xffffffff; bh = (regs->regs[7]) >> 32; bl = (regs->regs[7]) & 0xffffffff; ch = (regs->regs[8]) >> 32; cl = (regs->regs[8]) & 0xffffffff; printk("R6 : %08Lx%08Lx R7 : %08Lx%08Lx R8 : %08Lx%08Lx\n", ah, al, bh, bl, ch, cl); ah = (regs->regs[9]) >> 32; al = (regs->regs[9]) & 0xffffffff; bh = (regs->regs[10]) >> 32; bl = (regs->regs[10]) & 0xffffffff; ch = (regs->regs[11]) >> 32; cl = (regs->regs[11]) & 0xffffffff; printk("R9 : %08Lx%08Lx R10 : %08Lx%08Lx R11 : %08Lx%08Lx\n", ah, al, bh, bl, ch, cl); ah = (regs->regs[12]) >> 32; al = (regs->regs[12]) & 0xffffffff; bh = (regs->regs[13]) >> 32; bl = (regs->regs[13]) & 0xffffffff; ch = (regs->regs[14]) >> 32; cl = (regs->regs[14]) & 0xffffffff; printk("R12 : %08Lx%08Lx R13 : %08Lx%08Lx R14 : %08Lx%08Lx\n", ah, al, bh, bl, ch, cl); ah = (regs->regs[16]) >> 32; al = (regs->regs[16]) & 0xffffffff; bh = (regs->regs[17]) >> 32; bl = (regs->regs[17]) & 0xffffffff; ch = (regs->regs[19]) >> 32; cl = (regs->regs[19]) & 0xffffffff; printk("R16 : %08Lx%08Lx R17 : %08Lx%08Lx R19 : %08Lx%08Lx\n", ah, al, bh, bl, ch, cl); ah = (regs->regs[20]) >> 32; al = (regs->regs[20]) & 0xffffffff; bh = (regs->regs[21]) >> 32; bl = (regs->regs[21]) & 0xffffffff; ch = (regs->regs[22]) >> 32; cl = (regs->regs[22]) & 0xffffffff; printk("R20 : %08Lx%08Lx R21 : %08Lx%08Lx R22 : %08Lx%08Lx\n", ah, al, bh, bl, ch, cl); ah = (regs->regs[23]) >> 32; al = (regs->regs[23]) & 0xffffffff; bh = (regs->regs[24]) >> 32; bl = (regs->regs[24]) & 0xffffffff; ch = (regs->regs[25]) >> 32; cl = (regs->regs[25]) & 0xffffffff; printk("R23 : %08Lx%08Lx R24 : %08Lx%08Lx R25 : %08Lx%08Lx\n", ah, al, bh, bl, ch, cl); ah = (regs->regs[26]) >> 32; al = (regs->regs[26]) & 0xffffffff; bh = (regs->regs[27]) >> 32; bl = (regs->regs[27]) & 0xffffffff; ch = (regs->regs[28]) >> 32; cl = (regs->regs[28]) & 0xffffffff; printk("R26 : %08Lx%08Lx R27 : %08Lx%08Lx R28 : %08Lx%08Lx\n", ah, al, bh, bl, ch, cl); ah = (regs->regs[29]) >> 32; al = (regs->regs[29]) & 0xffffffff; bh = (regs->regs[30]) >> 32; bl = (regs->regs[30]) & 0xffffffff; ch = (regs->regs[31]) >> 32; cl = (regs->regs[31]) & 0xffffffff; printk("R29 : %08Lx%08Lx R30 : %08Lx%08Lx R31 : %08Lx%08Lx\n", ah, al, bh, bl, ch, cl); ah = (regs->regs[32]) >> 32; al = (regs->regs[32]) & 0xffffffff; bh = (regs->regs[33]) >> 32;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -