diff --git a/INSTALL.md b/INSTALL.md index f8746ab..56320bc 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -4,7 +4,7 @@ A pre-compiled archive is available here: https://matthieu-moy.fr/spip/?Pre-compiled-RISC-V-GNU-toolchain-and-spike -This is known to work on Ubuntu 20.04 and 20.10. Use at your own risk anywhere +This is known to work on Ubuntu 20.04, 20.10 and 22.04. Use at your own risk anywhere else. It contains the RiscV tools, ANTLR, and Pyright (a type-checker for Python used in the labs). diff --git a/PLANNING.md b/PLANNING.md index 6258da7..4ee3bb5 100644 --- a/PLANNING.md +++ b/PLANNING.md @@ -1,9 +1,9 @@ # Planning of the compilation course (CAP, Compilation and Program Analysis) _Academic first semester 2022-2023_ -# Week 1: +# Week 1: -- :book: First Course session: Tuesday 7/09/2022, 10h15-12h15. Amphi B (Gabriel Radanne) +- :book: First Course session: Wednesday 07/09/2022, 10h15-12h15. Amphi B (Gabriel Radanne) * Introduction: [transparents](course/capmif_cours01_intro_et_archi.pdf). * ISA [ref pdf RISCV](course/riscv_isa.pdf). @@ -11,13 +11,21 @@ _Academic first semester 2022-2023_ * Lexing, Parsing, [slides](course/capmif_cours02_lexing_parsing.pdf). * [Demo Parsing](course/ANTLRExamples.tar.xz). -- :book: Second Course session: Friday 9/09/2022, 10:15. Amphi B (Gabriel Radanne) +- :book: Second Course session: Friday 09/09/2022, 10:15. Amphi B (Gabriel Radanne) * Interpreters [slides in english](course/capmif_cours03_interpreters.pdf). - * [Demo files](course/ANTLRExamples.tar.xz) + * [Demo files](course/ANTLRExamples.tar.xz). * [Grammar exercise](course/TD2.pdf). - :rocket: Additional ressources (mainly in english) - * A nice YT video on [structural induction](https://www.youtube.com/watch?v=2o3EzvfgTiQ) by F. Pereira. - * Fernando Pereira's other videos on operational semantics : [video1](https://www.youtube.com/watch?v=bOzbRhXvtlY), [video2](https://www.youtube.com/watch?v=aiBKOuM5iEA) + * A nice YT video on [structural induction](https://www.youtube.com/watch?v=2o3EzvfgTiQ) by F. Pereira. + * Fernando Pereira's other videos on operational semantics : [video1](https://www.youtube.com/watch?v=bOzbRhXvtlY), [video2](https://www.youtube.com/watch?v=aiBKOuM5iEA). + +# Week 2: + +- :hammer: Lab 1: Wednesday 14/09/2021, 10h15-12h15. Salles B1 (Nicolas Chappe) & B2 (Rémi Di Guardia) + + * Introduction to RISCV [TP01](TP01/tp1.pdf). + * Code in [TP01/](TP01/). + * ISA [ref pdf RISCV](course/riscv_isa.pdf). diff --git a/README.md b/README.md index c63ec22..d1f6175 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# cap-labs 2021: Public files for ENSL M1 students (CAP course) +# cap-labs 2022: Public files for ENSL M1 students (CAP course) ![ensllogo](logos/logo_ensl.png) @@ -39,7 +39,7 @@ Gabriel Radanne, Inria, LIP [email](mailto:gabriel.radanne@ens-lyon.fr) * MCC (final grade computation) : ``` -let ccgrade = average(Lab3, Lab5, Lab6, partial) +let ccgrade = average(Lab3, Lab4, Lab5, partial) in (finalnote + ccgrade)/2 ``` * The partial exam is this academic year replaced by a written housework ("DM"). diff --git a/SSHENSL.md b/SSHENSL.md deleted file mode 100644 index 722e037..0000000 --- a/SSHENSL.md +++ /dev/null @@ -1,55 +0,0 @@ -Remote work on ENSL machines - -# SSH on ENSL machines, Linux version (with your ENSL Account) - - -* Edit your `.ssh/config` and add the following lines: -``` -Host !ssh.ens-lyon.fr *.ens-lyon.fr -ProxyCommand ssh -N -W %h:%p %r@ssh.ens-lyon.fr -``` - -* now `ssh` on one of the ENSL machines: - -``` -ssh mylogin@slsu0-02.dsi-ext.ens-lyon.fr -``` -(`slsu0` or `slsu1`, `01` to `20` at least, use `-X` if you want to use a graphical interface remotely). - - -# Windows version. - -* adapt the `mobaxterm` howto from [this page](https://nlouvet.gitlabpages.inria.fr/lifasr5/connec.html) The ssh gateway is `ssh.ens-lyon.fr` and the machine to log on is `slsu[0-1]-...` - -# Mount your ENS account on your laptop (Linux) with SSHFS. - -* I give you in `scripts/mountsinfoens` a script I wrote many years ago, use with caution. - -# Remote debugging with tmux - -`tmux` is a terminal multiplexer, that is you can transform one session into -many virtual sessions. Here we are using it to share one session between -multiple users so that we can help you debug in real time on your machine. - -Follow the following steps to share a tmux session with another user (this -method is not really secure and should not be used anywhere else): - - - Connect a tmux session with a sensible name (ie. your id) in a shared directory (ie. /tmp): - `tmux -S /tmp/` - - Allow the socket to be read by others: - `chmod 777 /tmp/` - - Give us the name of the socket (`/tmp/`) so that we can connect to - your session with the command `tmux -S /tmp/ attach` - -Inside your terminal session, you can use your favorite terminal editor, for -example `vim`, `emacs -nw`, `kak`, `nano` or whatever you like. - -Quick overview of tmux: - - C-b c : create a new window - - C-b n/p : go to next/previous window - - C-b d : detach current client - - C-b [0-9] : go to window [0-9] - - C-b " : split horizontally - - C-b % : split vertically - - C-b up : go up (same for down, left, right, etc), you can use ijkl - diff --git a/TP01/riscv/asshand.s b/TP01/riscv/asshand.s new file mode 100644 index 0000000..9054238 --- /dev/null +++ b/TP01/riscv/asshand.s @@ -0,0 +1,6 @@ + .globl main +main: + addi a0, a0, 1 + bne a0, a0, main +end: + ret diff --git a/TP01/riscv/bitcount.s b/TP01/riscv/bitcount.s new file mode 100644 index 0000000..2b0f403 --- /dev/null +++ b/TP01/riscv/bitcount.s @@ -0,0 +1,14 @@ + .globl main +main: + addi sp,sp,-16 + sd ra,8(sp) +## TODO Your assembly code there +## END TODO End of user assembly code + ld ra,8(sp) + addi sp,sp,16 + ret + +# Data comes here + .section .data +mydata: + .dword 7 diff --git a/TP01/riscv/carres.s b/TP01/riscv/carres.s new file mode 100644 index 0000000..cb83ccf --- /dev/null +++ b/TP01/riscv/carres.s @@ -0,0 +1,15 @@ + .text + .globl main +main: + addi sp,sp,-16 + sd ra,8(sp) +## TODO Your assembly code there +## END TODO End of user assembly code + ld ra,8(sp) + addi sp,sp,16 + ret + +# Data comes here + .section .data +mydata: + .dword 7 diff --git a/TP01/riscv/ex1.c b/TP01/riscv/ex1.c new file mode 100644 index 0000000..68849da --- /dev/null +++ b/TP01/riscv/ex1.c @@ -0,0 +1,12 @@ +/*Source code from Laure Gonnord, CAP Lab 1*/ + +#include + +int main(){ + + int x = 41; + x = x+1; + printf("%d\n",x); + + return 0; +} diff --git a/TP01/riscv/libprint.s b/TP01/riscv/libprint.s new file mode 100644 index 0000000..41b2dec --- /dev/null +++ b/TP01/riscv/libprint.s @@ -0,0 +1,249 @@ + .globl println_int +println_int: + addi sp,sp,-8 + sd ra, 0(sp) + call print_int + call newline + ld ra, 0(sp) + addi sp,sp,8 + ret + + .globl println_char +println_char: + addi sp,sp,-8 + sd ra, 0(sp) + call print_char + call newline + ld ra, 0(sp) + addi sp,sp,8 + ret + + .text + .align 1 + .globl println_string + .type println_string, @function +println_string: #address stored in a0 + addi sp,sp,-152 + sd ra,24(sp) + sd s0,16(sp) + addi s0,sp,32 + sd t0,32(sp) + sd t1,40(sp) + sd t2,48(sp) + sd t3,56(sp) + sd t4,64(sp) + sd t5,72(sp) + sd t6,80(sp) + + sd a0,88(sp) + sd a1,96(sp) + sd a2,104(sp) + sd a3,112(sp) + sd a4,120(sp) + sd a5,128(sp) + sd a6,136(sp) + sd a7,144(sp) + + ## Argument is already in a0, just forward it to puts + call puts + + ld ra,24(sp) + ld s0,16(sp) + + ld t0,32(sp) + ld t1,40(sp) + ld t2,48(sp) + ld t3,56(sp) + ld t4,64(sp) + ld t5,72(sp) + ld t6,80(sp) + + ld a0,88(sp) + ld a1,96(sp) + ld a2,104(sp) + ld a3,112(sp) + ld a4,120(sp) + ld a5,128(sp) + ld a6,136(sp) + ld a7,144(sp) + + addi sp,sp,152 + jr ra + .size println_string, .-println_string + .section .rodata + .align 3 +fmt_int: + .string "%ld" +str_empty: + .string "" + .text + .align 1 + .globl print_int + .type print_int, @function +print_int: # print int stored in a0, saves/restores all scratch registers (except ft which we don't use) + addi sp,sp,-152 + + sd ra,24(sp) + sd s0,16(sp) + + sd t0,32(sp) + sd t1,40(sp) + sd t2,48(sp) + sd t3,56(sp) + sd t4,64(sp) + sd t5,72(sp) + sd t6,80(sp) + + sd a0,88(sp) + sd a1,96(sp) + sd a2,104(sp) + sd a3,112(sp) + sd a4,120(sp) + sd a5,128(sp) + sd a6,136(sp) + sd a7,144(sp) + + ## first parameter of print_int is second parameter of printf + mv a1,a0 + ## first parameter of printf is the format string + la a0,fmt_int + call printf + + ld ra,24(sp) + ld s0,16(sp) + + ld t0,32(sp) + ld t1,40(sp) + ld t2,48(sp) + ld t3,56(sp) + ld t4,64(sp) + ld t5,72(sp) + ld t6,80(sp) + + ld a0,88(sp) + ld a1,96(sp) + ld a2,104(sp) + ld a3,112(sp) + ld a4,120(sp) + ld a5,128(sp) + ld a6,136(sp) + ld a7,144(sp) + + addi sp,sp,152 + jr ra + .size print_int, .-print_int + .align 1 + .globl newline + .type newline, @function +newline: # print int stored in a0, saves/restores all scratch registers (except ft which we don't use) + addi sp,sp,-152 + + sd ra,24(sp) + sd s0,16(sp) + + sd t0,32(sp) + sd t1,40(sp) + sd t2,48(sp) + sd t3,56(sp) + sd t4,64(sp) + sd t5,72(sp) + sd t6,80(sp) + + sd a0,88(sp) + sd a1,96(sp) + sd a2,104(sp) + sd a3,112(sp) + sd a4,120(sp) + sd a5,128(sp) + sd a6,136(sp) + sd a7,144(sp) + + ## first parameter of printf is the format string + la a0,str_empty + call puts + + ld ra,24(sp) + ld s0,16(sp) + + ld t0,32(sp) + ld t1,40(sp) + ld t2,48(sp) + ld t3,56(sp) + ld t4,64(sp) + ld t5,72(sp) + ld t6,80(sp) + + ld a0,88(sp) + ld a1,96(sp) + ld a2,104(sp) + ld a3,112(sp) + ld a4,120(sp) + ld a5,128(sp) + ld a6,136(sp) + ld a7,144(sp) + + addi sp,sp,152 + jr ra + .size newline, .-newline + .align 1 + .globl print_char + .type print_char, @function +print_char: # print char stored in a0 (ascii code) + addi sp,sp,-152 + sd ra,24(sp) + sd s0,16(sp) + + addi s0,sp,32 + + + sd t0,32(sp) + sd t1,40(sp) + sd t2,48(sp) + sd t3,56(sp) + sd t4,64(sp) + sd t5,72(sp) + sd t6,80(sp) + + sd a0,88(sp) + sd a1,96(sp) + sd a2,104(sp) + sd a3,112(sp) + sd a4,120(sp) + sd a5,128(sp) + sd a6,136(sp) + sd a7,144(sp) + + # call to putchar + mv a5,a0 + sb a5,-17(s0) + lbu a5,-17(s0) + sext.w a5,a5 + mv a0,a5 + call putchar + + #restore registers + ld ra,24(sp) + ld s0,16(sp) + + ld t0,32(sp) + ld t1,40(sp) + ld t2,48(sp) + ld t3,56(sp) + ld t4,64(sp) + ld t5,72(sp) + ld t6,80(sp) + + ld a0,88(sp) + ld a1,96(sp) + ld a2,104(sp) + ld a3,112(sp) + ld a4,120(sp) + ld a5,128(sp) + ld a6,136(sp) + ld a7,144(sp) + + addi sp,sp,152 + jr ra + .size print_char, .-print_char + + diff --git a/TP01/riscv/minmax.s b/TP01/riscv/minmax.s new file mode 100644 index 0000000..effe800 --- /dev/null +++ b/TP01/riscv/minmax.s @@ -0,0 +1,18 @@ + .text + .globl main +main: + addi sp,sp,-16 + sd ra,8(sp) +## TODO Your assembly code there +## END TODO End of user assembly code + ld ra,8(sp) + addi sp,sp,16 + ret + +# Data comes here + .section .data +mydata: + .dword 7 + .dword 42 +min: + .dword 0 diff --git a/TP01/riscv/test_print.s b/TP01/riscv/test_print.s new file mode 100644 index 0000000..36862d3 --- /dev/null +++ b/TP01/riscv/test_print.s @@ -0,0 +1,26 @@ +.section .text +.globl main +main: + addi sp,sp,-16 + sd ra,8(sp) +## Your assembly code there + la a0, .LC1 + call println_string + li a0,42 + call print_int + call newline + li a0,97 + call print_char + li a0,10 #new line char + call print_char + +## /end of user assembly code + ld ra,8(sp) + addi sp,sp,16 + ret + +# Data comes here + .section .data + .align 3 +.LC1: + .string "HI MIF08!" diff --git a/TP01/riscv/triangles.s b/TP01/riscv/triangles.s new file mode 100644 index 0000000..cb83ccf --- /dev/null +++ b/TP01/riscv/triangles.s @@ -0,0 +1,15 @@ + .text + .globl main +main: + addi sp,sp,-16 + sd ra,8(sp) +## TODO Your assembly code there +## END TODO End of user assembly code + ld ra,8(sp) + addi sp,sp,16 + ret + +# Data comes here + .section .data +mydata: + .dword 7 diff --git a/TP01/tp1.pdf b/TP01/tp1.pdf new file mode 100644 index 0000000..1eecfa6 Binary files /dev/null and b/TP01/tp1.pdf differ