Page 1 of 1

32 bits address interpretation/conflict in protected mode

Posted: Sun Jun 22, 2014 3:54 am
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.

Re: 32 bits address interpretation/conflict in protected mod

Posted: Sun Jun 22, 2014 4:26 am
by Octocontrabass
It sounds like you didn't enable A20. This article should help you.

Re: 32 bits address interpretation/conflict in protected mod

Posted: Sun Jun 22, 2014 6:51 am
by termty
this is because of A20. it works now. thank you a lot Octocontrabass :D