ISSUES WITH ENTERING RING3

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
osdoom
Posts: 1
Joined: Thu Aug 17, 2023 1:04 am
Freenode IRC: osdoom

ISSUES WITH ENTERING RING3

Post by osdoom »

Hello,
I am in the process of writing a small os in x86_32. I am currently trying to enter user mode. I'm using https://wiki.osdev.org/Getting_to_Ring_ ... ing_Ring_3 as a reference and this is my current assembly code:

Code: Select all

global enter_user_mode

USER_MODE_CODE_SEGMENT equ (0x18 | 0x3)
USER_MODE_DATA_SEGMENT equ (0x20| 0x3)

enter_user_mode:
    cli                                                ; disable interrupts
    mov eax, esp
    push USER_MODE_DATA_SEGMENT
    push eax
    pushf
    push USER_MODE_CODE_SEGMENT
    mov eax, user_entry
    push eax

    mov     eax, USER_MODE_DATA_SEGMENT
    mov     ds, eax
    mov     gs, eax
    mov     es, eax
    mov     fs, eax

    iret

user_entry:
    mov eax, 0xc00b8000 ;framebuffer address
    mov byte [eax], 'U'
    mov eax, 0xc00b8001
    mov byte [eax], 0xE
However, my bochs emulator spits out the following and stops running:

Code: Select all

(0).[310881190] [0x0000000000102710] 001b:00000000c0102710 (unk. ctxt): mov eax, 0xc00b8000       ; b800800bc0
Next at t=310881191
(0) [0x00000000fffffff0] f000:fff0 (unk. ctxt): jmp far f000:e05b         ; ea5be000f0
Moreover, I have noticed that it stops running on the first line of the label "user_entry", regardless of what it may be. Also, I disabled the interrupts in the beginning in hopes of not having to deal with a tss (yet). Just trying to get a simple user program to run first.

I have been super stuck on this for a while and would appreciate any help/leads regarding this.

I'm relatively new to this and still learning, so I would greatly appreciate your patience with any gaps in my understanding.
Thanks!


UPDATE:
There was quite a bit of delay between me posting this and it getting approved (probably because this was my first post here) but this issue has been resolved. For anyone curious, I had not set the U/S flag bit on my pdt.
Last edited by osdoom on Wed Aug 23, 2023 8:23 pm, edited 1 time in total.
Post Reply