Postagens

Assignments 2

Team 1 - process hierachy Create the system call pid_father() which returns the pid of the father (see task_struct).  Make init creates one child which creates one grandson. Both init and grandson continually prints "init" and father's pid, however, the child process, exits. What happens to the grandson parent? Study the linux source code and show how the kernel changes the grandson's father.  Team 2 - process switch Last year, Shibatas's team answered the following question: Create 2 system calls: block(pid) blocks the pid process inserting it in a blocked processes queue. error = unblock() which unblock the first process in the blocked queue returning error = 0, or does nothing, and returns error = 1. Test his solution making: - init creates two children. First child continually prints "1" and second child continually prints "2". - init continually blocks first child (you must see a lot of "2"),...

A first assignment report

I am posting the first assignment received by Shibata's team, from last year. It is in Portuguese. Here it goes: https://drive.google.com/file/d/1r_sqC3u2kAfBng7aKyzgZKW8r8uj3-Nq/view?usp=sharing

Basics on ARM processor

Imagem
I am also teaching "Laboratory of Microprocessors" focusing ARM. I use  ARM Lab Manual  for the first experiences.  I have been asking students to install a tool chain in ubuntu to develop experiments in the simulator provided by arm-...-gdb. Last year, one team made everything as the docker image: https://github.com/EpicEric/gcc-arm.git In order to use it:  git clone https://github.com/EpicEric/gcc-arm.git See README.md  cd gcc-arm/ ./build_docker.sh emacs # any other editor that you prefer; perhaps, you will need sudo,and perhaps gedit suchs as:                sudo ./build_docker.sh gedit docker run --rm -ti -v "$PWD/src":/home/student/src epiceric/gcc-arm Note that your directory $PWD/src is attached to /home/student/src. In this docker image, we have 2 tool-chains: arm-elf and arm-none-eabi. In the first part of the course, we are using arm-elf. We will use arm-none-eabi to deal with ...

Assignments - 1

Imagem
My Operating System course has, generally, 4 to 5 assignments corresponding to each chapter of the book: " Operating Systems Design and Implementation, Third Edition ", i.e., 1. Introduction, 2. Processes, 3. Input and Output, 4. Memory and 5. File Systems. For the first assignment, I ask students to implement a simple system call. Generally, I divide the class into 10 teams which are given 10 different tasks. General Instructions to the First Assignment A system call makes a software interrupt. All teams must install docker and Shibata's work, visualize the switch from user to kernel mode following:  http://linux-kernel-lab.blogspot.com.br/2018/04/arm-linux-kernel-on-docker-image-with.html http://linux-kernel-lab.blogspot.com.br/2018/04/first-run.html http://linux-kernel-lab.blogspot.com.br/2018/04/first-init.html http://linux-kernel-lab.blogspot.com.br/2018/04/rebuilding-new-docker-image.html http://linux-kernel-lab.blogspot.com.br/2018/04/creating-new-te...

From user to kernel mode, step by step

Imagem
Now that we have a very silly system call (sys_hello_world), let us see how it is called, step by step, monitoring the processor mode. We may put breakpoint at sys_hello_world and run it step by step (using s or n). You must try it. The big problem is that gdb is looking to the kernel source code while init is running in user mode. We can not debug init using gdb. Thus, we will make a trick, that is, we will get an address of some instruction to be executed by init. Run the gdb till this instruction, disassembly running step by step utll find the svc instruction that makes the software interrupt. At this moment, we leave the user mode and go to the kernel mode. To get an address inside init, we do: student@a3974e81f3d7:~/src/initramfs/build/initramfs_root$ arm-linux-gnueabi-nm  init  in particular, hello_world: $ arm-linux-gnueabi-nm  init|grep hello_world  000105b4 T hello_world Now, as usual, in one terminal make qemu ... -s -S runs and in another Con...

The system call "Hello World"

In our docker image, we have a system call that prints "Hello World"  from the kernel space. Its code is in: ~/Downloads/pcs3746-sistemas-operacionais/1/linux/sys_hello_world$ ls built-in.o  Makefile  modules.builtin  modules.order  sys_hello_world.c  sys_hello_world.o Modify it: change the string to print. That is your first modification in a kernel! Make init.c as in: ~/Downloads/pcs3746-sistemas-operacionais/1/initramfs$ more init.c #include "hello_world.h" int main() {    while (1) {       hello_world();    }    return 0; } This will make a lot of messages from the kernel in your terminal. When you run it through: ~/Downloads/pcs3746-sistemas-operacionais/1$ ./run.sh  the kernel and rootfs are remade.

2. run gdb

So far you must have two terminals on your docker container: One that shows the output of qemu ... -s -S One that is in a bash. See that you can give commands such as: ls, cd, etc.  You see something like this: $ docker exec -ti upbeat_khorana bash root@db40c62a2c8d:/# su student To run a command as administrator (user "root"), use "sudo <command>". See "man sudo_root" for details. student@db40c62a2c8d:/$ alias alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"' alias egrep='egrep --color=auto' alias fgrep='fgrep --color=auto' alias gdb='arm-none-eabi-gdb -ex '\''target remote:1234'\'' /home/student/src/linux/vmlinux' alias grep='grep --color=auto' alias l='ls -CF' alias la='ls ...