mirror of
				https://gitlab.com/freepascal.org/fpc/source.git
				synced 2025-11-04 00:19:39 +01:00 
			
		
		
		
	+ RTL support:
      o VFP exceptions are disabled by default on Darwin,
        because they cause kernel panics on iPhoneOS 2.2.1 at least
      o all denormals are truncated to 0 on Darwin, because disabling
        that also causes kernel panics on iPhoneOS 2.2.1 (probably
        because otherwise denormals can also cause exceptions)
    * set softfloat rounding mode correctly for non-wince/darwin/vfp
      targets
    + compiler support: only half the number of single precision
      registers is available due to limitations of the register
      allocator
    + added a number of comments about why the stackframe on ARM is
      set up the way it is by the compiler
    + added regtype and subregtype info to regsets, because they're
      also used for VFP registers (+ support in assembler reader)
    + various generic support routines for dealing with floating point
      values located in integer registers that have to be transferred to
      mm registers (needed for VFP)
    * renamed use_sse() to use_vectorfpu() and also use it for
      ARM/vfp support
    o only superficially tested for Linux (compiler compiled with -Cpvfpv6
      -Cfvfpv2 works on a Cortex-A8, no testsuite run performed -- at least
      the fpu exception handler still needs to be implemented), Darwin has
      been tested more thoroughly
  + added ARMv6 cpu type and made it default for Darwin/ARM
  + ARMv6+ implementations of atomic operations using ldrex/strex
  * don't use r9 on Darwin/ARM, as it's reserved under certain
    circumstances (don't know yet which ones)
  * changed C-test object files for ARM/Darwin to ARMv6 versions
  * check in assembler reader that regsets are not empty, because
    instructions with a regset operand have undefined behaviour in that
    case
  * fixed resultdef of tarmtypeconvnode.first_int_to_real in case of
    int64->single type conversion
  * fixed constant pool locations in case 64 bit constants are generated,
    and/or when vfp instructions with limited reach are present
  WARNING: when using VFP on an ARMv6 or later cpu, you *must* compile all
    code with -Cparmv6 (or higher), or you will get crashes. The reason is
    that storing/restoring multiple VFP registers must happen using
    different instructions on pre/post-ARMv6.
git-svn-id: trunk@14317 -
		
	
			
		
			
				
	
	
		
			279 lines
		
	
	
		
			6.3 KiB
		
	
	
	
		
			ObjectPascal
		
	
	
	
	
	
			
		
		
	
	
			279 lines
		
	
	
		
			6.3 KiB
		
	
	
	
		
			ObjectPascal
		
	
	
	
	
	
{
 | 
						|
    Copyright (c) 1998-2002 by Peter Vreman and Florian Klaempfl
 | 
						|
 | 
						|
    Convert spreg.dat to several .inc files for usage with
 | 
						|
    the Free pascal compiler
 | 
						|
 | 
						|
    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.
 | 
						|
 | 
						|
 **********************************************************************}
 | 
						|
program mkspreg;
 | 
						|
 | 
						|
const Version = '1.00';
 | 
						|
      max_regcount = 200;
 | 
						|
 | 
						|
var s : string;
 | 
						|
    i : longint;
 | 
						|
    line : longint;
 | 
						|
    regcount:byte;
 | 
						|
    regcount_bsstart:byte;
 | 
						|
    names,
 | 
						|
    regtypes,
 | 
						|
    subtypes,
 | 
						|
    supregs,
 | 
						|
    numbers,
 | 
						|
    stdnames,
 | 
						|
    stabs,dwarf : array[0..max_regcount-1] of string[63];
 | 
						|
    regnumber_index,
 | 
						|
    std_regname_index : array[0..max_regcount-1] of byte;
 | 
						|
 | 
						|
function tostr(l : longint) : string;
 | 
						|
 | 
						|
begin
 | 
						|
  str(l,tostr);
 | 
						|
end;
 | 
						|
 | 
						|
function readstr : string;
 | 
						|
 | 
						|
  var
 | 
						|
     result : string;
 | 
						|
 | 
						|
  begin
 | 
						|
     result:='';
 | 
						|
     while (s[i]<>',') and (i<=length(s)) do
 | 
						|
       begin
 | 
						|
          result:=result+s[i];
 | 
						|
          inc(i);
 | 
						|
       end;
 | 
						|
     readstr:=result;
 | 
						|
  end;
 | 
						|
 | 
						|
 | 
						|
procedure readcomma;
 | 
						|
  begin
 | 
						|
     if s[i]<>',' then
 | 
						|
       begin
 | 
						|
         writeln('Missing "," at line ',line);
 | 
						|
         writeln('Line: "',s,'"');
 | 
						|
         halt(1);
 | 
						|
       end;
 | 
						|
     inc(i);
 | 
						|
  end;
 | 
						|
 | 
						|
 | 
						|
procedure skipspace;
 | 
						|
 | 
						|
  begin
 | 
						|
     while (s[i] in [' ',#9]) do
 | 
						|
       inc(i);
 | 
						|
  end;
 | 
						|
 | 
						|
procedure openinc(var f:text;const fn:string);
 | 
						|
begin
 | 
						|
  writeln('creating ',fn);
 | 
						|
  assign(f,fn);
 | 
						|
  rewrite(f);
 | 
						|
  writeln(f,'{ don''t edit, this file is generated from armreg.dat }');
 | 
						|
end;
 | 
						|
 | 
						|
 | 
						|
procedure closeinc(var f:text);
 | 
						|
begin
 | 
						|
  writeln(f);
 | 
						|
  close(f);
 | 
						|
end;
 | 
						|
 | 
						|
procedure build_regnum_index;
 | 
						|
 | 
						|
var h,i,j,p,t:byte;
 | 
						|
 | 
						|
begin
 | 
						|
  {Build the registernumber2regindex index.
 | 
						|
   Step 1: Fill.}
 | 
						|
  for i:=0 to regcount-1 do
 | 
						|
    regnumber_index[i]:=i;
 | 
						|
  {Step 2: Sort. We use a Shell-Metzner sort.}
 | 
						|
  p:=regcount_bsstart;
 | 
						|
  repeat
 | 
						|
    for h:=0 to regcount-p-1 do
 | 
						|
      begin
 | 
						|
        i:=h;
 | 
						|
        repeat
 | 
						|
          j:=i+p;
 | 
						|
          if numbers[regnumber_index[j]]>=numbers[regnumber_index[i]] then
 | 
						|
            break;
 | 
						|
          t:=regnumber_index[i];
 | 
						|
          regnumber_index[i]:=regnumber_index[j];
 | 
						|
          regnumber_index[j]:=t;
 | 
						|
          if i<p then
 | 
						|
            break;
 | 
						|
          dec(i,p);
 | 
						|
        until false;
 | 
						|
      end;
 | 
						|
    p:=p shr 1;
 | 
						|
  until p=0;
 | 
						|
end;
 | 
						|
 | 
						|
procedure build_std_regname_index;
 | 
						|
 | 
						|
var h,i,j,p,t:byte;
 | 
						|
 | 
						|
begin
 | 
						|
  {Build the registernumber2regindex index.
 | 
						|
   Step 1: Fill.}
 | 
						|
  for i:=0 to regcount-1 do
 | 
						|
    std_regname_index[i]:=i;
 | 
						|
  {Step 2: Sort. We use a Shell-Metzner sort.}
 | 
						|
  p:=regcount_bsstart;
 | 
						|
  repeat
 | 
						|
    for h:=0 to regcount-p-1 do
 | 
						|
      begin
 | 
						|
        i:=h;
 | 
						|
        repeat
 | 
						|
          j:=i+p;
 | 
						|
          if stdnames[std_regname_index[j]]>=stdnames[std_regname_index[i]] then
 | 
						|
            break;
 | 
						|
          t:=std_regname_index[i];
 | 
						|
          std_regname_index[i]:=std_regname_index[j];
 | 
						|
          std_regname_index[j]:=t;
 | 
						|
          if i<p then
 | 
						|
            break;
 | 
						|
          dec(i,p);
 | 
						|
        until false;
 | 
						|
      end;
 | 
						|
    p:=p shr 1;
 | 
						|
  until p=0;
 | 
						|
end;
 | 
						|
 | 
						|
 | 
						|
procedure read_spreg_file;
 | 
						|
 | 
						|
var infile:text;
 | 
						|
 | 
						|
begin
 | 
						|
   { open dat file }
 | 
						|
   assign(infile,'armreg.dat');
 | 
						|
   reset(infile);
 | 
						|
   while not(eof(infile)) do
 | 
						|
     begin
 | 
						|
        { handle comment }
 | 
						|
        readln(infile,s);
 | 
						|
        inc(line);
 | 
						|
        while (s[1]=' ') do
 | 
						|
         delete(s,1,1);
 | 
						|
        if (s='') or (s[1]=';') then
 | 
						|
          continue;
 | 
						|
 | 
						|
        i:=1;
 | 
						|
        names[regcount]:=readstr;
 | 
						|
        readcomma;
 | 
						|
        regtypes[regcount]:=readstr;
 | 
						|
        readcomma;
 | 
						|
        subtypes[regcount]:=readstr;
 | 
						|
        readcomma;
 | 
						|
        supregs[regcount]:=readstr;
 | 
						|
        readcomma;
 | 
						|
        stdnames[regcount]:=readstr;
 | 
						|
        readcomma;
 | 
						|
        stabs[regcount]:=readstr;
 | 
						|
        readcomma;
 | 
						|
        dwarf[regcount]:=readstr;
 | 
						|
        { Create register number }
 | 
						|
        if supregs[regcount][1]<>'$' then
 | 
						|
          begin
 | 
						|
            writeln('Missing $ before number, at line ',line);
 | 
						|
            writeln('Line: "',s,'"');
 | 
						|
            halt(1);
 | 
						|
          end;
 | 
						|
        numbers[regcount]:=regtypes[regcount]+copy(subtypes[regcount],2,255)+'00'+copy(supregs[regcount],2,255);
 | 
						|
        if i<length(s) then
 | 
						|
          begin
 | 
						|
            writeln('Extra chars at end of line, at line ',line);
 | 
						|
            writeln('Line: "',s,'"');
 | 
						|
            halt(1);
 | 
						|
          end;
 | 
						|
        inc(regcount);
 | 
						|
        if regcount>max_regcount then
 | 
						|
          begin
 | 
						|
            writeln('Error: Too much registers, please increase maxregcount in source');
 | 
						|
            halt(2);
 | 
						|
          end;
 | 
						|
     end;
 | 
						|
   close(infile);
 | 
						|
end;
 | 
						|
 | 
						|
procedure write_inc_files;
 | 
						|
 | 
						|
var
 | 
						|
    norfile,stdfile,supfile,
 | 
						|
    numfile,stabfile,dwarffile,confile,
 | 
						|
    rnifile,srifile:text;
 | 
						|
    first:boolean;
 | 
						|
 | 
						|
begin
 | 
						|
  { create inc files }
 | 
						|
  openinc(confile,'rarmcon.inc');
 | 
						|
  openinc(supfile,'rarmsup.inc');
 | 
						|
  openinc(numfile,'rarmnum.inc');
 | 
						|
  openinc(stdfile,'rarmstd.inc');
 | 
						|
  openinc(stabfile,'rarmsta.inc');
 | 
						|
  openinc(dwarffile,'rarmdwa.inc');
 | 
						|
  openinc(norfile,'rarmnor.inc');
 | 
						|
  openinc(rnifile,'rarmrni.inc');
 | 
						|
  openinc(srifile,'rarmsri.inc');
 | 
						|
  first:=true;
 | 
						|
  for i:=0 to regcount-1 do
 | 
						|
    begin
 | 
						|
      if not first then
 | 
						|
        begin
 | 
						|
          writeln(numfile,',');
 | 
						|
          writeln(stdfile,',');
 | 
						|
          writeln(stabfile,',');
 | 
						|
          writeln(dwarffile,',');
 | 
						|
          writeln(rnifile,',');
 | 
						|
          writeln(srifile,',');
 | 
						|
        end
 | 
						|
      else
 | 
						|
        first:=false;
 | 
						|
      writeln(supfile,'RS_',names[i],' = ',supregs[i],';');
 | 
						|
      writeln(confile,'NR_'+names[i],' = ','tregister(',numbers[i],')',';');
 | 
						|
      write(numfile,'tregister(',numbers[i],')');
 | 
						|
      write(stdfile,'''',stdnames[i],'''');
 | 
						|
      write(stabfile,stabs[i]);
 | 
						|
      write(dwarffile,dwarf[i]);
 | 
						|
      write(rnifile,regnumber_index[i]);
 | 
						|
      write(srifile,std_regname_index[i]);
 | 
						|
    end;
 | 
						|
  write(norfile,regcount);
 | 
						|
  close(confile);
 | 
						|
  close(supfile);
 | 
						|
  closeinc(numfile);
 | 
						|
  closeinc(stdfile);
 | 
						|
  closeinc(stabfile);
 | 
						|
  closeinc(dwarffile);
 | 
						|
  closeinc(norfile);
 | 
						|
  closeinc(rnifile);
 | 
						|
  closeinc(srifile);
 | 
						|
  writeln('Done!');
 | 
						|
  writeln(regcount,' registers procesed');
 | 
						|
end;
 | 
						|
 | 
						|
 | 
						|
begin
 | 
						|
   writeln('Register Table Converter Version ',Version);
 | 
						|
   line:=0;
 | 
						|
   regcount:=0;
 | 
						|
   read_spreg_file;
 | 
						|
   regcount_bsstart:=1;
 | 
						|
   while 2*regcount_bsstart<regcount do
 | 
						|
     regcount_bsstart:=regcount_bsstart*2;
 | 
						|
   build_regnum_index;
 | 
						|
   build_std_regname_index;
 | 
						|
   write_inc_files;
 | 
						|
end.
 |