Subversion Repositories freemyipod

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
90 theseven 1
//
2
//
3
//    Copyright 2010 TheSeven
4
//
5
//
427 farthen 6
//    This file is part of emCORE.
90 theseven 7
//
427 farthen 8
//    emCORE is free software: you can redistribute it and/or
90 theseven 9
//    modify it under the terms of the GNU General Public License as
10
//    published by the Free Software Foundation, either version 2 of the
11
//    License, or (at your option) any later version.
12
//
427 farthen 13
//    emCORE is distributed in the hope that it will be useful,
90 theseven 14
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
//    See the GNU General Public License for more details.
17
//
18
//    You should have received a copy of the GNU General Public License along
427 farthen 19
//    with emCORE.  If not, see <http://www.gnu.org/licenses/>.
90 theseven 20
//
21
//
22
 
23
 
24
#include "global.h"
25
#include "console.h"
26
#include "execimage.h"
92 theseven 27
#include "mmu.h"
90 theseven 28
 
29
 
436 theseven 30
int execimage(void* image, bool nomalloc)
90 theseven 31
{
32
    struct execimage_header* header = (struct execimage_header*)image;
33
    if (memcmp(header, "emBIexec", 8))
34
    {
35
        cprintf(CONSOLE_BOOT, "execimage: Bad signature!\n"
36
                              "%02X %02X %02X %02X %02X %02X %02X %02X\n",
37
                header->signature[0], header->signature[1], header->signature[2],
38
                header->signature[3], header->signature[4], header->signature[5],
39
                header->signature[6], header->signature[7]);
40
        return -1;
41
    }
42
    if (header->version > 0)
43
    {
44
        cprintf(CONSOLE_BOOT, "execimage: Unsupported version! (%08X)\n", header->version);
45
        return -2;
46
    }
47
    if (header->baseaddr != image)
48
    {
49
        cprintf(CONSOLE_BOOT, "execimage: Image loaded to wrong address! "
50
                              "(expected: %08X, got: %08X)\n", header->baseaddr, image);
51
        return -3;
52
    }
92 theseven 53
    clean_dcache();
54
    invalidate_icache();
90 theseven 55
    return thread_create(header->threadname, header->entrypoint, header->stackaddr,
56
                         header->stacksize, header->threadtype, header->threadpriority, true);
57
}