Accessing Sifive debug DMI register using jlink script APIs


I facing problem DMI register reading and writing using JLink APIs.

void JTAG_DMI_WRITE(unsigned int addr, unsigned int val) {
int BitPos;


JLINK_JTAG_WriteDRCont(2, 2);
BitPos = JLINK_JTAG_WriteDRCont(val, 32);
JLINK_JTAG_WriteDREnd(addr, 32); 

MessageBox1("JTAG_DMI_WRITE BitPos ", BitPos);
MessageBox1("JTAG_DMI_WRITE addr : ", addr);


unsigned int JTAG_DMI_READ(unsigned int addr) {
int BitPos;
unsigned int val0;
unsigned int val1;
unsigned int val2;


BitPos = JLINK_JTAG_WriteDRCont(1, 2);
JLINK_JTAG_WriteDRCont(0, 32);
JLINK_JTAG_WriteDREnd(addr, 32); 

val0 = JTAG_GetU32(BitPos);
val1 = JTAG_GetU32(BitPos+32);
val2 = JTAG_GetU32(BitPos+64);

MessageBox1("JTAG_DMI_READ addr ", addr);
MessageBox1("JTAG_DMI_READ BitPos ", BitPos);
MessageBox1("JTAG_DMI_READ val 1 ", val0);
MessageBox1("JTAG_DMI_READ val 2 ", val1);
MessageBox1("JTAG_DMI_READ val 3 ", val2);

return val0;

is this sequence correct?
I am liitle confused with 66-bits of data writing in to DMI register. but JLink document mentioned only 64bits buffer for TDO or any other PIN.