From 3247a29d2adf99f3133625a23d1e941a5036d736 Mon Sep 17 00:00:00 2001 From: Ry Date: Thu, 12 May 2022 15:10:24 -0700 Subject: [PATCH] monitor: Add jump and list commands --- monitor/commands/commands.asm | 12 ++++++ monitor/commands/help.asm | 2 + monitor/commands/jump.asm | 14 +++++++ monitor/commands/list.asm | 69 +++++++++++++++++++++++++++++++++++ monitor/console.asm | 60 ++++++++++++++++++++++++++++++ 5 files changed, 157 insertions(+) create mode 100644 monitor/commands/jump.asm create mode 100644 monitor/commands/list.asm diff --git a/monitor/commands/commands.asm b/monitor/commands/commands.asm index f267e85..70ad765 100644 --- a/monitor/commands/commands.asm +++ b/monitor/commands/commands.asm @@ -14,6 +14,16 @@ monitor_shell_parse_command: call compare_string ifz jmp monitor_shell_help_command + ; jump + mov r1, monitor_shell_jump_command_string + call compare_string + ifz jmp monitor_shell_jump_command + + ; list + mov r1, monitor_shell_list_command_string + call compare_string + ifz jmp monitor_shell_list_command + ; set.8 mov r1, monitor_shell_set8_command_string call compare_string @@ -40,4 +50,6 @@ monitor_shell_invalid_command_string: data.str "invalid command" data.8 10 data. ; all commands #include "monitor/commands/exit.asm" #include "monitor/commands/help.asm" + #include "monitor/commands/jump.asm" + #include "monitor/commands/list.asm" #include "monitor/commands/set.asm" diff --git a/monitor/commands/help.asm b/monitor/commands/help.asm index 3fb8597..dd15cb2 100644 --- a/monitor/commands/help.asm +++ b/monitor/commands/help.asm @@ -12,5 +12,7 @@ monitor_shell_help_text: data.str "------- | -----------" data.8 10 data.str "exit | exit the monitor" data.8 10 data.str "help | display this help text" data.8 10 + data.str "jump | jump to address $0" data.8 10 + data.str "list | list memory contents starting at address $0" data.8 10 data.str "set.SZ | set [$0] to $1; equivalent to `mov.SZ [$0], $1`" data.8 10 data.8 0 diff --git a/monitor/commands/jump.asm b/monitor/commands/jump.asm new file mode 100644 index 0000000..6cad727 --- /dev/null +++ b/monitor/commands/jump.asm @@ -0,0 +1,14 @@ +; jump command + +monitor_shell_jump_command_string: data.str "jump" data.8 0 + +monitor_shell_jump_command: + call monitor_shell_parse_arguments + mov r1, 16 + call string_to_int + + ; r0: address + + call r0 + + ret diff --git a/monitor/commands/list.asm b/monitor/commands/list.asm new file mode 100644 index 0000000..5fba87e --- /dev/null +++ b/monitor/commands/list.asm @@ -0,0 +1,69 @@ +; list command + +monitor_shell_list_command_string: data.str "list" data.8 0 + +monitor_shell_list_command: + mov r0, monitor_shell_list_text + call print_string_to_monitor + + call monitor_shell_parse_arguments + mov r1, 16 + call string_to_int + + ; r0: starting address + + mov r10, r0 + mov r31, 16 ; line counter +monitor_shell_list_command_line_loop: + mov r30, 16 ; byte counter, 16 bytes per line + ; print current address + mov r0, r10 + call print_hex_word_to_monitor + mov r0, ' ' + call print_character_to_monitor + mov r0, '|' + call print_character_to_monitor + mov r0, ' ' + call print_character_to_monitor +monitor_shell_list_command_byte_loop: + movz.8 r0, [r10] + call print_hex_byte_to_monitor + mov r0, ' ' + call print_character_to_monitor + inc r10 + dec r30 + ifnz jmp monitor_shell_list_command_byte_loop + + mov r0, '|' + call print_character_to_monitor + mov r0, ' ' + call print_character_to_monitor + + mov r29, 16 + sub r10, 16 +monitor_shell_list_command_ascii_loop: + movz.8 r0, [r10] + cmp r0, ' ' + iflt jmp monitor_shell_list_command_ascii_loop_skip_char + cmp r0, '~' + ifgt jmp monitor_shell_list_command_ascii_loop_skip_char + + call print_character_to_monitor + inc r10 + dec r29 + ifnz jmp monitor_shell_list_command_ascii_loop + jmp monitor_shell_list_command_ascii_loop_done +monitor_shell_list_command_ascii_loop_skip_char: + mov r0, '.' + call print_character_to_monitor + inc r10 + dec r29 + ifnz jmp monitor_shell_list_command_ascii_loop +monitor_shell_list_command_ascii_loop_done: + mov r0, 10 + call print_character_to_monitor + loop monitor_shell_list_command_line_loop + + ret + +monitor_shell_list_text: data.str "address | x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xA xB xC xD xE xF | ASCII" data.8 10 data.8 0 diff --git a/monitor/console.asm b/monitor/console.asm index 48eade4..91952b5 100644 --- a/monitor/console.asm +++ b/monitor/console.asm @@ -19,6 +19,66 @@ print_string_to_monitor_loop: pop r0 ret +; print a hex word to the monitor +; inputs: +; r0: value +; outputs: +print_hex_word_to_monitor: + push r10 + push r11 + push r12 + push r31 + + mov r10, r0 + mov r31, 8 +print_hex_word_to_monitor_loop: + rol r10, 4 + movz.16 r11, r10 + and r11, 0x0F + mov r12, draw_hex_generic_characters + add r12, r11 + movz.8 r0, [r12] + call print_character_to_monitor + add r1, r6 + loop print_hex_word_to_monitor_loop + call redraw_monitor_console_line + + pop r31 + pop r12 + pop r11 + pop r10 + ret + +; print a hex byte to the monitor +; inputs: +; r0: value +; outputs: +print_hex_byte_to_monitor: + push r10 + push r11 + push r12 + push r31 + + movz.8 r10, r0 + mov r31, 2 +print_hex_byte_to_monitor_loop: + rol.8 r10, 4 + movz.16 r11, r10 + and r11, 0x0F + mov r12, draw_hex_generic_characters + add r12, r11 + movz.8 r0, [r12] + call print_character_to_monitor + add r1, r6 + loop print_hex_byte_to_monitor_loop + call redraw_monitor_console_line + + pop r31 + pop r12 + pop r11 + pop r10 + ret + ; print a single character to the monitor ; inputs: ; r0: character