// File: /workspace/github_cpp_makefile_star2_O1/goodix[P]gdix_hid_firmware_update/gtx8/gtx8.cpp
// Function: GTx8Device::SetBasicProperties()
int GTx8Device::SetBasicProperties()
{
	int ret;
	unsigned char fw_info[72] = {0};
	m_firmwareVersionMajor = 20;
	m_firmwareVersionMinor = 20;
	m_sensorID = 0xF;
	unsigned char cfg_ver = 0;
	int retry = 10;
	unsigned char chksum;

	if (!m_deviceOpen) {
		gdix_err("Please open device first\n");
		return -1;
	}
	do {
		ret = Read(CFG_START_ADDR, &cfg_ver, 1);
		if (ret < 0) {
			gdix_dbg("Failed read cfg VERSION, retry=%d\n", retry);
			continue;
		}
		gdix_dbg("cfg ver:%d\n", cfg_ver);
		ret = Read(VER_ADDR, fw_info, sizeof(fw_info));
		if (ret < 0)
			gdix_dbg("Failed read VERSION, retry=%d\n", retry);
		else
			break;
	} while (--retry);
	gdix_dbg("Fw_info array\n");
	gdix_dbg("0x%02x,0x%02x,0x%02x,0x%02x,0x%02x\n", fw_info[0], fw_info[1],
			 fw_info[2], fw_info[3], fw_info[4]);
	gdix_dbg("0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x\n", fw_info[5],
			 fw_info[6], fw_info[7], fw_info[8], fw_info[9], fw_info[10]);
	gdix_dbg("0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x\n", fw_info[11],
			 fw_info[12], fw_info[13], fw_info[14], fw_info[15], fw_info[16]);
	gdix_dbg("0x%02x,0x%02x,0x%02x,0x%02x,0x%02x\n", fw_info[17], fw_info[18],
			 fw_info[19], fw_info[20], fw_info[21]);
	if (!retry)
		return -1;

	/*check fw version*/
	chksum = ChecksumU8(fw_info, sizeof(fw_info));
	if (chksum) {
		gdix_err("fw version check sum error:%d\n", chksum);
		return -2;
	}

	memcpy(m_pid, &fw_info[9], 4);
	m_pid[4] = '\0';
	gdix_dbg("pid:%s\n", m_pid);
	m_sensorID = fw_info[21] & 0x0f;
	gdix_dbg("sensorID:%d\n", m_sensorID);

	m_firmwareVersionMajor = fw_info[18];
	m_firmwareVersionMinor =
		((fw_info[19] << 16) | (fw_info[20]) << 8) | cfg_ver;

	gdix_dbg("version:0x%x,0x%x\n", m_firmwareVersionMajor,
			 m_firmwareVersionMinor);

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x50(%rsp)
movabsq $0x1400000014, %rax     # imm = 0x1400000014
movq %rax, 0x10(%rdi)
movl $0xf, 0x18(%rdi)
movb $0x0, 0xf(%rsp)
cmpb $0x1, 0x8(%rdi)
jne 0xe88a
movq %rdi, %rbx
movl $0xa, %ebp
leaq 0xf(%rsp), %r14
leaq 0x12acb(%rip), %r13     # 0x21291
leaq 0x84ed(%rip), %r12      # 0x16cba
leaq 0x10(%rsp), %r15
movq (%rbx), %rax
movq %rbx, %rdi
movl $0x60dc, %esi           # imm = 0x60DC
movq %r14, %rdx
movl $0x1, %ecx
callq *0x20(%rax)
movb (%r13), %cl
testl %eax, %eax
js 0xe856
testb %cl, %cl
je 0xe81a
movq 0x127bd(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
movzbl 0xf(%rsp), %r8d
leaq 0x8559(%rip), %rsi      # 0x16d64
movq %r12, %rdx
movl $0x30, %ecx
xorl %eax, %eax
callq 0x5180
movq (%rbx), %rax
movq %rbx, %rdi
movl $0x452c, %esi           # imm = 0x452C
movq %r15, %rdx
movl $0x48, %ecx
callq *0x20(%rax)
testl %eax, %eax
jns 0xe8a9
cmpb $0x1, (%r13)
jne 0xe87d
movq 0x12776(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
leaq 0x8535(%rip), %rsi      # 0x16d81
movq %r12, %rdx
movl $0x33, %ecx
jmp 0xe873
testb %cl, %cl
je 0xe87d
movq 0x12757(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
leaq 0x84c5(%rip), %rsi      # 0x16d30
movq %r12, %rdx
movl $0x2d, %ecx
movl %ebp, %r8d
xorl %eax, %eax
callq 0x5180
decl %ebp
jne 0xe7d2
movb $0x1, %r14b
jmp 0xe8ac
leaq 0x12a00(%rip), %rax     # 0x21291
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpb $0x1, (%rax)
jne 0xeb47
callq 0x5c1a
jmp 0xeb47
xorl %r14d, %r14d
cmpb $0x1, (%r13)
jne 0xe8d7
movq 0x126fe(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
leaq 0x84ed(%rip), %rsi      # 0x16db1
leaq 0x83ef(%rip), %rdx      # 0x16cba
movl $0x37, %ecx
xorl %eax, %eax
callq 0x5180
cmpb $0x1, (%r13)
jne 0xe92e
movq 0x126d3(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
movzbl 0x10(%rsp), %r8d
movzbl 0x11(%rsp), %r9d
movzbl 0x12(%rsp), %r10d
movzbl 0x13(%rsp), %r11d
movzbl 0x14(%rsp), %r15d
subq $0x8, %rsp
leaq 0x84c0(%rip), %rsi      # 0x16dd1
leaq 0x83a2(%rip), %rdx      # 0x16cba
movl $0x39, %ecx
xorl %eax, %eax
pushq %r15
pushq %r11
pushq %r10
callq 0x5180
addq $0x20, %rsp
cmpb $0x1, (%r13)
jne 0xe989
movq 0x1267c(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
movzbl 0x15(%rsp), %r8d
movzbl 0x16(%rsp), %r9d
movzbl 0x17(%rsp), %r10d
movzbl 0x18(%rsp), %r11d
movzbl 0x19(%rsp), %r15d
movzbl 0x1a(%rsp), %r12d
leaq 0x849c(%rip), %rsi      # 0x16e06
leaq 0x8349(%rip), %rdx      # 0x16cba
movl $0x3b, %ecx
xorl %eax, %eax
pushq %r12
pushq %r15
pushq %r11
pushq %r10
callq 0x5180
addq $0x20, %rsp
cmpb $0x1, (%r13)
jne 0xe9e4
movq 0x12621(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
movzbl 0x1b(%rsp), %r8d
movzbl 0x1c(%rsp), %r9d
movzbl 0x1d(%rsp), %r10d
movzbl 0x1e(%rsp), %r11d
movzbl 0x1f(%rsp), %r15d
movzbl 0x20(%rsp), %r12d
leaq 0x8441(%rip), %rsi      # 0x16e06
leaq 0x82ee(%rip), %rdx      # 0x16cba
movl $0x3d, %ecx
xorl %eax, %eax
pushq %r12
pushq %r15
pushq %r11
pushq %r10
callq 0x5180
addq $0x20, %rsp
cmpb $0x1, (%r13)
jne 0xea3b
movq 0x125c6(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
movzbl 0x21(%rsp), %r8d
movzbl 0x22(%rsp), %r9d
movzbl 0x23(%rsp), %r10d
movzbl 0x24(%rsp), %r11d
movzbl 0x25(%rsp), %r15d
subq $0x8, %rsp
leaq 0x83b3(%rip), %rsi      # 0x16dd1
leaq 0x8295(%rip), %rdx      # 0x16cba
movl $0x3f, %ecx
xorl %eax, %eax
pushq %r15
pushq %r11
pushq %r10
callq 0x5180
addq $0x20, %rsp
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testb %r14b, %r14b
jne 0xeb47
leaq 0x10(%rsp), %rsi
movq %rbx, %rdi
movl $0x48, %edx
callq 0xdc70
testb %al, %al
je 0xea7c
movl $0xfffffffe, %ebp       # imm = 0xFFFFFFFE
cmpb $0x1, (%r13)
jne 0xeb47
movzbl %al, %edi
callq 0x5c3c
jmp 0xeb47
movl 0x19(%rsp), %eax
movl %eax, 0x1c(%rbx)
movb $0x0, 0x20(%rbx)
cmpb $0x1, (%r13)
jne 0xeab6
leaq 0x1c(%rbx), %r8
movq 0x1251f(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
leaq 0x83d7(%rip), %rsi      # 0x16e7a
leaq 0x8210(%rip), %rdx      # 0x16cba
movl $0x4c, %ecx
xorl %eax, %eax
callq 0x5180
movzbl 0x25(%rsp), %r8d
andl $0xf, %r8d
movl %r8d, 0x18(%rbx)
cmpb $0x1, (%r13)
jne 0xeaef
movq 0x124e6(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
leaq 0x83b7(%rip), %rsi      # 0x16e93
leaq 0x81d7(%rip), %rdx      # 0x16cba
movl $0x4e, %ecx
xorl %eax, %eax
callq 0x5180
movzbl 0x22(%rsp), %r8d
movl %r8d, 0x10(%rbx)
movzbl 0x23(%rsp), %eax
shll $0x10, %eax
movzbl 0x24(%rsp), %ecx
shll $0x8, %ecx
orl %eax, %ecx
movzbl 0xf(%rsp), %r9d
orl %ecx, %r9d
movl %r9d, 0x14(%rbx)
xorl %ebp, %ebp
cmpb $0x1, (%r13)
jne 0xeb47
movq 0x12490(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
leaq 0x837f(%rip), %rsi      # 0x16eb1
leaq 0x8181(%rip), %rdx      # 0x16cba
xorl %ebp, %ebp
movl $0x55, %ecx
xorl %eax, %eax
callq 0x5180
movl %ebp, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq