Enabled debugging symbols
This commit is contained in:
parent
3ccdeed57a
commit
a8fb879457
|
@ -37,7 +37,7 @@ CDLIC_FILE = $(TOOLCHAIN_PREFIX)/share/licenses/infoeur.dat
|
||||||
# Executable suffix for executable running on the host
|
# Executable suffix for executable running on the host
|
||||||
# i.e. suffix for the binaries of the tools
|
# i.e. suffix for the binaries of the tools
|
||||||
|
|
||||||
EXE_SUFFIX =
|
EXE_SUFFIX =
|
||||||
|
|
||||||
#EXE_SUFFIX = .exe # Use this on Windows
|
#EXE_SUFFIX = .exe # Use this on Windows
|
||||||
|
|
||||||
|
@ -58,8 +58,8 @@ CPP = mipsel-unknown-elf-gcc
|
||||||
OBJCOPY = mipsel-unknown-elf-objcopy
|
OBJCOPY = mipsel-unknown-elf-objcopy
|
||||||
|
|
||||||
# Uncomment the lines below if you want to have a debug build
|
# Uncomment the lines below if you want to have a debug build
|
||||||
# CFLAGS += -g -DPSXSDK_DEBUG
|
CFLAGS += -g -DPSXSDK_DEBUG
|
||||||
# CXXFLAGS += -g -DPSXSDK_DEBUG
|
CXXFLAGS += -g -DPSXSDK_DEBUG
|
||||||
|
|
||||||
# HOST_* variables specify the programs for compiling code on the host computer
|
# HOST_* variables specify the programs for compiling code on the host computer
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ HOST_CFLAGS = -g -Wall -Werror
|
||||||
HOST_CXXFLAGS = -g -Wall -Werror
|
HOST_CXXFLAGS = -g -Wall -Werror
|
||||||
HOST_AR = ar
|
HOST_AR = ar
|
||||||
HOST_RANLIB = ranlib
|
HOST_RANLIB = ranlib
|
||||||
HOST_LDFLAGS =
|
HOST_LDFLAGS =
|
||||||
|
|
||||||
# Flags for the examples
|
# Flags for the examples
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* memory.c
|
* memory.c
|
||||||
*
|
*
|
||||||
* PSXSDK malloc() family functions
|
* PSXSDK malloc() family functions
|
||||||
|
@ -30,20 +30,20 @@ void malloc_setup()
|
||||||
|
|
||||||
first_free_page = (unsigned int) __bss_end;
|
first_free_page = (unsigned int) __bss_end;
|
||||||
first_free_page-= 0x80000000;
|
first_free_page-= 0x80000000;
|
||||||
|
|
||||||
if(first_free_page & 0x3ff)
|
if(first_free_page & 0x3ff)
|
||||||
first_free_page = (first_free_page | 0x3ff) + 1;
|
first_free_page = (first_free_page | 0x3ff) + 1;
|
||||||
|
|
||||||
first_free_page>>=10;
|
first_free_page>>=10;
|
||||||
|
|
||||||
//printf("First free page: %d, bss_end: %x\n", first_free_page, __bss_end);
|
//printf("First free page: %d, bss_end: %x\n", first_free_page, __bss_end);
|
||||||
|
|
||||||
for(x = 0; x < first_free_page; x++)
|
for(x = 0; x < first_free_page; x++)
|
||||||
{
|
{
|
||||||
busy_pages[x] = 1; // RAM occupied by program, data and BIOS looks always allocated
|
busy_pages[x] = 1; // RAM occupied by program, data and BIOS looks always allocated
|
||||||
alloc_size[x] = 1; // Fake that 1K was required
|
alloc_size[x] = 1; // Fake that 1K was required
|
||||||
}
|
}
|
||||||
|
|
||||||
for(x = first_free_page; x < 2048; x++)
|
for(x = first_free_page; x < 2048; x++)
|
||||||
{
|
{
|
||||||
busy_pages[x] = 0;
|
busy_pages[x] = 0;
|
||||||
|
@ -56,16 +56,16 @@ void *malloc(size_t size)
|
||||||
dprintf("malloc(%d)\n", size);
|
dprintf("malloc(%d)\n", size);
|
||||||
|
|
||||||
int x, y;
|
int x, y;
|
||||||
|
|
||||||
// Round size
|
// Round size
|
||||||
|
|
||||||
if(size & 0x3ff)
|
if(size & 0x3ff)
|
||||||
size = (size | 0x3ff) + 1;
|
size = (size | 0x3ff) + 1;
|
||||||
|
|
||||||
// Divide it by 1024
|
// Divide it by 1024
|
||||||
size >>= 10;
|
size >>= 10;
|
||||||
//printf("Allocating %dKb\n", size);
|
//printf("Allocating %dKb\n", size);
|
||||||
|
|
||||||
// Find a free page
|
// Find a free page
|
||||||
for(x = 0; x < 2048; x++)
|
for(x = 0; x < 2048; x++)
|
||||||
{
|
{
|
||||||
|
@ -74,28 +74,31 @@ void *malloc(size_t size)
|
||||||
// If we find a free page, check how many free pages follow it.
|
// If we find a free page, check how many free pages follow it.
|
||||||
// If it's enough for the memory we want to allocate, then return
|
// If it's enough for the memory we want to allocate, then return
|
||||||
// the pointer to the free page we found, otherwise keep finding
|
// the pointer to the free page we found, otherwise keep finding
|
||||||
|
|
||||||
// printf("Page found at %dKb\n", x);
|
// printf("Page found at %dKb\n", x);
|
||||||
|
|
||||||
for(y = 0; y < size; y++)
|
for(y = 0; y < size; y++)
|
||||||
if(busy_pages[x+y] == 1) goto malloc_keep_finding;
|
if(busy_pages[x+y] == 1) goto malloc_keep_finding;
|
||||||
|
|
||||||
// We found the memory we wanted, now make it busy
|
// We found the memory we wanted, now make it busy
|
||||||
|
|
||||||
for(y = 0; y < size; y++)
|
for(y = 0; y < size; y++)
|
||||||
busy_pages[x+y] = 1;
|
busy_pages[x+y] = 1;
|
||||||
|
|
||||||
// Store allocation size, it is essential for free()
|
// Store allocation size, it is essential for free()
|
||||||
|
|
||||||
alloc_size[x] = size;
|
alloc_size[x] = size;
|
||||||
// printf("malloc(): alloc_size[%d] = %d\n", x, size);
|
// printf("malloc(): alloc_size[%d] = %d\n", x, size);
|
||||||
|
|
||||||
|
printf("finished malloc(%d)\n", size);
|
||||||
|
|
||||||
return (void*)((unsigned int)0x80000000 + (x<<10));
|
return (void*)((unsigned int)0x80000000 + (x<<10));
|
||||||
}
|
}
|
||||||
malloc_keep_finding:
|
malloc_keep_finding:
|
||||||
; // Useless statement to make GCC not bail out...
|
; // Useless statement to make GCC not bail out...
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printf("failed malloc(%d)\n", size);
|
||||||
// We couldn't find anything, return NULL
|
// We couldn't find anything, return NULL
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -105,15 +108,15 @@ void *calloc(size_t number, size_t size)
|
||||||
void *ptr = malloc(number * size);
|
void *ptr = malloc(number * size);
|
||||||
unsigned char *cptr = (unsigned char*)ptr;
|
unsigned char *cptr = (unsigned char*)ptr;
|
||||||
int x;
|
int x;
|
||||||
|
|
||||||
if(ptr == NULL)
|
if(ptr == NULL)
|
||||||
ptr = NULL;
|
ptr = NULL;
|
||||||
|
|
||||||
for(x = 0; x < (number * size); x++)
|
for(x = 0; x < (number * size); x++)
|
||||||
cptr[x] = 0;
|
cptr[x] = 0;
|
||||||
|
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void free(void *ptr)
|
void free(void *ptr)
|
||||||
{
|
{
|
||||||
|
@ -122,21 +125,21 @@ void free(void *ptr)
|
||||||
unsigned int ptri = (unsigned int)ptr;
|
unsigned int ptri = (unsigned int)ptr;
|
||||||
ptri -= 0x80000000;
|
ptri -= 0x80000000;
|
||||||
int x;
|
int x;
|
||||||
|
|
||||||
if((ptri & 0x3ff) || (busy_pages[ptri>>10] == 0) || (alloc_size[ptri>>10] == 0))
|
if((ptri & 0x3ff) || (busy_pages[ptri>>10] == 0) || (alloc_size[ptri>>10] == 0))
|
||||||
{
|
{
|
||||||
// If the pointer address is not a multiplier of 1K, or the page
|
// If the pointer address is not a multiplier of 1K, or the page
|
||||||
// is free, it means that memory not allocated by malloc() was passed to free.
|
// is free, it means that memory not allocated by malloc() was passed to free.
|
||||||
// Print a warning message and return.
|
// Print a warning message and return.
|
||||||
|
|
||||||
printf("** free() ** : tried to free memory with invalid pointer at %x\n",
|
printf("** free() ** : tried to free memory with invalid pointer at %x\n",
|
||||||
ptri + 0x80000000);
|
ptri + 0x80000000);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Divide ptri by 1024, getting initial page
|
// Divide ptri by 1024, getting initial page
|
||||||
|
|
||||||
ptri>>=10;
|
ptri>>=10;
|
||||||
|
|
||||||
// printf("Freeing page at %dKb\n", ptri);
|
// printf("Freeing page at %dKb\n", ptri);
|
||||||
|
@ -151,10 +154,10 @@ void free(void *ptr)
|
||||||
busy_pages[ptri + x] = 0;
|
busy_pages[ptri + x] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set allocation size to 0, finally freeing initial page
|
// Set allocation size to 0, finally freeing initial page
|
||||||
|
|
||||||
alloc_size[ptri] = 0;
|
alloc_size[ptri] = 0;
|
||||||
|
|
||||||
/*for(x=150;x<170;x++)
|
/*for(x=150;x<170;x++)
|
||||||
printf("%d: %d, %d\n", x, busy_pages[x], alloc_size[x]);*/
|
printf("%d: %d, %d\n", x, busy_pages[x], alloc_size[x]);*/
|
||||||
}
|
}
|
||||||
|
@ -164,52 +167,52 @@ void *realloc(void *ptr, size_t size)
|
||||||
unsigned int ptri = (unsigned int)ptr;
|
unsigned int ptri = (unsigned int)ptr;
|
||||||
int x;
|
int x;
|
||||||
void *newptr;
|
void *newptr;
|
||||||
|
|
||||||
if(ptr == NULL)
|
if(ptr == NULL)
|
||||||
return malloc(size);
|
return malloc(size);
|
||||||
|
|
||||||
ptri -= 0x80000000;
|
ptri -= 0x80000000;
|
||||||
|
|
||||||
size |= 0x3ff;
|
size |= 0x3ff;
|
||||||
size++;
|
size++;
|
||||||
|
|
||||||
size>>=10;
|
size>>=10;
|
||||||
|
|
||||||
if((ptri & 0x3ff) || (busy_pages[ptri>>10] == 0) || (alloc_size[ptri>>10] == 0))
|
if((ptri & 0x3ff) || (busy_pages[ptri>>10] == 0) || (alloc_size[ptri>>10] == 0))
|
||||||
{
|
{
|
||||||
// If the pointer address is not a multiplier of 1K, or the page
|
// If the pointer address is not a multiplier of 1K, or the page
|
||||||
// is free, it means that memory not allocated by malloc() was passed to realloc.
|
// is free, it means that memory not allocated by malloc() was passed to realloc.
|
||||||
// Print a warning message and return.
|
// Print a warning message and return.
|
||||||
|
|
||||||
printf("** realloc() ** : tried to reallocate memory with invalid pointer at %x\n",
|
printf("** realloc() ** : tried to reallocate memory with invalid pointer at %x\n",
|
||||||
ptri + 0x80000000);
|
ptri + 0x80000000);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get page
|
// Get page
|
||||||
|
|
||||||
ptri>>=10;
|
ptri>>=10;
|
||||||
|
|
||||||
if(size < alloc_size[ptri]) // New size smaller than old size
|
if(size < alloc_size[ptri]) // New size smaller than old size
|
||||||
{
|
{
|
||||||
for(x = size; x < alloc_size[ptri]; x++)
|
for(x = size; x < alloc_size[ptri]; x++)
|
||||||
busy_pages[ptri + x] = 0;
|
busy_pages[ptri + x] = 0;
|
||||||
|
|
||||||
alloc_size[ptri] = size;
|
alloc_size[ptri] = size;
|
||||||
}
|
}
|
||||||
else if(size > alloc_size[ptri]) // New size bigger than old size
|
else if(size > alloc_size[ptri]) // New size bigger than old size
|
||||||
{
|
{
|
||||||
newptr = malloc(size * 1024);
|
newptr = malloc(size * 1024);
|
||||||
|
|
||||||
if(newptr == NULL)
|
if(newptr == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
memcpy(newptr, ptr, alloc_size[ptri]);
|
memcpy(newptr, ptr, alloc_size[ptri]);
|
||||||
free(ptr);
|
free(ptr);
|
||||||
|
|
||||||
ptr = newptr;
|
ptr = newptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,8 +75,8 @@ SECTIONS
|
||||||
" > playstation.x
|
" > playstation.x
|
||||||
|
|
||||||
echo "#!/bin/sh
|
echo "#!/bin/sh
|
||||||
mipsel-unknown-elf-gcc -D__PSXSDK__ -fno-strict-overflow -fsigned-char -msoft-float -mno-gpopt -fno-builtin -G0 -I$1/include -T $1/mipsel-unknown-elf/lib/ldscripts/playstation.x \$*"> psx-gcc
|
mipsel-unknown-elf-gcc -D__PSXSDK__ -fno-strict-overflow -fsigned-char -msoft-float -mno-gpopt -fno-builtin -g -I$1/include -T $1/mipsel-unknown-elf/lib/ldscripts/playstation.x \$*"> psx-gcc
|
||||||
chmod +x psx-gcc
|
chmod +x psx-gcc
|
||||||
echo "#!/bin/sh
|
echo "#!/bin/sh
|
||||||
mipsel-unknown-elf-g++ -D__PSXSDK__ -fno-strict-overflow -fsigned-char -msoft-float -mno-gpopt -fno-builtin -G0 -I$1/include -T $1/mipsel-unknown-elf/lib/ldscripts/playstation.x -fno-rtti -fno-exceptions -fno-threadsafe-statics -fno-use-cxa-atexit \$*" > psx-g++
|
mipsel-unknown-elf-g++ -D__PSXSDK__ -fno-strict-overflow -fsigned-char -msoft-float -mno-gpopt -fno-builtin -g -I$1/include -T $1/mipsel-unknown-elf/lib/ldscripts/playstation.x -fno-rtti -fno-exceptions -fno-threadsafe-statics -fno-use-cxa-atexit \$*" > psx-g++
|
||||||
chmod +x psx-g++
|
chmod +x psx-g++
|
||||||
|
|
Loading…
Reference in New Issue