Skip to content

Commit

Permalink
more answers
Browse files Browse the repository at this point in the history
  • Loading branch information
sayon committed Jul 20, 2017
1 parent 1896a9f commit c5e4857
Show file tree
Hide file tree
Showing 42 changed files with 723 additions and 6 deletions.
8 changes: 4 additions & 4 deletions questions/answers/005.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ 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
* 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).
* An attempt to execute a privileged instruction in a non-privileged mode (internal interrupt).



Expand Down
2 changes: 1 addition & 1 deletion questions/answers/007.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Question 7


What are the main general purpose registers of \arch?
What are the main general purpose registers of Intel 64?


# Answer
Expand Down
2 changes: 1 addition & 1 deletion questions/answers/089.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ What sections can be present in ELF files?
* __.data__ stores initialized global variables.
* __.bss__ stores readable and writable global variables, initialized to zero. There is no need to dump their contents into an object file as they are all filled with zeros anyway. Instead, a total section size is stored. An operating system may know faster ways of initializing such memory than zeroing it manually. In assembly, you can put data here by placing `resb`, `resw`, and similar directives after the section __.bss__.
* __.rel.text__ stores relocation table for the .text section. It is used to memorize places where a linker should modify .text after choosing the loading address for this specific object file.
* __.rel.data_ stores a relocation table for data referenced in module.
* __.rel.data__ stores a relocation table for data referenced in module.
* __.debug__ stores a symbol table used to debug program. If the program was written in C or C++, it will store information not only about global variables (as __.symtab__ does) but also about local variables.
* __.line__ defines correspondence with pieces of code and line numbers in source code. We need it because the correspondence between lines of source code in higher-level languages and assembly instructions is not
straightforward. This information allows one to debug a program in a higher-level language line by line.
Expand Down
19 changes: 19 additions & 0 deletions questions/answers/090.md
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)
21 changes: 21 additions & 0 deletions questions/answers/091.md
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)
16 changes: 16 additions & 0 deletions questions/answers/092.md
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)
18 changes: 18 additions & 0 deletions questions/answers/093.md
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)
22 changes: 22 additions & 0 deletions questions/answers/094.md
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)
16 changes: 16 additions & 0 deletions questions/answers/095.md
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)
19 changes: 19 additions & 0 deletions questions/answers/097.md
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)
29 changes: 29 additions & 0 deletions questions/answers/098.md
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)
17 changes: 17 additions & 0 deletions questions/answers/099.md
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)
16 changes: 16 additions & 0 deletions questions/answers/100.md
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)
17 changes: 17 additions & 0 deletions questions/answers/102.md
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)
19 changes: 19 additions & 0 deletions questions/answers/103.md
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)
15 changes: 15 additions & 0 deletions questions/answers/104.md
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)
16 changes: 16 additions & 0 deletions questions/answers/105.md
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)
15 changes: 15 additions & 0 deletions questions/answers/107.md
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)
20 changes: 20 additions & 0 deletions questions/answers/108.md
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)
16 changes: 16 additions & 0 deletions questions/answers/109.md
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)
15 changes: 15 additions & 0 deletions questions/answers/110.md
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)
21 changes: 21 additions & 0 deletions questions/answers/111.md
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)
Loading

0 comments on commit c5e4857

Please sign in to comment.