Home | History | Annotate | Line # | Download | only in sh3
sh_arch.h revision 1.4.8.2
      1  1.4.8.2  nathanw /* -*-C++-*-	$NetBSD: sh_arch.h,v 1.4.8.2 2002/02/28 04:09:46 nathanw Exp $	*/
      2  1.4.8.2  nathanw 
      3  1.4.8.2  nathanw /*-
      4  1.4.8.2  nathanw  * Copyright (c) 2001, 2002 The NetBSD Foundation, Inc.
      5  1.4.8.2  nathanw  * All rights reserved.
      6  1.4.8.2  nathanw  *
      7  1.4.8.2  nathanw  * This code is derived from software contributed to The NetBSD Foundation
      8  1.4.8.2  nathanw  * by UCHIYAMA Yasushi.
      9  1.4.8.2  nathanw  *
     10  1.4.8.2  nathanw  * Redistribution and use in source and binary forms, with or without
     11  1.4.8.2  nathanw  * modification, are permitted provided that the following conditions
     12  1.4.8.2  nathanw  * are met:
     13  1.4.8.2  nathanw  * 1. Redistributions of source code must retain the above copyright
     14  1.4.8.2  nathanw  *    notice, this list of conditions and the following disclaimer.
     15  1.4.8.2  nathanw  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.4.8.2  nathanw  *    notice, this list of conditions and the following disclaimer in the
     17  1.4.8.2  nathanw  *    documentation and/or other materials provided with the distribution.
     18  1.4.8.2  nathanw  * 3. All advertising materials mentioning features or use of this software
     19  1.4.8.2  nathanw  *    must display the following acknowledgement:
     20  1.4.8.2  nathanw  *        This product includes software developed by the NetBSD
     21  1.4.8.2  nathanw  *        Foundation, Inc. and its contributors.
     22  1.4.8.2  nathanw  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.4.8.2  nathanw  *    contributors may be used to endorse or promote products derived
     24  1.4.8.2  nathanw  *    from this software without specific prior written permission.
     25  1.4.8.2  nathanw  *
     26  1.4.8.2  nathanw  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.4.8.2  nathanw  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.4.8.2  nathanw  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.4.8.2  nathanw  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.4.8.2  nathanw  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.4.8.2  nathanw  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.4.8.2  nathanw  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.4.8.2  nathanw  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.4.8.2  nathanw  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.4.8.2  nathanw  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.4.8.2  nathanw  * POSSIBILITY OF SUCH DAMAGE.
     37  1.4.8.2  nathanw  */
     38  1.4.8.2  nathanw 
     39  1.4.8.2  nathanw #ifndef _HPCBOOT_SH_ARCH_H_
     40  1.4.8.2  nathanw #define _HPCBOOT_SH_ARCH_H_
     41  1.4.8.2  nathanw 
     42  1.4.8.2  nathanw #include <arch.h>
     43  1.4.8.2  nathanw #include <memory.h>	// loadBank
     44  1.4.8.2  nathanw #include <console.h>	// DPRINTF
     45  1.4.8.2  nathanw 
     46  1.4.8.2  nathanw #include <sh3/dev/sh_dev.h>
     47  1.4.8.2  nathanw 
     48  1.4.8.2  nathanw // CPU specific macro
     49  1.4.8.2  nathanw #include <sh3/cpu/sh3.h>
     50  1.4.8.2  nathanw #include <sh3/cpu/sh4.h>
     51  1.4.8.2  nathanw 
     52  1.4.8.2  nathanw class SHArchitecture : public Architecture {
     53  1.4.8.2  nathanw protected:
     54  1.4.8.2  nathanw 	typedef void(*boot_func_t)(struct BootArgs *, struct PageTag *);
     55  1.4.8.2  nathanw 	SHdev *_dev;
     56  1.4.8.2  nathanw 
     57  1.4.8.2  nathanw private:
     58  1.4.8.2  nathanw 	typedef Architecture super;
     59  1.4.8.2  nathanw 	boot_func_t _boot_func;
     60  1.4.8.2  nathanw 
     61  1.4.8.2  nathanw protected:
     62  1.4.8.2  nathanw 	// should be created as actual product insntnce. not public.
     63  1.4.8.2  nathanw 	SHArchitecture(Console *&cons, MemoryManager *&mem, boot_func_t bootfunc)
     64  1.4.8.2  nathanw 		: _boot_func(bootfunc), Architecture(cons, mem) {
     65  1.4.8.2  nathanw 		// NO-OP
     66  1.4.8.2  nathanw 	}
     67  1.4.8.2  nathanw 	virtual ~SHArchitecture(void) { /* NO-OP */ }
     68  1.4.8.2  nathanw 	virtual void cache_flush(void) = 0;
     69  1.4.8.2  nathanw 
     70  1.4.8.2  nathanw public:
     71  1.4.8.2  nathanw 	virtual BOOL init(void);
     72  1.4.8.2  nathanw 	virtual BOOL setupLoader(void);
     73  1.4.8.2  nathanw 	virtual void systemInfo(void);
     74  1.4.8.2  nathanw 	virtual void jump(kaddr_t info, kaddr_t pvce);
     75  1.4.8.2  nathanw 
     76  1.4.8.2  nathanw 	// returns host machines CPU type. 3 for SH3. 4 for SH4
     77  1.4.8.2  nathanw 	static int cpu_type(void);
     78  1.4.8.2  nathanw };
     79  1.4.8.2  nathanw 
     80  1.4.8.2  nathanw //
     81  1.4.8.2  nathanw // SH product. setup cache flush routine and 2nd-bootloader.
     82  1.4.8.2  nathanw //
     83  1.4.8.2  nathanw 
     84  1.4.8.2  nathanw //
     85  1.4.8.2  nathanw // SH3 series.
     86  1.4.8.2  nathanw ///
     87  1.4.8.2  nathanw #define SH_(x)								\
     88  1.4.8.2  nathanw class SH ## x : public SHArchitecture {					\
     89  1.4.8.2  nathanw private:								\
     90  1.4.8.2  nathanw 	typedef SHArchitecture super;					\
     91  1.4.8.2  nathanw public:									\
     92  1.4.8.2  nathanw 	SH ## x(Console *&cons, MemoryManager *&mem, boot_func_t bootfunc)\
     93  1.4.8.2  nathanw 		: SHArchitecture(cons, mem, bootfunc) {			\
     94  1.4.8.2  nathanw 		DPRINTF((TEXT("CPU: SH") TEXT(#x) TEXT("\n")));		\
     95  1.4.8.2  nathanw 		_dev = new SH3dev;					\
     96  1.4.8.2  nathanw 	}								\
     97  1.4.8.2  nathanw 	~SH ## x(void) {						\
     98  1.4.8.2  nathanw 		delete _dev;						\
     99  1.4.8.2  nathanw 	}								\
    100  1.4.8.2  nathanw 									\
    101  1.4.8.2  nathanw 	virtual BOOL init(void) {					\
    102  1.4.8.2  nathanw 		int sz;							\
    103  1.4.8.2  nathanw 									\
    104  1.4.8.2  nathanw 		if (!super::init())					\
    105  1.4.8.2  nathanw 			return FALSE;					\
    106  1.4.8.2  nathanw 		/* SH7709, SH7709A split AREA3 to two area. */		\
    107  1.4.8.2  nathanw 		sz = SH_AREA_SIZE / 2;					\
    108  1.4.8.2  nathanw 		_mem->loadBank(SH_AREA3_START, sz);			\
    109  1.4.8.2  nathanw 		_mem->loadBank(SH_AREA3_START + sz , sz);		\
    110  1.4.8.2  nathanw 		return TRUE;						\
    111  1.4.8.2  nathanw 	}								\
    112  1.4.8.2  nathanw 									\
    113  1.4.8.2  nathanw 	virtual void cache_flush(void) {				\
    114  1.4.8.2  nathanw 		SH ## x ## _CACHE_FLUSH();				\
    115  1.4.8.2  nathanw 	}								\
    116  1.4.8.2  nathanw 									\
    117  1.4.8.2  nathanw 	static void boot_func(struct BootArgs *, struct PageTag *);	\
    118  1.4.8.2  nathanw }
    119  1.4.8.2  nathanw 
    120  1.4.8.2  nathanw SH_(7709);
    121  1.4.8.2  nathanw SH_(7709A);
    122  1.4.8.2  nathanw 
    123  1.4.8.2  nathanw //
    124  1.4.8.2  nathanw // SH4 series.
    125  1.4.8.2  nathanw ///
    126  1.4.8.2  nathanw class SH7750 : public SHArchitecture {
    127  1.4.8.2  nathanw private:
    128  1.4.8.2  nathanw 	typedef SHArchitecture super;
    129  1.4.8.2  nathanw 
    130  1.4.8.2  nathanw public:
    131  1.4.8.2  nathanw 	SH7750(Console *&cons, MemoryManager *&mem, boot_func_t bootfunc)
    132  1.4.8.2  nathanw 		: SHArchitecture(cons, mem, bootfunc) {
    133  1.4.8.2  nathanw 		DPRINTF((TEXT("CPU: SH7750\n")));
    134  1.4.8.2  nathanw 		_dev = new SH4dev;
    135  1.4.8.2  nathanw 	}
    136  1.4.8.2  nathanw 	~SH7750(void) {
    137  1.4.8.2  nathanw 		delete _dev;
    138  1.4.8.2  nathanw 	}
    139  1.4.8.2  nathanw 
    140  1.4.8.2  nathanw 	virtual BOOL init(void) {
    141  1.4.8.2  nathanw 
    142  1.4.8.2  nathanw 		if (!super::init())
    143  1.4.8.2  nathanw 			return FALSE;
    144  1.4.8.2  nathanw 		_mem->loadBank(SH_AREA3_START, SH_AREA_SIZE);
    145  1.4.8.2  nathanw 
    146  1.4.8.2  nathanw 		return TRUE;
    147  1.4.8.2  nathanw 	}
    148  1.4.8.2  nathanw 
    149  1.4.8.2  nathanw 	virtual void cache_flush(void) {
    150  1.4.8.2  nathanw 		//
    151  1.4.8.2  nathanw 		// To invalidate I-cache, program must run on P2. I can't
    152  1.4.8.2  nathanw 		// do it myself, use WinCE API. (WCE2.10 or later)
    153  1.4.8.2  nathanw 		//
    154  1.4.8.2  nathanw 		CacheSync(CACHE_D_WBINV);
    155  1.4.8.2  nathanw 		CacheSync(CACHE_I_INV);
    156  1.4.8.2  nathanw 	}
    157  1.4.8.2  nathanw 
    158  1.4.8.2  nathanw 	virtual BOOL setupLoader(void) {
    159  1.4.8.2  nathanw 		//
    160  1.4.8.2  nathanw 		// 2nd boot loader access cache address array. run on P2.
    161  1.4.8.2  nathanw 		//
    162  1.4.8.2  nathanw 		if (super::setupLoader()) {
    163  1.4.8.2  nathanw 			(u_int32_t)_loader_addr |= 0x20000000;
    164  1.4.8.2  nathanw 			DPRINTF
    165  1.4.8.2  nathanw 			    ((TEXT("loader address moved to P2-area 0x%08x\n"),
    166  1.4.8.2  nathanw 				(unsigned)_loader_addr));
    167  1.4.8.2  nathanw 			return TRUE;
    168  1.4.8.2  nathanw 		}
    169  1.4.8.2  nathanw 
    170  1.4.8.2  nathanw 		return FALSE;
    171  1.4.8.2  nathanw 	}
    172  1.4.8.2  nathanw 
    173  1.4.8.2  nathanw 	static void boot_func(struct BootArgs *, struct PageTag *);
    174  1.4.8.2  nathanw };
    175  1.4.8.2  nathanw 
    176  1.4.8.2  nathanw //
    177  1.4.8.2  nathanw // 2nd-bootloader.  make sure that PIC and its size is lower than page size.
    178  1.4.8.2  nathanw // and can't call subroutine.
    179  1.4.8.2  nathanw //
    180  1.4.8.2  nathanw #define SH_BOOT_FUNC_(x)						\
    181  1.4.8.2  nathanw void									\
    182  1.4.8.2  nathanw SH##x##::boot_func(struct BootArgs *bi, struct PageTag *p)		\
    183  1.4.8.2  nathanw {									\
    184  1.4.8.2  nathanw /* Disable interrupt. block exception.(TLB exception don't occur) */	\
    185  1.4.8.2  nathanw 	int tmp;							\
    186  1.4.8.2  nathanw 	__asm("stc	sr, r5\n"					\
    187  1.4.8.2  nathanw 	      "or	r4, r5\n"					\
    188  1.4.8.2  nathanw 	      "ldc	r5, sr\n", 0x500000f0, tmp);			\
    189  1.4.8.2  nathanw 	/* Now I run on P1(P2 for SH4), TLB flush. and disable. */	\
    190  1.4.8.2  nathanw 									\
    191  1.4.8.2  nathanw 	SH ## x ## _MMU_DISABLE();					\
    192  1.4.8.2  nathanw 	do {								\
    193  1.4.8.2  nathanw 		u_int32_t *dst =(u_int32_t *)p->dst;			\
    194  1.4.8.2  nathanw 		u_int32_t *src =(u_int32_t *)p->src;			\
    195  1.4.8.2  nathanw 		u_int32_t sz = p->sz / sizeof (int);			\
    196  1.4.8.2  nathanw 		if (p->src == ~0)					\
    197  1.4.8.2  nathanw 			while (sz--)					\
    198  1.4.8.2  nathanw 				*dst++ = 0;				\
    199  1.4.8.2  nathanw 		else	    						\
    200  1.4.8.2  nathanw 			while (sz--)					\
    201  1.4.8.2  nathanw 				*dst++ = *src++;			\
    202  1.4.8.2  nathanw 	} while ((p =(struct PageTag *)p->next) != ~0);			\
    203  1.4.8.2  nathanw 									\
    204  1.4.8.2  nathanw 	SH ## x ## _CACHE_FLUSH();					\
    205  1.4.8.2  nathanw 									\
    206  1.4.8.2  nathanw 	/* jump to kernel entry. */					\
    207  1.4.8.2  nathanw 	__asm("jmp	@r7\n"						\
    208  1.4.8.2  nathanw 	      "nop\n", bi->argc, bi->argv,				\
    209  1.4.8.2  nathanw 		 bi->bootinfo, bi->kernel_entry);			\
    210  1.4.8.2  nathanw }
    211  1.4.8.2  nathanw 
    212  1.4.8.2  nathanw //   suspend/resume external Interrupt.
    213  1.4.8.2  nathanw //  (don't block) use under privilege mode.
    214  1.4.8.2  nathanw //
    215  1.4.8.2  nathanw __BEGIN_DECLS
    216  1.4.8.2  nathanw u_int32_t suspendIntr(void);
    217  1.4.8.2  nathanw void resumeIntr(u_int32_t);
    218  1.4.8.2  nathanw __END_DECLS
    219  1.4.8.2  nathanw 
    220  1.4.8.2  nathanw #endif // _HPCBOOT_SH_ARCH_H_
    221