source: mainline/uspace/lib/c/arch/mips32/src/fibril.S@ 82d9087

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 82d9087 was a35a3d8, checked in by GitHub <noreply@…>, 7 years ago

Turn context_save/context_restore into standard setjmp/longjmp. (#24)

Turn context_save()/context_restore() into semi-standard __setjmp()/__longjmp().

The original context_* functions are similar to setjmp()/longjmp(), except that the return value is more restricted for the former, and with inverted meaning. This commit adopts the standard return value semantics and acknowledges that these functions are "standard setjmp()/longjmp() with additional implementation-specific properties" by changing the name. The only divergence from the standard is that __longjmp() causes __setjmp() to return its value unchanged, even if it is zero. This is just to avoid extra assembly, and longjmp() checks this in C.

Note that the original use of context_save()/context_restore() to implement context switching in fibril implementation has already been delegated to context_create()/context_swap(), which provide more natural control flow.

  • Property mode set to 100644
File size: 3.7 KB
Line 
1#
2# Copyright (c) 2003-2004 Jakub Jermar
3# All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions
7# are met:
8#
9# - Redistributions of source code must retain the above copyright
10# notice, this list of conditions and the following disclaimer.
11# - Redistributions in binary form must reproduce the above copyright
12# notice, this list of conditions and the following disclaimer in the
13# documentation and/or other materials provided with the distribution.
14# - The name of the author may not be used to endorse or promote products
15# derived from this software without specific prior written permission.
16#
17# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27#
28
29.text
30
31.set noat
32.set noreorder
33
34#include <abi/asmtool.h>
35#include <libarch/fibril_context.h>
36
37FUNCTION_BEGIN(__setjmp)
38 sw $s0, CONTEXT_OFFSET_S0($a0)
39 sw $s1, CONTEXT_OFFSET_S1($a0)
40 sw $s2, CONTEXT_OFFSET_S2($a0)
41 sw $s3, CONTEXT_OFFSET_S3($a0)
42 sw $s4, CONTEXT_OFFSET_S4($a0)
43 sw $s5, CONTEXT_OFFSET_S5($a0)
44 sw $s6, CONTEXT_OFFSET_S6($a0)
45 sw $s7, CONTEXT_OFFSET_S7($a0)
46 sw $s8, CONTEXT_OFFSET_S8($a0)
47 sw $gp, CONTEXT_OFFSET_GP($a0)
48
49 sw $k1, CONTEXT_OFFSET_TLS($a0)
50
51#ifdef CONFIG_FPU
52 mfc1 $t0, $20
53 sw $t0, CONTEXT_OFFSET_F20($a0)
54
55 mfc1 $t0, $21
56 sw $t0, CONTEXT_OFFSET_F21($a0)
57
58 mfc1 $t0, $22
59 sw $t0, CONTEXT_OFFSET_F22($a0)
60
61 mfc1 $t0, $23
62 sw $t0, CONTEXT_OFFSET_F23($a0)
63
64 mfc1 $t0, $24
65 sw $t0, CONTEXT_OFFSET_F24($a0)
66
67 mfc1 $t0, $25
68 sw $t0, CONTEXT_OFFSET_F25($a0)
69
70 mfc1 $t0, $26
71 sw $t0, CONTEXT_OFFSET_F26($a0)
72
73 mfc1 $t0, $27
74 sw $t0, CONTEXT_OFFSET_F27($a0)
75
76 mfc1 $t0, $28
77 sw $t0, CONTEXT_OFFSET_F28($a0)
78
79 mfc1 $t0, $29
80 sw $t0, CONTEXT_OFFSET_F29($a0)
81
82 mfc1 $t0, $30
83 sw $t0, CONTEXT_OFFSET_F30($a0)
84#endif /* CONFIG_FPU */
85
86 sw $ra, CONTEXT_OFFSET_PC($a0)
87 sw $sp, CONTEXT_OFFSET_SP($a0)
88
89 # __setjmp returns 0
90 j $ra
91 li $v0, 0
92FUNCTION_END(__setjmp)
93
94FUNCTION_BEGIN(__longjmp)
95 lw $s0, CONTEXT_OFFSET_S0($a0)
96 lw $s1, CONTEXT_OFFSET_S1($a0)
97 lw $s2, CONTEXT_OFFSET_S2($a0)
98 lw $s3, CONTEXT_OFFSET_S3($a0)
99 lw $s4, CONTEXT_OFFSET_S4($a0)
100 lw $s5, CONTEXT_OFFSET_S5($a0)
101 lw $s6, CONTEXT_OFFSET_S6($a0)
102 lw $s7, CONTEXT_OFFSET_S7($a0)
103 lw $s8, CONTEXT_OFFSET_S8($a0)
104 lw $gp, CONTEXT_OFFSET_GP($a0)
105 lw $k1, CONTEXT_OFFSET_TLS($a0)
106
107#ifdef CONFIG_FPU
108 lw $t0, CONTEXT_OFFSET_F20($a0)
109 mtc1 $t0, $20
110
111 lw $t0, CONTEXT_OFFSET_F21($a0)
112 mtc1 $t0, $21
113
114 lw $t0, CONTEXT_OFFSET_F22($a0)
115 mtc1 $t0, $22
116
117 lw $t0, CONTEXT_OFFSET_F23($a0)
118 mtc1 $t0, $23
119
120 lw $t0, CONTEXT_OFFSET_F24($a0)
121 mtc1 $t0, $24
122
123 lw $t0, CONTEXT_OFFSET_F25($a0)
124 mtc1 $t0, $25
125
126 lw $t0, CONTEXT_OFFSET_F26($a0)
127 mtc1 $t0, $26
128
129 lw $t0, CONTEXT_OFFSET_F27($a0)
130 mtc1 $t0, $27
131
132 lw $t0, CONTEXT_OFFSET_F28($a0)
133 mtc1 $t0, $28
134
135 lw $t0, CONTEXT_OFFSET_F29($a0)
136 mtc1 $t0, $29
137
138 lw $t0, CONTEXT_OFFSET_F30($a0)
139 mtc1 $t0, $30
140#endif /* CONFIG_FPU */
141
142 lw $ra, CONTEXT_OFFSET_PC($a0)
143 lw $sp, CONTEXT_OFFSET_SP($a0)
144
145 # Just for the jump into first function,
146 # but one instruction should not bother us
147 move $t9, $ra
148
149 # __longjmp returns second argument
150 j $ra
151 move $v0, $a1
152FUNCTION_END(__longjmp)
Note: See TracBrowser for help on using the repository browser.