1/*	$NetBSD: sal_stub.c,v 1.3 2009/07/20 04:59:04 kiyohara Exp $	*/
2
3/*-
4 * Copyright (c) 2003 Marcel Moolenaar
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 *
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in the
15 *    documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <sys/cdefs.h>
30/* __FBSDID("$FreeBSD: src/sys/boot/ia64/libski/sal_stub.c,v 1.2 2003/09/08 09:11:32 obrien Exp $"); */
31
32#include <sys/types.h>
33#include <machine/md_var.h>
34#include <machine/sal.h>
35#include <lib/libsa/stand.h>
36#include <lib/libsa/loadfile.h>
37
38#include "bootstrap.h"
39#include "libski.h"
40
41void ski_cons_putchar(int c);
42
43extern void PalProc(void);
44static sal_entry_t SalProc;
45
46struct {
47	struct sal_system_table header;
48	struct sal_entrypoint_descriptor entry;
49	struct sal_ap_wakeup_descriptor wakeup;
50} sal_systab = {
51	/* Header. */
52	{
53		SAL_SIGNATURE,
54		sizeof(sal_systab),
55		{ 00, 03 },		/* Revision 3.0. */
56		2,			/* Number of decsriptors. */
57		0,			/* XXX checksum. */
58		{ 0 },
59		{ 00, 00 },		/* XXX SAL_A version. */
60		{ 00, 00 },		/* XXX SAL_B version. */
61		"FreeBSD",
62		"Ski loader",
63		{ 0 }
64	},
65	/* Entrypoint. */
66	{
67		0,			/* Type=entrypoint descr. */
68		{ 0 },
69		0,			/* XXX PalProc. */
70		0,			/* XXX SalProc. */
71		0,			/* XXX SalProc GP. */
72		{ 0 }
73	},
74	/* AP wakeup. */
75	{
76		5,			/* Type=AP wakeup descr. */
77		0,			/* External interrupt. */
78		{ 0 },
79		255			/* Wakeup vector. */
80	}
81};
82
83static inline void
84puts(const char *s)
85{
86	s = (const char *)((7UL << 61) | (u_long)s);
87	while (*s)
88		ski_cons_putchar(*s++);
89}
90
91static struct ia64_sal_result
92SalProc(u_int64_t a1, u_int64_t a2, u_int64_t a3, u_int64_t a4, u_int64_t a5,
93    u_int64_t a6, u_int64_t a7, u_int64_t a8)
94{
95	struct ia64_sal_result res;
96
97	res.sal_status = -3;
98	res.sal_result[0] = 0;
99	res.sal_result[1] = 0;
100	res.sal_result[2] = 0;
101
102	if (a1 == SAL_FREQ_BASE) {
103		res.sal_status = 0;
104		res.sal_result[0] = 133338184;
105	} else if (a1 == SAL_SET_VECTORS) {
106		/* XXX unofficial SSC function. */
107		ssc(a2, a3, a4, a5, SSC_SAL_SET_VECTORS);
108	} else if (a1 != SAL_GET_STATE_INFO_SIZE) {
109		puts("SAL: unimplemented function called\n");
110	}
111
112	return (res);
113}
114
115void
116sal_stub_init(void)
117{
118	struct ia64_fdesc *fd;
119
120	fd = (void*)PalProc;
121	sal_systab.entry.sale_pal_proc = fd->func;
122	fd = (void*)SalProc;
123	sal_systab.entry.sale_sal_proc = fd->func;
124	sal_systab.entry.sale_sal_gp = fd->gp;
125}
126