;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; ;; 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 . ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; TODO: Make the interval programmable. Right now hogs MMIO entirely in vain. ;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Interval Clock Device ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;; ;----------------------------------------------------------------------------- ; Interval Clock MMIO: DECLARE_BUS_DEVICE CLOCK, 0x420, 0x42F ;----------------------------------------------------------------------------- ;----------------------------------------------------------------------------- ; Interval Clock IRQ: ;----------------------------------------------------------------------------- %define CLOCK_IRQ 3 ; UART0 Receiver Slave IRQ ;----------------------------------------------------------------------------- ;----------------------------------------------------------------------------- ; Interval Clock State ;----------------------------------------------------------------------------- section .bss CLOCK_Die resd 1 ; Shutdown Trigger ;----------------------------------------------------------------------------- section .text ;----------------------------------------------------------------------------- _PD_Read_Word_CLOCK: ; Word reads from CLOCK always 0 xor eax, eax ret ; Fin. ;----------------------------------------------------------------------------- _PD_Write_Word_CLOCK: ; Word writes to CLOCK do nothing! ret ;----------------------------------------------------------------------------- _PD_Read_Byte_CLOCK: xor eax, eax ; Read Byte from CLOCK: always 0 ret ;----------------------------------------------------------------------------- _PD_Write_Byte_CLOCK: ret ; Fin. ;----------------------------------------------------------------------------- _Device_Init_CLOCK: mov rdi, _Clock_Slave ; Clock Slave call _Create_Thread ; Start the Clock Slave Thread ret ;----------------------------------------------------------------------------- _Device_Shutdown_CLOCK: ; Shutdown mov dword [CLOCK_Die], 0x01 ; Ask (unblocked) slave to die ret ;----------------------------------------------------------------------------- ;----------------------------------------------------------------------------- _Clock_Slave: mov rax, _clock_interval_ts ; Set the 'nanosleep' interval call _Nano_Sleep ; Sleep for the given interval (nS) SetSlaveIRQ CLOCK_IRQ ; Invoke timer slave interrupt cmp dword [CLOCK_Die], 0x01 ; time to die? jne _Clock_Slave ; if not, keep going. jmp _exit_thread ; terminate thread ;----------------------------------------------------------------------------- section .rodata ;----------------------------------------------------------------------------- ; TS for Clock Slave interval: _clock_interval_ts: dq 0 ; seconds dq TIMER_SLAVE_PERIOD ; nanoseconds ;-----------------------------------------------------------------------------