[OS]miniOS-3(2)

โœ”๏ธ sector2.asm

— ๋‘๋ฒˆ์งธ ์„นํ„ฐ / Second sector

[org 0x8000]

1)์ปดํŒŒ์ผ๋Ÿฌ๋Š” ์ด ๊ฐ’์„ ๊ธฐ์ค€์œผ๋กœ ๋ชจ๋“  ๋ฌธ์ž์—ด ์ฃผ์†Œ(์˜ˆ: msg_next_sector)์˜ ์œ„์น˜๋ฅผ ๊ณ„์‚ฐํ•ฉ๋‹ˆ๋‹ค.
The compiler calculates the locations of all string addresses (e.g., msg_next_sector) based on this value.

2)PC๊ฐ€ ์ฒ˜์Œ ๋ถ€ํŒ…๋˜์—ˆ์„ ๋•Œ, 16๋น„ํŠธ ๋ฆฌ์–ผ ๋ชจ๋“œ์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๊ธฐ๋ณธ ๋ฉ”๋ชจ๋ฆฌ ๋งต(์•ฝ 640KB) ์ค‘ ์‚ฌ์šฉ์ž๊ฐ€ ๋งˆ์Œ๋Œ€๋กœ ์“ธ ์ˆ˜ ์žˆ๋Š” ์•ˆ์ „ํ•œ ๊ตฌ๊ฐ„์ด ์กด์žฌํ•ฉ๋‹ˆ๋‹ค.
When a PC first boots up, there is a safe region within the base memory map (approximately 640 KB) available in 16-bit real mode that the user can utilize freely.

3)๊ทธ๋ž˜์„œ ์ฃผ์†Œ๋ฅผ 0x9000์œผ๋กœ ๋ฐ”๊ฟ€ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
So, you can change the address to 0x9000.

0x0000 ~ 0x04FF: 
BIOS ์ธํ„ฐ๋ŸฝํŠธ ๋ฒกํ„ฐ ํ…Œ์ด๋ธ”, BIOS ๋ฐ์ดํ„ฐ ์˜์—ญ (์ ˆ๋Œ€ ๊ฑด๋“œ๋ฆฌ๋ฉด ์•ˆ ๋จ)
BIOS Interrupt Vector Table, BIOS Data Area (must absolutely not be touched)

0x7C00 ~ 0x7DFF: 
MBR ์ฝ”๋“œ๊ฐ€ ๋กœ๋“œ๋˜๋Š” ์˜์—ญ (512๋ฐ”์ดํŠธ)
The area where the MBR code is loaded (512 bytes)

0x7E00 ~ 0x9FFFF: 
๋น„์–ด ์žˆ๋Š” ์ผ๋ฐ˜ ๋ฉ”๋ชจ๋ฆฌ ์˜์—ญ (์ž์œ ๋กญ๊ฒŒ ์‚ฌ์šฉ ๊ฐ€๋Šฅ)
Unused general memory area (available for free use)

— 16๋น„ํŠธ ๋ฆฌ์–ผ๋ชจ๋“œ / 16bit real mode

bits 16

— mov si, msg_boot ์—ฌ๊ธฐ si๋ ˆ์ง€์Šคํ„ฐ์— msg_next_sector์— ์ €์žฅ๋œ ๊ฐ’์˜ ์ฃผ์†Œ๋ฅผ ์ €์žฅํ•ฉ๋‹ˆ๋‹ค.
mov si, msg_boot: This stores the address of the value held in msg_next_sector into the si register.

mov si, msg_next_sector

— print_string๋ผ๋ฒจ ํ•จ์ˆ˜ ํ˜ธ์ถœ์ž…๋‹ˆ๋‹ค.
This is a call to the print_string_label function.

call print_string

— ๋Œ€๊ธฐ๋ชจ๋“œ์ž…๋‹ˆ๋‹ค.(์ž๊ธฐ ์ž์‹ ์˜ ์œ„์น˜๋กœ ์ ํ”„ํ•ฉ๋‹ˆ๋‹ค.)
It is in standby mode. (It jumps to its own position.)

jmp $

— ๋ฉ”๋ชจ๋ฆฌ์— ์ €์žฅ๋œ ๋ฌธ์ž์—ด์„ ํ•œ ๊ธ€์ž์”ฉ ์ฝ์–ด์„œ, ํ™”๋ฉด์— ์—ฐ์†์œผ๋กœ ์ถœ๋ ฅํ•˜๋Š” ํ•จ์ˆ˜์ž…๋‹ˆ๋‹ค.
This function reads a string stored in memory character by character and outputs it to the screen continuously.

print_string:
    lodsb
    cmp al, 0
    je .done
    mov ah, 0x0e
    int 0x10
    jmp print_string
.done:
    ret

— ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธ๋ถ€๋ถ„์ž…๋‹ˆ๋‹ค.
This is the section where variables are declared.

1)๊ฐ ๋ณ€์ˆ˜์— ๋ฌธ์ž๋ฅผ 1๋ฐ”์ดํŠธ์”ฉ ์ €์žฅํ•ฉ๋‹ˆ๋‹ค.
Store one byte of character data in each variable.

2)13์€ ์บ๋ฆฌ์ง€ ๋ฆฌํ„ด(\r)์œผ๋กœ ์ปค์„œ๋ฅผ ํ˜„์žฌ ์ค„์˜ ๋งจ ์™ผ์ชฝ(์ฒซ ๋ฒˆ์งธ ์นธ)์œผ๋กœ ์ด๋™์‹œํ‚ต๋‹ˆ๋‹ค.
13 is the carriage return (\r), which moves the cursor to the far left (the first column) of the current line.

3)10 ๋ผ์ธ ํ”ผ๋“œ(\n)๋กœ ์ปค์„œ๋ฅผ ํ˜„์žฌ ์œ„์น˜์—์„œ ์ •ํ™•ํžˆ ํ•œ ์ค„ ์•„๋ž˜๋กœ ๋‚ด๋ฆฝ๋‹ˆ๋‹ค.
10 Moves the cursor exactly one line down from its current position using a line feed (\n).

msg_next_sector db '3. Hello from Sector 2 (0x8000)!', 13, 10, 0

— ๊ณ„์‚ฐ๋œ ํšŸ์ˆ˜๋งŒํผ ๋ฐ”์ดํŠธ(db) ๊ณต๊ฐ„์„ ์ „๋ถ€ 0์œผ๋กœ ์ฑ„์šฐ๋ผ๋Š” ๋ช…๋ น์–ด์ž…๋‹ˆ๋‹ค.
This command fills the specified number of bytes (db) with zeros.

1)๋ถ€ํŒ…ํŒ๋ณ„์„ ์œ„ํ•œ ์‹œ๊ทธ๋‹ˆ์ฒ˜๊ฐ€ ํ•„์š” ์—†๊ธฐ ๋•Œ๋ฌธ์— 512์ž…๋‹ˆ๋‹ค.
It is 512 because no signature is required to determine the boot status.

times 512 - ($ - $$) db 0

Leave a Reply