// File: 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
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xd8(%rbp)
movl $0x2e, -0xc(%rbp)
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
movl -0xc(%rbp), %eax
movl %eax, %edi
movl $0x1, %esi
movl $0x1, %edx
callq 0x5620
cmpl $0x0, %eax
je 0xcae6
movb $0x1, -0x45(%rbp)
movl $0x10, %edi
callq 0x51b0
movq %rax, -0xe8(%rbp)
leaq -0x31(%rbp), %rdi
movq %rdi, -0xe0(%rbp)
callq 0x56c0
movq -0xe0(%rbp), %rdx
leaq 0x618c(%rip), %rsi      # 0x12be6
leaq -0x30(%rbp), %rdi
callq 0x7600
jmp 0xca65
callq 0x5030
movq -0xe8(%rbp), %rdi
movl (%rax), %edx
leaq -0x30(%rbp), %rsi
callq 0x76b0
jmp 0xca7e
movq -0xe8(%rbp), %rdi
movb $0x0, -0x45(%rbp)
leaq 0xab70(%rip), %rsi      # 0x17600
leaq -0x5317(%rip), %rdx     # 0x7780
callq 0x5680
jmp 0xcfc7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0xcac4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x5230
leaq -0x31(%rbp), %rdi
callq 0x53f0
testb $0x1, -0x45(%rbp)
jne 0xcad5
jmp 0xcae1
movq -0xe8(%rbp), %rdi
callq 0x52a0
jmp 0xcfbe
movl -0x10(%rbp), %eax
movl %eax, %edi
movl $0x1, %esi
movl $0x1, %edx
callq 0x5620
cmpl $0x0, %eax
je 0xcbc2
movb $0x1, -0x6a(%rbp)
movl $0x10, %edi
callq 0x51b0
movq %rax, -0xf8(%rbp)
leaq -0x69(%rbp), %rdi
movq %rdi, -0xf0(%rbp)
callq 0x56c0
movq -0xf0(%rbp), %rdx
leaq 0x60b0(%rip), %rsi      # 0x12be6
leaq -0x68(%rbp), %rdi
callq 0x7600
jmp 0xcb41
callq 0x5030
movq -0xf8(%rbp), %rdi
movl (%rax), %edx
leaq -0x68(%rbp), %rsi
callq 0x76b0
jmp 0xcb5a
movq -0xf8(%rbp), %rdi
movb $0x0, -0x6a(%rbp)
leaq 0xaa94(%rip), %rsi      # 0x17600
leaq -0x53f3(%rip), %rdx     # 0x7780
callq 0x5680
jmp 0xcfc7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0xcba0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x5230
leaq -0x69(%rbp), %rdi
callq 0x53f0
testb $0x1, -0x6a(%rbp)
jne 0xcbb1
jmp 0xcbbd
movq -0xf8(%rbp), %rdi
callq 0x52a0
jmp 0xcfbe
movl -0xc(%rbp), %eax
movl $0x55, %edi
movzwl %ax, %esi
callq 0xb0b0
movl -0xc(%rbp), %eax
movl $0x20, %edi
movzwl %ax, %esi
callq 0xb0b0
movl -0x10(%rbp), %eax
movzwl %ax, %edi
callq 0xb0d0
movzbl %al, %eax
movl %eax, -0x70(%rbp)
cmpl $0x0, 0xb81e(%rip)      # 0x18418
je 0xcc5f
movq -0xd8(%rbp), %rdi
movq (%rdi), %rax
callq *0x10(%rax)
movq %rax, %rsi
movq 0xb39d(%rip), %rdi      # 0x17fb0
callq 0x5380
movq %rax, %rdi
leaq 0x5fe3(%rip), %rsi      # 0x12c05
callq 0x5380
movq %rax, %rdi
leaq 0x52f(%rip), %rsi       # 0xd160
callq 0x5110
movq %rax, %rdi
movl -0x70(%rbp), %esi
callq 0x5530
movq %rax, %rdi
leaq 0x545(%rip), %rsi       # 0xd190
callq 0x5110
movq %rax, %rdi
leaq 0x5b75(%rip), %rsi      # 0x127cf
callq 0x5380
movl -0xc(%rbp), %eax
movl $0x26, %edi
movzwl %ax, %esi
callq 0xb0b0
movl -0x10(%rbp), %eax
movzwl %ax, %edi
callq 0xb0d0
movzbl %al, %eax
movl %eax, -0x74(%rbp)
movl $0x4e, %eax
cmpl -0x74(%rbp), %eax
jne 0xcefc
movl -0xc(%rbp), %eax
movl $0xaa, %edi
movzwl %ax, %esi
callq 0xb0b0
movl -0xc(%rbp), %eax
movl %eax, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x5620
movl -0x10(%rbp), %eax
movl %eax, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x5620
cmpl $0x0, 0xb751(%rip)      # 0x18418
je 0xccf4
movq -0xd8(%rbp), %rdi
movq (%rdi), %rax
callq *0x10(%rax)
movq %rax, %rsi
movq 0xb2d0(%rip), %rdi      # 0x17fb0
callq 0x5380
movq %rax, %rdi
leaq 0x5f22(%rip), %rsi      # 0x12c11
callq 0x5380
movl $0x4e, -0xc(%rbp)
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
movl -0xc(%rbp), %eax
movl %eax, %edi
movl $0x1, %esi
movl $0x1, %edx
callq 0x5620
cmpl $0x0, %eax
je 0xcdf8
movb $0x1, -0x9a(%rbp)
movl $0x10, %edi
callq 0x51b0
movq %rax, -0x108(%rbp)
leaq -0x99(%rbp), %rdi
movq %rdi, -0x100(%rbp)
callq 0x56c0
movq -0x100(%rbp), %rdx
leaq 0x5e8c(%rip), %rsi      # 0x12be6
leaq -0x98(%rbp), %rdi
callq 0x7600
jmp 0xcd68
callq 0x5030
movq -0x108(%rbp), %rdi
movl (%rax), %edx
leaq -0x98(%rbp), %rsi
callq 0x76b0
jmp 0xcd84
movq -0x108(%rbp), %rdi
movb $0x0, -0x9a(%rbp)
leaq 0xa867(%rip), %rsi      # 0x17600
leaq -0x5620(%rip), %rdx     # 0x7780
callq 0x5680
jmp 0xcfc7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0xcdd0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x5230
leaq -0x99(%rbp), %rdi
callq 0x53f0
testb $0x1, -0x9a(%rbp)
jne 0xcde7
jmp 0xcdf3
movq -0x108(%rbp), %rdi
callq 0x52a0
jmp 0xcfbe
movl -0x10(%rbp), %eax
movl %eax, %edi
movl $0x1, %esi
movl $0x1, %edx
callq 0x5620
cmpl $0x0, %eax
je 0xceec
movb $0x1, -0xc2(%rbp)
movl $0x10, %edi
callq 0x51b0
movq %rax, -0x118(%rbp)
leaq -0xc1(%rbp), %rdi
movq %rdi, -0x110(%rbp)
callq 0x56c0
movq -0x110(%rbp), %rdx
leaq 0x5d98(%rip), %rsi      # 0x12be6
leaq -0xc0(%rbp), %rdi
callq 0x7600
jmp 0xce5c
callq 0x5030
movq -0x118(%rbp), %rdi
movl (%rax), %edx
leaq -0xc0(%rbp), %rsi
callq 0x76b0
jmp 0xce78
movq -0x118(%rbp), %rdi
movb $0x0, -0xc2(%rbp)
leaq 0xa773(%rip), %rsi      # 0x17600
leaq -0x5714(%rip), %rdx     # 0x7780
callq 0x5680
jmp 0xcfc7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0xcec4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x5230
leaq -0xc1(%rbp), %rdi
callq 0x53f0
testb $0x1, -0xc2(%rbp)
jne 0xcedb
jmp 0xcee7
movq -0x118(%rbp), %rdi
callq 0x52a0
jmp 0xcfbe
movl -0xc(%rbp), %eax
movl $0x55, %edi
movzwl %ax, %esi
callq 0xb0b0
movl -0xc(%rbp), %eax
movl $0x7, %edi
movzwl %ax, %esi
callq 0xb0b0
movl -0x10(%rbp), %eax
movl $0xa, %edi
movzwl %ax, %esi
callq 0xb0b0
movl -0xc(%rbp), %eax
movl $0x60, %edi
movzwl %ax, %esi
callq 0xb0b0
movl -0x10(%rbp), %eax
movzwl %ax, %edi
callq 0xb0d0
movzbl %al, %eax
movl %eax, -0xc8(%rbp)
movl -0xc(%rbp), %eax
movl $0x61, %edi
movzwl %ax, %esi
callq 0xb0b0
movl -0x10(%rbp), %eax
movzwl %ax, %edi
callq 0xb0d0
movb %al, %cl
movq -0xd8(%rbp), %rax
movzbl %cl, %ecx
movl %ecx, -0xcc(%rbp)
movl -0xc8(%rbp), %ecx
shll $0x8, %ecx
orl -0xcc(%rbp), %ecx
movl %ecx, 0xc(%rax)
movl -0xc(%rbp), %eax
movl $0xaa, %edi
movzwl %ax, %esi
callq 0xb0b0
movl -0x10(%rbp), %eax
movl %eax, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x5620
movl -0xc(%rbp), %eax
movl %eax, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x5620
movb $0x1, %al
andb $0x1, %al
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
movq -0x40(%rbp), %rdi
callq 0x56b0
nopw (%rax,%rax)