I'm trying to enter usermode for 3 hours. And finally, I did it. But
Code: Select all
00118395332e[CPU0 ] interrupt(): SS selector null
00118395332e[CPU0 ] interrupt(): SS selector null
Code: Select all
; Enter the userspace.
global enter_userspace
enter_userspace:
pop ebx ; 2nd argument (stack)
pop eax ; 1st argument (eip)
push 0x23
push ebx
push 0
push 0x1B
push eax
mov ax, 0x23
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
iret
Let me introduce what's going on (as I suppose). After `iret` the code execution is successfully transferred to
Code: Select all
; Userspace thread (test).
global thread_userspace
thread_userspace:
hlt
Code: Select all
// Setup the TSS.
void setup_tss (void)
{
tss = &_tss; // These variables are defined above.
// Fill in the TSS.
memset ((uint8_t *) tss, 0, sizeof (tss_t));
tss->ss0 = 0x10;
tss->esp0 = 0;
// Put the TSS into the GDT.
set_gdt_entry (5, (uint32_t) tss, sizeof (tss_t) - 1, 0xE9, 0x40);
}
Code: Select all
00053464865i[BIOS ] Booting from 07c0:0000
00118395339e[CPU0 ] interrupt(): SS selector null
00118395339e[CPU0 ] interrupt(): SS selector null
00118395339i[CPU0 ] CPU is in protected mode (active)
00118395339i[CPU0 ] CS.mode = 32 bit
00118395339i[CPU0 ] SS.mode = 32 bit
00118395339i[CPU0 ] EFER = 0x00000000
00118395339i[CPU0 ] | EAX=00100023 EBX=0010087f ECX=00000008 EDX=20001008
00118395339i[CPU0 ] | ESP=0010087f EBP=00106fec ESI=00000000 EDI=00000000
00118395339i[CPU0 ] | IOPL=0 id vip vif ac vm RF nt of df if tf sf zf af pf cf
00118395339i[CPU0 ] | SEG sltr(index|ti|rpl) base limit G D
00118395339i[CPU0 ] | CS:001b( 0003| 0| 3) 00000000 ffffffff 1 1
00118395339i[CPU0 ] | DS:0023( 0004| 0| 3) 00000000 ffffffff 1 1
00118395339i[CPU0 ] | SS:0023( 0004| 0| 3) 00000000 ffffffff 1 1
00118395339i[CPU0 ] | ES:0023( 0004| 0| 3) 00000000 ffffffff 1 1
00118395339i[CPU0 ] | FS:0023( 0004| 0| 3) 00000000 ffffffff 1 1
00118395339i[CPU0 ] | GS:0023( 0004| 0| 3) 00000000 ffffffff 1 1
00118395339i[CPU0 ] | EIP=001007a0 (001007a0)
00118395339i[CPU0 ] | CR0=0xe0000011 CR2=0x001007a0
00118395339i[CPU0 ] | CR3=0x0009b000 CR4=0x00000000
(0).[118395339] [0x0000001007a0] 001b:001007a0 (unk. ctxt): hlt ; f4
00118395339e[CPU0 ] exception(): 3rd (10) exception with no resolution, shutdown status is 00h, resetting
Also, is `hlt` privileged instruction? P.S. I've also tried `jmp $`.