Hi folks,
I work on reanimation of the XINU operation system for my real "old iron"
PDP-11/03. During my work I found a bug in the gcc code generation for PDP-11
target, please find details below.

Host information:
i686 running Debian 5.0, Kernel 2.6.26-1-686,
host native gcc version 4.3.2 (Debian 4.3.2-1.1)

Crosscompiler information:
gcc-core-4.3.3.tar.gz  source file downloaded from gnu.org, built with:
<gcc-src>/configure --target=pdp11-dec-bsd --disable-nls --without-headers
--enable-languages=c
make all-gcc
make install-gcc

Crosscompiler test:
Type "pdp11-dec-bsd-gcc -S and.c" for the following input C file:

/* and.c */

int and()
{
   int a = 06666;
   int b = 03333;

   return ( a & b );
}

It results in the following output assembler file:

        .text

        .even
        .globl _and
_and:
~~and:
        jsr     r5, csv
        /*abuse empty parameter slot for locals!*/
        sub $02, sp
        mov $06666, 0177764(r5)
        mov $03333, 0177766(r5)
        mov 0177764(r5), r0
        bic 0177766(r5), r0
        /* SP ignored by cret? */
        jmp cret

This is an obvious error, for the logical "AND" is *not* equivalent to the
PDP-11 "BIC" (BIt Clear) instruction. BIC performs the operation <dest> &=
!(<src>), see for example "PDP 11/40 processor handbook", DEC, Maynard (Mass.)
1972, page 4-29.

Temporary fix:
A quick but not-so-nice bugfix is to uncomment the buggy "and" definitions in
the machine definition file <gcc-src>/gcc/config/pdp11/pdp11.md (lines 1152 to
1217). The rebuilt compiler then generates function calls to ___andsi3 and
___andhi3 which the user must supply, of course.
Using this fix I was able to compile the demo.c program and standalone library
of the XINU sources and successfully ran the binary on my real old PDP-11/03.

~Diane.


-- 
           Summary: pdp11 code generation bug & temporary fix
           Product: gcc
           Version: 4.3.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: diane dot neisius at web dot de
 GCC build triplet: i386-linux-gnu
  GCC host triplet: i386-linux-gnu
GCC target triplet: pdp11-dec-bsd


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41822

Reply via email to