-
+ F53ED4111870F8286EF3DE18EB11E03B3ED2EC4575772EF9D3E581D98FDEE7453A1BCD9FDB6054F62FBCD9E4FAF78CC9764A231C02FE94BD06F67D94D616B2B1
m/devices/clock.asm
(0 . 0)(1 . 87)
385 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
386 ;; ;;
387 ;; This file is part of 'M', a MIPS system emulator. ;;
388 ;; ;;
389 ;; (C) 2019 Stanislav Datskovskiy ( www.loper-os.org ) ;;
390 ;; http://wot.deedbot.org/17215D118B7239507FAFED98B98228A001ABFFC7.html ;;
391 ;; ;;
392 ;; You do not have, nor can you ever acquire the right to use, copy or ;;
393 ;; distribute this software ; Should you use this software for any purpose, ;;
394 ;; or copy and distribute it to anyone or in any manner, you are breaking ;;
395 ;; the laws of whatever soi-disant jurisdiction, and you promise to ;;
396 ;; continue doing so for the indefinite future. In any case, please ;;
397 ;; always : read and understand any software ; verify any PGP signatures ;;
398 ;; that you use - for any purpose. ;;
399 ;; ;;
400 ;; See also http://trilema.com/2015/a-new-software-licensing-paradigm . ;;
401 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
402
403 ;; TODO: Make the interval programmable. Right now hogs MMIO entirely in vain.
404
405 ;;;;;;;;;;;;;;;;;;;;;;;;;;;
406 ;; Interval Clock Device ;;
407 ;;;;;;;;;;;;;;;;;;;;;;;;;;;
408
409 ;-----------------------------------------------------------------------------
410 ; Interval Clock MMIO:
411 DECLARE_BUS_DEVICE CLOCK, 0x420, 0x42F
412 ;-----------------------------------------------------------------------------
413
414 ;-----------------------------------------------------------------------------
415 ; Interval Clock IRQ:
416 ;-----------------------------------------------------------------------------
417 %define CLOCK_IRQ 3 ; UART0 Receiver Slave IRQ
418 ;-----------------------------------------------------------------------------
419
420 ;-----------------------------------------------------------------------------
421 ; Interval Clock State
422 ;-----------------------------------------------------------------------------
423 section .bss
424 CLOCK_Die resd 1 ; Shutdown Trigger
425 ;-----------------------------------------------------------------------------
426
427 section .text
428
429 ;-----------------------------------------------------------------------------
430 _PD_Read_Word_CLOCK: ; Word reads from CLOCK always 0
431 xor eax, eax
432 ret ; Fin.
433 ;-----------------------------------------------------------------------------
434 _PD_Write_Word_CLOCK: ; Word writes to CLOCK do nothing!
435 ret
436 ;-----------------------------------------------------------------------------
437 _PD_Read_Byte_CLOCK:
438 xor eax, eax ; Read Byte from CLOCK: always 0
439 ret
440 ;-----------------------------------------------------------------------------
441 _PD_Write_Byte_CLOCK:
442 ret ; Fin.
443 ;-----------------------------------------------------------------------------
444 _Device_Init_CLOCK:
445 mov rdi, _Clock_Slave ; Clock Slave
446 call _Create_Thread ; Start the Clock Slave Thread
447 ret
448 ;-----------------------------------------------------------------------------
449 _Device_Shutdown_CLOCK: ; Shutdown
450 mov dword [CLOCK_Die], 0x01 ; Ask (unblocked) slave to die
451 ret
452 ;-----------------------------------------------------------------------------
453
454 ;-----------------------------------------------------------------------------
455 _Clock_Slave:
456 mov rax, _clock_interval_ts ; Set the 'nanosleep' interval
457 call _Nano_Sleep ; Sleep for the given interval (nS)
458 SetSlaveIRQ CLOCK_IRQ ; Invoke timer slave interrupt
459 cmp dword [CLOCK_Die], 0x01 ; time to die?
460 jne _Clock_Slave ; if not, keep going.
461 jmp _exit_thread ; terminate thread
462 ;-----------------------------------------------------------------------------
463
464 section .rodata
465
466 ;-----------------------------------------------------------------------------
467 ; TS for Clock Slave interval:
468 _clock_interval_ts:
469 dq 0 ; seconds
470 dq TIMER_SLAVE_PERIOD ; nanoseconds
471 ;-----------------------------------------------------------------------------