mirror of
https://git.planet-casio.com/Vhex-Kernel-Core/fxlibc.git
synced 2024-12-28 20:43:38 +01:00
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:
parent
e6d2aa0638
commit
13c3390b22
5 changed files with 29 additions and 44 deletions
|
@ -3,27 +3,18 @@
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
/* Get '__jmp_buf' */
|
|
||||||
#include <bits/setjmp.h>
|
#include <bits/setjmp.h>
|
||||||
|
|
||||||
/* User jmp_buf alias */
|
/* Make jmp_buf an array type. (7.13§2) */
|
||||||
typedef struct __jmp_buf jmp_buf[1];
|
typedef struct __jmp_buf jmp_buf[1];
|
||||||
|
|
||||||
|
/* Save the calling environment in __env (not the signal mask), return 0. */
|
||||||
/*
|
extern int setjmp(jmp_buf __env);
|
||||||
** Store the calling environment in ENV, also saving the signal mask.
|
|
||||||
** Return 0.
|
|
||||||
*/
|
|
||||||
extern int setjmp(jmp_buf env);
|
|
||||||
|
|
||||||
/* Standard requires setjmp to be a macro (7.13§1) */
|
/* Standard requires setjmp to be a macro (7.13§1) */
|
||||||
#define setjmp setjmp
|
#define setjmp setjmp
|
||||||
|
|
||||||
/*
|
/* Restore the calling environment from __env, return __val to setjmp. */
|
||||||
** Store the calling environment in ENV, not saving the signal mask.
|
extern void longjmp(jmp_buf __env, int __val);
|
||||||
** Return 0.
|
|
||||||
*/
|
|
||||||
extern void longjmp(jmp_buf env, int val);
|
|
||||||
|
|
||||||
#endif /*__SETJMP_H__*/
|
#endif /*__SETJMP_H__*/
|
||||||
|
|
23
include/target/sh-generic/bits/setjmp.h
Normal file
23
include/target/sh-generic/bits/setjmp.h
Normal 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__*/
|
|
@ -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__*/
|
|
|
@ -28,7 +28,7 @@ int_block:
|
||||||
ldc r1, sr
|
ldc r1, sr
|
||||||
|
|
||||||
context_switch:
|
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
|
! (if needed) then move the context and the returned value into
|
||||||
! non-saved (by the setjmp context) registers.
|
! non-saved (by the setjmp context) registers.
|
||||||
ldc.l @r8+, sr
|
ldc.l @r8+, sr
|
||||||
|
|
|
@ -7,8 +7,6 @@
|
||||||
** int setjmp(jmp_buf env)
|
** int setjmp(jmp_buf env)
|
||||||
** Store the calling environment in ENV, also saving the signal mask.
|
** Store the calling environment in ENV, also saving the signal mask.
|
||||||
** Return 0.
|
** Return 0.
|
||||||
**
|
|
||||||
** TODO: hande signal mask
|
|
||||||
*/
|
*/
|
||||||
_setjmp:
|
_setjmp:
|
||||||
! block interrupt
|
! block interrupt
|
||||||
|
@ -43,4 +41,3 @@ _setjmp:
|
||||||
! return
|
! return
|
||||||
rts
|
rts
|
||||||
mov #0, r0
|
mov #0, r0
|
||||||
.end
|
|
||||||
|
|
Loading…
Reference in a new issue