forked from espressif/arduino-esp32
-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathoverlay_os_asm.h
executable file
·140 lines (119 loc) · 5.52 KB
/
overlay_os_asm.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// overlay_os_asm.h -- Overlay manager assembly macros for OS use.
// $Id$
// Copyright (c) 2013 Tensilica Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#ifndef OVERLAY_OS_ASM_H
#define OVERLAY_OS_ASM_H
// The macros in here are intended to be used by RTOS task switch code
// to check overlay status. Such code is usually in assembly and cannot
// call C code without penalty. For C code usage, it is best to use the
// corresponding C functions from the library.
// Inline assembly version of xt_overlay_get_state(). The arguments are
// three AR registers (a0-a15):
//
// "pcreg" - should contain the outgoing task's PC, i.e. the point at
// which the task got interrupted. The return value is also
// returned in this register.
// "sr1/2" - Scratch registers. These must be distinct from "pcreg".
//
// The return value is a 32-bit result that should be saved with the
// task context and passed as-is to xt_overlay_check_map.
.macro _xt_overlay_get_state pcreg sr1 sr2
movi \sr1, _mapping_id
movi \sr2, _ovly_id
l16si \sr1, \sr1, 0
l16ui \sr2, \sr2, 0
slli \sr1, \sr1, 16
or \pcreg, \sr1, \sr2
.endm
// Inline assembly version of xt_overlay_check_map(). It requires 5 AR
// registers (a0-a15) as arguments.
//
// "pcreg" - should contain the interrupted task's PC, i.e. the point
// at which the task got interrupted. This will be adjusted
// if required.
// "psreg" - should contain the interrupted task's PS. This will be
// adjusted if required.
// "ovreg" - should contain the overlay state on entry. Contents may
// be clobbered.
// "spreg" - should contain the tasks stack pointer on entry.
// "sr1" - Scratch register. Must be distinct from any of the above.
//
// The return values are "pcreg" and "psreg" and these must be used
// to update the task's PC and PS.
// Note that this macro may store data below the "spreg" pointer. If
// it does, then it will also disable interrupts via the PS, so that
// the task resumes with all interrupts disabled (to avoid corrupting
// this data).
//
// (SP - 24) Overlay ID to restore
// (SP - 28) Task PC
// (SP - 32) Task PS
.macro _xt_overlay_check_map pcreg psreg ovreg spreg sr1
// There are four cases to deal with:
//
// _ovly_id = -1, _mapping_id = -1
// No overlay is mapped or mapping, nothing to do.
//
// _ovly_id >= 0, _mapping_id = -1
// An overlay was mapped, check PC to see if we need a restore.
//
// _ovly_id = -1, _mapping_id >= 0
// An overlay is being mapped. Either it belongs to this task, which
// implies that the PC is in the mapping function, or it does not
// belong to this task. Either way there is nothing to do.
//
// _ovly_id >= 0, _mapping_id >= 0
// Illegal, cannot happen by design. Don't need to handle this.
//
// So, the logic is to check _ovly_id first. If this is >= 0, then
// we check the task PC. If the PC is in the regions of interest then
// we'll patch the return PC to invoke xt_overlay_restore.
.L1:
extui \sr1, \ovreg, 0, 16 // Extract _ovly_id
bbsi.l \sr1, 15, .Lno // If -1 then we're done
mov \ovreg, \sr1 // Restore this one
// Next check the PC to see if it falls within the ranges of interest.
.L2:
movi \sr1, _overlay_vma // Is PC < VMA range ?
bltu \pcreg, \sr1, .L3
movi \sr1, _overlay_vma_end // Is PC > VMA range ?
bgeu \pcreg, \sr1, .L3
j .L4 // PC is in VMA range
.L3:
movi \sr1, _overlay_call_stubs_start // Is PC < call stubs range ?
bltu \pcreg, \sr1, .Lno
movi \sr1, _overlay_call_stubs_end // Is PC > call stubs range ?
bgeu \pcreg, \sr1, .Lno
// If we get here then a restore is needed. Save the overlay ID, PC and PS.
// Return modified PC and PS so that xt_overlay_restore() will execute in
// the context of the task when resumed. Note that the OS resumption code
// may expect PS.EXCM to be set so we leave it as is in the return value.
.L4:
s32e \ovreg, \spreg, -24 // Save overlay ID
s32e \pcreg, \spreg, -28 // Save task PC
s32e \psreg, \spreg, -32 // Save task PS
movi \pcreg, xt_overlay_restore // Adjust resumption PC
movi \sr1, 15
or \psreg, \psreg, \sr1 // Set intlevel to highest
.Lno:
.endm
#endif // OVERLAY_OS_ASM_H