mirror of
https://git.planet-casio.com/Lephenixnoir/gint.git
synced 2025-01-01 14:33:34 +01:00
e5abe03b89
This commit introduces a large architectural change. Unlike previous models of the fx-9860G series, the G-III models have a new user RAM address different from 8801c000. The purpose of this change is to dynamically load GMAPPED functions to this address by querying the TLB, and call them through a function pointer whose address is determined when loading. Because of the overhead of using a function pointer in both assembly and C code, changes have been made to avoid GMAPPED functions altogether. Current, only cpu_setVBR() and gint_inth_callback() are left, the second being used specifically to enable TLB misses when needed. * Add a .gint.mappedrel section for the function pointers holding addresses to GMAPPED functions; add function pointers for cpu_setVBR() and gint_inth_callback() * Move rram to address 0 instead of the hardcoded 0x8801c000 * Load GMAPPED functions at their linked address + the physical address user RAM is mapped, to and compute their function pointers * Remove the GMAPPED macro since no user function needs it anymore * Add section flags "ax" (code) or "aw" (data) to every custom .section in assembler code, as they default to unpredictable values that can cause the section to be marked NOLOAD by the linker * Update the main kernel, TMU, ETMU and RTC interrupt handlers to use the new indirect calling method This is made possible by new MMU functions giving direct access to the physical area behind any virtualized page. * Add an mmu_translate() function to query the TLB * Add an mmu_uram() function to access user RAM from P1 The exception catching mechanism has been modified to avoid the use of GMAPPED functions altogether. * Set SR.BL=0 and SR.IMASK=15 before calling exception catchers * Move gint_exc_skip() to normal text ROM * Also fix registers not being popped off the stack before a panic The timer drivers have also been modified to avoid GMAPPED functions. * Invoke timer_stop() through gint_inth_callback() and move it to ROM * Move and expand the ETMU driver to span 3 blocks at 0xd00 (ETMU4) * Remove the timer_clear() function by inlining it into the ETMU handler (TCR is provided within the storage block of each timer) * Also split src/timer/inth.s into src/timer/inth-{tmu,etmu}.s Additionally, VBR addresses are now determined at runtime to further reduce hardcoded memory layout addresses in the linker script. * Determine fx-9860G VBR addresses dynamically from mmu_uram() * Determine fx-CG 50 VBR addresses dynamically from mmu_uram() * Remove linker symbols for VBR addresses Comments and documentation have been updated throughout the code to reflect the changes.
67 lines
2.8 KiB
C
67 lines
2.8 KiB
C
//---
|
|
// gint:exc - Exception handling
|
|
//
|
|
// This small module is used to display exceptions and configure when the
|
|
// exception handler displays these messages. This is for advanced users
|
|
// only!
|
|
//---
|
|
|
|
#ifndef GINT_EXC
|
|
#define GINT_EXC
|
|
|
|
#include <gint/defs/attributes.h>
|
|
#include <stdint.h>
|
|
|
|
/* gint_panic(): Panic handler function
|
|
This function is called when an uncaught CPU exception is generated. By
|
|
default, it displays a full-screen error message with the event code and
|
|
basic debugging information. Some custom event codes may be used for kernel
|
|
failure scenarios. This function never returns. */
|
|
GNORETURN void gint_panic(uint32_t code);
|
|
|
|
/* gint_panic_set(): Change the panic handler function
|
|
Sets up a different panic function instead of the default. It the argument
|
|
is NULL, restores the default. */
|
|
void gint_panic_set(GNORETURN void (*panic)(uint32_t code));
|
|
|
|
/* gint_exc_catch(): Set a function to catch exceptions
|
|
|
|
Sets up an exception-catching function. If an exception occurs, before a
|
|
panic is raised, the exception-catching function is executed with interrupt
|
|
disabled and is given a chance to handle the exception. Passing NULL
|
|
disables this feature.
|
|
|
|
The exception-catching function can do anything that does not use interrupts
|
|
or cause an exception, such as logging the exception or any other useful
|
|
mechanism. TLB misses are enabled. In general, this function should be as
|
|
short as possible.
|
|
|
|
What happens next depends on the return value:
|
|
* If it returns 0, the exception is considered handled and execution
|
|
continues normally at or after the offending instruction.
|
|
* If it returns nonzero, a panic is raised.
|
|
|
|
Please be aware that many exceptions are of re-execution type. When
|
|
execution restarts after such an exception is handled, the offending
|
|
instruction is re-executed. This can cause the exception handling mechanism
|
|
to loop. Use gint_exc_skip() to skip over the offending instruction when
|
|
needed. Whether an exception is of re-execution type depends on the
|
|
exception code. */
|
|
void gint_exc_catch(int (*handler)(uint32_t code));
|
|
|
|
/* gint_exc_skip(): Skip pending exception instructions
|
|
|
|
Many exceptions re-execute the offending instruction after the exception is
|
|
handled. For instance the TLB miss handler is supposed to load the required
|
|
page into memory, so that the instruction that accessed unmapped memory can
|
|
be successfully re-executed.
|
|
|
|
When an exception-catching function records an exception without solving it,
|
|
this re-execution will fail again and the exception handling process will
|
|
loop. In such a situation, gint_exc_skip() can be used to manually skip the
|
|
offending instruction, if this is an acceptable resolution.
|
|
|
|
@instructions Number of instructions to skip (usually only one) */
|
|
void gint_exc_skip(int instructions);
|
|
|
|
#endif /* GINT_EXC */
|