Browse Source

Merge remote-tracking branch 'mntmn/master'

Devine Lu Linvega 5 years ago
parent
commit
3b97f48348
6 changed files with 51 additions and 24 deletions
  1. 2 2
      README.md
  2. 33 12
      devices/sdl.c
  3. 5 5
      docs/what_i_learned.md
  4. 7 2
      sledge/compiler_new.c
  5. 2 1
      sledge/minilisp.h
  6. 2 2
      sledge/writer.c

+ 2 - 2
README.md

@@ -60,9 +60,9 @@ To launch the graphical REPL/Shell:
 Running (Raspberry Pi 2)
 ------------------------
 
-Prepare a bootable SD card with the usual FAT partition that has the Pi-specific boot blobs in it and copy ````kernel.img```` into it. You can recycle any other Raspberry OS distribution, i.e. Raspian for this. Just replace the kernel7.img and delete cmdline.txt. Keyboard input is currently only over UART, so you will probably want to connect a UART->USB cable to another computer and use it to control Interim. 
+Prepare a bootable SD card with the usual FAT partition that has the Pi-specific boot blobs in it and copy ````kernel.img```` into it. You can recycle any other Raspberry OS distribution, i.e. Raspbian for this. Just replace the kernel7.img and delete cmdline.txt. Keyboard input is currently only over UART, so you will probably want to connect a UART->USB cable to another computer and use it to control Interim. 
 
-![Interim OS Screenshot](http://dump.mntmn.com/interim-paper/illustrations/interim-picture.jpg)
+![Interim OS Screenshot](http://dump.mntmn.com/interim-paper/illustrations/interim-picture.jpg?wat=1)
 
 Roadmap
 -------

+ 33 - 12
devices/sdl.c

@@ -5,11 +5,11 @@
 #include "stream.h"
 #include "compiler_new.h"
 
-#define WIDTH 1920
-#define HEIGHT 1080
+#define WIDTH 800
+#define HEIGHT 600
 #define BPP 2
-#define DEPTH 16
-#define SCALE 2
+#define DEPTH 8*BPP
+#define SCALE 1
 
 SDL_Surface* screen;
 uint8_t* pixels = NULL;
@@ -24,6 +24,8 @@ void* sdl_init(int fullscreen)
 {
   if (sdl_initialized) return screen->pixels;
 
+  sdl_initialized = 1;
+
   SDL_Init(SDL_INIT_VIDEO);
   screen = SDL_SetVideoMode(WIDTH, HEIGHT, DEPTH, SDL_SWSURFACE);
 
@@ -64,8 +66,27 @@ Cell* fbfs_open() {
   return alloc_int(1);
 }
 
-Cell* fbfs_read() {
-  return alloc_int(0);
+Cell* fbfs_read(Cell* stream) {
+  Stream* s = (Stream*)stream->ar.addr;
+  char* path = s->path->ar.addr;
+  if (!strcmp(path+12,"/width")) {
+    return alloc_int(WIDTH);
+  }
+  else if (!strcmp(path+12,"/height")) {
+    return alloc_int(HEIGHT);
+  }
+  else if (!strcmp(path+12,"/depth")) {
+    return alloc_int(BPP);
+  }
+  else if (!strcmp(path+12,"/")) {
+    return
+      alloc_cons(alloc_string_copy("/width"),
+      alloc_cons(alloc_string_copy("/height"),
+      alloc_cons(alloc_string_copy("/depth"),alloc_nil())));
+  }
+  else {
+    return alloc_int(0);
+  }
 }
 
 static int fb_state = 0;
@@ -86,12 +107,12 @@ Cell* fbfs_write(Cell* arg) {
 
 Cell* fbfs_mmap(Cell* arg) {
   Cell* fbtest = alloc_num_bytes(0);
-  fbtest->addr = sdl_get_fb();
-  fbtest->size = sdl_get_fbsize();
-  printf("fbtest->addr: %p\n",fbtest->addr);
-  printf("fbtest->size: %lx\n",fbtest->size);
+  fbtest->ar.addr = sdl_get_fb();
+  fbtest->dr.size = sdl_get_fbsize();
+  //printf("fbtest->addr: %p\n",fbtest->addr);
+  //printf("fbtest->size: %lx\n",fbtest->size);
 
-  memset(fbtest->addr,0xff,WIDTH*HEIGHT*BPP);
+  memset(fbtest->ar.addr,0xff,WIDTH*HEIGHT*BPP);
 
   return fbtest;
 }
@@ -128,7 +149,7 @@ Cell* keyfs_read() {
   }
   
   Cell* res = alloc_string_copy(" ");
-  ((uint8_t*)res->addr)[0] = sdl_key;
+  ((uint8_t*)res->ar.addr)[0] = sdl_key;
   sdl_key = 0;
   return res;
 }

+ 5 - 5
docs/what_i_learned.md

@@ -30,7 +30,7 @@ I figured I needed a few components to make the system do something interesting:
 7. Write data to a disk
 8. Receive and send packets from/to ethernet (network)
 
-The platform I chose to implement these things was the Raspberry Pi 2 (actually first the Pi 1 because I had several lying around, but this is a differnt story). The Raspberry Pi 2 fulfills, in theory, mostly, the requirements I had for the hardware:
+The platform I chose to implement these things was the Raspberry Pi 2 (actually first the Pi 1 because I had several lying around, but this is a different story). The Raspberry Pi 2 fulfills, in theory, mostly, the requirements I had for the hardware:
 
 - (almost) 1 GHz RISC CPU (actually _four_ of them + "QPU")
 - 1 GB RAM
@@ -45,11 +45,11 @@ What I dislike about the RPi 2:
 - Unnecessary features on the board (MIPI, CSI) that seem like left-overs from mobile SoC
 - Ethernet is an internal USB device; USB is overly complex
 - After working with it intensively for several months, it doesn't seem at all like a "clean and simple" system to me
-- More detailled criticism at https://wiki.debian.org/RaspberryPi
+- More detailed criticism at https://wiki.debian.org/RaspberryPi
 
 ## Bare-Metal Setup (RPi2)
 
-Loading a bare-metal kernel on the RPi 2 is relatively easy. You put a file "kernel7.img" on the first FAT partition of an MBR partioned SD card. You also put the required binary blobs and a "config.txt" file on the card. Then you plug it in and pray. 
+Loading a bare-metal kernel on the RPi 2 is relatively easy. You put a file "kernel7.img" on the first FAT partition of an MBR partitioned SD card. You also put the required binary blobs and a "config.txt" file on the card. Then you plug it in and pray. 
 
 How do you create a "kernel" file?
 
@@ -275,7 +275,7 @@ A pair is a link between two atoms; it has a left-hand side (traditionally calle
 
 A list atom is a pair whose left side points to an atom of any type and whose right side points to the next list atom or an "empty list" atom (a pair of two "nothings"). Lists are entered and displayed simply by separating atoms with whitespace and wrapping the result in parentheses: (1 2 3 4).
 
-Interim programs are simply Interim lists. The first item of a progam list must be the symbol of the function to apply to the following parameters; the remaining items of the list are the parameters:
+Interim programs are simply Interim lists. The first item of a program list must be the symbol of the function to apply to the following parameters; the remaining items of the list are the parameters:
 
     (+ 1 2)    ; evaluates to 3.
     (- 5 4)    ; evaluates to 1.
@@ -314,7 +314,7 @@ Flow control
 ------------
 
     (if <condition> <then> <else>)
-Conditional branch. If condition evaluates to non-zero, <then> is evaluated, or else <else> is evaluted. The value of the evaluated branch is returned.
+Conditional branch. If condition evaluates to non-zero, <then> is evaluated, or else <else> is evaluated. The value of the evaluated branch is returned.
 
     (while <condition> <then>)
 Conditional loop. As long as condition evaluates to non-zero, <then> is evaluated over and over again. The value of the last evaluation is returned.

+ 7 - 2
sledge/compiler_new.c

@@ -40,9 +40,14 @@ Cell* insert_symbol(Cell* symbol, Cell* cell, env_t** env) {
   }
     
   e = malloc(sizeof(env_entry));
-  memcpy(e->name, (char*)symbol->ar.addr, symbol->dr.size);
-  e->cell = cell;
+  int ret = snprintf(e->name, MAX_SYMBOL_SIZE, "%s", (char*)symbol->ar.addr);
+  if (ret >= MAX_SYMBOL_SIZE) {
+    printf("[insert_symbol] max symbol size exceeded by %d\n", ret - MAX_SYMBOL_SIZE + 1);
+    free(e);
+    return alloc_nil();
+  }
 
+  e->cell = cell;
   //printf("[insert_symbol] %s entry at %p (cell: %p)\r\n",symbol->ar.addr,e,e->cell);
   sm_put(*env, e->name, e);
 

+ 2 - 1
sledge/minilisp.h

@@ -63,6 +63,7 @@
 #define MAX_EVAL_DEPTH 10000
 #define SYM_INIT_BUFFER_SIZE 32
 #define BIGNUM_INIT_BUFFER_SIZE 32
+#define MAX_SYMBOL_SIZE 64
 
 #define ERR_SYNTAX 0
 #define ERR_MAX_EVAL_DEPTH 1
@@ -94,7 +95,7 @@ int is_nil(Cell* c);
 
 typedef struct env_entry {
   Cell* cell;
-  char name[64];
+  char name[MAX_SYMBOL_SIZE];
 } env_entry;
 
 #define car(x) (x?(Cell*)((Cell*)x)->ar.addr:NULL)

+ 2 - 2
sledge/writer.c

@@ -87,10 +87,10 @@ char* write_(Cell* cell, char* buffer, int in_list, int bufsize) {
       if (car(car(args))->tag == TAG_CONS) {
         Cell* arg_cell = car(car(args));
         // typed arg
-        ai += snprintf(tmp_args+ai, TMP_BUF_SIZE-ai, "(%s %s) ", (char*)(car(arg_cell)->ar.addr), (char*)(car(cdr(arg_cell))->ar.addr));
+        ai += snprintf(tmp_args+ai, TMP_BUF_SIZE-ai, ai ? " (%s %s)" : "(%s %s)", (char*)(car(arg_cell)->ar.addr), (char*)(car(cdr(arg_cell))->ar.addr));
       } else {
         // untyped arg
-        ai += snprintf(tmp_args+ai, TMP_BUF_SIZE-ai, "%s ", (char*)(car(car(args)))->ar.addr);
+        ai += snprintf(tmp_args+ai, TMP_BUF_SIZE-ai, ai ? " %s" : "%s" , (char*)(car(car(args)))->ar.addr);
       }
       args = cdr(args);
     }