123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255 |
- #ifndef _LINUX_ARM_SYSDEP_H
- #define _LINUX_ARM_SYSDEP_H 1
- #include <common/sysdep.h>
- #include <bits/arm_bx.h>
- #include <sys/syscall.h>
- #undef SYS_ify
- #define SWI_BASE (0x900000)
- #define SYS_ify(syscall_name) (__NR_##syscall_name)
- #ifdef __ASSEMBLER__
- #define ALIGNARG(log2) log2
- #define ASM_TYPE_DIRECTIVE(name,typearg) .type name,%##typearg;
- #define ASM_SIZE_DIRECTIVE(name) .size name,.-name
- #undef NO_UNDERSCORES
- #define NO_UNDERSCORES
- #define PLTJMP(_x) _x##(PLT)
- #ifdef __APCS_32__
- #define LOADREGS(cond, base, reglist...)\
- ldm##cond base,reglist
- #define RETINSTR(cond, reg) \
- BXC(cond, reg)
- #define DO_RET(_reg) \
- BX(_reg)
- #else
- #define LOADREGS(cond, base, reglist...) \
- ldm##cond base,reglist^
- #define RETINSTR(cond, reg) \
- mov##cond##s pc, reg
- #define DO_RET(_reg) \
- movs pc, _reg
- #endif
- #define ENTRY(name) \
- .globl C_SYMBOL_NAME(name)
- ASM_TYPE_DIRECTIVE (C_SYMBOL_NAME(name),function) \
- .align ALIGNARG(4)
- name##:
- #undef END
- #define END(name) \
- ASM_SIZE_DIRECTIVE(name)
- #ifdef NO_UNDERSCORES
- #define syscall_error __syscall_error
- #define mcount _mcount
- #endif
- #undef PSEUDO
- #define PSEUDO(name, syscall_name, args) \
- .text
- ENTRY (name)
- DO_CALL (syscall_name, args)
- cmn r0, $4096
- #define PSEUDO_RET \
- RETINSTR(cc, lr)
- b PLTJMP(SYSCALL_ERROR)
- #undef ret
- #define ret PSEUDO_RET
- #undef PSEUDO_END
- #define PSEUDO_END(name) \
- SYSCALL_ERROR_HANDLER \
- END (name)
- #undef PSEUDO_NOERRNO
- #define PSEUDO_NOERRNO(name, syscall_name, args) \
- .text
- ENTRY (name)
- DO_CALL (syscall_name, args)
- #define PSEUDO_RET_NOERRNO \
- DO_RET (lr)
- #undef ret_NOERRNO
- #define ret_NOERRNO PSEUDO_RET_NOERRNO
- #undef PSEUDO_END_NOERRNO
- #define PSEUDO_END_NOERRNO(name) \
- END (name)
- #undef PSEUDO_ERRVAL
- #define PSEUDO_ERRVAL(name, syscall_name, args) \
- .text
- ENTRY (name) \
- DO_CALL (syscall_name, args)
- rsb r0, r0, #0
- #undef PSEUDO_END_ERRVAL
- #define PSEUDO_END_ERRVAL(name) \
- END (name)
- #if defined NOT_IN_libc
- # define SYSCALL_ERROR __local_syscall_error
- # define SYSCALL_ERROR_HANDLER \
- __local_syscall_error: \
- str lr, [sp, #-4]!; \
- str r0, [sp, #-4]!; \
- bl PLTJMP(C_SYMBOL_NAME(__errno_location))
- ldr r1, [sp], #4; \
- rsb r1, r1, #0; \
- str r1, [r0]
- mvn r0, #0; \
- ldr pc, [sp], #4;
- #else
- # define SYSCALL_ERROR_HANDLER
- # define SYSCALL_ERROR __syscall_error
- #endif
- #if __ARM_ARCH > 6 || defined (__ARM_ARCH_6K__) || defined (__ARM_ARCH_6ZK__)
- # define ARCH_HAS_HARD_TP
- #endif
- # ifdef __thumb2__
- # define NEGOFF_ADJ_BASE(R, OFF) add R, R, $OFF
- # define NEGOFF_ADJ_BASE2(D, S, OFF) add D, S, $OFF
- # define NEGOFF_OFF1(R, OFF) [R]
- # define NEGOFF_OFF2(R, OFFA, OFFB) [R, $((OFFA) - (OFFB))]
- # else
- # define NEGOFF_ADJ_BASE(R, OFF)
- # define NEGOFF_ADJ_BASE2(D, S, OFF) mov D, S
- # define NEGOFF_OFF1(R, OFF) [R, $OFF]
- # define NEGOFF_OFF2(R, OFFA, OFFB) [R, $OFFA]
- # endif
- # ifdef ARCH_HAS_HARD_TP
- # define GET_TLS(TMP) mrc p15, 0, r0, c13, c0, 3
- # else
- # define GET_TLS(TMP) \
- push { r1, r2, r3, lr }
- cfi_remember_state
- cfi_adjust_cfa_offset (16)
- cfi_rel_offset (r1, 0)
- cfi_rel_offset (r2, 4)
- cfi_rel_offset (r3, 8)
- cfi_rel_offset (lr, 12)
- bl __aeabi_read_tp
- pop { r1, r2, r3, lr }
- cfi_restore_state
- # endif
- #undef DO_CALL
- #if defined(__ARM_EABI__)
- #define DO_CALL(syscall_name, args) \
- DOARGS_##args \
- mov ip, r7
- ldr r7, =SYS_ify (syscall_name)
- swi 0x0
- mov r7, ip
- UNDOARGS_##args
- #else
- #define DO_CALL(syscall_name, args) \
- DOARGS_##args \
- swi SYS_ify (syscall_name)
- UNDOARGS_##args
- #endif
- #define DOARGS_0
- #define DOARGS_1
- #define DOARGS_2
- #define DOARGS_3
- #define DOARGS_4
- #define DOARGS_5 str r4, [sp, $-4]!; ldr r4, [sp, $4];
- #define DOARGS_6 mov ip, sp; stmfd sp!, {r4, r5}; ldmia ip, {r4, r5};
- #define DOARGS_7 mov ip, sp; stmfd sp!, {r4, r5, r6}; ldmia ip, {r4, r5, r6};
- #define UNDOARGS_0
- #define UNDOARGS_1
- #define UNDOARGS_2
- #define UNDOARGS_3
- #define UNDOARGS_4
- #define UNDOARGS_5 ldr r4, [sp], $4;
- #define UNDOARGS_6 ldmfd sp!, {r4, r5};
- #define UNDOARGS_7 ldmfd sp!, {r4, r5, r6};
- #endif
- #endif
|