[fpc-pascal] Embedded ARM7 and long strings

Carsten Bager carsten at beas.dk
Wed Jul 24 09:07:01 CEST 2013


I am using the FPC compiler to compile embedded ARM7 code (LPC21xx / LPC23xx).
For this purpose, I use the 2.05 compiler, and it is working without problems at all.
However, because we are using the 2.62 compiler on other platforms, I have compiled a new 
system unit for the ARM7 platform with the 2.62 compiler. I then ran into this problem.

The old compiler uses "fpc_chararray_to_shortstr" to comvert from an array of char to a 
shortstring. That works OK.

The 2.62 compiler wants to use "fpc_chararray_to_ansistr" to the same job, and that is a 
problem because my ARM7 system unit do not support ansistrings (and should not).

The {$LONGSTRINGS OFF} directive is given at the beginning of the program, and that 
eliminates any problems with "long strings" using the 2.05 compiler. That does not seem to 
work with the new compiler.

Is there a way around this problem?

Carsten



FPC 2.05
# [38] Val(pChar16(LineDataOfset)^,NameDataOfset,p);
	sub	r5,r11,#568
	ldr	r0,.L57
	ldr	r4,[r0]
	mov	r3,#1
	mov	r2,#15
	mov	r1,r4
	sub	r0,r11,#824
	bl	fpc_chararray_to_shortstr
	sub	r1,r11,#824
	mov	r0,#4
	mov	r2,r5
	bl	fpc_val_sint_shortstr
	ldr	r1,.L68
	str	r0,[r1]
	ldr	r0,.L71
	sub	r3,r11,#568
	mov	r2,#2
.L72:
	ldrb	r1,[r3], #1
	subs	r2,r2,#1
	strb	r1,[r0], #1
	bne	.L72

FPC 2.62
# [38] Val(pChar16(LineDataOfset)^,NameDataOfset,p);
	sub	r0,r11,#628
	bl	FPC_ANSISTR_DECR_REF
	mov	r0,#0
	str	r0,[r11, #-628]
	ldr	r0,.Lj13
	ldr	r1,[r0]
	sub	r0,r11,#628
	mov	r3,#1
	mov	r2,#15
	bl	fpc_chararray_to_ansistr
	ldr	r1,[r11, #-628]
	sub	r2,r11,#116
	mov	r0,#4
	bl	fpc_val_sint_ansistr
	ldr	r1,.Lj70
	str	r0,[r1]
	ldrb	r0,[r11, #-116]
	ldr	r1,.Lj73
	strb	r0,[r1]
	ldrb	r0,[r11, #-115]
	strb	r0,[r1, #1]
	.stabn 68,0,39,_$LINEINFO$_Ll9 - 




unit lineinfo;
{$LONGSTRINGS OFF}
{$Assertions off}
{$RANGECHECKS OFF}
{$OVERFLOWCHECKS OFF}
{$S- STACK CHECKING OFF}


interface

procedure GetLineInfo(addr:pointer; var FuncStringListPointer,SrcStringListPointer:pChar; 
var line:longWord);


implementation
uses
  LineInfoTyp;

var
  data_beg_src:byte; external name '__data_beg_src__';
  data_beg:byte; external name '__data_beg__';
  data_end:byte; external name '__data_end__';
  LineDataOfset,EndLineDataOfset,NameDataOfset:Longint;         {Skal være longint}
  p:integer;

Type
  Char16=array[0..15] of char;
  pChar16=^Char16;
  pArm7LineInfo=^Arm7LineInfo_typ;

procedure GetLineInfo(addr:pointer; var FuncStringListPointer,SrcStringListPointer:pChar; 
var line:longWord);
Begin
  LineDataOfset:=(Longint(@data_end)-Longint(@data_beg))+Longint(@data_beg_src);
  if (byte(LineDataOfset) and $0F)<>0 then
    LineDataOfset:=(LineDataOfset and $FFFFFFF0) +$10;
  if pChar16(LineDataOfset)^ = cLineDataOfsetString then
  begin
    LineDataOfset:=LineDataOfset+16;
    Val(pChar16(LineDataOfset)^,NameDataOfset,p);
    if p=0 then
    begin
      LineDataOfset:=LineDataOfset+16;
      NameDataOfset:=NameDataOfset+LineDataOfset;
      EndLineDataOfset:=NameDataOfset;
      if pChar16(NameDataOfset)^ = cNameDataOfsetString then
      begin
        NameDataOfset:=NameDataOfset+32;
        while LineDataOfset<EndLineDataOfset do
        begin
          if pArm7LineInfo(LineDataOfset)^.addr>longword(addr) then
          begin
            LineDataOfset:=LineDataOfset-16;
            line:=pArm7LineInfo(LineDataOfset)^.line;
            
longint(FuncStringListPointer):=longint(pArm7LineInfo(LineDataOfset)^.FuncStringListPointer
)+NameDataOfset;
            
longint(SrcStringListPointer):=longint(pArm7LineInfo(LineDataOfset)^.SrcStringListPointer)+
NameDataOfset;
            exit;
          end;
          LineDataOfset:=LineDataOfset+16;
        end;
      end else runerror(48);            {Error finding Str. Ofset}
    end else runerror(49);              {Error in val of str. Of.}
  end else runerror(50);                {Error finding Data Ofset}
End;

end.





More information about the fpc-pascal mailing list