/* $Id: processor.h,v 1.2 2005/06/16 13:46:43 cgoh Exp $
 *
 * 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.
 *
 * Copyright (C) Equator Technologies
 */

#ifndef _ASM_BSP_PROCESSOR_H_
#define _ASM_BSP_PROCESSOR_H_

#if !defined(_LANGUAGE_ASSEMBLY)
#include <linux/config.h>
#include <linux/types.h>
#include <linux/pci.h>

#include <asm/segment.h>
#include <asm/page.h>
#include <asm/ptrace.h>

#include <libdev/etiRegisters.h>
#include <libdev/etiContext.h>
#include <libdev/mapca/pcia_piomap.h>



typedef struct {
	unsigned long seg;
} mm_segment_t;


typedef void (*proc_fun_t)(u32 argc, u32 argv, u32 env);
typedef void (*start_fun_t)(unsigned long argc, unsigned long argv, unsigned long env);


struct thread_struct {
        ctxThreadContext        regs;       /* special case of struct ctxContext */
        start_fun_t             start_fun;
        unsigned long          *args;
        mm_segment_t            current_ds;
        unsigned long           pg_dir;
        unsigned long           atomic_start, atomic_end;
	unsigned long		signal_return;
        long                    page_cluster_behavior; /* -1: dont cluster
                                                        *  0: follow clusterer's default
                                                        *  1: do cluster
                                                        */
        /* debug state */
        unsigned long           debug_flags;
        unsigned long           saved_pc;
};

/* values for thread_struct.debug_flags */
#define TSS_DEBUG_SINGLE_STEPPING   0x01
#define TSS_DEBUG_SAVED_PC_VALID    0x02

#define TASK_CONTEXT(task) (&(task)->tss.regs)


/* Bus types */
extern int EISA_bus;

/*
 * User space process size
 */
#define TASK_SIZE                PAGE_OFFSET

/* This decides where the kernel will search for a free chunk of vm
 * space during mmap's.
 */
#define TASK_UNMAPPED_BASE	(TASK_SIZE / 3)

struct cpuinfo_eti_bsp {
	unsigned long pgtable_cache_sz;
	unsigned long *pgd_quick;
	unsigned long *pte_quick;
};

extern struct cpuinfo_eti_bsp boot_cpu_data;
#define current_cpu_data boot_cpu_data

#define INIT_MMAP { &init_mm, VMALLOC_START, VMALLOC_END, NULL, PAGE_SHARED, \
                    VM_READ | VM_WRITE | VM_EXEC, 1, NULL, NULL }

/* type thread_struct to go into init_task (in init_task.c) */
#define INIT_TSS { NULL }

#endif /* _LANGUAGE_ASSEMBLY */

#ifdef __KERNEL__

/* size of task_union: task_struct and Kernel stack 
 * 
 * Define KERNEL_STACK_SIZE in terms of the number of pages */
#define KERNEL_STACK_SIZE_ORDER 0
#define KERNEL_STACK_SIZE ((1 << PAGE_SHIFT) << KERNEL_STACK_SIZE_ORDER)

/* fields of CPUID register */
#define ETI_CPUID_FAMILY_MASK 0x00ff0000
#define ETI_CPUID_MAJOR_MASK  0x0000ff00
#define ETI_CPUID_MINOR_MASK  0x000000ff
#define ETI_CPUID_FAMILY_SHIFT 16
#define ETI_CPUID_MAJOR_SHIFT  8
#define ETI_CPUID_MINOR_SHIFT  0

#if !defined (_LANGUAGE_ASSEMBLY)

/* Free all resources held by a thread. */
extern void release_thread(struct task_struct *);
extern pid_t kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);

/* Copy and release all segment info associated with a VM */
#define copy_segments(nr, p, mm)
#define release_segments(mm)
#define forget_segments()

/*
 * Return saved PC of a blocked thread.
 */
extern inline unsigned long thread_saved_pc(struct thread_struct *t)
{
	ETISTUB("thread_saved_pc()");
	return 0;
}


extern inline int user_mode(struct pt_regs *regs )
{
    	return regs->ctx.u.header.u.s.psw & bspregPPL;
}


#define show_regs(regs) ctxPrintContext(regs)

/*
 * Do necessary setup to start up a newly executed thread.
 */
extern void start_thread(struct pt_regs * regs, unsigned long pc, unsigned long sp);

/* Allocation and freeing of basic task resources. */
/*
 * NOTE! The task struct and the stack go together
 */
#define alloc_task_struct() \
((struct task_struct *) __get_free_pages(GFP_KERNEL, KERNEL_STACK_SIZE_ORDER))
#define free_task_struct(p) \
free_pages((unsigned long)(p), KERNEL_STACK_SIZE_ORDER)

#define init_task	(init_task_union.task)
#define init_stack	(init_task_union.stack)

#endif /* !defined (_LANGUAGE_ASSEMBLY) */
#endif /* __KERNEL__ */

#endif /* _ASM_BSP_PROCESSOR_H_ */
