setjmp: expose setjmp and longjmp to sh-generic

... instead of vhex-generic, where it doesn't really belong because Vhex
might run on other architectures.
This commit is contained in:
Lephenixnoir 2021-05-29 09:56:47 +02:00
parent e6d2aa0638
commit 13c3390b22
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
5 changed files with 29 additions and 44 deletions

View File

@ -3,27 +3,18 @@
#include <stddef.h>
#include <stdint.h>
/* Get '__jmp_buf' */
#include <bits/setjmp.h>
/* User jmp_buf alias */
/* Make jmp_buf an array type. (7.13§2) */
typedef struct __jmp_buf jmp_buf[1];
/*
** Store the calling environment in ENV, also saving the signal mask.
** Return 0.
*/
extern int setjmp(jmp_buf env);
/* Save the calling environment in __env (not the signal mask), return 0. */
extern int setjmp(jmp_buf __env);
/* Standard requires setjmp to be a macro (7.13§1) */
#define setjmp setjmp
/*
** Store the calling environment in ENV, not saving the signal mask.
** Return 0.
*/
extern void longjmp(jmp_buf env, int val);
/* Restore the calling environment from __env, return __val to setjmp. */
extern void longjmp(jmp_buf __env, int __val);
#endif /*__SETJMP_H__*/

View File

@ -0,0 +1,23 @@
#ifndef __BITS_SETJMP_H__
# define __BITS_SETJMP_H__
#include <stddef.h>
#include <stdint.h>
/*
** Custom(?) jmp_buf struct
** The SR register is saved first because the long jump can be involved with
** different register bank. So to avoid this, it's simpler to restore the saved
** SR first (see <src/setjmp/target/sh-generic/longjmp.S>)
*/
struct __jmp_buf
{
uint32_t sr;
uint32_t reg[8];
uint32_t gbr;
uint32_t macl;
uint32_t mach;
uint32_t pr;
};
#endif /*__BITS_SETJMP_H__*/

View File

@ -1,26 +0,0 @@
#ifndef __BITS_SETJMP_H__
# define __BITS_SETJMP_H__
#include <stddef.h>
#include <stdint.h>
/*
** Custom(?) jmp_buf struct
** @note: save only r8 ~ r15 and SR / PC registers
** The SR register is saved first because the longjump can be involved with
** different register bank. So to avoid this, it's more simple to restore the
** saved SR first then restore all register (see <src/setjmp/longjmp.S>)
**
** TODO: save process signal mask ?
*/
struct __jmp_buf
{
uint32_t sr;
uint32_t reg[8];
uint32_t gbr;
uint32_t macl;
uint32_t mach;
uint32_t pr;
};
#endif /*__BITS_SETJMP_H__*/

View File

@ -28,7 +28,7 @@ int_block:
ldc r1, sr
context_switch:
! load the old SR regsiter first to force register bank switch
! load the old SR register first to force register bank switch
! (if needed) then move the context and the returned value into
! non-saved (by the setjmp context) registers.
ldc.l @r8+, sr

View File

@ -7,8 +7,6 @@
** int setjmp(jmp_buf env)
** Store the calling environment in ENV, also saving the signal mask.
** Return 0.
**
** TODO: hande signal mask
*/
_setjmp:
! block interrupt
@ -43,4 +41,3 @@ _setjmp:
! return
rts
mov #0, r0
.end