Page 1 of 1

Babystep2 Message Printing problem

Posted: Sat Aug 25, 2012 3:51 am
by phoenixstew
Hey folks,
Just setting up a new project and decided I would put in the Babystep bios printing code. The code so far (practically just the babystep tutorial):

Code: Select all

global boot_first

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Code                                           ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
section .text

boot_first:
	xor ax, ax
	mov ax, 0x07C0
	mov ds, ax

	mov si, msg                 ; This is the line that causes the error to occur
	call bios_print
	jmp hang

bios_print:
	lodsb
	or al,al
	jz bios_print_done
	mov ah, 0x0E
	int 0x10
	jmp bios_print
bios_print_done:
	ret

hang:
	hlt;
	jmp hang;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Data                                           ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
section .data

msg db "Welcome to Coria", 13, 10, 0                                      ; But I think this is the problem
and this is the error

Code: Select all

ld -T "../depend/Kernel_Linker.ld" -m elf_i386 -o "../bin/kernel.bin" boot.o
boot.o: In function `boot_first':
boot/boot.asm:(.text+0x8): relocation truncated to fit: R_386_16 against `.data'
Based on what I know of the error, it is saying that "msg" is 32-bit and I am trying to mov it to a 16-bit location. Problem is, I don't know why this actually is occuring, but a guess is, when I ask it to compile an "elf_i386", I am forcing it to be 32-bits, it is however necessary as I am building on a 64-bit system.

Any help or pointers appreciated.
Phoenix Stew.

Re: Babystep2 Message Printing problem

Posted: Sat Aug 25, 2012 4:58 am
by Combuster
ld -T "../depend/Kernel_Linker.ld" -m elf_i386 -o "../bin/kernel.bin" boot.o
That's not in the tutorial. Learn to read.

Re: Babystep2 Message Printing problem

Posted: Sat Aug 25, 2012 5:42 am
by phoenixstew
Clearly. But it should be quite obvious that using such a command will allow me to expand my kernel into non-asm code, so less pointless digs and more eye-opening revelations and solutions. Thank you.

Re: Babystep2 Message Printing problem

Posted: Sat Aug 25, 2012 6:03 am
by Griwes
You should read more about processor modes, BIOS booting and linkers; that could shed some light on your issue. Before that, you're out of luck, as you don't meet prerequisites for using this site.

Re: Babystep2 Message Printing problem

Posted: Sat Aug 25, 2012 6:14 am
by phoenixstew
Thanks, I guess. I have knowledge of using linkers, somewhat how a system boots and rudimentary assembly, my only problem occurs from the following two points:
- Using 16-bit code
- Linking code from multiple languages

Now, this site offers a plethora of information for my learning experience, aswell as a forum of what I would assume, are people helping one another but based on my reception here, getting and giving help for newcomers is not welcome.

Re: Babystep2 Message Printing problem

Posted: Sat Aug 25, 2012 10:18 am
by Tosi
You are expected to do some research of your own before coming here to ask questions.
If you had looked up protected mode, real mode, or the Intel manuals, you would know that you can't access the BIOS from protected mode, and that 16-bit code will not work when in protected mode as well.
You also show signs of not understanding your toolchain, and just copying and pasting code without knowing what it does.
Try reading the entire Wiki (at least the articles linked from the front page), the intel manuals, and the documentation for your toolchain before coming here to ask questions.

Re: Babystep2 Message Printing problem

Posted: Sat Aug 25, 2012 11:02 am
by Griwes
Tosi wrote:that 16-bit code will not work when in protected mode as well.
That is obviously not true - I guess you've forgotten about 16-bit protected mode...

@OP: "babysteps" are called so because they are meant to be strictly followed; don't try to do anything outside their scope without reading other essential pages on wiki.