bootloader???

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
Sam111
Member
Member
Posts: 385
Joined: Mon Nov 03, 2008 6:06 pm

bootloader???

Post by Sam111 »

I am very frustrated over this problem.
Basically I am testing in boch. I have my floppy.img file with the first sector containing code

Code: Select all

org 0x7C00
BITS 16
jmp start
greetings	    db	'Greetings and welcome ',13d,10d,'$' 
BOOTLOADER_NAME db 'Nates BootLoader Stage 1' ,13d,10d,'$'
STARTSECTOR     db  2            ;start sector to load
LOADADDRESS     dw  8000h       ; where to load the sectors into memory
NUMBEROFSECTORS db  1           ; number of bytes to load begining at STARTSECTOR

clear_screen:
mov ax , 600h      ; clear screen scroll up function
mov bh , 7h        ; white on black background
mov ch , 0h        ;upper line (top)
mov cl , 0h        ;left col (far left)
mov dh , 18h       ;bottom 
mov dl , 4Fh       ;far right
int 10h  ;                          do the clearing 
ret


readsectors_into_memory:
mov ah , 02h                    ; read function
mov al , NUMBEROFSECTORS        ; number  of sectors to read
mov ch , 0h                     ; cylinder number
mov cl , STARTSECTOR            ; starting sector to begin reading from
mov dh , 0h                     ; head number
mov dl , 00h                    ;drive for floppy
mov bx , LOADADDRESS            ; es:ds-> buffer for where the sectors will be loaded in this case 0000:8000h

int 13                          ; execute the interrupt for reading into memory
ret


start:
mov ax , 0x9100 ;set the stack to some random address
mov ss , ax
mov sp , 0x9000 ; set the stack pointer to some random address
xor ax , ax
mov ds , ax     ;data segment is at segment zero 
mov es , ax     ; exta segment is at segment zero now.

call clear_screen

mov ah , 13h
mov al , 01h 
mov bh , 0h
mov bl , 0Fh
mov dh , 5h
mov dl , 3h
mov cx , greetings
mov bp , cx
mov cx , 22d
int 10h


mov cx , BOOTLOADER_NAME
mov bp , cx
mov cx , 24d
mov dh , 10h
mov dl , 0h
int 10h

readData:
call readsectors_into_memory
jc readData



jmp 0000:8000 ;[color=#BF0000]When I get to this it loops back and seems like it executing the same code over and over and over It is not jumping to the correct place[/color]


On the second sector of the floppy I have the code

Code: Select all

org 0x8000
BITS 16
jmp main
hello	db	'This is sector 2!',13d,10d,'$' ;Put any data here!

main:
mov ax , 0
mov ds , ax 
mov es , ax
mov ax , 0x1110  ; set the stack to some random place.
mov ss , ax
mov sp , ax


mov ax , 600h       ; clear screen scroll up function
mov bh , 7h         ; white on black background
mov ch , 0h         ;upper line (top)
mov cl , 0h         ;left col (far left)
mov dh , 18h        ;bottom 
mov dl , 4Fh        ;far right
int 10h             ;do the clearing 

; display the string This is sector 2 on the screen
;mov ax , 0
;mov es , ax

mov ah , 13h
mov al , 01h 
mov bh , 0h
mov bl , 0Fh
mov dh , 5h
mov dl , 3h
mov cx , hello
mov bp , cx
mov cx , 16d
int 10h
; loop forever
endsss:
jmp endsss


Both code works seperately The first should just display Welcome and Greetings ....ect
Then it should load sector 2 which just displays 'This is sector 2!

I cann't figure out how to debug very well in boch. I am under windows xp.
The best I can do is look at the bochesout.txt which doesn't tell me very much.

If anybody has the time to run the to file I would greatly appreciatie it.
Since I have been stuck for ever with this. And I am more curious on why it isn't working as opposed to getting it working AHHHHHHHH #-o

Thanks
Attachments
load2.asm
(735 Bytes) Downloaded 67 times
bootit2.asm
(1.79 KiB) Downloaded 58 times
M-Saunders
Member
Member
Posts: 155
Joined: Fri Oct 27, 2006 5:11 am
Location: Oberbayern
Contact:

Re: bootloader???

Post by M-Saunders »

You're loading the second stage at:

Code: Select all

LOADADDRESS     dw  8000h       ; where to load the sectors into memory
...
mov bx , LOADADDRESS            ; es:ds-> buffer for where the sectors will be loaded in this case 0000:8000h
But then you jump to:

Code: Select all

jmp 0000:8000
(ie not a hex value). Might be the problem!

M
MikeOS -- simple, well-documented x86 real-mode OS written in assembly language
http://mikeos.sourceforge.net
User avatar
Sam111
Member
Member
Posts: 385
Joined: Mon Nov 03, 2008 6:06 pm

Re: bootloader???

Post by Sam111 »

No , I tried jmp 0000:8000h and it didn't work?

I have check that it is this instruction that is the problem.
By inserting infiinte loops and moving them down until I get the problem.
It is at the line jmp 0000:8000h.

Is the jump not correct?

I have my second program at org 0x8000 and copied it to the second sector of the floppy.img
floppy device is 00h but I could have got it from dl originally.

I set the stack , pointer and segement to some random number 9000 ...or something I don't think that is interfering.
But when I ret from a function could something be interfering?

I just don't know.
Seems like nothing can be wrong.
But I don't see any place where I forgot to set an segment register values
It seems to get by the jc instruction so I believe it is reading the second sector into memory.
When I look at bochout.txt it has all the segment registers = cs = ds = es = 0 , ss = 9000.
As I set them to be. I don't know of any other way to check it the second sector is load , other then checking the carry.
So I am assuming it is load because I keep doing the read floppy until the carry is not set.

I just can't debug in boche #-o
sebihepp
Member
Member
Posts: 195
Joined: Tue Aug 26, 2008 11:24 am
GitHub: https://github.com/sebihepp

Re: bootloader???

Post by sebihepp »

Hi,

that's why I don't use the ORG directive. The assembler adds to every address your
Offset specified by ORG.

Oh, and you are overwriting some BIOS areas, you know?
Look there: http://wiki.osdev.org/Memory_Map_%28x86%29

Greetings
Sebihepp
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Re: bootloader???

Post by Dex »

First check your not using int 13 instead of int 13h

So when you run the code what do you get ?, does it crash or just not print the message ?.
I would check things like, how are you puting your second stage to the second sector ?, have you checked it with a disk editor ?.
Next try printing one letter dirctly, instead of using a pointer to the message.
Also try clearing screen to a color to see if that code is run.
tantrikwizard
Member
Member
Posts: 153
Joined: Sun Jan 07, 2007 9:40 am
Contact:

Re: bootloader???

Post by tantrikwizard »

Sam111 wrote:...I cann't figure out how to debug very well in boch...
It's best to understand how to use the tools youre trying to work with. Run the code in the debugger, set break points and step through it to find out what is happening.
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: bootloader???

Post by neon »

Code: Select all

int 13                          ; execute the interrupt for reading into memory
ret
13 = 0xd = calls cpu generated #GPF interrupt.

Im surprised it doesn't die here.
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: bootloader???

Post by Troy Martin »

Can you GPF
in real mode? It is a
protection fault, rofl.

Real mode has no
protection features, if I
recall correctly.

Are my haiku posts
annoying? I hope I don't
get banned for this act.
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: bootloader???

Post by neon »

You can #GPF in real mode, yes. The manuals describe it as a #GPF not a "protection fault".
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: bootloader???

Post by Troy Martin »

Hmm, I guess I was
wrong in my description
of a GPF.

This will get very
annoying after a few
hours, I believe.
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
djmauretto
Member
Member
Posts: 116
Joined: Wed Oct 22, 2008 2:21 am
Location: Roma,Italy

Re: bootloader???

Post by djmauretto »

this works fine :wink:

Code: Select all

org 0x7C00
BITS 16


	jmp 0000h:start

start:
	cli
	mov ax , 0x9100 		
	mov ss , ax			; SS = 0x9100
	mov sp , 0x9000 		; SP = 0x9000
	sti
	xor ax , ax
	mov ds , ax     		; DS = 0 
	mov es , ax     		; ES = 0
	mov [Boot_Drive],dl

	mov ax,0003h
	int 10h             		; do the clearing 

	mov ah , 13h			; Write string
	mov al , 01h			; String contains alternating characters and attributes
	mov bh , 0h			; page
	mov bl , 0Fh			; attribute
	mov dh , 1			; row
	mov dl , 0			; column
	mov bp , greetings		; es:bp = segment:offset
	mov cx , 22			; number of characters in string
	int 10h

	mov bp , BOOTLOADER_NAME
	mov cx , 24			; number of characters in string
	mov dh , 2			; row
	mov dl , 0			; column
	int 10h	


	mov ah , 02h                    ; read function
	mov al , [NUMBEROFSECTORS]      ; number  of sectors to read
	mov ch , 0h                     ; cylinder number
	mov cl , [STARTSECTOR]          ; starting sector to begin reading from
	mov dh , 0h                     ; head number
	mov dl , [Boot_Drive]           ; drive 
	mov bx , [LOADADDRESS]          ; es:bx = 0x0000:0x7e00
	int 13h                         ; execute the interrupt for reading into memory
	jc floppy_read_Error

	jmp 0000h:7e00h

floppy_read_Error:

	mov ah , 13h			; Write string
	mov al , 01h			; String contains alternating characters and attributes
	mov bh , 0h			; page
	mov bl , 04h			; attribute
	mov dh , 1			; row
	mov dl , 0			; column
	mov bp , floppy_Error		; es:bp = segment:offset
	mov cx , 16			; number of characters in string
	int 10h
	
infinite_loop:

	jmp infinite_loop

;---------
; data
;---------

Boot_Drive		db ?
greetings	    	db 'Greetings and welcome '
BOOTLOADER_NAME 	db 'Nates BootLoader Stage 1'
floppy_Error		db 'Disk read error!'

STARTSECTOR     	db  2           ; start sector to load
LOADADDRESS     	dw  7e00h       ; where to load the sectors into memory
NUMBEROFSECTORS 	db  1           ; number of sector to load begining at STARTSECTOR
		
			rb 510 -($ - 0x7c00)
Boot_Signature		dw 0aa55H

;----------------
; Sector 2
;----------------
org 0x7E00
; display the string This is sector 2 on the screen

	mov ah , 13h			; Write string
	mov al , 01h			; String contains alternating characters and attributes
	mov bh , 0h			; page
	mov bl , 0Fh			; attribute
	mov dh , 3			; row
	mov dl , 0			; column
	mov bp , hello			; es:bp = segment:offset
	mov cx , 17			; number of characters in string
	int 10h

; loop forever
endsss:
	jmp endsss


hello	db	'This is sector 2!'
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: bootloader???

Post by Troy Martin »

It would probably be better to do a far jump to something like 0x2000:0 for the sake of being able to load 64K of code and not like 32 and a bit KB. And 0x2000 is a nice, round segment number as well, being the 128KB mark.

EDIT: This marks the end of my haiku posting. It was fun but annoying.
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
Post Reply