started coding to bring SD card routines to EmuTOS

This commit is contained in:
Markus Fröschle
2013-05-01 06:28:30 +00:00
parent dbe59f26a3
commit 77a1440290
3 changed files with 178 additions and 1 deletions

View File

@@ -71,7 +71,8 @@ CSRCS= \
$(SRCDIR)/sd_card.c \ $(SRCDIR)/sd_card.c \
$(SRCDIR)/wait.c \ $(SRCDIR)/wait.c \
$(SRCDIR)/s19reader.c \ $(SRCDIR)/s19reader.c \
$(SRCDIR)/flash.c $(SRCDIR)/flash.c \
$(SRCDIR)/xhdi_sd.c
ASRCS= \ ASRCS= \
$(SRCDIR)/startcf.S \ $(SRCDIR)/startcf.S \
@@ -137,6 +138,9 @@ $(LIBBAS): $(OBJS)
$(AR) rv $@ $(OBJS) $(AR) rv $@ $(OBJS)
$(RANLIB) $@ $(RANLIB) $@
# compile xhdi_sd.c with -mshort to adhere to TOS argument passing conventions
$(OBJDIR)/xhdi_sd.o: CFLAGS += -mshort
# compile init_fpga with -mbitfield for testing purposes # compile init_fpga with -mbitfield for testing purposes
#$(OBJDIR)/init_fpga.o: CFLAGS += -mbitfield #$(OBJDIR)/init_fpga.o: CFLAGS += -mbitfield

55
BaS_gcc/include/xhdi_sd.h Normal file
View File

@@ -0,0 +1,55 @@
/*
* xhdi_sd.h
*
* Created on: 01.05.2013
* Author: mfro
*/
#ifndef _XHDI_SD_H_
#define _XHDI_SD_H_
/*
* FIXME: dangerous TRAP here!
*
* all of these functions get compiled with "normal" GCC integers (32 bit). However, since they will be called
* from code compiled with -mshort, integers must be declared uint32_t for those compilation units to adhere
* to "normal" GCC calling conventions.
*
* This is ugly and slow (all stack frames from -mshort compiled code need to be rearranged for "normal"
* calling conventions), but that's the way it currently is...
*
*/
#ifdef __MSHORT__
#define UINT16_T uint32_t
#else
#define UINT16_T uint16_t
#endif
extern uint32_t xhdi_call(int xhdi_fun, ...);
extern uint32_t xhdi_version(void); /* XHDI 0 */
extern uint32_t xhdi_inquire_target(uint32_t major, uint32_t minor, uint32_t block_size, uint32_t flags,
char *product_name); /* XHDI 1 */
extern uint32_t xhdi_reserve(UINT16_T major, UINT16_T minor, UINT16_T do_reserve, UINT16_T key); /* XHDI 2 */
extern uint32_t xhdi_lock(UINT16_T major, UINT16_T minor, UINT16_T do_lock, UINT16_T key); /* XHDI 3 */
extern uint32_t xhdi_stop(UINT16_T major, UINT16_T minor, UINT16_T do_lock, UINT16_T key); /* XHDI 4 */
extern uint32_t xhdi_eject(UINT16_T major, UINT16_T minor, UINT16_T do_eject, UINT16_T key); /* XHDI 5 */
extern uint32_t xhdi_drivemap(void); /* XHDI 6 */
extern uint32_t xhdi_inquire_device(UINT16_T bios_device, UINT16_T *major, UINT16_T *minor,
uint32_t *start_sector, /* BPB */ void *bpb); /* XHDI 7 */
extern uint32_t xhdi_inquire_driver(UINT16_T bios_device, char *name, char *version,
char *company, UINT16_T *ahdi_version, UINT16_T *maxIPL); /* XHDI 8 */
extern uint32_t xhdi_new_cookie(void *newcookie); /* XHDI 9 */
extern uint32_t xhdi_read_write(UINT16_T major, UINT16_T minor, UINT16_T rwflag,
uint32_t recno, UINT16_T count, void *buf); /* XHDI 10 */
extern uint32_t xhdi_inquire_target2(UINT16_T major, UINT16_T minor, uint32_t *block_size,
uint32_t *device_flags, char *product_name, UINT16_T stringlen); /* XHDI 11 */
extern uint32_t xhdi_inquire_device2(UINT16_T bios_device, UINT16_T *major, UINT16_T *minor,
UINT16_T *start_sector, /* BPB */ void *bpb, uint32_t *blocks, char *partid); /* XHDI 12 */
extern uint32_t xhdi_driver_special(uint32_t key1, uint32_t key2, UINT16_T subopcode, void *data); /* XHDI 13 */
extern uint32_t xhdi_get_capacity(UINT16_T major, UINT16_T minor, uint32_t *blocks, uint32_t *bs); /* XHDI 14 */
extern uint32_t xhdi_medium_changed(UINT16_T major, UINT16_T minor); /* XHDI 15 */
extern uint32_t xhdi_mint_info(UINT16_T opcode, void *data); /* XHDI 16 */
extern uint32_t xhdi_dos_limits(UINT16_T which, uint32_t limit); /* XHDI 17 */
extern uint32_t xhdi_last_access(UINT16_T major, UINT16_T minor, uint32_t *ms); /* XHDI 18 */
#endif /* _XHDI_SD_H_ */

118
BaS_gcc/sources/xhdi_sd.c Normal file
View File

@@ -0,0 +1,118 @@
/*
* xhdi_sd.c
*
* Created on: 01.05.2013
* Author: mfro
*/
#include <stdint.h>
#include <stdarg.h>
#include "xhdi_sd.h"
#include "bas_printf.h"
uint32_t xhdi_call(int xhdi_fun, ...)
{
va_list arguments;
va_start(arguments, xhdi_fun);
switch(xhdi_fun)
{
case 0:
return xhdi_version();
break;
case 1:
{
uint16_t major;
uint16_t minor;
uint32_t block_size;
uint32_t flags;
char *product_name;
major = va_arg(arguments, unsigned int);
minor = va_arg(arguments, unsigned int);
block_size = va_arg(arguments, uint32_t);
flags = va_arg(arguments, uint32_t);
product_name = va_arg(arguments, char *);
return xhdi_inquire_target((uint32_t) major, (uint32_t) minor, block_size, flags,
product_name);
}
break;
#ifdef test
case 2:
return xhdi_reserve();
break;
case 3:
return xhdi_lock();
break;
case 4:
return xhdi_stop();
break;
case 5:
return xhdi_eject();
break;
case 6:
return xhdi_drivemap();
break;
case 7:
return xhdi_inquire_device();
break;
case 8:
return xhdi_inquire_driver();
break;
case 9:
return xhdi_new_cookie();
break;
case 10:
return xhdi_read_write();
break;
case 11:
return xhdi_inquire_target2();
break;
case 12:
return xhdi_inquire_device2();
break;
case 13:
return xhdi_driver_special();
break;
case 14:
return xhdi_get_capacity();
break;
case 15:
return xhdi_medium_changed();
break;
case 16:
return xhdi_mint_info();
break;
case 17:
return xhdi_dos_limits();
break;
case 18:
return xhdi_last_access();
break;
#endif
default:
;
}
xprintf("unknown XHDI function %d\r\n");
return -32;
}