Getting Ready to Enter x86 Protected ModeDiagnosticsHexadecimal DisplayConversion AlgorithmLookup-Table AlgorithmAlternative to avoid data-tableIn-Class Exercise #1Protected-Mode AddressesSegment Descriptor Format“Hidden” part of Segment RegistersSegment-Register “cache”ObservationProject #1In-Class Exercise #2Getting Ready to Enter x86 Protected ModeSurvival tactics for enabling Protected-Mode with a minimum of supporting infrastructureDiagnostics•Upon entering protected-mode, the “rules” change regarding the allowed CPU actions•Memory-addresses are computed using a different set of circuitry within the CPU•Restrictions are enforced by generating a variety of “exceptions” which interrupt the CPU’s normal fetch-execute cycle•We will need to “diagnose” their causesHexadecimal Display•To display values in registers or memory locations, we need to convert from binary numbers to character-strings that consist of ascii-codes for hexadecimal numerals•Why? Because hexadecimal values are easy for human programmers to convert into the actual bit-patterns represented, allowing us to “see” inside the computerConversion Algorithm•The easiest algorithm to understand uses a “lookup table” for converting ‘nybbles’ to ascii numerals: 0000→ ‘0’ (=0x30) 1010→ ‘A’ (=0x41) 0001→ ‘1’ (=0x31) 1011→ ‘B’ (=0x42) 0010→ ‘2’ (=0x32) 1011→ ‘C’ (=0x43)••• ••• 1001→ ‘9’ (=0x39) 1111→ ‘F’ (=0x46)Lookup-Table Algorithmhexlist: .ASCII “0123456789ABCDEF”;----------------------------------------------------------; Algorithm assumes DS already is setup lea bx, hexlist ; point DS:BX to table and al, #0x0F ; isolate nybble in ALxlat ; replace AL from tableAlternative to avoid data-table; Clever machine-algorithm (by Tim Lopez) and al, #0x0F ; isolate nybble in AL cmp al, #10 ; set carry-flag for SBB sbb al, #0x69 ; subtract-with-borrow das ; adjustment to result ; no lookup-table is needed here, just some; “immediate data” within instruction-streamIn-Class Exercise #1•Try replacing use of the ‘xlat’ instruction by the three Lopez-Algorithm instructions, in our bootsector demo-program ‘regdump.s’•Then the array of hexadecimal numerals, and the instruction setup for register BX, can be removed from the program source•Question: How many bytes are saved?Protected-Mode Addresses Segment-selectorLogical Address:Segment-offsetOperand’s effective addressPhysical Address:descriptordescriptordescriptordescriptorSegment Descriptor Table+Segment Base-address (also Segment-Limit and Access Rights)Validity is checked by CPUSegment Descriptor FormatBase[31..24] G DRSVAVLLimit[19..16]PDPLS XC/DR/WA Base[23..16]Base[15..0] Limit[15..0]63 32310“Hidden” part of Segment Registersselector Segment base Segment limitAccessrightsThe programmer-visible part of a segment-registerThe “invisible” parts of a segment-registerSegment-Register “cache”•The hidden portions of segment-registers are modified whenever any instruction modifies a segment-register’s visible part •Examples: mov ds, axpop eslss esp, tosjmpf #main, #0x07C0iretObservation•If we can enter protected-mode, but NOT do anything to alter any segment-register, then we won’t need to construct Tables of Segment-Descriptors•The left-over real-mode descriptor-values will still be in the segment-registers’ cache•We will pursue this idea in a future lessonProject #1•To get us ready for diagnosing the causes of protected-mode “exceptions”, we build a program that displays the contents of CPU registers (in hexadecimal format) similar to the ‘regdump.s’ demo (from our website)•Two more segment-registers: FS and GS•Also four special control-registers: CR0, CR2, CR3, CR4In-Class Exercise #2•Modify the ‘regdump.s’ bootsector demo so that it also displays the contents in the new 80386 segment-registers: FS and GS•Test your changes by reassembling you modified program text, installing it on the floppy diskette in your workstation, then rebooting (use the diskette’s menu-item)•Try rebooting from a diskette
View Full Document