From b6b821838ccd39ab4d709b02517f582c91b5c574 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Fr=C3=B6schle?= Date: Mon, 6 May 2013 20:48:39 +0000 Subject: [PATCH] code is a mess currently. I check it in nevertheless since it works a little better than before. Will be cleaned up later. --- BaS_gcc/Makefile | 1 + BaS_gcc/include/xhdi_sd.h | 17 +++++++- BaS_gcc/sources/xhdi_interface.c | 69 ++++++++++++++++---------------- BaS_gcc/sources/xhdi_sd.c | 31 +++++++++++--- 4 files changed, 77 insertions(+), 41 deletions(-) diff --git a/BaS_gcc/Makefile b/BaS_gcc/Makefile index 37982bf..bf87f3c 100644 --- a/BaS_gcc/Makefile +++ b/BaS_gcc/Makefile @@ -144,6 +144,7 @@ $(LIBBAS): $(OBJS) # compile xhdi_interface -mshort to make it callable from (-mshort-compiled) EmuTOS $(OBJDIR)/xhdi_interface.o: CFLAGS += -mshort + # compile printf pc-relative so it can be used as well before and after copy of BaS $(OBJDIR)/bas_printf.o: CFLAGS += -mpcrel # the same for flush_and_invalidate_cache() diff --git a/BaS_gcc/include/xhdi_sd.h b/BaS_gcc/include/xhdi_sd.h index d05190d..114a338 100644 --- a/BaS_gcc/include/xhdi_sd.h +++ b/BaS_gcc/include/xhdi_sd.h @@ -86,13 +86,23 @@ typedef void* (*xhdi_call_fun)(int xhdi_fun, ...); struct XHDICALL_args { - uint16_t opcode; + unsigned int opcode; }; extern unsigned long xhdi_call(struct XHDICALL_args stack); extern xhdi_call_fun xhdi_sd_install(xhdi_call_fun old_vector) __attribute__((__interrupt__)); +/* + * begin of XHDI calls. The following is a little tricky: since those functions can be called by code compiled with -mshort as + * well as from "normal" code, "-mshort"-code needs to be tricked to pass 16-bit values as 32-bit integers. + */ +#if __INT_MAX__ == 32767 +#define uint16_t unsigned long +#define uint32_t unsigned long +#warning -mshort trick activated +#endif /* _MSHORT_ */ + extern uint16_t xhdi_version(void); /* XHDI 0 */ extern uint32_t xhdi_inquire_target(uint16_t major, uint16_t minor, uint32_t *block_size, uint32_t *flags, @@ -139,4 +149,9 @@ extern uint32_t xhdi_last_access(uint16_t major, uint16_t minor, uint32_t *ms); extern uint32_t xhdi_reaccess(uint16_t major, uint16_t minor); /* XHDI 19 */ +/* disarm stack trick */ +#ifdef uint16_t +#undef uint16_t +#undef uint32_t +#endif /* uint16_t */ #endif /* _XHDI_SD_H_ */ diff --git a/BaS_gcc/sources/xhdi_interface.c b/BaS_gcc/sources/xhdi_interface.c index bc1d3ff..d3e0fc3 100644 --- a/BaS_gcc/sources/xhdi_interface.c +++ b/BaS_gcc/sources/xhdi_interface.c @@ -29,9 +29,7 @@ unsigned long xhdi_call(struct XHDICALL_args stack) { - uint16_t opcode = stack.opcode; - - xprintf("xhdi_call(): opcode %d\r\n", opcode); + unsigned int opcode = stack.opcode; switch (opcode) { @@ -43,12 +41,12 @@ unsigned long xhdi_call(struct XHDICALL_args stack) { struct XHINQTARGET_args { - uint16_t opcode; - uint16_t major; - uint16_t minor; - uint32_t *blocksize; - uint32_t *deviceflags; char *productname; + unsigned long *deviceflags; + unsigned long *blocksize; + unsigned int minor; + unsigned int major; + unsigned int opcode; }*args = (struct XHINQTARGET_args *) &stack; return xhdi_inquire_target(args->major, args->minor, args->blocksize, @@ -60,12 +58,12 @@ unsigned long xhdi_call(struct XHDICALL_args stack) { struct XHRESERVE_args { - uint16_t opcode; - uint16_t major; - uint16_t minor; - uint16_t do_reserve; uint16_t key; - }*args = (struct XHRESERVE_args *) &stack; + uint16_t do_reserve; + uint16_t minor; + uint16_t major; + uint16_t opcode; + } *args = (struct XHRESERVE_args *) &stack; return xhdi_reserve(args->major, args->minor, args->do_reserve, args->key); } @@ -121,13 +119,13 @@ unsigned long xhdi_call(struct XHDICALL_args stack) { struct XHINQDEV_args { - uint16_t opcode; - uint16_t drv; - uint16_t *major; - uint16_t *minor; - uint32_t *start; BPB *bpb; - }*args = (struct XHINQDEV_args *) &stack; + unsigned long *start; + unsigned int *minor; + unsigned int *major; + unsigned int drv; + unsigned int opcode; + } *args = (struct XHINQDEV_args *) &stack; return xhdi_inquire_device(args->drv, args->major, args->minor, args->start, args->bpb); @@ -137,13 +135,13 @@ unsigned long xhdi_call(struct XHDICALL_args stack) { struct XHINQDRIVER_args { - uint16_t opcode; - uint16_t dev; - char *name; - char *version; - char *company; - uint16_t *ahdi_version; uint16_t *maxIPL; + uint16_t *ahdi_version; + char *company; + char *version; + char *name; + uint16_t dev; + uint16_t opcode; }*args = (struct XHINQDRIVER_args *) &stack; return xhdi_inquire_driver(args->dev, args->name, args->version, args->company, @@ -154,8 +152,8 @@ unsigned long xhdi_call(struct XHDICALL_args stack) { struct XHNEWCOOKIE_args { + unsigned long newcookie; uint16_t opcode; - uint32_t newcookie; }*args = (struct XHNEWCOOKIE_args *) &stack; return xhdi_new_cookie(args->newcookie); @@ -165,17 +163,18 @@ unsigned long xhdi_call(struct XHDICALL_args stack) { struct XHREADWRITE_args { - uint16_t opcode; - uint16_t major; - uint16_t minor; - uint16_t rw; - uint32_t sector; - uint16_t count; void *buf; - }*args = (struct XHREADWRITE_args *) &stack; + unsigned int count; + unsigned long sector; + unsigned int rw; + unsigned int minor; + unsigned int major; + unsigned int opcode; + } *args = (struct XHREADWRITE_args *) &stack; - return xhdi_read_write(args->major, args->minor, args->rw, args->sector, - args->count, args->buf); + return xhdi_read_write((unsigned long) args->major, (unsigned long) args->minor, + (unsigned long) args->rw, args->sector, + (unsigned long) args->count, (unsigned long) args->buf); } case XHDI_INQUIRE_TARGET2: diff --git a/BaS_gcc/sources/xhdi_sd.c b/BaS_gcc/sources/xhdi_sd.c index 5888827..0f5f99d 100644 --- a/BaS_gcc/sources/xhdi_sd.c +++ b/BaS_gcc/sources/xhdi_sd.c @@ -25,6 +25,7 @@ #include "xhdi_sd.h" #include "bas_printf.h" +#include "bas_string.h" #define DRIVER_VERSION 0x130 @@ -36,6 +37,7 @@ static xhdi_call_fun old_vector = NULL; __attribute__((__interrupt__)) xhdi_call_fun xhdi_sd_install(xhdi_call_fun ov) { old_vector = ov; + uint32_t *_drvbits = (uint32_t *) 0x4c2; __asm__ __volatile__ ( "move.l %[xhdi_call],d1\n\t" @@ -44,6 +46,7 @@ __attribute__((__interrupt__)) xhdi_call_fun xhdi_sd_install(xhdi_call_fun ov) : [xhdi_call]"g"(xhdi_call) : "d1","memory"); + *_drvbits |= (uint32_t) 1 << ('S' - 'A'); /* * this is just to make the compiler happy, the return value is overwritten anyway. Therefore we previously overwrite * the saved register value on the stack so everything is as we want it to be @@ -112,8 +115,20 @@ uint32_t xhdi_inquire_device(uint16_t bios_device, uint16_t *major, uint16_t *mi uint32_t xhdi_inquire_driver(uint16_t bios_device, char *name, char *version, char *company, uint16_t *ahdi_version, uint16_t *maxIPL) { - xprintf("xhdi_inquire_driver() called\r\n"); - return ERROR; + xprintf("xhdi_inquire_driver() called. bios_device = %x, name = %p, version = %p,\r\n" + "company = %p, ahdi_version = %p, max_IPL = %p\r\n", + bios_device, name, version, company, ahdi_version, maxIPL); + if (bios_device == 'S' - 'A') + { + if (name != NULL) strcpy(name, "BaS SD-card driver"); + if (version != NULL) strcpy(version, "0.1"); + if (company != NULL) strcpy(company, "Markus Fröschle"); + if (ahdi_version != NULL) *ahdi_version = 300; + if (maxIPL != NULL) *maxIPL = 7; + + return E_OK; + } + return EUNDEV; } uint32_t xhdi_new_cookie(uint32_t newcookie) @@ -125,8 +140,9 @@ uint32_t xhdi_new_cookie(uint32_t newcookie) uint32_t xhdi_read_write(uint16_t major, uint16_t minor, uint16_t rwflag, uint32_t recno, uint16_t count, void *buf) { - xprintf("xhdi_read_write() called\r\n"); - return ERROR; + xprintf("xhdi_read_write() called: major = %x, minor = %x, rwflag = %x, \r\nrecno = %lx, count = %lx, buf = %p\r\n", + major, minor, rwflag, recno, count, buf); + return EUNDEV; } uint32_t xhdi_inquire_target2(uint16_t major, uint16_t minor, uint32_t *block_size, @@ -140,7 +156,12 @@ uint32_t xhdi_inquire_device2(uint16_t bios_device, uint16_t *major, uint16_t *m uint32_t *start_sector, BPB *bpb, uint32_t *blocks, char *partid) { xprintf("xhdi_inquire_device2() called\r\n"); - return ERROR; + + if (bios_device == 'S' - 'A') + { + return E_OK; + } + return EUNDEV; } uint32_t xhdi_driver_special(uint32_t key1, uint32_t key2, uint16_t subopcode, void *data)