Loading...
   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
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
/*
 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
 *
 * @APPLE_LICENSE_HEADER_START@
 * 
 * The contents of this file constitute Original Code as defined in and
 * are subject to the Apple Public Source License Version 1.1 (the
 * "License").  You may not use this file except in compliance with the
 * License.  Please obtain a copy of the License at
 * http://www.apple.com/publicsource and read it before using this file.
 * 
 * This Original Code and all software distributed under the License are
 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
 * License for the specific language governing rights and limitations
 * under the License.
 * 
 * @APPLE_LICENSE_HEADER_END@
 */
/*
 * Copyright 1996 1995 by Open Software Foundation, Inc. 1997 1996 1995 1994 1993 1992 1991  
 *              All Rights Reserved 
 *  
 * Permission to use, copy, modify, and distribute this software and 
 * its documentation for any purpose and without fee is hereby granted, 
 * provided that the above copyright notice appears in all copies and 
 * that both the copyright notice and this permission notice appear in 
 * supporting documentation. 
 *  
 * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE 
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
 * FOR A PARTICULAR PURPOSE. 
 *  
 * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR 
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 
 * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, 
 * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION 
 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 
 * 
 */
/*
 * Copyright 1996 1995 by Apple Computer, Inc. 1997 1996 1995 1994 1993 1992 1991  
 *              All Rights Reserved 
 *  
 * Permission to use, copy, modify, and distribute this software and 
 * its documentation for any purpose and without fee is hereby granted, 
 * provided that the above copyright notice appears in all copies and 
 * that both the copyright notice and this permission notice appear in 
 * supporting documentation. 
 *  
 * APPLE COMPUTER DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE 
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
 * FOR A PARTICULAR PURPOSE. 
 *  
 * IN NO EVENT SHALL APPLE COMPUTER BE LIABLE FOR ANY SPECIAL, INDIRECT, OR 
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 
 * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, 
 * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION 
 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 
 */

#include <debug.h>
#include <kern/thread_act.h>
#include <mach/thread_status.h>
#include <mach/boolean.h>
#include <kern/misc_protos.h>
#include <kern/simple_lock.h>
#include <ppc/proc_reg.h>
#include <ppc/fpu_protos.h>
#include <ppc/misc_protos.h>
#include <ppc/exception.h>

#if DEBUG
/* These variable may be used to keep track of alignment exceptions */
int alignment_exception_count_user;
int alignment_exception_count_kernel;
#endif

#define	_AINST(x)	boolean_t  align_##x##(unsigned long dsisr,\
					       struct ppc_saved_state *ssp, \
					       struct ppc_float_state *fsp, \
					       unsigned long *align_buffer, \
					       unsigned long dar)


#define	_AFENTRY(name, r, b)	{ #name, align_##name##, r, b, TRUE }
#define	_AENTRY(name, r, b)	{ #name, align_##name##, r, b, FALSE }
#define	_ANIL			{ (void *) 0, (void *) 0, 0, 0 }

_AINST(lwz);
_AINST(stw);
_AINST(lhz);
_AINST(lha);
_AINST(sth);
_AINST(lmw);
_AINST(lfs);
_AINST(lfd);
_AINST(stfs);
_AINST(stfd);
_AINST(lwzu);
_AINST(stwu);
_AINST(lhzu);
_AINST(lhau);
_AINST(sthu);
_AINST(lfsu);
_AINST(lfdu);
_AINST(stfsu);
_AINST(stfdu);
_AINST(lswx);
_AINST(lswi);
_AINST(lwbrx);
_AINST(stwbrx);
_AINST(lhbrx);
_AINST(sthbrx);
_AINST(dcbz);
_AINST(lwzx);
_AINST(stwx);
_AINST(lhzx);
_AINST(lhax);
_AINST(sthx);
_AINST(lfsx);
_AINST(lfdx);
_AINST(stfsx);
_AINST(stfdx);
_AINST(lwzux);
_AINST(stwux);
_AINST(lhzux);
_AINST(lhaux);
_AINST(sthux);
_AINST(stmw);
_AINST(lfsux);
_AINST(lfdux);
_AINST(stfsux);
_AINST(stfdux);

/*
 * Routines to set and get FPU registers.
 */

void GET_FPU_REG(struct ppc_float_state *fsp,
		 unsigned long reg,
		 unsigned long *value);
void SET_FPU_REG(struct ppc_float_state *fsp,
		 unsigned long reg,
		 unsigned long *value);

__inline__ void GET_FPU_REG(struct ppc_float_state *fsp,
			    unsigned long reg,
			    unsigned long *value)
{
	value[0] = ((unsigned long *) &fsp->fpregs[reg])[0];
	value[1] = ((unsigned long *) &fsp->fpregs[reg])[1];
}

__inline__ void SET_FPU_REG(struct ppc_float_state *fsp,
			    unsigned long reg, unsigned long *value)
{
	((unsigned long *) &fsp->fpregs[reg])[0] = value[0]; 
	((unsigned long *) &fsp->fpregs[reg])[1] = value[1];
}


/*
 * Macros to load and set registers according to 
 * a given cast type.
 */

#define	GET_REG(p, reg, value, cast) \
	{ *((cast *) value) = *((cast *) (&p->r0+reg)); }
#define	SET_REG(p, reg, value, cast) \
	{ *((cast *) (&p->r0+reg)) = *((cast *) value); }

/*
 * Macros to help decode the DSISR.
 */

#define	DSISR_BITS_15_16(bits)	((bits>>15) & 0x3)
#define	DSISR_BITS_17_21(bits)	((bits>>10) & 0x1f)	
#define	DSISR_BITS_REG(bits)	((bits>>5) & 0x1f)
#define	DSISR_BITS_RA(bits)	(bits & 0x1f)


struct ppc_align_instruction {
	char		*name;
	boolean_t	(*a_instruct)(unsigned long,
				      struct ppc_saved_state *,
				      struct ppc_float_state *,
				      unsigned long *,
				      unsigned long );
	int		a_readbytes;
	int		a_writebytes;
	boolean_t	a_is_float;
} align_table00[] = {
_AENTRY(lwz, 4, 0),	/* 00 0 0000 */
_ANIL,			/* 00 0 0001 */
_AENTRY(stw, 0, 4),	/* 00 0 0010 */
_ANIL,			/* 00 0 0011 */
_AENTRY(lhz, 2, 0),	/* 00 0 0100 */
_AENTRY(lha, 2, 0),	/* 00 0 0101 */
_AENTRY(sth, 0, 2),	/* 00 0 0110 */
_AENTRY(lmw, 32*4,0),	/* 00 0 0111 */
_AFENTRY(lfs, 4, 0),	/* 00 0 1000 */
_AFENTRY(lfd, 8, 0),	/* 00 0 1001 */
_AFENTRY(stfs, 0, 4),	/* 00 0 1010 */
_AFENTRY(stfd, 0, 8),	/* 00 0 1011 */
_ANIL,			/* 00 0 1100 ?*/
_ANIL,			/* 00 0 1101 - lwa */
_ANIL,			/* 00 0 1110 ?*/
_ANIL,			/* 00 0 1111 - std */
_AENTRY(lwzu, 4, 0),	/* 00 1 0000 */
_ANIL,			/* 00 1 0001 ?*/
_AENTRY(stwu, 0, 4),	/* 00 1 0010 */
_ANIL,			/* 00 1 0011 */
_AENTRY(lhzu, 2, 0),	/* 00 1 0100 */
_AENTRY(lhau, 2, 0),	/* 00 1 0101 */
_AENTRY(sthu, 0, 2),	/* 00 1 0110 */
_AENTRY(stmw, 0, 0),	/* 00 1 0111 */
_AFENTRY(lfsu, 4, 0),	/* 00 1 1000 */
_AFENTRY(lfdu, 8, 0),	/* 00 1 1001 - lfdu */
_AFENTRY(stfsu, 0, 4),	/* 00 1 1010 */
_AFENTRY(stfdu, 0, 8),	/* 00 1 1011 - stfdu */
};

struct ppc_align_instruction align_table01[] = {
_ANIL,			/* 01 0 0000 - ldx */
_ANIL,			/* 01 0 0001 ?*/
_ANIL,			/* 01 0 0010 - stdx */
_ANIL,			/* 01 0 0011 ?*/
_ANIL,			/* 01 0 0100 ?*/
_ANIL,			/* 01 0 0101 - lwax */
_ANIL,			/* 01 0 0110 ?*/
_ANIL,			/* 01 0 0111 ?*/
_AENTRY(lswx,32, 0),	/* 01 0 1000 - lswx */
_AENTRY(lswi,32, 0),	/* 01 0 1001 - lswi */
_ANIL,			/* 01 0 1010 - stswx */
_ANIL,			/* 01 0 1011 - stswi */
_ANIL,			/* 01 0 1100 ?*/
_ANIL,			/* 01 0 1101 ?*/
_ANIL,			/* 01 0 1110 ?*/
_ANIL,			/* 01 0 1111 ?*/
_ANIL,			/* 01 1 0000 - ldux */
_ANIL,			/* 01 1 0001 ?*/
_ANIL,			/* 01 1 0010 - stdux */
_ANIL,			/* 01 1 0011 ?*/
_ANIL,			/* 01 1 0100 ?*/
_ANIL,			/* 01 1 0101 - lwaux */
};

struct ppc_align_instruction align_table10[] = {
_ANIL,			/* 10 0 0000 ?*/
_ANIL,			/* 10 0 0001 ?*/
_ANIL,			/* 10 0 0010 - stwcx. */
_ANIL,			/* 10 0 0011 - stdcx.*/
_ANIL,			/* 10 0 0100 ?*/
_ANIL,			/* 10 0 0101 ?*/
_ANIL,			/* 10 0 0110 ?*/
_ANIL,			/* 10 0 0111 ?*/
_AENTRY(lwbrx, 4, 0),	/* 10 0 1000 */
_ANIL,			/* 10 0 1001 ?*/
_AENTRY(stwbrx, 0, 4),	/* 10 0 1010 */
_ANIL,			/* 10 0 1011 */
_AENTRY(lhbrx, 2, 0),	/* 10 0 1110 */
_ANIL,			/* 10 0 1101 ?*/
_AENTRY(sthbrx, 0, 2),	/* 10 0 1110 */
_ANIL,			/* 10 0 1111 ?*/
_ANIL,			/* 10 1 0000 ?*/
_ANIL,			/* 10 1 0001 ?*/
_ANIL,			/* 10 1 0010 ?*/
_ANIL,			/* 10 1 0011 ?*/
_ANIL,			/* 10 1 0100 - eciwx */
_ANIL,			/* 10 1 0101 ?*/
_ANIL,			/* 10 1 0110 - ecowx */
_ANIL,			/* 10 1 0111 ?*/
_ANIL,			/* 10 1 1000 ?*/
_ANIL,			/* 10 1 1001 ?*/
_ANIL,			/* 10 1 1010 ?*/
_ANIL,			/* 10 1 1011 ?*/
_ANIL,			/* 10 1 1100 ?*/
_ANIL,			/* 10 1 1101 ?*/
_ANIL,			/* 10 1 1110 ?*/
_AENTRY(dcbz, 0, 0),	/* 10 1 1111 */
};

struct ppc_align_instruction align_table11[] = {
_AENTRY(lwzx, 4, 0),	/* 11 0 0000 */
_ANIL,			/* 11 0 0001 ?*/
_AENTRY(stwx, 0, 4),	/* 11 0 0010 */
_ANIL,			/* 11 0 0011 */
_AENTRY(lhzx, 2, 0),	/* 11 0 0100 */
_AENTRY(lhax, 2, 0),	/* 11 0 0101 */
_AENTRY(sthx, 0, 2),	/* 11 0 0110 */
_ANIL,			/* 11 0 0111?*/
_AFENTRY(lfsx, 4, 0),	/* 11 0 1000 */
_AFENTRY(lfdx, 8, 0),	/* 11 0 1001 */
_AFENTRY(stfsx, 0, 4),	/* 11 0 1010 */
_AFENTRY(stfdx, 0, 8),	/* 11 0 1011 */
_ANIL,			/* 11 0 1100 ?*/
_ANIL,			/* 11 0 1101 ?*/
_ANIL,			/* 11 0 1110 ?*/
_ANIL,			/* 11 0 1111 - stfiwx */
_AENTRY(lwzux, 4, 0),	/* 11 1 0000 */
_ANIL,			/* 11 1 0001 ?*/
_AENTRY(stwux, 0, 4),	/* 11 1 0010 */
_ANIL,			/* 11 1 0011 */
_AENTRY(lhzux, 4, 0),	/* 11 1 0100 */
_AENTRY(lhaux, 4, 0),	/* 11 1 0101 */
_AENTRY(sthux, 0, 4),	/* 11 1 0110 */
_ANIL,			/* 11 1 0111 ?*/
_AFENTRY(lfsux, 4, 0),	/* 11 1 1000 */
_AFENTRY(lfdux, 8, 0),	/* 11 1 1001 */
_AFENTRY(stfsux, 0, 4),	/* 11 1 1010 */
_AFENTRY(stfdux, 0, 8),	/* 11 1 1011 */
};


struct ppc_align_instruction_table {
	struct ppc_align_instruction	*table;
	int				size;
} align_tables[4] = {
	align_table00, 	sizeof(align_table00)/
			sizeof(struct ppc_align_instruction),

	align_table01, 	sizeof(align_table01)/
			sizeof(struct ppc_align_instruction),

	align_table10, 	sizeof(align_table10)/
			sizeof(struct ppc_align_instruction),

	align_table11, 	sizeof(align_table11)/
			sizeof(struct ppc_align_instruction)
};

extern int 		real_ncpus;						/* Number of actual CPUs */

/*
 * Alignment Exception Handler
 *
 *
 * This handler is called when the chip attempts
 * to execute an instruction which causes page
 * boundaries to be crossed. Typically, this will
 * happen on stfd* and lfd* instructions.
 * (A request has been made for GNU C compiler
 * NOT to make use of these instructions to 
 * load and store 8 bytes at a time.)
 *
 * This is a *SLOW* handler. There is room for vast
 * improvement. However, it is expected that alignment
 * exceptions will be very infrequent.
 *
 * Not all of the 64 instructions (as listed in 
 * PowerPC Microprocessor Family book under the Alignment
 * Exception section) are handled yet.
 * Only the most common ones which are expected to
 * happen.
 * 
 * -- Michael Burg, Apple Computer, Inc. 1996
 *
 * TODO NMGS finish handler
 */

boolean_t
alignment(unsigned long dsisr, unsigned long dar,
	       struct ppc_saved_state *ssp)
{
	struct ppc_align_instruction_table	*table;
	struct ppc_align_instruction		*entry;
	struct ppc_float_state 				*fpc;
	unsigned long		align_buffer[32];
	boolean_t		success = FALSE;
	thread_act_t act;
	spl_t			s;
	int i;

#if	DEBUG
	if (USER_MODE(ssp->srr1))	(void)hw_atomic_add(&alignment_exception_count_user, 1);
	else 						(void)hw_atomic_add(&alignment_exception_count_kernel, 1);
#endif

	act = current_act();						/* Get the current activation */

	table = &align_tables[DSISR_BITS_15_16(dsisr)];

	if (table == (void *) 0
	|| table->size < DSISR_BITS_17_21(dsisr)) {
#if	DEBUG
		printf("EXCEPTION NOT HANDLED: Out of range.\n");
		printf("dsisr=%X, dar=%X\n",dsisr, dar);
		printf("table=%X\n",DSISR_BITS_15_16(dsisr));
		printf("table->size=%X\n", table->size);
		printf("entry=%X\n",DSISR_BITS_17_21(dsisr));
#endif
		goto out;
	}

	entry = &table->table[DSISR_BITS_17_21(dsisr)];

	if (entry->a_instruct == (void *) 0) {
#if	DEBUG
		printf("EXCEPTION NOT HANDLED: Inst out of table range.\n");
		printf("table=%X\n",DSISR_BITS_15_16(dsisr));
		printf("entry=%X\n",DSISR_BITS_17_21(dsisr));
#endif
		goto out;
	}

	/*
	 * Check to see if the instruction is a 
	 * floating point operation. Save off
	 * the FPU register set ...
	 */

	if (entry->a_is_float)
		fpu_save(act);

	/*
	 * Pull in any bytes which are going to be
	 * read.
	 */

	if (entry->a_readbytes) {
		if (USER_MODE(ssp->srr1)) {
			if (copyin((char *) dar,
				   (char *) align_buffer,
				   entry->a_readbytes)) {
				return	TRUE;
			}
		} else {
			bcopy((char *) dar,
			      (char *) align_buffer,
			      entry->a_readbytes);
		}
	}

#if	0 && DEBUG
	printf("Alignment exception: %s %d,0x%x (r%d/w%d) (tmp %x/%x)\n",
	       entry->name, DSISR_BITS_REG(dsisr),
	       dar, entry->a_readbytes, entry->a_writebytes, 
	       align_buffer[0], align_buffer[1]);
	printf("    pc=(0x%08X), msr=(0x%X)",ssp->srr0, ssp->srr1);
#endif

	
	success = entry->a_instruct(dsisr,
				    ssp,
					(entry->a_is_float ? find_user_fpu(act) : 0),	/* Find this user's FPU state if FP op */
				    align_buffer,
				    dar);

	if (success) {
		if (entry->a_writebytes) {
			if (USER_MODE(ssp->srr1)) {
				if (copyout((char *) align_buffer,
					    (char *) dar,
					    entry->a_writebytes)) {
					return	TRUE;
				}
			} else {
				bcopy((char *) align_buffer,
				      (char *) dar,
				      entry->a_writebytes);
			}
		}
		else {
			if(entry->a_is_float) {				/* If we are an FP op, blow away live context */
				for(i=0; i < real_ncpus; i++) {	/* Cycle through processors */
					(void)hw_compare_and_store((unsigned int)act, 0, &per_proc_info[i].FPU_thread);	/* Clear if ours */
				}
			}

			if (USER_MODE(ssp->srr1)) {
				if (copyout((char *) align_buffer,
					    (char *) dar,
					    entry->a_writebytes)) {
					return	TRUE;
				}
			} else {
				bcopy((char *) align_buffer,
				      (char *) dar,
				      entry->a_writebytes);
			}
		}

		ssp->srr0 += 4;	/* Skip the instruction .. */
	}

	return	!success;

out:
#if	0 && DEBUG
	printf("ALIGNMENT EXCEPTION: (dsisr 0x%x) table %d 0x%x\n",
		dsisr, DSISR_BITS_15_16(dsisr), DSISR_BITS_17_21(dsisr));
#endif

	return	TRUE;
}

_AINST(lwz)
{
	SET_REG(ssp, DSISR_BITS_REG(dsisr), align_buffer, unsigned long);

	return	TRUE;
}

_AINST(stw)
{
	GET_REG(ssp, DSISR_BITS_REG(dsisr), align_buffer, unsigned long);

	return	TRUE;
}

_AINST(lhz)
{
	unsigned long value = *((unsigned short *) align_buffer);

	SET_REG(ssp, DSISR_BITS_REG(dsisr), &value, unsigned long);

	return	TRUE;
}

_AINST(lha)
{
	long value = *((short *) align_buffer);

	SET_REG(ssp, DSISR_BITS_REG(dsisr), &value, unsigned long);

	return	TRUE;
}

_AINST(sth)
{
	GET_REG(ssp, DSISR_BITS_REG(dsisr), align_buffer, unsigned short);

	return	TRUE;
}

_AINST(lmw)
{
    int	i;

    for (i = 0; i < (32-DSISR_BITS_REG(dsisr)); i++)
    {
	SET_REG(ssp, DSISR_BITS_REG(dsisr)+i, &align_buffer[i], unsigned long);
    }
    return TRUE;
}

struct fpsp {
	unsigned long	s	:1;	/* Sign bit */
	unsigned long	exp	:8;	/* exponent + bias */
	unsigned long	fraction:23;	/* fraction */
};
typedef struct fpsp fpsp_t, *fpspPtr;

struct fpdp {
	unsigned long	s	:1;	/* Sign bit */
	unsigned long	exp	:11;	/* exponent + bias */
	unsigned long	fraction:20;	/* fraction */
	unsigned long	fraction1;	/* fraction */
};
typedef struct fpdp fpdp_t, *fpdpPtr;


_AINST(lfs)
{
	unsigned long	lalign_buf[2];


	lfs (align_buffer, lalign_buf);
	SET_FPU_REG(fsp, DSISR_BITS_REG(dsisr), lalign_buf);
	return	TRUE;
}

_AINST(lfd)
{
	SET_FPU_REG(fsp, DSISR_BITS_REG(dsisr), align_buffer);
	return	TRUE;
}

_AINST(stfs)
{
	unsigned long	lalign_buf[2];


	GET_FPU_REG(fsp, DSISR_BITS_REG(dsisr), lalign_buf);
	stfs(lalign_buf, align_buffer);
	return TRUE;
}

_AINST(stfd)
{
	GET_FPU_REG(fsp, DSISR_BITS_REG(dsisr), align_buffer);
	return TRUE;
}

_AINST(lwzu)
{
	SET_REG(ssp, DSISR_BITS_REG(dsisr), align_buffer, unsigned long)
	SET_REG(ssp, DSISR_BITS_RA(dsisr), &dar, unsigned long);
	return TRUE;
}

_AINST(stwu)
{
	GET_REG(ssp, DSISR_BITS_REG(dsisr), align_buffer, unsigned long)
	SET_REG(ssp, DSISR_BITS_RA(dsisr), &dar, unsigned long);
	return TRUE;
}


_AINST(lhzu)
{
	SET_REG(ssp, DSISR_BITS_REG(dsisr), align_buffer, unsigned short)
	SET_REG(ssp, DSISR_BITS_RA(dsisr), &dar, unsigned long);
	return TRUE;
}

_AINST(lhau)
{
	unsigned long	value = *((short *) align_buffer);

	SET_REG(ssp, DSISR_BITS_REG(dsisr), &value, unsigned long);
	SET_REG(ssp, DSISR_BITS_RA(dsisr), &dar, unsigned long);

	return	TRUE;
}

_AINST(sthu)
{
	GET_REG(ssp, DSISR_BITS_REG(dsisr), align_buffer, unsigned short)
	SET_REG(ssp, DSISR_BITS_RA(dsisr), &dar, unsigned long);
	return	TRUE;
}

_AINST(stmw)
{
    int	i, rS = DSISR_BITS_REG(dsisr);
    int numRegs = 32 - rS;
    int numBytes = numRegs * 4;
    int retval;


    for (i = 0; i < numRegs; i++)
    {
#if 0
	printf("    align_buffer[%d] == 0x%x\n",i,align_buffer[i]);
#endif
	GET_REG(ssp, rS+i, &align_buffer[i], unsigned long);
#if 0
	printf("    now align_buffer[%d] == 0x%x\n",i,align_buffer[i]);
#endif
    }
    if (USER_MODE(ssp->srr1)) {
	if ((retval=copyout((char *)align_buffer,(char *)dar,numBytes)) != 0) {
	    return FALSE;
	}
#if 0
	printf("    copyout(%X, %X, %X) succeeded\n",align_buffer,dar,numBytes);
#endif
    }
    else {
	bcopy((char *) align_buffer, (char *) dar, numBytes);
    }
    return TRUE;
}

_AINST(lfsu)
{
	unsigned long	lalign_buf[2];


	lfs (align_buffer, lalign_buf);
	SET_FPU_REG(fsp, DSISR_BITS_REG(dsisr), lalign_buf);
	SET_REG(ssp, DSISR_BITS_RA(dsisr), &dar, unsigned long);
	return	TRUE;
}

_AINST(lfdu)
{
	SET_FPU_REG(fsp, DSISR_BITS_REG(dsisr), align_buffer);
	SET_REG(ssp, DSISR_BITS_RA(dsisr), &dar, unsigned long);

	return	TRUE;
}

_AINST(stfsu)
{
	unsigned long	lalign_buf[2];


	GET_FPU_REG(fsp, DSISR_BITS_REG(dsisr), lalign_buf);
	stfs(lalign_buf, align_buffer);
	SET_REG(ssp, DSISR_BITS_RA(dsisr), &dar, unsigned long);
	return	TRUE;
}


_AINST(stfdu)
{
	GET_FPU_REG(fsp, DSISR_BITS_REG(dsisr), align_buffer);
	SET_REG(ssp, DSISR_BITS_RA(dsisr), &dar, unsigned long);

	return	TRUE;
}

_AINST(lswx)
{
    int	i, nb, nr, inst, zero = 0;


    /* check for invalid form of instruction */
    if (DSISR_BITS_RA(dsisr) >= DSISR_BITS_REG(dsisr) )
	return FALSE;

    if (USER_MODE(ssp->srr1)) {
	if (copyin((char *) ssp->srr0, (char *) &inst, 4 )) {
	return	FALSE;
	}
    } else {
	bcopy((char *) ssp->srr0, (char *) &inst, 4 );
    }
	
    nb = (inst >> 11) & 0x1F;	/* get the number of bytes in the instr */
    nr = (nb + sizeof(long)-1) / sizeof(long);/* get the number of regs to copy */

    if ((nr + DSISR_BITS_REG(dsisr)) > 31)
	return FALSE;		/* not supported yet */

    for (i = 0; i < nr; i++)
    {
	SET_REG(ssp, DSISR_BITS_REG(dsisr)+i, &zero, unsigned long);
    }
    /* copy the string into the save state */
    bcopy((char *) align_buffer, (char *) ssp->r0+DSISR_BITS_REG(dsisr), nb );
    return TRUE;
}

_AINST(lswi)
{
    int	i, nb, nr, inst, zero = 0;


    /* check for invalid form of instruction */
    if (DSISR_BITS_RA(dsisr) >= DSISR_BITS_REG(dsisr) )
	return FALSE;

    if (USER_MODE(ssp->srr1)) {
	if (copyin((char *) ssp->srr0, (char *) &inst, 4 )) {
	return	FALSE;
	}
    } else {
	bcopy((char *) ssp->srr0, (char *) &inst, 4 );
    }
	
    nb = (inst >> 11) & 0x1F;	/* get the number of bytes in the instr */
    nr = (nb + sizeof(long)-1) / sizeof(long);/* get the number of regs to copy */

    if ((nr + DSISR_BITS_REG(dsisr)) > 31)
	return FALSE;		/* not supported yet */

    for (i = 0; i < nr; i++)
    {
	SET_REG(ssp, DSISR_BITS_REG(dsisr)+i, &zero, unsigned long);
    }
    /* copy the string into the save state */
    bcopy((char *) align_buffer, (char *) ssp->r0+DSISR_BITS_REG(dsisr), nb );
    return TRUE;
}

_AINST(stswx)
{
	return	FALSE;
}

_AINST(stswi)
{
	return	FALSE;
}







_AINST(stwcx)
{
	return	FALSE;
}

_AINST(stdcx)
{
	return	FALSE;
}

_AINST(lwbrx)
{
	unsigned long 	new_value;

	__asm__ volatile("lwbrx	%0,0,%1" : : "b" (new_value),
			"b" (&align_buffer[0]));

	SET_REG(ssp, DSISR_BITS_REG(dsisr), &new_value, unsigned long);

	return	TRUE;
}

_AINST(stwbrx)
{
	unsigned long	value;

	GET_REG(ssp, DSISR_BITS_REG(dsisr), &value, unsigned long);
	__asm__ volatile("stwbrx	%0,0,%1" : : "b" (value), "b" (&align_buffer[0]));

	return	TRUE;
}

_AINST(lhbrx)
{
	unsigned short	value;

	__asm__ volatile("lhbrx %0,0,%1" : : "b" (value), "b" (&align_buffer[0]));

	SET_REG(ssp, DSISR_BITS_REG(dsisr), &value, unsigned short);

	return	TRUE;
}

_AINST(sthbrx)
{
	unsigned short value;

	GET_REG(ssp, DSISR_BITS_REG(dsisr), &value, unsigned short);
	__asm__ volatile("sthbrx %0,0,%1" : : "b" (value), "b" (&align_buffer[0]));

	return	TRUE;
}

_AINST(eciwx)
{
	return	FALSE;
}

_AINST(ecowx)
{
	return	FALSE;
}

_AINST(dcbz)
{
    long *alignedDAR = (long *)((long)dar & ~(CACHE_LINE_SIZE-1));


    if (USER_MODE(ssp->srr1)) {

	    align_buffer[0] = 0;
	    align_buffer[1] = 0;
	    align_buffer[2] = 0;
	    align_buffer[3] = 0;
	    align_buffer[4] = 0;
	    align_buffer[5] = 0;
	    align_buffer[6] = 0;
	    align_buffer[7] = 0;

	if (copyout((char *)align_buffer,(char *)alignedDAR,CACHE_LINE_SIZE) != 0)
	    return FALSE;
    } else {
	    /* Cannot use bcopy here just in case it caused the exception */
	    alignedDAR[0] = 0;
	    alignedDAR[1] = 0;
	    alignedDAR[2] = 0;
	    alignedDAR[3] = 0;
	    alignedDAR[4] = 0;
	    alignedDAR[5] = 0;
	    alignedDAR[6] = 0;
	    alignedDAR[7] = 0;
    }
    return	TRUE;
}







_AINST(lwzx)
{
	SET_REG(ssp, DSISR_BITS_REG(dsisr), &align_buffer[0], unsigned long);

	return	TRUE;
}

_AINST(stwx)
{
	GET_REG(ssp, DSISR_BITS_REG(dsisr), &align_buffer[0], unsigned long);

	return	TRUE;
}

_AINST(lhzx)
{
	SET_REG(ssp, DSISR_BITS_REG(dsisr), &align_buffer[0], unsigned short);

	return	TRUE;
}

_AINST(lhax)
{
	unsigned long	value	= *((short *) &align_buffer[0]);

	SET_REG(ssp, DSISR_BITS_REG(dsisr), &value, unsigned long);

	return	TRUE;
}

_AINST(sthx)
{
	GET_REG(ssp, DSISR_BITS_REG(dsisr), &align_buffer[0], unsigned short);

	return	TRUE;
}

_AINST(lfsx)
{
	long	lalign_buf[2];


	lfs (align_buffer, lalign_buf);
	SET_FPU_REG(fsp, DSISR_BITS_REG(dsisr), lalign_buf);
	return	TRUE;
}

_AINST(lfdx)
{
	SET_FPU_REG(fsp, DSISR_BITS_REG(dsisr), align_buffer);

	return	TRUE;
}

_AINST(stfsx)
{
	long	lalign_buf[2];


	GET_FPU_REG(fsp, DSISR_BITS_REG(dsisr), lalign_buf);
	stfs(lalign_buf, align_buffer);
	return	TRUE;
}

_AINST(stfdx)
{
	GET_FPU_REG(fsp, DSISR_BITS_REG(dsisr), align_buffer);

	return	TRUE;
}

_AINST(lwzux)
{
	SET_REG(ssp, DSISR_BITS_REG(dsisr), &align_buffer[0], unsigned long);
	SET_REG(ssp, DSISR_BITS_RA(dsisr), &dar, unsigned long);

	return	TRUE;
}

_AINST(stwux)
{
	GET_REG(ssp, DSISR_BITS_REG(dsisr), &align_buffer[0], unsigned long);
	SET_REG(ssp, DSISR_BITS_RA(dsisr), &dar, unsigned long);

	return	TRUE;
}

_AINST(lhzux)
{
	unsigned long value = *((unsigned short *)&align_buffer[0]);

	SET_REG(ssp, DSISR_BITS_REG(dsisr), &value, unsigned long);
	SET_REG(ssp, DSISR_BITS_RA(dsisr), &dar, unsigned long);

	return	TRUE;
}

_AINST(lhaux)
{
	long value = *((short *) &align_buffer[0]);

	SET_REG(ssp, DSISR_BITS_REG(dsisr), &value, unsigned long);
	SET_REG(ssp, DSISR_BITS_RA(dsisr), &dar, unsigned long);

	return	TRUE;
}

_AINST(sthux)
{
	GET_REG(ssp, DSISR_BITS_REG(dsisr), &align_buffer[0], unsigned short);
	SET_REG(ssp, DSISR_BITS_RA(dsisr), &dar, unsigned long);

	return	TRUE;
}

_AINST(lfsux)
{
	long	lalign_buf[2];


	lfs (align_buffer, lalign_buf);
	SET_FPU_REG(fsp, DSISR_BITS_REG(dsisr), lalign_buf);
	SET_REG(ssp, DSISR_BITS_RA(dsisr), &dar, unsigned long);
	return	TRUE;
}

_AINST(lfdux)
{
	SET_FPU_REG(fsp, DSISR_BITS_REG(dsisr), &align_buffer[0]);
	SET_REG(ssp, DSISR_BITS_RA(dsisr), &dar, unsigned long);

	return	TRUE;
}


_AINST(stfsux)
{
	long	lalign_buf[2];


	GET_FPU_REG(fsp, DSISR_BITS_REG(dsisr), lalign_buf);
	stfs(lalign_buf, align_buffer);
	SET_REG(ssp, DSISR_BITS_RA(dsisr), &dar, unsigned long);
	return	TRUE;
}

_AINST(stfdux)
{
	GET_FPU_REG(fsp, DSISR_BITS_REG(dsisr), &align_buffer[0]);
	SET_REG(ssp, DSISR_BITS_RA(dsisr), &dar, unsigned long);

	return	TRUE;
}