summaryrefslogblamecommitdiffstats
path: root/private/mvdm/softpc.new/base/ccpu386/c_page.c
blob: 540e554f0cb54c8984fd302b0658362c0e7b6a24 (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
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
























































































































































































































































































































































































































































































































































































































































































































































































































































































                                                                              
/*[

c_page.c

LOCAL CHAR SccsID[]="@(#)c_page.c	1.10 02/28/95";

Paging Support.
---------------

]*/


#include <insignia.h>

#include <host_def.h>
#include <xt.h>		/* SoftPC types */
#include <c_main.h>	/* C CPU definitions-interfaces */
#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_page.h>	/* our interface */
#include <c_mem.h>	/* CPU - Physical Memory interface */
#include <c_tlb.h>	/* Translation Lookaside Buffer interface */
#include <ccpusas4.h>	/* CPU <-> sas interface */
#include <c_debug.h>	/* Debugging Regs and Breakpoint interface */


/*[

   Various levels of interface are provided to the paging system (to
   allow fairly optimal emulation) these levels are:-

      spr_chk_	Checks Supervisor Access to given data item, caller
		aware that #PF may occur. 'A/D' bits will be set. No
		other action is taken.

      usr_chk_	Checks User Access to given data item, caller aware
		that #PF may occur. 'A/D' bits will be set. No other
		action is taken.

      spr_	Perform Supervisor Access, caller aware that #PF may
		occur. Action (Read/Write) is performed immediately.
		Will update A/D bits.
      
      vir_	Perform Virtual Memory Operation (Read/Write). No checks
		are made and no fault will be generated, only call after
		a spr_chk or usr_chk function.

	        NB. At present no super optimal vir_ implementation
		    exists. If a spr_chk or usr_chk function is not
		    called before a vir_ function, then the vir_
		    function may cause #PF, this condition will become
		    a fatal error in an optimised implementation.
		    For the moment we assume that after a 'chk' call it
		    is virtually 100% certain that the 'vir' call will
		    get a cache hit.

]*/

#define LAST_DWORD_ON_PAGE 0xffc
#define LAST_WORD_ON_PAGE  0xffe

#define OFFSET_MASK 0xfff

#ifdef	PIG
LOCAL VOID cannot_spr_write_byte IPT2( LIN_ADDR, lin_addr, IU8, valid_mask);
LOCAL VOID cannot_spr_write_word IPT2( LIN_ADDR, lin_addr, IU16, valid_mask);
LOCAL VOID cannot_spr_write_dword IPT2( LIN_ADDR, lin_addr, IU32, valid_mask);
#endif	/* PIG */

/*
   =====================================================================
   EXTERNAL ROUTINES STARTS HERE.
   =====================================================================
 */


/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* Check Supervisor Byte access.                                      */
/* May cause #PF.                                                     */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
GLOBAL PHY_ADDR
spr_chk_byte
       	    		               
IFN2(
	LIN_ADDR, lin_addr,	/* Linear Address */
	ISM32, access	/* Read(PG_R) or Write(PG_W) */
    )


   {
   if ( GET_PG() == 1 )
      {
      access |= PG_S;
      lin_addr = lin2phy(lin_addr, access);
      }

   return lin_addr;
   }

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* Check Supervisor Double Word access.                               */
/* May cause #PF.                                                     */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
GLOBAL VOID
spr_chk_dword
       	    		               
IFN2(
	LIN_ADDR, lin_addr,	/* Linear Address */
	ISM32, access	/* Read(PG_R) or Write(PG_W) */
    )


   {
   if ( GET_PG() == 1 )
      {
      access |= PG_S;
      (VOID)lin2phy(lin_addr, access);
      if ( (lin_addr & OFFSET_MASK) > LAST_DWORD_ON_PAGE )
	 (VOID)lin2phy(lin_addr + 3, access);
      }
   }

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* Check Supervisor Word access.                                      */
/* May cause #PF.                                                     */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
GLOBAL VOID
spr_chk_word
       	    		               
IFN2(
	LIN_ADDR, lin_addr,	/* Linear Address */
	ISM32, access	/* Read(PG_R) or Write(PG_W) */
    )


   {
   if ( GET_PG() == 1 )
      {
      access |= PG_S;
      (VOID)lin2phy(lin_addr, access);
      if ( (lin_addr & OFFSET_MASK) > LAST_WORD_ON_PAGE )
	 (VOID)lin2phy(lin_addr + 1, access);
      }
   }


/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* Check User Byte access.                                            */
/* May cause #PF.                                                     */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
GLOBAL IU32
usr_chk_byte
       	    		               
IFN2(
	LIN_ADDR, lin_addr,	/* Linear Address */
	ISM32, access	/* Read(PG_R) or Write(PG_W) */
    )


   {
   PHY_ADDR phy_addr;

   phy_addr = lin_addr;

   if ( GET_PG() == 1 )
      {
      if ( GET_CPL() == 3 )
	 access |= PG_U;
      else
	 access |= PG_S;

      phy_addr = lin2phy(lin_addr, access);
      }

   return phy_addr;
   }

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* Check User Double Word access.                                     */
/* May cause #PF.                                                     */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
GLOBAL IU32
usr_chk_dword
       	    		               
IFN2(
	LIN_ADDR, lin_addr,	/* Linear Address */
	ISM32, access	/* Read(PG_R) or Write(PG_W) */
    )


   {
   PHY_ADDR phy_addr;

   phy_addr = lin_addr;

   if ( GET_PG() == 1 )
      {
      if ( GET_CPL() == 3 )
	 access |= PG_U;
      else
	 access |= PG_S;

      phy_addr = lin2phy(lin_addr, access);

      if ( (lin_addr & OFFSET_MASK) > LAST_DWORD_ON_PAGE )
	 {
	 (VOID)lin2phy(lin_addr + 3, access);
	 phy_addr = NO_PHYSICAL_MAPPING;
	 }
      }

   return phy_addr;
   }

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* Check User Word access.                                            */
/* May cause #PF.                                                     */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
GLOBAL IU32
usr_chk_word
       	    		               
IFN2(
	LIN_ADDR, lin_addr,	/* Linear Address */
	ISM32, access	/* Read(PG_R) or Write(PG_W) */
    )


   {
   PHY_ADDR phy_addr;

   phy_addr = lin_addr;

   if ( GET_PG() == 1 )
      {
      if ( GET_CPL() == 3 )
	 access |= PG_U;
      else
	 access |= PG_S;

      phy_addr = lin2phy(lin_addr, access);
      if ( (lin_addr & OFFSET_MASK) > LAST_WORD_ON_PAGE )
	 {
	 (VOID)lin2phy(lin_addr + 1, access);
	 phy_addr = NO_PHYSICAL_MAPPING;
	 }
      }

   return phy_addr;
   }


/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* Supervisor Read a Byte from memory.                                */
/* May cause #PF.                                                     */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
GLOBAL IU8
spr_read_byte
       	          
IFN1(
	LIN_ADDR, lin_addr	/* Linear Address */
    )


   {
   if ( GET_PG() == 1 )
      {
      lin_addr = lin2phy(lin_addr, PG_R | PG_S);
      }

   return phy_read_byte(lin_addr);
   }

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* Supervisor Read a Double Word from memory.                         */
/* May cause #PF.                                                     */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
GLOBAL IU32
spr_read_dword
       	          
IFN1(
	LIN_ADDR, lin_addr	/* Linear Address */
    )


   {
   IU16 low_word;
   IU16 high_word;

   if ( GET_PG() == 1 )
      {
      if ( (lin_addr & OFFSET_MASK) > LAST_DWORD_ON_PAGE )
	 {
	 /* Spans two pages */
	 low_word  = spr_read_word(lin_addr);
	 high_word = spr_read_word(lin_addr + 2);
	 return (IU32)high_word << 16 | low_word;
	 }
      else
	 {
	 lin_addr = lin2phy(lin_addr, PG_R | PG_S);
	 }
      }

   return phy_read_dword(lin_addr);
   }

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* Supervisor Read a Word from memory.                                */
/* May cause #PF.                                                     */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
GLOBAL IU16
spr_read_word
       	          
IFN1(
	LIN_ADDR, lin_addr	/* Linear Address */
    )


   {
   IU8 low_byte;
   IU8 high_byte;

   if ( GET_PG() == 1 )
      {
      if ( (lin_addr & OFFSET_MASK) > LAST_WORD_ON_PAGE )
	 {
	 /* Spans two pages */
	 low_byte  = spr_read_byte(lin_addr);
	 high_byte = spr_read_byte(lin_addr + 1);
	 return (IU16)high_byte << 8 | low_byte;
	 }
      else
	 {
	 lin_addr = lin2phy(lin_addr, PG_R | PG_S);
	 }
      }

   return phy_read_word(lin_addr);
   }

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* Supervisor Write a Byte to memory.                                 */
/* May cause #PF.                                                     */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
GLOBAL VOID
spr_write_byte
       	                   
IFN2(
	LIN_ADDR, lin_addr,	/* Linear Address */
	IU8, data
    )


   {
   if ( GET_PG() == 1 )
      {
      lin_addr = lin2phy(lin_addr, PG_W | PG_S);
      }

   phy_write_byte(lin_addr, data);
   }

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* Supervisor Write a Double Word to memory.                          */
/* May cause #PF.                                                     */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
GLOBAL VOID
spr_write_dword
       	                   
IFN2(
	LIN_ADDR, lin_addr,	/* Linear Address */
	IU32, data
    )


   {
   if ( GET_PG() == 1 )
      {
      if ( (lin_addr & OFFSET_MASK) > LAST_DWORD_ON_PAGE )
	 {
	 /* Spans two pages */
	 spr_write_word(lin_addr, (IU16)data);
	 spr_write_word(lin_addr + 2, (IU16)(data >> 16));
         return;
	 }
      else
	 {
	 lin_addr = lin2phy(lin_addr, PG_W | PG_S);
	 }
      }

   phy_write_dword(lin_addr, data);
   }

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* Supervisor Write a Word to memory.                                 */
/* May cause #PF.                                                     */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
GLOBAL VOID
spr_write_word
       	                   
IFN2(
	LIN_ADDR, lin_addr,	/* Linear Address */
	IU16, data
    )


   {
   if ( GET_PG() == 1 )
      {
      if ( (lin_addr & OFFSET_MASK) > LAST_WORD_ON_PAGE )
	 {
	 /* Spans two pages */
	 spr_write_byte(lin_addr, (IU8)data);
	 spr_write_byte(lin_addr + 1, (IU8)(data >> 8));
	 return;
	 }
      else
	 {
	 lin_addr = lin2phy(lin_addr, PG_W | PG_S);
	 }
      }

   phy_write_word(lin_addr, data);
   }

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* Virtual Read Bytes from memory.                                   */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
GLOBAL void
vir_read_bytes
       	    	               
IFN4(
	IU8 *, destbuff,	/* Where the data goes */
	LIN_ADDR, lin_addr,	/* Linear Address */
	PHY_ADDR, phy_addr,	/* Physical Address, if non zero */
	IU32, num_bytes
    )
   {
   if ( nr_data_break )
      {
      check_for_data_exception(lin_addr, D_R, D_BYTE);
      }
   if ( phy_addr ) {
       phy_addr += (num_bytes-1);
       while (num_bytes--) {
		*destbuff++ = phy_read_byte(phy_addr);
		phy_addr--;
       }
   } else {
	lin_addr += (num_bytes-1);
	while (num_bytes--) {
      		*destbuff++ = spr_read_byte(lin_addr);
		lin_addr--;
   	}
   }
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* Virtual Read a Byte from memory.                                   */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
GLOBAL IU8
vir_read_byte
       	    	               
IFN2(
	LIN_ADDR, lin_addr,	/* Linear Address */
	PHY_ADDR, phy_addr	/* Physical Address, if non zero */
    )


   {
   if ( nr_data_break )
      {
      check_for_data_exception(lin_addr, D_R, D_BYTE);
      }

   if ( phy_addr )
      {
      return phy_read_byte(phy_addr);
      }
   else
      {
      return spr_read_byte(lin_addr);
      }
   }

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* Virtual Read a Double Word from memory.                            */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
GLOBAL IU32
vir_read_dword
       	    	               
IFN2(
	LIN_ADDR, lin_addr,	/* Linear Address */
	PHY_ADDR, phy_addr	/* Physical Address, if non zero */
    )


   {
   if ( nr_data_break )
      {
      check_for_data_exception(lin_addr, D_R, D_DWORD);
      }

   if ( phy_addr )
      {
      return phy_read_dword(phy_addr);
      }
   else
      {
      return spr_read_dword(lin_addr);
      }
   }

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* Virtual Read a Word from memory.                                   */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
GLOBAL IU16
vir_read_word
       	    	               
IFN2(
	LIN_ADDR, lin_addr,	/* Linear Address */
	PHY_ADDR, phy_addr	/* Physical Address, if non zero */
    )


   {
   if ( nr_data_break )
      {
      check_for_data_exception(lin_addr, D_R, D_WORD);
      }

   if ( phy_addr )
      {
      return phy_read_word(phy_addr);
      }
   else
      {
      return spr_read_word(lin_addr);
      }
   }

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* Virtual Write Bytes to memory.                                    */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
GLOBAL VOID
vir_write_bytes
       	    	                        
IFN4(
	LIN_ADDR, lin_addr,	/* Linear Address */
	PHY_ADDR, phy_addr,	/* Physical Address, if non zero */
	IU8 *, data,		/* Pointer to data to be written */
	IU32, num_bytes		/* Number of bytes to act on */
    )
   {
   IU8 data_byte;

   check_D(lin_addr, num_bytes);
   if ( nr_data_break ) {
      check_for_data_exception(lin_addr, D_W, D_BYTE);
   }
   if ( phy_addr ) {
	phy_addr += (num_bytes - 1);
	while (num_bytes--) {
		data_byte = *data++;
      		phy_write_byte(phy_addr, data_byte);
		phy_addr--;
	}
   } else {
	lin_addr += (num_bytes - 1);
	while (num_bytes--) {
		data_byte = *data++;
		spr_write_byte(lin_addr, data_byte);
		lin_addr--;
      }
   }
}


/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* Virtual Write a Byte to memory.                                    */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
GLOBAL VOID
vir_write_byte
       	    	                        
IFN3(
	LIN_ADDR, lin_addr,	/* Linear Address */
	PHY_ADDR, phy_addr,	/* Physical Address, if non zero */
	IU8, data
    )


   {
   check_D(lin_addr, 1);
   if ( nr_data_break )
      {
      check_for_data_exception(lin_addr, D_W, D_BYTE);
      }

   if ( phy_addr )
      {
      phy_write_byte(phy_addr, data);
      }
   else
      {
      spr_write_byte(lin_addr, data);
      }
   }

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* Virtual Write a Double Word to memory.                             */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
GLOBAL VOID
vir_write_dword
       	    	                        
IFN3(
	LIN_ADDR, lin_addr,	/* Linear Address */
	PHY_ADDR, phy_addr,	/* Physical Address, if non zero */
	IU32, data
    )


   {
   check_D(lin_addr, 4);
   if ( nr_data_break )
      {
      check_for_data_exception(lin_addr, D_W, D_DWORD);
      }

   if ( phy_addr )
      {
      phy_write_dword(phy_addr, data);
      }
   else
      {
      spr_write_dword(lin_addr, data);
      }
   }

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* Virtual Write a Word to memory.                                    */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
GLOBAL VOID
vir_write_word
       	    	                        
IFN3(
	LIN_ADDR, lin_addr,	/* Linear Address */
	PHY_ADDR, phy_addr,	/* Physical Address, if non zero */
	IU16, data
    )


   {
   check_D(lin_addr, 2);
   if ( nr_data_break )
      {
      check_for_data_exception(lin_addr, D_W, D_WORD);
      }

   if ( phy_addr )
      {
      phy_write_word(phy_addr, data);
      }
   else
      {
      spr_write_word(lin_addr, data);
      }
   }



#ifdef PIG
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* Supervisor Write a Byte to memory                                  */
/* But when Pigging INSD we have no data to write. Just flag address. */
/* May cause #PF.                                                     */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
LOCAL VOID
cannot_spr_write_byte
       	                   
IFN2(
	LIN_ADDR, lin_addr,	/* Linear Address */
	IU8, valid_mask
    )


   {
   if ( GET_PG() == 1 )
      {
      lin_addr = lin2phy(lin_addr, PG_W | PG_S);
      }

   cannot_phy_write_byte(lin_addr, valid_mask);
   }

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* Supervisor Write a Double Word to memory                           */
/* But when Pigging INSD we have no data to write. Just flag address. */
/* May cause #PF.                                                     */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
LOCAL VOID
cannot_spr_write_dword
       	                   
IFN2(
	LIN_ADDR, lin_addr,	/* Linear Address */
	IU32, valid_mask
    )


   {
   if ( GET_PG() == 1 )
      {
      if ( (lin_addr & OFFSET_MASK) > LAST_DWORD_ON_PAGE )
	 {
	 /* Spans two pages */
	 cannot_spr_write_word(lin_addr, valid_mask & 0xffff);
	 cannot_spr_write_word(lin_addr + 2, valid_mask >> 16);
         return;
	 }
      else
	 {
	 lin_addr = lin2phy(lin_addr, PG_W | PG_S);
	 }
      }

   cannot_phy_write_dword(lin_addr, valid_mask);
   }
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* Supervisor Write a Word to memory.                                 */
/* But when Pigging INSW we have no data to write. Just flag address. */
/* May cause #PF.                                                     */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
LOCAL VOID
cannot_spr_write_word
       	                   
IFN2(
	LIN_ADDR, lin_addr,	/* Linear Address */
	IU16, valid_mask
    )


   {
   if ( GET_PG() == 1 )
      {
      if ( (lin_addr & OFFSET_MASK) > LAST_WORD_ON_PAGE )
	 {
	 /* Spans two pages */
	 cannot_spr_write_byte(lin_addr, valid_mask & 0xff);
	 cannot_spr_write_byte(lin_addr + 1, valid_mask >> 8);
	 return;
	 }
      else
	 {
	 lin_addr = lin2phy(lin_addr, PG_W | PG_S);
	 }
      }

   cannot_phy_write_word(lin_addr, valid_mask);
   }


/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* Virtual Write a Byte to memory.                                    */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
GLOBAL VOID
cannot_vir_write_byte
       	    	                        
IFN3(
	LIN_ADDR, lin_addr,	/* Linear Address */
	LIN_ADDR, phy_addr,	/* Physical Address, if non zero */
	IU8, valid_mask
    )


   {
   check_D(lin_addr, 1);
   if ( nr_data_break )
      {
      check_for_data_exception(lin_addr, D_W, D_BYTE);
      }

   if ( phy_addr )
      {
      cannot_phy_write_byte(phy_addr, valid_mask);
      }
   else
      {
      cannot_spr_write_byte(lin_addr, valid_mask);
      }
   }
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* Virtual Write a Double Word to memory.                             */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
GLOBAL VOID
cannot_vir_write_dword
       	    	                        
IFN3(
	LIN_ADDR, lin_addr,	/* Linear Address */
	PHY_ADDR, phy_addr,	/* Physical Address, if non zero */
	IU32, valid_mask
    )


   {
   check_D(lin_addr, 4);
   if ( nr_data_break )
      {
      check_for_data_exception(lin_addr, D_W, D_DWORD);
      }

   if ( phy_addr )
      {
      cannot_phy_write_dword(phy_addr, valid_mask);
      }
   else
      {
      cannot_spr_write_dword(lin_addr, valid_mask);
      }
   }

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* Virtual Write a Word to memory.                                    */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
GLOBAL VOID
cannot_vir_write_word
       	    	                        
IFN3(
	LIN_ADDR, lin_addr,	/* Linear Address */
	PHY_ADDR, phy_addr,	/* Physical Address, if non zero */
	IU16, valid_mask
    )


   {
   check_D(lin_addr, 2);
   if ( nr_data_break )
      {
      check_for_data_exception(lin_addr, D_W, D_WORD);
      }

   if ( phy_addr )
      {
      cannot_phy_write_word(phy_addr, valid_mask);
      }
   else
      {
      cannot_spr_write_word(lin_addr, valid_mask);
      }
   }
#endif	/* PIG */