Skip to content

Commit

Permalink
Remove faulty assumption, do not assert on scsi read, fix faulty erro…
Browse files Browse the repository at this point in the history
…r report line
  • Loading branch information
Spritetm committed Jun 26, 2024
1 parent 2640e5a commit fc1028e
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion csr.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ unsigned int csr_read32(void *obj, unsigned int a) {
unsigned int csr_read8(void *obj, unsigned int a) {
//fake using read16
if (a&1) {
return csr_read16(obj, a-1);
return csr_read16(obj, a-1)&0xff;
} else {
return csr_read16(obj, a)>>8;
}
Expand Down
16 changes: 7 additions & 9 deletions emu.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,14 +314,15 @@ static int check_mem_access(unsigned int address, int flags) {
int access=mapper_access_allowed(mapper, address, flags);
if (access!=ACCESS_ERROR_OK) {
if (log_level_active(LOG_SRC_MAPPER, LOG_DEBUG)) {
EMU_LOG_INFO("Illegal access! Access %x\n", address);
EMU_LOG_INFO("Illegal access! Access %x. Generating bus error.\n", address);
dump_cpu_state();
dump_callstack();
}
csr_set_access_error(csr, cur_cpu, access, address, flags&ACCESS_W);

//note THIS WILL NOT RETURN!
//(m68ki_exception_bus_error ends with a longjmp)
//note: THIS WILL NOT RETURN!
//(m68k_pulse_bus error calls m68ki_exception_bus_error, which
//ends with a longjmp.)
m68k_pulse_bus_error();
return 0;
}
Expand Down Expand Up @@ -619,10 +620,6 @@ void setup_nop(const char *name) {
void m68k_fc_cb(unsigned int fc) {
fc_bits=fc;
mapper_set_sysmode(mapper, fc&4);
//Guess: mapid resets on int?
if ((fc&0x7)==7) {
mapper_set_mapid(mapper, 0);
}
}

//has a level if triggered, otherwise 0
Expand Down Expand Up @@ -703,7 +700,7 @@ void m68k_trace_cb(unsigned int pc) {
if (ir==0x4E75) callstack_ptr[cur_cpu]--;
prev_pc=pc;
unsigned int sr=m68k_get_reg(NULL, M68K_REG_SR);
if (do_tracefile) fprintf(tracefile, "%d %d %06x %x\n", insn_id, cur_cpu, pc, sr);
if (do_tracefile&(1<<cur_cpu)) fprintf(tracefile, "%d %d %06x %x\n", insn_id, cur_cpu, pc, sr);
if (!trace_enabled) return;
dump_cpu_state();
}
Expand Down Expand Up @@ -747,7 +744,8 @@ static void sig_hdl(int sig) {
void emu_start(emu_cfg_t *cfg) {
signal(SIGQUIT, sig_hdl); // ctrl+\ to dump status
tracefile=fopen("trace.txt","w");
// do_tracefile=1;
//Note: this is a bitmask for which CPU gets logged. (1<<0) for dma, (1<<1) for job cpu.
// do_tracefile=(1<<1);
setup_ram("RAM");
setup_ram("SRAM");
setup_rtcram("RTC_RAM", cfg->rtcram);
Expand Down
11 changes: 6 additions & 5 deletions mapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,20 @@ void mapper_set_mapid(mapper_t *m, uint8_t id) {
static int access_allowed_page(mapper_t *m, unsigned int page, int access_flags) {
assert(page<4096);
unsigned int ac=(m->desc[page].w1<<16)+m->desc[page].w0;
//Set fault to the access flags we need but are not set in the page.
int fault=(ac&access_flags)&(ACCESS_R|ACCESS_W|ACCESS_X);
int uid=(ac>>W0_UID_SHIFT)&W0_UID_MASK;
if ((access_flags&ACCESS_SYSTEM)==0) {
//If there's an uid fault, we set the lower 8 bits to 0xff
//and make the next 8 bits the uid.
if (uid != m->cur_id) fault=(uid<<8|0xff);
}
if (fault) {
MAPPER_LOG_DEBUG("Mapper: Access fault: page ent %x req %x, fault %x (", ac, access_flags, fault);
if (fault&(W1_W<<16)) MAPPER_LOG_DEBUG("write violation ");
if (fault&(W1_R<<16)) MAPPER_LOG_DEBUG("read violation ");
if (fault&(W1_X<<16)) MAPPER_LOG_DEBUG("execute violation ");
if (fault&0xff00) MAPPER_LOG_DEBUG("proc uid %d page uid %d ", m->cur_id, uid);
if (fault&0xff) MAPPER_LOG_DEBUG("proc uid %d page uid %d ", m->cur_id, uid);
MAPPER_LOG_DEBUG(")\n");
}
return fault;
Expand Down Expand Up @@ -117,7 +120,6 @@ void mapper_write16(void *obj, unsigned int a, unsigned int val) {
} else {
m->desc[a/2].w0=val;
}
if (a/2==2048) MAPPER_LOG_DEBUG("write page %d, w%d. w0=%x, w1=%x\n", a/2, a&1, m->desc[a/2].w0, m->desc[a/2].w1);
}

void mapper_write32(void *obj, unsigned int a, unsigned int val) {
Expand All @@ -129,7 +131,6 @@ void mapper_write32(void *obj, unsigned int a, unsigned int val) {
unsigned int mapper_read16(void *obj, unsigned int a) {
mapper_t *m=(mapper_t*)obj;
a=a/2; //word addr
if (a/2==2048) MAPPER_LOG_DEBUG("read page %d, w%d. w0=%x, w1=%x\n", a/2, a&1, m->desc[a/2].w0, m->desc[a/2].w1);
if (a&1) {
return m->desc[a/2].w1;
} else {
Expand All @@ -140,9 +141,9 @@ unsigned int mapper_read16(void *obj, unsigned int a) {
void mapper_write8(void *obj, unsigned int a, unsigned int val) {
int v=mapper_read16(obj, a&~1);
if (a&1) {
v=(v&0xFF00)|val;
v=(v&0xFF00)|(val&0xff);
} else {
v=(v&0xFF)|(val<<8);
v=(v&0xFF)|((val<<8)&0xff000);
}
mapper_write16(obj, a&~1, v);
}
Expand Down
4 changes: 3 additions & 1 deletion scsi_dev_hd.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ static int hd_handle_cmd(scsi_dev_t *dev, uint8_t *cd, int len) {
return SCSI_DEV_DATA_IN;
} else if (cd[0]==0x15) { //mode select
return SCSI_DEV_DATA_OUT;
} else if (cd[0]==0xa) { //write
return SCSI_DEV_DATA_IN;
} else if (cd[0]==0xC2) {
//omti config cmd?
return SCSI_DEV_DATA_IN;
Expand Down Expand Up @@ -72,7 +74,7 @@ int hd_handle_data_in(scsi_dev_t *dev, uint8_t *msg, int buflen) {
//omti config command?
} else {
printf("Unknown command: 0x%x\n", hd->cmd[0]);
assert(0 && "hd_handle_data_in: unknown cmd");
// assert(0 && "hd_handle_data_in: unknown cmd");
}
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ unsigned int uart_read8(void *obj, unsigned int addr) {
// Poll for console input if the emulated device might be expecting data
// (done at top of function because .has_char_rcv being set will determine
// if the character is ever read; so we cannot only do it in read character)
if (u->is_console && !is_in_loopback && !u->chan[chan].has_char_rcv) {
if (chan==1 && u->is_console && !is_in_loopback && !u->chan[chan].has_char_rcv) {
int in_ch = uart_poll_for_console_character();
if (in_ch >= 0) {
u->chan[chan].char_rcv = in_ch;
Expand Down

0 comments on commit fc1028e

Please sign in to comment.