String relocation PIO? Data address is execution dependant?

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
termty
Posts: 5
Joined: Sun Jun 22, 2014 3:47 am

String relocation PIO? Data address is execution dependant?

Post by termty »

First forgive me if my english is not perfect(it is not my native language)
If you don't understand something feel free to ask me.

I have again a problem during my OS development.
I have very basic code which switch to protected mode and read the hdd with PIO.
But when i try to execute it inside virtualbox it crashes( "guru meditation").
This is a voluntary crach( due to jmp 0x0) which i used as a perror().

The real problem is this one :
I have a constant string : char *mystring="blabla" inside a C function. let's call this piece of code "truekern code".
I compiled it and made my OS binary.
Once the firsts sectors are loaded, I use PIO to load this "truekern code" and so I'm loading the string into RAM.
then i locate where this string is(I do it findString() function which can be found in kern/kernel.c see below) and, after, I run "truekern code" which check if the address of the string is the address found previously by findString and this is often not the case(but sometimes it is. it seems to be random)

I simplified my code but I implemented a printf function and it seems the address found by my function findString() is not always the same at each execution.
I think my findString() is ok because i have done some others tests to check it so it is maybe a PIO bug ? maybe a virrtualbox emulated PIO?my code is for LBA28. maybe a compatibility error with LBA48?
----------------------------------------------------------------
VM configuration :
RAM : 1122 Mo
VT-x/AMD-V enabled
video memory : 16Mo
--
Host configuration:
NASM version 2.10.09 compiled on Dec 29 2013
gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1)
GNU ld (GNU Binutils for Ubuntu) 2.24
--
how i build it.
I just run Makefile in the root directory.
but each folder doens't depend on others folders.

> in boot/ folder i have a asm code to switch to protected mode and load some hdd sectors into RAM by running 0x10 BIOS interrupt. these sectors contains the code compiled in kern/ folder

> in kern/ folder i'm changing GDT and load other hdd sectors with PIO
these sectors contains the code compiled in the truekern/ folder and is mapped after ther 1Mo limit of real mode.
I also search where a string is located(this string is suppose to be defined in trueker/kernel.c)

> in truekern/
i'm just comparing if the address of the string found previously is the good one. and it seems it is not . actually the location of the string seems to change but i don't know why. it's probably because of PIO but why?

----------------------------------------------------------------
here are the files :

"root" Makefile : http://pastebin.com/HnCp99Cd

kern/gdt.c : http://pastebin.com/xp5WUU34
kern/gdt.h : http://pastebin.com/M3ZBM4F4
kern/io.h : http://pastebin.com/cDGzs05u
kern/kernel.c : http://pastebin.com/AAXuM1gT
kern/Makefile : http://pastebin.com/kkVTPSqk
kern/types.h : http://pastebin.com/XyG2Vcx9

truekern/funcTable.h : http://pastebin.com/50NAWkSk
truekern/kernel.c : http://pastebin.com/G2bT3MEc
truekern/lib.c : http://pastebin.com/EGWDX3xQ
truekern/lib.h : http://pastebin.com/2mspiweC
truekern/Makefile : http://pastebin.com/8evasLt1
truekern/overhead.c : http://pastebin.com/zTjk9u4S
truekern/types.h : http://pastebin.com/Qxm7FsPD

boot/bootsect.asm : http://pastebin.com/jsvCkYSU
boot/GDT.INC : http://pastebin.com/C182G2H9
boot/Makefile : http://pastebin.com/T8NiR4qc
----------------------------------------------------------

the journey begins with bootsect.asm.
bootsect.asm --jmp-> kern/kernel.c --jmp->truekern/kernel.c

the final image is /tmp/floppyA.img
I put this image on virtualbox hdd with `dd` comman (which i can use with a live cd on the vm)

if you want more information please ask me.
any help or suggestion will be helpful
thank you
Octocontrabass
Member
Member
Posts: 5590
Joined: Mon Mar 25, 2013 7:01 pm

Re: string relocation PIO? data address is execution dependa

Post by Octocontrabass »

termty wrote:gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1)
GNU ld (GNU Binutils for Ubuntu) 2.24
You need to use a cross-compiler. I don't know if it will solve your problem, but it will make it easier for us to help you.
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: string relocation PIO? data address is execution dependa

Post by Combuster »

You obviously missed the FAQ and Posting_Checklist. It'd be appreciated if you read these references before you post a question.
"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 ]
termty
Posts: 5
Joined: Sun Jun 22, 2014 3:47 am

Re: string relocation PIO? data address is execution dependa

Post by termty »

Combuster wrote:You obviously missed the FAQ and Posting_Checklist. It'd be appreciated if you read these references before you post a question.
i read the questions which are on the FAQ. "Strings do not work" especially attract my attention but it seems to not match to my problem.
there is "Why do I need a Cross Compiler?" but i was convinced cross compilation is used only for different cpu. this is of course not an valid excuse actually and i realised it's my fault and I deeply regret it. So i'm very sorry about that and i will be more carefully next time.



now i'm going to read http://wiki.osdev.org/GCC_Cross-Compiler and see if it resolve my problem.
thank you a lot Octocontrabass for turning me towards this solution i will try and tell you if it work.
User avatar
sortie
Member
Member
Posts: 931
Joined: Wed Mar 21, 2012 3:01 pm
Libera.chat IRC: sortie

Re: string relocation PIO? data address is execution dependa

Post by sortie »

There are probably many problems. Using a cross-compiler is a start. It might not solve the problem, but it will help. The problem is like that you use flat binaries (instead of ELF) and convert your kernel incorrectly to a flat binary. I think it's best to link to an ELF, and then use objcopy to create a flat binary. However, ELF is much superior and flat binaries are stupid: They don't specify where they should be loaded. I recommend you discard your bootloader, use GRUB instead (you can write your own bootloader when you really need one and have the skill). You should instead follow the Bare Bones tutorial as a base.

The problem is that you are using tools without truly understanding them and you are using them incorrectly. We can be much more helpful and guarantee the instructions work if you follow the community recommendations.
termty
Posts: 5
Joined: Sun Jun 22, 2014 3:47 am

Re: string relocation PIO? data address is execution dependa

Post by termty »

I'm sorry for the delay of my answer it took me some time to read the Bare Bones tutorial.
I have to give the answer of my problem if one have the same "bug" .

I just didn't consider the 400ns delays : http://wiki.osdev.org/ATA_PIO_Mode#400ns_delays
now it works.

Also i have to say it works with cross compiler but it also works WITHOUT a cross compiler. But i'm sure it's because of lucky. Actually I'm sure that it is very bad idea to not use a cross compiler !
sortie wrote:The problem is like that you use flat binaries (instead of ELF) and convert your kernel incorrectly to a flat binary
Well the problem was not here because it work without elf. But i'm wondering why do you told me I convert my kernel incorrectly?
I didn't do any convertion. ok it is flat binary because i want my own bootloader. but why i can't build like i have done?
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re: string relocation PIO? data address is execution dependa

Post by Candy »

Also i have to say it works with cross compiler but it also works WITHOUT a cross compiler
It's about as reliable as fueling your petrol car with alcohol. It's not guaranteed to blow up, but we recommend you not do it.
Post Reply