Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
yhzhang0128 committed Apr 24, 2022
1 parent b4e3332 commit 2c48fcf
Show file tree
Hide file tree
Showing 17 changed files with 56 additions and 53 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ github.com/AlDanial/cloc v 1.92 T=0.03 s (1668.0 files/s, 105414.7 lines/s)
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
C 35 454 486 1566
C/C++ Header 11 75 105 312
C 35 454 490 1565
C/C++ Header 11 74 105 313
Assembly 3 6 24 68
make 1 11 0 54
-------------------------------------------------------------------------------
SUM: 50 546 615 2000 << exactly 2000!
SUM: 50 545 619 2000 << exactly 2000!
-------------------------------------------------------------------------------
```
Expand Down
2 changes: 1 addition & 1 deletion apps/user/cd.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ int main(int argc, char** argv) {
grass->workdir_ino = dir_ino;

/* Get the path name of the new working directory */
if (!strcmp(".", argv[1])) return 0;
if (!strcmp("./", argv[1])) return 0;

int len = strlen(grass->workdir);
if (strcmp("../", argv[1])) {
Expand Down
3 changes: 2 additions & 1 deletion earth/bus_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
* All rights reserved.
*/

/* definitions for controlling GPIO0 in FE310
/* Author: Yunhao Zhang
* Description: definitions for controlling GPIO0 in FE310;
* see chapter17 of the SiFive FE310-G002 Manual
*/

Expand Down
3 changes: 2 additions & 1 deletion earth/bus_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
* All rights reserved.
*/

/* definitions for controlling UART0 in FE310
/* Author: Yunhao Zhang
* Description: definitions for controlling UART0 in FE310;
* see chapter18 of the SiFive FE310-G002 Manual
*/

Expand Down
3 changes: 2 additions & 1 deletion earth/earth.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
*/

/* Author: Yunhao Zhang
* Description: Initialize dev_tty, dev_disk, cpu_intr and cpu_mmu;
* Description: Initialize the bss and data segments;
* Initialize dev_tty, dev_disk, cpu_intr and cpu_mmu;
* Load the grass layer binary from disk and run it.
*/

Expand Down
2 changes: 1 addition & 1 deletion earth/sd/sd_init.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) 2021, Cornell University
* (C) 2022, Cornell University
* All rights reserved.
*/

Expand Down
2 changes: 1 addition & 1 deletion earth/sd/sd_rw.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) 2021, Cornell University
* (C) 2022, Cornell University
* All rights reserved.
*/

Expand Down
2 changes: 1 addition & 1 deletion earth/sd/sd_utils.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) 2021, Cornell University
* (C) 2022, Cornell University
* All rights reserved.
*/

Expand Down
2 changes: 1 addition & 1 deletion grass/grass.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

/* Author: Yunhao Zhang
* Description: Initialize the timer and the process control block;
* Description: Initialize timer and the process control block;
* Spawn the first kernel process, GPID_PROCESS (pid=1).
*/

Expand Down
6 changes: 3 additions & 3 deletions grass/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
*/

/* Author: Yunhao Zhang
* Description: Initialize and reset the timer;
* See section 3.1.15 of the RISC-V manual, volume2, v1.10
* and section 9.1, 9.3 of the Sifive FE310 manual, v19p04.
* Description: Initialize and reset timer;
* see section 3.1.15 of the RISC-V manual, volume2, v1.10
* and section 9.1, 9.3 of the Sifive FE310 manual, v19p04
*/

#include "egos.h"
Expand Down
2 changes: 1 addition & 1 deletion library/file/block_store.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#pragma once
/*
* (C) 2017, Cornell University
* All rights reserved.
Expand Down Expand Up @@ -39,6 +38,7 @@
* state the block store module needs to keep.
*/

#pragma once
#include "disk.h"

#define NINODES 128
Expand Down
2 changes: 1 addition & 1 deletion library/file/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* the list, or otherwise a pointer to the next block on the list. The
* remaining slots point to free blocks, or 0 if the slot is empty.
*/

#pragma once
#include "block_store.h"

#define INODES_PER_BLOCK (BLOCK_SIZE / sizeof(struct treedisk_inode))
Expand Down
2 changes: 1 addition & 1 deletion library/libc/malloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ static char* brk = &__heap_start;
char *_sbrk(int size) {
if ((brk + size) > (&__heap_end)) {
earth->tty_write("_sbrk: heap grows too large\r\n", 29);
*(int*)(0x1000) = 1; /* Trigger a memory exception */
*(int*)(0x1000) = 1; /* Trigger a memory exception */
}

char *old_brk = brk;
Expand Down
2 changes: 1 addition & 1 deletion library/libc/print.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <unistd.h>

/* printf() constructs a string based on its arguments
* and then print this string to tty by calling _write()
* and then print the string to tty by calling _write()
*/

int _write(int file, char *ptr, int len) {
Expand Down
2 changes: 1 addition & 1 deletion library/servers/servers.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

/* Author: Yunhao Zhang
* Description: user friendly interfaces of the servers
* Description: user friendly interfaces of the system servers
*/

#include "egos.h"
Expand Down
58 changes: 29 additions & 29 deletions references/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ There are five mandatory projects:
| P0 | Queue | memory, pointer, instruction and stack pointers | Linux/Mac |
| P1 | User-level threading | thread, context switch, synchronization | Linux/Mac |
| P2 | Multi-level feedback queue | timer and quantum, scheduling, priority | Linux/Mac |
| P3 | Memory management | control register, exception handling, privilege level | Arty board |
| P3 | Memory protection and exception | control register, exception handling, privilege level | Arty board |
| P5 | File system | inode layer, directory layer, layered file system | Arty board |

And some optional projects:
Expand All @@ -22,67 +22,67 @@ And some optional projects:
## Architecture

**Earth layer (hardware specific)**
* `earth/dev_disk`: SD card (touched by P4)
* `earth/dev_disk`: ROM and SD card (touched by P4)
* `earth/dev_tty`: keyboard input and tty output
* `earth/cpu_intr`: interrupt and exception handling (touched by P3)
* `earth/cpu_mmu`: memory paging and address translation (touched by P3)

**Grass layer (hardware independent)**
* `grass/timer`: control timer registers
* `grass/timer`: timer control registers
* `grass/syscall`: system call interfaces to user applications
* `grass/process`: manage process data structures (touched by P1)
* `grass/process`: data structures for managing processes (touched by P1)
* `grass/scheduler`: preemptive scheduling and inter-process communication (touched by P2)

**Application layer**
* `app/system/sys_proc`: manage allocation and free of user processes
* `app/system/sys_file`: manage an inode layer on the SD card (touched by P5)
* `app/system/sys_dir`: manage the directory layer on top of inode layer (touched by P5)
* `app/system/sys_proc`: allocation and free of user processes
* `app/system/sys_file`: the inode layer over the SD card (touched by P5)
* `app/system/sys_dir`: the directory layer over the inode layer (touched by P5)
* `app/system/sys_shell`: interactive user interface
* user commands: `pwd`, `clear`, `killall`, `ls`, `cat`, `echo`, `clock`
* user commands: `pwd`, `cd`, `ls`, `cat`, `echo`, `clock`, `killall`

Every layer has dedicated memory regions as described below (and in `library/egos.h`).
The complete memory layout is described in Chapter 4 of the FE310 manual in this repository.
The complete memory layout is described in Chapter 4 of the [FE310 manual](sifive-fe310-v19p04.pdf).

**Selected RAM regions**

| Base | Top | Attributes | Description | Notes |
|-------------|-------------|------------|-------------------|------------------------------------------------------------|
| 0x0800_0000 | 0x0800_2FFF | RWX A | ITIM, 12KB | Earth layer bss, data and heap |
| 0x0800_3000 | 0x0800_4FFF | RWX A | ITIM, 8KB | Grass layer code, bss, data and heap |
| 0x0800_5000 | 0x0800_7FFF | RWX A | ITIM, 12KB | App code, bss, data and heap |
| 0x0800_5000 | 0x0800_7FFF | RWX A | ITIM, 12KB | App layer code, bss, data and heap |
| ...... | ...... | ...... | ...... | |
| 0x2000_0000 | 0x203F_FFFF | R XC | Flash ROM, 4MB | FPGA binary of the FE310 RISC-V processor |
| 0x2040_0000 | 0x207F_FFFF | R XC | Flash ROM, 4MB | Earth layer code and rodata |
| 0x2040_0000 | 0x207F_FFFF | R XC | Flash ROM, 4MB | Earth layer binary |
| 0x2080_0000 | 0x20BF_FFFF | R XC | Flash ROM, 4MB | Disk image (disk.img produced by mkrom) |
| ...... | ...... | ...... | ...... | |
| 0x8000_0000 | 0x8000_1FFF | RW- A | DTIM, 8KB | App stack |
| 0x8000_2000 | 0x8000_3FFF | RW- A | DTIM, 8KB | Earth and grass stack |
| 0x8000_0000 | 0x8000_1FFF | RW- A | DTIM, 8KB | App layer stack |
| 0x8000_2000 | 0x8000_3FFF | RW- A | DTIM, 8KB | Earth layer and grass layer stack |
| 0x8000_4000 | 0x8001_FFFF | RW- A | DTIM, 112KB | MMU cache of physical frames for suspended grass processes |

The first 1MB of the microSD card is used as 256 physical frames by the MMU for paging.
The first 1MB of the microSD card is used as 256 physical frames by the MMU for paging (see `earth/cpu_mmu.c`).

**Selected memory-mapped I/O regions**

| Base | Top | Attributes | Description | Notes |
|-------------|-------------|------------|---------------|---------------------------------------|
| 0x1001_4000 | 0x1001_4FFF | RW A | QSPI 0 | Control the 16MB on-board flash ROM |
| 0x1002_4000 | 0x1002_4FFF | RW A | SPI 1 | Control the Pmod1 (microSD card) pins |
| Base | Top | Attributes | Description | Notes |
|-------------|-------------|------------|---------------|----------------------------------|
| 0x1001_4000 | 0x1001_4FFF | RW A | QSPI 0 | Control the 16MB on-board ROM |
| 0x1002_4000 | 0x1002_4FFF | RW A | SPI 1 | Control the Pmod1 (microSD card) |

## Software development history

**Iteration #6**

* [2022.04] Add a simple boot loader `earth/earth.S`; Remove dependency on the Freedom Metal library
* [2022.04] Add `_write()` and `_sbrk()` in `library/libc`; Remove the Freedom Metal library entirely
* [2022.04] Add a simple boot loader `earth/earth.S`; Remove dependency on the Metal library
* [2022.04] Add `_write()` and `_sbrk()` in `library/libc`; Remove the Metal library entirely
* [2022.04] Enrich `struct grass` in order to improve clarity of the architecture
* [2022.04] Experiment with RISC-V Physical Memory Protection (PMP) and memory exception handling
* [2022.04] Experiment with Physical Memory Protection (PMP) and switching privilege level (machine <-> user)

**Iteration #5**

* [2022.03] Implement system calls and 4 shell commands: `pwd`, `ls`, `cat` and `echo`
* [2022.03] Add support of background shell commands and `killall`
* [2022.03] Add servers in `library` and cleanup access to the file system
* [2022.03] Cleanup the code controlling UART and SPI; Remove dependency on the Freedom Metal library
* [2022.03] Cleanup the code controlling UART and SPI; Remove dependency on the Metal library

**Iteration #4**
* [2022.02] Read Chapter 1, 2 and 3 of [RISC-V manual](riscv-privileged-v1.10.pdf)
Expand All @@ -100,14 +100,14 @@ The first 1MB of the microSD card is used as 256 physical frames by the MMU for
**Iteration #2**
* Yeah, I didn't work on this project in most of 2021...
* [2021.12] Create a docker image for portable toolchain setup: [Docker Hub repo](https://hub.docker.com/repository/docker/yhzhang0128/arty-toolchain)
* [2021.12] Reconnect the processor SPI bus controller to the Arty Pmod1 ports
* [2021.12] Implement the SD card initialize, read_block and write_block functions
* [2021.12] Increase the processor clock frequency from 32MHz to 65MHz so that read/write blocks becomes faster
* [2021.12] Reconnect the processor SPI bus controller to the Arty Pmod1 pins
* [2021.12] Implement the SD card initialize, read and write functions
* [2021.12] Increase the processor clock frequency from 32MHz to 65MHz so that read/write blocks become faster

**Iteration #1**
* [2020.12] Increase the processor memory from 32KB to 160KB (128KB + 32KB)
* [2020.12] Confirm that the memory cannot be further increased due to the Artix-7 35T limits
* [2020.12] Increase the processor memory from 24KB to 160KB (128KB + 32KB)
* [2020.12] Confirm that the memory cannot be further increased due to the limitation of Artix-7 35T FPGA chip

**Iteration #0**
* [2020.09] Setup the toolchain; Compile and run Hello World on Arty
* [2020.09] Test the basic input and print functionalities using the Freedom Metal library
* [2020.09] Setup the toolchain provided by SiFive; Compile and run Hello World on Arty
* [2020.09] Test the basic input and print functionalities using the SiFive Metal library
10 changes: 5 additions & 5 deletions tools/mkfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@

/* Author: Yunhao Zhang
* Description: create the disk image file (disk.img)
* the first 1MB is reserved as 256 physical frames for paging
* the second 1MB contains some ELF binary executables for booting
* the last 2MB is managed by a file system
* in total, disk.img should be exactly 4MB
* The disk image should be exactly 4MB
* the first 1MB is reserved as 256 frames for memory paging
* the next 1MB contains some ELF binary executables for booting
* the last 2MB is managed by a file system
* the output is in binary format (disk.img)
*/

#include <stdio.h>
Expand Down Expand Up @@ -71,7 +72,6 @@ int main() {
write(1, exec, PAGING_DEV_SIZE);

/* grass kernel processes */
assert(NKERNEL_PROC <= GRASS_NEXEC);
int exec_size = GRASS_EXEC_SIZE / GRASS_NEXEC;
fprintf(stderr, "[INFO] Loading %d kernel binary files\n", NKERNEL_PROC);

Expand Down

0 comments on commit 2c48fcf

Please sign in to comment.