raw
m_genesis.kv            1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
m_genesis.kv 2 ;; ;;
m_genesis.kv 3 ;; This file is part of 'M', a MIPS system emulator. ;;
m_genesis.kv 4 ;; ;;
m_genesis.kv 5 ;; (C) 2019 Stanislav Datskovskiy ( www.loper-os.org ) ;;
m_genesis.kv 6 ;; http://wot.deedbot.org/17215D118B7239507FAFED98B98228A001ABFFC7.html ;;
m_genesis.kv 7 ;; ;;
m_genesis.kv 8 ;; You do not have, nor can you ever acquire the right to use, copy or ;;
m_genesis.kv 9 ;; distribute this software ; Should you use this software for any purpose, ;;
m_genesis.kv 10 ;; or copy and distribute it to anyone or in any manner, you are breaking ;;
m_genesis.kv 11 ;; the laws of whatever soi-disant jurisdiction, and you promise to ;;
m_genesis.kv 12 ;; continue doing so for the indefinite future. In any case, please ;;
m_genesis.kv 13 ;; always : read and understand any software ; verify any PGP signatures ;;
m_genesis.kv 14 ;; that you use - for any purpose. ;;
m_genesis.kv 15 ;; ;;
m_genesis.kv 16 ;; See also http://trilema.com/2015/a-new-software-licensing-paradigm . ;;
m_genesis.kv 17 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
m_genesis.kv 18
m_genesis.kv 19
m_genesis.kv 20 ;-----------------------------------------------------------------------------
m_genesis.kv 21 ;; State
m_genesis.kv 22 ;-----------------------------------------------------------------------------
m_genesis.kv 23 section .bss
m_genesis.kv 24 tty resb TTY_Config_size ; Linux tty state
m_genesis.kv 25 IOBUF resb 1 ; I/O buffer for print
m_genesis.kv 26 ;-----------------------------------------------------------------------------
m_genesis.kv 27
m_genesis.kv 28 ;----------------------------------------------------------------------------
m_genesis.kv 29 ;; TTY State Storage
m_genesis.kv 30 struc TTY_Config
m_genesis.kv 31 ;; Shell's old tty config (restore on quit) :
m_genesis.kv 32 .old_tty resb 12
m_genesis.kv 33 .old_lflag resb 4
m_genesis.kv 34 .old_brest resb 44
m_genesis.kv 35 ;; Modified tty config (to run with) :
m_genesis.kv 36 .tty resb 12
m_genesis.kv 37 .lflag resb 4
m_genesis.kv 38 .brest resb 44
m_genesis.kv 39 endstruc
m_genesis.kv 40 ;----------------------------------------------------------------------------
m_genesis.kv 41
m_genesis.kv 42 section .text
m_genesis.kv 43
m_genesis.kv 44 ;-----------------------------------------------------------------------------
m_genesis.kv 45 _Cure_TTY:
m_genesis.kv 46 ;; Get initial tty state (for restore after quit) :
m_genesis.kv 47 mov rdx, tty + TTY_Config.old_tty
m_genesis.kv 48 mov rax, SYS_IOCTL
m_genesis.kv 49 mov rdi, 0
m_genesis.kv 50 mov rsi, TCGETS
m_genesis.kv 51 syscall
m_genesis.kv 52
m_genesis.kv 53 ;; Get another copy of initial tty state (to modify) :
m_genesis.kv 54 mov rdx, tty + TTY_Config.tty
m_genesis.kv 55 mov rax, SYS_IOCTL
m_genesis.kv 56 mov rdi, 0
m_genesis.kv 57 mov rsi, TCGETS
m_genesis.kv 58 syscall
m_genesis.kv 59
m_genesis.kv 60 ;; Switch off linux console 'cooked mode' idiocy:
m_genesis.kv 61 and dword [tty + TTY_Config.lflag], ~(0xF)
m_genesis.kv 62
m_genesis.kv 63 ;; Set the modified tty state:
m_genesis.kv 64 mov rdx, tty + TTY_Config.tty
m_genesis.kv 65 mov rax, SYS_IOCTL
m_genesis.kv 66 mov rdi, 0
m_genesis.kv 67 mov rsi, TCPUTS
m_genesis.kv 68 syscall
m_genesis.kv 69 ret
m_genesis.kv 70 ;-----------------------------------------------------------------------------
m_genesis.kv 71 _Uncure_TTY: ;; Set original tty state again:
m_genesis.kv 72 mov rdx, tty + TTY_Config.old_tty
m_genesis.kv 73 mov rax, SYS_IOCTL
m_genesis.kv 74 mov rdi, 0
m_genesis.kv 75 mov rsi, TCPUTS
m_genesis.kv 76 syscall
m_genesis.kv 77 ret
m_genesis.kv 78 ;-----------------------------------------------------------------------------
m_genesis.kv 79
m_genesis.kv 80 ;-----------------------------------------------------------------------------
m_genesis.kv 81 ; I/O
m_genesis.kv 82 ;-----------------------------------------------------------------------------
m_genesis.kv 83 _Write_Char:
m_genesis.kv 84 PUSHA
m_genesis.kv 85 mov byte [IOBUF], dl
m_genesis.kv 86 mov rdx, 1
m_genesis.kv 87 mov rax, SYS_WRITE
m_genesis.kv 88 mov rsi, IOBUF
m_genesis.kv 89 mov rdi, STDOUT
m_genesis.kv 90 syscall
m_genesis.kv 91 POPA
m_genesis.kv 92 ret
m_genesis.kv 93
m_genesis.kv 94 ;; return char in IOBUF
m_genesis.kv 95 _Read_Char_Blocking:
m_genesis.kv 96 PUSHA
m_genesis.kv 97 mov rdi, 0 ; STDIN
m_genesis.kv 98 mov rsi, IOBUF ; where to put
m_genesis.kv 99 mov rdx, 1 ; read one char
m_genesis.kv 100 mov rax, 0
m_genesis.kv 101 syscall
m_genesis.kv 102 POPA
m_genesis.kv 103 ret
m_genesis.kv 104 ;-----------------------------------------------------------------------------
m_genesis.kv 105
m_genesis.kv 106 ;-----------------------------------------------------------------------------
m_genesis.kv 107 ; Transmit string to STDERR. RDX points to length (32bit) after which is text.
m_genesis.kv 108 ;-----------------------------------------------------------------------------
m_genesis.kv 109 _Print_Text_STDERR:
m_genesis.kv 110 PUSHA
m_genesis.kv 111 mov rdi, STDERR ; Destination
m_genesis.kv 112 lea rsi, [rdx + 4] ; Start of text
m_genesis.kv 113 mov rax, SYS_WRITE ; SYS_WRITE
m_genesis.kv 114 mov edx, dword [edx] ; Length of text
m_genesis.kv 115 syscall ; Transmit the text to STDERR
m_genesis.kv 116 POPA
m_genesis.kv 117 ret
m_genesis.kv 118 ;-----------------------------------------------------------------------------
m_genesis.kv 119
m_genesis.kv 120 ;-----------------------------------------------------------------------------
m_genesis.kv 121 ; Print hex value of EAX to STDOUT.
m_genesis.kv 122 ;-----------------------------------------------------------------------------
m_genesis.kv 123 ; _Dump_Byte:
m_genesis.kv 124 ; PUSHA
m_genesis.kv 125 ; mov ebp, eax
m_genesis.kv 126 ; shr eax, 4
m_genesis.kv 127 ; call _dig
m_genesis.kv 128 ; mov eax, ebp
m_genesis.kv 129 ; call _dig
m_genesis.kv 130 ; POPA
m_genesis.kv 131 ; ret
m_genesis.kv 132
m_genesis.kv 133 ; _Dump_EAX:
m_genesis.kv 134 ; PUSHA
m_genesis.kv 135 ; mov ebp, eax
m_genesis.kv 136 ; mov ebx, 28
m_genesis.kv 137 ; _do_dig:
m_genesis.kv 138 ; mov eax, ebp
m_genesis.kv 139 ; mov ecx, ebx
m_genesis.kv 140 ; shr eax, cl
m_genesis.kv 141 ; call _dig
m_genesis.kv 142 ; sub ebx, 4
m_genesis.kv 143 ; jnc _do_dig
m_genesis.kv 144 ; POPA
m_genesis.kv 145 ; ret
m_genesis.kv 146 ; _dig:
m_genesis.kv 147 ; and eax, 0xF
m_genesis.kv 148 ; mov rsi, _digits
m_genesis.kv 149 ; add rsi, rax
m_genesis.kv 150 ; mov rdx, 0x1
m_genesis.kv 151 ; mov rax, SYS_WRITE
m_genesis.kv 152 ; mov rdi, STDOUT
m_genesis.kv 153 ; syscall
m_genesis.kv 154 ; ret
m_genesis.kv 155 ;-----------------------------------------------------------------------------
m_genesis.kv 156
m_genesis.kv 157 section .rodata
m_genesis.kv 158
m_genesis.kv 159 ; _linefeed: db 0xA, 0
m_genesis.kv 160 _digits: db "0123456789abcdef", 0