-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
42 changed files
with
723 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
# Question 90 | ||
|
||
|
||
What is a symbol table? What kind of information does it store? | ||
|
||
|
||
# Answer | ||
|
||
|
||
|
||
In ELF files, this table stores information about all object symbols. An object | ||
symbol usually corresponds to a label in assembly file. Linker can use it to | ||
e.g. link the usage of a global variable, declared in one file, to its absolute | ||
address. This address is only known after relocation, so it is the linker's | ||
responsibility to fill it. | ||
|
||
|
||
[prev](089.md) +++ [next](091.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
# Question 91 | ||
|
||
|
||
Is there a connection between sections and segments? | ||
|
||
|
||
# Answer | ||
|
||
|
||
|
||
* Section is a static phenomenon, whereas segments are created in runtime. | ||
* Sections are declared in section header, segments are declared in program headers. | ||
* Each segment is a container for one or several sections. | ||
* Not all sections are put into segments (and are loaded at all -- e.g., __line__). | ||
* Segments define permissions for the virtual pages they consist of. If multiple | ||
data sections are put inside one segment, they will all be e.g. non-executable. | ||
|
||
|
||
|
||
[prev](090.md) +++ [next](092.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
# Question 92 | ||
|
||
|
||
Is there a connection between assembly sections and ELF sections? | ||
|
||
|
||
# Answer | ||
|
||
|
||
|
||
Assembly sections are transformed into ELF sections. Not all ELF sections are | ||
generated from assembly (e.g. __line__). | ||
|
||
|
||
[prev](091.md) +++ [next](093.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
# Question 93 | ||
|
||
|
||
What symbol marks the program entry point? | ||
|
||
|
||
# Answer | ||
|
||
|
||
|
||
|
||
`_start` | ||
|
||
|
||
|
||
|
||
[prev](092.md) +++ [next](094.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
# Question 94 | ||
|
||
|
||
Which are the two different kind of libraries? | ||
|
||
|
||
# Answer | ||
|
||
|
||
|
||
|
||
Static and dynamic. | ||
|
||
* Static libraries are the same thing as `.o` files: they are relocatable object | ||
files that will be inlined into the resulting executable by the linker. | ||
* Dynamic libraries are shared object files. They are compiled and linked separately, | ||
but an entity called dynamic linker should perform a special relocation job on them | ||
before they can be executed as a part of some running process. | ||
|
||
|
||
[prev](093.md) +++ [next](095.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
# Question 95 | ||
|
||
|
||
Is there a difference between a static library and a relocatable object file? | ||
|
||
|
||
# Answer | ||
|
||
|
||
|
||
Usually, no. The static libraries in form of `.a` file are just archives of | ||
multiple `.o` files. | ||
|
||
|
||
[prev](094.md) +++ [next](096.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
# Question 97 | ||
|
||
|
||
Is the `TF` flag cleared automatically when entering interrupt handlers? | ||
Refer to [Intel 64 and IA-32 Architectures Software Developer's Manual]. | ||
|
||
|
||
# Answer | ||
|
||
|
||
|
||
|
||
It depends on the interrupt descriptors (aka __gates__). There are two types of them: trap gates and interrupt gates. | ||
For _interrupt gates_ the interrupt handling is automatically disabled once CPU enters the interrupt handler. | ||
|
||
|
||
|
||
[prev](096.md) +++ [next](098.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
|
||
# Question 98 | ||
|
||
|
||
What is an interrupt? | ||
|
||
|
||
# Answer | ||
|
||
|
||
|
||
|
||
This is a controlled violation of the sequential execution of a program. | ||
Interrupts allows one to change program execution order based on events external to | ||
the program itself. | ||
|
||
After a signal (external or internal) is caught, a program’s execution is suspended, some | ||
registers are saved, and the CPU starts executing a special routine to handle the situation. Following are | ||
exemplary situations when an interrupt occurs (and an appropriate piece of code is executed to handle it): | ||
* A signal from an external device (external interrupt). | ||
* Zero division (internal interrupt). | ||
* Invalid instruction (when CPU failed to recognize an instruction by its binary | ||
representation -- internal interrupt). | ||
* An attempt to execute a privileged instruction in a non-privileged mode (internal interrupt). | ||
|
||
|
||
|
||
|
||
[prev](097.md) +++ [next](099.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
|
||
# Question 99 | ||
|
||
|
||
What is IDT? | ||
|
||
|
||
# Answer | ||
|
||
|
||
|
||
A system table that holds __interrupt descriptors__ (also called __gates__). Each | ||
of them holds the interrupt handler address and some additional information. Refer to the Figure 6-3 on page 94 to see its structure. | ||
|
||
|
||
|
||
[prev](098.md) +++ [next](100.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
# Question 100 | ||
|
||
|
||
What does setting IF change? | ||
|
||
|
||
# Answer | ||
|
||
|
||
|
||
If IF = 1, the interrupts are accepted and handled. If IF = 0, interrupts are | ||
ignored (except for Non-Maskable Interrupts). | ||
|
||
|
||
[prev](099.md) +++ [next](101.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
|
||
# Question 102 | ||
|
||
|
||
In which situations does the #PF error occur? | ||
|
||
|
||
# Answer | ||
|
||
|
||
|
||
* When the page is not in physical memory and should be loaded from file (data, | ||
code or or swap file). | ||
* When accessing forbidden addresses. | ||
|
||
|
||
[prev](101.md) +++ [next](103.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
# Question 103 | ||
|
||
|
||
How is #PF error related to the swapping? How does the operating system | ||
use it? | ||
|
||
|
||
# Answer | ||
|
||
|
||
|
||
When a page is swapped out to disk, the `P` bit in the relevant __page table entry__ | ||
is set to zero, because the page is not present in physical memory anymore. | ||
Accessing addresses on this page results in a page fault exception, which enables | ||
the operating system to load the page contents into memory. | ||
|
||
|
||
[prev](102.md) +++ [next](104.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
# Question 104 | ||
|
||
|
||
Can we implement system calls using interrupts? | ||
|
||
|
||
# Answer | ||
|
||
|
||
|
||
Yes, we can actually implement system calls using any instruction that results in an interrupt. Before `syscall` was introduced, `int 0x80` was used to access system calls on Linux, but in reality the choice is arbitrary. We can even use incorrectly encoded instruction to do it, because it results in #UD exception. | ||
|
||
|
||
[prev](103.md) +++ [next](105.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
# Question 105 | ||
|
||
|
||
Why do we need a separate instruction to implement system calls? | ||
|
||
|
||
# Answer | ||
|
||
|
||
|
||
Because it is faster than interrupts: it uses always the same routine to access | ||
the system calls handler, and it does not need to use IDT. | ||
|
||
|
||
[prev](104.md) +++ [next](106.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
# Question 107 | ||
|
||
|
||
What is the purpose of interrupt stack tables? | ||
|
||
|
||
# Answer | ||
|
||
|
||
|
||
To provide good, well-formed stacks for interrupt handlers. This can be more robust. | ||
|
||
|
||
[prev](106.md) +++ [next](108.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
# Question 108 | ||
|
||
|
||
Does a single thread application have only one stack? | ||
|
||
|
||
# Answer | ||
|
||
|
||
|
||
No, the application has a user stack per thread, but it also has a kernel stack | ||
per thread. Kernel can not trust user `rsp` value to be good and need its own | ||
separate stack for when e.g. the application performs system calls. | ||
|
||
A more profound explanation can be seen at: | ||
[https://stackoverflow.com/questions/12911841/kernel-stack-and-user-space-stack](https://stackoverflow.com/questions/12911841/kernel-stack-and-user-space-stack) | ||
|
||
|
||
[prev](107.md) +++ [next](109.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
# Question 109 | ||
|
||
|
||
What kinds of input and output mechanism does Intel 64 provide? | ||
|
||
|
||
# Answer | ||
|
||
|
||
|
||
* `in` and `out` instructions to work with input/output ports | ||
* memory mapped I/O | ||
|
||
|
||
[prev](108.md) +++ [next](110.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
# Question 110 | ||
|
||
|
||
What is a model specific register? | ||
|
||
|
||
# Answer | ||
|
||
|
||
|
||
A register that appears as a non standard extension used by a specific processor model. It can then become part of the standard and be usable in all newer processors. | ||
|
||
|
||
[prev](109.md) +++ [next](111.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
# Question 111 | ||
|
||
|
||
What are the shadow registers? | ||
|
||
|
||
# Answer | ||
|
||
|
||
|
||
A register that is not directly accessible but that is used as a cache for a | ||
certain memory value. It can be used implicitly by CPU instead of reading the | ||
said value from memory. | ||
|
||
For example, the current segment descriptors that correspond to the entries in GDT pointed | ||
at by `cs`, `ds`, `ss` are stored in shadow registers to prevent reading them from | ||
GDT at every memory access. | ||
|
||
|
||
[prev](110.md) +++ [next](112.md) |
Oops, something went wrong.