virtual 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.
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

Better idea: set the virtual mode CS to 0, others to some other value (I used 0x20, as that's my 16-bit data segment in the GDT).
User avatar
xyjamepa
Member
Member
Posts: 397
Joined: Fri Sep 29, 2006 8:59 am

Post by xyjamepa »

Hi...

I changed the cs to 0 and all other registers are 0x10 as my data
segment descripotr,but unfortunately I got GPF ,so now
my kernel is 1MB marked,cs=0, all other registers are 0x10.
Also when I set tss[1].eip=0x1000 I get stack fault exception
I think I've tried to fix every possible bug but nothing worked
I'm frustrated but I'll keep going untill I do it.

Thanx.
frank
Member
Member
Posts: 729
Joined: Sat Dec 30, 2006 2:31 pm
Location: East Coast, USA

Post by frank »

The value for ss0 and esp0 must be valid protected mode values. They will be the values that are used when the processor handles an interrupt and switches to PL0. Try this set eip to 0x1000 and set esp to a value less than 1mb. Also fix the values in ss0 and esp0 to proper protected mode ones. Then see what happens.
User avatar
xyjamepa
Member
Member
Posts: 397
Joined: Fri Sep 29, 2006 8:59 am

Post by xyjamepa »

Hi...

I changed eip to 0x1000 esp to 0x8000 also ss0 is 0x10
esp0(dword)&PL0_stack, cs is 0 and I got stack fault exception.
Every time I set esp0 to 0x1000 I get stack fault exception
what ever the other values are..

I'm afraid we are missing something so here's the whole picture:
our multitasking consistes of two tasks:main() PL0 and the virtual task()
which is PL0 too.the virtual task is 1MB marked ,cs,ds fs,gs,ss and es are
all zero ,eip =0x1000 ,ss0=0x10,esp0=(dword)&pl0_stack,EFLAGS = 0x23202L
paging is not enabled and I'm usign long call to switch to the selector
of the virtual task.
With all this values I'm getting stack fault exception,but when I change
eip to tss[1].eip=(dword)&task I get general protection fault.

Thanx.
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:

Post by Combuster »

What instruction is causing that stack fault?
"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 ]
User avatar
xyjamepa
Member
Member
Posts: 397
Joined: Fri Sep 29, 2006 8:59 am

Post by xyjamepa »

Hi...
What instruction is causing that stack fault?
when I point my virtual task to 0x1000
like this :
tss[1].eip=(void *)0x1000
or this:
tss[1].eip=0x1000

Thanx.
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:

Post by Combuster »

That wasn't what I asked. Verbosely: What compiled assembly instruction is executed at what adress with what values in the registers when the processor signals said stack fault.

It can't be tss[1].eip = 0x1000, as no exception is thrown when THAT statement is executed.
"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 ]
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

abuashraf wrote:Hi...
What instruction is causing that stack fault?
when I point my virtual task to 0x1000
like this :
tss[1].eip=(void *)0x1000
or this:
tss[1].eip=0x1000

Thanx.
For your faults, you should dump the CPU state before the exception (all the general purpose registers, segment descriptors and CR0-CR3).

For the purposes of debugging your OS, I'd also suggest you print the opcode at the CS:EIP of the exception.
User avatar
xyjamepa
Member
Member
Posts: 397
Joined: Fri Sep 29, 2006 8:59 am

Post by xyjamepa »

Hi...

I'm usign QEMU and its mointor but unfortunaely it dosen't have break points
to stop the executing befor the exception the only thing the monitor
could help me by dump cpu register after the exception and take a look
into them.but all that after the exception,I'll get Bochs with debugger
as soon as I can ...
Here's an IMG file,would you please guys debuge it with bochs debugger
and see what's wrong with it,I'm so grateful for your help.
The values with this IMG are:

Code: Select all

for(i;i<max_tasks;i++)
  {
   tss[i].trace=0;
   tss[i].io_map_addr=sizeof(TSS);
   tss[i].ldtr=0;
   if (i) {
   tss[i].fs=tss[i].gs=0;
   tss[i].ds=tss[i].es=tss[i].ss=0x0;
   tss[i].cs=0x0;
   tss[i].eflags=0x23202L;		//0x23202L VM=1 ,IOPL=3, interrupts are enabled
   tss[i].esp=(dword)&task_stack[i];	//points to task() stack top
   tss[i].ss0=0x10;
   tss[i].esp0=(dword)&pl0_stack[i];	//stack for kernel
   }
  }
 memcpy( (void*) 0x1000, &task, 1024 ); 
 tss[1].eip=&task;
 ltr(0x28);
This IMG will give you general protection fault.

Thanx.
Attachments
a.tar.gz
IMG
(47.5 KiB) Downloaded 114 times
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

The TSS esp field should be under 1 MB mark as well, and aligned to a 4k boundary.
User avatar
B.E
Member
Member
Posts: 275
Joined: Sat Oct 21, 2006 5:29 pm
Location: Brisbane Australia
Contact:

Post by B.E »

Firstly read the F**king manual, it tells you what you need to set it up and how to set it up. As I could not be bothered looking up it my self(need to download it again as I it didn't name it correctly when I downloaded it and it's in a folder with names like 123456.pdf, 123465.pdf). If I remember correctly to get into v8086. You have to create a code segment and set the 16bit code flag and also set the base of the descriptor to the base address of the. the segemnt selectors should then be set the processos segements.
Image
Microsoft: "let everyone run after us. We'll just INNOV~1"
User avatar
xyjamepa
Member
Member
Posts: 397
Joined: Fri Sep 29, 2006 8:59 am

Post by xyjamepa »

Hi...

Code: Select all

memcpy((void *)0x2000,&task_stak,2048);
tss[1].esp=(dword)0x2000;
Doesn't this mean its 1MB mark and aligned to a 4K boundry?
but I got general protection fault.
And about the Intel manual I've read it for about ten times,

Also I saw that eip and esp don't change whatever I'm doing with them
I pointed esp to become tss.esp(dword *)0x2000 and it still 0x10789e0
also eip tss[1].eip=(dword *)0x1000 and it still 0x100fc2,this two fields
never changed.

Thanx.
jnc100
Member
Member
Posts: 776
Joined: Mon Apr 09, 2007 12:10 pm
Location: London, UK
Contact:

Post by jnc100 »

abuashraf wrote:I'll get Bochs with debugger
as soon as I can ...
As I said before, if you download the win32 installers from the bochs site (which you've said you did) then you get both bochs.exe and bochsdbg.exe in the bochs directory. If you run bochsdbg, you'll find that it is a bochs with debugging enabled.

John.
User avatar
xyjamepa
Member
Member
Posts: 397
Joined: Fri Sep 29, 2006 8:59 am

Post by xyjamepa »

i...
Okay now I'm using Bochsdbg.exe and I've been debugging my kernel
for more than two houres.
This values have never been changed what ever I do with code

EFLAGS=0x3002 eip=0x100fc2 esp=0x107830,cs=0x8
fs,gs,ds,ss are all 0x10

Also here's my init_task would you please take a look at it:

Code: Select all

void init_task()
{
 disable();
 memcpy( (void *) 0x2000,(dword)&task_stack, 2048 );
 unsigned int i=0;
 for(i;i<max_tasks;i++)
  {
   tss[i].trace=0;
   tss[i].io_map_addr=sizeof(TSS);
   tss[i].ldtr=0;
   tss[i].fs=tss[i].gs=0;
   tss[i].ds=tss[i].es=tss[i].ss=0x0;
   tss[i].cs=0x0;
   tss[i].eflags=0x23202L;		//0x23202L VM=1 ,IOPL=3
   tss[i].esp=(dword *)0x2000;		
   tss[i].ss0=0x10;
   tss[i].esp0=(dword)&pl0_stack[i];	//stack for kernel
  }
 memcpy( (void*) 0x1000, (dword)&task, 1024 ); 
 //tss[1].eip=&task;
 tss[1].eip=(dword *)0x1000;
 ltr(0x28);
 enable();
}
what's wrong with my code.... :?: :?: :?: :?:

Thanx.
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:

Post by Combuster »

Once again,
For your faults, you should dump the CPU state before the exception (all the general purpose registers, segment descriptors and CR0-CR3).

For the purposes of debugging your OS, I'd also suggest you print the opcode at the CS:EIP of the exception.
Until we got that information we can at best only guess what is going on.
"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 ]
Post Reply