2

This may sounds crazy but it seems unclear to me whether there is an interface to assembly programmers to write code to load one register on core 1 to a register on core 2. For example, load EAX on core 1 to EAX on core 2. Is it even possible?

More over what is the interface to assembly programmers to use two cores (run code on more than one core)?

Awaken
  • 139
  • 6

2 Answers2

2

No. To do this, one core has to store the value in memory and the other has to take it out. So the core one might look like this:

mov eax, [235]

And core 2 would do this:

mov [235], eax
Linuxios
  • 34,849
  • 13
  • 91
  • 116
1

The hardware doesn't directly offer this.

However, to build real tools (e.g., debuggers), some facility like this must exist. This is implemented usually by kernal software for a system, that provides a facility for one CPU to "stop" another, to inspect its register state, to modify its register state, to single-step, to modify the memory map of the other CPU, etc. Such facilities are built on top of low level hardware primitives that allow one CPU to interrupt another, and code organized so that a CPU interrupt causes the interrupted CPU to make its state available to the the interrupting CPU. (This tends to be very tricky code, and extremely hardware dependent).

Windows offers these capabilities (at least the register access part) via the Win32 call, GetThreadContext(). I'm sure there's an equivalent for Win64, and something analogous for Linux, etc.

Ira Baxter
  • 93,541
  • 22
  • 172
  • 341
  • 1
    Just to be clear, this is inspecting the saved registers of a software thread, after stopping the other thread on whatever core it was running caused the OS to save its register state as normal for a context switch. (e.g. in Linux in the system-call or interrupt entry points for the integer reg state.) There isn't a mechanism for one core so single-step another *core*, at least not on x86, only for the kernel on one core to single-step a user-space thread on that same core. And BTW, the Linux system call for writing debuggers is `ptrace`, e.g. `ptrace(PTRACE_GETREGS)` after attaching. – Peter Cordes Apr 10 '23 at 06:34