Babystep2 Message Printing problem

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.
Locked
phoenixstew
Posts: 3
Joined: Sat Aug 25, 2012 3:41 am

Babystep2 Message Printing problem

Post 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.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Babystep2 Message Printing problem

Post 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.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
phoenixstew
Posts: 3
Joined: Sat Aug 25, 2012 3:41 am

Re: Babystep2 Message Printing problem

Post 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.
User avatar
Griwes
Member
Member
Posts: 374
Joined: Sat Jul 30, 2011 10:07 am
Libera.chat IRC: Griwes
Location: Wrocław/Racibórz, Poland
Contact:

Re: Babystep2 Message Printing problem

Post 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.
Reaver Project :: Repository :: Ohloh project page
<klange> This is a horror story about what happens when you need a hammer and all you have is the skulls of the damned.
<drake1> as long as the lock is read and modified by atomic operations
phoenixstew
Posts: 3
Joined: Sat Aug 25, 2012 3:41 am

Re: Babystep2 Message Printing problem

Post 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.
Tosi
Member
Member
Posts: 255
Joined: Tue Jun 15, 2010 9:27 am
Location: Flyover State, United States
Contact:

Re: Babystep2 Message Printing problem

Post 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.
User avatar
Griwes
Member
Member
Posts: 374
Joined: Sat Jul 30, 2011 10:07 am
Libera.chat IRC: Griwes
Location: Wrocław/Racibórz, Poland
Contact:

Re: Babystep2 Message Printing problem

Post 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.
Reaver Project :: Repository :: Ohloh project page
<klange> This is a horror story about what happens when you need a hammer and all you have is the skulls of the damned.
<drake1> as long as the lock is read and modified by atomic operations
Locked