It is currently 20 Oct 2018 10:36

All times are UTC + 1 hour




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: 26 Mar 2018 19:06 
Offline

Joined: 18 Jun 2008 11:43
Posts: 3764
Location: Nieuwpoort, Belgium
Just a question: Does anyone know why the compiler inserts a large 'Goto' table (except the interrupt vectors) in low memory?
I use the 18F67J60 together with mP v7.00.
The goto table is not always there: small programs do not have it. I do not know where the boundary between table or no table lies.

It looks like:

;  LST file generated by mikroListExporter - v.2.0
; Date/Time: 26/03/2018 19:21:27
;----------------------------------------------

;Address Opcode    ASM
0x0000   0xF000EF0E     GOTO        28
0x0004   0x0000         NOP
0x0006   0x0000         NOP
0x0008   0xF000EF6E     GOTO        220
0x000C   0x0000         NOP
0x000E   0x0000         NOP
0x0010   0x0000         NOP
0x0012   0x0000         NOP
0x0014   0x0000         NOP
0x0016   0x0000         NOP
0x0018   0xD7F3         BRA         0
0x001C   0xF0C7EFF3     GOTO        102374
0x0020   0xF0B0EF05     GOTO        90122
0x0024   0xF0A7EF88     GOTO        85776
0x0028   0xF0A7EF67     GOTO        85710
0x002C   0xF0B7EF0C     GOTO        93720
0x0030   0xF0B6EFCB     GOTO        93590
0x0034   0xF0B6EFAF     GOTO        93534
0x0038   0xF09BEF0E     GOTO        79388
0x003C   0xF099EFAE     GOTO        78684
0x0040   0xF099EF66     GOTO        78540
0x0044   0xF0A1EF14     GOTO        82472
0x0048   0xF0A0EFC6     GOTO        82316
0x004C   0xF09BEF3C     GOTO        79480
0x0050   0xF0BAEFEC     GOTO        95704
0x0054   0xF0B9EF49     GOTO        94866
0x0058   0xF0B8EFC6     GOTO        94604
0x005C   0xF0C6EFDC     GOTO        101816
0x0060   0xF0C6EFD3     GOTO        101798
0x0064   0xF0C6EFCA     GOTO        101780
0x0068   0xF0B7EFE8     GOTO        94160
0x006C   0xF0B7EF73     GOTO        93926
0x0070   0xF0B7EF4B     GOTO        93846
0x0074   0xF0B8EF58     GOTO        94384
0x0078   0xF0B8EF34     GOTO        94312
0x007C   0xF0B8EF2B     GOTO        94294
0x0080   0xF092EF95     GOTO        75050
0x0084   0xF093EF4C     GOTO        75416
0x0088   0xF093EFFE     GOTO        75772
0x008C   0xF08EEF32     GOTO        72804
0x0090   0xF08FEFDE     GOTO        73660
0x0094   0xF090EF01     GOTO        73730
0x0098   0xF094EFD1     GOTO        76194
0x009C   0xF097EF88     GOTO        77584
0x00A0   0xF098EF06     GOTO        77836
0x00A4   0xF099EF52     GOTO        78500
0x00A8   0xF094EFEE     GOTO        76252
0x00AC   0xF095EF68     GOTO        76496
0x00B0   0xF097EF30     GOTO        77408
0x00B4   0xF08CEFFD     GOTO        72186
0x00B8   0xF081EF52     GOTO        66212
0x00BC   0xF084EF15     GOTO        67626
0x00C0   0xF086EF68     GOTO        68816
0x00C4   0xF08CEFC7     GOTO        72078
0x00C8   0xF08CEFE5     GOTO        72138
0x00CC   0xF08CEFED     GOTO        72154
0x00D0   0xF087EF68     GOTO        69328
0x00D4   0xF087EF7B     GOTO        69366
0x00D8   0xF088EF48     GOTO        69776
0x00DC   0xF0C6EFE5     GOTO        101834
_main:
;.....mpas,2517 ::       begin
;.....mpas,2519 ::       HW_Init_1;
0x18FE6   0xF000EC20     CALL        _HW_Init_1, 0
....
....
_interrupt:
;.....mpas,389 ::               begin
0x18DCA   0xF018C000     MOVFF       R0, 24
0x18DCE   0xF017C001     MOVFF       R1, 23
....


The Goto addresses are simply addresses of routines (own units or mE libraries as far as I can see).
The addresses where the goto instructions are are never jumped to (except the first one which is main_ and the last one, that is apparently an interrupt vector).

Thanks in advance!

_________________
Kind regards, Dany.
There is a crack in everything, that's how the light gets in... (L. Cohen)


Last edited by Dany on 20 Apr 2018 15:01, edited 1 time in total.

Top
 Profile  
 
PostPosted: 27 Mar 2018 01:06 
Offline

Joined: 18 Feb 2006 13:17
Posts: 4983
Hi Dany,

The GOTO table appears only for processors with code memory larger than 64k because function pointers are implemented with 16-bit wide address field and thus cannot address functions above the 64k limit. The table always starts at 0x1C and expands upwards (an idea that the table could be easily offset to some other location within the first 64k block didn't get mE's approval, unfortunately).

Quote:
The addresses where the goto instructions are are never jumped to...
The list of jumps should contain only jumps to routines that are called in code with help of function pointers (and thus the jump is done through PCL registers within internal ____DoIFC function). In other words, you won't find GOTO or CALL instructions directed at the table jumps.

_________________
Replacement libraries for mP PRO and PIC18 processors, mP PRO tips & trics


Top
 Profile  
 
PostPosted: 27 Mar 2018 12:15 
Offline

Joined: 18 Jun 2008 11:43
Posts: 3764
Location: Nieuwpoort, Belgium
Hi Janni, thanks for your answer, somehow I knew the only answer would come from you... :D

I suppose the table is also only needed for routine calls rom the one 64Kb Flash to the other one? Otherwise also a bootloader for the 18F67J60 I wrote (residing in high flash memory) would have also that Goto table. Fortunately it has not... otherwise it would of course conflict with that of the actual main program.

This is the start of the bootloader (starts at $1F400):
;  LST file generated by mikroListExporter - v.2.0
; Date/Time: 23/03/2018 16:15:12
;----------------------------------------------

;Address Opcode    ASM
0x0000   0xF0FAEF00     GOTO        128000
0x0004   0x0000         NOP
0x0006   0x0000         NOP
0x0008   0xF000EF00     GOTO        0
0x000C   0x0000         NOP
0x000E   0x0000         NOP
0x0010   0x0000         NOP
0x0012   0x0000         NOP
0x0014   0x0000         NOP
0x0016   0x0000         NOP
0x0018   0xD7F3         BRA         0
_main:
;P18F67J60_Bootloader.mpas,161 ::       begin
;P18F67J60_Bootloader.mpas,166 ::       OSCTUNE:= %01000000;                 // 41.666667 MHz, da HS_OSC + PLL.
0x1F400   0x0E40         MOVLW       64
0x1F402   0x6E9B         MOVWF       OSCTUNE
...

_________________
Kind regards, Dany.
There is a crack in everything, that's how the light gets in... (L. Cohen)


Last edited by Dany on 07 Apr 2018 11:23, edited 1 time in total.

Top
 Profile  
 
PostPosted: 27 Mar 2018 13:03 
Offline

Joined: 18 Feb 2006 13:17
Posts: 4983
Dany wrote:
I suppose the table is also only needed for routine calls rom the one 64Kb Flash to the other one?
Existence of this table is caused only by compiler limitation (16-bit address stored in function pointer). It does not matter from where the function pointer mediated call is executed, only that the 'called' routine is placed above the 64k limit. Regular calls (or jumps) do not require any tables as CALL (or GOTO) instruction may access up to 2Mbytes of program memory.
Just don't use function pointers in your bootloader and it won't generate the GOTO table.

The sad thing is that the GOTO table could be easily avoided - the other 16-bit part of function pointer contains RAM address of function parameter list and only 12 bits of that part are used. It would not require many changes to store and use full address of called function in function pointer :( .

_________________
Replacement libraries for mP PRO and PIC18 processors, mP PRO tips & trics


Top
 Profile  
 
PostPosted: 27 Mar 2018 18:07 
Offline

Joined: 18 Jun 2008 11:43
Posts: 3764
Location: Nieuwpoort, Belgium
janni wrote:
Just don't use function pointers in your bootloader and it won't generate the GOTO table.
The sad thing is that the GOTO table could be easily avoided - the other 16-bit part of function pointer contains RAM address of function parameter list and only 12 bits of that part are used. It would not require many changes to store and use full address of called function in function pointer :( .

Thanks Janni. All is clear now... :D

_________________
Kind regards, Dany.
There is a crack in everything, that's how the light gets in... (L. Cohen)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: