1
0
mirror of https://github.com/cc65/cc65.git synced 2025-01-10 19:29:45 +00:00

Rearranged paravirt function vector.

- exit right below 6502 vectors.
- keep exit addr stable as it may be called from asm.
This commit is contained in:
Oliver Schmidt 2019-05-30 00:10:17 +02:00
parent c6bbea0bb0
commit 6efb71bea7
3 changed files with 25 additions and 30 deletions

View File

@ -166,14 +166,9 @@ Other internal details:
Aside from the loaded binary, the reset vector at <tt/$FFFC/ will be Aside from the loaded binary, the reset vector at <tt/$FFFC/ will be
pre-loaded with the given <bf/reset address/. pre-loaded with the given <bf/reset address/.
<item>The <tt/exit/ address is <tt/$FFF1/. <item>The <tt/exit/ address is <tt/$FFF9/.
Jumping to this address will terminate execution with the A register value as an exit code. Jumping to this address will terminate execution with the A register value as an exit code.
<item>The built-in functions are provided by 6 paravirtualization hooks present at
<tt/$FFF0-$FFF5/. Except for <tt/exit/, a <tt/JSR/ to one of these
addresses will return immediately after performing a special function.
These use cc65 calling conventions, and are intended for use with the sim65 target C library.
<item><tt/IRQ/ and <tt/NMI/ events will not be generated, though <tt/BRK/ <item><tt/IRQ/ and <tt/NMI/ events will not be generated, though <tt/BRK/
can be used if the IRQ vector at <tt/$FFFE/ is manually prepared by the test code. can be used if the IRQ vector at <tt/$FFFE/ is manually prepared by the test code.

View File

@ -7,11 +7,11 @@
; int __fastcall__ write (int fd, const void* buf, unsigned count); ; int __fastcall__ write (int fd, const void* buf, unsigned count);
; ;
.export args, exit, _open, _close, _read, _write .export exit, args, _open, _close, _read, _write
args := $FFF0 _open := $FFF4
exit := $FFF1 _close := $FFF5
_open := $FFF2 _read := $FFF6
_close := $FFF3 _write := $FFF7
_read := $FFF4 args := $FFF8
_write := $FFF5 exit := $FFF9

View File

@ -120,6 +120,18 @@ static unsigned PopParam (unsigned char Incr)
static void PVExit (CPURegs* Regs)
{
Print (stderr, 1, "PVExit ($%02X)\n", Regs->AC);
if (PrintCycles) {
Print (stdout, 0, "%lu cycles\n", GetCycles ());
}
exit (Regs->AC);
}
static void PVArgs (CPURegs* Regs) static void PVArgs (CPURegs* Regs)
{ {
unsigned ArgC = ArgCount - ArgStart; unsigned ArgC = ArgCount - ArgStart;
@ -152,18 +164,6 @@ static void PVArgs (CPURegs* Regs)
static void PVExit (CPURegs* Regs)
{
Print (stderr, 1, "PVExit ($%02X)\n", Regs->AC);
if (PrintCycles) {
Print (stdout, 0, "%lu cycles\n", GetCycles ());
}
exit (Regs->AC);
}
static void PVOpen (CPURegs* Regs) static void PVOpen (CPURegs* Regs)
{ {
char Path[1024]; char Path[1024];
@ -295,12 +295,12 @@ static void PVWrite (CPURegs* Regs)
static const PVFunc Hooks[] = { static const PVFunc Hooks[] = {
PVArgs,
PVExit,
PVOpen, PVOpen,
PVClose, PVClose,
PVRead, PVRead,
PVWrite, PVWrite,
PVArgs,
PVExit,
}; };
@ -318,13 +318,13 @@ void ParaVirtHooks (CPURegs* Regs)
/* Potentially execute paravirtualization hooks */ /* Potentially execute paravirtualization hooks */
{ {
/* Check for paravirtualization address range */ /* Check for paravirtualization address range */
if (Regs->PC < 0xFFF0 || if (Regs->PC < 0xFFF4 ||
Regs->PC >= 0xFFF0 + sizeof (Hooks) / sizeof (Hooks[0])) { Regs->PC >= 0xFFF4 + sizeof (Hooks) / sizeof (Hooks[0])) {
return; return;
} }
/* Call paravirtualization hook */ /* Call paravirtualization hook */
Hooks[Regs->PC - 0xFFF0] (Regs); Hooks[Regs->PC - 0xFFF4] (Regs);
/* Simulate RTS */ /* Simulate RTS */
Regs->PC = Pop(Regs) + (Pop(Regs) << 8) + 1; Regs->PC = Pop(Regs) + (Pop(Regs) << 8) + 1;