Skip to content

Commit d6548b2

Browse files
committed
Sync lab5 to lab7 // Don't need VA in this lab
1 parent 972e6ad commit d6548b2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+4886
-0
lines changed

lab5/kernel/src/exception.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ void sync_handler_lowerEL_64(uint64_t sp) {
3838
uint32_t ec = (esr_el1 >> 26) & 0x3f;
3939
// printf("EC: %x\n", ec);
4040
if (ec == 0b010101) { // SVC instruction
41+
// printf("pid = %d, ",get_current()->pid);
4142
uint64_t iss;
4243
asm volatile("mov %0, x8" : "=r"(iss));
4344
// printf("syscall number: %d\n", iss);
@@ -47,31 +48,36 @@ void sync_handler_lowerEL_64(uint64_t sp) {
4748
uint32_t pid = get_current()->pid;
4849
trap_frame->x[0] = pid;
4950
} else if (iss == 1) { // uartread
51+
// printf("[read]\n");
5052
disable_uart_interrupt();
5153
enable_interrupt();
5254
char *str = (char *)(trap_frame->x[0]);
5355
uint32_t size = (uint32_t)(trap_frame->x[1]);
5456
size = uart_gets(str, size);
5557
trap_frame->x[0] = size;
5658
} else if (iss == 2) { // uartwrite
59+
// printf("[write]\n");
5760
char *str = (char *)(trap_frame->x[0]);
5861
trap_frame->x[0] = uart_write(str,trap_frame->x[1]);
5962
} else if (iss == 3) { // exec
6063
const char *program_name = (const char *)trap_frame->x[0];
6164
const char **argv = (const char **)trap_frame->x[1];
6265
exec(program_name, argv);
6366
} else if (iss == 4) { // fork
67+
// printf("[fork]\n");
6468
fork(sp);
6569
} else if (iss == 5) { // exit
6670
exit();
6771
} else if (iss == 6) { // mbox_call
72+
// printf("[mbox_call]\n");
6873
trap_frame->x[0] = mbox_call(trap_frame->x[0],(unsigned int *)trap_frame->x[1]);
6974
} else if (iss == 7) { // kill
7075
kill((int)trap_frame->x[0]);
7176
}
7277
}
7378
}
7479

80+
7581
void irq_handler_currentEL_ELx() {
7682
// printf("====irq_handler_currentEL_ELx=====\n");
7783

lab7/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# osc2022
2+
## Author
3+
4+
| 學號 | GitHub 帳號 | 姓名 | Email |
5+
| --- | ----------- | --- | --- |
6+
|`309554042`| `JusticeLeee` | `李政毅` | franklp97531@gmail.com |
7+
8+
## How to build
9+
10+
```bash
11+
./make.sh
12+
```
13+
## How to run
14+
15+
```bash
16+
make run
17+
```
18+
## How to burn it into pi3
19+
```bash
20+
./rus.sh # write kernel to rpi3 through uart
21+
sudo screen /dev/ttyUSB0 115200
22+
```
23+
## Note
24+
25+
copy some string.h source for use strcmp

lab7/bootloader/Makefile

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#
2+
# Copyright (C) 2018 bzt (bztsrc@github)
3+
#
4+
# Permission is hereby granted, free of charge, to any person
5+
# obtaining a copy of this software and associated documentation
6+
# files (the "Software"), to deal in the Software without
7+
# restriction, including without limitation the rights to use, copy,
8+
# modify, merge, publish, distribute, sublicense, and/or sell copies
9+
# of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be
13+
# included in all copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19+
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20+
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22+
# DEALINGS IN THE SOFTWARE.
23+
#
24+
#
25+
26+
CFILE = $(wildcard *.c)
27+
ASMFILE = $(wildcard *.S)
28+
OBJS = $(CFILE:.c=_c.o)
29+
OBJS += $(ASMFILE:.S=_s.o)
30+
CFLAGS = -Wall -O2 -ffreestanding -nostdinc -nostdlib -nostartfiles -fno-stack-protector -Iinclude -Iinclude
31+
32+
all: kernel8.img
33+
34+
%_s.o: %.S
35+
aarch64-elf-gcc $(CFLAGS) -c $< -o $@
36+
37+
%_c.o: %.c
38+
aarch64-elf-gcc $(CFLAGS) -c $< -o $@
39+
40+
kernel8.img: $(OBJS)
41+
aarch64-elf-ld -nostdlib -nostartfiles $(OBJS) -T link.ld -o bootloader.elf
42+
aarch64-elf-objcopy -O binary bootloader.elf bootloader.img
43+
44+
clean:
45+
rm kernel8.elf *.o >/dev/null 2>/dev/null || true
46+
47+
run:
48+
qemu-system-aarch64 -M raspi3 -kernel kernel8.img -serial null -serial stdio

lab7/bootloader/bootloader.elf

3.05 KB
Binary file not shown.

lab7/bootloader/bootloader.img

1.08 KB
Binary file not shown.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#ifndef _MINI_UART_H
2+
#define _MINI_UART_H
3+
4+
void uart_init(void);
5+
char uart_getc(void);
6+
void uart_putc(char c);
7+
void uart_puts(char* str);
8+
9+
#endif

lab7/bootloader/include/mm.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#ifndef _MM_H
2+
#define _MM_H
3+
4+
#define PAGE_SHIFT 12
5+
#define TABLE_SHIFT 9
6+
#define SECTION_SHIFT (PAGE_SHIFT + TABLE_SHIFT)
7+
8+
#define PAGE_SIZE (1 << PAGE_SHIFT)
9+
#define SECTION_SIZE (1 << SECTION_SHIFT)
10+
11+
#define LOW_MEMORY (2 * SECTION_SIZE)
12+
13+
#ifndef __ASSEMBLER__
14+
void memzero(unsigned long src, unsigned long n);
15+
#endif
16+
17+
#endif
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#ifndef _PER_BASE_H_
2+
#define _PER_BASE_H_
3+
4+
#define PHY_BASE_ADDR 0x3F000000
5+
6+
#endif
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef _PER_GPIO_H
2+
#define _PER_GPIO_H
3+
4+
#include "peripherals/base.h"
5+
6+
#define GPFSEL1 (PHY_BASE_ADDR + 0x00200004)
7+
#define GPSET0 (PHY_BASE_ADDR + 0x0020001C)
8+
#define GPCLR0 (PHY_BASE_ADDR + 0x00200028)
9+
#define GPPUD (PHY_BASE_ADDR + 0x00200094)
10+
#define GPPUDCLK0 (PHY_BASE_ADDR + 0x00200098)
11+
12+
#endif
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef _PER_MINI_UART_H_
2+
#define _PER_MINI_UART_H_
3+
4+
#include "peripherals/base.h"
5+
#define AUX_ENABLES (PHY_BASE_ADDR + 0x00215004)
6+
#define AUX_MU_IO_REG (PHY_BASE_ADDR + 0x00215040)
7+
#define AUX_MU_IER_REG (PHY_BASE_ADDR + 0x00215044)
8+
#define AUX_MU_IIR_REG (PHY_BASE_ADDR + 0x00215048)
9+
#define AUX_MU_LCR_REG (PHY_BASE_ADDR + 0x0021504C)
10+
#define AUX_MU_MCR_REG (PHY_BASE_ADDR + 0x00215050)
11+
#define AUX_MU_LSR_REG (PHY_BASE_ADDR + 0x00215054)
12+
#define AUX_MU_MSR_REG (PHY_BASE_ADDR + 0x00215058)
13+
#define AUX_MU_SCRATCH (PHY_BASE_ADDR + 0x0021505C)
14+
#define AUX_MU_CNTL_REG (PHY_BASE_ADDR + 0x00215060)
15+
#define AUX_MU_STAT_REG (PHY_BASE_ADDR + 0x00215064)
16+
#define AUX_MU_BAUD_REG (PHY_BASE_ADDR + 0x00215068)
17+
18+
#endif

0 commit comments

Comments
 (0)