39582ecbedf2097bfbe4a892f113164a5f3f2699
[dragonfly.git] / usr.bin / doscmd / register.h
1 /*
2 ** Copyright (c) 1996
3 **      Michael Smith.  All rights reserved.
4 **
5 ** Redistribution and use in source and binary forms, with or without
6 ** modification, are permitted provided that the following conditions
7 ** are met:
8 ** 1. Redistributions of source code must retain the above copyright
9 **    notice, this list of conditions and the following disclaimer.
10 ** 2. Redistributions in binary form must reproduce the above copyright
11 **    notice, this list of conditions and the following disclaimer in the
12 **    documentation and/or other materials provided with the distribution.
13 **
14 ** THIS SOFTWARE IS PROVIDED BY Michael Smith ``AS IS'' AND
15 ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 ** ARE DISCLAIMED.  IN NO EVENT SHALL Michael Smith BE LIABLE
18 ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 ** OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 ** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 ** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 ** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 ** SUCH DAMAGE.
25 **
26 ** $FreeBSD: src/usr.bin/doscmd/register.h,v 1.4 1999/10/08 09:02:38 marcel Exp $
27 ** $DragonFly: src/usr.bin/doscmd/register.h,v 1.4 2004/01/22 03:22:52 rob Exp $
28 */
29
30 /******************************************************************************
31 ** Abstractions to hide register access methods across different platforms.
32 **
33 */
34
35 #ifndef _MACHINE_VM86_H_
36
37 /* standard register representation */
38 typedef union 
39 {
40     u_long      r_ex;
41     struct 
42     {
43         u_short r_x;
44         u_short :16;
45     } r_w;
46     struct
47     {
48         u_char  r_l;
49         u_char  r_h;
50         u_short :16;
51     } r_b;
52 } reg86_t;
53
54 #endif
55
56 #if defined(__DragonFly__)
57
58 /* layout must match definition of struct sigcontext in <machine/signal.h> */
59
60 typedef struct
61 {
62     int         onstack;
63     reg86_t     gs;
64     reg86_t     fs;
65     reg86_t     es;
66     reg86_t     ds;
67     reg86_t     edi;
68     reg86_t     esi;
69     reg86_t     ebp;
70     reg86_t     isp;
71     reg86_t     ebx;
72     reg86_t     edx;
73     reg86_t     ecx;
74     reg86_t     eax;
75     int         pad[2];
76     reg86_t     eip;
77     reg86_t     cs;
78     reg86_t     efl;
79     reg86_t     esp;
80     reg86_t     ss;
81 } registers_t;
82
83 typedef union 
84 {
85     mcontext_t  sc;
86     registers_t r;
87 } regcontext_t;
88
89 /* 
90 ** passed around as a reference to the registers.  This must be in
91 ** scope for the following register macros to work.
92 */
93
94 /* register shorthands */
95 #define R_ESP           (REGS->r.esp.r_ex)
96 #define R_SP            (REGS->r.esp.r_w.r_x)
97 #define R_EBP           (REGS->r.ebp.r_ex)
98 #define R_BP            (REGS->r.ebp.r_w.r_x)
99 #define R_ISP           (REGS->r.isp.r_ex)
100 #define R_EIP           (REGS->r.eip.r_ex)
101 #define R_IP            (REGS->r.eip.r_w.r_x)
102 #define R_EFLAGS        (REGS->r.efl.r_ex)
103 #define R_FLAGS         (REGS->r.efl.r_w.r_x)
104 #define R_EES           (REGS->r.es.r_ex)
105 #define R_ES            (REGS->r.es.r_w.r_x)
106 #define R_EDS           (REGS->r.ds.r_ex)
107 #define R_DS            (REGS->r.ds.r_w.r_x)
108 #define R_ECS           (REGS->r.cs.r_ex)
109 #define R_CS            (REGS->r.cs.r_w.r_x)
110 #define R_ESS           (REGS->r.ss.r_ex)
111 #define R_SS            (REGS->r.ss.r_w.r_x)
112 #define R_EDI           (REGS->r.edi.r_ex)
113 #define R_DI            (REGS->r.edi.r_w.r_x)
114 #define R_ESI           (REGS->r.esi.r_ex)
115 #define R_SI            (REGS->r.esi.r_w.r_x)
116 #define R_EBX           (REGS->r.ebx.r_ex)
117 #define R_BX            (REGS->r.ebx.r_w.r_x)
118 #define R_BL            (REGS->r.ebx.r_b.r_l)
119 #define R_BH            (REGS->r.ebx.r_b.r_h)
120 #define R_EDX           (REGS->r.edx.r_ex)
121 #define R_DX            (REGS->r.edx.r_w.r_x)
122 #define R_DL            (REGS->r.edx.r_b.r_l)
123 #define R_DH            (REGS->r.edx.r_b.r_h)
124 #define R_ECX           (REGS->r.ecx.r_ex)
125 #define R_CX            (REGS->r.ecx.r_w.r_x)
126 #define R_CL            (REGS->r.ecx.r_b.r_l)
127 #define R_CH            (REGS->r.ecx.r_b.r_h)
128 #define R_EAX           (REGS->r.eax.r_ex)
129 #define R_AX            (REGS->r.eax.r_w.r_x)
130 #define R_AL            (REGS->r.eax.r_b.r_l)
131 #define R_AH            (REGS->r.eax.r_b.r_h)
132 #define R_EGS           (REGS->r.gs.r_ex)
133 #define R_GS            (REGS->r.gs.r_w.r_x)
134 #define R_EFS           (REGS->r.fs.r_ex)
135 #define R_FS            (REGS->r.fs.r_w.r_x)
136
137 #endif
138
139 #ifdef __bsdi__
140 #endif
141
142 #ifdef __NetBSD__
143 #endif
144
145 /*
146 ** register manipulation macros 
147 */
148
149 #define PUTVEC(s, o, x) ((s) = ((x) >> 16), (o) = (x) & 0xffff)
150 #define MAKEVEC(s, o)           (((s) << 16) + (o))
151
152 #define PUTPTR(s, o, x) (((s) = ((x) & 0xf0000) >> 4), (o) = (x) & 0xffff)
153 #define MAKEPTR(s, o)           (((s) << 4) + (o))
154
155 #define VECPTR(x)               MAKEPTR((x) >> 16, (x) & 0xffff)
156
157 #define REGISTERS               regcontext_t *REGS
158
159 inline static void
160 PUSH(u_short x, REGISTERS)
161 {
162     R_SP -= 2;
163     *(u_short *)MAKEPTR(R_SS, R_SP) = (x);
164 }
165
166 inline static u_short
167 POP(REGISTERS)
168 {
169     u_short     x;
170     
171     x = *(u_short *)MAKEPTR(R_SS, R_SP);
172     R_SP += 2;
173     return(x);
174 }
175
176 # ifndef PSL_ALLCC      /* Grr, FreeBSD doesn't have this */
177 # define PSL_ALLCC        (PSL_C|PSL_PF|PSL_AF|PSL_Z|PSL_N)
178 # endif