180 |
|
isync |
181 |
|
lwarx r5,0,r3 |
182 |
|
cmpi 0,r5,0x0000 |
183 |
< |
beq 1f |
183 |
> |
bne 1f |
184 |
|
stwcx. r4,0,r3 |
185 |
|
bne- 0b |
186 |
|
1: isync |
710 |
|
* Native resource manager patches |
711 |
|
*/ |
712 |
|
|
713 |
< |
ASM_MACRO_START do_get_resource XLM_OLD_GET_RESOURCE |
713 |
> |
ASM_MACRO_START do_get_resource ASM_MACRO_ARG0_DEF |
714 |
|
// Create stack frame |
715 |
|
mflr r0 |
716 |
|
stw r0,8(r1) |
721 |
|
stw r4,56+4(r1) |
722 |
|
|
723 |
|
// Call old routine |
724 |
< |
lwz r0,\XLM_OLD_GET_RESOURCE(0) |
724 |
> |
lwz r0,ASM_MACRO_ARG0(0) |
725 |
|
lwz r2,XLM_RES_LIB_TOC(0) |
726 |
|
mtctr r0 |
727 |
|
bctrl |
811 |
|
// Enter nanokernel |
812 |
|
mtlr r3 |
813 |
|
blr |
814 |
+ |
|
815 |
+ |
|
816 |
+ |
/* |
817 |
+ |
* Define signal handlers with alternate stack initialization magic |
818 |
+ |
*/ |
819 |
+ |
|
820 |
+ |
#define SIG_STACK_SIZE 0x10000 |
821 |
+ |
|
822 |
+ |
ASM_MACRO_START do_define_signal_handler \ |
823 |
+ |
ASM_MACRO_ARG0_DEF /* name */ \ |
824 |
+ |
ASM_MACRO_ARG1_DEF /* stack */ \ |
825 |
+ |
ASM_MACRO_ARG2_DEF /* stack id */ \ |
826 |
+ |
ASM_MACRO_ARG3_DEF /* signal handler */ |
827 |
+ |
|
828 |
+ |
// Alternate stack lower base for this signal handler |
829 |
+ |
.lcomm ASM_MACRO_ARG1,SIG_STACK_SIZE,ASM_ALIGN_2(4) |
830 |
+ |
ASM_TYPE(ASM_MACRO_ARG1,@object) |
831 |
+ |
|
832 |
+ |
// Represents the current nest level for this signal handler |
833 |
+ |
// Note that in SheepShaver, SIGUSR2 signals are blocked while |
834 |
+ |
// handling other signals so, it's unlikely we ever get a nest |
835 |
+ |
// level greater than 1 |
836 |
+ |
.lcomm ASM_MACRO_ARG2,4,ASM_ALIGN_2(2) |
837 |
+ |
ASM_TYPE(ASM_MACRO_ARG2,@object) |
838 |
+ |
|
839 |
+ |
ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME(ASM_MACRO_ARG0) |
840 |
+ |
C_SYMBOL_NAME(ASM_MACRO_ARG0): |
841 |
+ |
// Preserve args in scratch registers |
842 |
+ |
mflr r14 |
843 |
+ |
mr r15,r3 |
844 |
+ |
mr r16,r4 |
845 |
+ |
mr r17,r5 |
846 |
+ |
mr r18,r1 |
847 |
+ |
|
848 |
+ |
// Atomically increase stack_id |
849 |
+ |
lis r19,ASM_HA16(ASM_MACRO_ARG2) |
850 |
+ |
la r19,ASM_LO16(ASM_MACRO_ARG2,r19) |
851 |
+ |
li r4,1 |
852 |
+ |
mr r3,r19 |
853 |
+ |
bl C_SYMBOL_NAME(atomic_add) |
854 |
+ |
cmpwi r3,0 |
855 |
+ |
bne- 1f |
856 |
+ |
|
857 |
+ |
// ID was 0, we can use the local stack |
858 |
+ |
lis r9,ASM_HA16(ASM_MACRO_ARG1) |
859 |
+ |
lis r3,(SIG_STACK_SIZE>>16) |
860 |
+ |
la r9,ASM_LO16(ASM_MACRO_ARG1,r9) |
861 |
+ |
addi r3,r3,((SIG_STACK_SIZE&0xffff)-64) |
862 |
+ |
add r1,r9,r3 |
863 |
+ |
|
864 |
+ |
1: // Invoke signal handler |
865 |
+ |
stwu r1,-16(r1) |
866 |
+ |
mr r3,r15 |
867 |
+ |
mr r4,r16 |
868 |
+ |
mr r5,r17 |
869 |
+ |
bl C_SYMBOL_NAME(ASM_MACRO_ARG3) |
870 |
+ |
addi r1,r1,16 |
871 |
+ |
|
872 |
+ |
// Atomically decrease stack id |
873 |
+ |
mr r3,r19 |
874 |
+ |
li r4,-1 |
875 |
+ |
bl C_SYMBOL_NAME(atomic_add) |
876 |
+ |
|
877 |
+ |
// Restore kernel stack and return |
878 |
+ |
mtlr r14 |
879 |
+ |
mr r1,r18 |
880 |
+ |
blr |
881 |
+ |
ASM_MACRO_END |
882 |
+ |
|
883 |
+ |
#define DEFINE_SIGNAL_HANDLER(NAME) \ |
884 |
+ |
do_define_signal_handler \ |
885 |
+ |
NAME##_handler_init ASM_MACRO_ARG_SEP \ |
886 |
+ |
NAME##_stack ASM_MACRO_ARG_SEP \ |
887 |
+ |
NAME##_stack_id ASM_MACRO_ARG_SEP \ |
888 |
+ |
NAME##_handler |
889 |
+ |
|
890 |
+ |
DEFINE_SIGNAL_HANDLER(sigusr2) |