// File: /workspace/github_cpp_makefile_star2_O2/merelin[P]mediasmartserverd/src/led_control_sch5127_base.h
// Function: LedControlSCH5127Base::initSch5127_()
bool initSch5127_( ) {
		enum {
			IDX_LDN			= 0x07,	///< Logical Device Number
			IDX_ID			= 0x20,	///< device identification
			IDX_BASE_MSB	= 0x60,	///< base address MSB register
			IDX_BASE_LSB	= 0x61,	///< base address LSB register
			IDX_ENTER		= 0x55,	///< enter configuration mode
			IDX_EXIT		= 0xaa,	///< exit configuration mode
		};
		
		// try LPC SIO @ 0x2e
		unsigned int sio_addr = 0x2e;
		unsigned int sio_data = sio_addr + 1;
		if ( ioperm(sio_addr, 1, 1) ) throw ErrnoException("ioperm");
		if ( ioperm(sio_data, 1, 1) ) throw ErrnoException("ioperm");
		
		// enter configuration mode
		outb( IDX_ENTER, sio_addr );
		
		// retrieve identification
		outb( IDX_ID, sio_addr );
		const unsigned int device_id = inb( sio_data );
		if ( debug ) std::cout << Desc() << ": Device 0x" << std::hex << device_id << std::dec << "\n";
		
		// 
		{
			outb( 0x26, sio_addr );
			const unsigned int in = inb( sio_data );
			if ( 0x4e == in ) {
				outb( IDX_EXIT, sio_addr );
				
				// finished with these ports
				ioperm( sio_addr, 1, 0 );
				ioperm( sio_data, 1, 0 );
				
				// and switch to these if we are told to
				if ( debug ) std::cout << Desc() << ": Using 0x4e\n";
				sio_addr = 0x4e;
				sio_data = sio_addr + 1;
				
				if ( ioperm(sio_addr, 1, 1) ) throw ErrnoException("ioperm");
		        if ( ioperm(sio_data, 1, 1) ) throw ErrnoException("ioperm");
				
				outb( IDX_ENTER, sio_addr );
			}
		}
		
		// select logical device 0x0a (base address?)
		outb( IDX_LDN, sio_addr );
		outb( 0x0a, sio_data );
		
		// get base address of runtime registers
		outb( IDX_BASE_MSB, sio_addr );
		const unsigned int index_msb = inb( sio_data );
		outb( IDX_BASE_LSB, sio_addr );
		const unsigned int index_lsb = inb( sio_data );
		
		io_sch5127_regs_ = index_msb << 8 | index_lsb;
		
		// exit configuration
		outb( IDX_EXIT, sio_addr );
		
		// finished with SuperI/O ports
		ioperm(sio_data, 1, 0);
		ioperm(sio_addr, 1, 0);
		
		return true;
	}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x30, %rsp
movq %rdi, %rbx
pushq $0x2e
popq %rdi
pushq $0x1
popq %rsi
pushq $0x1
popq %rdx
callq 0x44e0
testl %eax, %eax
jne 0x7e02
pushq $0x2f
popq %rdi
pushq $0x1
popq %rsi
pushq $0x1
popq %rdx
callq 0x44e0
testl %eax, %eax
jne 0x7e57
movb $0x55, %al
outb %al, $0x2e
movb $0x20, %al
outb %al, $0x2e
inb $0x2f, %al
cmpl $0x0, 0x86be(%rip)      # 0x10360
je 0x7d12
movl %eax, %ebp
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
movq 0x82fa(%rip), %rdi      # 0xffb0
movq %rax, %rsi
callq 0x42d0
leaq 0x2e64(%rip), %rsi      # 0xab29
movq %rax, %rdi
callq 0x42d0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x8, %edx
movl %edx, 0x18(%rax,%rcx)
movzbl %bpl, %esi
movq %rax, %rdi
callq 0x41e0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x2, %edx
movl %edx, 0x18(%rax,%rcx)
leaq 0x29e9(%rip), %rsi      # 0xa6f3
movq %rax, %rdi
callq 0x42d0
movb $0x26, %al
outb %al, $0x2e
inb $0x2f, %al
cmpb $0x4e, %al
jne 0x7da9
movb $-0x56, %al
outb %al, $0x2e
pushq $0x2e
popq %rdi
pushq $0x1
popq %r14
movq %r14, %rsi
xorl %edx, %edx
callq 0x44e0
pushq $0x2f
popq %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x44e0
cmpl $0x0, 0x8617(%rip)      # 0x10360
je 0x7d72
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
movq 0x8255(%rip), %rdi      # 0xffb0
movq %rax, %rsi
callq 0x42d0
leaq 0x2dcb(%rip), %rsi      # 0xab35
movq %rax, %rdi
callq 0x42d0
pushq $0x4e
popq %rdi
pushq $0x1
popq %rsi
pushq $0x1
popq %rdx
callq 0x44e0
testl %eax, %eax
jne 0x7eac
pushq $0x4f
popq %rdi
pushq $0x1
popq %rsi
pushq $0x1
popq %rdx
callq 0x44e0
testl %eax, %eax
jne 0x7efe
movb $0x55, %al
outb %al, $0x4e
pushq $0x4e
popq %rbp
pushq $0x4f
jmp 0x7dae
pushq $0x2e
popq %rbp
pushq $0x2f
popq %rcx
movb $0x7, %al
movl %ebp, %edx
outb %al, %dx
movb $0xa, %al
movl %ecx, %edx
outb %al, %dx
movb $0x60, %al
movl %ebp, %edx
outb %al, %dx
movl %ecx, %edx
inb %dx, %al
movzbl %al, %esi
movb $0x61, %al
movl %ebp, %edx
outb %al, %dx
movl %ecx, %edx
inb %dx, %al
movzbl %al, %eax
shll $0x8, %esi
orl %eax, %esi
movl %esi, 0xc(%rbx)
movb $-0x56, %al
movl %ebp, %edx
outb %al, %dx
movl %ecx, %edi
pushq $0x1
popq %rbx
movq %rbx, %rsi
xorl %edx, %edx
callq 0x44e0
movl %ebp, %edi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x44e0
movb $0x1, %al
addq $0x30, %rsp
popq %rbx
popq %r14
popq %rbp
retq
pushq $0x10
popq %rdi
callq 0x4160
movq %rax, %rbx
leaq 0x2cf6(%rip), %rsi      # 0xab0a
leaq 0x10(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x5694
callq 0x4030
movl (%rax), %edx
movb $0x1, %bpl
leaq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0x56d0
xorl %ebp, %ebp
leaq 0x789d(%rip), %rsi      # 0xf6e0
movq 0x8156(%rip), %rdx      # 0xffa0
movq %rbx, %rdi
callq 0x4530
jmp 0x7f4e
pushq $0x10
popq %rdi
callq 0x4160
movq %rax, %rbx
leaq 0x2ca1(%rip), %rsi      # 0xab0a
leaq 0x10(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x5694
callq 0x4030
movl (%rax), %edx
movb $0x1, %bpl
leaq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0x56d0
xorl %ebp, %ebp
leaq 0x7848(%rip), %rsi      # 0xf6e0
movq 0x8101(%rip), %rdx      # 0xffa0
movq %rbx, %rdi
callq 0x4530
jmp 0x7f4e
pushq $0x10
popq %rdi
callq 0x4160
movq %rax, %rbx
leaq 0x2c4c(%rip), %rsi      # 0xab0a
leaq 0x10(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x5694
callq 0x4030
movl (%rax), %edx
movb $0x1, %bpl
leaq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0x56d0
xorl %ebp, %ebp
leaq 0x77f3(%rip), %rsi      # 0xf6e0
movq 0x80ac(%rip), %rdx      # 0xffa0
movq %rbx, %rdi
callq 0x4530
jmp 0x7f4e
pushq $0x10
popq %rdi
callq 0x4160
movq %rax, %rbx
leaq 0x2bfa(%rip), %rsi      # 0xab0a
leaq 0x10(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x5694
callq 0x4030
movl (%rax), %edx
movb $0x1, %bpl
leaq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0x56d0
xorl %ebp, %ebp
leaq 0x77a1(%rip), %rsi      # 0xf6e0
movq 0x805a(%rip), %rdx      # 0xffa0
movq %rbx, %rdi
callq 0x4530
jmp 0x7f5a
jmp 0x7f6e
jmp 0x7f5a
jmp 0x7f6e
jmp 0x7f5a
jmp 0x7f6e
movq %rax, %r14
leaq 0x10(%rsp), %rdi
callq 0x4150
testb %bpl, %bpl
jne 0x7f71
jmp 0x7f79
movq %rax, %r14
movq %rbx, %rdi
callq 0x4220
movq %r14, %rdi
callq 0x4550
nop