1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00
This commit is contained in:
Alexander Medvednikov 2019-11-14 07:08:11 +03:00
parent 1d460c4d49
commit 8d4ef822b6
3 changed files with 47 additions and 3 deletions

View File

@ -957,7 +957,7 @@ pub fn new_v(args[]string) &V {
out_name_c = out_name.all_after(os.path_separator) + '_shared_lib.c'
}
$if !linux {
if pref.is_bare {
if pref.is_bare && !out_name.ends_with('.c') {
verror('-bare only works on Linux for now')
}
}

28
vlib/os/bare/bare.S Normal file
View File

@ -0,0 +1,28 @@
.intel_syntax noprefix
.text
.globl _start, syscall5
_start:
xor rbp,rbp
pop rdi
mov rsi,rsp
and rsp,-16
call main
mov rdi,rax /* syscall param 1 = rax (ret value of main) */
mov rax,60 /* SYS_exit */
syscall
ret /* should never be reached, but if the OS somehow fails
to kill us, it will cause a segmentation fault */
syscall5:
mov rax,rdi
mov rdi,rsi
mov rsi,rdx
mov rdx,rcx
mov r10,r8
mov r8,r9
syscall
ret

16
vlib/os/bare/bare.v Normal file
View File

@ -0,0 +1,16 @@
fn syscall5(number, arg1, arg2, arg3, arg4, arg5 voidptr) voidptr
fn write(fd int, data voidptr, nbytes u64) int {
return syscall5(
1, // SYS_write
fd,
data,
nbytes,
0, // ignored
0 // ignored
)
}
fn main() {
C.write(1, "hallo\n", 6)
}