home *** CD-ROM | disk | FTP | other *** search
File List | 1991-03-20 | 32.7 KB | 482 lines |
- Microsoft (R) Macro Assembler Version 5.10 3/20/91 22:38:53
- Method 1 Page 1-1
-
-
- 1 PAGE ,132
- 2 TITLE Method 1
- 3 .286P ; Tell MASM 2.0 about 286 instructions
- 4 ;--------------------------------------------------------------:
- 5 ; Sample Program 1 :
- 6 ; :
- 7 ; This program switches into Protected Virtual Mode, changes :
- 8 ; the display attribute to reverse video, and returns to Real :
- 9 ; Mode to exit to DOS :
- 10 ; :
- 11 ; Once entered into a file, do the following: :
- 12 ; MASM SAMPLE1; :
- 13 ; LINK SAMPLE1; :
- 14 ; EXE2BIN SAMPLE1 SAMPLE1.COM :
- 15 ; DEL SAMPLE1.EXE :
- 16 ; :
- 17 ; WARNING: This program will "kill" a PC. I should only :
- 18 ; be run on an AT. :
- 19 ;--------------------------------------------------------------:
- 20
- 21 0000 bios_data_seg SEGMENT at 0040h
- 22 0067 ORG 0067h
- 23 0067 0000 io_rom_init dw ? ; dword variable in BIOS data segment
- 24 0069 0000 io_rom_seg dw ? ; used to store a dword address
- 25 006B bios_data_seg ENDS
- 26
- 27 descriptor STRUC
- 28 0000 0000 seg_limit dw 0 ; segment limit (1-65536 bytes)
- 29 0002 0000 base_lo_word dw 0 ; 24 bit physical address
- 30 0004 00 base_hi_byte db 0 ; (0 - (16M-1))
- 31 0005 00 access_rights db 0 ; access rights byte
- 32 0006 0000 dw 0 ; reserved_386
- 33 0008 descriptor ENDS
- 34
- 35 = 0070 cmos_port equ 070h
- 36 = 009B code_seg_access equ 10011011b ;access rights byte for code seg
- 37 = 0093 data_seg_access equ 10010011b ;access rights byte for data seg
- 38 = 00DD disable_bit20 equ 11011101b ;8042 function code to de-gate A20
- 39 = 00DF enable_bit20 equ 11011111b ;8042 function code to gate A20
- 40 = 0021 inta01 equ 021h ;8259 Int Controller #1
- 41 = 00A1 intb01 equ 0A1h ;8259 Int Controller #2
- 42 = 0060 port_a equ 060h ;8042 port A
- 43 = 00FE shut_cmd equ 0FEh ;cmd to 8042: shut down AT
- 44 = 000F shut_down equ 00Fh ;CMOS shut down byte index
- 45 = 0064 status_port equ 064h ;8042 status port
- 46 = 0001 virtual_enable equ 0001h ;LSB=1: Protected Virtual Mode
- 47
- 48
- 49 ;; This is a "hard coded" far jump
- 50 jumpfar MACRO jumpfar1,jumpfar2
- 51 db 0EAh
- 52 dw (offset jumpfar1)
- 53 dw jumpfar2
- 54 ENDM
- Microsoft (R) Macro Assembler Version 5.10 3/20/91 22:38:53
- Method 1 Page 1-2
-
-
- 55
- 56
- 57 SUBTTL Program entry point and data area
- Microsoft (R) Macro Assembler Version 5.10 3/20/91 22:38:53
- Method 1 Page 1-3
- Program entry point and data area
-
- 58 PAGE
- 59 0000 cseg SEGMENT para public 'code'
- 60 ASSUME cs:cseg
- 61
- 62 0100 ORG 100h
- 63 0100 EB 32 start: jmp short main
- 64
- 65 EVEN
- 66 0102 gdt LABEL DWORD
- 67
- 68 = 0000 gdt_desc EQU (($-gdt)/8)*8 + 0000000000000000b
- 69 0102 3000 gdt1 descriptor <gdt_leng,,,data_seg_access,>
- 70 0104 0000
- 71 0106 00
- 72 0107 93
- 73 0108 0000
- 74
- 75 = 0008 cs_code EQU (($-gdt)/8)*8 + 0000000000000000b
- 76 010A 0261 R gdt2 descriptor <cseg_leng,,,code_seg_access,>
- 77 010C 0000
- 78 010E 00
- 79 010F 9B
- 80 0110 0000
- 81
- 82 = 0010 cs_data EQU (($-gdt)/8)*8 + 0000000000000000b
- 83 0112 0261 R gdt3 descriptor <cseg_leng,,,data_seg_access,>
- 84 0114 0000
- 85 0116 00
- 86 0117 93
- 87 0118 0000
- 88
- 89 = 0018 ss_desc EQU (($-gdt)/8)*8 + 0000000000000000b
- 90 011A FFFF gdt4 descriptor <0FFFFh,,,data_seg_access,>
- 91 011C 0000
- 92 011E 00
- 93 011F 93
- 94 0120 0000
- 95
- 96 = 0020 ds_desc equ (($-gdt)/8)*8 + 0000000000000000b
- 97 0122 FFFF gdt5 descriptor <0FFFFh,,,data_seg_access,>
- 98 0124 0000
- 99 0126 00
- 100 0127 93
- 101 0128 0000
- 102
- 103 = 0028 es_desc equ (($-gdt)/8)*8 + 0000000000000000b
- 104 012A FFFF gdt6 descriptor <0FFFFh,,,data_seg_access,>
- 105 012C 0000
- 106 012E 00
- 107 012F 93
- 108 0130 0000
- 109
- 110 = 0030 gdt_leng EQU $-gdt
- Microsoft (R) Macro Assembler Version 5.10 3/20/91 22:38:53
- Method 1 Page 1-4
- Program entry point and data area
-
- 111 PAGE
- 112 ;--------------------------------------------------------------:
- 113 ; Format of the Segment Selector Component: :
- 114 ; :
- 115 ; +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ :
- 116 ; | INDEX +TI+ RPL + :
- 117 ; +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ :
- 118 ; :
- 119 ; TI = Table Indicator (0=GDT, 1=LDT) :
- 120 ; RPL = Requested Privelege Level (00 = highest; 11 = Lowest) :
- 121 ;--------------------------------------------------------------:
- 122 ; Format of the Global Descriptor Table :
- 123 ; .-----------+ +---> TI :
- 124 ; V | |++-> RPL :
- 125 ; GDT ==> +---------------+ | ||| :
- 126 ; | GDT_DESC | --+ 0000000000000000b :
- 127 ; +---------------+ :
- 128 ; | CS_CODE | 0000000000001000b :
- 129 ; +---------------+ :
- 130 ; | CS_DATA | 0000000000010000b :
- 131 ; +---------------+ :
- 132 ; | SS_DESC | 0000000000011000b :
- 133 ; +---------------+ :
- 134 ; | DS_DESC | 0000000000100000b :
- 135 ; +---------------+ :
- 136 ; | ES_DESC | 0000000000101000b :
- 137 ; +---------------+ :
- 138 ;--------------------------------------------------------------:
- 139
- 140 0132 00 i8259_1 db ? ; store for status of 8259 #1
- 141 0133 00 i8259_2 db ? ; store for status of 8259 #2
- 142
- 143 SUBTTL Program Main
- Microsoft (R) Macro Assembler Version 5.10 3/20/91 22:38:53
- Method 1 Page 1-5
- Program Main
-
- 144 PAGE
- 145 ;--------------------------------------------------------------:
- 146 ; MAIN :
- 147 ;--------------------------------------------------------------:
- 148 ASSUME ds:cseg
- 149 0134 main PROC ;ES=DS=CS
- 150 0134 FC cld ;forward
- 151
- 152 0135 8C CA mov dx,cs ;form 24bit address out of
- 153 0137 B9 0102 R mov cx,offset gdt ; CS:GDT
- 154 013A E8 0237 R call form_24bit_address
- 155 013D 89 16 0104 R mov gdt1.base_lo_word,dx ;DESC now points to gdt
- 156 0141 88 0E 0106 R mov gdt1.base_hi_byte,cl
- 157
- 158 0145 8C CA mov dx,cs ;form 24bit address out of
- 159 0147 33 C9 xor cx,cx ; CS:0000
- 160 0149 E8 0237 R call form_24bit_address
- 161 014C 89 16 010C R mov gdt2.base_lo_word,dx ;CS_CODE now points to
- 162 0150 88 0E 010E R mov gdt2.base_hi_byte,cl ; CSEG as a code segment
- 163 0154 89 16 0114 R mov gdt3.base_lo_word,dx ;CS_DATA now points to
- 164 0158 88 0E 0116 R mov gdt3.base_hi_byte,cl ; CSEG as a data segment
- 165
- 166 015C 8C D2 mov dx,ss ;form 24bit address out of
- 167 015E 33 C9 xor cx,cx ; SS:0000
- 168 0160 E8 0237 R call form_24bit_address
- 169 0163 89 16 011C R mov gdt4.base_lo_word,dx ;SS_DESC now points to
- 170 0167 88 0E 011E R mov gdt4.base_hi_byte,cl ; stack segment
- 171
- 172 016B 2E: 0F 01 16 0102 R lgdt DWORD PTR Cs:gdt ;Load the GDTR
- prot4.ASM(142): warning A4057: Illegal size for operand
- 173
- 174 0171 B4 DF mov ah,enable_bit20 ;gate address bit 20 on
- 175 0173 E8 0215 R call gate_a20
- 176 0176 0A C0 or al,al ; was the command accepted?
- 177 0178 74 2E jz m_10 ; go if yes
- 178 017A BA 0183 R mov dx,offset gate_failure ;print error msg
- 179 017D B4 09 mov ah,9 ; and terminate
- 180 017F CD 21 int 21h
- 181 0181 CD 20 int 20h
- 182
- 183 0183 41 64 64 72 65 73 gate_failure db "Address line A20 failed to Gate open$"
- 184 73 20 6C 69 6E 65
- 185 20 41 32 30 20 66
- 186 61 69 6C 65 64 20
- 187 74 6F 20 47 61 74
- 188 65 20 6F 70 65 6E
- 189 24
- 190
- 191 01A8 FA m_10: cli ;No interrupts
- 192
- 193 01A9 E4 21 in al,inta01 ;get status of Int Controller #1
- 194 01AB A2 0132 R mov i8259_1,al
- 195 01AE E4 A1 in al,intb01 ;get status of Int Controller #2
- 196 01B0 A2 0133 R mov i8259_2,al
- 197
- Microsoft (R) Macro Assembler Version 5.10 3/20/91 22:38:53
- Method 1 Page 1-6
- Program Main
-
- 198 ASSUME ds:bios_data_seg
- 199 01B3 BA ---- R mov dx,bios_data_seg ;Real Mode Return address
- 200 01B6 8E DA mov ds,dx
- 201 01B8 8C 0E 0069 R mov io_rom_seg,cs
- 202 01BC C7 06 0067 R 024B R mov io_rom_init,offset real
- 203
- 204 01C2 B0 0F mov al,shut_down ;Set shutdown byte
- 205 01C4 E6 70 out cmos_port,al ; to shut down x05.
- 206 01C6 EB 00 jmp short $+2 ;I/O delay
- 207 01C8 B0 05 mov al,5
- 208 01CA E6 71 out cmos_port+1,al
- 209
- 210 01CC B8 0001 mov ax,virtual_enable ;machine status word needed to
- 211 01CF 0F 01 F0 lmsw ax ;switch to virtual mode
- 212 jumpfar m_20,cs_code ;Must purge prefetch queue
- 213 01D2 EA 1 db 0EAh
- 214 01D3 01D7 R 1 dw (offset m_20)
- 215 01D5 0008 1 dw cs_code
- 216
- 217 01D7 m_20: ASSUME ds:cseg ;IN VIRTUAL MODE ...
- 218 01D7 B8 0018 mov ax,ss_desc ;stack segment selector
- 219 01DA 8E D0 mov ss,ax ;user's ss+sp is not a descriptor
- 220
- 221 01DC B8 0010 mov ax,cs_data
- 222 01DF 8E D8 mov ds,ax ;DS = CSEG as data
- 223
- 224 01E1 C7 06 0124 R 8000 mov gdt5.base_lo_word,8000h ;use 8000 for COLOR
- 225 01E7 C6 06 0126 R 0B mov gdt5.base_hi_byte,0Bh
- 226 01EC C7 06 012C R 8000 mov gdt6.base_lo_word,8000h
- 227 01F2 C6 06 012E R 0B mov gdt6.base_hi_byte,0Bh
- 228
- 229 01F7 B8 0020 mov ax,ds_desc
- 230 01FA 8E D8 mov ds,ax
- 231 01FC B8 0028 mov ax,es_desc
- 232 01FF 8E C0 mov es,ax
- 233 0201 B9 07D0 mov cx,80*25
- 234 0204 33 F6 xor si,si
- 235 0206 33 FF xor di,di
- 236 0208 AD m_30: lodsw
- 237 0209 B4 65 mov ah,65h ;attribute reverse video
- 238 020B AB stosw
- 239 020C E2 FA loop m_30
- 240
- 241 020E B0 FE mov al,shut_cmd ;shutdown cmd
- 242 0210 E6 64 out status_port,al ;get back into REAL mode
- 243 0212 F4 m_40: hlt
- 244 0213 EB FD jmp short m_40
- 245
- 246 SUBTTL Gate A20
- Microsoft (R) Macro Assembler Version 5.10 3/20/91 22:38:53
- Method 1 Page 1-7
- Gate A20
-
- 247 PAGE
- 248 ;--------------------------------------------------------------:
- 249 ; GATE_A20 :
- 250 ; This routine controls a signal which gates address bit 20. :
- 251 ; The gate A20 signal is an output of the 8042 slave processor.:
- 252 ; Address bit 20 should be gated on before entering protected :
- 253 ; mode. It should be gated off after entering real mode from :
- 254 ; protected mode. :
- 255 ; Input: (AH)=0DDh addr bit 20 gated off (A20 always 0) :
- 256 ; (AH)=0DFh addr bit 20 gated on (286 controls A20) :
- 257 ; Output: (AL)=0 operation successful. 8042 has accepted cmd :
- 258 ; (AL)=2 Failure -- 8042 unable to accept command. :
- 259 ;--------------------------------------------------------------:
- 260 0215 gate_a20 PROC
- 261 0215 FA cli ;disable ints while using 8042
- 262 0216 E8 022C R call empty_8042 ;insure 8042 input buffer empty
- 263 0219 75 10 jnz gate_a20_01 ;ret if 8042 unable to accept cmd
- 264 021B B0 D1 mov al,0D1h ;8042 command to write output port
- 265 021D E6 64 out status_port,al ;output cmd to 8042
- 266 021F E8 022C R call empty_8042 ;wait for 8042 to accept command
- 267 0222 75 07 jnz gate_a20_01 ;ret if 8042 unable to accept cmd
- 268 0224 8A C4 mov al,ah ;8042 port data
- 269 0226 E6 60 out port_a,al ;output port data to 8042
- 270 0228 E8 022C R call empty_8042 ;wait for 8042 to port data
- 271 022B gate_a20_01:
- 272 022B C3 ret
- 273 022C gate_a20 ENDP
- 274 ;--------------------------------------------------------------:
- 275 ; EMPTY_8042 :
- 276 ; This routine waits for the 8042 buffer to empty :
- 277 ; Input: None :
- 278 ; Output: (AL)=0 8042 input buffer empty (ZF=1) :
- 279 ; (AL)=2 Time out, 8042 buffer full (ZF=0) :
- 280 ;--------------------------------------------------------------:
- 281 022C empty_8042 PROC
- 282 022C 51 push cx ;save CX
- 283 022D 2B C9 sub cx,cx ;CX=0 will be the time out value
- 284 022F empty_8042_01:
- 285 022F E4 64 in al,status_port ;read 8042 status port
- 286 0231 24 02 and al,00000010b ;test input buffer full flag (D1)
- 287 0233 E0 FA loopnz empty_8042_01 ;loop until input buffer empty
- 288 ; or time out
- 289 0235 59 pop cx ;restore CX
- 290 0236 C3 ret
- 291 0237 empty_8042 ENDP
- 292
- 293 SUBTTL form_24bit_address
- Microsoft (R) Macro Assembler Version 5.10 3/20/91 22:38:53
- Method 1 Page 1-8
- form_24bit_address
-
- 294 PAGE
- 295 ;--------------------------------------------------------------:
- 296 ; FORM_24BIT_ADDRESS :
- 297 ; Input: DX has some segment :
- 298 ; CX has some offset :
- 299 ; Output: DX has base_lo_word :
- 300 ; CL has base_hi_byte :
- 301 ;--------------------------------------------------------------:
- 302 0237 form_24bit_address PROC
- 303 0237 50 push ax
- 304 ;DX == s15 s14 s13 s12 s11 ... s04 s03 s02 s01 s00
- 305 0238 C1 C2 04 rol dx,4
- 306 ;DX == s11 ... s04 s03 s02 s01 s00 s15 s14 s13 s12
- 307 023B 8B C2 mov ax,dx
- 308 ;AX == s11 ... s04 s03 s02 s01 s00 s15 s14 s13 s12
- 309 023D 80 E2 F0 and dl,0F0h
- 310 ;DX == s11 ... s04 s03 s02 s01 s00 0 0 0 0
- 311 0240 25 000F and ax,0Fh
- 312 ;AX == 0 ... 0 0 0 0 0 s15 s14 s13 s12
- 313 0243 03 D1 add dx,cx ;form_24bit_address
- 314 0245 8B C8 mov cx,ax ;get base_hi_byte in CL
- 315 0247 12 CD adc cl,ch ;carry in (CH=0)
- 316 0249 58 pop ax
- 317 024A C3 ret
- 318 024B form_24bit_address ENDP
- 319
- 320 SUBTTL Real Mode re-entry point.
- Microsoft (R) Macro Assembler Version 5.10 3/20/91 22:38:53
- Method 1 Page 1-9
- Real Mode re-entry point.
-
- 321 PAGE
- 322 ASSUME ds:cseg ;IN REAL MODE ...
- 323
- 324 024B 8C CA real: mov dx,cs
- 325 024D 8E DA mov ds,dx ;DS = CS
- 326 024F B4 DD mov ah,disable_bit20 ;gate address bit 20 on
- 327 0251 E8 0215 R call gate_a20
- 328 0254 A0 0132 R mov al,i8259_1
- 329 0257 E6 21 out inta01,al ;set status of Int Controller #1
- 330 0259 A0 0133 R mov al,i8259_2
- 331 025C E6 A1 out intb01,al ;set status of Int Controller #2
- 332
- 333 025E FB sti ;turn the interrupts on
- 334 025F CD 20 int 20h ;back to DOS
- 335
- 336 0261 main ENDP
- 337 = 0261 cseg_leng EQU $
- 338 0261 cseg ENDS
- 339 END start
-
- Microsoft (R) Macro Assembler Version 5.10 3/20/91 22:38:53
- Method 1 Symbols-1
-
-
- Macros:
-
- N a m e Lines
-
- jumpfar . . . . . . . . . . . . 3
-
- Structures and Records:
-
- N a m e Width # fields
- Shift Width Mask Initial
-
- descriptor . . . . . . . . . . . 0008 0005
- seg_limit . . . . . . . . . . 0000
- base_lo_word . . . . . . . . . 0002
- base_hi_byte . . . . . . . . . 0004
- access_rights . . . . . . . . 0005
-
- Segments and Groups:
-
- N a m e Length Align Combine Class
-
- bios_data_seg . . . . . . . . . 006B AT 0040
- cseg . . . . . . . . . . . . . . 0261 PARA PUBLIC 'code'
-
- Symbols:
-
- N a m e Type Value Attr
-
- cmos_port . . . . . . . . . . . NUMBER 0070
- code_seg_access . . . . . . . . NUMBER 009B
- cs_code . . . . . . . . . . . . NUMBER 0008
- cs_data . . . . . . . . . . . . NUMBER 0010
- cseg_leng . . . . . . . . . . . NEAR 0261 cseg
-
- data_seg_access . . . . . . . . NUMBER 0093
- disable_bit20 . . . . . . . . . NUMBER 00DD
- ds_desc . . . . . . . . . . . . NUMBER 0020
-
- empty_8042 . . . . . . . . . . . N PROC 022C cseg Length = 000B
- empty_8042_01 . . . . . . . . . L NEAR 022F cseg
- enable_bit20 . . . . . . . . . . NUMBER 00DF
- es_desc . . . . . . . . . . . . NUMBER 0028
-
- form_24bit_address . . . . . . . N PROC 0237 cseg Length = 0014
-
- gate_a20 . . . . . . . . . . . . N PROC 0215 cseg Length = 0017
- gate_a20_01 . . . . . . . . . . L NEAR 022B cseg
- gate_failure . . . . . . . . . . L BYTE 0183 cseg
- gdt . . . . . . . . . . . . . . L DWORD 0102 cseg
- gdt1 . . . . . . . . . . . . . . L QWORD 0102 cseg
- gdt2 . . . . . . . . . . . . . . L QWORD 010A cseg
- gdt3 . . . . . . . . . . . . . . L QWORD 0112 cseg
- gdt4 . . . . . . . . . . . . . . L QWORD 011A cseg
- gdt5 . . . . . . . . . . . . . . L QWORD 0122 cseg
- Microsoft (R) Macro Assembler Version 5.10 3/20/91 22:38:53
- Method 1 Symbols-2
-
-
- gdt6 . . . . . . . . . . . . . . L QWORD 012A cseg
- gdt_desc . . . . . . . . . . . . NUMBER 0000
- gdt_leng . . . . . . . . . . . . NUMBER 0030
-
- i8259_1 . . . . . . . . . . . . L BYTE 0132 cseg
- i8259_2 . . . . . . . . . . . . L BYTE 0133 cseg
- inta01 . . . . . . . . . . . . . NUMBER 0021
- intb01 . . . . . . . . . . . . . NUMBER 00A1
- io_rom_init . . . . . . . . . . L WORD 0067 bios_data_seg
- io_rom_seg . . . . . . . . . . . L WORD 0069 bios_data_seg
-
- m_10 . . . . . . . . . . . . . . L NEAR 01A8 cseg
- m_20 . . . . . . . . . . . . . . L NEAR 01D7 cseg
- m_30 . . . . . . . . . . . . . . L NEAR 0208 cseg
- m_40 . . . . . . . . . . . . . . L NEAR 0212 cseg
- main . . . . . . . . . . . . . . N PROC 0134 cseg Length = 012D
-
- port_a . . . . . . . . . . . . . NUMBER 0060
-
- real . . . . . . . . . . . . . . L NEAR 024B cseg
-
- shut_cmd . . . . . . . . . . . . NUMBER 00FE
- shut_down . . . . . . . . . . . NUMBER 000F
- ss_desc . . . . . . . . . . . . NUMBER 0018
- start . . . . . . . . . . . . . L NEAR 0100 cseg
- status_port . . . . . . . . . . NUMBER 0064
-
- virtual_enable . . . . . . . . . NUMBER 0001
-
- @Cpu . . . . . . . . . . . . . . TEXT 1415
- @FileName . . . . . . . . . . . TEXT prot4
- @Version . . . . . . . . . . . . TEXT 510
-
-
- 300 Source Lines
- 303 Total Lines
- 62 Symbols
-
- 46452 Bytes symbol space free
-
- 1 Warning Errors
- 0 Severe Errors
-