Author Topic: TERMIOS Functionality Part I  (Read 8210 times)

Offline TightCoderEx

  • Full Member
  • **
  • Posts: 103
TERMIOS Functionality Part I
« on: June 06, 2012, 03:18:24 PM »
Application preamble, get default settings

Code: [Select]
                section .bss
; =--= =--= =--= =--= =--= =--= =--= =--= =--= =--= =--= =--= =--= =--= =--= =--= =--= =--=
  Termios       resq    1                       ; Pointer to default termios structure

  _start        enter   48, 0                   ; Room for termios (keep stack qword aligned).

        ; Going to live on the edge a bit here and assume kernel has passed nulls to all
        ; volatile registers. At least that's the way it appears in GDB.
                mov     esi, TCGETS
                mov     rdx, rsp
                mov      al, SYS_IOCTL
                inc     rax                     ; Bump to see if -1 was returned
                jnz     .Ok
                mov     rsi, .NoTerm
                call    Console
                jmp     .Exit
      .NoTerm   db      10, 10, 'Opps, could not read termios structure', 10, 0
          .Ok   mov     [Termios], rsp          ; Save pointer might be needed in app body

Post-amble, reset to default just to be sure

Code: [Select]

        .Exit   mov     rsi, SignOff
                call    Console
                xor     rax, rax                ; Set return status

        ; Just to be sure, we'll return terminal to its default settings
                mov     rdi, rax                ; STDIN does equal zero
                mov      ax, TCSETS             ; which we know is 0x5402
                mov     rsi, rax
                mov      ax, SYS_IOCTL
                mov     rdx, rsp                ; Stack should be pointing to termios struct

        ; Whatever the return status is here, we're going to pass it as apps return value
                leave                           ; Cleanup procedure frame

        ; Whatever is in RAX is what application determines exit status should be.
                mov     rdi, rax                ; Copy exit status
                xor     rax, rax
                mov      al, SYS_EXIT

NOTE: These listings depict a theory of operation, have been tested with GDB, but are only excerpts from original source.