Page 1 of 1

[SOLVED] Jumping to stage two - segment limit violation

Posted: Sun Apr 27, 2014 8:45 pm
by BASICFreak
Currently I have my stage two located at physical address 0xBE00 (7C0:4200) and I have tried many different ways to jump to it but almost always get the following bochs output:
00017075992e[CPU0 ] read_virtual_word_32(): segment limit violation
00017076000p[WGUI ] >>PANIC<< POWER button turned off.
00017076000i[CPU0 ] CPU is in real mode (active)
00017076000i[CPU0 ] CS.mode = 16 bit
00017076000i[CPU0 ] SS.mode = 16 bit
00017076000i[CPU0 ] EFER = 0x00000000
00017076000i[CPU0 ] | EAX=00004201 EBX=00004e00 ECX=0009ffff EDX=00000100
00017076000i[CPU0 ] | ESP=0000ffff EBP=00000000 ESI=000e01dd EDI=00000005
00017076000i[CPU0 ] | IOPL=0 id vip vif ac vm rf nt of df IF tf sf ZF af PF cf
00017076000i[CPU0 ] | SEG sltr(index|ti|rpl) base limit G D
00017076000i[CPU0 ] | CS:0be0( 0004| 0| 0) 0000be00 0000ffff 0 0
00017076000i[CPU0 ] | DS:07c0( 0005| 0| 0) 00007c00 0000ffff 0 0
00017076000i[CPU0 ] | SS:0000( 0005| 0| 0) 00000000 0000ffff 0 0
00017076000i[CPU0 ] | ES:07c0( 0005| 0| 0) 00007c00 0000ffff 0 0
00017076000i[CPU0 ] | FS:07c0( 0005| 0| 0) 00007c00 0000ffff 0 0
00017076000i[CPU0 ] | GS:07c0( 0005| 0| 0) 00007c00 0000ffff 0 0
00017076000i[CPU0 ] | EIP=00000403 (00000403)
00017076000i[CPU0 ] | CR0=0x60000010 CR2=0x00000000
00017076000i[CPU0 ] | CR3=0x00000000 CR4=0x00000000
00017076000i[CPU0 ] 0x0000000000000403>> pop ax : 58
the current code I'm using to jump is:

Code: Select all

push WORD 0x0BE0
push WORD 0x0000
retf
I have tried 0x07C0:0x4200 and "jmp seg:off" instead of retf; but, mostly the same issue.

My stage two:

Code: Select all

bits	16

org 0xBE00

jmp	main	

[.......]

main:
 cli				; clear interrupts
 xor	ax, ax			; null segments
 mov	ds, ax
 mov	es, ax
 mov	ax, 0x0
 mov	ss, ax
 mov	sp, 0xFFFF
 sti
 [.......]
Any direction is highly appreciated as this has been driving me mad for too long.

If you need anything else just ask.

Re: Jumping to stage two - segment limit violation

Posted: Sun Apr 27, 2014 11:31 pm
by thepowersgang
Thankyou for including all the relevant information from the bochs output.

If you look at the bottom of the posted log, it says that the faulting instruction is 'pop ax'. Now take a look at the vaue of (E)SP, and you'll find out why it's failing.

Re: Jumping to stage two - segment limit violation

Posted: Mon Apr 28, 2014 1:05 pm
by BASICFreak
I moved my stack to 500-2000h and all working fine.

I would have never thought to move the stack thank you very much.

Also would you recommend to use the same stack or different on stage two?



ASM is not my strong suit but I want the bootloader to be my code and not a 'copy and paste' fest like it was.

Re: [SOLVED] Jumping to stage two - segment limit violation

Posted: Mon Apr 28, 2014 2:12 pm
by DavidCooper
BASICFreak wrote:I moved my stack to 500-2000h and all working fine.
You say that, but is it really working fine? Are you still popping a value off the stack when it was never on there in the first place to be popped? That appears to be what caused your problem. The only real error with your original stack was that it was misaligned by one byte, something which would not cause a crash but would merely slow the processor down a fraction.
Also would you recommend to use the same stack or different on stage two?
If is isn't in the way, leave it where it is and keep using it there until you can think of a good reason for putting it somewhere else.