# Tutorial on how to get into LibreSOC development This tutorial is a guide for anyone wishing, literally, to start from scratch and learn how to contribute to the LibreSOC. # Debian Sorry, ubuntu lovers: start by installing debian either in actual hardware or in a VM. A VM has the psychological disadvantage of making you feel like you are not taking things seriously (it's a toy), so consider dual booting or getting a second machine. # Python First: learn python. python3 to be precise. Start by learnong the basic data types: string, int, float then dict, list and tuple. Then move on to functions, then classes, exceptions and the "with" statement. Along the way you will pick up imports. Do not use "import *". # Git Git is essential. look up git workflow: clone, pull, push, add, commit. Create some test repos and get familiar with it. Read the [[HDL_workflow]] document. # Basics of gates You need to understand what gates are. look up AND, OR, NOT, NAND, NOR, MUX, DFF, SR latch on electronics forums and wikipedia. also look up "register latches", then HALF ADDER and FULL ADDER. Also look up "boolean algebra", "Karnaugh maps", truth tables and things like that. From there you can begin to appreciate how deeply ridiculously low level this all is, and why we are using nmigen. nmigen constructs "useful" concepts like "32 bit numbers", which actually do not exist at the gate level: they only exist by way of being constructed from chains of 1 bit (binary) processing! So for example, a 32 bit adder is "constructed" from a batch of 32 FULL ADDERs (actually, 31 FULL and one HALF). Even things like comparing two numbers, the simple "==" or ">=" operators, are done entirely with a bit-level cascade! This would drive you nuts if you had to think at this level all the time, consequently "High" in "High Level Language" was invented. Luckily in python, you can override \_\_add\_\_ and so on in order that when you put "a + b" into a nmigen program it gives you the *impression* that two "actual" numbers are being added, whereas in fact you requested that the HDL create a massive bunch of "gates" on your behalf. i.e. *behind the scenes* the HDL uses "cells" that in a massive hierarchical cascade ultimately end up at nothing more than "gates". Yes you really do need to know this because those "gates" cost both power, space, and take time to switch. So if you have too many of them in a chain, your chip is limited in its top speed. This is the point at which you should be looking up "pipelines" and "register latches", as well as "combinatorial blocks". you also want to look up the concept of a FSM (Finite State Machine) and the difference between a Mealy and a Moore FSM. # nmigen once you understand gates and python, nmigen starts to make sense. nmigen works by creating an in-memory "Abstract Syntax Tree" which is handed to yosys (via yosys "ILANG" format) which in turn actually generates the cells and netlists. so you write code in python, using the nmigen library of classes and helper routines, to construct an AST which *represents* the actual hardware. yosys takes care of the level *below* nmigen, and is just a tool. install nmigen (and yosys) by following [[HDL_workflow]] then follow the excellent tutorial by Robert pay particular attention to the bits in HDL workflow about using yosys "show" command. this is essential because the nmigen code gets turned into gates, and yosys show will bring up a graph that allows you to see that. pay particular attention to "comb" (combinatorial) and "sync" (synchronous). comb is a sequence of gates without any clock-synxhronised latches. "sync" will *automatically* create a clock synchronised register for you. this is how you construct pipelines.