Code: Select all
syscall
Code: Select all
syscall
Did you try looking in the Intel or AMD manuals? This is one of the instructions that Intel and AMD treat differently, so it might be a good idea to check both. SYSCALL and SYSRET are designed to be used as a pair, but SYSRET always returns to user mode, so it doesn't make very much sense to use SYSCALL in kernel mode.FunnyGuy9796 wrote:I was wondering if this would still be applicable in kernel mode rather than user mode.
Usually you don't want to allow user mode to disable interrupts. Why do you need to do that?FunnyGuy9796 wrote:I am aware that disabling interrupts will still be required for functions in user mode
Code: Select all
liballoc_lock()
Code: Select all
liballoc_unlock
You normally would not implement user mode memory allocation in kernel. It's typically a part of the runtime library of your compiler/linker. You do need some kernel functions to reserve areas for the heap, but the heap itself is not implemented in kernel space.FunnyGuy9796 wrote:I am not yet in user mode. I am writing theandCode: Select all
liballoc_lock()
functions for the liballoc memory allocator.Code: Select all
liballoc_unlock
You need kernel-side memory management as one of the first things. However, that is a very large term. If you want a traditional higher-half kernel, you will need a physical memory manager, a virtual memory manager (possible two of them, one for kernel-side, one for user-side), a page-table handler to marry the two (you will at some point need to map a known physical address to a known virtual address). And then you will need a memory allocator on top of it all, because you rarely want to spend 4kB of memory on objects that are only a few bytes long. You will also need a page-fault handler to be able to lazily synchronize the TLBs and the page tables.FunnyGuy9796 wrote:Oh, ok. I have noticed that most roadmaps that people give examples for have the heap set up after reaching user space. Although, I am wondering, why does the OSDev Wiki roadmap have you setting up memory management before entering user mode?
Locking is a separate issue. You cannot solve locking issues in user space by disabling interrupts. If you need locks because you support multiple threads, you must implement locks in other ways.FunnyGuy9796 wrote:Makes sense. However, when trying to implement liballoc I was reading how to write the lock() function with an example that showed disabling interrupts followed by the ‘syscall’ assembly instruction which led me to believe that it was necessary to be in userspace.
That doesn't make sense. Normally, interrupts are only disabled in kernel mode, and the SYSCALL instruction is only used in user mode. Are you sure you weren't looking at two separate examples?FunnyGuy9796 wrote:an example that showed disabling interrupts followed by the ‘syscall’ assembly instruction
Code: Select all
INITKDBG:00000001402F4470 sub_1402F4470 proc near ; CODE XREF: .text:000000014018D3DDp
INITKDBG:00000001402F4470 ; INITKDBG:00000001402E7923p
INITKDBG:00000001402F4470
INITKDBG:00000001402F4470 var_18 = dword ptr -18h
INITKDBG:00000001402F4470
INITKDBG:00000001402F4470 mov ecx, 0C0000084h
INITKDBG:00000001402F4475 rdmsr
INITKDBG:00000001402F4477 push rdx
INITKDBG:00000001402F4478 push rax
INITKDBG:00000001402F4479 and eax, 0FFFFFEFFh
INITKDBG:00000001402F447E wrmsr
INITKDBG:00000001402F4480 pushfq
INITKDBG:00000001402F4481 or [rsp+18h+var_18], 100h
INITKDBG:00000001402F4488 popfq ; enable rflags.TF so when the next instruction execution completes, #DB will be generated
INITKDBG:00000001402F4489 syscall ; #DB generated after this instruction completes, note we are in kernemode but executing syscall instruction
INITKDBG:00000001402F448B mov r10, rcx ; grab the real address where MSR LSTAR is pointing
INITKDBG:00000001402F448E mov ecx, 0C0000084h
INITKDBG:00000001402F4493 pop rax
INITKDBG:00000001402F4494 pop rdx
INITKDBG:00000001402F4495 wrmsr
INITKDBG:00000001402F4497 mov rax, r10
INITKDBG:00000001402F449A retn
INITKDBG:00000001402F449A sub_1402F4470 endp