sim65 common define for paravirt hooks base location

allows the loaded binary to take up as much space as possible
restored some documentation of the hooks but without reference to specific location
This commit is contained in:
bbbradsmith 2019-05-30 15:34:05 -04:00 committed by Oliver Schmidt
parent 6efb71bea7
commit 5269552346
4 changed files with 26 additions and 20 deletions

View File

@ -115,22 +115,12 @@ The <tt/exit/ function may also be used to terminate with an exit code.
Exit codes are limited to 8 bits.
The standard C library high level file input and output is functional,
and can be used like a command line application in sim65.
The standard C library high level file input and output is functional.
A sim65 application can be written like a command line application,
providing arguments to <tt/main/ and using the <tt/stdio.h/ interfaces.
Lower level file input and output is provided by
a set of built-in paravirtualization functions:
<tscreen><verb>
int open (const char* name, int flags, ...);
int __fastcall__ close (int fd);
int __fastcall__ read (int fd, void* buf, unsigned count);
int __fastcall__ write (int fd, const void* buf, unsigned count);
</verb></tscreen>
These built-in functions can be used with
<tt/STDIN_FILENO/, <tt/STDOUT_FILENO/ and <tt/STDERR_FILENO/
which are mapped to sim65's corresponding file descriptors.
Internally, file input and output is provided at a lower level by
a set of built-in paravirtualization functions (<ref id="paravirt-internal" name="see below">).
<sect>Creating a Test in Assembly<p>
@ -169,6 +159,11 @@ pre-loaded with the given <bf/reset address/.
<item>The <tt/exit/ address is <tt/$FFF9/.
Jumping to this address will terminate execution with the A register value as an exit code.
<label id="paravirt-internal">
<item>Several bytes immediately below the vector table are reserved for paravirtualization functions.
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/
can be used if the IRQ vector at <tt/$FFFE/ is manually prepared by the test code.

View File

@ -200,8 +200,8 @@ static unsigned char ReadProgramFile (void)
/* Read the file body into memory */
Addr = Load;
while ((Val = fgetc(F)) != EOF) {
if (Addr == 0xFF00) {
Error ("'%s': To large to fit into $%04X-$FFF0", ProgramFile, Addr);
if (Addr >= PARAVIRT_BASE) {
Error ("'%s': To large to fit into $%04X-$%04X", ProgramFile, Addr, PARAVIRT_BASE);
}
MemWriteByte (Addr++, (unsigned char) Val);
}

View File

@ -318,13 +318,13 @@ void ParaVirtHooks (CPURegs* Regs)
/* Potentially execute paravirtualization hooks */
{
/* Check for paravirtualization address range */
if (Regs->PC < 0xFFF4 ||
Regs->PC >= 0xFFF4 + sizeof (Hooks) / sizeof (Hooks[0])) {
if (Regs->PC < PARAVIRT_BASE ||
Regs->PC >= PARAVIRT_BASE + sizeof (Hooks) / sizeof (Hooks[0])) {
return;
}
/* Call paravirtualization hook */
Hooks[Regs->PC - 0xFFF4] (Regs);
Hooks[Regs->PC - PARAVIRT_BASE] (Regs);
/* Simulate RTS */
Regs->PC = Pop(Regs) + (Pop(Regs) << 8) + 1;

View File

@ -38,6 +38,17 @@
/*****************************************************************************/
/* Data */
/*****************************************************************************/
#define PARAVIRT_BASE 0xFFF4
/* Lowest address used by a paravirtualization hook */
/*****************************************************************************/
/* Code */
/*****************************************************************************/