/*
* 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/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(