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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
|
/***************************************************************************
* Copyright (c) 2024 Microsoft Corporation
* Copyright (c) 2026-present Eclipse ThreadX contributors
*
* This program and the accompanying materials are made available under the
* terms of the MIT License which is available at
* https://opensource.org/licenses/MIT.
*
* SPDX-License-Identifier: MIT
**************************************************************************/
/**************************************************************************/
/**************************************************************************/
/** */
/** ThreadX Component */
/** */
/** Timer */
/** */
/**************************************************************************/
/**************************************************************************/
#define UserLocal $4,2
#define C0_TCBind $2,2
.text
.set noreorder
/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* _tx_timer_interrupt MIPS32_interAptiv/GNU */
/* 6.2.1 */
/* AUTHOR */
/* */
/* Scott Larson, Microsoft Corporation */
/* */
/* DESCRIPTION */
/* */
/* This function processes the hardware timer interrupt. This */
/* processing includes incrementing the system clock and checking for */
/* time slice and/or timer expiration. If either is found, the */
/* interrupt context save/restore functions are called along with the */
/* expiration functions. */
/* */
/* INPUT */
/* */
/* None */
/* */
/* OUTPUT */
/* */
/* None */
/* */
/* CALLS */
/* */
/* _tx_thread_smp_protect Get protection */
/* _tx_thread_smp_unprotect Release protection */
/* _tx_timer_expiration_process Timer expiration processing */
/* _tx_thread_time_slice Time slice interrupted thread */
/* */
/* CALLED BY */
/* */
/* interrupt vector */
/* */
/**************************************************************************/
/* VOID _tx_timer_interrupt(VOID)
{ */
.globl _tx_timer_interrupt
_tx_timer_interrupt:
/* Check VPE and throw away any timer interrupts for anything other than VPE 0. */
mfc0 $8, UserLocal # Pickup VPE ID
beq $8, $0, _handle_timer_interrupt # If 0, VPE 0 should handle the interrupt
nop
jr $31 # Other VPE simply returns
nop
_handle_timer_interrupt:
subu $29, $29, 16 # Allocate some storage on the stack
sw $31, 4($29) # Save ra
sw $16, 8($29) # Save preserved register s0
/* Get protection before the timer variables are updated. */
/* _tx_thread_smp_protect(); */
jal _tx_thread_smp_protect # Get VPE protection
nop #
addu $16, $2, 0 # Save return value
/* Increment timer interrupt active counter. */
/* _tx_timer_interrupt_active++; */
la $9, _tx_timer_interrupt_active # Build address of timer interrupt active count
lw $8, ($9) # Pickup timer interrupt active count
addu $8, $8, 1 # Increment timer interrupt active count
sw $8, ($9) # Store new timer interrupt active count
sync
/* Increment the system clock. */
/* _tx_timer_system_clock++; */
la $9, _tx_timer_system_clock # Pickup address of system clock
lw $8, ($9) # Pickup system clock
addu $8, $8, 1 # Increment system clock
sw $8, ($9) # Store new system clock
/* Test for timer expiration. */
/* if (*_tx_timer_current_ptr)
{ */
la $13, _tx_timer_expired # Pickup address of timer expired flag
lw $10, ($13) # Pickup the timer expired flag
bne $10, $0, _tx_timer_done # If already expired, skip expiration processing
nop #
la $9, _tx_timer_current_ptr # Pickup address of current ptr
lw $8, ($9) # Pickup current pointer
la $13, _tx_timer_expired # Pickup address of timer expired flag
lw $10, ($8) # Pickup the current timer entry
ori $12, $0, 1 # Build TX_TRUE flag
beqz $10, _tx_timer_no_timer # If NULL, no timer has expired
nop # Delay slot
/* Set expiration flag. */
/* _tx_timer_expired = TX_TRUE; */
ori $15, $0, 2 # Set local expired flag
b _tx_timer_done # Finished timer processing
sw $12, ($13) # Set expired flag in memory
/* }
else
{ */
_tx_timer_no_timer:
ori $15, $0, 0 # Set expired flag to false
/* No timer expired, increment the timer pointer. */
/* _tx_timer_current_ptr++; */
/* Check for wrap-around. */
/* if (_tx_timer_current_ptr == _tx_timer_list_end) */
la $12, _tx_timer_list_end # Pickup address of list end pointer
lw $11, ($12) # Pickup actual list end
addu $8, $8, 4 # Point to next timer entry
bne $8, $11, _tx_timer_skip_wrap # If not same, good pointer
sw $8, ($9) # Store new timer pointer
/* Wrap to beginning of list. */
/* _tx_timer_current_ptr = _tx_timer_list_start; */
la $12, _tx_timer_list_start # Pickup address of list start pointer
lw $10, ($12) # Pickup start of the list
sw $10, ($9) # Store new timer pointer
_tx_timer_skip_wrap:
/* } */
_tx_timer_done:
/* Did a timer expire? */
/* if (_tx_timer_expired)
{ */
beqz $15, _tx_timer_dont_activate # No, timer not expired
nop # Delay slot
/* Call the timer expiration processing. */
/* _tx_timer_expiration_process(void); */
la $9, _tx_timer_expiration_process # Build address of _tx_timer_expiratoin_process routine
jal $9 # Call _tx_timer_expiration_process
nop
lw $15, ($29) # Recover local expired flag
/* } */
_tx_timer_dont_activate:
/* Call time-slice processing. */
/* _tx_thread_time_slice(); */
la $9, _tx_thread_time_slice # Pickup address of time slice function
jal $9 # Call time slice
nop # Delay slot
/* Decrement timer interrupt active counter. */
/* _tx_timer_interrupt_active--; */
la $9, _tx_timer_interrupt_active # Build address of timer interrupt active count
lw $8, ($9) # Pickup timer interrupt active count
subu $8, $8, 1 # Decrement timer interrupt active count
sw $8, ($9) # Store new timer interrupt active count
sync
/* Release VPE protection. */
/* _tx_thread_smp_unprotect(); */
addu $4, $16, 0 # Setup input parameter
jal _tx_thread_smp_unprotect # Release protection
nop #
lw $31, 4($29) # Recover ra
lw $16, 8($29) # Recover s0
addu $29, $29, 16 # Recover stack space
j $31 # Return to caller
nop # Delay slot
/* } */
|