1 ;=============================================================================
\r
3 ; MMURTL IMAGE LOADER code:
\r
5 ; Turn ON A20 adress line gate
\r
6 ; Moves the OS data to 00000000 physical.
\r
7 ; Moves the OS Code to 00010000 physical (64K Boundary)
\r
8 ; Jumps to the OS Code entry point.
\r
9 ; (This basically turns MS-DOS into a $79.00 loader)
\r
12 ; We define the GDT and IDT entries in MOS.gdt and MOS.idt.
\r
14 ; NOTE: This the last the processor sees of 16 bit real mode code
\r
15 ; (no great loss at all)
\r
17 ;=============================================================================
\r
19 LoadSeg SEGMENT USE16
\r
20 ASSUME CS:LoadSeg, DS:Nothing, ES:Nothing, SS:Nothing
\r
22 IDTptr DW 7FFh ;LIMIT 256 IDT Slots
\r
23 DD 0000h ;BASE (Linear)
\r
25 GDTptr DW (nGDTSlots*8)-1 ;LIMIT 768 GDT Slots
\r
26 DD 0800h ;BASE (Linear)
\r
29 OSCodeSize EQU OSCodeEnd-OSCodeBegin
\r
30 OSCodeMore EQU OSCodeSize - 10000h
\r
31 OSDataSize EQU OSDataEnd-OSDataBegin
\r
35 START: CLI ; first we clear interrupts
\r
37 ; Note: this next few lines of code turns on the address line 20 Gate!
\r
38 ; This must be done before we can physically address above 1 Meg!
\r
40 XOR CX,CX ;check 64K times
\r
42 IN AL,64h ;Read Status Byte into AL
\r
43 TEST AL,02h ;Test The Input Buffer Full Bit
\r
47 XOR CX,CX ;check 64K times
\r
49 IN AL,64h ;Read Status Byte into AL
\r
50 TEST AL,02h ;Test The Input Buffer Full Bit
\r
54 XOR CX,CX ;check 64K times
\r
56 IN AL,64h ;Read Status Byte into AL
\r
57 TEST AL,02h ;Test The Input Buffer Full Bit
\r
60 ; Move OS data to Physical Address 0000h
\r
62 MOV AX,SEG OSDSeg ; Move Data segment to 0000h
\r
64 XOR SI,SI ; Source DS:SI
\r
67 XOR DI,DI ; Destination ES:DI
\r
68 MOV ECX, OSDataSize+3 ;
\r
72 ; Move OS Code to Physical Address 20000h (in 32K chunks)
\r
74 MOV AX,SEG OSCSeg ; Move OS Code to 10000h
\r
75 ADD AX, 1000h ; 10000h bytes into DOS segment
\r
77 XOR SI, SI ; Source DS:SI
\r
78 MOV AX,1000h ; Segment 1000h (address 10000h)
\r
80 XOR DI,DI ; Destination ES:DI
\r
81 MOV CX,8000h ; 64K Max (CODE is > 64K)
\r
85 MOV AX,SEG OSCSeg ; Move OS Code to 10000h
\r
86 ADD AX, 1800h ; 10000h bytes into DOS segment
\r
88 XOR SI, SI ; Source DS:SI
\r
89 MOV AX,1800h ; Segment 1800h (address 18000h)
\r
91 XOR DI,DI ; Destination ES:DI
\r
92 MOV CX,8000h ; 64K Max (CODE is > 64K)
\r
96 MOV AX,SEG OSCSeg ; Move OS Code to 10000h
\r
99 XOR SI, SI ; Source DS:SI
\r
100 MOV AX,2000h ; Segment 1000h (address 10000h)
\r
102 XOR DI,DI ; Destination ES:DI
\r
103 MOV CX, OSCodeMore+4;
\r
107 LIDT CS:FWORD PTR IDTptr ; Load IDTR
\r
108 LGDT CS:FWORD PTR GDTptr ; Load GDTR
\r
110 MOV EAX,CR0 ; Set Protected Mode BIT
\r
114 JMP Next ; Clear Instruction Prefetch Queue
\r
116 MOV BX,DataSel ; Setup Data Selectors
\r
117 MOV DS,BX ; D Selector
\r
118 MOV ES,BX ; E Selector
\r
119 MOV FS,BX ; F Selector
\r
120 MOV GS,BX ; G Selector
\r
121 MOV SS,BX ; S Selector
\r
123 ; PROTECTED MODE FAR JUMP TO 8:Offset OS code
\r
125 DB 066h ; 32 bit Data prefix
\r
126 DB 067h ; 32 bit Address instruction prefix
\r
127 DB 0EAh ; far jump opcode
\r
128 DD OFFSET OSInitBegin ; 32 bit Offset ( Code Offset )
\r
129 DW OSCodeSel ; 16 bit Selector ( Code Selector )
\r