Input and Output Flashcards
A computer may do input and output in a variety of ways:
- Interrupt-driven I/O
- Memory-mapped I/O
- Port I/O
- System I/O
Since our ARM server are running a Linux-OS, only system I/O is available
User-level programs communicate with external devices through the OS
What does this do?
This prevents malicious or accidental interactions that may damage the device
A program running exception level 0 does I/O by making a system call
What does it generate?
It generates an exception using the svc instruction like a subroutine call
- Control is transferred to a predefined system function (The address for this is stored in a table in the OS)
- The system code executes at EL1 (Is able to interact directly with I/O Devices)
- Once finished, control returns to the calling code (Changes back to EL0)
The type of system call is determined by the…
…number put into x8 before invoking svc
What are the I/O service requests?
[look at notes]
Where are the arguments for system calls put?
In registers x0 - x5 Any return value in x0 In UNIX (Linux), all peripheral devise are represented as files
What does it provide and what is the pattern?
Provides a uniform interface for I/O
Typical Pattern:
- Open the file (connect to the device, get its file descriptor)
- Read from or write to the file (do device I/O, transferring bytes)
- Close the file
File I/O involves interacting with ____________
secondary memory (usually a dis or tape device)
Standard I/O involves
The keyboard and screen devices
In File I/O Opening a file…
[check notes]
dirfd: directory file descriptor
- is used only if pathname is a relative path
- Can be set to AT_FDCWD (the value -100) to indicate that the pathname is relative to the program’s current working directory
pathname: absolute or relative pathname of a file
flags: combination of constants (using 1) indicating what will be done to the file’s data
mode: optional argument that specifies UNIX file permissions
- Required only when creating a new file (using O_CREAT)
- Specified in octal
fd: the returned file descriptor
- Is -1 on error
Flags
O_RDONLY 00 Read-only access
O_WRONLY 01 Write-only access
O_RDWR 02 Read/Write access
Optional flags
O_CREAT 0100 Create a file if it doesn’t exist
O_EXCL 0200 Fail if file exists (with O_CREAT)
O_TRUNC 01000 Truncate an existing file
O_APPEND 02000 Append Access
Reading a File code
[check notes] fd: file descriptor - Previously set by openat( ), or 0 for stdin buf: buffer where the bytes read will be stored - Usually a local variable n: number of bytes to read - Must be <= buffer size n_read: number of bytes actually read - -1 is returned on error
Writing to a File code
fd: file descriptor
- Previously set by openat( ), or -1 for stdin
buf: buffer where the bytes read will be stored
- Usually a local variable
n: number of bytes to write
- Must be <= buffer size
n_read: number of bytes actually written
- -1 is returned on error
Closing a File code
fd: file descriptor
status: 0 if successful, -1 otherwise