d82db97703
- Use "stdlib.h" to get prototype for alloca() under NetBSD. - Remove bogus "extern" declaration for a variable which is declared "static" later. - Fix bad lvalue constructs.
88 lines
2.5 KiB
Text
88 lines
2.5 KiB
Text
$NetBSD: patch-ac,v 1.2 2006/06/30 22:14:49 tron Exp $
|
|
|
|
--- mc68k/memory.c.orig 1998-08-25 05:52:56.000000000 +0100
|
|
+++ mc68k/memory.c 2006-06-30 23:09:38.000000000 +0100
|
|
@@ -346,9 +346,11 @@
|
|
0xff, 0xff, 0x00 };
|
|
|
|
const unsigned char *bootsign = _bootsign, *bootmask = _bootmask;
|
|
-
|
|
+ char *p;
|
|
+
|
|
+ p = (const char *)rom;
|
|
while ((*bootsign & *bootmask) == *bootsign)
|
|
- if ((*((char *)rom)++ & *bootmask++) != *bootsign++)
|
|
+ if ((*p++ & *bootmask++) != *bootsign++)
|
|
return 0;
|
|
|
|
return 1;
|
|
@@ -377,6 +379,7 @@
|
|
int i;
|
|
char *rombuf;
|
|
char *resetv;
|
|
+ void *tmpmemory;
|
|
int f;
|
|
struct stat st;
|
|
|
|
@@ -405,12 +408,24 @@
|
|
rom_size = pow_of_2;
|
|
}
|
|
|
|
- rommemory = (UWORD*)mmap(0, rom_size, PROT_READ|PROT_WRITE,
|
|
- MAP_FILE|MAP_PRIVATE, f, 0);
|
|
- if (rommemory == (UWORD *)-1) {
|
|
+ /* mmap'ing a larger region than the underlying object does not work.
|
|
+ * Instead, mmap the actual object and copy into a power-of-two sized
|
|
+ * buffer.
|
|
+ */
|
|
+ tmpmemory = mmap(0, st.st_size, PROT_READ|PROT_WRITE,
|
|
+ MAP_FILE|MAP_PRIVATE, f, 0);
|
|
+ if (tmpmemory == (void *)-1) {
|
|
return PILOTCPU_ERROR_LOADING_ROM;
|
|
}
|
|
-
|
|
+
|
|
+ /* We want the end of the buffer to be zero-filled */
|
|
+ rommemory = (UWORD *) calloc(1, rom_size);
|
|
+ if (rommemory == 0) {
|
|
+ return PILOTCPU_ERROR_LOADING_ROM;
|
|
+ }
|
|
+ memcpy(rommemory, tmpmemory, st.st_size);
|
|
+ munmap(tmpmemory, st.st_size);
|
|
+
|
|
if (!nocheck) {
|
|
/* Check if the reset vector looks plausible */
|
|
resetv = (char *)rommemory +
|
|
@@ -430,23 +445,15 @@
|
|
offset = resetv - find_entrypoint((char *)rommemory);
|
|
}
|
|
|
|
- /* Did we find it? If not, lets go with the original. */
|
|
- if ((char *)offset != resetv) {
|
|
- /* It may not always be page aligned... */
|
|
- pageoffset = ((offset-1) & ~(getpagesize() - 1)) + getpagesize();
|
|
-
|
|
- if ((st.st_size + offset) > rom_size)
|
|
- rom_size <<= 1;
|
|
-
|
|
- rommemory = (UWORD *)mmap((void*)(rommemory + pageoffset),
|
|
- rom_size - pageoffset,
|
|
- PROT_READ | PROT_WRITE,
|
|
- MAP_FILE | MAP_PRIVATE | MAP_FIXED, f, 0);
|
|
- if (rommemory == (UWORD *)-1)
|
|
- return PILOTCPU_ERROR_LOADING_ROM;
|
|
-
|
|
- memcpy(((char *)rommemory) - offset, rommemory, 256);
|
|
- ((char *)rommemory) -= offset;
|
|
+ if (offset != 0) {
|
|
+ if ((st.st_size + offset) > rom_size) {
|
|
+ rom_size <<= 1;
|
|
+ rommemory = realloc(rommemory, rom_size);
|
|
+ if (rommemory == 0)
|
|
+ return PILOTCPU_ERROR_LOADING_ROM;
|
|
+ }
|
|
+
|
|
+ memmove((char *)rommemory + offset, rommemory, st.st_size);
|
|
}
|
|
}
|
|
}
|