U E D R , A S I H C RSS

VM Ware/OS Implementation Test

2. ž‘„ฑ•œ œ 

OSฅผ งŒ“ค–๊ณ  ‹ถ€ งˆŒ— ž‘ • ›ฐ– “ค—ˆŠ”ฐ Œ€€ถ„ ™˜๊ฒฝ€ ฆฌˆ…Šคƒ
gcc˜€Šต‹ˆ‹ค. •˜€งŒ  €Š” windows ™˜๊ฒฝ•˜˜ vc ๊ฐœฐœ„ ฃผกœ •™”œผ€กœ ™
ถˆŽธ(?)–ˆŠต‹ˆ‹ค. Djgpp ผŠ” dosšฉ gcc ฌŒ… ฒ„ „๊ณผ œˆ„šฐšฉ cygwin Œจ‚ค€ฅผ
‚ฌšฉ•˜ —ญ‹œ ™ผ•˜๊ฒŒ gccฅผ œˆ„šฐ—„œ ŒŒผ •  ˆ˜ žˆŠต‹ˆ‹ค ๊ทธž˜„  €Š” vc˜
—””Œ… ™˜๊ฒฝ ง˜— “ค–„œ ””ฒ„๊น…๊นŒ€Š” ž˜“ค๊ฒ €งŒ (–ฐจ”ผ „ ””ฒ„๊น…•˜ ค
ŠคŠคกœ ž‹ ˜ „ ””ฒ„๊ฑฐฅผ งŒ“ค–••˜Š” ๊ฑฐ ๊ฐ™Šต‹ˆ‹ค. ) —””Œ…๊ณผ ŒŒผ
๊ทธฆฌ๊ณ  งฅผ vc6ฅผ ‚ฌšฉ•˜๊ณ  ‹ถ—ˆ๊ณ  ๊ทธž˜„œ ฅผ ‚ฌšฉ•  ˆ˜ žˆŠ” ฐฉ•„ †Œ๊ฐœ•˜ ค
•‹ˆ‹ค.

3. ฐธ๊ณ •˜ ข‹€ ‚ฌŠธ“ค

– คš ˜ฌธ OS๊ฐœฐœฐฉ•„ •œ๊ธ€™” •ฃผŠ” ๊ณ งˆš ‚ฌŠธ
Chobits os˜ †ŒŠคฅผ –„ ˆ˜ žˆŠต‹ˆ‹ค.
™ ข‹€ Protected mode— Œ€•œ „ค…๊ณผ †ŒŠคฅผ ‹๊ณ  žˆŠ” ‚ฌŠธ
http://www.nondot.org/sabre/os/articles
-
OS— Œ€•œ  „ฐ˜ ธ žฃŒ๊ฐ€ žˆŠต‹ˆ‹ค.
http://www.osdever.net/
-
Bona Fide OS ๊ฐœฐœ Šœ† ฆฌ–ผ ‚ฌŠธ
http://mega-tokyo.com/osfaq2/
-
OS FAQ
http://www.osdev.org/
-
†ŒŠค๊ฐ€ ๊ณต๊ฐœœ —ฌŸฌ os๊ฐ€ žˆŠต‹ˆ‹ค.
http://www.bellona2.com
-
˜ผž„œ GUI OSฅผ งŒ“œ‹œ๊ณ  ฑ…„ ถœŒ•˜‹  ถ„˜ ‚ฌŠธ
http://ksyspro.org
-
•œ๊ตญ ž„ฒ ””“œ ๊ฐœฐœž ž„

4. Protected i386 OSฅผ œ„•œ 잛€ „ค…

Intel€ ‹คฅธ cpu ฒค”‹ค —ญ‚ฌ๊ฐ€ ˜คž˜˜–„œ 4bit microprocessorธ 4004—„œ
ถœฐœ•„œ 8bit cpu 8008, 8080, 16น„Šธ 8086, 80186, 80286, 32น„Šธ 80386, 80486,
80586 (˜Š” P5 ๊ทธŸฌ‚˜ ˆซžŠ”  €ž‘๊ถŒ ˜ธฅผ ฐ›€ •œ‹ค๊ธธž˜ ›„— Pentiumœผกœ
ฐ”€Œ—ˆŠต‹ˆ‹ค ).  ‡๊ฒŒ ๊ธ —ญ‚ฌฅผ ๊ฐ–๊ณ  žˆŠ” Žธ ธ cpu 8080 ˜Š” 8086 †ต‹€–
intel x86 cpu—„œ Œ˜ ”„กœ๊ทธžจ„ 586—„œ„ ˆ˜–‰˜„ก •˜œ„˜ธ™˜„ ๊ฐ–๊ฒŒ ฉ‹ˆ‹ค.

 •˜œ„˜ธ™˜ •Œฌธ— •„ฆฌ ตœ‹  “จ„ฐ„ ฒ˜Œ €Œ…‹œ—Š” น ฅธ x86 ฒ˜Ÿผ
ˆ˜–‰˜„ก „ค๊ณ„˜—ˆŠต‹ˆ‹ค. €Šธ„น„ฐ—„œ  น ฅธ x86—„œ ตœ‹ ˜ ๊ธฐŠฅ„ ‚ฌšฉ•˜Š”
i386+ ™˜๊ฒฝœผกœ งŒ“ค๊ธฐ œ„•„œ  –„ ‹คŒ๊ณผ ๊ฐ™€ ผ„ •˜๊ฒŒ ฉ‹ˆ‹ค.

ORG 0x7C00 - PC๊ฐ€ ฆฌ…‹˜ €Œ…  ””ฐ”Šค˜ ฒซฒˆงธ „น„ฐ(512ฐ”Šธ)ฅผ
ฝ– ฉ”ฆฌ 0x7C00— ˜ฌ ค †“€ ›„  ฝ”“œกœ  ”„•˜๊ฒŒ ฉ‹ˆ‹ค. ”ฐผ„œ €Šธ„น„ฐ
ฝ”“œŠ” ๊ทธ ฉ”ฆฌ—„œ ‹œž‘•œ‹ค๊ณ  € •••• ๊ฒƒž…‹ˆ‹ค.

A20 enable - ˜ˆ „—Š” ‹ค œ ฉ”ฆฌฌ๊ธฐ๊ฐ€ ฌ€ •Š•„ 1M •˜งŒ  ‘๊ทผ•˜„ก
„ค๊ณ„˜—ˆŠ”ฐ    ฉ”ฆฌ๊ฐ€ 1Mƒ ˜Š” ๊ฒƒ งŽ•„ 1M ƒ„ ‹ค œ  ‘๊ทผ •˜๊ธฐ œ„•„œ
•ฃผ–••‹ˆ‹ค.

Protected mode - ฒ˜Œ €Œ…• • x86 Real ModeผŠ” „ธ๊ทธจผŠธ:˜ค”„…‹
€ • ฐฉ‹œผกœ ˆ˜–‰˜€งŒ 80286ƒ—„œŠ” ˜ธ“œ๊ฐ€ €›˜—ˆ๊ณ  (ตœŒ€16M๊ฐ€Šฅ)
80386—„œŠ” 4G๊นŒ€  ‘๊ทผ ๊ฐ€Šฅ•˜„ก ˜—ˆŠต‹ˆ‹ค.

„กœ“œ - €Šธ„น„ฐ ฝ”“œŠ” Cกœœ ฐ”„ˆฆฌ „„ —ฌŸฌ „น„ฐ—„œ
ฝ–„œ Šน • ฉ”ฆฌ ฒˆ€— กœ“œ•œ ›„ ๊ทธ ‹œž‘ •ˆ˜ (—”Šธฆฌ ฌธŠธ •ˆ˜)กœ  ”„•˜๊ฒŒ
ฉ‹ˆ‹ค.

5. €น„ฌผ


VC6,
- „˜ ŒŒผ ฐ ง‚น„ ‹‹น•‹ˆ‹ค.
- šฐฆฌŠ” ””Šคผ“„ ‚ฌšฉ•˜€ •Š๊ณ  ฐ”กœ ŒŒผ•„œ ฏธ€กœ œฌ ›„ VMWareกœ
กœ“œ•  ๊ฒƒž…‹ˆ‹ค. ( no ”Œกœ”ผ €Œ…””Šคผ“, no ฆฌถ“, no test machine )

Nasm
- Netwide Asmœผกœ at&t ๊ณ„— ฐ intel ๊ณ„— ‘˜‹ค €›•˜๊ณ  target format„
งŽ €›•˜Š” –…ˆธ”Ÿฌž…‹ˆ‹ค. „คน˜๊ณผ •—† ๊ทธƒฅ nasm.exe งŒ žˆœผ ฉ‹ˆ‹ค.

6. †ŒŠค ŒŒผ“ค

bootsect.asm
- ๊ฐ„‹จ•œ ˜ธ“œ(„ธ๊ทธจผ…Œ…˜ฐฉ‹) ง„ž… ฐ „ กœ“œ €Šธกœ”

main.c
- VCกœ ŒŒผ  ž‘€ „

Makeboot.exe
- €Šธ„น„ฐ™€ „ฏธ€ฅผ merge•˜Š” ๊ฐ„‹จ•œ makeboot.c ŒŒผ•„œ ž‹ งŒ˜
€Šธ ฏธ€ œจŠ” ”„กœ๊ทธžจ งŒ“คœ‹ค.

7. †ŒŠค

7.1. bootsect.asm

[BITS 16]       ; We need 16-bit intructions for Real 
mode

[ORG 0x7C00]    ; The BIOS loads the boot sector into memory location 
0x7C00

reset_drive:

        mov ah, 0               ; RESET-command

        int 13h                 ; Call interrupt 13h

        or ah, ah               ; Check for error code

        jnz reset_drive         ; Try again if ah != 0

        ;vc—„œ /base 10000 กœ 헀๊ธฐ •Œฌธ— —ฌ๊ธฐ„œ€„ฐ ฉ”ฆฌฅผ กœ“œ
        ; •••œ‹ค. ES:BX กœ 1000:0000h ๊ธฐ •Œฌธ— •„ž˜ฒ˜Ÿผ •œ‹ค.

        mov ax, 1000h           ; es:bx <-- 1000:0000h 

        mov es, ax
        mov bx, 0h          ; Destination address = 0000:1000

        mov ah, 02h             ; READ SECTOR-command

        ; ‘ฒˆงธ „น„ฐ€„ฐ 3นธ„น„ฐ๊ฐ€ „ฏธ€ „น„ฐ‹ค.

        mov al, 3h             ; Number of sectors to read = 1

        mov ch, 0               ; Cylinder = 0

        ; ˜„žฌ ฒซฒˆงธ„น„ฐ512 ฉฐ ‘ฒˆงธ „น„ฐ€„ฐ 3๊ฐœ „น„ฐ๊ฐ€ „ฏธ€‹ค

        mov cl, 02h             ; Sector = 2

        mov dh, 0               ; Head = 0

        int 13h                 ; Call interrupt 13h

        or ah, ah               ; Check for error code

        jnz reset_drive         ; Try again if ah != 0

A20Address:    ; Set A20 Address line here

    CLI

    CALL enableA20

    STI
    JMP Continue

enableA20:
        call enableA20o1

        jnz short enableA20done

        mov al,0d1h

        out 64h,al

        call enableA20o1

        jnz short enableA20done

        mov al,0dfh

        out 60h,al

enableA20o1:

        mov ecx,20000h

enableA20o1l:

        jmp short $+2

        in al,64h

        test al,2

        loopnz enableA20o1l

enableA20done:

        ret

Continue:   

        cli                 ; Disable interrupts, we want to be alone

        xor ax, ax

        mov ds, ax              ; Set DS-register to 0 - used by lgdt

        lgdt [gdt_desc]         ; Load the GDT descriptor

        mov eax, cr0            ; Copy the contents of CR0 into EAX

        or eax, 1               ; Set bit 0

        mov cr0, eax            ; Copy the contents of EAX into CR0

        jmp 08h:clear_pipe      ; Jump to code segment, offset clear_pipe

[BITS 32]                       ; We now need 32-bit instructions

clear_pipe:

        mov ax, 10h             ; Save data segment identifyer

        mov ds, ax              ; Move a valid data segment into the data segment register

        mov ss, ax              ; Move a valid data segment into the stack segment register

        mov esp, 090000h        ; Move the stack pointer to 090000h

        ; 10200hกœ  ”„ 200hŠ” vcกœ ง‚น•˜ ๊ธฐณธ PE—ค”(200h)ฅผ ™—ฌ„œ ”–ˆ‹ค.

        ; 10200h ฆ‰ 1000:0200h กœ  ”„

        ;jmp 1000:0200h

        jmp 10200h

        

gdt:                    ; Address for the GDT

gdt_null:               ; Null Segment

        dd 0

        dd 0

gdt_code:               ; Code segment, read/execute, nonconforming

        dw 0FFFFh

        dw 0

        db 0

        db 10011010b

        db 11001111b

        db 0

gdt_data:              ; Data segment, read/write, expand down

        dw 0FFFFh

        dw 0

        db 0

        db 10010010b

        db 11001111b

        db 0

gdt_end:		; Used to calculate the size of the GDT

gdt_desc:               ; The GDT descriptor

        dw gdt_end - gdt - 1    ; Limit (size)

        dd gdt                  ; Address of the GDT

times 510-($-$$) db 0           ; Fill up the file with zeros

        dw 0AA55h                ; Boot sector identifyer
•„ž˜ฒ˜Ÿผ –…ˆธ” •˜—ฌ ˜คธŒ  €Šธกœ” ฐ”„ˆฆฌฅผ ––‚•
•‹ˆ‹ค.

nasm -f bin bootsect.asm -o bootsect.bin

‹คŒ€ €Šธกœ”™€ „ ฏธ€ฅผ •ณ„œ •˜‚˜˜ €Œ…ฏธ€กœ งŒ“ค–ฃผŠ” makeboot.c
ž…‹ˆ‹ค. ”ฐกœ ”„กœ Šธฅผ งŒ“ค–„œ ๊ฐ„‹จžˆ ŒŒผ•„œ makeboot.exeฅผ งŒ“ค„ก
•‹ˆ‹ค.
#include 

int 
main(int argnr, char *args[])

{

  FILE 
*output, *input;

  int 
i, bytes_read, sectors_read, bytes_from_file;

  char 
buffer[512];

  if 
(argnr < 4) {

    printf("Invalid 
number of parameters.\n\n");

    printf("USAGE: 
%s [output] [input 1] [input 2] ... [input n]\n", args[0]);

    printf("Example: 
%s a.img bootsect.bin kernel.bin");

    exit(0);

  }

  output 
= fopen(args[1], "r");

// 
ฎ– “ฐ๊ธฐ • ๊บผƒ๊ณ  ฌผ–Š” ฝ”“ ฐ ๊ทธƒฎ–“ฐž. --

  if 
(output != NULL) {

    buffer[0] 
= 0;

  }

  fclose(output);

  output 
= fopen(args[1], "wb");

  for 
(i = 2; i < argnr; i++) {

    input 
= fopen(args[i], "rb");

    if 
(input == NULL) {

      printf("Missing 
input file %s. Aborting operation...", args[i]);

      fclose(output);

      exit(1);

    }

    bytes_read 
= 512;

    bytes_from_file 
= 0;

    sectors_read 
= 0;

    while(bytes_read 
== 512 && !feof(input)) {

      bytes_read 
= fread(buffer, 1, 512, input);

      if 
(bytes_read == 0)

        break;

      if 
(bytes_read != 512)

        memset(buffer+bytes_read, 
0, 512-bytes_read);

      sectors_read++;

      fwrite(buffer, 
1, 512, output);

      bytes_from_file 
+= bytes_read;

    }

    printf("%d 
sectors, %d bytes read from file %s...\n", sectors_read, bytes_from_file, 

args[i]);

    fclose(input);

  }

  fclose(output);

  return 
0;

}

‹คŒ€ „ †ŒŠคž…‹ˆ‹ค.


// 
bro (bro@shinbiro.com)2004-02-17 - initial ( vc dev envronment setting )

// 
starting function

void 
start()

{   

    char* 
hello = "Hello OS!";

    unsigned 
char* vidmem = (unsigned char*)0xB8000;

    while( 
*hello != '\0' )        

    {

        *vidmem++ 
= *hello++;

        *vidmem++ 
= 7;        // ฌธž ๊ธฐณธ †„ฑ

    }   

    

    // 
„ ‚˜ •ˆœ‹ค. ๊ณ„† Œ•„••œ‹ค.   

    for(;;);

}

7.2. Visual C++ ŒŒผ ™˜๊ฒฝ ๊ตฌ„ฑ•˜๊ธฐ


œ„˜ „ †ŒŠคฅผ ŒŒผ •˜๊ธฐ œ„•„œ VC ŒŒผ ™˜๊ฒฝ„ ๊ตฌ„ฑ•„ก •‹ˆ‹ค.

จผ € Win32 Console Applicationœผกœ ๊ฐ„‹จžˆ ”„กœ Šธฅผ ƒ„ฑ•‹ˆ‹ค.

””ฒ„๊น…€ •˜‹ˆ ๊ทธƒฅ Release “œกœ „ ƒ•œ ›„ C++ „ธŒ…„ •„ž˜ฒ˜Ÿผ •‹ˆ‹ค.
/nologo /G4 /Zp1 /ML /W3 /vmg /vd0 /GX /Od /Gf /FAc /Fa"Release/" /Fo"Release/" /Fd"Release/" /FD /c
Linkƒ˜ ˜ต…˜€ •„ž˜ฒ˜Ÿผ •‹ˆ‹ค.
/nologo /base:"0x10000" /entry:"start" /subsystem:console /incremental:no /pdb:"Release/testos.pdb" /map:"Release/testos.map" /machine:I386 /nodefaultlib /out:"testos.bin" /DRIVER /align:512 /FIXED
˜•œ ŒŒผ ž‘—…—„œ ฐ”กœ €Šธ„น„ฐ„ ŒŒผ•˜๊ณ  ŒŒผ ‚˜ ฐ”กœ €Šธ ฏธ€„
งŒ“ค„ก Pre-Link™€ Post-Buildฅผ ž‘„ฑ•‹ˆ‹ค.

ŒŒผ„ •…‹ˆ‹ค.
Deleting intermediate files and output files for project 'testos - Win32 Release'.
--------------------Configuration: testos - Win32 Release--------------------
Compiling...
main.c
Linking...
LINK 
: warning LNK4096: /BASE value "10000" is invalid for Windows 95; image may 
not run 1 sectors, 512 bytes read from file bootsect.bin...
3 sectors, 1536 bytes read from file testos.bin...
testos.bin 
- 0 error(s), 1 warning(s)

8. VMWare …ŒŠคŠธ ™˜๊ฒฝ ๊ตฌ„ฑ•˜๊ธฐ

ŒŒผ„ งˆน˜๊ณ  ‚˜ •„ž˜™€ ๊ฐ™€ ƒƒ‰๊ธฐ Šต   ๊ฒƒž…‹ˆ‹ค. งˆ€ง‰œผกœ …„ฑœ testos.img ๊ฐ€ šฐฆฌ˜ „ ฏธ€๊ฐ€ ฉ‹ˆ‹ค.
zeropage:VMWareOSImplementationTest01.gif
Partcopy.exe ˆ„ ‚ฌšฉ•˜—ฌ €Œ… ””Šคผ“— †“„ ˆ˜„ žˆ€งŒ ฒˆ๊ฑฐกญŠต‹ˆ‹ค. ”ฐผ„œ VMWare—„œ ง ‘ ฅผ ””Šคผ“ ฏธ€กœ กœ“œ•˜„ก •‹ˆ‹ค.
zeropage:VMWareOSImplementationTest02.gif
กฐ๊ฑ ๊ทธƒฅ ๊ธฐณธœผกœ Next •‹ˆ‹ค.
zeropage:VMWareOSImplementationTest03.gif
 œผ ค‘š”•œ ๊ฒƒ€  ‡๊ฒŒ งŒ“  ๊ฐ€ƒ testos ˜ ”Œกœ”ผ ””Šคผ“ €Œ… „ค •ž…‹ˆ‹ค.
zeropage:VMWareOSImplementationTest04.gif
Use Floppy Image— •‹น img ŒจŠค งžถ”„ก •‹ˆ‹ค.

 œ ‹ค–‰•…‹ˆ‹ค.
zeropage:VMWareOSImplementationTest05.gif
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:28:21
Processing time 0.0347 sec