Mercurial > repos > blastem
comparison m68k_core.c @ 1082:2ec5e6eaf81d
Add support for specifying a reset handler in the M68K core. Adjust memory map initialization to handle extra field. Improved handling of out of bounds execution.
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Thu, 06 Oct 2016 09:34:31 -0700 |
parents | 276cd582b728 |
children | c15896605bf2 |
comparison
equal
deleted
inserted
replaced
1081:89cc20cf1ad3 | 1082:2ec5e6eaf81d |
---|---|
41 size_t reg_offset(m68k_op_info *op) | 41 size_t reg_offset(m68k_op_info *op) |
42 { | 42 { |
43 return op->addr_mode == MODE_REG ? dreg_offset(op->params.regs.pri) : areg_offset(op->params.regs.pri); | 43 return op->addr_mode == MODE_REG ? dreg_offset(op->params.regs.pri) : areg_offset(op->params.regs.pri); |
44 } | 44 } |
45 | 45 |
46 void print_regs_exit(m68k_context * context) | 46 void m68k_print_regs(m68k_context * context) |
47 { | 47 { |
48 printf("XNZVC\n%d%d%d%d%d\n", context->flags[0], context->flags[1], context->flags[2], context->flags[3], context->flags[4]); | 48 printf("XNZVC\n%d%d%d%d%d\n", context->flags[0], context->flags[1], context->flags[2], context->flags[3], context->flags[4]); |
49 for (int i = 0; i < 8; i++) { | 49 for (int i = 0; i < 8; i++) { |
50 printf("d%d: %X\n", i, context->dregs[i]); | 50 printf("d%d: %X\n", i, context->dregs[i]); |
51 } | 51 } |
52 for (int i = 0; i < 8; i++) { | 52 for (int i = 0; i < 8; i++) { |
53 printf("a%d: %X\n", i, context->aregs[i]); | 53 printf("a%d: %X\n", i, context->aregs[i]); |
54 } | 54 } |
55 exit(0); | |
56 } | 55 } |
57 | 56 |
58 void m68k_read_size(m68k_options *opts, uint8_t size) | 57 void m68k_read_size(m68k_options *opts, uint8_t size) |
59 { | 58 { |
60 switch (size) | 59 switch (size) |
534 void swap_ssp_usp(m68k_options * opts) | 533 void swap_ssp_usp(m68k_options * opts) |
535 { | 534 { |
536 areg_to_native(opts, 7, opts->gen.scratch2); | 535 areg_to_native(opts, 7, opts->gen.scratch2); |
537 areg_to_native(opts, 8, opts->aregs[7]); | 536 areg_to_native(opts, 8, opts->aregs[7]); |
538 native_to_areg(opts, opts->gen.scratch2, 8); | 537 native_to_areg(opts, opts->gen.scratch2, 8); |
539 } | |
540 | |
541 void translate_m68k_reset(m68k_options *opts, m68kinst *inst) | |
542 { | |
543 code_info *code = &opts->gen.code; | |
544 call(code, opts->gen.save_context); | |
545 call_args(code, (code_ptr)print_regs_exit, 1, opts->gen.context_reg); | |
546 } | 538 } |
547 | 539 |
548 void translate_m68k_rte(m68k_options *opts, m68kinst *inst) | 540 void translate_m68k_rte(m68k_options *opts, m68kinst *inst) |
549 { | 541 { |
550 m68k_trap_if_not_supervisor(opts, inst); | 542 m68k_trap_if_not_supervisor(opts, inst); |
905 } | 897 } |
906 do { | 898 do { |
907 encoded = get_native_pointer(address, (void **)context->mem_pointers, &opts->gen); | 899 encoded = get_native_pointer(address, (void **)context->mem_pointers, &opts->gen); |
908 if (!encoded) { | 900 if (!encoded) { |
909 map_native_address(context, address, code->cur, 2, 1); | 901 map_native_address(context, address, code->cur, 2, 1); |
910 translate_out_of_bounds(code); | 902 translate_out_of_bounds(opts, address); |
911 break; | 903 break; |
912 } | 904 } |
913 code_ptr existing = get_native_address(opts, address); | 905 code_ptr existing = get_native_address(opts, address); |
914 if (existing) { | 906 if (existing) { |
915 jmp(code, existing); | 907 jmp(code, existing); |
1066 free(opts->gen.ram_inst_sizes); | 1058 free(opts->gen.ram_inst_sizes); |
1067 free(opts); | 1059 free(opts); |
1068 } | 1060 } |
1069 | 1061 |
1070 | 1062 |
1071 m68k_context * init_68k_context(m68k_options * opts) | 1063 m68k_context * init_68k_context(m68k_options * opts, m68k_reset_handler reset_handler) |
1072 { | 1064 { |
1073 size_t ctx_size = sizeof(m68k_context) + ram_size(&opts->gen) / (1 << opts->gen.ram_flags_shift) / 8; | 1065 size_t ctx_size = sizeof(m68k_context) + ram_size(&opts->gen) / (1 << opts->gen.ram_flags_shift) / 8; |
1074 m68k_context * context = malloc(ctx_size); | 1066 m68k_context * context = malloc(ctx_size); |
1075 memset(context, 0, ctx_size); | 1067 memset(context, 0, ctx_size); |
1076 context->native_code_map = opts->gen.native_code_map; | 1068 context->native_code_map = opts->gen.native_code_map; |
1077 context->options = opts; | 1069 context->options = opts; |
1078 context->int_cycle = CYCLE_NEVER; | 1070 context->int_cycle = CYCLE_NEVER; |
1079 context->status = 0x27; | 1071 context->status = 0x27; |
1072 context->reset_handler = (code_ptr)reset_handler; | |
1080 return context; | 1073 return context; |
1081 } | 1074 } |