mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
os_linux.v
This commit is contained in:
@ -26,3 +26,14 @@
|
||||
syscall
|
||||
ret
|
||||
|
||||
syscall6:
|
||||
mov rax,rdi
|
||||
mov rdi,rsi
|
||||
mov rsi,rdx
|
||||
mov rdx,rcx
|
||||
mov r10,r8
|
||||
mov r8,r9
|
||||
mov r9, [rsp+8]
|
||||
syscall
|
||||
ret
|
||||
|
||||
|
@ -1,4 +0,0 @@
|
||||
fn main() {
|
||||
write(1, c'Hello!\n', 7)
|
||||
println('println test\n')
|
||||
}
|
17
vlib/os/bare/bare_example_linux.v
Normal file
17
vlib/os/bare/bare_example_linux.v
Normal file
@ -0,0 +1,17 @@
|
||||
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() {
|
||||
write(1, c'hallo\n', 6)
|
||||
}
|
||||
|
48
vlib/os/os_linux.v
Normal file
48
vlib/os/os_linux.v
Normal file
@ -0,0 +1,48 @@
|
||||
// Copyright (c) 2019 Alexander Medvednikov. All rights reserved.
|
||||
// Use of this source code is governed by an MIT license
|
||||
// that can be found in the LICENSE file.
|
||||
|
||||
module os
|
||||
|
||||
const (
|
||||
PROT_READ = 1
|
||||
PROT_WRITE = 2
|
||||
|
||||
MAP_PRIVATE = 0x02
|
||||
MAP_ANONYMOUS = 0x20
|
||||
)
|
||||
|
||||
|
||||
/*
|
||||
// TODO no pub => error
|
||||
pub fn write(fd int, data voidptr, nbytes int) int {
|
||||
return syscall5(
|
||||
1, // SYS_write
|
||||
fd,
|
||||
data,
|
||||
nbytes,
|
||||
0, // ignored
|
||||
0 // ignored
|
||||
)
|
||||
}
|
||||
|
||||
pub fn println(s string) {
|
||||
write(1, (s + '\n').str, s.len)
|
||||
}
|
||||
|
||||
fn mmap(start voidptr, len, prot, flags, fd, off int) byteptr {
|
||||
return syscall6(9, start, len, prot, flags, fd, off) // sys_mmap
|
||||
}
|
||||
|
||||
pub fn malloc(n int) byteptr {
|
||||
println('malloc($n)')
|
||||
return mmap(0, n, 3, 4098, //PROT_READ|PROT_WRITE,
|
||||
-1,0) //MAP_PRIVATE|MAP_ANONYMOUS,
|
||||
}
|
||||
|
||||
pub fn free(b byteptr) {
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
|
Reference in New Issue
Block a user