Re: [Tuxnes-devel] Use of mmap ()
Brought to you by:
tmmm
From: Jim U. <ji...@3e...> - 2002-05-14 20:34:40
|
At 02:52pm on 2002 May 14, W. Michael Petullo did write: > Could someone explain what mmap is being used for in emu.c: [...] > Also, in mapper.h things like _RAM point to hard-coded addresses I encountered this a long time ago. (Remember when I said porting was hard?) As far as I remember, these issues are related. tuxnes maps the separate RAM, ROM, etc. arrays into a virtual address space. That's what the MAP_ANON (MAP_ANONYMOUS--see mmap(2)) does. I'm not sure why this is done. Originally I thought it needed the regions to be contiguous, because you'll see references to e.g. ROM_BASE - 0x4000 in mapper.c. However, these always ultimately resolve to addresses greater than ROM_BASE (!) because they must be accessed with offsets greater than the negative offset (0x4000, in this case). My guess is the mmaps may be used to prevent seg faults on out-of-bounds accesses, although it would be an odd way to do it. In tuxnes-dc I converted the ROM and RAM mmaps to use malloc(). Remember to zero out the resulting array or you'll start doing weird things like debugging SMB1 to find out why you always start out on level 5-1. However, since I discarded the dyn-rec I had no use for the CODE_BASE and INT_MAP mmaps. So I know you can successfully use malloc for RAM[] and ROM[] in the interpreted core, but otherwise you're on your own. In conclusion, let me just say good luck. ;) -- 'I came to the 3-day "breatharian" seminar in Hawaii, but without the $300 fee to attend. Wiley asked me: "If you can't find $300, then how do you expect to find God?"' -- breatharian.com ji...@3e... / 0x43340710 / 517B C658 D2CB 260D 3E1F 5ED1 6DB3 FBB9 4334 0710 |