Changeset 5fa5369 in buchla-emu
- Timestamp:
- 08/05/2017 07:03:20 PM (7 years ago)
- Branches:
- master
- Children:
- 149c3e0
- Parents:
- 7cc6ac0
- Location:
- emu
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
emu/all.h
r7cc6ac0 r5fa5369 81 81 extern void cpu_loop(void); 82 82 83 extern uint8_t cpu_peek(int32_t addr); 84 extern void cpu_poke(int32_t addr, uint8_t val); 85 83 86 extern void fpu_init(void); 84 87 extern void fpu_quit(void); -
emu/cpu.c
r7cc6ac0 r5fa5369 468 468 } 469 469 470 uint8_t cpu_peek(int32_t addr) 471 { 472 if (addr >= RAM_START && addr <= RAM_START + RAM_SIZE - 1) { 473 return ram_data[addr - RAM_START]; 474 } 475 476 if (addr >= ROM_START && addr <= ROM_START + ROM_SIZE - 1) { 477 return rom_data[addr - ROM_START]; 478 } 479 480 return 0; 481 } 482 483 void cpu_poke(int32_t addr, uint8_t val) 484 { 485 if (addr >= RAM_START && addr <= RAM_START + RAM_SIZE - 1) { 486 ram_data[addr - RAM_START] = val; 487 } 488 489 if (addr >= ROM_START && addr <= ROM_START + ROM_SIZE - 1) { 490 rom_data[addr - ROM_START] = val; 491 } 492 } 493 470 494 static void inst_cb(void) 471 495 { -
emu/gdb.c
r7cc6ac0 r5fa5369 117 117 } 118 118 119 ver2("<- lock none ");119 ver2("<- lock none / req"); 120 120 121 121 if (SDL_LockMutex(cpu_mutex) < 0) { … … 124 124 } 125 125 126 static void lock_cpu(void)126 static void stop_cpu(void) 127 127 { 128 128 ver2("-> lock req"); 129 129 SDL_AtomicSet(&lock, LOCK_REQ); 130 130 131 while (SDL_AtomicGet(&lock) == LOCK_REQ) {131 while (SDL_AtomicGet(&lock) != LOCK_ACK) { 132 132 SDL_Delay(100); 133 133 } … … 136 136 } 137 137 138 static void free_cpu(void)138 static void cont_cpu(void) 139 139 { 140 140 ver2("-> lock none"); … … 142 142 } 143 143 144 static void step_cpu(void) 145 { 146 ver2("-> lock req"); 147 SDL_AtomicSet(&lock, LOCK_REQ); 148 } 149 150 static void wait_cpu(void) 151 { 152 while (SDL_AtomicGet(&lock) != LOCK_ACK) { 153 SDL_Delay(100); 154 } 155 156 ver2("<- lock ack"); 157 } 158 159 static int32_t hex_digit(char c) 160 { 161 if (c >= '0' && c <= '9') { 162 return c - '0'; 163 } 164 165 if (c >= 'a' && c <= 'f') { 166 return 10 + c - 'a'; 167 } 168 169 if (c >= 'A' && c <= 'F') { 170 return 10 + c - 'A'; 171 } 172 173 return -1; 174 } 175 176 static int32_t hex_num(const char **pp) 177 { 178 int32_t res = 0; 179 int32_t dig; 180 181 while ((dig = hex_digit(**pp)) >= 0) { 182 res = (res << 4) | dig; 183 ++*pp; 184 } 185 186 return res; 187 } 188 144 189 static result_t com_reason(void) 145 190 { 146 return RES_DAT("S0a", 4); 147 } 148 149 static result_t com_cont(char *req) 150 { 151 return RES_DAT("", 0); 152 } 153 154 static result_t com_step(char *req) 155 { 156 return RES_DAT("", 0); 191 // 0x05 = SIGTRAP 192 return RES_DAT("S05", 3); 193 } 194 195 static void set_pc(const char **req) 196 { 197 int32_t addr = hex_num(req); 198 199 if (SDL_LockMutex(cpu_mutex) < 0) { 200 fail("SDL_LockMutex() failed: %s", SDL_GetError()); 201 } 202 203 m68k_set_reg(M68K_REG_PC, (uint32_t)addr); 204 205 if (SDL_UnlockMutex(cpu_mutex) < 0) { 206 fail("SDL_UnlockMutex() failed: %s", SDL_GetError()); 207 } 208 } 209 210 static result_t com_cont(const char *req) 211 { 212 if (req[0] != 0) { 213 set_pc(&req); 214 } 215 216 cont_cpu(); 217 wait_cpu(); 218 219 // 0x05 = SIGTRAP 220 return RES_DAT("S05", 3); 221 } 222 223 static result_t com_step(const char *req) 224 { 225 if (req[0] != 0) { 226 set_pc(&req); 227 } 228 229 step_cpu(); 230 wait_cpu(); 231 232 // 0x05 = SIGTRAP 233 return RES_DAT("S05", 3); 157 234 } 158 235 … … 201 278 } 202 279 203 static result_t com_wr_reg(c har *req)280 static result_t com_wr_reg(const char *req) 204 281 { 205 282 uint32_t d0, d1, d2, d3, d4, d5, d6, d7; … … 207 284 uint32_t ps, pc; 208 285 209 if (sscanf(req + 1,286 if (sscanf(req, 210 287 "%08x%08x%08x%08x%08x%08x%08x%08x" 211 288 "%08x%08x%08x%08x%08x%08x%08x%08x" … … 249 326 } 250 327 251 static result_t com_rd_mem(char *req) 252 { 253 return RES_DAT("", 0); 254 } 255 256 static result_t com_wr_mem(char *req) 257 { 258 return RES_DAT("", 0); 259 } 260 261 static result_t handle(char *req) 328 static result_t com_rd_mem(const char *req) 329 { 330 int32_t addr = hex_num(&req); 331 332 if (*req++ != ',') { 333 return RES_DAT("E01", 3); 334 } 335 336 int32_t len = hex_num(&req); 337 338 if (*req != 0 || len == 0) { 339 return RES_DAT("E01", 3); 340 } 341 342 if (len > 10000) { 343 len = 10000; 344 } 345 346 static char buf[10000 * 2 + 1]; 347 348 if (SDL_LockMutex(cpu_mutex) < 0) { 349 fail("SDL_LockMutex() failed: %s", SDL_GetError()); 350 } 351 352 for (int32_t i = 0; i < len; ++i) { 353 uint8_t byte = cpu_peek(addr + i); 354 sprintf(buf + i * 2, "%02x", byte); 355 } 356 357 if (SDL_UnlockMutex(cpu_mutex) < 0) { 358 fail("SDL_UnlockMutex() failed: %s", SDL_GetError()); 359 } 360 361 return RES_DAT(buf, len * 2); 362 } 363 364 static result_t com_wr_mem(const char *req) 365 { 366 int32_t addr = hex_num(&req); 367 368 if (*req++ != ',') { 369 return RES_DAT("E01", 3); 370 } 371 372 int32_t len = hex_num(&req); 373 374 if (*req++ != ':') { 375 return RES_DAT("E01", 3); 376 } 377 378 if (SDL_LockMutex(cpu_mutex) < 0) { 379 fail("SDL_LockMutex() failed: %s", SDL_GetError()); 380 } 381 382 int32_t i; 383 384 for (i = 0; i < len; ++i) { 385 int32_t hi = hex_digit(*req++); 386 387 if (hi < 0) { 388 break; 389 } 390 391 int32_t lo = hex_digit(*req++); 392 393 if (lo < 0) { 394 break; 395 } 396 397 cpu_poke(addr + i, (uint8_t)((hi << 4) | lo)); 398 } 399 400 if (SDL_UnlockMutex(cpu_mutex) < 0) { 401 fail("SDL_UnlockMutex() failed: %s", SDL_GetError()); 402 } 403 404 return RES_DAT("OK", 2); 405 } 406 407 static result_t handle(const char *req) 262 408 { 263 409 result_t res; … … 269 415 270 416 case 'c': 271 res = com_cont(req); 417 res = com_cont(req + 1); 418 break; 419 420 case 'C': 421 res = com_cont(req + 4); 272 422 break; 273 423 274 424 case 's': 275 res = com_step(req); 425 res = com_step(req + 1); 426 break; 427 428 case 'S': 429 res = com_step(req + 4); 276 430 break; 277 431 … … 281 435 282 436 case 'G': 283 res = com_wr_reg(req );437 res = com_wr_reg(req + 1); 284 438 break; 285 439 286 440 case 'm': 287 res = com_rd_mem(req );441 res = com_rd_mem(req + 1); 288 442 break; 289 443 290 444 case 'M': 291 res = com_wr_mem(req );445 res = com_wr_mem(req + 1); 292 446 break; 293 447 … … 320 474 ver2("resp %s", (char *)buf); 321 475 return RES_DAT(buf, res.n_out + 4); 322 }323 324 static int32_t hex_digit(uint8_t byte)325 {326 if (byte >= '0' && byte <= '9') {327 return byte - '0';328 }329 330 if (byte >= 'a' && byte <= 'f') {331 return 10 + byte - 'a';332 }333 334 if (byte >= 'A' && byte <= 'F') {335 return 10 + byte - 'A';336 }337 338 return -1;339 476 } 340 477 … … 380 517 381 518 case STATE_CHECK_1: 382 hex = hex_digit( byte);519 hex = hex_digit((char)byte); 383 520 384 521 if (hex < 0) { … … 392 529 393 530 case STATE_CHECK_2: 394 hex = hex_digit( byte);531 hex = hex_digit((char)byte); 395 532 396 533 if (hex < 0) { … … 442 579 443 580 SDLNet_TCP_Close(con); 444 free_cpu();581 cont_cpu(); 445 582 } 446 583 … … 480 617 } 481 618 482 lock_cpu();619 stop_cpu(); 483 620 state = STATE_ACK; 484 621 continue;
Note:
See TracChangeset
for help on using the changeset viewer.