inkernel.c revision 1.1
11.1Sgarbled/*	$NetBSD: inkernel.c,v 1.1 2007/12/17 19:09:50 garbled 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 * 3. All advertising materials mentioning features or use of this software
191.1Sgarbled *    must display the following acknowledgement:
201.1Sgarbled *        This product includes software developed by the NetBSD
211.1Sgarbled *        Foundation, Inc. and its contributors.
221.1Sgarbled * 4. Neither the name of The NetBSD Foundation nor the names of its
231.1Sgarbled *    contributors may be used to endorse or promote products derived
241.1Sgarbled *    from this software without specific prior written permission.
251.1Sgarbled *
261.1Sgarbled * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
271.1Sgarbled * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
281.1Sgarbled * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
291.1Sgarbled * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
301.1Sgarbled * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
311.1Sgarbled * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
321.1Sgarbled * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
331.1Sgarbled * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
341.1Sgarbled * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
351.1Sgarbled * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
361.1Sgarbled * POSSIBILITY OF SUCH DAMAGE.
371.1Sgarbled */
381.1Sgarbled
391.1Sgarbled#include <lib/libsa/stand.h>
401.1Sgarbled#include <sys/param.h>
411.1Sgarbled
421.1Sgarbled#include "boot.h"
431.1Sgarbled#include "magic.h"
441.1Sgarbled
451.1Sgarbled#define	KERNENTRY	(RELOC - 0x200000)
461.1Sgarbled/*#define	KERNENTRY	(0x800000)*/
471.1Sgarbled/* Note that the iplcb lives in the 0x700000 range, so we need to avoid that*/
481.1Sgarbled
491.1Sgarbledvoid
501.1Sgarbledinit_in(u_long ladr)
511.1Sgarbled{
521.1Sgarbled	extern char _start[], _edata[], _end[];
531.1Sgarbled	/*char *p = (char *)(ladr + _end); for loadaddr 0x0*/
541.1Sgarbled	char *p = (char *)(ladr + (_end - ladr));
551.1Sgarbled	u_int i;
561.1Sgarbled
571.1Sgarbled	printf("p=%p start %p edata %p end %p ladr %lx\n", p, _start, _edata, _end, ladr);
581.1Sgarbled
591.1Sgarbled	for (i = 0; i < 4096; i++, p++) {
601.1Sgarbled		if (memcmp(p, magic, MAGICSIZE) == 0) {
611.1Sgarbled			kern_len = *(int *)(p + MAGICSIZE);
621.1Sgarbled			printf("Found magic at 0x%x, kernel is size 0x%x\n", i, kern_len);
631.1Sgarbled			memmove((char *)KERNENTRY,
641.1Sgarbled				p + MAGICSIZE + KERNLENSIZE, kern_len);
651.1Sgarbled			return;
661.1Sgarbled		}
671.1Sgarbled	}
681.1Sgarbled	printf("magic is not found.\n");
691.1Sgarbled}
701.1Sgarbled
711.1Sgarbledint
721.1Sgarbledinopen(struct open_file *p)
731.1Sgarbled{
741.1Sgarbled
751.1Sgarbled	if (kern_len)
761.1Sgarbled		return (0);
771.1Sgarbled	return (EINVAL);
781.1Sgarbled}
791.1Sgarbled
801.1Sgarbledint
811.1Sgarbledinclose(struct open_file *p)
821.1Sgarbled{
831.1Sgarbled
841.1Sgarbled	return (0);
851.1Sgarbled}
861.1Sgarbled
871.1Sgarbledint
881.1Sgarbledinstrategy(void *devdata, int func, daddr_t blk, size_t size, void *buf,
891.1Sgarbled	size_t *rsize)
901.1Sgarbled{
911.1Sgarbled
921.1Sgarbled	memcpy(buf, (char *)KERNENTRY + ((long)blk * DEV_BSIZE), size);
931.1Sgarbled	*rsize = size;
941.1Sgarbled	return (0);
951.1Sgarbled}
96