View Issue Details

IDProjectCategoryView StatusLast Update
0035752FPCRTLpublic2019-08-16 09:19
ReporterAndi FriessAssigned ToJeppe Johansen 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
PlatformDell XPSOSWin10 / 64 ProOS VersionWin10 / 64 Pro
Product Version3.3.1Product Build42271 
Target VersionFixed in Version 
Summary0035752: Creating avr crosscompiler stops building rtl
Descriptionsystem.pp cannot build for avr5.

The error is in rtl\avr\avr.inc in the move procedure. This was switched in rev 42155 to assembler by laksen. It looks the line

 {$define FPC_SYSTEM_HAS_MOVE}
procedure Move(const source;var dest;count:SizeInt);[public, alias: 'FPC_MOVE']; assembler; nostackframe;
asm
  push r28
  push r29

  movw r26, r24 // Src=X
  movw r28, r22 // Dest=Y
  movw r30, r20 // Count=Z
  cp r1, r30
  cpc r1, r31
  brge .Lexit // if 0 >= Count
  cp r28, r26
  cpc r29, r27
  breq .Lexit // if dest = source
  brlo .LForwardMove // if dest < source

  // Add count to both pointers
  add r26, r30
  adc r27, r31
  add r28, r30
  adc r29, r31
.LBackwardMove:
  ld r18, -X
  st -Y, r18
  sbiw Z, 1 // <--- should be sbiw ZL,1
  brne .LBackwardMove
  rjmp .Lexit

.LForwardMove:
  ld r18, X+
  st Y+, r18
  sbiw Z, 1 // <--- should be sbiw ZL,1
  brne .LForwardMove
.Lexit:

  pop r29
  pop r28
end;

sbiw according https://www.microchip.com/webdoc/avrassembler/avrassembler.wb_SBIW.html should be sbiw ZH:ZL,1

See Thread (german) https://www.lazarusforum.de/viewtopic.php?f=9&t=12420&p=110081#p110081
Steps To Reproducebuild trunk version of fpc with fpcupdeluxe with tarbget avr embedded subarch avr5

with the change to sbiw ZL,1 it works.
Additional InformationD:/data/lazdev/trunk/fpcsrc/compiler/ppcrossavr.exe -Cpavr5 -Ur -Tembedded -Pavr -XPavr-embedded- -Xr -Ur -Xs -O2 -n -Fi../inc -Fi../avr -FDD:\data\lazdev\trunk\cross\bin\avr-embedded -FE. -FUD:/data/lazdev/trunk/fpcsrc/rtl/units/avr-embedded -vw-n-h-l-d-u-t-p-c- -O2 -davr -dRELEASE -XPavr-embedded- -Xd -FlD:\data\lazdev\trunk\cross\lib\avr-embedded\avr5 -Cpavr5 -Us -Sg system.pp @system.cfg
D:\data\lazdev\trunk\fpcsrc\rtl\units\avr-embedded\system.s: Assembler messages:
D:\data\lazdev\trunk\fpcsrc\rtl\units\avr-embedded\system.s:30: Error: constant value required
D:\data\lazdev\trunk\fpcsrc\rtl\units\avr-embedded\system.s:30: Error: register r24, r26, r28 or r30 required
D:\data\lazdev\trunk\fpcsrc\rtl\units\avr-embedded\system.s:36: Error: constant value required
D:\data\lazdev\trunk\fpcsrc\rtl\units\avr-embedded\system.s:36: Error: register r24, r26, r28 or r30 required
system.pp(336) Error: Error while assembling exitcode 1
system.pp(336) Fatal: There were 2 errors compiling module, stopping
Fatal: Compilation aborted
make[2]: *** [embedded_all] Error 2
make[1]: *** [rtl_all] Error 2
make: *** [build-stamp.avr-embedded] Error 2
TagsAVR
Fixed in Revision42336
FPCOldBugId
FPCTarget-
Attached Files
  • avr.inc.patch (397 bytes)
    Index: avr.inc
    ===================================================================
    --- avr.inc	(revision 42271)
    +++ avr.inc	(working copy)
    @@ -56,7 +56,7 @@
     .LBackwardMove:
       ld r18, -X
       st -Y, r18
    -  sbiw Z, 1
    +  sbiw ZL, 1
       brne .LBackwardMove
       rjmp .Lexit
     
    @@ -63,7 +63,7 @@
     .LForwardMove:
       ld r18, X+
       st Y+, r18
    -  sbiw Z, 1
    +  sbiw ZL, 1
       brne .LForwardMove
     .Lexit:
     
    
    avr.inc.patch (397 bytes)

Relationships

has duplicate 0035747 resolvedJonas Maebe Rev 42155 gives [dreaded] error: register r24, r26, r28 or r30 required 

Activities

Andi Friess

2019-06-22 17:01

reporter   ~0116854

patch inserted

avr.inc.patch (397 bytes)
Index: avr.inc
===================================================================
--- avr.inc	(revision 42271)
+++ avr.inc	(working copy)
@@ -56,7 +56,7 @@
 .LBackwardMove:
   ld r18, -X
   st -Y, r18
-  sbiw Z, 1
+  sbiw ZL, 1
   brne .LBackwardMove
   rjmp .Lexit
 
@@ -63,7 +63,7 @@
 .LForwardMove:
   ld r18, X+
   st Y+, r18
-  sbiw Z, 1
+  sbiw ZL, 1
   brne .LForwardMove
 .Lexit:
 
avr.inc.patch (397 bytes)

Christo Crause

2019-06-23 15:26

reporter   ~0116871

I can compile trunk without problems, and I verified that the sbiw Z, 1 is indeed present in the generated system.s
GNU assembler version 2.26 (avr) using BFD version (GNU Binutils) 2.26.20160125

I can confirm that Andi's patch also compile with binutils 2.26, so it would be an acceptable solution.

Stylistically speaking I would suggest sbiw R30, 1 because the surrounding code only refer to pointer register names for ld and st operations.

Andi Friess

2019-06-23 16:31

reporter   ~0116872

i test with GNU assembler version 2.21.1 (avr) using BFD version (GNU Binutils) 2.21.1

(as deliverd by my fpcupdeluxe)

Andi Friess

2019-08-16 09:19

reporter   ~0117696

THX

Issue History

Date Modified Username Field Change
2019-06-22 17:00 Andi Friess New Issue
2019-06-22 17:01 Andi Friess File Added: avr.inc.patch
2019-06-22 17:01 Andi Friess Note Added: 0116854
2019-06-22 17:07 Jonas Maebe Relationship added has duplicate 0035747
2019-06-22 22:38 Andi Friess Tag Attached: AVR
2019-06-23 15:26 Christo Crause Note Added: 0116871
2019-06-23 16:31 Andi Friess Note Added: 0116872
2019-07-07 13:51 Jeppe Johansen Assigned To => Jeppe Johansen
2019-07-07 13:51 Jeppe Johansen Status new => resolved
2019-07-07 13:51 Jeppe Johansen Resolution open => fixed
2019-07-07 13:51 Jeppe Johansen Fixed in Revision => 42336
2019-07-07 13:51 Jeppe Johansen FPCTarget => -
2019-08-16 09:19 Andi Friess Status resolved => closed
2019-08-16 09:19 Andi Friess Note Added: 0117696