Commit graph

956 commits

Author SHA1 Message Date
Lionel Sambuc 8e4736f2df Removing obsolete _MINIX define
Change-Id: Id33ac7e973d1c0e249b690fe44a597474fac6076
2013-02-26 09:44:20 +00:00
Ben Gras 2aa82a9c7b ARM: kernel: fix sanity check for copying
. phys_copy() (taken from memcpy) can legitimately
	  cause pagefaults below the source/dest address due
	  to word-alignment

Change-Id: Ibee8f069781d16caea671246c021fb17a2a892b1
2013-02-20 20:34:40 +01:00
Kees Jongenburger d47f512a13 kernel:handle improper svc calls gracefully.
Change-Id: Id0f694dd2a8c5981900601fcdb2112ee266d0d76
2013-02-19 17:02:29 +01:00
Ben Gras b18224051a kernel: more stack for vm 2013-02-19 13:53:56 +01:00
Lionel Sambuc e4fa9802cb ARM: Enable caches
First round, some more optimizations are possible and should be
activated.

Change-Id: I3b7dee7c82fbffd823a08bec1c5d5ebcf769f92f
2013-02-18 09:08:26 +01:00
Lionel Sambuc b36292e232 ARM: Fix interrupt management
Interrupts where not correctly masked while in kernel, which
breaks one of the current main assumptions.

Also remove some duplication on ARM asm files, and add a function
to check the status of ARM irqs (not compiled by default)

Change-Id: I3c25d2b388f93fd8fe423998b94b3c4f140ba831
2013-02-18 09:07:55 +01:00
Kees Jongenburger eff37b8a8b kernel:enable trace on arm.
Change-Id: Iabe6dfd758e8f1cdb4a18e2f2ab8f8ca988f3c86
2013-02-17 08:40:38 +01:00
Thomas Cort 8d5bf08308 kernel: correct typo in clock.c
Change-Id: Iae7f482268809c5675d023d10104f49e5bd65484
2013-02-15 12:10:56 +01:00
Ben Gras 3bc6d7df06 impove memory accounting
. the total amount of memory in the system didn't include the memory
	  used by the boot-time modules and some dynamic allocation by the
	  kernel at boot time (to map in VM). especially apparent on our
	  ARM board with 'only' 512MB of memory and a huge ramdisk.
	. also: *add* the VM loaded module to the freelist after it has
	  been allocated for & mapped in instead of cutting it *out* of the
	  freelist! so we get a few more MB free..

Change-Id: If37ac32b21c9d38610830e21421264da4f20bc4f
2013-02-11 19:31:57 +01:00
Ben Gras 5a0585359d ARM divsi3.S: raise(SIGFPE) when called for
. raise(SIGFPE) for modulo-0/divide-0 operations in
	  internal int division functions
	. gcc: do not link with -lgcc anywhere so these internal
	  functions are always used from libc instead of (sometimes)
	  masked by -lgcc
	. together fixes test53 on ARM

Change-Id: I31ec19dfdd68b8a92695595da901874e63106f9d
2013-02-09 22:24:59 +01:00
Ben Gras 3045d2870b arm: protect state after signal handler
. set MF_CONTEXT_SET after signal handler state
	  is set so it doesn't get clobbered by the kernel
	  afterwards (i.e. by delivermsg()).

fixes at least test41.

Change-Id: I7e5e0e9311c8bbc1c0a9c7ca466ceddd9edfa03f
2013-02-05 17:25:38 +01:00
Ben Gras 298b41b523 libexec: detect short files
if an exec() fails partway through reading in the sections, the target
process is already gone and a defunct process remains. sanity checking
the binary beforehand helps that.

test10 mutilates binaries and exec()s them on purpose; making an exec()
fail cleanly in such cases seems like acceptable behaviour.

fixes test10 on ARM.

Change-Id: I1ed9bb200ce469d4d349073cadccad5503b2fcb0
2013-02-04 12:04:35 +01:00
Ben Gras 57bab02d57 kernel, libc: signals fixes
. kernel: signal handler args for ARM
	. kernel: sanity check return address (LSB indicates thumb mode)
	. libc: properly retrieve signal mask for ARM

together fix test37 on ARM.

Change-Id: I4e00f754c50104ed85c7fdf8ec5ad54568f20a81
2013-02-04 12:03:46 +01:00
Ben Gras 8ea66915f2 kernel: scheduling fix for ARM
. make read_tsc_64 use the free-running clock, significantly
	  improving scheduling behaviour

Change-Id: Idf6a12f6e26be7fe3b3664c278cae846d8b2a442
2013-02-03 22:49:05 +01:00
Thomas Veerman db8c1ee9d0 ARM: provide free running clock to replace ccnt
The Cycle CouNTer on ARM cannot be used reliably as it wraps around
rather quickly and can be altered by user space (on Minix). Furthermore,
it's buggy when wrapping and is not implemented at all on the Linaro
Beagleboard emulator.

This patch programs GPTIMER10 as a free running clock at 1.625 MHz (it
doesn't generate interrupts). It's memory mapped into every process,
which enables libsys to provide micro_delay().

Change-Id: Iba004c6c62976762fe154ea390d69e518eec1531
2013-01-31 15:19:11 +00:00
Ben Gras e3e5cf6d34 arm: make signal handlers work
A few kernel and calling convention adjustments to make sigsend and
sigreturn work for arm.

	. provide a arch_proc_setcontext for earm in kernel
	. set LR in context of signal handler to provide a proper
	  return address (to __sigreturn)
	. change __sigreturn to retrieve the sigcontext pointer
	  from the sigframe struct and pass it to _sigreturn() in r0

Change-Id: Icd135a70595382c79d11d8dd9876f6a6f1df41f8
2013-01-30 04:10:12 +00:00
Thomas Veerman df0c35f0f5 Kernel/ARM: faster context save 2013-01-25 17:07:02 +00:00
Thomas Veerman fb4b3da7da Kernel/ARM: use modern srsdb invocation 2013-01-25 17:07:02 +00:00
Thomas Veerman 1a60a84cb7 ARM: clear BSS upon boot 2013-01-25 17:07:01 +00:00
Thomas Veerman c96cd5e1a0 ARM: provide means to pass boot cmdline 2013-01-25 17:07:01 +00:00
Ben Gras dcff984d6a kernel: fix sanity check 2013-01-18 21:38:28 +00:00
Lionel Sambuc b1c4ba4ab6 ARM updates
Due to the ABI we are using we have to use the earm architecture
moniker for the build system to behave correctly. This involves
then some headers to move around.

There is also a few related Makefile updates as well as minor
source code corrections.
2013-01-17 10:03:58 +01:00
Lionel Sambuc f14fb60209 Libraries updates and cleanup
* Updating common/lib
 * Updating lib/csu
 * Updating lib/libc
 * Updating libexec/ld.elf_so
 * Corrected test on __minix in featuretest to actually follow the
   meaning of the comment.
 * Cleaned up _REENTRANT-related defintions.
 * Disabled -D_REENTRANT for libfetch
 * Removing some unneeded __NBSD_LIBC defines and tests

Change-Id: Ic1394baef74d11b9f86b312f5ff4bbc3cbf72ce2
2013-01-14 11:36:26 +01:00
Thomas Veerman c77228c77b ARM: fix clock
The GPTIMER1 clock is configured to run at 32 kHz and generate
(overflow) interrupts every 1 ms. However, the Timer Overflow Wrappping
Register (TOWR) was configured to filter every other interrupt. This
caused to the internal 'realtime' value to be off.
2013-01-11 09:18:36 +00:00
Thomas Veerman aa3623d873 ARM: make cycle counter available to userspace 2013-01-11 09:18:36 +00:00
Thomas Veerman ea8ff9284a Add stack trace dumps for VFS over serial 2013-01-11 09:18:36 +00:00
Antoine Leca ffdb12bc9b Drop obsolete klib16.S
The 16-bit poweroff16() function is not called any more.
2013-01-08 16:00:37 +00:00
Ben Gras 604046faf3 kernel: trap-dependent state restore, trace fixes
. restore state depends on how saving of state was done;
	  also remember trap style in sig context
	. actually set and restore TRACEBIT with new trap styles;
	  have to remove it once process enters kernel though, done
	  in debug trap exception handler
	. introduce MF_STEP that makes arch-specific code
	  turn on trace bit instead of setting TRACEBIT directly,
	  a bit more arch-friendly and avoids keeping precious
	  state in per-process PSW arch-dependently
2013-01-08 15:47:37 +00:00
Ben Gras 51a3e84a97 kernel: separate state for trace-deferred syscalls
state is usually not in p_reg any more with sysenter/syscall trap entries,
so when saving/restarting do_ipc invocations the state has to be remembered
explicitly.
2013-01-08 15:47:37 +00:00
Ben Gras 7f1018b145 kernel: restore setting KTS_NONE
The 'trap style' variable records how a process has trapped into the
kernel (hardware/software interrupt, or one of the other trap
instructions). KTS_NONE indicates the process isn't trapped into the
kernel at all and is useful for sanity checking. The KTS_NONE reset was
inadvertently removed while removing some debugging code and this commit
restores it.
2013-01-08 15:47:37 +00:00
Kees Jongenburger 75c515e5f8 kernel:add a some information in backtraces.
* Display the pid and process name in the backtrace as we can
currently not read stackframes.

Change-Id: I2435d4098553c5b02adfe36f08b5aa3f47e9b531
2013-01-08 13:40:32 +01:00
Kees Jongenburger 09895f86fc vm:enable the instruction and data caches.
Enable the instruction and data caches. Whether data is cached
will depend on the MMU entries.

Change-Id: I51e9ebc38924db5525d4e7ad9ab69b2a5b1ca7b4
2013-01-08 13:40:32 +01:00
Ben Gras 9ee8c2c75f kernel: restore stacktraces
When processes have entered the kernel with one of the new
trap modes, %ebp is not valid, used for stacktraces, so we
need an alternative way to retrieve it to make the stacktraces
valid again.
2013-01-07 20:18:48 +00:00
Ben Gras 125fc7a918 kernel: vm kernel call can't suspend 2012-12-29 00:56:46 +00:00
Ben Gras 59ff758441 kernel debug: priv can be NULL early on 2012-12-29 00:56:42 +00:00
Lionel Sambuc 456a46e6bf Removing useless minix/types.h header
Change-Id: If5f922279b87f075f301b64c7786caa18b434c2a
2012-12-07 13:58:06 +01:00
Erik van der Kouwe 57c748b968 Remove ability to pass commands to bootloader 2012-11-22 19:16:17 +01:00
Erik van der Kouwe 22fa466268 Restore poweroff to some of it's former glory (on QEMU, at least) 2012-11-21 20:28:37 +01:00
Ben Gras 6e535c3aaf kernel: kill proc with bogus ipc address 2012-11-19 10:53:17 +01:00
Tomas Hruby 10f30159a9 struct minix_ipcvecs - pretty-print
- the _ptr suffix is not needed anymore :-)
2012-11-15 16:52:00 +01:00
Lionel Sambuc d19d7d58aa Toolchain upgrade and portability improvements.
upgrade to NetBSD CVS release from 2012/10/17 12:00:00 UTC

Makefiles updates to imporve portability

Made sure to be consistent in the usage of braces/parenthesis at
least on a per file basis. For variables, it is recommended to
continue to use braces.
2012-11-15 16:07:29 +01:00
Lionel Sambuc 9152e1c5a7 Upgrading build system to new NetBSD revision
The tested targets are the followgin ones:
 * tools
 * distribution
 * sets
 * release

The remaining NetBSD targets have not been disabled nor tested
*at all*. Try them at your own risk, they may reboot the earth.

For all compliant Makefiles, objects and generated files are put in
MAKEOBJDIR, which means you can now keep objects between two branch
switching. Same for DESTDIR, please refer to build.sh options.

Regarding new or modifications of Makefiles a few things:
 * Read share/mk/bsd.README
 * If you add a subdirectory, add a Makefile in it, and have it called
   by the parent through the SUBDIR variable.
 * Do not add arbitrary inclusion which crosses to another branch of
   the hierarchy; If you can't do without it, put a comment on why.
   If possible, do not use inclusion at all.
 * Use as much as possible the infrastructure, it is here to make
   life easier, do not fight it.

Sets and package are now used to track files.
We have one set called "minix", composed of one package called "minix-sys"
2012-11-15 16:07:29 +01:00
Lionel Sambuc e415d48872 Libc update to simplify merge.
Bumping libc files for unsupported architectures, to simplify merging.
A bunch of small fixes:
 * in libutil update
 * the macro in endian.h
 * some undefined types due to clear separation from host.
 * Fix a warning for cdbr.c

Some modification which were required for the new build system:
 * inclusion path for const.h in sconst, still hacky
 * Removed default malloc.c which conflicts on some occasions.
2012-11-15 16:07:29 +01:00
Ben Gras ba05f39d1e kernel: some boottime sanitychecks
. Check if we have the right number of boot modules
	. Check if the ELF parsing of VM actually succeeded

Both these are root causes of less-than-obvious other
errors/asserts a little further down the line; uncovered
while experimenting with booting by iPXE, specifically
(a) iPXE having a 8-multiboot-modules limit and
(b) trying to boot a gzipped VM.
2012-11-08 11:40:35 +01:00
Ben Gras 196021cd82 drop safemap code 2012-10-30 13:55:42 +01:00
Thomas Veerman aeda8e5c7b Kernel: reenable interrupts before halting 2012-10-30 11:32:05 +00:00
Thomas Veerman 87de141141 Kernel: busy wait until serial out has finished 2012-10-30 11:32:04 +00:00
Arun Thomas 471a03a362 ARM support for kernel and vm 2012-10-07 21:38:03 -04:00
Arne Welzel d8a89dcbe6 kernel: add safememset() kernel call 2012-09-26 02:18:00 +02:00
Arne Welzel 0617743bd1 kernel: handle pagefaults in vm_memset() 2012-09-26 02:17:59 +02:00
Ben Gras 2d72cbec41 SYSENTER/SYSCALL support
. add cpufeature detection of both
	. use it for both ipc and kernelcall traps, using a register
	  for call number
	. SYSENTER/SYSCALL does not save any context, therefore userland
	  has to save it
	. to accomodate multiple kernel entry/exit types, the entry
	  type is recorded in the process struct. hitherto all types
	  were interrupt (soft int, exception, hard int); now SYSENTER/SYSCALL
	  is new, with the difference that context is not fully restored
	  from proc struct when running the process again. this can't be
	  done as some information is missing.
	. complication: cases in which the kernel has to fully change
	  process context (i.e. sigreturn). in that case the exit type
	  is changed from SYSENTER/SYSEXIT to soft-int (i.e. iret) and
	  context is fully restored from the proc struct. this does mean
	  the PC and SP must change, as the sysenter/sysexit userland code
	  will otherwise try to restore its own context. this is true in the
	  sigreturn case.
	. override all usage by setting libc_ipc=1
2012-09-24 15:53:43 +02:00
Arne Welzel 629829e69c phys_memset improvements
. verify length argument
	. use rep stosl / stosb
2012-09-21 14:15:44 +02:00
Ben Gras fe6e291f59 vm, kernel, top: report memory usage of vm, kernel 2012-09-18 23:43:52 +02:00
Ben Gras 19e6dad47b VM: only single page chunks
. only reference single pages in process data structures
   to simplify page faults, copy-on-write, etc.
 . this breaks the secondary cache for objects that are
   not one-page-sized; restored in a next commit
2012-09-18 13:17:49 +02:00
Ben Gras 053fa581b5 vm: remove stack handling for signals
. moved to the kernel as the handling was only
	  reading it; the kernel may as well write it too
2012-08-29 17:31:38 +02:00
Arun Thomas 9a9d555f56 machine/ipcconst.h for arch-specific constants 2012-08-27 19:46:41 -04:00
Ben Gras e4ac80eb60 various warning/errorwarning fixes for gcc47
. warnings (sometimes promoted to errors) in servers/ and kernel/
 . -Os for ext2 boot module to make it small enough
2012-08-27 16:19:18 +02:00
Ben Gras 41ab295654 hide block_t behind _MINIX (for gcc) 2012-08-24 18:07:37 +02:00
Ben Gras caa7efa117 kernel: rely on alignment directive for stacks
. unnecessary to do it manually with ELF
	. also makes 1 extra alignment page unnecessary
2012-08-19 01:04:51 +02:00
Ben Gras d69cc76e03 rename struct mem_range to minix_mem_range
. avoid a name clash with gdb
2012-08-15 15:17:25 +02:00
David van Moolenbroek 8e116b71a1 Kernel: resolve Coverity warnings 2012-08-15 11:12:11 +00:00
David van Moolenbroek 0b5c2a058c Kernel: use okendpt() to resolve stored endpoints
This adds an integrity check at very little cost, and should stop
Coverity from flagging array overruns on the result.
2012-08-15 08:50:30 +00:00
David van Moolenbroek c0aa9bf6ed Kernel: resolve -Wall warnings for SMP 2012-08-14 16:38:03 +00:00
David van Moolenbroek cf9a4ec79b Kernel: clean up include statements a bit
Coverity was flagging a recursive include between kernel.h and
cpulocals.h. As cpulocals.h also included proc.h, we can move that
include statement into kernel.h, and clean up the source files'
include statements accordingly.
2012-08-14 16:29:05 +00:00
Arun Thomas 697f0d097f Rename sys_vmctl_get_cr3_i386 2012-08-12 23:30:54 +02:00
Arun Thomas 19ffad7692 Remove ACK EM_WSIZE/EM_PSIZE macro usage 2012-08-06 17:49:22 +02:00
Arun Thomas 6723dcfab7 Replace MACHINE/CHIP macros with compiler macros 2012-08-06 17:49:22 +02:00
Ben Gras b6ea15115c kernel: facility for user-visible memory
. map all objects named usermapped_*.o with globally visible
	  pages; usermapped_glo_*.o with the VM 'global' bit on, i.e.
	  permanently in tlb (very scarce resource!)
	. added kinfo, machine, kmessages and loadinfo for a start
	. modified log, tty to make use of the shared messages struct
2012-07-28 20:57:38 +00:00
Ben Gras 53a947167c kernel: few more objects required in unpaged mode
. for 64-bit printf()
2012-07-28 22:26:52 +02:00
Ben Gras 11084d94e6 kernel: clean up objects
. objects left over from libraries are left around
2012-07-28 22:21:53 +02:00
David van Moolenbroek 6ded58b510 kernel: give kernel tasks their process name back 2012-07-26 14:35:08 +00:00
Ben Gras 49d4116100 kernel: keep serial info in system env
. otherwise serial hardware gets reinitialized by tty
2012-07-18 15:16:57 +02:00
Ben Gras cbcdb838f1 various coverity-inspired fixes
. some strncpy/strcpy to strlcpy conversions
	. new <minix/param.h> to avoid including other minix headers
	  that have colliding definitions with library and commands code,
	  causing parse warnings
	. removed some dead code / assignments
2012-07-16 14:00:56 +02:00
Ben Gras 1d48c0148e segmentless smp fixes
adjust the smp booting procedure for segmentless operation. changes are
mostly due to gdt/idt being dependent on paging, because of the high
location, and paging being on much sooner because of that too.

also smaller fixes: redefine DESC_SIZE, fix kernel makefile variable name
(crosscompiling), some null pointer checks that trap now because of a
sparser pagetable, acpi sanity checking
2012-07-15 22:47:20 +02:00
Ben Gras 50e2064049 No more intel/minix segments.
This commit removes all traces of Minix segments (the text/data/stack
memory map abstraction in the kernel) and significance of Intel segments
(hardware segments like CS, DS that add offsets to all addressing before
page table translation). This ultimately simplifies the memory layout
and addressing and makes the same layout possible on non-Intel
architectures.

There are only two types of addresses in the world now: virtual
and physical; even the kernel and processes have the same virtual
address space. Kernel and user processes can be distinguished at a
glance as processes won't use 0xF0000000 and above.

No static pre-allocated memory sizes exist any more.

Changes to booting:
        . The pre_init.c leaves the kernel and modules exactly as
          they were left by the bootloader in physical memory
        . The kernel starts running using physical addressing,
          loaded at a fixed location given in its linker script by the
          bootloader.  All code and data in this phase are linked to
          this fixed low location.
        . It makes a bootstrap pagetable to map itself to a
          fixed high location (also in linker script) and jumps to
          the high address. All code and data then use this high addressing.
        . All code/data symbols linked at the low addresses is prefixed by
          an objcopy step with __k_unpaged_*, so that that code cannot
          reference highly-linked symbols (which aren't valid yet) or vice
          versa (symbols that aren't valid any more).
        . The two addressing modes are separated in the linker script by
          collecting the unpaged_*.o objects and linking them with low
          addresses, and linking the rest high. Some objects are linked
          twice, once low and once high.
        . The bootstrap phase passes a lot of information (e.g. free memory
          list, physical location of the modules, etc.) using the kinfo
          struct.
        . After this bootstrap the low-linked part is freed.
        . The kernel maps in VM into the bootstrap page table so that VM can
          begin executing. Its first job is to make page tables for all other
          boot processes. So VM runs before RS, and RS gets a fully dynamic,
          VM-managed address space. VM gets its privilege info from RS as usual
          but that happens after RS starts running.
        . Both the kernel loading VM and VM organizing boot processes happen
	  using the libexec logic. This removes the last reason for VM to
	  still know much about exec() and vm/exec.c is gone.

Further Implementation:
        . All segments are based at 0 and have a 4 GB limit.
        . The kernel is mapped in at the top of the virtual address
          space so as not to constrain the user processes.
        . Processes do not use segments from the LDT at all; there are
          no segments in the LDT any more, so no LLDT is needed.
        . The Minix segments T/D/S are gone and so none of the
          user-space or in-kernel copy functions use them. The copy
          functions use a process endpoint of NONE to realize it's
          a physical address, virtual otherwise.
        . The umap call only makes sense to translate a virtual address
          to a physical address now.
        . Segments-related calls like newmap and alloc_segments are gone.
        . All segments-related translation in VM is gone (vir2map etc).
        . Initialization in VM is simpler as no moving around is necessary.
        . VM and all other boot processes can be linked wherever they wish
          and will be mapped in at the right location by the kernel and VM
          respectively.

Other changes:
        . The multiboot code is less special: it does not use mb_print
          for its diagnostics any more but uses printf() as normal, saving
          the output into the diagnostics buffer, only printing to the
          screen using the direct print functions if a panic() occurs.
        . The multiboot code uses the flexible 'free memory map list'
          style to receive the list of free memory if available.
        . The kernel determines the memory layout of the processes to
          a degree: it tells VM where the kernel starts and ends and
          where the kernel wants the top of the process to be. VM then
          uses this entire range, i.e. the stack is right at the top,
          and mmap()ped bits of memory are placed below that downwards,
          and the break grows upwards.

Other Consequences:
        . Every process gets its own page table as address spaces
          can't be separated any more by segments.
        . As all segments are 0-based, there is no distinction between
          virtual and linear addresses, nor between userspace and
          kernel addresses.
        . Less work is done when context switching, leading to a net
          performance increase. (8% faster on my machine for 'make servers'.)
	. The layout and configuration of the GDT makes sysenter and syscall
	  possible.
2012-07-15 22:30:15 +02:00
Ben Gras cfe1ed4df4 profiling related cleanup
. do not declare any data in <minix/profile.h>
	. addr check no longer necessary
2012-07-15 21:56:55 +02:00
Thomas Veerman f09c2e014f Use MACHINE_ARCH instead of ARCH 2012-06-18 10:53:35 +00:00
Thomas Veerman f93afa00e9 Remove MINIXSRCDIR and use NETBSDSRCDIR
NETBSDSRCDIR is used all over the place anyway, and this reduces
our diff with NetBSD a little.
2012-06-18 10:53:35 +00:00
Dirk Vogt c735b0bb2c Makefile fixups for cross compilation 2012-06-18 10:53:24 +00:00
Dirk Vogt 207e4d2a71 Let the kernel load figure out where to put mods
This patch makes the mkimage tool obsolete
2012-06-18 10:53:22 +00:00
Ben Gras 0fb2f83da9 drop from segments physcopy/vircopy invocations
. sys_vircopy always uses D for both src and dst
	. sys_physcopy uses PHYS_SEG if and only if corresponding
	  endpoint is NONE, so we can derive the mode (PHYS_SEG or D)
	  from the endpoint arg in the kernel, dropping the seg args
	. fields in msg still filled in for backwards compatability,
	  using same NONE-logic in the library
2012-06-18 12:28:40 +00:00
Ben Gras 0e35eb0c6b drop segments from safemap/safeunmap invocations 2012-06-18 12:28:40 +00:00
Ben Gras 2bfeeed885 drop segment from safecopy invocations
. all invocations were S or D, so can safely be dropped
	  to prepare for the segmentless world
	. still assign D to the SCP_SEG field in the message
	  to make previous kernels usable
2012-06-16 16:22:51 +00:00
Ben Gras 769af57274 further libexec generalization
. new mode for sys_memset: include process so memset can be
	  done in physical or virtual address space.
	. add a mode to mmap() that lets a process allocate uninitialized
	  memory.
	. this allows an exec()er (RS, VFS, etc.) to request uninitialized
	  memory from VM and selectively clear the ranges that don't come
	  from a file, leaving no uninitialized memory left for the process
	  to see.
	. use callbacks for clearing the process, clearing memory in the
	  process, and copying into the process; so that the libexec code
	  can be used from rs, vfs, and in the future, kernel (to load vm)
	  and vm (to load boot-time processes)
2012-06-07 15:15:02 +02:00
Ben Gras 040362e379 exec() cleanup, generalization, improvement
. make exec() callers (i.e. vfs and rs) determine the
	  memory layout by explicitly reserving regions using
	  mmap() calls on behalf of the exec()ing process,
	  i.e. handling all of the exec logic, thereby eliminating
	  all special exec() knowledge from VM.
	. the new procedure is: clear the exec()ing process
	  first, then call third-party mmap()s to reserve memory, then
	  copy the executable file section contents in, all using callbacks
	  tailored to the caller's way of starting an executable
	. i.e. no more explicit EXEC_NEWMEM-style calls in PM or VM
	  as with rigid 2-section arguments
	. this naturally allows generalizing exec() by simply loading
	  all ELF sections
	. drop/merge of lots of duplicate exec() code into libexec
	. not copying the code sections to vfs and into the executable
	  again is a measurable performance improvement (about 3.3% faster
	  for 'make' in src/servers/)
2012-06-07 15:15:01 +02:00
Ben Gras 1daf36038c kernel: compact utility functions 2012-06-07 11:25:32 +02:00
Ben Gras 910a0e1093 kernel: make sure mpx.S is linked early
. for qemu multiboot detection
2012-06-01 16:58:00 +02:00
Ben Gras ad0db93247 no USE_BOOTPARAM 2012-05-31 01:13:27 +02:00
Ben Gras 3803c55856 kernel: neater arch-dependent split in Makefiles
. files in kernel/ references in kernel/Makefile, but
	  in kernel/arch/i386/ in kernel/arch/i386/Makefile.inc
2012-05-31 01:06:19 +02:00
Ben Gras cfb2d7bca5 retire BIOS_SEG and umap_bios
. readbios call is now a physical copy with range check in
	  the kernel call instead of BIOS_SEG+umap_bios
	. requires all access to physical memory in bios range to go
	  through sys_readbios
	. drivers/dpeth: wasn't using it
	. adjusted printer
2012-05-09 19:03:59 +02:00
Ben Gras b41df2eb0d kernel: mon_return cleanup
cleanup of boot monitor related code.
2012-04-25 17:59:43 +02:00
Ben Gras a149be43fc use linker to align fpu state save area 2012-04-19 15:06:47 +02:00
Ben Gras 53002f6f6c recognize and execute dynamically linked executables
. generalize libexec slightly to get some more necessary information
	  from ELF files, e.g. the interpreter
	. execute dynamically linked executables when exec()ed by VFS
	. switch to netbsd variant of elf32.h exclusively, solves some
	  conflicting headers
2012-04-16 00:41:42 +00:00
Ben Gras 927b9ef243 kernel: align gdt and idt base addresses
patch my fdmanana:
As recommended by the Intel 64 and IA-32 Architectures Developer's
Manual Volume 3A, the GDT and IDT base addresses should be aligned on an
8 byte boundary to yield better processor performance.
2012-04-15 20:41:36 +02:00
Ben Gras 8c4cdbd3c5 import genassym and use it for sconst.h in kernel 2012-03-31 15:29:53 +02:00
David van Moolenbroek fa805ebd1e Kernel/servers/drivers: resolve a few warnings
Flagged by clang 3.1.
2012-03-30 16:55:06 +02:00
Arun Thomas b0666ba6b6 kernel: Remove unnecessary ACK conditionals 2012-03-29 13:29:09 +02:00
Tomas Hruby 5ab87a6c38 ioapic - missing volatiles
leads to a kernel panic when using clang and SMP

reported by trd <trdempsey.201201@gmail.com>
2012-03-29 00:53:38 -07:00
Ben Gras 1e399dd8bd various kernel printing fixes
. remove some call cycles by low-level functions invoking printf(); e.g.
	  send_sig() gets a return value that the caller should check
	. reason: very-early-phase printf() would trigger a printf() causing
	  infinite recursion -> GPF
	. move serial initialization a little earlier so DEBUG_EXTRA works for
	  serial earlier (e.g. its first instance, for "cstart")
	. closes tracker item 583:
	  System Fails to Complete Startup with Verbose 2 and 3 Boot Parameters,
	  reported by Stephen Hatton / pikpik.
2012-03-28 18:23:12 +02:00
Ben Gras a5190194a0 build: don't -L/usr/pkg/lib
You might have to update the compiler-rt package! See UPDATING.

	. the purpose of this -L was solely to find compiler-rt, which contains
	  runtime support code for clang-compiled binaries
	. this also makes all other packaged libraries visible, however
	. it is cleaner to isolate the base system from packages, and so
	  compiler-rt puts itself in /usr/pkg/compiler-rt/lib/ too, which the
	  base system henceforth uses exclusively
	. e.g. this solves a link failure when libfetch is installed as a
	  package
	. the new compiler-rt package also puts itself in /usr/pkg/lib for 'old'
	  systems; that is harmless. The benefit of 'new' systems is that the other
	  packages are hidden.
2012-03-27 12:31:30 +02:00
David van Moolenbroek 9cca9d7566 Kernel: arch-related cleanup
- move umap_bios() into arch-specific code
- move proc.p_fpu_state access into arch-specific blocks
2012-03-26 14:19:33 +02:00
Ben Gras 204ae72525 retire _ANSI and <minix/ansi.h> 2012-03-25 21:58:27 +02:00
Ben Gras 7336a67dfe retire PUBLIC, PRIVATE and FORWARD 2012-03-25 21:58:14 +02:00
Ben Gras 6a73e85ad1 retire _PROTOTYPE
. only good for obsolete K&R support
	. also remove a stray ansi.h and the proto cmd
2012-03-25 16:17:10 +02:00
David van Moolenbroek 70abb127cc Add sys_vumap() kernel call
This new call is a vectored version of sys_umap(). It supports batch
lookups, non-contiguous memory, faulting in memory, and basic access
checks.
2012-03-24 19:51:13 +01:00
David van Moolenbroek 2a395dd8b4 Kernel: introduce vm_check_range 2012-03-24 19:51:13 +01:00
David van Moolenbroek 08af3f672b Kernel: replace vm_contiguous with vm_lookup_range 2012-03-24 19:51:12 +01:00
Ben Gras 6af9856d4a libcompat_minix-centric cleanup
remove some old minix-userland-specific stuff

	. /etc/ttytab as a file, and minix-compat function (fftyslot()),
	  replaced by /etc/ttys and new libc functions
	. also remove minix-specific nlist(), cuserid(), fttyslot(), v8 regex
	  functions and <compat/regex.h>
	. and remaining minix-only utilities that use them
	. also unused <compat/pwd.h> and <compat/syslog.h> and
	  redundant <sys/sigcontext.h>
2012-03-16 17:06:24 +01:00
David van Moolenbroek 1512dc5c23 Kernel: do not retry message delivery upon failure 2012-03-05 22:38:04 +01:00
David van Moolenbroek c8c9565a03 Kernel: only reset/reload FPU state when necessary 2012-03-05 22:32:14 +01:00
David van Moolenbroek a615a7d4d2 Kernel: retain FPU state upon save
On the x86, saving FPU state has the side effect of resetting this
state. In some cases (fork, getcontext), this would cause the state
to be lost. This patch restores the FPU state right after saving it,
except when different state is loaded immediately after.
2012-03-05 22:32:14 +01:00
David van Moolenbroek 0a8a2ecfb5 Kernel: pass FPU restore exception to user process
Previously, user processes could cause a kernel panic upon FPU state
restore, by passing bogus FPU state to the kernel (through e.g.
sigreturn). With this patch, the process is now sent a SIGFPE signal
instead.
2012-03-05 22:32:14 +01:00
David van Moolenbroek 4b6a98de5f Kernel: adjust FPU state upon process slot swap
This fixes seemingly random FPU exceptions and kernel panics occurring
after a system server restart.
2012-03-05 22:32:14 +01:00
Tomas Hruby 036ce9d4db Revert "SMP - no_apic=0 and acpi=1 set when CONFIG_SMP=y"
This reverts commit c468f4efa5.

Since we use the new boot loader, this hack is no longer necessary.
2012-02-24 10:16:55 +01:00
Arun Thomas 1f0bfa8519 kernel: Update copyright date 2012-02-22 16:36:26 +01:00
Ben Gras ca47635d0a try multiple reset methods
. fixes reboot-hang under vbox
	. makes experience nicer under vmware
	. taken from netbsd reset code
2012-02-20 23:46:38 +01:00
Arun Thomas 96940bcd57 kernel/utility.c: fix implicit decl warnings 2012-02-17 15:30:03 +01:00
Arun Thomas ff56906879 Remove obsolete INSTALLFLAGS from makefiles 2012-02-16 23:26:38 +01:00
Antoine Leca 3fb8cb760c More cleaning up 2012-02-15 19:04:58 +00:00
Antoine Leca f4ffbc6072 Make ELF kernel boot faster 2012-02-14 14:52:15 +01:00
Ben Gras 2fe8fb192f Full switch to clang/ELF. Drop ack. Simplify.
There is important information about booting non-ack images in
docs/UPDATING. ack/aout-format images can't be built any more, and
booting clang/ELF-format ones is a little different. Updating to the
new boot monitor is recommended.

Changes in this commit:

	. drop boot monitor -> allowing dropping ack support
	. facility to copy ELF boot files to /boot so that old boot monitor
	  can still boot fairly easily, see UPDATING
	. no more ack-format libraries -> single-case libraries
	. some cleanup of OBJECT_FMT, COMPILER_TYPE, etc cases
	. drop several ack toolchain commands, but not all support
	  commands (e.g. aal is gone but acksize is not yet).
	. a few libc files moved to netbsd libc dir
	. new /bin/date as minix date used code in libc/
	. test compile fix
	. harmonize includes
	. /usr/lib is no longer special: without ack, /usr/lib plays no
	  kind of special bootstrapping role any more and bootstrapping
	  is done exclusively through packages, so releases depend even
	  less on the state of the machine making them now.
	. rename nbsd_lib* to lib*
	. reduce mtree
2012-02-14 14:52:02 +01:00
Evgeniy Ivanov 2487445f5f make panic() work for multiboot/elf case
. we cannot use the boot monitor to print the system diag buffer
	. for serial, we do nothing, just reset, everything is already printed
	. for not-serial, we print the current diag buffer using direct video
	  memory access from the kernel
2012-02-14 14:48:10 +01:00
Ben Gras 636264c1c6 Fixes for loading kernel with multiboot
While parsing command line, only consider "variable=value" to
be part of environment.

Patch by Antoine Leca.
2012-02-09 18:54:45 +01:00
Tomas Hruby 5c0927e108 SMP - clock calibration spurious IRQ deadlock fix
- this patch fixes a deadlock which may occur if we get a
   spurious interrupt while calibrating clocks during the boot
   time. Since we never handle interrupts while in the kernel
   (BKL locked) the interrupt code locks the lock. This is a
   different situation, a corner case, boot time only. We do not
   return to userspace but to the kernel, so the BKL is not
   unlocked. So we need irq handler which leaves the BKL
   unlocked.  The clock handler does it already, this patch adds
   a dummy spurious irq handler for the same reason. It is better
   to handle the situation this way to keep the normal runtime
   code simple.
2012-01-26 11:39:40 +00:00
Tomas Hruby c468f4efa5 SMP - no_apic=0 and acpi=1 set when CONFIG_SMP=y
- this is a temporary change which makes images compiled for SMP
  boot in SMP mode by default.

- this change is needed until we can configure the multiboot
  images from the boot loader again.
2012-01-25 19:02:13 +00:00
Tomas Hruby 9e1d244cbe Revert 93b9873a56
- non need to have free PDEs per CPU since we only run one
  instance of the kernel at any time
2012-01-25 18:59:18 +00:00
Thomas Veerman a6d0ee24c3 Use correct value for _NSIG
User processes can send signals with number up to _NSIG. There are a few
signal numbers above that used by the kernel, but should explicitly not
be included in the range or range checks in PM will fail.

The system processes use a different version of sigaddset, sigdelset,
sigemptyset, sigfillset, and sigismember which does not include a range
check on signal numbers (as opposed to the normal functions used by normal
processes).

This patch unbreaks test37 when the boot image is compiled with GCC/Clang.
2012-01-16 11:42:29 +00:00
Tomas Hruby 758d788bbe SMP - asyn send SMP safe
- we must not deliver messages from/to unstable address spaces.
  In such a case, we must postpone the delivery. To make sute
  that a process which is expecting an asynchronous message does
  not starve, we must remember that we skipped delivery of some
  messages and we must try to deliver again once the source
  address space is stable again.
2012-01-13 11:30:01 +00:00
Tomas Hruby 0bb56e0e04 SMP - smp_schedule()
- always issues an IPI
2012-01-13 11:30:01 +00:00
Tomas Hruby 41bd5f2fc6 SMP - cpu_is_idle made volatile 2012-01-13 11:30:00 +00:00
Tomas Hruby 8fa95abae4 SMP - fixed usage of stale TLB entries
- when kernel copies from userspace, it must be sure that the TLB
  entries are not stale and thus the referenced memory is correct

- everytime we change a process' address space we set p_stale_tlb
  bits for all CPUs.

- Whenever a cpu finds its bit set when it wants to access the
  process' memory, it refreshes the TLB

- it is more conservative than it needs to be but it has low
  overhead than checking precisely
2012-01-13 11:30:00 +00:00
Tomas Hruby 0a55e63413 SMP - fixed IPI livelock
- two CPUs can issue IPI to each other now without any hazzard

- we must be able to handle synchronous scheduling IPIs from
  other CPUs when we are waiting for attention from another one.
  Otherwise we might livelock.

- necessary barriers to prevent reordering
2012-01-13 11:30:00 +00:00
Tomas Hruby 0468fca72b SMP - do_update fix
- adjust_proc_slot() must preserve scheduling info, for example
  on which cpu the process should run

- do_update() - consitency check
2012-01-13 11:30:00 +00:00
Tomas Hruby 192db70960 KERNEL - cause SIGSEGV if bad pointer to kernel 2012-01-13 11:30:00 +00:00
Tomas Hruby c82a5dd3e3 KERNEL - mini_senda simplification 2012-01-13 11:29:59 +00:00
Tomas Hruby e4d46a2146 KERNEL - has_pending() not exposed
- has_pending() takes a special argument that tells the code
  whether we are scanning for asynchronous message or something
  else.

- has_pending() is not used directly anymore

- the new functions are wrappings around has_pending() to make
  the use more comfortable.

- these functions should become static inline eventually
2012-01-13 11:29:59 +00:00
Tomas Hruby 8d0a1f71bf KERNEL - do_privctl() fix
- after a driver is restarted, do not register permissions
  which are already set again.
2012-01-13 11:29:59 +00:00
Antoine Leca 36d29dedd5 Allow clang for kernel compilation
Remove .ident sections, and force separations of .text and
.data sections into separate program headers, for the benefit
of the check done by MINIX boot monitor in multiboot mode.
2012-01-12 13:36:22 +01:00
Ben Gras 7cd4002083 vm: clear map cache after kernel requests
. fixes a dirty tlb situation (i.e. random crashes)
	  on some hardware, seemingly new intel architectures
	  (e.g. my desktop i7 machine)
2012-01-11 01:15:35 +01:00
Tomas Hruby aca5862db1 SMP - kernel links again 2011-12-20 13:05:25 +00:00
Tomas Hruby 9cd53f1cc0 SMP - fixed compilation and removed warnings 2011-12-20 12:58:20 +00:00
David van Moolenbroek 84662ec4b3 libsys: unbreak getidle() 2011-12-16 16:06:09 +00:00
Ben Gras 21168577a5 add -L for future compiler-rt lib location 2011-12-08 18:07:57 +01:00
David van Moolenbroek 1e1db53986 Introduce sys_getregs call, and let vfs use it 2011-11-22 02:07:33 +01:00
David van Moolenbroek b02c260ecb Miscellaneous legacy cleanup 2011-11-07 22:20:55 +01:00
David van Moolenbroek 0f3423cd75 Kernel: fix compilation with DEBUG_RACE on 2011-11-07 19:59:02 +01:00
David van Moolenbroek 8b00ebde78 Kernel: remove unused MF_ASYNMSG 2011-11-01 19:21:19 +00:00
Arun Thomas 8b4492ed1c kernel: remove unused var 2011-11-02 18:45:08 +01:00
David van Moolenbroek 1992529666 Kernel: fix for senda erroneously setting errors
Bug reported and fixed by Arne Welzel.
2011-10-31 18:43:37 +00:00
Arun Thomas f71ec49525 kernel: Remove legacy boot vars from pre_init 2011-09-19 16:39:51 +02:00