Hi Eric,

[email protected] schreef op 2026-08-01 17:51:
Hello Maarten,

From below reply, could you please explain what you mean with:

Since .bndry is not working in the linker I would be careful with this.

During preparation of the original example I examined both the map file as well as the produced binary, and they seem to confirm the desired memory
layout:

C:   00000089  __sdcc_program_startup             main
C:   00000100  _USBINT_AUTOVECTORS                main

00000080: F6 E6 A8 82 20 F5 D9 80 CF 12 01 6F 80 FE #vf(. uY.O..o.~ 00000100: 02 01 71 02 01 75 02 01 79 02 01 7D #..q ..u ..y ..} 00000110: 75 81 08 12 01 81 E5 82 60 03 02 00 89 79 00 E9 #u.....e.`....y.i

Without specifying .bndry 256 this changes to:

C:   00000089  __sdcc_program_startup             main
C:   0000008E  _USBINT_AUTOVECTORS                main

00000080: F6 E6 A8 82 20 F5 D9 80 CF 12 00 FD 80 FE 02 00 #vf(. uY.O..}.~.. 00000090: FF 02 01 03 02 01 07 02 01 0B 75 81 #. ... ... ... u. 000000A0: 08 12 01 0F E5 82 60 03 02 00 89 79 00 E9 44 00 #....e.`....y.iD.

Are you saying the former result is a lucky coincidence, and that the linker
may not produce correct results in other circumstances?

Yes, I am afraid that is exactly what I am saying. Though it is not a complete
coincidence of course since the linker is deterministic.

When you use .bndry in the first file you link you get a good chance that it works as expected. The assembler moves the data to a correct offset in the area segment but the linker may start the segment at a non-boundary multiple located
place.

Kind regards,
Maarten

Eric



-----Original Message-----
From: Maarten Brock <[email protected]>
Sent: Wednesday, 22 July 2026 15:25
To: [email protected]
Subject: Re: [Sdcc-user] Cypress FX2 USB vector "table"

Hello Ian,

[email protected] schreef op 2026-06-29 12:44:
>
> extern void USBINT_AUTOVECTORS(void) __interrupt(8) __naked;

This is a good idea.

> int main(void)

Since main() has nothing to return any value to, make it return void.

> {
> __asm
>   .area HOME (CODE)
>   .bndry 256
> _USBINT_AUTOVECTORS::
>   ljmp _USBINT_SUDAV
>   .ds 1
>   ljmp _USBINT_SOF
>   .ds 1
>   ljmp _USBINT_SUTOK
>   .ds 1
>   ljmp _USBINT_SUSPEND
>   .ds 1
>
>   // And so on...
>
>   .area CSEG (CODE)
> __endasm;
>
>   while (1)
>   {
>   }
> }

Since .bndry is not working in the linker I would be careful with this. Also, don't place this inside main(). Put it in a separate dummy function,
preferably at the end of the file containing main().

static void dummy(void) __naked
{
__asm
     ...
__endasm;
}

Using ljmp instead of the magic number 0x02 is better IMO.

> static volatile uint8_t i = 0;
>
> void USBINT_SUDAV(void) __interrupt
> {
>   i = 0;
> }

This is exactly right: __interrupt with no number.

> void USBINT_SOF(void) __interrupt
> {
>   i = 1;
> }
>
> void USBINT_SUTOK(void) __interrupt
> {
>   i = 2;
> }
>
> void USBINT_SUSPEND(void) __interrupt
> {
>   i = 3;
> }
>
> As compiled and linked with SDCC 4.6.0, this seems to give the desired
> layout in code space.
>
>  Eric
>


_______________________________________________
Sdcc-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to