Home | History | Annotate | Line # | Download | only in landisk
      1 /*	$NetBSD: kloader_machdep.c,v 1.2 2008/04/28 20:23:26 martin Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2001, 2002, 2004 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     17  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26  * POSSIBILITY OF SUCH DAMAGE.
     27  */
     28 
     29 #include <sys/cdefs.h>
     30 __KERNEL_RCSID(0, "$NetBSD: kloader_machdep.c,v 1.2 2008/04/28 20:23:26 martin Exp $");
     31 
     32 #include "debug_kloader.h"
     33 
     34 #include <sys/param.h>
     35 #include <sys/systm.h>
     36 
     37 #include <sh3/mmu.h>
     38 #include <sh3/mmu_sh4.h>
     39 #include <sh3/cache.h>
     40 #include <sh3/cache_sh4.h>
     41 
     42 #include <machine/cpu.h>
     43 #include <machine/kloader.h>
     44 
     45 kloader_jumpfunc_t kloader_landisk_jump;
     46 kloader_bootfunc_t kloader_landisk_boot;
     47 
     48 struct kloader_ops landisk_kloader_ops = {
     49 	.jump = kloader_landisk_jump,
     50 	.boot = kloader_landisk_boot,
     51 	.reset = machine_reset,
     52 };
     53 
     54 void
     55 kloader_reboot_setup(const char *filename)
     56 {
     57 
     58 	__kloader_reboot_setup(&landisk_kloader_ops, filename);
     59 }
     60 
     61 void
     62 kloader_landisk_jump(kloader_bootfunc_t func, vaddr_t sp,
     63     struct kloader_bootinfo *info, struct kloader_page_tag *tag)
     64 {
     65 
     66 	sh_icache_sync_all();	/* also flush d-cache */
     67 
     68 	__asm volatile(
     69 	    	"mov	%0, r4;"
     70 		"mov	%1, r5;"
     71 		"jmp	@%2;"
     72 		" mov	%3, sp"
     73 		: : "r" (info), "r" (tag), "r" (func), "r" (sp));
     74 	/* NOTREACHED */
     75 }
     76 
     77 /*
     78  * 2nd-bootloader. Make sure that PIC and its size is lower than page size.
     79  */
     80 void
     81 kloader_landisk_boot(struct kloader_bootinfo *kbi, struct kloader_page_tag *p)
     82 {
     83 	int howto;
     84 	int tmp = 0;
     85 
     86 	/* Disable interrupt. block exception. */
     87 	__asm volatile(
     88 		"stc	sr, %1;"
     89 		"or	%0, %1;"
     90 		"ldc	%1, sr" : : "r" (0x500000f0), "r" (tmp));
     91 
     92 	/* Now I run on P1, TLB flush. and disable. */
     93 	SH4_TLB_DISABLE;
     94 
     95 	do {
     96 		uint32_t *dst =(uint32_t *)p->dst;
     97 		uint32_t *src =(uint32_t *)p->src;
     98 		uint32_t sz = p->sz / sizeof(int);
     99 		while (sz--) {
    100 			*dst++ = *src++;
    101 		}
    102 	} while ((p = (struct kloader_page_tag *)p->next) != 0);
    103 
    104 	/* XXX: howto */
    105 	howto = 0;
    106 
    107 	SH7751R_CACHE_FLUSH();
    108 
    109 	/* jump to kernel entry. */
    110 	__asm volatile(
    111 		"mov	%0, r4;"
    112 		"jmp	@%2;"
    113 		" mov	%1, r5;"
    114 		: : "r" (howto), "r" (&kbi->bootinfo), "r" (kbi->entry));
    115 	/* NOTREACHED */
    116 }
    117