freemyipod r43 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r42‎ | r43 | r44 >
Date:20:57, 6 August 2010
Author:theseven
Status:new
Tags:
Comment:
Implement an SWI syscall interface and breakpoints
Modified paths:
  • /embios/trunk/SOURCES (modified) (history)
  • /embios/trunk/arm/contextswitch.S (modified) (history)
  • /embios/trunk/panic.h (modified) (history)
  • /embios/trunk/syscall.c (added) (history)
  • /embios/trunk/syscall.h (added) (history)
  • /embios/trunk/target/ipodnano2g/crt0.S (modified) (history)
  • /embios/trunk/thread.c (modified) (history)
  • /embios/trunk/thread.h (modified) (history)

Diff [purge]

Index: embios/trunk/arm/contextswitch.S
@@ -27,8 +27,7 @@
2828 .type context_switch, %function
2929 context_switch:
3030 mrs r1, cpsr
31 - orr r0, r1, #0xc0
32 - msr cpsr_c, r0
 31+ msr cpsr_c, #0xdf
3332 ldr r0, =current_thread
3433 ldr r0, [r0]
3534 stmia r0!, {r0-r14}
@@ -40,8 +39,56 @@
4140 b scheduler_switch
4241 .size context_switch, .-context_switch
4342
 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+
4484 .global irq_handler
4585 .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+
4693 irq_handler:
4794 str r12, [sp,#-4]
4895 ldr r12, =current_thread
@@ -50,12 +97,15 @@
5198 ldr r0, [sp,#-4]
5299 mrs r5, cpsr
53100 mrs r4, spsr
54 - orr r6, r4, #0xc0
55 - msr cpsr_c, r6
 101+ msr cpsr_c, #0xdf
56102 mov r1, sp
57103 mov r2, lr
 104+ and r3, r4, #0x1f
 105+ cmp r3, #0x13
 106+ beq was_in_svc_mode
58107 msr cpsr_c, r5
59108 sub r3, lr, #4
 109+enter_irqhandler:
60110 stmia r12, {r0-r4}
61111 bl irqhandler
62112 @ fallthrough
@@ -69,8 +119,7 @@
70120 ldr r1, [lr,#0x40]
71121 ldr lr, [lr,#0x3c]
72122 msr spsr_all, r1
73 - orr r1, r1, #0xc0
74 - msr cpsr_c, r1
 123+ msr cpsr_c, 0xdf
75124 ldmia r0, {r0-r14}
76125 msr cpsr_c, #0xd2
77126 movs pc, lr
@@ -92,3 +141,6 @@
93142 msr cpsr_c, r0
94143 mov pc, lr
95144 .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 @@
3131
3232 enum panic_severity
3333 {
34 - PANIC_KILLTHREAD,
35 - PANIC_KILLPROCESS,
36 - PANIC_FATAL
 34+ PANIC_KILLTHREAD = 0,
 35+ PANIC_KILLPROCESS = 1,
 36+ PANIC_FATAL = 2
3737 };
3838
3939
Index: embios/trunk/SOURCES
@@ -34,3 +34,4 @@
3535 thread.c
3636 usb/usb.c
3737 shutdown.c
 38+syscall.c
Index: embios/trunk/target/ipodnano2g/crt0.S
@@ -93,7 +93,7 @@
9494 ldr sp, =_abortstackend
9595 msr cpsr_c, #0xdb
9696 ldr sp, =_abortstackend
97 - msr cpsr_c, #0x13
 97+ msr cpsr_c, #0x1f
9898 ldr sp, =_initstackend
9999 bl init
100100 bl context_switch
@@ -129,7 +129,8 @@
130130
131131 .type reset_handler, %function
132132 reset_handler:
133 - adr r0, reset_text
 133+ mov r0, #0
 134+ adr r1, reset_text
134135 b panic
135136 reset_text:
136137 .ascii "Hit reset vector!\0"
@@ -137,43 +138,42 @@
138139
139140 .type undef_instr_handler, %function
140141 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
143145 b panicf
144146 .size undef_instr_handler, .-undef_instr_handler
145147
146148 .type prefetch_abort_handler, %function
147149 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
150153 b panicf
151154 .size prefetch_abort_handler, .-prefetch_abort_handler
152155
153156 .type data_abort_handler, %function
154157 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
157161 b panicf
158162 .size data_abort_handler, .-data_abort_handler
159163
160164 .type reserved_handler, %function
161165 reserved_handler:
162 - adr r0, reserved_text
 166+ mov r0, #0
 167+ adr r1, reserved_text
163168 b panic
164169 .size reserved_handler, .-reserved_handler
165170
166171 .type fiq_handler, %function
167172 fiq_handler:
168 - adr r0, fiq_text
 173+ mov r0, #2
 174+ adr r1, fiq_text
169175 b panic
170176 .size fiq_handler, .-fiq_handler
171177
172 -.type syscall_handler, %function
173 -syscall_handler:
174 - adr r0, syscall_text
175 - b panic
176 -.size syscall_handler, .-syscall_handler
177 -
178178 undef_instr_text:
179179 .ascii "Undefined instruction at %08X!\0"
180180
Index: embios/trunk/thread.c
@@ -322,7 +322,7 @@
323323 scheduler_threads[i].type = type;
324324 scheduler_threads[i].name = name;
325325 scheduler_threads[i].priority = priority;
326 - scheduler_threads[i].cpsr = 0x13;
 326+ scheduler_threads[i].cpsr = 0x1f;
327327 scheduler_threads[i].regs[15] = (uint32_t)code;
328328 scheduler_threads[i].regs[14] = (uint32_t)thread_exit;
329329 scheduler_threads[i].regs[13] = (uint32_t)stack + stacksize;
Index: embios/trunk/thread.h
@@ -44,10 +44,10 @@
4545 enum thread_state
4646 {
4747 THREAD_FREE = 0,
 48+ THREAD_SUSPENDED = 1,
4849 THREAD_READY,
4950 THREAD_RUNNING,
5051 THREAD_BLOCKED,
51 - THREAD_SUSPENDED,
5252 THREAD_DEFUNCT,
5353 THREAD_DEFUNCT_ACK
5454 };
@@ -74,9 +74,10 @@
7575 {
7676 uint32_t regs[16];
7777 uint32_t cpsr;
 78+ uint32_t state;
7879 const char* name;
 80+ uint32_t cputime_current;
7981 uint64_t cputime_total;
80 - uint32_t cputime_current;
8182 uint32_t startusec;
8283 struct scheduler_thread* queue_next;
8384 uint32_t timeout;
@@ -83,7 +84,6 @@
8485 uint32_t blocked_since;
8586 void* blocked_by;
8687 uint32_t* stack;
87 - enum thread_state state;
8888 enum thread_block block_type;
8989 enum thread_type type;
9090 uint8_t priority;