Home | History | Annotate | Line # | Download | only in mips
      1 /* -*-C++-*-	$NetBSD: mips_boot.cpp,v 1.8 2008/04/28 20:23:20 martin Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2001 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by UCHIYAMA Yasushi.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #include <hpcboot.h>
     33 #include <console.h>
     34 
     35 #include <arch.h>
     36 #include <memory.h>
     37 
     38 #include <mips/mips_arch.h>
     39 #include <mips/mips_boot.h>
     40 #include <mips/mips_vr41.h>
     41 #include <mips/mips_tx39.h>
     42 #include <mips/mips_console.h>
     43 
     44 MIPSBoot::MIPSBoot()
     45 {
     46 }
     47 
     48 MIPSBoot::~MIPSBoot()
     49 {
     50 	if (_mem)
     51 		delete _mem;
     52 	if (_arch)
     53 		delete _arch;
     54 
     55 	MIPSConsole::Destroy();
     56 }
     57 
     58 BOOL
     59 MIPSBoot::setup()
     60 {
     61 	struct HpcMenuInterface::HpcMenuPreferences &pref = HPC_PREFERENCE;
     62 
     63 	platid_t platid;
     64 	platid.dw.dw0 = pref.platid_hi;
     65 	platid.dw.dw1 = pref.platid_lo;
     66 
     67 	if (platid_match(&platid, &platid_mask_CPU_MIPS_VR)) {
     68 		args.architecture = ARCHITECTURE_MIPS_VR41;
     69 	} else if (platid_match(&platid, &platid_mask_CPU_MIPS_TX_3900)) {
     70 		args.architecture = ARCHITECTURE_MIPS_TX3900;
     71 	} else if (platid_match(&platid, &platid_mask_CPU_MIPS_TX_3920)) {
     72 		args.architecture = ARCHITECTURE_MIPS_TX3920;
     73 	} else {
     74 		DPRINTF((TEXT("unknown MIPS variants.\n")));
     75 		return FALSE;
     76 	}
     77 
     78 	return super::setup();
     79 }
     80 
     81 BOOL
     82 MIPSBoot::create()
     83 {
     84 	SYSTEM_INFO sysinfo;
     85 	size_t pagesz;
     86 	int shift;
     87 	BOOL(*lock_pages)(LPVOID, DWORD, PDWORD, int);
     88 	BOOL(*unlock_pages)(LPVOID, DWORD);
     89 
     90 	// Console
     91 	if (args.console == CONSOLE_SERIAL) {
     92 		_cons = MIPSConsole::Instance();
     93 		if (!_cons->init()) {
     94 			_cons = Console::Instance();
     95 			DPRINTF((TEXT("use LCD console instead.\n")));
     96 		}
     97 	} else {
     98 		_cons = Console::Instance();
     99 	}
    100 
    101 	// Architercure dependent ops.
    102 	switch(args.architecture) {
    103 	default:
    104 		DPRINTF((TEXT("unsupported architecture.\n")));
    105 		return FALSE;
    106 	case ARCHITECTURE_MIPS_TX3900:
    107 		// FALLTHROUGH
    108 	case ARCHITECTURE_MIPS_TX3920:
    109 		_arch = new TX39XX(_cons, _mem, args.architecture);
    110 		pagesz = 4096;
    111 		shift = 0;
    112 		break;
    113 	case ARCHITECTURE_MIPS_VR41:
    114 		_arch = new VR41XX(_cons, _mem);
    115 		GetSystemInfo(&sysinfo);
    116 		DPRINTF((TEXT("sysinfo.dwPageSize = %d\n"),
    117 		    sysinfo.dwPageSize));
    118 		pagesz = sysinfo.dwPageSize;
    119 		shift = 4; // VR41 specific shift. for LockPages()
    120 		break;
    121 	}
    122 	_arch->setDebug() = args.architectureDebug;
    123 
    124 	// Memory manager.
    125 	// LockPages API exists in Windows CE 2.11 or later. check it.
    126 	lock_pages = _arch->_load_LockPages();
    127 	unlock_pages = _arch->_load_UnlockPages();
    128 	if (lock_pages == 0 || unlock_pages == 0)
    129 		args.memory = MEMORY_MANAGER_VIRTUALCOPY;
    130 	else
    131 		args.memory = MEMORY_MANAGER_LOCKPAGES;
    132 
    133 	switch(args.memory) {
    134 	default:
    135 		break;
    136 	case MEMORY_MANAGER_SOFTMMU:
    137 		// FALLTHROUGH
    138 	case MEMORY_MANAGER_HARDMMU:
    139 		DPRINTF((TEXT("unsupported memory address detection method.\n")));
    140 		return FALSE;
    141 	case MEMORY_MANAGER_LOCKPAGES:
    142 		_mem = new MemoryManager_LockPages(lock_pages, unlock_pages,
    143 		    _cons, pagesz, shift);
    144 		break;
    145 	case MEMORY_MANAGER_VIRTUALCOPY:
    146 		_mem = new MemoryManager_VirtualCopy(_cons, pagesz);
    147 		break;
    148 	}
    149 	_mem->setDebug() = args.memorymanagerDebug;
    150 
    151 	// File Manager, Loader
    152 	return super::create();
    153 }
    154