8086 Assembler Tutorial for Beginners (Part 11)

Making your own Operating System

הדרכה בתכנות אסמבלר 8086 למתחילים (חלק 11)  

כתיבת מערכת הפעלה אישית

Usually, when a computer starts it will try to load the first 512-byte sector (that's Cylinder 0, Head 0, Sector 1) from any diskette in your A: drive to memory location 0000h:7C00h and give it control. If this fails, the BIOS tries to use the MBR of the first hard drive instead.

This tutorial covers booting up from a floppy drive, the same principles are used to boot from a hard drive. But using a floppy drive has several advantages:
  • You can keep your existing operating system intact (Windows, DOS...).

  • It is easy to modify the boot record of a floppy disk.


Example of a simple floppy disk boot program:

בדרך כלל, כאשר מופעל מחשב, הוא ינסה להטעין את 512 הבתים הראשונים של כל דיסקט הנמצא בכונן :A לחיפוש מערכת ההפעלה (מסלול "0" החיצוני של הדיסקט, ראש "0", במקטע 1), ואותם נתונים מעתיק לזיכרון ה-RAM שבכתובת 0000h:7C00h ומעביר את בקרת המחשב לאותו מקום. אם זה נכשל, אז תוכנית BIOS מנסה להפעיל מערכת הפעלה דרך טבלת MBR של דיסק הקשיח.

השיעור הזה מכסה את תהליך האתחול מתוך דיסקט, אותם עקרונות משתמשים לאתחול מתוך כונן קשיח. יש יתרונות בשימוש בדיסקט:

  • אתה יכול לשמור את מערכת ההפעלה הקיים אצלך שלם וללא תקלות (חלונות למיניהם, דוס, ...).
     

  •  זה קל לשנות את תוכן אזור האתחול של הדיסקט.

דוגמה של מערכת הפעלה פשוטה לאתחול מתוך דיסקט:


; directive to create BOOT file:
;                    הנחייה ליצירת קובץ אתחול
#MAKE_BOOT#

; Boot record is loaded at 0000:7C00,
; so inform compiler to make required
; corrections:
        0000:7C00  רשומת אתחול נטענת בכתובת
 אז מגדירים את המהדר לביצוע עדכונים מתאימים
ORG 7C00h

; load message address into SI register:
;                SI טען כתובת ההודעה בתוך אוגר
LEA SI, msg

; teletype function id:   כתובת פונקציה פלט
MOV AH, 0Eh

print:   MOV AL, [SI]
         CMP AL, 0
         JZ done
         INT 10h   ; print using teletype.
                   ;           הדפסה במסך
         INC SI
         JMP print

; wait for 'any key':      ממתין להקשה במקלדת
done:      MOV AH, 0
           INT 16h


; store magic value at 0040h:0072h:
 0040h:0072h :שמור ערך כתובת אתחול למצביע ב
;   0000h - cold boot.                אתחול קר
;   1234h - warm boot.                אתחול חם
MOV     AX, 0040h
MOV     DS, AX
MOV     w.[0072h], 0000h ; cold boot.
אתחול קר

JMP 0FFFFh:0000h  ; reboot!       ! אתחול מחדש


new_line EQU 13, 10 ;    הגדרת קבוע לשורה חדשה

msg DB  'Hello This is My First Boot Program!'
    DB  new_line, 'Press any key to reboot', 0

Copy the above example to Emu8086 source editor and press [Compile and Emulate] button. The Emulator automatically loads ".boot" file to 0000h:7C00h.

You can run it just like a regular program, or you can use the Virtual Drive menu to Write 512 bytes at 7C00h to the Boot Sector of a virtual floppy drive (FLOPPY_0 file in Emulator's folder).
After writing your program to the Virtual Floppy Drive, you can select Boot from Floppy from Virtual Drive menu.

העתק את הדוגמה הקודמת לעורך קובץ מקור ולחץ בכפתור: [הידור ואמולציה].
 האמולטור טוען קובץ ה- "
boot." לכתובת 0000h:7C00h שבזיכרון כתיבה/קריאה (RAM).

אתה יכול להריץ את זה כמו תוכנית רגילה, או אתה יכול להשתמש בתפריט של הכונן המדומה לכתיבת 512 בתים החל מכתובת
7C00h במקטע האתחול של דיסקט מדומה (קובץ FLOPPY_0 בתיקיה של האמולטור).

לאחר כתיבת התוכנית שלך לכונן דיסקטים המדומה, אתה יכול לבחור אתחול מתוך דיסקט בתפריט של כונן מדומה

If you are curious, you may write the virtual floppy (FLOPPY_0) or ".boot" file to a real floppy disk and boot your computer from it, I recommend using "RawWrite for Windows" from: http://uranus.it.swin.edu.au/~jn/linux/rawwrite.htm
(recent builds now work under all versions of Windows!)

Note: however, that this .boot file is not an MS-DOS compatible boot sector (it will not allow you to read or write data on this diskette until you format it again), so don't bother writing only this sector to a diskette with data on it. As a matter of fact, if you use any 'raw-write' programs, such at the one listed above, they will erase all of the data anyway. So make sure the diskette you use doesn't contain any important data.

מתוך סקרנות, אתה יכול לכתוב את הדיסקט המדומה (FLOPPY_0) או את הקובץ "boot." לדיסקט ממשי ולאתחל דרכו את המחשב שלך, מומלץ להשתמש "RawWrite for Windows" מכתובת אינטרנט:
http://uranus.it.swin.edu.au/~jn/linux/rawwrite.htm
גרסה חדשה פועלת בכל הגרסאות של חלונות !

הערה: קובץ אתחול זה הוא לא מתאים למקטעים של
MS-DOS. אין באפשרותך לקרוא או לקרוא נתונים מדיקט זה עד לאתחול מחדש של הדיסקט.  אז זהירות בכתיבת מקטע של אתחול בדיסקט עם נתונים.
למעשה, אם אתה משתמש בכל תוכנית לש קריאה או כתיבה, כמו זה שרשום מעלה, בכל אופן ימחקו כל הנתונים .
וודא שהדיסקט שאתה משתמש לא מכיל נתונים חשובים.


".boot" files are limited to 512 bytes (sector size). If your new Operating System is going to grow over this size, you will need to use a boot program to load data from other sectors. A good example of a tiny Operating System can be found in "Samples" folder as:
micro-os_loader.asm
micro-os_kernel.asm


To create extensions for your Operating System (over 512 bytes), you can use ".bin" files (select "BIN Template" from "File" -> "New" menu).

To write ".bin" file to virtual floppy, select "Write .bin file to floppy..." from "Virtual Drive" menu of emulator:


קבצים מסוג "boot." מוגבלים ב- 512 בתים (גודל של מקטע).
אם מערכת ההפעלה החדשה שלך הולכת לגדול מעל הגודל הזה, אתה תצטרך להשתמש בתוכנית האתחול לטעינת נתונים ממקטעים אחרים. 
דוגמה טובה של מערכת הפעלה ניתן למצאו בתיקיית "
Samples" ב- :
            
micro-os_loader.asm
             micro-os_kernel.asm


ליצירת הרחבה של המערכת ההפעלה מעל ה- 512 בתים, אתה יכול להשתמש בקבצי "
bin." . בחר "מבנה BIN" בתפריט "קובץ" -> "חדש".

לכתיבת קבצי "
bin." לתוך דיסקט מדומה, בחר "רשום קובץ bin. בתוך דיסקט" מתוך תפריט "דיסקט מדומה" של האמולטור:

You can also use this to write ".boot" files. אתה יכול להשתמש לכתיבת קבצי ".boot".
Sector at:   -מקטע ב

Cylinder: 0
Head:     0
Sector:   1

is the boot sector!
!
זה המקטע של אתחול

Idealized floppy drive and diskette structure: עיקרון כונן דיקטים ומבנה של דיסקט
מקרא של התמונה:
               
Cylinder      =  מסלול
                   
Sector        =  מקטע
                   
Head          =  ראש כתיבה/קריאה
                   
Floppy Disk
= דיסקט גמיש

For a 1440 kb diskette:

  • Floppy disk has 2 sides, and there are 2 heads; one for each side (0..1), the drive heads move above the surface of the disk on each side.

  • Each side has 80 cylinders (numbered 0..79).

  • Each cylinder has 18 sectors (1..18).

  • Each sector has 512 bytes.

  • Total size of floppy disk is: 2 x 80 x 18 x 512 = 1,474,560 bytes.

To read sectors from floppy drive use
 INT 13h / AH = 02h.

עבור דיסקט של 1440 קילו-בית (1440KB)

  • לדיסקט גמיש 2 צדדים, ובכונן 2 ראשים; אחד לכל צד (0..1), הראשים זזים מעל המשטח של הדיסקט בכל צד
     
  • לכל צד 80 צילינדרים (מסלולים) הממוספרים מ- 0 עד 79 .
     
  • לכל צילינדר (מסלול) יש 18 מקטעים הממוספרים מ- 0 עד 18 .
     
  • לכל מקטע 512 בתים.
     
  • תכולה הכוללת של דיסקט הוא:
    512 * 18 * 80 * 2 = 1,474,560 בתים.

לקריאת מקטעים של הדיסקט משתמשים ב-:
             
INT 13h / AH = 02h.

<<< to Part 10 <<   >> to Part 12 >>>

<<< לחלק 12 <<   >> לחלק 10 >>>