comparison debug.c @ 2499:d74d3998482c

Make some progress on compiling full emulator with new 68K core
author Michael Pavone <pavone@retrodev.com>
date Tue, 30 Apr 2024 00:02:14 -0700
parents cb62730d5c99
children d44fe974fb85
comparison
equal deleted inserted replaced
2498:dffda054d218 2499:d74d3998482c
1533 } 1533 }
1534 1534
1535 static uint8_t m68k_read_byte(uint32_t address, m68k_context *context) 1535 static uint8_t m68k_read_byte(uint32_t address, m68k_context *context)
1536 { 1536 {
1537 //TODO: share this implementation with GDB debugger 1537 //TODO: share this implementation with GDB debugger
1538 return read_byte(address, (void **)context->mem_pointers, &context->options->gen, context); 1538 return read_byte(address, (void **)context->mem_pointers, &context->opts->gen, context);
1539 } 1539 }
1540 1540
1541 static uint16_t m68k_read_word(uint32_t address, m68k_context *context) 1541 static uint16_t m68k_read_word(uint32_t address, m68k_context *context)
1542 { 1542 {
1543 return read_word(address, (void **)context->mem_pointers, &context->options->gen, context); 1543 return read_word(address, (void **)context->mem_pointers, &context->opts->gen, context);
1544 } 1544 }
1545 1545
1546 static uint32_t m68k_read_long(uint32_t address, m68k_context *context) 1546 static uint32_t m68k_read_long(uint32_t address, m68k_context *context)
1547 { 1547 {
1548 return m68k_read_word(address, context) << 16 | m68k_read_word(address + 2, context); 1548 return m68k_read_word(address, context) << 16 | m68k_read_word(address + 2, context);
1571 1571
1572 static uint8_t write_m68k(debug_root *root, uint32_t address, uint32_t value, char size) 1572 static uint8_t write_m68k(debug_root *root, uint32_t address, uint32_t value, char size)
1573 { 1573 {
1574 m68k_context *context = root->cpu_context; 1574 m68k_context *context = root->cpu_context;
1575 if (size == 'b') { 1575 if (size == 'b') {
1576 write_byte(address, value, (void **)context->mem_pointers, &context->options->gen, context); 1576 write_byte(address, value, (void **)context->mem_pointers, &context->opts->gen, context);
1577 } else if (size == 'l') { 1577 } else if (size == 'l') {
1578 if (address & 1) { 1578 if (address & 1) {
1579 fprintf(stderr, "Longword access to odd addresses ($%X) is not allowed\n", address); 1579 fprintf(stderr, "Longword access to odd addresses ($%X) is not allowed\n", address);
1580 return 0; 1580 return 0;
1581 } 1581 }
1582 write_word(address, value >> 16, (void **)context->mem_pointers, &context->options->gen, context); 1582 write_word(address, value >> 16, (void **)context->mem_pointers, &context->opts->gen, context);
1583 write_word(address + 2, value, (void **)context->mem_pointers, &context->options->gen, context); 1583 write_word(address + 2, value, (void **)context->mem_pointers, &context->opts->gen, context);
1584 } else { 1584 } else {
1585 if (address & 1) { 1585 if (address & 1) {
1586 fprintf(stderr, "Wword access to odd addresses ($%X) is not allowed\n", address); 1586 fprintf(stderr, "Wword access to odd addresses ($%X) is not allowed\n", address);
1587 return 0; 1587 return 0;
1588 } 1588 }
1589 write_word(address, value, (void **)context->mem_pointers, &context->options->gen, context); 1589 write_word(address, value, (void **)context->mem_pointers, &context->opts->gen, context);
1590 } 1590 }
1591 return 1; 1591 return 1;
1592 } 1592 }
1593 1593
1594 static debug_val m68k_dreg_get(debug_var *var) 1594 static debug_val m68k_dreg_get(debug_var *var)
1653 } 1653 }
1654 1654
1655 static debug_val m68k_cycle_get(debug_var *var) 1655 static debug_val m68k_cycle_get(debug_var *var)
1656 { 1656 {
1657 m68k_context *context = var->ptr; 1657 m68k_context *context = var->ptr;
1658 return debug_int(context->current_cycle); 1658 return debug_int(context->cycles);
1659 } 1659 }
1660 1660
1661 static debug_val m68k_usp_get(debug_var *var) 1661 static debug_val m68k_usp_get(debug_var *var)
1662 { 1662 {
1663 m68k_context *context = var->ptr; 1663 m68k_context *context = var->ptr;
3587 debugging = run_command(root, (*this_bp)->commands + i); 3587 debugging = run_command(root, (*this_bp)->commands + i);
3588 } 3588 }
3589 if (debugging) { 3589 if (debugging) {
3590 printf("VDP Register Breakpoint %d hit on register write $%X - Old: $%X, New: $%X\n", (*this_bp)->index, reg, context->regs[reg], value); 3590 printf("VDP Register Breakpoint %d hit on register write $%X - Old: $%X, New: $%X\n", (*this_bp)->index, reg, context->regs[reg], value);
3591 gen->header.enter_debugger = 1; 3591 gen->header.enter_debugger = 1;
3592 if (gen->m68k->sync_cycle > gen->m68k->current_cycle + 1) { 3592 if (gen->m68k->sync_cycle > gen->m68k->cycles + 1) {
3593 gen->m68k->sync_cycle = gen->m68k->current_cycle + 1; 3593 gen->m68k->sync_cycle = gen->m68k->cycles + 1;
3594 } 3594 }
3595 if (gen->m68k->target_cycle > gen->m68k->sync_cycle) { 3595 if (gen->m68k->target_cycle > gen->m68k->sync_cycle) {
3596 gen->m68k->target_cycle = gen->m68k->sync_cycle; 3596 gen->m68k->target_cycle = gen->m68k->sync_cycle;
3597 } 3597 }
3598 } 3598 }
3744 m68k_context *context = root->cpu_context; 3744 m68k_context *context = root->cpu_context;
3745 uint32_t stack = context->aregs[7]; 3745 uint32_t stack = context->aregs[7];
3746 uint8_t non_adr_count = 0; 3746 uint8_t non_adr_count = 0;
3747 do { 3747 do {
3748 uint32_t bt_address = m68k_instruction_fetch(stack, context); 3748 uint32_t bt_address = m68k_instruction_fetch(stack, context);
3749 bt_address = get_instruction_start(context->options, bt_address - 2); 3749 bt_address = get_instruction_start(context->opts, bt_address - 2);
3750 if (bt_address) { 3750 if (bt_address) {
3751 stack += 4; 3751 stack += 4;
3752 non_adr_count = 0; 3752 non_adr_count = 0;
3753 m68kinst inst; 3753 m68kinst inst;
3754 char buf[128]; 3754 char buf[128];
4802 } 4802 }
4803 4803
4804 static uint32_t m68k_chunk_end(debug_root *root, uint32_t start_address) 4804 static uint32_t m68k_chunk_end(debug_root *root, uint32_t start_address)
4805 { 4805 {
4806 m68k_context *m68k = root->cpu_context; 4806 m68k_context *m68k = root->cpu_context;
4807 memmap_chunk const *chunk = find_map_chunk(start_address, &m68k->options->gen, 0, NULL); 4807 memmap_chunk const *chunk = find_map_chunk(start_address, &m68k->opts->gen, 0, NULL);
4808 if (!chunk) { 4808 if (!chunk) {
4809 return start_address; 4809 return start_address;
4810 } 4810 }
4811 if (chunk->mask == m68k->options->gen.address_mask) { 4811 if (chunk->mask == m68k->opts->gen.address_mask) {
4812 return chunk->end; 4812 return chunk->end;
4813 } 4813 }
4814 return (start_address & ~chunk->mask) + chunk->mask + 1; 4814 return (start_address & ~chunk->mask) + chunk->mask + 1;
4815 } 4815 }
4816 4816
5380 char input_buf[1024]; 5380 char input_buf[1024];
5381 m68kinst inst; 5381 m68kinst inst;
5382 5382
5383 init_terminal(); 5383 init_terminal();
5384 5384
5385 context->options->sync_components(context, 0); 5385 context->opts->sync_components(context, 0);
5386 debug_root *root = find_m68k_root(context); 5386 debug_root *root = find_m68k_root(context);
5387 if (!root) { 5387 if (!root) {
5388 return; 5388 return;
5389 } 5389 }
5390 //probably not necessary, but let's play it safe 5390 //probably not necessary, but let's play it safe