-
+ 8F9465318A06392DE5A881B9E47B5912A206B79803F64169B63448F42CDA7123180F42CC90836DAFEE0612015C624E9DF583C7CEAAD80895218CE5B1673F22F0
m/os/linux_io.asm
(0 . 0)(1 . 160)
4964 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4965 ;; ;;
4966 ;; This file is part of 'M', a MIPS system emulator. ;;
4967 ;; ;;
4968 ;; (C) 2019 Stanislav Datskovskiy ( www.loper-os.org ) ;;
4969 ;; http://wot.deedbot.org/17215D118B7239507FAFED98B98228A001ABFFC7.html ;;
4970 ;; ;;
4971 ;; You do not have, nor can you ever acquire the right to use, copy or ;;
4972 ;; distribute this software ; Should you use this software for any purpose, ;;
4973 ;; or copy and distribute it to anyone or in any manner, you are breaking ;;
4974 ;; the laws of whatever soi-disant jurisdiction, and you promise to ;;
4975 ;; continue doing so for the indefinite future. In any case, please ;;
4976 ;; always : read and understand any software ; verify any PGP signatures ;;
4977 ;; that you use - for any purpose. ;;
4978 ;; ;;
4979 ;; See also http://trilema.com/2015/a-new-software-licensing-paradigm . ;;
4980 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4981
4982
4983 ;-----------------------------------------------------------------------------
4984 ;; State
4985 ;-----------------------------------------------------------------------------
4986 section .bss
4987 tty resb TTY_Config_size ; Linux tty state
4988 IOBUF resb 1 ; I/O buffer for print
4989 ;-----------------------------------------------------------------------------
4990
4991 ;----------------------------------------------------------------------------
4992 ;; TTY State Storage
4993 struc TTY_Config
4994 ;; Shell's old tty config (restore on quit) :
4995 .old_tty resb 12
4996 .old_lflag resb 4
4997 .old_brest resb 44
4998 ;; Modified tty config (to run with) :
4999 .tty resb 12
5000 .lflag resb 4
5001 .brest resb 44
5002 endstruc
5003 ;----------------------------------------------------------------------------
5004
5005 section .text
5006
5007 ;-----------------------------------------------------------------------------
5008 _Cure_TTY:
5009 ;; Get initial tty state (for restore after quit) :
5010 mov rdx, tty + TTY_Config.old_tty
5011 mov rax, SYS_IOCTL
5012 mov rdi, 0
5013 mov rsi, TCGETS
5014 syscall
5015
5016 ;; Get another copy of initial tty state (to modify) :
5017 mov rdx, tty + TTY_Config.tty
5018 mov rax, SYS_IOCTL
5019 mov rdi, 0
5020 mov rsi, TCGETS
5021 syscall
5022
5023 ;; Switch off linux console 'cooked mode' idiocy:
5024 and dword [tty + TTY_Config.lflag], ~(0xF)
5025
5026 ;; Set the modified tty state:
5027 mov rdx, tty + TTY_Config.tty
5028 mov rax, SYS_IOCTL
5029 mov rdi, 0
5030 mov rsi, TCPUTS
5031 syscall
5032 ret
5033 ;-----------------------------------------------------------------------------
5034 _Uncure_TTY: ;; Set original tty state again:
5035 mov rdx, tty + TTY_Config.old_tty
5036 mov rax, SYS_IOCTL
5037 mov rdi, 0
5038 mov rsi, TCPUTS
5039 syscall
5040 ret
5041 ;-----------------------------------------------------------------------------
5042
5043 ;-----------------------------------------------------------------------------
5044 ; I/O
5045 ;-----------------------------------------------------------------------------
5046 _Write_Char:
5047 PUSHA
5048 mov byte [IOBUF], dl
5049 mov rdx, 1
5050 mov rax, SYS_WRITE
5051 mov rsi, IOBUF
5052 mov rdi, STDOUT
5053 syscall
5054 POPA
5055 ret
5056
5057 ;; return char in IOBUF
5058 _Read_Char_Blocking:
5059 PUSHA
5060 mov rdi, 0 ; STDIN
5061 mov rsi, IOBUF ; where to put
5062 mov rdx, 1 ; read one char
5063 mov rax, 0
5064 syscall
5065 POPA
5066 ret
5067 ;-----------------------------------------------------------------------------
5068
5069 ;-----------------------------------------------------------------------------
5070 ; Transmit string to STDERR. RDX points to length (32bit) after which is text.
5071 ;-----------------------------------------------------------------------------
5072 _Print_Text_STDERR:
5073 PUSHA
5074 mov rdi, STDERR ; Destination
5075 lea rsi, [rdx + 4] ; Start of text
5076 mov rax, SYS_WRITE ; SYS_WRITE
5077 mov edx, dword [edx] ; Length of text
5078 syscall ; Transmit the text to STDERR
5079 POPA
5080 ret
5081 ;-----------------------------------------------------------------------------
5082
5083 ;-----------------------------------------------------------------------------
5084 ; Print hex value of EAX to STDOUT.
5085 ;-----------------------------------------------------------------------------
5086 ; _Dump_Byte:
5087 ; PUSHA
5088 ; mov ebp, eax
5089 ; shr eax, 4
5090 ; call _dig
5091 ; mov eax, ebp
5092 ; call _dig
5093 ; POPA
5094 ; ret
5095
5096 ; _Dump_EAX:
5097 ; PUSHA
5098 ; mov ebp, eax
5099 ; mov ebx, 28
5100 ; _do_dig:
5101 ; mov eax, ebp
5102 ; mov ecx, ebx
5103 ; shr eax, cl
5104 ; call _dig
5105 ; sub ebx, 4
5106 ; jnc _do_dig
5107 ; POPA
5108 ; ret
5109 ; _dig:
5110 ; and eax, 0xF
5111 ; mov rsi, _digits
5112 ; add rsi, rax
5113 ; mov rdx, 0x1
5114 ; mov rax, SYS_WRITE
5115 ; mov rdi, STDOUT
5116 ; syscall
5117 ; ret
5118 ;-----------------------------------------------------------------------------
5119
5120 section .rodata
5121
5122 ; _linefeed: db 0xA, 0
5123 _digits: db "0123456789abcdef", 0