/*
 * This file is subject to the terms and conditions of the GNU General Public
 * License.  See the file README.legal in the main directory of this archive
 * for more details.
 */

#ifndef _LINUX_PTRACE_H
#define _LINUX_PTRACE_H
/* ptrace.h */
/* structs and defines to help the user use the ptrace system call. */

/*
 * 680x0 support by Hamish Macdonald
 */

/* has the defines to get at the registers. */

#define PTRACE_TRACEME		   0
#define PTRACE_PEEKTEXT 	   1
#define PTRACE_PEEKDATA 	   2
#define PTRACE_PEEKUSR		   3
#define PTRACE_POKETEXT 	   4
#define PTRACE_POKEDATA 	   5
#define PTRACE_POKEUSR		   6
#define PTRACE_CONT		   7
#define PTRACE_KILL		   8
#define PTRACE_SINGLESTEP	   9

#define PTRACE_ATTACH		0x10
#define PTRACE_DETACH		0x11

#define PTRACE_SYSCALL		  24

/* use ptrace (3 or 6, pid, PT_EXCL, data); to read or write
   the processes registers. */

#if defined(__i386__)

#define EBX 0
#define ECX 1
#define EDX 2
#define ESI 3
#define EDI 4
#define EBP 5
#define EAX 6
#define DS 7
#define ES 8
#define FS 9
#define GS 10
#define ORIG_EAX 11
#define EIP 12
#define CS  13
#define EFL 14
#define UESP 15
#define SS   16


/* this struct defines the way the registers are stored on the 
   stack during a system call. */

struct pt_regs {
  long ebx;
  long ecx;
  long edx;
  long esi;
  long edi;
  long ebp;
  long eax;
  unsigned short ds, __dsu;
  unsigned short es, __esu;
  unsigned short fs, __fsu;
  unsigned short gs, __gsu;
  long orig_eax;
  long eip;
  unsigned short cs, __csu;
  long eflags;
  long esp;
  unsigned short ss, __ssu;
};

/* determines which flags the user has access to. */
/* 1 = access 0 = no access */
#define FLAG_MASK 0x00044dd5

/* set's the trap flag. */
#define TRAP_FLAG 0x100

/*
 * this is the number to subtract from the top of the stack. To find
 * the local frame.
 */
#define MAGICNUMBER 68

#define ptrace_setsingle(child)    \
do { long tmp;                     \
     tmp = ptrace_get_stack_long((child), \
               sizeof(long)*EFL-MAGICNUMBER) | TRAP_FLAG; \
     ptrace_put_stack_long((child),sizeof(long)*EFL-MAGICNUMBER,tmp); } while(0)
#define ptrace_clrsingle(child)    \
do { long tmp;                     \
     tmp = ptrace_get_stack_long((child), \
               sizeof(long)*EFL-MAGICNUMBER) & ~TRAP_FLAG; \
     ptrace_put_stack_long((child),sizeof(long)*EFL-MAGICNUMBER,tmp); } while(0)
#elif defined(__mc68000__)

#define PT_D1	   0
#define PT_D2	   1
#define PT_D3	   2
#define PT_D4	   3
#define PT_D5	   4
#define PT_D6	   5
#define PT_D7	   6
#define PT_A0	   7
#define PT_A1	   8
#define PT_A2	   9
#define PT_A3	   10
#define PT_A4	   11
#define PT_A5	   12
#define PT_A6	   13
#define PT_D0	   14
#define PT_USP	   15
#define PT_ORIG_D0 16
#define PT_SR	   17
#define PT_PC	   18


/* this struct defines the way the registers are stored on the
   stack during a system call. */

struct pt_regs {
  long	d1;
  long	d2;
  long	d3;
  long	d4;
  long	d5;
  long	d6;
  long	d7;
  long	a0;
  long	a1;
  long	a2;
  long	a3;
  long	a4;
  long	a5;
  long	a6;
  long	d0;
  long	usp;
  long	orig_d0;
  short stkadj;
  short sr;
  long	pc;
  short fmtvec;
};

/* determines which bits in the SR the user has access to. */
/* 1 = access 0 = no access */
#define SR_MASK 0x001f

/* sets the trace bits. */
#define TRACE_BITS 0x8000

#define ptrace_setsingle(child)    \
do { long tmp;                     \
     tmp = ptrace_get_stack_long((child), \
               sizeof(long)*PT_SR) | TRACE_BITS; \
     ptrace_put_stack_long((child),sizeof(long)*PT_SR,tmp); } while(0)
#define ptrace_clrsingle(child)    \
do { long tmp;                     \
     tmp = ptrace_get_stack_long((child), \
               sizeof(long)*PT_SR) & ~TRACE_BITS; \
     ptrace_put_stack_long((child),sizeof(long)*PT_SR,tmp); } while(0)
#else
#error Architecture not supported
#endif /* architecture */

extern int ptrace_put_stack_long (struct task_struct *, int, unsigned long);
extern int ptrace_get_stack_long (struct task_struct *, int);
extern int ptrace_read_long(struct task_struct *, long, unsigned long *);
extern int ptrace_write_long(struct task_struct *, long, long);
extern int ptrace_peekusr(struct task_struct *, long, long);
extern int ptrace_pokeusr(struct task_struct *, long, long);

#endif /* _LINUX_PTRACE_H */
