Commit Graph

175 Commits

Author SHA1 Message Date
Lephe 2fd4238d31
core: finalize TLB management in timer callbacks (STABLE)
This change enables interrupts within timer callbacks, making it
possible to load pages to MMU while handling a timer underflow. The call
to TLB_LoadPTEH() has been moved directly into the VBR handler to avoid
jumping to ILRAM for a short call on SH4.

The TMU and ETMU handlers have been changed to callback through a new
function gint_inth_callback() that saves the user bank and a few
registers, then invokes the callback with interrupts enabled and in user
bank; until now, callbacks were invoked with interrupts disabled and in
kernel bank. Note that IMASK is still set so a callback can only be
interrupted by a high-priority interrupt.

A timer_wait() function has also been added to simplify tests that
involve timers. Finally, the priority level of the TMU0 underflow
interrupt has been set to 13 (as per the comments) instead of 7.

This version is the first stable version that handles TLB misses
transparently for large add-ins. It is suitable for every gint
application.
2020-06-17 11:43:26 +02:00
Lephe 8148d89c88
core: backport TLB handling to fx9860g, fix return-to-menu (UNSTABLE)
This change ports the TLB management system to fx9860g through %003.
This raises the size limit for add-ins to about 500k.

Because SH3 fx9860g does not have ILRAM, the GMAPPED attribute has been
made to generate content to a .gint.mapped section which is sent to the
P1 RAM section historically dubbed "real ram" in which gint's data and
VBR are installed. (Now that I think about it, gint's data should try to
go to normal RAM instead to reduce pressure on this invasion.)

Return-to-menu was also fixed on both platforms by narrowing down the
need for code to remain mapped to the chance of running it with
interrupts disabled. The natural distribution of GMAPPED under this
criterion showed that _gint_setvbr had been left under TLB control;
moving it to the proper RAM area fixed gint switches.

Finally, an omission in the bound checks for mappable TEA addresses (TEA
>= 0x00300000) prevented the appearance of a non-interactible System
ERROR popup when some unmapped addresses are accessed.

This version still does not enable interrupts in timer callbacks,
exposing any application to a crash if a timer underflows while its
callback is not mapped. It is not suitable for any stable application!
2020-06-15 20:55:18 +02:00
Lephe fbfcdd7664
render-fx: fix VRAM overflows in gint_dhline() and gint_dvline()
Similar to 610362f.
2020-06-15 13:45:50 +02:00
Lephe d8886c7dbf
core: answer TLB misses and remove startup mapping (UNSTABLE)
This change adds a TLB miss handler that calls __TLB_LoadPTEH() and
removes the startu mapping of add-in pages in the explore() routine of
src/core/start.c.

Note that calling __TLB_LoadPTEH() manually might unexpectedly lead to a
TLB multihit problem as the requested page might be accidentally loaded
by a TLB miss in the code that loads it. A TLB multihit is a platform
reset, so this function should always be considered unsafe to call
(unless the calling code is in a combination of P1 space and ILRAM).

This change also moves a lot of functions out of the .pretext section,
notably topti, as this was designed to allow panic messages when the
add-in couldn't be mapped entirely. By contrast, a GMAPPED macro has
been defined to mark crucial kernel code and data that must remain
mapped at all times. This currently puts the data in ILRAM because
static RAM is not executable. An alternative will have to be found for
SH3-based fx9860g machines.

This version still does not allow TLB misses in timer callbacks and
breaks return-to-menu in a severe way! It is not suitable for any
stable application!
2020-06-14 18:22:20 +02:00
Lephe 4ad2110efc
core: accept large add-ins and setup TLB management (UNSTABLE)
This change modifies the fx-CG 50 linker script to allow add-ins up to
2M and no longer complains about add-ins that don't fit in the TLB.

It also exposes the __TLB_LoadPTEH() syscall (%003 on fx9860g, %00c on
fxcg50) that answers TLB misses. This syscall can be called manually
from an add-in to load some pages and seems to work without problem.

However, this version does not provide any automatic TLB management,
some key areas of the kernel are still under TLB and some user code
(such as timer callbacks) is not! This version is suitable only for
add-ins smaller than 220k!
2020-06-14 11:01:27 +02:00
Lephe b2172dd88e
make: improve the Git commit approximation scheme
Retrieve commit from branch reference when not in detached HEAD mode. A
full rebuild is still needed after changing branch, but not at each
commit.
2020-06-14 08:30:09 +02:00
Lephe 41294ec0a4
printf: fix %% doubling down as a format specifier
When parsing a %% format, the second % character was mistakenly not
skipped over after emitting a '%' output; this resulted in it being
treated as a format specifier. For instance,

  printf("%%d", 12);

would print "%12".
2020-06-14 08:15:00 +02:00
Lephe 610362f8c9
render-cg: fix potential VRAM overflow in gint_dhline()
A missing coordinate check in gint_dhline() would allow lines entirely
out of bounds of the screen to write pixels outside of their expected
range, often wrapping up to the next line, but possibly overflowing from
VRAM.
2020-06-13 20:41:13 +02:00
Lephe caa4f675c9
bopti: deprecate image_t, renamed to bopti_image_t 2020-06-01 12:11:59 +02:00
Lephe 0498344349
periodic check of SH3 compatibility 2020-05-31 22:26:30 +02:00
Lephe 50cc536324
libc: add random number generation with TinyMT
TinyMT is licensed under its own terms. See src/std/tinymt/LICENSE.txt.
2020-05-31 17:03:14 +02:00
Lephe 5ff1662e61
bfile: solve stability issues on fx9860g and fxcg50
This commit improves the stability of gint_switch() in two ways:

1. Wait for hardware availability every time driver contexts are saved
   or reloaded; this solves crashes due to DMA use when gint takes
   control after a BFile call, since BFile_Create() (and possibly
   BFile_Write()) leave the DMA running after returning.

2. Remap the add-in after a switch, as apparently calling BFile
   functions causes some pages to be evicted. This is more noticeable on
   fxcg50 when the size of add-ins nears 220k.

Additionally, dma_transfer_wait() has been updated to not sleep() unless
it is certain that the conditions for wakeup are fulfilled, as this
would sometimes freeze.
2020-05-31 15:52:00 +02:00
Lephe 14e59690a5
update README to clean up mkg3a reference and link 2020-05-21 10:41:35 +02:00
Lephe 4036a583df
bfile: add BFile syscalls on fx-CG 50 (still unstable)
For some reason these syscalls tend to crash in a basic delete, create,
open, write, close workflow (after the write is finished). I'll look
into using the new gint/fxlib switch to use them safely.
2020-05-16 17:11:55 +02:00
Lephe 15dd4990dd
core: add return-to-menu on Graph 90+E (looks bad though)
This is a first version of gint_osmenu() on Graph 90+E. It works on the
same basis as the mono version, with the caveat that the automatic VRAM
display done by the system is terrible because of the reduced resolution
and status bar. Disabling any of this requires taking back control
earlier, which would make the whole GetKeyWait() method obsolete.

Tried the special key processing syscall, but it crashes upon return in
the add-in even before the fxlib code finishes. Maybe try later.
2020-05-16 12:14:13 +02:00
Lephe e217309adf
render-cg: expose vram buffers with dgetvram() and dsetvram() 2020-05-10 23:03:02 +02:00
Lephe d3c43c3ecd
dma: do not wait before initialization
Hangs if the add-in is started first on a fresh boot, probably because
the OS doesn't bother initializing all the channels of its hardware.
2020-05-10 23:00:42 +02:00
Lephe 85311a0b31
drivers: update the model, replacing unload() with wait()
The unload() function is not very relevant for drivers because hardware
state is managed by ctx_save() and ctx_restore() and software state is
managed by underlying drivers when there are dependencies.

For now, it's been replaced with a wait() function that allows drivers
to not be interrupted at any point. It is currently used by the DMA to
wait for ongoing transfers to finish before disabling interrupts (which
would prevent the transfer end from being detected) and switching in and
out of gint.
2020-05-10 16:36:21 +02:00
Lephe 4485e7f865
core, tmu: add gint_switch(), return to menu, and improve timer code
* Add the gint_switch() function which executes user-provided code from
  the system (CASIOWIN) context.
* Added interrupt masks to the core context (should have been there long
  ago).
* Added the gint_osmenu() function that switches out of gint to invoke
  GetKeyWait() and inject KEY_CTRL_MENU to trigger the main menu. This
  uses many CASIOWIN syscalls, but we don't care because gint is unloaded.
  Trickery is used to catch the key following the return in the add-in
  and/or display a new application frame before GetKeyWait() even finishes
  after coming back. This is only available on fx9860g for now.
* Removed any public syscall definition to clear up interfaces.
* Patched the DMA interruption problem in a weird way on fxcg50, a
  driver function will be used to do that properly eventually.
* Changed the driver model to save driver contexts in preallocated
  spaces instead of on the stack for overall less risk.
* Enabled return-to-menu with the MENU key on fx9860g in getkey().
* Changed the keyboard driver to emit releases before presses, as a
  return-to-menu acts as a press+release of different keys in a single
  driver frame, which confuses getkey().
* Fixed a really stupid bug in memcpy() that made the function really
  not work.

Improvements in the timer driver:

* Expose ETMU modules as SH7705_TMU and SH7305_TMU in <gint/mpu/tmu.h>.
* Remove the timer_t structures, using SH*_ETMU and SH*_TMU instead.
  Only interrupt gate entries are left hardcoded.
* Discovered that not only every write to the TCNT or TCR of an ETMU
  takes about 1/32k of a second (hinting at registers being powered by
  the same clock as the timer), but every write occuring while a previous
  write is pending is *lost*. This led to terrible bugs when switching
  ETMU contexts too fast in gint_switch().
* Removed an internal timer_address() function.
* Overall simplified the handling of timers and the initialization step.
2020-05-10 14:03:41 +02:00
Lephe 2cdf925f94
interrupts: save caller-saved registers in main handler
This is an obvious requirement for the interrupt routine, which was
forgotten and only surfaced when I used a timer callback started with
multiplications in an innocent add-in. r0..r7 are saved automatically,
which leaves pr, gbr, mach et macl susceptible to corruption by the
interrupt handler.
2020-05-06 20:45:35 +02:00
Lephe 61da7debc8
code review and display driver changes
t6k11: use the gint array for variant detection
r61524: use true triple buffering by default
display: define DWIDTH and DHEIGHT
display: add C_RGB(r,g,b) (0 ≤ r,g,b ≤ 31) [fxcg50]
2020-02-23 16:05:25 +01:00
Lephe b6f545e63c
getkey: gracefully take command after other keyboard primitives 2020-02-20 21:09:39 +01:00
Lephe d655aa934f
core: slightly better integration of BFile calls 2020-02-19 23:09:06 +01:00
Alice 32aef78600 core: add BFile_FindFirst, Next and Close syscalls
The return code -1 noted in the BFile_FindFirst or BFile_FindNext is
from test,  which mean it could be possibles that they are negative
error code from functions failing and not meaning that no file have been
found, to be sure, the value IML_FILEERR_ENUMERATEEND from filebios.h in
the fxlib need to be checked (and maybe defined in gint with a more
meaningful name for user interactivity)
2020-01-13 23:14:30 +01:00
Alice 07e2de981a core: add BFile_Size syscall 2020-01-13 15:44:04 +01:00
Lephe 3147045196
bopti-cg: add p8, p4, and fix alignment issues on r5g6b5 2019-11-15 13:31:44 +01:00
Lephe 3baa7612ee
use sh-elf by default when building 2019-11-13 19:31:37 +01:00
Lephe 9eb723ee53
render: remove the GINT_NEED_VRAM macro
This macro used to protect the declaration of the [vram] variable of
gint. This variable was short to keep drawing functions short but could
clutter the namespace.

That being said, it's even better to just [#define vram gint_vram] if
you need. This change renames the variable to [gint_vram], exposes it
whenever <gint/display.h> is included, and removes the GINT_NEED_VRAM
macro altogether.
2019-10-27 08:14:42 +01:00
Lephe 95a3345326
keyboard: add keydown() in the model
This change adds a keydown() function that is synchronized with events,
ie. it returns the key state as seen by previously read events.

It also completely eliminates low-level repeat events, which are not
very meaningul as the keyboard scan frequency goes up (and would be
meaningless if KEYSC interrupts were used), and adapts getkey() by
giving it access to the current driver time through pollevent().
2019-09-28 19:25:01 +02:00
Lephe 86cd9b98d4
small improvements
* Update TOTO list
* Change the type of gint_vbr to comply with a new warning in GCC 9
* Add strcmp()
2019-09-19 15:59:38 +02:00
Lephe a05d3416f0
std: support integer size formats (hh, h, l, ll) 2019-09-19 15:58:35 +02:00
Lephe fc7aab6eba
dma: finalize dma_memset() and dma_memcpy()
Adds support for dma_memcpy(), and uses a proper ILRAM allocation scheme
(static linking here) for the temporary buffer in dma_memset().
2019-09-15 19:30:57 +02:00
Lephe 15558c8fb3
support data loading in ILRAM, XRAM and YRAM
This change adds support for three sections .ilram, .xram and .yram,
along with three macros GILRAM, GXRAM and GYRAM, that can be used to
statically load data to on-chip memory.
2019-09-15 19:29:47 +02:00
Lephe bb77e4588d
dma: fix freezes when transferring to/from IL memory
The IL memory is unavailable when the processor goes to sleep, causing
any involved DMA transfer to stall. The dma_transfer_wait() normally
sleeps to save battery power, but this causes the whole system to freeze
and never wake up.

This change lets dma_transfer_wait() decide dynamically whether to sleep
or spinlock. There is no concrete improvement over dma_transfer_noint()
when using IL memory, but it makes dma_transfer() fully generic.

Obviously the same goes for X and Y memory.
2019-09-15 15:20:23 +02:00
Lephe 552b9b9a43
dma: only expose API on fxcg50
Currently there seems to be no DMA at all on fx9860g. Further
investigation would be required, because this would be the first major
difference between the SH7305's found in fx9860g and fxcg50 models.

An automated peripheral register discovery strategy might help, but
identifying discovered registers would be non trivial.

Also use the pruning ability of the Makefile to avoid troublesome
ifdef's in the code.
2019-09-15 10:20:37 +02:00
Lephe 5630814897
core: allow custom panics and exception catching
This change introduces two new mechanismes for executing user code when
an exception occurs.

* This first is the custom panic message, which usually displays "System
  ERROR". The function that performs this task can now be user-defined.
  It is also run in user mode because the exception handler rte's into
  it, allowing it to execute any kind of interrupt-inducing task. The
  behavior is undefined if this function raises an exception.

* The second is an exception-catching function, which (when set) is
  called every time an exception occurs, and is granted the chance of
  handling the exception to continue execution normally. It can be used
  in various ways, the most primitive of which is recording the
  exception and going back. It runs in interrupt mode and must not raise
  any kind of exception.
2019-09-13 08:10:30 +02:00
Lephe 9a4ae4c80a
minor new definitions 2019-09-13 08:08:22 +02:00
Lephe 4a8ba82fab
truly support custom toolchains (almost) 2019-09-12 18:19:23 +02:00
Lephe ef0e5e32f8
render: add one-parameter dvline() and dhline()
Behave like Basic's Horizontal and Vertical commands. Internal dline()
optimizations are renamed gint_dhline() and gint_dvline().

Also supports ghline() and gvline() in the gray engine.

Optimization cases here are amost negligible due to limiting RAM access
frequencies and the very limited amount of work accomplished in the
functions. Code maintainability is prioritized by using dline().
2019-09-07 11:26:11 +02:00
Lephe 61e68d01bb
expose more platform-agnostic code
May be useful later on for libraries such as libprof.
2019-09-06 12:16:31 +02:00
lephe b9cba1d00a
style, formatting, font 2019-09-03 22:29:04 +02:00
lephe e1aca8d89b
exc: add exception handlers, use them in the DMA
This change introduces exception handlers that default to a fatal error
with an on-screen description of the exception and some debugging
information.

It also adds the dprint() function as a definitely-needed helper and
removes bootlog_unmapped() by using the exception handler for the fatal
error display. (Also printf() is now required in all gint add-ins; this
is sad, but space is not as much of a constraint as debugging.)

Finally, the exception handler is used to handle an interrupt which is
an exception in practice, the DMA address error. On fx-CG 50, additional
DMA-related information is displayed on the screen. This is left out on
fx-9860G as there is not enough space.
2019-09-03 22:15:00 +02:00
lephe 6d54a5fe0a dma: add exception handler and dma_memset() 2019-08-27 21:18:44 +02:00
lephe 652637d475 bopti: add support for r5g6b5 and r5g6b5a on fxcg50
This commit introduces bopti for fxcg50 with the first basic 16-bit
formats. The performance is rather slow, especially for large images,
and will need refinements and/or overclock to be really efficient in
full-screen real-time applications.
2019-08-27 21:04:07 +02:00
lephe 62a49a543e topti: spacing bug fix on fxcg50
Fixes a bug where spaces were not being rendered.
2019-08-27 21:02:28 +02:00
lephe b3cbb0a43f dma: add support for all six channels (merges #1) 2019-08-08 11:21:10 +02:00
lephe ab0fa06a1d bopti: fix bug in non-zero stride renders
Forgot to take into account the number of layers in the input
stride. Anything after the first line would be pretty much
garbage.
2019-08-06 16:17:25 +02:00
lephe 2e17b77e56 bopti: first fxcg50 version with r5g6b5 and r5g6b5a
This commit introduces bopti for fx-CG 50. Currently the only
interfaces are the bopti_render_{clip,noclip} functions, and the
only supported formats are r5g6b5 and r5g6b5a.

The algorithm for r5g6b5 is optimized to perform longword accesses
using movua.l, whereas the algorithm for r5g6b5a uses plain word
accesses because transparency checks feel more difficult than one
more loop iteration.

These algorithms are still slow for large surfaces and struggle to
keep up 25 FPS in full-screen, so possible improvements with the
DMA should definitely be tested before restorting to overclock.
2019-08-04 13:59:35 +02:00
lephe 64dbe6021d some formatting and comment updates 2019-08-04 13:59:17 +02:00
Antoine 8cbd5be038 Ajout de la fonction srtcat et modification du 0 de la police de la Graph 90+E 2019-07-31 04:24:42 -04:00