/*
 * include/asm-m68k/processor.h
 *
 * Copyright (C) 1995 Hamish Macdonald
 */

#ifndef __ASM_M68K_PROCESSOR_H
#define __ASM_M68K_PROCESSOR_H

#include <asm/segment.h>

/*
 * User space process size: 3.75GB. This is hardcoded into a few places,
 * so don't change it unless you know what you are doing.
 */
#define TASK_SIZE	(0xF0000000UL)

/*
 * Bus types
 */
#define EISA_bus__is_a_macro	1
#define EISA_bus 0
#define MCA_bus__is_a_macro	1
#define MCA_bus 0

/*
 * The m68k has no problems with write protection
 */
#define wp_works_ok__is_a_macro	1
#define wp_works_ok 1

/* MAX floating point unit state size (FSAVE/FRESTORE) */
#define FPSTATESIZE   (216/sizeof(unsigned short))

/* 
 * if you change this structure, you must change the code and offsets
 * in m68k/machasm.S
 */
   
struct thread_struct {
	unsigned long  regs[12];	/* d2-d7/a2-a7 */
	unsigned short sr;		/* saved status register */
	unsigned short fs;		/* saved fs (sfc, dfc) */
	unsigned long  *pagedir_v;	/* root page table virtual addr */
	unsigned long  pagedir_p;	/* root page table physaddr */
	unsigned long  crp[2];		/* cpu root pointer */
	unsigned long  fpregs[24];	/* fp0-fp7 registers */
	unsigned long  fpcntl[3];	/* fp control regs */
	unsigned short fpstate[FPSTATESIZE];  /* floating point state */
	unsigned long  esp0;		/* points to SR of stack frame */
};

#define INIT_MMAP { &init_task, 0, 0x40000000, __pgprot(_PAGE_PRESENT|_PAGE_ACCESSED), VM_READ | VM_WRITE | VM_EXEC }

#ifdef MASTER_STACK
#define INIT_TSS  { \
	{0,0,0,0,0,0,0,0,0,0,0, \
	sizeof(init_kernel_stack) + (long) init_kernel_stack}, \
	PS_S|PS_M, KERNEL_DS, \
	NULL, 0, {0, 0}, \
	{0,}, {0,}, {0,}, \
	0 \
}
#else
#define INIT_TSS  { \
	{0,0,0,0,0,0,0,0,0,0,0, \
	sizeof(init_kernel_stack) + (long) init_kernel_stack}, \
	PS_S, KERNEL_DS, \
	NULL, 0, {0, 0}, \
	{0,}, {0,}, {0,}, \
	0 \
}
#endif

/*
 * Do necessary setup to start up a newly executed thread.
 */
static inline void start_thread(struct pt_regs * regs, unsigned long pc, unsigned long usp)
{
	unsigned long nilstate = 0;

	/* clear registers */
	regs->d1  = 0;
	regs->d2  = 0;
	regs->d3  = 0;
	regs->d4  = 0;
	regs->d5  = 0;
	regs->d6  = 0;
	regs->d7  = 0;
	regs->a0  = 0;
	regs->a1  = 0;
	regs->a2  = 0;
	regs->a3  = 0;
	regs->a4  = 0;
	regs->a5  = 0;
	regs->a6  = 0;

	/* clear floating point state */
	__asm__ __volatile__ ("frestore %0@" : : "a" (&nilstate));

	/* reads from user space */
	set_fs(USER_DS);

	regs->pc = pc;
	regs->sr &= ~0x2000;
	regs->usp = usp;
}

#endif
