Page 1 of 1

Issue getting into protected mode.

Posted: Fri Feb 21, 2014 12:39 pm
by BASICFreak
First here is my code:

Code: Select all

;MAX SIZE 2048 BYTES 2KB

[bits 16]
[org 0x500]

jmp stagetwo

stagetwo:
	cli							; clear interrupts
	xor		ax, ax				; null segments
	mov		ds, ax
	mov		es, ax
	mov		ax, 0x9000			; stack begins at 0x9000-0xffff
	mov		ss, ax
	mov		sp, 0xFFFF
	sti							; enable interrupts
	mov		[bootdevice], dl
	call	mode13
	call	palette16
	call	InstallGDT
	call	EnableA20_Bios
	call	mode3
	cli
	mov		eax, cr0
	or		eax, 1
	mov		cr0, eax
	jmp		0x08:StageThree		;jump into protected mode funtion StageThree
	jmp		iError16
	
InstallGDT:
	cli
	pusha
	lgdt	[toc]
	sti
	popa
	ret
	
;*******************************************
; Global Descriptor Table (GDT)
;*******************************************
 
gdt_data: 
	dd 		0 				; null descriptor
	dd 		0 
 
; gdt code:				; code descriptor
	dw 		0FFFFh 			; limit low
	dw 		0 				; base low
	db 		0 				; base middle
	db 		10011010b 			; access
	db 		11001111b 			; granularity
	db 		0 				; base high
 
; gdt data:				; data descriptor
	dw		0FFFFh 			; limit low (Same as code)
	dw		0 				; base low
	db		0 				; base middle
	db 		10010010b 			; access
	db 		11001111b 			; granularity
	db 		0				; base high
 
end_of_gdt:

toc: 
	dw		end_of_gdt - gdt_data - 1 	; limit (Size of GDT)
	dd		gdt_data 			; base of GDT

mode3:
	mov		ah, 0x00
	mov 	al, 0x03
	int 	0x10
	ret

mode13:
	mov		ah, 0x00
	mov		al, 0x13
	int		0x10
	ret
	
pset16:
	mov		ah, 0x0C
	mov		bh, 0x00
	int		0x10
	ret
	
print16:
	lodsb
	or		al, al
	jz		printdone16
	mov		ah, 0x0E
	mov		bh, 0x00
	int		0x10
	jmp		print16
	printdone16:
		ret
	
	
palette16:
	mov 	ah, 0x0C
	mov 	bh, 0x00
	mov 	dx, 0
	.a:
		mov 	al, 0
		mov 	cx, 0
		.b:
			inc		al
			inc		cx
			call	pset16
			cmp		al, 255
			jne 	.b
			inc 	dx
			cmp 	dx, 200
			jne 	.a
	ret

EnableA20_Bios:
	pusha
	mov		ax, 0x2401
	int		0x15
	popa
	ret

EnableA20_KKbrd:
	cli
	push	ax
	mov		al, 0xdd	; send enable a20 address line command to controller
	out		0x64, al
	pop		ax
	ret

EnableA20_KKbrd_Out:
	cli
	pusha
        call    wait_input
        mov     al,0xAD
        out     0x64,al		; disable keyboard
        call    wait_input
        mov     al,0xD0
        out     0x64,al		; tell controller to read output port
        call    wait_output
        in      al,0x60
        push    eax		; get output port data and store it
        call    wait_input
        mov     al,0xD1
        out     0x64,al		; tell controller to write output port
        call    wait_input
        pop     eax
        or      al,2		; set bit 1 (enable a20)
        out     0x60,al		; write out data back to the output port
        call    wait_input
        mov     al,0xAE		; enable keyboard
        out     0x64,al
        call    wait_input
	popa
        sti
        ret

wait_input:
    in      al,0x64
    test    al,2
    jnz     wait_input
    ret

wait_output:
    in      al,0x64
    test    al,1
    jz      wait_output
    ret

iError16:
	call	mode3
	mov		si, ErrMsg16
	call	print16
HALT16:
	cli
	hlt
	.l jmp .l
	
;REAL-MODE VARIABLES:
bootdevice		db		0
ErrMsg16		db		"There was an error getting to Stage Three!", 0x00
	
[bits 32]
;Protected-Mode Variables:
%define			VIDMEM	0xB8000	;mode 0x03
%define			COLS	80
%define			ROWS	25
_CurX			db		0
_CurY			db		0
msg				db		"Hello Protected Mode!", 0x00

StageThree:
	mov		ax, 0x10
	mov		ds, ax
	mov		ss, ax
	mov		es, ax
	mov		esp, 0x90000
	call	cls
	mov		ebx, msg
	mov		al, 0x1F
	call	print
	jmp		STOP

;BL = CHAR
;BH = COLOR
putch:
	pusha
	mov		edi, VIDMEM
	xor		eax, eax
	mov		ecx, COLS*2
	mov		al, byte [_CurY]
	mul		ecx
	push	eax
	mov		al, byte [_CurX]
	mov		cl, 2
	mul		cl
	pop		ecx
	add		eax, ecx
	xor		ecx, ecx
	add		edi, eax
	cmp		bl, 0x0A		;Look for new line
	je		.Row
	mov		dl, bl			;CHAR
	mov		dh, bh			;COLOR
	mov		word [edi], dx	;To VIDMEM
	inc		byte [_CurX]
	cmp		byte [_CurX], COLS
	je		.Row
	jmp		.done
	.Row:
		mov		byte [_CurX], 0
		inc		byte [_CurY]
	.done:
		popa
		ret

;ebx = address of string to print
;al = color		
print:
	pusha
	push	ebx
	pop		edi
	.loop:
		mov		bh, al
		mov		bl, byte [edi]
		cmp		bl, 0
		je		.done
		call	putch
		inc		edi
		jmp		.loop
	.done:
		mov		bh, byte [_CurY]
		mov		bl, byte [_CurX]
		call	MovCur
		popa
		ret
		
;bh = y
;bl = x
MovCur:
	pusha
	xor		eax, eax
	mov		ecx, COLS
	mov		al, bh
	mul		ecx
	add		al, bl
	mov		ebx, eax
	mov		al, 0x0F
	mov		dx, 0x03D4
	out		dx, al
	mov		al, bl
	mov		dx, 0x03D5
	out		dx, al
	xor		eax, eax
	mov		al, 0x0E
	mov		dx, 0x03D4
	out		dx, al
	mov		al, bh
	mov		dx, 0x03D5
	out		dx, al
	popa
	ret
		
;ah = color
cls:
	pusha
	cld
	mov		edi, VIDMEM
	mov		cx, 2000
	mov		al, ' '
	rep		stosw
	mov		byte [_CurX], 0
	mov		byte [_CurY], 0
	popa
	ret
	
STOP:
	cli
	hlt
	.hl jmp .hl

	
times 2048 - ($-$$) db 0
Second here is BOCHS output:

Code: Select all

00000000000i[     ] Bochs x86 Emulator 2.6.2
00000000000i[     ]   Built from SVN snapshot on May 26, 2013
00000000000i[     ] Compiled on May 26 2013 at 10:10:55
00000000000i[     ] System configuration
00000000000i[     ]   processors: 1 (cores=1, HT threads=1)
00000000000i[     ]   A20 line support: yes
00000000000i[     ] IPS is set to 4000000
00000000000i[     ] CPU configuration
00000000000i[     ]   SMP support: no
00000000000i[     ]   level: 6
00000000000i[     ]   APIC support: xapic
00000000000i[     ]   FPU support: yes
00000000000i[     ]   MMX support: yes
00000000000i[     ]   3dnow! support: no
00000000000i[     ]   SEP support: yes
00000000000i[     ]   SSE support: sse2
00000000000i[     ]   XSAVE support: no 
00000000000i[     ]   AES support: no
00000000000i[     ]   MOVBE support: no
00000000000i[     ]   ADX support: no
00000000000i[     ]   x86-64 support: yes
00000000000i[     ]   1G paging support: no
00000000000i[     ]   MWAIT support: yes
00000000000i[     ]   VMX support: 1
00000000000i[     ] Optimization configuration
00000000000i[     ]   RepeatSpeedups support: yes
00000000000i[     ]   Fast function calls: yes
00000000000i[     ]   Handlers Chaining speedups: yes
00000000000i[     ] Devices configuration
00000000000i[     ]   NE2000 support: yes
00000000000i[     ]   PCI support: yes, enabled=yes
00000000000i[     ]   SB16 support: yes
00000000000i[     ]   USB support: yes
00000000000i[     ]   VGA extension support: vbe cirrus voodoo
00000000000i[MEM0 ] allocated memory at 02A90020. after alignment, vector=02A91000
00000000000i[MEM0 ] 16.00MB
00000000000i[MEM0 ] mem block size = 0x00100000, blocks=16
00000000000i[MEM0 ] rom at 0xfffe0000/131072 ('C:\Bochs/BIOS-bochs-latest')
00000000000i[     ] init_dev of 'pci' plugin device by virtual method
00000000000i[DEV  ] i440FX PMC present at device 0, function 0
00000000000i[     ] init_dev of 'pci2isa' plugin device by virtual method
00000000000i[DEV  ] PIIX3 PCI-to-ISA bridge present at device 1, function 0
00000000000i[     ] init_dev of 'cmos' plugin device by virtual method
00000000000i[CMOS ] Using local time for initial clock
00000000000i[CMOS ] Setting initial clock to: Fri Feb 21 12:23:15 2014 (time0=1393006995)
00000000000i[     ] init_dev of 'dma' plugin device by virtual method
00000000000i[DMA  ] channel 4 used by cascade
00000000000i[     ] init_dev of 'pic' plugin device by virtual method
00000000000i[     ] init_dev of 'pit' plugin device by virtual method
00000000000i[     ] init_dev of 'floppy' plugin device by virtual method
00000000000i[DMA  ] channel 2 used by Floppy Drive
00000000000i[FDD  ] fd0: 'floppy' ro=0, h=2,t=80,spt=18
00000000000i[     ] init_dev of 'vga' plugin device by virtual method
00000000000i[MEM0 ] Register memory access handlers: 0x0000000a0000 - 0x0000000bffff
00000000000i[VGA  ] interval=200000
00000000000i[MEM0 ] Register memory access handlers: 0x0000e0000000 - 0x0000e0ffffff
00000000000i[BXVGA] VBE Bochs Display Extension Enabled
00000000000i[WGUI ] Desktop Window dimensions: 1440 x 900
00000000000i[WGUI ] Number of Mouse Buttons = 16
00000000000i[WGUI ] IME disabled
00000000000i[MEM0 ] rom at 0xc0000/41472 ('C:\Bochs/VGABIOS-lgpl-latest')
00000000000i[     ] init_dev of 'acpi' plugin device by virtual method
00000000000i[DEV  ] ACPI Controller present at device 1, function 3
00000000000i[     ] init_dev of 'ioapic' plugin device by virtual method
00000000000i[IOAP ] initializing I/O APIC
00000000000i[MEM0 ] Register memory access handlers: 0x0000fec00000 - 0x0000fec00fff
00000000000i[IOAP ] IOAPIC enabled (base address = 0xfec00000)
00000000000i[     ] init_dev of 'keyboard' plugin device by virtual method
00000000000i[KBD  ] will paste characters every 400 keyboard ticks
00000000000i[     ] init_dev of 'harddrv' plugin device by virtual method
00000000000i[HD   ] Using boot sequence floppy, none, none
00000000000i[HD   ] Floppy boot signature check is enabled
00000000000i[     ] init_dev of 'pci_ide' plugin device by virtual method
00000000000i[DEV  ] PIIX3 PCI IDE controller present at device 1, function 1
00000000000i[     ] init_dev of 'unmapped' plugin device by virtual method
00000000000i[     ] init_dev of 'biosdev' plugin device by virtual method
00000000000i[     ] init_dev of 'speaker' plugin device by virtual method
00000000000i[     ] init_dev of 'extfpuirq' plugin device by virtual method
00000000000i[     ] init_dev of 'parallel' plugin device by virtual method
00000000000i[PAR  ] parallel port 1 at 0x0378 irq 7
00000000000i[     ] init_dev of 'serial' plugin device by virtual method
00000000000i[SER  ] com1 at 0x03f8 irq 4
00000000000i[     ] init_dev of 'gameport' plugin device by virtual method
00000000000i[     ] init_dev of 'usb_uhci' plugin device by virtual method
00000000000i[DEV  ] Experimental USB UHCI present at device 1, function 2
00000000000i[UHCI ] USB UHCI initialized
00000000000i[     ] register state of 'pci' plugin device by virtual method
00000000000i[     ] register state of 'pci2isa' plugin device by virtual method
00000000000i[     ] register state of 'cmos' plugin device by virtual method
00000000000i[     ] register state of 'dma' plugin device by virtual method
00000000000i[     ] register state of 'pic' plugin device by virtual method
00000000000i[     ] register state of 'pit' plugin device by virtual method
00000000000i[     ] register state of 'floppy' plugin device by virtual method
00000000000i[     ] register state of 'vga' plugin device by virtual method
00000000000i[     ] register state of 'unmapped' plugin device by virtual method
00000000000i[     ] register state of 'biosdev' plugin device by virtual method
00000000000i[     ] register state of 'speaker' plugin device by virtual method
00000000000i[     ] register state of 'extfpuirq' plugin device by virtual method
00000000000i[     ] register state of 'parallel' plugin device by virtual method
00000000000i[     ] register state of 'serial' plugin device by virtual method
00000000000i[     ] register state of 'gameport' plugin device by virtual method
00000000000i[     ] register state of 'usb_uhci' plugin device by virtual method
00000000000i[     ] register state of 'acpi' plugin device by virtual method
00000000000i[     ] register state of 'ioapic' plugin device by virtual method
00000000000i[     ] register state of 'keyboard' plugin device by virtual method
00000000000i[     ] register state of 'harddrv' plugin device by virtual method
00000000000i[     ] register state of 'pci_ide' plugin device by virtual method
00000000000i[SYS  ] bx_pc_system_c::Reset(HARDWARE) called
00000000000i[CPU0 ] cpu hardware reset
00000000000i[APIC0] allocate APIC id=0 (MMIO enabled) to 0x0000fee00000
00000000000i[CPU0 ] CPUID[0x00000000]: 00000005 756e6547 6c65746e 49656e69
00000000000i[CPU0 ] CPUID[0x00000001]: 00000633 00010800 00002028 1fcbfbff
00000000000i[CPU0 ] CPUID[0x00000002]: 00410601 00000000 00000000 00000000
00000000000i[CPU0 ] CPUID[0x00000003]: 00000000 00000000 00000000 00000000
00000000000i[CPU0 ] CPUID[0x00000004]: 00000000 00000000 00000000 00000000
00000000000i[CPU0 ] CPUID[0x00000005]: 00000040 00000040 00000003 00000020
00000000000i[CPU0 ] CPUID[0x80000000]: 80000008 00000000 00000000 00000000
00000000000i[CPU0 ] CPUID[0x80000001]: 00000000 00000000 00000101 2a100000
00000000000i[CPU0 ] CPUID[0x80000002]: 20202020 20202020 20202020 6e492020
00000000000i[CPU0 ] CPUID[0x80000003]: 286c6574 50202952 69746e65 52286d75
00000000000i[CPU0 ] CPUID[0x80000004]: 20342029 20555043 20202020 00202020
00000000000i[CPU0 ] CPUID[0x80000005]: 01ff01ff 01ff01ff 40020140 40020140
00000000000i[CPU0 ] CPUID[0x80000006]: 00000000 42004200 02008140 00000000
00000000000i[CPU0 ] CPUID[0x80000007]: 00000000 00000000 00000000 00000000
00000000000i[CPU0 ] CPUID[0x80000008]: 00003028 00000000 00000000 00000000
00000000000i[     ] reset of 'pci' plugin device by virtual method
00000000000i[     ] reset of 'pci2isa' plugin device by virtual method
00000000000i[     ] reset of 'cmos' plugin device by virtual method
00000000000i[     ] reset of 'dma' plugin device by virtual method
00000000000i[     ] reset of 'pic' plugin device by virtual method
00000000000i[     ] reset of 'pit' plugin device by virtual method
00000000000i[     ] reset of 'floppy' plugin device by virtual method
00000000000i[     ] reset of 'vga' plugin device by virtual method
00000000000i[     ] reset of 'acpi' plugin device by virtual method
00000000000i[     ] reset of 'ioapic' plugin device by virtual method
00000000000i[     ] reset of 'keyboard' plugin device by virtual method
00000000000i[     ] reset of 'harddrv' plugin device by virtual method
00000000000i[     ] reset of 'pci_ide' plugin device by virtual method
00000000000i[     ] reset of 'unmapped' plugin device by virtual method
00000000000i[     ] reset of 'biosdev' plugin device by virtual method
00000000000i[     ] reset of 'speaker' plugin device by virtual method
00000000000i[SPEAK] Using system beep for output
00000000000i[     ] reset of 'extfpuirq' plugin device by virtual method
00000000000i[     ] reset of 'parallel' plugin device by virtual method
00000000000i[     ] reset of 'serial' plugin device by virtual method
00000000000i[     ] reset of 'gameport' plugin device by virtual method
00000000000i[     ] reset of 'usb_uhci' plugin device by virtual method
00000000019i[MEM0 ] allocate_block: block=0x0 used 0x1 of 0x10
00000004655i[BIOS ] $Revision: 11545 $ $Date: 2012-11-11 09:11:17 +0100 (So, 11. Nov 2012) $
00000318061i[KBD  ] reset-disable command received
00000320697i[BIOS ] Starting rombios32
00000321138i[BIOS ] Shutdown flag 0
00000321710i[BIOS ] ram_size=0x01000000
00000322173i[BIOS ] ram_end=16MB
00000800001i[WGUI ] dimension update x=720 y=400 fontheight=16 fontwidth=9 bpp=8
00001250336i[BIOS ] Found 1 cpu(s)
00001264355i[BIOS ] bios_table_addr: 0x000fa448 end=0x000fcc00
00001592000i[PCI  ] i440FX PMC write to PAM register 59 (TLB Flush)
00001920317i[P2I  ] PCI IRQ routing: PIRQA# set to 0x0b
00001920342i[P2I  ] PCI IRQ routing: PIRQB# set to 0x09
00001920342i[P2I  ] PCI IRQ routing: PIRQC# set to 0x0b
00001920342i[P2I  ] PCI IRQ routing: PIRQD# set to 0x09
00001920342i[P2I  ] write: ELCR2 = 0x0a
00001921007i[BIOS ] PIIX3/PIIX4 init: elcr=00 0a
00001928466i[BIOS ] PCI: bus=0 devfn=0x00: vendor_id=0x8086 device_id=0x1237 class=0x0600
00001931005i[BIOS ] PCI: bus=0 devfn=0x08: vendor_id=0x8086 device_id=0x7000 class=0x0601
00001933000i[BIOS ] PCI: bus=0 devfn=0x09: vendor_id=0x8086 device_id=0x7010 class=0x0101
00001933464i[PIDE ] new BM-DMA address: 0xc000
00001934002i[BIOS ] region 4: 0x0000c000
00001936004i[BIOS ] PCI: bus=0 devfn=0x0a: vendor_id=0x8086 device_id=0x7020 class=0x0c03
00001936287i[UHCI ] new base address: 0xc020
00001936808i[BIOS ] region 4: 0x0000c020
00001937013i[UHCI ] new irq line = 9
00001938525i[BIOS ] PCI: bus=0 devfn=0x0b: vendor_id=0x8086 device_id=0x7113 class=0x0680
00001939002i[ACPI ] new irq line = 11
00001939182i[ACPI ] new irq line = 9
00001939203i[ACPI ] new PM base address: 0xb000
00001939203i[ACPI ] new SM base address: 0xb100
00001939235i[PCI  ] setting SMRAM control register to 0x4a
00002103353i[CPU0 ] Enter to System Management Mode
00002103353i[CPU0 ] enter_system_management_mode: temporary disable VMX while in SMM mode
00002103357i[CPU0 ] RSM: Resuming from System Management Mode
00002267376i[PCI  ] setting SMRAM control register to 0x0a
00002282001i[BIOS ] MP table addr=0x000fa520 MPC table addr=0x000fa450 size=0xc8
00002284003i[BIOS ] SMBIOS table addr=0x000fa530
00002284115i[MEM0 ] allocate_block: block=0xf used 0x2 of 0x10
00002286005i[BIOS ] ACPI tables: RSDP addr=0x000fa650 ACPI DATA addr=0x00ff0000 size=0xf72
00002289234i[BIOS ] Firmware waking vector 0xff00cc
00002291206i[PCI  ] i440FX PMC write to PAM register 59 (TLB Flush)
00002291760i[BIOS ] bios_table_cur_addr: 0x000fa674
00002419564i[VBIOS] VGABios $Id: vgabios.c,v 1.75 2011/10/15 14:07:21 vruppert Exp $

00002419634i[BXVGA] VBE known Display Interface b0c0
00002419666i[BXVGA] VBE known Display Interface b0c5
00002422592i[VBIOS] VBE Bios $Id: vbe.c,v 1.64 2011/07/19 18:25:05 vruppert Exp $
00014919119i[BIOS ] Booting from 0000:7c00
00017600001i[WGUI ] dimension update x=640 y=400 fontheight=0 fontwidth=0 bpp=8
00037111982e[CPU0 ] fetch_raw_descriptor: GDT: index (7c7) f8 > limit (17)
00037111982e[CPU0 ] interrupt(): gate descriptor is not valid sys seg (vector=0x0d)
00037111982e[CPU0 ] interrupt(): gate descriptor is not valid sys seg (vector=0x08)
00037111982i[CPU0 ] CPU is in protected mode (active)
00037111982i[CPU0 ] CS.mode = 32 bit
00037111982i[CPU0 ] SS.mode = 32 bit
00037111982i[CPU0 ] EFER   = 0x00000000
00037111982i[CPU0 ] | EAX=d88e07c0  EBX=00000000  ECX=000900ff  EDX=000000c8
00037111982i[CPU0 ] | ESP=0008fffc  EBP=00000000  ESI=000e019b  EDI=00000005
00037111982i[CPU0 ] | IOPL=0 id vip vif ac vm RF nt of df if tf sf zf af PF CF
00037111982i[CPU0 ] | SEG sltr(index|ti|rpl)     base    limit G D
00037111982i[CPU0 ] |  CS:0008( 0001| 0|  0) 00000000 ffffffff 1 1
00037111982i[CPU0 ] |  DS:0010( 0002| 0|  0) 00000000 ffffffff 1 1
00037111982i[CPU0 ] |  SS:0010( 0002| 0|  0) 00000000 ffffffff 1 1
00037111982i[CPU0 ] |  ES:0010( 0002| 0|  0) 00000000 ffffffff 1 1
00037111982i[CPU0 ] |  FS:07c0( 0005| 0|  0) 00007c00 0000ffff 0 0
00037111982i[CPU0 ] |  GS:07c0( 0005| 0|  0) 00007c00 0000ffff 0 0
00037111982i[CPU0 ] | EIP=00007c44 (00007c44)
00037111982i[CPU0 ] | CR0=0x60000011 CR2=0x00000000
00037111982i[CPU0 ] | CR3=0x00000000 CR4=0x00000000
00037111982i[CPU0 ] 0x0000000000007c44>> mov es, ax : 8EC0
00037111982e[CPU0 ] exception(): 3rd (13) exception with no resolution, shutdown status is 00h, resetting
00037111982i[SYS  ] bx_pc_system_c::Reset(HARDWARE) called
00037111982i[CPU0 ] cpu hardware reset
00037111982i[APIC0] allocate APIC id=0 (MMIO enabled) to 0x0000fee00000
00037111982i[CPU0 ] CPUID[0x00000000]: 00000005 756e6547 6c65746e 49656e69
00037111982i[CPU0 ] CPUID[0x00000001]: 00000633 00010800 00002028 1fcbfbff
00037111982i[CPU0 ] CPUID[0x00000002]: 00410601 00000000 00000000 00000000
00037111982i[CPU0 ] CPUID[0x00000003]: 00000000 00000000 00000000 00000000
00037111982i[CPU0 ] CPUID[0x00000004]: 00000000 00000000 00000000 00000000
00037111982i[CPU0 ] CPUID[0x00000005]: 00000040 00000040 00000003 00000020
00037111982i[CPU0 ] CPUID[0x80000000]: 80000008 00000000 00000000 00000000
00037111982i[CPU0 ] CPUID[0x80000001]: 00000000 00000000 00000101 2a100000
00037111982i[CPU0 ] CPUID[0x80000002]: 20202020 20202020 20202020 6e492020
00037111982i[CPU0 ] CPUID[0x80000003]: 286c6574 50202952 69746e65 52286d75
00037111982i[CPU0 ] CPUID[0x80000004]: 20342029 20555043 20202020 00202020
00037111982i[CPU0 ] CPUID[0x80000005]: 01ff01ff 01ff01ff 40020140 40020140
00037111982i[CPU0 ] CPUID[0x80000006]: 00000000 42004200 02008140 00000000
00037111982i[CPU0 ] CPUID[0x80000007]: 00000000 00000000 00000000 00000000
00037111982i[CPU0 ] CPUID[0x80000008]: 00003028 00000000 00000000 00000000
00037111982i[     ] reset of 'pci' plugin device by virtual method
00037111982i[     ] reset of 'pci2isa' plugin device by virtual method
00037111982i[     ] reset of 'cmos' plugin device by virtual method
00037111982i[     ] reset of 'dma' plugin device by virtual method
00037111982i[     ] reset of 'pic' plugin device by virtual method
00037111982i[     ] reset of 'pit' plugin device by virtual method
00037111982i[     ] reset of 'floppy' plugin device by virtual method
00037111982i[     ] reset of 'vga' plugin device by virtual method
00037111982i[     ] reset of 'acpi' plugin device by virtual method
00037111982i[     ] reset of 'ioapic' plugin device by virtual method
00037111982i[     ] reset of 'keyboard' plugin device by virtual method
00037111982i[     ] reset of 'harddrv' plugin device by virtual method
00037111982i[     ] reset of 'pci_ide' plugin device by virtual method
00037111982i[     ] reset of 'unmapped' plugin device by virtual method
00037111982i[     ] reset of 'biosdev' plugin device by virtual method
00037111982i[     ] reset of 'speaker' plugin device by virtual method
00037111982i[     ] reset of 'extfpuirq' plugin device by virtual method
00037111982i[     ] reset of 'parallel' plugin device by virtual method
00037111982i[     ] reset of 'serial' plugin device by virtual method
00037111982i[     ] reset of 'gameport' plugin device by virtual method
00037111982i[     ] reset of 'usb_uhci' plugin device by virtual method
00037116638i[BIOS ] $Revision: 11545 $ $Date: 2012-11-11 09:11:17 +0100 (So, 11. Nov 2012) $
00037430044i[KBD  ] reset-disable command received
00037432718i[BIOS ] Starting rombios32
00037433159i[BIOS ] Shutdown flag 0
00037433731i[BIOS ] ram_size=0x01000000
00037434194i[BIOS ] ram_end=16MB
00037600000i[WGUI ] dimension update x=720 y=400 fontheight=16 fontwidth=9 bpp=8
00038372335i[BIOS ] Found 1 cpu(s)
00038386354i[BIOS ] bios_table_addr: 0x000fa448 end=0x000fcc00
00038714004i[PCI  ] i440FX PMC write to PAM register 59 (TLB Flush)
00039042316i[P2I  ] PCI IRQ routing: PIRQA# set to 0x0b
00039042341i[P2I  ] PCI IRQ routing: PIRQB# set to 0x09
00039042341i[P2I  ] PCI IRQ routing: PIRQC# set to 0x0b
00039042341i[P2I  ] PCI IRQ routing: PIRQD# set to 0x09
00039042341i[P2I  ] write: ELCR2 = 0x0a
00039043006i[BIOS ] PIIX3/PIIX4 init: elcr=00 0a
00039050465i[BIOS ] PCI: bus=0 devfn=0x00: vendor_id=0x8086 device_id=0x1237 class=0x0600
00039053004i[BIOS ] PCI: bus=0 devfn=0x08: vendor_id=0x8086 device_id=0x7000 class=0x0601
00039055005i[BIOS ] PCI: bus=0 devfn=0x09: vendor_id=0x8086 device_id=0x7010 class=0x0101
00039056001i[BIOS ] region 4: 0x0000c000
00039058003i[BIOS ] PCI: bus=0 devfn=0x0a: vendor_id=0x8086 device_id=0x7020 class=0x0c03
00039058807i[BIOS ] region 4: 0x0000c020
00039059012i[UHCI ] new irq line = 9
00039060524i[BIOS ] PCI: bus=0 devfn=0x0b: vendor_id=0x8086 device_id=0x7113 class=0x0680
00039061001i[ACPI ] new irq line = 11
00039061181i[ACPI ] new irq line = 9
00039061234i[PCI  ] setting SMRAM control register to 0x4a
00039225352i[CPU0 ] Enter to System Management Mode
00039225352i[CPU0 ] enter_system_management_mode: temporary disable VMX while in SMM mode
00039225356i[CPU0 ] RSM: Resuming from System Management Mode
00039389375i[PCI  ] setting SMRAM control register to 0x0a
00039404000i[BIOS ] MP table addr=0x000fa520 MPC table addr=0x000fa450 size=0xc8
00039406002i[BIOS ] SMBIOS table addr=0x000fa530
00039408004i[BIOS ] ACPI tables: RSDP addr=0x000fa650 ACPI DATA addr=0x00ff0000 size=0xf72
00039411233i[BIOS ] Firmware waking vector 0xff00cc
00039413205i[PCI  ] i440FX PMC write to PAM register 59 (TLB Flush)
00039413759i[BIOS ] bios_table_cur_addr: 0x000fa674
00039541563i[VBIOS] 
VGABios $Id: vgabios.c,v 1.75 2011/10/15 14:07:21 vruppert Exp $

00039541633i[BXVGA] VBE known Display Interface b0c0
00039541665i[BXVGA] VBE known Display Interface b0c5
00039544591i[VBIOS] VBE Bios $Id: vbe.c,v 1.64 2011/07/19 18:25:05 vruppert Exp $
00045600000p[WGUI ] >>PANIC<< POWER button turned off.
00045600000i[CPU0 ] CPU is in real mode (halted)
00045600000i[CPU0 ] CS.mode = 16 bit
00045600000i[CPU0 ] SS.mode = 16 bit
00045600000i[CPU0 ] EFER   = 0x00000000
00045600000i[CPU0 ] | EAX=00000000  EBX=00000000  ECX=0009e080  EDX=00000000
00045600000i[CPU0 ] | ESP=0000ff9c  EBP=0000ffb0  ESI=000e0000  EDI=0000ffac
00045600000i[CPU0 ] | IOPL=0 id vip vif ac vm rf nt of df IF tf SF zf AF PF CF
00045600000i[CPU0 ] | SEG sltr(index|ti|rpl)     base    limit G D
00045600000i[CPU0 ] |  CS:f000( 0004| 0|  0) 000f0000 0000ffff 0 0
00045600000i[CPU0 ] |  DS:0000( 0005| 0|  0) 00000000 0000ffff 0 0
00045600000i[CPU0 ] |  SS:0000( 0005| 0|  0) 00000000 0000ffff 0 0
00045600000i[CPU0 ] |  ES:c000( 0005| 0|  0) 000c0000 0000ffff 0 0
00045600000i[CPU0 ] |  FS:0000( 0005| 0|  0) 00000000 0000ffff 0 0
00045600000i[CPU0 ] |  GS:0000( 0005| 0|  0) 00000000 0000ffff 0 0
00045600000i[CPU0 ] | EIP=00000863 (00000863)
00045600000i[CPU0 ] | CR0=0x60000010 CR2=0x00000000
00045600000i[CPU0 ] | CR3=0x00000000 CR4=0x00000000
00045600000i[CPU0 ] 0x0000000000000863>> mov ax, word ptr ds:0x46c : A16C04
00045600000i[CMOS ] Last time is 1393007006 (Fri Feb 21 12:23:26 2014)
00045600000i[     ] restoring default signal behavior
00045600000i[CTRL ] quit_sim called with exit code 1
I've tried Enable A20 VIA keyboard, still the same issue, so I assume A20 is enabled the error states "mov es, ax" is the issue, I've been looking through several tutorials and codes and cannot find why this error occurs in my code when this segment ended up being copy and pasted from 3 different sources which all worked flawlessly

It is changing from Text mode to video mode 13 and displaying the palette then back to text mode then straight to POST.

Re: Issue getting into protected mode.

Posted: Fri Feb 21, 2014 12:59 pm
by Antti
BASICFreak wrote:

Code: Select all

   mov      ax, 0x9000         ; stack begins at 0x9000-0xffff
   mov      ss, ax
   mov      sp, 0xFFFF
I did not read all your code but I think this is a serious bug. You are overwriting Extended Bios Data Area (EBDA). There is also one smaller issue: unaligned stack. It is like putting shoes on the wrong feet.

Re: Issue getting into protected mode.

Posted: Fri Feb 21, 2014 1:03 pm
by Combuster
this segment ended up being copy and pasted from 3 different sources which all worked flawlessly
And what happens when you take a gas burner, a microwave and an induction element and try to apply it to the same food at the same time? #-o


The reason for the crash is perfectly clear from the dump. Look at the value of AX, and remember what MOV ES, AX means in protected mode.

Re: Issue getting into protected mode.

Posted: Fri Feb 21, 2014 2:07 pm
by BASICFreak
Antti wrote:
BASICFreak wrote:

Code: Select all

   mov      ax, 0x9000         ; stack begins at 0x9000-0xffff
   mov      ss, ax
   mov      sp, 0xFFFF
I did not read all your code but I think this is a serious bug. You are overwriting Extended Bios Data Area (EBDA). There is also one smaller issue: unaligned stack. It is like putting shoes on the wrong feet.
This is still in real mode and after ES, AX and AX = 0x10 is the first in protected mode before ES, AX
Combuster wrote:
this segment ended up being copy and pasted from 3 different sources which all worked flawlessly
And what happens when you take a gas burner, a microwave and an induction element and try to apply it to the same food at the same time? #-o


The reason for the crash is perfectly clear from the dump. Look at the value of AX, and remember what MOV ES, AX means in protected mode.
All three sources were identical in this segment.

Value of AX should be 10h

Code: Select all

mov ax, 0x10     ;^
mov ds, ax
mov ss, ax
mov es, ax     ;v
mov esp, 90000h
and MOV ES, AX should initialize ES to data selector (0x10)?? Am I wrong

BOCHS on crash is:

Code: Select all

00037111862i[CPU0 ] CPU is in protected mode (active)
00037111862i[CPU0 ] CS.mode = 32 bit
00037111862i[CPU0 ] SS.mode = 32 bit
00037111862i[CPU0 ] EFER   = 0x00000000
00037111862i[CPU0 ] | EAX=d88e07c0  EBX=00000000  ECX=60000010  EDX=00000000
00037111862i[CPU0 ] | ESP=0008fff8  EBP=ffffffff  ESI=600e019c  EDI=00000003
00037111862i[CPU0 ] | IOPL=0 id vip vif ac vm RF nt of df if tf sf ZF af PF cf
00037111862i[CPU0 ] | SEG sltr(index|ti|rpl)     base    limit G D
00037111862i[CPU0 ] |  CS:0008( 0001| 0|  0) 00000000 ffffffff 1 1
00037111862i[CPU0 ] |  DS:0010( 0002| 0|  0) 00000000 ffffffff 1 1
00037111862i[CPU0 ] |  SS:0010( 0002| 0|  0) 00000000 ffffffff 1 1
00037111862i[CPU0 ] |  ES:0010( 0002| 0|  0) 00000000 ffffffff 1 1
00037111862i[CPU0 ] |  FS:07c0( 0005| 0|  0) 00007c00 0000ffff 0 0
00037111862i[CPU0 ] |  GS:07c0( 0005| 0|  0) 00007c00 0000ffff 0 0
00037111862i[CPU0 ] | EIP=00007c44 (00007c44)
00037111862i[CPU0 ] | CR0=0x60000011 CR2=0x00000000
00037111862i[CPU0 ] | CR3=0x00000000 CR4=0x00000000
00037111862i[CPU0 ] 0x0000000000007c44>> mov es, ax : 8EC0
00037111862e[CPU0 ] exception(): 3rd (13) exception with no resolution, shutdown status is 00h, resetting
00037111862i[SYS  ] bx_pc_system_c::Reset(HARDWARE) called
00037111862i[CPU0 ] cpu hardware reset
Is that then saying AX is 8EC0h or is that a location?

Re: Issue getting into protected mode.

Posted: Fri Feb 21, 2014 2:30 pm
by Octocontrabass
BASICFreak wrote:
Antti wrote:
BASICFreak wrote:

Code: Select all

   mov      ax, 0x9000         ; stack begins at 0x9000-0xffff
   mov      ss, ax
   mov      sp, 0xFFFF
I did not read all your code but I think this is a serious bug. You are overwriting Extended Bios Data Area (EBDA). There is also one smaller issue: unaligned stack. It is like putting shoes on the wrong feet.
This is still in real mode and after ES, AX and AX = 0x10 is the first in protected mode before ES, AX
What is the physical address the stack pointer points to after that code executes?

What is the physical address of the EBDA?

When you know the answer both of these questions, we can help you.

Re: Issue getting into protected mode.

Posted: Fri Feb 21, 2014 3:49 pm
by BASICFreak
Well, got it working

The stack was not the issue

The issue is in the following:

Code: Select all

;bh = y
;bl = x
MovCur:
	pusha
	xor		eax, eax
	mov		ecx, COLS
	mov		al, bh
	mul		ecx
	add		al, bl
	mov		ebx, eax
	mov		al, 0x0F
	mov		dx, 0x03D4
	out		dx, al
	mov		al, bl
	mov		dx, 0x03D5
	out		dx, al
	xor		eax, eax
	mov		al, 0x0E
	mov		dx, 0x03D4
	out		dx, al
	mov		al, bh
	mov		dx, 0x03D5
	out		dx, al
	popa
	ret
it is working flawlessly without calling this.

working on solution next.

Re: Issue getting into protected mode.

Posted: Fri Feb 21, 2014 4:37 pm
by Octocontrabass
You should fix the stack before you do anything else. Otherwise, you'll have all sorts of unusual errors when you try to run your code on real hardware.

Re: Issue getting into protected mode.

Posted: Fri Feb 21, 2014 5:13 pm
by BASICFreak
Octocontrabass wrote:You should fix the stack before you do anything else. Otherwise, you'll have all sorts of unusual errors when you try to run your code on real hardware.
somewhere between 500- 9FBFF and/or 100000- FEBFFFFF I assume?




Turned out my issue was worse than I first thought, my bootsector was not placing the next stage into the correct memory location (I forgot a 0 so instead of org = 0x500 - org was at 0x50 which is inside the IVT) which surprises me more that it worked at all...

After fixing the BootSector the code I pulled out works, and I shall change the stack next.

Re: Issue getting into protected mode.

Posted: Fri Feb 21, 2014 6:41 pm
by Octocontrabass
BASICFreak wrote:
Octocontrabass wrote:You should fix the stack before you do anything else. Otherwise, you'll have all sorts of unusual errors when you try to run your code on real hardware.
somewhere between 500- 9FBFF and/or 100000- FEBFFFFF I assume?
Don't assume. Those are both wrong.

Re: Issue getting into protected mode.

Posted: Fri Feb 21, 2014 8:56 pm
by Bender
Hi,
when this segment ended up being copy and pasted from 3 different sources which all worked flawlessly
You biggest problem is underlined. :wink:
As OctoContraBass said, IMO The basic rule of system programming is do not assume, and for something messy like a stack you shouldn't think of doing that.
IMO you should have something like this:

Code: Select all

jmp init
EMPTY_SPACE: rb 2048 * 3 ; You can put this to any number you want
; Since the stack grows downwards we should always point to the end of EMPTY_SPACE
KERNEL_STACK_BUFFER:
init:
........
........
Although this may increase executable size, but I feel its possibly the safest method. (*Waits for flames to come :)*)
The Bare Bones also follow pretty much the same method.
Bare Bones wrote: # Currently the stack pointer register (esp) points at anything and using it may
# cause massive harm. Instead, we'll provide our own stack. We will allocate
# room for a small temporary stack by creating a symbol at the bottom of it,
# then allocating 16384 bytes for it, and finally creating a symbol at the top.
.section .bootstrap_stack, "aw", @nobits
stack_bottom:
.skip 16384 # 16 KiB
stack_top:
As others have said you should fix the stack before anything else. I remember having a problem with writing to video memory because my stack was messed up.
-Bender

Re: Issue getting into protected mode.

Posted: Fri Feb 21, 2014 9:04 pm
by BASICFreak
Octocontrabass wrote:
BASICFreak wrote:
Octocontrabass wrote:You should fix the stack before you do anything else. Otherwise, you'll have all sorts of unusual errors when you try to run your code on real hardware.
somewhere between 500- 9FBFF and/or 100000- FEBFFFFF I assume?
Don't assume.
Those are both wrong.
The ranges I stated are "RAM (free for use, if it exists)"

I was looking at this
both of which seem to be identical (other than the ?'s depending on installed RAM) and my assumption is within a usable range

If I am wrong please explain why I cannot use unreserved RAM for the stack - I never said I would use all the range I said "between" (or within.)

Should I then use the Guaranteed Ranges - 0x500 to 7FFFF?

Re: Issue getting into protected mode.

Posted: Fri Feb 21, 2014 10:37 pm
by Octocontrabass
BASICFreak wrote:If I am wrong please explain why I cannot use unreserved RAM for the stack - I never said I would use all the range I said "between" (or within.)
Because you assume it's unreserved.
BASICFreak wrote:Should I then use the Guaranteed Ranges - 0x500 to 7FFFF?
Yes. You can always move it elsewhere after you've done some memory detection.

Re: Issue getting into protected mode.

Posted: Sat Feb 22, 2014 2:22 pm
by Combuster
d88e07c0
And then you suddenly realize that the high bytes of that number form the opcode "mov ds, ax"...

Fix you instruction encoding settings.