From 852d2c0283f698ac958b45be4d34431091e62522 Mon Sep 17 00:00:00 2001 From: oliverschmidt Date: Tue, 1 Jan 2008 18:49:50 +0000 Subject: [PATCH] Introduced very lightweight pfs implementation based on Apple ProDOS. ProDOS requires for each opened file a user-supplied page-aligned 1024 byte i/o buffer. This makes the generic POSIX file i/o library contained in the cc65 C-library quite heavyweight. In contrast the lightweight pfs implementation uses the uIP packet buffer as ProDOS i/o buffer. Therefore: - Only one file may be open at any time. - That file may not be open while the uIP packet buffer is used by uIP. The open()/read()/close() sequence should be completed before Contiki event scheduling or inside handling a single Contiki event. - The uIP packet buffer must be large enough to hold the ProDOS I/O buffer. Depending on the position of the uIP buffer in memory this means between 1024 and 1024 + 256 bytes. Therefore in an Ethernet environment setting the MTU_SIZE to at least 1266 is safe (So the default of 1500 is just fine). --- platform/apple2enh/Makefile.apple2enh | 2 +- platform/apple2enh/contiki-conf.h | 4 +- platform/apple2enh/lib/pfs.S | 154 ++++++++++++++++++++++++++ platform/apple2enh/lib/pfs.h | 43 +++++++ 4 files changed, 201 insertions(+), 2 deletions(-) create mode 100644 platform/apple2enh/lib/pfs.S create mode 100644 platform/apple2enh/lib/pfs.h diff --git a/platform/apple2enh/Makefile.apple2enh b/platform/apple2enh/Makefile.apple2enh index c5f85a3b9..942b4e8ac 100644 --- a/platform/apple2enh/Makefile.apple2enh +++ b/platform/apple2enh/Makefile.apple2enh @@ -1,4 +1,4 @@ -CONTIKI_SOURCEFILES += log-asm.S +CONTIKI_SOURCEFILES += log-asm.S pfs.S CONTIKI_CPU = $(CONTIKI)/cpu/6502 include $(CONTIKI_CPU)/Makefile.6502 diff --git a/platform/apple2enh/contiki-conf.h b/platform/apple2enh/contiki-conf.h index 254ee7740..112c6cc36 100644 --- a/platform/apple2enh/contiki-conf.h +++ b/platform/apple2enh/contiki-conf.h @@ -30,7 +30,7 @@ * * Author: Oliver Schmidt * - * $Id: contiki-conf.h,v 1.11 2007/12/23 13:57:08 oliverschmidt Exp $ + * $Id: contiki-conf.h,v 1.12 2008/01/01 18:49:50 oliverschmidt Exp $ */ #ifndef __CONTIKI_CONF_H__ @@ -38,6 +38,8 @@ #include "6502def.h" +#include "pfs.h" + #define LOG_CONF_ENABLED 1 #define UIP_CONF_LOGGING 0 diff --git a/platform/apple2enh/lib/pfs.S b/platform/apple2enh/lib/pfs.S new file mode 100644 index 000000000..d35628747 --- /dev/null +++ b/platform/apple2enh/lib/pfs.S @@ -0,0 +1,154 @@ +; +; Copyright (c) 2008, Swedish Institute of Computer Science. +; All rights reserved. +; +; 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 Institute 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 INSTITUTE 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 INSTITUTE 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. +; +; This file is part of the Contiki operating system. +; +; Author: Oliver Schmidt +; +; $Id: pfs.S,v 1.1 2008/01/01 18:49:51 oliverschmidt Exp $ +; +;--------------------------------------------------------------------- + .constructor init_pfs + .destructor done_pfs + .importzp ptr1 + .import popax, _uip_buf + .export _pfs_open, _pfs_read, _pfs_close +;--------------------------------------------------------------------- +pathname := $0280 +mli := $BF00 + +OPEN_CALL = $C8 +READ_CALL = $CA +CLOSE_CALL = $CC +;--------------------------------------------------------------------- + .bss + +prefix: .res 1 +;--------------------------------------------------------------------- + .data + +open_param: .byte $03 ;PARAM_COUNT + .addr pathname ;PATHNAME + .byte $00 ;IO_BUFFER (Lo) + .byte >_uip_buf+1 ;IO_BUFFER (Hi) +open_fd: .byte $00 ;REF_NUM + +read_param: .byte $04 ;PARAM_COUNT +read_fd: .byte $00 ;REF_NUM +read_buffer: .addr $0000 ;DATA_BUFFER +read_count_in: .word $0000 ;REQUEST_COUNT +read_count_out: .word $0000 ;TRANS_COUNT + +close_param: .byte $01 ;PARAM_COUNT +close_fd: .byte $00 ;REF_NUM +;--------------------------------------------------------------------- + .segment "INIT" + +init_pfs: + ; Get prefix len of path used to load binary + ldx pathname +: lda pathname,x + cmp #'/' + beq :+ + dex + bne :- +: stx prefix + rts +;--------------------------------------------------------------------- + .code + +_pfs_open: + ; Pop and store name + jsr popax + sta ptr1 + stx ptr1+1 + + ; Append name to prefix + ldy #$00 + ldx prefix +: lda (ptr1),y + beq :+ + sta pathname+1,x + iny + inx + bne :- +: stx pathname + + jsr mli + .byte OPEN_CALL + .addr open_param + bcs error + + ; Return fd + lda open_fd + ldx #$00 + rts + +_pfs_read: + ; Store len requested + sta read_count_in + stx read_count_in+1 + + ; Pop and store buf + jsr popax + sta read_buffer + stx read_buffer+1 + + ; Pop and store fd + jsr popax + sta read_fd + + jsr mli + .byte READ_CALL + .addr read_param + bcs error + + ; Return len read + lda read_count_out + ldx read_count_out+1 + rts + +done_pfs: + lda #$00 + +_pfs_close: + ; Store fd + sta close_fd + + jsr mli + .byte CLOSE_CALL + .addr close_param + bcs error + rts + +error: + ; Return -1 + lda #$FF + tax + rts +;--------------------------------------------------------------------- diff --git a/platform/apple2enh/lib/pfs.h b/platform/apple2enh/lib/pfs.h new file mode 100644 index 000000000..a7c358105 --- /dev/null +++ b/platform/apple2enh/lib/pfs.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2008, Swedish Institute of Computer Science. + * All rights reserved. + * + * 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 Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the Contiki operating system. + * + * Author: Oliver Schmidt + * + * $Id: pfs.h,v 1.1 2008/01/01 18:49:51 oliverschmidt Exp $ + */ + +#ifndef __PFS_H__ +#define __PFS_H__ + +int __fastcall__ pfs_open(const char* name, int flags); +void __fastcall__ pfs_close(int fd); +int __fastcall__ pfs_read(int fd, void* buf, unsigned int len); + +#endif /* __PFS_H__ */