Hi, I am probably doing something wrong, but I can't figure out how to get _GSINIT into the code section. I'm compiling for z80, and using link options: -mz80 --no-std-crt0 --code-loc 0x4100 --data-loc 0x8000
The target z80 based system has existing firmware at 0x0000-3fff. That firmware has provision to call a user app in dataflash at 0x4000-7fff. There is RAM available for this user app at 0x8000-bfff. The system RAM & stack is at 0xC000-ffff. A very simple example is pasted below, including my crt0.s, makefile, and contents of the .map file generated. The problem is that the *code* that inits the variable "x" is landing at 0x8002, in RAM, right after the two bytes reserved by the "int x" at 0x8000. Googling [sdcc gsinit] finds several examples of ".area GSINITx (CODE)", but I just get an undefined symbol error if I use ".area _GSINIT (CODE)" in my crt0.s. Also, the assembler manual doesn't show "CODE" as a valid .area option. I am using SDCC 2.7.0 #4818 (May 31 2007) (MINGW32) on an AMD K7 under win98. Also tried 2.7.3 #4913 (Sep 15 2007) (MINGW32) with same results. Thanks!!! Randy -------------- start of example.c ------------ int x = 1; int main(void) { return x; } -------------- end of example.c ------------ --------------- start of crt0.s --------------------- .module crt0 .globl _main .area _HEADER (ABS) .org 0x4000 call gsinit call _main jp 0x0000 ;; Ordering of segments for the linker. .area _HOME .area _CODE .area _GSINIT .area _GSFINAL .area _DATA .area _BSS .area _HEAP .area _GSINIT gsinit:: .area _GSFINAL ret -------------- end of crt0.s ---------------------------- -------------- start of makefile ---------------------------- # makefile for "example.c" TARGET = example SRC = example.c ASRC = crt0.s CODELOC = 0x4100 DATALOC = 0x8000 ###CC = "G:/Program Files/SDCC/bin/sdcc" ###AS = "G:/Program Files/SDCC/bin/as-z80" # Try latest snapshot. (sdcc-snapshot-i586-mingw32msvc-20070915-4913.zip) CC = "G:/projects/SDCC/snap/sdcc/bin/sdcc" AS = "G:/projects/SDCC/snap/sdcc/bin/as-z80" SHELL = sh REMOVE = rm -f COPY = cp # Define all object files. OBJ = $(SRC:.c=.o) $(ASRC:.s=.o) # Define all listing files. LST = $(SRC:.c=.lst) $(ASRC:.s=.lst) # Default target. all : $(TARGET).hex # Link object files. $(TARGET).hex: $(OBJ) @echo @echo "Linking: $@" $(CC) -mz80 --no-std-crt0 --code-loc $(CODELOC) --data-loc $(DATALOC) $^ -o $@ # Compile: create object files from C source files. %.o : %.c @echo @echo Compiling: $< $(CC) -mz80 -c $< -o $@ # Assemble: create object files from assembler source files. %.o : %.s @echo @echo Assembling: $< $(AS) -ls -o $@ $< # cheat sheet # $@ the target of the rule # $< the first dependency # $^ all the dependencies # Clean up project directory. clean: @echo @echo Cleaning project: $(REMOVE) $(TARGET).hex $(REMOVE) $(TARGET).map $(REMOVE) $(OBJ) $(REMOVE) $(LST) $(REMOVE) $(SRC:.c=.asm) $(REMOVE) $(SRC:.c=.sym) $(REMOVE) $(ASRC:.s=.sym) # coz I'm lazy, do "make clean" & "make all", in one step. clean_all: clean all # Listing of phony targets. .PHONY : all clean clean_all --------------- end of makefile ------------------------------- --------------- start of example.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 0002 l__DATA 0004 l__CODE 000C l__GSINIT 4009 l__HEADER 4100 s__CODE 8000 s__DATA 8002 s__GSINIT <<<<---------------- ******* THIS NEEDS TO GO IN CODE SECTION ******* 8002 s__HOME 8002 s__OVERLAY 800E s__GSFINAL 800F s__BSS 800F s__CABS 800F s__HEAP Hexadecimal Area Addr Size Decimal Bytes (Attributes) -------------------------------- ---- ---- ------- ----- ------------ _CODE 4100 0004 = 4. bytes (REL,CON) Value Global -------- -------------------------------- 4100 _main 4100 _main_start 4104 _main_end Hexadecimal Area Addr Size Decimal Bytes (Attributes) -------------------------------- ---- ---- ------- ----- ------------ _DATA 8000 0002 = 2. bytes (REL,CON) Value Global -------- -------------------------------- 8000 _x Hexadecimal Area Addr Size Decimal Bytes (Attributes) -------------------------------- ---- ---- ------- ----- ------------ _GSINIT 8002 000C = 12. bytes (REL,CON) Value Global -------- -------------------------------- 800E gsinit MODULES FILE example.o NAME example FILE crt0.o NAME crt0 USERBASEDEF _CODE = 0x4100 _DATA = 0x8000 ------------------------ end of example.map----------------------------- ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ Sdcc-user mailing list Sdcc-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sdcc-user