123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- {
- This file is part of the Free Pascal run time library.
- Copyright (c) 2003 by the Free Pascal development team.
- Processor dependent implementation for the system unit for
- Xtensa
- See the file COPYING.FPC, included in this distribution,
- for details about the copyright.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- **********************************************************************}
- {$define FPC_SYSTEM_HAS_SYSRESETFPU}
- Procedure SysResetFPU;{$ifdef SYSTEMINLINE}inline;{$endif}
- begin
- end;
- {$define FPC_SYSTEM_HAS_SYSINITFPU}
- Procedure SysInitFPU;{$ifdef SYSTEMINLINE}inline;{$endif}
- begin
- end;
- procedure fpc_cpuinit;
- begin
- { don't let libraries influence the FPU cw set by the host program }
- if not IsLibrary then
- SysInitFPU;
- end;
- {$ifdef fpc_abi_windowed}
- const
- // Minimum call8 calls to force register spilling to stack for caller of forceSpilledRegs
- spillcount = 6;
- procedure forceSpilledRegs(n: uint32); assembler; public name 'forcespilledregs';
- label
- done, fin;
- asm
- beqz a2, done
- addi a10, a2, -1
- call8 forcespilledregs
- done:
- bnez a2, fin
- movi a15, 0
- fin:
- end;
- procedure fixCodeAddress(var addr: pointer);
- begin
- // Check if valid code address
- if ptruint(addr) and $C0000000 >= $40000000 then
- begin
- // Replace windowed call prefix
- addr:=codepointer((ptruint(addr)and$00FFFFFF) or $40000000);
- // Rewind to call instruction address
- dec(addr,3);
- end
- else
- addr:=nil;
- end;
- {$endif fpc_abi_windowed}
- {$IFNDEF INTERNAL_BACKTRACE}
- {$define FPC_SYSTEM_HAS_GET_FRAME}
- function get_frame:pointer;assembler;
- label
- done;
- asm
- {$ifdef fpc_abi_windowed}
- // Force registers to spill onto stack
- movi a10, spillcount
- call8 forcespilledregs
- // now get frame pointer of caller
- addi a2, a1, -12
- l32i a2, a2, 0
- done:
- {$else}
- mov a2, a1
- {$endif}
- end;
- {$ENDIF not INTERNAL_BACKTRACE}
- {$define FPC_SYSTEM_HAS_GET_CALLER_ADDR}
- function get_caller_addr(framebp:pointer;addr:pointer=nil):pointer;
- begin
- {$ifdef fpc_abi_windowed}
- forceSpilledRegs(spillcount);
- if (ptruint(framebp)>$3ff00000)and(ptruint(framebp)<$40000000) then
- begin
- get_caller_addr:=pointer((framebp-16)^);
- fixCodeAddress(get_caller_addr);
- end
- else
- get_caller_addr:=nil;
- {$else}
- get_caller_addr:=nil;
- {$endif}
- end;
- {$define FPC_SYSTEM_HAS_GET_CALLER_FRAME}
- function get_caller_frame(framebp:pointer;addr:pointer=nil):pointer;
- begin
- {$ifdef fpc_abi_windowed}
- if (ptruint(framebp)>$3ff00000)and(ptruint(framebp)<$40000000) then
- begin
- forceSpilledRegs(spillcount);
- get_caller_frame:=pointer((framebp-12)^);
- end
- else
- get_caller_frame:=nil;
- {$else}
- get_caller_frame:=nil;
- {$endif}
- end;
- {$ifdef fpc_abi_windowed}
- {$define FPC_SYSTEM_HAS_GET_CALLER_STACKINFO}
- procedure get_caller_stackinfo(var framebp : pointer; var addr : codepointer);
- begin
- if (ptruint(framebp)>$3ff00000)and(ptruint(framebp)<$40000000) then
- begin
- forceSpilledRegs(spillcount);
- addr:=codepointer((framebp-16)^);
- framebp := pointer((framebp-12)^);
- fixCodeAddress(addr);
- end
- else
- begin
- addr:=nil;
- framebp:=nil;
- end;
- end;
- {$endif fpc_abi_windowed}
- {$define FPC_SYSTEM_HAS_SPTR}
- Function Sptr : pointer;assembler;
- asm
- mov a2,a1
- end;
- {$define FPC_SYSTEM_HAS_STACKTOP}
- // Interim fix for now, set to large address
- // TODO: provide more realistic value, possibly by inspecting stack pointer
- // when main or task is started
- function StackTop: pointer;
- begin
- StackTop:=pointer($3fffffff);
- end;
- function InterLockedDecrement (var Target: longint) : longint;
- var
- temp_sreg : byte;
- begin
- Result:=Target-1;
- Target:=Result;
- end;
- function InterLockedIncrement (var Target: longint) : longint;
- var
- temp_sreg : byte;
- begin
- Result:=Target+1;
- Target:=Result;
- end;
- function InterLockedExchange (var Target: longint;Source : longint) : longint;
- var
- temp_sreg : byte;
- begin
- Result:=Target;
- Target:=Source;
- end;
- function InterlockedCompareExchange(var Target: longint; NewValue: longint; Comperand: longint): longint;
- var
- temp_sreg : byte;
- begin
- Result:=Target;
- if Result=Comperand then
- Target:=NewValue;
- end;
- function InterLockedExchangeAdd (var Target: longint;Source : longint) : longint;
- var
- temp_sreg : byte;
- begin
- Result:=Target;
- Target:=Result+Source;
- end;
- function InterLockedDecrement (var Target: smallint) : smallint;
- var
- temp_sreg : byte;
- begin
- Result:=Target-1;
- Target:=Result;
- end;
- function InterLockedIncrement (var Target: smallint) : smallint;
- var
- temp_sreg : byte;
- begin
- Result:=Target+1;
- Target:=Result;
- end;
- function InterLockedExchange (var Target: smallint;Source : smallint) : smallint;
- var
- temp_sreg : byte;
- begin
- Result:=Target;
- Target:=Source;
- end;
- function InterlockedCompareExchange(var Target: smallint; NewValue: smallint; Comperand: smallint): smallint;
- var
- temp_sreg : byte;
- begin
- Result:=Target;
- if Result=Comperand then
- Target:=NewValue;
- end;
- function InterLockedExchangeAdd (var Target: smallint;Source : smallint) : smallint;
- var
- temp_sreg : byte;
- begin
- Result:=Target;
- Target:=Result+Source;
- end;
|