discussion_week_10
ECE 391 Discussion
Copyright By PowCoder代写 加微信 powcoder
Announcements & Reminders
! Exam 2 is Tomorrow, Thursday, October 28th 7PM to 9PM
! MP3.3 due Tuesday, November 9th at 5:59pm
! Plan accordingly!
! System calls
! Support 10 (numbered 1-10)
! CP3: Execute, halt, open, close, read, write
! CP4: The rest
! Parameters (convention)
! EAX – system call number
! EBX – 1st arg
! ECX – 2nd arg
! EDX – 3rd arg
! Return value in EAX (not all calls return)
! All system calls must be supported via a common IDT entry ! Need generic assembly
System calls
! Parameters
! Syscall number in EAX, 1st arg in EBX, 2nd arg in ECX, 3rd arg in EDX
! Must use assembly linkage
System Calls (contd.)
! Find the file in the file system and assign an unused file descriptor
! File descriptors need to be set up according to the file type
! Close the file descriptor passed in (set it to be available)
! Check for invalid descriptors
! Read, write
! Use file operations jump table to call the corresponding read or write
! The real functionality should be no longer than 1 line
Execute & Halt
! Parse args
! Executable check
! Set up program paging
! User-level Program Loader
! Create PCB
! Context Switch
! Create it’s own context switch
! Restore parent data
! Restore parent paging
! Close any relevant FDs
! Jump to execute return
Paging and Program Loader
! All user level programs will be loaded in
the page starting at 128MB (virtual mem)
! Physical memory starts at
8MB + (process number * 4MB)
process number starts from 0
! Flush TLB after swapping page
! Program loader
! Checks ELF magic constant
! Copy file contents to the correct location
! Find the first instruction’s address
File Descriptor Table
! File descriptor
! integer index into this array
! how user programs identify the open
! Up to 8 open files per task
! Stores structures containing:
! Pointer to file operations jump table
! File position
Process Control Block (PCB)
! Each process has its own PCB
! Each PCB starts at the top of a 8KB block inside the kernel
! First PCB starts at 8MB – 8KB
! Second PCB starts at 8MB – 8KB – 8KB
! Switch the kernel stack when switching PCB
! What you need in a PCB
! File descriptor array
! Whatever you think is necessary for running/stopping a program and
should be process specific
Now we combine everything
! IRET context:
! IRET needs 5 elements on stack
! Be careful with the order!
The first user level program your OS runs is shell.
It is invoked from the kernel.c.
system_execute(“shell”)
system_execute:
Parse args
Check for executable
Set up paging
Losd file into memory
Create PCB
Prepare for Context Switch
Push IRET context to kernel stack
Type in “ls”
system_execute(“ls”)
Do some work
system_halt()
User Space
The first user level program your OS runs is shell.
It is invoked from the kernel.c.
system_execute(“shell”)
system_execute:
Parse args
Check for executable
Set up paging
Losd file into memory
Create PCB
Prepare for Context Switch
Push IRET context to kernel stack
Type in “ls”
system_execute(“ls”)
Do some work
system_halt()
User Space
The first user level program your OS runs is shell.
It is invoked from the kernel.c.
system_execute(“shell”)
system_execute:
Parse args
Check for executable
Set up paging
Losd file into memory
Create PCB
Prepare for Context Switch
Push IRET context to kernel stack
System Call ASM linage:
Save register
Call correct system call
Restore registers
Type in “ls”
system_execute(“ls”)
Do some work
system_halt()
User Space
The first user level program your OS runs is shell.
It is invoked from the kernel.c.
system_execute(“shell”)
system_execute:
Parse args
Check for executable
Set up paging
Losd file into memory
Create PCB
Prepare for Context Switch
Push IRET context to kernel stack
System Call ASM linage:
Save register
Call correct system call
Restore registers
Type in “ls”
system_execute(“ls”)
Do some work
system_halt()
User Space
The first user level program your OS runs is shell.
It is invoked from the kernel.c.
system_execute(“shell”)
system_execute:
Parse args
Check for executable
Set up paging
Losd file into memory
Create PCB
Prepare for Context Switch
Push IRET context to kernel stack
System Call ASM linage:
Save register
Call correct system call
Restore registers
Type in “ls”
system_execute(“ls”)
Do some work
system_halt()
User Space
The first user level program your OS runs is shell.
It is invoked from the kernel.c.
system_execute(“shell”)
system_execute:
Parse args
Check for executable
Set up paging
Losd file into memory
Create PCB
Prepare for Context Switch
Push IRET context to kernel stack
System Call ASM linage:
Save register
Call correct system call
Restore registers
Type in “ls”
system_execute(“ls”)
Do some work
system_halt()
User Space
The first user level program your OS runs is shell.
It is invoked from the kernel.c.
system_execute(“shell”)
system_execute:
Parse args
Check for executable
Set up paging
Losd file into memory
Create PCB
Prepare for Context Switch
Push IRET context to kernel stack
System Call ASM linage:
Save register
Call correct system call
Restore registers
system_halt:
Restore parent data
Restore parent paging
Close any relevant FDs
Jump to execute return
Type in “ls”
system_execute(“ls”)
Do some work
system_halt()
User Space
The first user level program your OS runs is shell.
It is invoked from the kernel.c.
system_execute(“shell”)
system_execute:
Parse args
Check for executable
Set up paging
Losd file into memory
Create PCB
Prepare for Context Switch
Push IRET context to kernel stack
System Call ASM linage:
Save register
Call correct system call
Restore registers
system_halt:
Restore parent data
Restore parent paging
Close any relevant FDs
Jump to execute return
Type in “ls”
system_execute(“ls”)
Do some work
system_halt()
User Space
The first user level program your OS runs is shell.
It is invoked from the kernel.c.
system_execute(“shell”)
system_execute:
Parse args
Check for executable
Set up paging
Losd file into memory
Create PCB
Prepare for Context Switch
Push IRET context to kernel stack
System Call ASM linage:
Save register
Call correct system call
Restore registers
system_halt:
Restore parent data
Restore parent paging
Close any relevant FDs
Jump to execute return
Type in “ls”
system_execute(“ls”)
Do some work
system_halt()
User Space
The first user level program your OS runs is shell.
It is invoked from the kernel.c.
system_execute(“shell”)
system_execute:
Parse args
Check for executable
Set up paging
Losd file into memory
Create PCB
Prepare for Context Switch
Push IRET context to kernel stack
System Call ASM linage:
Save register
Call correct system call
Restore registers
system_halt:
Restore parent data
Restore parent paging
Close any relevant FDs
Jump to execute return
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com