OSDev.org
https://forum.osdev.org/

virtual mode...
https://forum.osdev.org/viewtopic.php?f=1&t=14084
Page 3 of 5

Author:  pcmattman [ Sun Jun 03, 2007 4:35 pm ]
Post subject: 

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).

Author:  xyjamepa [ Sun Jun 03, 2007 4:56 pm ]
Post subject: 

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.

Author:  frank [ Sun Jun 03, 2007 5:52 pm ]
Post subject: 

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.

Author:  xyjamepa [ Mon Jun 04, 2007 3:53 am ]
Post subject: 

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.

Author:  Combuster [ Mon Jun 04, 2007 11:52 am ]
Post subject: 

What instruction is causing that stack fault?

Author:  xyjamepa [ Mon Jun 04, 2007 12:54 pm ]
Post subject: 

Hi...

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

Author:  Combuster [ Mon Jun 04, 2007 1:00 pm ]
Post subject: 

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.

Author:  pcmattman [ Mon Jun 04, 2007 4:04 pm ]
Post subject: 

abuashraf wrote:
Hi...

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

Author:  xyjamepa [ Mon Jun 04, 2007 5:26 pm ]
Post subject: 

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:
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:
File comment: IMG
a.tar.gz [47.5 KiB]
Downloaded 55 times

Author:  pcmattman [ Mon Jun 04, 2007 5:30 pm ]
Post subject: 

The TSS esp field should be under 1 MB mark as well, and aligned to a 4k boundary.

Author:  B.E [ Tue Jun 05, 2007 1:16 am ]
Post subject: 

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.

Author:  xyjamepa [ Tue Jun 05, 2007 2:24 am ]
Post subject: 

Hi...

Code:
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[i].esp(dword *)0x2000 and it still 0x10789e0
also eip tss[1].eip=(dword *)0x1000 and it still 0x100fc2,this two fields
never changed.

Thanx.

Author:  jnc100 [ Tue Jun 05, 2007 2:55 am ]
Post subject: 

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.

Author:  xyjamepa [ Tue Jun 05, 2007 9:01 am ]
Post subject: 

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

Author:  Combuster [ Tue Jun 05, 2007 9:20 am ]
Post subject: 

Once again,
Quote:
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.

Page 3 of 5 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/