// File: /workspace/github_cpp_makefile_star2_O2/CMU-SAFARI[P]MQSim/src/ssd/Address_Mapping_Unit_Page_Level.cpp
// Function: SSD_Components::AddressMappingDomain::AddressMappingDomain(unsigned int, unsigned int, unsigned int, SSD_Components::Cached_Mapping_Table*, SSD_Components::Flash_Plane_Allocation_Scheme_Type, unsigned int*, unsigned int, unsigned int*, unsigned int, unsigned int*, unsigned int, unsigned int*, unsigned int, unsigned long, unsigned long, unsigned int)
AddressMappingDomain::AddressMappingDomain(unsigned int cmt_capacity, unsigned int cmt_entry_size, unsigned int no_of_translation_entries_per_page,
		Cached_Mapping_Table* CMT,
		Flash_Plane_Allocation_Scheme_Type PlaneAllocationScheme,
		flash_channel_ID_type* channel_ids, unsigned int channel_no, flash_chip_ID_type* chip_ids, unsigned int chip_no,
		flash_die_ID_type* die_ids, unsigned int die_no, flash_plane_ID_type* plane_ids, unsigned int plane_no,
		PPA_type total_physical_sectors_no, LHA_type total_logical_sectors_no, unsigned int sectors_no_per_page) :
		CMT_entry_size(cmt_entry_size), Translation_entries_per_page(no_of_translation_entries_per_page), No_of_inserted_entries_in_preconditioning(0),
		PlaneAllocationScheme(PlaneAllocationScheme), Channel_no(channel_no), Chip_no(chip_no), Die_no(die_no), Plane_no(plane_no)
	{
		Total_physical_pages_no = total_physical_sectors_no / sectors_no_per_page;
		max_logical_sector_address = total_logical_sectors_no;
		Total_logical_pages_no = (max_logical_sector_address / sectors_no_per_page) + (max_logical_sector_address % sectors_no_per_page == 0? 0 : 1);
		
		Channel_ids = new flash_channel_ID_type[channel_no];
		for (flash_channel_ID_type cid = 0; cid < channel_no; cid++) {
			Channel_ids[cid] = channel_ids[cid];
		}
		
		Chip_ids = new flash_chip_ID_type[chip_no];
		for (flash_chip_ID_type cid = 0; cid < chip_no; cid++) {
			Chip_ids[cid] = chip_ids[cid];
		}
		
		Die_ids = new flash_die_ID_type[die_no];
		for (flash_die_ID_type did = 0; did < die_no; did++) {
			Die_ids[did] = die_ids[did];
		}
		
		Plane_ids = new flash_plane_ID_type[plane_no];
		for (flash_plane_ID_type pid = 0; pid < plane_no; pid++) {
			Plane_ids[pid] = plane_ids[pid];
		}

		GlobalMappingTable = new GMTEntryType[Total_logical_pages_no];
		for (unsigned int i = 0; i < Total_logical_pages_no; i++) {
			GlobalMappingTable[i].PPA = NO_PPA;
			GlobalMappingTable[i].WrittenStateBitmap = UNWRITTEN_LOGICAL_PAGE;
			GlobalMappingTable[i].TimeStamp = 0;
		}

		//If CMT is NULL, then each address mapping domain should create its own CMT
		if (CMT == NULL) {
			//Each flow (address mapping domain) has its own CMT, so CMT is create here in the constructor
			this->CMT = new Cached_Mapping_Table(cmt_capacity);
		} else {
			//The entire CMT space is shared among concurrently running flows (i.e., address mapping domains of all flow)
			this->CMT = CMT;
		}

		Total_translation_pages_no = MVPN_type(Total_logical_pages_no / Translation_entries_per_page);
		GlobalTranslationDirectory = new GTDEntryType[Total_translation_pages_no + 1];
		for (MVPN_type i = 0; i <= Total_translation_pages_no; i++) {
			GlobalTranslationDirectory[i].MPPN = (MPPN_type)NO_MPPN;
			GlobalTranslationDirectory[i].TimeStamp = INVALID_TIME_STAMP;
		}
	}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r8, 0x18(%rsp)
movl %esi, 0x8(%rsp)
movq %rdi, %rbx
movl 0xb0(%rsp), %esi
movl 0x68(%rsp), %r13d
movl 0x98(%rsp), %edi
movl 0x88(%rsp), %r8d
movl %edx, 0x8(%rbx)
movl %ecx, 0x10(%rsp)
movl %ecx, 0xc(%rbx)
andl $0x0, 0x18(%rbx)
leaq 0x30(%rbx), %rax
andl $0x0, 0x30(%rbx)
andq $0x0, 0x38(%rbx)
movq %rax, 0x40(%rbx)
movq %rax, 0x48(%rbx)
andq $0x0, 0x50(%rbx)
leaq 0x60(%rbx), %rax
andl $0x0, 0x60(%rbx)
andq $0x0, 0x68(%rbx)
movq %rax, 0x70(%rbx)
movq %rax, 0x78(%rbx)
andq $0x0, 0x80(%rbx)
leaq 0x90(%rbx), %rax
andl $0x0, 0x90(%rbx)
andq $0x0, 0x98(%rbx)
movq %rax, 0xa0(%rbx)
movq %rax, 0xa8(%rbx)
andq $0x0, 0xb0(%rbx)
leaq 0xc0(%rbx), %rax
andl $0x0, 0xc0(%rbx)
andq $0x0, 0xc8(%rbx)
movq %rax, 0xd0(%rbx)
movq %rax, 0xd8(%rbx)
andq $0x0, 0xe0(%rbx)
leaq 0xf0(%rbx), %rax
andl $0x0, 0xf0(%rbx)
andq $0x0, 0xf8(%rbx)
movq %rax, 0x100(%rbx)
movq %rax, 0x108(%rbx)
andq $0x0, 0x110(%rbx)
leaq 0x120(%rbx), %rax
andl $0x0, 0x120(%rbx)
andq $0x0, 0x128(%rbx)
movq %rax, 0x130(%rbx)
movq %rax, 0x138(%rbx)
andq $0x0, 0x140(%rbx)
leaq 0x150(%rbx), %rax
andl $0x0, 0x150(%rbx)
andq $0x0, 0x158(%rbx)
movq %rax, 0x160(%rbx)
movq %rax, 0x168(%rbx)
andq $0x0, 0x170(%rbx)
leaq 0x180(%rbx), %rax
andl $0x0, 0x180(%rbx)
andq $0x0, 0x188(%rbx)
movq %rax, 0x190(%rbx)
movq %rax, 0x198(%rbx)
andq $0x0, 0x1a0(%rbx)
leaq 0x1b0(%rbx), %rax
andl $0x0, 0x1b0(%rbx)
andq $0x0, 0x1b8(%rbx)
movq %rax, 0x1c0(%rbx)
movq %rax, 0x1c8(%rbx)
andq $0x0, 0x1d0(%rbx)
movl 0x78(%rsp), %r10d
andl $0x0, 0x1e0(%rbx)
movq 0xa8(%rsp), %rcx
andq $0x0, 0x1e8(%rbx)
movq 0xa0(%rsp), %rax
leaq 0x1e0(%rbx), %rdx
movq %rdx, 0x1f0(%rbx)
movq %rdx, 0x1f8(%rbx)
andq $0x0, 0x200(%rbx)
movl %r9d, 0x208(%rbx)
movl %r13d, 0x218(%rbx)
movl %r10d, 0x228(%rbx)
movl %r8d, 0x238(%rbx)
movl %edi, 0x248(%rbx)
xorl %edx, %edx
divq %rsi
movq %rax, 0x260(%rbx)
movq %rcx, 0x250(%rbx)
movq %rcx, %rax
xorl %edx, %edx
divq %rsi
movq %rax, %r12
cmpq $0x1, %rdx
sbbq $-0x1, %r12
movq %r12, 0x258(%rbx)
leaq (,%r13,4), %rdi
callq 0x7030
movq 0x90(%rsp), %r15
movq 0x80(%rsp), %rbp
movq 0x70(%rsp), %r14
movq 0x60(%rsp), %rcx
movq %rax, 0x210(%rbx)
xorl %edx, %edx
cmpq %rdx, %r13
je 0x21172
movl (%rcx,%rdx,4), %esi
movl %esi, (%rax,%rdx,4)
incq %rdx
jmp 0x21162
movl 0x78(%rsp), %r13d
leaq (,%r13,4), %rdi
callq 0x7030
movq %rax, 0x220(%rbx)
xorl %ecx, %ecx
cmpq %rcx, %r13
je 0x2119e
movl (%r14,%rcx,4), %edx
movl %edx, (%rax,%rcx,4)
incq %rcx
jmp 0x2118d
movl 0x88(%rsp), %r14d
leaq (,%r14,4), %rdi
callq 0x7030
movq %rax, 0x230(%rbx)
xorl %ecx, %ecx
cmpq %rcx, %r14
je 0x211cd
movl (%rbp,%rcx,4), %edx
movl %edx, (%rax,%rcx,4)
incq %rcx
jmp 0x211bc
movl 0x98(%rsp), %r14d
leaq (,%r14,4), %rdi
callq 0x7030
movq %rax, 0x240(%rbx)
xorl %ecx, %ecx
cmpq %rcx, %r14
je 0x211fc
movl (%r15,%rcx,4), %edx
movl %edx, (%rax,%rcx,4)
incq %rcx
jmp 0x211eb
pushq $0x18
popq %rcx
movq %r12, %rax
mulq %rcx
pushq $-0x1
popq %rdi
cmovnoq %rax, %rdi
callq 0x7030
movq %rax, 0x20(%rbx)
xorl %ecx, %ecx
xorps %xmm0, %xmm0
movq 0x18(%rsp), %r14
movl %ecx, %ecx
cmpq %rcx, %r12
jbe 0x21238
imulq $0x18, %rcx, %rdx
orq $-0x1, (%rax,%rdx)
incl %ecx
movups %xmm0, 0x8(%rax,%rdx)
jmp 0x2121f
testq %r14, %r14
jne 0x21254
pushq $0x58
popq %rdi
callq 0x7370
movq %rax, %r14
movq %rax, %rdi
movl 0x8(%rsp), %esi
callq 0x209b0
movq %r14, 0x10(%rbx)
movl %r12d, %eax
xorl %edx, %edx
divl 0x10(%rsp)
movl %eax, %r14d
movl %eax, 0x268(%rbx)
movq %r14, %rax
shlq $0x4, %rax
addq $0x10, %rax
movabsq $0xffffffff0, %rdi      # imm = 0xFFFFFFFF0
andq %rax, %rdi
callq 0x7030
movq %rax, (%rbx)
addq $0x8, %rax
xorl %ecx, %ecx
cmpq %r14, %rcx
ja 0x212a6
orl $-0x1, -0x8(%rax)
orq $-0x1, (%rax)
incq %rcx
addq $0x10, %rax
jmp 0x21290
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, 0x18(%rsp)
leaq 0x1d8(%rbx), %rdi
leaq 0x1a8(%rbx), %r13
leaq 0x178(%rbx), %rbp
leaq 0x148(%rbx), %r14
leaq 0x118(%rbx), %r15
leaq 0xe8(%rbx), %r12
leaq 0xb8(%rbx), %rax
movq %rax, 0x20(%rsp)
leaq 0x88(%rbx), %rax
movq %rax, 0x8(%rsp)
leaq 0x58(%rbx), %rax
movq %rax, 0x10(%rsp)
addq $0x28, %rbx
callq 0x27180
movq %r13, %rdi
callq 0x27180
movq %rbp, %rdi
callq 0x271c8
movq %r14, %rdi
callq 0x271c8
movq %r15, %rdi
callq 0x27180
movq %r12, %rdi
callq 0x11eea
movq 0x20(%rsp), %rdi
callq 0x27180
movq 0x8(%rsp), %rdi
callq 0x27210
movq 0x10(%rsp), %rdi
callq 0x271c8
movq %rbx, %rdi
callq 0x271c8
movq 0x18(%rsp), %rdi
callq 0x75d0