calling time() or gettimeofday() freezes Saturn

RockinB

Established Member
As the title says, when I call time() or gettimeofday(), the Saturn does not continue execution behind that.

I'm using KPIT GNUSHV0403, newest version today and

have tried it with Satourne and GiriGiri Debugger 6a.

Any idea?
 
if you are testing it on emus, its possible that none of the emus have those commands implemented in the SMPC block.
 
Hey,

I'm noticed something similar. I don't remember the exact function, but when I tried to seed my rand() function with time, controller input would fail. I tried this on Satourne.
 
Have you verified that you even have proper Saturn-specific implementations of either function?
 
Originally posted by Borisz@Mon, 2004-12-13 @ 11:25 PM

if you are testing it on emus, its possible that none of the emus have those commands implemented in the SMPC block.

[post=125865]Quoted post[/post]​


Satourne has all SMPC functions implemented.

You won't be able to run anything without those ...
 
Originally posted by antime@Mon, 2004-12-13 @ 09:45 PM

Have you verified that you even have proper Saturn-specific implementations of either function?

[post=125868]Quoted post[/post]​


Not really.

I got the libc manual where time() and others are explained, so I guess it should be located in libc.a.

The SGL got such a file.

But as I discovered while trying 32x dev, this libc.a has to be declared when linking with ld, but SGL programs have to be linked with gcc(see SGL readme or something).

Bute when linking with gcc, you don't need to declare libc.a, so where does gcc take it's time() implementation from?
 
There is no C library provided with SGL. The default time() function provided by Newlib (the C library bundled with KPIT's toolchain eventually resolves to an attempt to do a system call through the "trapa" instruction which probably ends up in the default exception handler which just sits in a loop doing nothing.)
 
Originally posted by antime@Tue, 2004-12-14 @ 04:52 PM

There is no C library provided with SGL.
[post=125911]Quoted post[/post]​


Hmm, I meant the libc.a that came with the old Saturn compiler. So I would have to reimplement time() and gettimeofday(). Oh, I always hated these functions.
 
You don't have to reimplement newlib, as all operating system calls eventually become a "trapa #34". Since the syscall number and its parameters are passed as normal function parameters in the registers and on the stack you only have to hook the right vector and implement the functions you need. (However looking at the sources for gettimeofday you only get a single-second resolution. If you also need microseconds you will need to modify newlib.)
 
This is completely untested, but something like this could be used to wrap syscalls implemented in C. You have to fill in "TrapTable" with the addresses of the corresponding syscall implementation and then set the trap 34 vector to point to "OSTrap". If the syscall wants to set errno it should set "OSTrapErrno" instead, as newlib takes errno from r1 when returning from the trap. The parameter shuffling works because all calls use 0 to 3 parameters (see newlib/libc/sys/sh/syscalls.c).

Code:
    .text

    .global _OSTrap

    .global _OSTrapErrno

OSTrap:

    sts.l   pr, @-r15

    mova    TrapTable, r0

    shll2   r4

    mov.l   @(r0, r4), r0

    tst     r0, r0

    bt      Exit

    mov     r5, r4

    mov     r6, r5

    jsr     @r0

    mov     r7, r6

    mov.l   OSTrapErrno, r1

    mov.l   @r1, r1

Exit:

    lds.l   @r15+, pr

    rte

    nop

    .balign  4

OSTrapErrno:

    .long   0

TrapTable:

    .long   _SysCall0Implementation

    .long   _SysCall1Implementation

/* ..and so on */
 
Back
Top