You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 01_Build_Process/01_Overview.md
+15-12Lines changed: 15 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,15 +6,14 @@ In this part we are going to explore all the tools and steps that are needed in
6
6
7
7
In this chapter we will have a global overview of the build process, touching briefly what are the steps involved, and the tools that are going to be used.
8
8
9
-
Then in the [Boots Protocols and Bootloaders](02_Boot_Protocols.md) chapter we will explore in detail how to boot a kernel, and describe two options that can be used for the boot process: Multiboot and Stivale.
9
+
Then in the [Boots Protocols and Bootloaders](02_Boot_Protocols.md) chapter we will explore in detail how to boot a kernel, and describe two options that can be used for the boot process: Multiboot and Limine.
10
10
11
11
The [Makefiles](04_Gnu_Makefiles.md) chapter will explain how to build a process, even if initially is just a bunch of file and it can be done manually, it soon grow more complex, and having the process automated will be more than useful, we will use _Makefile_ for our build script.
12
12
13
13
One of the most _obscure_, that is always present while building any software, but is hidden to us until we start to roll up our own kernel is the _linking process_. The [Linker Scripts](05_Linker_Scripts.md) chapter will introduce us to the world of _linking_ files and explain how to write a linker script.
14
14
15
15
Finally the kernel is built but not ready to run yet, we need to copy it into a bootable media, the [Generating A Bootable Iso](06_Generating_Iso.md) chapter will show how to create a bootable iso of our kernel, and finally being able to launch it and see the results of our hard work.
16
16
17
-
18
17
For the rest of this part a basic knowledge of compiling these languages is assumed.
19
18
20
19
## Freestanding Environment
@@ -49,15 +48,17 @@ However, each GCC toolchain will use the platform-specific headers by default, w
49
48
Compiling GCC from source doesn't take too long on a modern CPU (~10 minutes for a complete build on a 7th gen intel mobile cpu, 4 cores), however there are also prebuilt binaries online from places like bootlin, see the useful links appendix for .
50
49
51
50
## Setting up a build environment
51
+
52
52
Setting up a proper build environment can be broken down into a few steps:
53
53
54
-
- Setup a cross compilation toolchain.
54
+
- Setup a cross compilation toolchain (refer to the [Appendix E: Cross Platform Building](../99_Appendices/E_Cross_Compilers.md).
55
55
- Install an emulator.
56
56
- Install any additional tools.
57
57
- Setup the bootloader of choice.
58
58
- Run a hello world to check everything works.
59
59
60
60
### Getting a Cross Compiler
61
+
61
62
The easiest approach here is to simply use clang. Clang is designed to be a cross compiler, and so any install of clang can compile to any supported platform.
62
63
To compile for another platform simply invoke clang as normally would, additionally passing `--target=xyz`, where xyz is the target triplet for the target platform.
63
64
@@ -80,6 +81,7 @@ The following sections will use the common shorthands to keep things simple:
80
81
If using clang be sure to remember to pass `--target=xyz` with each command. This is not necessary with GCC.
81
82
82
83
### Building C Source Files
84
+
83
85
Now that we have a toolchain setup we can test it all works by compiling a C file.
84
86
Create a C source file, its contents don't matter here as we wont be running it, just telling it compiles.
85
87
@@ -212,9 +214,9 @@ Getting access to these debug symbols is dependent on the boot protocol used:
212
214
213
215
Multiboot 2 provides the Elf-Symbols (section 3.6.7 of the spec) tag to the kernel which provides the elf section headers and the location of the string table. Using these is described below in the stivale section.
214
216
215
-
### Stivale 2
217
+
### Limine Protocol
216
218
217
-
Stivale2 uses a similar and slightly more complex (but more powerful) mechanism of providing the entire kernel file in memory. This means we're not limited to just using elf files, and can access debug symbols from a kernel in any format. This is because we have the file base address and length and have to do the parsing by ourselves.
219
+
Limine uses a similar and slightly more complex (but more powerful) mechanism of providing the entire kernel file in memory.
218
220
219
221
### ELFs Ahead, Beware!
220
222
@@ -239,18 +241,19 @@ Languages built around the C model will usually perform some kind of name mangli
239
241
240
242
### Locating The Symbol Table
241
243
242
-
We'll need to access the data stored in the string table quite frequently for looking up symbols, so let's calculate that and store it in the variable `char* strtab_data`. For both protocols it's assumed that we have found the tag returned by the bootloader that contains the location of the elf file/elf symbols.
244
+
We'll need to access the data stored in the string table quite frequently for looking up symbols, so let's calculate that and store it in the variable `char* strtab_data`. For both protocols it's assumed that we have found the tag returned by the bootloader that contains the location of the elf file/elf symbols (for more details, see the [Boot Protocols](./02_Boot_Protocols.md) chapter.
A quick note about getting the symbol table data address: On multiboot `sym_tab->sh_offset` will be the physical address of the data, while stivale2 will return the original value, which is an offset from the beginning of the file. This means for stivale 2 we would add `file_tag->kernel_base` to this address to get its location in memory.
294
+
A quick note about getting the symbol table data address: On multiboot `sym_tab->sh_offset` will be the physical address of the data, while limine protocol will return the original value, which is an offset from the beginning of the file. This means for limine protocol we need to add `kernel_file->address` to this address to get its location in memory.
0 commit comments