Skip to content

Commit

Permalink
added reset callback
Browse files Browse the repository at this point in the history
  • Loading branch information
shazz committed May 14, 2022
1 parent 9411bc5 commit c68547a
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 43 deletions.
Binary file modified boot/release/boot.dol
Binary file not shown.
Binary file modified boot/release/boot.dol.gci
Binary file not shown.
9 changes: 9 additions & 0 deletions boot/source/boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
// DEFINES
//---------------------------------------------------------------------------------
#define FILENAME "fat:/autoexec.dol"
#define GCLINK "fat:/gclink.dol"
#define TIMEOUT 3*60

// --------------------------------------------------------------------------------
Expand Down Expand Up @@ -108,6 +109,7 @@ int main() {
printf("[Start] for sd2sp2 (default)\n");
printf("[B] for SD gecko in port B\n");
printf("[A] for SD gecko in port A\n");
printf("[Z] for gclink on sd2sp2\n");

while(frames_counter <= TIMEOUT) {
VIDEO_WaitVSync();
Expand All @@ -133,13 +135,20 @@ int main() {
frames_counter = 0;
}
}
else if(buttonsDown & PAD_TRIGGER_Z) {
if (!load_fat_file(&__io_gcsd2, GCLINK)) {
printf("Error: Cannot mount fat on sd2 and load %s!\n", GCLINK);
frames_counter = 0;
}
}
frames_counter += 1;
}

// do in order
load_fat_file(&__io_gcsd2, FILENAME);
load_fat_file(&__io_gcsdb, FILENAME);
load_fat_file(&__io_gcsda, FILENAME);
load_fat_file(&__io_gcsd2, GCLINK);

printf("Error: Cannot mount and find any autoexec.dol, rebooting in 5s!\n");
sleep(5);
Expand Down
2 changes: 1 addition & 1 deletion boot/source/exi.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ int exi_bba_exists()
return exi_get_id(EXI_CHANNEL_0,EXI_DEVICE_2) == EXI_BBA_ID;
}

unsigned int exi_get_id(int chn, int dev)
unsigned int exi_get_id(int chn, int dev)
{
u32 cid = 0;
EXI_GetID(chn,dev,&cid);
Expand Down
15 changes: 13 additions & 2 deletions gclink/gc/gclink/source/gclink.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ const static char gclink_reset[] = "RESET";
extern u8 stub_bin[];
extern u32 stub_bin_size;

//---------------------------------------------------------------------------------
// Reset button callbak
//---------------------------------------------------------------------------------
static void reset_cb(u32 irq, void* ctx) {
printf("Reset button pushed with IRQ %d\n!", irq);
void (*reload)() = (void(*)()) 0x80001800;
reload ();
}

//---------------------------------------------------------------------------------
// init
//---------------------------------------------------------------------------------
Expand Down Expand Up @@ -456,14 +465,15 @@ int execute_dol(int csock, int size) {
if(size) {
ret = net_recv(csock, data_ptr, size, 0);
}
printf(". Done!\n");
printf(".Done!\n");

// install stub
printf("Installing stub\n");
ret = installStub();
if (ret == 1) {
printf("Could not copy the stub loader in RAM\n");
}
SYS_SetResetCallback(reset_cb);

// Check DOL header
DOLHEADER *dolhdr = (DOLHEADER*) data;
Expand Down Expand Up @@ -504,13 +514,14 @@ int execute_elf(int csock, int size) {
if(size) {
ret = net_recv(csock, data_ptr, size, 0);
}
printf(". Done!\n");
printf(".Done!\n");

// install stub
ret = installStub();
if (ret == 1) {
printf("Could not copy the stub loader in RAM\n");
}
SYS_SetResetCallback(reset_cb);

// Copy ELF to ARAM then execute
ret = ELFtoARAM(data, 0, NULL);
Expand Down
2 changes: 1 addition & 1 deletion gclink/gc/gclink/source/sidestep.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ void *ARAMRunStub() {
BOOTSTUB stub;
char *p;
char *s = (char *) ARAMStub;

/*** Copy ARAMStub to 81300000 ***/
if (_dst + _len < 0x81300000) p = (void *) 0x81300000;
else p = (void *) 0x80003100;
Expand Down
68 changes: 39 additions & 29 deletions gclink/pc/gclink_client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import socket
import ipaddress
import sys
import argparse
from pathlib import Path

Expand Down Expand Up @@ -55,35 +56,44 @@ def cmd_exec(gclink_host, gclink_port, cmd_type: str, path: Path):
raise RuntimeError(f"File size cannot be 0 bytes")

# connect
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((gclink_host, gclink_port))

# send command
cmd = f"{cmd_types[cmd_type]} {path.name} {path.stat().st_size}"
print(f"Command: {cmd}")
s.sendall(cmd.encode("ascii"))

# get ack
data = s.recv(1024)
ack = data.decode("ascii")

# check ack
if ack == "OK":

# send file bytes content
with open(str(path), "rb") as f:
file_data = f.read()
s.sendall(file_data)

# get result status
data = s.recv(1024)
ack = data.decode("ascii")
if "executed" not in ack:
raise RuntimeError("file not sent correctly!")

print("Success!")
else:
raise RuntimeError(f"Error! Received: {ack}")
try:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((gclink_host, gclink_port))

# send command
cmd = f"{cmd_types[cmd_type]} {path.name} {path.stat().st_size}"
print(f"Command: {cmd}")
s.sendall(cmd.encode("ascii"))

# get ack
s.settimeout(10.0)
data = s.recv(1024)
ack = data.decode("ascii")

# check ack
if ack == "OK":

# send file bytes content
with open(str(path), "rb") as f:
file_data = f.read()
s.sendall(file_data)

# get result status
data = s.recv(1024)
ack = data.decode("ascii")
if "executed" not in ack:
raise RuntimeError("file not sent correctly!")

print("Success!")
else:
raise RuntimeError(f"Error! Received: {ack}")

except KeyboardInterrupt:
print("Exiting!")
sys.exit()
except socket.timeout:
print("Timeout, exiting!")
sys.exit()


if __name__ == '__main__':
Expand Down
29 changes: 19 additions & 10 deletions libogc2/console/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,18 @@ vu16 keydown;
vu16 keyup;
PADStatus pad[4];

static void return_to_loader (void)
{
// Callbacks
static void return_to_loader (void) {
printf("Return to loader\n");
void (*reload)() = (void(*)()) 0x80001800;
reload ();
}

static void reset_cb(u32 irq, void* ctx) {
printf("Reset button pushed with IRQ %d\n!", irq);
return_to_loader();
}

int main() {

VIDEO_Init();
Expand All @@ -37,8 +42,8 @@ int main() {
PAD_Init();

// be sure we're going back to the gclink loader
atexit(return_to_loader);
// resetcallback SYS_SetResetCallback(resetcallback cb);
// atexit(return_to_loader);
SYS_SetResetCallback(reset_cb);

xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));

Expand All @@ -52,16 +57,16 @@ int main() {

if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();

console_init(xfb,30,30,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*2);
console_init(xfb, 20, 20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*2);

time_t gc_time;
gc_time = time(NULL);

srand(gc_time);

printf("testing console\n");
printf("\n\nTesting console\n");
std::cout << "Hello World" << std::endl;
printf("random number is %08x\n",rand());
printf("Random number is %08x\n",rand());

while(1) {

Expand All @@ -73,12 +78,16 @@ int main() {

int buttonsDown = PAD_ButtonsDown(0);

if ((buttonsDown & PAD_BUTTON_START) || (SYS_ResetButtonDown())) {
if (buttonsDown & PAD_BUTTON_START) {
printf("Existing with specific atexit\n");
atexit(return_to_loader);
exit(0);
}
if (buttonsDown & PAD_BUTTON_A) {
printf("Existing with exit(0)\n");
exit(0);
}
}

printf("Bye bye!)\n");
return_to_loader();

}

0 comments on commit c68547a

Please sign in to comment.