From 49625488e5691bd65ba11f837b906be9ad9e9cc2 Mon Sep 17 00:00:00 2001 From: Hudd Date: Sun, 1 Feb 2015 15:49:16 +0000 Subject: [PATCH 1/5] Part 3: Fix URLs Some links to the previous part were broken. --- Booting/linux-bootstrap-3.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Booting/linux-bootstrap-3.md b/Booting/linux-bootstrap-3.md index 32e10ba..023fed7 100644 --- a/Booting/linux-bootstrap-3.md +++ b/Booting/linux-bootstrap-3.md @@ -4,9 +4,9 @@ Kernel booting process. Part 3. Video mode initialization and transition to protected mode -------------------------------------------------------------------------------- -This is the third part of the `Kernel booting process` series. In the previous [part](https://github.com/0xAX/linux-insides/blob/master/linux-bootstrap-2.md#kernel-booting-process-part-2), we stopped right before the call of the `set_video` routine from the [main.c](https://github.com/torvalds/linux/blob/master/arch/x86/boot/main.c#L181). We will see video mode initialization in the kernel setup code, preparation before switching into the protected mode and transition into it in this part. +This is the third part of the `Kernel booting process` series. In the previous [part](https://github.com/0xAX/linux-insides/blob/master/Booting/linux-bootstrap-2.md#kernel-booting-process-part-2), we stopped right before the call of the `set_video` routine from the [main.c](https://github.com/torvalds/linux/blob/master/arch/x86/boot/main.c#L181). We will see video mode initialization in the kernel setup code, preparation before switching into the protected mode and transition into it in this part. -**NOTE** If you don't know anything about protected mode, you can find some information about it in the previous [part](https://github.com/0xAX/linux-insides/blob/master/linux-bootstrap-2.md#protected-mode). Also there are a couple of [links](https://github.com/0xAX/linux-insides/blob/master/linux-bootstrap-2.md#links) which can help you. +**NOTE** If you don't know anything about protected mode, you can find some information about it in the previous [part](https://github.com/0xAX/linux-insides/blob/master/Booting/linux-bootstrap-2.md#protected-mode). Also there are a couple of [links](https://github.com/0xAX/linux-insides/blob/master/Booting/linux-bootstrap-2.md#links) which can help you. As i wrote above, we will start from the `set_video` function which defined in the [arch/x86/boot/video.c](https://github.com/torvalds/linux/blob/master/arch/x86/boot/video.c#L315) source code file. We can see that it starts with getting of video mode from the `boot_params.hdr` structure: @@ -118,7 +118,7 @@ static inline bool heap_free(size_t n) } ``` -which subtracts value of the `HEAP` from the `heap_end` (we calculated it in the previous [part](https://github.com/0xAX/linux-insides/blob/master/linux-bootstrap-2.md)) and returns 1 if there is enough memory for `n`. +which subtracts value of the `HEAP` from the `heap_end` (we calculated it in the previous [part](https://github.com/0xAX/linux-insides/blob/master/Booting/linux-bootstrap-2.md)) and returns 1 if there is enough memory for `n`. That's all. Now we have simple API for heap and can setup video mode. @@ -351,7 +351,7 @@ where we can see - 16-bit length of IDT and 32-bit pointer to it (More details a Setup Global Descriptor Table -------------------------------------------------------------------------------- -The next point is setup of the Global Descriptor Table (GDT). We can see `setup_gdt` function which setups GDT (you can read about it in the [Kernel booting process. Part 2.](https://github.com/0xAX/linux-insides/blob/master/linux-bootstrap-2.md#protected-mode)). There is definition of the `boot_gdt` array in this function, which contains definition of the three segments: +The next point is setup of the Global Descriptor Table (GDT). We can see `setup_gdt` function which setups GDT (you can read about it in the [Kernel booting process. Part 2.](https://github.com/0xAX/linux-insides/blob/master/Booting/linux-bootstrap-2.md#protected-mode)). There is definition of the `boot_gdt` array in this function, which contains definition of the three segments: ```C static const u64 boot_gdt[] __attribute__((aligned(16))) = { @@ -421,7 +421,7 @@ in binary. Let's try to understand what every bit means. We will go through all * 101 - segment type execute/read/ * 1 - accessed bit -You can know more about every bit in the previous [post](https://github.com/0xAX/linux-insides/blob/master/linux-bootstrap-2.md) or in the [Intel® 64 and IA-32 Architectures Software Developer’s Manuals 3A](http://www.intel.com/content/www/us/en/processors/architectures-software-developer-manuals.html). +You can know more about every bit in the previous [post](https://github.com/0xAX/linux-insides/blob/master/Booting/linux-bootstrap-2.md) or in the [Intel® 64 and IA-32 Architectures Software Developer’s Manuals 3A](http://www.intel.com/content/www/us/en/processors/architectures-software-developer-manuals.html). After this we get length of GDT with: From 18490a9d67d63047ccf4e2821b7c9c9ae0d9f3d5 Mon Sep 17 00:00:00 2001 From: Hudd Date: Sun, 1 Feb 2015 15:57:11 +0000 Subject: [PATCH 2/5] Part 3: Put period at the end of the sentence --- Booting/linux-bootstrap-3.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Booting/linux-bootstrap-3.md b/Booting/linux-bootstrap-3.md index 023fed7..376c5f7 100644 --- a/Booting/linux-bootstrap-3.md +++ b/Booting/linux-bootstrap-3.md @@ -265,7 +265,7 @@ We can see the last function call - `go_to_protected_mode` in the [main.c](https `go_to_protected_mode` defined in the [arch/x86/boot/pm.c](https://github.com/torvalds/linux/blob/master/arch/x86/boot/pm.c#L104). It contains some functions which make last preparations before we can jump into protected mode, so let's look on it and try to understand what they do and how it works. -At first we see call of `realmode_switch_hook` function in the `go_to_protected_mode`. This function invokes real mode switch hook if it is present and disables [NMI](http://en.wikipedia.org/wiki/Non-maskable_interrupt). Hooks are used if bootloader runs in a hostile environment More about hooks you can read in the [boot protocol](https://www.kernel.org/doc/Documentation/x86/boot.txt) (see **ADVANCED BOOT LOADER HOOKS**). `readlmode_swtich` hook presents pointer to the 16-bit real mode far subroutine which disables non-maskable interruptions. After we checked `realmode_switch` hook (it doesn't present for me), there is disabling of non-maskable interruptions: +At first we see call of `realmode_switch_hook` function in the `go_to_protected_mode`. This function invokes real mode switch hook if it is present and disables [NMI](http://en.wikipedia.org/wiki/Non-maskable_interrupt). Hooks are used if bootloader runs in a hostile environment. More about hooks you can read in the [boot protocol](https://www.kernel.org/doc/Documentation/x86/boot.txt) (see **ADVANCED BOOT LOADER HOOKS**). `readlmode_swtich` hook presents pointer to the 16-bit real mode far subroutine which disables non-maskable interruptions. After we checked `realmode_switch` hook (it doesn't present for me), there is disabling of non-maskable interruptions: ```assembly asm volatile("cli"); From 2cc46df9ed252786135876f122e5f560dcb32f9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonatan=20P=C3=A5lsson?= Date: Mon, 2 Feb 2015 09:42:37 +0100 Subject: [PATCH 3/5] Update linux-bootstrap-2.md Fixed some typos --- Booting/linux-bootstrap-2.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Booting/linux-bootstrap-2.md b/Booting/linux-bootstrap-2.md index 9232b1b..cd02e62 100644 --- a/Booting/linux-bootstrap-2.md +++ b/Booting/linux-bootstrap-2.md @@ -9,9 +9,9 @@ We started to dive into linux kernel internals in the previous [part](https://gi Protected mode -------------------------------------------------------------------------------- -Before we can move to the native Intel64 [Long mode](http://en.wikipedia.org/wiki/Long_mode), the kernel must switch the CPU into protected mode. What is it protected mode? Protected mode was first added to the x86 architecture in 1982 and was the main mode of Intel processors from [80286](http://en.wikipedia.org/wiki/Intel_80286) processor until Intel 64 and long mode. Main reason to move from the real mode that there is very limited access to the RAM. As you can remember from the previous part, there is only 2^20 bytes or 1 megabyte, or even less 640 kilobytes. +Before we can move to the native Intel64 [Long mode](http://en.wikipedia.org/wiki/Long_mode), the kernel must switch the CPU into protected mode. What is protected mode? Protected mode was first added to the x86 architecture in 1982 and was the main mode of Intel processors from [80286](http://en.wikipedia.org/wiki/Intel_80286) processor until Intel 64 and long mode. Main reason to move from the real mode that there is very limited access to the RAM. As you can remember from the previous part, there is only 2^20 bytes or 1 megabyte, or even less 640 kilobytes. -Protected mode brought many changes, but main is another memory management. 24-bit address bus was replaced with 32-bit address bus. It gives 4 gigabytes of physical address. Also [paging](http://en.wikipedia.org/wiki/Paging) support was added which we will see in the next parts. +Protected mode brought many changes, but main is another memory management. 24-bit address bus was replaced with 32-bit address bus. It gives 4 gigabytes of physical address. Also [paging](http://en.wikipedia.org/wiki/Paging) support was added which we will see in the next parts. Memory management in the protected mode is divided into two, almost independent parts: @@ -35,7 +35,7 @@ Memory segmentation was completely redone in the protected mode. There are no 64 lgdt gdt ``` -where `lgdt` instruction loads base address and limit of global descriptor table to the `GDTR` register. `GDTR` is 48-bit register and consists of two parts: +where the `lgdt` instruction loads base address and limit of global descriptor table to the `GDTR` register. `GDTR` is 48-bit register and consists of two parts: * size - 16 bit of global descriptor table; * address - 32-bit of the global descriptor table. From 71c66d5c7756e3d4e49096c47644f9f6e9c1ff83 Mon Sep 17 00:00:00 2001 From: George Horrell Date: Mon, 2 Feb 2015 18:00:32 +0000 Subject: [PATCH 4/5] grammar fixes to README, CONTRIBUTING and SUMMARY --- CONTRIBUTING.md | 4 ++-- README.md | 8 ++++---- contributors.md | 1 + 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6121504..310c0b6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,7 +1,7 @@ Contributing ================================================================================ -If you want to contribute to the [linux-insides](https://github.com/0xAX/linux-insides), you can do it with following simple rules: +If you want to contribute to [linux-insides](https://github.com/0xAX/linux-insides), please follow these simple rules: 1. Press fork button: @@ -25,6 +25,6 @@ If you want to contribute to the [linux-insides](https://github.com/0xAX/linux-i **IMPORTANT** -Please, do the actual changes. While you made your changes, I can merge changes from somebody else and your changes can conflict with `master` branch content. Please rebase on master everytime before you're going to push your changes and check that your branch doesn't conflict with `master`. +Please, make the actual changes. While you made your changes, I can merge changes from somebody else and your changes can conflict with `master` branch content. Please rebase on master everytime before you're going to push your changes and check that your branch doesn't conflict with `master`. Thank you. \ No newline at end of file diff --git a/README.md b/README.md index 646ea4f..4efddd7 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,15 @@ linux-internals =============== -Series of posts about linux kernel. +A series of posts about the linux kernel. -**Goal is simple** - to share my modest knowledge about linux kernel internals and help people who are interested in low-level stuff and linux kernel as me. +**The goal is simple** - to share my modest knowledge about the internals of the linux kernel and help people who are interested in the linux kernel, and other low-level subject matter. **Questions/Suggestions**: Feel free about any questions or suggestions by pinging me at twitter [@0xAX](https://twitter.com/0xAX), adding [issue](https://github.com/0xAX/linux-internals/issues/new) or just drop me [email](anotherworldofworld@gmail.com). -**Contributions**: Feel free to create issues or create pull-requests if you find issues or my English is poor. +**Contributions**: Feel free to create issues or create pull-requests if you find any issues or my English is poor. -**Please read [CONTRIBUTING.md](https://github.com/0xAX/linux-insides/blob/master/CONTRIBUTING.md) before you pushed your changes.** +**Please read [CONTRIBUTING.md](https://github.com/0xAX/linux-insides/blob/master/CONTRIBUTING.md) before pushing any changes.** ![image](http://oi58.tinypic.com/23upobq.jpg) diff --git a/contributors.md b/contributors.md index 89c2699..21c5eee 100644 --- a/contributors.md +++ b/contributors.md @@ -20,3 +20,4 @@ Thank you to all contributors: * [Haddayn](https://github.com/Haddayn) * [Daniel Campoverde Carrión](https://github.com/alx741) * [Guillaume Gomez](https://github.com/GuillaumeGomez) +* [George Horrell](https://github.com/georgehorrell) \ No newline at end of file From 3047f17d086f1f4457501f0b9f95f06da2289608 Mon Sep 17 00:00:00 2001 From: Hudd Date: Mon, 2 Feb 2015 19:50:03 +0000 Subject: [PATCH 5/5] Make links to other parts relative Links to other parts had absolute URLs, so they were pointing to the same page, regardless of where they were located. E.g. pages on gitbooks links to github. Make them relative, so they are pointing to the host on which the are located. --- Booting/linux-bootstrap-2.md | 6 +++--- Booting/linux-bootstrap-3.md | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Booting/linux-bootstrap-2.md b/Booting/linux-bootstrap-2.md index cd02e62..a3df557 100644 --- a/Booting/linux-bootstrap-2.md +++ b/Booting/linux-bootstrap-2.md @@ -4,7 +4,7 @@ Kernel booting process. Part 2. First steps in the kernel setup -------------------------------------------------------------------------------- -We started to dive into linux kernel internals in the previous [part](https://github.com/0xAX/linux-insides/blob/master/Booting/linux-bootstrap-1.md) and saw the initial part of the kernel setup code. We stopped at the first call of the `main` function (which is the first function written in C) from [arch/x86/boot/main.c](https://github.com/torvalds/linux/blob/master/arch/x86/boot/main.c). Here we will continue to research of the kernel setup code and see what is `protected mode`, some preparation for transition to it, the heap and console initialization, memory detection and many many more. So... Let's go ahead. +We started to dive into linux kernel internals in the previous [part](linux-bootstrap-1.md) and saw the initial part of the kernel setup code. We stopped at the first call of the `main` function (which is the first function written in C) from [arch/x86/boot/main.c](https://github.com/torvalds/linux/blob/master/arch/x86/boot/main.c). Here we will continue to research of the kernel setup code and see what is `protected mode`, some preparation for transition to it, the heap and console initialization, memory detection and many many more. So... Let's go ahead. Protected mode -------------------------------------------------------------------------------- @@ -266,7 +266,7 @@ After that `biosregs` structure filled with `memset`, `bios_putchar` calls [0x10 Heap initialization -------------------------------------------------------------------------------- -After the stack and bss section were prepared in the [header.S](https://github.com/torvalds/linux/blob/master/arch/x86/boot/header.S) (see previous [part](https://github.com/0xAX/linux-insides/blob/master/Booting/linux-bootstrap-1.md)), need to initialize the [heap](https://github.com/torvalds/linux/blob/master/arch/x86/boot/main.c#L116) with the [init_heap](https://github.com/torvalds/linux/blob/master/arch/x86/boot/main.c#L116) function. +After the stack and bss section were prepared in the [header.S](https://github.com/torvalds/linux/blob/master/arch/x86/boot/header.S) (see previous [part](linux-bootstrap-1.md)), need to initialize the [heap](https://github.com/torvalds/linux/blob/master/arch/x86/boot/main.c#L116) with the [init_heap](https://github.com/torvalds/linux/blob/master/arch/x86/boot/main.c#L116) function. First of all `init_heap` checks `CAN_USE_HEAP` flag from the `loadflags` kernel setup header and calculates end of the stack if this flag was set: @@ -464,4 +464,4 @@ Links * [Intel SpeedStep](http://en.wikipedia.org/wiki/SpeedStep) * [APM](https://en.wikipedia.org/wiki/Advanced_Power_Management) * [EDD specification](http://www.t13.org/documents/UploadedDocuments/docs2004/d1572r3-EDD3.pdf) -* [Previous part](https://github.com/0xAX/linux-insides/blob/master/Booting/linux-bootstrap-1.md) +* [Previous part](linux-bootstrap-1.md) diff --git a/Booting/linux-bootstrap-3.md b/Booting/linux-bootstrap-3.md index 376c5f7..8cc25ac 100644 --- a/Booting/linux-bootstrap-3.md +++ b/Booting/linux-bootstrap-3.md @@ -4,9 +4,9 @@ Kernel booting process. Part 3. Video mode initialization and transition to protected mode -------------------------------------------------------------------------------- -This is the third part of the `Kernel booting process` series. In the previous [part](https://github.com/0xAX/linux-insides/blob/master/Booting/linux-bootstrap-2.md#kernel-booting-process-part-2), we stopped right before the call of the `set_video` routine from the [main.c](https://github.com/torvalds/linux/blob/master/arch/x86/boot/main.c#L181). We will see video mode initialization in the kernel setup code, preparation before switching into the protected mode and transition into it in this part. +This is the third part of the `Kernel booting process` series. In the previous [part](linux-bootstrap-2.md#kernel-booting-process-part-2), we stopped right before the call of the `set_video` routine from the [main.c](https://github.com/torvalds/linux/blob/master/arch/x86/boot/main.c#L181). We will see video mode initialization in the kernel setup code, preparation before switching into the protected mode and transition into it in this part. -**NOTE** If you don't know anything about protected mode, you can find some information about it in the previous [part](https://github.com/0xAX/linux-insides/blob/master/Booting/linux-bootstrap-2.md#protected-mode). Also there are a couple of [links](https://github.com/0xAX/linux-insides/blob/master/Booting/linux-bootstrap-2.md#links) which can help you. +**NOTE** If you don't know anything about protected mode, you can find some information about it in the previous [part](linux-bootstrap-2.md#protected-mode). Also there are a couple of [links](linux-bootstrap-2.md#links) which can help you. As i wrote above, we will start from the `set_video` function which defined in the [arch/x86/boot/video.c](https://github.com/torvalds/linux/blob/master/arch/x86/boot/video.c#L315) source code file. We can see that it starts with getting of video mode from the `boot_params.hdr` structure: @@ -118,7 +118,7 @@ static inline bool heap_free(size_t n) } ``` -which subtracts value of the `HEAP` from the `heap_end` (we calculated it in the previous [part](https://github.com/0xAX/linux-insides/blob/master/Booting/linux-bootstrap-2.md)) and returns 1 if there is enough memory for `n`. +which subtracts value of the `HEAP` from the `heap_end` (we calculated it in the previous [part](linux-bootstrap-2.md)) and returns 1 if there is enough memory for `n`. That's all. Now we have simple API for heap and can setup video mode. @@ -351,7 +351,7 @@ where we can see - 16-bit length of IDT and 32-bit pointer to it (More details a Setup Global Descriptor Table -------------------------------------------------------------------------------- -The next point is setup of the Global Descriptor Table (GDT). We can see `setup_gdt` function which setups GDT (you can read about it in the [Kernel booting process. Part 2.](https://github.com/0xAX/linux-insides/blob/master/Booting/linux-bootstrap-2.md#protected-mode)). There is definition of the `boot_gdt` array in this function, which contains definition of the three segments: +The next point is setup of the Global Descriptor Table (GDT). We can see `setup_gdt` function which setups GDT (you can read about it in the [Kernel booting process. Part 2.](linux-bootstrap-2.md#protected-mode)). There is definition of the `boot_gdt` array in this function, which contains definition of the three segments: ```C static const u64 boot_gdt[] __attribute__((aligned(16))) = { @@ -389,7 +389,7 @@ int main(void) Technically structure which contains one `int` field, must be 4 bytes, but here `aligned` structure will be 16 bytes: ``` -$ gcc test.c -o test && ./test +$ gcc test.c -o test && test Not aligned - 4 Aligned - 16 ``` @@ -421,7 +421,7 @@ in binary. Let's try to understand what every bit means. We will go through all * 101 - segment type execute/read/ * 1 - accessed bit -You can know more about every bit in the previous [post](https://github.com/0xAX/linux-insides/blob/master/Booting/linux-bootstrap-2.md) or in the [Intel® 64 and IA-32 Architectures Software Developer’s Manuals 3A](http://www.intel.com/content/www/us/en/processors/architectures-software-developer-manuals.html). +You can know more about every bit in the previous [post](linux-bootstrap-2.md) or in the [Intel® 64 and IA-32 Architectures Software Developer’s Manuals 3A](http://www.intel.com/content/www/us/en/processors/architectures-software-developer-manuals.html). After this we get length of GDT with: @@ -538,4 +538,4 @@ Links * [A20](http://en.wikipedia.org/wiki/A20_line) * [GCC designated inits](https://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Designated-Inits.html) * [GCC type attributes](https://gcc.gnu.org/onlinedocs/gcc/Type-Attributes.html) -* [Previous part](https://github.com/0xAX/linux-insides/blob/master/Booting/linux-bootstrap-2.md) +* [Previous part](linux-bootstrap-2.md)