inkernel.c revision 1.3
11.3Stsutsui/*	$NetBSD: inkernel.c,v 1.3 2009/01/12 07:16:17 tsutsui Exp $	*/
21.1Sgarbled
31.1Sgarbled/*-
41.1Sgarbled * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
51.1Sgarbled * All rights reserved.
61.1Sgarbled *
71.1Sgarbled * This code is derived from software contributed to The NetBSD Foundation
81.1Sgarbled * by Kazuki Sakamoto.
91.1Sgarbled *
101.1Sgarbled * Redistribution and use in source and binary forms, with or without
111.1Sgarbled * modification, are permitted provided that the following conditions
121.1Sgarbled * are met:
131.1Sgarbled * 1. Redistributions of source code must retain the above copyright
141.1Sgarbled *    notice, this list of conditions and the following disclaimer.
151.1Sgarbled * 2. Redistributions in binary form must reproduce the above copyright
161.1Sgarbled *    notice, this list of conditions and the following disclaimer in the
171.1Sgarbled *    documentation and/or other materials provided with the distribution.
181.1Sgarbled *
191.1Sgarbled * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
201.1Sgarbled * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
211.1Sgarbled * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
221.1Sgarbled * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
231.1Sgarbled * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
241.1Sgarbled * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
251.1Sgarbled * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
261.1Sgarbled * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
271.1Sgarbled * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
281.1Sgarbled * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
291.1Sgarbled * POSSIBILITY OF SUCH DAMAGE.
301.1Sgarbled */
311.1Sgarbled
321.1Sgarbled#include <lib/libsa/stand.h>
331.1Sgarbled#include <sys/param.h>
341.1Sgarbled
351.1Sgarbled#include "boot.h"
361.1Sgarbled#include "magic.h"
371.1Sgarbled
381.1Sgarbled#define	KERNENTRY	(RELOC - 0x200000)
391.1Sgarbled/*#define	KERNENTRY	(0x800000)*/
401.1Sgarbled/* Note that the iplcb lives in the 0x700000 range, so we need to avoid that*/
411.1Sgarbled
421.1Sgarbledvoid
431.1Sgarbledinit_in(u_long ladr)
441.1Sgarbled{
451.1Sgarbled	extern char _start[], _edata[], _end[];
461.1Sgarbled	/*char *p = (char *)(ladr + _end); for loadaddr 0x0*/
471.1Sgarbled	char *p = (char *)(ladr + (_end - ladr));
481.1Sgarbled	u_int i;
491.1Sgarbled
501.1Sgarbled	printf("p=%p start %p edata %p end %p ladr %lx\n", p, _start, _edata, _end, ladr);
511.1Sgarbled
521.1Sgarbled	for (i = 0; i < 4096; i++, p++) {
531.3Stsutsui		if (memcmp(p, rs6000_magic, RS6000_MAGICSIZE) == 0) {
541.3Stsutsui			kern_len = *(int *)(p + RS6000_MAGICSIZE);
551.1Sgarbled			printf("Found magic at 0x%x, kernel is size 0x%x\n", i, kern_len);
561.1Sgarbled			memmove((char *)KERNENTRY,
571.3Stsutsui				p + RS6000_MAGICSIZE + KERNLENSIZE, kern_len);
581.1Sgarbled			return;
591.1Sgarbled		}
601.1Sgarbled	}
611.1Sgarbled	printf("magic is not found.\n");
621.1Sgarbled}
631.1Sgarbled
641.1Sgarbledint
651.1Sgarbledinopen(struct open_file *p)
661.1Sgarbled{
671.1Sgarbled
681.1Sgarbled	if (kern_len)
691.1Sgarbled		return (0);
701.1Sgarbled	return (EINVAL);
711.1Sgarbled}
721.1Sgarbled
731.1Sgarbledint
741.1Sgarbledinclose(struct open_file *p)
751.1Sgarbled{
761.1Sgarbled
771.1Sgarbled	return (0);
781.1Sgarbled}
791.1Sgarbled
801.1Sgarbledint
811.1Sgarbledinstrategy(void *devdata, int func, daddr_t blk, size_t size, void *buf,
821.1Sgarbled	size_t *rsize)
831.1Sgarbled{
841.1Sgarbled
851.1Sgarbled	memcpy(buf, (char *)KERNENTRY + ((long)blk * DEV_BSIZE), size);
861.1Sgarbled	*rsize = size;
871.1Sgarbled	return (0);
881.1Sgarbled}
89