Page 1 of 1

Why does user function is not printing system call message?

Posted: Tue Jun 17, 2025 10:00 am
by gamingjam60
I am loading a elf file by Limine at Lower half Memory address(0x401000) and initialize MSR based System call (It is working when I am calling it from Kernel mode)as well as interrupt based System Call(But I do not know why t is not working now). I checked the user program can raise other exception like division by zero etc. But Below code I have included syscall instruction nothing is printing.

Code: Select all

[BITS 64]
global _start

section .text
_start:
    ; syscall(SYSCALL_PRINT, (uint64_t)msg, 0)
    mov     rax, 1                  ; SYSCALL_PRINT = 1
    lea     rdi, [rel msg]          ; First argument: pointer to message
    xor     rsi, rsi                ; Second argument (not used)
    syscall                         ; Perform syscall

    ; syscall(SYSCALL_EXIT, 0, 0)
    mov     rax, 3                  ; SYSCALL_EXIT = 3
    xor     rdi, rdi                ; First argument: exit code 0
    xor     rsi, rsi                ; Second argument (unused)
    syscall                         ; Exit syscall

.hang:
    jmp     .hang                   ; If syscall fails, loop forever

section .data
msg: db "Hello from user via syscall!", 0
Why do I not receiving "Hello from user via syscall!" ?

Output:

Code: Select all

Test Address: 0xFFFF800000401000, Value: 0
Page: present=1, rw=1, user=1, frame=0x100C10000, nx=0
Test Address: 0xFFFF800000401000, Value: 12345
Page: present=1, rw=1, user=1, frame=0x100C10000, nx=0
Test Address: 0x401000, Value: 12345
Page: present=1, rw=1, user=1, frame=0x100C10000, nx=0
Test Address: 0x401000, Value: 12345
Page: present=1, rw=1, user=1, frame=0x100C10000, nx=0
Module Path : /boot/user_program.elf
Module Address : 0xFFFF80017FFFE000
Module Size : 5 KB
Module Media Type : 1
Module Partition Index : 0
Module MBR Disk ID : 1069677400
user_program.elf base addr 0xFFFF80017FFFE000
Switching into usermode: user_entry_addr-0x401000, user_stack_addr-0x1000
V. addr: 0x401000, Page: present=1, rw=1, user=1, frame=0x100C10000
Thankyou.


syscal_manager.c



syscal_entry.asm



load_and_parse_elf.c



switch_user.asm

Re: Why does user function is not printing system call message?

Posted: Tue Jun 17, 2025 12:21 pm
by Octocontrabass
What do you see when you step through it in a debugger?