home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / assemblr / library / cpu / protex / protm1.pas < prev    next >
Pascal/Delphi Source File  |  1989-10-01  |  4KB  |  149 lines

  1. program protected_mode_and_back;
  2. {$u-,k-}
  3.  
  4. { Beeps once (low tone) }
  5.  
  6. CONST
  7.   gdt_size = 8;  { Max number of desc. m 1 }
  8.   idt_size = 13;
  9.   code_desc = 48;
  10.  
  11.   data_seg : INTEGER = 0;
  12.   stack_seg: INTEGER = 0;
  13.   extra_seg: INTEGER = 0;
  14.  
  15. TYPE
  16.   descriptor = RECORD
  17.     seg_limit       : INTEGER;
  18.     base_lo_word    : INTEGER;
  19.     base_hi_byte    : BYTE;
  20.     data_acc_rights : BYTE;
  21.     data_reserved   : INTEGER;
  22.   END;
  23.  
  24.   string80 = string[80];
  25.  
  26. VAR
  27.   gdt  :  array[0..gdt_size] of descriptor;
  28.   idt  :  array[0..idt_size] of descriptor;
  29.   result : RECORD
  30.     ax, bx, cx, dx, bp, si, di, ds, es, flags : INTEGER;
  31.   END;
  32.   mask1_8259, mask2_8259 : BYTE;
  33.   screen : array[0..$2000] of byte absolute $40:0;
  34.  
  35.  
  36. PROCEDURE setup_error;
  37.   Begin                      { setup_error };
  38.     Writeln;
  39.     Writeln('There has been an error during setup of descriptor tables.');
  40.     Halt;
  41.   End                        { setup_error };
  42.  
  43.  
  44. PROCEDURE Set_Gdt_Desc(num, seg_lim, base_lo : INTEGER;
  45.                        base_hi, acc_rights : BYTE);
  46.   Begin            { set_gdt_desc }
  47.     If (num >= 0) AND (num <= gdt_size)
  48.       Then
  49.         begin
  50.           with gdt[num] do
  51.             begin
  52.               seg_limit := seg_lim;
  53.               base_lo_word := base_lo;
  54.               base_hi_byte := base_hi;
  55.               data_acc_rights := acc_rights;
  56.               data_reserved := 0;
  57.             end;  { with }
  58.         end { then }
  59.       Else setup_error;
  60.   End;            { set_gdt_desc }
  61.  
  62.  
  63. PROCEDURE Set_Idt_Desc(num, seg_lin, base_lo : INTEGER;
  64.                        base_hi, acc_rights : BYTE);
  65. { This Procedure set up seg num in IDT }
  66.   Begin
  67.     If (num >= 0) AND (num <= idt_size)
  68.       Then
  69.         begin
  70.           with idt[num] do
  71.             begin
  72.               seg_limit := seg_lim;
  73.               base_lo_word := base_lo;
  74.               base_hi_byte := base_hi;
  75.               data_acc_rights := acc_rights;
  76.               data_reserved := 0;
  77.             end;  { with }
  78.         end { then }
  79.       Else setup_error;
  80.   End;            { set_idt_desc }
  81.  
  82.  
  83. PROCEDURE Beep;
  84.   Begin
  85.     Sound(300);
  86.     Delay(400);
  87.     NoSound;
  88.     Delay(400);
  89.   End;
  90.  
  91. PROCEDURE ErrBeep;
  92.   Begin
  93.     Sound(2000);
  94.     Delay(400);
  95.     NoSound;
  96.     Delay(400);
  97.   End;
  98.  
  99. PROCEDURE Fault; { Entered if a processor fault occurs while in PM }
  100.   Begin
  101.     ErrBeep; ErrBeep;
  102.     { Pop The 4 words on the stack where the fault occured }
  103.     Inline($5B/$5B/$5B/$5B);
  104.     Port[$64] := $FE; { Return to real mode }
  105.     Inline($F4); { Simply halt the system }
  106.   End;
  107.  
  108.  
  109. PROCEDURE Setup_Idt; { Load IDT with appropriate values }
  110.   Var
  111.     X : INTEGER;
  112.   Begin
  113.     Set_Idt_Desc(0,Ofs(Fault)+7,Code_Desc,0,$86);
  114.     Set_Idt_Desc(1,Ofs(Fault)+7,Code_Desc,0,$86);
  115.     Set_Idt_Desc(2,Ofs(Fault)+7,Code_Desc,0,$86);
  116.     Set_Idt_Desc(3,Ofs(Fault)+7,Code_Desc,0,$86);
  117.     Set_Idt_Desc(4,Ofs(Fault)+7,Code_Desc,0,$86);
  118.     Set_Idt_Desc(5,Ofs(Fault)+7,Code_Desc,0,$86);
  119.     Set_Idt_Desc(6,Ofs(Fault)+7,Code_Desc,0,$86);
  120.     Set_Idt_Desc(7,Ofs(Fault)+7,Code_Desc,0,$86);
  121.     Set_Idt_Desc(8,Ofs(Fault)+7,Code_Desc,0,$86);
  122.     Set_Idt_Desc(9,Ofs(Fault)+7,Code_Desc,0,$86);
  123.     Set_Idt_Desc(10,Ofs(Fault)+7,Code_Desc,0,$86);
  124.     Set_Idt_Desc(11,Ofs(Fault)+7,Code_Desc,0,$86);
  125.     Set_Idt_Desc(12,Ofs(Fault)+7,Code_Desc,0,$86);
  126.     Set_Idt_Desc(13,Ofs(Fault)+7,Code_Desc,0,$86);
  127.   End;
  128.  
  129. PROCEDURE Addr24(Segment, Offset:INTEGER;
  130.                  Var A24w:INTEGER; Var A24b:BYTE); { 20 bit to 24bit conv }
  131.   Var
  132.     X : INTEGER;
  133.     Y : BYTE;
  134.   Begin
  135.     Inline(
  136.            $8B/$86/Segment/               { Mov  Ax,Segment[Bp]            }
  137.            $BA/$10/$00/                   { Mov  Dx,16            (4 bits) }
  138.            $F7/$E2/                       { Mul  Dx                        }
  139.            $03/$86/Offset/                { Add  Ax,Offset[Bp]             }
  140.            $83/$D2/$00/                   { Adc  Dl,0                      }
  141.            $88/$96/Y/                     { Mov  Y[Bp],Dl                  }
  142.            $89/$86/X);                    { Mov  X[Bp],Ax                  }
  143.     A24w := X;
  144.     A24b := Y;
  145.   End;
  146.  
  147.  
  148.  
  149.