diff options
author | sago35 <[email protected]> | 2022-03-29 08:25:04 +0900 |
---|---|---|
committer | Ron Evans <[email protected]> | 2022-06-01 07:56:25 +0200 |
commit | 39805bca4598e3a3ad312a388a008c8d9f989eb2 (patch) | |
tree | ac03b2f534d650d551558160d2536e3b04323126 /src/os | |
parent | 97842b367c0fc92499f73b9b63014247906f9190 (diff) | |
download | tinygo-39805bca4598e3a3ad312a388a008c8d9f989eb2.tar.gz tinygo-39805bca4598e3a3ad312a388a008c8d9f989eb2.zip |
os, runtime: enable os.Stdin for baremetal target
Diffstat (limited to 'src/os')
-rw-r--r-- | src/os/file_other.go | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/src/os/file_other.go b/src/os/file_other.go index 036ddf690..82c84e958 100644 --- a/src/os/file_other.go +++ b/src/os/file_other.go @@ -38,9 +38,26 @@ func NewFile(fd uintptr, name string) *File { return &File{&file{stdioFileHandle(fd), name}} } -// Read is unsupported on this system. +// Read reads up to len(b) bytes from machine.Serial. +// It returns the number of bytes read and any error encountered. func (f stdioFileHandle) Read(b []byte) (n int, err error) { - return 0, ErrUnsupported + if len(b) == 0 { + return 0, nil + } + + size := buffered() + for size == 0 { + gosched() + size = buffered() + } + + if size > len(b) { + size = len(b) + } + for i := 0; i < size; i++ { + b[i] = getchar() + } + return size, nil } func (f stdioFileHandle) ReadAt(b []byte, off int64) (n int, err error) { @@ -78,6 +95,15 @@ func (f stdioFileHandle) Fd() uintptr { //go:linkname putchar runtime.putchar func putchar(c byte) +//go:linkname getchar runtime.getchar +func getchar() byte + +//go:linkname buffered runtime.buffered +func buffered() int + +//go:linkname gosched runtime.Gosched +func gosched() int + func Pipe() (r *File, w *File, err error) { return nil, nil, ErrNotImplemented } |