// File: /workspace/github_cpp_makefile_star2_O2/mattdibi[P]Programmatore-JTAG-per-Xilinx/serial.cpp
// Function: Serial::Open(char const*, unsigned int)
void Serial::Open(const char *Device,const unsigned Bauds)
{
   // Struttura per memorizzare i parametri della connessione
   struct termios options;

   // Apre la connessione in lettura/scrittura
   fd = open(Device, O_RDWR | O_NOCTTY | O_NDELAY);
   if (fd == -1)
   {
      // Se non è possibile aprire la connessione, lancia un'eccezione
      throw ErrorOpeningException();
   }

   // Impostazione dei flag per la seriale
   fcntl(fd, F_SETFL, FNDELAY);

   // Impostazione del puntatore della struttura per le opzioni
   tcgetattr(fd, &options);

   // Azzeramento la struttura options
   bzero(&options, sizeof(options));

   // Impostazione la velocità della seriale
   speed_t Speed;
   switch (Bauds)
   {
      case 110:
         Speed=B110;
         break;
      case 300:
         Speed=B300;
         break;
      case 600:
         Speed=B600;
         break;
      case 1200:
         Speed=B1200;
         break;
      case 2400:
         Speed=B2400;
         break;
      case 4800:
         Speed=B4800;
         break;
      case 9600:
         Speed=B9600;
         break;
      case 19200:
         Speed=B19200;
         break;
      case 38400:
         Speed=B38400;
         break;
      case 57600:
         Speed=B57600;
         break;
      case 115200:
         Speed=B115200;
         break;
      default:
         throw ErrorSpeedException();
   }
   cfsetispeed(&options, Speed);
   cfsetospeed(&options, Speed);

   // Impostazione dei flag
   options.c_cflag |= ( CLOCAL | CREAD |  CS8);
   options.c_iflag |= ( IGNPAR | IGNBRK );
   options.c_cc[VTIME]=0;
   options.c_cc[VMIN]=0;
   tcsetattr(fd, TCSANOW, &options);
   return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x48, %rsp
movl %edx, %r14d
movq %rdi, %rbx
movq %rsi, %rdi
movl $0x902, %esi            # imm = 0x902
xorl %eax, %eax
callq 0x3180
movl %eax, (%rbx)
cmpl $-0x1, %eax
je 0x4d57
pushq $0x4
popq %rsi
movl %eax, %edi
movl $0x800, %edx            # imm = 0x800
xorl %eax, %eax
callq 0x3110
movl (%rbx), %edi
leaq -0x60(%rbp), %r15
movq %r15, %rsi
callq 0x3260
xorps %xmm0, %xmm0
movaps %xmm0, (%r15)
movaps %xmm0, 0x10(%r15)
movaps %xmm0, 0x20(%r15)
movups %xmm0, 0x2c(%r15)
cmpl $0x6e, %r14d
je 0x4d0c
cmpl $0x1c200, %r14d         # imm = 0x1C200
je 0x4d4f
cmpl $0x258, %r14d           # imm = 0x258
je 0x4cf0
cmpl $0x4b0, %r14d           # imm = 0x4B0
je 0x4d00
cmpl $0x960, %r14d           # imm = 0x960
je 0x4ce8
cmpl $0x12c0, %r14d          # imm = 0x12C0
je 0x4cec
cmpl $0x2580, %r14d          # imm = 0x2580
je 0x4cfc
cmpl $0x4b00, %r14d          # imm = 0x4B00
je 0x4d04
cmpl $0x9600, %r14d          # imm = 0x9600
je 0x4d08
cmpl $0xe100, %r14d          # imm = 0xE100
je 0x4cf4
cmpl $0x12c, %r14d           # imm = 0x12C
jne 0x4d7f
pushq $0x7
jmp 0x4d0e
pushq $0xb
jmp 0x4d0e
pushq $0xc
jmp 0x4d0e
pushq $0x8
jmp 0x4d0e
movl $0x1001, %r14d          # imm = 0x1001
jmp 0x4d10
pushq $0xd
jmp 0x4d0e
pushq $0x9
jmp 0x4d0e
pushq $0xe
jmp 0x4d0e
pushq $0xf
jmp 0x4d0e
pushq $0x3
popq %r14
movq %r15, %rdi
movl %r14d, %esi
callq 0x3120
movq %r15, %rdi
movl %r14d, %esi
callq 0x3250
orl $0x8b0, 0x8(%r15)       # imm = 0x8B0
orb $0x5, (%r15)
andw $0x0, 0x16(%r15)
movl (%rbx), %edi
xorl %esi, %esi
movq %r15, %rdx
callq 0x3290
addq $0x48, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movl $0x1002, %r14d          # imm = 0x1002
jmp 0x4d10
pushq $0x8
popq %rdi
callq 0x30f0
leaq 0x3f62(%rip), %rcx      # 0x8cc8
movq %rcx, (%rax)
leaq 0x3ed0(%rip), %rsi      # 0x8c40
movq 0x4269(%rip), %rdx      # 0x8fe0
movq %rax, %rdi
callq 0x3380
pushq $0x8
popq %rdi
callq 0x30f0
leaq 0x3f62(%rip), %rcx      # 0x8cf0
movq %rcx, (%rax)
leaq 0x3ec0(%rip), %rsi      # 0x8c58
jmp 0x4d70