Copyright (c) Hyperion Entertainment and contributors.
Anatomy of a SATA Device Driver
Introduction
This article describes the p5020sata.device and how it works. It is intended to be used in conjunction with the actual source code. The author will be going through this article at the AmiWest 2016 DevCon on October 8 and 9, 2016.
Initialization
Everything begins with a resident kickstart module. You can see a list of kickstart modules in the SYS:Kickstart/Kicklayout file. All of the modules listed in there will be loaded and linked when the system boots up. They become the system kernel and they are no loaded again until you do a cold reboot.
Creating a resident kickstart module is pretty simple. Here is the resident structure used by the p5020sata.device driver:
// Priority of resident kernel module // // Chosen to be lower than mounter.library which is at -45 // which means this device is initialized after mounter.library. #define KMOD_PRIORITY -46 static struct Resident launch_restag USED = { RTC_MATCHWORD, &launch_restag, (APTR)(&launch_restag + 1), RTF_NATIVE | RTF_COLDSTART, 54, NT_UNKNOWN, KMOD_PRIORITY, DEVICE_NAME " launch", "$VER: " DEVICE_NAME " launch", launch_dev };
The most important item to note is the choice of kickstart module priority from 127 to -128 in that order. Each kickstart module will be executed in the order of its priority. So if you have a kickstart module which dependent on another kickstart module you need to ensure the other module is executed first. In this case we need mounter.library to be available.
You can see the complete list of resident modules using Ranger in the Exec/Residents tab.
The entry point is named launch_dev and it looks like this:
APTR launch_dev(struct Library *lib, APTR seglist, struct ExecBase *exec) { struct ExecIFace *IExec = (struct ExecIFace*)exec->MainInterface; IExec->Obtain(); IExec->DebugPrintF("launch_dev() enter\n"); struct SataDevice *device = create_sata_device(IExec); IExec->DebugPrintF("launch_dev() exit\n"); IExec->Release(); if (device == NULL) { return 0; } else { return (APTR)1; } }
The return value from the launch routine is either 0 for failure or 1 for success.