| Index: emcore/trunk/init.c | 
| — | — | @@ -86,6 +86,7 @@ | 
| 87 | 87 | { | 
| 88 | 88 | struct scheduler_thread initthread; | 
| 89 | 89 | uint32_t initstack[0x400]; | 
|  | 90 | +    void* bootalloc; | 
| 90 | 91 | #ifdef HAVE_STORAGE | 
| 91 | 92 | struct scheduler_thread storagethread; | 
| 92 | 93 | uint32_t storagestack[0x400]; | 
| — | — | @@ -234,6 +235,7 @@ | 
| 235 | 236 | cprintf(CONSOLE_BOOT, unknownboottypestr, option->type); | 
| 236 | 237 | } | 
| 237 | 238 | cputs(CONSOLE_BOOT, nobootoptionsstr); | 
|  | 239 | +    free(ib->bootalloc); | 
| 238 | 240 | } | 
| 239 | 241 |  | 
| 240 | 242 | void init() INITCODE_ATTR; | 
| — | — | @@ -251,7 +253,6 @@ | 
| 252 | 254 | #ifdef HAVE_TARGETINIT_EARLY | 
| 253 | 255 | targetinit_early(); | 
| 254 | 256 | #endif | 
| 255 |  | -    interrupt_init();
 | 
| 256 | 257 | malloc_init(); | 
| 257 | 258 | size_t size = (size_t)(&bootinfo) - (size_t)(&_poolstart) + bootinfo.totalsize; | 
| 258 | 259 | void* bootalloc = malloc(size); | 
| — | — | @@ -260,6 +261,8 @@ | 
| 261 | 262 | ib = (struct initbss*)malloc(sizeof(struct initbss)); | 
| 262 | 263 | reownalloc(ib, &(ib->initthread)); | 
| 263 | 264 | reownalloc(bootalloc, &(ib->initthread)); | 
|  | 265 | +    ib->bootalloc = bootalloc; | 
| 264 | 266 | thread_create(&(ib->initthread), initthreadname, initthread, ib->initstack, | 
| 265 | 267 | sizeof(ib->initstack), USER_THREAD, 127, true); | 
|  | 268 | +    interrupt_init(); | 
| 266 | 269 | } | 
| Index: emcore/trunk/target/ipodnano2g/ls.x | 
| — | — | @@ -56,11 +56,18 @@ | 
| 57 | 57 | *(.initcode*) | 
| 58 | 58 | *(.initrodata*) | 
| 59 | 59 | *(.initdata*) | 
| 60 |  | -        *(.inittail*)
 | 
| 61 | 60 | . = ALIGN(0x4); | 
| 62 | 61 | _initend = .; | 
| 63 | 62 | } > INIT | 
| 64 | 63 |  | 
|  | 64 | +    .inittail : | 
|  | 65 | +    { | 
|  | 66 | +        _inittailstart = .; | 
|  | 67 | +        *(.inittail*) | 
|  | 68 | +        . = ALIGN(0x4); | 
|  | 69 | +        _inittailend = .; | 
|  | 70 | +    } > INIT | 
|  | 71 | + | 
| 65 | 72 | .ibss (NOLOAD) : | 
| 66 | 73 | { | 
| 67 | 74 | _ibssstart = .; | 
| Index: emcore/trunk/target/ipodnano2g/crt0.S | 
| — | — | @@ -62,6 +62,7 @@ | 
| 63 | 63 | bhi	.copysdram | 
| 64 | 64 | ldr	r0, =_ibssstart | 
| 65 | 65 | ldr	r1, =_ibssend | 
|  | 66 | +	mov	r2, #0 | 
| 66 | 67 | .clearibss: | 
| 67 | 68 | cmp	r1, r0 | 
| 68 | 69 | strhi	r2, [r0], #4 | 
| Index: emcore/trunk/target/ipodnano3g/ls.x | 
| — | — | @@ -56,11 +56,18 @@ | 
| 57 | 57 | *(.initcode*) | 
| 58 | 58 | *(.initrodata*) | 
| 59 | 59 | *(.initdata*) | 
| 60 |  | -        *(.inittail*)
 | 
| 61 | 60 | . = ALIGN(0x4); | 
| 62 | 61 | _initend = .; | 
| 63 | 62 | } > INIT | 
| 64 | 63 |  | 
|  | 64 | +    .inittail : | 
|  | 65 | +    { | 
|  | 66 | +        _inittailstart = .; | 
|  | 67 | +        *(.inittail*) | 
|  | 68 | +        . = ALIGN(0x4); | 
|  | 69 | +        _inittailend = .; | 
|  | 70 | +    } > INIT | 
|  | 71 | + | 
| 65 | 72 | .ibss (NOLOAD) : | 
| 66 | 73 | { | 
| 67 | 74 | _ibssstart = .; | 
| Index: emcore/trunk/target/ipodnano3g/crt0.S | 
| — | — | @@ -62,6 +62,7 @@ | 
| 63 | 63 | bhi	.copysdram | 
| 64 | 64 | ldr	r0, =_ibssstart | 
| 65 | 65 | ldr	r1, =_ibssend | 
|  | 66 | +	mov	r2, #0 | 
| 66 | 67 | .clearibss: | 
| 67 | 68 | cmp	r1, r0 | 
| 68 | 69 | strhi	r2, [r0], #4 | 
| Index: emcore/trunk/target/ipodnano4g/ls.x | 
| — | — | @@ -56,11 +56,18 @@ | 
| 57 | 57 | *(.initcode*) | 
| 58 | 58 | *(.initrodata*) | 
| 59 | 59 | *(.initdata*) | 
| 60 |  | -        *(.inittail*)
 | 
| 61 | 60 | . = ALIGN(0x4); | 
| 62 | 61 | _initend = .; | 
| 63 | 62 | } > INIT | 
| 64 | 63 |  | 
|  | 64 | +    .inittail : | 
|  | 65 | +    { | 
|  | 66 | +        _inittailstart = .; | 
|  | 67 | +        *(.inittail*) | 
|  | 68 | +        . = ALIGN(0x4); | 
|  | 69 | +        _inittailend = .; | 
|  | 70 | +    } > INIT | 
|  | 71 | + | 
| 65 | 72 | .ibss (NOLOAD) : | 
| 66 | 73 | { | 
| 67 | 74 | _ibssstart = .; | 
| Index: emcore/trunk/target/ipodnano4g/crt0.S | 
| — | — | @@ -61,6 +61,7 @@ | 
| 62 | 62 | bhi	.copysdram | 
| 63 | 63 | ldr	r0, =_ibssstart | 
| 64 | 64 | ldr	r1, =_ibssend | 
|  | 65 | +	mov	r2, #0 | 
| 65 | 66 | .clearibss: | 
| 66 | 67 | cmp	r1, r0 | 
| 67 | 68 | strhi	r2, [r0], #4 | 
| Index: emcore/trunk/target/ipodclassic/ls.x | 
| — | — | @@ -56,11 +56,18 @@ | 
| 57 | 57 | *(.initcode*) | 
| 58 | 58 | *(.initrodata*) | 
| 59 | 59 | *(.initdata*) | 
| 60 |  | -        *(.inittail*)
 | 
| 61 | 60 | . = ALIGN(0x4); | 
| 62 | 61 | _initend = .; | 
| 63 | 62 | } > INIT | 
| 64 | 63 |  | 
|  | 64 | +    .inittail : | 
|  | 65 | +    { | 
|  | 66 | +        _inittailstart = .; | 
|  | 67 | +        *(.inittail*) | 
|  | 68 | +        . = ALIGN(0x4); | 
|  | 69 | +        _inittailend = .; | 
|  | 70 | +    } > INIT | 
|  | 71 | + | 
| 65 | 72 | .ibss (NOLOAD) : | 
| 66 | 73 | { | 
| 67 | 74 | _ibssstart = .; | 
| Index: emcore/trunk/target/ipodclassic/crt0.S | 
| — | — | @@ -62,6 +62,7 @@ | 
| 63 | 63 | bhi	.copysdram | 
| 64 | 64 | ldr	r0, =_ibssstart | 
| 65 | 65 | ldr	r1, =_ibssend | 
|  | 66 | +	mov	r2, #0 | 
| 66 | 67 | .clearibss: | 
| 67 | 68 | cmp	r1, r0 | 
| 68 | 69 | strhi	r2, [r0], #4 | 
| Index: emcore/trunk/target/ipodclassic/storage_ata.c | 
| — | — | @@ -556,6 +556,7 @@ | 
| 557 | 557 | else ata_virtual_sectors = ata_total_sectors; | 
| 558 | 558 | free(buf); | 
| 559 | 559 | } | 
|  | 560 | +    else ata_virtual_sectors = ata_total_sectors; | 
| 560 | 561 | mutex_unlock(&ata_mutex); | 
| 561 | 562 | #endif | 
| 562 | 563 | thread_create(&ata_thread_handle, "ATA idle monitor", ata_thread, ata_stack, | 
| Index: emcore/trunk/thread.c | 
| — | — | @@ -283,7 +283,7 @@ | 
| 284 | 284 | } | 
| 285 | 285 | } | 
| 286 | 286 |  | 
| 287 |  | -    if (scheduler_frozen) thread = 0;
 | 
|  | 287 | +    if (scheduler_frozen) thread = &idle_thread; | 
| 288 | 288 | else | 
| 289 | 289 | { | 
| 290 | 290 | for (t = head_thread; t; t = t->thread_next) | 
| — | — | @@ -301,7 +301,7 @@ | 
| 302 | 302 | if (thread && thread->state == THREAD_READY) current_thread = thread; | 
| 303 | 303 | else | 
| 304 | 304 | { | 
| 305 |  | -            thread = NULL;
 | 
|  | 305 | +            thread = &idle_thread; | 
| 306 | 306 | best = 0xffffffff; | 
| 307 | 307 | for (t = head_thread; t; t = t->thread_next) | 
| 308 | 308 | if (t->state == THREAD_READY && t->priority) | 
| — | — | @@ -325,6 +325,7 @@ | 
| 326 | 326 | enum thread_type type, int priority, bool run) | 
| 327 | 327 | { | 
| 328 | 328 | bool stack_alloced = false; | 
|  | 329 | +    bool thread_alloced = false; | 
| 329 | 330 | if (!stack) | 
| 330 | 331 | { | 
| 331 | 332 | stack = malloc(stacksize); | 
| — | — | @@ -331,14 +332,18 @@ | 
| 332 | 333 | stack_alloced = true; | 
| 333 | 334 | } | 
| 334 | 335 | if (!stack) return NULL; | 
| 335 |  | -    if (!thread) thread = (struct scheduler_thread*)malloc(sizeof(struct scheduler_thread));
 | 
| 336 | 336 | if (!thread) | 
| 337 | 337 | { | 
|  | 338 | +        thread = (struct scheduler_thread*)malloc(sizeof(struct scheduler_thread)); | 
|  | 339 | +        thread_alloced = true; | 
|  | 340 | +    } | 
|  | 341 | +    if (!thread) | 
|  | 342 | +    { | 
| 338 | 343 | if (stack_alloced) free(stack); | 
| 339 | 344 | return NULL; | 
| 340 | 345 | } | 
| 341 |  | -    reownalloc(thread, thread);
 | 
| 342 |  | -    reownalloc(stack, thread);
 | 
|  | 346 | +    if (thread_alloced) reownalloc(thread, thread); | 
|  | 347 | +    if (stack_alloced) reownalloc(stack, thread); | 
| 343 | 348 |  | 
| 344 | 349 | int i; | 
| 345 | 350 | for (i = 0; i < stacksize >> 2; i ++) ((uint32_t*)stack)[i] = 0xaffebeaf; |