summaryrefslogtreecommitdiff
path: root/src/arch/i386/lib/copy_and_run.c
blob: 9cec90a81c2fa87763dd414d5810b47c07701e7d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* by yhlu 6.2005
	moved from nrv2v.c and some lines from crt0.S
   2006/05/02 - stepan: move nrv2b to an extra file.
*/

#include <console/console.h>
#include <stdint.h>
#include <string.h>

#if CONFIG_COMPRESS
#define ENDIAN   0
#define BITSIZE 32
#include "../lib/nrv2b.c"
#endif

void copy_and_run_core(u8 *src, u8 *dst, unsigned long ilen, unsigned ebp)
{
        unsigned long olen;

#if CONFIG_USE_INIT
	printk_spew("src=%08x\r\n",src);
	printk_spew("dst=%08x\r\n",dst);
#else
        print_spew("src="); print_spew_hex32((uint32_t)src); print_spew("\r\n");
        print_spew("dst="); print_spew_hex32((uint32_t)dst); print_spew("\r\n");
#endif

#if !CONFIG_COMPRESS
	print_debug("Copying image to RAM.\r\n");
	memcpy(src, dst, ilen);
	olen = ilen;
#else
	print_debug("Uncompressing image to RAM.\r\n");
//	dump_mem(src, src+0x100);
	olen = unrv2b(src, dst, &ilen);
#endif

//	dump_mem(dst, dst+0x100);
#if CONFIG_USE_INIT
	printk_spew("image length = %08x\r\n", olen);
#else
	print_spew("image length = "); print_spew_hex32(olen); print_spew("\r\n");
#endif
	print_debug("Jumping to image.\r\n");

	__asm__ volatile (
		"movl %%eax, %%ebp\n\t"
		"cli\n\t"
		"jmp     *%%edi\n\t"
		:: "a"(ebp), "D"(dst)
	);

}