Input and Output Flashcards

1
Q

A computer may do input and output in a variety of ways:

A
  • Interrupt-driven I/O
  • Memory-mapped I/O
  • Port I/O
  • System I/O
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

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?

A

This prevents malicious or accidental interactions that may damage the device

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

A program running exception level 0 does I/O by making a system call

What does it generate?

A

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)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

The type of system call is determined by the…

A

…number put into x8 before invoking svc

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the I/O service requests?

A

[look at notes]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Where are the arguments for system calls put?

A
In registers x0 - x5
Any return value in x0
In UNIX (Linux), all peripheral devise are represented as files
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does it provide and what is the pattern?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

File I/O involves interacting with ____________

A

secondary memory (usually a dis or tape device)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Standard I/O involves

A

The keyboard and screen devices

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

In File I/O Opening a file…

A

[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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Flags

A

O_RDONLY 00 Read-only access
O_WRONLY 01 Write-only access
O_RDWR 02 Read/Write access

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Optional flags

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Reading a File code

A
[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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Writing to a File code

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Closing a File code

A

fd: file descriptor
status: 0 if successful, -1 otherwise

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Standard I/O

A

Are input and output streams predefined by the OS
- Are always available (are not opened or closed)

Standard input (stdin)

  • Represents input coming from the keyboard
  • File descriptor: 0

Standard output (stout)

  • Represents output to the monitor screen
  • File descriptor: 1

Standard error (stderr)

  • Represents output to the monitor screen (Normally used to output error messages)
  • File descriptor: 2

[Example in notes]