Hi, When I use my custom crt0, in the final binary, gsinit: is pointing to GSFINAL instead of GSINIT. Therefore, global variables do not get initialised. Also, GSINIT is placed into DATA which seems to be wrong. Finally, since my device only has RAM and not ROM, I don't think I need separate CODE and DATA areas - all variables can be stored in CODE like consts are. Is there some way to tell the compiler to do that?
Here is my custom crt0: ;; crt0 for Actions chips. ;; Based on SDCC's z80 crt0 ;; Modified by Alistair Buxton <a.j.bux...@gmail.com> ;; Generic crt0.s for a Z80 .module crt0 .globl _main .area _HEADER (ABS) ;; Reset vector .org 0 jp init ;; Vector used by firmware reloader .org 0x10 di xor a out (0x4e), a ld hl,#0x4000 ld de,#0x0000 ld bc,#0x4000 ldir jp init ;; -------------------------------------------------- ;; INT Vector 0x38 ;; -------------------------------------------------- .org 0x38 jp int_ret int_ret: reti ;; -------------------------------------------------- ;; NMI Vector 0x66 ;; -------------------------------------------------- .org 0x66 jp nmi_ret nmi_ret: retn .org 0x100 ; normal org ;.org 0xC00 ; leave room to copy in ADFU mode init: di ; disable interrupts ld a, #0 ; and watchdog out (0x4e), a ;; Stack at the top of zram1. ld sp,#0x3fff ;; Initialise global variables call gsinit call _main jp _exit ;; Ordering of segments for the linker. .area _HOME .area _CODE .area _GSINIT .area _GSFINAL .area _DATA .area _BSS .area _HEAP .area _CODE __clock:: ld a,#2 rst 0x08 ret _exit:: ;; Exit - special code to the emulator ld a,#0 rst 0x08 1$: halt jr 1$ nop .area _GSINIT gsinit:: .area _GSFINAL ret Here is the resulting .map: Hexadecimal Area Addr Size Decimal Bytes (Attributes) -------------------------------- ---- ---- ------- ----- ------------ . .ABS. 0000 0000 = 0. bytes (ABS,CON) Value Global -------- -------------------------------- 0000 l__BSS 0000 l__CABS 0000 l__HEAP 0000 l__HOME 0000 l__OVERLAY 0000 s__HEADER 0001 l__GSFINAL 0013 l__DATA 0060 l__GSINIT 0111 l__HEADER 0200 s__CODE 0D52 l__CODE 3100 s__DATA 3113 s__GSINIT 3113 s__HOME 3113 s__OVERLAY 3173 s__GSFINAL 3174 s__BSS 3174 s__CABS 3174 s__HEAP Hexadecimal Area Addr Size Decimal Bytes (Attributes) -------------------------------- ---- ---- ------- ----- ------------ _CODE 0200 0D52 = 3410. bytes (REL,CON) Value Global -------- -------------------------------- 0200 _int_handler 0200 _int_handler_start 0245 _int_handler_end 0245 _main 0245 _main_start 02D2 _main_end 02DD _lcd_draw_mode 02DD _lcd_draw_mode_start 02E9 _lcd_draw_mode_end 0529 _lcd_command_mode 0529 _lcd_command_mode_start 0538 _lcd_command 0538 _lcd_command_mode_end 0538 _lcd_command_start 0550 _lcd_command_end 0550 _lcd_set_page 0550 _lcd_set_page_start 056C _lcd_set_col 056C _lcd_set_col_start 056C _lcd_set_page_end 059C _lcd_draw 059C _lcd_draw_start 059C _lcd_set_col_end 05B4 _lcd_cls 05B4 _lcd_cls_start 05B4 _lcd_draw_end 05EA _lcd_cls_end 05EA _lcd_test_char 05EA _lcd_test_char_start 0673 _lcd_test_char_end 0673 _lcd_write_string 0673 _lcd_write_string_start 0743 _lcd_write_char 0743 _lcd_write_char_start 0743 _lcd_write_string_end 07EF _lcd_write_char_end 07EF _lcd_write_hex 07EF _lcd_write_hex_start 081A _lcd_write_byte 081A _lcd_write_byte_start 081A _lcd_write_hex_end 0845 _delay 0845 _delay_start 0845 _lcd_write_byte_end 0886 _delay_end 08C0 _usb_reset 08C0 _usb_reset_start 0921 _usb_check_length 0921 _usb_check_length_start 0921 _usb_reset_end 0955 _usb_check_length_end 0955 _usb_wait_ep_br 0955 _usb_wait_ep_br_start 0991 _usb_setup_epi 0991 _usb_setup_epi_start 0991 _usb_wait_ep_br_end 09CB _usb_read 09CB _usb_read_start 09CB _usb_setup_epi_end 0A05 _usb_read_end 0A05 _usb_write 0A05 _usb_write_start 0A5D _usb_reenumerate 0A5D _usb_reenumerate_start 0A5D _usb_write_end 0A6E _usb_reenumerate_end 0A6E _usb_unsetup 0A6E _usb_unsetup_start 0A85 _usb_setup 0A85 _usb_setup_start 0A85 _usb_unsetup_end 0F47 __clock 0F47 _usb_setup_end 0F4B _exit Hexadecimal Area Addr Size Decimal Bytes (Attributes) -------------------------------- ---- ---- ------- ----- ------------ _DATA 3100 0013 = 19. bytes (REL,CON) Value Global -------- -------------------------------- 3107 _porttmp Hexadecimal Area Addr Size Decimal Bytes (Attributes) -------------------------------- ---- ---- ------- ----- ------------ _GSINIT 3113 0060 = 96. bytes (REL,CON) Value Global -------- -------------------------------- 3173 gsinit MODULES FILE test.o NAME test FILE gfx.o NAME gfx FILE usb.o NAME usb FILE crt0.o NAME crt0 USERBASEDEF _CODE = 0x0200 _DATA = 0x3100 Thanks, -- Alistair Buxton a.j.bux...@gmail.com ------------------------------------------------------------------------------ Enter the BlackBerry Developer Challenge This is your chance to win up to $100,000 in prizes! For a limited time, vendors submitting new applications to BlackBerry App World(TM) will have the opportunity to enter the BlackBerry Developer Challenge. See full prize details at: http://p.sf.net/sfu/blackberry _______________________________________________ Sdcc-user mailing list Sdcc-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sdcc-user