| 90 |
theseven |
1 |
//
|
|
|
2 |
//
|
|
|
3 |
// Copyright 2010 TheSeven
|
|
|
4 |
//
|
|
|
5 |
//
|
|
|
6 |
// This file is part of emBIOS.
|
|
|
7 |
//
|
|
|
8 |
// emBIOS is free software: you can redistribute it and/or
|
|
|
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 |
//
|
|
|
13 |
// emBIOS is distributed in the hope that it will be useful,
|
|
|
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
|
|
|
19 |
// with emBIOS. If not, see <http://www.gnu.org/licenses/>.
|
|
|
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 |
|
|
|
30 |
int execimage(void* image)
|
|
|
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 |
}
|