;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; ;; This file is part of 'M', a MIPS system emulator. ;; ;; ;; ;; (C) 2019 Stanislav Datskovskiy ( www.loper-os.org ) ;; ;; http://wot.deedbot.org/17215D118B7239507FAFED98B98228A001ABFFC7.html ;; ;; ;; ;; You do not have, nor can you ever acquire the right to use, copy or ;; ;; distribute this software ; Should you use this software for any purpose, ;; ;; or copy and distribute it to anyone or in any manner, you are breaking ;; ;; the laws of whatever soi-disant jurisdiction, and you promise to ;; ;; continue doing so for the indefinite future. In any case, please ;; ;; always : read and understand any software ; verify any PGP signatures ;; ;; that you use - for any purpose. ;; ;; ;; ;; See also http://trilema.com/2015/a-new-software-licensing-paradigm . ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;----------------------------------------------------------------------------- ;; State ;----------------------------------------------------------------------------- section .bss tty resb TTY_Config_size ; Linux tty state IOBUF resb 1 ; I/O buffer for print ;----------------------------------------------------------------------------- ;---------------------------------------------------------------------------- ;; TTY State Storage struc TTY_Config ;; Shell's old tty config (restore on quit) : .old_tty resb 12 .old_lflag resb 4 .old_brest resb 44 ;; Modified tty config (to run with) : .tty resb 12 .lflag resb 4 .brest resb 44 endstruc ;---------------------------------------------------------------------------- section .text ;----------------------------------------------------------------------------- _Cure_TTY: ;; Get initial tty state (for restore after quit) : mov rdx, tty + TTY_Config.old_tty mov rax, SYS_IOCTL mov rdi, 0 mov rsi, TCGETS syscall ;; Get another copy of initial tty state (to modify) : mov rdx, tty + TTY_Config.tty mov rax, SYS_IOCTL mov rdi, 0 mov rsi, TCGETS syscall ;; Switch off linux console 'cooked mode' idiocy: and dword [tty + TTY_Config.lflag], ~(0xF) ;; Set the modified tty state: mov rdx, tty + TTY_Config.tty mov rax, SYS_IOCTL mov rdi, 0 mov rsi, TCPUTS syscall ret ;----------------------------------------------------------------------------- _Uncure_TTY: ;; Set original tty state again: mov rdx, tty + TTY_Config.old_tty mov rax, SYS_IOCTL mov rdi, 0 mov rsi, TCPUTS syscall ret ;----------------------------------------------------------------------------- ;----------------------------------------------------------------------------- ; I/O ;----------------------------------------------------------------------------- _Write_Char: PUSHA mov byte [IOBUF], dl mov rdx, 1 mov rax, SYS_WRITE mov rsi, IOBUF mov rdi, STDOUT syscall POPA ret ;; return char in IOBUF _Read_Char_Blocking: PUSHA mov rdi, 0 ; STDIN mov rsi, IOBUF ; where to put mov rdx, 1 ; read one char mov rax, 0 syscall POPA ret ;----------------------------------------------------------------------------- ;----------------------------------------------------------------------------- ; Transmit string to STDERR. RDX points to length (32bit) after which is text. ;----------------------------------------------------------------------------- _Print_Text_STDERR: PUSHA mov rdi, STDERR ; Destination lea rsi, [rdx + 4] ; Start of text mov rax, SYS_WRITE ; SYS_WRITE mov edx, dword [edx] ; Length of text syscall ; Transmit the text to STDERR POPA ret ;----------------------------------------------------------------------------- ;----------------------------------------------------------------------------- ; Print hex value of EAX to STDOUT. ;----------------------------------------------------------------------------- ; _Dump_Byte: ; PUSHA ; mov ebp, eax ; shr eax, 4 ; call _dig ; mov eax, ebp ; call _dig ; POPA ; ret ; _Dump_EAX: ; PUSHA ; mov ebp, eax ; mov ebx, 28 ; _do_dig: ; mov eax, ebp ; mov ecx, ebx ; shr eax, cl ; call _dig ; sub ebx, 4 ; jnc _do_dig ; POPA ; ret ; _dig: ; and eax, 0xF ; mov rsi, _digits ; add rsi, rax ; mov rdx, 0x1 ; mov rax, SYS_WRITE ; mov rdi, STDOUT ; syscall ; ret ;----------------------------------------------------------------------------- section .rodata ; _linefeed: db 0xA, 0 _digits: db "0123456789abcdef", 0