URL
https://opencores.org/ocsvn/scarts/scarts/trunk
Subversion Repositories scarts
[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libffi/] [src/] [cris/] [sysv.S] - Rev 14
Compare with Previous | Blame | View Log
/* -----------------------------------------------------------------------sysv.S - Copyright (c) 2004 Simon PosnjakCopyright (c) 2005 Axis Communications ABCRIS Foreign Function InterfacePermission is hereby granted, free of charge, to any person obtaininga copy of this software and associated documentation files (the``Software''), to deal in the Software without restriction, includingwithout limitation the rights to use, copy, modify, merge, publish,distribute, sublicense, and/or sell copies of the Software, and topermit persons to whom the Software is furnished to do so, subject tothe following conditions:The above copyright notice and this permission notice shall be includedin all copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESSOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OFMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL SIMON POSNJAK BE LIABLE FOR ANY CLAIM, DAMAGES OROTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OROTHER DEALINGS IN THE SOFTWARE.----------------------------------------------------------------------- */#define LIBFFI_ASM#include <ffi.h>#define CONCAT(x,y) x ## y#define XCONCAT(x,y) CONCAT (x, y)#define L(x) XCONCAT (__USER_LABEL_PREFIX__, x).text;; OK, when we get called we should have this (according to;; AXIS ETRAX 100LX Programmer's Manual chapter 6.3).;;;; R10: ffi_prep_args (func. pointer);; R11: &ecif;; R12: cif->bytes;; R13: fig->flags;; sp+0: ecif.rvalue;; sp+4: fn (function pointer to the function that we need to call).globl L(ffi_call_SYSV).type L(ffi_call_SYSV),@function.hidden L(ffi_call_SYSV)L(ffi_call_SYSV):;; Save the regs to the stack.push $srp;; Used for stack pointer saving.push $r6;; Used for function address pointer.push $r7;; Used for stack pointer saving.push $r8;; We save fig->flags to stack we will need them after we;; call The Function.push $r13;; Saving current stack pointer.move.d $sp,$r8move.d $sp,$r6;; Move address of ffi_prep_args to r13.move.d $r10,$r13;; Make room on the stack for the args of fn.sub.d $r12,$sp;; Function void ffi_prep_args(char *stack, extended_cif *ecif) parameters are:;; r10 <-- stack pointer;; r11 <-- &ecif (already there)move.d $sp,$r10;; Call the function.jsr $r13;; Save the size of the structures which are passed on stack.move.d $r10,$r7;; Move first four args in to r10..r13.move.d [$sp+0],$r10move.d [$sp+4],$r11move.d [$sp+8],$r12move.d [$sp+12],$r13;; Adjust the stack and check if any parameters are given on stack.addq 16,$spsub.d $r7,$r6cmp.d $sp,$r6bpl go_onnopgo_on_no_params_on_stack:move.d $r6,$spgo_on:;; Discover if we need to put rval address in to r9.move.d [$r8+0],$r7cmpq FFI_TYPE_STRUCT,$r7bne call_nownop;; Move rval address to $r9.move.d [$r8+20],$r9call_now:;; Move address of The Function in to r7.move.d [$r8+24],$r7;; Call The Function.jsr $r7;; Reset stack.move.d $r8,$sp;; Load rval type (fig->flags) in to r13.pop $r13;; Detect rval type.cmpq FFI_TYPE_VOID,$r13beq epiloguecmpq FFI_TYPE_STRUCT,$r13beq epiloguecmpq FFI_TYPE_DOUBLE,$r13beq return_double_or_longlongcmpq FFI_TYPE_UINT64,$r13beq return_double_or_longlongcmpq FFI_TYPE_SINT64,$r13beq return_double_or_longlongnop;; Just return the 32 bit value.ba returnnopreturn_double_or_longlong:;; Load half of the rval to r10 and the other half to r11.move.d [$sp+16],$r13move.d $r10,[$r13]addq 4,$r13move.d $r11,[$r13]ba epiloguenopreturn:;; Load the rval to r10.move.d [$sp+16],$r13move.d $r10,[$r13]epilogue:pop $r8pop $r7pop $r6Jump [$sp+].size ffi_call_SYSV,.-ffi_call_SYSV/* Save R10..R13 into an array, somewhat like varargs. Copy the nextargument too, to simplify handling of any straddling parameter.Save R9 and SP after those. Jump to function handling the rest.Since this is a template, copied and the main function filled in bythe user. */.globl L(ffi_cris_trampoline_template).type L(ffi_cris_trampoline_template),@function.hidden L(ffi_cris_trampoline_template)L(ffi_cris_trampoline_template):0:/* The value we get for "PC" is right after the prefix instruction,two bytes from the beginning, i.e. 0b+2. */move.d $r10,[$pc+2f-(0b+2)]move.d $pc,$r101:addq 2f-1b+4,$r10move.d $r11,[$r10+]move.d $r12,[$r10+]move.d $r13,[$r10+]move.d [$sp],$r11move.d $r11,[$r10+]move.d $r9,[$r10+]move.d $sp,[$r10+]subq FFI_CRIS_TRAMPOLINE_DATA_PART_SIZE,$r10move.d 0,$r113:jump 02:.size ffi_cris_trampoline_template,.-0b/* This macro create a constant usable as "extern const int \name" inC from within libffi, when \name has no prefix decoration. */.macro const name,value.globl \name.type \name,@object.hidden \name\name:.dword \value.size \name,4.endm/* Constants for offsets within the trampoline. We could do this withjust symbols, avoiding memory contents and memory accesses, but theC usage code would look a bit stranger. */const L(ffi_cris_trampoline_fn_offset),2b-4-0bconst L(ffi_cris_trampoline_closure_offset),3b-4-0b
