Jump to protected mode

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
vision
Posts: 12
Joined: Wed Oct 27, 2010 1:32 pm
Location: Warsaw, Poland

Jump to protected mode

Post 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:
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Jump to protected mode

Post by Combuster »

dw START
That is not a jump... Worse, depending on your design you might even be starting to execute your header.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
vision
Posts: 12
Joined: Wed Oct 27, 2010 1:32 pm
Location: Warsaw, Poland

Re: Jump to protected mode

Post 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
jcmatias
Posts: 11
Joined: Mon Nov 08, 2004 12:00 am
Location: Ribeirao Preto SP Brasil

Re: Jump to protected mode

Post by jcmatias »

Your must specify a 48-bit far address, since the target segment is a 32-bit one.

jmp dword 0x08:pmode ;
Post Reply