More link.ld -> kernel.ld renaming

pull/158/head
Andre Richter 2 years ago
parent 6e3051e6fd
commit b836655d66
No known key found for this signature in database
GPG Key ID: 2116C1AB102F615E

@ -14,7 +14,7 @@
- `nm`: 检查符号。 - `nm`: 检查符号。
- 代码按照 `kernel` `arch``BSP` (板级支持包)的形式组织。 - 代码按照 `kernel` `arch``BSP` (板级支持包)的形式组织。
- 条件编译会根据用户提供的参数编译各自的 `arch``BSP` 的内容。 - 条件编译会根据用户提供的参数编译各自的 `arch``BSP` 的内容。
- 自定义 `link.ld` 链接脚本. - 自定义 `kernel.ld` 链接脚本.
- 载入地址为 `0x80_000` - 载入地址为 `0x80_000`
- 目前仅有 `.text` 小节section - 目前仅有 `.text` 小节section
- `main.rs`: 重要的 [inner attributes]: - `main.rs`: 重要的 [inner attributes]:

@ -9,37 +9,37 @@
## Compilar ## Compilar
* El archivo `Makefile` permite ejecutar: * El archivo `Makefile` permite ejecutar:
* `doc`: Genera la documentación. * `doc`: Genera la documentación.
* `qemu`: Ejecutar el kernel en QEMU. * `qemu`: Ejecutar el kernel en QEMU.
* `clippy`: Analiza el código y sugiere mejoras. * `clippy`: Analiza el código y sugiere mejoras.
* `clean`: Elimina todos los archivos generados durante la compilación, etc. * `clean`: Elimina todos los archivos generados durante la compilación, etc.
* `readelf`: Inspecciona el archivo `ELF` de salida. * `readelf`: Inspecciona el archivo `ELF` de salida.
* `objdump`: Inspecciona el ensamblador. * `objdump`: Inspecciona el ensamblador.
* `nm`: Inspecciona los símbolos. * `nm`: Inspecciona los símbolos.
## Código a revisar ## Código a revisar
* El script para enlazado específico para la `BSP` llamado `link.ld`. * El script para enlazado específico para la `BSP` llamado `kernel.ld`.
* Carga la dirección en `0x8_0000`. * Carga la dirección en `0x8_0000`.
* Solo la sección `.text`. * Solo la sección `.text`.
* `main.rs`: [Atributos internos](https://doc.rust-lang.org/reference/attributes.html) importantes: * `main.rs`: [Atributos internos](https://doc.rust-lang.org/reference/attributes.html) importantes:
* `#![no_std]`, `#![no_main]`. * `#![no_std]`, `#![no_main]`.
* `boot.s`: La función de ensamblador `_start()` que inicia `wfe` (Wait For Event / Esperar Hasta Un Evento), detiene todos los núcleos del procesador que están ejecutando `_start()`. * `boot.s`: La función de ensamblador `_start()` que inicia `wfe` (Wait For Event / Esperar Hasta Un Evento), detiene todos los núcleos del procesador que están ejecutando `_start()`.
* Tenemos que definir una función que funcione como `#[panic_handler]` (manejador de pánico) para que el compilador no nos cause problemas. * Tenemos que definir una función que funcione como `#[panic_handler]` (manejador de pánico) para que el compilador no nos cause problemas.
* Hazla `unimplemented!()` porque se eliminará ya que no está siendo usada. * Hazla `unimplemented!()` porque se eliminará ya que no está siendo usada.
## Pruébalo ## Pruébalo

@ -8,7 +8,7 @@
## Adiciones importantes ## Adiciones importantes
* Adiciones importantes al script `link.ld`: * Adiciones importantes al script `kernel.ld`:
* Nuevas secciones: `.rodata`, `.got`, `.data`, `.bss`. * Nuevas secciones: `.rodata`, `.got`, `.data`, `.bss`.

@ -17,8 +17,8 @@ at the source code changes.
The gist of it is that in `boot.s`, we are writing a piece of [position independent code] which The gist of it is that in `boot.s`, we are writing a piece of [position independent code] which
automatically determines where the firmware has loaded the binary (`0x8_0000`), and where it was automatically determines where the firmware has loaded the binary (`0x8_0000`), and where it was
linked to (`0x200_0000`, see `link.ld`). The binary then copies itself from loaded to linked address linked to (`0x200_0000`, see `kernel.ld`). The binary then copies itself from loaded to linked
(aka "relocating" itself), and then jumps to the relocated version of `_start_rust()`. address (aka "relocating" itself), and then jumps to the relocated version of `_start_rust()`.
Since the chainloader has put itself "out of the way" now, it can now receive another kernel binary Since the chainloader has put itself "out of the way" now, it can now receive another kernel binary
from the `UART` and copy it to the standard load address of the RPi firmware at `0x8_0000`. Finally, from the `UART` and copy it to the standard load address of the RPi firmware at `0x8_0000`. Finally,
@ -27,8 +27,9 @@ from SD card all along.
Please bear with me until I find the time to write it all down here elaborately. For the time being, Please bear with me until I find the time to write it all down here elaborately. For the time being,
please see this tutorial as an enabler for a convenience feature that allows booting the following please see this tutorial as an enabler for a convenience feature that allows booting the following
tutorials in a quick manner. _For those keen to get a deeper understanding, it could make sense to skip forward to [Chapter 15](../15_virtual_mem_part3_precomputed_tables) and read the first half of the README, tutorials in a quick manner. _For those keen to get a deeper understanding, it could make sense to
where `Load Address != Link Address` is discussed_. skip forward to [Chapter 15](../15_virtual_mem_part3_precomputed_tables) and read the first half of
the README, where `Load Address != Link Address` is discussed_.
[position independent code]: https://en.wikipedia.org/wiki/Position-independent_code [position independent code]: https://en.wikipedia.org/wiki/Position-independent_code

@ -14,7 +14,7 @@
* [Generic Kernel code: `memory/mmu.rs`](#generic-kernel-code-memorymmurs) * [Generic Kernel code: `memory/mmu.rs`](#generic-kernel-code-memorymmurs)
* [BSP: `bsp/raspberrypi/memory/mmu.rs`](#bsp-bspraspberrypimemorymmurs) * [BSP: `bsp/raspberrypi/memory/mmu.rs`](#bsp-bspraspberrypimemorymmurs)
* [AArch64: `_arch/aarch64/memory/*`](#aarch64-_archaarch64memory) * [AArch64: `_arch/aarch64/memory/*`](#aarch64-_archaarch64memory)
* [`link.ld`](#linkld) * [`kernel.ld`](#kernelld)
- [Address translation examples](#address-translation-examples) - [Address translation examples](#address-translation-examples)
* [Address translation using a 64 KiB page descriptor](#address-translation-using-a-64-kib-page-descriptor) * [Address translation using a 64 KiB page descriptor](#address-translation-using-a-64-kib-page-descriptor)
- [Zero-cost abstraction](#zero-cost-abstraction) - [Zero-cost abstraction](#zero-cost-abstraction)
@ -222,7 +222,7 @@ enables caching for data and instructions.
[Translation Control Register - EL1]: https://docs.rs/crate/cortex-a/5.1.2/source/src/regs/tcr_el1.rs [Translation Control Register - EL1]: https://docs.rs/crate/cortex-a/5.1.2/source/src/regs/tcr_el1.rs
[System Control Register - EL1]: https://docs.rs/crate/cortex-a/5.1.2/source/src/regs/sctlr_el1.rs [System Control Register - EL1]: https://docs.rs/crate/cortex-a/5.1.2/source/src/regs/sctlr_el1.rs
### `link.ld` ### `kernel.ld`
We need to align the `code` segment to `64 KiB` so that it doesn't overlap with the next section We need to align the `code` segment to `64 KiB` so that it doesn't overlap with the next section
that needs read/write attributes instead of read/execute attributes: that needs read/write attributes instead of read/execute attributes:

@ -118,7 +118,7 @@ Here are the compilation steps and the corresponding `objdump` for `AArch64`:
```console ```console
$ clang --target=aarch64-none-elf -Iinclude -Wall -c start.c -o start.o $ clang --target=aarch64-none-elf -Iinclude -Wall -c start.c -o start.o
$ ld.lld start.o -T link.ld -o example.elf $ ld.lld start.o -T kernel.ld -o example.elf
``` ```
```c-objdump ```c-objdump
@ -326,7 +326,7 @@ space:
```console ```console
$ clang --target=aarch64-none-elf -Iinclude -Wall -fpic -c start.c -o start.o $ clang --target=aarch64-none-elf -Iinclude -Wall -fpic -c start.c -o start.o
$ ld.lld start.o -T link.ld -o example.elf $ ld.lld start.o -T kernel.ld -o example.elf
``` ```
```c-objdump ```c-objdump
@ -473,7 +473,7 @@ the precompute use-case. The additional `#[no_mangle]` is added because we will
symbol from the `translation table tool`, and this is easier with unmangled names. symbol from the `translation table tool`, and this is easier with unmangled names.
In the `BSP` code, there is also a new file called `kernel_virt_addr_space_size.ld`, which contains In the `BSP` code, there is also a new file called `kernel_virt_addr_space_size.ld`, which contains
the kernel's virtual address space size. This file gets included in both, the `link.ld` linker the kernel's virtual address space size. This file gets included in both, the `kernel.ld` linker
script and `mmu.rs`. We need this value both as a symbol in the kernel's ELF (for the `translation script and `mmu.rs`. We need this value both as a symbol in the kernel's ELF (for the `translation
table tool` to parse it later) and as a constant in the `Rust` code. This inclusion approach is just table tool` to parse it later) and as a constant in the `Rust` code. This inclusion approach is just
a convenience hack that turned out working well. a convenience hack that turned out working well.

Loading…
Cancel
Save