Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test for git pull #128

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# OSC2023

| Github Account | Student ID | Name |
|----------------|------------|---------------|
| Haoze0102 | A122542 | Hao-Ze Wang |

## Requirements

* a cross-compiler for aarch64
* (optional) qemu-system-arm

## Build

```
make kernel.img
```

## Test With QEMU

```
qemu-system-aarch64 -M raspi3b -kernel kernel.img -initrd initramfs.cpio -serial null -serial stdio -dtb bcm2710-rpi-3-b-plus.dtb
```
87 changes: 15 additions & 72 deletions README.org
Original file line number Diff line number Diff line change
@@ -1,79 +1,22 @@
#+TITLE: Operating Systems Capstone 2023
#+OPTIONS: toc:nil
# OSC2023

This repository is used for homework submission.
| Github Account | Student ID | Name |
|----------------|------------|---------------|
| psychicalcoder | 0816171 | Tsung-Han Liu |

*To protect your rights, please create a pull request (PR) before the demo and*
*make sure the TA merges your PR after the demo.*
## Requirements

* How To Submit Homework
* a cross-compiler for aarch64
* (optional) qemu-system-arm

** Overview
For those who are familiar with git.
1. TA creates a branch named your student ID.
2. You fork this repo.
3. Base on the =<student id>= branch, you do your labs and put your code in the
forked repo.
4. Create a PR to the =<student id>= branch in this repo to submit the homework.
5. TA merges the PR as a proof that you have demo the lab.
## Build

** Fork The Repo
Fork the repository on Github.
```
make kernel.img
```

[[./images/fork_button.jpg]]
## Test With QEMU

Uncheck the "Copy the =main= branch only".

[[./images/create_fork.jpg]]

If you don't want to see a lot of redundant branches in the forked repo, keep
the checkbox checked and follow the [[./git-usage.org][guide]] to fetch your own branch.

** Clone To Your Computer
Clone the forked repo and switch to the branch named your student id.
If you cannot find your branch, ask TAs for help.

[[./images/clone_url.jpg]]

#+BEGIN_SRC shell
git clone <repo url>
cd osc2023
git checkout --track origin/<student id>
#+END_SRC

** Specify Personal Information
Write down the following info in your =README.md= (or =README.org=, =README.rst=
etc.)
+ Github account name
+ Student ID
+ Your name
+ Any other information you want

Here is an example [[https://github.com/psychicalcoder/osc2023/blob/0816171/README.md][README.md]].

** Implement Your Kernel
Design and implement your kernel in the forked repository.
#+BEGIN_QUOTE
Make good use of =.gitignore=. In the git history, we do not want to see
binaries, objective files, __MACOSX, python caches, super large test files,
or any files that can be compiled from your source code.
#+END_QUOTE

** Create a PR
Create a Github pull request before your demo. Once the PR is created, you can
always push additional commits to your forked repo before the PR is merged. The
changes will automatically appear within the PR.

1. Click the =New pull request= buttom in your repo.
[[./images/pr_button.jpg]]
2. Choose the branch with your student ID as the base branch.
[[./images/pr_base_selection.jpg]]
3. Type a title and some information about the PR.
[[./images/pr_desc.jpg]]

Here is a [[https://github.com/oscapstone/osc2023/pull/1][PR example]].

* Happy Coding ~
As long as you meet the above requirements and the PR can be merged without
conflicts, we do not care about what the forked repo look like. You can rename
your branch, change the default branch, or do whatever you want.
```
qemu-system-aarch64 -M raspi3b -kernel kernel.img -initrd initramfs.cpio -serial null -serial stdio -dtb bcm2710-rpi-3-b-plus.dtb
```
5 changes: 5 additions & 0 deletions lab1/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.vscode
gen.py
build/
kernel8.img
kernel8.elf
141 changes: 141 additions & 0 deletions lab1/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
BUILD_DIR = ./build
# Lib
LIB_SRC_DIR = ./lib

# LIB_SRC = \
# $(LIB_SRC_DIR)/mbox.c \
# $(LIB_SRC_DIR)/mmio.c \
# $(LIB_SRC_DIR)/shell.c \
# $(LIB_SRC_DIR)/string.c \
# $(LIB_SRC_DIR)/uart.c \
# $(LIB_SRC_DIR)/utils.c \

LIB_SRC = \
$(LIB_SRC_DIR)/mmio.c \
$(LIB_SRC_DIR)/mbox.c \
$(LIB_SRC_DIR)/shell.c \
$(LIB_SRC_DIR)/uart.c \

LIB_INCLUDES = \
-I $(LIB_SRC_DIR)/include \

LIB_BUILD_DIR = $(BUILD_DIR)/lib
LIB_OBJS := $(patsubst %.c,$(LIB_BUILD_DIR)/%.o,$(notdir $(LIB_SRC)))

# Application
APP_SRC_DIR = .

APP_SRC = \
$(APP_SRC_DIR)/main.c \

APP_ASM = \
$(APP_SRC_DIR)/boot.S \

APP_INCLUDES = \
-I ./ \
$(LIB_INCLUDES) \

APP_BUILD_DIR = $(BUILD_DIR)/app
APP_OBJS := $(patsubst %.c,$(APP_BUILD_DIR)/%.o,$(notdir $(APP_SRC)))
APP_OBJS += $(patsubst %.S,$(APP_BUILD_DIR)/%.o,$(notdir $(APP_ASM)))

VPATH += \
$(LIB_SRC_DIR) \
$(APP_SRC_DIR) \

# ARM toolchain
CROSS = aarch64-linux-gnu
CC = $(CROSS)-gcc
AS = $(CROSS)-as
LD = $(CROSS)-ld
OC = $(CROSS)-objcopy
OD = $(CROSS)-objdump
SP = $(CROSS)-strip

# Project
OUT_OBJS = \
$(LIB_OBJS) \
$(APP_OBJS) \

BUILD_DIRECTORIES = \
$(LIB_BUILD_DIR) \
$(APP_BUILD_DIR) \

PROJ = kernel8
OUT_ELF = ./$(PROJ).elf
OUT_IMG = ./$(PROJ).img
LINKER_FILE = linker.ld

CCFLAGS = -Wall -O0 -fno-stack-protector
LDFLAGS = -T$(LINKER_FILE) -nostdlib

.PHONY: clean directories out_elf run docker_cp
all: directories $(OUT_OBJS) $(OUT_ELF) $(OUT_IMG)
directories: $(BUILD_DIRECTORIES)
out_elf: directories $(OUT_ELF)
out_img: directories $(OUT_IMG)

# Compile Object Files ---------------------------------------------------------
$(APP_BUILD_DIR)/%.o : %.c
@echo '============================================================'
@echo ' Building target: $@'
@echo '============================================================'
@echo "[+] Building: $<"
$(CC) $(CCFLAGS) $(APP_INCLUDES) -g -o $@ -c $<
@echo "[+] Finished Building: $<"
@echo ''

$(APP_BUILD_DIR)/%.o : %.S
@echo '============================================================'
@echo ' Building target: $@'
@echo '============================================================'
@echo "[+] Building: $<"
$(CC) $(ASMFLAGS) $(APP_INCLUDES) -g -o $@ -c $<
@echo "[+] Finished Building: $<"
@echo ''

$(LIB_BUILD_DIR)/%.o : %.c
@echo '============================================================'
@echo ' Building target: $@'
@echo '============================================================'
@echo "[+] Building: $<"
$(CC) $(CCFLAGS) $(LIB_INCLUDES) -g -o $@ -c $<
@echo "[+] Finished Building: $<"
@echo ''

# Generate ELF -----------------------------------------------------------------
$(OUT_ELF): $(OUT_OBJS)
@echo '============================================================'
@echo ' Building target: $@'
@echo '============================================================'
$(LD) $(LDFLAGS) -o $@ $(OUT_OBJS)
$(OD) -d $@ > $(BUILD_DIR)/$(PROJ).objdump
# $(SP) $@
@echo '[+] Finished building target: $@'
@echo ' '

# Generate IMG -----------------------------------------------------------------
$(OUT_IMG): $(OUT_ELF)
@echo '============================================================'
@echo ' Building target: $@'
@echo '============================================================'
$(OC) -O binary $(OUT_ELF) $@
@echo '[+] Finished building target: $@'
@echo ' '

$(BUILD_DIRECTORIES):
mkdir -p $@

run:
qemu-system-aarch64 -M raspi3 -kernel kernel8.img -display none -serial null -serial stdio

debug:
qemu-system-aarch64 -M raspi3b -kernel kernel8.img -display none -serial null -serial stdio -s -S

docker_cp:
docker cp kernel8.elf my_kali:/

clean:
rm -rf *.elf
rm -rf *.img
rm -rf $(BUILD_DIR)
30 changes: 30 additions & 0 deletions lab1/boot.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
.section ".text.boot"

.global _start

_start:
// read cpu id, stop slave cores
mrs x1, mpidr_el1
and x1, x1, #3
cbz x1, 2f
// cpu id > 0, stop
1: wfe
b 1b
2: // cpu id == 0

// set top of stack just before our code (stack grows to a lower address per AAPCS64)
ldr x1, =_start
mov sp, x1

// clear bss
ldr x1, =__bss_start
ldr w2, =__bss_size
3: cbz w2, 4f
str xzr, [x1], #8
sub w2, w2, #1
cbnz w2, 3b

// jump to C code, should not return
4: bl kernel_main
// for failsafe, halt this core too
b 1b
Binary file added lab1/boot.o
Binary file not shown.
33 changes: 33 additions & 0 deletions lab1/lib/include/aux.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#ifndef __AUX_H__
#define __AUX_H__

#include "mmio.h"
/* Ref: https://cs140e.sergio.bz/docs/BCM2837-ARM-Peripherals.pdf
* Page: 8
*/
#define AUX_BASE (MMIO_BASE + 0x00215000)
#define AUX_IRQ (AUX_BASE + 0x0)
#define AUX_ENABLES (AUX_BASE + 0x4)
#define AUX_MU_IO_REG (AUX_BASE + 0x40)
#define AUX_MU_IER_REG (AUX_BASE + 0x44)
#define AUX_MU_IIR_REG (AUX_BASE + 0x48)
#define AUX_MU_LCR_REG (AUX_BASE + 0x4c)
#define AUX_MU_MCR_REG (AUX_BASE + 0x50)
#define AUX_MU_LSR_REG (AUX_BASE + 0x54)
#define AUX_MU_MSR_REG (AUX_BASE + 0x58)
#define AUX_MU_SCRATCH (AUX_BASE + 0x5c)
#define AUX_MU_CNTL_REG (AUX_BASE + 0x60)
#define AUX_MU_STAT_REG (AUX_BASE + 0x64)
#define AUX_MU_BAUD_REG (AUX_BASE + 0x68)
#define AUX_SPI0_CNTL0_REG (AUX_BASE + 0x80)
#define AUX_SPI0_CNTL1_REG (AUX_BASE + 0x84)
#define AUX_SPI0_STAT_REG (AUX_BASE + 0x88)
#define AUX_SPI0_IO_REG (AUX_BASE + 0x90)
#define AUX_SPI0_PEEK_REG (AUX_BASE + 0x94)
#define AUX_SPI1_CNTL0_REG (AUX_BASE + 0xc0)
#define AUX_SPI1_CNTL1_REG (AUX_BASE + 0xc4)
#define AUX_SPI1_STAT_REG (AUX_BASE + 0xc8)
#define AUX_SPI1_IO_REG (AUX_BASE + 0xd0)
#define AUX_SPI1_PEEK_REG (AUX_BASE + 0xd4)

#endif
35 changes: 35 additions & 0 deletions lab1/lib/include/gpio.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#ifndef __GPIO_H__
#define __GPIO_H__

#define GPIO_BASE 0x3f200000
#define GPFSEL0 (GPIO_BASE + 0x0)
#define GPFSEL1 (GPIO_BASE + 0x4)
#define GPFSEL2 (GPIO_BASE + 0x8)
#define GPFSEL3 (GPIO_BASE + 0xc)
#define GPFSEL4 (GPIO_BASE + 0x10)
#define GPFSEL5 (GPIO_BASE + 0x14)
#define GPSET0 (GPIO_BASE + 0x1c)
#define GPSET1 (GPIO_BASE + 0x20)
#define GPCLR0 (GPIO_BASE + 0x28)
#define GPCLR1 (GPIO_BASE + 0x2c)
#define GPLEV0 (GPIO_BASE + 0x34)
#define GPLEV1 (GPIO_BASE + 0x38)
#define GPEDS0 (GPIO_BASE + 0x40)
#define GPEDS1 (GPIO_BASE + 0x44)
#define GPREN0 (GPIO_BASE + 0x4c)
#define GPREN1 (GPIO_BASE + 0x50)
#define GPFEN0 (GPIO_BASE + 0x58)
#define GPFEN1 (GPIO_BASE + 0x5c)
#define GPHEN0 (GPIO_BASE + 0x64)
#define GPHEN1 (GPIO_BASE + 0x68)
#define GPLEN0 (GPIO_BASE + 0x70)
#define GPLEN1 (GPIO_BASE + 0x74)
#define GPAREN0 (GPIO_BASE + 0x7c)
#define GPAREN1 (GPIO_BASE + 0x80)
#define GPAFEN0 (GPIO_BASE + 0x88)
#define GPAFEN1 (GPIO_BASE + 0x8c)
#define GPPUD (GPIO_BASE + 0x94)
#define GPPUDCLK0 (GPIO_BASE + 0x98)
#define GPPUDCLK1 (GPIO_BASE + 0x9c)

#endif
Loading