Compare commits

...

2 Commits

Author SHA1 Message Date
31e03ae36d Move BOOTXX boot priority adjustment from mounter to device.c
I am preparing to rebase mounter on shared codebase with a4091.device
2025-07-01 07:45:51 +00:00
bdf8463dce Whitespace fixes 2025-07-01 07:06:14 +00:00
4 changed files with 170 additions and 74 deletions

138
device.c
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>
@ -81,7 +82,7 @@ char * set_dev_name(struct DeviceBase *dev) {
if (devName == NULL) return NULL; if (devName == NULL) return NULL;
strcpy(devName + 4,device_name); strcpy(devName + 4,device_name);
} }
switch (i) { switch (i) {
case 0: case 0:
*(ULONG *)devName = device_prefix[0]; *(ULONG *)devName = device_prefix[0];
@ -111,33 +112,33 @@ char * set_dev_name(struct DeviceBase *dev) {
* CreateFakeConfigDev * CreateFakeConfigDev
* Create fake ConfigDev and DiagArea to support autoboot without requiring real autoconfig device. * Create fake ConfigDev and DiagArea to support autoboot without requiring real autoconfig device.
* Adapted from mounter.c by Toni Wilen * Adapted from mounter.c by Toni Wilen
* *
* @param SysBase Pointer to SysBase * @param SysBase Pointer to SysBase
* @param ExpansionBase Pointer to ExpansionBase * @param ExpansionBase Pointer to ExpansionBase
* @returns Pointer to a ConfigDev struct * @returns Pointer to a ConfigDev struct
*/ */
struct ConfigDev *CreateFakeConfigDev(struct ExecBase *SysBase, struct Library *ExpansionBase) struct ConfigDev *CreateFakeConfigDev(struct ExecBase *SysBase, struct Library *ExpansionBase)
{ {
struct ConfigDev *cd; struct ConfigDev *cd;
cd = AllocConfigDev(); cd = AllocConfigDev();
if (cd) { if (cd) {
cd->cd_BoardAddr = NULL; cd->cd_BoardAddr = NULL;
cd->cd_BoardSize = 0; cd->cd_BoardSize = 0;
cd->cd_Rom.er_Type = ERTF_DIAGVALID; cd->cd_Rom.er_Type = ERTF_DIAGVALID;
ULONG bbSize = &bootblock_end - &bootblock; ULONG bbSize = &bootblock_end - &bootblock;
ULONG daSize = sizeof(struct DiagArea) + bbSize; ULONG daSize = sizeof(struct DiagArea) + bbSize;
struct DiagArea *diagArea = AllocMem(daSize, MEMF_CLEAR | MEMF_PUBLIC); struct DiagArea *diagArea = AllocMem(daSize, MEMF_CLEAR | MEMF_PUBLIC);
if (diagArea) { if (diagArea) {
diagArea->da_Config = DAC_CONFIGTIME; diagArea->da_Config = DAC_CONFIGTIME;
diagArea->da_BootPoint = sizeof(struct DiagArea); diagArea->da_BootPoint = sizeof(struct DiagArea);
diagArea->da_Size = (UWORD)daSize; diagArea->da_Size = (UWORD)daSize;
CopyMem(&bootblock, diagArea+1, bbSize); CopyMem(&bootblock, diagArea+1, bbSize);
// cd_Rom.er_Reserved0c is used as a pointer to diagArea by strap // cd_Rom.er_Reserved0c is used as a pointer to diagArea by strap
ULONG *da_Pointer = (ULONG *)&cd->cd_Rom.er_Reserved0c; ULONG *da_Pointer = (ULONG *)&cd->cd_Rom.er_Reserved0c;
*da_Pointer = (ULONG)diagArea; *da_Pointer = (ULONG)diagArea;
} }
} else { } else {
FreeConfigDev(cd); FreeConfigDev(cd);
cd = NULL; cd = NULL;
} }
@ -264,7 +265,7 @@ static void Cleanup(struct DeviceBase *dev) {
} }
// if devName doesn't point to the const device_name then we need to free up that memory // if devName doesn't point to the const device_name then we need to free up that memory
if (devName != device_name) { if (devName != device_name) {
FreeMem(devName,sizeof(device_name)+4); FreeMem(devName,sizeof(device_name)+4);
devName = NULL; devName = NULL;
} }
@ -485,12 +486,12 @@ struct Library __attribute__((used, saveds)) * init_device(struct ExecBase *SysB
} }
/* /*
* device dependent expunge function * device dependent expunge function
* !!! CAUTION: This function runs in a forbidden state !!! * !!! CAUTION: This function runs in a forbidden state !!!
* This call is guaranteed to be single-threaded; only one task * This call is guaranteed to be single-threaded; only one task
* will execute your Expunge at a time. * will execute your Expunge at a time.
* *
* IMPORTANT: because Expunge is called from the memory allocator, * IMPORTANT: because Expunge is called from the memory allocator,
* it may NEVER Wait() or otherwise take long time to complete. * it may NEVER Wait() or otherwise take long time to complete.
*/ */
@ -509,11 +510,11 @@ static BPTR __attribute__((used, saveds)) expunge(struct DeviceBase *dev asm("a6
} }
/* /*
* device dependent open function * device dependent open function
* !!! CAUTION: This function runs in a forbidden state !!! * !!! CAUTION: This function runs in a forbidden state !!!
* This call is guaranteed to be single-threaded; only one task * This call is guaranteed to be single-threaded; only one task
* will execute your Open at a time. * will execute your Open at a time.
*/ */
static void __attribute__((used, saveds)) open(struct DeviceBase *dev asm("a6"), struct IORequest *ioreq asm("a1"), ULONG unitnum asm("d0"), ULONG flags asm("d1")) static void __attribute__((used, saveds)) open(struct DeviceBase *dev asm("a6"), struct IORequest *ioreq asm("a1"), ULONG unitnum asm("d0"), ULONG flags asm("d1"))
{ {
@ -628,11 +629,11 @@ static void td_get_geometry(struct IOStdReq *ioreq) {
} }
/* /*
* device dependent close function * device dependent close function
* !!! CAUTION: This function runs in a forbidden state !!! * !!! CAUTION: This function runs in a forbidden state !!!
* This call is guaranteed to be single-threaded; only one task * This call is guaranteed to be single-threaded; only one task
* will execute your Close at a time. * will execute your Close at a time.
*/ */
static BPTR __attribute__((used, saveds)) close(struct DeviceBase *dev asm("a6"), struct IORequest *ioreq asm("a1")) static BPTR __attribute__((used, saveds)) close(struct DeviceBase *dev asm("a6"), struct IORequest *ioreq asm("a1"))
{ {
@ -925,6 +926,85 @@ 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[8];
UWORD major;
major=(ExpansionBase->LibNode.lib_Version)%100; // we assume version number is under 100, but better safe than sorry
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;
Forbid();
AdjustBootPriority(SysBase,bootname,&ExpansionBase->MountList,false,1);
bootname[5]=bootname[6]='0';
AdjustBootPriority(SysBase,bootname,&ExpansionBase->MountList,true,2);
Permit();
CloseLibrary((struct Library *)ExpansionBase);
}
}
/** /**
* init * init
* *
@ -988,6 +1068,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"
@ -18,9 +19,9 @@
/** /**
* L_NewList * L_NewList
* *
* Initialize a new list * Initialize a new list
* *
* @param new_list Pointer to a new list * @param new_list Pointer to a new list
*/ */
void L_NewList(struct List *new_list) { void L_NewList(struct List *new_list) {
@ -31,9 +32,9 @@ void L_NewList(struct List *new_list) {
/** /**
* L_CreatePort * L_CreatePort
* *
* Create a new MsgPort * Create a new MsgPort
* *
* @param name (optional) name of the port * @param name (optional) name of the port
* @param priority priority of the port * @param priority priority of the port
* @returns pointer to a MsgPort * @returns pointer to a MsgPort
@ -49,7 +50,7 @@ struct MsgPort *L_CreatePort(STRPTR name, LONG pri) {
mp->mp_Node.ln_Name = name; mp->mp_Node.ln_Name = name;
mp->mp_SigBit = sigNum; mp->mp_SigBit = sigNum;
mp->mp_SigTask = FindTask(0); mp->mp_SigTask = FindTask(0);
L_NewList(&mp->mp_MsgList); L_NewList(&mp->mp_MsgList);
if (mp->mp_Node.ln_Name) if (mp->mp_Node.ln_Name)
@ -62,9 +63,9 @@ struct MsgPort *L_CreatePort(STRPTR name, LONG pri) {
/** /**
* L_DeletePort * L_DeletePort
* *
* Delete a MsgPort * Delete a MsgPort
* *
* @param mp Pointer to a MsgPort * @param mp Pointer to a MsgPort
*/ */
void L_DeletePort(struct MsgPort *mp) { void L_DeletePort(struct MsgPort *mp) {
@ -73,7 +74,7 @@ void L_DeletePort(struct MsgPort *mp) {
if (mp) { if (mp) {
if (mp->mp_Node.ln_Name) if (mp->mp_Node.ln_Name)
RemPort(mp); RemPort(mp);
FreeSignal(mp->mp_SigBit); FreeSignal(mp->mp_SigBit);
FreeMem(mp,sizeof(struct MsgPort)); FreeMem(mp,sizeof(struct MsgPort));
} }
@ -81,9 +82,9 @@ void L_DeletePort(struct MsgPort *mp) {
/** /**
* L_CreateExtIO * L_CreateExtIO
* *
* Create an Extended IO Request * Create an Extended IO Request
* *
* @param mp Pointer to the reply port * @param mp Pointer to the reply port
* @param size Size of the IO request * @param size Size of the IO request
* @return pointer to the IO request * @return pointer to the IO request
@ -105,9 +106,9 @@ struct IORequest* L_CreateExtIO(struct MsgPort *mp, ULONG size) {
/** /**
* L_CreateStdIO * L_CreateStdIO
* *
* Create a standard IO Request * Create a standard IO Request
* *
* @param mp Pointer to the reply port * @param mp Pointer to the reply port
* @return Pointer to an IOStdReq * @return Pointer to an IOStdReq
*/ */
@ -117,9 +118,9 @@ struct IOStdReq* L_CreateStdIO(struct MsgPort *mp) {
/** /**
* L_DeleteExtIO * L_DeleteExtIO
* *
* Delete an Extended IO Request * Delete an Extended IO Request
* *
* @param ior Pointer to an IORequest * @param ior Pointer to an IORequest
*/ */
void L_DeleteExtIO(struct IORequest *ior) { void L_DeleteExtIO(struct IORequest *ior) {
@ -133,9 +134,9 @@ void L_DeleteExtIO(struct IORequest *ior) {
/** /**
* L_DeleteStdIO * L_DeleteStdIO
* *
* Delete a Standard IO Requesrt * Delete a Standard IO Requesrt
* *
* @param ior Pointer to an IOStdReq * @param ior Pointer to an IOStdReq
*/ */
void L_DeleteStdIO(struct IOStdReq *ior) { void L_DeleteStdIO(struct IOStdReq *ior) {
@ -192,4 +193,43 @@ struct Task *L_CreateTask(char * taskName, LONG priority, APTR funcEntry, ULONG
AddTask(task,funcEntry,NULL); AddTask(task,funcEntry,NULL);
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
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 = (part->pb_Flags & PBFF_BOOTABLE) ? pp->de.de_BootPri : -128;
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+