Page 1 of 1

real mode asm won't link help

Posted: Sun Jul 23, 2006 5:56 pm
by aryan_illusion
hi there..
well this time around just to get a clear picture of whats goin' on i decided to leave the pmode OS for a while and develop a simple real mode console type thingy...

apperntly its not that simple :(

here is the asm file
simker.asm

Code: Select all

BITS 16
global start

start:
	mov	ax, cs		; Get the current segment
	mov	ds, ax		; The data is in this segment
	cli			; disable interrupts while changing stack
	mov	ss, ax		; We'll use this segment for the stack too
	mov	sp, 0xfffe	;  Start the stack at the top of the segment
	sti			; Reenable interrupts
	mov	si, msg		; load address of our message
	call	putstr		; print the message

hang:
	jmp	hang		; just loop forever.

; --------------------------------------------
; data for our program
msg	db	'Hello from the real world!', 0
; ---------------------------------------------
; Print a null-terminated string on the screen
; ---------------------------------------------
putstr:
	lodsb		; AL = [DS:SI]
	or al, al	; Set zero flag if al=0
	jz putstrd	; jump to putstrd if zero flag is set
	mov ah, 0x0e	; video function 0Eh (print char)
	mov bx, 0x0007	; color
	int 0x10
	jmp putstr
putstrd:
retn

i assemble it using:

Code: Select all

nasmw -f aout simker.asm -o simker.o
then i have a C file..which just loops forever...for now

Code: Select all

void main()
{
	for(;;)


return;
};
compile it using...

Code: Select all

gcc -c C1.c -o C1.o

And here comes the linking part!...

Code: Select all

ld -T kernel.ld simker.o C1.o
the linker script...

Code: Select all

OUTPUT_FORMAT("binary")
ENTRY(start)
SECTIONS
{
  .text  0xFF800000 : {
    *(.text)
  }
  .data  : {
    *(.data)
  }
  .bss  :
  { 					
    *(.bss)
  }
}
now everything is works fine but the linking part.. it generates the msg.
simker.o(.text+0xf):simker.o: relocation truncated to fit: 16 .text

okay...i know the problem is with the lines using the stack...and that i'am trying to mix a 16 bit asm with a C file(but really the C file does nothing!)

but this looks a fairly simple code right..i mean this should work!!

what might be causing this?
the same linker script worrks fine when i link pmode asm

can u belive this lousy thing kept me up whole night!
HELP

Posted: Sun Jul 23, 2006 7:05 pm
by Daedalus
I'm not entirely sure, but I'm thinking it has something to do with the .text in your linker script ...
I could be wrong, but shouldnt you be using a 16-bit number there? You're using a 32-bit number, which would be fine in pmode, but real mode is only 16-bit.

I havent done much with linker scripts, so I'm not entirely sure.

Posted: Sun Jul 23, 2006 8:48 pm
by aryan_illusion
Correct!
thnx a bunch man :)

But now it looks like i've got my self into fresh errors,the code doesn't run properly..i mean instead of printing the msg bochs hangs up...or displays an error msg..
is any thing wrong with the asm code?(what?)...
well this is too frustating...grrr
does anybody have that kinda example?..

i think something is wrong with asm compiling....nasmw can assemble 16 bit code right?

and whats the diff. between nasm and nasmw

if i create obj image using nasm...and try to link it ld can't recognize the file format..

any help will do great

Posted: Mon Jul 24, 2006 4:46 am
by Dex
I would use something like this at the start:

Code: Select all

org 0x7C00
BITS 16
;****************************
; Realmode startup code.
;****************************
start:
        xor   ax,ax
        mov   ds,ax
        mov   es,ax
        cli
        mov   ss,ax
        mov   sp,0x7C00
        sti
But i would use fasm, its a much better assembler.

Posted: Mon Jul 24, 2006 9:00 am
by JAAman
and whats the diff. between nasm and nasmw
nothing at all -- they are the same file in newer versions

yes, nasmw will have no problems with 16bit code

another problem to keep in mind, is that GCC cannot make 16bit code (there is an option to compile to 16bit code, but all it does is add prefixes everywhere -- still wont work properly in RMode)