Commit Graph

2480 Commits

Author SHA1 Message Date
Alex Richardson
231f58903b [make][clang] Do not add unsupported warning flags
Currently, clang does not support the -Wno-nonnull-compare and
-Wmaybe-uninitialized warning flags so this adds lots of unknown warning
flag output for each compile job when not using GCC.
This commit adds a makefile macro to check for supported warning flags
and only adds them if the compiler actually supports them.
2023-06-01 17:50:50 -07:00
Alex Richardson
06a206f44e [make] Fix linker invocation to be compatible with ld.lld
The LLD linker does not allow joined short arguments, so split -dT <script>
into -d -T <script>.
2023-06-01 17:50:50 -07:00
Alex Richardson
82e565e232 [arm64] Allow assembling with clang
Clang does not accept this .if condition since phys_offset is a register
alias and not an absolute expression. We can keep these two instructions
here if the argument is zero since the result will be the same.
Additionally, this macro is only called once and always passes a non-zero
argument. If more calls are added in the future and avoiding these two
instructions just before a loop is really important, we could use
`.ifnc \phys_offset,0` instead, but that looks rather obscure to me.
2023-06-01 17:50:50 -07:00
Alex Richardson
365bb4e7a7 [clang][compiler.h] Expose a few more macros for Clang
Clang sets the defines for GCC 4.2.1, so we have to check __clang__ for
these macros in addition to the GCC version.
2023-06-01 17:50:50 -07:00
Alex Richardson
e40ac2a883 [clang] Avoid a nested function in heap_wrapper.c
This GCC extension is not supported by clang and in this case is not
necessary. Move the function to the top level to avoid the syntax error.
2023-06-01 17:50:50 -07:00
Akansh
28c615456c Fix CVE-2004-0230
Applied patch for CVE-2004-0230 in tcp_in.c which prevents RST Spoofing Attack (Denial of Service).
2023-06-01 12:43:56 -07:00
Aaron Odell
b8e102ecb7 [kernel][thread] Track per-thread scheduling statistics
Track per-thread runtime, last scheduled time, and count of times
scheduled. Query via existing threadstats CLI.
2023-06-01 12:40:55 -07:00
Aaron Odell
08111d4a37 [arch][arm-m][systick] Update for monotonicity
Update arm-m systick current_time() and current_time_hires() to advance
monotonically even when interrupts are disabled.

Previous implementation relied on the systick exception triggering
immediately when the counter wrapped and incrementing the current_ticks
count. But if called when interrutps are disabled, then the systick has
not had a chance to trigger and increment the count, but the counter has
already wrapped around. This would result in the current_time() value
moving backwards.

The implementation in this commit is as follows:
- Access to the systick val csr is always done in conjunction with a
  check of the COUNTFLAG bit, which indicates counter reaching zero.
- The global current_ticks count is incremented immediately when
  wrap around is detected via COUNTFLAG, rather than waiting for the
  systick exception to run.
- The check of the counter value, COUNTFLAG bit, and current_ticks
  global count are always done in a critical section to avoid race
  conditions between current_time and the systick handler.
- The critical section and workarounds are consolidated into a helper
  function shared by current_time() and current_time_hires() to
  atomically get the tick count and the cycles since the last tick.

The effect should be that current_time() always returns an accurate
monotonically increasing value, regardless of interrupt enablement
or not.
2023-06-01 12:40:55 -07:00
Travis Geiselbrecht
957b9033fb [scripts][python] Move a few more scripts from python2 to python3
Turns out they were already python3 safe, so just switch to requested
version over.
2023-06-01 12:17:37 -07:00
Pedro Falcato
67a5104d23 [arch][x86] Change the cache line size to 64 bytes
All remotely modern x86 CPUs use 64-byte cache lines. Change CACHE_LINE
to reflect this.
2023-05-20 17:46:24 -07:00
Aaron Odell
431e409c78 [arch][arm-m] Add Cortex M55 support
Add the Cortex M55 as a supported target.
2023-04-23 17:37:18 -07:00
Aaron Odell
9165714702 [inc][utils] Add a utils.h for miscellaneous helpers
Add a utils.h file containing miscellaneous convenience helpers.
2023-04-23 17:35:03 -07:00
Aaron Odell
8fc673fe4a [lib][debugcommands] Add panic command
Add a simple command to generate a test panic.
2023-04-23 17:34:57 -07:00
Aaron Odell
9ba1f165cd [libc][string] Add strcasecmp support
Add strcasecmp() for case insensitive string compares. There is no ISO
standard function for this purpose but strcasecmp() is POSIX standard.
2023-04-23 17:34:54 -07:00
Aaron Odell
9ac5708eb5 [lib][debugcommands] Add commands to display current time
Add debug commands "time" and "timeh" to display current_time() and
current_time_hires() respectively.
2023-04-23 17:34:51 -07:00
Aaron Odell
af844a2ff6 [lib][console] Add an unsigned long long to console_cmd_args
Add and populate an unsigned long long element in the console_cmd_args
struct. This enables handling of 64 bit values on 32 bit targets.
2023-04-23 17:34:49 -07:00
Aaron Odell
47c8b9a711 [scripts][buildall] Propogate logged error status through pipe tee
In the non-QUIET case, the log function pipes output to the tee command.
Without the pipefail option, if a make command fails, but the tee exits
succesfully, the overall status is 0 and the failed project doesn't get
added to the FAILED list and reported. Adding the pipefail option
propagates the make failure appropriately and adds the target to the
FAILED list.
2023-04-23 17:34:45 -07:00
Alex Richardson
6bbdcd5a09 [arm64][clang] Silence a register size mismatch warning
Even though we only need 32 bits here, clang warns that we should be
using a "w" register in the inline assembly (which is not legal with
mrs/msr). Silence the warning by declaring the value as unsigned long.

(cherry picked from commit a0de5d88dfc67b3ba34c0455b1619e12e6cfccae)
2023-04-23 17:23:31 -07:00
Alex Richardson
6b29ec9223 [clang] Silence unused private member warning
We could also remove this variable, but it seems best to keep it to
retain the same struct layout.
2023-04-23 17:23:31 -07:00
Alex Richardson
b8ae41a295 [float_test_vec] Fix -Wdouble-promotion warnings 2023-04-23 17:23:31 -07:00
Alex Richardson
8f3537d7b8 [benchmarks] Fix -Wdouble-promotion warnings 2023-04-23 17:23:31 -07:00
Alex Richardson
00f7060ba9 [benchmarks] Use volatile variables in bench_sincos
In addition to fixing -Wdouble-promition issues in bench_sincos, this also
ensures that the compiler can't replace the calls to sin/cos/sqrt with a
compile-time constant.
2023-04-23 17:23:31 -07:00
Alex Richardson
99bf8f9c41 [clang] Fix -Wformat warnings
Use %hx for uint16_t instead of %hhx.
2023-04-23 17:23:31 -07:00
Alex Richardson
7c7612225a [libc] Fix -Wincompatible-library-redeclaration for strerror
Return a char * instead of a const char * to silence this Clang warning.
2023-04-23 17:23:31 -07:00
Alex Richardson
7b12b201fd [dlmalloc] Fix -Wnull-pointer-arithmetic
Arithmetic on a NULL pointer is undefined behaviour and could be used by
the compiler to optimize out the arithmetic. Use the integer expansion of
chunk2mem(0) instead to silence this warning:
`arithmetic on a null pointer treated as a cast from integer to pointer is a GNU extension [-Wnull-pointer-arithmetic]`
2023-04-23 17:23:31 -07:00
Travis Geiselbrecht
a1eb850079 [target][visionfive2] set the time base properly
Seems to be running at 4Mhz according to the device tree.
2023-03-09 23:20:18 -08:00
Travis Geiselbrecht
7c2c8d8e56 [dev][interrupt][riscv_plic] merge now 3 implementations of the same plic driver into one
Move a copy of the PLIC driver out of one of the platforms and make the
setup of the interrupt controller a bit more dynamic.
2023-03-09 23:09:32 -08:00
Travis Geiselbrecht
c66ad44efa WIP [target][visionfive2] Add initial support for a VisionFive 2 RISC-V board
Still TODO:
-Set the timer rate properly
-Fix nonzero based hart secondary cpu boot
-Try to parse the device tree for some information
2023-03-06 01:06:27 -08:00
Pedro Falcato
ca633e2cb2 [ubsan] Improve printing of value in shift_out_of_bounds
Print it according to the type information we're given.
2023-02-18 23:13:23 -08:00
Pedro Falcato
36fd884faa [ubsan] Fix minor copy-paste bugs
Two handlers accidentally had the wrong prototype, called the wrong
thing and/or had the wrong name.

Should only affect divrem_overflow_abort, negate_overflow_abort.
2023-02-18 23:13:23 -08:00
Pedro Falcato
34d1bf4e42 [github][CI] Add UBSAN variants to CI 2023-02-18 16:47:16 -08:00
Pedro Falcato
8ebbcea5ed [ubsan] Add UBSAN implementation
Add an UBSAN implementation and a new UBSAN switch to the make build.
The implementation is taken from Onyx and handles most of the cases
that should be needed for a kernel build. Floating point and fancy
C++ CFI features are not supported yet.

To build with UBSAN, pass UBSAN=1 to make such as:
PROJECT=pc-x86-64-test make -jN UBSAN=1
2023-02-18 16:47:16 -08:00
Pedro Falcato
bf2e94c2f8 [minip] Fix undefined behavior in mac_addr_copy
There was a possibly unaligned store in mac_addr_copy.
Replace it with a memcpy call that should generate equivalent,
well defined code.
2023-02-18 16:47:16 -08:00
Travis Geiselbrecht
81d6014493 [arch][riscv] Add more defines and optimize fpu context switch
Add a few more #defines for the status register
Tweak the FPU context switch to not rewrite the entire status register,
      which may not be a generally safe thing to do.
2023-02-18 16:39:45 -08:00
Travis Geiselbrecht
92505637e8 [app][tests][float] generally spiff up the test
Still doesn't seem to work right on some arches, will need
to debug whats going on.
2023-02-18 16:39:13 -08:00
Travis Geiselbrecht
3dd8a32e92 [arch][riscv] a few small tweaks
Updated comment regarding clobbers on the SBI call.
Tweak a boot time print of SBI version.
Add a commented out line to the do-qemuriscv to assist in dumping future
device trees.
2023-02-18 14:42:59 -08:00
Travis Geiselbrecht
415096a2bf [external][lib][fdt] update libfdt to newest version
Update libfdt from https://github.com/dgibson/dtc at revision
73590342fc85ca207ca1e6cbc110179873a96962

Source is verbatim except moving headers into an include directory added
to the path.

Using 2-clause BSD option.
2023-01-15 19:02:30 -08:00
Pedro Falcato
93a8b45ada [bus][pci] Clarify device::assign_resource
The previous XXX comments were unnecessary as the spec defines the
bottom 3 bits as being hardwired and read-only.
2023-01-15 18:35:49 -08:00
Pedro Falcato
3b4dade91f [bus][pci] Disable IO and mem decoding around BAR enumeration
Disable IO and mem decoding around BAR enumation as described in the PCI
Local Bus specification. This behavior should be safer when messing
around BARs for BAR lengths.
2023-01-15 18:35:49 -08:00
Travis Geiselbrecht
91d0a5f7d1 [lib][fdtwalk] add routine to find and parse /reserved-memory node
Add logic to the riscv virt platform to properly mark off memory
claimed by OpenSBI.
2022-12-17 17:12:35 -08:00
Travis Geiselbrecht
2d561b4fcf [platform][qemu-virt-riscv] seems the first 512K are now used by opensbi 1.1
Looks like this is described in /reserved_memory/mmode_resv@<address> as
patched by opensbi on top of the existing qemu provided dtb.

Future patch should parse this instead of hard coding it.
2022-12-17 00:57:37 -08:00
gvk51
8b1335ea7e [lib][debugcommands] sanity check address is mapped before display/modify
Accessing un-mapped address/address-range results in data abort. Ensure
the address and all the pages in the requested range are mapped. Mapping
is checked at page size, also adjusts the stop address to the nearest valid
address mapped.
2022-11-03 00:04:30 -07:00
Travis Geiselbrecht
bcfad25587 [arch][x86][mmu] update how mmu code accesses physical pages
Move the mmu_initial_mapping from platform into arch/x86. For this
architecture the default mappings are basically hard coded in arch/x86
anyway, so move ownership of this data there, closer to where it's
actually initialized.
Update the 32 and 64bit paging code to properly use the paddr_to_kvaddr
and vice versa routines.
Update to allocate page tables directly from the pmm instead of the heap
(on 32bit code).
2022-11-02 23:48:49 -07:00
Travis Geiselbrecht
7742bd021b [arch][x86] general cleanup
Clean up the x86.h file a bit with how constants are defined
Switch rdtsc to builtin
Added all of the known bits for the main CR registers.
Move the invlpg macro over to the common header.
Update comments in start.S
2022-11-02 23:02:24 -07:00
Travis Geiselbrecht
0d0568612a [lib][acpi_lite] update to use the VMM to map acpi tables in
The old method assumed that all of the tables were mapped within the
kmap area of the kernel. This basically works on 64bit machines but on a
32bit x86 its entirely likely the ACPI tables are at higher physical
addresses that can be reached, which is currently limited to 1GB.

By using the VM it means it can individually map the headers and each
individual table.
2022-11-02 21:44:15 -07:00
Travis Geiselbrecht
7ddde308a3 [arch][x86][mmu] fix unmap routines to actually work
also additionally invlpg the address.
2022-11-02 02:09:46 -07:00
Travis Geiselbrecht
b990ad7999 [dev][net][e1000] just added a few comments with device ids
Was fiddling with making it work on i219 based e1000s, which was not
easily fruitful. However, may as well check in some comments with some
ids.
2022-11-02 00:28:36 -07:00
Travis Geiselbrecht
2367686854 [make] add a way for a module to opt into additional warnings
Move -Wmissing-declarations and -Wmissing-prototypes into this bucket.
Opt in most of the core top level modules in the system. More to follow.
2022-10-23 23:16:48 -07:00
Travis Geiselbrecht
4ce2e6a35d [libc] fix a warning squelch for some locally defined routines 2022-10-23 23:03:17 -07:00
Travis Geiselbrecht
7017a8fff9 [arch][mmu] add another routine to query if the arch supports user aspaces
Trim the arch mmu unit tests accordingly.

Should probably switch this to a #define, but it's possible some of
these queries could be dynamically detected (XN for example). May
revisit at some point.
2022-10-23 22:40:00 -07:00