A
download klglue.S
Language: NonCode
LOC: 0
Project Info
Hurd on Mach on PowerPC(hurdppc)
Server: Savannah NonGNU
Type: cvs
...pc\hurdppc\gnu‑osfmach\ppc\
   _setjmp.S
   alignment.c
   asm.h
   ast.h
   ast_types.h
   bcopy.S
   bits.S
   boot.h
   bzero.S
   cache.S
   clock.h
   console_feed.c
   console_feed_entries.h
   cpu_number.h
   cswtch.S
   db_disasm.c
   db_interface.c
   db_low_trace.c
   db_low_trace.h
   db_machdep.h
   db_trace.c
   endian.h
   exception.h
   Firmware.h
   Firmware.S
   FirmwareCalls.h
   fpu_protos.h
   gdb_defs.h
   genassym.c
   go.c
   hardclock_entries.h
   hw_exception.S
   hw_lock.S
   interrupt.c
   io_map.c
   io_map_entries.h
   iobus.h
   iso_font.h
   kgdb_defs.h
   kgdb_interface.c
   kgdb_setjmp.h
   klglue.S
   lock.h
   low_trace.h
   lowmem_vectors.S
   mach_param.h
   machine_routines.h
   machine_rpc.h
   machlimits.h
   machparam.h
   mem.c
   mem.h
   misc.c
   misc_asm.S
   misc_protos.h
   model_dep.c
   movc.S
   mp.h
   MPinterfaces.S
   ndr_def.h
   net_filter.c
   new_screen.h
   pcb.c
   pmap.c
   pmap.c-broken
   pmap.h
   pmap_internals.h
   ppc_disasm.i
   ppc_init.c
   ppc_rpc.c
   proc_reg.h
   screen.h
   screen_defs.h
   screen_switch.h
   serial_console.c
   serial_defs.h
   setjmp.h
   spl.h
   start.S
   status.c
   strlen.c
   stubs.c
   syscall_subr.h
   task.h
   testjump.c
   thread.h
   thread_act.h
   trap.c
   trap.h
   vm_tuning.h
   xpr.h

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
/*
 * Copyright 1991-1998 by Open Software Foundation, Inc. 
 *              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. 
 */
/*
 * MkLinux
 */

#include <cpus.h>
#include <debug.h>
#include <assym.S>
#include <mach_prof.h>
	
#include <mach/machine/vm_param.h>
#include <ppc/proc_reg.h>
#include <ppc/asm.h>
#include <ppc/spl.h>

/* 
 * boolean_t
 * klcopyinstr (mach_port_t target,
 *		vm_offset_t src,
 *		vm_offset_t dst,
 *		int maxcount,
 *		int *out)
 *
 * Call the 'copyin string' function from a kernel loaded server. We're
 * running in a server thread on its user stack, so switch to the thread's
 * kernel stack to perform the 'copyinstr' operation then switch back.
 */

ENTRY(klcopyinstr, TAG_NO_FRAME_USED)

	/* Save off some user state on the user stack if we need to */

	stwu	r1,	-(FM_SIZE+28)(r1)
	mflr	r0

	stw	r25,	FM_SIZE(r1)
	stw	r26,	FM_SIZE+4(r1)
	stw	r27,	FM_SIZE+8(r1)
	stw	r28,	FM_SIZE+12(r1)
	stw	r29,	FM_SIZE+16(r1)
	stw	r30,	FM_SIZE+20(r1)
	stw	r31,	FM_SIZE+24(r1)
	
	stw	r0,	FM_SIZE+28+FM_LR_SAVE(r1)
	
	/* copy our arguments into callee-saved registers now */
	mr	r31,	ARG1
	mr	r30,	ARG2
	mr	r29,	ARG3
	mr	r28,	ARG4
	
	/* Find the current thread's kernel stack to switch to */	

	mr	r25,	r1	/* temp save of user stack ptr */

	lwz	r27,	PP_CPU_DATA(r2)
	lwz	r27,	CPU_ACTIVE_THREAD(r27)
	lwz	r27,	THREAD_TOP_ACT(r27)
	lwz	r26,	ACT_MACT_PCB(r27)
	lwz	r1,	PCB_KSP(r26)

	/* reserve ourselves a frame on the stack */
	stwu	r1,	-FM_SIZE(r1)

	/* We're at the top of our kernel stack now, mark as busy */

	li	r0,	0
	stw	r0,	PCB_KSP(r26)

	/* save off the user's MSR value, since the kernel may want
	 * to disable our FPU from under our feet
	 */
	mfmsr	r0
	stw	r0,	SS_SRR1(r26)
	
#if DEBUG
	/* Mark as a kl-calling routine by some magic in pcb srr0 for debug */
	lis	r0,	0x000ca11ed@h
	ori	r0,	r0,	0x000ca11ed@l
	stw	r0,	SS_SRR0(r26)
	
	/* Store a debugging backpointer frame */
	lwz	r26,	FM_BACKPTR(r1)	
	stw	r25,	FM_BACKPTR(r26)
	mflr	r0
	stw	r0,	FM_LR_SAVE(r1)
	
	stwu	r1,	-FM_SIZE(r1)

	/* Assert that r2 wasn't modified by server */
	/* TODO NMGS - assumes 1-1 mapping of kernel data */
	mfsprg	r0,	0
	twne	r2,	r0
	
#endif /* DEBUG */

	/* Now do the work we actually want to do */
	
	bl	port_name_to_map

	/* Quit if we can't find a pmap */
	cmpwi	CR0,	ARG0,	0
	bne+	.L_klcopyinstr_ok

	li	r31,	1		/* Return code */
	b	.L_klcopyinstr_out

.L_klcopyinstr_ok:

	/* Save our current map */

	lwz	r26,	ACT_VMMAP(r27)
	
	/* Change the current map to that of the user process */

	stw	ARG0,	ACT_VMMAP(r27)

	mr	ARG0,	r31
	mr	ARG1,	r30
	mr	ARG2,	r29
	mr	ARG3,	r28
	
	bl	copyinstr

	/* Save  return code */
	mr	r31,	ARG0

	lwz	ARG0,	ACT_VMMAP(r27)

	bl	vm_map_deallocate

	/* restore our map */
	
	stw	r26,	ACT_VMMAP(r27)
	
.L_klcopyinstr_out:

	/* We require the value that we're going to return to be in r31 */

.L_klcopyinstr_check_ast:
	
	lwz	r4,	PP_NEED_AST(r2)
	lwz	r4,	0(r4)
	cmpi	CR0,	r4,	0
	beq	CR0,	.L_klcopyinstr_no_ast

	/* Yes there is, call ast_taken 
	 * pretending that the user thread took an AST exception here,
	 * ast_taken will save all state and bring us back here
	 */

	/* disable interrupts */

	li	r3,	MSR_SUPERVISOR_INT_OFF
	mtmsr	r3
	isync		/* For mtmsr */

	li	ARG0,	0
	li	ARG1,	AST_ALL


	/* Perform splhigh and put old spl value in ARG2.
	 * Interrupts have already been disabled
	 */

	lwz	ARG3,	PP_CPU_DATA(r2)
	lwz	ARG2,	CPU_INTERRUPT_LEVEL(ARG3)
	li	r0,	SPLHIGH
	stw	r0,	CPU_INTERRUPT_LEVEL(ARG3)
	
	bl	ast_taken
		/* loop back and check again */
	b	.L_klcopyinstr_check_ast

.L_klcopyinstr_no_ast:

	/* recover return code */
	
	mr	ARG0,	r31

	/* free the kernel stack , unwind the user stack and return */
	
#if DEBUG
	/* skip debugging frame */
	lwz	r1,	FM_BACKPTR(r1)
#endif /* DEBUG */
	/* skip back over our frame */
	lwz	r1,	FM_BACKPTR(r1)
	
	/* reset the server's MSR which may or may not have had its FPU
	 * disabled
	 */
	lwz	r26,	ACT_MACT_PCB(r27)
	lwz	r0,	SS_SRR1(r26)
	mtmsr	r0
	isync
	
	stw	r1,	PCB_KSP(r26)

	/* back on to user stack ... */
	
	mr	r1,	r25
		
	/* recover callee saved registers */

	lwz	r0,	FM_SIZE+28+FM_LR_SAVE(r1)

	lwz	r25,	FM_SIZE(r1)
	lwz	r26,	FM_SIZE+4(r1)
	lwz	r27,	FM_SIZE+8(r1)
	lwz	r28,	FM_SIZE+12(r1)
	lwz	r29,	FM_SIZE+16(r1)
	lwz	r30,	FM_SIZE+20(r1)
	lwz	r31,	FM_SIZE+24(r1)

	mtlr	r0
	
	lwz	r1,	FM_BACKPTR(r1)

	blr

/* 
 * boolean_t
 * klcopyin (mach_port_t target,
 *	     vm_offset_t src,
 *	     vm_offset_t dst,
 *	     int count)
 *
 * Call the 'copyin' function from a kernel loaded server. We're
 * running in a server thread on its user stack, so switch to the thread's
 * kernel stack to perform the 'copyin' operation then switch back.
 */

ENTRY(klcopyin, TAG_NO_FRAME_USED)

	/* Save off some user state on the user stack if we need to */

	stwu	r1,	-(FM_SIZE+28)(r1)
	mflr	r0

	stw	r25,	FM_SIZE(r1)
	stw	r26,	FM_SIZE+4(r1)
	stw	r27,	FM_SIZE+8(r1)
/*	stw	r28,	FM_SIZE+12(r1) */
	stw	r29,	FM_SIZE+16(r1)
	stw	r30,	FM_SIZE+20(r1)
	stw	r31,	FM_SIZE+24(r1)
	
	stw	r0,	FM_SIZE+28+FM_LR_SAVE(r1)
	
	/* copy our arguments into callee-saved registers now */
	mr	r31,	ARG1
	mr	r30,	ARG2
	mr	r29,	ARG3
/*	mr	r28,	ARG4 */
	
	/* Find the current thread's kernel stack to switch to*/	

	mr	r25,	r1	/* temp save of user stack ptr */

	lwz	r27,	PP_CPU_DATA(r2)
	lwz	r27,	CPU_ACTIVE_THREAD(r27)
	lwz	r27,	THREAD_TOP_ACT(r27)
	lwz	r26,	ACT_MACT_PCB(r27)
	lwz	r1,	PCB_KSP(r26)

	/* reserve ourselves a frame on the stack */
	stwu	r1,	-FM_SIZE(r1)

	/* We're at the top of our kernel stack now, mark as busy */

	li	r0,	0
	stw	r0,	PCB_KSP(r26)

	/* save off the user's MSR value, since the kernel will want
	 * to disable our FPU from under our feet
	 */
	mfmsr	r0
	stw	r0,	SS_SRR1(r26)
	
#if DEBUG
	/* Mark as a kl-calling routine by some magic in pcb srr0 for debug */
	lis	r0,	0x000ca11ed@h
	ori	r0,	r0,	0x000ca11ed@l
	stw	r0,	SS_SRR0(r26)
	
	/* Store a debugging backpointer frame */
	lwz	r26,	FM_BACKPTR(r1)	
	stw	r25,	FM_BACKPTR(r26)

	mflr	r0
	stw	r0,	FM_LR_SAVE(r1)
	
	stwu	r1,	-FM_SIZE(r1)

	/* Assert that r2 wasn't modified by server */
	/* TODO NMGS - assumes 1-1 mapping of kernel data */
	mfsprg	r0,	0
	twne	r2,	r0
#endif /* DEBUG */

	/* Now do the work we actually want to do */
	
	bl	port_name_to_map

	/* Quit if we can't find a pmap */
	cmpwi	CR0,	ARG0,	0
	bne+	.L_klcopyin_ok

	li	r31,	1		/* Return code */
	b	.L_klcopyin_out

.L_klcopyin_ok:

	/* Save our current map */

	lwz	r26,	ACT_VMMAP(r27)
	
	/* Change the current map to that of the user process */

	stw	ARG0,	ACT_VMMAP(r27)

	mr	ARG0,	r31
	mr	ARG1,	r30
	mr	ARG2,	r29

	bl	copyin

	/* Save return code */
	mr	r31,	ARG0

	lwz	ARG0,	ACT_VMMAP(r27)

	bl	vm_map_deallocate

	/* restore our map */
	
	stw	r26,	ACT_VMMAP(r27)
	
.L_klcopyin_out:
	/* We require the value that we're going to return to be in r31 */
	
	/* We require the value that we're going to return to be in r31 */

.L_klcopyin_check_ast:
	
	lwz	r4,	PP_NEED_AST(r2)
	lwz	r4,	0(r4)
	cmpi	CR0,	r4,	0
	beq	CR0,	.L_klcopyin_no_ast

	/* Yes there is, call ast_taken 
	 * pretending that the user thread took an AST exception here,
	 * ast_taken will save all state and bring us back here
	 */

	/* disable interrupts */

	li	r3,	MSR_SUPERVISOR_INT_OFF
	mtmsr	r3
	isync		/* For mtmsr */

	li	ARG0,	0
	li	ARG1,	AST_ALL


	/* Perform splhigh and put old spl value in ARG2.
	 * Interrupts have already been disabled
	 */

	lwz	ARG3,	PP_CPU_DATA(r2)
	lwz	ARG2,	CPU_INTERRUPT_LEVEL(ARG3)
	li	r0,	SPLHIGH
	stw	r0,	CPU_INTERRUPT_LEVEL(ARG3)
	
	bl	ast_taken
		/* loop back and check again */
	b	.L_klcopyin_check_ast

.L_klcopyin_no_ast:

	/* recover return code */
	
	mr	ARG0,	r31

	/* free the kernel stack , unwind the user stack and return */
	
#if DEBUG
	/* skip debugging frame */
	lwz	r1,	FM_BACKPTR(r1)
#endif /* DEBUG */
	/* skip back over our frame */
	lwz	r1,	FM_BACKPTR(r1)
	
	/* reset the server's MSR which may or may not have had its FPU
	 * disabled
	 */
	lwz	r26,	ACT_MACT_PCB(r27)
	lwz	r0,	SS_SRR1(r26)
	mtmsr	r0
	isync
	
	stw	r1,	PCB_KSP(r26)

	/* back on to user stack ... */
	
	mr	r1,	r25
		
	/* recover callee saved registers */

	lwz	r0,	FM_SIZE+28+FM_LR_SAVE(r1)

	lwz	r25,	FM_SIZE(r1)
	lwz	r26,	FM_SIZE+4(r1)
	lwz	r27,	FM_SIZE+8(r1)
/*	lwz	r28,	FM_SIZE+12(r1) */
	lwz	r29,	FM_SIZE+16(r1)
	lwz	r30,	FM_SIZE+20(r1)
	lwz	r31,	FM_SIZE+24(r1)

	mtlr	r0
	
	lwz	r1,	FM_BACKPTR(r1)

	blr

/* 
 * boolean_t
 * klcopyout (mach_port_t target,
 *	      vm_offset_t src,
 *	      vm_offset_t dst,
 *	      int count)
 *
 * Call the 'copyout' function from a kernel loaded server. We're
 * running in a server thread on its user stack, so switch to the thread's
 * kernel stack to perform the 'copyout' operation then switch back.
 */

ENTRY(klcopyout, TAG_NO_FRAME_USED)

	/* Save off some user state on the user stack if we need to */

	stwu	r1,	-(FM_SIZE+28)(r1)
	mflr	r0

	stw	r25,	FM_SIZE(r1)
	stw	r26,	FM_SIZE+4(r1)
	stw	r27,	FM_SIZE+8(r1)
/*	stw	r28,	FM_SIZE+12(r1) */
	stw	r29,	FM_SIZE+16(r1)
	stw	r30,	FM_SIZE+20(r1)
	stw	r31,	FM_SIZE+24(r1)
	
	stw	r0,	FM_SIZE+28+FM_LR_SAVE(r1)
	
	/* copy our arguments into callee-saved registers now */
	mr	r31,	ARG1
	mr	r30,	ARG2
	mr	r29,	ARG3
/*	mr	r28,	ARG4 */
	
	/* Find the current thread's kernel stack to switch to*/	

	mr	r25,	r1	/* temp save of user stack ptr */

	lwz	r27,	PP_CPU_DATA(r2)
	lwz	r27,	CPU_ACTIVE_THREAD(r27)
	lwz	r27,	THREAD_TOP_ACT(r27)
	lwz	r26,	ACT_MACT_PCB(r27)
	lwz	r1,	PCB_KSP(r26)

	/* reserve ourselves a frame on the stack */
	stwu	r1,	-FM_SIZE(r1)

	/* We're at the top of our kernel stack now, mark as busy */

	li	r0,	0
	stw	r0,	PCB_KSP(r26)

	/* save off the user's MSR value, since the kernel will want
	 * to disable our FPU from under our feet
	 */
	mfmsr	r0
	stw	r0,	SS_SRR1(r26)
	
#if DEBUG
	/* Mark as a kl-calling routine by some magic in pcb srr0 for debug */
	lis	r0,	0x000ca11ed@h
	ori	r0,	r0,	0x000ca11ed@l
	stw	r0,	SS_SRR0(r26)
	
	/* Store a debugging backpointer frame */
	lwz	r26,	FM_BACKPTR(r1)	
	stw	r25,	FM_BACKPTR(r26)

	mflr	r0
	stw	r0,	FM_LR_SAVE(r1)
	
	stwu	r1,	-FM_SIZE(r1)

	/* Assert that r2 wasn't modified by server */
	/* TODO NMGS - assumes 1-1 mapping of kernel data */
	mfsprg	r0,	0
	twne	r2,	r0
	
#endif /* DEBUG */

	/* Now do the work we actually want to do */
	
	bl	port_name_to_map

	/* Quit if we can't find a pmap */
	cmpwi	CR0,	ARG0,	0
	bne+	.L_klcopyout_ok

	li	r31,	1		/* return code */
	b	.L_klcopyout_out

.L_klcopyout_ok:

	/* Save our current map */

	lwz	r26,	ACT_VMMAP(r27)
	
	/* Change the current map to that of the user process */

	stw	ARG0,	ACT_VMMAP(r27)

	mr	ARG0,	r31
	mr	ARG1,	r30
	mr	ARG2,	r29

	bl	copyout

	/* Save return code */
	mr	r31,	ARG0

	lwz	ARG0,	ACT_VMMAP(r27)

	bl	vm_map_deallocate

	/* restore our map */
	
	stw	r26,	ACT_VMMAP(r27)

.L_klcopyout_out:

	/* We require the value that we're going to return to be in r31 */
	
	/* We require the value that we're going to return to be in r31 */

.L_klcopyoutcheck_ast:
	
	lwz	r4,	PP_NEED_AST(r2)
	lwz	r4,	0(r4)
	cmpi	CR0,	r4,	0
	beq	CR0,	.L_klcopyoutno_ast

	/* Yes there is, call ast_taken 
	 * pretending that the user thread took an AST exception here,
	 * ast_taken will save all state and bring us back here
	 */

	/* disable interrupts */

	li	r3,	MSR_SUPERVISOR_INT_OFF
	mtmsr	r3
	isync		/* For mtmsr */

	li	ARG0,	0
	li	ARG1,	AST_ALL


	/* Perform splhigh and put old spl value in ARG2.
	 * Interrupts have already been disabled
	 */

	lwz	ARG3,	PP_CPU_DATA(r2)
	lwz	ARG2,	CPU_INTERRUPT_LEVEL(ARG3)
	li	r0,	SPLHIGH
	stw	r0,	CPU_INTERRUPT_LEVEL(ARG3)
	
	bl	ast_taken
		/* loop back and check again */
	b	.L_klcopyoutcheck_ast

.L_klcopyoutno_ast:

	/* recover return code */
	
	mr	ARG0,	r31

	/* free the kernel stack , unwind the user stack and return */
	
#if DEBUG
	/* skip debugging frame */
	lwz	r1,	FM_BACKPTR(r1)
#endif /* DEBUG */
	/* skip back over our frame */
	lwz	r1,	FM_BACKPTR(r1)
	
	/* reset the server's MSR which may or may not have had its FPU
	 * disabled
	 */
	lwz	r26,	ACT_MACT_PCB(r27)
	lwz	r0,	SS_SRR1(r26)
	mtmsr	r0
	isync
	
	stw	r1,	PCB_KSP(r26)

	/* back on to user stack ... */
	
	mr	r1,	r25
		
	/* recover callee saved registers */

	lwz	r0,	FM_SIZE+28+FM_LR_SAVE(r1)

	lwz	r25,	FM_SIZE(r1)
	lwz	r26,	FM_SIZE+4(r1)
	lwz	r27,	FM_SIZE+8(r1)
/*	lwz	r28,	FM_SIZE+12(r1) */
	lwz	r29,	FM_SIZE+16(r1)
	lwz	r30,	FM_SIZE+20(r1)
	lwz	r31,	FM_SIZE+24(r1)

	mtlr	r0
	
	lwz	r1,	FM_BACKPTR(r1)

	blr

/*
 * kern_return_t
 * klthread_switch(mach_port_t thread, int option, int option_time)
 *
 * Call the kernel's thread_switch function from a kernel-loaded
 * server.  We assume that we're running in a server thread on its
 * user stack, so just switch to the thread's kernel stack "around"
 * the call.
 */

ENTRY(klthread_switch, TAG_NO_FRAME_USED)


	/* Save off some user state on the user stack if we need to */

	stwu	r1,	-(FM_SIZE+12)(r1)
	mflr	r0

	stw	r31,	FM_SIZE+8(r1)
	stw	r30,	FM_SIZE+4(r1)
	stw	r29,	FM_SIZE(r1)
	
	stw	r0,	FM_SIZE+12+FM_LR_SAVE(r1)
	
	/* Find the current thread's kernel stack to switch to*/	

	mr	r31,	r1	/* temp save of user stack ptr */

#ifdef	DEBUG
	/* Assert that r2 wasn't modified by server */
	/* TODO NMGS - assumes 1-1 mapping of kernel data */
	mfsprg	r0,	0
	twne	r2,	r0
#endif	/* DEBUG */
	
	lwz	r30,	PP_CPU_DATA(r2)
	lwz	r30,	CPU_ACTIVE_THREAD(r30)
	lwz	r30,	THREAD_TOP_ACT(r30)
	lwz	r29,	ACT_MACT_PCB(r30)
	lwz	r1,	PCB_KSP(r29)

	/* reserve ourselves a frame on the stack */
	stwu	r1,	-FM_SIZE(r1)

	/* We're at the top of our kernel stack now, mark as busy */

	li	r0,	0
	stw	r0,	PCB_KSP(r29)

	/* save off the user's MSR value, since the kernel might want
	 * to disable our FPU from under our feet
	 */
	mfmsr	r0
	stw	r0,	SS_SRR1(r29)
	
#if DEBUG
	/* Mark as a kl-calling routine by some magic in pcb srr0 for debug */
	lis	r0,	0x000ca11ed@h
	ori	r0,	r0,	0x000ca11ed@l
	stw	r0,	SS_SRR0(r29)
	
	/* Store a debugging backpointer frame */
	lwz	r29,	FM_BACKPTR(r1)
	stw	r31,	FM_BACKPTR(r29)
	mflr	r0
	stw	r0,	FM_LR_SAVE(r1)
	
	stwu	r1,	-FM_SIZE(r1)

#endif /* DEBUG */
		
	/* Now do the work we actually want to do */
	
	bl	syscall_thread_switch

	/* Save result for after AST check */
	
	mr	r29,	ARG0
	
	/* Check if there's an AST outstanding, we're about to
	 * "leave the kernel"
	 */
.L_klthread_switch_check_ast:	
	lwz	r4,	PP_NEED_AST(r2)
	lwz	r4,	0(r4)
	cmpi	CR0,	r4,	0
	beq	CR0,	.L_klthread_switch_no_ast

	/* Yes there is, call ast_taken 
	 * pretending that the user thread took an AST exception here,
	 * ast_taken will save all state and bring us back here
	 */

	/* disable interrupts */

	li	r3,	MSR_SUPERVISOR_INT_OFF
	mtmsr	r3
	isync		/* For mtmsr */

	li	ARG0,	0
	li	ARG1,	AST_ALL


	/* Perform splhigh and put old spl value in ARG2.
	 * Interrupts have already been disabled
	 */

	lwz	ARG3,	PP_CPU_DATA(r2)
	lwz	ARG2,	CPU_INTERRUPT_LEVEL(ARG3)
	li	r0,	SPLHIGH
	stw	r0,	CPU_INTERRUPT_LEVEL(ARG3)
	
	bl	ast_taken
		/* loop back and check again */
	b	.L_klthread_switch_check_ast

.L_klthread_switch_no_ast:

	/* recover the result we want to return */

	mr	ARG0,	r29
	
	/* free the kernel stack , unwind the user stack and return */
	
#if DEBUG
	/* skip debugging frame */
	lwz	r1,	FM_BACKPTR(r1)
#endif /* DEBUG */
	/* skip back over our frame */
	lwz	r1,	FM_BACKPTR(r1)
	

	/* reset the server's MSR which may or may not have had its FPU
	 * disabled
	 */
	lwz	r29,	ACT_MACT_PCB(r30)
	lwz	r0,	SS_SRR1(r29)
	mtmsr	r0
	isync
	
	stw	r1,	PCB_KSP(r29)

	/* back on to user stack ... */
	
	mr	r1,	r31
		
	/* recover callee saved registers */

	lwz	r0,	FM_SIZE+12+FM_LR_SAVE(r1)

	lwz	r29,	FM_SIZE(r1)
	lwz	r30,	FM_SIZE+4(r1)
	lwz	r31,	FM_SIZE+8(r1)

	mtlr	r0
	
	lwz	r1,	FM_BACKPTR(r1)

	blr


/* 
 * kern_return_t
 * klthread_depress_abort(mach_port_t name)
 *
 * Call the kernel's thread_depress_abort function from a kernel-loaded
 * server.  We assume that we're running in a server thread on its
 * user stack, so just switch to the thread's kernel stack "around"
 * the call.
 */

ENTRY(klthread_depress_abort, TAG_NO_FRAME_USED)


	/* Save off some user state on the user stack if we need to */

	stwu	r1,	-(FM_SIZE+12)(r1)
	mflr	r0

	stw	r31,	FM_SIZE+8(r1)
	stw	r30,	FM_SIZE+4(r1)
	stw	r29,	FM_SIZE(r1)
	
	stw	r0,	FM_SIZE+12+FM_LR_SAVE(r1)
	
	/* Find the current thread's kernel stack to switch to*/	

	mr	r31,	r1	/* temp save of user stack ptr */

	lwz	r30,	PP_CPU_DATA(r2)
	lwz	r30,	CPU_ACTIVE_THREAD(r30)
	lwz	r30,	THREAD_TOP_ACT(r30)
	lwz	r29,	ACT_MACT_PCB(r30)
	lwz	r1,	PCB_KSP(r29)

	/* reserve ourselves a frame on the stack */
	stwu	r1,	-FM_SIZE(r1)

	/* We're at the top of our kernel stack now, mark as busy */

	li	r0,	0
	stw	r0,	PCB_KSP(r29)

	/* save off the user's MSR value, since the kernel might want
	 * to disable our FPU from under our feet
	 */
	mfmsr	r0
	stw	r0,	SS_SRR1(r29)
	
#if DEBUG
	/* Mark as a kl-calling routine by some magic in pcb srr0 for debug */
	li	r0,	0x000ca11ed@h
	ori	r0,	r0,	0x000ca11ed@l
	stw	r0,	SS_SRR0(r29)
	
	/* Store a debugging backpointer frame */
	lwz	r29,	FM_BACKPTR(r1)	
	stw	r31,	FM_BACKPTR(r29)

	mflr	r0
	stw	r0,	FM_LR_SAVE(r1)
	
	stwu	r1,	-FM_SIZE(r1)

	/* Assert that r2 wasn't modified by server */
	/* TODO NMGS - assumes 1-1 mapping of kernel data */
	mfsprg	r0,	0
	twne	r2,	r0
#endif /* DEBUG */

	/* Now do the work we actually want to do */
	
	bl	syscall_thread_depress_abort

	/* Save result for after AST check */
	
	mr	r29,	ARG0
	
	/* Check if there's an AST outstanding, we're about to
	 * "leave the kernel"
	 */

.L_klthread_depress_abort_check_ast:	
	lwz	r4,	PP_NEED_AST(r2)
	lwz	r4,	0(r4)
	cmpi	CR0,	r4,	0
	beq	CR0,	.L_klthread_depress_abort_no_ast

	/* Yes there is, call ast_taken 
	 * pretending that the user thread took an AST exception here,
	 * ast_taken will save all state and bring us back here
	 */

	/* disable interrupts */

	li	r3,	MSR_SUPERVISOR_INT_OFF
	mtmsr	r3
	isync

	li	ARG0,	0
	li	ARG1,	AST_ALL

	/* Perform splhigh and put old spl value in ARG2.
	 * Interrupts have already been disabled
	 */

	lwz	ARG3,	PP_CPU_DATA(r2)
	lwz	ARG2,	CPU_INTERRUPT_LEVEL(ARG3)
	li	r0,	SPLHIGH
	stw	r0,	CPU_INTERRUPT_LEVEL(ARG3)
	
	bl	ast_taken
	/* check again before we go out */
	b	.L_klthread_depress_abort_check_ast

.L_klthread_depress_abort_no_ast:

	/* recover the result we want to return */

	mr	ARG0,	r29
	
	/* free the kernel stack , unwind the user stack and return */
	
#if DEBUG
	/* skip debugging frame */
	lwz	r1,	FM_BACKPTR(r1)
#endif /* DEBUG */
	/* skip back over our frame */
	lwz	r1,	FM_BACKPTR(r1)

	/* reset the server's MSR which may or may not have had its FPU
	 * disabled
	 */
	lwz	r29,	ACT_MACT_PCB(r30)
	lwz	r0,	SS_SRR1(r29)
	mtmsr	r0
	isync

	stw	r1,	PCB_KSP(r29)

	/* back on to user stack ... */
	
	mr	r1,	r31
		
	/* recover callee saved registers */

	lwz	r0,	FM_SIZE+12+FM_LR_SAVE(r1)

	lwz	r29,	FM_SIZE(r1)
	lwz	r30,	FM_SIZE+4(r1)
	lwz	r31,	FM_SIZE+8(r1)

	mtlr	r0
	
	lwz	r1,	FM_BACKPTR(r1)

	blr

/*
 * void
 * call_exc_serv(
 *		 mach_port_t exc_port, exception_type_t exception,
 *		 exception_data_t code, mach_msg_type_number_t codeCnt,
 *		 int *new_sp, mig_impl_routine_t func,
 *		 int *flavor, thread_state_t statep, unsigned int *state_cnt)
 *
 * Switch stacks, call the function, and switch back.  Since
 * we're switching stacks, the asm fragment can't use auto's
 * for temporary storage; use a callee-saves register instead.
 *
 * Don't save anything in the user stack, since caller ensures that
 * all data queried from server work function resides in stable,
 * act-private storage, not on (shared) kernel stack.
 */

ENTRY(call_exc_serv, TAG_NO_FRAME_USED)

	/* reserve a frame for us on the server's stack, with an argument */
	
	subi	r31,	ARG4,	FM_SIZE+4
	
	mtctr	ARG5			/* Save off func */

	mr	ARG4,	ARG6		/* move flavor down to ARG4 */
	mr	ARG5,	ARG7		/* move statep down to ARG5 */

	lwz	ARG6,	FM_ARG0(r1)	/* Recover state_cnt from stack */
	stw	ARG6,	FM_ARG0(r31)	/* Put state_cnt into newsp->arg8 */
		
	lwz	ARG6,	0(ARG6)		/* put *state_cnt into ARG6 */

					/* still holds state_ptr : ARG7 */

	/* Find top of kernel stack and mark kernel stack as free */
	
	lwz	r29,	PP_CPU_DATA(r2)
	lwz	r29,	CPU_ACTIVE_THREAD(r29)
	lwz	r28,	THREAD_TOP_ACT(r29)
	lwz	r28,	ACT_MACT_PCB(r28)

	lwz	r27,	THREAD_KERNEL_STACK(r29)

	ori	r27,	r27,	KERNEL_STACK_SIZE-KS_SIZE-FM_SIZE
	stw	r27,	PCB_KSP(r28)		/* mark stack as free */

	lwz	r0,	SS_SRR1(r28)
	mtmsr	r0
	isync

	mr	r1,	r31	/* Move onto new stack */

	bctrl			/* call server *func */

	/* Move back onto kernel stack + mark busy
	 * using pointers still in callee saved regs
	 */
	
	mr	r1,	r27

	li	r0,	0
	stw	r0,	PCB_KSP(r28)

	/* From here, we never return */
#if DEBUG
	/* Assert that r2 wasn't modified by server */
	/* TODO NMGS - assumes 1-1 mapping of kernel data */
	mfsprg	r0,	0
	twne	r2,	r0
#endif /* DEBUG */
		
	b	exception_return_wrapper

About Koders | Resources | Downloads | Support | Black Duck | Terms of Service | DMCA | Privacy Policy | Contact Us