Presentation is loading. Please wait.

Presentation is loading. Please wait.

Features of Intel Processor Architectures that Lend to Operating System Design Jim Snyder.

Similar presentations


Presentation on theme: "Features of Intel Processor Architectures that Lend to Operating System Design Jim Snyder."— Presentation transcript:

1 Features of Intel Processor Architectures that Lend to Operating System Design Jim Snyder

2 Overview System Calls System Calls Intel Architecture (IA-32) Support for Interrupts and System Calls Intel Architecture (IA-32) Support for Interrupts and System Calls System Calls in Linux System Calls in Linux Interrupts in Linux Interrupts in Linux

3 System Calls A system call is the mechanism used by an application program to request service from the operating system. A system call is the mechanism used by an application program to request service from the operating system. Some common examples of system calls available in Linux are: Some common examples of system calls available in Linux are: read, write, open, close, kill or fork read, write, open, close, kill or fork

4 IA-32 Feature Support for Operating System Development Memory management Memory management Protection of software modules Protection of software modules Multitasking Multitasking Multiprocessing Multiprocessing Cache management Cache management Hardware resource and power management Hardware resource and power management Debugging and performance monitoring Debugging and performance monitoring Exception and interrupt handling Exception and interrupt handling

5 IA-32 Support for Interrupts & System Calls (1) Interrupts Interrupts Intel 286 Processor (1982) Intel 286 Processor (1982) Privilege levels protect the operating system from: Privilege levels protect the operating system from: Malicious code Malicious code Careless code Careless code Intel offers privilege levels 0-3 Intel offers privilege levels 0-3 Backward compatibility Backward compatibility

6

7 IA-32 Support for Interrupts & System Calls (2) 2 Types of Interrupts: 2 Types of Interrupts: External hardware interrupts External hardware interrupts Software Interrupts Software Interrupts Gates provide needed flexibility Gates provide needed flexibility 4 Types of Gates: 4 Types of Gates: Call gates Call gates Interrupt gates Interrupt gates Trap gates Trap gates Task gates Task gates Interrupt Descriptor Table (IDT) Interrupt Descriptor Table (IDT)

8 Gateways Between High and Low Privileged Code

9 Interrupt and Trap Gate Descriptors

10 Using IA-32 Interrupts Interrupt Vectors Interrupt Vectors Index into IDT Index into IDT Value of 0-255 (0-31 are reserved) Value of 0-255 (0-31 are reserved) Hardware Interrupts Hardware Interrupts Software Interrupts (relevant instructions) Software Interrupts (relevant instructions) INT n (most important to system calls in Linux) INT n (most important to system calls in Linux) INTO INTO INT 3 INT 3 BOUND BOUND

11

12 System Calls in Linux (1) 1. Initialization  Trap_init() is executed within the rest_init() function in init/main.c  Setup_idt() is called from startup_32() in /arch/i386/kernel/head.S 2. Invocation of system call in program 3. Call to library 4. SyscallX (include/asm/unistd.h)

13 Generic Macro #define _syscall1(type,name,type1,arg1) \ type name(type1 arg1) \ { \ long __res; \ __asm__ volatile ("int $0x80" \ : "=a" (__res) \ : "0" (__NR_##name),"b" ((long)(arg1))); \ if (__res >= 0) \ return (type) __res; \ errno = -__res; \ return -1; \ }

14 Example Call & Macro Expansion into Assembly _syscall1(int,chdir,char*,path);_chdir: subl $4,%exp subl $4,%exp pushl %ebx; save address pushl %ebx; save address movzwl 12(%esp),%eax; prepare parameters movzwl 12(%esp),%eax; prepare parameters movl %eax,4(%esp) movl %eax,4(%esp) movl $23,%eax movl $23,%eax movl 4(%esp),%ebx movl 4(%esp),%ebx int $0x80; software interrupt changes to kernel mode and jumps to handler int $0x80; software interrupt changes to kernel mode and jumps to handler movl %eax,%edx movl %eax,%edx testl %edx,%edx; check for error testl %edx,%edx; check for error jge L2; if no error, go to L2 jge L2; if no error, go to L2 negl %edx negl %edx movl %edx,_errno movl %edx,_errno movl $-1,%eax movl $-1,%eax popl %ebx popl %ebx addl $4,%esp addl $4,%esp ret ret L2: L2: movl %edx,%eax; clean up movl %edx,%eax; clean up popl %ebx popl %ebx addl $4,%esp addl $4,%esp ret; return ret; return

15 Each System Call Has a Unique ID From linux/include/linux/unistd.h: From linux/include/linux/unistd.h: #define __NR_chdir 12 #define __NR_time 13 #define __NR_mknod 14 #define __NR_chmod 15

16 INT 0x80 Interrupts the Kernel.align 4 _system_call: pushl %eax; save orig_eax SAVE_ALL movl $-ENOSYS,EAX(%esp) cmpl $(NR_syscalls),%eax jae ret_from_sys_call movl _sys_call_table(,%eax,4),%eax testl %eax,%eax je ret_from_sys_call movl _current,%ebx andl $~CF_MASK,EFLAGS(%esp); clear carry - assume no errors movl $0,errno(%ebx) movl %db6,%edx movl %edx,dbgreg6(%ebx) ; save current hardware debugging status testb $0x20,flags(%ebx) jne 1f call *%eax movl %eax,EAX(%esp); save the return value movl errno(%ebx),%edx negl %edx je ret_from_sys_call movl %edx,EAX(%esp) orl $(CF_MASK),EFLAGS(%esp); set carry to indicate error jmp ret_from_sys_call

17 Control Finally Transfers asmlinkage int sys_chdir(const char * filename) { struct inode * inode; struct inode * inode; int error; int error; error = namei(filename,&inode); error = namei(filename,&inode); if (error) if (error) return error; return error; if (!S_ISDIR(inode->i_mode)) { if (!S_ISDIR(inode->i_mode)) { iput(inode); iput(inode); return -ENOTDIR; return -ENOTDIR; } if ((error = permission(inode,MAY_EXEC)) != 0) { if ((error = permission(inode,MAY_EXEC)) != 0) { iput(inode); iput(inode); return error; return error; } iput(current->fs->pwd); iput(current->fs->pwd); current->fs->pwd = inode; current->fs->pwd = inode; return (0); return (0);}

18 Interrupts in Linux Bidirectional communication: Bidirectional communication: Hardware OS Hardware OS Two types of interrupts under Linux: Two types of interrupts under Linux: Short & long Short & long All interrupt handlers perform 5 basic actions: All interrupt handlers perform 5 basic actions: Save IRQ Save IRQ Acknowledge Acknowledge Execute interrupt service routine Execute interrupt service routine Terminate by jumping to ret_from_intr() Terminate by jumping to ret_from_intr() Request_irq() (from linux/arch/i386/kernel/irq.c) Request_irq() (from linux/arch/i386/kernel/irq.c)

19 Struct irqaction This data structure is found in include/linux/interrupt.h This data structure is found in include/linux/interrupt.h struct irqaction { void (*handler)(int, void *, struct pt_regs *); void (*handler)(int, void *, struct pt_regs *); unsigned long flags; unsigned long flags; unsigned long mask; unsigned long mask; const char *name; const char *name; void *dev_id; void *dev_id; struct irqaction *next; struct irqaction *next;};

20 Conclusion From it’s earliest processors back to the 16-bit 8086, released in 1978, Intel has had extensive support for hardware and software interrupts. Interrupt features are vital to operating systems. From it’s earliest processors back to the 16-bit 8086, released in 1978, Intel has had extensive support for hardware and software interrupts. Interrupt features are vital to operating systems. The only significant architectural change related to interrupts was the inclusion of the Advanced Programmable Interrupt Controller (APIC) in 1993 on the Intel Pentium. The APIC is used in support of SMP systems. The only significant architectural change related to interrupts was the inclusion of the Advanced Programmable Interrupt Controller (APIC) in 1993 on the Intel Pentium. The APIC is used in support of SMP systems.

21 References IA-32 Intel Architecture Software Developer’s Manual (volumes 1-3: Basic Architecture, Instruction Set Reference & System Programming Guide) IA-32 Intel Architecture Software Developer’s Manual (volumes 1-3: Basic Architecture, Instruction Set Reference & System Programming Guide) http://futura.disca.upv.es/~eso/en/t2- arquitectura/gen-t2-arquitectura.html http://futura.disca.upv.es/~eso/en/t2- arquitectura/gen-t2-arquitectura.html http://microlabs.cs.utt.ro/~mmarcu/books/03/p_all8. htm http://microlabs.cs.utt.ro/~mmarcu/books/03/p_all8. htm http://www.cs.ucr.edu/~brett/cs153_w02/syscall.html http://www.cs.ucr.edu/~brett/cs153_w02/syscall.html http://www.linux.com/guides/lkmpg/x1206.shtml http://www.linux.com/guides/lkmpg/x1206.shtml


Download ppt "Features of Intel Processor Architectures that Lend to Operating System Design Jim Snyder."

Similar presentations


Ads by Google