Enabled debugging symbols

This commit is contained in:
Xavi Del Campo 2020-02-01 07:20:36 +01:00
parent 3ccdeed57a
commit a8fb879457
3 changed files with 53 additions and 50 deletions

View File

@ -37,7 +37,7 @@ CDLIC_FILE = $(TOOLCHAIN_PREFIX)/share/licenses/infoeur.dat
# Executable suffix for executable running on the host
# i.e. suffix for the binaries of the tools
EXE_SUFFIX =
EXE_SUFFIX =
#EXE_SUFFIX = .exe # Use this on Windows
@ -58,8 +58,8 @@ CPP = mipsel-unknown-elf-gcc
OBJCOPY = mipsel-unknown-elf-objcopy
# Uncomment the lines below if you want to have a debug build
# CFLAGS += -g -DPSXSDK_DEBUG
# CXXFLAGS += -g -DPSXSDK_DEBUG
CFLAGS += -g -DPSXSDK_DEBUG
CXXFLAGS += -g -DPSXSDK_DEBUG
# 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_AR = ar
HOST_RANLIB = ranlib
HOST_LDFLAGS =
HOST_LDFLAGS =
# Flags for the examples

View File

@ -1,4 +1,4 @@
/*
/*
* memory.c
*
* PSXSDK malloc() family functions
@ -30,20 +30,20 @@ void malloc_setup()
first_free_page = (unsigned int) __bss_end;
first_free_page-= 0x80000000;
if(first_free_page & 0x3ff)
first_free_page = (first_free_page | 0x3ff) + 1;
first_free_page>>=10;
//printf("First free page: %d, bss_end: %x\n", first_free_page, __bss_end);
for(x = 0; x < first_free_page; x++)
{
busy_pages[x] = 1; // RAM occupied by program, data and BIOS looks always allocated
alloc_size[x] = 1; // Fake that 1K was required
}
for(x = first_free_page; x < 2048; x++)
{
busy_pages[x] = 0;
@ -56,16 +56,16 @@ void *malloc(size_t size)
dprintf("malloc(%d)\n", size);
int x, y;
// Round size
if(size & 0x3ff)
size = (size | 0x3ff) + 1;
// Divide it by 1024
// Divide it by 1024
size >>= 10;
//printf("Allocating %dKb\n", size);
// Find a free page
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 it's enough for the memory we want to allocate, then return
// the pointer to the free page we found, otherwise keep finding
// printf("Page found at %dKb\n", x);
for(y = 0; y < size; y++)
if(busy_pages[x+y] == 1) goto malloc_keep_finding;
// We found the memory we wanted, now make it busy
for(y = 0; y < size; y++)
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;
// printf("malloc(): alloc_size[%d] = %d\n", x, size);
printf("finished malloc(%d)\n", size);
return (void*)((unsigned int)0x80000000 + (x<<10));
}
malloc_keep_finding:
; // Useless statement to make GCC not bail out...
}
printf("failed malloc(%d)\n", size);
// We couldn't find anything, return NULL
return NULL;
}
@ -105,15 +108,15 @@ void *calloc(size_t number, size_t size)
void *ptr = malloc(number * size);
unsigned char *cptr = (unsigned char*)ptr;
int x;
if(ptr == NULL)
ptr = NULL;
for(x = 0; x < (number * size); x++)
cptr[x] = 0;
return ptr;
}
}
void free(void *ptr)
{
@ -122,21 +125,21 @@ void free(void *ptr)
unsigned int ptri = (unsigned int)ptr;
ptri -= 0x80000000;
int x;
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
// is free, it means that memory not allocated by malloc() was passed to free.
// Print a warning message and return.
printf("** free() ** : tried to free memory with invalid pointer at %x\n",
ptri + 0x80000000);
return;
return;
}
// Divide ptri by 1024, getting initial page
ptri>>=10;
// printf("Freeing page at %dKb\n", ptri);
@ -151,10 +154,10 @@ void free(void *ptr)
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;
/*for(x=150;x<170;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;
int x;
void *newptr;
if(ptr == NULL)
return malloc(size);
ptri -= 0x80000000;
size |= 0x3ff;
size++;
size>>=10;
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
// is free, it means that memory not allocated by malloc() was passed to realloc.
// Print a warning message and return.
printf("** realloc() ** : tried to reallocate memory with invalid pointer at %x\n",
ptri + 0x80000000);
return NULL;
return NULL;
}
// Get page
ptri>>=10;
if(size < alloc_size[ptri]) // New size smaller than old size
{
for(x = size; x < alloc_size[ptri]; x++)
busy_pages[ptri + x] = 0;
alloc_size[ptri] = size;
}
else if(size > alloc_size[ptri]) // New size bigger than old size
{
newptr = malloc(size * 1024);
if(newptr == NULL)
return NULL;
memcpy(newptr, ptr, alloc_size[ptri]);
free(ptr);
ptr = newptr;
}
return ptr;
}

View File

@ -75,8 +75,8 @@ SECTIONS
" > playstation.x
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
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++