web123456

Linux 0.12 Compilation and Clion Debugging

1. Introduction

1. Modified part of the c and assembly code, can be compiled by the latest version of GCC (my computer macOS Catalina 10.15; gcc).version 10.3.0 (GCC))

2. Learning materials are placed in the source code directory of the study, you can check with the

2. Compile the source code

  1. Download source code/galis/linux-0.12
  2. Modify the Makefile file in the root directory of the source code, change the following paths to your computer's
export KERNEL_INCLUDE = /Volumes/mac-code/linux-0.12/include
export GCC_PREFIX = /usr/local/opt/x86_64-elf-gcc/bin/x86_64-elf-
export BINUTILS_PREFIX = /usr/local/opt/x86_64-elf-binutils/bin/x86_64-elf-
  • 1
  • 2
  • 3
  1. fulfillmentmake clean && make, you can get Image, located in the root directory of the source code

3. Operation and commissioning

  1. Make sure you have bochs installed on your computer to support gdb, please find out how to install bochs on your own, there is a lot of information on the internet.
  2. Unzip tools/root-0., get tools/root-0.... (git does not allow more than 100M files to be uploaded!)
  3. Modify the tools/scripts configuration to suit the situation
LINUX_CODE_PATH=/Volumes/mac-code/linux-0.12
BOCHS_EXE_PATH=/Volumes/mac-data/bochs-2.6.11/build-mac-gdb/bin/bochsdbg
BOCHS_CONFIG_PATH=${LINUX_CODE_PATH}/tools/bochsconfig_linux12.txt
  • 1
  • 2
  • 3
  1. Modify the tools/bochsconfig_linux11.txt configuration as appropriate
romimage:file=/Volumes/mac-data/bochs-2.6.11/build-mac/share/bochs/BIOS-bochs-latest
vgaromimage:file=/Volumes/mac-data/bochs-2.6.11/build-mac/share/bochs/VGABIOS-lgpl-latest
floppya:1_44=/Volumes/mac-code/linux-0.12/Image,status=inserted
ata0-master: type=disk, mode=flat, path="/tmp/root-0.", cylinders=410, heads=16, spt=38
  • 1
  • 2
  • 3
  • 4
  1. existClionCreate a script to execute the configuration, fill in the relevant parameters, click OK to create

    parametersScript Path, select tools/ in the source code root directory.
    parametersWorking Directory,Select the path to the source code root directory

在这里插入图片描述

  1. Create a GDB REMOTE DEBUG configuration in Clion, then fill in the relevant parameters, and click OK to create.

    parameterssymbol file, select the source code compiled from the tools/
    parameterssysroot, select the source code root directory.
    Before launchAdd the Shell Script you created in step 5.The goal is to compile and start bochs before debugging.

在这里插入图片描述

  1. At the point of interruption, click on the debug button to debug it

在这里插入图片描述
在这里插入图片描述

4. Notes and Revision Records

  1. Remove AS86 LD86 and replace it with gcc
  2. Compiling with as
  3. Delete seg, change some code. seg affects the next statement only.
  4. export variables for the next level of makefiles
  5. Delete the compilation clobber list
  6. Extending the assembly requires %%, not extending it requires %%.
  7. Merge redefinition symbols, using only the first symbol. ld
  8. lvalue required as left operand of assignment There's no good way to do this, just rewrite it.
  9. Remove the function modifier _. Change it yourself...BUILD irq lots of
  10. In Mac case-sensitive is very important, in the MAC compiler to pay attention to whether the partition support case.
  11. invalidate_buffers I can't find it.。Add a lineextern void invalidate_buffers(int dev);
  12. Outputs and memory variable inputs at the same time should be taken care of.
  13. HD controller not ready problem

The original statement:
163 int retries=10000;
165 while (–retries && (inb_p(HD_STATUS)&0xc0)!=0x40);
modify to
163 int retries=100000;
165 while (–retries && (inb_p(HD_STATUS)&0x80));
The reasoning is that whether the driver is ready or not is independent of the state of the controller, we only need to detect if the status register busy bit is 1, we don't need to care about the ready bit. `