1 /*
2  * arch/mips/dec/decstation.c
3  */
4 #include <linux/config.h>
5 
6 #define RELOC
7 #define INITRD
8 #define DEBUG_BOOT
9 
10 /*
11  * Magic number indicating REX PROM available on DECSTATION.
12  */
13 #define	REX_PROM_MAGIC		0x30464354
14 
15 #define REX_PROM_CLEARCACHE	0x7c/4
16 #define REX_PROM_PRINTF		0x30/4
17 
18 #define VEC_RESET		0xBFC00000		/* Prom base address */
19 #define	PMAX_PROM_ENTRY(x)	(VEC_RESET+((x)*8))	/* Prom jump table */
20 #define	PMAX_PROM_PRINTF	PMAX_PROM_ENTRY(17)
21 
22 #define PARAM	(k_start + 0x2000)
23 
24 #define LOADER_TYPE (*(unsigned char *) (PARAM+0x210))
25 #define INITRD_START (*(unsigned long *) (PARAM+0x218))
26 #define INITRD_SIZE (*(unsigned long *) (PARAM+0x21c))
27 
28 extern int _ftext, _end;		/* begin and end of kernel image */
29 extern void *__rd_start, *__rd_end;	/* begin and end of ramdisk image */
30 extern void kernel_entry(int, char **, unsigned long, int *);
31 
memcpy(void * dest,const void * src,unsigned int count)32 void * memcpy(void * dest, const void *src, unsigned int count)
33 {
34 	unsigned long *tmp = (unsigned long *) dest, *s = (unsigned long *) src;
35 
36 	count >>= 2;
37 	while (count--)
38 		*tmp++ = *s++;
39 
40 	return dest;
41 }
42 
dec_entry(int argc,char ** argv,unsigned long magic,int * prom_vec)43 void dec_entry(int argc, char **argv,
44 	       unsigned long magic, int *prom_vec)
45 {
46 	void (*rex_clear_cache)(void);
47 	int (*prom_printf)(char *, ...);
48 	unsigned long k_start, len;
49 
50 	/*
51 	 * The DS5100 leaves cpu with BEV enabled, clear it.
52 	 */
53 	asm(	"lui\t$8,0x3000\n\t"
54 		"mtc0\t$8,$12\n\t"
55 		".section\t.sdata\n\t"
56 		".section\t.sbss\n\t"
57 		".section\t.text"
58 		: : : "$8");
59 
60 #ifdef DEBUG_BOOT
61 	if (magic == REX_PROM_MAGIC) {
62 	prom_printf = (int (*)(char *, ...)) *(prom_vec + REX_PROM_PRINTF);
63 	} else {
64 		prom_printf = (int (*)(char *, ...)) PMAX_PROM_PRINTF;
65 	}
66 	prom_printf("Launching kernel...\n");
67 #endif
68 
69 	k_start = (unsigned long) (&kernel_entry) & 0xffff0000;
70 
71 #ifdef RELOC
72 	/*
73 	 * Now copy kernel image to it's destination.
74 	 */
75 	len = ((unsigned long) (&_end) - k_start);
76 	memcpy((void *)k_start, &_ftext, len);
77 #endif
78 
79 	if (magic == REX_PROM_MAGIC) {
80 		rex_clear_cache = (void (*)(void)) * (prom_vec + REX_PROM_CLEARCACHE);
81 		rex_clear_cache();
82 	}
83 
84 #ifdef CONFIG_BLK_DEV_INITRD
85 	LOADER_TYPE = 1;
86 	INITRD_START = (long)&__rd_start;
87 	INITRD_SIZE = (long)&__rd_end - (long)&__rd_start;
88 #endif
89 
90 	kernel_entry(argc, argv, magic, prom_vec);
91 }
92