The nearest source codes that I have are the two FreeBASIC-DOS sources in the attachment. Except for the interface function and a few global variables, the essential parts are done in inline (GAS) assembly. And in case it’s not obvious, the commenting is aimed at the "lowest common denominator"

Also, I doubt that it’s likely to matter but in dostimer_posted I noticed that I forgot to undo the unmasking of IRQ8 in my destructor.
This is an older source that maximizes the short-term resolution at the expense of long-term accuracy.
'====================================================================
'' This function returns the elapsed seconds since the system was
'' started, or zero if the processor does not support the CPUID
'' or RDTSC instructions. The elapsed seconds are determined by
'' dividing the current Time Stamp Counter (TSC) value by the CPU
'' clock frequency, as determined in the first call by counting
'' the processor clock cycles over a (65536/1193182) second
'' interval timed with system timer 2.
'====================================================================
function HrTimer() as double
static as double clkhz
dim as ulongint tsc
dim as integer i
if clkhz = 0 then
'------------------------------------------------------------
'' CPUID supported if can set/clear ID flag (EFLAGS bit 21).
'------------------------------------------------------------
asm
pushfd
pop edx
pushfd
pop eax
xor eax, &h200000 '' flip ID flag
push eax
popfd
pushfd
pop eax
xor eax, edx
mov [i], eax
end asm
if i = 0 then return 0
'---------------------------------------------------------------
'' TSC supported if CPUID func 1 returns with bit 4 of EDX set.
'---------------------------------------------------------------
asm
mov eax, 1
cpuid
and edx, &h10
mov [i], edx
end asm
if i = 0 then return 0
'-----------------------------------------------------------
'' Set the gate for timer 2 (bit 0 at I/O port 61h) to OFF.
'-----------------------------------------------------------
out &h61, inp(&h61) and not 1
'----------------------------------------------------
'' Program timer 2 for LSB then MSB, mode 0, binary.
'' bit 7-6: 10 = timer 2
'' bit 5-4: 11 = R/W LSB then MSB
'' bit 3-1: 000 = single timeout
'' bit 0: 0 = binary
'----------------------------------------------------
out &h43, &hb0
'---------------------------------------------------------
'' Load the starting value, LSB then MSB. This value will
'' cause the timer to time out after 65536 cycles of its
'' 1193182 Hz clock.
'---------------------------------------------------------
out &h42, 0
out &h42, 0
'-------------------------------------------
'' Serialize and get the current TSC value.
'-------------------------------------------
asm
xor eax, eax
cpuid
rdtsc
mov [tsc], eax
mov [tsc+4], edx
end asm
'----------------------------------------------------------
'' Set the gate for timer 2 (bit 0 at I/O port 61h) to ON.
'----------------------------------------------------------
out &h61, inp(&h61) or 1
'------------------------------------------------------------
'' Wait until the output bit (bit 5 at I/O port 61h) is set.
'------------------------------------------------------------
wait &h61, &h20
'--------------------------------------------------
'' Serialize and calculate the elapsed TSC counts.
'--------------------------------------------------
asm
xor eax, eax
cpuid
rdtsc
sub eax, [tsc]
sbb edx, [tsc+4]
mov [tsc], eax
mov [tsc+4], edx
end asm
'-------------------------------------------------------------
'' Set the gate for timer 2 (bit 0 at I/O port 61h) to OFF.
'-------------------------------------------------------------
out &h61, inp(&h61) and not 1
'-------------------------------------------
'' Calc and save the processor clock speed.
'-------------------------------------------
clkhz = tsc / (65536 / 1193182)
end if
'-------------------------------------------
'' Serialize and get the current TSC value.
'-------------------------------------------
asm
xor eax, eax
cpuid
rdtsc
mov [tsc], eax
mov [tsc+4], edx
end asm
'---------------------------------------
'' Calc and return the elapsed seconds.
'---------------------------------------
return tsc / clkhz
end function
'====================================================================
And, although I cannot find the source ATM, I did multiple tests of a timer that read the running count for system timer 0 and combined it with the BIOS timer tick value. In theory this should effectively emulate a counter with a 1/1193182 = 838 ns period, but in my tests, running in PM, the effective resolution was in the millisecond range. I recall the I/O port accesses taking much longer than I expected.