From 0720a8caed7981547fc69f51b9004fe3d28c8d1d Mon Sep 17 00:00:00 2001 From: beeanyew Date: Sat, 24 Apr 2021 09:28:30 +0200 Subject: [PATCH] Add terrifying Pi shutdown command Should make users nervous about corrupting their SD card more nervous, but somehow doesn't. --- emulator.c | 2 + .../amiga/pistorm-dev/pistorm-dev-enums.h | 103 +++++++++--------- platforms/amiga/pistorm-dev/pistorm-dev.c | 25 ++++- .../pistorm-dev/pistorm_dev_amiga/PiSimple | Bin 14256 -> 14368 bytes .../pistorm_dev_amiga/pistorm_dev.c | 12 ++ 5 files changed, 90 insertions(+), 52 deletions(-) diff --git a/emulator.c b/emulator.c index 306ae7c..39dac56 100644 --- a/emulator.c +++ b/emulator.c @@ -473,6 +473,8 @@ int main(int argc, char *argv[]) { } switch_config: + srand(clock()); + if (load_new_config != 0) { uint8_t config_action = load_new_config - 1; load_new_config = 0; diff --git a/platforms/amiga/pistorm-dev/pistorm-dev-enums.h b/platforms/amiga/pistorm-dev/pistorm-dev-enums.h index ece375d..1778674 100644 --- a/platforms/amiga/pistorm-dev/pistorm-dev-enums.h +++ b/platforms/amiga/pistorm-dev/pistorm-dev-enums.h @@ -6,61 +6,64 @@ // [R], [W] and [RW] indicate read, write or both access modes for register // Any failure or result code from a write command should be put in PI_CMDRESULT enum pistorm_dev_cmds { - PI_CMD_RESET = 0x00, // [W] Reset the host system. - PI_CMD_SWITCHCONFIG = 0x02, // [W] Switch config file to string at PI_STR1, if it exists. - // This will reset the Amiga if the config loads successfully. - PI_CMD_PISCSI_CTRL = 0x04, // [RW] Write: Control a PiSCSI device. The command written here uses - // values From various data registers around $2000. - // Read: Returns whether PiSCSI is enabled or not. - PI_CMD_RTGSTATUS = 0x06, // [RW] Read: Check RTG status Write: Set RTG status (enabled/disabled) - PI_CMD_NETSTATUS = 0x08, // [RW] Read: Check ETH status Write: Set ETH status (enabled/disabled) - PI_CMD_KICKROM = 0x0A, // [W] Map a different Kickstart ROM to the standard address using - // the string at PI_STR1, if the file exists. Requires some config - // file names to be set in order to find it. - PI_CMD_EXTROM = 0x0E, // [W] Same as above, but the extended ROM. + PI_CMD_RESET = 0x00, // [W] Reset the host system. + PI_CMD_SWITCHCONFIG = 0x02, // [W] Switch config file to string at PI_STR1, if it exists. + // This will reset the Amiga if the config loads successfully. + PI_CMD_PISCSI_CTRL = 0x04, // [RW] Write: Control a PiSCSI device. The command written here uses + // values From various data registers around $2000. + // Read: Returns whether PiSCSI is enabled or not. + PI_CMD_RTGSTATUS = 0x06, // [RW] Read: Check RTG status Write: Set RTG status (enabled/disabled) + PI_CMD_NETSTATUS = 0x08, // [RW] Read: Check ETH status Write: Set ETH status (enabled/disabled) + PI_CMD_KICKROM = 0x0A, // [W] Map a different Kickstart ROM to the standard address using + // the string at PI_STR1, if the file exists. Requires some config + // file names to be set in order to find it. + PI_CMD_EXTROM = 0x0E, // [W] Same as above, but the extended ROM. - PI_CMD_HWREV = 0x10, // [R] Check the PiStorm hardware version/revision - PI_CMD_SWREV = 0x12, // [R] Check the PiStorm software version/revision + PI_CMD_HWREV = 0x10, // [R] Check the PiStorm hardware version/revision + PI_CMD_SWREV = 0x12, // [R] Check the PiStorm software version/revision - PI_CMD_QBASIC = 0x0FFC, // QBasic - PI_CMD_NIBBLES = 0x0FFE, // Nibbles + PI_CMD_QBASIC = 0x0FFC, // QBasic + PI_CMD_NIBBLES = 0x0FFE, // Nibbles - PI_DBG_MSG = 0x1000, // [W] Trigger debug message output to avoid slow serial kprintf. - PI_DBG_VAL1 = 0x1010, // [RW] - PI_DBG_VAL2 = 0x1014, // [RW] - PI_DBG_VAL3 = 0x1018, // [RW] - PI_DBG_VAL4 = 0x101C, // [RW] - PI_DBG_VAL5 = 0x1020, // [RW] - PI_DBG_VAL6 = 0x1024, // [RW] - PI_DBG_VAL7 = 0x1028, // [RW] - PI_DBG_VAL8 = 0x102C, // [RW] - PI_DBG_STR1 = 0x1030, // [W] Pointers to debug strings (typically in "Amiga RAM") - PI_DBG_STR2 = 0x1034, // [W] - PI_DBG_STR3 = 0x1038, // [W] - PI_DBG_STR4 = 0x103C, // [W] + PI_DBG_MSG = 0x1000, // [W] Trigger debug message output to avoid slow serial kprintf. + PI_DBG_VAL1 = 0x1010, // [RW] + PI_DBG_VAL2 = 0x1014, // [RW] + PI_DBG_VAL3 = 0x1018, // [RW] + PI_DBG_VAL4 = 0x101C, // [RW] + PI_DBG_VAL5 = 0x1020, // [RW] + PI_DBG_VAL6 = 0x1024, // [RW] + PI_DBG_VAL7 = 0x1028, // [RW] + PI_DBG_VAL8 = 0x102C, // [RW] + PI_DBG_STR1 = 0x1030, // [W] Pointers to debug strings (typically in "Amiga RAM") + PI_DBG_STR2 = 0x1034, // [W] + PI_DBG_STR3 = 0x1038, // [W] + PI_DBG_STR4 = 0x103C, // [W] - PI_BYTE1 = 0x2000, // [RW] // Bytes, words and longwords used as extended arguments. - PI_BYTE2 = 0x2001, // [RW] // for PiStorm interaction device commands. - PI_BYTE3 = 0x2002, // [RW] - PI_BYTE4 = 0x2003, // [RW] - PI_BYTE5 = 0x2004, // [RW] - PI_BYTE6 = 0x2005, // [RW] - PI_BYTE7 = 0x2006, // [RW] - PI_BYTE8 = 0x2007, // [RW] - PI_WORD1 = 0x2008, // [RW] - PI_WORD2 = 0x200A, // [RW] - PI_WORD3 = 0x200C, // [RW] - PI_WORD4 = 0x200E, // [RW] - PI_LONGWORD1 = 0x2010, // [RW] - PI_LONGWORD2 = 0x2014, // [RW] - PI_LONGWORD3 = 0x2018, // [RW] - PI_LONGWORD4 = 0x201C, // [RW] - PI_STR1 = 0x2020, // [W] Pointers to strings (typically in "Amiga RAM") - PI_STR2 = 0x2024, // [W] - PI_STR3 = 0x2028, // [W] - PI_STR4 = 0x202C, // [W] + PI_CMD_SHUTDOWN = 0x1FFC, // [W] Initiate requesting the Pi to shut down + PI_CMD_CONFIRMSHUTDOWN = 0x1FFE, // [W] Confirm shutting down the Pi - PI_CMDRESULT = 0x2100, // [R] Check the result of any command that provides a "return value". + PI_BYTE1 = 0x2000, // [RW] // Bytes, words and longwords used as extended arguments. + PI_BYTE2 = 0x2001, // [RW] // for PiStorm interaction device commands. + PI_BYTE3 = 0x2002, // [RW] + PI_BYTE4 = 0x2003, // [RW] + PI_BYTE5 = 0x2004, // [RW] + PI_BYTE6 = 0x2005, // [RW] + PI_BYTE7 = 0x2006, // [RW] + PI_BYTE8 = 0x2007, // [RW] + PI_WORD1 = 0x2008, // [RW] + PI_WORD2 = 0x200A, // [RW] + PI_WORD3 = 0x200C, // [RW] + PI_WORD4 = 0x200E, // [RW] + PI_LONGWORD1 = 0x2010, // [RW] + PI_LONGWORD2 = 0x2014, // [RW] + PI_LONGWORD3 = 0x2018, // [RW] + PI_LONGWORD4 = 0x201C, // [RW] + PI_STR1 = 0x2020, // [W] Pointers to strings (typically in "Amiga RAM") + PI_STR2 = 0x2024, // [W] + PI_STR3 = 0x2028, // [W] + PI_STR4 = 0x202C, // [W] + + PI_CMDRESULT = 0x2100, // [R] Check the result of any command that provides a "return value". }; enum pistorm_piscsi_commands { diff --git a/platforms/amiga/pistorm-dev/pistorm-dev.c b/platforms/amiga/pistorm-dev/pistorm-dev.c index 30c0dfb..5ca3488 100644 --- a/platforms/amiga/pistorm-dev/pistorm-dev.c +++ b/platforms/amiga/pistorm-dev/pistorm-dev.c @@ -3,6 +3,7 @@ #include #include #include +#include #include "pistorm-dev.h" #include "pistorm-dev-enums.h" @@ -12,6 +13,9 @@ #include "platforms/amiga/piscsi/piscsi.h" #include "platforms/amiga/net/pi-net.h" +#include +#include + #define DEBUG_PISTORM_DEVICE #ifdef DEBUG_PISTORM_DEVICE @@ -33,7 +37,7 @@ extern uint32_t pistorm_dev_base; extern uint32_t do_reset; extern void adjust_ranges_amiga(struct emulator_config *cfg); -extern uint8_t rtg_enabled, rtg_on, pinet_enabled, piscsi_enabled, load_new_config; +extern uint8_t rtg_enabled, rtg_on, pinet_enabled, piscsi_enabled, load_new_config, end_signal; extern struct emulator_config *cfg; char cfg_filename[256] = "default.cfg"; @@ -47,7 +51,7 @@ static uint32_t pi_string[4]; static uint32_t pi_dbg_val[4]; static uint32_t pi_dbg_string[4]; -static uint32_t pi_cmd_result = 0; +static uint32_t pi_cmd_result = 0, shutdown_confirm = 0xFFFFFFFF; int32_t grab_amiga_string(uint32_t addr, uint8_t *dest, uint32_t str_max_len) { int32_t r = get_mapped_item_by_address(cfg, addr); @@ -293,6 +297,23 @@ void handle_pistorm_dev_write(uint32_t addr_, uint32_t val, uint8_t type) { DEBUG("[PISTORM-DEV] System reset called, code %d\n", (val & 0xFFFF)); do_reset = 1; break; + case PI_CMD_SHUTDOWN: + DEBUG("[PISTORM-DEV] Shutdown requested. Confirm by replying with return value to CONFIRMSHUTDOWN.\n"); + shutdown_confirm = rand() % 0xFFFF; + pi_cmd_result = shutdown_confirm; + break; + case PI_CMD_CONFIRMSHUTDOWN: + if (val != shutdown_confirm) { + DEBUG("[PISTORM-DEV] Attempted shutdown with wrong shutdown confirm value. Not shutting down.\n"); + shutdown_confirm = 0xFFFFFFFF; + pi_cmd_result = PI_RES_FAILED; + } else { + printf("[PISTORM-DEV] Shutting down the PiStorm. Good night, fight well, until we meet again.\n"); + reboot(LINUX_REBOOT_CMD_POWER_OFF); + pi_cmd_result = PI_RES_OK; + end_signal = 1; + } + break; case PI_CMD_SWITCHCONFIG: DEBUG("[PISTORM-DEV] Config switch called, command: "); switch (val) { diff --git a/platforms/amiga/pistorm-dev/pistorm_dev_amiga/PiSimple b/platforms/amiga/pistorm-dev/pistorm_dev_amiga/PiSimple index b6355d91f955cd2e97459a4d736b8c28a2af6b02..b4f8d8b03ae56a2be375fe617833ab3fd647561d 100644 GIT binary patch delta 2917 zcmZ{mduUtN9mmhPvSY`&cD#@#A+fD1S++&$M7HCm&lNAUs~dtESUXHedoAl>DV8O1 zB_&D-m6v5($im|Kz%V0Z#e@(_*xZ^8R>JVw62d6MbfuVKMkpnuC2hT6N;_J6pL3<8 z?H?0-&$++%uBut-oBN|2@yKgxQ|(XWW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Sv^RN_Gp-edMYmB{6jS-t;|;oIIJ9f>gLN$po%3_tLblonWpSh|R3Aw2sT z?o}y1maq!RVmV_+?RW@Xz0Rgcg;GhXS4e)VQpVeAJsjj6clES=pROSXZCTD+sdR?h zz1yoYEld^)Sr`($6T>|R(#dFzI+76s&6`f`*olTd< zVwp^?TJWHbTFW*0ne<2@R!AqQOGqWtX? zR6LWj*$C*CCJF1FgzsuiE%xqv=5S4;1F2QpzhR#~T}YQ~D&16{+u`8!NEw=4%l4iR zq?9XX_#oEpeg3{T)zjzUK|jjqS9!*as`Rx#wNSOwU8t*NRv7H0^oLYDO@+ph2xCnT zbV%t;K55}EQr%Yt_WuPNeQi%&L#lI%pF9;C$rW^E-7B``SS+pEhRdsYkEiU;*FJeB zZ!;Ly|AQ5Qel>g`_>8`7sM_g*U#g%sj@F3pWv&05wU)-tZrL7wu{2lOUKbAgpe}mN je(S2bdEgtrN7KWfR}Xn=HmMiP6ZUJ#k)@4;0muIUtMg4= diff --git a/platforms/amiga/pistorm-dev/pistorm_dev_amiga/pistorm_dev.c b/platforms/amiga/pistorm-dev/pistorm_dev_amiga/pistorm_dev.c index 778f021..c5b20f1 100644 --- a/platforms/amiga/pistorm-dev/pistorm_dev_amiga/pistorm_dev.c +++ b/platforms/amiga/pistorm-dev/pistorm_dev_amiga/pistorm_dev.c @@ -64,6 +64,18 @@ void pi_reset_amiga(unsigned short reset_code) { WRITESHORT(PI_CMD_RESET, reset_code); } +unsigned short pi_shutdown_pi(unsigned short shutdown_code) { + WRITESHORT(PI_CMD_SHUTDOWN, shutdown_code); + + RETURN_CMDRES; +} + +unsigned short pi_confirm_shutdown(unsigned short shutdown_code) { + WRITESHORT(PI_CMD_CONFIRMSHUTDOWN, shutdown_code); + + RETURN_CMDRES; +} + // Kickstart/Extended ROM stuff unsigned short pi_remap_kickrom(char *filename) { WRITELONG(PI_STR1, (unsigned int)filename); -- 2.39.2