mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-18 07:17:49 +00:00
Update some broken anchor links (#1444)
This commit is contained in:
committed by
GitHub
parent
86c36479cf
commit
211f460251
@@ -643,7 +643,7 @@ extern "x86-interrupt" fn keyboard_interrupt_handler(
|
||||
El código anterior traduce las pulsaciones de las teclas numéricas 0-9 y ignora todas las otras teclas. Utiliza una declaración [match] para asignar un carácter o `None` a cada scancode. Luego, utiliza [`if let`] para desestructurar la opción `key`. Al usar el mismo nombre de variable `key` en el patrón, [somos sombras de] la declaración anterior, lo cual es un patrón común para desestructurar tipos `Option` en Rust.
|
||||
|
||||
[match]: https://doc.rust-lang.org/book/ch06-02-match.html
|
||||
[`if let`]: https://doc.rust-lang.org/book/ch18-01-all-the-places-for-patterns.html#conditional-if-let-expressions
|
||||
[`if let`]: https://doc.rust-lang.org/book/ch19-01-all-the-places-for-patterns.html#conditional-if-let-expressions
|
||||
[sombra]: https://doc.rust-lang.org/book/ch03-01-variables-and-mutabilidad.html#shadowing
|
||||
|
||||
Ahora podemos escribir números:
|
||||
|
||||
@@ -278,16 +278,16 @@ pub fn _print(args: fmt::Arguments) {
|
||||
|
||||
`WRITER` را قفل می کند، `write_fmt` را روی آن فراخوانی می کند و در انتهای تابع به طور ضمنی قفل آن را باز می کند. حال تصور کنید که در حالی که `WRITER` قفل شده است وقفه رخ دهد و کنترل کننده وقفه نیز سعی کند چیزی را چاپ کند:
|
||||
|
||||
Timestep | _start | interrupt_handler
|
||||
---------|------|------------------
|
||||
0 | calls `println!` |
|
||||
1 | `print` locks `WRITER` |
|
||||
2 | | **interrupt occurs**, handler begins to run
|
||||
3 | | calls `println!` |
|
||||
4 | | `print` tries to lock `WRITER` (already locked)
|
||||
5 | | `print` tries to lock `WRITER` (already locked)
|
||||
… | | …
|
||||
_never_ | _unlock `WRITER`_ |
|
||||
| Timestep | _start | interrupt_handler |
|
||||
| -------- | ---------------------- | ----------------------------------------------- |
|
||||
| 0 | calls `println!` | |
|
||||
| 1 | `print` locks `WRITER` | |
|
||||
| 2 | | **interrupt occurs**, handler begins to run |
|
||||
| 3 | | calls `println!` |
|
||||
| 4 | | `print` tries to lock `WRITER` (already locked) |
|
||||
| 5 | | `print` tries to lock `WRITER` (already locked) |
|
||||
| … | | … |
|
||||
| _never_ | _unlock `WRITER`_ |
|
||||
|
||||
`WRITER` قفل شده است ، بنابراین کنترل کننده وقفه منتظر می ماند تا آزاد شود. اما این هرگز اتفاق نمی افتد ، زیرا تابع `start_` فقط پس از بازگشت کنترل کننده وقفه ادامه می یابد. بنابراین کل سیستم هنگ است.
|
||||
|
||||
@@ -644,7 +644,7 @@ extern "x86-interrupt" fn keyboard_interrupt_handler(
|
||||
کد بالا فشردن کلیدهای عددی 9-0 را ترجمه کرده و کلیه کلیدهای دیگر را نادیده می گیرد. از عبارت [match] برای اختصاص یک کاراکتر یا `None` به هر اسکن کد استفاده می کند. سپس با استفاده از [`if let`] اپشن `key` را از بین می برد. با استفاده از همان نام متغیر `key` در الگو که یک روش معمول برای از بین بردن انواع`Option` در راست است تعریف قبلی را [سایه می زنیم].
|
||||
|
||||
[match]: https://doc.rust-lang.org/book/ch06-02-match.html
|
||||
[`if let`]: https://doc.rust-lang.org/book/ch18-01-all-the-places-for-patterns.html#conditional-if-let-expressions
|
||||
[`if let`]: https://doc.rust-lang.org/book/ch19-01-all-the-places-for-patterns.html#conditional-if-let-expressions
|
||||
[سایه می زنیم]: https://doc.rust-lang.org/book/ch03-01-variables-and-mutability.html#shadowing
|
||||
|
||||
اکنون می توانیم اعداد را بنویسیم:
|
||||
|
||||
@@ -277,16 +277,16 @@ pub fn _print(args: fmt::Arguments) {
|
||||
|
||||
_print 関数は `WRITER` をロックし、`write_fmt` を呼び出し、そして関数の最後で暗黙にロックを解放します。では、`WRITER` がロックされている間に割り込みが発生し、割り込みハンドラもなにかを表示しようとしていると想像してみてください:
|
||||
|
||||
時刻 | _start | 割り込みハンドラ
|
||||
---------|------|------------------
|
||||
0 | `println!` を呼び出す |
|
||||
1 | `print` が `WRITER` をロック |
|
||||
2 | | **割り込みが発生**、割り込みハンドラが動き出す
|
||||
3 | | `println!` を呼び出す |
|
||||
4 | | `print` が `WRITER` をロックしようとする (既にロック済み)
|
||||
5 | | `print` が `WRITER` をロックしようとする (既にロック済み)
|
||||
… | | …
|
||||
_(決して起こらない)_ | _`WRITER` のロックを解放する_ |
|
||||
| 時刻 | _start | 割り込みハンドラ |
|
||||
| -------------------- | ----------------------------- | --------------------------------------------------------- |
|
||||
| 0 | `println!` を呼び出す | |
|
||||
| 1 | `print` が `WRITER` をロック | |
|
||||
| 2 | | **割り込みが発生**、割り込みハンドラが動き出す |
|
||||
| 3 | | `println!` を呼び出す |
|
||||
| 4 | | `print` が `WRITER` をロックしようとする (既にロック済み) |
|
||||
| 5 | | `print` が `WRITER` をロックしようとする (既にロック済み) |
|
||||
| … | | … |
|
||||
| _(決して起こらない)_ | _`WRITER` のロックを解放する_ |
|
||||
|
||||
`WRITER` はロックされているので、割り込みハンドラはそれが解放されるのを待ちます。しかし `_start` 関数は割り込みハンドラから処理が戻らないと実行されることはないので、ロックが解放されることはありません。このためシステム全体がハングしてしまいます。
|
||||
|
||||
@@ -645,7 +645,7 @@ extern "x86-interrupt" fn keyboard_interrupt_handler(
|
||||
上記のコードは、0から9の数字キーが押された場合に変換を行い、それ以外のキーは無視します。全てのスキャンコードに対し、[match] 文を使って対応する文字か `None` を割り当てます。そのあと [`if let`] 構文を使ってオプション型の `key` から値を取り出します。パターン部分に `key` という同じ変数名を使うことでそれ以前の宣言を[シャドーイング][shadow]します。これは Rust において `Option` 型から値を取り出すときによく使うパターンです。
|
||||
|
||||
[match]: https://doc.rust-lang.org/book/ch06-02-match.html
|
||||
[`if let`]: https://doc.rust-lang.org/book/ch18-01-all-the-places-for-patterns.html#conditional-if-let-expressions
|
||||
[`if let`]: https://doc.rust-lang.org/book/ch19-01-all-the-places-for-patterns.html#conditional-if-let-expressions
|
||||
[shadow]: https://doc.rust-lang.org/book/ch03-01-variables-and-mutability.html#shadowing
|
||||
|
||||
これで数字が表示できるようになりました:
|
||||
|
||||
@@ -645,7 +645,7 @@ extern "x86-interrupt" fn keyboard_interrupt_handler(
|
||||
위 코드는 0-9의 숫자 키 누름을 인식하고 출력하며, 다른 키는 무시합니다. [match]문을 사용해 각 스캔코드에 문자 또는 `None`을 배정합니다. 그 후 [`if let`]을 사용해 스캔 코드에 배정된 문자 `key`를 추출합니다. 이미 존재하던 변수 `key`와 같은 이름을 패턴에서 사용해 기존 변수의 정의를 [shadow]하는데, 이는 Rust에서 `Option` 타입 안의 값을 추출할 때 자주 사용되는 방식입니다.
|
||||
|
||||
[match]: https://doc.rust-lang.org/book/ch06-02-match.html
|
||||
[`if let`]: https://doc.rust-lang.org/book/ch18-01-all-the-places-for-patterns.html#conditional-if-let-expressions
|
||||
[`if let`]: https://doc.rust-lang.org/book/ch19-01-all-the-places-for-patterns.html#conditional-if-let-expressions
|
||||
[shadow]: https://doc.rust-lang.org/book/ch03-01-variables-and-mutability.html#shadowing
|
||||
|
||||
이제 키보드로 숫자를 입력할 수 있습니다.
|
||||
|
||||
@@ -274,16 +274,16 @@ pub fn _print(args: fmt::Arguments) {
|
||||
|
||||
It locks the `WRITER`, calls `write_fmt` on it, and implicitly unlocks it at the end of the function. Now imagine that an interrupt occurs while the `WRITER` is locked and the interrupt handler tries to print something too:
|
||||
|
||||
Timestep | _start | interrupt_handler
|
||||
---------|------|------------------
|
||||
0 | calls `println!` |
|
||||
1 | `print` locks `WRITER` |
|
||||
2 | | **interrupt occurs**, handler begins to run
|
||||
3 | | calls `println!` |
|
||||
4 | | `print` tries to lock `WRITER` (already locked)
|
||||
5 | | `print` tries to lock `WRITER` (already locked)
|
||||
… | | …
|
||||
_never_ | _unlock `WRITER`_ |
|
||||
| Timestep | _start | interrupt_handler |
|
||||
| -------- | ---------------------- | ----------------------------------------------- |
|
||||
| 0 | calls `println!` | |
|
||||
| 1 | `print` locks `WRITER` | |
|
||||
| 2 | | **interrupt occurs**, handler begins to run |
|
||||
| 3 | | calls `println!` |
|
||||
| 4 | | `print` tries to lock `WRITER` (already locked) |
|
||||
| 5 | | `print` tries to lock `WRITER` (already locked) |
|
||||
| … | | … |
|
||||
| _never_ | _unlock `WRITER`_ |
|
||||
|
||||
The `WRITER` is locked, so the interrupt handler waits until it becomes free. But this never happens, because the `_start` function only continues to run after the interrupt handler returns. Thus, the entire system hangs.
|
||||
|
||||
@@ -640,7 +640,7 @@ extern "x86-interrupt" fn keyboard_interrupt_handler(
|
||||
The above code translates keypresses of the number keys 0-9 and ignores all other keys. It uses a [match] statement to assign a character or `None` to each scancode. It then uses [`if let`] to destructure the optional `key`. By using the same variable name `key` in the pattern, we [shadow] the previous declaration, which is a common pattern for destructuring `Option` types in Rust.
|
||||
|
||||
[match]: https://doc.rust-lang.org/book/ch06-02-match.html
|
||||
[`if let`]: https://doc.rust-lang.org/book/ch18-01-all-the-places-for-patterns.html#conditional-if-let-expressions
|
||||
[`if let`]: https://doc.rust-lang.org/book/ch19-01-all-the-places-for-patterns.html#conditional-if-let-expressions
|
||||
[shadow]: https://doc.rust-lang.org/book/ch03-01-variables-and-mutability.html#shadowing
|
||||
|
||||
Now we can write numbers:
|
||||
|
||||
@@ -280,16 +280,16 @@ pub fn _print(args: fmt::Arguments) {
|
||||
|
||||
Ela trava o `WRITER`, chama `write_fmt` nele, e implicitamente o destrava no final da função. Agora imagine que uma interrupção ocorre enquanto o `WRITER` está travado e o manipulador de interrupção tenta imprimir algo também:
|
||||
|
||||
Passo de Tempo | _start | interrupt_handler
|
||||
---------|------|------------------
|
||||
0 | chama `println!` |
|
||||
1 | `print` trava `WRITER` |
|
||||
2 | | **interrupção ocorre**, manipulador começa a executar
|
||||
3 | | chama `println!` |
|
||||
4 | | `print` tenta travar `WRITER` (já travado)
|
||||
5 | | `print` tenta travar `WRITER` (já travado)
|
||||
… | | …
|
||||
_nunca_ | _destravar `WRITER`_ |
|
||||
| Passo de Tempo | _start | interrupt_handler |
|
||||
| -------------- | ---------------------- | ----------------------------------------------------- |
|
||||
| 0 | chama `println!` | |
|
||||
| 1 | `print` trava `WRITER` | |
|
||||
| 2 | | **interrupção ocorre**, manipulador começa a executar |
|
||||
| 3 | | chama `println!` |
|
||||
| 4 | | `print` tenta travar `WRITER` (já travado) |
|
||||
| 5 | | `print` tenta travar `WRITER` (já travado) |
|
||||
| … | | … |
|
||||
| _nunca_ | _destravar `WRITER`_ |
|
||||
|
||||
O `WRITER` está travado, então o manipulador de interrupção espera até que se torne livre. Mas isso nunca acontece, porque a função `_start` só continua a executar após o manipulador de interrupção retornar. Assim, o sistema inteiro trava.
|
||||
|
||||
@@ -646,7 +646,7 @@ extern "x86-interrupt" fn keyboard_interrupt_handler(
|
||||
O código acima traduz pressionamentos das teclas numéricas 0-9 e ignora todas as outras teclas. Ele usa uma instrução [match] para atribuir um caractere ou `None` a cada scancode. Então usa [`if let`] para desestruturar o `key` opcional. Ao usar o mesmo nome de variável `key` no padrão, [sombreamos] a declaração anterior, que é um padrão comum para desestruturar tipos `Option` em Rust.
|
||||
|
||||
[match]: https://doc.rust-lang.org/book/ch06-02-match.html
|
||||
[`if let`]: https://doc.rust-lang.org/book/ch18-01-all-the-places-for-patterns.html#conditional-if-let-expressions
|
||||
[`if let`]: https://doc.rust-lang.org/book/ch19-01-all-the-places-for-patterns.html#conditional-if-let-expressions
|
||||
[sombreamos]: https://doc.rust-lang.org/book/ch03-01-variables-and-mutability.html#shadowing
|
||||
|
||||
Agora podemos escrever números:
|
||||
@@ -737,4 +737,4 @@ Agora somos capazes de interagir com nosso kernel e temos alguns blocos fundamen
|
||||
|
||||
Interrupções de timer são essenciais para um sistema operacional porque fornecem uma forma de interromper periodicamente o processo em execução e deixar o kernel retomar o controle. O kernel pode então mudar para um processo diferente e criar a ilusão de múltiplos processos executando em paralelo.
|
||||
|
||||
Mas antes de podermos criar processos ou threads, precisamos de uma forma de alocar memória para eles. As próximas postagens explorarão gerenciamento de memória para fornecer este bloco fundamental.
|
||||
Mas antes de podermos criar processos ou threads, precisamos de uma forma de alocar memória para eles. As próximas postagens explorarão gerenciamento de memória para fornecer este bloco fundamental.
|
||||
|
||||
@@ -646,7 +646,7 @@ extern "x86-interrupt" fn keyboard_interrupt_handler(
|
||||
以上代码可以对数字按键0-9进行转义,并忽略其他键位。具体到程序逻辑中,就是使用 [match] 匹配映射数字0-9,对于其他扫描码则返回 `None`,然后使用 [`if let`] 语句对 `key` 进行解构取值,在这个语法中,代码块中的 `key` 会 [遮蔽][shadow] 掉代码块外的同名 `Option` 型变量。
|
||||
|
||||
[match]: https://doc.rust-lang.org/book/ch06-02-match.html
|
||||
[`if let`]: https://doc.rust-lang.org/book/ch18-01-all-the-places-for-patterns.html#conditional-if-let-expressions
|
||||
[`if let`]: https://doc.rust-lang.org/book/ch19-01-all-the-places-for-patterns.html#conditional-if-let-expressions
|
||||
[shadow]: https://doc.rust-lang.org/book/ch03-01-variables-and-mutability.html#shadowing
|
||||
|
||||
现在我们就可以向控制台写入数字了:
|
||||
|
||||
Reference in New Issue
Block a user