SYSTEM CALLS
program and programmer's interface to the hardware and software
resources
- CPU, RAM, disk storage, ports, NIC, keyboard, monitor, mouse,
printer, modem:
allocate and deallocate, read and write,
change serial (modem) port speed
- processes:
create, kill, suspend, resume, raise priority, lower priority,
wait for
- files: create, delete, open, close, read, write, change permissions
- directories: create, delete, add entry (link), remove entry (unlink),
change permissions
a user program wants the current time and date
- program executes date_time = get_date_and_time()
- get_date_and_time() is a C++ runtime library routine
- inside get_date_and_time() is a TRAP 17 instruction
- causes switch to CPU kernel mode and save PC register contents
``somewhere'' (process table or kernel stack
)
- load PC from TRAP's entry in the interrupt vector
- execute the TRAP (software interrupt) handler in kernel mode
- disable interrupts
- save all CPU registers in process table
- examine TRAP argument (17) and jump to code (clock device driver)
that reads the system clock (or reads an OS variable that contains
the current date and time if all the system clock does is
generate interrupts)
- store current time and date in a designated register or push on stack
- restore CPU registers from process table
- enable interrupts
- return from TRAP/INTERRUPT
- switch to CPU user mode and restore PC from ``somewhere''
(process table or kernel stack
)
- continue executing get_date_and_time() right after
TRAP 17
- retrieve current time and date from register or stack
and push onto process stack as get_date_and_time() return value
- return from get_date_and_time()
- pop current time and date from stack and store in variable
date_time
a user program wants to read some bytes from a file
- program executes read(filePath, memoryBuffer, numberBytes)
- read() is a C++ runtime library routine
- inside read() is a TRAP 42 instruction
- causes switch to CPU kernel mode and save PC register contents
``somewhere'' (process table or kernel stack
)
- load PC from TRAP's entry in the interrupt vector
- execute the TRAP (software interrupt) handler in kernel mode
- disable interrupts
- save all CPU registers in process table
- examine TRAP argument (42) and jump to file system manager
- follow path to file
- check file permissions
- figure out which disk has the file and which sector(s) on that
disk contain the requested bytes (by looking in various OS tables)
- call the disk device driver code to initiate a read
- device driver writes command to controller register
- file system manager puts entry into pending IO table
- file system manager marks the reading process as blocked,
takes it out of ready queue (from the front)
- file system manager calls CPU scheduler to pick a ready process
to get the CPU
(more simply, a different process is now at the head of the ready queue)
- restore CPU registers from process table
- enable interrupts
- return from TRAP/INTERRUPT
- switch to CPU user mode and restore PC from ``somewhere''
(process table or kernel stack
)
- continue executing some other process from where it left off after
last having the CPU
- meanwhile the disk controller moves the read-write arm, reads the
sector(s) into its local memory, copies the sector(s) over the
system bus into the file system manager's buffer area,
and generates an interrupt (all this takes 5--15 milliseconds)
- causes switch to CPU kernel mode and save PC register contents
``somewhere'' (process table or kernel stack
)
- load PC from disk's entry in the interrupt vector
- execute the disk (hardware) interrupt handler in kernel mode
- disable interrupts
- save all CPU registers in process table
- interrupt handler calls file system manager
- file system manager looks in pending IO table and copies
the requested bytes from its buffer area into the reading process
buffer
- file system marks the reading process as ready,
adds it to front or rear of ready queue
- file system manager calls CPU scheduler to pick a ready process
to get the CPU
(more simply, the process now at the head of the ready queue runs)
- restore CPU registers from process table
- enable interrupts
- return from TRAP/INTERRUPT
- switch to CPU user mode and restore PC from ``somewhere''
(process table or kernel stack
)
- continue executing some process from where it left off after
last having the CPU
interrupts are disabled to prevent corruption problems (for example,
the ready queue) and because there is only one place to save the CPU
registers (PCB in process table); more on this later
home page:
http://elvis.rowan.edu/~hartley/index.html
e-mail:
hartley@elvis.rowan.edu