Commit Graph

67 Commits

Author SHA1 Message Date
Travis Geiselbrecht
cc9c3a053c [arch][mmu] clean up page size definitions in each arch's defines.h
No real functional change except how the smaller ARCH_DEFAULT_PAGE_SIZE
is now computed and set in defines.h instead of rules.mk for arch/arm to
be consistent with the other arch that has a large/small build (riscv).
2025-08-31 19:16:58 -07:00
Travis Geiselbrecht
731ea62c38 [includes] remove lk/utils.h which seem to be unused on anything in mainline
Was a bit of a hodgepodge of defines. If any of these are needed we can
add them back somewhere a bit more appropriate.

ARRAY_SIZE can use countof() defined in compiler.h

KB/MB/GB are generally duplicately defined in architecture specific
files, but not generically. I couldn't think off the top of my head of a
better place to generically put these, especially since they're used in
asm files, so just deleted it for now.

The other stuff seemed to be just unused anywhere.
2025-07-18 20:25:02 -07:00
Travis Geiselbrecht
28ae26f7be [init] pack the lk init structures a little tighter by making the levels uint16_t
Should save 4 bytes per init level on 32bit architectures, though for
64bit it'll almost certainly just pad it out to the same size as before.
2025-07-18 20:16:38 -07:00
Travis Geiselbrecht
50b6f8c85c [include][compiler.h] fix a warning with gcc 2024-06-14 15:32:38 -07:00
Kelvin Zhang
4e9edd234f Fix missing apps section issue on clang
Clang linker would remove apps section even though variable
insied it are marked as "used". Per clang doc, we need to add
"retain" attribute to prevent section gc.

Bug: 294283461
Test: th
Change-Id: I5fc0aee885a419f314de811a2cf92b77af230c0c
2024-06-14 15:26:15 -07:00
Travis Geiselbrecht
86267ca23c [include][reg.h] define new mmio_read/write accessors
To work properly with some hypervisors on various architectures (ARM,
ARM64, x86), add global routines to allow access to MMIO registers via
architecturally defined accessors.

Add accessors for ARM, ARM64, and x86-32/64. Have the other arches
default to just using whatever the compiler emits.

Will need to generally move things off the legacy REG*() accessors
since they're really not safe going forward with what compilers emit.
2024-05-13 00:39:29 -07:00
Travis Geiselbrecht
6a3db09e55 [compiler] GCC 14.1 supports __has_feature
Enable it if not present, not just if its clang.
2024-05-09 18:54:38 -07:00
Travis Geiselbrecht
d9b7d070c9 [top] add header declaration for lk_boot_args
Update users of the boot args array to use the header.
2024-02-11 00:38:09 -08:00
Alex Richardson
496e2f4b8c [riscv][clang] Use a CSR name instead of a numeric expression
Clang's assembler rejects expressions containing e.g. (1u << N) in the
assembler. Instead using numeric expressions for per-privilege level
CSRs, we can prepend `m` or `s`. This also lets the compiler assign the
CSR encoding instead of having to hardcode it in the source code.
2023-06-08 07:08:49 -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
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
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
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
Peter Collingbourne
894a580b5f [top] use incomplete array declarations for constructor symbols
Clang will omit the initial comparison in this while loop on the
assumption that two different variables will not have the same address,
which will lead to a crash if the kernel has no constructors.

It will, however, retain the comparison for incomplete arrays
because they may have zero size (and therefore may alias with another
variable). Therefore, change the declarations of the start/end symbols
for the constructor list to incomplete arrays.
2022-04-19 18:29:02 -07:00
Travis Geiselbrecht
b74a4e33d4 [lib][cpp] add a auto_call class
useful for calling routines at the exit of a function.
2021-12-27 19:49:14 -08:00
Travis Geiselbrecht
dbd1b6d903 [kernel][C++] add some simple C++ wrapper and RAII holders for various locks
Just a wrapper around mutex and spinlock for now.
2021-11-10 22:57:07 -08:00
Travis Geiselbrecht
b4e6747a62 [compiler.h] add __USED to all __SECTION entries
This keeps the compiler from eliding things that are explicitly placed
in particular sections that it thinks aren't used.
2021-11-09 23:29:20 -08:00
Travis Geiselbrecht
911900f3df [arch][m68k] Merge in Motorola 68k port 2021-11-08 23:24:37 -08:00
Travis Geiselbrecht
a895bcece5 [kernel][warnings] fix a few -Wmissing-declarations warnings in the kernel 2021-10-21 23:14:27 -07:00
Travis Geiselbrecht
d6fa4d5b80 [arch][m68k] add exception and irq processing
-Add interrupt controller and timer support for qemu virt machine
-Switch tty read to irq driven as well
2021-06-07 02:40:02 -07:00
Andrei Homescu
7e502816f6 [include][compiler.h] Fix INCBIN/INCFILE macros
The compiler.h header defines two macros INCBIN and
INCFILE that can be used to include binary files
into C sources. This patch fixes a few issues with them:
* The .align directive is equivalent to .p2align
  on some architectures (ARM/AArch64) and to .balign
  on others (x86). INCBIN previously used .align and
  now uses .balign for correct alignment.
* .align 1 enforces a 2-byte alignment on ARM/AArch64,
  which caused the _end symbol for the binary to be off
  by 1 byte in some cases, which the macro previously
  accounted for (incorrectly). With the correct .balign
  directive the extra byte is never added, so the size
  is now correctly computed without the -1 addend.
* INCBIN should end in a .previous directive
  to restore the previous section, since the macro
  starts with .section.

Bug: 115420908
Change-Id: I2149e21d6f7157369a7b374a51af23933bff6b39
2021-04-08 23:55:27 -07:00
Travis Geiselbrecht
890504c922 [inc][compiler] update compiler.h with new bits from zircon
Mostly macros dealing with clang, which do not yet work, but lets
some other zircon code be compiled cleanly.
2021-04-02 19:28:58 -07:00
Travis Geiselbrecht
45a27cbf14 [arch][riscv] more work on riscv MMU code
Use a callback based shared walker to implement the
same page table walking code for different operations.

Add SBI hooks for TLB flushing.
2021-03-30 02:48:59 -07:00
Travis Geiselbrecht
7033559d38 [inc][c++] add some additional __BEGIN_CDECL/__END_CDECLS to various global headers
Just a few that were missed, and picked up with some additional C++ code.
2021-01-20 01:02:48 -08:00
Travis Geiselbrecht
4edb93adde [lib][console] rename some console command types to be prefixed with console_
Some of the structures, notably 'cmd', in the lib console stuff are a
little too generically named and have collided with some other code
so prefix the names a bit more cleanly with console_

The change is largely mechanical, and folks with out of tree code can
easily switch by renaming:
cmd -> console_cmd
cmd_args -> console_cmd_args
cmd_block -> console_cmd_block
console_cmd -> console_cmd_func

Apologies if this breaks you but it should be pretty easy to fix.
2020-07-25 15:59:58 -07:00
Travis Geiselbrecht
dac96bea90 [asm] add END_FUNCTION and END_DATA macros and mark up some riscv assembly
Doesn't really do much but at least sets the symbol size properly in a
symbol dump.
2020-07-12 13:41:11 -07:00
Travis Geiselbrecht
30a334288f [lib][console] move the command block private stuff into lib/console
Pull some of the machinery of the lib/console stuff into a private
header that is only pulled in when lib/console is built.
2020-05-17 15:43:00 -07:00
Travis Geiselbrecht
f371fa246b [arch] move the atomic ops into a separate header
Now you need to include arch/atomic.h to get to the atomic routines.
This simplifies a recusion issue in the way arch/ops.h included
arch_ops. Also just generally makes things cleaner.
2020-05-16 15:05:34 -07:00
Travis Geiselbrecht
d3d22d68a5 [lib][console] switch the console commands to __start __stop style symbols 2020-05-15 00:03:14 -07:00
Travis Geiselbrecht
c6ee887e96 [init] switch the init hook system to __start __stop style symbols 2020-05-15 00:00:50 -07:00
Travis Geiselbrecht
95cf798c83 [console][panic] slight tweak to where the panic shell define is set
Tweak the default platform_halt to idle the core if fully wedged.
2020-05-10 20:03:31 -07:00
Travis Geiselbrecht
445283fd8c [lib][unittest] slight tidying of the unittest library
Added unittest lib to the test virtual project. Currently nothing uses
it.
2020-05-10 19:50:08 -07:00
Travis Geiselbrecht
7c9906a5ff [arch][riscv] Initial implementation of MMU for RISC-V
Implements both SV39 and SV48. No 32bit support yet.

Currently implements basic setup of paging in start.S by mapping a large
chunk of memory into both an identity map and to the bottom of the
kernel address space. Run the kernel out of this physical mapping.

Added basic arch mmu support for querying existing paging structures and
mapping 4K pages. No unmap support as of yet.

System boots with mmu on when running supervisor test on qemu. Untested
on real hardware as of yet.
2020-05-10 17:09:48 -07:00
Travis Geiselbrecht
83c2eb5b0e [debug][panic] remove the wrapper panic #define and read the caller inside panic itself
Was always this way for some reason, which would tend to print the
calling routine that called the routine that paniced, which was of
dubious use. Simplify the panic logic and just call it as a standard
varargs routine.
2020-04-30 01:00:45 -07:00
Travis Geiselbrecht
df32504748 [kernel] test run sorting some includes
No functional change.
2019-07-13 17:21:00 -07:00
Travis Geiselbrecht
6cb02526b7 [include][console] split lib/console.h into two
TL;DR most uses of lib/console.h -> lk/console_cmd.h

Move the part that lets a piece of code somewhere in the system to
define a console command from the actual lib/console api to start an
instance of the console. Move in almost every place the user of the
console command definition to the new header, lk/console_cmd.h which is
always in the include path.

Also remove most uses of testing for WITH_LIB_CONSOLE since you can
almost always just safely define it and then let the linker remove it.
2019-07-13 16:56:33 -07:00
Travis Geiselbrecht
35a8d555a3 [include] move almost all of the remainder of top level includes into a subdir
Examples are include/platform.h -> platform/include/platform.h
include/target.h -> target/include/target.h

The old model generally considered these to be Always There includes,
but they're starting to stick out more and more so may as well actually
follow the model that most of the rest of the system follows.
2019-07-13 16:09:27 -07:00
Travis Geiselbrecht
cba9e47987 [license] replace the longer full MIT license with a shorter one
Used scripts/replacelic. Everything seems to build fine.
2019-07-05 17:22:23 -07:00
Travis Geiselbrecht
d8fa82cb91 [formatting] run everything through codestyle
Almost nothing changes here except moving braces to the same line as the
function declaration. Everything else is largely whitespace changes and
a few dangling files with tab indents.

See scripts/codestyle
2019-06-19 21:02:24 -07:00
Travis Geiselbrecht
1b7a28efb8 [include][lk] fixup lk/ include path move 2019-06-19 19:46:11 -07:00
Travis Geiselbrecht
2937371c84 [include] move some high level lk includes into lk/ prefixed namespace
This moves a lot of simple headers out of the top level of the namespace
under lk/.

Will affect potentially a lot of downstream code, but the fixup is very
easy. Just prepend lk/ to the path of the few files that were moved
here.
2019-06-19 19:46:11 -07:00
Travis Geiselbrecht
2eb32a4369 [style] mass reformat all the non external code to 4 space indents
Ran everything through scripts/codestyle.space, which uses astyle
to generally follow K&R style.

Biggest non whitespace change is pulling brackets down on function
declarations, which I'm pretty ambivalent about, but astyle insists
on taking a stance
2016-02-14 12:24:01 -08:00
Brian Swetland
1de5270d6e [kernel][smp] reduce impact of SMP code on UP builds
Hopefully to nothing...
- remove current/pinned cpu tracking in thread struct
- macroize access to current/pinned cpu tracking
- empty-inline/remove vestigial mp_* bits in UP builds
2016-01-17 18:46:51 -08:00
Travis Geiselbrecht
491e47fbc6 [linker] align special sections on native pointer bounary
This fixes a bug in x86-64 where it was trying to default align
input sections on 16 byte boundaries, which was screwing up the
padding between structures.
2015-11-06 12:00:04 -08:00
Travis Geiselbrecht
a79328fe97 [main] move the printf for heap after the pre-heap init hooks are run 2015-11-02 11:55:30 -08:00
Travis Geiselbrecht
114a350e55 [linker] align all the special sections on 8 byte boundaries, remove x86-64 hack
A bit overkill for 32bit machines, but aligning all the special data structures
on 8 byte boundaries removes any special case for 64bit machines.
2015-10-26 17:01:34 -07:00
Travis Geiselbrecht
0e1ce411ba [make] add ability to set EXTRA_LINKER_SCRIPTS in modules
This allows for individual modules to extend the main linker script,
primarily to add their own sections to interate over.
Remove the main shared_* linker scripts.
2015-10-26 16:47:18 -07:00
Travis Geiselbrecht
e53bc45b5b [top] add missing license and reformat top/ module 2015-10-22 21:58:59 -07:00
Travis Geiselbrecht
7682dff72f [init] bump the earliest init trace level out to TARGET_EARLY
On STM32f7xx this is the earliest point that we can printf, and it
makes sense to be more conservative than before. This is probably
a pretty common spot to be able to finally printf.
2015-10-20 16:14:16 -07:00
Travis Geiselbrecht
fab92f3179 [lib][heap] have novm initialize itself, rename novm 'heap' to 'arena' to be less confusing 2015-10-15 18:15:45 -07:00