GP2X How Does A Compiler Handle Memory?


goobers

Member
Joined
Jan 22, 2007
Messages
344
Location
The UK
Website
Visit site
I know this isn't exactly a GP2X relevant question, but I feel that this is probably the best place to ask. Sorry if it would be better placed in Off Topic, but I feel that the people likely to be able to answer my question would see it here.

What I want to know is how a compiler would handle memory addressing. The reason I ask this is because I am about to build a Z80 based single board computer and am wondering about the possibility of a C compiler. I know that there are C compilers for a Z80, but I am confused as to how this would work with the differing memory locations.

The Z80 I am looking at using can address 1MB of memory, and I am planning on having 512k rom and 512k ram. How exactly would I be able to adjust a compiler to work with this memory arrangement?

Have I got the wrong end of the stick completely and the Operating System handles memory management when the code is executed?

Thanks for your help, and I hope my question isn't too stupid. I am building it in an effort to better understand the workings of computers, and for no real practical purpose. Best way eh?

Cheers
 
The compiler normally does very little in regards to memory usage; it's the linker that decides what code goes where and how to allocate space for variables/etc. GCC for example has a linker specification file that tells it what goes where when you are writing code for the gp32 (and gp2x when not using Linux). When compiling code for Windows and Linux, the executable file format used by those OS's actually states how much memory they require and the OS allocates that memory. The linkers job is made easier by the fact that all programs have there own memory map in those OS's (although there is a complicated loader "relocator" which can alter addresses used in the program)

For the simple system you are going to create, you'll have to do is write a linker script to match your hardware configuration, and then write some startup code for C programs that copy any initialised variables to ram on startup (and clear any uninitialised variables). Don't worry about the complicated loader stuff, as you'll only ever have one program running at once anyway.
 
Cool, the more I learn about this stuff, the more I want to do! I've got some ideas already for graphic hardware with a coprocessor and double buffering, but I think I'm getting a bit too ahead of myself ;) I think the first call will be getting a minimal system going hooked up to a character LCD display :)

Thanks for the help :) If anybody else has anything to add, feel free

EDIT:

http://www.z88dk.org/ this compiler looks promising.
 
You ought to get in touch with Orkie, he's building a Z80 computer too! I will someday as well, it's always been a dream of mine. Good luck!
 
I may do just that! (all of this stuff is frying my brain at the moment- I'm trying to find the right bits in the linker to do what I want to do. The best I've come up with so far is being able to set the origin. I'm not sure if this compiler will even support the amount of memory that the Z80 I want to use can address anyway... :/)
 
Back
Top