serial: fix input interrupts on VMWare

The serial-port input was not working on VMWare, because interrupts were
not received. It turns out that VMWare does not send serial-port interrupts
(IRQ 4) unless the Aux Output 2 bit of the MCR register in the UART is
enabled. Many physical PCs also require this bit, but it's surprising that
VMWare bothers to check it - QEMU doesn't.

So this patch turns on that bit, and serial-port input starts to work
correctly on VMWare.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
gdb: fix 'osv thread' to work with GDB with python3

GDB's convert_value_from_python() with python2 was interpreting 'long'
typed value which doesn't fit into 'long long' as 'unsigned long
long'. On python3 we only have 'int' but the function was not adjusted
to replicate 'long' behavior, it throws overflow error if the value
exceeds 'long' range.

The value is converted using that function for example when it is
passed as gdb.Value() argument or when gdb.Value is used as comparison
target:

  if gdb_value == 0xffff000000000000:

The above will fail with:

  OverflowError: Python int too large to convert to C long

because GDB will try to fit the numeric constant on the right into
'long' on python3. As a workaround I convert gdb_value to python like
this:

  if ulong(gdb_value) == 0xffff000000000000:

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
gdb: fix 'osv pagetable walk'

gdb.Value() handled 'int' differently than 'long' on python2. When the
value was 'int' GDB tried to fit it in 'long' (signed) whereas when it
was 'long', it tried 'unisgned long long'. On python3 we no longer
have 'long' and gdb.Value will treat python3's int the same way as
python2's int. We relied on being able to put unsigned long numbers
into gdb.Value and it seems there is no way to do that on python3. The
workaround is to use gdb.parse_and_eval() instead of gdb.Value
constructor.

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
gdb: use parentheses in print

So that it works on GDB with python3.

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
scripts: Python3 support for scripts/nbd_client.py

Standard exceptions are build-in now, and 'exceptions' module
was removed from Python3.

Use bytes instead of string, since no implicitly conversion between
them in Python3.

Signed-off-by: Zifei Tong <zifeitong@gmail.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
scripts: Python3 support for scripts/imgedit.py

* Use floor division. As in Python3, the default division is float division.
* Encode string when bytes are required.
* Use Python3 style print function.

Signed-off-by: Zifei Tong <zifeitong@gmail.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
scripts: Python3 support for scripts/osv/modules/resolve.py

* Use Python3 style print function.
* Fix inconsistent use of tabs and spaces.

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Zifei Tong <zifeitong@gmail.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
scripts: Python3 support for scripts/osv/modules/filemap.py

* dict.iteritems() and itertools.ifilter() are removed form Python3, use
dict.items(), and build-in filter() function.
* Change loop variable name to avoid shadow build-in filter() function.

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Zifei Tong <zifeitong@gmail.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
scripts: Python3 support for scripts/module.py

* Use Python3 style print function.
* 'basestring' is removed from Python3, use 'str' instead.
* reduce() is removed from build-ins in Python3, import it from functools.

Signed-off-by: Zifei Tong <zifeitong@gmail.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
scripts: leave only one '[manifest]' in manifest files

Started in Python 3.2, configparser will not allow for any section
duplicates while reading from file by default. This change of default
behavior will cause upload_manifest.py failing. So make sure only one
[manifest] section tag left while generating manifest files.

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Zifei Tong <zifeitong@gmail.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
scripts: Python3 support for scripts/upload_manifest.py

* StringIO and ConfigParser are removed from Python3, use io.StringIO
and configparser instead.
* The backported io.StringIO requires unicode string not basestring in
Python2.
* Use Python3 style print function.
* Send bytes through socket to guest instead of string, and decode bytes
read from sys.stdout.

Signed-off-by: Zifei Tong <zifeitong@gmail.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
scripts: Python3 support for scripts/mkzfs.py

* StringIO and ConfigParser are removed from Python3, use io.StringIO
and configparser instead.
* The backported io.StringIO requires unicode string not basestring in
Python2.
* file() removed from Python3, use open().

Signed-off-by: Zifei Tong <zifeitong@gmail.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
scripts: Python3 support for scripts/mkbootfs.py

* StringIO and ConfigParser are removed from Python3, use io.StringIO
and configparser instead.
* The backported io.StringIO requires unicode string not basestring in
Python2.
* file() removed from Python3, use open().
* Use bytes instead of string when packing with format 's'.

Signed-off-by: Zifei Tong <zifeitong@gmail.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
mmu: consolidate code in map_file_page_mmap alloc/free

Reviewed-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Gleb Natapov <gleb@cloudius-systems.com>
mmu: split mmu-defs.hh header

arch-mmu.hh depend on mmu.hh currently which make it impossible to
include in header that mmu.hh itself includes. mmu.hh is pretty heavy
header containing many definitions and code, so move bare definitions
into separate header file.

Reviewed-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Gleb Natapov <gleb@cloudius-systems.com>
mmu: track mapping between ARC pages and ptep instead of virtual address

Currently we track mapping between ARC pages and virtual addresses which
require us to walk the page table to get to a pte pointer when invalidation
is required. Change that to track pointers to pte directly.

Signed-off-by: Gleb Natapov <gleb@cloudius-systems.com>
mmu: constify hw_ptep methods that do not change pte it points to

This allows those function to be called on const object.

Signed-off-by: Gleb Natapov <gleb@cloudius-systems.com>
mmu: map file private mappings with small pages too.

Private mapping are also done from ARC cache and have same problem as
shared mappings.

Reviewed-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Gleb Natapov <gleb@cloudius-systems.com>
mmu: save flags passed during file mapping in a vma.

Currently flags are saved for anon_vma, but not for file_vma. Examining
those flags in gdb proved to be helpful. Remove _shared since it no
longer needed, the information is in the flags.

Reviewed-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Gleb Natapov <gleb@cloudius-systems.com>
mmu: pass type of a page fault (r/w) to a page allocator

Page allocation may behave differently depending on a type of a fault.
Read fault may return ARC page, but write may do cow for instance.

Reviewed-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Gleb Natapov <gleb@cloudius-systems.com>