Skip to content

Commit

Permalink
增加一个测试程序
Browse files Browse the repository at this point in the history
  • Loading branch information
min0911Y committed Dec 31, 2024
1 parent 0630930 commit 577d37e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
2 changes: 2 additions & 0 deletions apps/filereader/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_binary(filereader)
target_link_libraries(filereader misc)
17 changes: 17 additions & 0 deletions apps/filereader/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

#include <libc.h>
#include <sys.h>
int main(int argc, const char **argv) {
if (argc != 2) {
printf("Usage: %s filename\n", argv[0]);
return 1;
}
size_t size = __syscall(SYSCALL_FILE_SIZE, argv[1]);
byte *buff = (byte *)xmalloc(size);
__syscall(SYSCALL_LOAD_FILE, argv[1], buff, size);
for (int i = 0; i < size; i++) {
printf("%c", buff[i]);
}
printf("\n");
return 0;
}
1 change: 1 addition & 0 deletions src/boot/make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ mcopy -i disk.img v86_service.bin ::
qemu-img create hd.img 128M
mformat -t 64 -h 64 -i hd.img
mcopy -i hd.img testapp.bin ::
mcopy -i hd.img filereader.bin ::
mcopy -i hd.img testapp-cpp.bin ::
mcopy -i hd.img font1.plff ::
mcopy -i hd.img font2.plff ::
Expand Down
20 changes: 0 additions & 20 deletions src/kernel/task/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,26 +182,6 @@ int shell_exec(char *path, cstr comand) {
pos += len;
}
free(buf);
} else if (strneq(comand, "readhex ", 8)) {
char *s = comand + 8;
vfs_node_t p = vfs_open(s);
if (!p) {
printf("open %s failed\n", s);
return 1;
}
if (p->type == file_dir) {
printf("not a file\n");
return 1;
}
size_t size = p->size;
byte *buf = malloc(size);
memset(buf, 0, size);
vfs_read(p, buf, 0, size);
for (size_t i = 0; i < size; i++) {
printf("%02x ", buf[i]);
}
printf("\n");
free(buf);
} else if (strneq(comand, "mkdir ", 6)) {
vfs_mkdir(comand + 6);
} else if (strneq(comand, "mount ", 6)) {
Expand Down

0 comments on commit 577d37e

Please sign in to comment.