Loading ...
Sorry, an error occurred while loading the content.

No assembly code generated

Expand Messages
  • Clarence Roop
    Hi, I’ve tried to compile a driver for a UART on the TMS470R1B1M part of the driver ( the write function is shown below):   staticintuart_write(
    Message 1 of 9 , Jan 30, 2014
    • 0 Attachment

      Hi, I’ve tried to compile a driver for a UART on the TMS470R1B1M part of the driver ( the write function is shown below):
       
      static int uart_write( struct _file_descriptor* fd, const void* write_buf, int num_bytes )
      {
             int bytes_written = -1;
             SCI_TypeDef* SCIx;
             if( ( is_valid_handle( fd ) )     &&
                 ( write_buf != NULL )         &&
                 ( num_bytes > 0 ) )
             {
                   SCIx = ( ( SCI_TypeDef* )( fd->fd_priv_data ) );
                   if( ( fd->mode & O_RDONLY ) != O_RDONLY )
                   {
                          bytes_written = 0;
                          while( bytes_written < num_bytes )
                          {
                                 /* Determine if the transmitter is ready to
                                    transmit a byte */
                                 while( ( SCIx->CTL2 & SCI_TXRDY ) != 0 )
                                        asm("nop;");
                                 SCIx->TXBUF =
                                  ( ( char* )( write_buf ) )[bytes_written++];
                          }
                   }
             }
             return bytes_written;
      }
       
      When complied with gcc arm-elf 4.2.0 I’ve gotten the following output:
       
      static int uart_write( struct _file_descriptor* fd, const void* write_buf, int num_bytes ) 
      {
      uart_wri:mov     r12,r13              
      stmdb   r13!,{r11-r12,r14,pc} 
      sub     r11,r12,#0x4
      sub     r13,r13,#0x14
      str     r0,[r11,#-0x18]
      str     r1,[r11,#-0x1C]
      str     r2,[r11,#-0x20]  
      volatile int bytes_written = -1;
      mvn     r3,#0x0
      str     r3,[r11,#-0x14]
      volatile SCI_TypeDef* SCIx;
      if( ( is_valid_handle( fd ) ) && ( write_buf != NULL ) && ( num_bytes > 0 ) )
      ldr     r0,[r11,#-0x18]
      bl      0x11180          ; is_valid_handle 
      mov     r3,r0  
      cmp     r3,#0x0
      beq     0x11540  
      ldr     r3,[r11,#-0x1C] 
      cmp     r3,#0x0
      beq     0x11540
      ldr     r3,[r11,#-0x20]
      cmp     r3,#0x0
      ble     0x11540
      {
      SCIx = ( ( SCI_TypeDef* )( fd->fd_priv_data ) );
      ldr     r3,[r11,#-0x18]
      ldr     r3,[r3,#0x1C]    
      str     r3,[r11,#-0x10] 
       
      while( bytes_written < num_bytes ) 
      {
      /* Determine if the transmitter is ready to transmit a byte */
      while( ( SCIx->CTL2 & SCI_TXRDY ) != 0 ) asm("nop;"); 
      SCIx->TXBUF = ( ( char* )( write_buf ) )[bytes_written++];
      }
       
      }
      return bytes_written;
      ldr     r3,[r11,#-0x14]
      mov     r0,r3
      sub     r13,r11,#0x0C 
      ldmia   r13,{r11,r13,pc} 
      }
       
      As can be seen no assembly code is generated for the while loop. These are the flags used for gcc
       
      CFLAGS += -mbig-endian  -mcpu=arm7tdmi -mapcs-frame -gdwarf-2 -I$(PROJECTROOT)
       
      AFLAGS = -mcpu=arm7tdmi  --warn -EB -mfpu=softfpa -mapcs-32 --gdwarf2
       
      LDFLAGS = --script=$(TMS470R1B1MDIR)ldscript -EB -Map=$(OUTPUTDIR)/main.map --cref --gc-sections
       
      ODFLAGS = --wide --source --all-headers --reloc --syms --disassemble -t
       
      LDFLAGS += -L /cygdrive/c/GNUARM/arm-elf/lib/be/
       
      LIBS = $(SYSTEMLIBSDIR)libgcc.a
      LIBS += /cygdrive/c/GNUARM/arm-elf/lib/be/libc.a
      LIBS += /cygdrive/c/GNUARM/arm-elf/lib/be/libg.a
      LIBS += /cygdrive/c/GNUARM/arm-elf/lib/be/libm.a
       
       
      Any suggestion I can try to get the complier to generate the assembly code for the while loop?
       
      Thanks
      Regards,
      Clarence Roopnarine.
       
       
    • German Ortiz
      Try declaring bytes_written as volatile Greatings!  El 30/01/2014 07:55 a.m., Clarence Roop escribió: Hi, I’ve tried to compile a driver for a UART on the
      Message 2 of 9 , Jan 30, 2014
      • 0 Attachment
        Try declaring bytes_written as volatile
        Greatings!

         El 30/01/2014 07:55 a.m., Clarence Roop escribió:

        Hi, I’ve tried to compile a driver for a UART on the TMS470R1B1M part of the driver ( the write function is shown below):
         
        static int uart_write( struct _file_descriptor* fd, const void* write_buf, int num_bytes )
        {
               int bytes_written = -1;
               SCI_TypeDef* SCIx;
               if( ( is_valid_handle( fd ) )     &&
                   ( write_buf != NULL )         &&
                   ( num_bytes > 0 ) )
               {
                     SCIx = ( ( SCI_TypeDef* )( fd->fd_priv_data ) );
                     if( ( fd->mode & O_RDONLY ) != O_RDONLY )
                     {
                            bytes_written = 0;
                            while( bytes_written < num_bytes )
                            {
                                   /* Determine if the transmitter is ready to
                                      transmit a byte */
                                   while( ( SCIx->CTL2 & SCI_TXRDY ) != 0 )
                                          asm("nop;");
                                   SCIx->TXBUF =
                                    ( ( char* )( write_buf ) )[bytes_written++];
                            }
                     }
               }
               return bytes_written;
        }
         
        When complied with gcc arm-elf 4.2.0 I’ve gotten the following output:
         
        static int uart_write( struct _file_descriptor* fd, const void* write_buf, int num_bytes ) 
        {
        uart_wri:mov     r12,r13              
        stmdb   r13!,{r11-r12,r14,pc} 
        sub     r11,r12,#0x4
        sub     r13,r13,#0x14
        str     r0,[r11,#-0x18]
        str     r1,[r11,#-0x1C]
        str     r2,[r11,#-0x20]  
        volatile int bytes_written = -1;
        mvn     r3,#0x0
        str     r3,[r11,#-0x14]
        volatile SCI_TypeDef* SCIx;
        if( ( is_valid_handle( fd ) ) && ( write_buf != NULL ) && ( num_bytes > 0 ) )
        ldr     r0,[r11,#-0x18]
        bl      0x11180          ; is_valid_handle 
        mov     r3,r0  
        cmp     r3,#0x0
        beq     0x11540  
        ldr     r3,[r11,#-0x1C] 
        cmp     r3,#0x0
        beq     0x11540
        ldr     r3,[r11,#-0x20]
        cmp     r3,#0x0
        ble     0x11540
        {
        SCIx = ( ( SCI_TypeDef* )( fd->fd_priv_data ) );
        ldr     r3,[r11,#-0x18]
        ldr     r3,[r3,#0x1C]    
        str     r3,[r11,#-0x10] 
         
        while( bytes_written < num_bytes ) 
        {
        /* Determine if the transmitter is ready to transmit a byte */
        while( ( SCIx->CTL2 & SCI_TXRDY ) != 0 ) asm("nop;"); 
        SCIx->TXBUF = ( ( char* )( write_buf ) )[bytes_written++];
        }
         
        }
        return bytes_written;
        ldr     r3,[r11,#-0x14]
        mov     r0,r3
        sub     r13,r11,#0x0C 
        ldmia   r13,{r11,r13,pc} 
        }
         
        As can be seen no assembly code is generated for the while loop. These are the flags used for gcc
         
        CFLAGS += -mbig-endian  -mcpu=arm7tdmi -mapcs-frame -gdwarf-2 -I$(PROJECTROOT)
         
        AFLAGS = -mcpu=arm7tdmi  --warn -EB -mfpu=softfpa -mapcs-32 --gdwarf2
         
        LDFLAGS = --script=$(TMS470R1B1MDIR)ldscript -EB -Map=$(OUTPUTDIR)/main.map --cref --gc-sections
         
        ODFLAGS = --wide --source --all-headers --reloc --syms --disassemble -t
         
        LDFLAGS += -L /cygdrive/c/GNUARM/arm-elf/lib/be/
         
        LIBS = $(SYSTEMLIBSDIR)libgcc.a
        LIBS += /cygdrive/c/GNUARM/arm-elf/lib/be/libc.a
        LIBS += /cygdrive/c/GNUARM/arm-elf/lib/be/libg.a
        LIBS += /cygdrive/c/GNUARM/arm-elf/lib/be/libm.a
         
         
        Any suggestion I can try to get the complier to generate the assembly code for the while loop?
         
        Thanks
        Regards,
        Clarence Roopnarine.
         
         

      • German Ortiz
        Sorry, forget my previous answer. Change the while for a do-while loop:                     bytes_written = 0;
        Message 3 of 9 , Jan 30, 2014
        • 0 Attachment
          Sorry, forget my previous answer.

          Change the while for a do-while loop:
                              bytes_written = 0;
                              do
                              {
                                     /* Determine if the transmitter is ready to
                                        transmit a byte */
                                     while( ( SCIx->CTL2 & SCI_TXRDY ) != 0 )
                                            asm("nop;");
                                     SCIx->TXBUF =
                                      ( ( char* )( write_buf ) )[bytes_written++];
                              } while ( bytes_written < num_bytes ) ;
          Greetings!

          El 30/01/2014 07:55 a.m., Clarence Roop escribió:

          Hi, I’ve tried to compile a driver for a UART on the TMS470R1B1M part of the driver ( the write function is shown below):
           
          static int uart_write( struct _file_descriptor* fd, const void* write_buf, int num_bytes )
          {
                 int bytes_written = -1;
                 SCI_TypeDef* SCIx;
                 if( ( is_valid_handle( fd ) )     &&
                     ( write_buf != NULL )         &&
                     ( num_bytes > 0 ) )
                 {
                       SCIx = ( ( SCI_TypeDef* )( fd->fd_priv_data ) );
                       if( ( fd->mode & O_RDONLY ) != O_RDONLY )
                       {
                              bytes_written = 0;
                              while( bytes_written < num_bytes )
                              {
                                     /* Determine if the transmitter is ready to
                                        transmit a byte */
                                     while( ( SCIx->CTL2 & SCI_TXRDY ) != 0 )
                                            asm("nop;");
                                     SCIx->TXBUF =
                                      ( ( char* )( write_buf ) )[bytes_written++];
                              }
                       }
                 }
                 return bytes_written;
          }
           
          When complied with gcc arm-elf 4.2.0 I’ve gotten the following output:
           
          static int uart_write( struct _file_descriptor* fd, const void* write_buf, int num_bytes ) 
          {
          uart_wri:mov     r12,r13              
          stmdb   r13!,{r11-r12,r14,pc} 
          sub     r11,r12,#0x4
          sub     r13,r13,#0x14
          str     r0,[r11,#-0x18]
          str     r1,[r11,#-0x1C]
          str     r2,[r11,#-0x20]  
          volatile int bytes_written = -1;
          mvn     r3,#0x0
          str     r3,[r11,#-0x14]
          volatile SCI_TypeDef* SCIx;
          if( ( is_valid_handle( fd ) ) && ( write_buf != NULL ) && ( num_bytes > 0 ) )
          ldr     r0,[r11,#-0x18]
          bl      0x11180          ; is_valid_handle 
          mov     r3,r0  
          cmp     r3,#0x0
          beq     0x11540  
          ldr     r3,[r11,#-0x1C] 
          cmp     r3,#0x0
          beq     0x11540
          ldr     r3,[r11,#-0x20]
          cmp     r3,#0x0
          ble     0x11540
          {
          SCIx = ( ( SCI_TypeDef* )( fd->fd_priv_data ) );
          ldr     r3,[r11,#-0x18]
          ldr     r3,[r3,#0x1C]    
          str     r3,[r11,#-0x10] 
           
          while( bytes_written < num_bytes ) 
          {
          /* Determine if the transmitter is ready to transmit a byte */
          while( ( SCIx->CTL2 & SCI_TXRDY ) != 0 ) asm("nop;"); 
          SCIx->TXBUF = ( ( char* )( write_buf ) )[bytes_written++];
          }
           
          }
          return bytes_written;
          ldr     r3,[r11,#-0x14]
          mov     r0,r3
          sub     r13,r11,#0x0C 
          ldmia   r13,{r11,r13,pc} 
          }
           
          As can be seen no assembly code is generated for the while loop. These are the flags used for gcc
           
          CFLAGS += -mbig-endian  -mcpu=arm7tdmi -mapcs-frame -gdwarf-2 -I$(PROJECTROOT)
           
          AFLAGS = -mcpu=arm7tdmi  --warn -EB -mfpu=softfpa -mapcs-32 --gdwarf2
           
          LDFLAGS = --script=$(TMS470R1B1MDIR)ldscript -EB -Map=$(OUTPUTDIR)/main.map --cref --gc-sections
           
          ODFLAGS = --wide --source --all-headers --reloc --syms --disassemble -t
           
          LDFLAGS += -L /cygdrive/c/GNUARM/arm-elf/lib/be/
           
          LIBS = $(SYSTEMLIBSDIR)libgcc.a
          LIBS += /cygdrive/c/GNUARM/arm-elf/lib/be/libc.a
          LIBS += /cygdrive/c/GNUARM/arm-elf/lib/be/libg.a
          LIBS += /cygdrive/c/GNUARM/arm-elf/lib/be/libm.a
           
           
          Any suggestion I can try to get the complier to generate the assembly code for the while loop?
           
          Thanks
          Regards,
          Clarence Roopnarine.
           
           

        • clarenceroop
          Mr Ortiz, I did, I even delcare the register as volatile and it did not help. Thanks.
          Message 4 of 9 , Jan 30, 2014
          • 0 Attachment

            Mr Ortiz,

              I did, I even delcare the register as volatile and it did not help. Thanks.

          • clarenceroop
            Thanks Mr. Ortiz, will try and respond with feedback, appreciate the help.
            Message 5 of 9 , Jan 30, 2014
            • 0 Attachment

              Thanks Mr. Ortiz, will try and respond with feedback, appreciate the  help.

            • clarenceroop
              Tried and got the same results, no assembly code was generated for the do...while loop. Thanks again.
              Message 6 of 9 , Jan 30, 2014
              • 0 Attachment

                Tried and got the same results, no assembly code was generated for the do...while loop. Thanks again.

              • Steven Leiphart
                The first thing I thought of too was using a volatile data type (which you should be doing even if it is not actually THE problem). However, that would not
                Message 7 of 9 , Jan 30, 2014
                • 0 Attachment

                  The first thing I thought of too was using a volatile data type (which you should be doing even if it is not actually THE problem).  However, that would not prevent the generation of code, it would have just made it not work correctly since the inner while loop could be running off of a cached data value and never see the flag change in the register field it should be referencing.

                   

                  The only reason beyond there being a bug in the compiler is if the compiler assumes it can optimize the code away.  This is only done if the compiler, using more information than is available in your code snippet, can determine a priori that the outer while loop will be a constant false value or the operation to be performed inside the loop is effectively a no-op.

                   

                  Since insufficient information is provided with the data types and values represented by the constants, any more support than that is impossible without merely providing guesses and assumptions.

                   

                  Follow the data types and constant values back to their definitions and attempt to determine if they are values that will never be true in the while condition or if the operation to be performed accomplishes nothing and can be removed due to an invalid value or something similar.

                   

                  Thanks,

                  Steve.

                   

                   

                  From: TMS470_ARM@yahoogroups.com [mailto:TMS470_ARM@yahoogroups.com] On Behalf Of clarenceroop@...
                  Sent: Thursday, January 30, 2014 1:28 PM
                  To: TMS470_ARM@yahoogroups.com
                  Subject: Re: [TMS470_ARM] No assembly code generated

                   

                   

                  Tried and got the same results, no assembly code was generated for the do...while loop. Thanks again.

                • clarenceroop
                  Thanks Mr. Leiphart, I ve found the cause but don t know the solution. If I comment out the if condition i.e. //if( ( ( fd- mode ) & O_RDONLY ) != O_RDONLY )
                  Message 8 of 9 , Jan 31, 2014
                  • 0 Attachment

                    Thanks Mr. Leiphart, I've found the cause but don't know the solution. If I comment out the if condition i.e. 

                     

                    //if( ( ( fd->mode ) & O_RDONLY ) != O_RDONLY )

                     

                    the compiler generates the assmebly code. This is a valid necessisity for the driver. Any suggestion? ( Tried casing all the variables to volatile but that did not help.)

                     

                    Thanks again

                     

                     

                  • clarenceroop
                    Thanks everyone for your input - Mr. Leiphart was right, the condition (fd- mode & O_RDONLY != O_RDONLY) will always evaluate to false since the constan
                    Message 9 of 9 , Jan 31, 2014
                    • 0 Attachment

                      Thanks everyone for your input - Mr. Leiphart was right, the condition

                          (fd->mode & O_RDONLY != O_RDONLY)

                      will always evaluate to false since the constan O_RDONLY ≡ 0 and anything ANDDED with it will yield zero. I've replaced this with

                      if(fd->mode != O_RDONLY) and all is fine.

                      Thanks again.

                       

                    Your message has been successfully submitted and would be delivered to recipients shortly.