Page 1 of 1

Jump to protected mode

Posted: Sun Jan 09, 2011 3:40 am
by vision
Hi!
I have a problem. Namely, he wants to jump to protected mode, but here I have a problem. Compiling goes well, but in a virtual machine is not working.
Everything goes well until the A20 line. Then there is nothing
PS. Speak English poorly.
This is the kernel code:

Code: Select all

BITS 16
ORG 0x8000

%include "header.inc"

dw START
		
%include "realmode/data.asm"
%include "realmode/video.asm"
%include "realmode/procedures.asm"
%include "realmode/a20.asm"
 	
START:

cli
clr ax
mov ax, cs         
mov ds, ax          ; musimy zainicjować pozostałe rejestry
mov es, ax
sti

; Poczłątkowy napis włączenia się kernela
mov si, loadermsg 
call print

; Włączenie A20!
mov si, a20msg 
call print

call EnableA20

cli
	lgdt [gdtr]
	mov	eax, cr0
	or	eax, 1
	mov	cr0, eax

	jmp	0x08:pmode

%include "realmode/gdt.inc"			; dolaczamy plik z tablica gdt

[BITS 32]				; zaczynamy 32 bitowy kod
pmode:
	mov	ax, 0x10
	mov	ds, ax
	mov	es, ax
	mov	ss, ax
	xor	ax, ax
	mov	fs, ax
	mov	gs, ax
	mov	esp, 0x200000

	call	clrscr32

	mov	esi, welcome		; teraz musimy dawac wiadomosci do ESI
	call	print32

;	call	main			; wywolujemy funkcje main z kernela napisanego w C

	jmp	$			; petla nieskonczona

clrscr32:				; funkcja czyszczaca ekran
	mov	edi, [printptr]		; do EDI 0xB8000
	mov	ecx, 40*25		; do ECX liczba znakow na ekranie
	mov	eax, 0x02200220		; do EAX 0x02 - kolor znaku, 0x20 - spacja ;)
	rep	stosd			; powtarzamy dopoki ECX != 0
	ret

print32:				; funkcja wypisujaca komunikaty w trybie 32 bitowym
	mov	edi, [printptr]		; do EDI 0xB8000
  .pisz:
	lodsb
	or	al, al
	jz	.napisalem
	stosw				; tym razem powtarzamy po 2 bajty dopoki nie napotkamy 

konca ciagu, czyli 0
	jmp	.pisz
  .napisalem:
	mov	[printptr], edi		; do printptr aktualna pozycja na ekranie
	ret

printptr	dd	0xB8000
welcome		db	"Witam w trybie chronionym ;)", 0

VISION_END:
and gtd.inc :

Code: Select all

gdtr:
	dw	gdt - gdtend - 1
	dd	gdt
gdt:
	dd	0x00000000, 0x00000000
	dd	0x0000FFFF, 0x00CF9A00
	dd	0x0000FFFF, 0x00CF9200
	dd	0x0000FFFF, 0x00CFFA00
	dd	0x0000FFFF, 0x00CFF200
gdtend:

Re: Jump to protected mode

Posted: Sun Jan 09, 2011 4:49 am
by Combuster
dw START
That is not a jump... Worse, depending on your design you might even be starting to execute your header.

Re: Jump to protected mode

Posted: Sun Jan 09, 2011 5:03 am
by vision
I do not know why, but how do I use the jmp is not working

http://zapodaj.net/images/1b2d9c86fd43.png
http://zapodaj.net/images/c8caaed9cf67.png

Re: Jump to protected mode

Posted: Mon Jan 10, 2011 3:48 am
by jcmatias
Your must specify a 48-bit far address, since the target segment is a 32-bit one.

jmp dword 0x08:pmode ;