1139825Simp/*-
268549Sbenno * Copyright (C) 1995, 1996 Wolfgang Solfrank.
368549Sbenno * Copyright (C) 1995, 1996 TooLs GmbH.
468549Sbenno * All rights reserved.
568549Sbenno *
668549Sbenno * Redistribution and use in source and binary forms, with or without
768549Sbenno * modification, are permitted provided that the following conditions
868549Sbenno * are met:
968549Sbenno * 1. Redistributions of source code must retain the above copyright
1068549Sbenno *    notice, this list of conditions and the following disclaimer.
1168549Sbenno * 2. Redistributions in binary form must reproduce the above copyright
1268549Sbenno *    notice, this list of conditions and the following disclaimer in the
1368549Sbenno *    documentation and/or other materials provided with the distribution.
1468549Sbenno * 3. All advertising materials mentioning features or use of this software
1568549Sbenno *    must display the following acknowledgement:
1668549Sbenno *	This product includes software developed by TooLs GmbH.
1768549Sbenno * 4. The name of TooLs GmbH may not be used to endorse or promote products
1868549Sbenno *    derived from this software without specific prior written permission.
1968549Sbenno *
2068549Sbenno * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
2168549Sbenno * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2268549Sbenno * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2368549Sbenno * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2468549Sbenno * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
2568549Sbenno * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
2668549Sbenno * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
2768549Sbenno * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
2868549Sbenno * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
2968549Sbenno * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3070585Sobrien *
3177944Sobrien *	$NetBSD: frame.h,v 1.2 1999/01/10 10:13:15 tsubai Exp $
3270585Sobrien * $FreeBSD$
3368549Sbenno */
3470585Sobrien
3568549Sbenno#ifndef	_MACHINE_FRAME_H_
3668549Sbenno#define	_MACHINE_FRAME_H_
3768549Sbenno
38103614Sgrehan#include <sys/types.h>
3968549Sbenno
4068549Sbenno/*
4168549Sbenno * We have to save all registers on every trap, because
4268549Sbenno *	1. user could attach this process every time
4368549Sbenno *	2. we must be able to restore all user registers in case of fork
4468549Sbenno * Actually, we do not save the fp registers on trap, since
4568549Sbenno * these are not used by the kernel. They are saved only when switching
4668549Sbenno * between processes using the FPU.
4768549Sbenno *
4868549Sbenno * Change ordering to cluster together these register_t's.		XXX
4968549Sbenno */
5068549Sbennostruct trapframe {
5168549Sbenno	register_t fixreg[32];
5268549Sbenno	register_t lr;
53209975Snwhitehorn	register_t cr;
54209975Snwhitehorn	register_t xer;
5568549Sbenno	register_t ctr;
5668549Sbenno	register_t srr0;
5768549Sbenno	register_t srr1;
58209975Snwhitehorn	register_t exc;
59176742Sraj	union {
60176742Sraj		struct {
61176742Sraj			/* dar & dsisr are only filled on a DSI trap */
62176742Sraj			register_t dar;
63209975Snwhitehorn			register_t dsisr;
64176742Sraj		} aim;
65176742Sraj		struct {
66176742Sraj			register_t dear;
67176742Sraj			register_t esr;
68189100Sraj			register_t dbcr0;
69176742Sraj		} booke;
70176742Sraj	} cpu;
7168549Sbenno};
72176742Sraj
7368549Sbenno/*
74209975Snwhitehorn * FRAMELEN is the size of the stack region used by the low-level trap
75209975Snwhitehorn * handler. It is the size of its data (trapframe) plus the callframe
76209975Snwhitehorn * header (sizeof(struct callframe) - 3 register widths). It must also
77209975Snwhitehorn * be 16-byte aligned.
7868549Sbenno */
79209975Snwhitehorn#define	FRAMELEN	roundup(sizeof(struct trapframe) + \
80209975Snwhitehorn			    sizeof(struct callframe) - 3*sizeof(register_t), 16)
8183682Smp#define	trapframe(td)	((td)->td_frame)
8268549Sbenno
8368549Sbenno/*
8468549Sbenno * Call frame for PowerPC used during fork.
8568549Sbenno */
86209975Snwhitehorn#ifdef __powerpc64__
8768549Sbennostruct callframe {
88132520Sgrehan	register_t	cf_dummy_fp;	/* dummy frame pointer */
89209975Snwhitehorn	register_t	cf_cr;
90209975Snwhitehorn	register_t	cf_lr;
91209975Snwhitehorn	register_t	cf_compiler;
92209975Snwhitehorn	register_t	cf_linkeditor;
93209975Snwhitehorn	register_t	cf_toc;
94209975Snwhitehorn	register_t	cf_func;
95209975Snwhitehorn	register_t	cf_arg0;
96209975Snwhitehorn	register_t	cf_arg1;
97255897Snwhitehorn	register_t	_padding;	/* Maintain 16-byte alignment */
98209975Snwhitehorn};
99209975Snwhitehorn#else
100209975Snwhitehornstruct callframe {
101209975Snwhitehorn	register_t	cf_dummy_fp;	/* dummy frame pointer */
102132520Sgrehan	register_t	cf_lr;		/* space for link register save */
10391467Sbenno	register_t	cf_func;
10491467Sbenno	register_t	cf_arg0;
10591467Sbenno	register_t	cf_arg1;
106255897Snwhitehorn	register_t	_padding;	/* Maintain 16-byte alignment */
10768549Sbenno};
108209975Snwhitehorn#endif
10968549Sbenno
11097397Sbenno/* Definitions for syscalls */
11197397Sbenno#define	FIRSTARG	3				/* first arg in reg 3 */
11297397Sbenno#define	NARGREG		8				/* 8 args in regs */
113209975Snwhitehorn#define	MOREARGS(sp)	((caddr_t)((uintptr_t)(sp) + \
114209975Snwhitehorn    sizeof(struct callframe) - 3*sizeof(register_t))) /* more args go here */
11597397Sbenno
11668549Sbenno#endif	/* _MACHINE_FRAME_H_ */
117