Watt-32 tcp/ip  2.2 dev-rel.10
crit.c
Go to the documentation of this file.
1 
5 /* Targets:
6  * Metaware HighC / PharLap
7  * WatcomC (real/prot mode) \todo finish suport for Watcom
8  * GNU C / djgpp2
9  * real-mode DOS targets
10  *
11  * Copyright (c) 1997-2002 Gisle Vanem <gvanem@yahoo.no>
12  *
13  * Redistribution and use in source and binary forms, with or without
14  * modification, are permitted provided that the following conditions
15  * are met:
16  * 1. Redistributions of source code must retain the above copyright
17  * notice, this list of conditions and the following disclaimer.
18  * 2. Redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in the
20  * documentation and/or other materials provided with the distribution.
21  * 3. All advertising materials mentioning features or use of this software
22  * must display the following acknowledgement:
23  * This product includes software developed by Gisle Vanem
24  * Bergen, Norway.
25  *
26  * THIS SOFTWARE IS PROVIDED BY ME (Gisle Vanem) AND CONTRIBUTORS ``AS IS''
27  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29  * ARE DISCLAIMED. IN NO EVENT SHALL I OR CONTRIBUTORS BE LIABLE FOR ANY
30  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
33  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
35  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  *
37  */
38 
39 #include <stdio.h>
40 #include <stdlib.h>
41 
42 #include "wattcp.h"
43 #include "language.h"
44 #include "x32vm.h"
45 #include "misc.h"
46 
47 #if defined(NOT_USED_ANYMORE) || 1
48 
49 #if (DOSX & PHARLAP)
50 #include <mw/exc.h>
51 #endif
52 
53 #include "nochkstk.h" /* disable stack-checking here */
54 
55 #if defined(__HIGHC__)
56  #pragma off(Call_trace)
57  #pragma off(Prolog_trace)
58  #pragma off(Epilog_trace)
59 #endif
60 
61 #if (DOSX & (PHARLAP|X32VM))
62  static REALPTR int24_old, rmcb;
63 
64  static void cdecl int24_isr (SWI_REGS *reg)
65  {
66  reg->r_ax = 3; /* simply fail the function */
67  } /* note: this only works on DOS 3.0 and above */
68 
69  void int24_restore (void)
70  {
71  if (!rmcb)
72  return;
73  _dx_ulock_pgsn (&int24_isr, 20);
74  _dx_rmiv_set (CRIT_VECT, int24_old);
75  _dx_free_rmode_wrapper (rmcb);
76  rmcb = 0;
77  }
78 
79  void int24_init (void)
80  {
81  if (_watt_os_ver < 0x300)
82  return;
83 
84  _dx_rmiv_get (CRIT_VECT, &int24_old);
85  rmcb = _dx_alloc_rmode_wrapper_iret (int24_isr, 256);
86 
87  if (!rmcb)
88  return;
89 
90  _dx_lock_pgsn (&int24_isr, 20);
91  _dx_rmiv_set (CRIT_VECT, rmcb);
92  RUNDOWN_ADD (int24_restore, 20);
93  }
94 
95 /*---------------------------------------------------------------------*/
96 
97 #elif (defined (__DMC__) && !defined(DMC386)) || defined(__WATCOMC__)
98  static int _far int24_isr (unsigned dev_err, unsigned err_code,
99  unsigned _far *dev_hdr)
100  {
101  ARGSUSED (dev_err);
102  ARGSUSED (dev_hdr);
103  ARGSUSED (err_code);
104  return (_HARDERR_FAIL);
105  }
106 
107  void int24_init (void)
108  {
109  if (_watt_os_ver >= 0x300)
110  _harderr (int24_isr);
111  }
112 
113 /*---------------------------------------------------------------------*/
114 
115 #elif (DOSX & DJGPP)
116  static _go32_dpmi_seginfo rm_cb, int24_old;
117  static __dpmi_regs rm_reg;
118 
119  static void int24_isr (void)
120  {
121  rm_reg.x.ax = 3;
122  }
123 
124  void int24_restore (void)
125  {
126  if (int24_old.rm_segment)
127  {
128  _go32_dpmi_set_real_mode_interrupt_vector (CRIT_VECT, &int24_old);
129  _go32_dpmi_free_real_mode_callback (&rm_cb);
130  int24_old.rm_segment = 0;
131  }
132  }
133 
134  void int24_init (void)
135  {
136  if (_watt_os_ver < 0x300)
137  return;
138 
139  _go32_dpmi_get_real_mode_interrupt_vector (CRIT_VECT, &int24_old);
140  rm_cb.pm_offset = (DWORD) int24_isr;
141  if (_go32_dpmi_allocate_real_mode_callback_iret(&rm_cb,&rm_reg))
142  return;
143 
144  _go32_dpmi_set_real_mode_interrupt_vector (CRIT_VECT, &rm_cb);
145  RUNDOWN_ADD (int24_restore, 20);
146  }
147 
148 /*---------------------------------------------------------------------*/
149 
150 #elif DOSX == 0 /* real-mode targets */
151  static W32_IntrHandler int24_old;
152 
153  static INTR_PROTOTYPE int24_isr (bp,di,si,ds,es,dx,cx,bx,ax,ip,cs,flags)
154  {
155  ax = 3;
156  ARGSUSED (bp); ARGSUSED (di); ARGSUSED (si); ARGSUSED (ds);
157  ARGSUSED (es); ARGSUSED (dx); ARGSUSED (cx); ARGSUSED (bx);
158  ARGSUSED (ax); ARGSUSED (ip); ARGSUSED (cs); ARGSUSED (flags);
159  }
160 
161  void int24_restore (void)
162  {
163  if (int24_old)
164  setvect (CRIT_VECT, int24_old);
165  int24_old = NULL;
166  }
167 
168  void int24_init (void)
169  {
170  if (_watt_os_ver >= 0x300)
171  {
172  int24_old = getvect (CRIT_VECT);
173  setvect (CRIT_VECT, int24_isr);
174  RUNDOWN_ADD (int24_restore, 20);
175  }
176  }
177 #endif
178 
179 #endif /* NOT_USED_ANYMORE */
WORD _watt_os_ver
Definition: misc.c:61
Core definitions.
Definition: ip.h:67
Definition: x32vm.h:16
static struct RMCB_record rmcb[MAX_WRAPPERS]
Definition: x32vm.c:47