// File: /workspace/github_cpp_makefile_star2_O1/ksherlock[P]wdc-utils/link.cpp
// Function: init()
void init() {

	sections.resize(5);

	sections[SECT_PAGE0].number = SECT_PAGE0;
	sections[SECT_PAGE0].flags = SEC_DATA | SEC_NONAME | SEC_DIRECT | SEC_REF_ONLY;
	sections[SECT_PAGE0].name = "page0";

	sections[SECT_CODE].number = SECT_CODE;
	sections[SECT_CODE].flags = SEC_NONAME;
	sections[SECT_CODE].name = "code"; 

	sections[SECT_KDATA].number = SECT_KDATA;
	sections[SECT_KDATA].flags = SEC_DATA | SEC_NONAME;
	sections[SECT_KDATA].name = "kdata"; 

	sections[SECT_DATA].number = SECT_DATA;
	sections[SECT_DATA].flags = SEC_DATA | SEC_NONAME;
	sections[SECT_DATA].name = "data"; 

	sections[SECT_UDATA].number = SECT_UDATA;
	sections[SECT_UDATA].flags = SEC_DATA | SEC_NONAME | SEC_REF_ONLY;
	sections[SECT_UDATA].name = "udata"; 

	/*
	 * For each section, [the linker] creates three symbols, 
	 * _ROM_BEG_secname, _BEG_secname and _END_secname, which
	 * correspond to the rom location and the execution beginning
	 * and end of the section. These will be used more in the next
	 * two sections of code.
	 */

	// n.b - only for pre-defined sections [?], skip the _ROM_BEG_* symbols...

	static std::string names[] = {
			"_BEG_PAGE0", "_END_PAGE0",
			"_BEG_CODE", "_END_CODE",
			"_BEG_KDATA", "_END_KDATA",
			"_BEG_DATA", "_END_DATA",
			"_BEG_UDATA", "_END_UDATA",
	};

	for (int i = 0; i < 5; ++i) {

		// begin is 0.
		symbol s;
		s.name = names[i * 2];
		s.section = i;
		s.type = S_REL;
		s.flags = SF_DEF | SF_GBL;
		symbol_map.emplace(s.name, i * 2);
		symbols.emplace_back(s);

		// end is undefined...
		s.name = names[i * 2 + 1];
		s.section = i * 2 + 1; // symbol number.
		s.type = S_UND;
		s.flags = 0;

		sections[i].end_symbol = s.section;

		symbol_map.emplace(s.name, s.section);
		symbols.emplace_back(s);

		// even though it's undefined, don't add it to the undefined list ...
		// don't need to search libraries for it!
	}

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
leaq 0x1156f(%rip), %rdi     # 0x15300
movl $0x5, %esi
callq 0x6e3e
movq 0x1155e(%rip), %rdi     # 0x15300
movl $0x0, 0x2c(%rdi)
movb $-0x18, 0x20(%rdi)
movq 0x8(%rdi), %rdx
leaq 0xb4e0(%rip), %rcx      # 0xf298
xorl %ebp, %ebp
movl $0x5, %r8d
xorl %esi, %esi
callq 0x2360
movq 0x11532(%rip), %rax     # 0x15300
leaq 0x68(%rax), %rdi
movl $0x1, 0x94(%rax)
movb $0x40, 0x88(%rax)
movq 0x70(%rax), %rdx
leaq 0xb4b0(%rip), %rcx      # 0xf29e
movl $0x4, %r8d
xorl %esi, %esi
callq 0x2360
movq 0x114fe(%rip), %rax     # 0x15300
leaq 0xd0(%rax), %rdi
movl $0x2, 0xfc(%rax)
movb $-0x40, %bl
movb %bl, 0xf0(%rax)
movq 0xd8(%rax), %rdx
leaq 0xb47a(%rip), %rcx      # 0xf2a3
movl $0x5, %r8d
xorl %esi, %esi
callq 0x2360
movq 0x114c3(%rip), %rax     # 0x15300
leaq 0x138(%rax), %rdi
movl $0x3, 0x164(%rax)
movb %bl, 0x158(%rax)
movq 0x140(%rax), %rdx
leaq 0xb442(%rip), %rcx      # 0xf2a4
movl $0x4, %r8d
xorl %esi, %esi
callq 0x2360
movq 0x1148a(%rip), %rax     # 0x15300
leaq 0x1a0(%rax), %rdi
movl $0x4, 0x1cc(%rax)
movb $-0x38, 0x1c0(%rax)
movq 0x1a8(%rax), %rdx
leaq 0xb40d(%rip), %rcx      # 0xf2a9
movl $0x5, %r8d
xorl %esi, %esi
callq 0x2360
movb 0x11631(%rip), %al      # 0x154e0
testb %al, %al
je 0x3fd8
movl $0x1, %r12d
movl $0x30, %ebx
leaq 0x8(%rsp), %r14
leaq 0x11482(%rip), %r13     # 0x15350
xorl %r15d, %r15d
leaq 0x18(%rsp), %rax
movq %rax, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
movb $0x0, 0x18(%rsp)
movw $0x0, 0x28(%rsp)
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
movq %rax, 0x2c(%rsp)
leaq 0x1149a(%rip), %rax     # 0x153a0
leaq (%rax,%r15), %rsi
movq %r14, %rdi
callq 0x2160
movl %ebp, 0x30(%rsp)
movw $0x302, 0x28(%rsp)      # imm = 0x302
leal -0x1(%r12), %eax
movl %eax, 0x4(%rsp)
leaq 0x113eb(%rip), %rdi     # 0x15318
movq %r14, %rsi
leaq 0x4(%rsp), %rdx
callq 0x9b2e
movq %r13, %rdi
movq %r14, %rsi
callq 0x5fe6
leaq 0x11454(%rip), %rax     # 0x153a0
leaq (%r15,%rax), %rsi
addq $0x20, %rsi
movq %r14, %rdi
callq 0x2160
movl %r12d, 0x30(%rsp)
movw $0x0, 0x28(%rsp)
movq 0x11391(%rip), %rax     # 0x15300
movl %r12d, (%rax,%rbx,2)
leaq 0x1139e(%rip), %rdi     # 0x15318
movq %r14, %rsi
leaq 0x30(%rsp), %rdx
callq 0x837a
movq %r13, %rdi
movq %r14, %rsi
callq 0x5fe6
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x3fae
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2260
incl %ebp
addl $0x2, %r12d
addq $0x40, %r15
addq $0x34, %rbx
cmpq $0x140, %r15            # imm = 0x140
jne 0x3ed1
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x11501(%rip), %rdi     # 0x154e0
callq 0x23f0
testl %eax, %eax
je 0x3eb7
leaq 0x113bd(%rip), %rax     # 0x153b0
movq %rax, 0x113a6(%rip)     # 0x153a0
leaq 0x1139f(%rip), %rbx     # 0x153a0
leaq 0xb2a7(%rip), %rsi      # 0xf2af
leaq 0xb2aa(%rip), %rdx      # 0xf2b9
movq %rbx, %rdi
callq 0x7e88
leaq 0x113b2(%rip), %rax     # 0x153d0
movq %rax, 0x1139b(%rip)     # 0x153c0
leaq 0x11394(%rip), %rbx     # 0x153c0
leaq 0xb287(%rip), %rsi      # 0xf2ba
leaq 0xb28a(%rip), %rdx      # 0xf2c4
movq %rbx, %rdi
callq 0x7e88
leaq 0x113a7(%rip), %rax     # 0x153f0
movq %rax, 0x11390(%rip)     # 0x153e0
leaq 0x11389(%rip), %rbx     # 0x153e0
leaq 0xb267(%rip), %rsi      # 0xf2c5
leaq 0xb269(%rip), %rdx      # 0xf2ce
movq %rbx, %rdi
callq 0x7e88
leaq 0x1139c(%rip), %rax     # 0x15410
movq %rax, 0x11385(%rip)     # 0x15400
leaq 0x1137e(%rip), %rbx     # 0x15400
leaq 0xb246(%rip), %rsi      # 0xf2cf
leaq 0xb248(%rip), %rdx      # 0xf2d8
movq %rbx, %rdi
callq 0x7e88
leaq 0x11391(%rip), %rax     # 0x15430
movq %rax, 0x1137a(%rip)     # 0x15420
leaq 0x11373(%rip), %rbx     # 0x15420
leaq 0xb225(%rip), %rsi      # 0xf2d9
leaq 0xb228(%rip), %rdx      # 0xf2e3
movq %rbx, %rdi
callq 0x7e88
leaq 0x11386(%rip), %rax     # 0x15450
movq %rax, 0x1136f(%rip)     # 0x15440
leaq 0x11368(%rip), %rbx     # 0x15440
leaq 0xb205(%rip), %rsi      # 0xf2e4
leaq 0xb208(%rip), %rdx      # 0xf2ee
movq %rbx, %rdi
callq 0x7e88
leaq 0x1137b(%rip), %rax     # 0x15470
movq %rax, 0x11364(%rip)     # 0x15460
leaq 0x1135d(%rip), %rbx     # 0x15460
leaq 0xb1e5(%rip), %rsi      # 0xf2ef
leaq 0xb1e7(%rip), %rdx      # 0xf2f8
movq %rbx, %rdi
callq 0x7e88
leaq 0x11370(%rip), %rax     # 0x15490
movq %rax, 0x11359(%rip)     # 0x15480
leaq 0x11352(%rip), %rbx     # 0x15480
leaq 0xb1c4(%rip), %rsi      # 0xf2f9
leaq 0xb1c6(%rip), %rdx      # 0xf302
movq %rbx, %rdi
callq 0x7e88
leaq 0x11365(%rip), %rax     # 0x154b0
movq %rax, 0x1134e(%rip)     # 0x154a0
leaq 0x11347(%rip), %rbx     # 0x154a0
leaq 0xb1a3(%rip), %rsi      # 0xf303
leaq 0xb1a6(%rip), %rdx      # 0xf30d
movq %rbx, %rdi
callq 0x7e88
leaq 0x1135a(%rip), %rax     # 0x154d0
movq %rax, 0x11343(%rip)     # 0x154c0
leaq 0x1133c(%rip), %rbx     # 0x154c0
leaq 0xb183(%rip), %rsi      # 0xf30e
leaq 0xb186(%rip), %rdx      # 0xf318
movq %rbx, %rdi
callq 0x7e88
leaq -0x1ac4(%rip), %rdi     # 0x26dd
leaq 0x11098(%rip), %rdx     # 0x15240
xorl %esi, %esi
callq 0x2230
leaq 0x1132a(%rip), %rdi     # 0x154e0
callq 0x21b0
jmp 0x3eb7
jmp 0x41d0
jmp 0x41d0
jmp 0x41d0
jmp 0x41d0
jmp 0x41d0
jmp 0x41d0
jmp 0x41d0
jmp 0x41d0
movq %rax, %r14
xorl %eax, %eax
testb %al, %al
jne 0x4208
addq $-0x10, %rbx
leaq 0x111bc(%rip), %r15     # 0x153a0
movq -0x10(%rbx), %rdi
cmpq %rdi, %rbx
je 0x41f8
movq (%rbx), %rsi
incq %rsi
callq 0x2260
leaq -0x20(%rbx), %rax
addq $-0x10, %rbx
cmpq %r15, %rbx
movq %rax, %rbx
jne 0x41e4
leaq 0x112d1(%rip), %rdi     # 0x154e0
callq 0x21a0
jmp 0x423e
movq %rax, %r14
movb $0x1, %al
jmp 0x41d5
jmp 0x421f
movq %rax, %r14
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x423e
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2260
movq %r14, %rdi
callq 0x23c0