如果有任何建议意见或组织社团老师同学有意共同建设git,请联系20666093@tongji.edu.cn

提交 91bfff05 编辑于 作者: GTY's avatar GTY
浏览文件

updated to catch up with gcc13 and other modern softwares

无相关合并请求
显示 625 个添加0 个删除
+625 -0
target
build
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/src",
"${workspaceFolder}/src/include",
"${workspaceFolder}/lib/include",
"${workspaceFolder}/lib/src"
],
"defines": [],
"cStandard": "c17",
"cppStandard": "c++20",
"intelliSenseMode": "linux-gcc-x86"
}
],
"version": 4
}
\ No newline at end of file
{
"version": "0.2.0",
"configurations": [
{
"name": "V6PP - build and debug kernel",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/target/objs/kernel.exe",
//"program": "${workspaceFolder}/target/objs/apps/ls.exe",
//"program": "${workspaceFolder}/target/objs/Shell.exe",
// check this ^^^^^^^^^^^
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/src",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerServerAddress": "localhost:1234",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
],
"miDebuggerPath": "/usr/bin/gdb"
},
{
"name": "nasm - debug active file",
"type": "cppdbg",
"request": "launch",
"program": ""
}
]
}
\ No newline at end of file
{
"files.encoding": "gb18030",
"files.associations": {
"*.def": "cpp",
"*.s": "asm-intel-x86-generic",
"compare": "cpp",
"cstdint": "cpp",
"format": "cpp",
"getoptandpath.h": "c"
},
"C_Cpp.default.compilerPath": "/usr/bin/g++"
}
Makefile 0 → 100644
# Unix V6++ Tongji 顶层构建脚本
#
# 创建于 2024年4月28日 上海市嘉定区
# by 2051565 GTY
.DEFAULT_GOAL := all
.PHONY: help
help:
@echo "unix-v6pp makefile"
@echo "---------------"
@echo "commands available:"
@echo "- make bochs"
@echo " build and launch unix-v6pp using Bochs"
@echo "- make qemu"
@echo " build and launch unix-v6pp using QEMU"
@echo "- make qemug"
@echo " build and launch unix-v6pp using QEMU (with GDB)"
@echo "- make"
@echo " alias for \"make all\""
.PHONY: prepare
prepare:
mkdir -p build/kernel && cd build/kernel \
&& cmake -G"Unix Makefiles" ../../src
mkdir -p target
mkdir -p target/objs
mkdir -p target/objs/asm-dump
.PHONY: build-programs
build-programs:
mkdir -p target/objs/apps
mkdir -p build/apps && cd build/apps \
&& cmake -G"Unix Makefiles" ../../programs
cd build/apps && cmake --build . -- -j 1
.PHONY: build-lib
build-lib:
mkdir -p build/lib && cd build/lib \
&& cmake -G"Unix Makefiles" ../../lib/src
cd build/lib && cmake --build . -- -j 1
mkdir -p target/objs
cp build/lib/libv6pptongji.a target/objs/libv6pptongji.a
.PHONY: build-shell
build-shell:
mkdir -p build/shell && cd build/shell \
&& cmake -G"Unix Makefiles" ../../shell
cd build/shell && cmake --build . -- -j 1
mkdir -p target/objs
cp build/shell/Shell.exe target/objs/
objcopy --remove-section .comment target/objs/Shell.exe
objdump -d target/objs/Shell.exe > target/asm-dump/Shell.exe.text.asm
objdump -D target/objs/Shell.exe > target/asm-dump/Shell.exe.full.asm
.PHONY: build
build: prepare build-lib build-programs build-shell
cd build/kernel && cmake --build . -- -j 1
.PHONY: deploy
deploy: build
mkdir -p target/img-workspace
mkdir -p target/img-workspace/programs/bin
mkdir -p target/img-workspace/programs/etc
cp target/objs/kernel.bin target/img-workspace/
cp target/objs/boot/boot.bin target/img-workspace/
cp target/objs/apps/* target/img-workspace/programs/bin/
cp target/objs/Shell.exe target/img-workspace/programs/
cp tools/unix-v6pp-filesystem-editor/bin/* target/img-workspace/
cd target/img-workspace && ./filescanner | ./fsedit c.img c
cp target/img-workspace/c.img target/
.PHONY: bochs
bochs:
@echo 'not supported. use \"make qemu\" instead.'
QEMU := qemu-system-i386
QEMU += -m 32M
QEMU += -rtc base=localtime
QEMU += -d cpu_reset -D target/qemu.log
QEMU += -machine pc
QEMU += -cpu Icelake-Server
QEMU_DISK := -boot c -drive file=target/c.img,if=ide,index=0,media=disk,format=raw
.PHONY: qemu-no-rebuild
qemu-no-rebuild:
$(QEMU) $(QEMU_DISK)
.PHONY: qemug-no-rebuild
qemug-no-rebuild:
$(QEMU) $(QEMU_DISK) -s -S
.PHONY: qemu
qemu: deploy qemu-no-rebuild
.PHONY: qemug
qemug: deploy qemug-no-rebuild
.PHONY: clean
clean:
rm -rf ./target
rm -rf ./build
.PHONY: all
all: deploy
@echo -e "\033[32mbuild success (unix-v6pp-tongji).\033[0m"
# Unix V6++ Tongji's Edition for Education
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug",
"type": "cppdbg",
"request": "launch",
"miDebuggerServerAddress": "localhost:1234",
"program": "${workspaceFolder}/targets/objs/kernel.exe",
"args": [],
"cwd": "${workspaceFolder}/src",
// 如果遇到 GDB 无法找到符号的问题, 请取消下面这段代码的注释, 并将其中出现的所有路径(共14个)改为当前项目的路径, 请注意使用斜杠 / 而不是反斜杠 \
// 注意: 如果将当前 OOS 移动到其他路径, 下面的路径也需要同步变更; 如果在 src 下添加了新文件夹, 也需要加入下面的代码中
// TODO: 当前解决方案非常不优雅, 改为路径自动填充
//
// "setupCommands": [
// {
// "text": "directory 'E:/Project/unix v6++/oos_qz3/src/boot' 'E:/Project/unix v6++/oos_qz3/src/dev' 'E:/Project/unix v6++/oos_qz3/src/fs' 'E:/Project/unix v6++/oos_qz3/src/include' 'E:/Project/unix v6++/oos_qz3/src/interrupt' 'E:/Project/unix v6++/oos_qz3/src/kernel' 'E:/Project/unix v6++/oos_qz3/src/lib' 'E:/Project/unix v6++/oos_qz3/src/machine' 'E:/Project/unix v6++/oos_qz3/src/mm' 'E:/Project/unix v6++/oos_qz3/src/pe' 'E:/Project/unix v6++/oos_qz3/src/proc' 'E:/Project/unix v6++/oos_qz3/src/program' 'E:/Project/unix v6++/oos_qz3/src/shell' 'E:/Project/unix v6++/oos_qz3/src/tty'"
// },
// ],
"externalConsole": false,
"MIMode": "gdb",
// !修改!(5) 请修改为 : MinGW GDB 所在位置
"miDebuggerPath": "E:\\Library\\OOS\\MinGW\\bin\\gdb.exe",
"preLaunchTask": "OOS Run", // 前置任务: 启动 Bochs, 运行 OOS
}
]
}
\ No newline at end of file
{
"tasks": [
{ // 编译 OOS, 使用 Ctrl + Shift + B 编译
"type": "shell",
"label": "OOS Make",
"command": "make",
"args": [
// TODO: 修改 OOS Makefile.
// 当前 OOS Makefile 在执行 make all , 部分发生修改的源代码不会重新编译
// 因此先执行一次 make clean, 但这会造成编译时间增加, 考虑优化 OOS Makefile
"clean",
"all",
"-C",
"${workspaceFolder}/src",
"SHELL=cmd", // 如果安装了 Git, make 会自动调用 bash 导致命令执行出错
],
"options": {
"env": {
// !修改!(1) 请修改为 : MinGW 所在位置
// !修改!(2) 请修改为 : NASM 所在位置
"Path": "E:\\Library\\OOS\\MinGW\\bin;E:\\Library\\OOS\\NASM;${env:Path};",
// 注意: 1. 别把 ${env:Path}; 删了
// 2. 别把分号 ; 删了
"SHELL": "cmd"
}
},
"detail": "调用 Make 编译 OOS",
"group": {
"kind": "build",
"isDefault": true
}
},
{ // 异步运行 Bochs 启动 OOS, 并且不跟踪其状态
"type": "shell",
"label": "OOS Run",
"command": "bochs.exe",
"args": [
"-q",
"-f",
"${workspaceFolder}\\targets\\UNIXV6++\\bochsrc.bxrc",
"-noconsole" // 停用命令行输出, 退出时不用再按enter
],
"options": {
"cwd": "${workspaceFolder}\\targets\\UNIXV6++\\",
"env": {
// !修改!(3) 请修改为 : Bochs所在位置
"BXSHARE": "E:\\Library\\OOS\\Bochs-2.6",
// !修改!(4) 请修改为 : Bochs所在位置
"Path": "E:\\Library\\OOS\\Bochs-2.6;${env:Path};"
// 注意: 1. 别把 ${env:Path}; 删了
// 2. 别把分号 ; 删了
}
},
"detail": "运行 OOS",
"group": {
"kind": "test",
"isDefault": true
},
"isBackground": true // 作为后台任务, 不跟踪状态, 避免堵塞后续 GDB 的运行
},
],
"version": "2.0.0"
}
\ No newline at end of file
文件已添加
文件已添加
#ifndef FILE_H
#define FILE_H
struct st_inode
{
unsigned int st_mode; /* 状态的标志位 */
int st_nlink; /* 文件联结计数,即该文件在目录树中不同路径名的数量 */
short st_uid; /* 文件所有者的用户标识数 */
short st_gid; /* 文件所有者的组标识数 */
int st_size; /* 文件大小,字节为单位 */
int st_addr[10]; /* 用于文件逻辑块好和物理块好转换的基本索引表 */
int st_atime; /* 最后访问时间 */
int st_mtime; /* 最后修改时间 */
};
int creat(char* pathname, unsigned int mode);
int open(char* pathname, unsigned int mode);
int close(int fd);
int write(int fd, char* buf, int nbytes);
int read(int fd, char* buf, int nbytes);
int mknod(char* pathname,unsigned int mode, int dev);
int link(char* pathname,char* newPathname);
int unlink(char* pathname);
int chdir(char* pathname);
int seek(int fd,unsigned int offset,unsigned int ptrname);
int chmod(char* pathname,unsigned int mode);
int chown(char* pathname,short uid, short gid);
int pipe(int* fildes);
int dup(int fd);
int fstat(int fd,unsigned long statbuf);
int stat(char* pathname,unsigned long statbuf);
#endif
#ifndef MALLOC_H
#define MALLOC_H
#include <stddef.h>
void* malloc(unsigned int);
int free(void*);
#endif
#ifndef STDDEF_H
#define STDDEF_H
#define NULL 0
#endif
#ifndef STDIO_H
#define STDIO_H
#define STDIN 0
#define STDOUT 1
int sprintf(char* buffer, char* fmt,...);
void printf(char* fmt,...);
void gets(char *s);
/* Don't Del It!!! */
extern char *g_STDIO_str;
extern int g_STDIO_data;
extern char g_STDIO_bss[10];
#endif
#ifndef STDLIB_H
#define STDLIB_H
extern int errno;
char* itoa( long value, char* buffer, int radix );
char* ltoa( int value, char* buffer, int radix );
char* ultoa( int value, char* buffer, int radix );
char* _itoa( unsigned long value, int is_sign, char* buffer, int radix);
/* ftoa由于其精度问题不再使用*/
char* ftoa( float value, char* buffer, int precision );
char* lftoa( double value, char* buffer, int precision );
char* exlftoa( double value, char* buffer, int precision, char e );
#endif
#ifndef STRING_H
#define STRING_H
int strcmp( unsigned char* src, unsigned char* dst);
char* strcpy( char* src, char* dst);
char* strcat( char* src, char* dst);
int strlen (char* str);
void* memset(void* dst, int c, unsigned int len);
#endif
#ifndef SYS_H
#define SYS_H
#include <time.h>
/* p_sig中接受到的信号定义 */
#define SIGNUL 0 /* No Signal Received */
#define SIGHUP 1 /* Hangup (kill controlling terminal) */
#define SIGINT 2 /* Interrupt from keyboard */
#define SIGQUIT 3 /* Quit from keyboard */
#define SIGILL 4 /* Illegal instrution */
#define SIGTRAP 5 /* Trace trap */
#define SIGABRT 6 /* use abort() API */
#define SIGBUS 7 /* Bus error */
#define SIGFPE 8 /* Floating point exception */
#define SIGKILL 9 /* Kill(can't be caught or ignored) */
#define SIGUSR1 10 /* User defined signal 1 */
#define SIGSEGV 11 /* Invalid memory segment access */
#define SIGUSR2 12 /* User defined signal 2 */
#define SIGPIPE 13 /* Write on a pipe with no reader, Broken pipe */
#define SIGALRM 14 /* Alarm clock */
#define SIGTERM 15 /* Termination */
#define SIGSTKFLT 16 /* Stack fault */
#define SIGCHLD 17 /* Child process has stopped or exited, changed */
#define SIGCONT 18 /* Continue executing, if stopped */
#define SIGSTOP 19 /* Stop executing */
#define SIGTSTP 20 /* Terminal stop signal */
#define SIGTTIN 21 /* Background process trying to read, from TTY */
#define SIGTTOU 22 /* Background process trying to write, to TTY */
#define SIGURG 23 /* Urgent condition on socket */
#define SIGXCPU 24 /* CPU limit exceeded */
#define SIGXFSZ 25 /* File size limit exceeded */
#define SIGVTALRM 26 /* Virtual alarm clock */
#define SIGPROF 27 /* Profiling alarm clock */
#define SIGWINCH 28 /* Window size change */
#define SIGIO 29 /* I/O now possible */
#define SIGPWR 30 /* Power failure restart */
#define SIGSYS 31 /* invalid sys call */
int execv(char* pathname, char* argv[]);
int fork();
int wait(int* status);
int exit(int status);
int signal(int signal, void (*func)());
int kill(int pid, int signal);
int sleep(unsigned int seconds);
int brk(void * newEndDataAddr);
int sbrk(int increment);
int syncFileSystem();
int getPath(char* path);
int getpid();
unsigned int getgid();
unsigned int getuid();
int setgid(short gid);
int setuid(short uid);
int gettime(struct tms* ptms); /* 读系统时钟 */
/* 获取进程用户态、核心态CPU时间片数 */
int times(struct tms* ptms);
/* 获取系统进程切换次数 */
int getswtch();
/* 启用屏幕底部的lines行输出调试信息 */
int trace(int lines);
#endif
#ifndef TIME_H
#define TIME_H
/* 保存系统时间信息的结构体 */
struct tm
{
int Second; /* Seconds: 0 ~ 59 */
int Minute; /* Minutes: 0 ~ 59 */
int Hour; /* Hours of Day: 0 ~ 23 */
int DayOfMonth; /* Day of Month: 1 ~ 31 */
int Month; /* Months since January: 1 ~ 12 */
int Year; /* Years since 1900 */
int DayOfWeek; /* Days since Sunday: 1 ~ 7 */
};
/* 记录进程使用的内核态和用户态下CPU时间的结构体 */
struct tms
{
int utime; /* 进程用户态CPU时间 */
int stime; /* 进程核心态CPU时间 */
int cutime; /* 子进程用户态时间总和 */
int cstime; /* 子进程核心态时间总和 */
};
/* 获取进程用户态、核心态CPU时间片数 */
extern int times(struct tms* ptms);
#define SECONDS_IN_MINUTE (60)
#define SECONDS_IN_HOUR (3600)
#define SECONDS_IN_DAY (86400)
#define isLeapYear(year) ((year % 4) == 0 && ( (year % 100) != 0 || (year % 400) == 0 ))
/* 某个月份前经过的天数,第0项不使用,未纳入计算闰年2月份29天 */
static unsigned int daysBeforeMonth[13] = { 0xFFFFFFFF/* Unused */,
0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
static unsigned int daysInMonth[13] = { 0xFFFFFFFF/* Unused */,
31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
static int weekdayNumber[7] = {4/*Thrusday*/, 5, 6, 7, 1, 2, 3};
static char* weekdayName[8] = { "NOT Used", "SUN", "MON", "TUE",
"WED", "THUR", "FRI", "SAT"};
static char* monthName[13] = {"NOT Used", "Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
/* 获取系统时间,返回值从1970年1月1日0时至当前的秒数 */
unsigned int gtime();
/* 设置系统时间,参数seconds从1970年1月1日0时至当前的秒数 */
int stime(unsigned int seconds);
/* 根据tm结构体中的值计算出从1970年1月1日0时至当前的秒数 */
unsigned int mktime(struct tm* ptime);
/* 根据参数seconds(从1970年1月1日0时至当前的秒数)设置tm结构体的各项值 */
struct tm* localtime(unsigned int timeInSeconds);
/* 根据tm结构体中的值,返回ASCII格式的时间日期值 */
char* asctime(struct tm* ptime);
/* 返回一年的天数,闰年为366天 */
unsigned int daysInYear( int year );
#endif
#[[
Lib 构造文件
创建于 2024年4月28日 上海市嘉定区安亭镇
by 2051565 GTY
]]
cmake_minimum_required(VERSION 3.29.2)
string(TIMESTAMP build_time_iso8601 UTC) # example: 2024-04-19T13:39Z
string(TIMESTAMP build_time_human_readable "%B %d, %Y %H:%M:%S %Z")
set(V6PP_BUILD_TIME_ISO8601 ${build_time_iso8601})
set(V6PP_BUILD_TIME_HUMAN_READABLE ${build_time_human_readable})
project(v6pptongji)
# 指定使用 C++20
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
# 头文件路径。
include_directories("${PROJECT_SOURCE_DIR}/../include")
include_directories("${PROJECT_SOURCE_DIR}")
# GCC(g++) 编译选项。
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nostartfiles")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-builtin")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nostdinc")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-pic")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-pie")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -no-pie")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nostdlib")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-stack-protector")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-threadsafe-statics")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-use-cxa-atexit")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mno-red-zone")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mno-mmx")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mno-sse")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mno-sse2")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mcmodel=large") # 编译64位内核时需启用
set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS}")
#[[
项目构造产物
]]
file(GLOB_RECURSE CPP_SOURCE_FILES *.cpp)
file(GLOB_RECURSE C_SOURCE_FILES *.c)
add_library(
v6pptongji STATIC
${CPP_SOURCE_FILES}
${C_SOURCE_FILES}
)
set_target_properties(
v6pptongji PROPERTIES
COMPILE_FLAGS "-m32"
LINK_FLAGS "-m32"
)
支持 Markdown
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册