Skip to content

Terminal Input Output

Neelabh Gupta edited this page Apr 11, 2016 · 2 revisions

This page aims to provide a detailed overview of how typed characters are received, processed, and displayed on the terminal.

For other details of how jor1k works, check out the Technical details Wiki page.

Overview

Jor1k currently supports the following input devices:

  1. A "terminal input" device, which sends and receives data through UART
  2. An Opencores keyboard device
  3. A Virtio input device

Character Input and Printing Using the Terminal Input Device

The goal of the detailed description below is to better understand and document this process so that issue #26 can be addressed effectively.

Initialization
  1. Jor1k master registers handlers for DOM input events ((master) system.js#L140)
  2. Terminal-Linux registers handler for tty0/tty1 message from worker ((master) terminal-linux.js#L9)
  3. Worker initializes the UART devices for each of the two TTYs and assigns them interrupt vectors ((worker) system.js#L140)
  4. The UART devices register handlers for tty0/tty1 messages from master ((worker) uart.js#L79)
Runtime
  1. On keyboard input, the master checks if a terminal was focused earlier ((master) system.js#L141)
  2. Master calls TerminalInput's OnKeyPress/OnKeyDown/OnKeyUp method ((master) system.js#L143)
  3. TerminalInput transforms keys and calls master's SendChars method ((master) terminal-input.js#L34)
  4. SendChars sends the tty0/tty1 message to worker with data ((master) system.js#L252)
  5. UART receives the characters and pushes them into its receive buffer ((worker) uart.js#L118)
  6. UART raises interrupt (UART_IIR_CTI, signifying a character timeout) ((worker) uart.js#L123)
  7. CPU handles interrupt ((worker) system.js#L223)
  8. ... CPU, OS stuff ...
  9. CPU writes to UART register using memory-mapped I/O ((worker) ram.js#L166)
  10. UART adds characters to transmit buffer ((worker) uart.js#L247)
  11. UART raises interrupt (UART_IIR_THRI, signifying that the transmitter holding register is empty, because the transmitter buffer is immediately emptied) ((worker) uart.js#L251)
  12. UART empties the transmission buffer and sends its data with the tty0/tty1 message to master ((worker) uart.js#L111)
  13. Terminal-Linux calls Terminal's PutChar method ((master) terminal-linux.js#L11)
  14. PutChar transforms and "prints" the message data to the DOM ((master) terminal.js#L736)
  15. Terminal-Linux calls the optional onCharReceived callback function supplied by client code ((master) terminal.js#L835)