6.1.2.3 Parameter passing
There is one VFP co-processor register class using registers s0-s15 (d0-d7) for passing arguments.
The following co-processor rules are defined for the VFP:
A.2.vfp The floating point argument registers are marked as unallocated.
B.3.vfp Nothing to do.
C.1.vfp If the argument is a VFP CPRC and there are sufficient consecutive VFP registers of the appropriate
type unallocated then the argument is allocated to the lowest-numbered sequence of such registers.
C.2.vfp If the argument is a VFP CPRC then any VFP registers that are unallocated are marked as
unavailable. The NSAA is adjusted upwards until it is correctly aligned for the argument and the
argument is copied to the stack at the adjusted NSAA. The NSAA is further incremented by the size
of the argument. The argument has now been allocated.
Note that the rules require the ‘back-filling’ of unused co-processor registers that are skipped by the alignment
constraints of earlier
测试一下:
- float PP_TETS
- (
- float s0,
- float s1,
- float s2,
- float s3,
- float s4,
- float s5,
- float s6,
- float s7,
- float s8,
- float s9,
- float s10,
- float s11,
- float s12,
- float s13,
- float s14,
- float s15,
- int r0,
- int r1,
- int r2,
- int r3
- )
- {
- r0+=r1;
- r0+=r2;
- r0+=r3;
- if(r0)
- {
- s0+=s1;
- s0+=s2;
- s0+=s3;
- s0+=s4;
- s0+=s5;
- s0+=s6;
- s0+=s7;
- s0+=s8;
- s0+=s9;
- s0+=s10;
- s0+=s11;
- s0+=s12;
- s0+=s13;
- s0+=s14;
- s0+=s15;
- }
- return s0;
- }
复制代码
编译结果:
- ER_IROM1:080002FC
- ER_IROM1:080002FC ; =============== S U B R O U T I N E =======================================
- ER_IROM1:080002FC
- ER_IROM1:080002FC
- ER_IROM1:080002FC ; PP_TETS(float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, int, int, int, int)
- ER_IROM1:080002FC EXPORT _Z7PP_TETSffffffffffffffffiiii
- ER_IROM1:080002FC _Z7PP_TETSffffffffffffffffiiii
- ER_IROM1:080002FC PUSH {R4,LR}
- ER_IROM1:080002FE VPUSH {D8}
- ER_IROM1:08000302 ADD R0, R1
- ER_IROM1:08000304 ADD R0, R2
- ER_IROM1:08000306 ADD R0, R3
- ER_IROM1:08000308 CBZ R0, loc_8000382
- ER_IROM1:0800030A VADD.F32 S16, S0, S1
- ER_IROM1:0800030E VMOV.F32 S0, S16
- ER_IROM1:08000312 VADD.F32 S16, S0, S2
- ER_IROM1:08000316 VMOV.F32 S0, S16
- ER_IROM1:0800031A VADD.F32 S16, S0, S3
- ER_IROM1:0800031E VMOV.F32 S0, S16
- ER_IROM1:08000322 VADD.F32 S16, S0, S4
- ER_IROM1:08000326 VMOV.F32 S0, S16
- ER_IROM1:0800032A VADD.F32 S16, S0, S5
- ER_IROM1:0800032E VMOV.F32 S0, S16
- ER_IROM1:08000332 VADD.F32 S16, S0, S6
- ER_IROM1:08000336 VMOV.F32 S0, S16
- ER_IROM1:0800033A VADD.F32 S16, S0, S7
- ER_IROM1:0800033E VMOV.F32 S0, S16
- ER_IROM1:08000342 VADD.F32 S16, S0, S8
- ER_IROM1:08000346 VMOV.F32 S0, S16
- ER_IROM1:0800034A VADD.F32 S16, S0, S9
- ER_IROM1:0800034E VMOV.F32 S0, S16
- ER_IROM1:08000352 VADD.F32 S16, S0, S10
- ER_IROM1:08000356 VMOV.F32 S0, S16
- ER_IROM1:0800035A VADD.F32 S16, S0, S11
- ER_IROM1:0800035E VMOV.F32 S0, S16
- ER_IROM1:08000362 VADD.F32 S16, S0, S12
- ER_IROM1:08000366 VMOV.F32 S0, S16
- ER_IROM1:0800036A VADD.F32 S16, S0, S13
- ER_IROM1:0800036E VMOV.F32 S0, S16
- ER_IROM1:08000372 VADD.F32 S16, S0, S14
- ER_IROM1:08000376 VMOV.F32 S0, S16
- ER_IROM1:0800037A VADD.F32 S16, S0, S15
- ER_IROM1:0800037E VMOV.F32 S0, S16
- ER_IROM1:08000382
- ER_IROM1:08000382 loc_8000382 ; CODE XREF: PP_TETS(float,float,float,float,float,float,float,float,float,float,float,float,float,float,float,float,int,int,int,int)+Cj
- ER_IROM1:08000382 VPOP {D8}
- ER_IROM1:08000386 POP {R4,PC}
- ER_IROM1:08000386 ; End of function PP_TETS(float,float,float,float,float,float,float,float,float,float,float,float,float,float,float,float,int,int,int,int)
复制代码
THE END ...
|
发出来咋成这模样了
谢谢指点,测试下
c代码中是怎么做到让s0就是S0寄存器的?貌似没打看懂啊。
我用的IDA6.6。
c代码s0与汇编s0寄存器本没有关系的。
只是一般C函数(实际上我用的是cpp),
使用fpu,第一个float参数以s0寄存器传参,
第二个float用s1,以此类推。
返回值(float) 用s0
返回值(int) 用r0
以上个人观点
可以参考:
Procedure Call Standard for the ARM® Architecture
http://infocenter.arm.com/help/t ... /IHI0042E_aapcs.pdf
学习了。
第一个参数不是R0传递,一直到R3吗?4个往上的参数不是使用栈传递啊。没大搞懂。在看看那个链接。
你是搞反汇编的吗?
一开始我也这么想的。但是我隐隐的感觉到这种做法效率不好。
于是具体看了下函数的实现,怎么优化的。。
另外,我是搞正向开发的。
何以见得
看你用IDA,动不动就反汇编。。。