// File: /workspace/github_cpp_makefile_star2_O3/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 0x11552(%rip), %rdi     # 0x15300
movl $0x5, %esi
callq 0x6d8a
movq 0x11541(%rip), %rdi     # 0x15300
movl $0x0, 0x2c(%rdi)
movb $-0x18, 0x20(%rdi)
movq 0x8(%rdi), %rdx
leaq 0xb4c3(%rip), %rcx      # 0xf298
xorl %ebp, %ebp
movl $0x5, %r8d
xorl %esi, %esi
callq 0x2360
movq 0x11515(%rip), %rax     # 0x15300
leaq 0x68(%rax), %rdi
movl $0x1, 0x94(%rax)
movb $0x40, 0x88(%rax)
movq 0x70(%rax), %rdx
leaq 0xb493(%rip), %rcx      # 0xf29e
movl $0x4, %r8d
xorl %esi, %esi
callq 0x2360
movq 0x114e1(%rip), %rax     # 0x15300
leaq 0xd0(%rax), %rdi
movl $0x2, 0xfc(%rax)
movb $-0x40, %bl
movb %bl, 0xf0(%rax)
movq 0xd8(%rax), %rdx
leaq 0xb45d(%rip), %rcx      # 0xf2a3
movl $0x5, %r8d
xorl %esi, %esi
callq 0x2360
movq 0x114a6(%rip), %rax     # 0x15300
leaq 0x138(%rax), %rdi
movl $0x3, 0x164(%rax)
movb %bl, 0x158(%rax)
movq 0x140(%rax), %rdx
leaq 0xb425(%rip), %rcx      # 0xf2a4
movl $0x4, %r8d
xorl %esi, %esi
callq 0x2360
movq 0x1146d(%rip), %rax     # 0x15300
leaq 0x1a0(%rax), %rdi
movl $0x4, 0x1cc(%rax)
movb $-0x38, 0x1c0(%rax)
movq 0x1a8(%rax), %rdx
leaq 0xb3f0(%rip), %rcx      # 0xf2a9
movl $0x5, %r8d
xorl %esi, %esi
callq 0x2360
movb 0x11614(%rip), %al      # 0x154e0
testb %al, %al
je 0x3ff5
movl $0x1, %r12d
movl $0x30, %ebx
leaq 0x8(%rsp), %r14
leaq 0x11465(%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 0x1147d(%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 0x113ce(%rip), %rdi     # 0x15318
movq %r14, %rsi
leaq 0x4(%rsp), %rdx
callq 0x9a1c
movq %r13, %rdi
movq %r14, %rsi
callq 0x5f6a
leaq 0x11437(%rip), %rax     # 0x153a0
leaq (%r15,%rax), %rsi
addq $0x20, %rsi
movq %r14, %rdi
callq 0x2160
movl %r12d, 0x30(%rsp)
movw $0x0, 0x28(%rsp)
movq 0x11374(%rip), %rax     # 0x15300
movl %r12d, (%rax,%rbx,2)
leaq 0x11381(%rip), %rdi     # 0x15318
movq %r14, %rsi
leaq 0x30(%rsp), %rdx
callq 0x82ca
movq %r13, %rdi
movq %r14, %rsi
callq 0x5f6a
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x3fcb
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2260
incl %ebp
addq $0x40, %r15
addl $0x2, %r12d
addq $0x34, %rbx
cmpq $0x140, %r15            # imm = 0x140
jne 0x3eee
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x114e4(%rip), %rdi     # 0x154e0
callq 0x23f0
testl %eax, %eax
je 0x3ed4
leaq 0x113a0(%rip), %rax     # 0x153b0
movq %rax, 0x11389(%rip)     # 0x153a0
leaq 0x11382(%rip), %rbx     # 0x153a0
leaq 0xb28a(%rip), %rsi      # 0xf2af
leaq 0xb28d(%rip), %rdx      # 0xf2b9
movq %rbx, %rdi
callq 0x7dd6
leaq 0x11395(%rip), %rax     # 0x153d0
movq %rax, 0x1137e(%rip)     # 0x153c0
leaq 0x11377(%rip), %r14     # 0x153c0
leaq 0xb26a(%rip), %rsi      # 0xf2ba
leaq 0xb26d(%rip), %rdx      # 0xf2c4
movq %r14, %rdi
callq 0x7dd6
leaq 0x1138a(%rip), %rax     # 0x153f0
movq %rax, 0x11373(%rip)     # 0x153e0
leaq 0x1136c(%rip), %r14     # 0x153e0
leaq 0xb24a(%rip), %rsi      # 0xf2c5
leaq 0xb24c(%rip), %rdx      # 0xf2ce
movq %r14, %rdi
callq 0x7dd6
leaq 0x1137f(%rip), %rax     # 0x15410
movq %rax, 0x11368(%rip)     # 0x15400
leaq 0x11361(%rip), %r14     # 0x15400
leaq 0xb229(%rip), %rsi      # 0xf2cf
leaq 0xb22b(%rip), %rdx      # 0xf2d8
movq %r14, %rdi
callq 0x7dd6
leaq 0x11374(%rip), %rax     # 0x15430
movq %rax, 0x1135d(%rip)     # 0x15420
leaq 0x11356(%rip), %r14     # 0x15420
leaq 0xb208(%rip), %rsi      # 0xf2d9
leaq 0xb20b(%rip), %rdx      # 0xf2e3
movq %r14, %rdi
callq 0x7dd6
leaq 0x11369(%rip), %rax     # 0x15450
movq %rax, 0x11352(%rip)     # 0x15440
leaq 0x1134b(%rip), %r14     # 0x15440
leaq 0xb1e8(%rip), %rsi      # 0xf2e4
leaq 0xb1eb(%rip), %rdx      # 0xf2ee
movq %r14, %rdi
callq 0x7dd6
leaq 0x1135e(%rip), %rax     # 0x15470
movq %rax, 0x11347(%rip)     # 0x15460
leaq 0x11340(%rip), %r14     # 0x15460
leaq 0xb1c8(%rip), %rsi      # 0xf2ef
leaq 0xb1ca(%rip), %rdx      # 0xf2f8
movq %r14, %rdi
callq 0x7dd6
leaq 0x11353(%rip), %rax     # 0x15490
movq %rax, 0x1133c(%rip)     # 0x15480
leaq 0x11335(%rip), %r14     # 0x15480
leaq 0xb1a7(%rip), %rsi      # 0xf2f9
leaq 0xb1a9(%rip), %rdx      # 0xf302
movq %r14, %rdi
callq 0x7dd6
leaq 0x11348(%rip), %rax     # 0x154b0
movq %rax, 0x11331(%rip)     # 0x154a0
leaq 0x1132a(%rip), %r14     # 0x154a0
leaq 0xb186(%rip), %rsi      # 0xf303
leaq 0xb189(%rip), %rdx      # 0xf30d
movq %r14, %rdi
callq 0x7dd6
leaq 0x1133d(%rip), %rax     # 0x154d0
movq %rax, 0x11326(%rip)     # 0x154c0
leaq 0x1131f(%rip), %r14     # 0x154c0
leaq 0xb166(%rip), %rsi      # 0xf30e
leaq 0xb169(%rip), %rdx      # 0xf318
movq %r14, %rdi
callq 0x7dd6
leaq -0x1ac1(%rip), %rdi     # 0x26fd
leaq 0x1107b(%rip), %rdx     # 0x15240
xorl %esi, %esi
callq 0x2230
leaq 0x1130d(%rip), %rdi     # 0x154e0
callq 0x21b0
jmp 0x3ed4
jmp 0x41ed
jmp 0x41ed
jmp 0x41ed
jmp 0x41ed
jmp 0x41ed
jmp 0x41ed
jmp 0x41ed
jmp 0x41ed
movq %rax, %r15
addq $-0x10, %r14
movq -0x10(%r14), %rdi
cmpq %rdi, %r14
je 0x4208
movq (%r14), %rsi
incq %rsi
callq 0x2260
leaq -0x20(%r14), %rax
addq $-0x10, %r14
cmpq %rbx, %r14
movq %rax, %r14
jne 0x41f4
leaq 0x112c1(%rip), %rdi     # 0x154e0
callq 0x21a0
jmp 0x424c
movq %rax, %r15
jmp 0x4218
jmp 0x422d
movq %rax, %r15
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x424c
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2260
movq %r15, %rdi
callq 0x23c0