엔지니어가 되고 싶은 공돌이

03. Interrupt and Exception (2) 본문

Computer Science/Operating System

03. Interrupt and Exception (2)

Geca 2025. 5. 13. 16:30

 

3. 1. Exception

 

- Exception: Software Executing Instructions이 생성. ex) x86의 INT instruction.

 

- Interrupts와 exceptions의 처리방법은 거의 동일합니다.

 

 

1) Trap

 

- User Application이 Intentional하게 발생시킵니다.

 

- ex) System Calls, Breakpoint Traps.

 

- Return next instruction(Recoverable).

 

 

2) Fault

 

- Unintentional and Possibly(or Impossibly) Recoverable.

 

- Page Fault (Recoverable), Protection Fault(Unrecoverable).

 

 

3) Abort

 

- Unintentional and Unrecoverable.

 

- Parity error, machine error.

 

 

Systems call(대략 350개): OS가 Application Software에게 제공하는 Service에 관한 Programming Interface.

 

- Process Management: fork, exec, exit, kill…

 

- File Management: open, close, read, write…

 

- File System Management: mkdir, rmdir, chdir…

 

 

- Application Software가 Function을 통해서 System Call을 호출하면, 해당 Function을 가지고 있는 Library로 간 뒤, Library가 Kernel or OS에 특별한 작업을 요청합니다. Kernel or OS는 해당작업을 완료한 뒤 Library로 보내고, 다시 Library는 결과를 Application Software로 보내줍니다.

 


 

 

3. 2. DMA & Timer

 

- Data Transfer Mode

 

1) Programmed I/O(PIO)

 

- CPU가 I/O Device와 Memory사이의 데이터 교환에 직접 관여합니다.

 

- 조그만한 데이터를 보낼 때 유리합니다.

 

 

2) DMA(direct Memory Access)

 

- 최근 I/O Device의 속도랑 성능이 향상되면서 CPU의 개입없이 Memory와 직접 데이터를 교환하는 방식.

 

- CPU가 Device에게 명령을 내리면, Device Controller가 Block단위로 Data를 Main Memory로 보냅니다.

 

  Data를 보내고 나서 Device가 Interrupt를 발생시킵니다.

 

- Burst Mode, Steal Mode가 존재해서, Control을 얻는 즉시 Data를 한번에 다 보낼수 도 있고, Control를 획득해서 Data를 조금 보내고 Control를 반납하고, 다시 획득하고 Data를 조금 보내고 다시 반납하고… 이 방식으로 수행할 수 있습니다.

 

- 일반적으로 PIO보다 더 효율적입니다.

 

 

- Timer: Computer 0~1번 Device.

 

  1) 적절한 주기마다 Interrupt를 생성하여 Control를 OS에게 다시 넘겨주는 역할을 합니다.

 

  2) 특정 Program이 CPU를 독점하는 것을 방지하며, Time Sharing을 가능하게 해줍니다.

 

  3) 최대 Clock수 만큼 줄 수 있으며, 최근에는 Dynamic하게 동작하며, 오직 OS에서만 접근이 가능합니다.

 


 

3. 3. OS & Memory Protection

 

- Protected Instruction: User Mode에서 사용 불가능하고, Kernel Mode에서만 실행가능한 명령어들.

 

  I/O access, Memory Management, Setting “mode bits”(CPU 내부에 존재).

 

 

- Architecture는 최소한 2가지의 Mode를 제공하여야 합니다.

 

  Mode는 Mode Bit에 의해서 결정되며, 오직 운영체제만이 변경할 수 있어야 합니다.

 

- IA-32 에서는 Ring 0 > 1 > 2 > 3의 4가지 모드를 지원하며,

 

  CS Register이라는 Mode Bit Register를 가지고 있어서, 현재 Mode값을 저장합니다.

 

- System calls을 호출해서 Mode Bit를 바꾸고, (kernel mode -> mode bit = 0) kernel mode에서의 작업이 끝나면 다시 user mode(mode bit = 1)로 돌아갑니다.

 

 

- OS는 사용자 프로그램간의 Memory를 보호하고, 자기자신 스스로도 보호할 수 있어야 합니다.

 

- 간단한 방법으로 Base Register, Limit Register를 준비해서 Memory를 보호할 수 있습니다.

 

- MMU(Memory Management Unit): 메모리 보호 메커니즘을 제공합니다.

 

  1) CPU 안에 존재합니다.

 

  2) Base Register, Limit register를 가지고 있습니다.

 

  3) TLB, Virtual Memory, Segmentation를 제공합니다.

 

 

- Synchronization: 작업들 사이의 수행시간을 맞추는 것을 말합니다.

 

  예를 들어, Interrupt가 동시에 발생하는 경우와 같이,

 

  OS는 다양한 상황에서 여러 작업을 수행할 수 있어야 합니다.


'Computer Science > Operating System' 카테고리의 다른 글

05. Fork, Exec and CreateProcess  (0) 2025.05.17
04. Process  (0) 2025.05.15
02. Interrupt and Exception (1)  (0) 2025.05.12
01. Introduction to Operation System  (0) 2025.05.06
Comments