Skip to content

Commit 5105950

Browse files
committed
Implement getcontext()/setcontext()/makecontext()/swapcontext()
1 parent 3cd9766 commit 5105950

File tree

12 files changed

+663
-70
lines changed

12 files changed

+663
-70
lines changed

include/bits/sigstack.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ enum
4343
typedef struct sigaltstack
4444
{
4545
__ptr_t ss_sp;
46+
#ifdef __MSHORT__
47+
long ss_flags;
48+
#else
4649
int ss_flags;
50+
#endif
4751
size_t ss_size;
4852
} stack_t;

include/sys/ucontext.h

Lines changed: 77 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
/* Copyright (C) 1997, 1999 Free Software Foundation, Inc.
1+
/* Copyright (C) 1997-2022 Free Software Foundation, Inc.
22
This file is part of the GNU C Library.
33
44
The GNU C Library is free software; you can redistribute it and/or
5-
modify it under the terms of the GNU Library General Public License as
6-
published by the Free Software Foundation; either version 2 of the
7-
License, or (at your option) any later version.
5+
modify it under the terms of the GNU Lesser General Public
6+
License as published by the Free Software Foundation; either
7+
version 2.1 of the License, or (at your option) any later version.
88
99
The GNU C Library is distributed in the hope that it will be useful,
1010
but WITHOUT ANY WARRANTY; without even the implied warranty of
1111
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12-
Library General Public License for more details.
12+
Lesser General Public License for more details.
1313
14-
You should have received a copy of the GNU Library General Public
15-
License along with the GNU C Library; if not, see
14+
You should have received a copy of the GNU Lesser General Public
15+
License along with the GNU C Library. If not, see
1616
<https://www.gnu.org/licenses/>. */
1717

1818
/* Modified for MiNTLib by Frank Naumann <fnaumann@freemint.de>. */
@@ -25,85 +25,112 @@
2525
#ifndef _FEATURES_H
2626
# include <features.h>
2727
#endif
28+
/* get definitions of sigset_t and stack_t */
2829
#include <signal.h>
2930

3031
/* Type for general register. */
32+
#ifdef __MSHORT__
33+
typedef long greg_t;
34+
#else
3135
typedef int greg_t;
36+
#endif
3237

3338
/* Number of general registers. */
34-
#define NGREG 18
39+
#define __NGREG 18
40+
#ifdef __USE_MISC
41+
# define NGREG __NGREG
42+
#endif
3543

3644
/* Container for all general registers. */
37-
typedef greg_t gregset_t[NGREG];
45+
typedef greg_t gregset_t[__NGREG];
3846

47+
#ifdef __USE_MISC
3948
/* Number of each register is the `gregset_t' array. */
4049
enum
4150
{
4251
R_D0 = 0,
43-
#define R_D0 R_D0
52+
# define R_D0 R_D0
4453
R_D1 = 1,
45-
#define R_D1 R_D1
54+
# define R_D1 R_D1
4655
R_D2 = 2,
47-
#define R_D2 R_D2
56+
# define R_D2 R_D2
4857
R_D3 = 3,
49-
#define R_D3 R_D3
58+
# define R_D3 R_D3
5059
R_D4 = 4,
51-
#define R_D4 R_D4
60+
# define R_D4 R_D4
5261
R_D5 = 5,
53-
#define R_D5 R_D5
62+
# define R_D5 R_D5
5463
R_D6 = 6,
55-
#define R_D6 R_D6
64+
# define R_D6 R_D6
5665
R_D7 = 7,
57-
#define R_D7 R_D7
66+
# define R_D7 R_D7
5867
R_A0 = 8,
59-
#define R_A0 R_A0
68+
# define R_A0 R_A0
6069
R_A1 = 9,
61-
#define R_A1 R_A1
70+
# define R_A1 R_A1
6271
R_A2 = 10,
63-
#define R_A2 R_A2
72+
# define R_A2 R_A2
6473
R_A3 = 11,
65-
#define R_A3 R_A3
74+
# define R_A3 R_A3
6675
R_A4 = 12,
67-
#define R_A4 R_A4
76+
# define R_A4 R_A4
6877
R_A5 = 13,
69-
#define R_A5 R_A5
78+
# define R_A5 R_A5
7079
R_A6 = 14,
71-
#define R_A6 R_A6
80+
# define R_A6 R_A6
7281
R_A7 = 15,
73-
#define R_A7 R_A7
82+
# define R_A7 R_A7
7483
R_SP = 15,
75-
#define R_SP R_SP
76-
R_PS = 16,
77-
#define R_PS R_PS
78-
R_PC = 17
79-
#define R_PC R_PC
84+
# define R_SP R_SP
85+
R_PC = 16,
86+
# define R_PC R_PC
87+
R_PS = 17
88+
# define R_PS R_PS
8089
};
90+
#endif
91+
92+
#ifdef __USE_MISC
93+
# define __ctx(fld) fld
94+
#else
95+
# define __ctx(fld) __ ## fld
96+
#endif
8197

8298
/* Structure to describe FPU registers. */
83-
typedef struct fpregset
84-
{
85-
int f_fpregs[8][3];
86-
int f_pcr;
87-
int f_psr;
88-
int f_fpiaddr;
89-
} fpregset_t;
99+
typedef struct
100+
{
101+
long __ctx(f_pcr);
102+
long __ctx(f_psr);
103+
long __ctx(f_fpiaddr);
104+
#ifdef __mcoldfire__
105+
long __ctx(f_fpregs)[8][2];
106+
#else
107+
long __ctx(f_fpregs)[8][3];
108+
#endif
109+
} fpregset_t;
90110

91111
/* Context to describe whole processor state. */
92112
typedef struct
93-
{
94-
gregset_t gregs;
95-
fpregset_t fpregs;
96-
} mcontext_t;
113+
{
114+
long __ctx(version);
115+
gregset_t __ctx(gregs);
116+
fpregset_t __ctx(fpregs);
117+
} mcontext_t;
118+
119+
#ifdef __USE_MISC
120+
# define MCONTEXT_VERSION 2
121+
#endif
97122

98123
/* Userlevel context. */
99-
typedef struct ucontext
100-
{
101-
unsigned long int uc_flags;
102-
struct ucontext *uc_link;
103-
__sigset_t uc_sigmask;
104-
stack_t uc_stack;
105-
mcontext_t uc_mcontext;
106-
long int uc_filler[13];
107-
} ucontext_t;
124+
typedef struct ucontext_t
125+
{
126+
unsigned long __ctx(uc_flags);
127+
struct ucontext_t *uc_link;
128+
__sigset_t uc_sigmask;
129+
stack_t uc_stack;
130+
mcontext_t uc_mcontext;
131+
long int uc_filler[13];
132+
} ucontext_t;
133+
134+
#undef __ctx
108135

109136
#endif /* sys/ucontext.h */

include/ucontext.h

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
/* Copyright (C) 1997, 1998 Free Software Foundation, Inc.
1+
/* Copyright (C) 1997-2022 Free Software Foundation, Inc.
22
This file is part of the GNU C Library.
33
44
The GNU C Library is free software; you can redistribute it and/or
5-
modify it under the terms of the GNU Library General Public License as
6-
published by the Free Software Foundation; either version 2 of the
7-
License, or (at your option) any later version.
5+
modify it under the terms of the GNU Lesser General Public
6+
License as published by the Free Software Foundation; either
7+
version 2.1 of the License, or (at your option) any later version.
88
99
The GNU C Library is distributed in the hope that it will be useful,
1010
but WITHOUT ANY WARRANTY; without even the implied warranty of
1111
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12-
Library General Public License for more details.
12+
Lesser General Public License for more details.
1313
14-
You should have received a copy of the GNU Library General Public
14+
You should have received a copy of the GNU Lesser General Public
1515
License along with the GNU C Library; if not, see
1616
<https://www.gnu.org/licenses/>. */
1717

@@ -31,25 +31,26 @@
3131

3232
__BEGIN_DECLS
3333

34-
#if 0 /* not implemneted yet */
3534
/* Get user context and store it in variable pointed to by UCP. */
36-
extern int getcontext __P ((ucontext_t *__ucp));
35+
extern int getcontext (ucontext_t *__ucp) __THROWNL;
3736

3837
/* Set user context from information of variable pointed to by UCP. */
39-
extern int setcontext __P ((__const ucontext_t *__ucp));
38+
extern int setcontext (const ucontext_t *__ucp) __THROWNL;
4039

4140
/* Save current context in context variable pointed to by OUCP and set
4241
context from variable pointed to by UCP. */
43-
extern int swapcontext __P ((ucontext_t *__oucp, __const ucontext_t *__ucp));
42+
extern int swapcontext (ucontext_t *__restrict __oucp, const ucontext_t *__restrict __ucp) __THROWNL;
4443

4544
/* Manipulate user context UCP to continue with calling functions FUNC
4645
and the ARGC-1 parameters following ARGC when the context is used
4746
the next time in `setcontext' or `swapcontext'.
4847
4948
We cannot say anything about the parameters FUNC takes; `void'
5049
is as good as any other choice. */
51-
extern void makecontext __P ((ucontext_t *__ucp, void (*__func) (void),
52-
int __argc, ...));
50+
#ifdef __MSHORT__
51+
extern void makecontext (ucontext_t *__ucp, void (*__func) (void), long __argc, ...) __THROW;
52+
#else
53+
extern void makecontext (ucontext_t *__ucp, void (*__func) (void), int __argc, ...) __THROW;
5354
#endif
5455

5556
__END_DECLS

mintlib/libc-symbols.h

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,25 @@
9393

9494
#else /* !__ASSEMBLER__ */
9595

96+
#ifndef C_LABEL
97+
/* Define a macro we can use to construct the asm name for a C symbol. */
98+
#define C_LABEL(name) C_SYMBOL_NAME(name):
99+
#endif
100+
101+
#define ENTRY(name) \
102+
.globl C_SYMBOL_NAME(name); \
103+
C_LABEL(name)
104+
105+
/* Mark the end of function named SYM. This is used on some platforms
106+
to generate correct debugging information. */
107+
#ifndef END
108+
#define END(sym)
109+
#endif
110+
111+
#undef PSEUDO_END
112+
#define PSEUDO_END(name) \
113+
END (name)
114+
96115
# ifdef HAVE_WEAK_SYMBOLS
97116
# define weak_alias(original, alias) \
98117
.weak C_SYMBOL_NAME (alias); \
@@ -111,6 +130,47 @@
111130

112131
# endif /* !HAVE_WEAK_SYMBOLS */
113132

133+
/* Makros to generate eh_frame unwind information. */
134+
#ifdef __ELF__
135+
# define cfi_startproc .cfi_startproc
136+
# define cfi_endproc .cfi_endproc
137+
# define cfi_def_cfa(reg, off) .cfi_def_cfa reg, off
138+
# define cfi_def_cfa_register(reg) .cfi_def_cfa_register reg
139+
# define cfi_def_cfa_offset(off) .cfi_def_cfa_offset off
140+
# define cfi_adjust_cfa_offset(off) .cfi_adjust_cfa_offset off
141+
# define cfi_offset(reg, off) .cfi_offset reg, off
142+
# define cfi_rel_offset(reg, off) .cfi_rel_offset reg, off
143+
# define cfi_register(r1, r2) .cfi_register r1, r2
144+
# define cfi_return_column(reg) .cfi_return_column reg
145+
# define cfi_restore(reg) .cfi_restore reg
146+
# define cfi_same_value(reg) .cfi_same_value reg
147+
# define cfi_undefined(reg) .cfi_undefined reg
148+
# define cfi_remember_state .cfi_remember_state
149+
# define cfi_restore_state .cfi_restore_state
150+
# define cfi_window_save .cfi_window_save
151+
# define cfi_personality(enc, exp) .cfi_personality enc, exp
152+
# define cfi_lsda(enc, exp) .cfi_lsda enc, exp
153+
#else
154+
# define cfi_startproc
155+
# define cfi_endproc
156+
# define cfi_def_cfa(reg, off)
157+
# define cfi_def_cfa_register(reg)
158+
# define cfi_def_cfa_offset(off)
159+
# define cfi_adjust_cfa_offset(off)
160+
# define cfi_offset(reg, off)
161+
# define cfi_rel_offset(reg, off)
162+
# define cfi_register(r1, r2)
163+
# define cfi_return_column(reg)
164+
# define cfi_restore(reg)
165+
# define cfi_same_value(reg)
166+
# define cfi_undefined(reg)
167+
# define cfi_remember_state
168+
# define cfi_restore_state
169+
# define cfi_window_save
170+
# define cfi_personality(enc, exp)
171+
# define cfi_lsda(enc, exp)
172+
#endif
173+
114174
#endif /* !__ASSEMBLER__ */
115175

116176
/* Currently disabled since not supported by gcc for MiNT. FIXME!!! */

mintlib/sysdep.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,9 @@
2020

2121
/* Define a macro we can use to construct the asm name for a C symbol. */
2222
#ifdef NO_UNDERSCORES
23-
#ifdef __STDC__
2423
#define C_LABEL(name) name##:
2524
#else
26-
#define C_LABEL(name) name/**/:
27-
#endif
28-
#else
29-
#ifdef __STDC__
3025
#define C_LABEL(name) _##name##:
31-
#else
32-
#define C_LABEL(name) _/**/name/**/:
33-
#endif
3426
#endif
3527

3628
#endif

unix/SRCFILES

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ SRCFILES = \
117117
utime.c \
118118
utimes.c \
119119
vfork.S \
120+
getcontext.S \
121+
setcontext.S \
122+
makecontext.S \
123+
swapcontext.S \
120124
wait.c \
121125
wait3.c \
122126
wait4.c \

0 commit comments

Comments
 (0)