Index: embios/trunk/arm/contextswitch.S |
— | — | @@ -27,8 +27,7 @@ |
28 | 28 | .type context_switch, %function
|
29 | 29 | context_switch:
|
30 | 30 | mrs r1, cpsr
|
31 | | - orr r0, r1, #0xc0
|
32 | | - msr cpsr_c, r0
|
| 31 | + msr cpsr_c, #0xdf
|
33 | 32 | ldr r0, =current_thread
|
34 | 33 | ldr r0, [r0]
|
35 | 34 | stmia r0!, {r0-r14}
|
— | — | @@ -40,8 +39,56 @@ |
41 | 40 | b scheduler_switch
|
42 | 41 | .size context_switch, .-context_switch
|
43 | 42 |
|
| 43 | +.global syscall_handler
|
| 44 | +.type syscall_handler, %function
|
| 45 | +syscall_handler:
|
| 46 | + ldr sp, [lr,#-4]
|
| 47 | + bics sp, sp, #0xff000000
|
| 48 | + beq syscall_breakpoint
|
| 49 | + mov r12, lr
|
| 50 | + mrs sp, spsr
|
| 51 | + msr cpsr_c, sp
|
| 52 | + mov lr, r12
|
| 53 | + ldr r12, [lr,#-4]
|
| 54 | + bic r12, r12, #0xff000000
|
| 55 | + cmp r12, #(swilist_end-swilist_start)/4+1
|
| 56 | + movcs r0, #0
|
| 57 | + addcc pc, pc, r12,lsl#2
|
| 58 | + adr r1, unknown_swi_string
|
| 59 | + mov r2, r12
|
| 60 | +swilist_start:
|
| 61 | + b panicf
|
| 62 | + b get_syscall_table
|
| 63 | +swilist_end:
|
| 64 | +
|
| 65 | +syscall_breakpoint:
|
| 66 | + msr cpsr_c, #0xd3
|
| 67 | + ldr sp, =current_thread
|
| 68 | + ldr sp, [sp]
|
| 69 | + stmia sp!, {r0-r12}
|
| 70 | + mov r2, lr
|
| 71 | + mrs r3, spsr
|
| 72 | + mov r4, #1
|
| 73 | + mov r5, sp
|
| 74 | + msr cpsr_c, #0xdf
|
| 75 | + mov r0, sp
|
| 76 | + mov r1, lr
|
| 77 | + msr cpsr_c, #0xd2
|
| 78 | + stmia r5, {r0-r4}
|
| 79 | + adr lr, resume_thread
|
| 80 | + mov r0, #-1
|
| 81 | + b scheduler_switch
|
| 82 | +.size syscall_handler, .-syscall_handler
|
| 83 | +
|
44 | 84 | .global irq_handler
|
45 | 85 | .type irq_handler, %function
|
| 86 | +was_in_svc_mode:
|
| 87 | + msr cpsr_c, #0xd3
|
| 88 | + sub r3, lr, #4
|
| 89 | + mrs r4, spsr
|
| 90 | + msr cpsr_c, r5
|
| 91 | + b enter_irqhandler
|
| 92 | +
|
46 | 93 | irq_handler:
|
47 | 94 | str r12, [sp,#-4]
|
48 | 95 | ldr r12, =current_thread
|
— | — | @@ -50,12 +97,15 @@ |
51 | 98 | ldr r0, [sp,#-4]
|
52 | 99 | mrs r5, cpsr
|
53 | 100 | mrs r4, spsr
|
54 | | - orr r6, r4, #0xc0
|
55 | | - msr cpsr_c, r6
|
| 101 | + msr cpsr_c, #0xdf
|
56 | 102 | mov r1, sp
|
57 | 103 | mov r2, lr
|
| 104 | + and r3, r4, #0x1f
|
| 105 | + cmp r3, #0x13
|
| 106 | + beq was_in_svc_mode
|
58 | 107 | msr cpsr_c, r5
|
59 | 108 | sub r3, lr, #4
|
| 109 | +enter_irqhandler:
|
60 | 110 | stmia r12, {r0-r4}
|
61 | 111 | bl irqhandler
|
62 | 112 | @ fallthrough
|
— | — | @@ -69,8 +119,7 @@ |
70 | 120 | ldr r1, [lr,#0x40]
|
71 | 121 | ldr lr, [lr,#0x3c]
|
72 | 122 | msr spsr_all, r1
|
73 | | - orr r1, r1, #0xc0
|
74 | | - msr cpsr_c, r1
|
| 123 | + msr cpsr_c, 0xdf
|
75 | 124 | ldmia r0, {r0-r14}
|
76 | 125 | msr cpsr_c, #0xd2
|
77 | 126 | movs pc, lr
|
— | — | @@ -92,3 +141,6 @@ |
93 | 142 | msr cpsr_c, r0
|
94 | 143 | mov pc, lr
|
95 | 144 | .size leave_critical_section, .-leave_critical_section
|
| 145 | +
|
| 146 | +unknown_swi_string:
|
| 147 | + .ascii "Unhandled SWI %08X\0"
|
Index: embios/trunk/syscall.c |
— | — | @@ -0,0 +1,31 @@ |
| 2 | +//
|
| 3 | +//
|
| 4 | +// Copyright 2010 TheSeven
|
| 5 | +//
|
| 6 | +//
|
| 7 | +// This file is part of emBIOS.
|
| 8 | +//
|
| 9 | +// emBIOS is free software: you can redistribute it and/or
|
| 10 | +// modify it under the terms of the GNU General Public License as
|
| 11 | +// published by the Free Software Foundation, either version 2 of the
|
| 12 | +// License, or (at your option) any later version.
|
| 13 | +//
|
| 14 | +// emBIOS is distributed in the hope that it will be useful,
|
| 15 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 16 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
| 17 | +// See the GNU General Public License for more details.
|
| 18 | +//
|
| 19 | +// You should have received a copy of the GNU General Public License along
|
| 20 | +// with emBIOS. If not, see <http://www.gnu.org/licenses/>.
|
| 21 | +//
|
| 22 | +//
|
| 23 | +
|
| 24 | +
|
| 25 | +#include "global.h"
|
| 26 | +#include "syscall.h"
|
| 27 | +
|
| 28 | +
|
| 29 | +void* get_syscall_table()
|
| 30 | +{
|
| 31 | + return NULL;
|
| 32 | +}
|
Index: embios/trunk/syscall.h |
— | — | @@ -0,0 +1,34 @@ |
| 2 | +//
|
| 3 | +//
|
| 4 | +// Copyright 2010 TheSeven
|
| 5 | +//
|
| 6 | +//
|
| 7 | +// This file is part of emBIOS.
|
| 8 | +//
|
| 9 | +// emBIOS is free software: you can redistribute it and/or
|
| 10 | +// modify it under the terms of the GNU General Public License as
|
| 11 | +// published by the Free Software Foundation, either version 2 of the
|
| 12 | +// License, or (at your option) any later version.
|
| 13 | +//
|
| 14 | +// emBIOS is distributed in the hope that it will be useful,
|
| 15 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 16 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
| 17 | +// See the GNU General Public License for more details.
|
| 18 | +//
|
| 19 | +// You should have received a copy of the GNU General Public License along
|
| 20 | +// with emBIOS. If not, see <http://www.gnu.org/licenses/>.
|
| 21 | +//
|
| 22 | +//
|
| 23 | +
|
| 24 | +
|
| 25 | +#ifndef __SYSCALL_H__
|
| 26 | +#define __SYSCALL_H__
|
| 27 | +
|
| 28 | +
|
| 29 | +#include "global.h"
|
| 30 | +
|
| 31 | +
|
| 32 | +void* get_syscall_table() ICODE_ATTR;
|
| 33 | +
|
| 34 | +
|
| 35 | +#endif
|
Index: embios/trunk/panic.h |
— | — | @@ -30,9 +30,9 @@ |
31 | 31 |
|
32 | 32 | enum panic_severity
|
33 | 33 | {
|
34 | | - PANIC_KILLTHREAD,
|
35 | | - PANIC_KILLPROCESS,
|
36 | | - PANIC_FATAL
|
| 34 | + PANIC_KILLTHREAD = 0,
|
| 35 | + PANIC_KILLPROCESS = 1,
|
| 36 | + PANIC_FATAL = 2
|
37 | 37 | };
|
38 | 38 |
|
39 | 39 |
|
Index: embios/trunk/SOURCES |
— | — | @@ -34,3 +34,4 @@ |
35 | 35 | thread.c
|
36 | 36 | usb/usb.c
|
37 | 37 | shutdown.c
|
| 38 | +syscall.c
|
Index: embios/trunk/target/ipodnano2g/crt0.S |
— | — | @@ -93,7 +93,7 @@ |
94 | 94 | ldr sp, =_abortstackend
|
95 | 95 | msr cpsr_c, #0xdb
|
96 | 96 | ldr sp, =_abortstackend
|
97 | | - msr cpsr_c, #0x13
|
| 97 | + msr cpsr_c, #0x1f
|
98 | 98 | ldr sp, =_initstackend
|
99 | 99 | bl init
|
100 | 100 | bl context_switch
|
— | — | @@ -129,7 +129,8 @@ |
130 | 130 |
|
131 | 131 | .type reset_handler, %function
|
132 | 132 | reset_handler:
|
133 | | - adr r0, reset_text
|
| 133 | + mov r0, #0
|
| 134 | + adr r1, reset_text
|
134 | 135 | b panic
|
135 | 136 | reset_text:
|
136 | 137 | .ascii "Hit reset vector!\0"
|
— | — | @@ -137,43 +138,42 @@ |
138 | 139 |
|
139 | 140 | .type undef_instr_handler, %function
|
140 | 141 | undef_instr_handler:
|
141 | | - adr r0, undef_instr_text
|
142 | | - sub r0, lr, #4
|
| 142 | + mov r0, #0
|
| 143 | + adr r1, undef_instr_text
|
| 144 | + sub r2, lr, #4
|
143 | 145 | b panicf
|
144 | 146 | .size undef_instr_handler, .-undef_instr_handler
|
145 | 147 |
|
146 | 148 | .type prefetch_abort_handler, %function
|
147 | 149 | prefetch_abort_handler:
|
148 | | - adr r0, prefetch_abort_text
|
149 | | - sub r0, lr, #4
|
| 150 | + mov r0, #0
|
| 151 | + adr r1, prefetch_abort_text
|
| 152 | + sub r2, lr, #4
|
150 | 153 | b panicf
|
151 | 154 | .size prefetch_abort_handler, .-prefetch_abort_handler
|
152 | 155 |
|
153 | 156 | .type data_abort_handler, %function
|
154 | 157 | data_abort_handler:
|
155 | | - adr r0, data_abort_text
|
156 | | - sub r0, lr, #4
|
| 158 | + mov r0, #0
|
| 159 | + adr r1, data_abort_text
|
| 160 | + sub r2, lr, #4
|
157 | 161 | b panicf
|
158 | 162 | .size data_abort_handler, .-data_abort_handler
|
159 | 163 |
|
160 | 164 | .type reserved_handler, %function
|
161 | 165 | reserved_handler:
|
162 | | - adr r0, reserved_text
|
| 166 | + mov r0, #0
|
| 167 | + adr r1, reserved_text
|
163 | 168 | b panic
|
164 | 169 | .size reserved_handler, .-reserved_handler
|
165 | 170 |
|
166 | 171 | .type fiq_handler, %function
|
167 | 172 | fiq_handler:
|
168 | | - adr r0, fiq_text
|
| 173 | + mov r0, #2
|
| 174 | + adr r1, fiq_text
|
169 | 175 | b panic
|
170 | 176 | .size fiq_handler, .-fiq_handler
|
171 | 177 |
|
172 | | -.type syscall_handler, %function
|
173 | | -syscall_handler:
|
174 | | - adr r0, syscall_text
|
175 | | - b panic
|
176 | | -.size syscall_handler, .-syscall_handler
|
177 | | -
|
178 | 178 | undef_instr_text:
|
179 | 179 | .ascii "Undefined instruction at %08X!\0"
|
180 | 180 |
|
Index: embios/trunk/thread.c |
— | — | @@ -322,7 +322,7 @@ |
323 | 323 | scheduler_threads[i].type = type;
|
324 | 324 | scheduler_threads[i].name = name;
|
325 | 325 | scheduler_threads[i].priority = priority;
|
326 | | - scheduler_threads[i].cpsr = 0x13;
|
| 326 | + scheduler_threads[i].cpsr = 0x1f;
|
327 | 327 | scheduler_threads[i].regs[15] = (uint32_t)code;
|
328 | 328 | scheduler_threads[i].regs[14] = (uint32_t)thread_exit;
|
329 | 329 | scheduler_threads[i].regs[13] = (uint32_t)stack + stacksize;
|
Index: embios/trunk/thread.h |
— | — | @@ -44,10 +44,10 @@ |
45 | 45 | enum thread_state
|
46 | 46 | {
|
47 | 47 | THREAD_FREE = 0,
|
| 48 | + THREAD_SUSPENDED = 1,
|
48 | 49 | THREAD_READY,
|
49 | 50 | THREAD_RUNNING,
|
50 | 51 | THREAD_BLOCKED,
|
51 | | - THREAD_SUSPENDED,
|
52 | 52 | THREAD_DEFUNCT,
|
53 | 53 | THREAD_DEFUNCT_ACK
|
54 | 54 | };
|
— | — | @@ -74,9 +74,10 @@ |
75 | 75 | {
|
76 | 76 | uint32_t regs[16];
|
77 | 77 | uint32_t cpsr;
|
| 78 | + uint32_t state;
|
78 | 79 | const char* name;
|
| 80 | + uint32_t cputime_current;
|
79 | 81 | uint64_t cputime_total;
|
80 | | - uint32_t cputime_current;
|
81 | 82 | uint32_t startusec;
|
82 | 83 | struct scheduler_thread* queue_next;
|
83 | 84 | uint32_t timeout;
|
— | — | @@ -83,7 +84,6 @@ |
84 | 85 | uint32_t blocked_since;
|
85 | 86 | void* blocked_by;
|
86 | 87 | uint32_t* stack;
|
87 | | - enum thread_state state;
|
88 | 88 | enum thread_block block_type;
|
89 | 89 | enum thread_type type;
|
90 | 90 | uint8_t priority;
|