Skip to content

Instantly share code, notes, and snippets.

@chainq
Created March 25, 2023 17:27
Show Gist options
  • Save chainq/c2ae18e16d6603d9de2f6ea1f6fa88cc to your computer and use it in GitHub Desktop.
Save chainq/c2ae18e16d6603d9de2f6ea1f6fa88cc to your computer and use it in GitHub Desktop.
NetBSD BootBlock Patch to boot with Hyperion's Kickstart versions
diff --git a/sys/arch/amiga/stand/bootblock/boot/console.c b/sys/arch/amiga/stand/bootblock/boot/console.c
index 08cb523adccd..5e385de0bdd2 100644
--- a/sys/arch/amiga/stand/bootblock/boot/console.c
+++ b/sys/arch/amiga/stand/bootblock/boot/console.c
@@ -138,8 +138,21 @@ consinit(void *consptr) {
goto err;
mc->cnior->buf = (void *)mc->w;
- if (OpenDevice("console.device", 0, mc->cnior, 0))
- goto err;
+ mc->cnior->length = 136; /* sizeof(struct Window) */
+ if (OpenDevice("console.device", 0, mc->cnior, 0)) {
+ /* Kludge - some "modern" Kickstart versions decided not
+ to initialize the console.device before bootstrap, so
+ we have to do it ourselves. */
+ void *res = FindResident("console.device");
+ if (!res)
+ goto err;
+
+ if (!InitResident(res, 0))
+ goto err;
+
+ if (OpenDevice("console.device", 0, mc->cnior, 0))
+ goto err;
+ }
mc->tmior = (struct TimerIO *)CreateIORequest(mc->cnmp, sizeof(struct TimerIO));
if (!mc->tmior)
diff --git a/sys/arch/amiga/stand/bootblock/boot/libstubs.h b/sys/arch/amiga/stand/bootblock/boot/libstubs.h
index 8aeff9544f0c..dc67dc174a51 100644
--- a/sys/arch/amiga/stand/bootblock/boot/libstubs.h
+++ b/sys/arch/amiga/stand/bootblock/boot/libstubs.h
@@ -65,6 +65,7 @@ void CloseDevice(struct AmigaIO *);
#endif
void *FindResident(const char *);
+void *InitResident(const char *, u_int32_t);
void *OpenResource(const char *);
u_int32_t CachePreDMA(u_int32_t, u_int32_t *, int);
diff --git a/sys/arch/amiga/stand/bootblock/boot/libstubs.s b/sys/arch/amiga/stand/bootblock/boot/libstubs.s
index 6ffdaf896bf0..3e24f786e8c8 100644
--- a/sys/arch/amiga/stand/bootblock/boot/libstubs.s
+++ b/sys/arch/amiga/stand/bootblock/boot/libstubs.s
@@ -208,6 +208,16 @@ ENTRY_NOPROFILE(FindResident)
movl %d0,%a0 | Comply with ELF ABI
rts
+ENTRY_NOPROFILE(InitResident)
+ movl %a6,%sp@-
+ movl %pc@(_C_LABEL(SysBase):w),%a6
+ movl %sp@(8),%a1
+ movl %sp@(12),%d1
+ jsr %a6@(-0x66)
+ movl %sp@+,%a6
+ movl %d0,%a0 | Comply with ELF ABI
+ rts
+
ENTRY_NOPROFILE(OpenResource)
movl %a6,%sp@-
movl %pc@(_C_LABEL(SysBase):w),%a6
diff --git a/sys/arch/amiga/stand/bootblock/boot/version b/sys/arch/amiga/stand/bootblock/boot/version
index 08a6caf7dfb2..0c3f8546f00e 100644
--- a/sys/arch/amiga/stand/bootblock/boot/version
+++ b/sys/arch/amiga/stand/bootblock/boot/version
@@ -12,3 +12,4 @@ is taken as the current.
2.4: Moved default command into fixed location for easy patching
3.0: Initial 2 stage amiga bootblocks
3.1: Add support for FFSv2
+3.2: Fix booting with some "modern" Kickstart versions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment