Problem with real mode

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
Pes88
Posts: 11
Joined: Sun Nov 21, 2010 11:49 am

Problem with real mode

Post by Pes88 »

Hello, I'm new of this forum!
I have a problem with a boot program. This must print to the video the string "HELLO WORD", but don't show nothing! I think it's the fault of the addresing of memory because the code is executed correctly.

Code: Select all


.code16		# code 16 bit 

.set SEG_BOOT, 0x07c0
.set INIT_STACK, 0x400

	.text

	movw $SEG_BOOT, %ax	# caricamento di valori noti nei registri 
	movw %ax, %ds		# data selector 
	movw %ax, %es

	cli			#disable interrupt because change the stack 
	movw %ax, %ss
	movw $INIT_STACK, %sp	#  begin stack a 0x07c0:0400, cioe'

	sti

	movw $mess, %si		# address of the first char on the si 
	movb $0x0e, %ah		# print char 
	movb $0, %bh		# number of paging 
nuovo_car:
	lodsb			        # load char to the al
	cmpb $0, %al		# test if  it is the last 
	je fine
	int $0x10		        # print
	jmp nuovo_car

fine:	jmp fine		        # loop

mess : .asciz "Hello word" 

	.org 510
sign:	.byte	0x55		# signature per un settore di avviamento valido
	.byte	0xaa
Thi is the my makefile :

Code: Select all

all: test.fd

test.fd: test.sect
	dd if=/dev/zero bs=512 count=2879 | cat test.sect - > test.fd

test.sect: test.bin
	objcopy -O binary test.bin test.sect

test.bin : test.o 
	ld test.o -m elf_i386  -Tldscript -o test.bin -M  > test.map

test.o: test.s
	as test.s -o test.o -g --32


clean : 
	rm test.fd test.o test.bin test.sect

qemu : 
	qemu -fda test.fd
The script for the linking is :

Code: Select all

SECTIONS
{
	. = 0x07c0;		/* indirizzo di partenza */
	.text :
	{
		_text = . ;
		*(.text)
		*(.rodata)
		. = ALIGN(4096);
	}
	.data :
	{
		_data = . ;
		*(.data)
		. = ALIGN(4096);
	}
	.bss :
	{
		_bss = . ;
		*(.bss)
		. = ALIGN(4096);
		_end = . ;
	}
}
I Have try also only . = 0x07c0, but the result is the same!
thanks..
Sorry for my bad English.. :oops: :oops: :oops: :oops:
Hangin10
Member
Member
Posts: 162
Joined: Wed Feb 27, 2008 12:40 am

Re: Problem with real mode

Post by Hangin10 »

The problem is that you are mixing offsets and segments. The GNU assembler assumes a flat memory model, so you should probably use 0x7c00 as your base address for the linker script and load the data segment registers with zero.

Currently, your code thinks starts at 0x7c0, and then you are also using that as the segment, so when you try to load the string it is being loaded from 0x7c0:0x7e0, which is wrong.
Pes88
Posts: 11
Joined: Sun Nov 21, 2010 11:49 am

Re: Problem with real mode

Post by Pes88 »

thaks!!!
Now everything works!
I have changed the ldscript so :

Code: Select all

SECTIONS
{
	[b]. = 0x0000;	[/b]	
	.text :
	{
		_text = . ;
		*(.text)
		*(.rodata)
		. = ALIGN(4096);
	}
	.data :
	{
		_data = . ;
		*(.data)
		. = ALIGN(4096);
	}
	.bss :
	{
		_bss = . ;
		*(.bss)
		. = ALIGN(4096);
		_end = . ;
	}
}

Post Reply