Why does user function is not printing system call message?

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
User avatar
gamingjam60
Member
Member
Posts: 52
Joined: Sat Aug 24, 2024 10:06 pm
Libera.chat IRC: gamingjam60
Location: India
GitHub: https://github.com/baponkar
Contact:

Why does user function is not printing system call message?

Post 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
Octocontrabass
Member
Member
Posts: 5873
Joined: Mon Mar 25, 2013 7:01 pm

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

Post by Octocontrabass »

What do you see when you step through it in a debugger?
Post Reply