mirror of
https://github.com/captain-amygdala/pistorm.git
synced 2026-01-28 12:39:10 +00:00
Add terrifying Pi shutdown command
Should make users nervous about corrupting their SD card more nervous, but somehow doesn't.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#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 <linux/reboot.h>
|
||||
#include <sys/reboot.h>
|
||||
|
||||
#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) {
|
||||
|
||||
Binary file not shown.
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user