Executables misbehaving
Posted: Sat Nov 09, 2024 11:58 am
Hello! Last time i asked for help here, i got a very nice and helpful response. Now i am having a different problem.
So, i have implemented a really simple syscall mechanism, which uses interrupts and has support for arguments and returns.
Trying to execute the syscalls inside the main.c file, from the kernel, results in expected things happening. Stuff prints, pixels are drawn, etc. So:
Trying, however, to use the same syscalls and functions in a program (flat binary) and executing it, yields in unexpected things happening. It prints garbage out, the garbage being dynamic.
Doing an objdump on the binary, i see something peculiar, mainly:
Disassembly of section .data:
What is happening, i'd guess, is that it is triggering the syscall interrupt while not setting the values right, so the syscall tries to print whatever it is in the current RDX.
I, however, am unsure on how to fix it.
The code can be found here:
program being ran and functions definitions for it:
https://github.com/theoriginalgrasshopp ... ernal/apps
the makefile and linker script for generating the binary can be found in this directory:
https://github.com/theoriginalgrasshopp ... R/external
the syscall code can be found in this file:
https://github.com/theoriginalgrasshopp ... c/syscalls
the way of executing, said binary (while temporary), can be found in this file
https://github.com/theoriginalgrasshopp ... e/binary.c
Regards,
qwr
So, i have implemented a really simple syscall mechanism, which uses interrupts and has support for arguments and returns.
Trying to execute the syscalls inside the main.c file, from the kernel, results in expected things happening. Stuff prints, pixels are drawn, etc. So:
Code: Select all
sys_print_func("hello from a syscall"); // <--- this works
sys_draw_pixel_func(0, 0, red); // <--- this also works
Doing an objdump on the binary, i see something peculiar, mainly:
Disassembly of section .data:
Code: Select all
0000000000000000 <.data>:
0: 31 c0 xor %eax,%eax
2: 48 89 fa mov %rdi,%rdx
5: cd 10 int $0x10
7: c3 ret
I, however, am unsure on how to fix it.
The code can be found here:
program being ran and functions definitions for it:
https://github.com/theoriginalgrasshopp ... ernal/apps
the makefile and linker script for generating the binary can be found in this directory:
https://github.com/theoriginalgrasshopp ... R/external
the syscall code can be found in this file:
https://github.com/theoriginalgrasshopp ... c/syscalls
the way of executing, said binary (while temporary), can be found in this file
https://github.com/theoriginalgrasshopp ... e/binary.c
Regards,
qwr