Sega Genesis Dev Kit (SGDK)
Moderator: Stef
I'm not sure if this was discovered earlier, but I've found a serious bug in this devkit. I'm using version 0.4, with the bundled gcc.
If a global variable is given a negative value at startup, ld gives the following error:
Make exits then.
Code: Select all
/* This code doesn't work, while it should */
int a = -1;
int main()
{
return 0;
}
Code: Select all
ld: address 0x49328 of rom.out section .data is not within region ram
GCC issue. Initialized global variables will never work (either they're hardcoded in the ROM or GCC expects the value to be initialized before main() and it isn't), and for uninitialized ones to work you need to somehow tell the linker to store them in the RAM area (0xFF0000), through no idea if the devkit does this already. Local variables work in the stack so they never have problems.
The only way to get through it would be a specialized compiler :/
The only way to get through it would be a specialized compiler :/
Sik is pronounced as "seek", not as "sick".
It's an issue with all compilers. They expect the values to be initialized before calling main(). Since there's no stub program that does it (the only stub thing used is normally just the header), compilers fail to do the right thing. Which is why I say only a specialized compiler would do, because it would require a compiler that knows about this issue and does the initialization by its own before calling main().
I guess GCC can be modified to support that through, right?
I guess GCC can be modified to support that through, right?
Sik is pronounced as "seek", not as "sick".
-
- Very interested
- Posts: 2443
- Joined: Tue Dec 05, 2006 1:37 pm
- Location: Estonia, Rapla City
- Contact:
somebody write a translator (like BasiEgaXorz - BASIC to ASM)
Mida sa loed ? Nagunii aru ei saa
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen
That's the exact definition of a compiler >_>
I would make a C compiler, but it would be a lot of work and I don't feel like doing so, as well as it would have to be very optimizing, through we could make one in group if you want. But still, modifying GCC is also a good alternative, as we already have the compiler
I would make a C compiler, but it would be a lot of work and I don't feel like doing so, as well as it would have to be very optimizing, through we could make one in group if you want. But still, modifying GCC is also a good alternative, as we already have the compiler
Sik is pronounced as "seek", not as "sick".
-
- Very interested
- Posts: 2443
- Joined: Tue Dec 05, 2006 1:37 pm
- Location: Estonia, Rapla City
- Contact:
Translator and compiler are different... first translates code in one language to another, BEX does BASIC to ASM(which is then assembled to binary), second does code directly to binary.
Mida sa loed ? Nagunii aru ei saa
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen
-
- Very interested
- Posts: 2443
- Joined: Tue Dec 05, 2006 1:37 pm
- Location: Estonia, Rapla City
- Contact:
my QB compiler doesn't generate ASM code... it will make a OBJ, which is a binary, which you'll feed to a Linker which makes that OBJ ready to run in my case in MS-DOS environment...
Mida sa loed ? Nagunii aru ei saa
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen
-
- Very interested
- Posts: 2984
- Joined: Fri Aug 17, 2007 9:33 pm
The problem is that anything with data, be it code or not, MUST go into the ROM. We're not loading a file off a hard drive, after all. So if variables are initialized with a value to start, they HAVE to go into the rom. But they are variables and should go into the RAM. So you'd need to have a way to put the initialized contents into the ROM, then when the ROM is started, copy that to the RAM address used in linking.
And that's what the stub program should do, but there isn't such a program running before main(). Also compilers assume the program will be run from RAM, so anything can be modified. This isn't the case. This is the main reason they fail to work with global variables properly.
Sik is pronounced as "seek", not as "sick".
I did some tests today.Stef wrote:I realised i never replied your last post.
I think the 32 bits modulo operation is buggy, i guess you're doing it on 32 bits sized variable ? I rarely use modulo but i never meet any problem with division. I'll check the 32 bits modulo code in sega.s file, maybe a stupid bug.
I downloaded and setup kit (only changed path where needed) once again to make sure that nothing broken after my previous try. I made only one change in sega.s - replaced line 132 from 'jmp start' to 'jmp main' (I don't use kit libs, like I said).
I made small program which changes palette randomly in loop (to see if program hangs). When I added some test lines in code.
First, I tried unsigned short variable. It have some value on start (i tried different initial values).
If I do operations:
i=(i+1)%10; //hangs
i++;
i%=10; //works
i=(i+1)/10; //hangs too
i++;
i/=10; //works
Then I tried unsigned long variable. Things even worse:
i%=10; //hangs
i/=10; //hangs
I also tried signed int and long, tried to declare variable inside 'main' or as global variable. Results are same.
So, if I did nothing wrong, it means that there is serious problems with kit.