1 /*
2  *  Copyright (C) 2008-2021  Anders Gavare.  All rights reserved.
3  *
4  *  Redistribution and use in source and binary forms, with or without
5  *  modification, are permitted provided that the following conditions are met:
6  *
7  *  1. Redistributions of source code must retain the above copyright
8  *     notice, this list of conditions and the following disclaimer.
9  *  2. Redistributions in binary form must reproduce the above copyright
10  *     notice, this list of conditions and the following disclaimer in the
11  *     documentation and/or other materials provided with the distribution.
12  *  3. The name of the author may not be used to endorse or promote products
13  *     derived from this software without specific prior written permission.
14  *
15  *  THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  *  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  *  ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  *  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  *  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  *  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  *  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  *  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  *  SUCH DAMAGE.
26  *
27  *
28  *  COMMENT: LUNA88K machine
29  *
30  *  This is for experiments with OpenBSD/luna88k. See
31  *  openbsd/sys/arch/luna88k/luna88k/locore0.S for more information about
32  *  how OpenBSD starts up on this platform.
33  *
34  *  RAMDISK kernel used for experiments:
35  *
36  *	https://ftp.eu.openbsd.org/pub/OpenBSD/6.8/luna88k/bsd.rd
37  *
38  *  Launch with   gxemul -e luna-88k bsd.rd
39  */
40 
41 #include <stdio.h>
42 #include <stdlib.h>
43 #include <string.h>
44 
45 #include "cpu.h"
46 #include "device.h"
47 #include "devices.h"
48 #include "machine.h"
49 #include "memory.h"
50 #include "misc.h"
51 
52 #include "thirdparty/luna88k_board.h"
53 
54 
MACHINE_SETUP(luna88k)55 MACHINE_SETUP(luna88k)
56 {
57 	const char* luna88k2_fuse_string = "MNAME=LUNA88K+";
58 
59 	device_add(machine, "luna88k");
60 
61 	switch (machine->machine_subtype) {
62 
63 	case MACHINE_LUNA_88K:
64 		machine->machine_name = strdup("LUNA 88K");
65 		break;
66 
67 	case MACHINE_LUNA_88K2:
68 		machine->machine_name = strdup("LUNA 88K2");
69 
70 		/*  According to OpenBSD source code,
71 		    the string "MNAME=LUNA88K+" in FUSE_ROM_DATA
72 		    is used to determine that this is a 88K2, and
73 		    not an 88K.
74 	                fuse_rom_data[i] =
75 	                    (char)((((p->h) >> 24) & 0x000000f0) |
76 	                           (((p->l) >> 28) & 0x0000000f));
77 		    where h is first 32-bit word, l is second.
78 		*/
79 
80 		for (size_t i = 0; i < strlen(luna88k2_fuse_string); ++i) {
81 			uint32_t h = luna88k2_fuse_string[i] & 0xf0;
82 			uint32_t l = luna88k2_fuse_string[i] & 0x0f;
83 			store_32bit_word(cpu, FUSE_ROM_ADDR + i * 8 + 0, h << 24);
84 			store_32bit_word(cpu, FUSE_ROM_ADDR + i * 8 + 4, l << 28);
85 		}
86 
87 		break;
88 
89 	default:fatal("Unimplemented LUNA88K machine subtype %i\n",
90 		    machine->machine_subtype);
91 		exit(1);
92 	}
93 
94 	if (machine->ncpus > 4) {
95 		fatal("More than 4 CPUs is not supported for LUNA 88K.\n");
96 		exit(1);
97 	}
98 
99 	if (!machine->prom_emulation)
100 		return;
101 
102 	luna88kprom_init(machine);
103 }
104 
105 
MACHINE_DEFAULT_CPU(luna88k)106 MACHINE_DEFAULT_CPU(luna88k)
107 {
108 	machine->cpu_name = strdup("88100");
109 }
110 
111 
MACHINE_DEFAULT_RAM(luna88k)112 MACHINE_DEFAULT_RAM(luna88k)
113 {
114 	// Two OpenBSD dmesgs found on the Internet for a LUNA-88K2 showed
115 	// 112 MB of real mem. (I don't know what the max was for a LUNA-88K.)
116 	machine->physical_ram_in_mb = 112;
117 }
118 
119 
MACHINE_REGISTER(luna88k)120 MACHINE_REGISTER(luna88k)
121 {
122 	MR_DEFAULT(luna88k, "LUNA88K", ARCH_M88K, MACHINE_LUNA88K);
123 
124 	machine_entry_add_alias(me, "luna88k");
125 
126 	machine_entry_add_subtype(me, "LUNA-88K", MACHINE_LUNA_88K,
127 	    "luna-88k", NULL);
128 
129 	machine_entry_add_subtype(me, "LUNA-88K2", MACHINE_LUNA_88K2,
130 	    "luna-88k2", NULL);
131 
132 	me->set_default_ram = machine_default_ram_luna88k;
133 }
134 
135