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/execbase.h>
#include <exec/resident.h>
#include <hardware/cia.h>
#include <proto/exec.h>
#include <proto/expansion.h>
#include <resources/filesysres.h>
@ -81,7 +82,7 @@ char * set_dev_name(struct DeviceBase *dev) {
if (devName == NULL) return NULL;
strcpy(devName + 4,device_name);
}
switch (i) {
case 0:
*(ULONG *)devName = device_prefix[0];
@ -111,33 +112,33 @@ char * set_dev_name(struct DeviceBase *dev) {
* CreateFakeConfigDev
* Create fake ConfigDev and DiagArea to support autoboot without requiring real autoconfig device.
* Adapted from mounter.c by Toni Wilen
*
*
* @param SysBase Pointer to SysBase
* @param ExpansionBase Pointer to ExpansionBase
* @returns Pointer to a ConfigDev struct
*/
struct ConfigDev *CreateFakeConfigDev(struct ExecBase *SysBase, struct Library *ExpansionBase)
{
struct ConfigDev *cd;
struct ConfigDev *cd;
cd = AllocConfigDev();
if (cd) {
cd->cd_BoardAddr = NULL;
cd->cd_BoardSize = 0;
cd->cd_Rom.er_Type = ERTF_DIAGVALID;
ULONG bbSize = &bootblock_end - &bootblock;
ULONG daSize = sizeof(struct DiagArea) + bbSize;
struct DiagArea *diagArea = AllocMem(daSize, MEMF_CLEAR | MEMF_PUBLIC);
if (diagArea) {
diagArea->da_Config = DAC_CONFIGTIME;
diagArea->da_BootPoint = sizeof(struct DiagArea);
diagArea->da_Size = (UWORD)daSize;
cd = AllocConfigDev();
if (cd) {
cd->cd_BoardAddr = NULL;
cd->cd_BoardSize = 0;
cd->cd_Rom.er_Type = ERTF_DIAGVALID;
ULONG bbSize = &bootblock_end - &bootblock;
ULONG daSize = sizeof(struct DiagArea) + bbSize;
struct DiagArea *diagArea = AllocMem(daSize, MEMF_CLEAR | MEMF_PUBLIC);
if (diagArea) {
diagArea->da_Config = DAC_CONFIGTIME;
diagArea->da_BootPoint = sizeof(struct DiagArea);
diagArea->da_Size = (UWORD)daSize;
CopyMem(&bootblock, diagArea+1, bbSize);
// cd_Rom.er_Reserved0c is used as a pointer to diagArea by strap
ULONG *da_Pointer = (ULONG *)&cd->cd_Rom.er_Reserved0c;
*da_Pointer = (ULONG)diagArea;
}
} else {
// cd_Rom.er_Reserved0c is used as a pointer to diagArea by strap
ULONG *da_Pointer = (ULONG *)&cd->cd_Rom.er_Reserved0c;
*da_Pointer = (ULONG)diagArea;
}
} else {
FreeConfigDev(cd);
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 != device_name) {
if (devName != device_name) {
FreeMem(devName,sizeof(device_name)+4);
devName = NULL;
}
@ -485,12 +486,12 @@ struct Library __attribute__((used, saveds)) * init_device(struct ExecBase *SysB
}
/*
/*
* device dependent expunge function
* !!! CAUTION: This function runs in a forbidden state !!!
* This call is guaranteed to be single-threaded; only one task
* will execute your Expunge at a time.
*
*
* IMPORTANT: because Expunge is called from the memory allocator,
* 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
* !!! CAUTION: This function runs in a forbidden state !!!
* 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"))
{
@ -628,11 +629,11 @@ static void td_get_geometry(struct IOStdReq *ioreq) {
}
/*
/*
* device dependent close function
* !!! CAUTION: This function runs in a forbidden state !!!
* 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"))
{
@ -925,6 +926,85 @@ static const ULONG device_vectors[] =
-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
*
@ -988,6 +1068,10 @@ static struct Library __attribute__((used)) * init(BPTR seg_list asm("a0"))
}
FreeMem(ms,ms_size);
if (!seg_list) // Only tweak if we're in boot
TweakBootList(SysBase);
}
done:
return (struct Library *)mydev;

View File

@ -7,6 +7,7 @@
#include <exec/nodes.h>
#include <exec/ports.h>
#include <proto/exec.h>
#include <stdbool.h>
#include <string.h>
#include "debug.h"
@ -18,9 +19,9 @@
/**
* L_NewList
*
*
* Initialize a new list
*
*
* @param new_list Pointer to a new list
*/
void L_NewList(struct List *new_list) {
@ -31,9 +32,9 @@ void L_NewList(struct List *new_list) {
/**
* L_CreatePort
*
*
* Create a new MsgPort
*
*
* @param name (optional) name of the port
* @param priority priority of the port
* @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_SigBit = sigNum;
mp->mp_SigTask = FindTask(0);
L_NewList(&mp->mp_MsgList);
if (mp->mp_Node.ln_Name)
@ -62,9 +63,9 @@ struct MsgPort *L_CreatePort(STRPTR name, LONG pri) {
/**
* L_DeletePort
*
*
* Delete a MsgPort
*
*
* @param mp Pointer to a MsgPort
*/
void L_DeletePort(struct MsgPort *mp) {
@ -73,7 +74,7 @@ void L_DeletePort(struct MsgPort *mp) {
if (mp) {
if (mp->mp_Node.ln_Name)
RemPort(mp);
FreeSignal(mp->mp_SigBit);
FreeMem(mp,sizeof(struct MsgPort));
}
@ -81,9 +82,9 @@ void L_DeletePort(struct MsgPort *mp) {
/**
* L_CreateExtIO
*
*
* Create an Extended IO Request
*
*
* @param mp Pointer to the reply port
* @param size Size of the IO request
* @return pointer to the IO request
@ -105,9 +106,9 @@ struct IORequest* L_CreateExtIO(struct MsgPort *mp, ULONG size) {
/**
* L_CreateStdIO
*
*
* Create a standard IO Request
*
*
* @param mp Pointer to the reply port
* @return Pointer to an IOStdReq
*/
@ -117,9 +118,9 @@ struct IOStdReq* L_CreateStdIO(struct MsgPort *mp) {
/**
* L_DeleteExtIO
*
*
* Delete an Extended IO Request
*
*
* @param ior Pointer to an IORequest
*/
void L_DeleteExtIO(struct IORequest *ior) {
@ -133,9 +134,9 @@ void L_DeleteExtIO(struct IORequest *ior) {
/**
* L_DeleteStdIO
*
*
* Delete a Standard IO Requesrt
*
*
* @param ior Pointer to an IOStdReq
*/
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);
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_DeleteStdIO(struct IOStdReq *ior);
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

View File

@ -39,7 +39,6 @@
#include <dos/dos.h>
#include <dos/dosextens.h>
#include <dos/doshunks.h>
#include <hardware/cia.h>
#include <stdio.h>
#include <stdbool.h>
@ -91,8 +90,6 @@ struct MountData
int blocksize;
};
static volatile struct CIA * const ciaa = (struct CIA *)0x0bfe001;
// Get Block size of unit
BYTE GetGeometry(struct IOExtTD *req, struct DriveGeometry *geometry) {
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 DosLibrary *DOSBase = md->DOSBase;
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 = -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
}
}
}
bootPri = (part->pb_Flags & PBFF_BOOTABLE) ? pp->de.de_BootPri : -128;
if (ExpansionBase->LibNode.lib_Version >= 37) {
// KS 2.0+