os_linux.v
parent
1dadf9d966
commit
d1b8d34dd5
|
@ -1,28 +1,9 @@
|
|||
module builtin
|
||||
|
||||
pub fn syscall5(number, arg1, arg2, arg3, arg4, arg5 voidptr) voidptr
|
||||
|
||||
// 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.str, s.len)
|
||||
}
|
||||
//pub fn syscall5(number, arg1, arg2, arg3, arg4, arg5 voidptr) voidptr
|
||||
//pub fn syscall6(number, arg1, arg2, arg3, arg4, arg5, arg6 voidptr) voidptr
|
||||
|
||||
pub fn panic(s string) {
|
||||
write(1, s.str, s.len)
|
||||
//write(1, s.str, s.len)
|
||||
}
|
||||
|
||||
pub fn malloc(n int) voidptr {
|
||||
return syscall5(0,0,0,0,0,0)
|
||||
|
||||
}
|
||||
|
|
|
@ -24,12 +24,14 @@ pub fn tos(s byteptr, len int) string {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
pub fn tos_clone(s byteptr) string {
|
||||
if s == 0 {
|
||||
panic('tos: nil string')
|
||||
}
|
||||
return tos2(s).clone()
|
||||
}
|
||||
*/
|
||||
|
||||
// Same as `tos`, but calculates the length. Called by `string(bytes)` casts.
|
||||
// Used only internally.
|
||||
|
@ -53,6 +55,7 @@ pub fn tos3(s *C.char) string {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
pub fn (a string) clone() string {
|
||||
mut b := string {
|
||||
len: a.len
|
||||
|
@ -64,3 +67,4 @@ pub fn (a string) clone() string {
|
|||
b[a.len] = `\0`
|
||||
return b
|
||||
}
|
||||
*/
|
||||
|
|
|
@ -123,7 +123,7 @@ fn (v mut V) cc() {
|
|||
v.out_name = v.out_name + '.so'
|
||||
}
|
||||
if v.pref.is_bare {
|
||||
a << '-static -nostdlib $vdir/vlib/os/bare/bare.S'
|
||||
a << '-static -ffreestanding -nostdlib $vdir/vlib/os/bare/bare.S'
|
||||
}
|
||||
if v.pref.build_mode == .build_module {
|
||||
// Create the modules & out directory if it's not there.
|
||||
|
|
|
@ -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')
|
||||
}
|
|
@ -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)
|
||||
}
|
||||
|
|
@ -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) {
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
|
Loading…
Reference in New Issue