Re: [Fx2lib-devel] Linker Options
Status: Beta
Brought to you by:
mulicheng
From: Steve C. <nos...@ya...> - 2010-01-27 18:51:05
|
--- On Wed, 1/27/10, Dennis Muhlestein <de...@ub...> wrote: > So the 0.2 /lib/fx2.mk is working > quite well for me. It's pretty > customizable in terms of where you link things and is > building all my > firmware's in addition to the sample firmwares in the > fx2lib repo. > > I tried out a different firmware this last week that I > hadn't used for a > while and it took a bit to get it running. I ended up > finding out that > the usb jump table had been overwritten by the device > descriptor. This > specific firmware had a much larger device descriptor than > the other > firmware's I've created and the linker parameters needed to > be > adjusted. To be precise a device descriptor is exactly 18 bytes long. You are referring to all the device's descriptors, including config and strings. >The Makefile lets you do this fine, and > that resolved my > issue, but I'm wondering if anyone knows a way to make it > so there is > some type of warning that this is happening. > > Example: > > -Wl"-b DSCR_AREA=0x3e00" -Wl"-b INT2JT=0x3f00" > > Suppose the descriptor is more than 256 bytes and goes > beyond 0x3f. Any > way to produce some kind of error? > The problem is more generic than that. Is there a way for the linker to fail when two sections (which may be abs sections or not) overlap. Setting the code/data etc sizes "--code-size" does protect against relative code sections from overrunning the boundary, but there is no protection for abs sections. The problem is the FX2 has 2 alignment requirements, the vectors must be on a 256 byte page boundary and the various descriptors - in order to be sent automatically - need to be word aligned. The fx1 does not have the descriptor alignment limitation, so its descriptor can just be defined in regular .c files. One thing that can help is to move the interrupt vectors to low memory, the descriptors after that - which can be tucked tightly after the interrupt vectors (no page alignment issues, just word). And then you can move the starting --code-addr to after the descriptors. This does not eliminate the possible overlap, but does confine it to just one place. I think I remember using something like "--code-loc 0x0200 --code-size 0x1200 --xram-loc 0x1400 --xram-size 0x0030" on the fx2. Then you have from 0 to 200 to use for your alignment fussy code. .area interrupt_area(ABS) .globl __sdcc_gsinit_startup /* * location 0, where the CPU starts execution on a cpu reset */ .org 0x0000 _entry:: ljmp __sdcc_gsinit_startup ; Jump to C entry point /* * External INT 0 starts at location 3 */ _interrupt_table:: hang: ljmp hang /* unexpected isr -- tuck in a hang here - should not happen*/ nop nop nop nop nop ljmp _isrTimer0 nop nop nop nop nop /* * External INT 1 * Hardware requires it to be at .org 0x13 */ ljmp hang nop nop nop nop nop /* * Timer 1 ISR vector */ ljmp _isrTimer1 nop nop nop nop nop /* * Serial port 0 ISR vector */ ljmp hang nop nop nop nop nop /* * Timer 2 ISR vector */ ljmp hang nop nop nop nop nop /* * RESUME ISR vector */ ljmp hang nop nop nop nop nop /* * Serial port 1 ISR vector */ ljmp hang nop nop nop nop nop /* * USB Autovector ISR vector */ ljmp _USB_autovector nop nop nop nop nop /* * I2C Interrupt ISR vector */ ljmp _isri2c nop nop nop nop nop /* * FIFO/GPIF Autovector, or External INT 4 ISR vector */ ljmp _GPIF_autovector nop nop nop nop nop /* * External INT 5 ISR vector */ ljmp hang nop nop nop nop nop /* * External INT 6 ISR vector */ ljmp hang Here there is a gap, if the vectors start at 0x100, so you can add some descriptors here using .even align pseudo ops before each in your asm code. Memory from 0x66 to 0xFF can be used for device, config, string and other descriptors. starting at 0x100 you can define the usb and the gpif autovectors: .org 0x0100 _USB_autovector:: _GPIF_autovector:: ljmp _USBsudav nop ljmp _USBsof nop ...etc... ljmp hang ; GPIF Done nop ljmp hang ; GPIF Waveform nop there is a little free memory in this page - for asm fixed allocation. This routine occupies 0x100 to 0x1b7 for the autovector table, So there is room at 0x1b8 for 0x48 bytes (72 decimal). You could get more if you are not using the gpif autovectors. If no more absolute data is needed you could set the --code-loc 0x0200 to --code-loc 0x01b8 |