// File: /workspace/github_c_makefile_star2_O0/krinkinmu[P]64bit/memory.c
// Function: setup_memory
void setup_memory(void)
{
	for (int i = 0; i != memory_map_size; ++i) {
		const struct mmap_entry *entry = memory_map + i;

		balloc_add_region(entry->addr, entry->length);
		printf("memory range: %#llx-%#llx type %lu\n",
			entry->addr, entry->addr + entry->length - 1,
			entry->type);
	}

	extern char text_phys_begin[];
	extern char bss_phys_end[];
	const phys_t kernel_begin = (phys_t)text_phys_begin;
	const phys_t kernel_end = (phys_t)bss_phys_end;

	balloc_add_region(kernel_begin, kernel_end - kernel_begin);
	balloc_add_region(initrd_begin, initrd_end - initrd_begin);

	for (int i = 0; i != memory_map_size; ++i) {
		const struct mmap_entry *entry = memory_map + i;

		if (entry->type != MMAP_AVAILABLE)
			balloc_reserve_region(entry->addr, entry->length);
	}

	printf("reserve memory range: %#llx-%#llx for kernel\n",
			(unsigned long long) kernel_begin,
			(unsigned long long) kernel_end - 1);
	balloc_reserve_region(kernel_begin, kernel_end - kernel_begin);

	printf("reserve memory range: %#llx-%#llx for initrd\n",
			(unsigned long long) initrd_begin,
			(unsigned long long) initrd_end - 1);
	balloc_reserve_region(initrd_begin, initrd_end - initrd_begin);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
movq $-0x7fbb9bc0, %rcx      # imm = 0x80446440
cmpl (%rcx), %eax
je 0xffffffff801039f2
movslq -0x4(%rbp), %rcx
movq $-0x7fbb9da0, %rax      # imm = 0x80446260
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0xffffffff80102f90
movq -0x10(%rbp), %rax
movq (%rax), %rsi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
movq -0x10(%rbp), %rax
addq 0x8(%rax), %rdx
subq $0x1, %rdx
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rcx
leaq 0xe886(%rip), %rdi      # 0xffffffff80112266
movb $0x0, %al
callq 0xffffffff80101bc0
movl -0x4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4(%rbp)
jmp 0xffffffff8010397f
movq $0x100158, %rax         # imm = 0x100158
movq %rax, -0x18(%rbp)
movq $0x446588, %rax         # imm = 0x446588
movq %rax, -0x20(%rbp)
movq $0x100158, %rdi         # imm = 0x100158
movq $0x446588, %rsi         # imm = 0x446588
subq %rdi, %rsi
callq 0xffffffff80102f90
movq $-0x7fbb9bb8, %rax      # imm = 0x80446448
movq (%rax), %rdi
movq $-0x7fbb9bb0, %rax      # imm = 0x80446450
movq (%rax), %rsi
movq $-0x7fbb9bb8, %rax      # imm = 0x80446448
subq (%rax), %rsi
callq 0xffffffff80102f90
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq $-0x7fbb9bc0, %rcx      # imm = 0x80446440
cmpl (%rcx), %eax
je 0xffffffff80103a98
movslq -0x24(%rbp), %rcx
movq $-0x7fbb9da0, %rax      # imm = 0x80446260
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq $0x1, 0x10(%rax)
je 0xffffffff80103a8b
movq -0x30(%rbp), %rax
movq (%rax), %rdi
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0xffffffff80103140
jmp 0xffffffff80103a8d
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0xffffffff80103a48
leaq 0xe7eb(%rip), %rdi      # 0xffffffff8011228a
movq $0x100158, %rsi         # imm = 0x100158
movq $0x446588, %rdx         # imm = 0x446588
subq $0x1, %rdx
movb $0x0, %al
callq 0xffffffff80101bc0
movq $0x100158, %rdi         # imm = 0x100158
movq $0x446588, %rsi         # imm = 0x446588
subq %rdi, %rsi
callq 0xffffffff80103140
movq $-0x7fbb9bb8, %rax      # imm = 0x80446448
movq (%rax), %rsi
movq $-0x7fbb9bb0, %rax      # imm = 0x80446450
movq (%rax), %rdx
subq $0x1, %rdx
leaq 0xe7cb(%rip), %rdi      # 0xffffffff801122b8
movb $0x0, %al
callq 0xffffffff80101bc0
movq $-0x7fbb9bb8, %rax      # imm = 0x80446448
movq (%rax), %rdi
movq $-0x7fbb9bb0, %rax      # imm = 0x80446450
movq (%rax), %rsi
movq $-0x7fbb9bb8, %rax      # imm = 0x80446448
subq (%rax), %rsi
callq 0xffffffff80103140
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)