Bladeren bron

posixfs, various rpi fixes

mntmn 9 jaren geleden
bovenliggende
commit
95438268ea

+ 74 - 0
devices/posixfs.c

@@ -0,0 +1,74 @@
+#include <stdio.h>
+#include "minilisp.h"
+#include "alloc.h"
+#include "stream.h"
+#include "compiler_new.h"
+#include <sys/mman.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+Cell* _file_cell;
+
+Cell* posixfs_open(Cell* cpath) {
+  _file_cell = alloc_nil();
+
+  if (!cpath || cpath->tag!=TAG_STR) {
+    printf("[posixfs] open error: non-string path given\r\n");
+    return _file_cell;
+  }
+
+  char* path = cpath->addr;
+  
+  if (!strncmp(path,"/sd/",4)) {
+    char* name = NULL;
+    char* filename = NULL;
+
+    if (strlen(path)>4) {
+      filename = path+4;
+    }
+    
+    if (filename) {
+      FILE* f = fopen(filename, "rb");
+      if (f) {
+        fseek(f, 0L, SEEK_END);
+        int len = ftell(f);
+        fseek(f, 0L, SEEK_SET);
+        
+        printf("[posixfs] trying to read file of len %d…\r\n",len);
+        Cell* res = alloc_num_string(len);
+        int read_len = fread(res->addr, len, 1, f);
+        // TODO: close?
+        _file_cell = res;
+        return res;
+      } else {
+        // TODO should return error
+        printf("FAT could not open file :(\r\n");
+        _file_cell = alloc_string_copy("<error: couldn't open file.>"); // FIXME hack
+        return _file_cell;
+      }
+      _file_cell = alloc_string_copy("<error: file not found.>");
+      return _file_cell;
+    } else {
+      // TODO dir
+    }
+  }
+
+  return _file_cell;
+}
+
+Cell* posixfs_read(Cell* stream) {
+  return _file_cell;
+}
+
+Cell* posixfs_write(Cell* arg) {
+  return NULL;
+}
+
+Cell* posixfs_mmap(Cell* arg) {
+  return alloc_nil();
+}
+
+void mount_posixfs() {
+  fs_mount_builtin("/sd", posixfs_open, posixfs_read, posixfs_write, 0, posixfs_mmap);
+}
+

+ 9 - 39
devices/rpi2/arm_start.S

@@ -1,35 +1,10 @@
 .global _start
 .global _get_stack_pointer
+.global DelayLoop  
 
 // https://github.com/dwelch67/raspberrypi/blob/master/float02/vectors.s
 
 _start:
-  ldr pc,reset_handler
-  ldr pc,undefined_handler
-  ldr pc,swi_handler
-  ldr pc,prefetch_handler
-  ldr pc,=data_handler
-  ldr pc,unused_handler
-  ldr pc,irq_handler
-  ldr pc,fiq_handler
-reset_handler:      .word reset
-undefined_handler:  .word undef
-swi_handler:        .word hang
-prefetch_handler:   .word hang
-data_handler:       .word hang
-unused_handler:     .word hang
-irq_handler:        .word hang
-fiq_handler:        .word hang
-
-reset:
-  // copy vectors to #0000
-  mov r0,#0x8000
-  mov r1,#0x0000
-  ldmia r0!,{r2,r3,r4,r5,r6,r7,r8,r9}
-  stmia r1!,{r2,r3,r4,r5,r6,r7,r8,r9}
-  ldmia r0!,{r2,r3,r4,r5,r6,r7,r8,r9}
-  stmia r1!,{r2,r3,r4,r5,r6,r7,r8,r9}
-
   // init stack
   ldr     sp, =stack_top
   sub     sp, sp, #0x4
@@ -51,11 +26,11 @@ reset:
 	mov r0,#0x40000000
 	fmxr FPEXC, r0
 
-  // enable unaligned access
-  /*mrc p15, #0, r0, c1, c0, #0
+  // enable unaligned access (doesn't seem to work on rpi2)
+  mrc p15, #0, r0, c1, c0, #0
   bic r0, r0, #2 // clear A bit
   orr r0, #0x400000         // 1<<22 set U bit
-	mcr p15, #0, r0, c1, c0, #0*/
+	mcr p15, #0, r0, c1, c0, #0
   
 	// jump to kernel_main
 	ldr r3, =_cstartup
@@ -70,16 +45,11 @@ _get_stack_pointer:
   ldr     r0, [sp]
   mov     pc, lr
 
-hang:
-    b hang
-    .word 0
-    .word 0
-
-undef:
-    b .
-    .word 0
-    .word 0
-
+DelayLoop:
+	subs	r0, r0, #1
+	bhi	DelayLoop
+	mov	pc, lr
+  
 // constants for ldr macro
 constants:
 .ltorg

+ 28 - 47
devices/rpi2/main_rpi2.c

@@ -76,11 +76,11 @@ void main()
   memset(FB, 0xff, 1920*1080*2);
   
   // uspi glue
-  //printf("uu uspi glue init…\r\n");
-  //extern void uspi_glue_init();
-  //uspi_glue_init();
+  printf("uu uspi glue init…\r\n");
+  extern void uspi_glue_init();
+  uspi_glue_init();
 
-  /*printf("uu USPiInitialize…\r\n");
+  printf("uu USPiInitialize…\r\n");
   int res = USPiInitialize();
   printf("uu USPI initialization: %d\r\n", res);
   
@@ -93,11 +93,11 @@ void main()
   have_eth = USPiEthernetAvailable();
   printf("uu USPI has ethernet: %d\r\n", have_eth);
 
-  eth_rx_buffer=malloc(64*1024);*/
+  //eth_rx_buffer=malloc(64*1024);*/
   
   libfs_init();
   
-  memset(FB, 0x44, 1920*1080*2);
+  memset(FB, 0x40, 1920*1080*2);
   
   uart_repl();
 }
@@ -265,31 +265,6 @@ int machine_get_key(int modifiers) {
   return k;
 }
 
-/*
-Cell* machine_poll_udp() {
-  return NULL;
-}
-
-Cell* machine_send_udp(Cell* data_cell) {
-  return NULL;
-}
-
-Cell* machine_connect_tcp(Cell* host_cell, Cell* port_cell, Cell* connected_fn_cell, Cell* data_fn_cell) {
-  return NULL;
-}
-
-Cell* machine_bind_tcp(Cell* port_cell, Cell* fn_cell) {
-  return NULL;
-}
-
-Cell* machine_send_tcp(Cell* data_cell) {
-  return NULL;
-  }*/
-
-Cell* machine_save_file(Cell* cell, char* path) {
-  return alloc_int(0);
-}
-
 typedef jit_word_t (*funcptr)();
 
 Cell* platform_eval_string(Cell* strc); // FIXME
@@ -337,17 +312,14 @@ Cell* platform_eval_string(Cell* strc); // FIXME
   init_mini_ip(udp_cell);
   }*/
 
-void data_handler() {
-  uart_puts("~~ data abort!\r\n");
-}
-
 #define CODESZ 4096
+#define REPLBUFSZ 1024*6
 
 void uart_repl() {
   uart_puts("~~ trying to malloc repl buffers\r\n");
-  char* out_buf = malloc(1024*10);
-  char* in_line = malloc(1024*2);
-  char* in_buf = malloc(1024*10);
+  char* out_buf = malloc(REPLBUFSZ);
+  char* in_line = malloc(REPLBUFSZ);
+  char* in_buf = malloc(REPLBUFSZ);
   uart_puts("\r\n\r\n++ welcome to sledge arm/32 (c)2015 mntmn.\r\n");
   
   init_compiler();
@@ -357,9 +329,9 @@ void uart_repl() {
   
   uart_puts("\r\n~~ fs initialized.\r\n");
   
-  memset(out_buf,0,1024*10);
-  memset(in_line,0,1024*2);
-  memset(in_buf,0,1024*10);
+  memset(out_buf,0,REPLBUFSZ);
+  memset(in_line,0,REPLBUFSZ);
+  memset(in_buf,0,REPLBUFSZ);
 
   long count = 0;  
   int fullscreen = 0;
@@ -374,8 +346,8 @@ void uart_repl() {
 
   //strcpy(in_line,"(eval (load \"/sd/boot.l\"))\n");
   
-  r3d_init(FB);
-  uart_puts("-- R3D initialized.\r\n");
+  //r3d_init(FB);
+  //uart_puts("-- R3D initialized.\r\n");
   
   while (1) {
     expr = NULL;
@@ -384,7 +356,7 @@ void uart_repl() {
 
     int i = 0;
 
-    while (c!=13) {
+    while (c!=13 && i<(REPLBUFSZ-1)) {
       c = uart_getc();
       uart_putc(c);
       in_line[i++] = c;
@@ -392,7 +364,7 @@ void uart_repl() {
     }
     c = 0;
     
-    int len = strlen(in_line);
+    int len = strnlen(in_line,REPLBUFSZ);
 
     // recognize parens
     
@@ -429,13 +401,18 @@ void uart_repl() {
       memset(code, 0, CODESZ);
       jit_init(512);
       register void* sp asm ("sp"); // FIXME maybe unportable
+      printf("frame sp %p\r\n",sp);
+      
       Frame empty_frame = {NULL, 0, 0, sp};
       int tag = compile_expr(expr, &empty_frame, TAG_ANY);
       jit_ret();
 
-      if (tag) {
+      if (tag>0) {
         funcptr fn = (funcptr)code;
+        printf("fn at %p\r\n",fn);
+        __asm("stmfd sp!, {r5-r12, lr}"); // FIXME put in jit
         res = (Cell*)fn();
+        __asm("ldmfd sp!, {r5-r12, lr}");
         success = 1;
       }
 
@@ -443,7 +420,7 @@ void uart_repl() {
         if (!res) {
           uart_puts("null\n");
         } else {
-          lisp_write(res, out_buf, 1024*10);
+          lisp_write(res, out_buf, REPLBUFSZ);
           uart_puts(out_buf);
         }
       }
@@ -501,7 +478,11 @@ Cell* platform_eval_string(Cell* strc) {
             jit_ret();
             if (tag) {
               funcptr fn = (funcptr)code;
+              printf("fn at %p\r\n",fn);
+              
+              __asm("stmfd sp!, {r5-r12, lr}");
               res = (Cell*)fn();
+              __asm("ldmfd sp!, {r5-r12, lr}");
               //success = 1;
             }
           }

+ 1 - 1
devices/rpi2/uspi/env/include/uspienv/sysconfig.h

@@ -37,7 +37,7 @@
 #define MEM_KERNEL_START	0x8000
 //#define MEM_KERNEL_END		(MEM_KERNEL_START + KERNEL_MAX_SIZE)
 //#define MEM_KERNEL_STACK	(MEM_KERNEL_END + KERNEL_STACK_SIZE)		// expands down
-#define MEM_ABORT_STACK	(256 * MEGABYTE)	// expands down
+#define MEM_ABORT_STACK	(511 * MEGABYTE)	// expands down FIXME
 #define MEM_IRQ_STACK		(512 * MEGABYTE)	// expands down
 //#define MEM_PAGE_TABLE1		MEM_IRQ_STACK				// must be 16K aligned
 

+ 7 - 5
devices/rpi2/uspi/env/lib/exceptionhandler.c

@@ -43,7 +43,7 @@ void ExceptionHandler2 (TExceptionHandler *pThis)
 	assert (s_pThis == 0);
 	s_pThis = pThis;
 
-	TExceptionTable *pTable = (TExceptionTable *) ARM_EXCEPTION_TABLE_BASE;
+	TExceptionTable *pTable = (TExceptionTable *) ARM_EXCEPTION_TABLE_BASE; // #0000
 
 	pTable->UndefinedInstruction = ARM_OPCODE_BRANCH (ARM_DISTANCE (
 					pTable->UndefinedInstruction, UndefinedInstructionStub));
@@ -104,18 +104,20 @@ void ExceptionHandlerThrow2 (TExceptionHandler *pThis, unsigned nException, TAbo
 
 	if ((pFrame->spsr & 0x1F) == 0x12)	// IRQ mode?
 	{
+    printf("irq mode!\r\n");
 		lr = pFrame->lr_irq;
 		sp = pFrame->sp_irq;
 	}
 	
-#ifndef NDEBUG
-	debug_stacktrace ((u32 *) sp, FromExcept);
-#endif
 
-	printf ("%s (PC 0x%X, FSR 0x%X, FAR 0x%X, SP 0x%X, LR 0x%X, PSR 0x%X)",
+	printf ("%s (PC 0x%X, FSR 0x%X, FAR 0x%X, SP 0x%X, LR 0x%X, PSR 0x%X)\r\n",
 		s_pExceptionName[nException],
 		pFrame->pc, FSR, FAR,
 		sp, lr, pFrame->spsr);
+
+  printf("instruction: 0x%X\r\n",*((u32*)pFrame->pc));
+
+	debug_stacktrace ((u32 *) sp, FromExcept);
 }
 
 TExceptionHandler *ExceptionHandlerGet (void)

+ 1 - 1
devices/rpi2/uspi/env/lib/exceptionstub.S

@@ -24,7 +24,7 @@
 
 	.globl	\name
 \name:
-	mov	sp, #MEM_ABORT_STACK
+	ldr	sp, =MEM_ABORT_STACK
 	sub	lr, lr, #\pc_offset		/* lr: correct PC of aborted program */
 	stmfd	sp!, {lr}			/* store PC onto stack */
 	mrs	lr, spsr			/* lr can be overwritten now */

+ 13 - 15
devices/rpi2/uspi/env/lib/timer.c

@@ -34,7 +34,7 @@ void TimerTuneMsDelay (TTimer *pThis);
 
 static TTimer *s_pThis = 0;
 
-void Timer (TTimer *pThis, TInterruptSystem *pInterruptSystem)
+void Timer(TTimer *pThis, TInterruptSystem *pInterruptSystem)
 {
 	assert (pThis != 0);
 
@@ -70,20 +70,20 @@ boolean TimerInitialize (TTimer *pThis)
 
 	assert (pThis->m_pInterruptSystem != 0);
   printf(".. InterruptSystemConnectIRQ\r\n");
-	InterruptSystemConnectIRQ (pThis->m_pInterruptSystem, ARM_IRQ_TIMER3, TimerInterruptHandler, pThis);
+	InterruptSystemConnectIRQ(pThis->m_pInterruptSystem, ARM_IRQ_TIMER3, TimerInterruptHandler, pThis);
 
-	DataMemBarrier ();
+	DataMemBarrier();
 
   printf(".. ARM_SYSTIMER_CLO\r\n");
-	write32 (ARM_SYSTIMER_CLO, -(30 * CLOCKHZ));	// timer wraps soon, to check for problems
+	write32(ARM_SYSTIMER_CLO, -(30 * CLOCKHZ));	// timer wraps soon, to check for problems
 
   printf(".. ARM_SYSTIMER_C3\r\n");
-	write32 (ARM_SYSTIMER_C3, read32 (ARM_SYSTIMER_CLO) + CLOCKHZ / HZ);
+	write32(ARM_SYSTIMER_C3, read32 (ARM_SYSTIMER_CLO) + CLOCKHZ / HZ);
 	
   printf(".. TimerTuneMsDelay\r\n");
-	TimerTuneMsDelay (pThis);
+	TimerTuneMsDelay(pThis);
 
-	DataMemBarrier ();
+	DataMemBarrier();
 
 	return TRUE;
 }
@@ -216,13 +216,13 @@ void TimerusDelay (TTimer *pThis, unsigned nMicroSeconds)
 	}
 }
 
-TTimer *TimerGet (void)
+TTimer *TimerGet(void)
 {
 	assert (s_pThis != 0);
 	return s_pThis;
 }
 
-void TimerSimpleMsDelay (unsigned nMilliSeconds)
+void TimerSimpleMsDelay(unsigned nMilliSeconds)
 {
 	if (nMilliSeconds > 0)
 	{
@@ -230,21 +230,19 @@ void TimerSimpleMsDelay (unsigned nMilliSeconds)
 	}
 }
 
-void TimerSimpleusDelay (unsigned nMicroSeconds)
+void TimerSimpleusDelay(unsigned nMicroSeconds)
 {
 	if (nMicroSeconds > 0)
 	{
 		unsigned nTicks = nMicroSeconds * (CLOCKHZ / 1000000);
 
-		DataMemBarrier ();
+		DataMemBarrier();
 
-		unsigned nStartTicks = read32 (ARM_SYSTIMER_CLO);
-		while (read32 (ARM_SYSTIMER_CLO) - nStartTicks < nTicks)
+		unsigned nStartTicks = read32(ARM_SYSTIMER_CLO);
+		while (read32(ARM_SYSTIMER_CLO) - nStartTicks < nTicks)
 		{
 			// do nothing
 		}
-
-		DataMemBarrier ();
 	}
 }
 

+ 2 - 2
devices/rpi2/uspi_glue.c

@@ -183,9 +183,9 @@ static TTimer uspi_timer;
 
 void uspi_glue_init() {
   printf("uu ExceptionHandler2…\r\n");
-  ExceptionHandler2 (&uspi_exception_handler);
+  ExceptionHandler2(&uspi_exception_handler);
   printf("uu InterruptSystem…\r\n");
-	InterruptSystem (&uspi_interrupts);
+	InterruptSystem(&uspi_interrupts);
   printf("uu InterruptSystemInitialize…\r\n");
   InterruptSystemInitialize(&uspi_interrupts);
   printf("uu Timer…\r\n");

+ 1 - 3
rpi2-build.sh

@@ -3,7 +3,7 @@
 # -mtune=cortex-a7 -mfpu=neon-vfpv4  -ftree-vectorize
 
 NEWLIB="/usr/lib/arm-none-eabi/newlib"
-
+# -fcall-saved-r1 -fcall-saved-r2 -fcall-saved-r3 
 set -e
 GCC_OPTS=" -g -O2 -nostartfiles -nostdlib -mhard-float -ffreestanding -mno-unaligned-access -fno-toplevel-reorder -mcpu=cortex-a7 -mfpu=neon-vfpv4 -std=gnu11 -L$NEWLIB/fpu -I./sledge -I. -I/usr/include/newlib -Idevices/rpi2/uspi/env/include/ -DCPU_ARM "
 
@@ -34,7 +34,6 @@ $COMPILE -c -o obj/interrupt.o        devices/rpi2/uspi/env/lib/interrupt.c
 $COMPILE -c -o obj/memio.o            devices/rpi2/uspi/env/lib/memio.c
 $COMPILE -c -o obj/assert.o           devices/rpi2/uspi/env/lib/assert.c
 $COMPILE -c -o obj/bcmpropertytags.o  devices/rpi2/uspi/env/lib/bcmpropertytags.c
-$COMPILE -c -o obj/delayloop.o        devices/rpi2/uspi/env/lib/delayloop.S
 $COMPILE -c -o obj/bcmmailbox.o       devices/rpi2/uspi/env/lib/bcmmailbox.c
 $COMPILE -c -o obj/exceptionstub.o    devices/rpi2/uspi/env/lib/exceptionstub.S
 $COMPILE -c -o obj/exceptionhandler.o devices/rpi2/uspi/env/lib/exceptionhandler.c
@@ -61,7 +60,6 @@ $COMPILE -o build/interim-arm.elf -T devices/rpi2/arm.ld devices/rpi2/arm_start.
          obj/memio.o\
          obj/assert.o\
          obj/bcmpropertytags.o\
-         obj/delayloop.o\
          obj/bcmmailbox.o\
          obj/exceptionstub.o\
          obj/exceptionhandler.o\

+ 1 - 0
sledge/alloc.c

@@ -427,6 +427,7 @@ Cell* alloc_error(unsigned int code) {
 
 Cell* alloc_clone(Cell* orig) {
   if (!orig) return 0;
+
   Cell* clone = cell_alloc();
   clone->tag  = orig->tag;
   clone->addr = 0;

+ 1 - 1
sledge/build_rpi.sh

@@ -1,3 +1,3 @@
 
-gcc -g -o sledge --std=gnu99 -I. sledge.c reader.c writer.c alloc.c strmap.c stream.c ../devices/linux/dev_linuxfb.c -lm -DCPU_ARM -DDEV_LINUXFB
+gcc -g -o sledge --std=gnu99 -I. sledge.c reader.c writer.c alloc.c strmap.c stream.c ../devices/posixfs.c ../devices/linux/dev_linuxfb.c -lm -DCPU_ARM -DDEV_LINUXFB -DDEV_POSIXFS
 

+ 27 - 15
sledge/compiler_new.c

@@ -26,7 +26,7 @@ Cell* insert_symbol(Cell* symbol, Cell* cell, env_t** env) {
   
   if (found) {
     e->cell = cell;
-    //printf("[insert_symbol] update %s entry at %p (cell: %p value: %d)\r\n",symbol->addr,e,e->cell,e->cell->value);
+    printf("[insert_symbol] update %s entry at %p (cell: %p value: %d)\r\n",symbol->addr,e,e->cell,e->cell->value);
     return e->cell;
   }
     
@@ -44,6 +44,7 @@ Cell* insert_global_symbol(Cell* symbol, Cell* cell) {
   return insert_symbol(symbol, cell, &global_env);
 }
 
+// register used for passing args to functions
 #define LBDREG R4
 
 static FILE* jit_out;
@@ -271,6 +272,7 @@ int compile_expr(Cell* expr, Frame* frame, int return_type) {
       if (env) {
         Cell* value = env->cell;
         jit_movi(R0,(jit_word_t)value);
+        return value->tag;
       } else {
         printf("undefined symbol %s\n",expr->addr);
         jit_movi(R0,0);
@@ -361,6 +363,8 @@ int compile_expr(Cell* expr, Frame* frame, int return_type) {
           frame->sp+=(1+argi-1);
         }
         given_tag = compile_expr(arg, frame, signature_arg->value);
+        if (given_tag<1) return given_tag; // failure
+        
         argdefs[argi].cell = NULL; // cell is in R0 at runtime
         argdefs[argi].slot = argi;
 
@@ -510,7 +514,9 @@ int compile_expr(Cell* expr, Frame* frame, int return_type) {
       }
       jit_lea(ARGR0,argdefs[0].cell); // load symbol address
       
+      push_frame_regs(frame->f);
       jit_call(insert_global_symbol, "insert_global_symbol");
+      pop_frame_regs(frame->f);
       break;
     }
     case BUILTIN_LET: {
@@ -588,7 +594,8 @@ int compile_expr(Cell* expr, Frame* frame, int return_type) {
       jit_dec_stack(num_lets*PTRSZ);
       
       Frame nframe = {fn_new_frame, 0, 0, frame->stack_end};
-      compile_expr(fn_body, &nframe, TAG_ANY); // new frame, fresh sp
+      int tag = compile_expr(fn_body, &nframe, TAG_ANY); // new frame, fresh sp
+      if (!tag) return 0;
 
       printf(">> fn has %d args and %d locals. predicted locals: %d\n",fn_argc,nframe.locals,num_lets);
       
@@ -618,7 +625,8 @@ int compile_expr(Cell* expr, Frame* frame, int return_type) {
       jit_cmpi(R1,0);
       jit_je(label_skip);
 
-      compile_expr(argdefs[1].cell, frame, return_type);
+      int tag = compile_expr(argdefs[1].cell, frame, return_type);
+      if (!tag) return 0;
 
       // else?
       if (argdefs[2].cell) {
@@ -627,7 +635,9 @@ int compile_expr(Cell* expr, Frame* frame, int return_type) {
         jit_jmp(label_end);
         
         jit_label(label_skip);
-        compile_expr(argdefs[2].cell, frame, return_type);
+        tag = compile_expr(argdefs[2].cell, frame, return_type);
+        if (!tag) return 0;
+        
         jit_label(label_end);
       } else {
         jit_label(label_skip);
@@ -645,6 +655,8 @@ int compile_expr(Cell* expr, Frame* frame, int return_type) {
       jit_label(label_loop);
       
       int compiled_type = compile_expr(argdefs[0].cell, frame, TAG_INT);
+      if (!compiled_type) return 0;
+      
       if (compiled_type != TAG_INT) {
         jit_ldr(R0);
         jit_cmpi(R0,0);
@@ -655,7 +667,8 @@ int compile_expr(Cell* expr, Frame* frame, int return_type) {
       // compare to zero
       jit_je(label_skip);
 
-      compile_expr(argdefs[1].cell, frame, return_type);
+      int tag = compile_expr(argdefs[1].cell, frame, return_type);
+      if (!tag) return 0;
 
       jit_jmp(label_loop);
       jit_label(label_skip);
@@ -752,8 +765,8 @@ int compile_expr(Cell* expr, Frame* frame, int return_type) {
       char label_skip[64];
       sprintf(label_skip,"skip_%d",++label_skip_count);
 
-      jit_movi(R1,0);    
-      load_cell(R3,argdefs[0], frame);
+      jit_movi(R3,0);    
+      load_cell(R1,argdefs[0], frame);
       load_int(R2,argdefs[1], frame); // offset -> R2
       //jit_cmpi(R2,0);
       //jit_jneg(label_skip); // negative offset?
@@ -767,13 +780,13 @@ int compile_expr(Cell* expr, Frame* frame, int return_type) {
       //jit_je(label_skip); // overflow? (R2==R0)
 
       //jit_movr(R1,R2);
-      jit_ldr(R3); // string address
-      jit_addr(R1,R3);
-      jit_ldrb(R1);
+      jit_ldr(R1); // string address
+      jit_addr(R1,R2);
+      jit_ldrb(R1); // data in r3
 
       //jit_label(label_skip);
       
-      jit_movr(ARGR0, R1);
+      jit_movr(ARGR0, R3);
       jit_call(alloc_int,"alloc_int");
       break;
     }
@@ -784,12 +797,13 @@ int compile_expr(Cell* expr, Frame* frame, int return_type) {
       //sprintf(label_noskip,"noskip_%d",label_skip_count);
     
       load_cell(R1,argdefs[0], frame);
+      jit_movr(R0,R1);
       //jit_push(R1,R1);
       //frame->sp++;
       load_int(R2,argdefs[1], frame); // offset -> R2
+      load_int(R3,argdefs[2], frame); // byte to store -> R3
       //jit_cmpi(R2,0);
       //jit_jneg(label_skip); // negative offset?
-      load_int(R3,argdefs[2], frame); // byte to store -> R3
 
       //jit_movr(R0,R1);
       //jit_addi(R0,PTRSZ); // fetch size -> R0
@@ -801,10 +815,8 @@ int compile_expr(Cell* expr, Frame* frame, int return_type) {
 
       jit_ldr(R1); // string address
       jit_addr(R1,R2);
-      jit_strb(R1); // strb is always from R3
+      jit_strb(R1); // address is in r1, data in r3
 
-      jit_movr(R0,R1);
-      
       //jit_jmp(label_noskip);
       
       //jit_label(label_skip);

+ 4 - 4
sledge/jit_arm_raw.c

@@ -164,8 +164,8 @@ void jit_ldrw(int reg) {
 void jit_ldrb(int reg) {
   uint32_t op = 0xe5900000;
   op |= 1<<22; // byte access
-  op |= (3<<16); // r3
-  op |= (reg<<12); // dreg
+  op |= (reg<<16); // r3
+  op |= (3<<12); // dreg
   code[code_idx++] = op;
 }
 
@@ -173,8 +173,8 @@ void jit_ldrb(int reg) {
 void jit_strb(int reg) {
   uint32_t op = 0xe5800000;
   op |= 1<<22; // byte access
-  op |= (3<<16); // r3
-  op |= (reg<<12); // dreg
+  op |= (reg<<16); // r3
+  op |= (3<<12); // dreg
   code[code_idx++] = op;
 }
 

+ 5 - 0
sledge/sledge.c

@@ -44,6 +44,11 @@ int main(int argc, char *argv[])
   void mount_linux_fbfs();
   mount_linux_fbfs();
 #endif
+
+#ifdef DEV_POSIXFS
+  void mount_posixfs();
+  mount_posixfs();
+#endif
   
   while (1) {
     expr = NULL;

+ 6 - 5
sledge/tests/font.l

@@ -11,6 +11,7 @@
 (def blit-char (fn rune x y (do
   (let sx (* (+ 2 (% rune 256)) 16))
   (let sy (* (+ 4 (/ rune 256)) 16))
+  (print (cons sx sy))
   (let so (+ (* sx 2) (* sy unifont-pitch)))
   (let do (+ (*  x 2) (*  y screen-pitch)))
   (let iy 0)
@@ -18,13 +19,13 @@
   (while (lt iy 16) (do
     (let ix 0)
     (while (lt ix 32) (do
-      (let c (get32 unifont (+ so ix)))
-      (put32 fb (+ do ix) c)
+      (let c (get unifont (+ so ix)))
+      (put fb (+ do ix) c)
+      (put fb (+ (+ do ix) 1) c)
       (let ix (+ ix 2))
     ))
-    (let so (- (+ so unifont-pitch) 16))
-    (let do (- (+ do screen-pitch) 16))
+    (let so (+ so unifont-pitch))
+    (let do (+ do screen-pitch))
     (let iy (+ iy 1))
   ))
 )))
-