freemyipod r437 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r436‎ | r437 | r438 >
Date:23:26, 16 January 2011
Author:theseven
Status:new
Tags:
Comment:
emCORE: Fix dozens of problems, it finally boots!
Modified paths:
  • /emcore/trunk/init.c (modified) (history)
  • /emcore/trunk/target/ipodclassic/crt0.S (modified) (history)
  • /emcore/trunk/target/ipodclassic/ls.x (modified) (history)
  • /emcore/trunk/target/ipodclassic/storage_ata.c (modified) (history)
  • /emcore/trunk/target/ipodnano2g/crt0.S (modified) (history)
  • /emcore/trunk/target/ipodnano2g/ls.x (modified) (history)
  • /emcore/trunk/target/ipodnano3g/crt0.S (modified) (history)
  • /emcore/trunk/target/ipodnano3g/ls.x (modified) (history)
  • /emcore/trunk/target/ipodnano4g/crt0.S (modified) (history)
  • /emcore/trunk/target/ipodnano4g/ls.x (modified) (history)
  • /emcore/trunk/thread.c (modified) (history)

Diff [purge]

Index: emcore/trunk/init.c
@@ -86,6 +86,7 @@
8787 {
8888 struct scheduler_thread initthread;
8989 uint32_t initstack[0x400];
 90+ void* bootalloc;
9091 #ifdef HAVE_STORAGE
9192 struct scheduler_thread storagethread;
9293 uint32_t storagestack[0x400];
@@ -234,6 +235,7 @@
235236 cprintf(CONSOLE_BOOT, unknownboottypestr, option->type);
236237 }
237238 cputs(CONSOLE_BOOT, nobootoptionsstr);
 239+ free(ib->bootalloc);
238240 }
239241
240242 void init() INITCODE_ATTR;
@@ -251,7 +253,6 @@
252254 #ifdef HAVE_TARGETINIT_EARLY
253255 targetinit_early();
254256 #endif
255 - interrupt_init();
256257 malloc_init();
257258 size_t size = (size_t)(&bootinfo) - (size_t)(&_poolstart) + bootinfo.totalsize;
258259 void* bootalloc = malloc(size);
@@ -260,6 +261,8 @@
261262 ib = (struct initbss*)malloc(sizeof(struct initbss));
262263 reownalloc(ib, &(ib->initthread));
263264 reownalloc(bootalloc, &(ib->initthread));
 265+ ib->bootalloc = bootalloc;
264266 thread_create(&(ib->initthread), initthreadname, initthread, ib->initstack,
265267 sizeof(ib->initstack), USER_THREAD, 127, true);
 268+ interrupt_init();
266269 }
Index: emcore/trunk/target/ipodnano2g/ls.x
@@ -56,11 +56,18 @@
5757 *(.initcode*)
5858 *(.initrodata*)
5959 *(.initdata*)
60 - *(.inittail*)
6160 . = ALIGN(0x4);
6261 _initend = .;
6362 } > INIT
6463
 64+ .inittail :
 65+ {
 66+ _inittailstart = .;
 67+ *(.inittail*)
 68+ . = ALIGN(0x4);
 69+ _inittailend = .;
 70+ } > INIT
 71+
6572 .ibss (NOLOAD) :
6673 {
6774 _ibssstart = .;
Index: emcore/trunk/target/ipodnano2g/crt0.S
@@ -62,6 +62,7 @@
6363 bhi .copysdram
6464 ldr r0, =_ibssstart
6565 ldr r1, =_ibssend
 66+ mov r2, #0
6667 .clearibss:
6768 cmp r1, r0
6869 strhi r2, [r0], #4
Index: emcore/trunk/target/ipodnano3g/ls.x
@@ -56,11 +56,18 @@
5757 *(.initcode*)
5858 *(.initrodata*)
5959 *(.initdata*)
60 - *(.inittail*)
6160 . = ALIGN(0x4);
6261 _initend = .;
6362 } > INIT
6463
 64+ .inittail :
 65+ {
 66+ _inittailstart = .;
 67+ *(.inittail*)
 68+ . = ALIGN(0x4);
 69+ _inittailend = .;
 70+ } > INIT
 71+
6572 .ibss (NOLOAD) :
6673 {
6774 _ibssstart = .;
Index: emcore/trunk/target/ipodnano3g/crt0.S
@@ -62,6 +62,7 @@
6363 bhi .copysdram
6464 ldr r0, =_ibssstart
6565 ldr r1, =_ibssend
 66+ mov r2, #0
6667 .clearibss:
6768 cmp r1, r0
6869 strhi r2, [r0], #4
Index: emcore/trunk/target/ipodnano4g/ls.x
@@ -56,11 +56,18 @@
5757 *(.initcode*)
5858 *(.initrodata*)
5959 *(.initdata*)
60 - *(.inittail*)
6160 . = ALIGN(0x4);
6261 _initend = .;
6362 } > INIT
6463
 64+ .inittail :
 65+ {
 66+ _inittailstart = .;
 67+ *(.inittail*)
 68+ . = ALIGN(0x4);
 69+ _inittailend = .;
 70+ } > INIT
 71+
6572 .ibss (NOLOAD) :
6673 {
6774 _ibssstart = .;
Index: emcore/trunk/target/ipodnano4g/crt0.S
@@ -61,6 +61,7 @@
6262 bhi .copysdram
6363 ldr r0, =_ibssstart
6464 ldr r1, =_ibssend
 65+ mov r2, #0
6566 .clearibss:
6667 cmp r1, r0
6768 strhi r2, [r0], #4
Index: emcore/trunk/target/ipodclassic/ls.x
@@ -56,11 +56,18 @@
5757 *(.initcode*)
5858 *(.initrodata*)
5959 *(.initdata*)
60 - *(.inittail*)
6160 . = ALIGN(0x4);
6261 _initend = .;
6362 } > INIT
6463
 64+ .inittail :
 65+ {
 66+ _inittailstart = .;
 67+ *(.inittail*)
 68+ . = ALIGN(0x4);
 69+ _inittailend = .;
 70+ } > INIT
 71+
6572 .ibss (NOLOAD) :
6673 {
6774 _ibssstart = .;
Index: emcore/trunk/target/ipodclassic/crt0.S
@@ -62,6 +62,7 @@
6363 bhi .copysdram
6464 ldr r0, =_ibssstart
6565 ldr r1, =_ibssend
 66+ mov r2, #0
6667 .clearibss:
6768 cmp r1, r0
6869 strhi r2, [r0], #4
Index: emcore/trunk/target/ipodclassic/storage_ata.c
@@ -556,6 +556,7 @@
557557 else ata_virtual_sectors = ata_total_sectors;
558558 free(buf);
559559 }
 560+ else ata_virtual_sectors = ata_total_sectors;
560561 mutex_unlock(&ata_mutex);
561562 #endif
562563 thread_create(&ata_thread_handle, "ATA idle monitor", ata_thread, ata_stack,
Index: emcore/trunk/thread.c
@@ -283,7 +283,7 @@
284284 }
285285 }
286286
287 - if (scheduler_frozen) thread = 0;
 287+ if (scheduler_frozen) thread = &idle_thread;
288288 else
289289 {
290290 for (t = head_thread; t; t = t->thread_next)
@@ -301,7 +301,7 @@
302302 if (thread && thread->state == THREAD_READY) current_thread = thread;
303303 else
304304 {
305 - thread = NULL;
 305+ thread = &idle_thread;
306306 best = 0xffffffff;
307307 for (t = head_thread; t; t = t->thread_next)
308308 if (t->state == THREAD_READY && t->priority)
@@ -325,6 +325,7 @@
326326 enum thread_type type, int priority, bool run)
327327 {
328328 bool stack_alloced = false;
 329+ bool thread_alloced = false;
329330 if (!stack)
330331 {
331332 stack = malloc(stacksize);
@@ -331,14 +332,18 @@
332333 stack_alloced = true;
333334 }
334335 if (!stack) return NULL;
335 - if (!thread) thread = (struct scheduler_thread*)malloc(sizeof(struct scheduler_thread));
336336 if (!thread)
337337 {
 338+ thread = (struct scheduler_thread*)malloc(sizeof(struct scheduler_thread));
 339+ thread_alloced = true;
 340+ }
 341+ if (!thread)
 342+ {
338343 if (stack_alloced) free(stack);
339344 return NULL;
340345 }
341 - reownalloc(thread, thread);
342 - reownalloc(stack, thread);
 346+ if (thread_alloced) reownalloc(thread, thread);
 347+ if (stack_alloced) reownalloc(stack, thread);
343348
344349 int i;
345350 for (i = 0; i < stacksize >> 2; i ++) ((uint32_t*)stack)[i] = 0xaffebeaf;