Changeset 5fa5369 in buchla-emu


Ignore:
Timestamp:
08/05/2017 07:03:20 PM (7 years ago)
Author:
Thomas Lopatic <thomas@…>
Branches:
master
Children:
149c3e0
Parents:
7cc6ac0
Message:

Single-stepping looks OK.

Location:
emu
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • emu/all.h

    r7cc6ac0 r5fa5369  
    8181extern void cpu_loop(void);
    8282
     83extern uint8_t cpu_peek(int32_t addr);
     84extern void cpu_poke(int32_t addr, uint8_t val);
     85
    8386extern void fpu_init(void);
    8487extern void fpu_quit(void);
  • emu/cpu.c

    r7cc6ac0 r5fa5369  
    468468}
    469469
     470uint8_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
     483void 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
    470494static void inst_cb(void)
    471495{
  • emu/gdb.c

    r7cc6ac0 r5fa5369  
    117117        }
    118118
    119         ver2("<- lock none");
     119        ver2("<- lock none / req");
    120120
    121121        if (SDL_LockMutex(cpu_mutex) < 0) {
     
    124124}
    125125
    126 static void lock_cpu(void)
     126static void stop_cpu(void)
    127127{
    128128        ver2("-> lock req");
    129129        SDL_AtomicSet(&lock, LOCK_REQ);
    130130
    131         while (SDL_AtomicGet(&lock) == LOCK_REQ) {
     131        while (SDL_AtomicGet(&lock) != LOCK_ACK) {
    132132                SDL_Delay(100);
    133133        }
     
    136136}
    137137
    138 static void free_cpu(void)
     138static void cont_cpu(void)
    139139{
    140140        ver2("-> lock none");
     
    142142}
    143143
     144static void step_cpu(void)
     145{
     146        ver2("-> lock req");
     147        SDL_AtomicSet(&lock, LOCK_REQ);
     148}
     149
     150static void wait_cpu(void)
     151{
     152        while (SDL_AtomicGet(&lock) != LOCK_ACK) {
     153                SDL_Delay(100);
     154        }
     155
     156        ver2("<- lock ack");
     157}
     158
     159static 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
     176static 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
    144189static result_t com_reason(void)
    145190{
    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
     195static 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
     210static 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
     223static 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);
    157234}
    158235
     
    201278}
    202279
    203 static result_t com_wr_reg(char *req)
     280static result_t com_wr_reg(const char *req)
    204281{
    205282        uint32_t d0, d1, d2, d3, d4, d5, d6, d7;
     
    207284        uint32_t ps, pc;
    208285
    209         if (sscanf(req + 1,
     286        if (sscanf(req,
    210287                        "%08x%08x%08x%08x%08x%08x%08x%08x"
    211288                        "%08x%08x%08x%08x%08x%08x%08x%08x"
     
    249326}
    250327
    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)
     328static 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
     364static 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
     407static result_t handle(const char *req)
    262408{
    263409        result_t res;
     
    269415
    270416        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);
    272422                break;
    273423
    274424        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);
    276430                break;
    277431
     
    281435
    282436        case 'G':
    283                 res = com_wr_reg(req);
     437                res = com_wr_reg(req + 1);
    284438                break;
    285439
    286440        case 'm':
    287                 res = com_rd_mem(req);
     441                res = com_rd_mem(req + 1);
    288442                break;
    289443
    290444        case 'M':
    291                 res = com_wr_mem(req);
     445                res = com_wr_mem(req + 1);
    292446                break;
    293447
     
    320474        ver2("resp %s", (char *)buf);
    321475        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;
    339476}
    340477
     
    380517
    381518        case STATE_CHECK_1:
    382                 hex = hex_digit(byte);
     519                hex = hex_digit((char)byte);
    383520
    384521                if (hex < 0) {
     
    392529
    393530        case STATE_CHECK_2:
    394                 hex = hex_digit(byte);
     531                hex = hex_digit((char)byte);
    395532
    396533                if (hex < 0) {
     
    442579
    443580        SDLNet_TCP_Close(con);
    444         free_cpu();
     581        cont_cpu();
    445582}
    446583
     
    480617                        }
    481618
    482                         lock_cpu();
     619                        stop_cpu();
    483620                        state = STATE_ACK;
    484621                        continue;
Note: See TracChangeset for help on using the changeset viewer.