// File: /workspace/github_cpp_makefile_star2_O2/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)
andq $0x0, 0x50(%rsp)
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movabsq $0x1400000014, %rax     # imm = 0x1400000014
movq %rax, 0x10(%rdi)
movl $0xf, 0x18(%rdi)
movb $0x0, 0xf(%rsp)
cmpb $0x1, 0x8(%rdi)
jne 0xd1fd
movq %rdi, %rbx
pushq $0xa
popq %rbp
leaq 0xf(%rsp), %r14
pushq $0x1
popq %r15
leaq 0x8b28(%rip), %r13      # 0x15c59
pushq $0x48
popq %r12
movq (%rbx), %rax
movq %rbx, %rdi
movl $0x60dc, %esi           # imm = 0x60DC
movq %r14, %rdx
movl %r15d, %ecx
callq *0x20(%rax)
leaq 0x13141(%rip), %rcx     # 0x20291
movb (%rcx), %cl
testl %eax, %eax
js 0xd1c2
testb %cl, %cl
je 0xd17e
movq 0x12e57(%rip), %rax     # 0x1ffb8
movq (%rax), %rdi
movzbl 0xf(%rsp), %r8d
leaq 0x8b92(%rip), %rsi      # 0x15d03
movq %r13, %rdx
pushq $0x30
popq %rcx
xorl %eax, %eax
callq 0x5180
movq (%rbx), %rax
movq %rbx, %rdi
movl $0x452c, %esi           # imm = 0x452C
leaq 0x10(%rsp), %rdx
movl %r12d, %ecx
callq *0x20(%rax)
leaq 0x130f6(%rip), %rcx     # 0x20291
movb (%rcx), %cl
testl %eax, %eax
jns 0xd237
testb $0x1, %cl
je 0xd1e7
movq 0x12e07(%rip), %rax     # 0x1ffb8
movq (%rax), %rdi
leaq 0x8b65(%rip), %rsi      # 0x15d20
movq %r13, %rdx
pushq $0x33
jmp 0xd1dc
testb %cl, %cl
je 0xd1e7
movq 0x12deb(%rip), %rax     # 0x1ffb8
movq (%rax), %rdi
leaq 0x8af8(%rip), %rsi      # 0x15ccf
movq %r13, %rdx
pushq $0x2d
popq %rcx
movl %ebp, %r8d
xorl %eax, %eax
callq 0x5180
decl %ebp
jne 0xd135
leaq 0x1309b(%rip), %rax     # 0x20291
movb (%rax), %cl
movb $0x1, %bpl
jmp 0xd239
leaq 0x1308d(%rip), %rax     # 0x20291
pushq $-0x1
popq %rbx
cmpb $0x1, (%rax)
jne 0xd50e
movq 0x12dc1(%rip), %rax     # 0x1ffd8
movq (%rax), %rdi
leaq 0x8a0d(%rip), %rsi      # 0x15c2e
leaq 0x8a31(%rip), %rdx      # 0x15c59
pushq $0x27
popq %rcx
xorl %eax, %eax
callq 0x5180
jmp 0xd50e
xorl %ebp, %ebp
testb $0x1, %cl
je 0xd269
movq 0x12d73(%rip), %rax     # 0x1ffb8
movq (%rax), %rdi
leaq 0x8b01(%rip), %rsi      # 0x15d50
leaq 0x8a03(%rip), %rdx      # 0x15c59
pushq $0x37
popq %rcx
xorl %eax, %eax
callq 0x5180
leaq 0x1302a(%rip), %rax     # 0x20291
movb (%rax), %cl
testb $0x1, %cl
je 0xd2c5
movq 0x12d43(%rip), %rax     # 0x1ffb8
movq (%rax), %rdi
movzbl 0x10(%rsp), %r8d
movzbl 0x11(%rsp), %r9d
movzbl 0x12(%rsp), %r10d
movzbl 0x13(%rsp), %r11d
movzbl 0x14(%rsp), %r14d
subq $0x8, %rsp
leaq 0x8acf(%rip), %rsi      # 0x15d70
leaq 0x89b1(%rip), %rdx      # 0x15c59
pushq $0x39
popq %rcx
xorl %eax, %eax
pushq %r14
pushq %r11
pushq %r10
callq 0x5180
addq $0x20, %rsp
leaq 0x12fce(%rip), %rax     # 0x20291
movb (%rax), %cl
testb $0x1, %cl
je 0xd325
movq 0x12ce7(%rip), %rax     # 0x1ffb8
movq (%rax), %rdi
movzbl 0x15(%rsp), %r8d
movzbl 0x16(%rsp), %r9d
movzbl 0x17(%rsp), %r10d
movzbl 0x18(%rsp), %r11d
movzbl 0x19(%rsp), %r14d
movzbl 0x1a(%rsp), %r15d
leaq 0x8aa6(%rip), %rsi      # 0x15da5
leaq 0x8953(%rip), %rdx      # 0x15c59
pushq $0x3b
popq %rcx
xorl %eax, %eax
pushq %r15
pushq %r14
pushq %r11
pushq %r10
callq 0x5180
addq $0x20, %rsp
leaq 0x12f6e(%rip), %rax     # 0x20291
movb (%rax), %cl
testb $0x1, %cl
je 0xd385
movq 0x12c87(%rip), %rax     # 0x1ffb8
movq (%rax), %rdi
movzbl 0x1b(%rsp), %r8d
movzbl 0x1c(%rsp), %r9d
movzbl 0x1d(%rsp), %r10d
movzbl 0x1e(%rsp), %r11d
movzbl 0x1f(%rsp), %r14d
movzbl 0x20(%rsp), %r15d
leaq 0x8a46(%rip), %rsi      # 0x15da5
leaq 0x88f3(%rip), %rdx      # 0x15c59
pushq $0x3d
popq %rcx
xorl %eax, %eax
pushq %r15
pushq %r14
pushq %r11
pushq %r10
callq 0x5180
addq $0x20, %rsp
leaq 0x12f0e(%rip), %rax     # 0x20291
movb (%rax), %cl
testb $0x1, %cl
je 0xd3d8
movq 0x12c27(%rip), %rax     # 0x1ffb8
movq (%rax), %rdi
movzbl 0x21(%rsp), %r8d
movzbl 0x22(%rsp), %r9d
movzbl 0x23(%rsp), %r10d
movzbl 0x24(%rsp), %r11d
movzbl 0x25(%rsp), %r14d
subq $0x8, %rsp
leaq 0x89b3(%rip), %rsi      # 0x15d70
leaq 0x8895(%rip), %rdx      # 0x15c59
pushq $0x3f
popq %rcx
xorl %eax, %eax
pushq %r14
pushq %r11
pushq %r10
callq 0x5180
addq $0x20, %rsp
testb %bpl, %bpl
je 0xd3e5
pushq $-0x1
popq %rbx
jmp 0xd50e
leaq 0x10(%rsp), %rsi
pushq $0x48
popq %rdx
movq %rbx, %rdi
callq 0xc54a
testb %al, %al
je 0xd437
pushq $-0x2
popq %rbx
leaq 0x12e8e(%rip), %rcx     # 0x20291
cmpb $0x1, (%rcx)
jne 0xd50e
movq 0x12bc5(%rip), %rcx     # 0x1ffd8
movq (%rcx), %rdi
movzbl %al, %r8d
leaq 0x9b16(%rip), %rsi      # 0x16f37
leaq 0x8831(%rip), %rdx      # 0x15c59
pushq $0x46
popq %rcx
xorl %eax, %eax
callq 0x5180
jmp 0xd50e
movl 0x19(%rsp), %eax
movl %eax, 0x1c(%rbx)
movb $0x0, 0x20(%rbx)
leaq 0x12e48(%rip), %rax     # 0x20291
movb (%rax), %al
cmpb $0x1, %al
jne 0xd47e
leaq 0x1c(%rbx), %r8
movq 0x12b5e(%rip), %rax     # 0x1ffb8
movq (%rax), %rdi
leaq 0x89b5(%rip), %rsi      # 0x15e19
leaq 0x87ee(%rip), %rdx      # 0x15c59
pushq $0x4c
popq %rcx
xorl %eax, %eax
callq 0x5180
leaq 0x12e15(%rip), %rax     # 0x20291
movb (%rax), %al
movzbl 0x25(%rsp), %r8d
andl $0xf, %r8d
movl %r8d, 0x18(%rbx)
testb $0x1, %al
je 0xd4bb
movq 0x12b21(%rip), %rax     # 0x1ffb8
movq (%rax), %rdi
leaq 0x8991(%rip), %rsi      # 0x15e32
leaq 0x87b1(%rip), %rdx      # 0x15c59
pushq $0x4e
popq %rcx
xorl %eax, %eax
callq 0x5180
leaq 0x12dd8(%rip), %rax     # 0x20291
movb (%rax), %al
movzbl 0x22(%rsp), %r8d
movl %r8d, 0x10(%rbx)
movzbl 0x23(%rsp), %ecx
shll $0x10, %ecx
movzbl 0x24(%rsp), %edx
shll $0x8, %edx
orl %ecx, %edx
movzbl 0xf(%rsp), %r9d
orl %edx, %r9d
movl %r9d, 0x14(%rbx)
xorl %ebx, %ebx
testb $0x1, %al
je 0xd50e
movq 0x12ac7(%rip), %rax     # 0x1ffb8
movq (%rax), %rdi
leaq 0x8955(%rip), %rsi      # 0x15e50
leaq 0x8757(%rip), %rdx      # 0x15c59
xorl %ebx, %ebx
pushq $0x55
popq %rcx
xorl %eax, %eax
callq 0x5180
movl %ebx, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop