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

fix: fix lab1 minors #32

Merged
merged 4 commits into from
Sep 21, 2024
Merged
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
2 changes: 1 addition & 1 deletion Lab1/.clangd
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
CompileFlags:
CompilationDatabasePath: build/kernel/
CompilationDatabase: build/kernel/
1 change: 1 addition & 0 deletions Lab1/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ chcore_add_subproject(
BINARY_DIR ${_kernel_build_dir}
INSTALL_DIR ${_kernel_install_dir}
CMAKE_ARGS
${_cache_args}
${_common_args}
-DCHCORE_USER_INSTALL_DIR=${_system_services_install_dir} # used by kernel/CMakeLists.txt to incbin cpio files
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
Expand Down
Binary file modified Lab1/kernel/arch/aarch64/debug/backtrace.c.obj
Binary file not shown.
Binary file modified Lab1/kernel/arch/aarch64/debug/ptrace.c.obj
Binary file not shown.
Binary file modified Lab1/kernel/arch/aarch64/irq/ipi.c.obj
Binary file not shown.
Binary file modified Lab1/kernel/arch/aarch64/irq/irq_entry.c.obj
Binary file not shown.
Binary file modified Lab1/kernel/arch/aarch64/irq/pgfault.c.obj
Binary file not shown.
Binary file modified Lab1/kernel/arch/aarch64/machine/pmu.c.obj
Binary file not shown.
Binary file modified Lab1/kernel/arch/aarch64/machine/smp.c.obj
Binary file not shown.
Binary file modified Lab1/kernel/arch/aarch64/main.c.obj
Binary file not shown.
Binary file modified Lab1/kernel/arch/aarch64/mm/cache.c.obj
Binary file not shown.
Binary file modified Lab1/kernel/arch/aarch64/mm/memset.c.obj
Binary file not shown.
Binary file modified Lab1/kernel/arch/aarch64/mm/page_table.c.obj
Binary file not shown.
Binary file modified Lab1/kernel/arch/aarch64/mm/tlb.c.obj
Binary file not shown.
Binary file modified Lab1/kernel/arch/aarch64/mm/uaccess.c.obj
Binary file not shown.
Binary file modified Lab1/kernel/arch/aarch64/mm/vmspace.c.obj
Binary file not shown.
Binary file modified Lab1/kernel/arch/aarch64/plat/raspi3/irq/irq.c.obj
Binary file not shown.
Binary file modified Lab1/kernel/arch/aarch64/plat/raspi3/irq/timer.c.obj
Binary file not shown.
Binary file modified Lab1/kernel/arch/aarch64/plat/raspi3/mm/mmparse.c.obj
Binary file not shown.
Binary file modified Lab1/kernel/arch/aarch64/plat/raspi3/poweroff.c.obj
Binary file not shown.
Binary file modified Lab1/kernel/arch/aarch64/plat/raspi3/uart/uart.c.obj
Binary file not shown.
Binary file modified Lab1/kernel/arch/aarch64/sched/context.c.obj
Binary file not shown.
Binary file modified Lab1/kernel/arch/aarch64/sched/fpu.c.obj
Binary file not shown.
Binary file modified Lab1/kernel/arch/aarch64/sched/sched.c.obj
Binary file not shown.
Binary file modified Lab1/kernel/arch/aarch64/sync/rwlock.c.obj
Binary file not shown.
Binary file modified Lab1/kernel/arch/aarch64/sync/ticket.c.obj
Binary file not shown.
20 changes: 20 additions & 0 deletions Lab1/kernel/include/arch/aarch64/arch/context.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright (c) 2023 Institute of Parallel And Distributed Systems (IPADS), Shanghai Jiao Tong University (SJTU)
* Licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
*/

#ifndef ARCH_AARCH64_ARCH_CONTEXT_H
#define ARCH_AARCH64_ARCH_CONTEXT_H

#include <object/thread.h>

void arch_thread_mask_fiq(struct thread *thread, bool mask);

#endif /* ARCH_AARCH64_ARCH_CONTEXT_H */
3 changes: 3 additions & 0 deletions Lab1/kernel/include/arch/aarch64/arch/mm/page_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
/* Access flag bit. */
#define AARCH64_MMU_ATTR_PAGE_AF_ACCESSED (1)

/* Non-secure bit */
#define AARCH64_MMU_ATTR_PAGE_NS_NON_SECURE (1)

/* Present (valid) bit. */
#define AARCH64_MMU_PTE_INVALID_MASK (1 << 0)
/* Table bit: whether the next level is aonther pte or physical memory page. */
Expand Down
67 changes: 67 additions & 0 deletions Lab1/kernel/include/arch/aarch64/arch/trustzone/smc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright (c) 2023 Institute of Parallel And Distributed Systems (IPADS), Shanghai Jiao Tong University (SJTU)
* Licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
*/

#ifndef ARCH_AARCH64_ARCH_TRUSTZONE_SMC_H
#define ARCH_AARCH64_ARCH_TRUSTZONE_SMC_H

#include <common/types.h>
#include <smc_num.h>

enum tz_switch_req {
TZ_SWITCH_REQ_ENTRY_DONE,
TZ_SWITCH_REQ_STD_REQUEST,
TZ_SWITCH_REQ_STD_RESPONSE,
TZ_SWITCH_REQ_NR
};

enum smc_ops_exit {
SMC_OPS_NORMAL = 0x0,
SMC_OPS_SCHEDTO = 0x1,
SMC_OPS_START_SHADOW = 0x2,
SMC_OPS_START_FIQSHD = 0x3,
SMC_OPS_PROBE_ALIVE = 0x4,
SMC_OPS_ABORT_TASK = 0x5,
SMC_EXIT_NORMAL = 0x0,
SMC_EXIT_PREEMPTED = 0x1,
SMC_EXIT_SHADOW = 0x2,
SMC_EXIT_ABORT = 0x3,
SMC_EXIT_MAX = 0x4,
};

struct tz_vectors;

struct smc_registers {
unsigned long x0;
unsigned long x1;
unsigned long x2;
unsigned long x3;
unsigned long x4;
};

extern struct tz_vectors tz_vectors;

typedef struct {
unsigned long params_stack[8];
} __attribute__((packed)) kernel_shared_varibles_t;

void smc_init(void);

void smc_call(int fid, ...);

/* smc thread will call this function to wait for next smc request */
int ot_sys_tee_switch_req(struct smc_registers *regs_u);
/* idle thread will call this function to switch back to normal world */
int ot_sys_tee_wait_switch_req(struct smc_registers *regs_u);
/* gtask will call this function to get registers of the first smc request */
int ot_sys_tee_pull_kernel_var(kernel_shared_varibles_t *cmd_buf_addr_buf);

#endif /* ARCH_AARCH64_ARCH_TRUSTZONE_SMC_H */
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (c) 2023 Institute of Parallel And Distributed Systems (IPADS),
* Shanghai Jiao Tong University (SJTU) Licensed under the Mulan PSL v2. You can
* use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY
* KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
* NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. See the
* Mulan PSL v2 for more details.
*/

#ifndef ARCH_AARCH64_ARCH_TRUSTZONE_SPD_OPTEED_SMC_NUM_H
#define ARCH_AARCH64_ARCH_TRUSTZONE_SPD_OPTEED_SMC_NUM_H

#define SMC_ENTRY_DONE 0xbe000000
#define SMC_STD_REQUEST 0x3e000008
#define SMC_STD_RESPONSE 0xbe000005
#define SMC_ON_DONE 0xbe000001
#define SMC_OFF_DONE 0xbe000002
#define SMC_SUSPEND_DONE 0xbe000003
#define SMC_RESUME_DONE 0xbe000004
#define SMC_FIQ_DONE 0xbe000006
#define SMC_SYSOFF_DONE 0xbe000007
#define SMC_SYSRST_DONE 0xbe000008

#endif /* ARCH_AARCH64_ARCH_TRUSTZONE_SPD_OPTEED_SMC_NUM_H */
28 changes: 28 additions & 0 deletions Lab1/kernel/include/arch/aarch64/arch/trustzone/spd/teed/smc_num.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2023 Institute of Parallel And Distributed Systems (IPADS),
* Shanghai Jiao Tong University (SJTU) Licensed under the Mulan PSL v2. You can
* use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY
* KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
* NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. See the
* Mulan PSL v2 for more details.
*/

#ifndef ARCH_AARCH64_ARCH_TRUSTZONE_SPD_TEED_SMC_NUM_H
#define ARCH_AARCH64_ARCH_TRUSTZONE_SPD_TEED_SMC_NUM_H

#define SMC_ENTRY_DONE 0xf2000000
#define SMC_ON_DONE 0xf2000001
#define SMC_OFF_DONE 0xf2000002
#define SMC_SUSPEND_DONE 0xf2000003
#define SMC_RESUME_DONE 0xf2000004
#define SMC_PREEMPTED 0xf2000005
#define SMC_ABORT_DONE 0xf2000007
#define SMC_SYSTEM_OFF_DONE 0xf2000008
#define SMC_SYSTEM_RESET_DONE 0xf2000009
#define SMC_STD_REQUEST 0xb2000008
#define SMC_STD_RESPONSE 0xb2000009

#endif /* ARCH_AARCH64_ARCH_TRUSTZONE_SPD_TEED_SMC_NUM_H */
77 changes: 77 additions & 0 deletions Lab1/kernel/include/arch/aarch64/arch/trustzone/tlogger.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright (c) 2023 Institute of Parallel And Distributed Systems (IPADS),
* Shanghai Jiao Tong University (SJTU) Licensed under the Mulan PSL v2. You can
* use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY
* KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
* NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. See the
* Mulan PSL v2 for more details.
*/

#ifndef ARCH_AARCH64_ARCH_TRUSTZONE_TLOGGER_H
#define ARCH_AARCH64_ARCH_TRUSTZONE_TLOGGER_H

#include <common/types.h>
#include <common/tee_uuid.h>

#define UUID_LEN 16
#define NEVER_USED_LEN 32U
#define LOG_ITEM_RESERVED_LEN 1U

/* 64 byte head + user log */
struct log_item {
u8 never_used[NEVER_USED_LEN];
u16 magic;
u16 reserved0;
u32 serial_no;
s16 real_len; /* log real len */
u16 buffer_len; /* log buffer's len, multiple of 32 bytes */
u8 uuid[UUID_LEN];
u8 log_source_type;
u8 reserved[LOG_ITEM_RESERVED_LEN];
u8 log_level;
u8 new_line; /* '\n' char, easy viewing log in bbox.bin file */
u8 log_buffer[0];
};

/* --- for log mem --------------------------------- */
#define LOG_BUFFER_RESERVED_LEN 11U
#define VERSION_INFO_LEN 156U

/*
* Log's buffer flag info, size: 64 bytes head + 156 bytes's version info.
* For filed description:
* last_pos : current log's end position, last log's start position.
* write_loops: Write cyclically. Init value is 0, when memory is used
* up, the value add 1.
*/
struct log_buffer_flag {
u32 reserved0;
u32 last_pos;
u32 write_loops;
u32 log_level;
u32 reserved[LOG_BUFFER_RESERVED_LEN];
u32 max_len;
u8 version_info[VERSION_INFO_LEN];
};

struct log_buffer {
struct log_buffer_flag flag;
u8 buffer_start[0];
};

void enable_tlogger(void);
bool is_tlogger_on(void);

int tmp_tlogger_init(void);

int append_chcore_log(const char *str, size_t len, bool is_kernel);

int ot_sys_tee_push_rdr_update_addr(paddr_t addr, size_t size, bool is_cache_mem,
char *chip_type_buff, size_t buff_len);

int ot_sys_debug_rdr_logitem(char *str, size_t str_len);

#endif /* ARCH_AARCH64_ARCH_TRUSTZONE_TLOGGER_H */
114 changes: 57 additions & 57 deletions Lab1/kernel/include/common/asm.h
Original file line number Diff line number Diff line change
@@ -1,58 +1,58 @@
/*
* Copyright (c) 2023 Institute of Parallel And Distributed Systems (IPADS), Shanghai Jiao Tong University (SJTU)
* Licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
*/

#ifndef COMMON_ASM_H
#define COMMON_ASM_H

#define ASM_EXTABLE_32(insn, fixup) \
.pushsection .extable, "a"; \
.align 2; \
.word ((insn)); \
.word ((fixup)); \
.popsection;

#define ASM_EXTABLE_64(insn, fixup) \
.pushsection .extable, "a"; \
.align 4; \
.quad ((insn)); \
.quad ((fixup)); \
.popsection;

/*
* clang-format will change '%function' into '% function',
* which cannot be understood by the compiler
*/
// clang-format off
#define BEGIN_FUNC(_name) \
.global _name; \
.type _name, %function; \
_name:
// clang-format on

#define END_FUNC(_name) .size _name, .- _name

#define EXPORT(symbol) \
.globl symbol; \
symbol:

#define LOCAL_DATA(x) \
.type x, 1; \
x:

#define DATA(x) \
.global x; \
.hidden x; \
LOCAL_DATA(x)

#define END_DATA(x) .size x, .- x

/*
* Copyright (c) 2023 Institute of Parallel And Distributed Systems (IPADS), Shanghai Jiao Tong University (SJTU)
* Licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
*/
#ifndef COMMON_ASM_H
#define COMMON_ASM_H
#define ASM_EXTABLE_32(insn, fixup) \
.pushsection .extable, "a"; \
.align 2; \
.word ((insn)); \
.word ((fixup)); \
.popsection;
#define ASM_EXTABLE_64(insn, fixup) \
.pushsection .extable, "a"; \
.align 4; \
.quad ((insn)); \
.quad ((fixup)); \
.popsection;
/*
* clang-format will change '%function' into '% function',
* which cannot be understood by the compiler
*/
// clang-format off
#define BEGIN_FUNC(_name) \
.global _name; \
.type _name, %function; \
_name:
// clang-format on
#define END_FUNC(_name) .size _name, .- _name
#define EXPORT(symbol) \
.globl symbol; \
symbol:
#define LOCAL_DATA(x) \
.type x, 1; \
x:
#define DATA(x) \
.global x; \
.hidden x; \
LOCAL_DATA(x)
#define END_DATA(x) .size x, .- x
#endif /* COMMON_ASM_H */
5 changes: 4 additions & 1 deletion Lab1/kernel/include/common/macro.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@
#define likely(x) (!!(x))
#define unlikely(x) (!!(x))
#endif // __GNUC__
//
#define __maybe_unused __attribute__((unused))
#define UNUSED(x) (void)(x)

/*
* Different platform may have different cacheline size
Expand All @@ -93,4 +96,4 @@
#define OBJECT_STATE_INVALID (0)
#define OBJECT_STATE_VALID (1)

#endif /* COMMON_MACRO_H */
#endif /* COMMON_MACRO_H */
Loading