inaciose
Posts: 17
Joined: Thu Aug 24, 2017 3:34 pm

Anyone wants to help to do a working port of xv6 to PI2/3 on armv7

Tue Sep 26, 2017 3:26 am

There is some ports done for armv6, armv7 and armv8. T ports I have found for the armv7 and armv8 are not complete.
They missing multitasking, and don't recover from a ilegal memory access done by user mode processes (the os just hangs).

Because of the above issues, the preempt (multitasking) test and the sbrk test (process memory grow) fail.

The preempt test is usually commented out so people just trying didn't notice the missing multitasking feature.
The sbrk test os just hangs after a data abort exception.

After some time reading the code, its a simple base code of unix, not many files, and making experiences I manage to put the multitasking working, and manage to do all tests without hanging the os.

But the sbrk test still not full complete, i just manage to kill the offending usr processes, the sbrktest child's and sbrktest, and the os continues running without crash or hang. But sbrktest dont run until the end of the code, its killed before.

In xv6 x86 in original code, the sbrktest its not killed, just the child's, and sbrktest continues running until the end of the code.

This different behavior is the main issue.

There are also some more tests implemented in xv6 x86 original code, that are missing in arm versions. The code is portable, but i don't know if these ones fail, need copy the code, compile and run, just to see.

The missing tests list.

argptest
fourfiles
openiputtest
exitiputtest
iputtest
uio

So, i need help in my main issue, different behavior of the sbrktest
- the updated arm version, don't hangs and sbrktest don't full complete;
- the x86 version don't hangs and sbrktest full complete;

Code for real machine
https://github.com/inaciose/xv6-armv7-rpi

Code for qemu vexpress-a15 (quick run for debugging) when problem its not related directly related with raspberry hardware pi devices.
https://github.com/inaciose/xv6-armv7-a15

I hope some one could help to get a proper working xv6 on armv7 world, to use in raspeberry pi 2 and 3.

if you have any questions feel free to ask.

LdB
Posts: 912
Joined: Wed Dec 07, 2016 2:29 pm

Re: Anyone wants to help to do a working port of xv6 to PI2/3 on armv7

Thu Sep 28, 2017 10:35 am

The code appears to be baremetal, so do you even know if the compiler implements S_BRK?

A quick search of the repository tells me you haven't implemented it so you are going to praying the compiler library does.

inaciose
Posts: 17
Joined: Thu Aug 24, 2017 3:34 pm

Re: Anyone wants to help to do a working port of xv6 to PI2/3 on armv7

Fri Sep 29, 2017 11:11 pm

There is a syscall sbrk that calls the growproc process.
The growproc is in proc.c. The syscall code are bellow.

I don't understand what's missing in sbrk. But I believe it's nothing missing. The problem is not in process memory shrinks or grows, but the handling of data abort exception.

If you still interested in the subject I explain better. In some way I suspect that after a databort exception, the parent of the killed process get the program counter of the killed child.



https://github.com/inaciose/xv6-armv7-a ... /sysproc.c

int sys_sbrk(void)
{
int addr;
int n;

if(argint(0, &n) < 0) {
return -1;
}

addr = proc->sz;

if(growproc(n) < 0) {
return -1;
}

return addr;
}

sumeet
Posts: 21
Joined: Mon Jan 15, 2018 3:34 pm

Re: Anyone wants to help to do a working port of xv6 to PI2/3 on armv7

Tue Jan 23, 2018 2:11 pm

Trying to build https://github.com/inaciose/xv6-armv7-rpi.git on Ubuntu 16.04. I am getting error when I run make.

arm-none-eabi-objdump -S build/initcode.o > initcode.asm
make -C tools
make[1]: Entering directory '/home/sumeet/source/xv6-armv7-rpi/tools'
gcc -Werror -Wall -iquote ../ -o mkfs mkfs.c
mkfs.c:14:0: error: "static_assert" redefined [-Werror]
#define static_assert(a, b) do { switch (0) case 0: case (a): ; } while (0)
^
In file included from mkfs.c:6:0:
/usr/include/assert.h:120:0: note: this is the location of the previous definition
# define static_assert _Static_assert
^
cc1: all warnings being treated as errors
Makefile:9: recipe for target 'mkfs' failed
make[1]: *** [mkfs] Error 1
make[1]: Leaving directory '/home/sumeet/source/xv6-armv7-rpi/tools'
Makefile:73: recipe for target 'build/fs.img' failed
make: *** [build/fs.img] Error 2

LdB
Posts: 912
Joined: Wed Dec 07, 2016 2:29 pm

Re: Anyone wants to help to do a working port of xv6 to PI2/3 on armv7

Thu Jan 25, 2018 12:03 pm

In C11 they actually gave us a static assert
http://en.cppreference.com/w/c/error/static_assert

So GCC is complaining static_assert is already defined because it is compiling in C11 or higher mode but you have a macro with a restricted name. So this macro is illegal in C11 and beyond
#define static_assert(a, b) do { switch (0) case 0: case (a): ; } while (0)
Normally you remove the static_assert macro totally and in any C file that calls it add the standard c header

Code: Select all

#include <assert.h>  

It's old school how to make the compiler break at compile time if something is wrong ... the xv6 code is old like me.

The old post above with the SBRK won't work either so hopefully it's fixed in your code :-)

sumeet
Posts: 21
Joined: Mon Jan 15, 2018 3:34 pm

Re: Anyone wants to help to do a working port of xv6 to PI2/3 on armv7

Fri Jan 26, 2018 12:26 pm

Thanks again LdB. I commented the #define for static_assert and it compiled!

But unfortunately I cannot see anything on my monitor - it shows the colourful box which means the framebuffer is not initialized. Maybe it uses UART for IO?

@inaciose: Can you confirm and provide instructions on how to build and use the code?

LdB
Posts: 912
Joined: Wed Dec 07, 2016 2:29 pm

Re: Anyone wants to help to do a working port of xv6 to PI2/3 on armv7

Sat Jan 27, 2018 11:00 am

If you link a source/github site I will have a quick look :-)


LdB
Posts: 912
Joined: Wed Dec 07, 2016 2:29 pm

Re: Anyone wants to help to do a working port of xv6 to PI2/3 on armv7

Sat Jan 27, 2018 2:23 pm

Downloading but first obvious thing is it is setup for 0x0 startup from linker as its designed for QEMU

From makefile
$(call LINK_INIT, -N -e start -Ttext 0)
You need it at 0x8000 OR use config.sys and kernel_old =1 trick on a real Pi with bootloader in baremetal

I will setup a proper linker file it's a bit primitive calling the linker directly.

UPDATE:
Ok sorted the makefiles out and put in a linker directive file and everything is building but I have an issue are you trying to run this on linux or baremetal?

The reason for the question is this looks like it is supposed to have a file system ... is that correct?
Under baremetal compilation I am getting this sort of thing
undefined reference to `fwrite'
undefined reference to `read'
undefined reference to `close'
Under linux not a problem the libraries connect to the linux file system but baremetal, I have to implement a filesystem and hook it to the SD Card for example.

The code hasn't sorted out the memory allocator either but that isn't hard to make a simple one :-)

sumeet
Posts: 21
Joined: Mon Jan 15, 2018 3:34 pm

Re: Anyone wants to help to do a working port of xv6 to PI2/3 on armv7

Sat Jan 27, 2018 4:04 pm

I wanted to run it on a real Pi baremetal but qemu would also be fine.

I wanted to learn how operating systems work. I started looking at Linux but that is huge. So I found about MIT xv6 which looks small enough for my little brain to grasp.

If the implementation for this port is incomplete then you can just leave it (unless you have time and interest to complete the implementation ;) ). I just started doing assembly so writing memory manager, etc. is too much for me :P.

I think I am rushing through things and need to slow down. I have received my USB to TTL cable today. I will first try to setup a good dev environment like you suggested in the other thread - will give VS2017 a shot. Once I am able to write and debug code conveniently and get my basics strong then I can get into reading OS code, etc.

sumeet
Posts: 21
Joined: Mon Jan 15, 2018 3:34 pm

Re: Anyone wants to help to do a working port of xv6 to PI2/3 on armv7

Mon Jan 29, 2018 11:08 pm

This port works if anyone is interested: https://github.com/zhiyihuang/xv6_rpi2_port.git

Edit Makefile and fix the TOOLCHAIN variable.
Then follow instructions in README. Basically run "make loader" and copy kernel7.img and config.txt as specified in README to the SDcard ofcourse along with bootcode.bin and start.elf

Connect your Pi to your laptop/desktop with USB to TTL cable. Then run "sudo screen /dev/ttyUSB0 115200" or equivalent for your system.

Return to “C/C++”