解决指定内存区域分配时,缺页模拟的内存还是使用的第一块

This commit is contained in:
zhangzheng
2025-03-30 13:16:30 +08:00
parent 7d689eda0f
commit 1013936ec1
46 changed files with 231 additions and 139 deletions

View File

@@ -25,42 +25,42 @@ add_subdirectory(cutest)
add_subdirectory(fd)
add_custom_target(
mkrtos_static_libc ALL
#以下命令用于生成binutils链接需要的库
COMMAND
cd ${CMAKE_SOURCE_DIR}/build
COMMAND
rm -f -r usr_lib
COMMAND
mkdir -p usr_lib
COMMAND
find mkrtos_user -name "*.a" | xargs cp -t usr_lib
COMMAND
cd usr_lib
COMMAND
${CMAKE_AR} x libmuslc.a
COMMAND
${CMAKE_AR} x liblibc_be.a
COMMAND
${CMAKE_AR} x libsys.a
COMMAND
${CMAKE_AR} x libsys_svr.a
COMMAND
${CMAKE_AR} x libsys_util.a
COMMAND
${CMAKE_AR} x libutil.a
COMMAND
${CMAKE_AR} cr libnewc.a *.obj
COMMAND
rm *.obj
)
add_dependencies(
mkrtos_static_libc
muslc
libc_be
sys
sys_svr
sys_util
util
)
# add_custom_target(
# mkrtos_static_libc ALL
# #以下命令用于生成binutils链接需要的库
# COMMAND
# cd ${CMAKE_SOURCE_DIR}/build
# COMMAND
# rm -f -r usr_lib
# COMMAND
# mkdir -p usr_lib
# COMMAND
# find mkrtos_user -name "*.a" | xargs cp -t usr_lib
# COMMAND
# cd usr_lib
# COMMAND
# ${CMAKE_AR} x libmuslc.a
# COMMAND
# ${CMAKE_AR} x liblibc_be.a
# COMMAND
# ${CMAKE_AR} x libsys.a
# COMMAND
# ${CMAKE_AR} x libsys_svr.a
# COMMAND
# ${CMAKE_AR} x libsys_util.a
# COMMAND
# ${CMAKE_AR} x libutil.a
# COMMAND
# ${CMAKE_AR} cr libnewc.a *.obj
# COMMAND
# rm *.obj
# )
# add_dependencies(
# mkrtos_static_libc
# muslc
# libc_be
# sys
# sys_svr
# sys_util
# util
# )

View File

@@ -75,11 +75,11 @@ int ls(int argc, char *agrv[])
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN), ls, ls, ls command);
int cp(int argc, char *argv[])
{
#define BUFFER_SIZE 64
#define BUFFER_SIZE 1024
int source_fd, target_fd;
ssize_t bytes_read, bytes_written;
char buffer[BUFFER_SIZE];
char *buffer;
int ret;
// 检查参数数量
@@ -88,12 +88,19 @@ int cp(int argc, char *argv[])
fprintf(stderr, "example: %s /bin/a.bin /mnt/a.bin\n", argv[0]);
return -1;
}
// 分配缓冲区
buffer = (char *)u_malloc(BUFFER_SIZE);
if (buffer == NULL)
{
perror("malloc buffer is error.\n");
return -1;
}
// 打开源文件
source_fd = open(argv[1], O_RDONLY);
if (source_fd == -1)
{
perror("can not open src file.\n");
u_free(buffer);
return -1;
}
struct stat st = {0};
@@ -106,11 +113,13 @@ int cp(int argc, char *argv[])
{
perror("can not open dest file.");
close(source_fd);
u_free(buffer);
return -1;
}
if (ftruncate(target_fd, st.st_size) < 0)
{
printf("to set fiel size is error.\n");
u_free(buffer);
return -1;
}
@@ -123,6 +132,7 @@ int cp(int argc, char *argv[])
perror("write file is error.\n");
close(source_fd);
close(target_fd);
u_free(buffer);
return -1;
}
}
@@ -135,7 +145,7 @@ int cp(int argc, char *argv[])
// 关闭文件
close(source_fd);
close(target_fd);
u_free(buffer);
printf("cp file is success.\n");
return 0;

View File

@@ -1473,7 +1473,7 @@ void shellExec(Shell *shell)
}
if (shell->parser.param[shell->parser.paramCount - 1][0] == '@')
{
// 指定启动的mem参数少一个
// 指定启动的pid
pid = atoi(&(shell->parser.param[shell->parser.paramCount - 1][1]));
shell->parser.paramCount--;
}

View File

@@ -39,6 +39,30 @@
#define IS_ENABLED(option) __or(IS_BUILTIN(option), IS_MODULE(option))
static unsigned int mk_ffs(unsigned int x)
{
unsigned int ret;
__asm__ volatile("clz\t%0, %1"
: "=r"(ret)
: "r"(x)
: "cc");
ret = (sizeof(void *) * 8 - 1) - ret;
return ret;
}
static inline unsigned long is_power_of_2(unsigned long num)
{
return (num & (num - 1)) == 0;
}
static inline unsigned long align_power_of_2(unsigned long num)
{
if (is_power_of_2(num))
{
return num;
}
return (1 << (mk_ffs(num) + 1));
}
/* Import a binary file */
#define IMPORT_BIN(sect, file, sym) asm (\
".section " #sect "\n" /* Change section */\