اهلا شباب اقدم لكم فى هذا الدرس الجزء الخاص بالتحويل بين اوضاع المعالج x86 وهو الجزء الثانى من الدرس التاسع
سوف نتعلم فى هذا الدرس كيفية التحويل بين الاوضاع المختلفة للمعالج ونحتاج هذا طبعا لانه كما ذكرنا سابقا اننا نحتاج الى التحويل من الوضع الحقيقى الذى عيوبه كثيرة بالنسبة لمتطلبات العصر الى الوضع المحمى الذى وضحنا ما هو ايضا فى الدرس السابق
عليك تذكر ان الوضع الغير حقيقى (Unreal Mode) هو يقبع فى الوضع الحقيقى لكنه يستخدم نظام عنونة الوضع المحمى
وتذكر ايضا ان الوضع الوهى 8086 هو يقبع فى الوضع المحمى لكنه يستخدم الوضع الحقيقى ليتم تنفيذه فى الوضع 16 Bit
وما يهمنا والذى سأشرحه هو التحويل الى الوضع المحمى من الوضع الحقيقى
أشياء يجب علينا تذكرها فى الوضع المحمى
1- لن تكون هناك مقاطعات متاحة واذا احتجت الى اى مقاطعة عتاد ستحتاج الى كتابتها بنفسك :)
2- عند تحويلك للنمط المحمى كن منتبها فان غلطة slightest
3- النمط المحمى يحتاج الى جدول مواصفات مثل GDT, LDT ,IDT
4- النمط المحمى يمكنك من الولوج الى 4 جيجا من الذاكرة مع خاصية حماية الذاكرة
5- سوف تستطيع استخدام مسجلات 32bit
توسيع boot loader
مقاطعات البيوس و الروتين المفيد
OEM Parameter Block
OEM Parameter Block تقوم بحفظ MBR و سجل معلومات الاقلاع والهدف الثانى هو توصيف نظام الملفات الموجود بالفعل على القرص
لن نقوم بوصف هذا الجدول حتى نأتى فى الدورة الى الجزء الخاص بشرح انظمة الملفات وشوف اقوم بتوضيح هذه الجزئية بالتفصيل وقتها ان شاء الله
هذا هو الكود الكامل للتحديثات فى ملفنا boot loader
********************************************* ; Boot1.asm ; - A Simple Bootloader ; ; Operating Systems Development Tutorial ;********************************************* bits 16 ; We are still in 16 bit Real Mode org 0x7c00 ; We are loaded by BIOS at 0x7C00 start: jmp loader ; jump over OEM block ;*************************************************; ; OEM Parameter block ;*************************************************; TIMES 0Bh-$+start DB 0 bpbBytesPerSector: DW 512 bpbSectorsPerCluster: DB 1 bpbReservedSectors: DW 1 bpbNumberOfFATs: DB 2 bpbRootEntries: DW 224 bpbTotalSectors: DW 2880 bpbMedia: DB 0xF0 bpbSectorsPerFAT: DW 9 bpbSectorsPerTrack: DW 18 bpbHeadsPerCylinder: DW 2 bpbHiddenSectors: DD 0 bpbTotalSectorsBig: DD 0 bsDriveNumber: DB 0 bsUnused: DB 0 bsExtBootSignature: DB 0x29 bsSerialNumber: DD 0xa0a1a2a3 bsVolumeLabel: DB "MOS FLOPPY " bsFileSystem: DB "FAT12 " ;*************************************************; ; Bootloader Entry Point ;*************************************************; loader: cli ; Clear all Interrupts hlt ; halt the system times 510 - ($-$$) db 0 ; We have to be 512 bytes. Clear the rest of the bytes with 0 dw 0xAA55 ; Boot Signiture
طباعة نص باستخدام المقاطعة 0x10 والفنكشن 0x0E
ملاحظة : نحن نستخدم المقاطعة INT 0x10 لمقاطعات الفيديو
INT 0x10 --- مخرجات الفيديو
AH = 0x0E
AL - امر الكتابة
BH - رقم الصفحة والذى من المفترض ان يكون صفرا (0)
BL -- لون الخلفية >>>> هذا فقط فى اوضاع الجرافيك
مثال بسيط
xor bx, bx ; A faster method of clearing BX to 0 mov ah, 0x0e mov al, 'A' int 0x10
هذا سوف يقوم بطباعة الحرف "A" على الشاشة
طباعة السلاسل الحرفية : باستخدام المقاطعة 0x10 والفنكشن 0x0E
باستخدام نفس المقاطعة نستطيع طباعة سلسلة صفرية مثال
sg db "Welcome to My Operating System!", 0 ;*************************************** ; Prints a string ; DS=>SI: 0 terminated string ;*************************************** Print: lodsb or al, al ; al=current character jz PrintDone ; null terminator found mov ah, 0eh ; get next character int 10h jmp Print PrintDone: ret ;*************************************************; ; Bootloader Entry Point ;*************************************************; loader: ; Error Fix 1 ------------------------------------------ xor ax, ax ; Setup segments to insure they are 0. Remember that mov ds, ax ; we have ORG 0x7c00. This means all addresses are based mov es, ax ; from 0x7c00:0. Because the data segments are within the same ; code segment, null em. mov si, msg call Print cli ; Clear all Interrupts hlt ; halt the system times 510 - ($-$$) db 0 ; We have to be 512 bytes. Clear the rest of the bytes with 0 dw 0xAA55 ; Boot Signiture
جلب معلومات وحجم الذاكرة ::
هذا فى منتهى السهولة
المقاطعة 0x12 تستخدم لجلب حجم الذاكرة وهذا مثال
xor ax, ax int 0x12 ; Now AX = Amount of KB in system recorded by BIOS
هذا الدرس صعب شيئا ما لذا قم بمراجعته اكثر من مرة لاننا فى المرة القادم سنتطرق الى امر اصعب والدروس ستسهل بعضها
وهذا هو الكود الخاص ب Boot Loader حتى هذا الدرس
********************************************* ; Boot1.asm ; - A Simple Bootloader ; ; Operating Systems Development Tutorial ;********************************************* bits 16 ; We are still in 16 bit Real Mode org 0x7c00 ; We are loaded by BIOS at 0x7C00 start: jmp loader ; jump over OEM block ;*************************************************; ; OEM Parameter block ;*************************************************; ; Error Fix 2 - Removing the ugly TIMES directive ------------------------------------- ;; TIMES 0Bh-$+start DB 0 ; The OEM Parameter Block is exactally 3 bytes ; from where we are loaded at. This fills in those ; 3 bytes, along with 8 more. Why? bpbOEM db "My OS " ; This member must be exactally 8 bytes. It is just ; the name of your OS :) Everything else remains the same. bpbBytesPerSector: DW 512 bpbSectorsPerCluster: DB 1 bpbReservedSectors: DW 1 bpbNumberOfFATs: DB 2 bpbRootEntries: DW 224 bpbTotalSectors: DW 2880 bpbMedia: DB 0xF0 bpbSectorsPerFAT: DW 9 bpbSectorsPerTrack: DW 18 bpbHeadsPerCylinder: DW 2 bpbHiddenSectors: DD 0 bpbTotalSectorsBig: DD 0 bsDriveNumber: DB 0 bsUnused: DB 0 bsExtBootSignature: DB 0x29 bsSerialNumber: DD 0xa0a1a2a3 bsVolumeLabel: DB "MOS FLOPPY " bsFileSystem: DB "FAT12 " msg db "Welcome to My Operating System!", 0 ; the string to print ;*************************************** ; Prints a string ; DS=>SI: 0 terminated string ;*************************************** Print: lodsb ; load next byte from string from SI to AL or al, al ; Does AL=0? jz PrintDone ; Yep, null terminator found-bail out mov ah, 0eh ; Nope-Print the character int 10h jmp Print ; Repeat until null terminator found PrintDone: ret ; we are done, so return ;*************************************************; ; Bootloader Entry Point ;*************************************************; loader: xor ax, ax ; Setup segments to insure they are 0. Remember that mov ds, ax ; we have ORG 0x7c00. This means all addresses are based mov es, ax ; from 0x7c00:0. Because the data segments are within the same ; code segment, null em. mov si, msg ; our message to print call Print ; call our print function xor ax, ax ; clear ax int 0x12 ; get the amount of KB from the BIOS cli ; Clear all Interrupts hlt ; halt the system times 510 - ($-$$) db 0 ; We have to be 512 bytes. Clear the rest of the bytes with 0 dw 0xAA55 ; Boot Signiture
والى اللقاء فى الدرس العاشر
تحياتى لكم
المراجع
http://members.tripod.com/protected_mode/prashant/protmode.html