OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Source/] [portable/] [GCC/] [NiosII/] [port_asm.S] - Blame information for rev 649

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 572 jeremybenn
/*
2
    FreeRTOS V6.1.1 - Copyright (C) 2011 Real Time Engineers Ltd.
3
 
4
    ***************************************************************************
5
    *                                                                         *
6
    * If you are:                                                             *
7
    *                                                                         *
8
    *    + New to FreeRTOS,                                                   *
9
    *    + Wanting to learn FreeRTOS or multitasking in general quickly       *
10
    *    + Looking for basic training,                                        *
11
    *    + Wanting to improve your FreeRTOS skills and productivity           *
12
    *                                                                         *
13
    * then take a look at the FreeRTOS books - available as PDF or paperback  *
14
    *                                                                         *
15
    *        "Using the FreeRTOS Real Time Kernel - a Practical Guide"        *
16
    *                  http://www.FreeRTOS.org/Documentation                  *
17
    *                                                                         *
18
    * A pdf reference manual is also available.  Both are usually delivered   *
19
    * to your inbox within 20 minutes to two hours when purchased between 8am *
20
    * and 8pm GMT (although please allow up to 24 hours in case of            *
21
    * exceptional circumstances).  Thank you for your support!                *
22
    *                                                                         *
23
    ***************************************************************************
24
 
25
    This file is part of the FreeRTOS distribution.
26
 
27
    FreeRTOS is free software; you can redistribute it and/or modify it under
28
    the terms of the GNU General Public License (version 2) as published by the
29
    Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
30
    ***NOTE*** The exception to the GPL is included to allow you to distribute
31
    a combined work that includes FreeRTOS without being obliged to provide the
32
    source code for proprietary components outside of the FreeRTOS kernel.
33
    FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
34
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
35
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
36
    more details. You should have received a copy of the GNU General Public
37
    License and the FreeRTOS license exception along with FreeRTOS; if not it
38
    can be viewed here: http://www.freertos.org/a00114.html and also obtained
39
    by writing to Richard Barry, contact details for whom are available on the
40
    FreeRTOS WEB site.
41
 
42
    1 tab == 4 spaces!
43
 
44
    http://www.FreeRTOS.org - Documentation, latest information, license and
45
    contact details.
46
 
47
    http://www.SafeRTOS.com - A version that is certified for use in safety
48
    critical systems.
49
 
50
    http://www.OpenRTOS.com - Commercial support, development, porting,
51
    licensing and training services.
52
*/
53
 
54
.extern         vTaskSwitchContext
55
 
56
.set noat
57
 
58
# Exported to start the first task.
59
.globl restore_sp_from_pxCurrentTCB
60
 
61
# Entry point for exceptions.
62
.section .exceptions.entry, "xa"
63
 
64
# Save the entire context of a task.
65
save_context:
66
        addi    ea, ea, -4                      # Point to the next instruction.
67
        addi    sp,     sp, -116                # Create space on the stack.
68
        stw             ra, 0(sp)
69
                                                                # Leave a gap for muldiv 0
70
        stw             at, 8(sp)
71
        stw             r2, 12(sp)
72
        stw             r3, 16(sp)
73
        stw             r4, 20(sp)
74
        stw             r5, 24(sp)
75
        stw             r6, 28(sp)
76
        stw             r7, 32(sp)
77
        stw             r8, 36(sp)
78
        stw             r9, 40(sp)
79
        stw             r10, 44(sp)
80
        stw             r11, 48(sp)
81
        stw             r12, 52(sp)
82
        stw             r13, 56(sp)
83
        stw             r14, 60(sp)
84
        stw             r15, 64(sp)
85
        rdctl   r5, estatus             # Save the eStatus
86
        stw             r5, 68(sp)
87
        stw             ea, 72(sp)                      # Save the PC
88
        stw             r16, 76(sp)                     # Save the remaining registers
89
        stw             r17, 80(sp)
90
        stw             r18, 84(sp)
91
        stw             r19, 88(sp)
92
        stw             r20, 92(sp)
93
        stw             r21, 96(sp)
94
        stw             r22, 100(sp)
95
        stw             r23, 104(sp)
96
        stw             gp, 108(sp)
97
        stw             fp, 112(sp)
98
 
99
save_sp_to_pxCurrentTCB:
100
        movia   et, pxCurrentTCB        # Load the address of the pxCurrentTCB pointer
101
        ldw             et, (et)                        # Load the value of the pxCurrentTCB pointer
102
        stw             sp, (et)                        # Store the stack pointer into the top of the TCB
103
 
104
        .section .exceptions.irqtest, "xa"
105
hw_irq_test:
106
        /*
107
     * Test to see if the exception was a software exception or caused
108
     * by an external interrupt, and vector accordingly.
109
     */
110
    rdctl       r4, ipending            # Load the Pending Interrupts indication
111
        rdctl   r5, estatus             # Load the eStatus (enabled interrupts).
112
    andi        r2, r5, 1                       # Are interrupts enabled globally.
113
    beq         r2, zero, soft_exceptions               # Interrupts are not enabled.
114
    beq         r4, zero, soft_exceptions               # There are no interrupts triggered.
115
 
116
        .section .exceptions.irqhandler, "xa"
117
hw_irq_handler:
118
        call    alt_irq_handler                                 # Call the alt_irq_handler to deliver to the registered interrupt handler.
119
 
120
    .section .exceptions.irqreturn, "xa"
121
restore_sp_from_pxCurrentTCB:
122
        movia   et, pxCurrentTCB                # Load the address of the pxCurrentTCB pointer
123
        ldw             et, (et)                                # Load the value of the pxCurrentTCB pointer
124
        ldw             sp, (et)                                # Load the stack pointer with the top value of the TCB
125
 
126
restore_context:
127
        ldw             ra, 0(sp)               # Restore the registers.
128
                                                        # Leave a gap for muldiv 0.
129
        ldw             at, 8(sp)
130
        ldw             r2, 12(sp)
131
        ldw             r3, 16(sp)
132
        ldw             r4, 20(sp)
133
        ldw             r5, 24(sp)
134
        ldw             r6, 28(sp)
135
        ldw             r7, 32(sp)
136
        ldw             r8, 36(sp)
137
        ldw             r9, 40(sp)
138
        ldw             r10, 44(sp)
139
        ldw             r11, 48(sp)
140
        ldw             r12, 52(sp)
141
        ldw             r13, 56(sp)
142
        ldw             r14, 60(sp)
143
        ldw             r15, 64(sp)
144
        ldw             et, 68(sp)              # Load the eStatus
145
        wrctl   estatus, et     # Write the eStatus
146
        ldw             ea, 72(sp)              # Load the Program Counter
147
        ldw             r16, 76(sp)
148
        ldw             r17, 80(sp)
149
        ldw             r18, 84(sp)
150
        ldw             r19, 88(sp)
151
        ldw             r20, 92(sp)
152
        ldw             r21, 96(sp)
153
        ldw             r22, 100(sp)
154
        ldw             r23, 104(sp)
155
        ldw             gp, 108(sp)
156
        ldw             fp, 112(sp)
157
        addi    sp,     sp, 116         # Release stack space
158
 
159
    eret                                        # Return to address ea, loading eStatus into Status.
160
 
161
        .section .exceptions.soft, "xa"
162
soft_exceptions:
163
        ldw             et, 0(ea)                               # Load the instruction where the interrupt occured.
164
        movhi   at, %hi(0x003B683A)             # Load the registers with the trap instruction code
165
        ori             at, at, %lo(0x003B683A)
166
        cmpne   et, et, at                              # Compare the trap instruction code to the last excuted instruction
167
        beq             et, r0, call_scheduler  # its a trap so switchcontext
168
        break                                                   # This is an un-implemented instruction or muldiv problem.
169
        br              restore_context                 # its something else
170
 
171
call_scheduler:
172
        addi    ea, ea, 4                                               # A trap was called, increment the program counter so it is not called again.
173
        stw             ea, 72(sp)                                              # Save the new program counter to the context.
174
        call    vTaskSwitchContext                              # Pick the next context.
175
        br              restore_sp_from_pxCurrentTCB    # Switch in the task context and restore.

powered by: WebSVN 2.1.0

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