summaryrefslogblamecommitdiffstats
path: root/private/mvdm/softpc.new/base/ccpu386/c_xcptn.c
blob: 69fe8c7670caaa76717d442c9b4ec4454de9ef20 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
































































































































































































































































































































































































































































































































































































































































                                                                                                                 
/*[

c_xcptn.c

LOCAL CHAR SccsID[]="@(#)c_xcptn.c	1.14 01/31/95";

Exception Handling Support.
---------------------------

]*/


#include <stdio.h>
#include <insignia.h>

#include <host_def.h>
#include StringH
#include <xt.h>

#include <c_main.h>
#include <c_addr.h>
#include <c_bsic.h>
#include <c_prot.h>
#include <c_seg.h>
#include <c_stack.h>
#include <c_xcptn.h>
#include <c_reg.h>
#include <c_intr.h>
#include <c_xtrn.h>
#include <ccpupig.h>
#include <fault.h>

/*
   Allow print out of exceptions or disallow it.
 */
GLOBAL BOOL show_exceptions = FALSE;
GLOBAL BOOL trap_exceptions = FALSE;
LOCAL  BOOL first_exception = TRUE;

#define check_exception_env()						\
{									\
	IMPORT char *host_getenv IPT1 (char *, name);			\
	if (first_exception)						\
	{								\
		char *env = host_getenv ("CCPU_SHOW_EXCEPTIONS");	\
		if (env != NULL)					\
		{							\
			show_exceptions = TRUE;				\
			if (strcasecmp(env, "TRAP") == 0)		\
				trap_exceptions = TRUE;			\
		}							\
	}								\
	first_exception = FALSE;					\
}

IMPORT FILE *trace_file;
IMPORT IBOOL took_absolute_toc;

/*
   Intel interrupt(exception) numbers.
 */
#define I0_INT_NR   0
#define I1_INT_NR   1
#define I5_INT_NR   5
#define I6_INT_NR   6
#define I7_INT_NR   7
#define I16_INT_NR 16
#define DF_INT_NR   8
#define GP_INT_NR  13
#define NP_INT_NR  11
#define PF_INT_NR  14
#define SF_INT_NR  12
#define TS_INT_NR  10

#define NULL_ERROR_CODE (IU16)0

/*
   Intel IDT Error Code format.
 */
#define IDT_VECTOR_MASK 0xff
#define IDT_VECTOR_SHIFT   3
#define IDT_INDICATOR_BIT  2

/*
   Interrupt/Fault Status.
 */
GLOBAL BOOL doing_contributory;
GLOBAL BOOL doing_page_fault;
GLOBAL BOOL doing_double_fault;
GLOBAL BOOL doing_fault;	/* true: FAULT, false: TRAP or ABORT */
GLOBAL ISM32 EXT;			/* external/internal source */
GLOBAL IU32 CCPU_save_EIP;	/* IP at start of instruction */

/*
   Prototype our internal functions.
 */
LOCAL VOID check_for_double_fault IPT1(IU16, xcode);

LOCAL VOID check_for_shutdown IPT1(IU16, xcode);

LOCAL VOID benign_exception  IPT3( ISM32, nmbr, ISM32, source, IU16, xcode);

LOCAL VOID contributory_exception  IPT3( IU16, selector, ISM32, nmbr, IU16, xcode);

LOCAL VOID contributory_idt_exception  IPT3( IU16, vector, ISM32, nmbr, IU16, xcode);

LOCAL char *faultstr IPT1(ISM32, nmbr );


/*
   =====================================================================
   INTERNAL ROUTINES START HERE.
   =====================================================================
 */

LOCAL char *faultstr IFN1(ISM32, nmbr )
{
	char *faulttable[] =
	{
		"DIV", "DBG", "NMI", "BPT",
		"OVF", "BND", "OPC", "NAV",
		"DF", "9", "TSS", "NP", "SF",
		"GP", "PF", "15", "FPE", "ALN"
	};
	SAVED char buf[4];

	if (nmbr > 16)
	{
		sprintf(buf, "%d", nmbr);
		return buf;
	}
	else
		return faulttable[nmbr];
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* Determine if things are so bad we need a double fault.             */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
LOCAL VOID 
check_for_double_fault IFN1( IU16, xcode)
   {
   if ( doing_contributory || doing_page_fault )
      DF(xcode);
   }

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* Determine if things are so bad we need to close down.              */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
LOCAL VOID check_for_shutdown IFN1(IU16, xcode)
   {
   if ( doing_double_fault )
      {
      doing_contributory = FALSE;
      doing_page_fault = FALSE;
      doing_double_fault = FALSE;
      EXT = INTERNAL;

      /* force a reset - see schematic for AT motherboard */
      c_cpu_reset();

#ifdef	PIG
      save_last_xcptn_details("Exception:- Shutdown @%2d\n", xcode, 0, 0, 0, 0);
      ccpu_synch_count++;
      pig_cpu_action = CHECK_ALL;
      c_cpu_unsimulate();
#endif	/* PIG */

      /* then carry on */
      c_cpu_continue();   /* DOES NOT RETURN */
      }
   }

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* Handle Benign Exception                                            */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
LOCAL VOID
benign_exception
       	    	               
IFN3(
	ISM32, nmbr,	/* exception number */
	ISM32, source,	/* internal/external interrupt cause */
	IU16, xcode	/* insignia exception code */
    )


   {
   SET_EIP(CCPU_save_EIP);

#ifdef NTVDM
   {
   extern BOOL host_exint_hook IPT2(IS32, exp_no, IS32, error_code);

   if(GET_PE() && host_exint_hook((IS32) nmbr, NULL_ERROR_CODE))
	c_cpu_continue();	/* DOES NOT RETURN */
   }
#endif

   /* Set default mode up */
   SET_OPERAND_SIZE(GET_SR_AR_X(CS_REG));
   SET_ADDRESS_SIZE(GET_SR_AR_X(CS_REG));
   SET_POP_DISP(0);

   EXT = source;
   check_exception_env();
#ifdef	PIG
   save_last_xcptn_details("Exception:- #%s-%d @%2d \n", (IUH)faultstr(nmbr), nmbr, xcode, 0, 0);
#endif	/* PIG */
   if (show_exceptions){
	fprintf(trace_file, "(%04x:%08x)Exception:- %d.\n",
		       GET_CS_SELECTOR(), GET_EIP(), nmbr);
	if (trap_exceptions) force_yoda();
   }
	took_absolute_toc = TRUE;
   do_intrupt((IU16)nmbr, FALSE, FALSE, NULL_ERROR_CODE);

   c_cpu_continue();   /* DOES NOT RETURN */
   }

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* Handle Contributory Exception                                      */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
LOCAL VOID
contributory_exception
       	    		               
IFN3(
	IU16, selector,	/* failing selector */
	ISM32, nmbr,	/* exception number */
	IU16, xcode	/* insignia exception code */
    )


   {
   IU16 error_code;


   /* check if exception caused by external caller */
   check_interface_active(nmbr);

   check_for_shutdown(xcode);
   check_for_double_fault(xcode);

   doing_contributory = TRUE;

   error_code = (selector & 0xfffc) | EXT;

   SET_EIP(CCPU_save_EIP);

#ifdef NTVDM
    {
	extern BOOL host_exint_hook IPT2(IS32, exp_no, IS32, error_code);

	if(GET_PE() && host_exint_hook((IS32) nmbr, (IS32)error_code))
        doing_contributory = FALSE;
	    c_cpu_continue();	    /* DOES NOT RETURN */
    }
#endif

   /* Set default mode up */
   SET_OPERAND_SIZE(GET_SR_AR_X(CS_REG));
   SET_ADDRESS_SIZE(GET_SR_AR_X(CS_REG));
   SET_POP_DISP(0);

   EXT = INTERNAL;
   check_exception_env();
#ifdef	PIG
   save_last_xcptn_details("Exception:- #%s-%d(%04x) @%2d\n", (IUH)faultstr(nmbr), nmbr, error_code, xcode, 0);
#endif	/* PIG */
   if (show_exceptions){
	fprintf(trace_file, "(%04x:%08x)Exception:- %d(%04x).\n",
		       GET_CS_SELECTOR(), GET_EIP(), nmbr, error_code);
        if (trap_exceptions) force_yoda();
   }
	took_absolute_toc = TRUE;
   do_intrupt((IU16)nmbr, FALSE, TRUE, error_code);

   c_cpu_continue();   /* DOES NOT RETURN */
   }

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* Handle Contributory Exception (Via IDT).                           */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
LOCAL VOID
contributory_idt_exception
       	    	               
IFN3(
	IU16, vector,	/* failing interrupt vector */
	ISM32, nmbr,	/* exception number */
	IU16, xcode	/* insignia exception code */
    )


   {
   IU16 error_code;

   /* check if exception caused by external caller */
   check_interface_active(nmbr);

   check_for_shutdown(xcode);
   check_for_double_fault(xcode);

   doing_contributory = TRUE;
   error_code = ((vector & IDT_VECTOR_MASK) << IDT_VECTOR_SHIFT)
		| IDT_INDICATOR_BIT
		| EXT;

   SET_EIP(CCPU_save_EIP);

#ifdef NTVDM
      {
	  extern BOOL host_exint_hook IPT2(IS32, exp_no, IS32, error_code);

	  if(GET_PE() && host_exint_hook((IS32) nmbr, (IS32)error_code))
          doing_contributory = FALSE;
	      c_cpu_continue();	/* DOES NOT RETURN */
      }
#endif

   /* Set default mode up */
   SET_OPERAND_SIZE(GET_SR_AR_X(CS_REG));
   SET_ADDRESS_SIZE(GET_SR_AR_X(CS_REG));
   SET_POP_DISP(0);

   EXT = INTERNAL;
   check_exception_env();
#ifdef	PIG
   save_last_xcptn_details("Exception:- %s-%d(%04x) @%2d\n", (IUH)faultstr(nmbr), nmbr, error_code, xcode, 0);
#endif	/* PIG */
   if (show_exceptions){
	if ( GET_IDT_LIMIT() != 0 ){
           fprintf(trace_file, "(%04x:%08x)Exception:- %d(%04x).\n",
                       GET_CS_SELECTOR(), GET_EIP(), nmbr, error_code);
           if (trap_exceptions) force_yoda();
	}
   }
	took_absolute_toc = TRUE;
   do_intrupt((IU16)nmbr, FALSE, TRUE, error_code);

   c_cpu_continue();   /* DOES NOT RETURN */
   }


/*
   =====================================================================
   EXTERNAL ROUTINES START HERE.
   =====================================================================
 */


/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* Interrupt Table Too Small/Double Fault Exception.                  */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
GLOBAL VOID
DF

IFN1(
	IU16, xcode	/* insignia exception code */
    )
   {
   doing_fault = FALSE;

   if ( GET_PE() == 1 )
      {
      check_for_shutdown(xcode);
      doing_double_fault = TRUE;
      }

   SET_EIP(CCPU_save_EIP);

#ifdef NTVDM
      {
	  extern BOOL host_exint_hook IPT2(IS32, exp_no, IS32, error_code);

	  if(GET_PE() && host_exint_hook((IS32) DF_INT_NR, (IS32)NULL_ERROR_CODE))
            doing_double_fault = FALSE;
		    c_cpu_continue(); /* DOES NOT RETURN */
      }
#endif

   /* Set default mode up */
   SET_OPERAND_SIZE(GET_SR_AR_X(CS_REG));
   SET_ADDRESS_SIZE(GET_SR_AR_X(CS_REG));
   SET_POP_DISP(0);

   EXT = INTERNAL;
   check_exception_env();
#ifdef	PIG
   save_last_xcptn_details("Exception:- #DF-8 @%2d\n", xcode, 0, 0, 0, 0);
#endif	/* PIG */
   if (show_exceptions){
        if ( GET_IDT_LIMIT() != 0 ){
           fprintf(trace_file, "(%04x:%08x)Exception:- %d.\n",
			  GET_CS_SELECTOR(), GET_EIP(), DF_INT_NR);
           if (trap_exceptions) force_yoda();
        }
   }
	took_absolute_toc = TRUE;
   do_intrupt((IU16)DF_INT_NR, FALSE, TRUE, NULL_ERROR_CODE);

   c_cpu_continue();   /* DOES NOT RETURN */
   }

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* General Protection Exception.                                      */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
GLOBAL VOID GP  IFN2( IU16, selector, IU16, xcode)
   {
   doing_fault = TRUE;
   contributory_exception(selector, GP_INT_NR, xcode);
   }

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* General Protection Exception. (Via IDT)                            */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
GLOBAL VOID GP_INT  IFN2( IU16, vector, IU16, xcode)
   {
   doing_fault = TRUE;
   contributory_idt_exception(vector, GP_INT_NR, xcode);
   }

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* Divide Error Exception.                                            */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
GLOBAL VOID Int0 IFN0 ()
   {
   doing_fault = TRUE;
   if ( GET_PE() == 1 )
      {
      doing_contributory = TRUE;
      }

   SET_EIP(CCPU_save_EIP);

#ifdef NTVDM
      {
	  extern BOOL host_exint_hook IPT2(IS32, exp_no, IS32, error_code);

	  if(GET_PE() && host_exint_hook((IS32) I0_INT_NR, (IS32)NULL_ERROR_CODE))
          doing_fault = FALSE;
          doing_contributory = FALSE;
	      c_cpu_continue(); /* DOES NOT RETURN */
      }
#endif

   /* Set default mode up */
   SET_OPERAND_SIZE(GET_SR_AR_X(CS_REG));
   SET_ADDRESS_SIZE(GET_SR_AR_X(CS_REG));
   SET_POP_DISP(0);

   EXT = INTERNAL;

   check_exception_env();
#ifdef	PIG
   save_last_xcptn_details("Exception:- #DIV-0\n", 0, 0, 0, 0, 0);
#endif	/* PIG */
   if (show_exceptions){
        fprintf(trace_file, "(%04x:%08x)Exception:- %d.\n",
		       GET_CS_SELECTOR(), GET_EIP(), I0_INT_NR);
        if (trap_exceptions) force_yoda();
   }
	took_absolute_toc = TRUE;
   do_intrupt((IU16)I0_INT_NR, FALSE, FALSE, NULL_ERROR_CODE);

   c_cpu_continue();   /* DOES NOT RETURN */
   }

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* Single Step Exception. (FAULT)                                     */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
GLOBAL VOID
Int1_f()
   {
   doing_fault = TRUE;
   benign_exception(I1_INT_NR, EXTERNAL, -1);
   }

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* Single Step Exception. (TRAP)                                      */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
GLOBAL VOID
Int1_t()
   {
   doing_fault = FALSE;
   benign_exception(I1_INT_NR, EXTERNAL, -1);
   }

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* Bounds Check Exception.                                            */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
GLOBAL VOID
Int5()
   {
   doing_fault = TRUE;
   benign_exception(I5_INT_NR, INTERNAL, -1);
   }

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* Invalid Opcode Exception.                                          */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
GLOBAL VOID
Int6()
   {
   doing_fault = TRUE;
   benign_exception(I6_INT_NR, INTERNAL, -1);
   }

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* NPX Not Available Exception.                                       */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
GLOBAL VOID
Int7()
   {
   doing_fault = TRUE;
   benign_exception(I7_INT_NR, INTERNAL, -1);
   }

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* NPX Error Exception.                                               */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
GLOBAL VOID
Int16()
   {
   doing_fault = TRUE;
   benign_exception(I16_INT_NR, EXTERNAL, -1);
   }

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* Not Present Exception.                                             */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
GLOBAL VOID NP  IFN2( IU16, selector, IU16, xcode)
   {
   doing_fault = TRUE;
   contributory_exception(selector, NP_INT_NR, xcode);
   }

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* Not Present Exception. (Via IDT)                                   */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
GLOBAL VOID
NP_INT

IFN2(
	IU16, vector,
	IU16, xcode
    )

   {
   doing_fault = TRUE;
   contributory_idt_exception(vector, NP_INT_NR, xcode);
   }

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* Page Fault Exception.                                              */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
GLOBAL VOID
PF
       	          
IFN2(
	IU16, page_error,	/* correctly formatted page fault error code */
	IU16, xcode
    )


   {
   /* check if exception caused by external caller */
   check_interface_active(PF_INT_NR);

   doing_fault = TRUE;

   check_for_shutdown(xcode);

   /* Check for double page fault */
   if ( doing_page_fault )
      DF(xcode);

   doing_page_fault = TRUE;

   SET_EIP(CCPU_save_EIP);

#ifdef NTVDM
      {
	  extern BOOL host_exint_hook IPT2(IS32, exp_no, IS32, error_code);

	  if(GET_PE() && host_exint_hook((IS32) PF_INT_NR, (IS32)page_error))
          doing_fault = FALSE;
          doing_page_fault = FALSE;
	      c_cpu_continue(); /* DOES NOT RETURN */
      }
#endif

   /* Set default mode up */
   SET_OPERAND_SIZE(GET_SR_AR_X(CS_REG));
   SET_ADDRESS_SIZE(GET_SR_AR_X(CS_REG));
   SET_POP_DISP(0);

   check_exception_env();
#ifdef	PIG
   save_last_xcptn_details("Exception:- #PF-14(%04x) CR2=%08x @%2d\n", page_error, GET_CR(CR_PFLA), xcode, 0, 0);
#endif	/* PIG */
   if (show_exceptions){
	fprintf(trace_file, "(%04x:%08x)Exception:- %d(%04x) CR2=%08x.\n",
           GET_CS_SELECTOR(), GET_EIP(), PF_INT_NR, page_error, GET_CR(CR_PFLA));
        if (trap_exceptions) force_yoda();
   }
	took_absolute_toc = TRUE;
   do_intrupt((IU16)PF_INT_NR, FALSE, TRUE, page_error);

   c_cpu_continue();   /* DOES NOT RETURN */
   }

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* Stack Fault Exception.                                             */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
GLOBAL VOID
SF
                 
IFN2(
	IU16, selector,
	IU16, xcode
    )

   {
   doing_fault = TRUE;
   contributory_exception(selector, SF_INT_NR, xcode);
   }


/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* Task Switch Exception.                                             */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
GLOBAL VOID
TS
                 
IFN2(
	IU16, selector,
	IU16, xcode
    )

   {
   doing_fault = TRUE;
   contributory_exception(selector, TS_INT_NR, xcode);
   }