#include <sys/param.h>
#include <sys/boot_flag.h>
#include <machine/cpu.h>
#include <luna68k/stand/boot/samachdep.h>
#include <luna68k/stand/boot/romvec.h>
#include <luna68k/stand/boot/status.h>
#include <lib/libsa/loadfile.h>
#ifdef SUPPORT_ETHERNET
#include <lib/libsa/dev_net.h>
#endif
static int get_plane_numbers(void);
static int reorder_dipsw(int);
int cpuspeed;
int hz = 60;
int machtype;
char default_file[64];
const char *default_bootdev;
int default_unit;
#define VERS_LOCAL "Phase-31"
int nplane;
#define BUFFSIZE 100
#define MAXARGS 30
char buffer[BUFFSIZE];
int argc;
char *argv[MAXARGS];
#define BOOT_TIMEOUT 10
int boot_timeout = BOOT_TIMEOUT;
static const char prompt[] = "boot> ";
#define LUNA1_BOOTINFOADDR 0x000008c0
struct luna1_bootinfo {
uint8_t bi_xxx1[3];
uint8_t bi_device;
#define LUNA1_BTDEV_DK 0
#define LUNA1_BTDEV_FB 1
#define LUNA1_BTDEV_SD 2
#define LUNA1_BTDEV_P0 3
#define LUNA1_BTDEV_ET 4
#define LUNA1_NBTDEV 5
struct {
uint8_t bd_xxx1;
uint8_t bd_boot;
char bd_name[2];
uint8_t bd_drv;
uint8_t bd_xxx2;
uint8_t bd_xxx3;
uint8_t bd_part;
uint8_t bd_xxx4[4];
uint8_t bd_xxx5[4];
} bi_devinfo[LUNA1_NBTDEV];
} __packed;
#define LUNA2_BOOTINFOADDR 0x00001d80
struct luna2_bootinfo {
uint8_t bi_xxx1[13];
uint8_t bi_device;
#define LUNA2_BTDEV_DK 0
#define LUNA2_BTDEV_FT 1
#define LUNA2_BTDEV_SD 2
#define LUNA2_BTDEV_P0 3
#define LUNA2_NBTDEV 4
struct {
uint8_t bd_xxx1;
uint8_t bd_boot;
char bd_name[4];
uint8_t bd_xxx2;
uint8_t bd_ctlr;
uint8_t bd_id;
uint8_t bd_xxx3;
uint8_t bd_xxx4;
uint8_t bd_part;
uint8_t bd_xxx5[4];
uint8_t bd_xxx6[4];
} bi_devinfo[LUNA2_NBTDEV];
} __packed;
void
main(void)
{
int i, status = ST_NORMAL;
const char *machstr;
const char *bootdev;
uint32_t howto;
int unit, part;
int bdev, ctlr, id;
if (cputype == CPU_68030) {
machtype = LUNA_I;
machstr = "LUNA-I";
cpuspeed = MHZ_25;
hz = 60;
} else {
machtype = LUNA_II;
machstr = "LUNA-II";
cpuspeed = MHZ_25 * 2;
hz = 100;
}
nplane = get_plane_numbers();
cninit();
printf("\n");
printf(">> %s, Revision %s\n", bootprog_name, bootprog_rev);
printf(">> (based on Stinger ver 0.0 [%s])\n", VERS_LOCAL);
printf("\n");
i = ROM_memsize;
printf("Machine model = %s\n", machstr);
printf("Physical Memory = 0x%x ", i);
i >>= 20;
printf("(%d MB)\n", i);
printf("\n");
#ifdef SUPPORT_ETHERNET
try_bootp = 1;
#endif
find_devs();
printf("\n");
bootdev = "sd";
unit = 0;
part = 0;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Warray-bounds"
if (machtype == LUNA_I) {
const struct luna1_bootinfo *bi1 = (void *)LUNA1_BOOTINFOADDR;
bdev = bi1->bi_device;
switch (bdev) {
case LUNA1_BTDEV_DK:
ctlr = 0;
id = 6 - bi1->bi_devinfo[bdev].bd_drv;
unit = UNIT(ctlr, id);
break;
case LUNA1_BTDEV_ET:
bootdev = "le";
unit = 0;
break;
default:
break;
}
#ifdef BTINFO_DEBUG
printf("bi1->bi_device = 0x%02x\n", bi1->bi_device);
printf("bi1->bi_devinfo[bdev].bd_boot = 0x%02x\n",
bi1->bi_devinfo[bdev].bd_boot);
printf("bi1->bi_devinfo[bdev].bd_name = %c%c\n",
bi1->bi_devinfo[bdev].bd_name[0],
bi1->bi_devinfo[bdev].bd_name[1]);
printf("bi1->bi_devinfo[bdev].bd_drv = 0x%02x\n",
bi1->bi_devinfo[bdev].bd_drv);
printf("bi1->bi_devinfo[bdev].bd_part = 0x%02x\n",
bi1->bi_devinfo[bdev].bd_part);
#endif
} else {
const struct luna2_bootinfo *bi2 = (void *)LUNA2_BOOTINFOADDR;
bdev = bi2->bi_device;
switch (bdev) {
case LUNA2_BTDEV_DK:
ctlr = bi2->bi_devinfo[bdev].bd_ctlr;
id = bi2->bi_devinfo[bdev].bd_id;
unit = UNIT(ctlr, id);
break;
default:
break;
}
#ifdef BTINFO_DEBUG
printf("bi2->bi_device = 0x%02x\n", bi2->bi_device);
printf("bi2->bi_devinfo[bdev].bd_boot = 0x%02x\n",
bi2->bi_devinfo[bdev].bd_boot);
printf("bi2->bi_devinfo[bdev].bd_name = %s\n",
bi2->bi_devinfo[bdev].bd_name);
printf("bi2->bi_devinfo[bdev].bd_ctlr = 0x%02x\n",
bi2->bi_devinfo[bdev].bd_ctlr);
printf("bi2->bi_devinfo[bdev].bd_id = 0x%02x\n",
bi2->bi_devinfo[bdev].bd_id);
printf("bi2->bi_devinfo[bdev].bd_part = 0x%02x\n",
bi2->bi_devinfo[bdev].bd_part);
#endif
}
#pragma GCC diagnostic pop
snprintf(default_file, sizeof(default_file),
"%s(%d,%d)%s", bootdev, unit, part, "netbsd");
default_bootdev = bootdev;
default_unit = unit;
howto = reorder_dipsw(dipsw2);
if ((howto & 0xFE) == 0) {
char c;
printf("Press return to boot now,"
" any other key for boot menu\n");
printf("booting %s - starting in ", default_file);
c = awaitkey("%d seconds. ", boot_timeout, true);
if (c == '\r' || c == '\n' || c == 0) {
printf("auto-boot %s\n", default_file);
bootnetbsd(default_file, 0);
}
}
printf("type \"help\" for help.\n");
do {
memset(buffer, 0, BUFFSIZE);
if (getline(prompt, buffer) > 0) {
argc = getargs(buffer, argv,
sizeof(argv) / sizeof(char *));
status = parse(argc, argv);
if (status == ST_NOTFOUND)
printf("Command \"%s\" is not found !!\n",
argv[0]);
}
} while (status != ST_EXIT);
exit(0);
}
static int
get_plane_numbers(void)
{
int r = ROM_plane;
int n = 0;
for (; r ; r >>= 1)
if (r & 0x1)
n++;
return n;
}
static int
reorder_dipsw(int dipsw)
{
int i, sw = 0;
for (i = 0; i < 8; i++) {
if ((dipsw & 0x01) == 0)
sw += 1;
if (i == 7)
break;
sw <<= 1;
dipsw >>= 1;
}
return sw;
}