write: actually write to the serial console

This commit is contained in:
Felix Kopp 2021-01-05 14:40:18 +01:00
parent 632824e437
commit dee9ce667f
No known key found for this signature in database
GPG key ID: C478BA0A85F75728
7 changed files with 82 additions and 29 deletions

View file

@ -20,7 +20,6 @@
struct serial_interface {
struct ringbuf *rx;
struct ringbuf *tx;
long int baud;
int id;
};

View file

@ -29,7 +29,8 @@ typedef __SIZE_TYPE__ uintptr_t;
/** Signed size specifier (negative sizes mean error codes). */
typedef __PTRDIFF_TYPE__ ssize_t;
typedef __PTRDIFF_TYPE__ ptrdiff_t;
typedef __PTRDIFF_TYPE__ loff_t;
typedef __PTRDIFF_TYPE__ off_t;
typedef long __PTRDIFF_TYPE__ loff_t;
/*
* Copyright (c) 2020 Felix Kopp <sandtler@sandtler.club>

34
include/unistd.h Normal file
View file

@ -0,0 +1,34 @@
/* SPDX-License-Identifier: BSD-3-Clause */
/* See the end of this file for copyright, licensing, and warranty information. */
#pragma once
#include <stdint.h>
ssize_t pwrite(int fildes, const void *buf, size_t nbyte, off_t offset);
ssize_t write(int fildes, const void *buf, size_t nbyte);
/*
* Copyright (c) 2020 Felix Kopp <sandtler@sandtler.club>
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
* 3. Neither the name of the copyright holder nor the names of its contributors may be
* used to endorse or promote products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

View file

@ -25,6 +25,7 @@
ARDIX_KERNEL_PWD = $(PWD)/kernel
include $(ARDIX_KERNEL_PWD)/fs/Makefile
include $(ARDIX_KERNEL_PWD)/io/Makefile
ARDIX_SOURCES += \

View file

@ -23,17 +23,9 @@ int serial_init(struct serial_interface *interface, long int baud)
if (interface->rx == NULL)
return -1;
interface->tx = ringbuf_create(SERIAL_BUFSZ);
if (interface->tx == NULL) {
ringbuf_destroy(interface->rx);
return -1;
}
err = arch_serial_init(interface);
if (err) {
if (err)
ringbuf_destroy(interface->rx);
ringbuf_destroy(interface->tx);
}
return err;
}
@ -42,7 +34,6 @@ void serial_exit(struct serial_interface *interface)
{
arch_serial_exit(interface);
ringbuf_destroy(interface->rx);
ringbuf_destroy(interface->tx);
interface->id = -1;
}
@ -59,23 +50,11 @@ ssize_t serial_read(void *dest, struct serial_interface *interface, size_t len)
ssize_t serial_write(struct serial_interface *interface, const void *data, size_t len)
{
size_t ret = 0;
size_t tmp;
size_t ret;
while (1) {
atomic_enter();
tmp = ringbuf_write(interface->tx, data, len);
atomic_leave();
ret += tmp;
if (ret != len) { /* buffer full, suspend until I/O is ready */
len -= tmp;
data += tmp;
sched_yield(PROC_IOWAIT);
} else {
break;
}
}
atomic_enter();
ret = arch_serial_write(interface, data, len);
atomic_leave();
return (ssize_t)ret;
}

View file

@ -12,7 +12,7 @@ __rodata
const int (*syscall_table[NSYSCALLS])(sysarg_t arg1, sysarg_t arg2, sysarg_t arg3,
sysarg_t arg4, sysarg_t arg5, sysarg_t arg6) = {
syscall_entry(SYSCALL_READ, &sys_stub),
syscall_entry(SYSCALL_WRITE, &sys_stub),
syscall_entry(SYSCALL_WRITE, &sys_write),
};
int sys_stub(void)

39
lib/unistd.c Normal file
View file

@ -0,0 +1,39 @@
/* SPDX-License-Identifier: BSD-3-Clause */
/* See the end of this file for copyright, licensing, and warranty information. */
#include <stdarg.h>
#include <ardix/syscall.h>
#include <toolchain.h>
#include <unistd.h>
__shared ssize_t write(int fildes, const void *buf, size_t nbyte)
{
return pwrite(fildes, buf, nbyte, 0);
}
/*
* Copyright (c) 2020 Felix Kopp <sandtler@sandtler.club>
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
* 3. Neither the name of the copyright holder nor the names of its contributors may be
* used to endorse or promote products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/