Jump to content
Sign in to follow this  
BrownFrog

Boostc Compiler Crash - Access Violation Error

Recommended Posts

The following code crashes boostc.pic18 in versions 6.60 and 6.70:

 

#include <system.h>

#undef BYTE
typedef unsigned char BYTE;                 // 8-bit

typedef struct _MAC_ADDR
{
   BYTE v[6];
} MAC_ADDR;

typedef struct _NODE_INFO
{
   MAC_ADDR    MACAddr;
} NODE_INFO;

typedef enum _TCP_STATE
{
   TCP_INVALID
} TCP_STATE;

typedef struct _SOCKET_INFO
{
   TCP_STATE smState;
   NODE_INFO remote;
} SOCKET_INFO;

SOCKET_INFO test;

void CrashMe(void)
{
   SOCKET_INFO *ps;
   NODE_INFO *remote;

   ps = &test;
   
   remote = &ps->remote;

   return;
}

 

(This is a much-abridged fragment from Microchip TCP/IP stack - some of the struct nesting looks unnecessary because I've removed members not needed to trigger the crash).

 

The compiler crashes, popping up an error window reporting "Error: Access violation at 0x004a93a9 (tried to write 0x00000064), program terminated", and the IDE Build window reports an exit code of -1073741819.

 

The offending statement is the access to ps->remote - with that line commented out the code compiles fine.

 

Swapping the order of the members inside the SOCKET_INFO struct removes the problem (although I've not tested the full code with this change).

 

 

IDE version: 6.70

Compiler: BoostC

Compiler version: 6.60, 6.70

Target device: PIC18F25J10

OS: WinXP SP2

 

 

Comments: The crash occurs when boostc.pic18 is invoked from the command line too.

 

Cheers

 

John

Share this post


Link to post
Share on other sites

John,

The following code crashes boostc.pic18 in versions 6.60 and 6.70:

 

...

...

 

Swapping the order of the members inside the SOCKET_INFO struct removes the problem (although I've not tested the full code with this change).

 

 

IDE version:          6.70

Compiler:              BoostC

Compiler version:  6.60, 6.70

Target device:      PIC18F25J10

OS:                      WinXP SP2

We can reproduce this problem, so its been added to our bug list.

 

Regards

Dave

Share this post


Link to post
Share on other sites

Hi Guys,

 

I'm seeing a similar crash, though not from struct pointers.

 

The error pop-up reads:

Error: Access violation at 0x7800FFE7 (tried to read from 0x014B2000), program terminated.

 

And the return error code in SourceBoost is 128

 

The command line is:

"C:\Program Files\SourceBoost\boostc.pic18.exe" LED_Head.c -t PIC18F2420 LED_Head.c

 

The main application is fairly small (around 300 lines), but it includes a very-slightly-patched version of rs232_driver.h. I was going to offer to mail it, but at that size it might as well get attached here..

 

This code compiled fine in V6.55 in the IDE but I just had a warning/error from MPLAB that my compiler license "has expired" (? .. no it hasn't .. and SourceBoost is OK). I downloaded V6.60 in case this was a fixed bug, but just get this bug instead (or possibly as well?).

 

This program is a cut-down of a larger program, so there may be a few redundant bits still lying around.

 

--------8<-----  LED_Head.h --------------------------------------------
#ifndef _LED_HEAD_H_
#define _LED_HEAD_H_

//==================================================================
//    USART definitions
//==================================================================
//
//    I think these must be values, not #defines from the CPU header file?
//    ( see serial_test.c in the Samples directory)
//
// #define USART_SIM

#ifdef USART_SIM
#   define TX_PORT    0x0f8b
#   define TX_TRIS    0x0f94
#   define TX_BIT    6
#   define RX_PORT    0x0f82
#   define RX_TRIS    0x0f94
#   define RX_BIT    7
#   define e_SPBRG    0x47
#   define e_RCREG    0x48
#   define e_TXREG    0x49
#   define e_TXSTA    0x4A
#   define e_RCSTA    0x4B
#   define e_TXIF_PIR    0x4C
#   define e_RCIF_PIR    0x4C
#   define e_TXIF_BIT    4
#   define e_RCIF_BIT    5                
#   define MODE        (USART_reset_wdt)
#else
#   define TX_PORT    0x0f82
#   define TX_TRIS    0x0f94
#   define TX_BIT    6
#   define RX_PORT    0x0f82
#   define RX_TRIS    0x0f94
#   define RX_BIT    7
#   define e_SPBRG    0xfaf
#   define e_RCREG    0xfae
#   define e_TXREG    0xfad
#   define e_TXSTA    0xfac
#   define e_RCSTA    0xfab
#   define e_TXIF_PIR    0xf9e
#   define e_RCIF_PIR    0xf9e
#   define e_TXIF_BIT    4
#   define e_RCIF_BIT    5                
#   define MODE        (USART_reset_wdt | USART_HW)
#endif

//#define bit_time 87    /* 115200 bps */
#define bit_time 174    /*  57600 bps */
//#define bit_time 340    /*  28800 bps */
//#define bit_time 690    /*  14400 bps */
//#define bit_time 520    /*  19200 bps */
//#define bit_time 1042    /*  9600 bps */


enum RX_STATE
{
   RX_START,
   RX_CHAR1,        // R, S, V, X, Y
   RX_CHAR2,        // Looking for RR, Sxx, VV, XX, YO!
   RX_CHAR3,        // Looking for Sxx
   RX_AWAITCR,        // just await a <CR> (usually error recovery)
   RX_MAX_STATE    // Something's awry -- try a reinitialise.
};

enum ERRORS
{
   ERR_OK,
   ERR_BAD_CHAR,
   ERR_BAD_CHAR1,
   ERR_BAD_CHAR2,
   ERR_BAD_CHAR3,
   ERR_BAD_DIGIT,
};


#endif //_LED_HEAD_H_

--------8<----  LED_Head.c ----------------------------------

#include <system.h>
#include "LED_Head.h"
#include "rs232_driver.h"    /* local copy -- adapt to buffered IRQ */

#define stroke_watchdog()    clear_wdt()
//
//==================================================================
//    COOLLED        Microscopy Illuminator LED Head controller
//==================================================================
//
//    $Header$
//
//    Uses serial data to communicate with main controller.
//        (Serial interface is 0V..+3V `TTL')
//    Uses parallel interface to read LED module IDs
//    Uses parallel interface to control LED switches
//
//    Comms:
//        YO!    interlock. Just echo the same string
//        RR    Read LH/RH ident lines, responding R<LH><RH>\n
//            where LH and RN are 0x30..0x3F
//        S<SW>    Set switch outputs, where <SW> is 0x30..0x7F
//            so can control 6 lines (we use only four for now)
//            Response SS\n
//        VV    Return ident string
//        XX    Reset the CPU (loop until watchdog).
//            No response.

//Set clock frequency
#pragma CLOCK_FREQ    8000000

//#define    T0TIME        55    /* 100us ticks at 8MHz clock */
#define    T0TIME        131    /* 1ms ticks at 8MHz clock, prescaler=16 */

enum ERRORS    Error;

char    tick;        // IRQ flag
char    tick_100us;
char    tick_1ms;
char    tick_10ms;
char    tick_100ms;
char    tick_1s;

char    char1;
char    char2;
char    char3;

//    Circular buffer for RX data (holds up to 63 chars).
#define RX_BUF_MASK    0x3F        // must match buffer size
char    RX_buffer[64];            // somewhere to hold incomming data
char    RX_fillidx;            // .. where we're filling
char    RX_readidx;            // .. where we're unfilling
enum    RX_STATE RX_state;        // what were doing right now.

char TX_buffer[8];            // small buffer for transmissions.


char    tracebuf[256];
char    tracebuf_idx;

void
Head_error( enum ERRORS e )
{
   if( e )
   {
   Error = e;
   } else {
   Error = ERR_OK;
   }
}

char Bad_char;
char RX_status;

void
Head_error_irq( enum ERRORS e )
{
   if( e )
   {
   Error = e;
   } else {
   Error = ERR_OK;
   }
}

//
//    Low overhead ascii/int encoding
//
//    0..4F --> '0'..0x7F
//

#define a2n( c )    ((c >= '0') ? c-'0' : -1)
#define n2a( n )    ((n <= 0x4F) ? n+'0' : -1)

//Timer 0 handler
static void
tick( void )
{
   tick++;

   // Urgent work only here, remainder in background.
}

void
put_RX_buf( char c )
{
   char temp = RX_fillidx;

   temp += 1;
   temp &= RX_BUF_MASK;            // Wrap buffer!!
   if( temp != RX_readidx )
   {
   RX_buffer[RX_fillidx] = c;
   RX_fillidx = temp;
   }
}

char
get_RX_buf( void )
{
   char temp;

   if( RX_fillidx != RX_readidx )
   {
   pie1 &= ~0x20;                // RX interrupts Off
   temp = RX_buffer[ RX_readidx ];
   RX_readidx = (RX_readidx+1)&RX_BUF_MASK;    // Wrap buffer!!

   pie1 |= 0x20;                // RX interrupts On
   return( temp );
   } else {
   return( '\0' );
   }
}


static void
RX_handler( char c )
{
   //tracebuf[tracebuf_idx] = c;
   put_RX_buf( c );
   //tracebuf_idx++;
}


char RX_temp;        // use to assemble hex-digit pairs.

static void
comms_RX( char c )
{
   char temp;

   switch( RX_state )
   {

   case RX_START:
//    uart_init( 1, 8 );            // 57.6kbps at 8MHz
//    RX_state = RX_CHAR1;
//    break;

   case RX_CHAR1:
   char1 = c;
   if( 'Y' == c )
   {
       RX_state = RX_CHAR2;
   } else if( 'R' == c ) {            // Read head data
       RX_state = RX_CHAR2;        // await a second R
   } else if( 'S' == c ) {            // Set head outputs
       RX_state = RX_CHAR2;        // await some data
   } else if( 'V' == c ) {
       RX_state = RX_CHAR2;        // await a second V
   } else if( 'X' == c ) {            // could be a reset...
       RX_state = RX_CHAR2;        // await a 2nd X
   } else {
       RX_state = RX_AWAITCR;        // Error .. await <CR>
       Head_error( ERR_BAD_CHAR1 );
   }
   break;

   case RX_CHAR2:
   if( 'Y' == char1 )
   {
       if( 'O' == c )            // "saw YO!"
       {
       puts( "YO!\n" );        // acknowledge it
       }
       RX_state = RX_AWAITCR;        // Error .. await <CR>
   } else if( 'R' == char1 ) {        // Read head data
       if( 'R' == c )            // RR .. send data
       {
       TX_buffer[0] = 'R';
       TX_buffer[1] = n2a( portc & 0x0F );    // LH ident (six bits available, only four used)
       TX_buffer[2] = n2a( porta & 0x0F );    // RH ident (six bits available, only four used)
       TX_buffer[3] = '\n';
       // send data
       } else {
       RX_state = RX_AWAITCR;        // Error .. await <CR>
       Head_error( ERR_BAD_CHAR2 );
       }
       RX_state = RX_AWAITCR;
   } else if( 'S' == char1 ) {        // set head outputs
       char2 = a2n(c);
       if( char2 >= 0 )
       {
       temp = portb;            // update six bits without glitches.
       temp &= 0xC0;
       temp |= char2;
       portb = temp;
       puts( "SS\n" );
       } else {
       RX_state = RX_AWAITCR;        // Error .. await <CR>
       Head_error( ERR_BAD_CHAR2 );
       }
   } else if( 'V' == char1 ) {
       if( 'V' == c )            // VV .. send version
       {
       puts( "VER=$Name$\n" );
       } else {
       RX_state = RX_AWAITCR;        // Error .. await <CR>
       Head_error( ERR_BAD_CHAR2 );
       }
       RX_state = RX_AWAITCR;
   } else if( 'X' == char1 ) {        // XX .. Reset
       while(1)
       { }                    // wait here for watchdog reset.
       RX_state = RX_AWAITCR;        // Error .. await <CR>
       Head_error( ERR_BAD_CHAR2 );
   }
   break;

   case RX_AWAITCR:
   if( '\r' == c )
   {
       RX_state = RX_CHAR1;
   }
   break;

   default:                    // invalid state ..  RX_START
   RX_state = RX_START;
   break;
   }
}

static void
TX_handler( void )
{
   // Probably do this by polling.
   // we only send 3..5 characters at a time at present...
}


void interrupt( void )
{
   char mychar;

   //Handle RX interrupt
   if( pir1 & (1<<RCIF) )
   {

   mychar = rcreg;
   if( mychar & 0x80 )
   {
       RX_status = rcsta;
       Bad_char = mychar;
       Head_error_irq( ERR_BAD_CHAR );
       RX_state = RX_AWAITCR;    // Error .. await <CR>
   } else {
       RX_handler( mychar );         // call serial receive handler
   }
   // this is cleared by the read.
   // clear_bit( pir1, RCIF );     // clear RX interrupt bit
   }

   //Handle timer0 interrupt
   if( intcon & (1<<T0IF) )
   {
   // tick();             // call timer 0 handler
   tick++;
   clear_bit( intcon, T0IF );     // clear timer 0 interrupt bit
   tmr0l = T0TIME;            // 100us ticks
   }

   //Handle TX interrupt
   if( pir1 & (1<<TXIF) )
   {
//    TX_handler();            //call serial transmit handler
   clear_bit( pir1, TXIF );     // clear TX interrupt bit
   }

}


void main()
{
   char c;

   osccon = 0x73;        // 8MHz, internal system clock.

   //Configure port A
   trisa = 0x0F;        // LH array ident inputs

   //Configure port B
   trisb = 0x00;        // outputs and ICD port

   //Configure port C
   trisc = 0xCF;        // RH array ident inputs & serial comms

   //Initialize port A
   porta = 0x00;
   adcon1 = 0x0F;
   cmcon  = 0x07;
   //Initialize port B
   //portb = 0x00;
   //Initialize port C
   portc = 0x00;

   t0con = 0xC3;
   tmr0l = T0TIME;

   // initialise some data
   tick = 0;
   tick_100us = 0;
   tick_1ms = 0;
   tick_10ms = 0;
   tick_100ms = 0;
   tick_1s = 0;
   RX_fillidx = 0;
   RX_readidx = 0;
   RX_state  = RX_START;

   uart_init( 1, 8 );        // 57.6kbps at 8MHz

   //Enable interrupts (Peripherals and Timer0)
   pie1 = 0x20;                // RX interrupts
   intcon = 0xE0;                // Global, peripheral and timer0 IRQs.

   intcon2 = 0x84;                // T0 high priority

   //Endless loop
   while( 1 )
   {
   if( tick )
   {
       tick = 0;
       tick_1ms++;
   }

   while( c = get_RX_buf() )
   {
       comms_RX( c );
   }

   if( tick_1ms >= 10 )                // 1ms ticks
   {
       tick_1ms -= 10;
       tick_10ms++;
       stroke_watchdog();
   }
   }
}

--------8<------ Patches to rs232_driver.h ---------

Line 371:
             //delay_us(1);
Line 467:
           //putc(0x0a);    // only send <CR>, not <LF>

--------8<----------------------------------------------

Edited by GordonS

Share this post


Link to post
Share on other sites

Hmmm

 

Actually there's something much more fundamental going on here.

 

Even if I exclude _all_ the code using a #if 0, the problem persists.

 

Right now I can't compile at all.

 

Win2K SP4

Share this post


Link to post
Share on other sites
Hmmm

 

Actually there's something much more fundamental going on here.

 

I've been trying to track down what's happening here, but it seems that V6.60 boostc.pic18.exe will not run properly on my machine from the build or compile buttons, or from the command line. I've reinstalled several times, rebooted once. Nothing. Odd.

 

One other odd symptom that might give a clue. At one point the various build/compile buttons all became greyed out and the only way I could find to get them back was to reinstall.

Share this post


Link to post
Share on other sites

GordonS,

 

Reinstalled V6.55, working. Ignoriung V6.60 for now.

Consider trying V6.70.

 

Regards

Dave

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...