[SOLVED] Jumping to stage two - segment limit violation

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
User avatar
BASICFreak
Member
Member
Posts: 284
Joined: Fri Jan 16, 2009 8:34 pm
Location: Louisiana, USA

[SOLVED] Jumping to stage two - segment limit violation

Post 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.
Last edited by BASICFreak on Mon Apr 28, 2014 1:05 pm, edited 1 time in total.
BOS Source Thanks to GitHub
BOS Expanded Commentary
Both under active development!
Sortie wrote:
  • Don't play the role of an operating systems developer, be one.
  • Be truly afraid of undefined [behavior].
  • Your operating system should be itself, not fight what it is.
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: Jumping to stage two - segment limit violation

Post 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.
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
User avatar
BASICFreak
Member
Member
Posts: 284
Joined: Fri Jan 16, 2009 8:34 pm
Location: Louisiana, USA

Re: Jumping to stage two - segment limit violation

Post 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.
BOS Source Thanks to GitHub
BOS Expanded Commentary
Both under active development!
Sortie wrote:
  • Don't play the role of an operating systems developer, be one.
  • Be truly afraid of undefined [behavior].
  • Your operating system should be itself, not fight what it is.
User avatar
DavidCooper
Member
Member
Posts: 1150
Joined: Wed Oct 27, 2010 4:53 pm
Location: Scotland

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

Post 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.
Help the people of Laos by liking - https://www.facebook.com/TheSBInitiative/?ref=py_c

MSB-OS: http://www.magicschoolbook.com/computing/os-project - direct machine code programming
Post Reply