Skip to content

Commit

Permalink
prep for supporting debug/profiling builds
Browse files Browse the repository at this point in the history
- let `make` accept a SLIPPI_DEBUG flag for generating debug builds
- remove vestigial debugging code
- fix some minor style mistakes
  • Loading branch information
meta committed Mar 15, 2019
1 parent b9c4edd commit f8106c2
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 32 deletions.
12 changes: 11 additions & 1 deletion kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ else
ZIP = zip
endif


CFLAGS := -mbig-endian -O3 -std=gnu89 -g -I. -Wall \
-mcpu=arm926ej-s -msoft-float -mfloat-abi=soft \
-fdata-sections -ffunction-sections -fno-builtin-toupper -fno-builtin-memcpy \
Expand All @@ -34,7 +35,7 @@ LDFLAGS := -nostartfiles -nodefaultlibs -mbig-endian -Wl,--gc-sections,-T,kernel
TARGET := kernel.elf
OBJECTS := start.o common.o alloc.o GCAM.o JVSIO.o JVSIOMessage.o FST.o DI.o RealDI.o \
SlippiMemory.o SlippiFileWriter.o SlippiNetwork.o SlippiNetworkBroadcast.o \
SlippiDebug.o Patch.o PatchTimers.o TRI.o \
Patch.o PatchTimers.o TRI.o \
PatchWidescreen.o ISO.o Stream.o adp.o EXI.o SRAM.o GCNCard.o SI.o HID.o diskio.o \
Config.o utils_asm.o ES.o NAND.o main.o syscalls.o ReadSpeed.o vsprintf.o string.o \
prs.o SDI.o usb.o usbstorage.o wdvd.o net.o
Expand All @@ -44,6 +45,15 @@ ZIPFILE := ../loader/data/kernel.zip
# Bluetooth stack
OBJECTS += lwbt/bte.o lwbt/btmemb.o lwbt/btmemr.o lwbt/btpbuf.o lwbt/hci.o lwbt/l2cap.o lwbt/physbusif.o BT.o


# When make is invoked with `make SLIPPI_DEBUG=1`: compile SlippiDebug.o and
# let GCC define SLIPPI_PROFILE as a macro. Use this for some profiling code.

ifeq ($(SLIPPI_DEBUG), 1)
OBJECTS += SlippiDebug.o
CFLAGS += -DSLIPPI_DEBUG
endif

#---------------------------------------------------------------------------------
# For pulling in built-in Gecko codes
ifeq ($(OS),Windows_NT)
Expand Down
2 changes: 0 additions & 2 deletions kernel/SlippiFileWriter.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
#include "string.h"
#include "ff_utf8.h"

#include "SlippiDebug.h"

#include "Config.h"

// Game can transfer at most 784 bytes / frame
Expand Down
11 changes: 2 additions & 9 deletions kernel/SlippiMemory.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "SlippiMemory.h"
#include "SlippiDebug.h"
#include "common.h"
#include "debug.h"
#include "string.h"
Expand Down Expand Up @@ -71,7 +70,6 @@ SlpMemError SlippiMemoryRead(SlpGameReader *reader, u8 *buf, u32 bufLen, u64 rea
if (bytesRead > 0 && command == SLP_CMD_RECEIVE_COMMANDS)
{
dbgprintf("WARN: Unnexpected new game message\r\n");
ppc_msg("SLP UNEXP MSG\x00", 14);
errCode = SLP_MEM_UNNEX_NG;
break;
}
Expand All @@ -82,7 +80,6 @@ SlpMemError SlippiMemoryRead(SlpGameReader *reader, u8 *buf, u32 bufLen, u64 rea
reader->lastReadResult.isNewGame = true;
resetMetadata(reader);
setPayloadSizes(reader, normalizedReadPos);
ppc_msg("SLP NEWGAME\x00", 12);
}

u16 payloadSize = getPayloadSize(reader, command);
Expand Down Expand Up @@ -129,7 +126,6 @@ SlpMemError SlippiMemoryRead(SlpGameReader *reader, u8 *buf, u32 bufLen, u64 rea
// Special case handling: game end message processed
if (command == SLP_CMD_RECEIVE_GAME_END)
{
ppc_msg("SLP GAME END\x00", 13);
reader->lastReadResult.isGameEnd = true;
break;
}
Expand All @@ -156,11 +152,10 @@ void resetMetadata(SlpGameReader *reader)
void updateMetadata(SlpGameReader *reader, u8 *message, u32 messageLength)
{
u8 command = message[0];

// Only need to update if this is a post frame update
if (messageLength <= 0 || command != SLP_CMD_RECEIVE_POST_FRAME_UPDATE)
{
// Only need to update if this is a post frame update
return;
}

// Keep track of last frame
reader->metadata.lastFrame = message[1] << 24 | message[2] << 16 | message[3] << 8 | message[4];
Expand Down Expand Up @@ -205,9 +200,7 @@ u16 getPayloadSize(SlpGameReader *reader, u8 command)
{
int payloadSizesIndex = command - SLP_CMD_RECEIVE_COMMANDS;
if (payloadSizesIndex >= PAYLOAD_SIZES_BUFFER_SIZE || payloadSizesIndex < 0)
{
return 0;
}

return reader->payloadSizes[payloadSizesIndex];
}
20 changes: 7 additions & 13 deletions kernel/SlippiNetwork.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ s32 SlippiNetworkInit()
0x78);
thread_continue(SlippiNetwork_Thread);
SlippiServerStarted = 1;
ppc_msg("SERVER INIT OK\x00", 15);
return 0;
}

Expand Down Expand Up @@ -121,7 +120,6 @@ void listenForClient()
dbgprintf("[TCP_NODELAY] Client setsockopt result: %d\r\n", optRes);

dbgprintf("Client connection detected\r\n");
ppc_msg("CLIENT OK\x00", 10);
client_alive_ts = read32(HW_TIMER);
} else {
// dbgprintf("Client sock accept failure: %d\r\n", client_sock);
Expand All @@ -146,7 +144,6 @@ void hangUpConnection() {
close(top_fd, client_sock);
client_sock = -1;
reset_broadcast_timer();
ppc_msg("CLIENT HUP\x00", 11);
}

/* handleFileTransfer()
Expand All @@ -163,10 +160,10 @@ static SlpGameReader reader;
s32 handleFileTransfer()
{
int status = getConnectionStatus();
if (status != CONN_STATUS_CONNECTED) {
// Do nothing if we aren't connected to a client

// Do nothing if we aren't connected to a client
if (status != CONN_STATUS_CONNECTED)
return 0;
}

SlpMemError err = SlippiMemoryRead(&reader, readBuf, READ_BUF_SIZE, memReadPos);
if (err)
Expand Down Expand Up @@ -231,17 +228,14 @@ static char alive_msg[] __attribute__((aligned(32))) = "HELO";
s32 checkAlive(void)
{
int status = getConnectionStatus();
if (status != CONN_STATUS_CONNECTED) {
// Do nothing if we aren't connected to a client
// the handleFileTransfer could sometimes cause a disconnect

// Do nothing if we aren't connected to a client
if (status != CONN_STATUS_CONNECTED)
return 0;
}

// Only check alive if we haven't detected any communication
if (TimerDiffSeconds(client_alive_ts) < 3)
{
// Only check alive if we haven't detected any communication
return 0;
}

s32 res;
res = sendto(top_fd, client_sock, alive_msg, sizeof(alive_msg), 0);
Expand Down
2 changes: 0 additions & 2 deletions kernel/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "SlippiFileWriter.h"
#include "SlippiNetwork.h"
#include "SlippiNetworkBroadcast.h"
#include "SlippiDebug.h"
#include "net.h"

#include "diskio.h"
Expand Down Expand Up @@ -477,7 +476,6 @@ int _main( int argc, char *argv[] )

// Initialize 8040a5a8 with a string to print w/ UnclePunch Gecko code
if ( (TimerDiffSeconds(NCDTimer) > 3) && (SlippiDbgStringInit == 0) ) {
ppc_msg("SLIPPI BUP\x00", 11);
SlippiDbgStringInit = 1;
}

Expand Down
6 changes: 1 addition & 5 deletions kernel/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
#include "debug.h"
#include "net.h"

#include "SlippiDebug.h"

// File descriptor for the IOS socket driver, shared by all Slippi threads
s32 top_fd __attribute__((aligned(32)));

Expand Down Expand Up @@ -93,7 +91,6 @@ int NCDInit(void)
dbgprintf("IOCTL_SO_GETHOSTID: 0x%x\n", current_ip_address);

NetworkStarted = 1;
ppc_msg("NCDINIT OK\x00", 11);
return 0;
}

Expand Down Expand Up @@ -231,9 +228,8 @@ s32 sendto(s32 fd, s32 socket, void *data, s32 len, u32 flags)
*/

u8 *message_buf = (u8*)heap_alloc_aligned(0, len, 32);
if (message_buf == NULL) {
if (message_buf == NULL)
return -1;
}

// I don't see how this won't totally kill performance
memset(params, 0, sizeof(struct sendto_params));
Expand Down

0 comments on commit f8106c2

Please sign in to comment.