///////////////////////////////////////////////////////////////////////// // $Id: parser.y,v 1.21 2007-09-23 21:10:06 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// %{ #include #include #include "debug.h" #if BX_DEBUGGER %} %union { char *sval; Bit64u uval; bx_bool bval; } // Common registers %type BX_TOKEN_NONSEG_REG %type BX_TOKEN_SEGREG %type BX_TOKEN_TOGGLE_ON_OFF %token BX_TOKEN_8BH_REG %token BX_TOKEN_8BL_REG %token BX_TOKEN_16B_REG %token BX_TOKEN_32B_REG %token BX_TOKEN_64B_REG %token BX_TOKEN_CS %token BX_TOKEN_ES %token BX_TOKEN_SS %token BX_TOKEN_DS %token BX_TOKEN_FS %token BX_TOKEN_GS %token BX_TOKEN_FLAGS %token BX_TOKEN_ON %token BX_TOKEN_OFF %token BX_TOKEN_CONTINUE %token BX_TOKEN_STEPN %token BX_TOKEN_STEP_OVER %token BX_TOKEN_NEXT_STEP %token BX_TOKEN_SET %token BX_TOKEN_DEBUGGER %token BX_TOKEN_LIST_BREAK %token BX_TOKEN_VBREAKPOINT %token BX_TOKEN_LBREAKPOINT %token BX_TOKEN_PBREAKPOINT %token BX_TOKEN_DEL_BREAKPOINT %token BX_TOKEN_ENABLE_BREAKPOINT %token BX_TOKEN_DISABLE_BREAKPOINT %token BX_TOKEN_INFO %token BX_TOKEN_QUIT %token BX_TOKEN_REGISTERS %token BX_TOKEN_CPU %token BX_TOKEN_FPU %token BX_TOKEN_SSE %token BX_TOKEN_ALL %token BX_TOKEN_IDT %token BX_TOKEN_IVT %token BX_TOKEN_GDT %token BX_TOKEN_LDT %token BX_TOKEN_TSS %token BX_TOKEN_TAB %token BX_TOKEN_DIRTY %token BX_TOKEN_LINUX %token BX_TOKEN_CONTROL_REGS %token BX_TOKEN_EXAMINE %token BX_TOKEN_XFORMAT %token BX_TOKEN_DISFORMAT %token BX_TOKEN_SETPMEM %token BX_TOKEN_SYMBOLNAME %token BX_TOKEN_QUERY %token BX_TOKEN_PENDING %token BX_TOKEN_TAKE %token BX_TOKEN_DMA %token BX_TOKEN_IRQ %token BX_TOKEN_DUMP_CPU %token BX_TOKEN_SET_CPU %token BX_TOKEN_DISASSEMBLE %token BX_TOKEN_INSTRUMENT %token BX_TOKEN_STRING %token BX_TOKEN_STOP %token BX_TOKEN_DOIT %token BX_TOKEN_CRC %token BX_TOKEN_TRACE %token BX_TOKEN_TRACEREG %token BX_TOKEN_SWITCH_MODE %token BX_TOKEN_SIZE %token BX_TOKEN_PTIME %token BX_TOKEN_TIMEBP_ABSOLUTE %token BX_TOKEN_TIMEBP %token BX_TOKEN_RECORD %token BX_TOKEN_PLAYBACK %token BX_TOKEN_MODEBP %token BX_TOKEN_PRINT_STACK %token BX_TOKEN_WATCH %token BX_TOKEN_UNWATCH %token BX_TOKEN_READ %token BX_TOKEN_WRITE %token BX_TOKEN_SHOW %token BX_TOKEN_LOAD_SYMBOLS %token BX_TOKEN_SYMBOLS %token BX_TOKEN_LIST_SYMBOLS %token BX_TOKEN_GLOBAL %token BX_TOKEN_WHERE %token BX_TOKEN_PRINT_STRING %token BX_TOKEN_NUMERIC %token BX_TOKEN_NE2000 %token BX_TOKEN_PIC %token BX_TOKEN_PAGE %token BX_TOKEN_HELP %token BX_TOKEN_CALC %token BX_TOKEN_VGA %token BX_TOKEN_COMMAND %token BX_TOKEN_GENERIC %token BX_TOKEN_RSHIFT %token BX_TOKEN_LSHIFT %token BX_TOKEN_REG_IP %token BX_TOKEN_REG_EIP %token BX_TOKEN_REG_RIP %type optional_numeric %type vexpression %type expression %left '+' '-' '|' '^' %left '*' '/' '&' BX_TOKEN_LSHIFT BX_TOKEN_RSHIFT %left NOT NEG %start commands %% commands: commands command | command ; command: continue_command | stepN_command | step_over_command | set_command | breakpoint_command | info_command | regs_command | blist_command | slist_command | dump_cpu_command | delete_command | bpe_command | bpd_command | quit_command | examine_command | setpmem_command | query_command | take_command | set_cpu_command | disassemble_command | instrument_command | doit_command | crc_command | trace_command | trace_reg_command | ptime_command | timebp_command | record_command | playback_command | modebp_command | print_stack_command | watch_point_command | page_command | show_command | symbol_command | where_command | print_string_command | help_command | calc_command | | '\n' { } ; BX_TOKEN_TOGGLE_ON_OFF: BX_TOKEN_ON | BX_TOKEN_OFF { $$=$1; } ; BX_TOKEN_SEGREG: BX_TOKEN_CS | BX_TOKEN_ES | BX_TOKEN_SS | BX_TOKEN_DS | BX_TOKEN_FS | BX_TOKEN_GS { $$=$1; } ; timebp_command: BX_TOKEN_TIMEBP BX_TOKEN_NUMERIC '\n' { bx_dbg_timebp_command(0, $2); free($1); } | BX_TOKEN_TIMEBP_ABSOLUTE BX_TOKEN_NUMERIC '\n' { bx_dbg_timebp_command(1, $2); free($1); } ; record_command: BX_TOKEN_RECORD BX_TOKEN_STRING '\n' { bx_dbg_record_command($2); free($1); free($2); } ; playback_command: BX_TOKEN_PLAYBACK BX_TOKEN_STRING '\n' { bx_dbg_playback_command($2); free($1); free($2); } ; modebp_command: BX_TOKEN_MODEBP '\n' { bx_dbg_modebp_command(); free($1); } ; show_command: BX_TOKEN_SHOW BX_TOKEN_COMMAND '\n' { bx_dbg_show_command($2); free($1); free($2); } | BX_TOKEN_SHOW BX_TOKEN_STRING '\n' { bx_dbg_show_param_command($2); free($1); free($2); } | BX_TOKEN_SHOW '\n' { bx_dbg_show_command(0); free($1); } ; page_command: BX_TOKEN_PAGE BX_TOKEN_NUMERIC '\n' { bx_dbg_xlate_address($2); free($1); } ; ptime_command: BX_TOKEN_PTIME '\n' { bx_dbg_ptime_command(); free($1); } ; trace_command: BX_TOKEN_TRACE BX_TOKEN_TOGGLE_ON_OFF '\n' { bx_dbg_trace_command($2); free($1); } ; trace_reg_command: BX_TOKEN_TRACEREG BX_TOKEN_TOGGLE_ON_OFF '\n' { bx_dbg_trace_reg_command($2); free($1); } ; print_stack_command: BX_TOKEN_PRINT_STACK '\n' { bx_dbg_print_stack_command(16); free($1); } | BX_TOKEN_PRINT_STACK BX_TOKEN_NUMERIC '\n' { bx_dbg_print_stack_command($2); free($1); } ; watch_point_command: BX_TOKEN_WATCH BX_TOKEN_STOP '\n' { watchpoint_continue = 0; dbg_printf("Will stop on watch points\n"); free($1); free($2); } | BX_TOKEN_WATCH BX_TOKEN_CONTINUE '\n' { watchpoint_continue = 1; dbg_printf("Will not stop on watch points (they will still be logged)\n"); free($1); free($2); } | BX_TOKEN_WATCH '\n' { bx_dbg_watch(-1, 0); free($1); } | BX_TOKEN_UNWATCH '\n' { bx_dbg_unwatch(-1, 0); free($1); } | BX_TOKEN_WATCH BX_TOKEN_READ BX_TOKEN_NUMERIC '\n' { bx_dbg_watch(1, $3); free($1); free($2); } | BX_TOKEN_UNWATCH BX_TOKEN_READ BX_TOKEN_NUMERIC '\n' { bx_dbg_unwatch(1, $3); free($1); free($2); } | BX_TOKEN_WATCH BX_TOKEN_WRITE BX_TOKEN_NUMERIC '\n' { bx_dbg_watch(0, $3); free($1); free($2); } | BX_TOKEN_UNWATCH BX_TOKEN_WRITE BX_TOKEN_NUMERIC '\n' { bx_dbg_unwatch(0, $3); free($1); free($2); } ; symbol_command: BX_TOKEN_LOAD_SYMBOLS BX_TOKEN_STRING '\n' { bx_dbg_symbol_command($2, 0, 0); free($1); free($2); } | BX_TOKEN_LOAD_SYMBOLS BX_TOKEN_STRING BX_TOKEN_NUMERIC '\n' { bx_dbg_symbol_command($2, 0, $3); free($1); free($2); } | BX_TOKEN_LOAD_SYMBOLS BX_TOKEN_GLOBAL BX_TOKEN_STRING BX_TOKEN_NUMERIC '\n' { bx_dbg_symbol_command($3, 1, $4); free($1); free($2); free($3); } ; where_command: BX_TOKEN_WHERE '\n' { bx_dbg_where_command(); free($1); } ; print_string_command: BX_TOKEN_PRINT_STRING BX_TOKEN_NUMERIC '\n' { bx_dbg_print_string_command($2); free($1); } ; continue_command: BX_TOKEN_CONTINUE '\n' { bx_dbg_continue_command(); free($1); } ; stepN_command: BX_TOKEN_STEPN '\n' { bx_dbg_stepN_command(1); free($1); } | BX_TOKEN_STEPN BX_TOKEN_NUMERIC '\n' { bx_dbg_stepN_command($2); free($1); } ; step_over_command: BX_TOKEN_STEP_OVER '\n' { bx_dbg_step_over_command(); free($1); } ; set_command: BX_TOKEN_SET BX_TOKEN_DISASSEMBLE BX_TOKEN_TOGGLE_ON_OFF '\n' { bx_dbg_set_auto_disassemble($3); free($1); free($2); } | BX_TOKEN_SET BX_TOKEN_SYMBOLNAME '=' BX_TOKEN_NUMERIC '\n' { bx_dbg_set_symbol_command($2, $4); free($1); free($2); } | BX_TOKEN_SET BX_TOKEN_8BL_REG '=' expression '\n' { bx_dbg_set_reg8l_value($2, $4); } | BX_TOKEN_SET BX_TOKEN_8BH_REG '=' expression '\n' { bx_dbg_set_reg8h_value($2, $4); } | BX_TOKEN_SET BX_TOKEN_16B_REG '=' expression '\n' { bx_dbg_set_reg16_value($2, $4); } | BX_TOKEN_SET BX_TOKEN_32B_REG '=' expression '\n' { bx_dbg_set_reg32_value($2, $4); } | BX_TOKEN_SET BX_TOKEN_64B_REG '=' expression '\n' { bx_dbg_set_reg64_value($2, $4); } ; breakpoint_command: BX_TOKEN_VBREAKPOINT '\n' { bx_dbg_vbreakpoint_command(bkAtIP, 0, 0); free($1); } | BX_TOKEN_VBREAKPOINT vexpression ':' vexpression '\n' { bx_dbg_vbreakpoint_command(bkRegular, $2, $4); free($1); } | BX_TOKEN_LBREAKPOINT '\n' { bx_dbg_lbreakpoint_command(bkAtIP, 0); free($1); } | BX_TOKEN_LBREAKPOINT expression '\n' { bx_dbg_lbreakpoint_command(bkRegular, $2); free($1); } | BX_TOKEN_LBREAKPOINT BX_TOKEN_STRING '\n' { bx_dbg_lbreakpoint_symbol_command($2); free($1);free($2); } | BX_TOKEN_PBREAKPOINT '\n' { bx_dbg_pbreakpoint_command(bkAtIP, 0); free($1); } | BX_TOKEN_PBREAKPOINT expression '\n' { bx_dbg_pbreakpoint_command(bkRegular, $2); free($1); } | BX_TOKEN_PBREAKPOINT '*' expression '\n' { bx_dbg_pbreakpoint_command(bkRegular, $3); free($1); } ; blist_command: BX_TOKEN_LIST_BREAK '\n' { bx_dbg_info_bpoints_command(); free($1); } ; slist_command: BX_TOKEN_LIST_SYMBOLS '\n' { bx_dbg_info_symbols_command(0); free($1); } | BX_TOKEN_LIST_SYMBOLS BX_TOKEN_STRING '\n' { bx_dbg_info_symbols_command($2); free($1);free($2); } ; info_command: BX_TOKEN_INFO BX_TOKEN_PBREAKPOINT '\n' { bx_dbg_info_bpoints_command(); free($1); free($2); } | BX_TOKEN_INFO BX_TOKEN_CPU '\n' { bx_dbg_dump_cpu_command(); free($1); free($2); } | BX_TOKEN_INFO BX_TOKEN_REGISTERS '\n' { bx_dbg_info_registers_command(BX_INFO_CPU_REGS); free($1); free($2); } | BX_TOKEN_INFO BX_TOKEN_FPU '\n' { bx_dbg_info_registers_command(BX_INFO_FPU_REGS); free($1); free($2); } | BX_TOKEN_INFO BX_TOKEN_SSE '\n' { bx_dbg_info_registers_command(BX_INFO_SSE_REGS); free($1); free($2); } | BX_TOKEN_INFO BX_TOKEN_ALL '\n' { bx_dbg_info_registers_command(BX_INFO_CPU_REGS | BX_INFO_FPU_REGS | BX_INFO_SSE_REGS); free($1); free($2); } | BX_TOKEN_INFO BX_TOKEN_DIRTY '\n' { bx_dbg_info_dirty_command(); free($1); free($2); } | BX_TOKEN_INFO BX_TOKEN_IDT optional_numeric optional_numeric '\n' { bx_dbg_info_idt_command($3, $4); free($1); free($2); } | BX_TOKEN_INFO BX_TOKEN_IVT optional_numeric optional_numeric '\n' { bx_dbg_info_ivt_command($3, $4); free($1); free($2); } | BX_TOKEN_INFO BX_TOKEN_GDT optional_numeric optional_numeric '\n' { bx_dbg_info_gdt_command($3, $4); free($1); free($2); } | BX_TOKEN_INFO BX_TOKEN_LDT optional_numeric optional_numeric '\n' { bx_dbg_info_ldt_command($3, $4); free($1); free($2); } | BX_TOKEN_INFO BX_TOKEN_TAB '\n' { bx_dbg_dump_table(); free($1); free($2); } | BX_TOKEN_INFO BX_TOKEN_TSS '\n' { bx_dbg_info_tss_command(); free($1); free($2); } | BX_TOKEN_INFO BX_TOKEN_FLAGS '\n' { bx_dbg_info_flags(); free($1); } | BX_TOKEN_INFO BX_TOKEN_LINUX '\n' { bx_dbg_info_linux_command(); free($1); free($2); } | BX_TOKEN_INFO BX_TOKEN_SYMBOLS '\n' { bx_dbg_info_symbols_command(0); free($1); free($2); } | BX_TOKEN_INFO BX_TOKEN_SYMBOLS BX_TOKEN_STRING '\n' { bx_dbg_info_symbols_command($3); free($1); free($2); free($3); } | BX_TOKEN_INFO BX_TOKEN_CONTROL_REGS '\n' { bx_dbg_info_control_regs_command(); free($1); free($2); } | BX_TOKEN_INFO BX_TOKEN_NE2000 '\n' { bx_dbg_info_ne2k(-1, -1); free($1); free($2); } | BX_TOKEN_INFO BX_TOKEN_NE2000 BX_TOKEN_PAGE BX_TOKEN_NUMERIC '\n' { free($1); free($2); free($3); bx_dbg_info_ne2k($4, -1); } | BX_TOKEN_INFO BX_TOKEN_NE2000 BX_TOKEN_PAGE BX_TOKEN_NUMERIC BX_TOKEN_REGISTERS BX_TOKEN_NUMERIC '\n' { free($1); free($2); free($3); free($5); bx_dbg_info_ne2k($4, $6); } | BX_TOKEN_INFO BX_TOKEN_PIC '\n' { bx_dbg_info_pic(); free($1); free($2); } | BX_TOKEN_INFO BX_TOKEN_VGA '\n' { bx_dbg_info_vga(); free($1); free($2); } ; optional_numeric : /* empty */ { $$ = EMPTY_ARG; } | BX_TOKEN_NUMERIC; regs_command: BX_TOKEN_REGISTERS '\n' { bx_dbg_info_registers_command(BX_INFO_CPU_REGS); free($1); } ; dump_cpu_command: BX_TOKEN_DUMP_CPU '\n' { bx_dbg_dump_cpu_command(); free($1); } ; delete_command: BX_TOKEN_DEL_BREAKPOINT BX_TOKEN_NUMERIC '\n' { bx_dbg_del_breakpoint_command($2); free($1); } ; bpe_command: BX_TOKEN_ENABLE_BREAKPOINT BX_TOKEN_NUMERIC '\n' { bx_dbg_en_dis_breakpoint_command($2, 1); free($1); } ; bpd_command: BX_TOKEN_DISABLE_BREAKPOINT BX_TOKEN_NUMERIC '\n' { bx_dbg_en_dis_breakpoint_command($2, 0); free($1); } ; quit_command: BX_TOKEN_QUIT '\n' { bx_dbg_quit_command(); free($1); } ; examine_command: BX_TOKEN_EXAMINE BX_TOKEN_XFORMAT expression '\n' { bx_dbg_examine_command($1, $2,1, $3, 1); free($1); free($2); } | BX_TOKEN_EXAMINE BX_TOKEN_XFORMAT '\n' { bx_dbg_examine_command($1, $2,1, 0, 0); free($1); free($2); } | BX_TOKEN_EXAMINE expression '\n' { bx_dbg_examine_command($1, NULL,0, $2, 1); free($1); } | BX_TOKEN_EXAMINE '\n' { bx_dbg_examine_command($1, NULL,0, 0, 0); free($1); } ; setpmem_command: BX_TOKEN_SETPMEM BX_TOKEN_NUMERIC BX_TOKEN_NUMERIC BX_TOKEN_NUMERIC '\n' { bx_dbg_setpmem_command($2, $3, $4); free($1); } ; query_command: BX_TOKEN_QUERY BX_TOKEN_PENDING '\n' { bx_dbg_query_command($2); free($1); free($2); } ; take_command: BX_TOKEN_TAKE BX_TOKEN_DMA '\n' { bx_dbg_take_command($2, 1); free($1); free($2); } | BX_TOKEN_TAKE BX_TOKEN_DMA BX_TOKEN_NUMERIC '\n' { bx_dbg_take_command($2, $3); free($1); free($2); } | BX_TOKEN_TAKE BX_TOKEN_IRQ '\n' { bx_dbg_take_command($2, 1); free($1); free($2); } ; set_cpu_command: BX_TOKEN_SET_CPU '\n' { bx_dbg_set_cpu_command(); free($1); } ; disassemble_command: BX_TOKEN_DISASSEMBLE '\n' { bx_dbg_disassemble_current(NULL); free($1); } | BX_TOKEN_DISASSEMBLE expression '\n' { bx_dbg_disassemble_command(NULL, $2, $2); free($1); } | BX_TOKEN_DISASSEMBLE expression expression '\n' { bx_dbg_disassemble_command(NULL, $2, $3); free($1); } | BX_TOKEN_DISASSEMBLE BX_TOKEN_DISFORMAT '\n' { bx_dbg_disassemble_current($2); free($1); free($2); } | BX_TOKEN_DISASSEMBLE BX_TOKEN_DISFORMAT expression '\n' { bx_dbg_disassemble_command($2, $3, $3); free($1); free($2); } | BX_TOKEN_DISASSEMBLE BX_TOKEN_DISFORMAT expression expression '\n' { bx_dbg_disassemble_command($2, $3, $4); free($1); free($2); } | BX_TOKEN_DISASSEMBLE BX_TOKEN_SWITCH_MODE '\n' { bx_dbg_disassemble_switch_mode(); free($1); free($2); } | BX_TOKEN_DISASSEMBLE BX_TOKEN_SIZE '=' BX_TOKEN_NUMERIC '\n' { bx_dbg_set_disassemble_size($4); free($1); free($2); } ; instrument_command: BX_TOKEN_INSTRUMENT BX_TOKEN_STOP '\n' { bx_dbg_instrument_command($2); free($1); free($2); } | BX_TOKEN_INSTRUMENT BX_TOKEN_COMMAND '\n' { bx_dbg_instrument_command($2); free($1); free($2); } ; doit_command: BX_TOKEN_DOIT BX_TOKEN_NUMERIC '\n' { bx_dbg_doit_command($2); free($1); } ; crc_command: BX_TOKEN_CRC BX_TOKEN_NUMERIC BX_TOKEN_NUMERIC '\n' { bx_dbg_crc_command($2, $3); free($1); } ; help_command: BX_TOKEN_HELP BX_TOKEN_QUIT '\n' { dbg_printf("q|quit|exit - quit debugger and emulator execution\n"); free($1);free($2); } | BX_TOKEN_HELP BX_TOKEN_CONTINUE '\n' { dbg_printf("c|cont|continue - continue executing\n"); free($1);free($2); } | BX_TOKEN_HELP BX_TOKEN_STEPN '\n' { dbg_printf("s|step|stepi [count] - execute #count instructions (default is one instruction)\n"); free($1);free($2); } | BX_TOKEN_HELP BX_TOKEN_STEP_OVER '\n' { dbg_printf("n|next|p - execute instruction stepping over subroutines\n"); free($1);free($2); } | BX_TOKEN_HELP BX_TOKEN_VBREAKPOINT '\n' { dbg_printf("vb|vbreak - set a virtual address instruction breakpoint\n"); free($1);free($2); } | BX_TOKEN_HELP BX_TOKEN_LBREAKPOINT '\n' { dbg_printf("lb|lbreak - set a linear address instruction breakpoint\n"); free($1);free($2); } | BX_TOKEN_HELP BX_TOKEN_PBREAKPOINT '\n' { dbg_printf("p|pb|break|pbreak - set a physical address instruction breakpoint\n"); free($1);free($2); } | BX_TOKEN_HELP BX_TOKEN_DEL_BREAKPOINT '\n' { dbg_printf("d|del|delete - delete a breakpoint\n"); free($1);free($2); } | BX_TOKEN_HELP BX_TOKEN_ENABLE_BREAKPOINT '\n' { dbg_printf("bpe - enable a breakpoint\n"); free($1);free($2); } | BX_TOKEN_HELP BX_TOKEN_DISABLE_BREAKPOINT '\n' { dbg_printf("bpd - disable a breakpoint\n"); free($1);free($2); } | BX_TOKEN_HELP BX_TOKEN_LIST_BREAK '\n' { dbg_printf("blist - list all breakpoints (same as 'info break')\n"); free($1);free($2); } | BX_TOKEN_HELP BX_TOKEN_MODEBP '\n' { dbg_printf("modebp - toggles mode switch breakpoint\n"); free($1);free($2); } | BX_TOKEN_HELP BX_TOKEN_CRC '\n' { dbg_printf("crc - show CRC32 for physical memory range addr1..addr2\n"); free($1);free($2); } | BX_TOKEN_HELP BX_TOKEN_TRACE '\n' { dbg_printf("trace on - print disassembly for every executed instruction\n"); dbg_printf("trace off - disable instruction tracing\n"); free($1);free($2); } | BX_TOKEN_HELP BX_TOKEN_TRACEREG '\n' { dbg_printf("trace-reg on - print all registers before every executed instruction\n"); dbg_printf("trace-reg off - disable registers state tracing\n"); free($1);free($2); } | BX_TOKEN_HELP BX_TOKEN_DUMP_CPU '\n' { dbg_printf("dump_cpu - dump complete cpu state\n"); free($1);free($2); } | BX_TOKEN_HELP BX_TOKEN_SET_CPU '\n' { dbg_printf("set_cpu - set complete cpu state\n"); free($1);free($2); } | BX_TOKEN_HELP BX_TOKEN_PTIME '\n' { dbg_printf("ptime - print current time (number of ticks since start of simulation)\n"); free($1);free($2); } | BX_TOKEN_HELP BX_TOKEN_TIMEBP '\n' { dbg_printf("sb - insert a time breakpoint delta instructions into the future\n"); free($1);free($2); } | BX_TOKEN_HELP BX_TOKEN_TIMEBP_ABSOLUTE '\n' { dbg_printf("sba