Is there any documentation for writing hal driver modules for linuxcnc?
linuxcnc.org/docs/2.5/html/hal/comp.html is a starting point, then look at the components in the source code and pick one which is closest to what you want to do.
Some of these are in pure C, it might be easiest to understand the ones with a .comp suffix to start with, as they just contain pin creation and the relevant function code, without the other
bits that comp fills in.
does linuxcnc have any code to load modules with root access?
You shouldn't need to if the module is loaded with loadrt, it will have access to what it requires, unless you are completely directly hacking and not using rtapi calls.
You will need to be specific as to what you want to achieve when you have been able to study the existing modules.
I suspect the code most of interest to you will be in the ../src/hal/drivers/ directory. Most of them are in pure C, you can always run
comp filename to generate a C file from an existing .comp file to see what is added.
Lot of reading to do!
regards