Devices in CREATOR

Devices in CREATOR simulate the behavior of different components that the simulator can interact with, e.g. a terminal, a hard drive, etc.

The code interacts with a device through the program memory, a device specifies a set of "special" memory addresses that can be read and written by both the code and the device.

Device definition

A device is defined by the following:

  • An identifier (id), which uniquely identifies the device.
  • A control register address (ctrl_addr), which is typically used by the processor to signal an action to perform on the device.
  • A status register address (status_addr), which is typically used by the device to signal its status to the processor.
  • A data range (data), which defines a section of memory (start and end) that is shared between the processor and the device, typically for the exchange of data.
  • A handler function (handler()), which is called once per cycle, and defines the behavior of the device.
  • An enabled flag (enabled), which controls whether the device is enabled or not. If it's not, the callback is not called.

To create a new device, create a new class extending Device and implementing its handler method. Then, instantiate that object and add it to devices with its corresponding ID.

Device handling

All the devices are managed by the DeviceManager, which holds all the devices and acts as an interface with them. After executing each instruction, the executor calls the handleDevices() method, which executes the handlers for all enabled devices.

Typically, a device reads its control register and checks its value. If it's 0, it exits. If it's not, it works with the other data and clears the control register when it ends by calling reset().

Implemented devices

ConsoleDevice

A device for interacting with CREATOR's console.

Depending on the value stored in the control register (ctrl_addr), it executes one of the following:

  • 1 - print int: Reads a word from the data.start address and writes it as an integer value in the console.
  • 2 - print float: Reads a word from the data.start address and writes it as a float value in the console.
  • 3 - print double: Reads a word from the data.start address and writes it as a float value in the console.
  • 4 - print string: Reads the main memory address of a string from the data.start address and writes it in the console.
  • 5 - read int: Reads an integer from the console and stores it as a word in data.start.
  • 6 - read float: Reads a float from the console and stores it as a word in data.start.
  • 7 - read double: Reads a double from the console and stores it as a word in data.start.
  • 8 - read string: Reads a string from the console of the length specified in data.start + 4 and stores it in the main memory address specified in data.start.
  • 11 - print char: Reads a byte from the data.start address and writes it as a char in the console.
  • 12 - read char: Reads a char from the console and stores it as a byte in data.start.

OSDriver

A device to simulate system calls to a fictitious "Operating System".

Depending on the value stored in the control register (ctrl_addr), it executes one of the following:

  • 9 - sbrk: Allocates a segment of main memory of the size specified in data.start and stores its address in data.start.
  • 10 - exit: Terminates the current program's execution.

results matching ""

    No results matching ""