Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CORE: Implement a generic external monitor framework in Xemu (initially used by MEGA65 emulation only though) #11

Open
lgblgblgb opened this issue Aug 19, 2016 · 7 comments

Comments

@lgblgblgb
Copy link
Owner

Mega65 target got "UART monitor" for similar job as a real Mega65 has for. Note, that this feature would be useful for every targets for some form! So the monitor framework should be put into the common directory, also it would be cool to have Windows port, since currently it's UNIX only as it needs UNIX/POSIX related socket interface to be able to work.

@lgblgblgb lgblgblgb self-assigned this Aug 19, 2016
@lgblgblgb lgblgblgb changed the title Implement a generic "external" monitor feature as Mega65 target has one now Implement a generic "external" monitor feature Aug 27, 2016
@lgblgblgb
Copy link
Owner Author

lgblgblgb commented Feb 1, 2017

According to my current ideas only ... I think (after chatting on these with Paul as well) the best way would be to keep uart-mon interface fully compatible with the real M65 (ie, VHDL implementation of M65 in the FPGA) as m65dbg (and btw uart-monitor was "invented"!) was written for that, and not for Xemu (Xemu tries only implement this uart-mon interface of the board itself). So then m65dbg is really a dual purpose tool, to be able to support the real hardware, and the emulator too. It also requires to try to keep the features of the interface at the minimum as much as possible and implement advanced features (like disasm) on the level of the m65dbg tool itself (or possibly even in a library - libm65dbg - which can be used then by the m65dbg CLI tool, and maybe other future debugger projects with GUI interfaces, PC-based IDEs, or whatever). This basically means, that only the minimal set of features needed at the emulator (or the board/FPGA/VHDL) side, and implement as many features as possible on the m65dbg side then. Surely it's only an idea now.

I've got a very neat piece of work as pull request #52 which made me think about the plans and older chats with developers on this topic, that's why I write these for now.

@lgblgblgb
Copy link
Owner Author

Commit 3a85292
The new wannabe interface working through TCP/IP even on Windows (using Winsock2). Capable of detecting HTTP requests (so the possibility to write a html5/JS interface as well) but with compatibility with the existing protocol. It runs in a thread not to disturb the emulator to maintain the connection, and will use some kind of simple message queue to exchange information between the monitor thread and the main emulator thread. Note, this is only the framework yet, it does nothing currently. Though it echoes back the given statement, and with a web browser, it produces a test HTML page for it.

lgblgblgb referenced this issue Sep 20, 2017
* works over TCP/IP, through network too, on windows too
* works on windows too (not the UNIX domain socket old one), with winsock2
* auto detection of text mode (normal) and HTTP communication
* runs in separate thread with msg queues to interact with the emulator
* WORKS IN PROGRESS, it does not do too much currently!!
@lgblgblgb
Copy link
Owner Author

#143 was a step to the direction by providing a socketapi which can be used for this really old issue

@lgblgblgb lgblgblgb moved this from TODO to Stalling in C65 emulator project Sep 15, 2020
@lgblgblgb lgblgblgb removed this from Stalling in C65 emulator project Sep 15, 2020
@lgblgblgb lgblgblgb changed the title Implement a generic "external" monitor feature CORE: Implement a generic external monitor feature Sep 22, 2020
@lgblgblgb lgblgblgb added this to TODO in Xemu core Oct 13, 2020
@lgblgblgb lgblgblgb moved this from TODO to Stalling / Delayed in MEGA65 emulator project Jan 27, 2021
@lgblgblgb lgblgblgb moved this from TODO to Delayed / stalling in Xemu core Jan 27, 2021
@lgblgblgb lgblgblgb changed the title CORE: Implement a generic external monitor feature CORE: Implement a generic external monitor framework in Xemu (initially used by MEGA65 emulation only though) Jan 27, 2021
@lgblgblgb
Copy link
Owner Author

lgblgblgb commented Jan 27, 2021

Some works on the current monitor (not this feature): #220 by Gurcei.

@lgblgblgb
Copy link
Owner Author

Again a new beginning. Commit 7629a37 intends to create a cross-platform tcp/ip, thread based umon server solution based on xemu's socketapi abstraction.

@lgblgblgb
Copy link
Owner Author

umon branch for MEGA65-based work, see how it fits in general then.

@lgblgblgb lgblgblgb moved this from Delayed / stalling to In Progress in Xemu core Aug 30, 2022
lgblgblgb referenced this issue Dec 28, 2023
…o the hardware (particularly the extra map-mask bits in MAPL, MAPH)
@lgblgblgb
Copy link
Owner Author

lgblgblgb commented May 5, 2024

@gurcei The plan for breakpoints API in general:

CPU65 emulation core will get an opcode callback mechanism. Rules:

  • Macro CPU65_EXECUTION_CALLBACK_SUPPORT must be defined (probably in xemu-target.h)
  • The emulator must provide the following functions then:
    • bool cpu65_nmi_debug_callback ( void ) - called before a pending NMI is accepted, if callbacks are enabled
    • bool cpu65_irq_debug_callback ( void ) - called before a pending IRQ is accepted, if callbacks are enabled
    • bool cpu65_execution_debug_callback ( void ) - called each time at opcode fetch (only the opcode itself!), if callbacks are enabled
  • These callbacks must return with false if there is no need to stop the CPU or true if stopping is desired (breakpoint, etc?)
  • The callbacks can query the cpu65 structure to learn more about the situation, like:
    • cpu65.pc the program counter (unlike memwatch callbacks, the PC is accurate and points to the address the next instruction would be executed - or in case of IRQ and NMI where the execution will continue after the NMI/IRQ is executed - but it's still true that the callbacks are issued before IRQ or NMI is accepted)
    • cpu65.op the fetched opcode (only valid for the cpu65_execution_debug_callback not for the NMI or IRQ - for those cpu65.op contains the previous executed opcode, so beware of this)
      • Note: the opcode is single byte. Prefixed opcodes are not handled, ie, both the prefix bytes and the "real" opcode has its own callback invocation. If it's needed anyway to query prefixed opcode, the cpu65 struct contains a prefix field, which can be decoded, if it's really needed at all. This is how CPU65 core emulation works internally too: when the emulator encounters a "wannabe prefix" (like NOP or NEG) it does not know yet if it will be a prefix or a real NEG or NOP alone, it only turns out later, of course. Thus it's not possible to know "in advance".
    • etc ... (see ROOT/xemu/cpu65.h to learn more on the cpu65 structure)
  • The callbacks must be enabled/activated before they start to be called by CPU65 core with setting cpu65.execution_debug_callback to true
  • cpu65.execution_debug_callback should be set to false as soon as possible when there is no need for the callbacks, since these mechanisms consumes CPU time from the emulator
  • Returning with true from callback is not enough alone to stop the CPU, as it only causes the CPU emulation to abort further CPU emulation for that "round". Thus it's emulator target dependent, but some other emulation main loop setting is needed as well. The exact method is no longer scope of CPU65 core though, but emulator target specific.

With this, the emulation target can choose its own way to implement breakpoint, based on PC or even on a given opcode only (by checking cpu65.op) and so on ...

Really this is kinda easy to implement, in fact, already done (but not committed yet).

TODO:

  • Implement emulator target (in our case MEGA65) specific solution for the other part of the requirement to keep the CPU stopped. This will also affect some other parts of the MEGA65 emulator not just the shared CPU65 emulation.
  • Rework the uartmon stuff to take advantage the new system

NOTE: some may need to be careful not to confuse the breakpoint API with the "memwatch" API: the breakpoint API we're talking about here only deals with opcode fetches and NMI/IRQ acceptances. The "memwatch" API in the other hand can handle any kind of memory read and write operations to be intercepted. Also the breakpoint API can stop the CPU before the actual opcode, while the memwatch API - unfortunately - can only react when an opcode emulation already in progress, thus it's inconsistent somewhat what phase the opcode emulation we're in ... Because it can happen even many-many times within a single opcode (think about a 32 bit flat addressed 32 bit opcode ..., there is need to query BP for 4 bytes of read, then the target memory, not even counting the opcode and prefix fetches ...).

lgblgblgb added a commit that referenced this issue May 12, 2024
To allow easier debugger implementation with breakpoints, and such, a
new (optional to be used) mechanism is introduced. It allows the CPU65
emulation core to call target emulator defined functions on each op code
executions (and in case of IRQ and NMI acceptance). The target emulator
itself can decide what to do in the callbacks, it can simply return, or
instructing the CPU emulation to be stopped (ie: breakpoint or step
based opcode execution during debugging).

NOTE: still, the target emulator's main loop must aware of this, the
CPU65 core itself alone cannot stop the whole emulation in a sane way.
lgblgblgb added a commit that referenced this issue May 12, 2024
This quite big change rewrites the MEGA65 emulation memory decoder
subsystem. Some of the reasons:

* Create a new, not overcomplicated decoder which can be understood at
  all without major headache, and can be also faster as per #209
* Taking account some new findings about how C65 worked (both Xemu and
  MEGA65 was wrong here) and adopted since then by MEGA65 as per #378
* More about the future (not ready in this commit): allow functionality
  for debugger implementation "watchmem" which can monitor about every
  memory r/w events debugger want to check as per #11

This commit is quite big as was mentioned, and may introduce some
regressions. So it's important to have feedback in those cases. Also it
changes the behaviour of memory decoding (#378). The new decoder seems
to be already faster than the old one and more easy to understand and
maintain. Also there is some room for future improvements still in every
areas, including optimizations. The "memwatch" part currently is not
usable though, but the basis are there to be able to implement that at
all (wouldn't be possible with the older scheme).
@lgblgblgb lgblgblgb pinned this issue Jun 10, 2024
lgblgblgb added a commit that referenced this issue Jun 12, 2024
Preliminary initial work, reorganization of uartmon, moving things out
from mega65.c to uart_monitor.c

No functionality change yet! And not even tested yet ;)
@lgblgblgb lgblgblgb moved this from Stalling / Delayed to In Progress in MEGA65 emulator project Jun 20, 2024
lgblgblgb added a commit that referenced this issue Jun 21, 2024
Moving everything out of mega65.c which is uartmon into uart_monitor.c, well,
at least allmost everything ... Still, no new feature is used from CPU65
emulation, just mainly reorganization of the source to look nicer for
further hacking/developing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Xemu core
In Progress
Development

No branches or pull requests

1 participant