diff options
Diffstat (limited to 'avr')
-rw-r--r-- | avr/Tupfile | 6 | ||||
-rw-r--r-- | avr/cmd_boot.c | 27 | ||||
-rw-r--r-- | avr/cmd_cpu.c | 90 | ||||
-rw-r--r-- | avr/command_tbl.c | 6 | ||||
-rw-r--r-- | avr/z80-if.c | 31 |
5 files changed, 130 insertions, 30 deletions
diff --git a/avr/Tupfile b/avr/Tupfile index b74b305..68a6ae0 100644 --- a/avr/Tupfile +++ b/avr/Tupfile @@ -7,7 +7,7 @@ FATFS = $(FATFSD)/ff.c $(FATFSD)/ffunicode.c SRC = main.c SRC += cli.c cli_readline.c command.c command_tbl.c -SRC += cmd_run.c cmd_boot.c cmd_misc.c +SRC += cmd_run.c cmd_boot.c cmd_misc.c cmd_cpu.c SRC += cmd_date.c cmd_mem.c cmd_gpio.c cmd_attach.c SRC += cmd_loadihex.c cmd_loadcpm3.c cmd_sd.c cmd_fat.c SRC += env.c con-utils.c print-utils.c getopt-min.c eval_arg.c @@ -23,7 +23,7 @@ SRC += ../time/system_time.c ../time/set_system_time.c ASRC += ../time/system_tick.S -SRC_Z = ../z180/hdrom.c ../z180/cfboot.c +SRC_Z = ../z180/hdrom.c ../z180/cfboot.c ../z180/cpuinfo.c #TARGETS = $(PROG).elf @@ -112,7 +112,7 @@ LDFLAGS += -Wl,--cref !SIZE = |> ^ SIZE^ $(SIZE) %f |> : foreach $(ASRC) |> !as |> {objs} -: foreach $(SRC) | ../z180/hdrom.h ../z180/cfboot.h |> !cc |> {objs} +: foreach $(SRC) | ../z180/hdrom.h ../z180/cfboot.h ../z180/cpuinfo.h |> !cc |> {objs} : foreach $(SRC_Z) |> !cc -D'const=const __flash' |> {objs} : {objs} |> !LINK |> $(PROG).elf diff --git a/avr/cmd_boot.c b/avr/cmd_boot.c index 600bad3..2159608 100644 --- a/avr/cmd_boot.c +++ b/avr/cmd_boot.c @@ -31,33 +31,6 @@ #undef const - -static void z80_load_mem(int_fast8_t verbosity, - const FLASH unsigned char data[], - const FLASH unsigned long *sections, - const FLASH unsigned long address[], - const FLASH unsigned long length_of_sections[]) -{ - uint32_t sec_base = 0; - - if (verbosity > 1) - printf_P(PSTR("Loading Z180 memory... \n")); - - for (unsigned sec = 0; sec < *sections; sec++) { - if (verbosity > 0) { - printf_P(PSTR(" From: 0x%.5lX to: 0x%.5lX (%5li bytes)\n"), - address[sec], - address[sec]+length_of_sections[sec] - 1, - length_of_sections[sec]); - } - - z80_write_block_P((const FLASH unsigned char *) &data[sec_base], /* src */ - address[sec], /* dest */ - length_of_sections[sec]); /* len */ - sec_base += length_of_sections[sec]; - } -} - command_ret_t do_loadf(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc UNUSED, char * const argv[] UNUSED) { if (z80_bus_state() & ZST_RUNNING) diff --git a/avr/cmd_cpu.c b/avr/cmd_cpu.c new file mode 100644 index 0000000..de627c6 --- /dev/null +++ b/avr/cmd_cpu.c @@ -0,0 +1,90 @@ +/* + * (C) Copyright 2018 Leo C. <erbl259-lmu@yahoo.de> + * + * SPDX-License-Identifier: GPL-2.0 + */ + +#include "cmd_cpu.h" +//#include <ctype.h> +//#include <util/atomic.h> + +#include "z80-if.h" +#include "con-utils.h" +//#include "env.h" +//#include "eval_arg.h" +//#include "getopt-min.h" +//#include "debug.h" + +/* hack to get Z180 loadfile into flash memory */ +#define const const FLASH +#include "../z180/cpuinfo.h" +#undef const + + +static const FLASH char * const FLASH cpu_strings[] = { + FSTR("Unknown CPU"), + FSTR("8080"), + FSTR("8085"), + FSTR("Z80"), + FSTR("x180"), + FSTR("HD64180"), + FSTR("Z80180"), + FSTR("Z80S180"), +}; + +command_ret_t do_cpuchk(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc UNUSED, char * const argv[] UNUSED) +{ + uint8_t done = 0; + uint8_t cputype; + ERRNUM err = ESUCCESS; + uint8_t ram_save[cpuinfo_length]; + + if (z80_bus_state() & ZST_RUNNING) { + err = ERUNNING; + } else { + z80_bus_request_or_exit(); + z80_read_block(ram_save, 0, cpuinfo_length); + z80_load_mem(0, cpuinfo, + &cpuinfo_sections, + cpuinfo_address, + cpuinfo_length_of_sections); + z80_bus_cmd(Release); + + if (argv[1] && (argv[1][0] == 'n')) + goto donot; + + z80_bus_cmd(Run); + + clear_ctrlc(); /* forget any previous Control C */ + while (done != 0xFF) { + _delay_ms(8); + /* check for ctrl-c to abort... */ + if (had_ctrlc() || ctrlc()) { + err = EINTR; + break; + } + z80_bus_cmd(Request); + done = z80_read(3); + if (done == 0xFF) + cputype = z80_read(4); + z80_bus_cmd(Release); + } + z80_bus_cmd(Reset); + z80_bus_cmd(Request); +// z80_write_block(ram_save, 0, cpuinfo_length); + z80_bus_cmd(Release); + } + +donot: + + if (err) + cmd_error(CMD_RET_FAILURE, err, NULL); + + if (done == 0xFF) { + if (cputype >= ARRAY_SIZE(cpu_strings)) + cputype = 0; + printf_P(PSTR("Detected CPU: %S\n"), cpu_strings[cputype]); + } + + return CMD_RET_SUCCESS; +} diff --git a/avr/command_tbl.c b/avr/command_tbl.c index 5d185ba..9968dc0 100644 --- a/avr/command_tbl.c +++ b/avr/command_tbl.c @@ -8,6 +8,7 @@ #include "command.h" #include "cmd_mem.h" #include "cmd_boot.h" +#include "cmd_cpu.h" #include "cmd_misc.h" #include "cmd_date.h" #include "cmd_run.h" @@ -126,6 +127,11 @@ CMD_TBL_ITEM_TOP( ), CMD_TBL_ITEM( + chkcpu, CONFIG_SYS_MAXARGS, CTBL_RPT, do_cpuchk, + "Check CPU", + "" +), +CMD_TBL_ITEM( loadf, 1, 0, do_loadf, "load srec_cat prepared image from controller flash", "" diff --git a/avr/z80-if.c b/avr/z80-if.c index 180a27f..7a953f0 100644 --- a/avr/z80-if.c +++ b/avr/z80-if.c @@ -506,6 +506,8 @@ int32_t z80_memsize_detect(void) return addr; } +/*--------------------------------------------------------------------------*/ + void z80_write(uint32_t addr, uint8_t data) { z80_setaddress(addr); @@ -605,6 +607,7 @@ void z80_read_block (uint8_t *dest, uint32_t src, size_t length) Z80_O_MREQ = 1; } +/*--------------------------------------------------------------------------*/ /* 0179' rx.bs_mask: ds 1 ; (buf_len - 1) @@ -745,3 +748,31 @@ void z80_memfifo_putc(fifo_t f, uint8_t val) z80_write(fifo_dsc[f].base+FIFO_INDEX_IN, fifo_dsc[f].idx_in); z80_bus_cmd(Release); } + +/*--------------------------------------------------------------------------*/ + +void z80_load_mem(int_fast8_t verbosity, + const FLASH unsigned char data[], + const FLASH unsigned long *sections, + const FLASH unsigned long address[], + const FLASH unsigned long length_of_sections[]) +{ + uint32_t sec_base = 0; + + if (verbosity > 1) + printf_P(PSTR("Loading Z180 memory... \n")); + + for (unsigned sec = 0; sec < *sections; sec++) { + if (verbosity > 0) { + printf_P(PSTR(" From: 0x%.5lX to: 0x%.5lX (%5li bytes)\n"), + address[sec], + address[sec]+length_of_sections[sec] - 1, + length_of_sections[sec]); + } + + z80_write_block_P((const FLASH unsigned char *) &data[sec_base], /* src */ + address[sec], /* dest */ + length_of_sections[sec]); /* len */ + sec_base += length_of_sections[sec]; + } +} |