1*53524e44Schristos /* $NetBSD: mips.c,v 1.4 2007/03/04 05:59:53 christos Exp $ */
29759fc21Stakemura
39759fc21Stakemura /*-
49759fc21Stakemura * Copyright (c) 1999 Shin Takemura.
59759fc21Stakemura * All rights reserved.
69759fc21Stakemura *
79759fc21Stakemura * This software is part of the PocketBSD.
89759fc21Stakemura *
99759fc21Stakemura * Redistribution and use in source and binary forms, with or without
109759fc21Stakemura * modification, are permitted provided that the following conditions
119759fc21Stakemura * are met:
129759fc21Stakemura * 1. Redistributions of source code must retain the above copyright
139759fc21Stakemura * notice, this list of conditions and the following disclaimer.
149759fc21Stakemura * 2. Redistributions in binary form must reproduce the above copyright
159759fc21Stakemura * notice, this list of conditions and the following disclaimer in the
169759fc21Stakemura * documentation and/or other materials provided with the distribution.
179759fc21Stakemura * 3. All advertising materials mentioning features or use of this software
189759fc21Stakemura * must display the following acknowledgement:
199759fc21Stakemura * This product includes software developed by the PocketBSD project
209759fc21Stakemura * and its contributors.
219759fc21Stakemura * 4. Neither the name of the project nor the names of its contributors
229759fc21Stakemura * may be used to endorse or promote products derived from this software
239759fc21Stakemura * without specific prior written permission.
249759fc21Stakemura *
259759fc21Stakemura * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
269759fc21Stakemura * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
279759fc21Stakemura * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
289759fc21Stakemura * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
299759fc21Stakemura * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
309759fc21Stakemura * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
319759fc21Stakemura * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
329759fc21Stakemura * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
339759fc21Stakemura * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
349759fc21Stakemura * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
359759fc21Stakemura * SUCH DAMAGE.
369759fc21Stakemura *
379759fc21Stakemura */
389759fc21Stakemura #include <pbsdboot.h>
399759fc21Stakemura
40943a3259Such #define DUMMYBUFSIZE (1024*32)
41943a3259Such int dummy_buf[DUMMYBUFSIZE];
42943a3259Such
439759fc21Stakemura int
mips_boot(void * map)44*53524e44Schristos mips_boot(void *map)
459759fc21Stakemura {
469759fc21Stakemura unsigned char *mem;
479759fc21Stakemura unsigned long jump_instruction, phys_mem;
48943a3259Such int i, j;
499759fc21Stakemura
509759fc21Stakemura /*
519759fc21Stakemura * allocate physical memory for startup program.
529759fc21Stakemura */
539759fc21Stakemura if ((mem = (unsigned char*)vmem_alloc()) == NULL) {
54943a3259Such msg_printf(MSG_ERROR, whoami, TEXT("Can't allocate root page.\n"));
55943a3259Such return -1;
569759fc21Stakemura }
579759fc21Stakemura
589759fc21Stakemura /*
599759fc21Stakemura * copy startup program code
609759fc21Stakemura */
619759fc21Stakemura memcpy(mem, system_info.si_asmcode, system_info.si_asmcodelen);
629759fc21Stakemura
639759fc21Stakemura /*
649759fc21Stakemura * set map address (override target field of asmcode
659759fc21Stakemura * "lui a0, 0x0; ori a0, 0x0;".
669759fc21Stakemura */
679759fc21Stakemura *(unsigned short*)&mem[0] = (unsigned short)(((long)map) >> 16);
689759fc21Stakemura *(unsigned short*)&mem[4] = (unsigned short)map;
699759fc21Stakemura
709759fc21Stakemura /*
719759fc21Stakemura * construct start instruction
729759fc21Stakemura */
73943a3259Such if (!(phys_mem = (unsigned long)vtophysaddr(mem))) {
74943a3259Such msg_printf(MSG_ERROR, whoami, TEXT("Missing physical page.\n"));
75943a3259Such return -1;
76943a3259Such }
779759fc21Stakemura jump_instruction = (0x08000000 | ((phys_mem >> 2) & 0x03ffffff));
789759fc21Stakemura
799759fc21Stakemura /*
809759fc21Stakemura * map interrupt vector
819759fc21Stakemura */
829759fc21Stakemura mem = (unsigned char*)VirtualAlloc(0, 0x400, MEM_RESERVE, PAGE_NOACCESS);
83943a3259Such if (!(VirtualCopy((LPVOID)mem, (LPVOID)(system_info.si_dramstart >> 8), 0x400,
84943a3259Such PAGE_READWRITE | PAGE_NOCACHE | PAGE_PHYSICAL))) {
85943a3259Such msg_printf(MSG_ERROR, whoami, TEXT("Mapping interrupt vector failed.\n"));
86943a3259Such return -1;
87943a3259Such }
88943a3259Such
89943a3259Such /*
90943a3259Such * Flush D-cache
91943a3259Such */
92943a3259Such for (i = 0; i < DUMMYBUFSIZE; i++) {
93943a3259Such dummy_buf[i] = j;
94943a3259Such }
95943a3259Such for (i = 0; i < DUMMYBUFSIZE; i++) {
96943a3259Such j = dummy_buf[i];
97943a3259Such j++;
98943a3259Such }
99943a3259Such /*
100943a3259Such * Flush I-cache
101943a3259Such */
102943a3259Such __asm(".space 32768;");
103943a3259Such
1049759fc21Stakemura /*
1059759fc21Stakemura * GO !
1069759fc21Stakemura */
107943a3259Such *(unsigned long*)&mem[system_info.si_intrvec] = jump_instruction;
1089759fc21Stakemura
1099759fc21Stakemura return (0); /* not reachable */
1109759fc21Stakemura }
111