implement generic syscalls
This commit is contained in:
parent
11548e74ba
commit
a73ea804b5
6 changed files with 106 additions and 1 deletions
|
@ -1,7 +1,7 @@
|
|||
# See the end of this file for copyright and license terms.
|
||||
|
||||
cmake_minimum_required(VERSION 3.0.0)
|
||||
project(neo VERSION 0.1.0 LANGUAGES C)
|
||||
project(neo VERSION 0.1.0 LANGUAGES C ASM)
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
|
||||
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
/** See the end of this file for copyright and license terms. */
|
||||
|
||||
#include "neo.h"
|
||||
#include "neo/_unistd.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
_neo_sys_write(1, "hello, world\n", 14);
|
||||
return 69;
|
||||
}
|
||||
|
||||
|
|
24
include/neo/_unistd.h
Normal file
24
include/neo/_unistd.h
Normal file
|
@ -0,0 +1,24 @@
|
|||
/** See the end of this file for copyright and license terms. */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "neo.h"
|
||||
|
||||
long _neo_syscall(long number, ...);
|
||||
|
||||
isize _neo_sys_write(int fd, const void *buf, usize count);
|
||||
__attribute__((__noreturn__))
|
||||
void _neo_sys_exit(int status);
|
||||
|
||||
/*
|
||||
* This file is part of libneo.
|
||||
* Copyright (c) 2021 Fefie <owo@fef.moe>.
|
||||
*
|
||||
* libneo is non-violent software: you may only use, redistribute,
|
||||
* and/or modify it under the terms of the CNPLv6+ as found in
|
||||
* the LICENSE file in the source code root directory or at
|
||||
* <https://git.pixie.town/thufie/CNPL>.
|
||||
*
|
||||
* libneo comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPLv6+ for details.
|
||||
*/
|
3
src/arch/x86_64/CMakeLists.txt
Normal file
3
src/arch/x86_64/CMakeLists.txt
Normal file
|
@ -0,0 +1,3 @@
|
|||
target_sources(neo PRIVATE
|
||||
arch/${TARGET_ARCH}/syscall_${TARGET_OS}.S
|
||||
)
|
46
src/arch/x86_64/syscall_linux.S
Normal file
46
src/arch/x86_64/syscall_linux.S
Normal file
|
@ -0,0 +1,46 @@
|
|||
/** See the end of this file for copyright and license terms. */
|
||||
|
||||
.global _neo_syscall
|
||||
|
||||
/*
|
||||
* long _neo_syscall(long number, ...);
|
||||
*
|
||||
* We just want to get stuff working for now, therefore we don't care
|
||||
* about efficiency and just always copy all 6 arguments to the
|
||||
* respective registers and hope Linux just ignores them lmao
|
||||
*
|
||||
* SysV ABI -> Linux syscall
|
||||
* -----------------------------
|
||||
* 1. %rdi -> %rax (number)
|
||||
* 2. %rsi -> %rdi (arg1)
|
||||
* 3. %rdx -> %rsi (arg2)
|
||||
* 4. %rcx -> %rdx (arg3)
|
||||
* 5. %r8 -> %r10 (arg4)
|
||||
* 6. %r9 -> %r8 (arg5)
|
||||
* 7. stack -> %r9 (arg6)
|
||||
*/
|
||||
_neo_syscall:
|
||||
mov %rdi, %rax
|
||||
mov %rsi, %rdi
|
||||
mov %rdx, %rsi
|
||||
mov %rcx, %rdx
|
||||
mov %r8, %r10
|
||||
mov %r9, %r8
|
||||
mov (%rsp), %r9
|
||||
syscall
|
||||
ret /* result is already in %rax */
|
||||
.size _neo_syscall,.-_neo_syscall
|
||||
.type _neo_syscall,function
|
||||
|
||||
/*
|
||||
* This file is part of libneo.
|
||||
* Copyright (c) 2021 Fefie <owo@fef.moe>.
|
||||
*
|
||||
* libneo is non-violent software: you may only use, redistribute,
|
||||
* and/or modify it under the terms of the CNPLv6+ as found in
|
||||
* the LICENSE file in the source code root directory or at
|
||||
* <https://git.pixie.town/thufie/CNPL>.
|
||||
*
|
||||
* libneo comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPLv6+ for details.
|
||||
*/
|
30
src/unistd.c
Normal file
30
src/unistd.c
Normal file
|
@ -0,0 +1,30 @@
|
|||
/** See the end of this file for copyright and license terms. */
|
||||
|
||||
#include "neo.h"
|
||||
#include "neo/_unistd.h"
|
||||
|
||||
/* TODO: get rid of hardcoded syscall numbers */
|
||||
|
||||
isize _neo_sys_write(int fd, const void *buf, usize len)
|
||||
{
|
||||
return _neo_syscall(1, fd, buf, len);
|
||||
}
|
||||
|
||||
void _neo_sys_exit(int status)
|
||||
{
|
||||
_neo_syscall(60, status);
|
||||
while (1); /* should not be reached */
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of libneo.
|
||||
* Copyright (c) 2021 Fefie <owo@fef.moe>.
|
||||
*
|
||||
* libneo is non-violent software: you may only use, redistribute,
|
||||
* and/or modify it under the terms of the CNPLv6+ as found in
|
||||
* the LICENSE file in the source code root directory or at
|
||||
* <https://git.pixie.town/thufie/CNPL>.
|
||||
*
|
||||
* libneo comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPLv6+ for details.
|
||||
*/
|
Loading…
Reference in a new issue