Commit Graph

267 Commits

Author SHA1 Message Date
Lephe f300338a57
fs: fix tracking of initial position with O_APPEND (*)
(*) O_APPEND is *not* functional yet, this is just a hack for write-only
streams. Currently O_APPEND does not reposition the cursor at the end of
the file before every write.
2022-03-19 19:26:23 +00:00
Lephe 36d66a6317
bopti: fix p4 stride omission from 1384c54b5 2022-01-18 13:50:04 +01:00
Lephe d8b85a9fab
hardware: specify gint[HWRAM] = 8 MiB on the CG-50 2022-01-18 13:49:33 +01:00
Lephe 227c06631b
fs: buffer Fugue writes through RAM
Writing from ROM causes occasional crashes, which are fairly hard to
produce when the buffers are small.
2022-01-10 14:47:14 +01:00
Lephe 8aea762e7a
fs: use a static variable in calls to BFile_Create()
There is no evidence that BFile_Create() keeps the address and writes
to it later on, but I'd rather be overly careful than have to debug a
stack corruption problem in half a year :)
2022-01-10 13:38:28 +01:00
Lephe 59a3b39fb4
dma: do not use ICS in foreign unbinds
I'm pretty sure it makes no difference because the OS does not rely on
interrupts for most (if not all) of its DMA operations, but it's better
to keep it clean anyway.
2022-01-10 13:36:57 +01:00
Lephe ef8707ee9d
dma: remove IE flag at end of transfer
This should have no effect since the channel is disabled, but it's much
better to leave unused modules in predictable states.
2022-01-10 13:31:20 +01:00
Lephe 3aa1471ac5
fs: track offset of Fugue files manually
This helped locate some bugs:
* read() could read past EOF due to BFile_Read() allowing you to read up
  until the end of the last sector, beyond the file size
* pread() did not restore the file offset because the negative seek at
  the end is not relative (that was the CASIOWIN fs API), so pread()
  could not actually be written without knowing the current position
* lseek() would clamp you to EOF but still return its out-of-bounds
  arguments, as a direct result of BFile_Seek() doing that

Benefits:
* Made pread() a generic function
2022-01-06 14:05:52 +01:00
Lephe b549fd68ba
fs: stat(), proper unlink(), rmdir() 2021-12-30 18:17:13 +01:00
Lephe aed90d9b3c
fs: folder support, part 2 (path normalization and root) 2021-12-23 01:19:45 +01:00
Lephe 9cae0040b5
fs: folder support, part 1 (mkdir/rmdir and the opendir(3) family) 2021-12-21 19:01:00 +01:00
Lephe 34c73ba0ba
fs: fix include path for bfile.h 2021-12-15 13:32:39 +01:00
Lephe 6903bd58d5
fs: cast BFile support into generic file descriptors
This paves the way for standard streams, USB streams, and some more.
2021-12-13 18:38:47 +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 8635880bbb
fs: basic filesystem support over BFile 2021-12-11 16:38:28 +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 055c8f405b
r61524: fix a tight freeze window due to a CPU/DMA race 2021-11-20 16:39:46 +01:00
Lephe caf585b0a1
tmu: fix freeze when using sleep_us_spin() with interrupts on
Because of timing the interrupt handler could run before the flag is
checked.
2021-11-15 06:43:00 +01:00
Lephe 1384c54b5f
render-cg: update to bopti formats for Azur 2021-09-28 09:55:26 +02: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 192ff17303
render-cg: fix an incorrect x bound on vertical lines 2021-09-05 17:55:29 +02:00
Lephe d3a2cf07a0
usb: add video capture through the fxlink protocol 2021-08-11 01:43:26 +02:00
Lephe 545db2f9ce
r61524: add low-level get/set and start_frame functions 2021-06-22 17:52:26 +02:00
Lephe 8d444b4f78
kernel: add crash details on illegal instructions 2021-06-17 14:33:45 +02:00
Lephe 03ef59521c
dma: add support for standard DMA access to SPU memory
* Mark SPU memory as sleep-blocking.
* Perform 4-byte accesses only in dma_memset() and dma_memcpy() (32-byte
  accesses freeze as one would expect).

This change does *NOT* implement support for SPU's integrated DMAC.
2021-06-17 14:32:27 +02:00
Lephe 5bd04a9613
cpu, dma: add interrupt-cancellable sleep (perfect async sleep) 2021-06-17 14:32:08 +02:00
Lephe 658413ba19
r61524: fix hardcoded VRAM and don't assume full-size 2021-06-16 21:12:53 +02:00
Lephe 57531e63bf
bopti: fix mistake in edcebff31
Test case was flawed.
2021-06-08 14:52:56 +02:00
Lephe 8e730c2f78
replace gint/std headers with standard ones 2021-06-08 11:01:27 +02:00
Lephe edcebff311
bopti: fix a VRAM overflow through the rightmost column
The checks for VRAM access account for image columns intersecting the
longword before the start of a VRAM line, but not the longword after the
start of a VRAM line. This is now fixed.
2021-06-08 09:38:09 +02:00
Lephe fc6fb9dc09
std: remove the malloc impl and string header 2021-06-07 21:52:52 +02:00
Lephe 3a6165f026
std: remove the TinyMT-based rand implementation 2021-06-07 19:16:58 +02:00
Lephe b25924d740
std: remove the asprintf/vasprintf implementation 2021-06-07 19:04:48 +02:00
Lephe 991b616a10
std: remove the printf implementation 2021-06-07 18:53:05 +02:00
Lephe a9f6c4b622
display-cg: fix a bug in bopti r5g6b6 for very thin images 2021-06-02 11:22:29 +02:00
Lephe 7b40e1e0d0
display: fix a bad overflow for empty lines due to clipping 2021-05-30 23:46:11 +02:00
Lephe 850544349c
kernel: implement _Exit to support exit 2021-05-29 16:29:50 +02:00
Lephe 9e43dcb27a
std: remove string functions now in the fxlibc 2021-05-25 11:18:36 +02:00
Lephe 6c12217777
std: move memcmp, memcpy, memmove, memset to fxlibc 2021-05-25 11:18:33 +02:00
Lephe 7e0ccc3f69
kprint: do not call Grisu2b with input 0.0
It doesn't generate the expected string "0" for some reason, which
causes a freeze somewhere.
2021-05-21 22:30:51 +02:00
Lephe bc3b8f5602
kprint: add support for L modifier in %f
This is just a parsing trick because long double and double are the same
type on this platform.
2021-05-21 22:30:30 +02:00
Lephe 21e91b30d5
keysc: set the key_event_t.mod bit as getkey() did before 2021-05-15 18:37:36 +02:00
Lephe 99403a9504
render: support C_INVERT on fx-CG 50 2021-05-12 09:17:25 +02:00
Lephe 31dcc6fd6c
usb: enable writing with DMA
Nothing particular to change, simply make sure that the DMA channels
have higher priority than the USB module, otherwise the BEMP interrupt
might be executed before the DMA frees the channel, resulting in the
transfer failing because the channel is still busy.

Also reduce BUSWAIT since it works even on high overclock levels, and
keeping it high won't help increase performance.
2021-05-12 09:17:25 +02:00
Lephe a547235f8f
usb: FIFO controllers and fxlink API
This changes fixes the way gint uses the FIFO controllers D0F and D1F
to access the FIFO. It previously used D0F in the main thread and D1F
during interrupt handling, but this is incorrect for several reasons,
mainly the possible change of controllers between a write and a commit,
and numerous instances of two FIFOs managing the same pipe caused by
the constant switching.

gint now treats FIFO controllers as resources allocated to pipes for
the duration of a commit-terminated sequence of writes. The same
controller is used for a single pipe in both normal and interrupt
modes, and released when the pipe is committed. If no controller is
available, asynchronous writes fail and synchronous ones wait.

The fxlink API is also added with a small amount of functions, namely
to transfer screenshots and raw text. Currently these are synchronous
and do not use the DMA, this will be improved later.

Finally:
* Removed pipe logic from src/usb/setup.c, instead letting pipes.c
  handle the special case of the DCP (which might be regularized later)
* Removed the usb_pipe_mode_{read,write} functions as they're actually
  about FIFo controllers and it's not clear yet how a pipe with both
  read and write should be handled. This is left for the future.
* Clarified end-of-sequence semantics after a successful commit.
2021-05-12 09:17:25 +02:00
Lephe 7aa86235a3
cpu: fix a data race occurring on the cpu_atomic lock
The function was designed with multi-threaded concurrency in mind,
where threads can take over while the lock is held and simply block
trying to acquire it, which allows the lock holder to proceed.

However interrupt handlers are different; they have priority, so once
they start they must complete immediately. The cannot afford to block
on the lock as the program would simply freeze. In exchange, they clean
up before they leave, so there are some guarantees on the execution
state even when interrupted.

The correct protection is therefore not a lock but a temporary block on
interrupts. There is no data race on the value of the saved IMASK
because it is preserved during interrupt handling.
2021-05-12 09:17:25 +02:00
Lephe 95dbec17ab
cpu: allow functions to block the sleep() function
This change introduces new sleep_block() and sleep_unblock() functions
that control whether the sleep() function actually sleeps. This type of
behavior was already implemented in the DMA driver, since DMA access to
on-chip memory is paused when sleeping (on-chip memory being paused
itself), which would make waiting for a DMA transfer a freeze.

Because DMA transfers are now asynchronous, and USB transfers that may
involve on-chip memory are coming, this API change allows the DMA and
USB drivers to block the sleep() function so that user code can sleep()
for interrupts without having to worry about asynchronous tasks
requiring on-chip memory to complete.
2021-05-12 09:17:25 +02:00