Page 1 of 1

Bochs error

Posted: Sat Mar 17, 2012 4:15 am
by Samathy
hey,
i started developing a boot loader for my kernel a few weeks back but every time i test it using Bochs i get this error:
'00014058132i[CPU0 ] BOUND_GdMa: fails bounds test' and i get no output.
i did a few search and read that this error seems to be because of an incorrectly set up stack.
But what confuses me is no matter what method i use to set up the stack,
whether i read about it and write my own code or steal it from another boot loader from some tutorial, i still get this error.
what im asking is what does this error acctually mean, how can i fix it and how do you go about setting up the stack?

further info:
my boot loader is in NASM assembly,
it loads the kernel from the second sector of the floppy then jumps to the kernel. simples.

here is the code:

Code: Select all

; ================================
;OS/B boot loader
; ================================
msg_wait db "press any key to boot kernel", 0x0D, 0x0A , 0
org 0x07C0
;==============================================================================
;this is from MikeOS, because no matter how hard i try i cant get any sort of stack set up to work :(

	mov ax, 07C0h			; Set up 4K of stack space above buffer
	add ax, 544			; 8k buffer = 512 paragraphs + 32 paragraphs (loader)
	cli				; Disable interrupts while changing stack
	mov ss, ax
	mov sp, 4096
	sti				; Restore interrupts

	mov ax, 07C0h			; Set data segment to where we're loaded
	mov ds, ax
;================================================================================
 

 ;ok, load the kernel from the second sector of the floppy drive into 0x1000 of the RAM
 
 mov si, msg_wait
call print_string
   mov ah, 0
   int 0x16   ; wait for keypress
      mov dl, 0x00 ;drive is set as first floppy
   mov ah,0x00  ; reset drive
   int 0x13
   mov ax, 0x1000  ;memory adress for second sector to be loaded into
   mov cl, 2       ;sector to be read
   mov al, 1       ;number of sectors to be read
   mov dh, 0       ;head
   mov ch, 0       ;track
   mov ah, 0x02    ;set up interrupt
   mov bx, 0
   int 0x13        ;go go go!
   jmp 0x1000
   

 cli
 hlt
 
 ; ================
 ; calls ( from an OSDev tutorial, called something like 'writing a 16 bit real mode OS' i think...)
 ; ================
 
 print_string:
   lodsb        ; grab a byte from SI
 
   or al, al  ; logical or AL by itself
   jz .done   ; if the result is zero, get out
 
   mov ah, 0x0E
   int 0x10      ; otherwise, print out the character!
 
   jmp print_string
 
 .done:
   ret
 
   
   

 
   times 510-($-$$) db 0 ;fill whatever is left of the first sector with 0's
   dw 0AA55h ; BIOS boot sig
thanks in advance :)

Re: Bochs error

Posted: Sat Mar 17, 2012 4:23 am
by Brendan
Hi,
Samathy wrote:

Code: Select all

   mov ax, 0x1000  ;memory adress for second sector to be loaded into
   mov cl, 2       ;sector to be read
   mov al, 1       ;number of sectors to be read
   mov dh, 0       ;head
   mov ch, 0       ;track
   mov ah, 0x02    ;set up interrupt
   mov bx, 0
   int 0x13        ;go go go!
This BIOS function loads sectors at the address ES:BX. ES is never set anywhere. The BIOS might have left ES set to 0x07C0 so that the data you read overwrites the code you're executing, but the BIOS may also have left ES set to anything (so you could be trashing anything).


Cheers,

Brendan

Re: Bochs error

Posted: Sat Mar 17, 2012 4:32 am
by Samathy
ah,thanks you, i see
so because ES is not set i could not be loading the sectors at all, or loading them someplace random?
how would i set ES so my kernel is loaded directly after the bootloader?
Thanks.

Re: Bochs error

Posted: Sat Mar 17, 2012 4:49 am
by assembler01
Here is how you whould setup ES:

Code: Select all

mov bx, 0x1000 ; your load segment
mov es, bx
xor bx, bx
And remember: as Brendan said, the bios loads sectors at es:bx.

Re: Bochs error

Posted: Sat Mar 17, 2012 4:57 am
by assembler01
No wait, here is the error:
Samathy wrote:

Code: Select all

; ================================
;OS/B boot loader
; ================================
msg_wait db "press any key to boot kernel", 0x0D, 0x0A , 0
org 0x07C0
;==============================================================================
[/quote]
Never ever put data in code, you would need to jump over the data to the code.

Re: Bochs error

Posted: Sat Mar 17, 2012 5:02 am
by Samathy
ah, silly human error then!
thank you anyway, learnt alot in a few minuets!