요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
.. SPDX-License-Identifier: GPL-2.0
==========================================
Notes on register bank usage in the kernel
==========================================
Introduction
------------
The SH-3 and SH-4 CPU families traditionally include a single partial register
bank (selected by SR.RB, only r0 ... r7 are banked), whereas other families
may have more full-featured banking or simply no such capabilities at all.
SR.RB banking
-------------
In the case of this type of banking, banked registers are mapped directly to
r0 ... r7 if SR.RB is set to the bank we are interested in, otherwise ldc/stc
can still be used to reference the banked registers (as r0_bank ... r7_bank)
when in the context of another bank. The developer must keep the SR.RB value
in mind when writing code that utilizes these banked registers, for obvious
reasons. Userspace is also not able to poke at the bank1 values, so these can
be used rather effectively as scratch registers by the kernel.
Presently the kernel uses several of these registers.
- r0_bank, r1_bank (referenced as k0 and k1, used for scratch
registers when doing exception handling).
- r2_bank (used to track the EXPEVT/INTEVT code)
- Used by do_IRQ() and friends for doing irq mapping based off
of the interrupt exception vector jump table offset
- r6_bank (global interrupt mask)
- The SR.IMASK interrupt handler makes use of this to set the
interrupt priority level (used by local_irq_enable())
- r7_bank (current)
3. 한국어 전문 번역
영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.
SH register bank 개요
1-13SH-3과 SH-4 CPU family는 전통적으로 하나의 partial register bank를 포함합니다. 이 bank는 `SR.RB`로 선택하며 `r0`부터 `r7`까지만 banked register입니다. 다른 family는 더 완전한 banking 기능을 제공하거나 register bank 기능이 전혀 없을 수 있습니다.
SR.RB banking 동작
14-24이 banking 방식에서는 `SR.RB`가 관심 있는 bank를 선택한 상태이면 banked register가 `r0`부터 `r7`에 직접 mapping됩니다. 다른 bank context에서도 `ldc/stc`를 사용해 `r0_bank`부터 `r7_bank` 이름으로 banked register를 참조할 수 있습니다.
banked register를 사용하는 코드를 작성할 때는 `SR.RB` 값을 반드시 고려해야 합니다. user space는 `bank1` 값에 접근해 수정할 수 없으므로 kernel은 이를 scratch register로 효과적으로 활용할 수 있습니다.
kernel의 현재 banked register 용도
25-40현재 kernel은 다음 banked register를 사용합니다.
| register | 용도 |
|---|---|
| `r0_bank`, `r1_bank` | `k0`, `k1`으로 참조하며 exception handling 중 scratch register로 사용합니다. |
| `r2_bank` | `EXPEVT`/`INTEVT` code를 추적합니다. `do_IRQ()`와 관련 함수는 interrupt exception vector jump table offset을 바탕으로 IRQ를 mapping할 때 사용합니다. |
| `r6_bank` | global interrupt mask입니다. `SR.IMASK` interrupt handler가 `local_irq_enable()`에서 사용하는 interrupt priority level을 설정할 때 이용합니다. |
| `r7_bank` | `current`를 보관합니다. |
요약과 해설
register-banks.rst:1-40`SR.RB`가 선택한 bank의 `r0-r7`은 빠른 exception·interrupt 처리에 쓰입니다. user space가 `bank1`을 수정할 수 없어 kernel scratch와 상태 저장에 적합하지만, assembly code는 현재 `SR.RB`와 register 이름의 mapping을 항상 의식해야 합니다.