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

A102039 lab7 #189

Open
wants to merge 26 commits into
base: A102039
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
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
*.o
*.img
*.elf
*.elf
nand_*
make_ioctl
make_ssd
ssd_fuse_dut
ssd_fuse
13 changes: 12 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
{
"files.associations": {
"utils.h": "c",
"algorithm": "c"
"algorithm": "c",
"thread.h": "c",
"array": "c",
"string_view": "c",
"initializer_list": "c",
"utility": "c",
"*.tcc": "cpp",
"functional": "cpp",
"fstream": "cpp",
"istream": "cpp",
"streambuf": "cpp",
"cpio.h": "c"
}
}
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ clean:
rm kernel8.elf kernel8.img src/*.o *.o>/dev/null 2>/dev/null || true

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

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

flash:
sudo dd if=kernel8.img of=/dev/sdb
Expand Down
180 changes: 168 additions & 12 deletions a.S
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ main_loop:
b busy_loop

.macro save_all
sub sp, sp, 32 * 9
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 @@ -66,20 +66,30 @@ main_loop:
stp x24, x25, [sp ,16 * 12]
stp x26, x27, [sp ,16 * 13]
stp x28, x29, [sp ,16 * 14]
str x30, [sp, 16 * 15]

mrs x9, sp_el0
stp x30,x9, [sp, 16 * 15]
// for nested interrupt
mrs x0, spsr_el1
mrs x1, elr_el1
stp x0,x1, [sp, 16 * 16]
ldp x0, x1, [sp ,16 * 0]
mrs x9, spsr_el1
mrs x10, elr_el1
stp x9,x10, [sp, 16 * 16]

// ldp x0, x1, [sp ,16 * 0]

// for el0 user stack pointer


.endm

// load general registers from stack
.macro load_all
ldp x0,x1,[sp, 16 * 16]
msr spsr_el1,x0
msr elr_el1,x1

ldp x30,x9, [sp, 16 * 15]
msr sp_el0,x9

ldp x9,x10,[sp, 16 * 16]
msr spsr_el1,x9
msr elr_el1,x10

ldp x0, x1, [sp ,16 * 0]
ldp x2, x3, [sp ,16 * 1]
Expand All @@ -96,19 +106,26 @@ main_loop:
ldp x24, x25, [sp ,16 * 12]
ldp x26, x27, [sp ,16 * 13]
ldp x28, x29, [sp ,16 * 14]
ldr x30, [sp, 16 * 15]
// ldr x30, [sp, 16 * 15]

add sp, sp, 32 * 9
add sp, sp, 16 * 17
.endm

.global load_eret
load_eret:
load_all
eret

exception_handler:
save_all
mov x0,sp
bl exception_entry
load_all
eret

irq_handler:
save_all
mov x0,sp
bl irq_entry
load_all
eret
Expand Down Expand Up @@ -188,4 +205,143 @@ core_timer_handler:
add x0,x0,x0
// add x0,x0,x1
msr cntp_tval_el0, x0
ret
ret

.global switch_to
switch_to:
stp x19, x20, [x0, 16 * 0]
stp x21, x22, [x0, 16 * 1]
stp x23, x24, [x0, 16 * 2]
stp x25, x26, [x0, 16 * 3]
stp x27, x28, [x0, 16 * 4]
stp fp, lr, [x0, 16 * 5]
mov x9, sp
str x9, [x0, 16 * 6]

ldp x19, x20, [x1, 16 * 0]
ldp x21, x22, [x1, 16 * 1]
ldp x23, x24, [x1, 16 * 2]
ldp x25, x26, [x1, 16 * 3]
ldp x27, x28, [x1, 16 * 4]
ldp fp, lr, [x1, 16 * 5]
ldr x9, [x1, 16 * 6]
mov sp, x9
msr tpidr_el1, x1
ret

.global get_current
get_current:
mrs x0, tpidr_el1
ret

.global save_cpu_context
save_cpu_context:
stp x19, x20, [x0, 16 * 0]
stp x21, x22, [x0, 16 * 1]
stp x23, x24, [x0, 16 * 2]
stp x25, x26, [x0, 16 * 3]
stp x27, x28, [x0, 16 * 4]
stp fp, lr, [x0, 16 * 5]
mov x9, sp
str x9, [x0, 16 * 6]
ret

.global load_cpu_context
load_cpu_context:
ldp x19, x20, [x0, 16 * 0]
ldp x21, x22, [x0, 16 * 1]
ldp x23, x24, [x0, 16 * 2]
ldp x25, x26, [x0, 16 * 3]
ldp x27, x28, [x0, 16 * 4]
ldp fp, lr, [x0, 16 * 5]
ldr x9, [x0, 16 * 6]
mov sp, x9
ret

.global get_pid
get_pid:
mov x8,0
svc #0
ret

.global uart_read
uart_read:
mov x8,1
svc #0
ret

.global uart_write
uart_write:
mov x8,2
svc #0
ret

.global exec
exec:
mov x8,3
svc #0
ret

.global fork
fork:
mov x8,4
svc #0
ret

.global exit
exit:
mov x8,5
svc #0
ret

.global mbox_call
mbox_call:
mov x8,6
svc #0
ret

.global kill
kill:
mov x8,7
svc #0
ret
.global ls
ls:
mov x8,10
svc #0
ret
.global open
open:
mov x8,11
svc #0
ret
.global close
close:
mov x8,12
svc #0
ret
.global write
write:
mov x8,13
svc #0
ret
.global read
read:
mov x8,14
svc #0
ret
.global mkdir
mkdir:
mov x8,15
svc #0
ret
.global mount
mount:
mov x8,16
svc #0
ret
.global chdir
chdir:
mov x8,17
svc #0
ret
2 changes: 1 addition & 1 deletion bootloader/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ ptty:
boot:
sudo python3 uart_boot.py
screenb:
sudo screen /dev/pts/1 115200
sudo screen /dev/pts/4 115200
13 changes: 13 additions & 0 deletions include/allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,17 @@ void memory_reserve(unsigned long long start, unsigned long long end);
void init_memory();
void pop_frame(int idx);

static inline void *my_memset(void *ptr, int val, int len)
{
int i = len;
unsigned char *p = ptr;
while(i > 0)
{
*p = val;
p++;
i--;
}
return(ptr);
}

#endif
23 changes: 21 additions & 2 deletions include/cpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,30 @@
#include "utils.h"
#include "dtb.h"
extern uint32_t* cpio_addr;
typedef struct {
char c_magic[6]; /* Magic header '070701'. */
char c_ino[8]; /* "i-node" number. */
char c_mode[8]; /* Permisions. */
char c_uid[8]; /* User ID. */
char c_gid[8]; /* Group ID. */
char c_nlink[8]; /* Number of hard links. */
char c_mtime[8]; /* Modification time. */
char c_filesize[8]; /* File size. */
char c_devmajor[8]; /* Major dev number. */
char c_devminor[8]; /* Minor dev number. */
char c_rdevmajor[8];
char c_rdevminor[8];
char c_namesize[8]; /* Length of filename in bytes. */
char c_check[8]; /* Checksum. */
}cpio_newc_header;
void cpio_ls();
void cpio_cat();
unsigned long long cpio_get_addr();
unsigned long cpio_get_addr(char** filedata,unsigned long* filesize);
//void* initramfs_callback(fdt_prop* prop,char * name,uint32_t len_prop);
void* initramfs_start_callback(fdt_prop* prop,char * name,uint32_t len_prop);
void* initramfs_end_callback(fdt_prop* prop,char * name,uint32_t len_prop);

unsigned long parse_hex_str(char *s, unsigned int max_len);
int cpio_parse_header(cpio_newc_header *archive,
char **filename, unsigned long *_filesize, char **data,
cpio_newc_header **next);
#endif
10 changes: 10 additions & 0 deletions include/fat32.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// struct mbr{
// char boot_code[436];
// struct partion_entry partion_entry[4];

// };
// struct partion_entry
// {
// char boot_flag;

// };
39 changes: 22 additions & 17 deletions include/mini_uart.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#ifndef _UART_HEADER_
#define _UART_HEADER
#include "utils.h"
#define MMIO_BASE 0x3F000000

Expand Down Expand Up @@ -44,12 +46,7 @@ void write_int_uart(unsigned int,bool newline);
#define GPPUDCLK1 ((volatile unsigned int*)(MMIO_BASE+0x0020009C))

#define IRQ_ENABLE1 ((volatile unsigned *)(0x3F00B210))
char uart_buf_read[1024];
char uart_buf_write[1024];
int uart_read_i_l;
int uart_read_i_r;
int uart_write_i_l;
int uart_write_i_r;

void init_uart_buf();
void uart_buf_read_push(char c);
void uart_buf_write_push(char c);
Expand All @@ -59,17 +56,25 @@ char uart_buf_write_pop();
void busy_wait_writes(char *s,bool newline);
void busy_wait_writec(char s);
void busy_wait_writeint(int i,bool newline);
void busy_wait_writehex(unsigned long long h,bool newline);
int is_empty_write();
int is_empty_read();

#ifdef __DEBUG_LOG
static inline void writes_uart_debug(char* s, bool newline){
while(*s){
if(*s=='\n')
writec_uart('\r');
writec_uart(*s++);
}
if(newline)
writes_uart("\r\n");
}
#endif

#ifndef _DEBUG_UART_
#define _DEBUG_UART_
static inline void writes_uart_debug(char* s, bool newline){
// while(*s){
// if(*s=='\n')
// busy_wait_writec('\r');
// busy_wait_writec(*s++);
// }
// if(newline)
// busy_wait_writes("\r\n",FALSE);
}
#endif

#endif



Loading