Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
ebcd76d5
Commit
ebcd76d5
authored
Jul 29, 2008
by
Rob Pike
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rewrite system call interface to use less assembler.
R=gri OCL=13546 CL=13546
parent
f095e263
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
165 additions
and
198 deletions
+165
-198
Makefile
src/syscall/Makefile
+1
-1
errstr_darwin.go
src/syscall/errstr_darwin.go
+1
-1
file_amd64_darwin.go
src/syscall/file_amd64_darwin.go
+57
-3
file_amd64_linux.go
src/syscall/file_amd64_linux.go
+57
-3
syscall.go
src/syscall/syscall.go
+7
-6
syscall_amd64_darwin.s
src/syscall/syscall_amd64_darwin.s
+22
-85
syscall_amd64_linux.s
src/syscall/syscall_amd64_linux.s
+20
-99
No files found.
src/syscall/Makefile
View file @
ebcd76d5
...
...
@@ -13,7 +13,7 @@ PKG=syscall.a
OFILES
=
\
syscall.
$O
\
errstr_
$(GOOS)
.
$O
\
stat
_
$(GOARCH)
_
$(GOOS)
.
$O
\
file
_
$(GOARCH)
_
$(GOOS)
.
$O
\
syscall_
$(GOARCH)
_
$(GOOS)
.
$O
\
...
...
src/syscall/errstr_darwin.go
View file @
ebcd76d5
...
...
@@ -98,7 +98,7 @@ const (
EBADMACHO
=
88
;
ECANCELED
=
89
;
EIDRM
=
90
;
ENOMSG
=
91
;
ENOMSG
=
91
;
EILSEQ
=
92
;
ENOATTR
=
93
;
EBADMSG
=
94
;
...
...
src/syscall/
stat
_amd64_darwin.go
→
src/syscall/
file
_amd64_darwin.go
View file @
ebcd76d5
...
...
@@ -4,12 +4,13 @@
package
syscall
func
stat
(
name
*
byte
,
buf
*
Stat
)
(
ret
int64
,
errno
int64
);
func
fstat
(
fd
int64
,
buf
*
Stat
)
(
ret
int64
,
errno
int64
);
func
lstat
(
name
*
byte
,
buf
*
Stat
)
(
ret
int64
,
errno
int64
);
import
syscall
"syscall"
export
Stat
export
stat
,
fstat
,
lstat
export
open
,
close
,
read
,
write
,
pipe
func
StatToInt
(
s
*
Stat
)
int64
;
// Stat and relatives for Darwin
...
...
@@ -48,3 +49,56 @@ type Stat struct {
st_gen
uint32
;
st_qspare
[
2
]
int64
;
}
func
open
(
name
*
byte
,
mode
int64
)
(
ret
int64
,
errno
int64
)
{
const
SYSOPEN
=
5
;
r1
,
r2
,
err
:=
syscall
.
Syscall
(
SYSOPEN
,
AddrToInt
(
name
),
mode
,
0
);
return
r1
,
err
;
}
func
close
(
fd
int64
)
(
ret
int64
,
errno
int64
)
{
const
SYSCLOSE
=
6
;
r1
,
r2
,
err
:=
syscall
.
Syscall
(
SYSCLOSE
,
fd
,
0
,
0
);
return
r1
,
err
;
}
func
read
(
fd
int64
,
buf
*
byte
,
nbytes
int64
)
(
ret
int64
,
errno
int64
)
{
const
SYSREAD
=
3
;
r1
,
r2
,
err
:=
syscall
.
Syscall
(
SYSREAD
,
fd
,
AddrToInt
(
buf
),
nbytes
);
return
r1
,
err
;
}
func
write
(
fd
int64
,
buf
*
byte
,
nbytes
int64
)
(
ret
int64
,
errno
int64
)
{
const
SYSWRITE
=
4
;
r1
,
r2
,
err
:=
syscall
.
Syscall
(
SYSWRITE
,
fd
,
AddrToInt
(
buf
),
nbytes
);
return
r1
,
err
;
}
func
pipe
(
fds
*
[
2
]
int64
)
(
ret
int64
,
errno
int64
)
{
const
SYSPIPE
=
42
;
r1
,
r2
,
err
:=
syscall
.
Syscall
(
SYSPIPE
,
0
,
0
,
0
);
if
r1
<
0
{
return
r1
,
err
;
}
fds
[
0
]
=
r1
;
fds
[
1
]
=
r2
;
return
0
,
err
;
}
func
stat
(
name
*
byte
,
buf
*
Stat
)
(
ret
int64
,
errno
int64
)
{
const
SYSSTAT
=
338
;
r1
,
r2
,
err
:=
syscall
.
Syscall
(
SYSSTAT
,
AddrToInt
(
name
),
StatToInt
(
buf
),
0
);
return
r1
,
err
;
}
func
lstat
(
name
*
byte
,
buf
*
Stat
)
(
ret
int64
,
errno
int64
)
{
const
SYSLSTAT
=
340
;
r1
,
r2
,
err
:=
syscall
.
Syscall
(
SYSLSTAT
,
AddrToInt
(
name
),
StatToInt
(
buf
),
0
);
return
r1
,
err
;
}
func
fstat
(
fd
int64
,
buf
*
Stat
)
(
ret
int64
,
errno
int64
)
{
const
SYSFSTAT
=
339
;
r1
,
r2
,
err
:=
syscall
.
Syscall
(
SYSFSTAT
,
fd
,
StatToInt
(
buf
),
0
);
return
r1
,
err
;
}
src/syscall/
stat
_amd64_linux.go
→
src/syscall/
file
_amd64_linux.go
View file @
ebcd76d5
...
...
@@ -4,12 +4,13 @@
package
syscall
func
stat
(
name
*
byte
,
buf
*
Stat
)
(
ret
int64
,
errno
int64
);
func
fstat
(
fd
int64
,
buf
*
Stat
)
(
ret
int64
,
errno
int64
);
func
lstat
(
name
*
byte
,
buf
*
Stat
)
(
ret
int64
,
errno
int64
);
import
syscall
"syscall"
export
Stat
export
stat
,
fstat
,
lstat
export
open
,
close
,
read
,
write
,
pipe
func
StatToInt
(
s
*
Stat
)
int64
;
// Stat and relatives for Linux
...
...
@@ -46,3 +47,56 @@ type Stat struct {
st_ctime
Timespec
;
/* time of last status change */
}
func
open
(
name
*
byte
,
mode
int64
)
(
ret
int64
,
errno
int64
)
{
const
SYSOPEN
=
2
;
r1
,
r2
,
err
:=
syscall
.
Syscall
(
SYSOPEN
,
AddrToInt
(
name
),
mode
,
0
);
return
r1
,
err
;
}
func
close
(
fd
int64
)
(
ret
int64
,
errno
int64
)
{
const
SYSCLOSE
=
3
;
r1
,
r2
,
err
:=
syscall
.
Syscall
(
SYSCLOSE
,
fd
,
0
,
0
);
return
r1
,
err
;
}
func
read
(
fd
int64
,
buf
*
byte
,
nbytes
int64
)
(
ret
int64
,
errno
int64
)
{
const
SYSREAD
=
0
;
r1
,
r2
,
err
:=
syscall
.
Syscall
(
SYSREAD
,
fd
,
AddrToInt
(
buf
),
nbytes
);
return
r1
,
err
;
}
func
write
(
fd
int64
,
buf
*
byte
,
nbytes
int64
)
(
ret
int64
,
errno
int64
)
{
const
SYSWRITE
=
1
;
r1
,
r2
,
err
:=
syscall
.
Syscall
(
SYSWRITE
,
fd
,
AddrToInt
(
buf
),
nbytes
);
return
r1
,
err
;
}
func
pipe
(
fds
*
[
2
]
int64
)
(
ret
int64
,
errno
int64
)
{
const
SYSPIPE
=
22
;
r1
,
r2
,
err
:=
syscall
.
Syscall
(
SYSPIPE
,
0
,
0
,
0
);
if
r1
<
0
{
return
r1
,
err
;
}
fds
[
0
]
=
r1
;
fds
[
1
]
=
r2
;
return
0
,
err
;
}
func
stat
(
name
*
byte
,
buf
*
Stat
)
(
ret
int64
,
errno
int64
)
{
const
SYSSTAT
=
4
;
r1
,
r2
,
err
:=
syscall
.
Syscall
(
SYSSTAT
,
AddrToInt
(
name
),
StatToInt
(
buf
),
0
);
return
r1
,
err
;
}
func
lstat
(
name
*
byte
,
buf
*
Stat
)
(
ret
int64
,
errno
int64
)
{
const
SYSLSTAT
=
6
;
r1
,
r2
,
err
:=
syscall
.
Syscall
(
SYSLSTAT
,
AddrToInt
(
name
),
StatToInt
(
buf
),
0
);
return
r1
,
err
;
}
func
fstat
(
fd
int64
,
buf
*
Stat
)
(
ret
int64
,
errno
int64
)
{
const
SYSFSTAT
=
5
;
r1
,
r2
,
err
:=
syscall
.
Syscall
(
SYSFSTAT
,
fd
,
StatToInt
(
buf
),
0
);
return
r1
,
err
;
}
src/syscall/syscall.go
View file @
ebcd76d5
...
...
@@ -8,12 +8,13 @@ package syscall
* These calls have signatures that are independent of operating system.
*
* For simplicity of addressing in assembler, all integers are 64 bits
* in these calling sequences
.
* in these calling sequences
(although it complicates some, such as pipe)
*/
func
open
(
name
*
byte
,
mode
int64
)
(
ret
int64
,
errno
int64
);
func
close
(
fd
int64
)
(
ret
int64
,
errno
int64
);
func
read
(
fd
int64
,
buf
*
byte
,
nbytes
int64
)
(
ret
int64
,
errno
int64
);
func
write
(
fd
int64
,
buf
*
byte
,
nbytes
int64
)
(
ret
int64
,
errno
int64
);
func
Syscall
(
trap
int64
,
a1
,
a2
,
a3
int64
)
(
r1
,
r2
,
err
int64
);
func
AddrToInt
(
b
*
byte
)
int64
;
export
Syscall
export
AddrToInt
export
open
,
close
,
read
,
write
src/syscall/syscall_amd64_darwin.s
View file @
ebcd76d5
...
...
@@ -3,98 +3,35 @@
// license that can be found in the LICENSE file.
//
// System call
s
for AMD64, Darwin
// System call
support
for AMD64, Darwin
//
TEXT syscall·open(SB),1,$-8
MOVQ 8(SP), DI
MOVQ 16(SP), SI
MOVQ $0, R10
MOVL $(0x2000000+5), AX // syscall entry
SYSCALL
JCC 4(PC)
MOVQ $-1, 24(SP)
MOVQ AX, 32(SP)
RET
MOVQ AX, 24(SP)
MOVQ $0, 32(SP)
RET
TEXT syscall·close(SB),1,$-8
MOVL 8(SP), DI
MOVL $(0x2000000+6), AX // syscall entry
SYSCALL
JCC 4(PC)
MOVQ $-1, 16(SP)
MOVQ AX, 24(SP)
RET
MOVQ AX, 16(SP)
MOVQ $0, 24(SP)
RET
TEXT syscall·read(SB),1,$-8
MOVQ 8(SP), DI
MOVQ 16(SP), SI
MOVQ 24(SP), DX
MOVL $(0x2000000+3), AX // syscall entry
SYSCALL
JCC 4(PC)
MOVQ $-1, 32(SP)
MOVQ AX, 40(SP)
RET
MOVQ AX, 32(SP)
MOVQ $0, 40(SP)
RET
TEXT syscall·write(SB),1,$-8
MOVQ 8(SP), DI
MOVQ 16(SP), SI
MOVQ 24(SP), DX
MOVL $(0x2000000+4), AX // syscall entry
SYSCALL
JCC 4(PC)
MOVQ $-1, 32(SP)
MOVQ AX, 40(SP)
RET
MOVQ AX, 32(SP)
MOVQ $0, 40(SP)
RET
// func Syscall(trap int64, a1, a2, a3 int64) (r1, r2, err int64);
// Trap # in AX, args in DI SI DX, return in AX DX
TEXT syscall·stat(SB),1,$-8
MOVQ 8(SP), DI
MOVQ 16(SP), SI
MOVL $(0x2000000+338), AX // syscall entry
TEXT syscall·Syscall(SB),1,$-8
MOVQ 16(SP), DI
MOVQ 24(SP), SI
MOVQ 32(SP), DX
MOVQ 8(SP), AX // syscall entry
ADDQ $0x2000000, AX
SYSCALL
JCC 4(PC)
MOVQ $-1, 24(SP)
MOVQ AX, 32(SP)
JCC 5(PC)
MOVQ $-1, 40(SP) // r1
MOVQ $0, 48(SP) // r2
MOVQ AX, 56(SP) // errno
RET
MOVQ AX, 24(SP)
MOVQ $0, 32(SP)
MOVQ AX, 40(SP) // r1
MOVQ DX, 48(SP) // r2
MOVQ $0, 56(SP) // errno
RET
TEXT syscall·fstat(SB),1,$-8
MOVQ 8(SP), DI
MOVQ 16(SP), SI
MOVL $(0x2000000+339), AX // syscall entry
SYSCALL
JCC 4(PC)
MOVQ $-1, 24(SP)
MOVQ AX, 32(SP)
RET
MOVQ AX, 24(SP)
MOVQ $0, 32(SP)
TEXT syscall·AddrToInt(SB),1,$-8
MOVQ 8(SP), AX
MOVQ AX, 16(SP)
RET
TEXT syscall·lstat(SB),1,$-8
MOVQ 8(SP), DI
MOVQ 16(SP), SI
MOVL $(0x2000000+340), AX // syscall entry
SYSCALL
JCC 4(PC)
MOVQ $-1, 24(SP)
MOVQ AX, 32(SP)
RET
MOVQ AX, 24(SP)
MOVQ $0, 32(SP)
TEXT syscall·StatToInt(SB),1,$-8
MOVQ 8(SP), AX
MOVQ AX, 16(SP)
RET
src/syscall/syscall_amd64_linux.s
View file @
ebcd76d5
...
...
@@ -6,112 +6,33 @@
// System calls for AMD64, Linux
//
TEXT syscall·open(SB),1,$0-16
MOVQ 8(SP), DI
MOVQ 16(SP), SI
MOVQ $0, DX
MOVQ $2, AX // syscall entry
// func Syscall(trap int64, a1, a2, a3 int64) (r1, r2, err int64);
// Trap # in AX, args in DI SI DX, return in AX DX
TEXT syscall·Syscall(SB),1,$-8
MOVQ 16(SP), DI
MOVQ 24(SP), SI
MOVQ 32(SP), DX
MOVQ 8(SP), AX // syscall entry
SYSCALL
CMPQ AX, $0xfffffffffffff001
JLS 5(PC)
MOVQ $-1, 24(SP)
JLS 6(PC)
MOVQ $-1, 40(SP) // r1
MOVQ $0, 48(SP) // r2
NEGQ AX
MOVQ AX,
32(SP)
MOVQ AX,
56(SP) // errno
RET
MOVQ AX, 24(SP)
MOVQ $0, 32(SP)
MOVQ AX, 40(SP) // r1
MOVQ DX, 48(SP) // r2
MOVQ $0, 56(SP) // errno
RET
TEXT syscall·close(SB),1,$0-16
MOVQ 8(SP), DI
MOVL $3, AX // syscall entry
SYSCALL
CMPQ AX, $0xfffffffffffff001
JLS 5(PC)
MOVQ $-1, 16(SP)
NEGQ AX
MOVQ AX, 24(SP)
RET
TEXT syscall·AddrToInt(SB),1,$-8
MOVQ 8(SP), AX
MOVQ AX, 16(SP)
MOVQ $0, 24(SP)
RET
TEXT syscall·read(SB),1,$0-16
MOVL 8(SP), DI
MOVQ 16(SP), SI
MOVL 24(SP), DX
MOVL $0, AX // syscall entry
SYSCALL
CMPQ AX, $0xfffffffffffff001
JLS 5(PC)
MOVQ $-1, 32(SP)
NEGQ AX
MOVQ AX, 40(SP)
RET
MOVQ AX, 32(SP)
MOVQ $0, 40(SP)
RET
TEXT syscall·write(SB),1,$0-16
MOVL 8(SP), DI
MOVQ 16(SP), SI
MOVL 24(SP), DX
MOVL $1, AX // syscall entry
SYSCALL
CMPQ AX, $0xfffffffffffff001
JLS 5(PC)
MOVQ $-1, 32(SP)
NEGQ AX
MOVQ AX, 40(SP)
RET
MOVQ AX, 32(SP)
MOVQ $0, 40(SP)
RET
TEXT syscall·stat(SB),1,$0-16
MOVQ 8(SP), DI
MOVQ 16(SP), SI
MOVQ $0, DX
MOVQ $5, AX // syscall entry
SYSCALL
CMPQ AX, $0xfffffffffffff001
JLS 5(PC)
MOVQ $-1, 24(SP)
NEGQ AX
MOVQ AX, 32(SP)
RET
MOVQ AX, 24(SP)
MOVQ $0, 32(SP)
RET
TEXT syscall·fstat(SB),1,$0-16
MOVL 8(SP), DI
MOVQ 16(SP), SI
MOVQ $0, DX
MOVQ $5, AX // syscall entry
SYSCALL
CMPQ AX, $0xfffffffffffff001
JLS 5(PC)
MOVQ $-1, 24(SP)
NEGQ AX
MOVQ AX, 32(SP)
RET
MOVQ AX, 24(SP)
MOVQ $0, 32(SP)
RET
TEXT syscall·lstat(SB),1,$0-16
MOVL 8(SP), DI
MOVQ 16(SP), SI
MOVQ $0, DX
MOVQ $6, AX // syscall entry
SYSCALL
CMPQ AX, $0xfffffffffffff001
JLS 5(PC)
MOVQ $-1, 24(SP)
NEGQ AX
MOVQ AX, 32(SP)
RET
MOVQ AX, 24(SP)
MOVQ $0, 32(SP)
TEXT syscall·StatToInt(SB),1,$-8
MOVQ 8(SP), AX
MOVQ AX, 16(SP)
RET
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment