123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448 |
- {
- Copyright (c) 1998-2002 by Florian Klaempfl and Peter Vreman
- Contains the base types for the ARM
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
- 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. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- ****************************************************************************
- }
- {# Base unit for processor information. This unit contains
- enumerations of registers, opcodes, sizes, and other
- such things which are processor specific.
- }
- unit cpubase;
- {$define USEINLINE}
- {$i fpcdefs.inc}
- interface
- uses
- globtype,globals,
- cpuinfo,
- cgbase
- ;
- {*****************************************************************************
- Assembler Opcodes
- *****************************************************************************}
- type
- TAsmOp= {$i xtensaop.inc}
- { This should define the array of instructions as string }
- op2strtable=array[tasmop] of string[11];
- const
- { First value of opcode enumeration }
- firstop = low(tasmop);
- { Last value of opcode enumeration }
- lastop = high(tasmop);
- {*****************************************************************************
- Registers
- *****************************************************************************}
- type
- { Number of registers used for indexing in tables }
- tregisterindex=0..{$i rxtensanor.inc}-1;
- const
- { Available Superregisters }
- {$i rxtensasup.inc}
- { No Subregisters }
- R_SUBWHOLE = R_SUBNONE;
- { Available Registers }
- {$i rxtensacon.inc}
- { Integer Super registers first and last }
- first_int_supreg = RS_A0;
- first_int_imreg = $10;
- { Float Super register first and last }
- first_fpu_supreg = RS_F0;
- first_fpu_imreg = $08;
- { MM Super register first and last }
- first_mm_supreg = RS_INVALID;
- first_mm_imreg = $30;
- { TODO: Calculate bsstart}
- regnumber_count_bsstart = 16;
- regnumber_table : array[tregisterindex] of tregister = (
- {$i rxtensanum.inc}
- );
- regstabs_table : array[tregisterindex] of shortint = (
- {$i rxtensasta.inc}
- );
- regdwarf_table : array[tregisterindex] of shortint = (
- {$i rxtensadwa.inc}
- );
- {*****************************************************************************
- Conditions
- *****************************************************************************}
- type
- TAsmCond=(C_None,
- C_EQ,C_NE,C_CS,C_CC,C_MI,C_PL,C_VS,C_VC,C_HI,C_LS,
- C_GE,C_LT,C_GT,C_LE,C_AL,C_NV
- );
- TAsmConds = set of TAsmCond;
- const
- cond2str : array[TAsmCond] of string[2]=('',
- 'eq','ne','cs','cc','mi','pl','vs','vc','hi','ls',
- 'ge','lt','gt','le','al','nv'
- );
- uppercond2str : array[TAsmCond] of string[2]=('',
- 'EQ','NE','CS','CC','MI','PL','VS','VC','HI','LS',
- 'GE','LT','GT','LE','AL','NV'
- );
- {*****************************************************************************
- Flags
- *****************************************************************************}
- type
- TResFlags = (F_EQ,F_NE,F_CS,F_CC,F_MI,F_PL,F_VS,F_VC,F_HI,F_LS,
- F_GE,F_LT,F_GT,F_LE);
- {*****************************************************************************
- Operands
- *****************************************************************************}
- taddressmode = (AM_OFFSET,AM_PREINDEXED,AM_POSTINDEXED);
- tshiftmode = (SM_None,SM_LSL,SM_LSR,SM_ASR,SM_ROR,SM_RRX);
- tupdatereg = (UR_None,UR_Update);
- pshifterop = ^tshifterop;
- tshifterop = record
- shiftmode : tshiftmode;
- rs : tregister;
- shiftimm : byte;
- end;
- tcpumodeflag = (mfA, mfI, mfF);
- tcpumodeflags = set of tcpumodeflag;
- tspecialregflag = (srC, srX, srS, srF);
- tspecialregflags = set of tspecialregflag;
- {*****************************************************************************
- Constants
- *****************************************************************************}
- const
- max_operands = 6;
- maxintregs = 15;
- maxfpuregs = 8;
- maxaddrregs = 0;
- {*****************************************************************************
- Operand Sizes
- *****************************************************************************}
- type
- topsize = (S_NO,
- S_B,S_W,S_L,S_BW,S_BL,S_WL,
- S_IS,S_IL,S_IQ,
- S_FS,S_FL,S_FX,S_D,S_Q,S_FV,S_FXX
- );
- {*****************************************************************************
- Default generic sizes
- *****************************************************************************}
- const
- { Defines the default address size for a processor, }
- OS_ADDR = OS_32;
- { the natural int size for a processor,
- has to match osuinttype/ossinttype as initialized in psystem }
- OS_INT = OS_32;
- OS_SINT = OS_S32;
- { the maximum float size for a processor, }
- OS_FLOAT = OS_F64;
- { the size of a vector register for a processor }
- OS_VECTOR = OS_M32;
- {*****************************************************************************
- Generic Register names
- *****************************************************************************}
- { Stack pointer register }
- NR_STACK_POINTER_REG = NR_A1;
- RS_STACK_POINTER_REG = RS_A1;
- { Frame pointer register (initialized in tcpuprocinfo.init_framepointer) }
- RS_FRAME_POINTER_REG: tsuperregister = RS_NO;
- NR_FRAME_POINTER_REG: tregister = NR_NO;
- { Register for addressing absolute data in a position independant way,
- such as in PIC code. The exact meaning is ABI specific. For
- further information look at GCC source : PIC_OFFSET_TABLE_REGNUM
- }
- { Results are returned in this register (32-bit values) }
- NR_FUNCTION_RETURN_REG = NR_A2;
- RS_FUNCTION_RETURN_REG = RS_A2;
- { The value returned from a function is available in this register }
- NR_FUNCTION_RESULT_REG = NR_FUNCTION_RETURN_REG;
- RS_FUNCTION_RESULT_REG = RS_FUNCTION_RETURN_REG;
- NR_FPU_RESULT_REG = NR_INVALID;
- NR_MM_RESULT_REG = NR_INVALID;
- NR_RETURN_ADDRESS_REG = NR_FUNCTION_RETURN_REG;
- { Offset where the parent framepointer is pushed }
- PARENT_FRAMEPOINTER_OFFSET = 0;
- NR_DEFAULTFLAGS = NR_INVALID;
- RS_DEFAULTFLAGS = RS_INVALID;
- {*****************************************************************************
- GCC /ABI linking information
- *****************************************************************************}
- const
- { Required parameter alignment when calling a routine declared as
- stdcall and cdecl. The alignment value should be the one defined
- by GCC or the target ABI.
- The value of this constant is equal to the constant
- PARM_BOUNDARY / BITS_PER_UNIT in the GCC source.
- }
- std_param_align = 4;
- {*****************************************************************************
- Helpers
- *****************************************************************************}
- { Returns the tcgsize corresponding with the size of reg.}
- function reg_cgsize(const reg: tregister) : tcgsize;
- function cgsize2subreg(regtype: tregistertype; s:Tcgsize):Tsubregister;
- function is_calljmp(o:tasmop):boolean;{$ifdef USEINLINE}inline;{$endif USEINLINE}
- procedure inverse_flags(var f: TResFlags);
- function flags_to_cond(const f: TResFlags) : TAsmCond;
- function findreg_by_number(r:Tregister):tregisterindex;
- function std_regnum_search(const s:string):Tregister;
- function std_regname(r:Tregister):string;
- function inverse_cond(const c: TAsmCond): TAsmCond; {$ifdef USEINLINE}inline;{$endif USEINLINE}
- function conditions_equal(const c1, c2: TAsmCond): boolean; {$ifdef USEINLINE}inline;{$endif USEINLINE}
- { Checks if Subset is a subset of c (e.g. "less than" is a subset of "less than or equal" }
- function condition_in(const Subset, c: TAsmCond): Boolean;
- function dwarf_reg(r:tregister):shortint;
- function dwarf_reg_no_error(r:tregister):shortint;
- function eh_return_data_regno(nr: longint): longint;
- implementation
- uses
- systems,rgBase,verbose;
- const
- std_regname_table : TRegNameTable = (
- {$i rxtensastd.inc}
- );
- regnumber_index : array[tregisterindex] of tregisterindex = (
- {$i rxtensarni.inc}
- );
- std_regname_index : array[tregisterindex] of tregisterindex = (
- {$i rxtensasri.inc}
- );
- function cgsize2subreg(regtype: tregistertype; s:Tcgsize):Tsubregister;
- begin
- case regtype of
- R_MMREGISTER:
- begin
- case s of
- { records passed in MM registers }
- OS_32,
- OS_F32:
- cgsize2subreg:=R_SUBFS;
- OS_64,
- OS_F64:
- cgsize2subreg:=R_SUBFD;
- else
- internalerror(2009112701);
- end;
- end;
- else
- cgsize2subreg:=R_SUBWHOLE;
- end;
- end;
- function reg_cgsize(const reg: tregister): tcgsize;
- begin
- case getregtype(reg) of
- R_INTREGISTER :
- reg_cgsize:=OS_32;
- R_FPUREGISTER :
- reg_cgsize:=OS_F80;
- R_MMREGISTER :
- begin
- case getsubreg(reg) of
- R_SUBFD,
- R_SUBWHOLE:
- result:=OS_F64;
- R_SUBFS:
- result:=OS_F32;
- else
- internalerror(2009112903);
- end;
- end;
- else
- internalerror(200303181);
- end;
- end;
- function is_calljmp(o:tasmop):boolean;{$ifdef USEINLINE}inline;{$endif USEINLINE}
- begin
- { This isn't 100% perfect because the arm allows jumps also by writing to PC=R15.
- To overcome this problem we simply forbid that FPC generates jumps by loading R15 }
- is_calljmp:= o in [A_Bcc,A_BT,A_CALL0,A_CALL4,A_CALL8,A_CALL12,A_CALLX0,A_CALLX4,A_CALLX8,A_CALLX12];
- end;
- procedure inverse_flags(var f: TResFlags);
- const
- inv_flags: array[TResFlags] of TResFlags =
- (F_NE,F_EQ,F_CC,F_CS,F_PL,F_MI,F_VC,F_VS,F_LS,F_HI,
- F_LT,F_GE,F_LE,F_GT);
- begin
- f:=inv_flags[f];
- end;
- function flags_to_cond(const f: TResFlags) : TAsmCond;
- const
- flag_2_cond: array[F_EQ..F_LE] of TAsmCond =
- (C_EQ,C_NE,C_CS,C_CC,C_MI,C_PL,C_VS,C_VC,C_HI,C_LS,
- C_GE,C_LT,C_GT,C_LE);
- begin
- if f>high(flag_2_cond) then
- internalerror(200112301);
- result:=flag_2_cond[f];
- end;
- function findreg_by_number(r:Tregister):tregisterindex;
- begin
- result:=rgBase.findreg_by_number_table(r,regnumber_index);
- end;
- function std_regnum_search(const s:string):Tregister;
- begin
- result:=regnumber_table[findreg_by_name_table(s,std_regname_table,std_regname_index)];
- end;
- function std_regname(r:Tregister):string;
- var
- p : tregisterindex;
- begin
- p:=findreg_by_number_table(r,regnumber_index);
- if p<>0 then
- result:=std_regname_table[p]
- else
- result:=generic_regname(r);
- end;
- function inverse_cond(const c: TAsmCond): TAsmCond; {$ifdef USEINLINE}inline;{$endif USEINLINE}
- const
- inverse: array[TAsmCond] of TAsmCond=(C_None,
- C_NE,C_EQ,C_CC,C_CS,C_PL,C_MI,C_VC,C_VS,C_LS,C_HI,
- C_LT,C_GE,C_LE,C_GT,C_None,C_None
- );
- begin
- result := inverse[c];
- end;
- function conditions_equal(const c1, c2: TAsmCond): boolean; {$ifdef USEINLINE}inline;{$endif USEINLINE}
- begin
- result := c1 = c2;
- end;
- { Checks if Subset is a subset of c (e.g. "less than" is a subset of "less than or equal" }
- function condition_in(const Subset, c: TAsmCond): Boolean;
- begin
- Result := (c = C_None) or conditions_equal(Subset, c);
- { Please update as necessary. [Kit] }
- if not Result then
- case Subset of
- C_EQ:
- Result := (c in [C_GE, C_LE]);
- C_LT:
- Result := (c in [C_LE]);
- C_GT:
- Result := (c in [C_GE]);
- else
- Result := False;
- end;
- end;
- function dwarf_reg(r:tregister):shortint;
- begin
- result:=regdwarf_table[findreg_by_number(r)];
- if result=-1 then
- internalerror(200603251);
- end;
- function dwarf_reg_no_error(r:tregister):shortint;
- begin
- result:=regdwarf_table[findreg_by_number(r)];
- end;
- function eh_return_data_regno(nr: longint): longint;
- begin
- if (nr>=0) and (nr<2) then
- result:=nr
- else
- result:=-1;
- end;
- end.
|