32 bits address interpretation/conflict in protected 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
termty
Posts: 5
Joined: Sun Jun 22, 2014 3:47 am

32 bits address interpretation/conflict in protected mode

Post by termty »

First of all please forgive me if my english is not perfect. this is not my native language so feel free to ask me is you don't understand something.
Because this is the first time i post on this forum i also hope my message is in a good place.
if I'm doing anything wrong I will follow your recommendations very carefully.

My problem is about kernel programming and more precisely I have some difficulties to switch to protected mode on Intel CPU.
I created GDT structure and I'm just using segmentation (not pagination) then i switched to protected mode.
It seems to work fine except the CPU seems work like my addresses are not 32 bits addresses : let's take an example (in kernel.c see below):

Code: Select all

char *b=(char *)0x00000400; //1024*1;
char *c=(char *)0x00100400; //1024*(1024+1);
//char *c=(char*)0x01000400; // no problems with that
//char *c=(char*)0x00100401; // no problems with that
*b=1;
*c=2;

*c = 2 write to addresse b...so at the end *b == 2 is true.
Do you know how to solve it?

I'm doing my tests on virtual box with 1254 Mo of virtual RAM and 100,00 Mio hdd.
Of course I haven't `printf` function so i can't debug with it by doing `if(something bad)printf("error");` but i use the fact that `jmp 0x0` will crash virtual box : this replace printf("error\n");

the files I'm using : the two first files were originally found at http://a.michelizza.free.fr

Code: Select all

*c = 2
write to addresse b...so at the end

Code: Select all

 *b == 2
is true.
Do you know how to solve it?

I'm doing my tests on virtual box with 1254 Mo of virtual RAM and 100,00 Mio hdd.
Of course I haven't `printf` function so i can't debug with it by doing `if(something bad)printf("error");` but i use the fact that `jmp 0x0` will crash virtual box : this replace printf("error\n");

the files I'm using :
bootsect.asm : where the trip begin(mbr sector) : http://pastebin.com/TM1hzXAW
GDT.inc : include for bootsect.asm : http://pastebin.com/Xt95LErb
kernel.c : where the bug is at : http://pastebin.com/iP3kALqH

the two first files were originally found at http://a.michelizza.free.fr

the commands i'm using:

`
nasm -f bin -o bootsect bootsect.asm
gcc -c kernel.c
ld --oformat binary -Ttext 1000 kernel.o -o kernel
cat bootsect kernel /dev/zero | dd of=hdd bs=512 count=2
`

my configuration (host):
gcc version 4.8.2
Ubuntu 4.8.2-19ubuntu1
GNU ld (GNU Binutils for Ubuntu) 2.24
if you want something else please ask

Any help or suggestions is welcome even if it doesn't solve my problem.
Maybe something bad is happening during the link step?
thank you.
Octocontrabass
Member
Member
Posts: 5604
Joined: Mon Mar 25, 2013 7:01 pm

Re: 32 bits address interpretation/conflict in protected mod

Post by Octocontrabass »

It sounds like you didn't enable A20. This article should help you.
termty
Posts: 5
Joined: Sun Jun 22, 2014 3:47 am

Re: 32 bits address interpretation/conflict in protected mod

Post by termty »

this is because of A20. it works now. thank you a lot Octocontrabass :D
Post Reply