Joakim Carlsson - 2010-08-22

Hi,

I'm trying to use the SDCC together with MPLAB using the module found here http://lne.byexamples.com/?p=21 and a small wrapper I wrote to put the linker output the way gplink wants it.

The problem I'm having is that after assembling my program, MPLAB won't run my main() method first. After looking through the generated assembly code I can't find anything telling the program which method to start with and it seems the label _main and occuring first of all methods is not enough. I'll post the program below along with most of its generated assembly code:

#define __18F2680
#include "pic18f2680.h"
int test;
void main(void)
{
    test = 0;
}
void fun1()
{
}
void fun2(int hej)
{
}
int fun3()
{
    return 0;
}

;--------------------------------------------------------
; File Created by SDCC : free open source ANSI-C Compiler
; Version 2.9.7 #5938 (Aug 21 2010) (MINGW32)
; This file was generated Sun Aug 22 12:44:16 2010
;--------------------------------------------------------
; PIC16 port for the Microchip 16-bit core micros
;--------------------------------------------------------
    list    p=18f2680
    radix dec
;--------------------------------------------------------
; public variables in this module
;--------------------------------------------------------
    global _test
    global _fun1
    global _fun2
    global _fun3
    global _main
;--------------------------------------------------------
; extern variables in this module
;--------------------------------------------------------
    extern _RXF6SIDHbits
;   ... lots and lots of extern declarations ...
;--------------------------------------------------------
;   Equates to used internal registers
;--------------------------------------------------------
WREG    equ 0xfe8
FSR1L   equ 0xfe1
FSR2L   equ 0xfd9
POSTDEC1    equ 0xfe5
PREINC1 equ 0xfe4
PRODL   equ 0xff3
udata_program_0 udata
_test   res 2
;--------------------------------------------------------
; interrupt vector 
;--------------------------------------------------------
;--------------------------------------------------------
; global & static initialisations
;--------------------------------------------------------
; I code from now on!
; ; Starting pCode block
S_program__main code
_main:
    BANKSEL _test
;   .line   13; program.c   test = 0;
    CLRF    _test, B
    BANKSEL (_test + 1)
    CLRF    (_test + 1), B
    RETURN  
; ; Starting pCode block
S_program__fun3 code
_fun3:
;   .line   24; program.c   int fun3()
    MOVFF   FSR2L, POSTDEC1
    MOVFF   FSR1L, FSR2L
;   .line   26; program.c   return 0;
    CLRF    PRODL
    CLRF    WREG
    MOVFF   PREINC1, FSR2L
    RETURN  
; ; Starting pCode block
S_program__fun2 code
_fun2:
;   .line   20; program.c   void fun2(int hej)
    MOVFF   FSR2L, POSTDEC1
    MOVFF   FSR1L, FSR2L
;   .line   22; program.c   }
    MOVFF   PREINC1, FSR2L
    RETURN  
; ; Starting pCode block
S_program__fun1 code
_fun1:
;   .line   16; program.c   void fun1()
    MOVFF   FSR2L, POSTDEC1
    MOVFF   FSR1L, FSR2L
;   .line   18; program.c   }
    MOVFF   PREINC1, FSR2L
    RETURN  
; Statistics:
; code size:       56 (0x0038) bytes ( 0.04%)
;                  28 (0x001c) words
; udata size:       2 (0x0002) bytes ( 0.05%)
; access size:      0 (0x0000) bytes
    end

MPLAB is hell bent on starting at fun3() for whatever reason. Moving around the main() method in the c program file does not seem to affect this.

I have managed to get things going using SDCC with the 16F series so I'm thinking this has to have something to do with either the 18F compilation or the 18F interpretation. Or that I simply missed some simple setting.