How I can swith into CPL=3 ?

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
Russian OS coder

How I can swith into CPL=3 ?

Post by Russian OS coder »

Code: Select all

tss->back_link=0x20;
  tss->ESP0=0x3000;
  tss->SS0=0x10;
  tss->ESP1=0;
  tss->SS1=0x0;
  tss->ESP2=0;
  tss->SS2=0x0;
  tss->CR3=0;
  tss->EIP=&qq;
  tss->EFLAGS=0x3202;
??????      ???
  tss->EAX=0;
  tss->ECX=0;
  tss->EDX=0;
  tss->EBX=0;
  tss->ESP=0x2000;
  tss->EBP=0;
  tss->ESI=0;
  tss->EDI=0;
  tss->ES=0x33;
  tss->CS=0x2b;
  tss->SS=0x33;
  tss->DS=0x33;
  tss->FS=0x0;
  tss->GS=0x0;
  tss->LDT=0;
  tss->offset_andT=0;
  tss->IOPB=0xFFFFFFFF;
  tss->CR3=page_directory2;




tss2->back_link=0x20;
  tss2->ESP0=0x5000;
  tss2->SS0=0x10;
  tss2->ESP1=0;
  tss2->SS1=0x0;
  tss2->ESP2=0;
  tss2->SS2=0x0;
  tss2->CR3=0;
  tss2->EIP=&qq2;
  tss2->EFLAGS=0x3202;???
  tss2->EAX=0;
  tss2->ECX=0;
  tss2->EDX=0;
  tss2->EBX=0;
  tss2->ESP=0x4000;
  tss2->EBP=0;
  tss2->ESI=0;
  tss2->EDI=0;
  tss2->ES=0x33;
  tss2->CS=0x2b;
  tss2->SS=0x33;
  tss2->DS=0x33;
  tss2->FS=0x0;
  tss2->GS=0x0;
  tss2->LDT=0;
  tss2->offset_andT=0;
  tss2->IOPB=0x3;
  tss2->CR3=page_directory2;
I initialised Tss ,

Code: Select all

  gdt[0]=0;     // not used
  gdt[1]=0;
  gdt[2]=0x00000025;    // code
  gdt[3]=0x00CF9A00;    
  gdt[4]=0x00000025;    // data
  gdt[5]=0x00CF9200;
gdt[6]=((TSS_KERNEL_MAIN<<16)&0xFFFF0000)|((sizeof(struct TSS))&0x0000FFFF);
  gdt[7]=(TSS_KERNEL_MAIN&0xFF000000)|0x8900|((TSS_KERNEL_MAIN>>16)&0x000000FF);
        // TSS kernel
  gdt[8]=((TSS_APP<<16)&0xFFFF0000)|((sizeof(struct TSS))&0x0000FFFF);
  gdt[9]=(TSS_APP&0xFF000000)|0xE900|((TSS_APP>>16)&0x000000FF);
//u
  gdt[10]=((mem_size)/4096/0x10);    // code 28
  gdt[11]=0x00CFFA00;    
  gdt[12]=((mem_size)/4096/0x10);    // data 30
  gdt[13]=0x00CFF200;
  gdt[14]=((TSS_APP2<<16)&0xFFFF0000)|((sizeof(struct TSS))&0x0000FFFF);
  gdt[15]=(TSS_APP2&0xFF000000)|0xE900|((TSS_APP2>>16)&0x000000FF);

        // TSS app
  g_gdtr[0]=(GDT_MAIN<<16)|0xFFFF;
  g_gdtr[1]=(GDT_MAIN>>16)&0xFFFF;
  gdt_flush();
  asm("lgdt g_gdtr");
Gdt,So process with tss2 and tss runs in CPL=0, but I want CPL=3
What am I doing wrong ?

P.S.
Sorry for my English
[edit] use the [ code ] - tags [/edit]
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:How I can swith into CPL=3 ?

Post by Pype.Clicker »

- if you want your TSS2 running CPL3 code, make sure you give it a CPL3 code segment
- honnestly, you should try to find a way to have easier to understand way to write your code. Both your TSS declarations and GDT entries are a real pain to read (and thus also a real pain to debug)
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:How I can swith into CPL=3 ?

Post by Candy »

You can try to replace the GDT code with something like:

Code: Select all

char gdt[16] = { 0x01, 0x02, 0x03, 0xFA, 0xDE, 0xEF, 0xFE, 0xC7 };
for clearer overview with large numeric arrays. I can't say the TSS is unclear.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:How I can swith into CPL=3 ?

Post by Pype.Clicker »

something like

Code: Select all

*tss= {
 .back_link=0x20, 
 .ESP0=0x3000,.tss->SS0=0x10,
 .EIP=&qq,
 .EFLAGS=0x3202,
 .ESP=0x2000,
 .ES=0x33, .CS=0x2b, .SS=0x33, .DS=0x33,
 .IOPB=0xFFFFFFFF,
 .CR3=page_directory2;
};


*tss2={
 .back_link=0x20,
 .ESP0=0x5000,.SS0=0x10,
 .EIP=&qq2, .EFLAGS=0x3202,
 .ESP=0x4000,
 .ES=0x33, .CS=0x2b, .SS=0x33, .DS=0x33,
 .IOPB=0x3;
 .CR3=page_directory2
};
would have been preferred by my eyes ...
Post Reply