Commit Graph

6015 Commits

Author SHA1 Message Date
Ithamar R. Adema
9c71c67140 ARM: Fix OMAP3 framebuffer divider setting
QEMU was crashing since when setting the DSS divider we were _clearing_
the TV divider, and QEMU did not check for a divide by zero.

This "fixes" the QEMU crash and gets us a working framebuffer on Beagle ;)
2014-10-25 14:49:51 -07:00
Axel Dörfler
5a95af70a2 vfs/{b|btr|package|b}fs/ext2/exfat: common access check.
* Added VFS helper function check_access_permissions() that combines
  several partially correct versions to the one true version (tm).
* All but BFS (since recently) missed the S_IXOTH for root on directories,
  and all but packagefs missed proper group handling.
2014-10-25 18:47:15 +02:00
Ithamar R. Adema
2ce0d69a7e ARM: fix bootloader's mmu_map_physical_memory size
When the address is not page aligned, not only adjust the address
to start mapping, but also take the "overflow" on the last page
into account.

This makes the bootloader boot again ;)
2014-10-25 09:43:15 -07:00
Axel Dörfler
8efd5b7613 vfs: check the X permission on set cwd.
* When you change the current working directory, you actually
  should have the permission to enter that directory.
* This gives us a 0.04% better score on the perl test suite :-)
2014-10-25 15:57:38 +02:00
Michael Lotz
e9922e775f haiku_loader: Fix wrong size of gBootGDT on x86_64.
The BOOT_GDT_SEGMENT_COUNT was based on USER_DATA_SEGMENT on both
x86 and x86_64. However, on x86_64 the order of the segments is
different, leading to a too small gBootGDT array. Move the define to
the arch specific headers so they can be setup correctly in either case.
Also add a STATIC_ASSERT() to check that the descriptors fit into the
array.

Pointed out by CID 1210898.
2014-10-22 21:06:07 +02:00
Michael Lotz
368dd37798 runtime_loader: Fix missing include of util/kernel_cpp.h.
Due to the missing include, the builtin new and delete operators were
used in those two files instead of the ones from the include used
everywhere else in the runtime_loader.
2014-10-18 21:58:08 +02:00
Michael Lotz
8ea3e9126d Typo: Fix doubled "not" in comment. 2014-10-18 19:32:33 +02:00
Adrien Destugues
7554bc9a19 wctype: out of bound access in POSIX locale.
The POSIX locale has gLocaleRoster = NULL and relies on the non-wide
version of the implementation. However it doesn't check that the
characters are actually in range which leads to out of bound access and
crashes in __isctype.

Fixes #11322.
2014-10-06 16:54:31 +02:00
Lioncash
a4a9dade68 boot: Fix some always false conditions 2014-09-26 20:56:04 +02:00
Paweł Dziepak
9c5c599041 kernel: pagecache: provided buffers are not always in user memory
Source or destination buffers passed to pagecache functions may belong
to kernel memory (e.g. when the caller is packagefs). Because of that
we should tell vm_memcpy_{from, to}_physical() truth, not assume that all
buffers are in user memory. That's important because user memory page fault
handlers cannot be nested and these functions may be used while handling
a page fault.

With high probability fixes #11246.

Signed-off-by: Paweł Dziepak <pdziepak@quarnos.org>
2014-09-25 21:57:32 +02:00
Jérôme Duval
c8990b0907 _user_wait_for_objects: remove redundant check. 2014-09-17 21:04:14 +02:00
Jessica Hamilton
f0b0d6578b Undo accidental file mode changes. 2014-09-15 16:38:30 +12:00
Paweł Dziepak
95e97463d2 kernel: add generic wrapper for accessing user memory
This patch adds user_access() which can be used to gracefully handle
page faults that may happen when accessing user memory. It is used
by arch_cpu_user{memcpy, memset, strlcpy}() to allow using optimized
functions from the standard library.

Currently only x64 uses this, but nothing really is arch specific here.

Signed-off-by: Paweł Dziepak <pdziepak@quarnos.org>
2014-09-14 22:39:07 +02:00
Paweł Dziepak
4582b6e3a3 libroot/x86_64: new memcpy implementation
This patch introduces new memcpy() implementation that improves the
performance when the buffer is small. It was written for processors that
support ERMSB, but performs reasonably well on older CPUs as well.

The following benchmarks were done on Haswell i7 running Debian Jessie
with Linux 3.16.1. In each iteration 64MB buffer was copied, the
parameter "size" is the size of the buffer passed in a single call (i.e.
for "size: 2" memcpy() was called ~32 million times to copy the whole
64MB).

f - original implementation, g - new implementation, all buffers 16 byte
aligned

cpy, size:        8, f:    79971 µs, g:    20419 µs, ∆:   74.47%
cpy, size:       32, f:    42068 µs, g:    12159 µs, ∆:   71.10%
cpy, size:      128, f:    13408 µs, g:    10359 µs, ∆:   22.74%
cpy, size:      512, f:    10634 µs, g:    10433 µs, ∆:    1.89%
cpy, size:     1024, f:    10474 µs, g:    10536 µs, ∆:   -0.59%
cpy, size:     4096, f:     9419 µs, g:     8630 µs, ∆:    8.38%

f - glibc 2.19 implementation, g - new implementation, all buffers 16 byte
aligned

cpy, size:        8, f:    26299 µs, g:    20919 µs, ∆:   20.46%
cpy, size:       32, f:    11146 µs, g:    12159 µs, ∆:   -9.09%
cpy, size:      128, f:    10778 µs, g:    10354 µs, ∆:    3.93%
cpy, size:      512, f:    12291 µs, g:    10426 µs, ∆:   15.17%
cpy, size:     1024, f:    13923 µs, g:    10571 µs, ∆:   24.08%
cpy, size:     4096, f:    11770 µs, g:     8671 µs, ∆:   26.33%

f - glibc 2.19 implementation, g - new implementation, all buffers unaligned

cpy, size:       16, f:    13376 µs, g:    13009 µs, ∆:    2.74%
cpy, size:       32, f:    11130 µs, g:    12171 µs, ∆:   -9.35%
cpy, size:       64, f:    11017 µs, g:    11231 µs, ∆:   -1.94%
cpy, size:      128, f:    10884 µs, g:    10407 µs, ∆:    4.38%
cpy, size:      256, f:    10826 µs, g:    10106 µs, ∆:    6.65%
cpy, size:      512, f:    12354 µs, g:    10396 µs, ∆:   15.85%

Signed-off-by: Paweł Dziepak <pdziepak@quarnos.org>
2014-09-14 19:16:52 +02:00
Paweł Dziepak
1d7b716f84 libroot/x86_64: new memset implementation
This patch introduces new memset() implementation that improves the
performance when the buffer is small. It was written for processors that
support ERMSB, but performs reasonably well on older CPUs as well.

The following benchmarks were done on Haswell i7 running Debian Jessie
with Linux 3.16.1. In each iteration 64MB buffer was memset()ed, the
parameter "size" is the size of the buffer passed in a single call (i.e.
for "size: 2" memset() was called ~32 million times to memset the whole
64MB).

f - original implementation, g - new implementation, all buffers 16 byte
aligned

set, size:        8, f:    66885 µs, g:    17768 µs, ∆:   73.44%
set, size:       32, f:    17123 µs, g:     9163 µs, ∆:   46.49%
set, size:      128, f:     6677 µs, g:     6919 µs, ∆:   -3.62%
set, size:      512, f:    11656 µs, g:     7715 µs, ∆:   33.81%
set, size:     1024, f:     9156 µs, g:     7359 µs, ∆:   19.63%
set, size:     4096, f:     4936 µs, g:     5159 µs, ∆:   -4.52%

f - glibc 2.19 implementation, g - new implementation, all buffers 16 byte
aligned

set, size:        8, f:    19631 µs, g:    17828 µs, ∆:    9.18%
set, size:       32, f:     8545 µs, g:     9047 µs, ∆:   -5.87%
set, size:      128, f:     8304 µs, g:     6874 µs, ∆:   17.22%
set, size:      512, f:     7373 µs, g:     7486 µs, ∆:   -1.53%
set, size:     1024, f:     9007 µs, g:     7344 µs, ∆:   18.46%
set, size:     4096, f:     8169 µs, g:     5146 µs, ∆:   37.01%

Apparently, glibc uses SSE even for large buffers and therefore does not
takes advantage of ERMSB:

set, size:    16384, f:     7007 µs, g:     3223 µs, ∆:   54.00%
set, size:    32768, f:     6979 µs, g:     2930 µs, ∆:   58.02%
set, size:    65536, f:     6907 µs, g:     2826 µs, ∆:   59.08%
set, size:   131072, f:     6919 µs, g:     2752 µs, ∆:   60.23%

The new implementation handles unaligned buffers quite well:

f - glibc 2.19 implementation, g - new implementation, all buffers unaligned

set, size:       16, f:    10045 µs, g:    10498 µs, ∆:   -4.51%
set, size:       32, f:     8590 µs, g:     9358 µs, ∆:   -8.94%
set, size:       64, f:     8618 µs, g:     8585 µs, ∆:    0.38%
set, size:      128, f:     8393 µs, g:     6893 µs, ∆:   17.87%
set, size:      256, f:     8042 µs, g:     7621 µs, ∆:    5.24%
set, size:      512, f:     9661 µs, g:     7738 µs, ∆:   19.90%

Signed-off-by: Paweł Dziepak <pdziepak@quarnos.org>
2014-09-14 19:16:52 +02:00
Paweł Dziepak
718fd007a6 kernel/x86_64: clear xmm0-15 registers on syscall exit
As Alex pointed out we can leak possibly sensitive data in xmm registers
when returning from the kernel. To prevent that xmm0-15 are zeroed
before sysret or iret. The cost is negligible.

Signed-off-by: Paweł Dziepak <pdziepak@quarnos.org>
2014-09-14 19:16:52 +02:00
Paweł Dziepak
396b74228e kernel/x86_64: save fpu state at interrupts
The kernel is allowed to use fpu anywhere so we must make sure that
user state is not clobbered by saving fpu state at interrupt entry.
There is no need to do that in case of system calls since all fpu
data registers are caller saved.

We do not need, though, to save the whole fpu state at task swich
(again, thanks to calling convention). Only status and control
registers are preserved. This patch actually adds xmm0-15 register
to clobber list of task swich code, but the only reason of that is
to make sure that nothing bad happens inside the function that
executes that task swich. Inspection of the generated code shows
that no xmm registers are actually saved.

Signed-off-by: Paweł Dziepak <pdziepak@quarnos.org>
2014-09-14 19:16:52 +02:00
Paweł Dziepak
b41f281071 boot/x86_64: enable sse early
Enable SSE as a part of the "preparation of the environment to run any
C or C++ code" in the entry points of stage2 bootloader.

SSE2 is going to be used by memset() and memcpy().

Signed-off-by: Paweł Dziepak <pdziepak@quarnos.org>
2014-09-14 19:16:52 +02:00
Paweł Dziepak
acad7bf64a kernel/x86_64: make sure stack is properly aligned in syscalls
Just following the path of least resistance and adding andq $~15, %rsp
where appropriate. That should also make things harder to break
when changing the amount of stuff placed on stack before calling the
actual syscall routine.

Signed-off-by: Paweł Dziepak <pdziepak@quarnos.org>
2014-09-14 19:16:52 +02:00
Paweł Dziepak
f2f91078bd kernel/x86_64: remove memset and memcpy from commpage
There is absolutely no reason for these functions to be in commpage,
they don't do anything that involves the kernel in any way.

Additionaly, this patch rewrites memset and memcpy to C++, current
implementation is quite simple (though it may perform surprisingly
well when dealing with large buffers on cpus with ermsb). Better
versions are coming soon.

Signed-off-by: Paweł Dziepak <pdziepak@quarnos.org>
2014-09-14 19:16:52 +02:00
Paweł Dziepak
6156a508ad kernel/x86[_64]: remove get_optimized_functions from cpu modules
The possibility to specify custom memcpy and memset implementations
in cpu modules is currently unused and there is generally no point
in such feature.

There are only 2 x86 vendors that really matter and there isn't
very big difference in performance of the generic optmized versions
of these funcions across different models. Even if we wanted different
versions of memset and memcpy depending on the processor model or
features much better solution would be to use STT_GNU_IFUNC and save
one indirect call.

Long story short, we don't really benefit in any way from
get_optimized_functions and the feature it implements and it only adds
unnecessary complexity to the code.

Signed-off-by: Paweł Dziepak <pdziepak@quarnos.org>
2014-09-14 19:16:51 +02:00
Axel Dörfler
2dba000784 libroot: sethostname() now uses ftruncate().
* Before, it would just overwrite the previous name, leaving extra
  bytes from the previous name (they wouldn't become part of the
  host name, but it just didn't look that nice).
2014-09-14 14:11:00 +02:00
Paweł Dziepak
b52b104798 boot/x86_64: convert address of previous_debug_output
Together with the previous commit should fix #10535.

Signed-off-by: Paweł Dziepak <pdziepak@quarnos.org>
2014-09-12 01:09:17 +02:00
Paweł Dziepak
c343f75d76 boot/x86_64: call debug_cleanup() before preparing mmu data
long_mmu_init() prepares initial paging structures for 64 bit kernel.
Once that function completes bootloader cannot allocate any memory
that needs to be passed to the kernel.

Signed-off-by: Paweł Dziepak <pdziepak@quarnos.org>
2014-09-12 01:09:14 +02:00
Jessica Hamilton
e547662664 stage1/2 loaders: auto-generate binary files. Fixes #10723 2014-09-10 22:00:30 +12:00
PulkoMandy
0c65f35f47 u-boot: sync console implementation from raspberry port
* VT100 is much more common than VT52 which the u-boot port was
previously using (a legacy of the Atari m68k port)
 * Implement serial_getc (again, code is identical to raspberry port...)
so the boot menu can be used over the serial port. The enter key is
recognized, arrows currently aren't.
2014-09-09 22:06:21 +02:00
PulkoMandy
19ad221e37 Raspberry_pi: fix VT100 console driver
* Cursor coordinates are 1-based, not 0-based
 * Color change was disabled and broken

This implementation of our console over VT100 is generic and should be
moved out of the raspberry-pi specific folder. However, leaving it there
for now as we will have some bigger reorganization a swe add FDT support
here.
2014-09-09 22:06:20 +02:00
Ithamar R. Adema
1819aa71ee ARM: sync up VM code with x86
No big functional reason for this, but rather keep it in sync now
then have to do lots of work later on, when there are major changes.
Once I have it fully fleshed out for ARM, I might take a look if
we can generalise it a little more, as there's lots of code
_exactly_ the same for both platforms (and other platforms in
progress using the same code).
2014-09-08 00:52:33 +02:00
Ithamar R. Adema
eea45d0a32 ARM: cleanup of bootloader memory mapping
* Removes default mapping of a portion of the RAM (will be done
  as needed)
* Passes on the page directory area to kernel, so on early vm init
  the kernel can use the area for pagetable allocation.
* Leaves it to the platform to pass in physical memory range(s). This
  will ultimately come from FDT.
* Fix long standing issue with allocation of the heap, potentially
  causing other part of the bootloader to overwrite the heap.
* Implements pagetable allocator in kernel for early vm mapping.

This fixes the first PANIC seen, we now just get the same one later
on when the VM is up... more to come...
2014-09-07 20:56:15 +02:00
Ithamar R. Adema
3e450daa1c ARM: remove the loader from the memory map table
We have _start/_end symbols to mark our start and end, use those
to determine where we are loaded. We're slowly getting closer to
a fully dynamic handling of our memory map!
2014-09-07 20:56:15 +02:00
Ithamar R. Adema
e3020a5039 ARM: remove initrd handling from mmu code
Let the platform mmu_map_physical_memory the initrd region, and
reserve it before calling mmu_init. This removes another hardcoded
address, since e.g. U-Boot gets the address from the uImage file.
2014-09-07 20:56:14 +02:00
Ithamar R. Adema
0a163b65c7 ARM: define bootloader stack in linker script
This removes the need for the whole HAIKU_BOARD_LOADER_STACK_BASE
sing and dance, since it is always included in the bootloader binary
itself.
2014-09-07 20:56:14 +02:00
Ithamar R. Adema
6fb65b9dfe ARM: remove section handling TODO; no need for it
We will never use sections anyway..
2014-09-07 20:56:14 +02:00
Ithamar R. Adema
6048591e9d Revert "Added check to ensure KDL does not include frames beyond kernel entry in the backtrace. This prevents KDL from faulting when printing backtrace on ARM."
This reverts commit 3fbb24680c.

As I mentioned in #11131, this fix is not correct, and works around
the problem. The real reason was that arch_debug_call_with_fault_handler
was not working properly, so the fault handler went crazy.

With commit eb92810 that is fixed so this can be reverted.
2014-09-07 19:15:01 +02:00
Ithamar R. Adema
eb92810edc ARM: fix arch_debug_call_with_fault_handler
This fixes the problem with KDL freaking out when doing a stacktrace
and having its fault handler triggered. Have no clue how this could
have worked before, but it did :P
2014-09-07 19:14:29 +02:00
Michael Lotz
42a91653ba kernel: Fix missing else in dump_page_queue debugger command.
The entered page queue address would always be overwritten. Pointed
out by CID 610504.
2014-09-07 13:18:03 +02:00
Paweł Dziepak
ece6f8ba5d boot: remove check against large gaps between elf segments
As discussed on the ML the limitation of the gap between segments
imposed by this check is completely artifical and pointless.

Signed-off-by: Paweł Dziepak <pdziepak@quarnos.org>
2014-09-06 19:38:13 +02:00
Ithamar R. Adema
72b52fdf92 ARM: u-boot: work around dd issues on OSX
The oflag parameter does not exist on OSX, and neither on BSD. Just
use "cat" to append instead.
2014-09-05 22:32:18 +02:00
PulkoMandy
5de8dca2e4 Bootloader: fix loading of ARM ELF files
* Let the loader know about PT_ARM_UNWIND (and ignore it)
 * Allow up to 32K of space between sections of an ELF files as ARM ones
need that.
2014-09-02 18:15:50 +02:00
Arvind S Raj
3fbb24680c Added check to ensure KDL does not include frames beyond kernel entry in the backtrace. This prevents KDL from faulting when printing backtrace on ARM. 2014-09-02 13:39:57 +02:00
Ithamar R. Adema
f9f3b564ac ARM: only enable C++11 for libroot, not globally
This resembles the x86_64 build, and fixes the compilation issues
with the bootloader stdio.h header.

Fixes #11144
2014-09-01 15:28:49 +02:00
François Revol
66b9a96b18 typo 2014-08-31 02:06:37 +02:00
Ithamar R. Adema
586995da47 ARM: make ARM C++ unwind stubs panic
As suggested by Francois, thanks for paying attention!
2014-08-30 16:50:46 -07:00
Ithamar R. Adema
780ca2bd15 ARM: abort() is already pulled in using kernel_util.o
It was just here to make libgcc happy.
2014-08-30 16:43:49 -07:00
Ithamar R. Adema
ad5bdbdfd4 ELF: enlarge the allowed padding between sections
Turns out the padding on ARM is slightly larger, and prevented
the kernel add-ons from being loaded.
2014-08-30 16:43:48 -07:00
Ithamar R. Adema
cbe5cf641d ARM: add a couple of ARM specific stubs
These are ARM EABI specific exception handling functions, referenced
from the gcc c++ libraries.
2014-08-30 21:10:27 +02:00
Paweł Dziepak
72a446e10b libroot/x86_64: implement get_cpuid() in user mode
cpuid is available in user mode as well and it doesn't look like there
are going to be any x86 platforms with significantly different CPUs anytime
soon.

Signed-off-by: Paweł Dziepak <pdziepak@quarnos.org>
2014-08-26 19:01:37 +02:00
Paweł Dziepak
6d70d75a8e libroot/x86_64: rewrite system_time[_nsecs]() to C++
No functional change intended, just code deobfuscation.

Signed-off-by: Paweł Dziepak <pdziepak@quarnos.org>
2014-08-26 19:01:37 +02:00
Paweł Dziepak
2268a48350 kernel/x86_64: use C++11 style static assert
Signed-off-by: Paweł Dziepak <pdziepak@quarnos.org>
2014-08-25 23:07:32 +02:00
Paweł Dziepak
4b75a1e237 kernel/x86_64: implement x86_swap_pgdir in C++
No reason not to inline this function.

Signed-off-by: Paweł Dziepak <pdziepak@quarnos.org>
2014-08-25 23:07:29 +02:00