Mercurial > repos > blastem
comparison cpu_dsl.py @ 2676:7e86ec94c899
Implement breakpoints in new 68K core
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 15 Mar 2025 23:15:05 -0700 |
parents | 6894a25ebfaa |
children | e3394457427e |
comparison
equal
deleted
inserted
replaced
2675:dbff641a33df | 2676:7e86ec94c899 |
---|---|
2054 self.context_type = self.prefix + 'context' | 2054 self.context_type = self.prefix + 'context' |
2055 self.body = info.get('body', [None])[0] | 2055 self.body = info.get('body', [None])[0] |
2056 self.interrupt = info.get('interrupt', [None])[0] | 2056 self.interrupt = info.get('interrupt', [None])[0] |
2057 self.sync_cycle = info.get('sync_cycle', [None])[0] | 2057 self.sync_cycle = info.get('sync_cycle', [None])[0] |
2058 self.includes = info.get('include', []) | 2058 self.includes = info.get('include', []) |
2059 self.pc_reg = info.get('pc_reg', [None])[0] | |
2060 self.pc_offset = info.get('pc_offset', [0])[0] | |
2059 self.flags = flags | 2061 self.flags = flags |
2060 self.lastDst = None | 2062 self.lastDst = None |
2061 self.scopes = [] | 2063 self.scopes = [] |
2062 self.currentScope = None | 2064 self.currentScope = None |
2063 self.lastOp = None | 2065 self.lastOp = None |
2086 macro = header.upper().replace('.', '_') | 2088 macro = header.upper().replace('.', '_') |
2087 hFile.write('#ifndef {0}_'.format(macro)) | 2089 hFile.write('#ifndef {0}_'.format(macro)) |
2088 hFile.write('\n#define {0}_'.format(macro)) | 2090 hFile.write('\n#define {0}_'.format(macro)) |
2089 hFile.write('\n#include <stdio.h>') | 2091 hFile.write('\n#include <stdio.h>') |
2090 hFile.write('\n#include "backend.h"') | 2092 hFile.write('\n#include "backend.h"') |
2093 if self.pc_reg: | |
2094 hFile.write('\n#include "tern.h"') | |
2091 hFile.write(f'\n\ntypedef struct {self.prefix}options {self.prefix}options;') | 2095 hFile.write(f'\n\ntypedef struct {self.prefix}options {self.prefix}options;') |
2092 hFile.write(f'\n\ntypedef struct {self.prefix}context {self.prefix}context;') | 2096 hFile.write(f'\n\ntypedef struct {self.prefix}context {self.prefix}context;') |
2093 for decl in self.declares: | 2097 for decl in self.declares: |
2094 if decl.startswith('define '): | 2098 if decl.startswith('define '): |
2095 decl = '#' + decl | 2099 decl = '#' + decl |
2098 hFile.write('\n\tcpu_options gen;') | 2102 hFile.write('\n\tcpu_options gen;') |
2099 hFile.write('\n\tFILE* address_log;') | 2103 hFile.write('\n\tFILE* address_log;') |
2100 hFile.write('\n};') | 2104 hFile.write('\n};') |
2101 hFile.write(f'\n\nstruct {self.prefix}context {{') | 2105 hFile.write(f'\n\nstruct {self.prefix}context {{') |
2102 hFile.write(f'\n\t{self.prefix}options *opts;') | 2106 hFile.write(f'\n\t{self.prefix}options *opts;') |
2107 if self.pc_reg: | |
2108 hFile.write('\n\ttern_node *breakpoints;'); | |
2103 self.regs.writeHeader(otype, hFile) | 2109 self.regs.writeHeader(otype, hFile) |
2104 hFile.write('\n};') | 2110 hFile.write('\n};') |
2105 hFile.write('\n') | 2111 hFile.write('\n') |
2106 hFile.write('\nvoid {pre}execute({type} *context, uint32_t target_cycle);'.format(pre = self.prefix, type = self.context_type)) | 2112 hFile.write('\nvoid {pre}execute({type} *context, uint32_t target_cycle);'.format(pre = self.prefix, type = self.context_type)) |
2107 hFile.write('\n#endif //{0}_'.format(macro)) | 2113 hFile.write('\n#endif //{0}_'.format(macro)) |
2199 if self.dispatch == 'call': | 2205 if self.dispatch == 'call': |
2200 if self.body in self.subroutines: | 2206 if self.body in self.subroutines: |
2201 pieces.append('\nvoid {pre}execute({type} *context, uint32_t target_cycle)'.format(pre = self.prefix, type = self.context_type)) | 2207 pieces.append('\nvoid {pre}execute({type} *context, uint32_t target_cycle)'.format(pre = self.prefix, type = self.context_type)) |
2202 pieces.append('\n{') | 2208 pieces.append('\n{') |
2203 pieces.append('\n\t{sync}(context, target_cycle);'.format(sync=self.sync_cycle)) | 2209 pieces.append('\n\t{sync}(context, target_cycle);'.format(sync=self.sync_cycle)) |
2210 if self.pc_reg: | |
2211 pieces.append('\n\tif (context->breakpoints) {') | |
2212 pieces.append('\n\t\twhile (context->cycles < target_cycle)') | |
2213 pieces.append('\n\t\t{') | |
2214 if self.interrupt in self.subroutines: | |
2215 pieces.append('\n\t\t\tif (context->cycles >= context->sync_cycle) {') | |
2216 pieces.append(f'\n\t\t\t\t{self.sync_cycle}(context, target_cycle);') | |
2217 pieces.append('\n\t\t\t}') | |
2218 self.meta = {} | |
2219 self.temp = {} | |
2220 intpieces = [] | |
2221 self.subroutines[self.interrupt].inline(self, [], intpieces, otype, None) | |
2222 for size in self.temp: | |
2223 pieces.append('\n\t\t\tuint{sz}_t gen_tmp{sz}__;'.format(sz=size)) | |
2224 pieces += intpieces | |
2225 if self.pc_offset: | |
2226 pieces.append(f'\n\t\t\tuint32_t debug_pc = context->{self.pc_reg} - {self.pc_offset};') | |
2227 pc_reg = 'debug_pc' | |
2228 else: | |
2229 pc_reg = 'context->' + self.pc_reg | |
2230 pieces.append('\n\t\t\tchar key_buf[6];') | |
2231 pieces.append(f'\n\t\t\tdebug_handler handler = tern_find_ptr(context->breakpoints, tern_int_key({pc_reg}, key_buf));') | |
2232 pieces.append('\n\t\t\tif (handler) {') | |
2233 pieces.append(f'\n\t\t\t\thandler(context, {pc_reg});') | |
2234 pieces.append('\n\t\t\t}') | |
2235 self.meta = {} | |
2236 self.temp = {} | |
2237 self.subroutines[self.body].inline(self, [], pieces, otype, None) | |
2238 pieces.append('\n\t}') | |
2239 pieces.append('\n\t} else {') | |
2204 pieces.append('\n\twhile (context->cycles < target_cycle)') | 2240 pieces.append('\n\twhile (context->cycles < target_cycle)') |
2205 pieces.append('\n\t{') | 2241 pieces.append('\n\t{') |
2206 if self.interrupt in self.subroutines: | 2242 if self.interrupt in self.subroutines: |
2207 pieces.append('\n\t\tif (context->cycles >= context->sync_cycle) {') | 2243 pieces.append('\n\t\tif (context->cycles >= context->sync_cycle) {') |
2208 pieces.append(f'\n\t\t\t{self.sync_cycle}(context, target_cycle);') | 2244 pieces.append(f'\n\t\t\t{self.sync_cycle}(context, target_cycle);') |
2216 pieces += intpieces | 2252 pieces += intpieces |
2217 self.meta = {} | 2253 self.meta = {} |
2218 self.temp = {} | 2254 self.temp = {} |
2219 self.subroutines[self.body].inline(self, [], pieces, otype, None) | 2255 self.subroutines[self.body].inline(self, [], pieces, otype, None) |
2220 pieces.append('\n\t}') | 2256 pieces.append('\n\t}') |
2257 if self.pc_reg: | |
2258 pieces.append('\n\t}') | |
2221 pieces.append('\n}') | 2259 pieces.append('\n}') |
2222 body.append('\nstatic void unimplemented({pre}context *context, uint32_t target_cycle)'.format(pre = self.prefix)) | 2260 body.append('\nstatic void unimplemented({pre}context *context, uint32_t target_cycle)'.format(pre = self.prefix)) |
2223 body.append('\n{') | 2261 body.append('\n{') |
2224 if len(self.mainDispatch) == 1: | 2262 if len(self.mainDispatch) == 1: |
2225 dispatch = self.resolveParam(list(self.mainDispatch)[0], None, {}) | 2263 dispatch = self.resolveParam(list(self.mainDispatch)[0], None, {}) |