commit a9f42f824c0cadca392a18c43ed1529c91770912
parent 421b1dc3ac04d22a02b86cab1b959fac28fa974a
Author: Gabriel G. de Brito (AKA 96) <gabrielgbrito@icloud.com>
Date: Sat, 6 Jan 2024 17:43:30 -0300
Merge pull request #3 from gboncoffee/docs
Added docs
Diffstat:
7 files changed, 237 insertions(+), 0 deletions(-)
diff --git a/CONTRIBUINDO.md b/CONTRIBUINDO.md
@@ -0,0 +1,65 @@
+[Read this document in English](CONTRIBUTING.md)
+
+# Achei um bug!
+
+Por favor, [crie uma issue](https://github.com/gboncoffee/egg/issues)
+descrevendo-o caso uma ainda não exista.
+
+# Requisição de features
+
+Por favor, [crie uma issue](https://github.com/gboncoffee/egg/issues)
+descrevendo a feature desejada caso alguma ainda não exista. Uma nova feature
+pode ser qualquer coisa desde uma nova _syscall_, um novo comando para o
+debugger, ou um novo backend. Por favor note que o propósito desse projeto é ser
+simples, então coisas como um backend de `x86_64` nunca vão ocorrer.
+
+# Eu gostaria de contribuir com código
+
+Bem, muito obrigado! A base de código é bem simples e navegável. Divirta-se, e
+se tiver alguma dúvida,
+[crie uma issue](https://github.com/gboncoffee/egg/issues).
+
+## Adicionando backends
+
+Crie um novo pacote Go no diretório do projeto. Por exemplo, vamos adicionar um
+backend para a arquitetura fictícia R2D2:
+
+```shell
+$ cd egg
+$ mkdir r2d2
+$ cd r2d2
+$ touch r2d2.go
+$ touch r2d2_test.go
+```
+
+Implementaremos tudo no arquivo `r2d2.go`:
+
+```go
+// Package egg/r2d2 implements a R2D2 machine for the EGG emulator.
+package r2d2
+
+import (
+ "github.com/gboncoffee/egg/assembler"
+ "github.com/gboncoffee/egg/machine"
+)
+
+// The R2D2 struct implements the machine interface needed by the EGG emulator.
+type R2D2 struct {
+ registers [32]uint32
+ pc uint32
+ mem [math.MaxUint32 + 1]uint8
+}
+```
+
+As funções necessárias estão na interface `Machine` importada pelo pacote
+`egg/machine`. Elas devem ser implementadas como métodos em ponteiros e não na
+struct em si.
+
+A maioria das funções é bem simples. A documentação pode ser encontrada
+[no site pkg.go.dev](https://pkg.go.dev/github.com/gboncoffee/egg).
+
+O pacote `egg/assembler` também é importado porque possui definições necessárias
+para o suporte ao debugger. A interface requer a implementação da função
+`Assemble(string) ([]uint8, []assembler.DebuggerToken, error)`. Se o segundo
+valor de retorno for `nil`, o suporte ao debugger é desativado. Além disso, esse
+pacote facilita a criação de assemblers simples.
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
@@ -0,0 +1,66 @@
+[Ler esse documento em português](CONTRIBUINDO.md)
+
+# I found a bug!
+
+Please [fill an issue](https://github.com/gboncoffee/egg/issues) describing your
+bug if none is already opened.
+
+# Feature requests
+
+Please [fill an issue](https://github.com/gboncoffee/egg/issues) describing your
+feature request if none is already opened. Features can be anything from a new
+syscall, a new debugger command, or a new architeture backend. Please remind
+that the purpouse of this project is to be simple, so stuff like a `x86_64`
+backend will never happen.
+
+# I would like to write code for it
+
+Well, first thanks! The codebase is very simple and navigatable. Enjoy your
+time, and if you have any questions,
+[fill an issue](https://github.com/gboncoffee/egg/issues).
+
+## Adding backends
+
+Create a new Go package at the project directory. For example, let's add a
+backend for the fictional R2D2 instruction set architeture:
+
+```shell
+$ cd egg
+$ mkdir r2d2
+$ cd r2d2
+$ touch r2d2.go
+$ touch r2d2_test.go
+```
+
+We'll implement everything in `r2d2.go`:
+
+```go
+// Package egg/r2d2 implements a R2D2 machine for the EGG emulator.
+package r2d2
+
+import (
+ "github.com/gboncoffee/egg/assembler"
+ "github.com/gboncoffee/egg/machine"
+)
+
+// The R2D2 struct implements the machine interface needed by the EGG emulator.
+type R2D2 struct {
+ registers [32]uint32
+ pc uint32
+ mem [math.MaxUint32 + 1]uint8
+}
+```
+
+The required functions are in the interface `Machine` imported via the
+`egg/machine` package. They should be implemented as methods on pointers rather
+than on the struct itself.
+
+Most functions there are rather simple. The documentation can be found
+[at pkg.go.dev](https://pkg.go.dev/github.com/gboncoffee/egg).
+
+The `egg/assembler` package is also imported because it has the definitions
+required for the debugger support. The interface requires the implementation of
+the assembler function `Assemble(string) ([]uint8, []assembler.DebuggerToken,
+error)`. If it's second return value is `nil`, debugger support is
+disabled. Furthermore, this package helps with the boilerplate of creating a
+simple assembler.
diff --git a/README-pt.md b/README-pt.md
@@ -5,6 +5,10 @@
# EGG, um emulador de processadores genérico
+[Documentação para RISC-V](riscv-doc-pt.md)
+
+[Contribuindo, bugs, requisição de features](CONTRIBUINDO.md)
+
EGG (Emulador Genérico do Gabriel) é um emulador modular de arquiteturas de
processador, criado para fins educacionais.
@@ -16,6 +20,11 @@ Um backend de MIPS é planejado para o futuro.
O pacote `egg/assembler` provém uma pequena biblioteca para criação de
assemblers e o suporte ao debugger do EGG.
+### Estudantes da UFPR
+
+Quer ajuda, ou tem alguma dúvida? Me mande um email: `ggb23@inf.ufpr.br`. Ou
+me procure no campus e nos laboratórios!
+
## Instalação
Baixe o binário estático para o seu sistema na página de
@@ -69,6 +78,20 @@ msg:
Cada diretório de cada arquitetura possui programas Assembly de teste que podem
ser usados de exemplo.
+## Chamadas
+
+As chamadas (_environment calls_) respondidas pelo emulator são as
+seguintes. Consulte a documentação da arquitetura para realizá-las:
+
+- BREAK (Número 1): Transfere o controle para o debugger ou finaliza a máquina.
+ Nenhum argumento.
+- READ (Número 2): Lê uma entrada da linha de comando.
+ - Argumento 1: Endereço do buffer.
+ - Argumento 2: Tamanho da entrada em bytes.
+- WRITE (Número 3): Escreve uma saída.
+ - Argumento 1: Endereço do buffer.
+ - Argumento 2: Tamanho da saída em bytes.
+
## Debugger
A interface do debugger é semelhante à do `gdb` porém bem enxuta. Use a opção
diff --git a/README.md b/README.md
@@ -5,6 +5,10 @@
# EGG, a generic processor emulator
+[Documentation for RISC-V](riscv-doc.md)
+
+[Contributing, bugs, feature requests](CONTRIBUTING.md)
+
EGG stands for "Emulador Genérico do Gabriel" ("Gabriel's Generic Emulator", in
portuguese). It's a modular emulator for processor architetures, made for
educational purpouses.
@@ -17,6 +21,11 @@ machine. A MIPS backend is coming soon.
`egg/assembler` also provides a small library for creating assemblers, and the
support for EGG's debugger.
+### UFPR students
+
+Have any questions, or want some help? Mail me: `ggb23@inf.ufpr.br`. Or find me
+at the campus and the laboratories!
+
## Installation
Simply grab the static binary for your OS at the
@@ -70,6 +79,20 @@ msg:
Each architeture folder has test Assembly files you may use as examples.
+## Calls
+
+Standard calls handled by the emulator are as follows. Refer to the architeture
+documentation on how to perform them:
+
+- BREAK (Number 1): Transfer control to debugger or stop the machine.
+ No arguments.
+- READ (Number 2): Read input.
+ - Argument 1: Buffer address.
+ - Argument 2: Size of input in bytes.
+- WRITE (Number 3): Write output.
+ - Argument 1: Buffer address.
+ - Argument 2: Size of output in bytes.
+
## Debugger
The debugger interface is kinda similar to `gdb`, though much smaller. Use the
diff --git a/riscv-doc-pt.md b/riscv-doc-pt.md
@@ -0,0 +1,30 @@
+[Read this document in English](riscv-doc.md)
+
+# RISC-V IM 32 bits para o EGG
+
+A implementação de RISC-V para o EGG usa a sintaxe de Assembly padrão descrita
+no [README](README-pt.md). Ela implementa os registradores e instruções do
+conjunto base e da extensão de multiplicação descritos [nesse
+documento](riscv/riscv.pdf).
+
+Para realizar uma chamada (_environment call_), o número dela é colocado no
+registrador `a7` e os argumentos nos registradores `a0` e `a1`.
+
+Uma instrução `ebreak` realiza a chamada BREAK.
+
+Código de exemplo (escreve "Hello, World!", quebra a linha e sai):
+
+```asm
+ addi a7, zero, 3
+ addi a0, zero, msg
+ addi a1, zero, 14
+ ecall
+ ebreak
+
+msg:
+#Hello, World!%0a
+```
+
+O programa montado é carregado no endereço `0` e o `pc` é inicializado em `0`. O
+ponteiro da stack não é inicializado. Caso o programa faça uso da stack, ela
+deve ser inicializada no programa.
diff --git a/riscv-doc.md b/riscv-doc.md
@@ -0,0 +1,30 @@
+[Ler esse documento em português](riscv-doc-pt.md)
+
+# RISC-V IM 32 bits for EGG
+
+The RISC-V implementation for EGG uses the standard Assembly syntax described in
+the [README](README.md). It implements the registers and instructions from the
+base integer set and the multiplication extension described in
+[this](riscv/riscv.pdf) document.
+
+Environment call numbers are placed in the `a7` registers, and arguments are
+placed in `a0` and `a1`.
+
+An `ebreak` instruction will perform a BREAK call.
+
+Example program (writes "Hello, World!", breaks a line and exits):
+
+```asm
+ addi a7, zero, 3
+ addi a0, zero, msg
+ addi a1, zero, 14
+ ecall
+ ebreak
+
+msg:
+#Hello, World!%0a
+```
+
+The assembled program is loaded at the address `0` on the machine startup, and
+the `pc` register is set to `0`. The stack pointer register is not initialized:
+the program should initialize it if it wants to use the stack.
diff --git a/riscv/riscv.pdf b/riscv/riscv.pdf
Binary files differ.