// File: estwings57[P]CasHMC/sources/Packet.cpp
// Function: CasHMC::Packet::Packet(CasHMC::PacketType, CasHMC::PacketCommandType, unsigned long, unsigned int, unsigned int, CasHMC::TranTrace*)
Packet::Packet(PacketType packet, PacketCommandType cmd, uint64_t addr, unsigned cub, unsigned lng, TranTrace *lat):
	trace(lat),
	packetType(packet),
	CUB(cub),
	LNG(lng),
	CMD(cmd),
	ADRS(addr)
{
	bufPopDelay=1;
	CRCtable[256]=0;	
	Pb=0;
	CRC=0; RTC=0; SLID=0;
	SEQ=0; FRP=0; RRP=0;
	AF=0; ERRSTAT=0; DINV=0;
	chkCRC = false;
	chkRRP = false;
	segment = false;
	reqDataSize=16;	//The minimum size is 16-Byte
	
	if(packet != FLOW) {
		TAG = (packetGlobalTAG++)%2048;
	}
	else {
		TAG = 0;
	}
	
	ADRS = (ADRS<<30)>>30;	//Address length is 34 bits
	
	if(CRC_CHECK) {
		if(LNG>1) {
			DATA = new uint64_t[(LNG-1)*2];
			uint64_t tempData;
			for(int i=0; i<(LNG-1)*2; i++) {
				tempData = rand();
				tempData = (tempData<<32)|rand();
				DATA[i] = tempData;
			}
		}
		else {
			DATA = NULL;
		}
		MakeCRCtable(CRCtable, 0xEB31D82E);
	}
	else {
		DATA = NULL;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq %rcx, -0x18(%rbp)
movl %r8d, -0x1c(%rbp)
movl %r9d, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x38(%rbp)
leaq 0x22227(%rip), %rcx     # 0x65ce8
addq $0x10, %rcx
movq %rcx, (%rax)
movq 0x10(%rbp), %rcx
movq %rcx, 0x8(%rax)
movl -0xc(%rbp), %ecx
movl %ecx, 0x10(%rax)
movl -0x1c(%rbp), %ecx
movl %ecx, 0x428(%rax)
movl -0x20(%rbp), %ecx
movl %ecx, 0x430(%rax)
movl -0x10(%rbp), %ecx
movl %ecx, 0x434(%rax)
movq -0x18(%rbp), %rcx
movq %rcx, 0x450(%rax)
movl $0x1, 0x14(%rax)
movl $0x0, 0x420(%rax)
movl $0x0, 0x458(%rax)
movl $0x0, 0x438(%rax)
movl $0x0, 0x43c(%rax)
movl $0x0, 0x440(%rax)
movl $0x0, 0x444(%rax)
movl $0x0, 0x448(%rax)
movl $0x0, 0x44c(%rax)
movl $0x0, 0x45c(%rax)
movl $0x0, 0x460(%rax)
movl $0x0, 0x464(%rax)
movb $0x0, 0x420(%rax)
movb $0x0, 0x421(%rax)
movb $0x0, 0x422(%rax)
movl $0x10, 0x424(%rax)
cmpl $0x2, -0xc(%rbp)
je 0x43bbf
movq -0x38(%rbp), %rax
leaq 0x22977(%rip), %rcx     # 0x66518
movl (%rcx), %ecx
movl %ecx, %esi
addl $0x1, %esi
leaq 0x22969(%rip), %rdx     # 0x66518
movl %esi, (%rdx)
andl $0x7ff, %ecx            # imm = 0x7FF
movl %ecx, 0x42c(%rax)
jmp 0x43bcd
movq -0x38(%rbp), %rax
movl $0x0, 0x42c(%rax)
movq -0x38(%rbp), %rax
movq 0x450(%rax), %rcx
shlq $0x1e, %rcx
shrq $0x1e, %rcx
movq %rcx, 0x450(%rax)
leaq 0x2297e(%rip), %rax     # 0x6656c
testb $0x1, (%rax)
je 0x43cd2
movq -0x38(%rbp), %rax
cmpl $0x1, 0x430(%rax)
jbe 0x43caf
movq -0x38(%rbp), %rax
movl 0x430(%rax), %eax
subl $0x1, %eax
shll %eax
movl %eax, %eax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x4030
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x18(%rax)
movl $0x0, -0x2c(%rbp)
movq -0x38(%rbp), %rcx
movl -0x2c(%rbp), %eax
movl 0x430(%rcx), %ecx
subl $0x1, %ecx
shll %ecx
cmpl %ecx, %eax
jae 0x43cad
callq 0x4120
cltq
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
shlq $0x20, %rax
movq %rax, -0x40(%rbp)
callq 0x4120
movq -0x40(%rbp), %rcx
movl %eax, %edx
movq -0x38(%rbp), %rax
movslq %edx, %rdx
orq %rdx, %rcx
movq %rcx, -0x28(%rbp)
movq -0x28(%rbp), %rdx
movq 0x18(%rax), %rax
movslq -0x2c(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x43c4c
jmp 0x43cbb
movq -0x38(%rbp), %rax
movq $0x0, 0x18(%rax)
movq -0x38(%rbp), %rdi
movq %rdi, %rsi
addq $0x20, %rsi
movl $0xeb31d82e, %edx       # imm = 0xEB31D82E
callq 0x43cf0
jmp 0x43cde
movq -0x38(%rbp), %rax
movq $0x0, 0x18(%rax)
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)