OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [arm/] [arch/] [current/] [src/] [context.S] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
// #===========================================================================
2
// #
3
// #    context.S
4
// #
5
// #    ARM context switch code
6
// #
7
// #===========================================================================
8
// ####ECOSGPLCOPYRIGHTBEGIN####
9
// -------------------------------------------
10
// This file is part of eCos, the Embedded Configurable Operating System.
11
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
12
//
13
// eCos is free software; you can redistribute it and/or modify it under
14
// the terms of the GNU General Public License as published by the Free
15
// Software Foundation; either version 2 or (at your option) any later
16
// version.
17
//
18
// eCos is distributed in the hope that it will be useful, but WITHOUT
19
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
21
// for more details.
22
//
23
// You should have received a copy of the GNU General Public License
24
// along with eCos; if not, write to the Free Software Foundation, Inc.,
25
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
26
//
27
// As a special exception, if other files instantiate templates or use
28
// macros or inline functions from this file, or you compile this file
29
// and link it with other works to produce a work based on this file,
30
// this file does not by itself cause the resulting work to be covered by
31
// the GNU General Public License. However the source code for this file
32
// must still be made available in accordance with section (3) of the GNU
33
// General Public License v2.
34
//
35
// This exception does not invalidate any other reasons why a work based
36
// on this file might be covered by the GNU General Public License.
37
// -------------------------------------------
38
// ####ECOSGPLCOPYRIGHTEND####
39
// #===========================================================================
40
// ######DESCRIPTIONBEGIN####
41
// #
42
// # Author(s):    nickg, gthomas
43
// # Contributors: nickg, gthomas
44
// # Date:         1998-09-15
45
// # Purpose:      ARM context switch code
46
// # Description:  This file contains implementations of the thread context
47
// #               switch routines. It also contains the longjmp() and setjmp()
48
// #               routines.
49
// #
50
// #####DESCRIPTIONEND####
51
// #
52
// #===========================================================================
53
 
54
#include 
55
 
56
#include "arm.inc"
57
 
58
        .text
59
 
60
// ----------------------------------------------------------------------------
61
//  function declaration macro (start body in ARM mode)
62
 
63
#ifdef __thumb__
64
#define FUNC_START_ARM(_name_, _r_)              \
65
        .code   16                              ;\
66
        .thumb_func                             ;\
67
        .globl _name_                           ;\
68
_name_:                                         ;\
69
        ldr     _r_,=_name_ ## _ARM             ;\
70
        bx      _r_                             ;\
71
        .code   32                              ;\
72
_name_ ## _ARM:
73
 
74
#else
75
 
76
#define FUNC_START_ARM(_name_, _r_) \
77
        .globl _name_; \
78
_name_:
79
 
80
#endif
81
 
82
// ----------------------------------------------------------------------------
83
//  hal_thread_switch_context
84
//  Switch thread contexts
85
//  R0 = address of sp of next thread to execute
86
//  R1 = address of sp save location of current thread
87
 
88
// Need to save/restore R4..R12, R13 (sp), R14 (lr)
89
 
90
// Note: this is a little wasteful since r0..r3 don't need to be saved.
91
// They are saved here though so that the information can match the
92
// HAL_SavedRegisters
93
 
94
FUNC_START_ARM(hal_thread_switch_context, r2)
95
        mov     ip,sp
96
        sub     sp,sp,#(ARMREG_SIZE - armreg_lr - 4) // skip svc_sp, svc_lr, vector, cpsr, and pc
97
        stmfd   sp!,{ip,lr}
98
        stmfd   sp!,{r0-r10,fp,ip}
99
        mrs     r2,cpsr
100
        str     r2,[sp,#armreg_cpsr]
101
        str     sp,[r1]                 // return new stack pointer
102
#ifdef __thumb__
103
        b       hal_thread_load_context_ARM // skip mode switch stuff
104
#endif
105
 
106
        # Now load the destination thread by dropping through
107
        # to hal_thread_load_context
108
 
109
// ----------------------------------------------------------------------------
110
//  hal_thread_load_context
111
//  Load thread context
112
//  R0 = address of sp of next thread to execute
113
//  Note that this function is also the second half of
114
//  hal_thread_switch_context and is simply dropped into from it.
115
 
116
FUNC_START_ARM(hal_thread_load_context, r2)
117
        ldr     fp,[r0]                 // get context to restore
118
        mrs     r0,cpsr                 // disable IRQ's
119
        orr     r0,r0,#CPSR_IRQ_DISABLE|CPSR_FIQ_DISABLE
120
        msr     cpsr,r0
121
        ldr     r0,[fp,#armreg_cpsr]
122
        msr     spsr,r0
123
        ldmfd   fp,{r0-r10,fp,ip,sp,lr}
124
#ifdef __thumb__
125
        mrs     r1,spsr                 // r1 is scratch
126
                                        // [r0 holds initial thread arg]
127
        msr     cpsr,r1                 // hopefully no mode switch here!
128
        bx      lr
129
#else
130
        movs    pc,lr                   // also restores saved PSR
131
#endif
132
 
133
// ----------------------------------------------------------------------------
134
//  HAL longjmp, setjmp implementations
135
//  hal_setjmp saves only to callee save registers 4-14
136
//  and lr into buffer supplied in r0[arg0]
137
 
138
FUNC_START_ARM(hal_setjmp, r2)
139
        stmea   r0,{r4-r14}
140
        mov     r0,#0
141
#ifdef __thumb__
142
        bx      lr
143
#else
144
        mov     pc,lr;          # return
145
#endif
146
 
147
//  hal_longjmp loads state from r0[arg0] and returns
148
 
149
FUNC_START_ARM(hal_longjmp, r2)
150
        ldmfd   r0,{r4-r14}
151
        mov     r0,r1;          # return [arg1]
152
#ifdef __thumb__
153
        bx      lr
154
#else
155
        mov     pc,lr
156
#endif
157
 
158
// ----------------------------------------------------------------------------
159
//  end of context.S

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.