Protected mode - RAM tester
From: aciuh (mw_at_obronet.wytnij.org)
Date: 05/24/04
- Next message: Axel Schlicht: "Re: i86, AT&T syntax, GNU as"
- Previous message: josh: "Re: Performance benefits of rep/loop?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 24 May 2004 17:59:53 +0000 (UTC)
Hello
I have problem with enabling protected mode....
Program resets my PC when "mov cr0,eax" is executing....
Do you have any ideas, where is the problem ?...
sorry for no comments ...
here is the code :>
;===========================================================================
===============
.MODEL SMALL
.386P
assume cs:cseg, ds:dseg, ss:sseg
;---------------------------------------------------------------------------
-
; SEGMENT KODU
;---------------------------------------------------------------------------
-
cseg segment
start:
mov AX,dseg
mov DS,AX
;ustawiam tablice deskryptorow gdzie SI - adres deskryptora, AX - adres
segmentowy selektora, BX - rozmiar segmentu, CX - znaczniki segmentu
mov si,offset GblDT ; setting global description table
add si,8
mov bx,0FFFFh
mov cx,RDWRDATA
call SetDscrpt
mov ax,SEG _TEXT
add si,8
mov bx,0FFFFh
mov cx,EXECUT
call SetDscrpt
mov ax,SEG SSEG
add si,8
mov bx,0FFFFh
mov cx,EXECUT
call SetDscrpt
;mov AX,0003H ; czyszcze ekran i ustawiam tryb textowy nr 3H
;int 10H
call ile_ramu ; amount of RAM
call GoProtect ; HERE IS THE PROBLEM
;call sprawdz_RAM ;checking RAM
call GoReal
; exit to DOS
mov ax, 4C00h
int 21h
;---------------------------------------------------------------------------
-
; Sprawdzanie RAMu
;---------------------------------------------------------------------------
-
sprawdz_RAM PROC
mov CX,WORD PTR ilosc_ramu
shl ECX,20
xor EBX,EBX
mov EDX,EDX
mov EBX,00040000H
petla:
mov DWORD PTR [EBX],00000000H
mov EAX,DWORD PTR [EBX]
jnz blad
mov DWORD PTR [EBX],0FFFFFFFFH
mov EAX,DWORD PTR [EBX]
inc EAX
jnz blad
mov DWORD PTR [EBX],0AAAAAAAAH
mov EAX,DWORD PTR [EBX]
shr EAX,1
cmp EAX,55555555H
jnz blad
loop petla
ret
blad:
inc EDX
loop petla
mov AX,dseg
mov ES,AX
mov AX,0100H
mov SI,AX
mov EAX,EDX
call Word2Str
mov AX,00FAH
mov SI,AX
mov EAX,EDX
shr EAX,16
call Word2Str
sprawdz_RAM endp
;---------------------------------------------------------------------------
-
; Czyszczenie ekranu
;---------------------------------------------------------------------------
-
czysc_ekran PROC
mov AX,0600H
mov BH,00H
mov CX,0000H
mov DX,184FH
int 10H
ret
czysc_ekran endp
;---------------------------------------------------------------------------
-
; Sprawdzenie ile ramu siedzi w komputerze
;---------------------------------------------------------------------------
-
ile_ramu PROC
mov AX,0E801H
int 15H
shr BX,1
shr BX,1
shr BX,1
shr BX,1
shr AH,1
shr AH,1
add BL,AH
nop
mov AX,dseg
mov ES,AX
mov AX,BX
mov WORD PTR ilosc_ramu,AX
call Word2Str
ret
ile_ramu endp
;---------------------------------------------------------------------------
-
; ZAMIANA ZAWAROSCI AX na TEXT
;---------------------------------------------------------------------------
-
Byte2str proc
mov DI,AX;
and DI,000FH;
mov BX,offset Digits;
mov AH,ES:[BX+DI];
mov [SI+2],AH;
xor AH,AH;
mov DI,AX;
shr DI,1;
shr DI,1;
shr DI,1;
shr DI,1;
mov AH,ES:[BX+DI];
mov [SI],AH;
ret
Byte2str endp
Word2Str proc
mov CX,AX;
xchg AH,AL;
call Byte2Str;
add SI,8;
mov AX,CX;
call Byte2Str;
ret
Word2Str endp
;---------------------------------------------------------------------------
-
; Ustawianie deskryptorow
;---------------------------------------------------------------------------
-
SetDscrpt PROC
mov dl,ah;
shl ax,4;
shr dl,4;
mov WORD PTR [si],bx;
mov WORD PTR [si+2],ax;
mov BYTE PTR [si+4],dl;
mov WORD PTR [si+5],cx;
mov BYTE PTR [si+7],0;
ret
SetDscrpt ENDP
;---------------------------------------------------------------------------
-
; Przechodzenie do trybu PROTECTED
;---------------------------------------------------------------------------
-
GoProtect PROC
;call enable_a20;
; tu procedurka wklejona z netu i pewnie sie wysypie tez
setup_a20:
call empty_8042
mov al,0D1H
out 064H,al
call empty_8042
mov al,0DFH
out 060H,al
call empty_8042
empty_8042:
dw 0EBH,0EBH
in al,064H
test al,2
jnz empty_8042
mov ax,SEG _DATA;
mov dl,ah
shl ax,4
shr dl,4
sub dh,dh
add ax,OFFSET GblDT
adc dl,0
mov GblDscTbl+2,ax
mov GblDscTbl+4,dx
lgdt FWORD PTR GblDscTbl
cli
;smsw ax
;and ax,1Fh
;or ax,1
;lmsw ax
mov eax,cr0 ; pobranie CR0 do EAX
or al,1 ; ustawienie bitu trybu chronionego
mov cr0,eax ; po tej operacji jestesmy w trybie chronionym!
DB 0EAh
DW ClearPF
DW 10h
ClearPF:
mov ax,8
mov ds,ax
mov ax,18h
mov ss,ax
ret
GoProtect ENDP
;---------------------------------------------------------------------------
-
; Przechodzenie do tryby REAL
;---------------------------------------------------------------------------
-
GoReal PROC
mov eax,CR0
and eax,07FFFFFFEh
mov CR0,eax
DB 0EAh
DW ClearPF2
DW _TEXT
ClearPF2:
mov ax,SEG DGROUP
mov ds,ax
mov ax,SEG SSEG
mov ss,ax
sti
call disable_a20
ret
Goreal ENDP
;---------------------------------------------------------------------------
-
; Uaktywnienie linii adresowej A20
;---------------------------------------------------------------------------
-
enable_a20 PROC NEAR
mov al,A20_PORT
out STATUS_PORT,al
mov al,A20_ON
out KBD_PORT_A,al ; tu sie wywala
ret
enable_a20 ENDP
;---------------------------------------------------------------------------
-
; Deaktywacja linii adresowej A20
;---------------------------------------------------------------------------
-
disable_a20 PROC NEAR
mov al,A20_PORT
out STATUS_PORT,al
mov al,A20_OFF
out KBD_PORT_A,al
ret
disable_a20 ENDP
cseg ends
;---------------------------------------------------------------------------
-
; SEGMENT DANYCH
;---------------------------------------------------------------------------
-
dseg segment byte
EXECUT EQU 10011101b
RDWRDATA EQU 10010010b
STACKSEG EQU 10010110b
STATUS_PORT EQU 64
A20_PORT EQU 0d1h
A20_ON EQU 0dfh
A20_OFF EQU 0ddh
KBD_PORT_A EQU 60
;Tworzymy globalna tablice deskryptorow
GblDT DW 0,0,0,0;
DW 0,0,0,0;
DW 0,0,0,0;
DW 0,0,0,0;
GblDscTbl DW 4*8-1;
DD 0;
dziwny_tryb db 'Niestety nie obsluguje twojego trybu graficznego - NARA
:)',13,10,'$'
no386e db 'Sorry, przynajmniej 386 jest wymagane!',13,10,'$'
mam386e db 'hurrrraaaa mam minimum 386 :)',13,10,'$'
ilosc_ramu dw (0)
ekran Dw (0)
Digits db "0123456789abcdef";
dseg ends
;---------------------------------------------------------------------------
-
; SEGMENT STOSU
;---------------------------------------------------------------------------
-
sseg segment stack
db 4096h dup(?)
sseg ends
;---------------------------------------------------------------------------
-
; KONIEC KODU
;---------------------------------------------------------------------------
-
end start
- Next message: Axel Schlicht: "Re: i86, AT&T syntax, GNU as"
- Previous message: josh: "Re: Performance benefits of rep/loop?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|