Commit Graph

52 Commits

Author SHA1 Message Date
Lephe faead4bc1d
Merge remote-tracking branch 'redoste/gdb' into dev (#27) 2024-03-25 08:05:48 +01:00
Lephe 3a42b5d386
gint: switch away from FX9860G/FXCG50 macros
Not changing much for now, just distilling them into hardware/OS/render
macros. Later on the rendering stuff will become more dynamic and down
the line I want to unify the APIs more.
2024-03-24 08:28:22 +01:00
Lephe 5548bf68ab
render: add R61524 backend to render-fx for build-fxg3a target 2024-03-23 12:09:53 +01:00
Lephe 5ff6a518f6
gint: memory micro-optimizations 2024-03-19 19:03:17 +01:00
Lephe fd5a70e21b
gint: add power-off feature and shortcut in getkey() 2024-01-16 11:42:49 +01:00
Lephe 5655699cd8
gint: reload on-chip sections after world, with option to backup (#26)
Solves the power off crash, at least for programs that don't store
long-term data in on-chip memory.
2024-01-16 11:07:41 +01:00
Lephe 2bb5294578
gint: avoid annoying banner on return from menu on fx-CG
Instead of using GetKeyWait(), we directly call into an internal OS
function, which avoids the need to press a key before we can redraw over
the OS banner and VRAM when coming back. The disassembly to locate the
function was developed by Dr-Carlos.

We still have to redraw when coming back; getkey() will do it by
dupdate() by default, and it that's not a possibility for the
application an option to receive a special event and handle it manually
is provided.
2023-08-19 22:52:53 +02:00
redoste 6efcfa6018
ubc: panic when trying to break in code using register bank 1 2023-06-04 23:20:42 +02:00
redoste 76c82beec6
intc: allow user-space handlers to access the interrupted context
This workaround using a gint_call_t with an odd address is not realy the
cleanest idea but it helps keep the existing intc_generic_handler in
the 32 bytes size limit of the VBR space.
2023-05-27 18:36:15 +02:00
Lephe 1a61e97ef0
mmu: provide read-only access to ITLB 2023-02-02 14:23:03 +01:00
Lephe 6f758cd36c
defs: allow NULL callbacks in gint_call() 2023-01-31 16:04:35 +01:00
Lephe db50c9b192
kernel: more options in System ERROR screen
* Add options to RESET, go to menu, or abort()
* Define weak symbols for driver functions so that low-level debugging
  add-ins can be linked with minimal drivers (CPU/INTC/MMU)
2023-01-25 22:38:39 +01:00
mibi88 984f162cb2 Added gint_set_quit_handler() 2022-11-20 11:48:26 +01:00
mibi88 2fe67412cc Added SetQuitHandler. 2022-11-20 11:48:26 +01:00
calamari a735e074d8 Clean up style mismatch 2022-09-25 11:23:07 -07:00
calamari ddf340cccd Support gint_osmenu() on fx-9860G Slim 2022-09-25 10:37:41 -07:00
calamari b23ed9629e Add HWCALC entry for fx-9860G Slim 2022-09-24 19:48:07 -07:00
Lephe 3e5c45c5ad
kernel: make gint_setrestart() reset everything 2022-09-02 22:29:19 +02:00
Lephe 9924dc4684
fs: add rename() function on fx-CG 2022-08-22 15:25:14 +02:00
Lephe b942bc5d19
clock: add overclock support on fx-CG 10/20/50 2022-05-15 19:20:14 +01:00
Lephe 7a3604ccbb
render-cg: allocate VRAM in the heap; default to double buffering
* Create a heap arena over the OS stack, large enough to hold two VRAMs
  as was previously done, unless GINT_NO_OS_STACK is set at compile
  time. (This replaces GINT_USER_VRAM.)

* Allocate a single VRAM in the heap at startup.

* Use double buffering by default as triple buffering is almost entirely
  useless. dudpate() waits if both VRAMs are identical to prevent
  corruption, but this can be bypassed with R61524 functions as usual.
  This adds about 180 kB of heap data to any add-in using default
  settings.
2022-05-04 20:08:52 +01:00
Lephe 8210524152
ld: merge XRAM and YRAM into a single 16-kiB section 2022-05-04 19:08:54 +01:00
Lephe d8b85a9fab
hardware: specify gint[HWRAM] = 8 MiB on the CG-50 2022-01-18 13:49:33 +01:00
Lephe 321d6937e0
kernel: tentative stack overflow panic, 14 kiB stack on G-III
I saw a crash with the 12 kB stack. Added an error message to diagnose
further similar issues, and bumbed the stack to 14 kB. That's a lot of
space just for BFile but stability is queen... :x
2021-12-11 16:38:31 +01:00
Lephe 71de4dcb95
bfile: clean up header, add BFile_Seek and BFile_GetPos 2021-12-10 07:24:12 +01:00
Lephe 2e5e56f82e
hardware: expose filesystem type in the hardware info
Filesystem type is detected with a trivial heuristic:
* fx-9860G: CASIOWIN, unless Fugue in the G-III series (OS >= 3.00)
* fx-CG 50: Always Fugue
2021-12-06 21:31:00 +01:00
Lephe 86fad757e1
kernel: increase stack size to 12 kB on SH4 fx-9860G
BFile calls on the G-III series can overflow an 8 kB stack, overriding
the VBR which is located just before (!).
2021-12-05 21:15:41 +01:00
Lephe b7173a5109
kernel: fix incorrect interrupt save/restore for MAC on SH3 2021-11-25 14:02:04 +01:00
Lephe 73446aae61
bfile: use non-smem syscalls for Fugue
Not sure how the design is internally, but only these ones can find
files in subfolders.
2021-09-25 15:59:47 +02:00
Lephe 8d444b4f78
kernel: add crash details on illegal instructions 2021-06-17 14:33:45 +02:00
Lephe 5bd04a9613
cpu, dma: add interrupt-cancellable sleep (perfect async sleep) 2021-06-17 14:32:08 +02:00
Lephe 8e730c2f78
replace gint/std headers with standard ones 2021-06-08 11:01:27 +02:00
Lephe 850544349c
kernel: implement _Exit to support exit 2021-05-29 16:29:50 +02:00
Lephe 74b2dbeb36
string: use __restrict instead of restrict for C++ compatibility 2021-04-27 14:48:34 +02:00
Lephe 50cbcd4ac1
usb: fix module not being restored after usb_close()
usb_close() would unpower the module and gint_world_switch_out()
assumed it was powered, so the context switch would fail.
2021-04-27 14:45:12 +02:00
Lephe c37f150600
use GINT_CALL() in every API that has callbacks
* Change gint_inth_callback()
* Add intc_handler_function() to use C functions as handlers instead of
  writing assembler, and use it in the RTC and USB

* Revisit the TMU handlers, which after moving out the callbacks, now
  fit into 3 gates (great!), and adapt the ETMU handler
* Improve the timer driver (less code = better code, removed magic
  constants assuming the VBR layout on SH3/SH4, etc.)
* Remove 2 gates and a gap from the compact scheme on SH3

* Define timer_configure() to replace timer_setup(), which could not be
  cleanly updated to support GINT_CALL()
* Replace rtc_start/stop_timer with rtc_periodic_enable/disable, which
  is less confusing because of ETMU being "RTC timers"
2021-04-27 14:29:38 +02:00
Lephe c9264a06d5
kernel: driver and world system overhaul
Changes in the driver and world system:

* Rewrite driver logic to include more advanced concepts. The notion of
  binding a driver to a device is introduced to formalize wait(); power
  management is now built-in instead of being handled by the drivers
  (for instance DMA). The new driver model is described in great detail
  in <gint/drivers.h>

* Formalized the concept of "world switch" where the hardware state is
  saved and later restored. As a tool, the world switch turns out to be
  very stable, and allows a lot of hardware manipulation that would be
  edgy at best when running in the OS world.

* Added a GINT_DRV_SHARED flag for drivers to specify that their state
  is shared between worlds and not saved/restored. This has a couple of
  uses.

* Exposed a lot more of the internal driver/world system as their is no
  particular downside to it. This includes stuff in <gint/drivers.h>
  and the driver's state structures in <gint/drivers/states.h>. This is
  useful for debugging and for cracked concepts, but there is no
  API stability guarantee.

* Added a more flexible driver level system that allows any 2-digit
  level to be used.

Feature changes:

* Added a CPU driver that provides the VBR change as its state save.
  Because the whole context switch relied on interrupts being disabled
  anyway, there is no longer an inversion of control when setting the
  VBR; this is just part of the CPU driver's configuration. The CPU
  driver may also support other features such as XYRAM block transfer
  in the future.

* Moved gint_inthandler() to the INTC driver under the name
  intc_handler(), pairing up again with intc_priority().

* Added a reentrant atomic lock based on the test-and-set primitive.
  Interrupts are disabled with IMASK=15 for the duration of atomic
  operations.

* Enabled the DMA driver on SH7305-based fx-9860G. The DMA provides
  little benefit on this platform because the RAM is generally faster
  and buffers are ultimately small. The DMA is still not available on
  SH3-based fx-9860G models.

* Solved an extremely obnoxious bug in timer_spin_wait() where the
  timer is not freed, causing the callback to be called when interrupts
  are re-enabled. This increments a random value on the stack. As a
  consequence of the change, removed the long delays in the USB driver
  since they are not actually needed.

Minor changes:

* Deprecated some of the elements in <gint/hardware.h>. There really is
  no good way to "enumerate" devices yet.

* Deprecated gint_switch() in favor of a new function
  gint_world_switch() which uses the GINT_CALL abstraction.

* Made the fx-9860G VRAM 32-aligned so that it can be used for tests
  with the DMA.

Some features of the driver and world systems have not been implemented
yet, but may be in the future:

* Some driver flags should be per-world in order to create multiple
  gint worlds. This would be useful in Yatis' hypervisor.
* A GINT_DRV_LAZY flag would be useful for drivers that don't want to
  be started up automatically during a world switch. This is relevant
  for drivers that have a slow start/stop sequence. However, this is
  tricky to do correctly as it requires dynamic start/stop and also
  tracking which world the current hardware state belongs to.
2021-04-23 20:44:08 +02:00
Lephe fb8d1525f4
kernel: guarantee availability of drivers based on dependency levels
The question of how to handle a partially-restored world state begs for
an elegant symmetrical answer, but that doesn't work unless both kernels
do the save/restore for themselves. So far, things have worked out
because any order works since interrupts are disabled therefore
partially-restored drivers are inactive.

However the USB module requires waits that are best performed with
timers, so the order cannot be chosen arbitrarily. This commit enforces
a gint-centric order where code from a gint driver is only run when all
lower-level drivers are active. This solves some pretty bad freezes with
the USB module.
2021-04-11 18:36:07 +02:00
Lephe 18f9a18925
kmalloc: implement a custom segregated list allocator
The new allocator uses a segregated best-fit algorithm with exact-size
lists for all sizes between 8 bytes (the minimum) and 60 bytes, one list
for blocks of size 64-252 and one for larger blocks.

Arenas managed by this allocator have built-in statistics that track
used and free memory (accounting for block headers), peak memory, and
various allocation results.

In addition, the allocator has self-checks in the form of integrity
verifications, that can be enabled with -DGINT_KMALLOC_DEBUG=1 at
configuration time or with the :dev configuration for GiteaPC. This is
used by gintctl.

The kmalloc interface is extended with a new arena covering all unused
memory in user RAM, managed by gint's allocator. It spans about 4 kB on
SH3 fx-9860G, 16 kB on SH4 fx-9860G, and 500 kB on fx-CG 50, in addition
to the OS heap. This new arena is now the default arena for malloc(),
except on SH3 where some heap problems are currently known.
2021-03-15 15:04:24 +01:00
Lephe 162b11cc73
kmalloc: create the kmalloc interface
This change introduces a centralized memory allocator in the kernel.
This interface can call into multiple arenas, including the default OS
heap and planned arenas managed by a gint algorithm.

The main advantage of this method is that it allows the heap to be
extended over previously-unused areas of RAM such as the end of the
static RAM region (apart from where the stack resides). Not using the OS
heap is also sometimes a matter of correctness since on some OS versions
the heap is known to fragment badly and degrade over time.

I hope the deep control this interfaces gives over meomry allocation
will allow very particular applications like object-specific allocators
in fragmented SPU memory.

This change does not introduce any new algorithm or arena so programs
should behave exactly as before.
2021-03-12 17:24:49 +01:00
Lephe 3885f10ee1
kernel: move VBR at the end of the user RAM area on fx-9860G
This leaves more space available for the heap.
2021-02-15 09:46:59 +01:00
Lephe 293532024d
kernel: fix gint[HWURAM] not being set on fx-9860G
When switching to dynamic TLB the counting of mapped memory was no
longer required at boot time. This was restored weirdly for fx-CG 50 and
not at all for fx-9860G; this is now fixed.
2021-02-02 18:18:02 +01:00
Lephe ad6c108dfc
kernel: always pull the INTC driver
Some very trivial applications might not require its symbols explicitly,
thus the need to force a dependency (otherwise OS interrupts such as the
KEYSC are not disabled and crash the handler very quickly).
2020-10-28 10:01:55 +01:00
Lephe 19951ccf62
mmu: add MMU registers with a driver context for PASCR and IRMCR 2020-10-21 14:44:47 +02:00
Lephe e63ff8351b
dsp: enable integrated DSP in SR at startup 2020-10-09 18:58:43 +02:00
Lephe 078edb50b2
small cleanup 2020-10-05 16:31:37 +02:00
Lephe 9b462deca1
kernel: preload add-in to TLB on SH3 (UNSTABLE) (#12) 2020-09-28 14:09:03 +02:00
Lephe e66b9083b4
kernel: do not copy data to on-chip memory on SH3
Avoids a crash at startup, but the application needs to be smart enough
to not use the data.
2020-09-28 14:06:29 +02:00
Lephe 744d243265
kernel: do SH3 initialization before context saves
This should be obvious and breaks ctx_save() for the RTC and TMU. Which
apparently never came up during testing.
2020-09-28 14:01:32 +02:00
Lephe 589c25c10c
kernel: do not rely on COMMON sections for GMAPPED refs
Seems to break with binutils 2.35.
2020-09-22 15:17:31 +02:00