Linux Audio

Check our new training course

Embedded Linux Audio

Check our new training course
with Creative Commons CC-BY-SA
lecture materials

Bootlin logo

Elixir Cross Referencer

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
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
/*
 * alpha/entry.S
 *
 * kernel entry-points
 */

#include <asm/system.h>

#define halt	.long PAL_halt
#define rti	.long PAL_rti
#define SIGCHLD	20

#define NR_SYSCALLS 360
#define osf_vfork sys_fork

/*
 * These offsets must match with "struct hae" in io.h:
 */
#define HAE_CACHE	0
#define HAE_REG		8

/*
 * stack offsets
 */
#define SP_OFF		184

#define SWITCH_STACK_SIZE 320

/*
 * task structure offsets
 */
#define TASK_STATE	0
#define TASK_COUNTER	8
#define TASK_PRIORITY	16
#define TASK_FLAGS	24
#define TASK_SIGPENDING	32	

/*
 * task flags (must match include/linux/sched.h):
 */
#define	PF_PTRACED	0x00000010

/*
 * This defines the normal kernel pt-regs layout.
 *
 * regs 9-15 preserved by C code
 * regs 16-18 saved by PAL-code
 * regs 29-30 saved and set up by PAL-code
 * JRP - Save regs 16-18 in a special area of the stack, so that
 * the palcode-provided values are available to the signal handler.
 */
#define SAVE_ALL			\
	subq	$30,184,$30;		\
	stq	$0,0($30);		\
	stq	$1,8($30);		\
	stq	$2,16($30);		\
	stq	$3,24($30);		\
	stq	$4,32($30);		\
	lda	$2,hae;			\
	stq	$5,40($30);		\
	stq	$6,48($30);		\
	stq	$7,56($30);		\
	stq	$8,64($30);		\
	stq	$19,72($30);		\
	stq	$20,80($30);		\
	stq	$21,88($30);		\
	ldq	$2,HAE_CACHE($2);	\
	stq	$22,96($30);		\
	stq	$23,104($30);		\
	stq	$24,112($30);		\
	stq	$25,120($30);		\
	stq	$26,128($30);		\
	stq	$27,136($30);		\
	stq	$28,144($30);		\
	stq	$2,152($30);		\
	stq	$16,160($30);		\
	stq	$17,168($30);		\
	stq	$18,176($30)

#define RESTORE_ALL			\
	lda	$19,hae;		\
	ldq	$0,0($30);		\
	ldq	$1,8($30);		\
	ldq	$2,16($30);		\
	ldq	$3,24($30);		\
	ldq	$20,152($30);		\
	ldq	$21,HAE_CACHE($19);	\
	ldq	$4,32($30);		\
	ldq	$5,40($30);		\
	ldq	$6,48($30);		\
	ldq	$7,56($30);		\
	subq	$20,$21,$20;		\
	ldq	$8,64($30);		\
	beq	$20,99f;		\
	ldq	$20,HAE_REG($19);	\
	addq	$31,7,$16;		\
	call_pal PAL_swpipl;		\
	stq	$21,HAE_CACHE($19);	\
	stq	$21,0($20);		\
	bis	$0,$0,$16;		\
	call_pal PAL_swpipl;		\
	ldq	$0,0($30);		\
	ldq	$1,8($30);		\
99:;					\
	ldq	$19,72($30);		\
	ldq	$20,80($30);		\
	ldq	$21,88($30);		\
	ldq	$22,96($30);		\
	ldq	$23,104($30);		\
	ldq	$24,112($30);		\
	ldq	$25,120($30);		\
	ldq	$26,128($30);		\
	ldq	$27,136($30);		\
	ldq	$28,144($30);		\
	addq	$30,184,$30

.text
.set noat
#if defined(__linux__) && !defined(__ELF__)
  .set singlegp
#endif

.align 3
.globl	entInt
.ent	entInt
entInt:
	SAVE_ALL
	lda	$8,0x3fff
	bic	$30,$8,$8
	jsr	$26,do_entInt
	br	$31,ret_from_sys_call
.end entInt

.align 3
.globl	entMM
.ent	entMM
entMM:
	SAVE_ALL
/* save $9 - $15 so the inline exception code can manipulate them.  */
	subq	$30,56,$30
	stq	$9,0($30)
	stq	$10,8($30)
	stq	$11,16($30)
	stq	$12,24($30)
	stq	$13,32($30)
	stq	$14,40($30)
	stq	$15,48($30)
	addq	$30,56,$19
/* handle the fault */
	lda	$8,0x3fff
	bic	$30,$8,$8
	jsr	$26,do_page_fault
/* reload the registers after the exception code played.  */
	ldq	$9,0($30)
	ldq	$10,8($30)
	ldq	$11,16($30)
	ldq	$12,24($30)
	ldq	$13,32($30)
	ldq	$14,40($30)
	ldq	$15,48($30)
	addq	$30,56,$30
/* finish up the syscall as normal.  */
	br	ret_from_sys_call
.end entMM

.align 3
.globl	entArith
.ent	entArith
entArith:
	SAVE_ALL
	lda	$8,0x3fff
	bic	$30,$8,$8
	/* How much of a win is this clockwise?  We are, after all, messing
	   up the call/return prefetch stack.  -- rth */
	lda	$27,do_entArith
	lda	$26,ret_from_sys_call
	jsr	$31,($27),do_entArith
.end entArith

.align 3
.globl	entIF
.ent	entIF
entIF:
	SAVE_ALL
	lda	$8,0x3fff
	bic	$30,$8,$8
	lda	$27,do_entIF
	lda	$26,ret_from_sys_call
	jsr	$31,($27),do_entIF
.end entIF

/*
 * Fork() is one of the special system calls: it needs to
 * save the callee-saved regs so that the regs can be found
 * for the new process.. We save them in the "context switch"
 * stack format (see arch/alpha/kernel/process.c).
 *
 * Also, for the kernel fork, we need to fake the system call
 * stack buildup, as we can't do system calls from kernel space.
 */
.align 3
.ent	kernel_clone
kernel_clone:
	.frame $30, 0, $26
	.prologue 0
	subq $30,6*8,$30
	stq $31,0($30)
	stq $26,8($30)
	stq $29,16($30)
	stq $16,24($30)
	stq $17,32($30)
	stq $18,40($30)
	bis $31,2,$0	/* Register v0: syscall nr for fork() */
	SAVE_ALL
	jsr $26,sys_clone
	stq $0,0($30)
	br $31,ret_from_sys_call
.end	kernel_clone

/*
 * __kernel_thread(clone_flags, fn, arg)
 */
.align 3
.globl	__kernel_thread
.ent	__kernel_thread
__kernel_thread:
	ldgp $29,0($27)		/* we can be called from a module */
	.frame $30, 4*8, $26
	subq $30,4*8,$30
	stq $10,16($30)
	stq $9,8($30)
	stq $26,0($30)
	.prologue 1
	bis $17,$17,$9		/* save fn */
	bis $18,$18,$10		/* save arg */
	bsr $26,kernel_clone
	bne $20,1f		/* $20 is non-zero in child */
	ldq $26,0($30)
	ldq $9,8($30)
	ldq $10,16($30)
	addq $30,4*8,$30
	ret $31,($26),1
/* this is in child: look out as we don't have any stack here.. */
1:	bis $9,$9,$27		/* get fn */
	lda $8,0x3fff
	bis $10,$10,$16		/* get arg */
	bic $30,$8,$8		/* get current */
	jsr $26,($27)
	ldgp	$29,0($26)
	bis $0,$0,$16
	jsr $26,sys_exit
	call_pal PAL_halt
.end	__kernel_thread

/*
 * __kernel_execve(path, argv, envp, regs)
 */
.align 3
.globl	__kernel_execve
.ent	__kernel_execve
__kernel_execve:
	ldgp	$29,0($27)	/* we can be called from modules.  */
	subq	$30,16,$30
	.frame	$30,16,$26,0
	stq	$26,0($30)
	stq	$19,8($30)
	.prologue 1
	jsr	$26,do_execve
	bne	$0,1f		/* error! */
	ldq	$30,8($30)
	br	$31,ret_from_sys_call
1:	ldq	$26,0($30)
	addq	$30,16,$30
	ret
.end	__kernel_execve

.align 3
.ent	do_switch_stack
do_switch_stack:
	lda $30,-SWITCH_STACK_SIZE($30)
	stq  $9,0($30)
	stq $10,8($30)
	stq $11,16($30)
	stq $12,24($30)
	stq $13,32($30)
	stq $14,40($30)
	stq $15,48($30)
	stq $26,56($30)
	stt $f0,64($30)
	stt $f1,72($30)
	stt $f2,80($30)
	stt $f3,88($30)
	stt $f4,96($30)
	stt $f5,104($30)
	stt $f6,112($30)
	stt $f7,120($30)
	stt $f8,128($30)
	stt $f9,136($30)
	stt $f10,144($30)
	stt $f11,152($30)
	stt $f12,160($30)
	stt $f13,168($30)
	stt $f14,176($30)
	stt $f15,184($30)
	stt $f16,192($30)
	stt $f17,200($30)
	stt $f18,208($30)
	stt $f19,216($30)
	stt $f20,224($30)
	stt $f21,232($30)
	stt $f22,240($30)
	stt $f23,248($30)
	stt $f24,256($30)
	stt $f25,264($30)
	stt $f26,272($30)
	stt $f27,280($30)
	mf_fpcr $f0		# get fpcr
	stt $f28,288($30)
	stt $f29,296($30)
	stt $f30,304($30)
	stt $f0,312($30)	# save fpcr in slot of $f31
	ret $31,($1),1
.end do_switch_stack

.align 3
.ent	undo_switch_stack
undo_switch_stack:
	ldq  $9,0($30)
	ldq $10,8($30)
	ldq $11,16($30)
	ldq $12,24($30)
	ldq $13,32($30)
	ldq $14,40($30)
	ldq $15,48($30)
	ldq $26,56($30)
	ldt $f30,312($30)	# get saved fpcr
	ldt $f0,64($30)
	ldt $f1,72($30)
	ldt $f2,80($30)
	ldt $f3,88($30)
	mt_fpcr $f30		# install saved fpcr
	ldt $f4,96($30)
	ldt $f5,104($30)
	ldt $f6,112($30)
	ldt $f7,120($30)
	ldt $f8,128($30)
	ldt $f9,136($30)
	ldt $f10,144($30)
	ldt $f11,152($30)
	ldt $f12,160($30)
	ldt $f13,168($30)
	ldt $f14,176($30)
	ldt $f15,184($30)
	ldt $f16,192($30)
	ldt $f17,200($30)
	ldt $f18,208($30)
	ldt $f19,216($30)
	ldt $f20,224($30)
	ldt $f21,232($30)
	ldt $f22,240($30)
	ldt $f23,248($30)
	ldt $f24,256($30)
	ldt $f25,264($30)
	ldt $f26,272($30)
	ldt $f27,280($30)
	ldt $f28,288($30)
	ldt $f29,296($30)
	ldt $f30,304($30)
	lda $30,SWITCH_STACK_SIZE($30)
	ret $31,($1),1
.end undo_switch_stack

.align 3
.globl	entUna
.ent	entUna
entUna:
	lda $30,-256($30)
	stq $0,0($30)
	ldq $0,256($30)		/* get PS */
	stq $1,8($30)
	stq $2,16($30)
	stq $3,24($30)
	and $0,8,$0		/* user mode? */
	stq $4,32($30)
	bne $0,entUnaUser	/* yup -> do user-level unaligned fault */
	stq $5,40($30)
	stq $6,48($30)
	stq $7,56($30)
	stq $8,64($30)
	stq $9,72($30)
	stq $10,80($30)
	stq $11,88($30)
	stq $12,96($30)
	stq $13,104($30)
	stq $14,112($30)
	stq $15,120($30)
	/* 16-18 PAL-saved */
	stq $19,152($30)
	stq $20,160($30)
	stq $21,168($30)
	stq $22,176($30)
	stq $23,184($30)
	stq $24,192($30)
	stq $25,200($30)
	stq $26,208($30)
	stq $27,216($30)
	stq $28,224($30)
	stq $29,232($30)
	stq $30,240($30)
	stq $31,248($30)
	lda $8,0x3fff
	bic $30,$8,$8
	jsr $26,do_entUna
	ldq $0,0($30)
	ldq $1,8($30)
	ldq $2,16($30)
	ldq $3,24($30)
	ldq $4,32($30)
	ldq $5,40($30)
	ldq $6,48($30)
	ldq $7,56($30)
	ldq $8,64($30)
	ldq $9,72($30)
	ldq $10,80($30)
	ldq $11,88($30)
	ldq $12,96($30)
	ldq $13,104($30)
	ldq $14,112($30)
	ldq $15,120($30)
	/* 16-18 PAL-saved */
	ldq $19,152($30)
	ldq $20,160($30)
	ldq $21,168($30)
	ldq $22,176($30)
	ldq $23,184($30)
	ldq $24,192($30)
	ldq $25,200($30)
	ldq $26,208($30)
	ldq $27,216($30)
	ldq $28,224($30)
	ldq $29,232($30)
	ldq $30,240($30)
	lda $30,256($30)
	rti
.end entUna

.align 3
.ent	entUnaUser
entUnaUser:
	ldq $0,0($30)			/* restore original $0 */
	lda $30,256($30)		/* pop entUna's stack frame */
	SAVE_ALL			/* setup normal kernel stack */
	lda $30,-56($30)
	stq $9,0($30)
	stq $10,8($30)
	stq $11,16($30)
	stq $12,24($30)
	stq $13,32($30)
	stq $14,40($30)
	stq $15,48($30)
	lda $8,0x3fff
	addq $30,56,$19
	bic $30,$8,$8
	jsr $26,do_entUnaUser
	ldq $9,0($30)
	ldq $10,8($30)
	ldq $11,16($30)
	ldq $12,24($30)
	ldq $13,32($30)
	ldq $14,40($30)
	ldq $15,48($30)
	lda $30,56($30)
	br $31,ret_from_sys_call

.end	entUnaUser

/*
 * A fork is the same as clone(SIGCHLD, 0);
 */
.align 3
.globl	sys_fork
.ent	sys_fork
sys_fork:
	bsr $1,do_switch_stack
	bis $31,SIGCHLD,$16
	bis $31,$31,$17
	bis $30,$30,$18
	jsr $26,alpha_clone
	bsr $1,undo_switch_stack
	ret $31,($26),1
.end	sys_fork

.align 3
.globl	sys_clone
.ent	sys_clone
sys_clone:
	bsr $1,do_switch_stack
	/* arg1 and arg2 come from the user */
	bis $30,$30,$18
	jsr $26,alpha_clone
	bsr $1,undo_switch_stack
	ret $31,($26),1
.end	sys_clone

.align 3
.globl  alpha_switch_to
.ent    alpha_switch_to
alpha_switch_to:
	bsr $1,do_switch_stack
	call_pal PAL_swpctx
	bsr $1,undo_switch_stack
	ret $31,($26),1
.end alpha_switch_to

/*
 * Oh, well.. Disassembling OSF/1 binaries to find out how the
 * system calls work isn't much fun.
 *
 * entSys is special in that the PAL-code doesn't save a0-a2, so
 * we start off by doing that by hand.
 */
.align 3
.globl	entSys
.globl	ret_from_sys_call
.ent	entSys
entSys:
	SAVE_ALL
	lda	$8,0x3fff
	bic	$30,$8,$8
	lda	$4,NR_SYSCALLS($31)
	stq	$16,SP_OFF+24($30)
	lda	$5,sys_call_table
	lda	$27,alpha_ni_syscall
	cmpult	$0,$4,$4
	ldq	$3,TASK_FLAGS($8)
	stq	$17,SP_OFF+32($30)
	s8addq	$0,$5,$5
	and     $3,PF_PTRACED,$3
	stq	$18,SP_OFF+40($30)
	bne     $3,strace
	beq	$4,1f
	ldq	$27,0($5)
1:	jsr	$26,($27),alpha_ni_syscall
	ldgp	$29,0($26)
	blt	$0,syscall_error	/* the call failed */
	stq	$0,0($30)
	stq	$31,72($30)		/* a3=0 => no error */

.align 3
ret_from_sys_call:
	cmovne	$26,0,$19		/* $19 = 0 => non-restartable */
	/* check bottom half interrupts */
	bne	$1,ret_from_handle_bh
	ldq	$3,bh_active
	ldq	$4,bh_mask
	and	$3,$4,$2
	bne	$2,handle_bottom_half
ret_from_handle_bh:
	ldq	$0,SP_OFF($30)
	and	$0,8,$0
	beq	$0,restore_all
ret_from_reschedule:
	lda	$0,need_resched
	ldl	$2,0($0)
	lda	$4,init_task_union
	bne	$2,reschedule
	xor	$4,$8,$4
	ldl	$5,TASK_SIGPENDING($8)
	beq	$4,restore_all
	bne	$5,signal_return
restore_all:
	RESTORE_ALL
	rti


/* PTRACE syscall handler */
.align 3
strace:
	/* set up signal stack, call syscall_trace */
	bsr	$1,do_switch_stack
	jsr     $26,syscall_trace
	bsr	$1,undo_switch_stack

	/* get the system call number and the arguments back.. */
	ldq     $0,0($30)
	ldq     $16,SP_OFF+24($30)
	ldq     $17,SP_OFF+32($30)
	ldq     $18,SP_OFF+40($30)
	ldq     $19,72($30)
	ldq     $20,80($30)
	ldq     $21,88($30)

	/* get the system call pointer.. */
	lda	$1,NR_SYSCALLS($31)
	lda	$2,sys_call_table
	lda	$27,alpha_ni_syscall
	cmpult	$0,$1,$1
	s8addq	$0,$2,$2
	beq	$1,1f
	ldq	$27,0($2)
1:	jsr	$26,($27),alpha_ni_syscall
	ldgp	$29,0($26)

	/* check return.. */
	blt	$0,strace_error	/* the call failed */
	stq	$31,72($30)		/* a3=0 => no error */
strace_success:
	stq	$0,0($30)		/* save return value */

	bsr	$1,do_switch_stack
	jsr     $26,syscall_trace
	bsr	$1,undo_switch_stack
	br	$31,ret_from_sys_call

	.align  3
strace_error:
	ldq	$19,0($30)	/* old syscall nr (zero if success) */
	beq	$19,strace_success
	ldq	$20,72($30)	/* .. and this a3 */

	subq	$31,$0,$0	/* with error in v0 */
	addq	$31,1,$1	/* set a3 for errno return */
	stq	$0,0($30)
	stq	$1,72($30)	/* a3 for return */

	bsr	$1,do_switch_stack
	bis	$19,$19,$9	/* save old syscall number */
	bis	$20,$20,$10	/* save old a3 */
	jsr     $26,syscall_trace
	bis	$9,$9,$19
	bis	$10,$10,$20
	bsr	$1,undo_switch_stack

	bis	$31,$31,$26	/* tell "ret_from_sys_call" that we can restart */
	br	$31,ret_from_sys_call

	.align 3
handle_bottom_half:
	subq	$30,16,$30
	stq	$19,0($30)	/* save syscall nr */
	stq	$20,8($30)	/* and error indication (a3) */
	jsr	$26,do_bottom_half
	ldq	$19,0($30)
	ldq	$20,8($30)
	addq	$30,16,$30
	br	$31,ret_from_handle_bh

	.align 3
syscall_error:
	/*
	 * Some system calls (e.g., ptrace) can return arbitrary
	 * values which might normally be mistaken as error numbers.
	 * Those functions must zero $0 (v0) directly in the stack
	 * frame to indicate that a negative return value wasn't an
	 * error number..
	 */
	ldq	$19,0($30)	/* old syscall nr (zero if success) */
	beq	$19,ret_success

	ldq	$20,72($30)	/* .. and this a3 */
	subq	$31,$0,$0	/* with error in v0 */
	addq	$31,1,$1	/* set a3 for errno return */
	stq	$0,0($30)
	bis	$31,$31,$26	/* tell "ret_from_sys_call" we can restart */
	stq	$1,72($30)	/* a3 for return */
	br	$31,ret_from_sys_call

ret_success:
	stq	$0,0($30)
	stq	$31,72($30)	/* a3=0 => no error */
	br	$31,ret_from_sys_call

.align 3
signal_return:
	bis	$30,$30,$17
	br	$1,do_switch_stack
	bis	$30,$30,$18
	bis	$31,$31,$16
	jsr	$26,do_signal
	lda	$30,SWITCH_STACK_SIZE($30)
	br	$31,restore_all
.end entSys

.align 3
.ent reschedule
reschedule:
	subq	$30,16,$30
	stq	$19,0($30)	/* save syscall nr */
	stq	$20,8($30)	/* and error indication (a3) */
	jsr	$26,schedule
	ldq	$19,0($30)
	ldq	$20,8($30)
	addq	$30,16,$30
	br	$31,ret_from_reschedule
.end reschedule

.align 3
.ent sys_sigreturn
sys_sigreturn:
	bis	$30,$30,$17
	lda	$30,-SWITCH_STACK_SIZE($30)
	bis	$30,$30,$18
	jsr	$26,do_sigreturn
	br	$1,undo_switch_stack
	br	$31,ret_from_sys_call
.end sys_sigreturn

.align 3
.ent sys_rt_sigreturn
sys_rt_sigreturn:
	bis	$30,$30,$17
	lda	$30,-SWITCH_STACK_SIZE($30)
	bis	$30,$30,$18
	jsr	$26,do_rt_sigreturn
	br	$1,undo_switch_stack
	br	$31,ret_from_sys_call
.end sys_rt_sigreturn

.align 3
.ent sys_sigsuspend
sys_sigsuspend:
	bis	$30,$30,$17
	br	$1,do_switch_stack
	bis	$30,$30,$18
	jsr	$26,do_sigsuspend
	lda	$30,SWITCH_STACK_SIZE($30)
	br	$31,ret_from_sys_call
.end sys_sigsuspend

.align 3
.ent sys_rt_sigsuspend
sys_rt_sigsuspend:
	bis	$30,$30,$18
	br	$1,do_switch_stack
	bis	$30,$30,$19
	jsr	$26,do_rt_sigsuspend
	lda	$30,SWITCH_STACK_SIZE($30)
	br	$31,ret_from_sys_call
.end sys_rt_sigsuspend

	.data
	.align 3
	.globl sys_call_table
sys_call_table:
	.quad alpha_ni_syscall			/* 0 */
	.quad sys_exit
	.quad sys_fork
	.quad sys_read
	.quad sys_write
	.quad alpha_ni_syscall			/* 5 */
	.quad sys_close
	.quad osf_wait4
	.quad alpha_ni_syscall
	.quad sys_link
	.quad sys_unlink			/* 10 */
	.quad alpha_ni_syscall
	.quad sys_chdir
	.quad sys_fchdir
	.quad sys_mknod
	.quad sys_chmod				/* 15 */
	.quad sys_chown
	.quad osf_brk
	.quad alpha_ni_syscall
	.quad sys_lseek
	.quad sys_getxpid			/* 20 */
	.quad osf_mount
	.quad osf_umount
	.quad sys_setuid
	.quad sys_getxuid
	.quad alpha_ni_syscall			/* 25 */
	.quad sys_ptrace
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall			/* 30 */
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad sys_access
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall			/* 35 */
	.quad sys_sync
	.quad sys_kill
	.quad alpha_ni_syscall
	.quad sys_setpgid
	.quad alpha_ni_syscall			/* 40 */
	.quad sys_dup
	.quad sys_pipe
	.quad osf_set_program_attributes
	.quad alpha_ni_syscall
	.quad sys_open				/* 45 */
	.quad alpha_ni_syscall
	.quad sys_getxgid
	.quad osf_sigprocmask
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall			/* 50 */
	.quad sys_acct
	.quad osf_sigpending
	.quad alpha_ni_syscall
	.quad sys_ioctl
	.quad alpha_ni_syscall			/* 55 */
	.quad alpha_ni_syscall
	.quad sys_symlink
	.quad sys_readlink
	.quad sys_execve
	.quad sys_umask				/* 60 */
	.quad sys_chroot
	.quad alpha_ni_syscall
	.quad sys_getpgrp
	.quad sys_getpagesize
	.quad alpha_ni_syscall			/* 65 */
	.quad osf_vfork
	.quad sys_newstat
	.quad sys_newlstat
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall			/* 70 */
	.quad osf_mmap
	.quad alpha_ni_syscall
	.quad sys_munmap
	.quad sys_mprotect
	.quad sys_madvise			/* 75 */
	.quad sys_vhangup
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad sys_getgroups
	/* map BSD's setpgrp to sys_setpgid for binary compatibility: */
	.quad sys_setgroups			/* 80 */
	.quad alpha_ni_syscall
	.quad sys_setpgid
	.quad osf_setitimer
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall			/* 85 */
	.quad osf_getitimer
	.quad sys_gethostname
	.quad sys_sethostname
	.quad sys_getdtablesize
	.quad sys_dup2				/* 90 */
	.quad sys_newfstat
	.quad sys_fcntl
	.quad osf_select
	.quad sys_poll
	.quad sys_fsync				/* 95 */
	.quad sys_setpriority
	.quad sys_socket
	.quad sys_connect
	.quad sys_accept
	.quad osf_getpriority			/* 100 */
	.quad sys_send
	.quad sys_recv
	.quad sys_sigreturn
	.quad sys_bind
	.quad sys_setsockopt			/* 105 */
	.quad sys_listen
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall			/* 110 */
	.quad sys_sigsuspend
	.quad alpha_ni_syscall
	.quad sys_recvmsg
	.quad sys_sendmsg
	.quad alpha_ni_syscall			/* 115 */
	.quad osf_gettimeofday
	.quad osf_getrusage
	.quad sys_getsockopt
	.quad alpha_ni_syscall
	.quad sys_readv				/* 120 */
	.quad sys_writev
	.quad osf_settimeofday
	.quad sys_fchown
	.quad sys_fchmod
	.quad sys_recvfrom			/* 125 */
	.quad sys_setreuid
	.quad sys_setregid
	.quad sys_rename
	.quad sys_truncate
	.quad sys_ftruncate			/* 130 */
	.quad sys_flock
	.quad sys_setgid
	.quad sys_sendto
	.quad sys_shutdown
	.quad sys_socketpair			/* 135 */
	.quad sys_mkdir
	.quad sys_rmdir
	.quad osf_utimes
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall			/* 140 */
	.quad sys_getpeername
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad sys_getrlimit
	.quad sys_setrlimit			/* 145 */
	.quad alpha_ni_syscall
	.quad sys_setsid
	.quad sys_quotactl
	.quad alpha_ni_syscall
	.quad sys_getsockname			/* 150 */
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall			/* 155 */
	.quad osf_sigaction
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad osf_getdirentries
	.quad osf_statfs			/* 160 */
	.quad osf_fstatfs
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad osf_getdomainname			/* 165 */
	.quad sys_setdomainname
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall			/* 170 */
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall			/* 175 */
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall			/* 180 */
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall			/* 185 */
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall			/* 190 */
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall			/* 195 */
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad osf_swapon
	.quad sys_msgctl			/* 200 */
	.quad sys_msgget
	.quad sys_msgrcv
	.quad sys_msgsnd
	.quad sys_semctl
	.quad sys_semget			/* 205 */
	.quad sys_semop
	.quad osf_utsname
	.quad alpha_ni_syscall
	.quad osf_shmat
	.quad sys_shmctl			/* 210 */
	.quad sys_shmdt
	.quad sys_shmget
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall			/* 215 */
	.quad alpha_ni_syscall
	.quad sys_msync
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall			/* 220 */
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall			/* 225 */
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall			/* 230 */
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad sys_getpgid
	.quad sys_getsid
	.quad alpha_ni_syscall			/* 235 */
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall			/* 240 */
	.quad osf_sysinfo
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad osf_proplist_syscall
	.quad alpha_ni_syscall			/* 245 */
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall			/* 250 */
	.quad osf_usleep_thread
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad sys_sysfs
	.quad alpha_ni_syscall			/* 255 */
	.quad osf_getsysinfo
	.quad osf_setsysinfo
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall			/* 260 */
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall			/* 265 */
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall			/* 270 */
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall			/* 275 */
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall			/* 280 */
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall			/* 285 */
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall			/* 290 */
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall			/* 295 */
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
/* linux-specific system calls start at 300 */
	.quad sys_bdflush			/* 300 */
	.quad sys_sethae
	.quad sys_mount
	.quad sys_adjtimex
	.quad sys_swapoff
	.quad sys_getdents			/* 305 */
	.quad alpha_create_module
	.quad sys_init_module
	.quad sys_delete_module
	.quad sys_get_kernel_syms
	.quad sys_syslog			/* 310 */
	.quad sys_reboot
	.quad sys_clone
	.quad sys_uselib
	.quad sys_mlock
	.quad sys_munlock			/* 315 */
	.quad sys_mlockall
	.quad sys_munlockall
	.quad sys_sysinfo
	.quad sys_sysctl
	.quad sys_idle				/* 320 */
	.quad sys_umount
	.quad sys_swapon
	.quad sys_times
	.quad sys_personality
	.quad sys_setfsuid			/* 325 */
	.quad sys_setfsgid
	.quad sys_ustat
	.quad sys_statfs
	.quad sys_fstatfs
	.quad sys_sched_setparam		/* 330 */
	.quad sys_sched_getparam
	.quad sys_sched_setscheduler
	.quad sys_sched_getscheduler
	.quad sys_sched_yield
	.quad sys_sched_get_priority_max	/* 335 */
	.quad sys_sched_get_priority_min
	.quad sys_sched_rr_get_interval
	.quad alpha_ni_syscall /* sys_afs_syscall */
	.quad sys_newuname
	.quad sys_nanosleep			/* 340 */
	.quad sys_mremap
	.quad sys_nfsservctl
	.quad sys_setresuid
	.quad sys_getresuid
	.quad sys_pciconfig_read		/* 345 */
	.quad sys_pciconfig_write
	.quad sys_query_module
	.quad sys_prctl
	.quad sys_pread
	.quad sys_pwrite			/* 350 */
	.quad sys_rt_sigreturn
	.quad sys_rt_sigaction
	.quad sys_rt_sigprocmask
	.quad sys_rt_sigpending
	.quad sys_rt_sigtimedwait		/* 355 */
	.quad sys_rt_sigqueueinfo
	.quad sys_rt_sigsuspend
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall
	.quad alpha_ni_syscall			/* 360 */