Move BOOTXX boot priority adjustment from mounter to device.c

I am preparing to rebase mounter on shared codebase with a4091.device
This commit is contained in:
Matt Harlum 2025-07-01 07:06:50 +00:00
parent 972c6f2c11
commit af8d03e0b9
4 changed files with 135 additions and 47 deletions

View File

@ -8,6 +8,7 @@
#include <exec/errors.h> #include <exec/errors.h>
#include <exec/execbase.h> #include <exec/execbase.h>
#include <exec/resident.h> #include <exec/resident.h>
#include <hardware/cia.h>
#include <proto/exec.h> #include <proto/exec.h>
#include <proto/expansion.h> #include <proto/expansion.h>
#include <resources/filesysres.h> #include <resources/filesysres.h>
@ -925,6 +926,77 @@ static const ULONG device_vectors[] =
-1 //function table end marker -1 //function table end marker
}; };
/**
* AdjustBootPriority
*
* Adjusts the boot priority of the first matching device in a mount list. Searches
* for a device node with the specified name and increases its priority by the given
* increment. Optionally checks gameport 1 button state before applying changes.
* Re-orders the device in the priority list after modification.
*
* @param bootname BSTR name to match against device nodes
* @param MountList Pointer to the mount list to traverse
* @param checkFire If true, only modify when gameport 1 button is pressed
* @param increment Amount to increase both device and boot node priorities
*/
void AdjustBootPriority(struct ExecBase *SysBase, char *bootname, struct List *MountList, bool checkFire, int increment) {
volatile struct CIA *ciaa = (struct CIA *)0x0bfe001;
struct BootNode *bn;
struct DeviceNode *dn;
for (bn = (struct BootNode *)MountList->lh_Head;
bn->bn_Node.ln_Succ;
bn = (struct BootNode *)bn->bn_Node.ln_Succ)
{
dn = bn->bn_DeviceNode;
if (dn->dn_Priority != -128)
{
if (L_CompareBSTR(BADDR(dn->dn_Name),bootname)) {
if(!checkFire || (ciaa->ciapra & CIAF_GAMEPORT1)==0) {
dn->dn_Priority+=increment;
bn->bn_Node.ln_Pri+=increment;
Remove((struct Node *)bn);
Enqueue(MountList,(struct Node *)bn);
break;
}
}
}
}
}
/**
* TweakBootList
*
* Modifies boot device priorities in the expansion library mount list. Traverses all
* boot nodes and increases priority (+1) for devices matching "BOOTxx" names (where xx
* is the expansion library major version). Additionally boosts priority (+2) for
* "BOOT00" devices when gameport 1 button is pressed. Skips devices with priority -128.
*
* @param SysBase Pointer to the ExecBase system library base
*/
void TweakBootList(struct ExecBase *SysBase) {
struct ExpansionBase *ExpansionBase;
if (ExpansionBase = (struct ExpansionBase *)OpenLibrary("expansion.library",0)) {
char bootname[] = "\6BOOT00"; // BSTR
UWORD major = (ExpansionBase->LibNode.lib_Version)%100; // we assume version number is under 100, but better safe than sorry
Forbid();
AdjustBootPriority(SysBase,bootname,&ExpansionBase->MountList,true,2);
bootname[5]=0x30+(major/10);
bootname[6]=0x30+(major%10);
AdjustBootPriority(SysBase,bootname,&ExpansionBase->MountList,false,1);
Permit();
CloseLibrary((struct Library *)ExpansionBase);
}
}
/** /**
* init * init
* *
@ -988,6 +1060,10 @@ static struct Library __attribute__((used)) * init(BPTR seg_list asm("a0"))
} }
FreeMem(ms,ms_size); FreeMem(ms,ms_size);
if (!seg_list) // Only tweak if we're in boot
TweakBootList(SysBase);
} }
done: done:
return (struct Library *)mydev; return (struct Library *)mydev;

View File

@ -7,6 +7,7 @@
#include <exec/nodes.h> #include <exec/nodes.h>
#include <exec/ports.h> #include <exec/ports.h>
#include <proto/exec.h> #include <proto/exec.h>
#include <stdbool.h>
#include <string.h> #include <string.h>
#include "debug.h" #include "debug.h"
@ -193,3 +194,42 @@ struct Task *L_CreateTask(char * taskName, LONG priority, APTR funcEntry, ULONG
return task; return task;
} }
/**
* L_Uppercase
* Convert lowercase char to uppercase
*
* @param c char to uppercase
* @returns char
*/
char L_UpperCase(char c) {
if (c >= 'a' && c <= 'z')
c -= ('a'-'A');
return c;
}
/**
* L_CompareBSTR
* Compare two BSTRs
*
* @param str1 String 1
* @param str2 String 2
* @returns bool Equality
*/
bool L_CompareBSTR(char *str1, char *str2) {
UBYTE len1 = str1[0];
UBYTE len2 = str2[0];
if (len1 != len2) {
return false;
}
for (int i=1; i<=len1; i++) {
if (L_UpperCase(str1[i]) != L_UpperCase(str2[i]))
return false;
}
return true;
}

View File

@ -19,4 +19,6 @@ struct IOStdReq* L_CreateStdIO(struct MsgPort *mp);
void L_DeleteExtIO(struct IORequest *ior); void L_DeleteExtIO(struct IORequest *ior);
void L_DeleteStdIO(struct IOStdReq *ior); void L_DeleteStdIO(struct IOStdReq *ior);
struct Task *L_CreateTask(char * taskName, LONG priority, APTR funcEntry, ULONG stackSize, APTR userData); struct Task *L_CreateTask(char * taskName, LONG priority, APTR funcEntry, ULONG stackSize, APTR userData);
bool L_CompareBSTR(char *str1, char *str2);
char L_UpperCase(char c);
#endif #endif

View File

@ -39,7 +39,6 @@
#include <dos/dos.h> #include <dos/dos.h>
#include <dos/dosextens.h> #include <dos/dosextens.h>
#include <dos/doshunks.h> #include <dos/doshunks.h>
#include <hardware/cia.h>
#include <stdio.h> #include <stdio.h>
#include <stdbool.h> #include <stdbool.h>
@ -91,8 +90,6 @@ struct MountData
int blocksize; int blocksize;
}; };
static volatile struct CIA * const ciaa = (struct CIA *)0x0bfe001;
// Get Block size of unit // Get Block size of unit
BYTE GetGeometry(struct IOExtTD *req, struct DriveGeometry *geometry) { BYTE GetGeometry(struct IOExtTD *req, struct DriveGeometry *geometry) {
struct ExecBase *SysBase = *(struct ExecBase **)4UL; struct ExecBase *SysBase = *(struct ExecBase **)4UL;
@ -909,35 +906,8 @@ static void AddNode(struct PartitionBlock *part, struct ParameterPacket *pp, str
struct ExpansionBase *ExpansionBase = md->ExpansionBase; struct ExpansionBase *ExpansionBase = md->ExpansionBase;
struct DosLibrary *DOSBase = md->DOSBase; struct DosLibrary *DOSBase = md->DOSBase;
LONG bootPri; LONG bootPri;
char bootname[8];
UWORD major;
major=(ExpansionBase->LibNode.lib_Version)%100; // we assume version number is under 100, but better safe than sorry bootPri = (part->pb_Flags & PBFF_BOOTABLE) ? pp->de.de_BootPri : -128;
bootname[0]=0x06;
bootname[1]='B';
bootname[2]='O';
bootname[3]='O';
bootname[4]='T';
bootname[5]=0x30+(major/10);
bootname[6]=0x30+(major%10);
bootname[7]=0;
if (!(part->pb_Flags & PBFF_BOOTABLE)) {
bootPri = -128;
} else {
bootPri = pp->de.de_BootPri;
// Do we have a bootpartition for this kickstart?
if(CompareBSTRNoCase(part->pb_DriveName, bootname)==TRUE) {
bootPri++; // make priority a bit higher
}
// Do we have a setup bootpartition?
bootname[5]=bootname[6]='0';
if(CompareBSTRNoCase(part->pb_DriveName, bootname)==TRUE) {
if((ciaa->ciapra & CIAF_GAMEPORT1)==0) {
bootPri+=2; // make priority a bit more higher
}
}
}
if (ExpansionBase->LibNode.lib_Version >= 37) { if (ExpansionBase->LibNode.lib_Version >= 37) {
// KS 2.0+ // KS 2.0+