nut version 2.1   


Nut language itself has not changed in this version.  Nut v2.0 is integrated with Som interpreter and NOS (Nut operating system) to create NOSS (NOS simulator) that will be used to study the behaviour of an operating system.  In order to simplify eval (the interpreter for n-machine), we target the executable for other very similar processor, Som s-machine, which is a linear stack-based instruction set.  S-code is very similar to n-code except for the structure.  Generating s-code from n-code is trivial.  

modify nut2 to run NOS (Nut operating system).  The main support OS functions are:
run (create process)
signal (signal semaphore)
wait (wait semaphore)

with the following syntax:
(run (func param...) ) return process pointer
(signal sem)
(wait sem)

run, signal, wait  are user defined functions, running in user space. They are compiled into call.run, call.signal, call.wait .  No new n-code is required, where run, signal, wait are user defined functions implemented in NOS (nut operating system).  A semaphore is declared as a global variable using "let".

What is needed is an array (pointer) to a semaphore which can be implemented as follows:

(let sem1)

(def ...
  ...
  (set sem1 (new 2))
  ...

get_sem_val  is  (vec sem 0)
get_sem_list is  (vec sem 1)
set_sem_val  is  (setv sem 0 value)
set_sem_list is  (setv sem 1 value)

Therefore, the declaration of a semaphore is just a global variable and must be initialised before used.

Atomic operations

run, signal, wait must be atomic operations, e.g. must not be task switched before their completion.  To implement atomic operations in critical section, the interrupt flag is required.  This is done via syscall 5 (disable interrupt) and syscall 6 (enable interrupt).

System calls

The system calls in Nut 2.1 are:

1  print x
2  printc x
3  getchar
4  gets s
5  di (disable interrupt)
6  ei (enable interrupt)
7  end
8  saveCstate
9  restoreCstate

syscall 8 and 9 are used to transfer the variables (fp, sp, ip) between user space and the processor simulator.

18 Jan 2005