#18123 - ProblemBaby - Sun Mar 21, 2004 2:11 am
what is crt0.s?
why do people use it?
#18130 - poslundc - Sun Mar 21, 2004 4:48 am
ProblemBaby wrote: |
what is crt0.s?
why do people use it? |
Because your game wouldn't get very far without it...
crt0.S takes care of all of the necessary loading of your game's data, when you load a GBA program, and then starts the program for you. It also includes a free interrupt handler you can enable by going in and uncommenting a line.
Try looking at the file. You don't need to be an assembly programmer to understand most of it.
Dan.
#18131 - dagamer34 - Sun Mar 21, 2004 5:10 am
Questions like these are easily answered on the #gbadev channel because the response time is a lot quicker. No need to wait.
www.mirc.com/
_________________
Little kids and Playstation 2's don't mix. :(
#18134 - sajiimori - Sun Mar 21, 2004 6:39 am
eeew irc
#18135 - ProblemBaby - Sun Mar 21, 2004 2:21 pm
what do you mean by take care??
how do I add it to my project?
gcc -o test.elf test.c crt0.s -lm
this doesn't work
#18136 - poslundc - Sun Mar 21, 2004 2:37 pm
Well, for one...
... do you have crt0.s or crt0.S? GCC is case-sensitive.
Dan.
#18138 - yaustar - Sun Mar 21, 2004 2:48 pm
I found 3 crt0.s in my DevKitAdvance folder, which on do I edit and which line needs to be commented?
edit: ignore this, I found crt0.o :/
_________________
[Blog] [Portfolio]
#18139 - ProblemBaby - Sun Mar 21, 2004 7:33 pm
I dont understand why you use it!
and I dont understand how to use it
why just dont skip it??
can anyone tell me the actual reason to use it or give me a link to a page that describes it!
#18143 - yaustar - Sun Mar 21, 2004 8:14 pm
Using batch files, how would you include it?
_________________
[Blog] [Portfolio]
#18146 - poslundc - Sun Mar 21, 2004 9:05 pm
ProblemBaby wrote: |
I dont understand why you use it! |
Me, earlier wrote: |
crt0.S takes care of all of the necessary loading of your game's data, when you load a GBA program, and then starts the program for you. |
What part didn't you understand?
Quote: |
and I dont understand how to use it
why just dont skip it?? |
If you're able to compile and run GBA programs without explicitly mentioning it then you've probably got your devkit environment configured in such a way that it is loaded automatically.
Without the crt0 output file (or something equivalent to it), your game would not run.
Dan.
#18148 - Lupin - Sun Mar 21, 2004 9:19 pm
it explicitly puts the CPU into a special state (USR mode), i don't really know why it does that, but it seems to be important. It also sets up your stack pointer and it's branching to the actual code. It is managing the nintendo logo data space as well (i think it's kinda hard to put the logo data into your C code).
Just accept that you have to use it, if you don't use it your DevKit will most likely use a standard one for you.
I am not sure, but i think that it is also copying the parts of your ROM that should go to IWRAM/EWRAM to their right location.
I also think that doing this stuff in C is not possible because you would have to use the "Coprocessor" instruction MSR which you can't access from C (i put Coprocessor in " because the GBA doesn't really have a Coprocessor i think...)
As you might have noticed my knowledge about this stuff is not so clear :)
_________________
Team Pokeme
My blog and PM ASM tutorials
#18152 - Lupin - Sun Mar 21, 2004 9:36 pm
I am now cycling through my crt0.s and trying to understand what it does. It seems like depending on the mode the CPU is in the r13 register will have another purpose, this means that if we go to IRQ mode (which is for interrupt handling i would guess) we set up a stack pointer that will only used within or when calling interrupts.
I was right with the copy from ROM to RAM, it seems like the RAM data is placed right behind the ROM by the linker. But i am still wondering why my crt0.s file is only copying IWRAM data but not EWRAM...
Well, maybe you now have more information as you want, but it's very interesting for me to actually take a look at the crt0 file :)
_________________
Team Pokeme
My blog and PM ASM tutorials
#18153 - poslundc - Sun Mar 21, 2004 10:03 pm
Lupin wrote: |
I am now cycling through my crt0.s and trying to understand what it does. |
I think that Devkit Advance comes with a crt0.S (that's with a capitalized "S" instead of lowercase "s" at the end). It is very well-commented and explains what almost every line is for.
Dan.
#18154 - ProblemBaby - Sun Mar 21, 2004 10:28 pm
thanks!
I've seen people who dont use the standard crt0-file that don't follows with devkitadv how do I use my own
how do i add it to the compilation?
now i've a batch file that look like this:
path="C:\devkitadv\bin"
gcc -o test.elf test.c -lm
objcopy -O binary test.elf test.bin
#18156 - DekuTree64 - Sun Mar 21, 2004 10:45 pm
Yeah, it's not so bad when you actually read through it.
All that's really necessary is the header data and stack initialization (just for the record, games normally run in system mode, not user, although they do use the same stack register. Also, msr/mrs are for status registers, mrc/mcr are for coprocessors), the rest is just copying in the I/EWRAM section data and interrupt handling.
One of these days I'm going to have some fun and write a pure ASM demo so I can play with cutting down the Crt0 to exactly what I need, and so I can play with those FIQ regs that I'm always jabbering about. Not sure exactly what I'd use them for, but it sure would be fun^_^
And ProblemBaby, I'm not sure, but I think you'll have to compile your files to .o files and then link them with ld. That's the normal way of doing it anyway, so you might as well learn how. I've always used makefiles with MSVC++'s NMAKE, so I may be wrong on this, but I think all you have to do is like
gcc -o Crt0.o Crt0.S
gcc -o file.o file.c
ld -T lnkscript -o game.elf Crt0.o file.o
objcopy -O binary game.elf game.bin
lnkscript comes with the Crt0 from www.devrs.com, if you don't have it already.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku
#18157 - ProblemBaby - Sun Mar 21, 2004 11:12 pm
Quote: |
I've always used makefiles with MSVC++'s NMAKE |
how?
in VS.NET
#18168 - DekuTree64 - Mon Mar 22, 2004 3:46 am
Nope, mine's MSVC++ 6.0. Basically you create a makefile project, set the command line to
nmake /f "file.mak"
And you're done. Of course, you need to have a makefile to do that. Here's what mine is like
Code: |
PATH=c:\devkitadv\bin;%PATH%
NAME = Rpg
CARMFLAGS = -c -g -O1 -marm -mthumb-interwork -Wall -ffreestanding
CTHUMBFLAGS = -c -g -O1 -mthumb -mthumb-interwork -Wall -ffreestanding
ASFLAGS = -mthumb-interwork
LDFLAGS = -T lnkscript -Map $(NAME).map
all : $(NAME).bin
$(NAME).bin : $(NAME).elf
objcopy -v -O binary $(NAME).elf $(NAME).bin
$(NAME).elf : crt0.o main.o
ld $(LDFLAGS) -o $(NAME).elf crt0.o main.o
crt0.o : crt0.s
as $(ASFLAGS) crt0.s -o crt0.o
main.o : main.c
gcc $(CTHUMBFLAGS) main.c
|
I'm not sure how correct it is, I haven't messed with making it any different since I first started out in GBA coding. Never had any reason to, since it works perfectly fine.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku