cli: Use a proper terminal definition

This patch takes vt100 terminal definition, changes it to fit qemu's handling
of ^J (taken from Nadav's rogue module) and updates the CLI code to use that
definiton.

This removes the weird warning message of "couldn't find dumb, using dumb".
If running outside OSv, there's no need for this and libedit will find the
proper terminal definition according to TERM environment variable.

Signed-off-by: Or Cohen <orc@fewbytes.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
httpserver: Fix /os/dmesg output format

Output should be json formatted, according to the schema.

Signed-off-by: Or Cohen <orc@fewbytes.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
x64: Document how boot16.S get loader size

Signed-off-by: Elazar Leibovich <elazarl@gmail.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
console: Fix bare linefeeds on early output on Xen

This patch fixes #371, which reported OSv's early output (first few lines
of verbose messages) is "scrambled" in the sense that each line starts
below the place where the previous line ended, instead of the beginning
of the line where it should.

Even modern terminals follow typewriters (does anyone even remember those?)
in that they have two separate concepts: A "line feed", which moves one line
down (in the same column), and a "carriage return", which returns to the
first column (on the same line). In ASCII, the line feed is '\n' (\012)
and the carriage return is '\r' (\015). You actually need to output *both*
of them to do what people normally expect from a "new line", i.e., go
to the first column of the next line.

Since UNIX adopted the convention that it only takes a "\n" to mark a new
line, the terminal driver needs to convert "\n" to a "\r\n" sequence.
This conversion can be turned on or off using the ONLCR flag in an ioctl
to the terminal driver (see termios(3)). Normally, in "cooked mode", this
conversion is enabled. In our implementation, this conversion is done
by LineDiscipline::write(), and is working fine, which is why we don't
see the linefeed problem after the early output.

But for the early console output, we had separate code for outputting it,
and in that case, forgot to do the \n->\r\n conversion. So this patch
adds it.

Why did this problem only effect Xen?

Xen doesn't use qemu. It turns out that qemu has a long-known bug which
hides this OSv bug :-) Qemu enables the ONLCR bit on the host's tty
(don't be confused - this is in the host and not the ONLCR code in OSv
described earlier). In other words, qemu translates every \n it gets over
the serial port to \r\n when printing it to the screen, so even if our
code just outputted \n, it would show it correctly. That may sound like
"not a bug, it's a feature", but it really *is* a bug in qemu - it also
means that the guest has no way to output a bare linefeed to go one
line down. This is why in apps/rogue I had to patch the terminal
definition to use the cursor-down escape sequence instead of the linefeed.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Merge branch 'master' of https://github.com/cloudius-systems/osv
isa-serial: Introduce early_init() to init driver ealier

Introduce early_init(), to initialize driver before using early console.
This is required for VMware.

Signed-off-by: Takuya ASADA <syuu@cloudius-systems.com>
[ penberg: squash into one commit for bisectability ]
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Another early-boot linefeed fix

After the previous patch, we get most of the linefeeds in early boot
fixed (see issue #371), except one after the first line, which is printed
by debug_early().

We need to do in debug_early() exactly the same thing described in the
previous patch, i.e., translate \n in the string to \r\n in the output.

Reviewed-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
fs: call abort on sys_panic, instead of kprintf

We want backtrace on sys_panic, too.

Signed-off-by: Takuya ASADA <syuu@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
net: respect MTU set via ioctl

Fixes #372.

ioctl handler for virtio-net was ignoring MTU changes. On GCE the
interface MTU is less than the default (1460 vs 1500). Not respecting
MTU led to communication failures when large packets were sent, for
example:

IP truncated-ip - OSV.8443 > TOMEK.52012: Flags [.], seq 1:1449, ack 179, win 1040, options [nop,nop,TS val 476582182 ecr 62762835], length 1448
IP 10.240.0.1 > OSV: ICMP TOMEK unreachable - need to frag (mtu 1460), length 36

The same problem existed for vmxnet3 driver.

The fix is to remove handler for SIOCSIFMTU, which does nothing but
logging, so that we fall through to ether_ioctl() in the default
clause.

Reviewed-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
tests/tst-pthread-affinity: Remove bogus struct

tst-pthread-affinity implements a useless copy of pthread.cc's thread_attr
structure. This structure is not used by any code and, hence, can be removed.

Signed-off-by: Renato L. F. Cunha <renato@renatocunha.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
random: fix includes

Reviewed-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
random: create random devices even when there's no virtio-rng

This fixes a bug which manifests in /dev/random and /dev/urandom
missing on platforms which do not have virtio-rng. That includes GCE
and EC2. The problem was that if virtio-rng did not register itself
then random devices were not initialized. We now have more hardware
sources (rdrand) and we should not rely on virito-rng alone.

The fix is to always initialize random devices. If virtio-rng is
probed successfully it will register itself as entropy source.

Reviewed-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
cpuid: add string to cpuid parser

We would like to dump that later in string format.

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
processor: provide a string representation of all processor features

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
move cpuid.hh to processor.hh header

Although this is just naming, "processor" is more arch independent than
cpuid. So arch neutral code can now include "processor.hh" and still have
access to the cpuid.hh goodies.

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
httpserver: harware probing API

This patch provides an interface that allow clients to REST probe for the current
processor flags currently available. In this same level, I intend to soon create
calls for disk features, network interface features, etc.

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Merge branch 'master' of https://github.com/cloudius-systems/osv
elf: Make lookup_addr() respect symbol size

This makes lookup_addr() to check that "addr" is within the bounds of
the "best" symbol symbol we found.

This should clean up backtraces such as the following that have
obviously bogus symbols (with very large offsets):

  [backtrace]
  0x000000000032282f <mmu::jvm_balloon_vma::split(unsigned long)+367>
  0x0000000000323632 <mmu::vm_fault(unsigned long, exception_frame*)+146>
  0x000000000036f939 <page_fault+105>
  0x000000000036e826 <ex_pf+34>
  0x0000100004400898 <main+80>
  0x00000000003d32db <osv::run(std::string, int, char**, int*)+507>
  0x0000100004007930 <run_elf(int, char**, int*)+128>
  0x0000100004007c0c <Java_com_cloudius_util_Exec_run+172>
  0x00002000006134b5 <???+6370485>
  0x00002000006061d3 <???+6316499>
  0x000020000060050a <???+6292746>
  0x00001000011ef168 <AsyncGetCallTrace+919944>
  0x00001000011eebc7 <AsyncGetCallTrace+918503>
  0x000010000144b6e7 <JVM_handle_linux_signal+463895>
  0x000010000144c837 <JVM_handle_linux_signal+468327>
  0x000010000123c542 <JVM_InvokeMethod+402>

Fixes #263.

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
pci: Add VGA classcode

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Takuya ASADA <syuu@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
vga: use PCI classcode on probe function

Signed-off-by: Takuya ASADA <syuu@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>