1 // Copyright 2016 The Fuchsia Authors 2 // Copyright (c) 2008-2009 Travis Geiselbrecht 3 // 4 // Use of this source code is governed by a MIT-style 5 // license that can be found in the LICENSE file or at 6 // https://opensource.org/licenses/MIT 7 8 #pragma once 9 10 #include <stdbool.h> 11 #include <stddef.h> 12 #include <sys/types.h> 13 #include <zircon/compiler.h> 14 15 __BEGIN_CDECLS 16 17 /* command args */ 18 typedef struct { 19 const char* str; 20 unsigned long u; 21 void* p; 22 long i; 23 bool b; 24 } cmd_args; 25 26 typedef int console_cmd(int argc, const cmd_args* argv, uint32_t flags); 27 28 #define CMD_AVAIL_NORMAL (0x1 << 0) 29 #define CMD_AVAIL_PANIC (0x1 << 1) 30 #define CMD_AVAIL_ALWAYS (CMD_AVAIL_NORMAL | CMD_AVAIL_PANIC) 31 32 /* command is happening at crash time */ 33 #define CMD_FLAG_PANIC (0x1 << 0) 34 35 /* a block of commands to register */ 36 typedef struct { 37 const char* cmd_str; 38 const char* help_str; 39 console_cmd* cmd_callback; 40 uint8_t availability_mask; 41 } cmd; 42 43 /* register a static block of commands at init time */ 44 45 /* enable the panic shell if we're being built */ 46 #if !defined(ENABLE_PANIC_SHELL) && PLATFORM_SUPPORTS_PANIC_SHELL 47 #define ENABLE_PANIC_SHELL 1 48 #endif 49 50 #define STATIC_COMMAND_START \ 51 __USED __SECTION(".data.rel.ro.commands") static const cmd _cmd_list[] = { 52 53 #define STATIC_COMMAND_END(name) \ 54 } \ 55 ; 56 57 #define STATIC_COMMAND(command_str, help_str, func) {command_str, help_str, func, CMD_AVAIL_NORMAL}, 58 #define STATIC_COMMAND_MASKED(command_str, help_str, func, availability_mask) {command_str, help_str, func, availability_mask}, 59 60 /* external api */ 61 int console_run_script(const char* string); 62 int console_run_script_locked(const char* string); // special case from inside a command 63 console_cmd* console_get_command_handler(const char* command); 64 void console_abort_script(void); 65 66 /* panic shell api */ 67 void panic_shell_start(void); 68 69 extern int lastresult; 70 71 __END_CDECLS 72