Operating Systems In Depth VI–1 Copyright © 2020 Thomas W. Doeppner. All rights reserved.
CS 167: I/O and Booting
Operating Systems In Depth VI–2 Copyright © 2020 Thomas W. Doeppner. All rights reserved.
Simple I/O Architecture
Bus
ControllerController
Memory
Controller
DiskProcessor
Operating Systems In Depth VI–3 Copyright © 2020 Thomas W. Doeppner. All rights reserved.
PIO Registers
Control registerGoR GoW IER IEW
Status registerRdyR RdyW
Read register
Write register
GoR Go read (start a read operation)
GoW Go write (start a write operation)
IER Enable read-completion interruptsIEW Enable write-completion interrupts
RdyR Ready to read
RdyW Ready to write
Legend:
Operating Systems In Depth VI–4 Copyright © 2020 Thomas W. Doeppner. All rights reserved.
Programmed I/O
• E.g.: Terminal controller• Procedure (write)
– write a byte into the write register– set the WGO bit in the control register– wait for WREADY bit (in status register) to be
set (if interrupts have been enabled, an interrupt occurs when this happens)
Operating Systems In Depth VI–5 Copyright © 2020 Thomas W. Doeppner. All rights reserved.
DMA RegistersOp Code Control registerGo IE
Status registerRdy
Memory address register
Device address register
Go Start an operation
Op Code Operation code (identifies the operation)IE Enable interruptsRdy Controller is ready
Legend:
Operating Systems In Depth VI–6 Copyright © 2020 Thomas W. Doeppner. All rights reserved.
Direct Memory Access
• E.g.: Disk controller• Procedure
– set the disk address in the device address register (only relevant for a seek request)
– set the buffer address in the memory address register
– set the op code (SEEK, READ or WRITE), the GO bit and, if desired, the interrupt ENABLE bit in the control register
– wait for interrupt or for READY bit to be set
Operating Systems In Depth VI–7 Copyright © 2020 Thomas W. Doeppner. All rights reserved.
Device Drivers
Device Driver
CommonData
read
write
interrupt
Device
Operating Systems In Depth VI–8 Copyright © 2020 Thomas W. Doeppner. All rights reserved.
Operating Systems In Depth VI–9 Copyright © 2020 Thomas W. Doeppner. All rights reserved.
PDP-8
Operating Systems In Depth VI–10 Copyright © 2020 Thomas W. Doeppner. All rights reserved.
PDP-8 Boot Code
07756 6032 KCC07757 6031 KSF07760 5357 JMP .-107761 6036 KRB07762 7106 CLL RTL07763 7006 RTL07764 7510 SPA07765 5357 JMP 775707766 7006 RTL07767 6031 KSF07770 5367 JMP .-107771 6034 KRS07772 7420 SNL07773 3776 DCA I 777607774 3376 DCA 777607775 5356 JMP 775607776 0000 AND 007777 5301 JMP 7701
Operating Systems In Depth VI–11 Copyright © 2020 Thomas W. Doeppner. All rights reserved.
VAX-11/780
Operating Systems In Depth VI–12 Copyright © 2020 Thomas W. Doeppner. All rights reserved.
VAX-11/780 Boot
• Separate “console computer”– LSI-11– read boot code from floppy disk– load OS from root directory of first file system
on primary disk
Operating Systems In Depth VI–13 Copyright © 2020 Thomas W. Doeppner. All rights reserved.
Configuring the OS (1)
• Early Unix– OS statically linked to contain all needed
device drivers- all device-specific info included with
drivers– disk drivers contained partitioning description
Operating Systems In Depth VI–14 Copyright © 2020 Thomas W. Doeppner. All rights reserved.
Configuring the OS (2)
• Later Unix– OS statically linked to contain all needed
device drivers- at boot time, OS would probe to see which
devices were present and discover device-specific info
– partition table in first sector of each disk
Operating Systems In Depth VI–15 Copyright © 2020 Thomas W. Doeppner. All rights reserved.
IBM PC
Operating Systems In Depth VI–16 Copyright © 2020 Thomas W. Doeppner. All rights reserved.
Issues
• Open architecture– large market for peripherals, most requiring
special drivers– how to access boot device?– how does OS get drivers for new devices?
Operating Systems In Depth VI–17 Copyright © 2020 Thomas W. Doeppner. All rights reserved.
The Answer: BIOS
• Basic Input-Output System– code stored in non-volatile RAM
- CMOS, flash, whatever …– configuration data also in NV RAM
- including set of boot-device names– three primary functions
- power-on self test (POST)- load and transfer control to boot program- provide drivers for all devices
– main BIOS on motherboard– additional BIOSes on other boards
Operating Systems In Depth VI–18 Copyright © 2020 Thomas W. Doeppner. All rights reserved.
POST
• On power-on, CPU executes BIOS code– located in last 64k of first megabyte of address
space– initializes hardware– counts memory locations
Operating Systems In Depth VI–19 Copyright © 2020 Thomas W. Doeppner. All rights reserved.
Getting the Boot Program
Boot Program
Partition Table
Magic Number
446 bytes
64 bytes
2 bytes
Partition 1Partition 2Partition 3Partition 4
Master Boot Record
Operating Systems In Depth VI–20 Copyright © 2020 Thomas W. Doeppner. All rights reserved.
Linux Booting (1)
• Two stages of booting provided by one of:– lilo (Linux Loader)
- uses sector numbers of kernel image– grub (Grand Unified Boot Manager)
- understands various file systems– both allow dual (or greater) booting
- select which system to boot from menu• perhaps choice of Linux or Windows
Operating Systems In Depth VI–21 Copyright © 2020 Thomas W. Doeppner. All rights reserved.
Linux Booting (2)
• Kernel image is compressed– step 1: set up stack, clear BSS,
uncompress kernel, then transfer control to it
• Process 0 is created– step 2: set up initial page tables,
turn on address translation• Do further initialization
– step 3: initialize rest of kernel, create init process (#1)
– invoke scheduler
assembler code (startup_32)
assembler code (different
startup_32)
C code (start_kernel)
Operating Systems In Depth VI–22 Copyright © 2020 Thomas W. Doeppner. All rights reserved.
Beyond BIOS
• BIOS– designed for 16-bit x86 of mid 1980s
• Open Firmware– designed by Sun– portable
- drivers, boot code in Forth• compiled into bytecode
– used on non-Intel systems• UEFI (Unified Extensible Firmware Interface)
– improved BIOS originally from Intel– also uses bytecode
Operating Systems In Depth VI–23 Copyright © 2020 Thomas W. Doeppner. All rights reserved.
UNIX Structure
Operating Systems In Depth VI–24 Copyright © 2020 Thomas W. Doeppner. All rights reserved.
The Unix Address Space
text
data
bssdynamic
stack
Operating Systems In Depth VI–25 Copyright © 2020 Thomas W. Doeppner. All rights reserved.
Creating a Process: Before
fork( )
parent process
Operating Systems In Depth VI–26 Copyright © 2020 Thomas W. Doeppner. All rights reserved.
Creating a Process: After
fork( )// returns p
parent process
fork( )// returns 0
child process (pid = p)
Operating Systems In Depth VI–27 Copyright © 2020 Thomas W. Doeppner. All rights reserved.
Fork and Wait
short pid;
if ((pid = fork()) == 0) {
/* some code is here for the child to execute */
exit(n);
} else {
int ReturnCode;
while(pid != wait(&ReturnCode))
;
/* the child has terminated with ReturnCode as its
return code */
}
Operating Systems In Depth VI–28 Copyright © 2020 Thomas W. Doeppner. All rights reserved.
Process Control BlocksPID
Terminated children
Link
Return code
Process Control Block
PID
Terminated children
Link
Return codePID
Terminated children
Link
Return codeOther Stuff
Other Stuff
Other Stuff
Operating Systems In Depth VI–29 Copyright © 2020 Thomas W. Doeppner. All rights reserved.
Exec
int pid;
if ((pid = fork()) == 0) {
/* we’ll soon discuss what might take place before execis called */
execl("/home/twd/bin/primes", "primes", "300", 0);
exit(1);
}
/* parent continues here */
while(pid != wait(0)) /* ignore the return code */
;
Operating Systems In Depth VI–30 Copyright © 2020 Thomas W. Doeppner. All rights reserved.
Loading a New Image
exec(prog, args)
Beforeprog’s textprog’s dataprog’s bss
args
After
Operating Systems In Depth VI–31 Copyright © 2020 Thomas W. Doeppner. All rights reserved.
Quiz 1int A=0, B=0, C=0, D=0;
A=1;
if (fork() > 0) {B=1;
A=111;
} else {
C=2;if (fork() > 0) {
D=222;
} else {D=A+B+C;
// what value is now// in D for this process?
}}
exit(0);
Answer:a) 0b) 3c) 113d) indeterminate
Operating Systems In Depth VI–32 Copyright © 2020 Thomas W. Doeppner. All rights reserved.
Representing the Address Space
• Important component of a process is its address space
– how is it represented?• Can page tables represent a process’s
address space?
Operating Systems In Depth VI–33 Copyright © 2020 Thomas W. Doeppner. All rights reserved.
Simple User Address Space
text
data
bss & dynamic
stack
Operating Systems In Depth VI–34 Copyright © 2020 Thomas W. Doeppner. All rights reserved.
Address-Space RepresentationSomewhat Simplified
mm_structtask_struct
vm_area_struct0–7fff
x, shared
vm_area_struct8000–1afffrw, private
vm_area_struct1b000–1bfffrw, private
vm_area_struct7fffd000–7fffffff
rw, private
struct file
Operating Systems In Depth VI–35 Copyright © 2020 Thomas W. Doeppner. All rights reserved.
Adding a Mapped File
text
data
bss & dynamic
stack
mapped file
Operating Systems In Depth VI–36 Copyright © 2020 Thomas W. Doeppner. All rights reserved.
Address-Space Representation:More Areas
mm_structtask_struct
vm_area_struct0–7fff
x, shared
vm_area_struct8000–1afffrw, private
vm_area_struct1b000–1bfffrw, private
vm_area_struct200000–201fff
rw, shared
vm_area_struct7fffd000–7fffffff
rw, private
struct file struct file
Operating Systems In Depth VI–37 Copyright © 2020 Thomas W. Doeppner. All rights reserved.
Adding More Stuff
text
data
stack 2
bss & dynamic
stack 1
stack 3
mapped file 3
mapped file 117
...
mapped file 2mapped file 1
Operating Systems In Depth VI–38 Copyright © 2020 Thomas W. Doeppner. All rights reserved.
Address-Space Representation:Reality
mm_structtask_struct
200000–201fff
1b000–1bfff 202000–203fff
0–7fff 8000–1afff 7fffd000–7fffffff204000–204fff
208000–210fff
Operating Systems In Depth VI–39 Copyright © 2020 Thomas W. Doeppner. All rights reserved.
Layering
User Applications
System CallsUserKernel
Virtual File System (VFS)
disk file systems (e.g. S5FS)
terminals networkingother things (e.g. /proc)
Operating Systems In Depth VI–40 Copyright © 2020 Thomas W. Doeppner. All rights reserved.
Quiz 2int fd1 = open("file", O_CREAT|O_RDWR, 0666);
unlink("file");
write(fd1, "123", 3);int fd2 = open("file", O_CREAT|O_RDWR, 0666);
write(fd2, "4", 1);
if (fork() == 0) {
write(fd1, "5", 1);}
exit(0);
The final contents of file are:a) 12345b) 453c) 45d) 4