Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mos-platform/common/include/unistd.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ typedef long int off_t;
int write(int fd, const void* buf, unsigned count);
int read(int fd, void* buf, unsigned count);
off_t lseek(int fd, off_t offset, int whence);
int syncfs (int fd);
int unlink(const char* name); /* Same as remove() */

/* Directories */
Expand Down
26 changes: 22 additions & 4 deletions mos-platform/rp6502/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,44 @@ merge_libraries(rp6502-crt0

add_platform_library(rp6502-c
abort.c
chdir.c
clock_getres.c
clock_gettime.c
clock_settime.c
clock.c
close.c
codepage.c
code_page.c
errno.s
f_chdrive.c
f_chmod.c
f_closedir.c
f_getcwd.c
f_getfree.c
f_getlabel.c
f_lseek.c
f_mkdir.c
f_opendir.c
f_readdir.c
f_rewinddir.c
f_seekdir.c
f_setlabel.c
f_stat.c
f_telldir.c
f_utime.c
getchar.c
lrand.c
lseek.c
open.c
oserror.s
phi2.c
putchar.c
read_xram.c
read_xstack.c
read.c
remove.c
rename.c
ria.s
stdin_opt.c
sysremove.c
sysrename.c
syncfs.c
write_xram.c
write_xstack.c
write.c
Expand Down
16 changes: 16 additions & 0 deletions mos-platform/rp6502/chdir.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <errno.h>
#include <rp6502.h>
#include <string.h>
#include <unistd.h>

int chdir(const char *name) {
size_t namelen = strlen(name);
if (namelen > 255) {
errno = EINVAL;
return -1;
}
while (namelen) {
ria_push_char(name[--namelen]);
}
return ria_call_int(RIA_OP_CHDIR);
}
2 changes: 1 addition & 1 deletion mos-platform/rp6502/clock_gettimespec.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

/* Internal method shared by clock_getres and clock_gettime. */
int __clock_gettimespec(struct timespec *ts, unsigned char op) {
int ax = ria_call_int_errno(op);
int ax = ria_call_int(op);
if (ax >= 0) {
ts->tv_sec = ria_pop_long();
ts->tv_nsec = ria_pop_long();
Expand Down
2 changes: 1 addition & 1 deletion mos-platform/rp6502/clock_settime.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ int clock_settime(clockid_t clock_id, const struct timespec *tp) {
ria_set_ax(clock_id);
ria_push_long(tp->tv_nsec);
ria_push_long(tp->tv_sec);
return ria_call_int_errno(RIA_OP_CLOCK_SETTIME);
return ria_call_int(RIA_OP_CLOCK_SETTIME);
}
2 changes: 1 addition & 1 deletion mos-platform/rp6502/close.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@

int close(int fd) {
ria_set_ax(fd);
return ria_call_int_errno(RIA_OP_CLOSE);
return ria_call_int(RIA_OP_CLOSE);
}
6 changes: 6 additions & 0 deletions mos-platform/rp6502/code_page.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "rp6502.h"

int code_page(int cp) {
ria_set_ax(cp);
return ria_call_int(RIA_OP_CODE_PAGE);
}
3 changes: 0 additions & 3 deletions mos-platform/rp6502/codepage.c

This file was deleted.

16 changes: 16 additions & 0 deletions mos-platform/rp6502/errno.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.include "rp6502.inc"

; The errno on the RP6502 RIA is the errno for llvm-mos.
; There is no oserror and nothing calls __mappederrno.

.global _errno
.set _errno, RIA_ERRNO

; Request the RIA use llvm-mos values for RIA_ERRNO

.section .init.100,"ax",@progbits
lda #$02 ; 2 = llvm-mos
sta RIA_A
lda #RIA_OP_ERRNO_OPT
sta RIA_OP
jsr RIA_SPIN
15 changes: 15 additions & 0 deletions mos-platform/rp6502/f_chdrive.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <errno.h>
#include <rp6502.h>
#include <string.h>

int f_chdrive(const char *name) {
size_t namelen = strlen(name);
if (namelen > 255) {
errno = EINVAL;
return -1;
}
while (namelen) {
ria_push_char(name[--namelen]);
}
return ria_call_int(RIA_OP_CHDRIVE);
}
18 changes: 18 additions & 0 deletions mos-platform/rp6502/f_chmod.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <errno.h>
#include <rp6502.h>
#include <string.h>

int f_chmod(const char *path, unsigned char attr, unsigned char mask) {
size_t pathlen;
ria_set_a(mask);
pathlen = strlen(path);
if (pathlen > 255) {
errno = EINVAL;
return -1;
}
while (pathlen) {
ria_push_char(path[--pathlen]);
}
ria_push_char(attr);
return ria_call_int(RIA_OP_CHMOD);
}
6 changes: 6 additions & 0 deletions mos-platform/rp6502/f_closedir.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <rp6502.h>

int f_closedir(int dirdes) {
ria_set_ax(dirdes);
return ria_call_int(RIA_OP_CLOSEDIR);
}
17 changes: 17 additions & 0 deletions mos-platform/rp6502/f_getcwd.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <errno.h>
#include <rp6502.h>
#include <string.h>

int f_getcwd(char *name, int size) {
int i, ax;
ax = ria_call_int(RIA_OP_GETCWD);
if (ax > size) {
RIA.op = RIA_OP_ZXSTACK;
errno = ENOMEM;
return -1;
}
for (i = 0; i < ax; i++) {
name[i] = ria_pop_char();
}
return ax;
}
21 changes: 21 additions & 0 deletions mos-platform/rp6502/f_getfree.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <errno.h>
#include <rp6502.h>
#include <string.h>

int f_getfree(const char *name, unsigned long *free, unsigned long *total) {
int ax;
size_t namelen = strlen(name);
if (namelen > 255) {
errno = EINVAL;
return -1;
}
while (namelen) {
ria_push_char(name[--namelen]);
}
ax = ria_call_int(RIA_OP_GETFREE);
if (ax >= 0) {
*free = ria_pop_long();
*total = ria_pop_long();
}
return ax;
}
20 changes: 20 additions & 0 deletions mos-platform/rp6502/f_getlabel.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <errno.h>
#include <rp6502.h>
#include <string.h>

int f_getlabel(const char *path, char *label) {
int i, ax;
size_t pathlen = strlen(path);
if (pathlen > 255) {
errno = EINVAL;
return -1;
}
while (pathlen) {
ria_push_char(path[--pathlen]);
}
ax = ria_call_int(RIA_OP_GETLABEL);
for (i = 0; i < ax; i++) {
label[i] = ria_pop_char();
}
return ax;
}
8 changes: 8 additions & 0 deletions mos-platform/rp6502/f_lseek.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <rp6502.h>

long f_lseek(long offset, int whence, int fildes) {
ria_set_ax(fildes);
ria_push_long(offset);
ria_push_char(whence);
return ria_call_long(RIA_OP_LSEEK);
}
15 changes: 15 additions & 0 deletions mos-platform/rp6502/f_mkdir.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <errno.h>
#include <rp6502.h>
#include <string.h>

int f_mkdir(const char *name) {
size_t namelen = strlen(name);
if (namelen > 255) {
errno = EINVAL;
return -1;
}
while (namelen) {
ria_push_char(name[--namelen]);
}
return ria_call_int(RIA_OP_MKDIR);
}
15 changes: 15 additions & 0 deletions mos-platform/rp6502/f_opendir.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <errno.h>
#include <rp6502.h>
#include <string.h>

int f_opendir(const char *name) {
size_t namelen = strlen(name);
if (namelen > 255) {
errno = EINVAL;
return -1;
}
while (namelen) {
ria_push_char(name[--namelen]);
}
return ria_call_int(RIA_OP_OPENDIR);
}
11 changes: 11 additions & 0 deletions mos-platform/rp6502/f_readdir.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <rp6502.h>

int f_readdir(f_stat_t *dirent, int dirdes) {
int i, ax;
ria_set_ax(dirdes);
ax = ria_call_int(RIA_OP_READDIR);
for (i = 0; i < sizeof(f_stat_t); i++) {
((char *)dirent)[i] = ria_pop_char();
}
return ax;
}
6 changes: 6 additions & 0 deletions mos-platform/rp6502/f_rewinddir.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <rp6502.h>

int f_rewinddir(int dirdes) {
ria_set_ax(dirdes);
return ria_call_int(RIA_OP_REWINDDIR);
}
7 changes: 7 additions & 0 deletions mos-platform/rp6502/f_seekdir.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <rp6502.h>

int f_seekdir(long offs, int dirdes) {
ria_set_ax(dirdes);
ria_push_long(offs);
return ria_call_int(RIA_OP_SEEKDIR);
}
15 changes: 15 additions & 0 deletions mos-platform/rp6502/f_setlabel.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <errno.h>
#include <rp6502.h>
#include <string.h>

int f_setlabel(const char *name) {
size_t namelen = strlen(name);
if (namelen > 255) {
errno = EINVAL;
return -1;
}
while (namelen) {
ria_push_char(name[--namelen]);
}
return ria_call_int(RIA_OP_SETLABEL);
}
20 changes: 20 additions & 0 deletions mos-platform/rp6502/f_stat.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <errno.h>
#include <rp6502.h>
#include <string.h>

int f_stat(const char *path, f_stat_t *dirent) {
int i, ax;
size_t pathlen = strlen(path);
if (pathlen > 255) {
errno = EINVAL;
return -1;
}
while (pathlen) {
ria_push_char(path[--pathlen]);
}
ax = ria_call_int(RIA_OP_STAT);
for (i = 0; i < sizeof(f_stat_t); i++) {
((char *)dirent)[i] = ria_pop_char();
}
return ax;
}
6 changes: 6 additions & 0 deletions mos-platform/rp6502/f_telldir.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <rp6502.h>

long f_telldir(int dirdes) {
ria_set_ax(dirdes);
return ria_call_long(RIA_OP_TELLDIR);
}
21 changes: 21 additions & 0 deletions mos-platform/rp6502/f_utime.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <errno.h>
#include <rp6502.h>
#include <string.h>

int f_utime(const char *path, unsigned fdate, unsigned ftime, unsigned crdate,
unsigned crtime) {
size_t pathlen;
ria_set_ax(crtime);
pathlen = strlen(path);
if (pathlen > 255) {
errno = EINVAL;
return -1;
}
while (pathlen) {
ria_push_char(path[--pathlen]);
}
ria_push_int(fdate);
ria_push_int(ftime);
ria_push_int(crdate);
return ria_call_int(RIA_OP_UTIME);
}
2 changes: 1 addition & 1 deletion mos-platform/rp6502/getchar.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
int __getchar(void) {
ria_push_char(1);
ria_set_a(STDIN_FILENO);
if (ria_call_int_errno(RIA_OP_READ_XSTACK) == 1)
if (ria_call_int(RIA_OP_READ_XSTACK) == 1)
return RIA.xstack;
return EOF;
}
18 changes: 2 additions & 16 deletions mos-platform/rp6502/lseek.c
Original file line number Diff line number Diff line change
@@ -1,23 +1,9 @@
#include "rp6502.h"
#include <stdio.h>
#include <unistd.h>

off_t lseek(int fd, off_t offset, int whence) {
switch (whence) {
case SEEK_CUR:
ria_push_char(RIA_SEEK_CUR);
break;
case SEEK_END:
ria_push_char(RIA_SEEK_END);
break;
case SEEK_SET:
ria_push_char(RIA_SEEK_SET);
break;
default:
ria_push_int(whence);
break;
}
ria_push_long(offset);
ria_push_char(whence);
ria_set_ax(fd);
return ria_call_long_errno(RIA_OP_LSEEK);
return ria_call_long(RIA_OP_LSEEK);
}
Loading