fzdwx

fzdwx

Hello , https://github.com/fzdwx

Record learning jyyos operating system course

Recently, I have started following the operating system course at Nanjing University again (I gave up halfway through the previous few times), so I'm recording it.

1. The first issue is that I couldn't find the ld command when compiling a demo for the third lecture.#

http://jyywiki.cn/OS/2023/build/lect3.ipynb demo('hello-os', 'i/hello-os')

Since I am using Arch Linux, the ld, gcc, and other commands compiled by binutils do not have the x86 prefix. However, the Makefile defines them with the x86 prefix, so I need to create a symbolic link:

ln -s /usr/bin/ld /usr/bin/x86_64-linux-gnu-ld

{{< block type="tip" title="Explanation from chatgpt:">}}
This command creates a symbolic link named "x86_64-linux-gnu-ld" that points to "/usr/bin/ld". This symbolic link can be used as a substitute for the "x86_64-linux-gnu-ld" binary file.
A symbolic link is a special type of file that is a pointer to another file. It can be used to create aliases to other files or directories in the file system.

In Linux systems, "/usr/bin/ld" is a linker used to merge multiple object files into a single executable file. By creating a symbolic link named "x86_64-linux-gnu-ld", the functionality of this linker can be used on different systems without changing the code of the executable file.
This symbolic link is commonly used for cross-compiling applications, where the application runs on different hardware platforms.
{{< /block >}}

2. When using editors like vscode, the header files in the code of the first issue cannot be navigated.#

Use bear to generate compile_commands.json, and then the editor will automatically recognize it.

bear -- make

{{< block type="tip" title="Explanation from chatgpt:">}}
This command uses Bear and Make tools to automatically capture the compilation commands in the Makefile and the call chain during compilation.

Specifically, Bear is a tool that converts the output of the system call tracer (strace) into a JSON file format, which contains all the system calls made during runtime.
Make is a tool used to automatically build and compile programs based on Makefile rules.

When these two tools are used together, the "bear -- make" command can automatically capture the compilation commands in the Makefile and the call chain during compilation, which can be used for debugging in subsequent stages.
Executing this command will generate a JSON file that contains all the system calls during compilation and their arguments. This file can be used for debugging, performance optimization, and the development of automated compilation and build systems.

In summary, the "bear -- make" command can help programmers better understand what their code is doing during compilation and identify potential issues in the code.
{{< /block >}}

3. Write a pstree - M1#

http://jyywiki.cn/OS/2023/labs/M1

Implementation approach:

  1. Scan all folders in the /proc/ directory that are numeric.
  2. Read the /proc/{pid}/status file.
  3. Read the name and ppid.
  4. Build the tree and print the tree structure.

4. About compiling the new os-workbench#

Today I tried downloading the code repository for 2023, and unexpectedly, I was able to download it.

~~git clone https://git.nju.edu.cn/jyy/os-workbench.git~~

Then I pulled L0 to run it, but it couldn't run no matter what: [-Werror=array-bounds] is about array out of bounds.
The file is os-workbench/abstract-machine/am/build/x86_64-qemu/src/x86/qemu/ioe.o:433.

~~git pull origin L0~~

The solution is to add -Wno-array-bounds at the end of CFLAGS in os-workbench/abstract-machine/Makefile.

5. Run the code for 2023#

Last night, I couldn't get it to run with the L0 code on my local machine. QEMU started normally, but the screen was black. The environment is:

Linux archlinux 6.2.2-arch1-1
qemu 7.2
gcc 12.2.1

In the end, I had to find a workaround and build it in Docker, and then run QEMU on my local machine (it's not convenient to use a graphical interface in Docker).

FROM ubuntu:22.04
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update
RUN apt-get install -y build-essential git gcc-multilib qemu-system strace gdb sudo python3 libsdl2-dev libreadline-dev llvm-11 
RUN useradd -ms /bin/bash user
USER user
WORKDIR /home/users
docker build -t jyyos .
# os-workbench
docker run --rm -it -v ${PWD}:/mnt -w /mnt jyyos bash

# exit docker : os-workbench/kernel
make
qemu-system-x86_64 -serial mon:stdio -machine accel=tcg -smp "" -drive format=raw,file=./build/kernel-x86_64-qemu

There may still be issues with the compilation, but after compiling in Docker, the fourth issue did not occur.

6. Display an image in AbstractMachine - L0#

I remember last year we were working on a game that could move and respond based on keyboard input. This year, we just need to print an image. Here's the general idea:

  1. xxd -i xxx.png > img_data.h
  2. Traverse this array, extract RGB, and call draw_title.
  3. Parse the parameters, get the desired resolution, then obtain the scaling factor for width and height, and finally get the corresponding pixels.

I feel like there's an issue with my implementation; it's just zooming in on the top left corner.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.