#9601 - regularkid - Sun Aug 10, 2003 3:39 am
Hi. I've got a problem with compiling code into THUMB / ARM. I'm not very familiar with how the compiler really works and I've read the docs and FAQ at devrs but still can't seem to figure some things out. Any help would be great!
So, I'm mixing C code and ASM code and want to make sure that everything gets compiled to the right format / place in memory. I have been looking at my memory map that gets outputted from the compiler and it seems that code and constants are being placed into ROM (0x08000000 and up). This is cool, becuase it is where I want it to go. However, I want to make sure that it is compiling into THUMB code since it wouldn't be very smart to put ARM code into ROM seeing how it is 16bit memory and ARM opcodes are 32bit. Here is my makefile:
Now, how would I make sure that the .c files get compiled into THUMB code instead of ARM. By the way, the linkscript file is just a generic one that I downloaded from the FAQ on devrs.
Next, here is the basic setup for all my ASM files:
Then I have the function prototypes in the .h files so that these asm functions can be called from .c code. However, the problem I have here is that when I look at the code in my emulator's disassembler I can see the opcodes are duplicated twice in each 32bits instead of just having the one 16 bit opcode, so it comes up as "<Undefined Opcode>" in the disassembler. However, when I use .ARM code, it works fine (but I obviously want to use THUMB code because it will be faster in ROM).
Basically, I am just really confused as to how most of this stuff works, so if anyone could help me out in any way I would really appreciate it. Thanks!
_________________
- RegularKid
So, I'm mixing C code and ASM code and want to make sure that everything gets compiled to the right format / place in memory. I have been looking at my memory map that gets outputted from the compiler and it seems that code and constants are being placed into ROM (0x08000000 and up). This is cool, becuase it is where I want it to go. However, I want to make sure that it is compiling into THUMB code since it wouldn't be very smart to put ARM code into ROM seeing how it is 16bit memory and ARM opcodes are 32bit. Here is my makefile:
Code: |
CC = gcc -mthumb-interwork AS = as -mthumb-interwork GCCARM = C:\DevKitAdv\bin INCDIR = C:\DevKitAdv\include LIBDIR = C:\DevKitAdv\lib GAME = Game CFILES = Debug.c \ Dma.c \ Input.c \ Irq.c \ Level.c \ Main.c \ Math.c \ Render.c \ Sprite.c \ Timer.c \ Video.c \ SFILES = Video.S \ Render.S \ OBJS = $(CFILES:.c=.o) \ $(SFILES:.S=_ASM.o) \ ASFLAGS = CFLAGS = -c -Wall LFLAGS = -TLinkscript -Wl,-Map,Memory_map ############################################################## ## RULES ############################################################## Code : $(GAME).bin @ECHO @ECHO CODE BUILD COMPLETE! $(GAME).bin : $(GAME).elf @ECHO @ECHO ---------------------------- @ECHO Making Game binary... @objcopy -O binary $(GAME).elf $(GAME).bin $(GAME).elf : $(OBJS) @ECHO Linking... @$(CC) $(LFLAGS) -o $(GAME).elf $(OBJS) -lc -lgcc -lm %.o : %.c @ECHO Compiling $<... @$(CC) $(CFLAGS) $< -o $@ clean : @ECHO Cleaning files... @rm -f *.o ############################################################## ## DEPENDENCIES ############################################################## include C:\Game\Dependencies\Debug.dpn include C:\Game\Dependencies\Input.dpn include C:\Game\Dependencies\Main.dpn include C:\Game\Dependencies\Video.dpn include C:\Game\Dependencies\Timer.dpn include C:\Game\Dependencies\Dma.dpn include C:\Game\Dependencies\Level.dpn include C:\Game\Dependencies\Math.dpn include C:\Game\Dependencies\Sprite.dpn include C:\Game\Dependencies\Irq.dpn include C:\Game\Dependencies\Render.dpn Video_ASM.o : Video.S @ECHO Assembling Video.S... @$(AS) $(ASFLAGS) Video.S -o Video_ASM.o Render_ASM.o : Render.S @ECHO Assembling Render.S... @$(AS) $(ASFLAGS) Render.S -o Render_ASM.o |
Now, how would I make sure that the .c files get compiled into THUMB code instead of ARM. By the way, the linkscript file is just a generic one that I downloaded from the FAQ on devrs.
Next, here is the basic setup for all my ASM files:
Code: |
.THUMB .ALIGN 2 .THUMB_FUNC .GLOBAL myFunc myFunc: [... code] bx lr |
Then I have the function prototypes in the .h files so that these asm functions can be called from .c code. However, the problem I have here is that when I look at the code in my emulator's disassembler I can see the opcodes are duplicated twice in each 32bits instead of just having the one 16 bit opcode, so it comes up as "<Undefined Opcode>" in the disassembler. However, when I use .ARM code, it works fine (but I obviously want to use THUMB code because it will be faster in ROM).
Basically, I am just really confused as to how most of this stuff works, so if anyone could help me out in any way I would really appreciate it. Thanks!
_________________
- RegularKid