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

310552001 Lab5 & Lab7 #178

Open
wants to merge 63 commits into
base: 310552001
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
f9db006
change task & timer, simple malloc->kmalloc
fanhouin Apr 19, 2022
5d7bed6
fix sub sp bug -> rpi3 can do irq
fanhouin Apr 19, 2022
cac3039
change size
fanhouin Apr 19, 2022
c589d8e
task queue change to linux kernel list
fanhouin Apr 19, 2022
4350f41
thead init & create (?
fanhouin Apr 20, 2022
212338b
thead_create need user&kernel thread
fanhouin Apr 20, 2022
314d8d1
something
fanhouin May 3, 2022
579453c
can run into idle thread
fanhouin May 3, 2022
3fd59f7
Thread: can use schedule change task
fanhouin May 5, 2022
a75e6ed
syscall: In development~~
fanhouin May 6, 2022
ea7bbc4
syscall: NO TEST QQ
fanhouin May 7, 2022
a988504
kernel_exec: run a user program with a thread
fanhouin May 8, 2022
460c235
syscall: do_fork and exec a sample user program
fanhouin May 9, 2022
0a7488a
syscall: getpid, uart_read, uart_write, exec -> ok
fanhouin May 10, 2022
ca871d3
syscall: fork done, and don't copy code
fanhouin May 10, 2022
14b7335
syscall: fork ok
fanhouin May 11, 2022
7f974ac
syscall: mbox maybe ok &
fanhouin May 12, 2022
9603307
QQ
fanhouin May 13, 2022
6340252
video player ok
fanhouin May 13, 2022
e82e743
Merge branch 'lab5' of github.com:fanhouin/osc2022 into lab5
fanhouin May 13, 2022
c6535fe
signal syscall setup
fanhouin May 16, 2022
f7bbdd1
signal: signal kill ready
fanhouin May 19, 2022
8939c78
signal: signal_kill done
fanhouin May 20, 2022
09e326f
signal: POSIX Signal done(qemu ok)
fanhouin May 21, 2022
ec411d0
ALL DONE!!!
fanhouin May 21, 2022
96a4c1f
update lab5 readme
fanhouin May 22, 2022
b66d506
vfs: create rootfs done
fanhouin May 22, 2022
66275b0
vfs_lookup: ok but no test
fanhouin May 23, 2022
99a5562
vfs_open: limit the last name when O_CREAT
fanhouin May 23, 2022
651866a
tmpfs create & open & close & read (no test)
fanhouin May 24, 2022
3c94bb6
tmpfs_read: use block size to read
fanhouin May 24, 2022
9d628ac
tmpfs_write: done (no test)
fanhouin May 24, 2022
28937a9
vfs_open: simple test ok
fanhouin May 24, 2022
2f19f59
vps_read, vps_write: simple test ok
fanhouin May 24, 2022
6904cdf
vfs_mkdir & vfs_ls: simple test ok
fanhouin May 25, 2022
b3cd1bf
vfs_ls: use tmpfs_ls
fanhouin May 25, 2022
a60c923
vfs_mount: done (no test)
fanhouin May 25, 2022
bf06e69
vfs_chdir: ok (no test)
fanhouin May 26, 2022
411a672
vfs_mount & vfs_umount & vfs_chdir: simple test ok
fanhouin May 26, 2022
4fff30a
shell: add the vfs_{mathod}
fanhouin May 27, 2022
cad2e2d
update O_CREAT
fanhouin May 27, 2022
afc2b4d
add vfs syscall call
fanhouin May 27, 2022
571704a
find_component_name: return the null flag
fanhouin May 28, 2022
27d2ff3
save vfs info to thread
fanhouin May 28, 2022
f1cea03
cpio.c: add the cpio file_info list
fanhouin May 28, 2022
bed8d90
what the bug==
fanhouin May 28, 2022
7eddb22
fix the data_len bug
fanhouin May 28, 2022
c25a240
tmpfs_write: fixed bug?
fanhouin May 30, 2022
b492505
tmpfs_read: fixed bug?
fanhouin May 30, 2022
1edbe0b
read only fs
fanhouin May 30, 2022
ed21be5
user program: basic1234 ok
fanhouin May 31, 2022
38679e2
/dev/uart: pass the test
fanhouin Jun 1, 2022
355c79e
Use vfs method to exec file
fanhouin Jun 1, 2022
c823c0d
cpio check file type use c_nlink
fanhouin Jun 1, 2022
ac6a634
lseek64
fanhouin Jun 1, 2022
6f2a666
vfs_write: resize block size everytime
fanhouin Jun 1, 2022
d3651ec
kill_zombie: init vfs
fanhouin Jun 1, 2022
4c05770
change typo
fanhouin Jun 2, 2022
accdad3
sys_read: add vfs_write after uart_read?
fanhouin Jun 2, 2022
cde8eb5
exec read one time
fanhouin Jun 2, 2022
9c9a25c
/dev/uart; change f_ops
fanhouin Jun 2, 2022
a7cea80
framebuffer: done
fanhouin Jun 2, 2022
9d2497a
update readme
fanhouin Jun 6, 2022
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
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.cpio
*.elf
*.img
src/*.elf
Expand All @@ -15,6 +16,12 @@ bootloader/src/*.elf
bootloader/src/*.img
bootloader/src/*.o
bootloader/boot/*.o


user/*.elf
user/*.img
user/build/*

peda*
.gdb*

Expand Down
25 changes: 23 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ sudo ../uartboot.py <num>
┃ ┣ 📂include
┃ ┃ ┣ 📜allocator.h
┃ ┃ ┣ 📜cpio.h
┃ ┃ ┣ 📜dev_ops.h
┃ ┃ ┣ 📜exc.h
┃ ┃ ┣ 📜fdt.h
┃ ┃ ┣ 📜gpio.h
Expand All @@ -78,14 +79,25 @@ sudo ../uartboot.py <num>
┃ ┃ ┣ 📜math.h
┃ ┃ ┣ 📜read.h
┃ ┃ ┣ 📜reboot.h
┃ ┃ ┣ 📜sched.h
┃ ┃ ┣ 📜shell.h
┃ ┃ ┣ 📜signal.h
┃ ┃ ┣ 📜stddef.h
┃ ┃ ┣ 📜stdint.h
┃ ┃ ┣ 📜string.h
┃ ┃ ┣ 📜syscall.h
┃ ┃ ┣ 📜task.h
┃ ┃ ┣ 📜test_fs.h
┃ ┃ ┣ 📜timer.h
┃ ┃ ┗ 📜uart.h
┃ ┃ ┣ 📜tmpfs.h
┃ ┃ ┣ 📜uart.h
┃ ┃ ┣ 📜user_syscall.h
┃ ┃ ┗ 📜vfs.h
┃ ┣ 📂initramfs
┃ ┃ ┣ 📂flag
┃ ┃ ┃ ┣ 📂fffflag
┃ ┃ ┃ ┃ ┗ 📜flag
┃ ┃ ┃ ┗ 📜fakeflag.txt
┃ ┃ ┣ 📜me
┃ ┃ ┣ 📜test1
┃ ┃ ┣ 📜test2.txt
Expand All @@ -94,6 +106,8 @@ sudo ../uartboot.py <num>
┃ ┣ 📂src
┃ ┃ ┣ 📜allocator.c
┃ ┃ ┣ 📜cpio.c
┃ ┃ ┣ 📜ctx_switch.S
┃ ┃ ┣ 📜dev_ops.c
┃ ┃ ┣ 📜exc.c
┃ ┃ ┣ 📜fdt.c
┃ ┃ ┣ 📜irq.c
Expand All @@ -103,11 +117,18 @@ sudo ../uartboot.py <num>
┃ ┃ ┣ 📜math.c
┃ ┃ ┣ 📜read.c
┃ ┃ ┣ 📜reboot.c
┃ ┃ ┣ 📜sched.c
┃ ┃ ┣ 📜shell.c
┃ ┃ ┣ 📜signal.c
┃ ┃ ┣ 📜string.c
┃ ┃ ┣ 📜syscall.c
┃ ┃ ┣ 📜task.c
┃ ┃ ┣ 📜test_fs.c
┃ ┃ ┣ 📜timer.c
┃ ┃ ┗ 📜uart.c
┃ ┃ ┣ 📜tmpfs.c
┃ ┃ ┣ 📜uart.c
┃ ┃ ┣ 📜user_syscall.S
┃ ┃ ┗ 📜vfs.c
┃ ┣ 📜Makefile
┃ ┣ 📜bcm2710-rpi-3-b-plus.dtb
┃ ┗ 📜initramfs.cpio
Expand Down
2 changes: 1 addition & 1 deletion debug.gdb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
file kernel8.elf
b *0x81600
b *tmpfs_read
target remote :1234
29 changes: 24 additions & 5 deletions kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,26 @@ SRC_DIR = src
BUILD_DIR = build
BOOT_DIR = boot

SFILES_ASM = $(wildcard src/*.S)
OFILES_ASM = $(patsubst src/%.S, build/%.o, $(SFILES_ASM)) # OFILES = $(SFILES:.c=.o)
SFILES = $(wildcard src/*.c)
OFILES = $(patsubst src/%.c, build/%.o, $(SFILES)) # OFILES = $(SFILES:.c=.o)
BOOTFILES = $(wildcard boot/*.S)
BOOTOFILES = $(patsubst boot/%.S, build/%.o, $(BOOTFILES)) # BOOTOFILES = $(BOOTFILES:.S=.o)
ALLOFILES = $(OFILES) $(BOOTOFILES)
ALLOFILES = $(OFILES) $(BOOTOFILES) $(OFILES_ASM)

CFLAGS = -Wall -O2 -ffreestanding -nostdinc -nostdlib -nostartfiles

all: clean kernel8.img run
all: clean kernel8.img run-display

$(BUILD_DIR)/%.o: $(BOOT_DIR)/%.S
$(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ -g
$(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ -g

$(BUILD_DIR)/%.o: $(SRC_DIR)/%.S
$(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ -g

$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c
$(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ -g
$(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ -g

kernel8.img: $(ALLOFILES)
$(LD) -nostdlib -nostartfiles $(ALLOFILES) -T boot/linker.ld -o kernel8.elf
Expand All @@ -31,7 +36,21 @@ clean:
rm *.elf *.img build/* >/dev/null 2>/dev/null || true

run:
qemu-system-aarch64 -M raspi3 -kernel kernel8.img -display none -s -serial null -serial stdio -initrd initramfs.cpio -dtb bcm2710-rpi-3-b-plus.dtb
qemu-system-aarch64 -M raspi3 -kernel kernel8.img -display none -s -serial null -serial stdio -initrd initramfs.cpio -dtb bcm2710-rpi-3-b-plus.dtb

run-display:
qemu-system-aarch64 -M raspi3 -kernel kernel8.img -s -serial null -serial stdio -initrd initramfs.cpio -dtb bcm2710-rpi-3-b-plus.dtb

pty:
qemu-system-aarch64 -M raspi3 -kernel kernel8.img -display none -s -serial null -serial pty -initrd initramfs.cpio -dtb bcm2710-rpi-3-b-plus.dtb

cpio:
cd initramfs;\find . | cpio -o -H newc > ../initramfs.cpio;

user:
cd ../user;\
make;\
cp user2.img ./initramfs/user2.img;\
cd initramfs;\find . | cpio -o -H newc > ../initramfs.cpio;\
cd ..;\
cp ./initramfs.cpio ../kernel/initramfs.cpio
42 changes: 26 additions & 16 deletions kernel/boot/start.S
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ _start:

// save general registers to stack
.macro save_all
sub sp, sp, 33 * 8
sub sp, sp, 16 * 17
stp x0, x1, [sp ,16 * 0]
stp x2, x3, [sp ,16 * 1]
stp x4, x5, [sp ,16 * 2]
Expand All @@ -55,18 +55,20 @@ _start:
stp x24, x25, [sp ,16 * 12]
stp x26, x27, [sp ,16 * 13]
stp x28, x29, [sp ,16 * 14]
str x30, [sp, 16 * 15]

mrs x5, spsr_el1
mrs x6, elr_el1
stp x5, x6, [sp ,16 * 16]
mrs x9, sp_el0
stp x30, x9, [sp, 16 * 15]
mrs x9, elr_el1
mrs x10, spsr_el1
stp x9, x10, [sp ,16 * 16]
.endm

// load general registers from stack
.macro load_all
ldp x5, x6, [sp ,16 * 16]
msr spsr_el1, x5
msr elr_el1, x6
ldp x30, x10, [sp ,16 * 15]
msr sp_el0, x10
ldp x9, x10, [sp ,16 * 16]
msr elr_el1, x9
msr spsr_el1, x10

ldp x0, x1, [sp ,16 * 0]
ldp x2, x3, [sp ,16 * 1]
Expand All @@ -83,23 +85,31 @@ _start:
ldp x24, x25, [sp ,16 * 12]
ldp x26, x27, [sp ,16 * 13]
ldp x28, x29, [sp ,16 * 14]
ldr x30, [sp, 16 * 15]

add sp, sp, 33 * 8
add sp, sp, 16 * 17
.endm

.global after_fork
after_fork:
load_all
eret

sync_exception_entry:
save_all
mrs x1, esr_el1
mrs x2, elr_el1
mrs x3, spsr_el1
mrs x0, esr_el1
mrs x1, elr_el1
mrs x2, spsr_el1

// trap frame
mov x3, sp
bl exception_handler
load_all
eret

irq_entry:
save_all
mrs x1, spsr_el1
mrs x0, spsr_el1
mov x1, sp
bl irq_handler
load_all
eret
Expand All @@ -122,7 +132,7 @@ exception_vector_table:
b fail
.align 7

b fail
b sync_exception_entry
.align 7
b irq_entry
.align 7
Expand Down
7 changes: 5 additions & 2 deletions kernel/include/cpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ unsigned long long CPIO_BASE_END;
#define CPIO_HEADER_MAGIC "070701"
#define CPIO_FOOTER_MAGIC "TRAILER!!!"
#define CPIO_ALIGNMENT 4
#define MAX_CPIO_FILE_NUM 1024


typedef struct _cpio_newc_header{
Expand All @@ -36,14 +37,16 @@ typedef struct _file_info{
char *data;
unsigned int filename_size;
unsigned int datasize;
char *c_nlink;
}file_info;

void testprint();
void init_cpio_file_info();
unsigned int padding(unsigned int);
void ls();
void cat(char [MAX_SIZE]);
void run(unsigned long);
unsigned long findDataAddr(char [MAX_SIZE]);
unsigned long findDataAddr(const char *);
file_info cpio_find_file_info(const char *thefilename);
void parse_cpio_header(cpio_newc_header *, file_info *);


Expand Down
14 changes: 14 additions & 0 deletions kernel/include/dev_ops.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef DRIVER_OPS_H_
#define DRIVER_OPS_H_

#include <stddef.h>
#include <vfs.h>
#include <tmpfs.h>

void dev_ops_init();
int uart_dev_write(struct file* file, const void* buf, size_t len);
int uart_dev_read(struct file* file, void* buf, size_t len);
int framebuf_dev_write(struct file* file, const void* buf, size_t len);


#endif
14 changes: 9 additions & 5 deletions kernel/include/exc.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#ifndef EXC_H_
#define EXC_H_
#include <syscall.h>

void exception_handler(unsigned long long,
unsigned long long,
unsigned long long,
unsigned long long);
void exception_handler( unsigned long long,
unsigned long long,
unsigned long long,
TrapFrame *);

void syscall_handler(unsigned int syscall_id, TrapFrame *trapFrame);

#endif

#endif
3 changes: 2 additions & 1 deletion kernel/include/irq.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define IRQ_H_

#include <gpio.h>
#include <syscall.h>

#define IRQ_BASIC_PENDING ((volatile unsigned int*)(MMIO_BASE+0x0000B200))
#define IRQ_PENDING_1 ((volatile unsigned int*)(MMIO_BASE+0x0000B204))
Expand All @@ -22,7 +23,7 @@
#define SYSTEM_TIMER_IRQ_3 (1 << 3)
#define NON_SECURE_TIMER_IRQ (1 << 1)

void irq_handler(unsigned long long, unsigned long long);
void irq_handler(unsigned long long, TrapFrame*);
void Time_interrupt(unsigned long long);
void GPU_interrupt();

Expand Down
12 changes: 9 additions & 3 deletions kernel/include/mailbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,14 @@
#define MAILBOX_CH_COUNT 7
#define MAILBOX_CH_PROP 8

unsigned int get_board_revision(volatile unsigned int [36]);
unsigned int get_arm_memory(volatile unsigned int [36]);
unsigned int mailbox_call(volatile unsigned int [36], unsigned char);
#define MBOX_REQUEST 0
#define MBOX_CH_PROP 8
#define MBOX_TAG_LAST 0


unsigned int get_board_revision(unsigned int [36]);
unsigned int get_arm_memory(unsigned int [36]);
void framebuffer_init();
unsigned int mailbox_call(unsigned int *, unsigned char);

#endif
2 changes: 2 additions & 0 deletions kernel/include/read.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ int async_readline(char [MAX_SIZE], int);
/* scan the input until get \r */
int readline(char [MAX_SIZE], int);


int async_readnbyte(char buf[MAX_SIZE], int size);
/* read n bytes from uart */
int readnbyte(char [MAX_SIZE], int);
#endif
Loading