[OS]miniOS-7(3)

๐Ÿ‘‰๏ธ ๋ฐ์ดํ„ฐ ์˜์—ญ: GDT(Global Descriptor Table) ๊ตฌ์กฐ ์ •์˜ ๋ถ€๋ถ„ ์ฝ”๋“œ ์„ค๋ช…์ž…๋‹ˆ๋‹ค.
Data Area: This is an explanation of the code defining the GDT (Global Descriptor Table) structure.

โœ”๏ธ ๋ฐ์ดํ„ฐ ์˜์—ญ์œผ๋กœ GDT(Global Descriptor Table) ๊ตฌ์กฐ๋ฅผ ์ •์˜ ํ•ฉ๋‹ˆ๋‹ค.
Define the GDT (Global Descriptor Table) structure in the data area.

— 4๋ฐ”์ดํŠธ ์ •๋ ฌ / 4-byte alignment

1)ํ˜„์žฌ ์œ„์น˜์˜ ์ฝ”๋“œ ๋ฐ์ดํ„ฐ์˜ ๋ฐ”์ดํŠธ ์ˆ˜๋ฅผ 4๋กœ ๋‚˜๋ˆ„์—ˆ์„๊ฒฝ์šฐ ๋‚˜๋จธ์ง€๊ฐ€ 0์ด ์•„๋‹ˆ๋ฉด 0~3๋ฐ”์ดํŠธ๋ฅผ 0์„ ์ถ”๊ฐ€ํ•ด์„œ 4๋กœ ๋‚˜๋ˆˆ ๋‚˜๋จธ์ง€๊ฐ€0์ด ๋˜๋„๋ก ๋งž์ถฅ๋‹ˆ๋‹ค.
If the byte count of the code data at the current position is not divisible by 4 (i.e., the remainder is not 0), 0 to 3 bytes are added to make the remainder 0 when divided by 4.

2)ํ•„์ˆ˜ ์‚ฌํ•ญ์€ ์•„๋‹ˆ๋ฉฐ GDT์˜ ๊น”๋”ํ•œ ์ •๋ ฌ ๋•Œ๋ฌธ์— ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
It is not mandatory; I use it because of GDT’s clean alignment.

align 4

— ๋„ ๋””์Šคํฌ๋ฆฝํ„ฐ ์ž…๋‹ˆ๋‹ค.
It is a null descriptor.

dd 0, 0 

1)GDT์˜ ์ฒซ ๋ฒˆ์งธ ์—”ํŠธ๋ฆฌ๋Š” Null Descriptor์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค.
The first entry of the GDT must be a null descriptor.

2)๋””์Šคํฌ๋ฆฝํ„ฐ๋Š” ์„ธ๊ทธ๋จผํŠธ๋ฅผ ์„ค๋ช…ํ•˜๋Š” 8๋ฐ”์ดํŠธ์งœ๋ฆฌ ์ •๋ณด์ž…๋‹ˆ๋‹ค.
A descriptor is an 8-byte piece of information that describes a segment.

3) GDT๋Š” ํ…Œ์ด๋ธ”์ด๊ณ  ๋””์Šคํฌ๋ฆฝํ„ฐ๋Š” ํ…Œ์ด๋ธ”์˜ ์›์†Œ์ž…๋‹ˆ๋‹ค.
The GDT is a table, and descriptors are the elements of that table.

4) dd 0, 0์€ 32๋น„ํŠธ(double word) ๋ฐ์ดํ„ฐ ๋‘ ๊ฐœ๋ฅผ 0์œผ๋กœ ์ €์žฅํ•˜๋ผ๋Š” ์˜๋ฏธ์ž…๋‹ˆ๋‹ค.
“dd 0, 0” means to store two 32-bit (double-word) data items as 0.

5) ์ง€์‹œ์–ด์˜ ํฌ๊ธฐ / Size of the directive

db (Define Byte) : 1Byte
dw (Define Word) : 2Byte
dd (Define Double Word) : 4Byte

6)์‹ค์ œ ๋ฉ”๋ชจ๋ฆฌ์—๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ €์žฅ ๋ฉ๋‹ˆ๋‹ค.(4๋ฐ”์ดํŠธ + 4๋ฐ”์ดํŠธ = 8๋ฐ”์ดํŠธ)
It is stored in actual memory as follows (4 bytes + 4 bytes = 8 bytes).

6-1) ๋„๋””์Šคํฌ๋ฆฝํ„ฐ์˜ ํฌ๊ธฐ๋Š” 8๋ฐ”์ดํŠธ์ด๋ฉฐ ๋ฉ”๋ชจ๋ฆฌ์—๋Š” ์‹ค์ œ๋กœ ์•„๋ž˜์™€ ๊ฐ™์ด ์ €์žฅ๋ฉ๋‹ˆ๋‹ค.
The null descriptor is 8 bytes in size and is actually stored in memory as shown below

00 00 00 00
00 00 00 00

— ์ฝ”๋“œ ์„ธ๊ทธ๋จผํŠธ ๋””์Šคํฌ๋ฆฝํ„ฐ (์˜คํ”„์…‹ 0x08 = ๋„ ๋””์Šคํฌ๋ฆฝํ„ฐ 8๋ฐ”์ดํŠธ)
Code segment descriptor (offset 0x08 = 8-byte null descriptor)

    dw 0xFFFF, 0x0000
    db 0x00, 0x9A, 0xCF, 0x00

1) ์ฝ”๋“œ ์„ธ๊ทธ๋จผํŠธ ๋””์Šคํฌ๋ฆฝํ„ฐ๋Š” ์ฝ”๋“œ ์„ธ๊ทธ๋จผํŠธ์˜ ์œ„์น˜์— ๋Œ€ํ•œ ์ •๋ณด๊ฐ€ ์ €์žฅ๋ฉ๋‹ˆ๋‹ค.
A code segment descriptor stores information about the location of a code segment.

2)dw๋Š” 2๋ฐ”์ดํŠธ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.
dw generates 2 bytes.

3) 0xFFFF๋Š” FF FF 2๋ฐ”์ดํŠธ๊ฐ€ ๋˜๊ณ  0x0000๋Š” 00 00๋กœ 2๋ฐ”์ดํŠธ๊ฐ€ ๋ฉ๋‹ˆ๋‹ค.
0xFFFF becomes the two bytes FF FF, and 0x0000 becomes the two bytes 00 00.

4) ๊ทธ๋Ÿฌ๋ฉด ์ด 4๋ฐ”์ดํŠธ๊ฐ€ ๋ฉ๋‹ˆ๋‹ค.
That makes a total of 4 bytes.

5) db๋Š” 1๋ฐ”์ดํŠธ๋ฅผ ๋งŒ๋“ญ๋‹ˆ๋‹ค.
db creates a 1-byte value.

6) ๊ทธ๋Ÿฌ๋ฉด ์•„๋ž˜์ฒ˜๋Ÿผ ๊ฐ1๋ฐ”์ดํŠธ์˜ ํ•ฉ๊ณ„๋Š” ์ด4๋ฐ”์ดํŠธ๊ฐ€ ๋ฉ๋‹ˆ๋‹ค.
Then, as shown below, the sum of the 1-byte values โ€‹โ€‹results in a total of 4 bytes.

1)dw๋Š” 2๋ฐ”์ดํŠธ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.
dw generates 2 bytes.

2) 0xFFFF๋Š” FF FF 2๋ฐ”์ดํŠธ๊ฐ€ ๋˜๊ณ  0x0000๋Š” 00 00๋กœ 2๋ฐ”์ดํŠธ๊ฐ€ ๋ฉ๋‹ˆ๋‹ค.
0xFFFF becomes the two bytes FF FF, and 0x0000 becomes the two bytes 00 00.

3) ๊ทธ๋Ÿฌ๋ฉด ์ด 4๋ฐ”์ดํŠธ๊ฐ€ ๋ฉ๋‹ˆ๋‹ค.
That makes a total of 4 bytes.

4) db๋Š” 1๋ฐ”์ดํŠธ๋ฅผ ๋งŒ๋“ค๊ณ  ์ด 4๋ฐ”์ดํŠธ๊ฐ€ ๋ฉ๋‹ˆ๋‹ค.
db creates 1 byte, resulting in a total of 4 bytes.

db 0x00 โ†’ 1 byte
db 0x9A โ†’ 1 byte
db 0xCF โ†’ 1 byte
db 0x00 โ†’ 1 byte
--------------------
ํ•ฉ๊ณ„/total 4  byte

5) ์ฝ”๋“œ ์„ธ๊ทธ๋จผํŠธ ๋””์Šคํฌ๋ฆฝํ„ฐ๋Š” dw(2byteร—2) 4๋ฐ”์ดํŠธ์™€ db(1byteร—4) 4๋ฐ”์ดํŠธ๋ฅผ ํ•ฉํ•ด์„œ ์ด 8๋ฐ”์ดํŠธ๊ฐ€ ๋ฉ๋‹ˆ๋‹ค.
A code segment descriptor totals 8 bytes, combining 4 bytes from dw (2 bytes ร— 2) and 4 bytes from db (1 byte ร— 4).

6) ๋ฉ”๋ชจ๋ฆฌ์—๋Š” ๋‹ค์Œ์ฒ˜๋Ÿผ 8๋ฐ”์ดํŠธ๊ฐ€ ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค.
8 bytes are created in memory as follows.

FF FF 00 00 00 9A CF 00

7) ์ฝ”๋“œ ๋””์Šคํฌ๋ฆฝํ„ฐ์˜ ๊ตฌ์กฐ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.
The structure of the code descriptor is as follows.

+----------------+----------------+
| Limit(2B)      |
+----------------+----------------+
| Base(2B)       |
+----------------+----------------+
| Base(1B)       |
+----------------+----------------+
| Access(1B)     |
+----------------+----------------+
| Flags+Limit(1B)|
+----------------+----------------+
| Base(1B)       |
+----------------+----------------+

8) ๋‹ค์Œ์€ ์ฝ”๋“œ ๋””์Šคํฌ๋ฆฝํ„ฐ์˜ ๊ธฐ๋Šฅ์ž…๋‹ˆ๋‹ค.
The following are the functions of the code descriptor.

Code Descriptor

Base
-- ์ฝ”๋“œ ์„ธ๊ทธ๋จผํŠธ๊ฐ€ ์‹œ์ž‘๋  ์œ„์น˜
The starting location of the code segment

Limit
-- ์‚ฌ์šฉํ•  ๋ฉ”๋ชจ๋ฆฌ ์šฉ๋Ÿ‰
Memory capacity to use

Access
 -- ์ฝ”๋“œ์ธ์ง€ ๋ฐ์ดํ„ฐ์ธ์ง€ ์„ค์ •
Configure whether it is code or data.
 -- ์‹คํ–‰ ๊ฐ€๋Šฅํ•œ์ง€ ์„ค์ •
Set whether it is executable
 -- ๊ถŒํ•œ์„ค์ •
Permission Settings

Flags
-- 16๋น„ํŠธ์ธ์ง€ 32๋น„ํŠธ์ธ์ง€ ์„ค์ •
Set to 16-bit or 32-bit
-- Limit๋ฅผ ๋ฐ”์ดํŠธ ๋‹จ์œ„๋กœ ๋ณผ์ง€ 4KB ๋‹จ์œ„๋กœ ๋ณผ์ง€ ์„ค์ •
Configure whether to view the limit in bytes or 4KB units.

7-2) ์ฝ”๋“œ๋””์Šคํฌ๋ฆฝํ„ฐ์˜ ๊ฐ ์ฝ”๋“œ์™€ ๊ธฐ๋Šฅ ์„ค๋ช…์ž…๋‹ˆ๋‹ค.
Here are the descriptions of the codes and functions for the code descriptor.

dw 0xFFFF
-- Limit์˜ ํ•˜์œ„ 16๋น„ํŠธ
The lower 16 bits of the Limit
-- 0xCF ์•ˆ์—๋„ Limit์˜ ์ƒ์œ„ 4๋น„ํŠธ๊ฐ€ ๋“ค์–ด๊ฐ‘๋‹ˆ๋‹ค.
The upper 4 bits of the Limit are also included in 0xCF.
โœ… Limit = ์ƒ์œ„ 4๋น„ํŠธ(0xF) + ํ•˜์œ„16๋น„ํŠธ(0xFFFF) = 4GB
Limit = Upper 4 bits (0xF) + Lower 16 bits (0xFFFF) = 4GB

dw 0x0000 
-- Base Address ํ•˜์œ„ 16๋น„ํŠธ
Lower 16 bits of the base address
-- ์„ธ๊ทธ๋จผํŠธ์˜ ์‹œ์ž‘ ์ฃผ์†Œ์ž…๋‹ˆ๋‹ค.
This is the starting address of the segment.
-- Base = 0x0000

db 0x00 
-- Base Address 16~23bit
-- Base = 0x000000

db 0x9A
-- Access Byte(๊ถŒํ•œ ๋ฐ ์„ธ๊ทธ๋จผํŠธ ์ข…๋ฅ˜)๐Ÿ““
Access Byte (Permissions and Segment Type)

db 0xCF
-- 11001111์—์„œ 1100์€ ํ”Œ๋ž˜๊ทธ๐Ÿ““, 1111์€ Limit์˜ ์ƒ์œ„ 4๋น„ํŠธ์ž…๋‹ˆ๋‹ค.
In 11001111, 1100 represents the flags ๐Ÿ““, and 1111 represents the upper 4 bits of the Limit.

db 0x00
-- Base = 0x00000000
โœ… Base Address๋Š” dw 0x0000 , db 0x00 ,db 0x00๋ฅผ ์กฐํ•ฉํ•ด์„œ 32๋น„ํŠธ๋ฅผ ๋งŒ๋“ญ๋‹ˆ๋‹ค.
The Base Address is formed as a 32-bit value by combining `dw 0x0000`, `db 0x00`, and `db 0x00`.

๐Ÿ““ ์ ‘๊ทผ๊ถŒํ•œ๋ฐ”์ดํŠธ / Access Byte

— 0x9A = 10011010

๋น„ํŠธ/Bit์ด๋ฆ„/Name๊ฐ’/Vale์„ค๋ช…/Description
7P(Present)1๋ฉ”๋ชจ๋ฆฌ์— ์กด์žฌ
Resides in memory
6~5DPL00Ring0
4S1Code/Data ์„ธ๊ทธ๋จผํŠธ
Code/Data segment
3E1์‹คํ–‰ ๊ฐ€๋ŠฅFeasible(Code)
2C0Conforming ์•ˆ ํ•จ
Non-conforming
1R1์ฝ๊ธฐ ๊ฐ€๋Šฅ
Readable
0A0CPU๊ฐ€ ์ ‘๊ทผํ•˜๋ฉด 1๋กœ ๋ณ€๊ฒฝ
Changes to 1 when accessed by the CPU.
๋น„ํŠธ/Bit์ด๋ฆ„/Name๊ฐ’/Vale์„ค๋ช…/Description
7P(Present)1๋ฉ”๋ชจ๋ฆฌ์— ์กด์žฌ
Resides in memory
6~5DPL00Ring0
4S1Code/Data ์„ธ๊ทธ๋จผํŠธ
Code/Data segment
3E1์‹คํ–‰ ๊ฐ€๋ŠฅFeasible(Code)
2C0Conforming ์•ˆ ํ•จ
Non-conforming
1R1์ฝ๊ธฐ ๊ฐ€๋Šฅ
Readable
0A0CPU๊ฐ€ ์ ‘๊ทผํ•˜๋ฉด 1๋กœ ๋ณ€๊ฒฝ
Changes to 1 when accessed by the CPU.

๐Ÿ““ ํ”Œ๋ž˜๊ทธ / Flags

— 1100(G D L AVL)

๋น„ํŠธ
Bit
์ด๋ฆ„
Name
ํ˜„์žฌ ๊ฐ’
Current Value
์˜๋ฏธ
Description
7G (Granularity)1Limit๋ฅผ 4KB ๋‹จ์œ„๋กœ ํ•ด์„ํ•ฉ๋‹ˆ๋‹ค.
The limit is interpreted in 4KB units.
6D (Default Operation Size)132๋น„ํŠธ ์ฝ”๋“œ/๋ฐ์ดํ„ฐ
32-bit code/data
5L (Long Mode)064๋น„ํŠธ ์•„๋‹˜
Not 64-bit
4AVL (Available)0์šด์˜์ฒด์ œ๊ฐ€ ์ž์œ ๋กญ๊ฒŒ ์‚ฌ์šฉํ•˜๋Š” ๋น„ํŠธ
bits freely used by the operating system

1)G (Granularity)

1-1) G=0์ด๋ฉด Limit๋ฅผ 1๋ฐ”์ดํŠธ ๋‹จ์œ„๋กœ ํ•ด์„ํ•ฉ๋‹ˆ๋‹ค.Limit = 100์ด๋ฉด 100Byte๊นŒ์ง€๋งŒ ์‚ฌ์šฉ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
If G=0, the limit is interpreted in 1-byte units. If Limit = 100, only up to 100 bytes can be used.

1-2)G=1์ด๋ฉด Limit๋ฅผ 4KB ๋‹จ์œ„๋กœ ํ•ด์„ํ•ฉ๋‹ˆ๋‹ค.100 ร— 4096 Byte๋ฅผ ์‚ฌ์šฉ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
If G=1, the Limit is interpreted in 4 KB units; 100 ร— 4,096 bytes can be used.

1-3)ํ˜„์žฌ ์ฝ”๋“œ์—์„œ 0xFFFFF(1,048,575) ร— 4096 + 4095 = 4GB์ด ๋ฉ๋‹ˆ๋‹ค.
In the current code, 0xFFFFF (1,048,575) ร— 4096 + 4095 equals 4 GB.

1-4)0~4GB์ด๊ธฐ ๋•Œ๋ฌธ์— 0xFFFFF(1,048,575) ร— 4096 ์ด ๋ถ€๋ถ„์—์„œ 4096์€ 0~4095๊นŒ์ง€์˜ ๊ฐ’์ž…๋‹ˆ๋‹ค.
Since the range is 0 to 4 GB, in the expression 0xFFFFF (1,048,575) ร— 4096, the value 4096 represents the range from 0 to 4095.

1-5)๊ทธ๋ž˜์„œ ๋ฉ”๋ชจ๋ฆฌ ์ „์ฒด ์šฉ๋Ÿ‰์€ 1~4GB๊ฐ€ ์•„๋‹ˆ๋ผ 0~4GB๋ฅผ ์‚ฌ์šฉ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
Therefore, the total usable memory capacity is 0 to 4 GB, rather than 1 to 4 GB.

1-6)1~4GB์— ๋Œ€ํ•œ ๊ณ„์‚ฐ์€ 0xFFFFF(1,048,575) ร— 4096 ์ž…๋‹ˆ๋‹ค.
The calculation for 1โ€“4 GB is 0xFFFFF (1,048,575) ร— 4096.

1-7)์œ„์˜ ๊ฐ’์— 0์—์„œ ๋ถ€ํ„ฐ 1์‚ฌ์ด์˜ ๊ฐ’์ธ 4095๋ฅผ ๋”ํ•ฉ๋‹ˆ๋‹ค.(4096๊ฐœ์—์„œ 0์„ ๋นผ๋ฉด 4095)
Add 4095โ€”a value ranging from 0 to 4095โ€”to the value above. (Subtracting 0 from 4,096 yields 4,095.)

1-8)๊ทธ๋Ÿฌ๋ฉด ์ „์ฒด ๋ฉ”๋ชจ๋ฆฌ ์šฉ๋Ÿ‰์€ 0xFFFFF(1,048,575) ร— 4096 + 4095 = 4GB ์ด๋ ‡๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.
Then, the total memory capacity becomes 0xFFFFF (1,048,575) ร— 4096 + 4095 = 4 GB.

2)D (Default Operation Size)

2-1)CPU๊ฐ€ ์ด ์„ธ๊ทธ๋จผํŠธ๋ฅผ 16๋น„ํŠธ๋กœ ์‚ฌ์šฉํ• ์ง€ 32๋น„ํŠธ๋กœ ์‚ฌ์šฉํ• ์ง€๋ฅผ ๊ฒฐ์ •ํ•ฉ๋‹ˆ๋‹ค.
It determines whether the CPU uses this segment as 16-bit or 32-bit.

3)L (Long Mode)

3-1)64๋น„ํŠธ ๋ชจ๋“œ ์—ฌ๋ถ€์ž…๋‹ˆ๋‹ค.
Indicates whether 64-bit mode is enabled.

4)AVL (Available)

4-1)์šด์˜์ฒด์ œ๊ฐ€ ์ž์œ ๋กญ๊ฒŒ ์‚ฌ์šฉํ•˜๋Š” ๋น„ํŠธ๋กœ cpu๋Š” ๋ณ„๋กœ ์‹ ๊ฒฝ์“ฐ์ง€ ์•Š์œผ๋ฉฐ ๋ณดํ†ต 0์œผ๋กœ ๋‘ก๋‹ˆ๋‹ค.
This is a bit that the operating system is free to use; the CPU generally pays no attention to it and usually leaves it set to 0.


— ๋ฐ์ดํ„ฐ ์„ธ๊ทธ๋จผํŠธ ๋””์Šคํฌ๋ฆฝํ„ฐ
Data segment descriptor

1)์ฝ”๋“œ ์„ธ๊ทธ๋จผํŠธ ๋””์Šคํฌ๋ฆฝํ„ฐ์™€ ๋ฐ์ดํ„ฐ ์„ธ๊ทธ๋จผํŠธ ๋””์Šคํฌ๋ฆฝํ„ฐ์˜ Base, Limit, Flags๋Š” ๋™์ผํ•ฉ๋‹ˆ๋‹ค.
The Base, Limit, and Flags of the code segment descriptor and the data segment descriptor are identical.

2) access byte์—์„œ ๋Š” bit3์˜ ์„ค์ •๊ฐ’์ด ๋‹ฌ๋ผ ์ฝ”๋“œ/๋ฐ์ดํ„ฐ๋ฅผ ๊ตฌ๋ถ„ํ•ฉ๋‹ˆ๋‹ค.
In the access byte, the setting of bit 3 distinguishes between code and data.

3)๊ทธ๋ฆฌ๊ณ  CPU๋Š” ๊ทธ ๊ฒฐ๊ณผ์— ๋”ฐ๋ผ bit2์™€ bit1์„ ์„œ๋กœ ๋‹ค๋ฅธ ์˜๋ฏธ(์ฝ”๋“œ์—์„œ๋Š” Conforming/Readable, ๋ฐ์ดํ„ฐ์—์„œ๋Š” Expand Down/Writable)๋กœ ํ•ด์„ํ•ฉ๋‹ˆ๋‹ค.
Based on that result, the CPU interprets bits 2 and 1 differently (as Conforming/Readable for code, and as Expand-Down/Writable for data).

2)0x92 = 10010010

๋น„ํŠธ
Bit
์ด๋ฆ„
Name
๊ฐ’
Value
์„ค๋ช…
Description
7P (Present)1์„ธ๊ทธ๋จผํŠธ๊ฐ€ ๋ฉ”๋ชจ๋ฆฌ์— ์กด์žฌ
Segment exists in memory
6~5DPL00Ring 0
4S1์‹œ์Šคํ…œ ์„ธ๊ทธ๋จผํŠธ๊ฐ€ ์•„๋‹ˆ๋ผ Code/Data ์„ธ๊ทธ๋จผํŠธ
Code/Data segment, not a system segment.
3E (Executable)0์‹คํ–‰ ๋ถˆ๊ฐ€ โ†’ ๋ฐ์ดํ„ฐ ์„ธ๊ทธ๋จผํŠธ
Non-executable โ†’ Data segment
2ED (Expand Down)0์ผ๋ฐ˜ ๋ฐ์ดํ„ฐ ์„ธ๊ทธ๋จผํŠธ
General data segment
1W (Writable)1์“ฐ๊ธฐ ๊ฐ€๋Šฅ
Writable
0A (Accessed)0์•„์ง ์ ‘๊ทผ ์•ˆ ํ•จ
Not yet approached.

1)P,DPL,S๋ถ€๋ถ„์€ ์ฝ”๋“œ ์„ธ๊ทธ๋จผํŠธ ๋””์Šคํฌ๋ฆฝํ„ฐ์™€ ๋™์ผํ•ฉ๋‹ˆ๋‹ค.
The P, DPL, and S fields are identical to those of the code segment descriptor.

2)E (Executable)

2-1)์ด๊ฐ’์ด 0์ด๋ฉด ๋ฐ์ดํ„ฐ ์„ธ๊ทธ๋จผํŠธ๋ผ๊ณ  ํŒ๋‹จํ•ฉ๋‹ˆ๋‹ค.
If this value is 0, it is determined to be a data segment.

3)ED – Expand Down (๋ฐ์ดํ„ฐ ์„ธ๊ทธ๋จผํŠธ ์ „์šฉ์œผ๋กœ ์‚ฌ์šฉ/Used exclusively for data segments)

3-1)ED = 1์ด๋ฉด ์Šคํƒ์ฒ˜๋Ÿผ ๋†’์€ ์ฃผ์†Œ์—์„œ ๋‚ฎ์€ ์ฃผ์†Œ ๋ฐฉํ–ฅ์œผ๋กœ ์‚ฌ์šฉํ•˜๋Š” ํŠน์ˆ˜ํ•œ ๋ฐ์ดํ„ฐ ์„ธ๊ทธ๋จผํŠธ ์ž…๋‹ˆ๋‹ค.
If ED = 1, it is a special data segment that is used in the direction from high addresses to low addresses, similar to a stack.

3-2)ED = 0์ด๋ฉด ์ผ๋ฐ˜์ ์ธ ๋ฐ์ดํ„ฐ ์„ธ๊ทธ๋จผํŠธ์ž…๋‹ˆ๋‹ค.
If ED = 0, it is a standard data segment.

4)W

4-1)์ด ๊ฐ’์ด 1์ด๋ฉด ์“ฐ๊ธฐ๊ฐ€ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.
If this value is 1, writing is possible.

5)A

5-1)A ๋น„ํŠธ๋Š” ํ”„๋กœ๊ทธ๋ž˜๋จธ๊ฐ€ ์ง์ ‘ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ CPU๊ฐ€ “์ด ์„ธ๊ทธ๋จผํŠธ๋ฅผ ์‚ฌ์šฉํ–ˆ๋‹ค”๋Š” ํ‘œ์‹œ๋กœ ์‚ฌ์šฉํ•˜๋Š” ๋น„ํŠธ์ž…๋‹ˆ๋‹ค.
The A-bit is not used directly by the programmer; instead, it is a bit used by the CPU to indicate that “this segment has been used.”


— CPU์—๊ฒŒ “GDT๊ฐ€ ์–ด๋”” ์žˆ๋Š”์ง€” ์•Œ๋ ค์ฃผ๋Š” ๊ตฌ์กฐ์ฒด์ž…๋‹ˆ๋‹ค.(dw 2byte,dd 4byte)
It is a structure that tells the CPU “where the GDT is.”

gdt_pointer:
    dw gdt_end - gdt_start - 1  ; GDT์˜ ํฌ๊ธฐ (Size of GDT)
    dd gdt_start                ; GDT์˜ ์‹œ์ž‘ ์ฃผ์†Œ (Starting address of GDT)

1)lgdt [gdt_pointer] ์ด ์ฝ”๋“œ์—์„œ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•œ ๋ถ€๋ถ„์ž…๋‹ˆ๋‹ค.
This part is intended for use with the lgdt [gdt_pointer] instruction.

2) gdt_end์™€ gdt_start๋Š” ๋ผ๋ฒจ์˜ ์œ„์น˜์ž…๋‹ˆ๋‹ค.
gdt_end and gdt_start are the locations of the labels.

3)gdt_end – gdt_start = 24(8[Null Descriptor]+8[Code Descriptor]+8[Data Descriptor])

4)๊ทธ๋ž˜์„œ dw gdt_end – gdt_start – 1 ์ด ๊ฐ’์€ dw 23์ด ์ €์žฅ ๋ฉ๋‹ˆ๋‹ค.
Therefore, the value dw 23 is stored for the expression dw gdt_end - gdt_start - 1.

5)gdt_start๋Š” gdt์‹œ์ž‘ ์ฃผ์†Œ๊ฐ€ ์ €์žฅ๋ฉ๋‹ˆ๋‹ค.
The starting address of the GDT is stored in gdt_start.

— (sector2.asm) 512๋ฐ”์ดํŠธ์—์„œ ๋ฐ์ดํ„ฐ๋กœ ์‚ฌ์šฉ๋˜๊ณ  ๋‚œ ๋‚˜๋จธ์ง€ ์ฝ”๋“œ๋Š” 0์œผ๋กœ ๋งž์ถ”๋Š” ๋ถ€๋ถ„์ž…๋‹ˆ๋‹ค.
(sector2.asm) This section pads the remaining space within the 512 bytes with zeros after the code.

times 512 - ($ - $$) db 0

1) boot.asm์—์„œ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์„นํ„ฐ๋ฅผ 1๊ฐœ๋งŒ ์ฝ์–ด์˜ค๋ฉด 512๋ฐ”์ดํŠธ๊ฐ€ ๋ฉ๋‹ˆ๋‹ค.
If you read only one sector in boot.asm as shown below, it amounts to 512 bytes.

boot.asm
mov al, 1 โ†’ 1์„นํ„ฐ ์ฝ์Œ / 1 Sector Read

secotr2.asm
times 512 - ($ - $$) db 0

2) boot.asm์—์„œ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์„นํ„ฐ๋ฅผ 2๊ฐœ๋ฅผ ์ฝ์–ด์˜ค๋ฉด 1024๋ฐ”์ดํŠธ๊ฐ€ ๋ฉ๋‹ˆ๋‹ค.
If you read two sectors in boot.asm as shown below, it amounts to 1024 bytes.

boot.asm
mov al, 2 โ†’ 2์„นํ„ฐ ์ฝ์Œ / 2 Sector Read

sector2.asm
times 1024 - ($ - $$) db 0

3) boot.asm์—์„œ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์„นํ„ฐ๋ฅผ 3๊ฐœ๋ฅผ ์ฝ์–ด์˜ค๋ฉด 1536๋ฐ”์ดํŠธ๊ฐ€ ๋ฉ๋‹ˆ๋‹ค.
If you read three sectors in boot.asm as shown below, it amounts to 1,536 bytes.

boot.asm
mov al, 3 โ†’ 3์„นํ„ฐ ์ฝ์Œ / 3 Sector Read

sector2.asm
times 1536 - ($ - $$) db 0

Leave a Reply