bochs error

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
elias

bochs error

Post by elias »

whenever i try to boot my floppy image, it just sits there with the message "booting from floppy" and it seems like its not doing anything. thecursor has gone onto the next line, so maybe it did load, but my code wont print anyhting, like its supposed to. heres my boot code:

[ORG 7C00h]

jmp start

start:
mov ax, 0000h
mov ss, ax
mov sp, 7BEFh
push cs
pop ds

mov ah, 02h ;call int 13h to load off floppy
mov al, 01h
mov ch, 00h
mov cl, 02h
mov dh, 00h
mov bx, 0800h
mov es, bx
mov bx, 0000h
int 13h
jmp 0800h:0000h


times 472 db 0 ;waste of space

sig1 db 0x55 ;magic BIOS numbers
sig2 db 0xAA

and heres my kernel code:

[ORG 8000]

jmp print

msg db 'kernel succesfully loaded', 0

print:
push ds
pop es
mov ah, 0Eh
lea si, [msg]

str_loop:
lodsb
cmp al, 0
jz end
int 10h
jmp str_loop

end:
ret

is theres anythign wrong, please tell me, and tell me wats wrong too. thanx
PlayOS

Re:bochs error

Post by PlayOS »

I am not sure who posted it, but I fixed this code a few days ago, so there is a solution in one of these threads, anyway here is the fixed code, read the comments for help on what was wrong

Boot.asm

Nothing wrong with this, just added a better way to fill out the file.

Code: Select all

[ORG 7C00h]

jmp start

start:
  mov ax, 0000h
  mov ss, ax
  mov sp, 7BEFh

  push cs
  pop ds

  mov ah, 02h                ;call int 13h to load off floppy
  mov al, 01h
  mov ch, 00h
  mov cl, 02h
  mov dh, 00h
  mov bx, 0800h
  mov es, bx
  mov bx, 0000h
  int 13h
  jmp 0800h:0000h                                

  ; times 472 db 0              ;waste of space
  times 510-($-$$) db 0      ; doing this will mean you do not have to do any calculations, it will automaticlly
                        ; fill out to 510 bytes

  sig1 db 0x55                ;magic BIOS numbers
  sig2 db 0xAA
Kernel.asm

See comments for help

Code: Select all

;[ORG 8000]  ; this is the wrong offset, you loaded to 0800:0000 which is 8000 physical, you need to read up on
             ; what the org directive does.
[ORG 0x0000]

   mov ax, 0x0800  ; you had no data segment
   mov ds, ax

   ; jmp print ; must be call not jmp, because you do a ret down the bottom
   call print

     jmp $   ; this will just hang

msg db 'kernel succesfully loaded', 0

print:
  push ds
  pop es
  mov ah, 0Eh
  lea si, [msg]

  str_loop:
      lodsb
      cmp al, 0
      jz end
      int 10h
      jmp str_loop

  end:
      ret
Hope this helps.
elias

Re:bochs error

Post by elias »

now bochs panics and i get the error:
[BIOS ] BIOS panic at rombios.c, line 9841
PlayOS

Re:bochs error

Post by PlayOS »

You may need to re-download bochs, what version do you have?

If you have the sources to bochs then you could try recompiling it.

This error is not anything to do with your code.
Tom

Re:bochs error

Post by Tom »

try your code without bochs...if in linux ( are you? ) use my favorite "reboot" ( or with any jornaling FS, "reboot -f" ) :D ;)
elias

Re:bochs error

Post by elias »

well unfortunatley i am not on linux, and i have the latest version of bochs, unless another on has come out in the previous week. could someone who has compiled and run my code, and had it work, please post your config file. that could be some error
PlayOS

Re:bochs error

Post by PlayOS »

No dramas, your code worked on my bochs so it is probably just your bochsrc.txt file, here is the one I used to fix your code.

# ========================
romimage: file=../BIOS-bochs-latest, address=0xf0000
vgaromimage: ../VGABIOS-elpin-2.40
megs: 64
floppya: 1_44=playos.img, status=inserted
boot: a
log: bochsout.txt
# ========================

Hope this helps.
wentong

Re:bochs error

Post by wentong »

one is the boot.asm,one is the kernel.asm
compile them by NASM,
but the boot' size is 512byte,one sector
i know how to put it into the playos.img,but how about the other.
PlayOS

Re:bochs error

Post by PlayOS »

When I create my disk images I write evrything to the disk and then copy the disk to an image file, like this

compile the files

nasm boot.asm
nasm kernel.asm

copy to the disk

bootcopy boot 0 ; you can use partcopy or whatever
bootcopy kernel 1 ; bootcopy has zero based sector #'s

create the image

partcopy -f0 0 1000 playos.img

this image is bigger than needed but that is nothing to worry about.
wentong

Re:bochs error

Post by wentong »

thanks for your post
and can u check this code for me

==========================
here it is
==========================
;filename: boot.asm
ORG 0x7C00
BEGIN: ; NOW AT 0000:7C00, RELOCATE
   CLI ;disable int's
   XOR AX,AX ;set stack seg to 0000
   MOV SS,AX
   MOV SP,0x7C00 ;set stack ptr to 7c00
   MOV SI,SP ;SI now 7c00
   PUSH AX
   POP ES ;ES now 0000:7c00
   PUSH AX
   POP DS ;DS now 0000:7c00
   STI ;allow int's
   CLD ;clear direction
   MOV DI,0x600 ;DI now 0600
   MOV CX,0x100 ;move 256 words (512 bytes)
   REPNZ MOVSW ;move MBR from 0000:7c00
    ; to 0000:0600
   JMP 0000:0x6000+ start - BEGIN    ;jmp to start


start:

   mov ax,0xb800
   mov es,ax
   xor di,di
   mov ax,0x0720
   mov cx,80*25   
   cld
   rep stosw

   cli
   hlt

times 510-($-$$) db 0x90
dw 0xAA55

==============================

next step by me

==============================
nasm -f bin boot.asm -o boot.bin

partcopy -f0 0 200 boot.img


and then i test it by bochs,but i can't work. what's wrong
PlayOS

Re:bochs error

Post by PlayOS »

OK, your code is pretty much right, except you are trying to jump to 0x0:0x6000 when your code is at 0x0:0x600 one too many zeros on that address.

So here is the code that I ended up with after fixing:

Code: Select all

[BITS 16]     ; should have this, dont have to, but you should
[ORG 0x7c00]

BEGIN:                  ;    NOW AT 0000:7C00, RELOCATE
   CLI                    ;disable int's
   XOR      AX,AX          ;set stack seg to 0000
   MOV      SS,AX
   MOV      SP,0x7C00        ;set stack ptr to 7c00
   MOV      SI,SP          ;SI now 7c00
   PUSH      AX
   POP      ES              ;ES now 0000:7c00
   PUSH      AX
   POP      DS              ;S now 0000:7c00
   STI                    ;allow int's
   CLD                    ;clear direction
   MOV      DI,0x600        ;I now 0600
   MOV      CX,0x100        ;move 256 words (512 bytes)
   REPNZ                  ;move MBR from 0000:7c00
   MOVSW                  ;  to 0000:0600
   JMP      0x0000:0x0600 + start - BEGIN   ; notice 0x600 instead of 0x6000

start:
              ;clear screen
   mov      ax,0xb800
   mov      es,ax
   xor      di,di
   mov      ax,0x0720
   mov      cx,80*25   
   cld
   rep      stosw
   
   mov      word [es:0x0], 0x1e41 ; this just confirms we get here

   cli
   hlt

times 510-($-$$) db 0x90
dw 0xAA55
Hope this helps.
wentong

Re:bochs error

Post by wentong »

but it doesn't work,
and why code here

mov word [es:0x0], 0x1e41 ; this just confirms we get here


and here 's the sample can works


==================================
;** represent i delete that line,it can't work
i don't understand why i can't delete.
==================================
ORG 0x7c00

BOOTSEG equ    0x07c0
INITSEG equ    0x600

start:
   ;move all the code to 0x6000
   mov   ax,0xb800
   mov   fs,ax
   mov   byte [fs:0],'1' ;**
   mov   byte [fs:2],'2' ;**
   mov   byte [fs:4],'2' ;**
   mov   byte [fs:6],'2' ;**
   mov   ax,BOOTSEG
   mov   ds,ax
   mov   byte [fs:2],'2' ;**
   mov   ax,INITSEG
   mov   es,ax
   mov   cx,256
   sub   si,si
   sub   di,di

   rep    movsw
   mov   byte [fs:4],'3' ;**
   jmp    INITSEG:go
go:
   mov   byte [fs:6],'4' ;**
   mov   ax,cs
   mov   ds,ax
   mov   es,ax
   mov   ss,ax
   mov   sp,0x400 ; arbitrary value >>512

   ;read the cursor position
   mov   ah,0x03   ; read cursor pos
   xor   bh,bh
   int   0x10

   ;display the string
   mov   cx,24
   mov   bx,0x0007 ; page 0, attribute 7 (normal)
   mov   bp,msg1
   mov   ax,0x1301 ; write string, move cursor
   int   0x10

   jmp $

msg1:
   db 13,10
   db "Loading system ..."
   db 13,10,13,10

times 510-($-$$) db 0
dw 0xAA55
Tom

Re:bochs error

Post by Tom »

Why don't you try setting up a stack more simply?
Post Reply