History log of /openbsd-current/sys/arch/riscv64/riscv64/machdep.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.38 06-Apr-2024 kettenis

Now that we support RISC-V CPUs that have MMUs with memory cachability
attributes, the "direct map" becomes problematic as it results in
mappings for the same physical memory pages with different cachability
addresses. The RISC-V specification of the "Svpbmt" extension doesn't
outright state that this is "verboten" like on some other
architectures that we support. But it does say that it may result in
access with the wrong attributes. So restrict the use of the direct
map to just mapping the 64MB block that the bootloader loaded us into.
To make this possible map the device tree later like we do on arm64.
This allows us to get rid of some assembly code in locore.S as a bonus!

ok miod@, jca@


# 1.37 26-Mar-2024 kettenis

The devicetree standard allows for multiple /memory nodes, each with
multiple memory ranges. We support the latter, but not the former.
Fix this, such that we detect all the memory on the Milk-V Pioneer
board.

ok miod@


Revision tags: OPENBSD_7_5_BASE
# 1.36 21-Feb-2024 dlg

revert r1.35

i dont know what i'm doing wrong with the handling of the no-map
property, but i'll find some coffee and time and figure it out soon
hopefully.


# 1.35 21-Feb-2024 dlg

handle /reserved-memory nodes from device trees on arm64.

u-boot is supposed to take these entries and put them in the efi
memory map, but i keep hitting machines where an otherwise functional
u-boot does not do this, resulting in weird errors.

i have an espressobin with a vendor u-boot that has a reserved-memory
region for psci. without this diff the machine faults when the
kernel tries to reboot using a psci handler.

a macchiatobin with an otherwise working u-boot throws SErrors or
panics on weird memory corruption problems without this. i thought
it was bad RAM, but the problems persisted with completely different
ram, and very underclocked and well cooled ram.

riscv64 already has code to handle reserved-memory regions. the
riscv64 change is to add handling for the "no-map" property.

ok kettenis@


# 1.34 23-Jan-2024 kettenis

T-Head implemented a page attribute extension that violates the RISC-V
specification. The default attributes result in memory being uncached
which makes the system perform like a slug. So implement a workaround
that is designed to make implementation of the Svpbmt extension that is
part of the latest published RISC-V specification. This gets us a bit
further booting OpenBSD on an Allwinner D1 SoC.

ok mlarkin@, jca@


# 1.33 04-Dec-2023 claudio

Account for nkmempages as well in the pmap_growkernel() call during
initalisation. This way there is enough KVA mapped that kmeminit()
succeeds even with large nkmempages. This is similar to e.g. alpha.
OK miod@ kettenis@


Revision tags: OPENBSD_7_4_BASE
# 1.32 14-Aug-2023 miod

Skip leading dash in kernel boot options instead of complaining it is an
unknown option character.


# 1.31 05-Aug-2023 guenther

cpu_idle_{enter,leave} are no-ops on riscv64, so just #define
away the calls

ok jca@


Revision tags: OPENBSD_7_3_BASE
# 1.30 06-Dec-2022 jca

Print SBI vendor, version and implemented spec version

On my Unmatched:

SBI: OpenSBI v0.9, SBI Specification Version 0.2

ok mlarkin@


# 1.29 30-Oct-2022 guenther

Simplfity setregs() by passing it the ps_strings and switching
sys_execve() to return EJUSTRETURN.

setregs() is the MD routine used by sys_execve() to set up the
thread's trapframe and PCB such that, on 'return' to userspace, it
has the register values defined by the ABI and otherwise zero. It
had to set the syscall retval[] values previously because the normal
syscall return path overwrites a couple registers with the retval[]
values. By instead returning EJUSTRETURN that and some complexity
with program-counter handling on m88k and sparc64 goes away.

Also, give setregs() add a 'struct ps_strings *arginfo' argument
so powerpc, powerpc64, and sh can directly get argc/argv/envp
values for registers instead of copyin()ing the one in userspace.

Improvements from miod@ and millert@
Testing assistance miod@, kettenis@, and aoyama@
ok miod@ kettenis@


# 1.28 03-Oct-2022 kettenis

Reorganize the EFI code a bit. Move the efi.h header from dev/acpi to
dev/efi and rename the arm64 efi.c to efi_machdep.c, preparing the way
for MI EFI code and an amd64 implementation of EFI runtime support.

ok deraadt@, mlarkin@


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.27 22-Mar-2022 miod

Do not bother initializing a0 with a special value in setregs, that's a
FreeBSDism we have no need for.
ok jsg@


Revision tags: OPENBSD_7_0_BASE
# 1.26 14-Sep-2021 jca

Provide instruction cache invalidation through sysarch(RISCV_ICACHE_SYNC)

Modelled after the arm implementation. The first consumer would be
__builtin___clear_cache() in libcompiler_rt.

Input from kettenis@ and deraadt@, ok kettenis@


# 1.25 02-Jul-2021 kettenis

Remove a few pointless comments.


# 1.24 02-Jul-2021 kettenis

Cleanup early bootstrap code. This mostly realigns the code with the
FreeBSD code from which it was derived. In particular, it uses the same
trick to switch page tables as FreeBSD, which is what we use to spin up
the secondary CPUs already. This avoids having to install a temporary
1:1 mapping.

ok mlarkin@


# 1.23 30-Jun-2021 kettenis

Simplify the way we track the FPU state, using powerpc64 as a model.
The new code still uses the clean/dirty state that the hardware reports
to optimize saving/restoring the FPU register, but no longer attempts to
keep the FPU registers alive across a context switch. Fixes panics seen
on MP kernels.

ok drahn@


# 1.22 21-Jun-2021 kettenis

Change tb_freq to uint64_t. This prevents an overflow in the riscv64
implementation of delay(9).

ok deraadt@


# 1.21 18-Jun-2021 kettenis

When we do a context switch, always set the FPU to "off" for the old proc.
Disable the optimization to mark the new proc "clean" since it causes
random failures in regress. Hopefully we can revisit this soon.

ok drahn@


# 1.20 13-Jun-2021 kettenis

Add support for sfuart(4) as a console.

ok drahn@


# 1.19 20-May-2021 drahn

Significant overhaul of the floating point save/restore code.
At this point the mechanism should closely resemble the powerpc64
save/restore points with one difference. (reload avoidance)
The previous 'aggressive' fpu save code that was (mostly) implemented before
and is present on arm32 and arm64.

There is one piece from that other design that remains, if
pcb->pcb_fpcpu == ci && ci->ci_fpuproc == p
after sleep, this will automatically re-activate the FPU state without
needing to reload it.
To enable this, the pointer pair is not changed on FPU context save
to indicate that the CPU still holds the valid content as long as both
of those pointers are pointing to each other.
Note that if another core steals the FPU conxtex (when we get to SMP)
the pcb->pcb_fpcpu will be another cpu, and from that it will know
to reload the FPU context. Also optimistically enabling this only makes
sense on riscv64 because there is the notion of FPU on and clean. Other
implimentations would need to 'fault on' the FPU enable, but could avoid
the FPU context load if no other processor has run this FPU context and no
other process has use FPU on this core.

ok kettenis@ deraadt@ Prior to a couple of fixes.


# 1.18 19-May-2021 kettenis

Get rid of the do-nothing cache setup code. The RISC-V architecture has
no architecturally defined caches (yet) so there is nothing to set up here.
Gets rid of some more useless XXX.


# 1.17 16-May-2021 kettenis

Sync memreg_add() implementation with arm64 and powerpc64.


# 1.16 14-May-2021 jsg

remove uneeded includes


# 1.15 13-May-2021 kettenis

Use intr_enable()/int_disable()/intr_restore() instead of
enable_interrupts()/disable_interrupts()/restore_interrupts() and remove
the latter interfaces.

ok mlarkin@, drahn@


# 1.14 12-May-2021 jsg

add OpenBSD rcs ids


# 1.13 11-May-2021 deraadt

more whitespace cleanups


# 1.12 11-May-2021 deraadt

whitespace cleanup


# 1.11 04-May-2021 kettenis

The clock on RISC-V is architectural, so we really don't need the
whole abstraction layer to support multiple timers. And we don't
really need a separate driver. Replace timer(4) with code based on
the powerpc64 implementation of the randomized statclock code.

Fixes hangs seen on real hardware.

ok jsg@, drahn@


# 1.10 04-May-2021 jsg

Check that fdt hart id matches boot hart id before associating an fdt
node with the primary cpu.

Prompted by the polarfire icicle where hart 0 is an mmuless e51 core.

ok drahn@ mlarkin@


# 1.9 03-May-2021 kettenis

Use the EFI memory map (if available) to determine available physical
memory. This brings the code closer to arm64 but some key differences
remain. The most notable difference is that the riscv64 currently uses
its own private direct map of physical memory. Therefore it needs to know
the RAM address range which we derive from the /memory node in the FDT.

The code also needs to work around some bugs/flaws in the firmware:

* Newer OpenSBI versions no longer add a "no-map" property to the
reserved memory block that covers the memory used by OpenSBI itself.
This makes it appear as EfiBootServicesData in the EFI memory map,
which means it is available for general use.

* The OpenSBI shipped with the beaglev prototype boards doesn't reserve
the memory used by OpenBSI at all.

The workaround for the first issue is to remove all reserved memory blocks
specified in the FDT. In its current implementation this may remove
too much memory on certain boards.

The workaround for the second issue is to remove 2MB before the memory
where the kernel lives. This workaround is fragile since it relies on
a specific memory layout. Hopefully the beaglev firmware gets fixed and
we can remove this hack.

ok jsg@


# 1.8 03-May-2021 jsg

change some commented vfp paths to riscv64 fpu equivalents

ok mlarkin@


# 1.7 02-May-2021 kettenis

Initialize the per-CPU pointer register early.

ok drahn@


# 1.6 02-May-2021 jsg

fix logic error in boot()
ok deraadt@


# 1.5 01-May-2021 kettenis

Implement early console functionality based on available SBI calls.

While these calls are part of the legacy extensions and deprecated, they
are really useful for debugging purposes.

ok jsg@


# 1.4 30-Apr-2021 jsg

reduce diff to current arm64

ok mlarkin@


# 1.3 30-Apr-2021 jsg

remove commented arm console init lines


# 1.2 23-Apr-2021 jsg

spelling


# 1.1 23-Apr-2021 drahn

Initial import of OpenBSD/riscv64

This work is based on the effort:
https://www.openbsd.org/papers/Porting_OpenBSD_to_RISCV_FinalReport.pdf
"Porting OpenBSD to RISC-V ISA"
by
Brian Bamsch <bbamsch@google.com>
Wenyan He <wenyan.he@sjsu.edu>
Mars Li <mengshi.li.mars@gmail.com>
Shivam Waghela <shivamwaghela@gmail.com>

With additional work by Dale Rahn <drahn@openbsd.org>


# 1.37 26-Mar-2024 kettenis

The devicetree standard allows for multiple /memory nodes, each with
multiple memory ranges. We support the latter, but not the former.
Fix this, such that we detect all the memory on the Milk-V Pioneer
board.

ok miod@


Revision tags: OPENBSD_7_5_BASE
# 1.36 21-Feb-2024 dlg

revert r1.35

i dont know what i'm doing wrong with the handling of the no-map
property, but i'll find some coffee and time and figure it out soon
hopefully.


# 1.35 21-Feb-2024 dlg

handle /reserved-memory nodes from device trees on arm64.

u-boot is supposed to take these entries and put them in the efi
memory map, but i keep hitting machines where an otherwise functional
u-boot does not do this, resulting in weird errors.

i have an espressobin with a vendor u-boot that has a reserved-memory
region for psci. without this diff the machine faults when the
kernel tries to reboot using a psci handler.

a macchiatobin with an otherwise working u-boot throws SErrors or
panics on weird memory corruption problems without this. i thought
it was bad RAM, but the problems persisted with completely different
ram, and very underclocked and well cooled ram.

riscv64 already has code to handle reserved-memory regions. the
riscv64 change is to add handling for the "no-map" property.

ok kettenis@


# 1.34 23-Jan-2024 kettenis

T-Head implemented a page attribute extension that violates the RISC-V
specification. The default attributes result in memory being uncached
which makes the system perform like a slug. So implement a workaround
that is designed to make implementation of the Svpbmt extension that is
part of the latest published RISC-V specification. This gets us a bit
further booting OpenBSD on an Allwinner D1 SoC.

ok mlarkin@, jca@


# 1.33 04-Dec-2023 claudio

Account for nkmempages as well in the pmap_growkernel() call during
initalisation. This way there is enough KVA mapped that kmeminit()
succeeds even with large nkmempages. This is similar to e.g. alpha.
OK miod@ kettenis@


Revision tags: OPENBSD_7_4_BASE
# 1.32 14-Aug-2023 miod

Skip leading dash in kernel boot options instead of complaining it is an
unknown option character.


# 1.31 05-Aug-2023 guenther

cpu_idle_{enter,leave} are no-ops on riscv64, so just #define
away the calls

ok jca@


Revision tags: OPENBSD_7_3_BASE
# 1.30 06-Dec-2022 jca

Print SBI vendor, version and implemented spec version

On my Unmatched:

SBI: OpenSBI v0.9, SBI Specification Version 0.2

ok mlarkin@


# 1.29 30-Oct-2022 guenther

Simplfity setregs() by passing it the ps_strings and switching
sys_execve() to return EJUSTRETURN.

setregs() is the MD routine used by sys_execve() to set up the
thread's trapframe and PCB such that, on 'return' to userspace, it
has the register values defined by the ABI and otherwise zero. It
had to set the syscall retval[] values previously because the normal
syscall return path overwrites a couple registers with the retval[]
values. By instead returning EJUSTRETURN that and some complexity
with program-counter handling on m88k and sparc64 goes away.

Also, give setregs() add a 'struct ps_strings *arginfo' argument
so powerpc, powerpc64, and sh can directly get argc/argv/envp
values for registers instead of copyin()ing the one in userspace.

Improvements from miod@ and millert@
Testing assistance miod@, kettenis@, and aoyama@
ok miod@ kettenis@


# 1.28 03-Oct-2022 kettenis

Reorganize the EFI code a bit. Move the efi.h header from dev/acpi to
dev/efi and rename the arm64 efi.c to efi_machdep.c, preparing the way
for MI EFI code and an amd64 implementation of EFI runtime support.

ok deraadt@, mlarkin@


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.27 22-Mar-2022 miod

Do not bother initializing a0 with a special value in setregs, that's a
FreeBSDism we have no need for.
ok jsg@


Revision tags: OPENBSD_7_0_BASE
# 1.26 14-Sep-2021 jca

Provide instruction cache invalidation through sysarch(RISCV_ICACHE_SYNC)

Modelled after the arm implementation. The first consumer would be
__builtin___clear_cache() in libcompiler_rt.

Input from kettenis@ and deraadt@, ok kettenis@


# 1.25 02-Jul-2021 kettenis

Remove a few pointless comments.


# 1.24 02-Jul-2021 kettenis

Cleanup early bootstrap code. This mostly realigns the code with the
FreeBSD code from which it was derived. In particular, it uses the same
trick to switch page tables as FreeBSD, which is what we use to spin up
the secondary CPUs already. This avoids having to install a temporary
1:1 mapping.

ok mlarkin@


# 1.23 30-Jun-2021 kettenis

Simplify the way we track the FPU state, using powerpc64 as a model.
The new code still uses the clean/dirty state that the hardware reports
to optimize saving/restoring the FPU register, but no longer attempts to
keep the FPU registers alive across a context switch. Fixes panics seen
on MP kernels.

ok drahn@


# 1.22 21-Jun-2021 kettenis

Change tb_freq to uint64_t. This prevents an overflow in the riscv64
implementation of delay(9).

ok deraadt@


# 1.21 18-Jun-2021 kettenis

When we do a context switch, always set the FPU to "off" for the old proc.
Disable the optimization to mark the new proc "clean" since it causes
random failures in regress. Hopefully we can revisit this soon.

ok drahn@


# 1.20 13-Jun-2021 kettenis

Add support for sfuart(4) as a console.

ok drahn@


# 1.19 20-May-2021 drahn

Significant overhaul of the floating point save/restore code.
At this point the mechanism should closely resemble the powerpc64
save/restore points with one difference. (reload avoidance)
The previous 'aggressive' fpu save code that was (mostly) implemented before
and is present on arm32 and arm64.

There is one piece from that other design that remains, if
pcb->pcb_fpcpu == ci && ci->ci_fpuproc == p
after sleep, this will automatically re-activate the FPU state without
needing to reload it.
To enable this, the pointer pair is not changed on FPU context save
to indicate that the CPU still holds the valid content as long as both
of those pointers are pointing to each other.
Note that if another core steals the FPU conxtex (when we get to SMP)
the pcb->pcb_fpcpu will be another cpu, and from that it will know
to reload the FPU context. Also optimistically enabling this only makes
sense on riscv64 because there is the notion of FPU on and clean. Other
implimentations would need to 'fault on' the FPU enable, but could avoid
the FPU context load if no other processor has run this FPU context and no
other process has use FPU on this core.

ok kettenis@ deraadt@ Prior to a couple of fixes.


# 1.18 19-May-2021 kettenis

Get rid of the do-nothing cache setup code. The RISC-V architecture has
no architecturally defined caches (yet) so there is nothing to set up here.
Gets rid of some more useless XXX.


# 1.17 16-May-2021 kettenis

Sync memreg_add() implementation with arm64 and powerpc64.


# 1.16 14-May-2021 jsg

remove uneeded includes


# 1.15 13-May-2021 kettenis

Use intr_enable()/int_disable()/intr_restore() instead of
enable_interrupts()/disable_interrupts()/restore_interrupts() and remove
the latter interfaces.

ok mlarkin@, drahn@


# 1.14 12-May-2021 jsg

add OpenBSD rcs ids


# 1.13 11-May-2021 deraadt

more whitespace cleanups


# 1.12 11-May-2021 deraadt

whitespace cleanup


# 1.11 04-May-2021 kettenis

The clock on RISC-V is architectural, so we really don't need the
whole abstraction layer to support multiple timers. And we don't
really need a separate driver. Replace timer(4) with code based on
the powerpc64 implementation of the randomized statclock code.

Fixes hangs seen on real hardware.

ok jsg@, drahn@


# 1.10 04-May-2021 jsg

Check that fdt hart id matches boot hart id before associating an fdt
node with the primary cpu.

Prompted by the polarfire icicle where hart 0 is an mmuless e51 core.

ok drahn@ mlarkin@


# 1.9 03-May-2021 kettenis

Use the EFI memory map (if available) to determine available physical
memory. This brings the code closer to arm64 but some key differences
remain. The most notable difference is that the riscv64 currently uses
its own private direct map of physical memory. Therefore it needs to know
the RAM address range which we derive from the /memory node in the FDT.

The code also needs to work around some bugs/flaws in the firmware:

* Newer OpenSBI versions no longer add a "no-map" property to the
reserved memory block that covers the memory used by OpenSBI itself.
This makes it appear as EfiBootServicesData in the EFI memory map,
which means it is available for general use.

* The OpenSBI shipped with the beaglev prototype boards doesn't reserve
the memory used by OpenBSI at all.

The workaround for the first issue is to remove all reserved memory blocks
specified in the FDT. In its current implementation this may remove
too much memory on certain boards.

The workaround for the second issue is to remove 2MB before the memory
where the kernel lives. This workaround is fragile since it relies on
a specific memory layout. Hopefully the beaglev firmware gets fixed and
we can remove this hack.

ok jsg@


# 1.8 03-May-2021 jsg

change some commented vfp paths to riscv64 fpu equivalents

ok mlarkin@


# 1.7 02-May-2021 kettenis

Initialize the per-CPU pointer register early.

ok drahn@


# 1.6 02-May-2021 jsg

fix logic error in boot()
ok deraadt@


# 1.5 01-May-2021 kettenis

Implement early console functionality based on available SBI calls.

While these calls are part of the legacy extensions and deprecated, they
are really useful for debugging purposes.

ok jsg@


# 1.4 30-Apr-2021 jsg

reduce diff to current arm64

ok mlarkin@


# 1.3 30-Apr-2021 jsg

remove commented arm console init lines


# 1.2 23-Apr-2021 jsg

spelling


# 1.1 23-Apr-2021 drahn

Initial import of OpenBSD/riscv64

This work is based on the effort:
https://www.openbsd.org/papers/Porting_OpenBSD_to_RISCV_FinalReport.pdf
"Porting OpenBSD to RISC-V ISA"
by
Brian Bamsch <bbamsch@google.com>
Wenyan He <wenyan.he@sjsu.edu>
Mars Li <mengshi.li.mars@gmail.com>
Shivam Waghela <shivamwaghela@gmail.com>

With additional work by Dale Rahn <drahn@openbsd.org>


# 1.36 21-Feb-2024 dlg

revert r1.35

i dont know what i'm doing wrong with the handling of the no-map
property, but i'll find some coffee and time and figure it out soon
hopefully.


# 1.35 21-Feb-2024 dlg

handle /reserved-memory nodes from device trees on arm64.

u-boot is supposed to take these entries and put them in the efi
memory map, but i keep hitting machines where an otherwise functional
u-boot does not do this, resulting in weird errors.

i have an espressobin with a vendor u-boot that has a reserved-memory
region for psci. without this diff the machine faults when the
kernel tries to reboot using a psci handler.

a macchiatobin with an otherwise working u-boot throws SErrors or
panics on weird memory corruption problems without this. i thought
it was bad RAM, but the problems persisted with completely different
ram, and very underclocked and well cooled ram.

riscv64 already has code to handle reserved-memory regions. the
riscv64 change is to add handling for the "no-map" property.

ok kettenis@


# 1.34 23-Jan-2024 kettenis

T-Head implemented a page attribute extension that violates the RISC-V
specification. The default attributes result in memory being uncached
which makes the system perform like a slug. So implement a workaround
that is designed to make implementation of the Svpbmt extension that is
part of the latest published RISC-V specification. This gets us a bit
further booting OpenBSD on an Allwinner D1 SoC.

ok mlarkin@, jca@


# 1.33 04-Dec-2023 claudio

Account for nkmempages as well in the pmap_growkernel() call during
initalisation. This way there is enough KVA mapped that kmeminit()
succeeds even with large nkmempages. This is similar to e.g. alpha.
OK miod@ kettenis@


Revision tags: OPENBSD_7_4_BASE
# 1.32 14-Aug-2023 miod

Skip leading dash in kernel boot options instead of complaining it is an
unknown option character.


# 1.31 05-Aug-2023 guenther

cpu_idle_{enter,leave} are no-ops on riscv64, so just #define
away the calls

ok jca@


Revision tags: OPENBSD_7_3_BASE
# 1.30 06-Dec-2022 jca

Print SBI vendor, version and implemented spec version

On my Unmatched:

SBI: OpenSBI v0.9, SBI Specification Version 0.2

ok mlarkin@


# 1.29 30-Oct-2022 guenther

Simplfity setregs() by passing it the ps_strings and switching
sys_execve() to return EJUSTRETURN.

setregs() is the MD routine used by sys_execve() to set up the
thread's trapframe and PCB such that, on 'return' to userspace, it
has the register values defined by the ABI and otherwise zero. It
had to set the syscall retval[] values previously because the normal
syscall return path overwrites a couple registers with the retval[]
values. By instead returning EJUSTRETURN that and some complexity
with program-counter handling on m88k and sparc64 goes away.

Also, give setregs() add a 'struct ps_strings *arginfo' argument
so powerpc, powerpc64, and sh can directly get argc/argv/envp
values for registers instead of copyin()ing the one in userspace.

Improvements from miod@ and millert@
Testing assistance miod@, kettenis@, and aoyama@
ok miod@ kettenis@


# 1.28 03-Oct-2022 kettenis

Reorganize the EFI code a bit. Move the efi.h header from dev/acpi to
dev/efi and rename the arm64 efi.c to efi_machdep.c, preparing the way
for MI EFI code and an amd64 implementation of EFI runtime support.

ok deraadt@, mlarkin@


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.27 22-Mar-2022 miod

Do not bother initializing a0 with a special value in setregs, that's a
FreeBSDism we have no need for.
ok jsg@


Revision tags: OPENBSD_7_0_BASE
# 1.26 14-Sep-2021 jca

Provide instruction cache invalidation through sysarch(RISCV_ICACHE_SYNC)

Modelled after the arm implementation. The first consumer would be
__builtin___clear_cache() in libcompiler_rt.

Input from kettenis@ and deraadt@, ok kettenis@


# 1.25 02-Jul-2021 kettenis

Remove a few pointless comments.


# 1.24 02-Jul-2021 kettenis

Cleanup early bootstrap code. This mostly realigns the code with the
FreeBSD code from which it was derived. In particular, it uses the same
trick to switch page tables as FreeBSD, which is what we use to spin up
the secondary CPUs already. This avoids having to install a temporary
1:1 mapping.

ok mlarkin@


# 1.23 30-Jun-2021 kettenis

Simplify the way we track the FPU state, using powerpc64 as a model.
The new code still uses the clean/dirty state that the hardware reports
to optimize saving/restoring the FPU register, but no longer attempts to
keep the FPU registers alive across a context switch. Fixes panics seen
on MP kernels.

ok drahn@


# 1.22 21-Jun-2021 kettenis

Change tb_freq to uint64_t. This prevents an overflow in the riscv64
implementation of delay(9).

ok deraadt@


# 1.21 18-Jun-2021 kettenis

When we do a context switch, always set the FPU to "off" for the old proc.
Disable the optimization to mark the new proc "clean" since it causes
random failures in regress. Hopefully we can revisit this soon.

ok drahn@


# 1.20 13-Jun-2021 kettenis

Add support for sfuart(4) as a console.

ok drahn@


# 1.19 20-May-2021 drahn

Significant overhaul of the floating point save/restore code.
At this point the mechanism should closely resemble the powerpc64
save/restore points with one difference. (reload avoidance)
The previous 'aggressive' fpu save code that was (mostly) implemented before
and is present on arm32 and arm64.

There is one piece from that other design that remains, if
pcb->pcb_fpcpu == ci && ci->ci_fpuproc == p
after sleep, this will automatically re-activate the FPU state without
needing to reload it.
To enable this, the pointer pair is not changed on FPU context save
to indicate that the CPU still holds the valid content as long as both
of those pointers are pointing to each other.
Note that if another core steals the FPU conxtex (when we get to SMP)
the pcb->pcb_fpcpu will be another cpu, and from that it will know
to reload the FPU context. Also optimistically enabling this only makes
sense on riscv64 because there is the notion of FPU on and clean. Other
implimentations would need to 'fault on' the FPU enable, but could avoid
the FPU context load if no other processor has run this FPU context and no
other process has use FPU on this core.

ok kettenis@ deraadt@ Prior to a couple of fixes.


# 1.18 19-May-2021 kettenis

Get rid of the do-nothing cache setup code. The RISC-V architecture has
no architecturally defined caches (yet) so there is nothing to set up here.
Gets rid of some more useless XXX.


# 1.17 16-May-2021 kettenis

Sync memreg_add() implementation with arm64 and powerpc64.


# 1.16 14-May-2021 jsg

remove uneeded includes


# 1.15 13-May-2021 kettenis

Use intr_enable()/int_disable()/intr_restore() instead of
enable_interrupts()/disable_interrupts()/restore_interrupts() and remove
the latter interfaces.

ok mlarkin@, drahn@


# 1.14 12-May-2021 jsg

add OpenBSD rcs ids


# 1.13 11-May-2021 deraadt

more whitespace cleanups


# 1.12 11-May-2021 deraadt

whitespace cleanup


# 1.11 04-May-2021 kettenis

The clock on RISC-V is architectural, so we really don't need the
whole abstraction layer to support multiple timers. And we don't
really need a separate driver. Replace timer(4) with code based on
the powerpc64 implementation of the randomized statclock code.

Fixes hangs seen on real hardware.

ok jsg@, drahn@


# 1.10 04-May-2021 jsg

Check that fdt hart id matches boot hart id before associating an fdt
node with the primary cpu.

Prompted by the polarfire icicle where hart 0 is an mmuless e51 core.

ok drahn@ mlarkin@


# 1.9 03-May-2021 kettenis

Use the EFI memory map (if available) to determine available physical
memory. This brings the code closer to arm64 but some key differences
remain. The most notable difference is that the riscv64 currently uses
its own private direct map of physical memory. Therefore it needs to know
the RAM address range which we derive from the /memory node in the FDT.

The code also needs to work around some bugs/flaws in the firmware:

* Newer OpenSBI versions no longer add a "no-map" property to the
reserved memory block that covers the memory used by OpenSBI itself.
This makes it appear as EfiBootServicesData in the EFI memory map,
which means it is available for general use.

* The OpenSBI shipped with the beaglev prototype boards doesn't reserve
the memory used by OpenBSI at all.

The workaround for the first issue is to remove all reserved memory blocks
specified in the FDT. In its current implementation this may remove
too much memory on certain boards.

The workaround for the second issue is to remove 2MB before the memory
where the kernel lives. This workaround is fragile since it relies on
a specific memory layout. Hopefully the beaglev firmware gets fixed and
we can remove this hack.

ok jsg@


# 1.8 03-May-2021 jsg

change some commented vfp paths to riscv64 fpu equivalents

ok mlarkin@


# 1.7 02-May-2021 kettenis

Initialize the per-CPU pointer register early.

ok drahn@


# 1.6 02-May-2021 jsg

fix logic error in boot()
ok deraadt@


# 1.5 01-May-2021 kettenis

Implement early console functionality based on available SBI calls.

While these calls are part of the legacy extensions and deprecated, they
are really useful for debugging purposes.

ok jsg@


# 1.4 30-Apr-2021 jsg

reduce diff to current arm64

ok mlarkin@


# 1.3 30-Apr-2021 jsg

remove commented arm console init lines


# 1.2 23-Apr-2021 jsg

spelling


# 1.1 23-Apr-2021 drahn

Initial import of OpenBSD/riscv64

This work is based on the effort:
https://www.openbsd.org/papers/Porting_OpenBSD_to_RISCV_FinalReport.pdf
"Porting OpenBSD to RISC-V ISA"
by
Brian Bamsch <bbamsch@google.com>
Wenyan He <wenyan.he@sjsu.edu>
Mars Li <mengshi.li.mars@gmail.com>
Shivam Waghela <shivamwaghela@gmail.com>

With additional work by Dale Rahn <drahn@openbsd.org>


# 1.34 23-Jan-2024 kettenis

T-Head implemented a page attribute extension that violates the RISC-V
specification. The default attributes result in memory being uncached
which makes the system perform like a slug. So implement a workaround
that is designed to make implementation of the Svpbmt extension that is
part of the latest published RISC-V specification. This gets us a bit
further booting OpenBSD on an Allwinner D1 SoC.

ok mlarkin@, jca@


# 1.33 04-Dec-2023 claudio

Account for nkmempages as well in the pmap_growkernel() call during
initalisation. This way there is enough KVA mapped that kmeminit()
succeeds even with large nkmempages. This is similar to e.g. alpha.
OK miod@ kettenis@


Revision tags: OPENBSD_7_4_BASE
# 1.32 14-Aug-2023 miod

Skip leading dash in kernel boot options instead of complaining it is an
unknown option character.


# 1.31 05-Aug-2023 guenther

cpu_idle_{enter,leave} are no-ops on riscv64, so just #define
away the calls

ok jca@


Revision tags: OPENBSD_7_3_BASE
# 1.30 06-Dec-2022 jca

Print SBI vendor, version and implemented spec version

On my Unmatched:

SBI: OpenSBI v0.9, SBI Specification Version 0.2

ok mlarkin@


# 1.29 30-Oct-2022 guenther

Simplfity setregs() by passing it the ps_strings and switching
sys_execve() to return EJUSTRETURN.

setregs() is the MD routine used by sys_execve() to set up the
thread's trapframe and PCB such that, on 'return' to userspace, it
has the register values defined by the ABI and otherwise zero. It
had to set the syscall retval[] values previously because the normal
syscall return path overwrites a couple registers with the retval[]
values. By instead returning EJUSTRETURN that and some complexity
with program-counter handling on m88k and sparc64 goes away.

Also, give setregs() add a 'struct ps_strings *arginfo' argument
so powerpc, powerpc64, and sh can directly get argc/argv/envp
values for registers instead of copyin()ing the one in userspace.

Improvements from miod@ and millert@
Testing assistance miod@, kettenis@, and aoyama@
ok miod@ kettenis@


# 1.28 03-Oct-2022 kettenis

Reorganize the EFI code a bit. Move the efi.h header from dev/acpi to
dev/efi and rename the arm64 efi.c to efi_machdep.c, preparing the way
for MI EFI code and an amd64 implementation of EFI runtime support.

ok deraadt@, mlarkin@


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.27 22-Mar-2022 miod

Do not bother initializing a0 with a special value in setregs, that's a
FreeBSDism we have no need for.
ok jsg@


Revision tags: OPENBSD_7_0_BASE
# 1.26 14-Sep-2021 jca

Provide instruction cache invalidation through sysarch(RISCV_ICACHE_SYNC)

Modelled after the arm implementation. The first consumer would be
__builtin___clear_cache() in libcompiler_rt.

Input from kettenis@ and deraadt@, ok kettenis@


# 1.25 02-Jul-2021 kettenis

Remove a few pointless comments.


# 1.24 02-Jul-2021 kettenis

Cleanup early bootstrap code. This mostly realigns the code with the
FreeBSD code from which it was derived. In particular, it uses the same
trick to switch page tables as FreeBSD, which is what we use to spin up
the secondary CPUs already. This avoids having to install a temporary
1:1 mapping.

ok mlarkin@


# 1.23 30-Jun-2021 kettenis

Simplify the way we track the FPU state, using powerpc64 as a model.
The new code still uses the clean/dirty state that the hardware reports
to optimize saving/restoring the FPU register, but no longer attempts to
keep the FPU registers alive across a context switch. Fixes panics seen
on MP kernels.

ok drahn@


# 1.22 21-Jun-2021 kettenis

Change tb_freq to uint64_t. This prevents an overflow in the riscv64
implementation of delay(9).

ok deraadt@


# 1.21 18-Jun-2021 kettenis

When we do a context switch, always set the FPU to "off" for the old proc.
Disable the optimization to mark the new proc "clean" since it causes
random failures in regress. Hopefully we can revisit this soon.

ok drahn@


# 1.20 13-Jun-2021 kettenis

Add support for sfuart(4) as a console.

ok drahn@


# 1.19 20-May-2021 drahn

Significant overhaul of the floating point save/restore code.
At this point the mechanism should closely resemble the powerpc64
save/restore points with one difference. (reload avoidance)
The previous 'aggressive' fpu save code that was (mostly) implemented before
and is present on arm32 and arm64.

There is one piece from that other design that remains, if
pcb->pcb_fpcpu == ci && ci->ci_fpuproc == p
after sleep, this will automatically re-activate the FPU state without
needing to reload it.
To enable this, the pointer pair is not changed on FPU context save
to indicate that the CPU still holds the valid content as long as both
of those pointers are pointing to each other.
Note that if another core steals the FPU conxtex (when we get to SMP)
the pcb->pcb_fpcpu will be another cpu, and from that it will know
to reload the FPU context. Also optimistically enabling this only makes
sense on riscv64 because there is the notion of FPU on and clean. Other
implimentations would need to 'fault on' the FPU enable, but could avoid
the FPU context load if no other processor has run this FPU context and no
other process has use FPU on this core.

ok kettenis@ deraadt@ Prior to a couple of fixes.


# 1.18 19-May-2021 kettenis

Get rid of the do-nothing cache setup code. The RISC-V architecture has
no architecturally defined caches (yet) so there is nothing to set up here.
Gets rid of some more useless XXX.


# 1.17 16-May-2021 kettenis

Sync memreg_add() implementation with arm64 and powerpc64.


# 1.16 14-May-2021 jsg

remove uneeded includes


# 1.15 13-May-2021 kettenis

Use intr_enable()/int_disable()/intr_restore() instead of
enable_interrupts()/disable_interrupts()/restore_interrupts() and remove
the latter interfaces.

ok mlarkin@, drahn@


# 1.14 12-May-2021 jsg

add OpenBSD rcs ids


# 1.13 11-May-2021 deraadt

more whitespace cleanups


# 1.12 11-May-2021 deraadt

whitespace cleanup


# 1.11 04-May-2021 kettenis

The clock on RISC-V is architectural, so we really don't need the
whole abstraction layer to support multiple timers. And we don't
really need a separate driver. Replace timer(4) with code based on
the powerpc64 implementation of the randomized statclock code.

Fixes hangs seen on real hardware.

ok jsg@, drahn@


# 1.10 04-May-2021 jsg

Check that fdt hart id matches boot hart id before associating an fdt
node with the primary cpu.

Prompted by the polarfire icicle where hart 0 is an mmuless e51 core.

ok drahn@ mlarkin@


# 1.9 03-May-2021 kettenis

Use the EFI memory map (if available) to determine available physical
memory. This brings the code closer to arm64 but some key differences
remain. The most notable difference is that the riscv64 currently uses
its own private direct map of physical memory. Therefore it needs to know
the RAM address range which we derive from the /memory node in the FDT.

The code also needs to work around some bugs/flaws in the firmware:

* Newer OpenSBI versions no longer add a "no-map" property to the
reserved memory block that covers the memory used by OpenSBI itself.
This makes it appear as EfiBootServicesData in the EFI memory map,
which means it is available for general use.

* The OpenSBI shipped with the beaglev prototype boards doesn't reserve
the memory used by OpenBSI at all.

The workaround for the first issue is to remove all reserved memory blocks
specified in the FDT. In its current implementation this may remove
too much memory on certain boards.

The workaround for the second issue is to remove 2MB before the memory
where the kernel lives. This workaround is fragile since it relies on
a specific memory layout. Hopefully the beaglev firmware gets fixed and
we can remove this hack.

ok jsg@


# 1.8 03-May-2021 jsg

change some commented vfp paths to riscv64 fpu equivalents

ok mlarkin@


# 1.7 02-May-2021 kettenis

Initialize the per-CPU pointer register early.

ok drahn@


# 1.6 02-May-2021 jsg

fix logic error in boot()
ok deraadt@


# 1.5 01-May-2021 kettenis

Implement early console functionality based on available SBI calls.

While these calls are part of the legacy extensions and deprecated, they
are really useful for debugging purposes.

ok jsg@


# 1.4 30-Apr-2021 jsg

reduce diff to current arm64

ok mlarkin@


# 1.3 30-Apr-2021 jsg

remove commented arm console init lines


# 1.2 23-Apr-2021 jsg

spelling


# 1.1 23-Apr-2021 drahn

Initial import of OpenBSD/riscv64

This work is based on the effort:
https://www.openbsd.org/papers/Porting_OpenBSD_to_RISCV_FinalReport.pdf
"Porting OpenBSD to RISC-V ISA"
by
Brian Bamsch <bbamsch@google.com>
Wenyan He <wenyan.he@sjsu.edu>
Mars Li <mengshi.li.mars@gmail.com>
Shivam Waghela <shivamwaghela@gmail.com>

With additional work by Dale Rahn <drahn@openbsd.org>


# 1.33 04-Dec-2023 claudio

Account for nkmempages as well in the pmap_growkernel() call during
initalisation. This way there is enough KVA mapped that kmeminit()
succeeds even with large nkmempages. This is similar to e.g. alpha.
OK miod@ kettenis@


Revision tags: OPENBSD_7_4_BASE
# 1.32 14-Aug-2023 miod

Skip leading dash in kernel boot options instead of complaining it is an
unknown option character.


# 1.31 05-Aug-2023 guenther

cpu_idle_{enter,leave} are no-ops on riscv64, so just #define
away the calls

ok jca@


Revision tags: OPENBSD_7_3_BASE
# 1.30 06-Dec-2022 jca

Print SBI vendor, version and implemented spec version

On my Unmatched:

SBI: OpenSBI v0.9, SBI Specification Version 0.2

ok mlarkin@


# 1.29 30-Oct-2022 guenther

Simplfity setregs() by passing it the ps_strings and switching
sys_execve() to return EJUSTRETURN.

setregs() is the MD routine used by sys_execve() to set up the
thread's trapframe and PCB such that, on 'return' to userspace, it
has the register values defined by the ABI and otherwise zero. It
had to set the syscall retval[] values previously because the normal
syscall return path overwrites a couple registers with the retval[]
values. By instead returning EJUSTRETURN that and some complexity
with program-counter handling on m88k and sparc64 goes away.

Also, give setregs() add a 'struct ps_strings *arginfo' argument
so powerpc, powerpc64, and sh can directly get argc/argv/envp
values for registers instead of copyin()ing the one in userspace.

Improvements from miod@ and millert@
Testing assistance miod@, kettenis@, and aoyama@
ok miod@ kettenis@


# 1.28 03-Oct-2022 kettenis

Reorganize the EFI code a bit. Move the efi.h header from dev/acpi to
dev/efi and rename the arm64 efi.c to efi_machdep.c, preparing the way
for MI EFI code and an amd64 implementation of EFI runtime support.

ok deraadt@, mlarkin@


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.27 22-Mar-2022 miod

Do not bother initializing a0 with a special value in setregs, that's a
FreeBSDism we have no need for.
ok jsg@


Revision tags: OPENBSD_7_0_BASE
# 1.26 14-Sep-2021 jca

Provide instruction cache invalidation through sysarch(RISCV_ICACHE_SYNC)

Modelled after the arm implementation. The first consumer would be
__builtin___clear_cache() in libcompiler_rt.

Input from kettenis@ and deraadt@, ok kettenis@


# 1.25 02-Jul-2021 kettenis

Remove a few pointless comments.


# 1.24 02-Jul-2021 kettenis

Cleanup early bootstrap code. This mostly realigns the code with the
FreeBSD code from which it was derived. In particular, it uses the same
trick to switch page tables as FreeBSD, which is what we use to spin up
the secondary CPUs already. This avoids having to install a temporary
1:1 mapping.

ok mlarkin@


# 1.23 30-Jun-2021 kettenis

Simplify the way we track the FPU state, using powerpc64 as a model.
The new code still uses the clean/dirty state that the hardware reports
to optimize saving/restoring the FPU register, but no longer attempts to
keep the FPU registers alive across a context switch. Fixes panics seen
on MP kernels.

ok drahn@


# 1.22 21-Jun-2021 kettenis

Change tb_freq to uint64_t. This prevents an overflow in the riscv64
implementation of delay(9).

ok deraadt@


# 1.21 18-Jun-2021 kettenis

When we do a context switch, always set the FPU to "off" for the old proc.
Disable the optimization to mark the new proc "clean" since it causes
random failures in regress. Hopefully we can revisit this soon.

ok drahn@


# 1.20 13-Jun-2021 kettenis

Add support for sfuart(4) as a console.

ok drahn@


# 1.19 20-May-2021 drahn

Significant overhaul of the floating point save/restore code.
At this point the mechanism should closely resemble the powerpc64
save/restore points with one difference. (reload avoidance)
The previous 'aggressive' fpu save code that was (mostly) implemented before
and is present on arm32 and arm64.

There is one piece from that other design that remains, if
pcb->pcb_fpcpu == ci && ci->ci_fpuproc == p
after sleep, this will automatically re-activate the FPU state without
needing to reload it.
To enable this, the pointer pair is not changed on FPU context save
to indicate that the CPU still holds the valid content as long as both
of those pointers are pointing to each other.
Note that if another core steals the FPU conxtex (when we get to SMP)
the pcb->pcb_fpcpu will be another cpu, and from that it will know
to reload the FPU context. Also optimistically enabling this only makes
sense on riscv64 because there is the notion of FPU on and clean. Other
implimentations would need to 'fault on' the FPU enable, but could avoid
the FPU context load if no other processor has run this FPU context and no
other process has use FPU on this core.

ok kettenis@ deraadt@ Prior to a couple of fixes.


# 1.18 19-May-2021 kettenis

Get rid of the do-nothing cache setup code. The RISC-V architecture has
no architecturally defined caches (yet) so there is nothing to set up here.
Gets rid of some more useless XXX.


# 1.17 16-May-2021 kettenis

Sync memreg_add() implementation with arm64 and powerpc64.


# 1.16 14-May-2021 jsg

remove uneeded includes


# 1.15 13-May-2021 kettenis

Use intr_enable()/int_disable()/intr_restore() instead of
enable_interrupts()/disable_interrupts()/restore_interrupts() and remove
the latter interfaces.

ok mlarkin@, drahn@


# 1.14 12-May-2021 jsg

add OpenBSD rcs ids


# 1.13 11-May-2021 deraadt

more whitespace cleanups


# 1.12 11-May-2021 deraadt

whitespace cleanup


# 1.11 04-May-2021 kettenis

The clock on RISC-V is architectural, so we really don't need the
whole abstraction layer to support multiple timers. And we don't
really need a separate driver. Replace timer(4) with code based on
the powerpc64 implementation of the randomized statclock code.

Fixes hangs seen on real hardware.

ok jsg@, drahn@


# 1.10 04-May-2021 jsg

Check that fdt hart id matches boot hart id before associating an fdt
node with the primary cpu.

Prompted by the polarfire icicle where hart 0 is an mmuless e51 core.

ok drahn@ mlarkin@


# 1.9 03-May-2021 kettenis

Use the EFI memory map (if available) to determine available physical
memory. This brings the code closer to arm64 but some key differences
remain. The most notable difference is that the riscv64 currently uses
its own private direct map of physical memory. Therefore it needs to know
the RAM address range which we derive from the /memory node in the FDT.

The code also needs to work around some bugs/flaws in the firmware:

* Newer OpenSBI versions no longer add a "no-map" property to the
reserved memory block that covers the memory used by OpenSBI itself.
This makes it appear as EfiBootServicesData in the EFI memory map,
which means it is available for general use.

* The OpenSBI shipped with the beaglev prototype boards doesn't reserve
the memory used by OpenBSI at all.

The workaround for the first issue is to remove all reserved memory blocks
specified in the FDT. In its current implementation this may remove
too much memory on certain boards.

The workaround for the second issue is to remove 2MB before the memory
where the kernel lives. This workaround is fragile since it relies on
a specific memory layout. Hopefully the beaglev firmware gets fixed and
we can remove this hack.

ok jsg@


# 1.8 03-May-2021 jsg

change some commented vfp paths to riscv64 fpu equivalents

ok mlarkin@


# 1.7 02-May-2021 kettenis

Initialize the per-CPU pointer register early.

ok drahn@


# 1.6 02-May-2021 jsg

fix logic error in boot()
ok deraadt@


# 1.5 01-May-2021 kettenis

Implement early console functionality based on available SBI calls.

While these calls are part of the legacy extensions and deprecated, they
are really useful for debugging purposes.

ok jsg@


# 1.4 30-Apr-2021 jsg

reduce diff to current arm64

ok mlarkin@


# 1.3 30-Apr-2021 jsg

remove commented arm console init lines


# 1.2 23-Apr-2021 jsg

spelling


# 1.1 23-Apr-2021 drahn

Initial import of OpenBSD/riscv64

This work is based on the effort:
https://www.openbsd.org/papers/Porting_OpenBSD_to_RISCV_FinalReport.pdf
"Porting OpenBSD to RISC-V ISA"
by
Brian Bamsch <bbamsch@google.com>
Wenyan He <wenyan.he@sjsu.edu>
Mars Li <mengshi.li.mars@gmail.com>
Shivam Waghela <shivamwaghela@gmail.com>

With additional work by Dale Rahn <drahn@openbsd.org>


# 1.32 14-Aug-2023 miod

Skip leading dash in kernel boot options instead of complaining it is an
unknown option character.


# 1.31 05-Aug-2023 guenther

cpu_idle_{enter,leave} are no-ops on riscv64, so just #define
away the calls

ok jca@


Revision tags: OPENBSD_7_3_BASE
# 1.30 06-Dec-2022 jca

Print SBI vendor, version and implemented spec version

On my Unmatched:

SBI: OpenSBI v0.9, SBI Specification Version 0.2

ok mlarkin@


# 1.29 30-Oct-2022 guenther

Simplfity setregs() by passing it the ps_strings and switching
sys_execve() to return EJUSTRETURN.

setregs() is the MD routine used by sys_execve() to set up the
thread's trapframe and PCB such that, on 'return' to userspace, it
has the register values defined by the ABI and otherwise zero. It
had to set the syscall retval[] values previously because the normal
syscall return path overwrites a couple registers with the retval[]
values. By instead returning EJUSTRETURN that and some complexity
with program-counter handling on m88k and sparc64 goes away.

Also, give setregs() add a 'struct ps_strings *arginfo' argument
so powerpc, powerpc64, and sh can directly get argc/argv/envp
values for registers instead of copyin()ing the one in userspace.

Improvements from miod@ and millert@
Testing assistance miod@, kettenis@, and aoyama@
ok miod@ kettenis@


# 1.28 03-Oct-2022 kettenis

Reorganize the EFI code a bit. Move the efi.h header from dev/acpi to
dev/efi and rename the arm64 efi.c to efi_machdep.c, preparing the way
for MI EFI code and an amd64 implementation of EFI runtime support.

ok deraadt@, mlarkin@


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.27 22-Mar-2022 miod

Do not bother initializing a0 with a special value in setregs, that's a
FreeBSDism we have no need for.
ok jsg@


Revision tags: OPENBSD_7_0_BASE
# 1.26 14-Sep-2021 jca

Provide instruction cache invalidation through sysarch(RISCV_ICACHE_SYNC)

Modelled after the arm implementation. The first consumer would be
__builtin___clear_cache() in libcompiler_rt.

Input from kettenis@ and deraadt@, ok kettenis@


# 1.25 02-Jul-2021 kettenis

Remove a few pointless comments.


# 1.24 02-Jul-2021 kettenis

Cleanup early bootstrap code. This mostly realigns the code with the
FreeBSD code from which it was derived. In particular, it uses the same
trick to switch page tables as FreeBSD, which is what we use to spin up
the secondary CPUs already. This avoids having to install a temporary
1:1 mapping.

ok mlarkin@


# 1.23 30-Jun-2021 kettenis

Simplify the way we track the FPU state, using powerpc64 as a model.
The new code still uses the clean/dirty state that the hardware reports
to optimize saving/restoring the FPU register, but no longer attempts to
keep the FPU registers alive across a context switch. Fixes panics seen
on MP kernels.

ok drahn@


# 1.22 21-Jun-2021 kettenis

Change tb_freq to uint64_t. This prevents an overflow in the riscv64
implementation of delay(9).

ok deraadt@


# 1.21 18-Jun-2021 kettenis

When we do a context switch, always set the FPU to "off" for the old proc.
Disable the optimization to mark the new proc "clean" since it causes
random failures in regress. Hopefully we can revisit this soon.

ok drahn@


# 1.20 13-Jun-2021 kettenis

Add support for sfuart(4) as a console.

ok drahn@


# 1.19 20-May-2021 drahn

Significant overhaul of the floating point save/restore code.
At this point the mechanism should closely resemble the powerpc64
save/restore points with one difference. (reload avoidance)
The previous 'aggressive' fpu save code that was (mostly) implemented before
and is present on arm32 and arm64.

There is one piece from that other design that remains, if
pcb->pcb_fpcpu == ci && ci->ci_fpuproc == p
after sleep, this will automatically re-activate the FPU state without
needing to reload it.
To enable this, the pointer pair is not changed on FPU context save
to indicate that the CPU still holds the valid content as long as both
of those pointers are pointing to each other.
Note that if another core steals the FPU conxtex (when we get to SMP)
the pcb->pcb_fpcpu will be another cpu, and from that it will know
to reload the FPU context. Also optimistically enabling this only makes
sense on riscv64 because there is the notion of FPU on and clean. Other
implimentations would need to 'fault on' the FPU enable, but could avoid
the FPU context load if no other processor has run this FPU context and no
other process has use FPU on this core.

ok kettenis@ deraadt@ Prior to a couple of fixes.


# 1.18 19-May-2021 kettenis

Get rid of the do-nothing cache setup code. The RISC-V architecture has
no architecturally defined caches (yet) so there is nothing to set up here.
Gets rid of some more useless XXX.


# 1.17 16-May-2021 kettenis

Sync memreg_add() implementation with arm64 and powerpc64.


# 1.16 14-May-2021 jsg

remove uneeded includes


# 1.15 13-May-2021 kettenis

Use intr_enable()/int_disable()/intr_restore() instead of
enable_interrupts()/disable_interrupts()/restore_interrupts() and remove
the latter interfaces.

ok mlarkin@, drahn@


# 1.14 12-May-2021 jsg

add OpenBSD rcs ids


# 1.13 11-May-2021 deraadt

more whitespace cleanups


# 1.12 11-May-2021 deraadt

whitespace cleanup


# 1.11 04-May-2021 kettenis

The clock on RISC-V is architectural, so we really don't need the
whole abstraction layer to support multiple timers. And we don't
really need a separate driver. Replace timer(4) with code based on
the powerpc64 implementation of the randomized statclock code.

Fixes hangs seen on real hardware.

ok jsg@, drahn@


# 1.10 04-May-2021 jsg

Check that fdt hart id matches boot hart id before associating an fdt
node with the primary cpu.

Prompted by the polarfire icicle where hart 0 is an mmuless e51 core.

ok drahn@ mlarkin@


# 1.9 03-May-2021 kettenis

Use the EFI memory map (if available) to determine available physical
memory. This brings the code closer to arm64 but some key differences
remain. The most notable difference is that the riscv64 currently uses
its own private direct map of physical memory. Therefore it needs to know
the RAM address range which we derive from the /memory node in the FDT.

The code also needs to work around some bugs/flaws in the firmware:

* Newer OpenSBI versions no longer add a "no-map" property to the
reserved memory block that covers the memory used by OpenSBI itself.
This makes it appear as EfiBootServicesData in the EFI memory map,
which means it is available for general use.

* The OpenSBI shipped with the beaglev prototype boards doesn't reserve
the memory used by OpenBSI at all.

The workaround for the first issue is to remove all reserved memory blocks
specified in the FDT. In its current implementation this may remove
too much memory on certain boards.

The workaround for the second issue is to remove 2MB before the memory
where the kernel lives. This workaround is fragile since it relies on
a specific memory layout. Hopefully the beaglev firmware gets fixed and
we can remove this hack.

ok jsg@


# 1.8 03-May-2021 jsg

change some commented vfp paths to riscv64 fpu equivalents

ok mlarkin@


# 1.7 02-May-2021 kettenis

Initialize the per-CPU pointer register early.

ok drahn@


# 1.6 02-May-2021 jsg

fix logic error in boot()
ok deraadt@


# 1.5 01-May-2021 kettenis

Implement early console functionality based on available SBI calls.

While these calls are part of the legacy extensions and deprecated, they
are really useful for debugging purposes.

ok jsg@


# 1.4 30-Apr-2021 jsg

reduce diff to current arm64

ok mlarkin@


# 1.3 30-Apr-2021 jsg

remove commented arm console init lines


# 1.2 23-Apr-2021 jsg

spelling


# 1.1 23-Apr-2021 drahn

Initial import of OpenBSD/riscv64

This work is based on the effort:
https://www.openbsd.org/papers/Porting_OpenBSD_to_RISCV_FinalReport.pdf
"Porting OpenBSD to RISC-V ISA"
by
Brian Bamsch <bbamsch@google.com>
Wenyan He <wenyan.he@sjsu.edu>
Mars Li <mengshi.li.mars@gmail.com>
Shivam Waghela <shivamwaghela@gmail.com>

With additional work by Dale Rahn <drahn@openbsd.org>


# 1.31 05-Aug-2023 guenther

cpu_idle_{enter,leave} are no-ops on riscv64, so just #define
away the calls

ok jca@


Revision tags: OPENBSD_7_3_BASE
# 1.30 06-Dec-2022 jca

Print SBI vendor, version and implemented spec version

On my Unmatched:

SBI: OpenSBI v0.9, SBI Specification Version 0.2

ok mlarkin@


# 1.29 30-Oct-2022 guenther

Simplfity setregs() by passing it the ps_strings and switching
sys_execve() to return EJUSTRETURN.

setregs() is the MD routine used by sys_execve() to set up the
thread's trapframe and PCB such that, on 'return' to userspace, it
has the register values defined by the ABI and otherwise zero. It
had to set the syscall retval[] values previously because the normal
syscall return path overwrites a couple registers with the retval[]
values. By instead returning EJUSTRETURN that and some complexity
with program-counter handling on m88k and sparc64 goes away.

Also, give setregs() add a 'struct ps_strings *arginfo' argument
so powerpc, powerpc64, and sh can directly get argc/argv/envp
values for registers instead of copyin()ing the one in userspace.

Improvements from miod@ and millert@
Testing assistance miod@, kettenis@, and aoyama@
ok miod@ kettenis@


# 1.28 03-Oct-2022 kettenis

Reorganize the EFI code a bit. Move the efi.h header from dev/acpi to
dev/efi and rename the arm64 efi.c to efi_machdep.c, preparing the way
for MI EFI code and an amd64 implementation of EFI runtime support.

ok deraadt@, mlarkin@


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.27 22-Mar-2022 miod

Do not bother initializing a0 with a special value in setregs, that's a
FreeBSDism we have no need for.
ok jsg@


Revision tags: OPENBSD_7_0_BASE
# 1.26 14-Sep-2021 jca

Provide instruction cache invalidation through sysarch(RISCV_ICACHE_SYNC)

Modelled after the arm implementation. The first consumer would be
__builtin___clear_cache() in libcompiler_rt.

Input from kettenis@ and deraadt@, ok kettenis@


# 1.25 02-Jul-2021 kettenis

Remove a few pointless comments.


# 1.24 02-Jul-2021 kettenis

Cleanup early bootstrap code. This mostly realigns the code with the
FreeBSD code from which it was derived. In particular, it uses the same
trick to switch page tables as FreeBSD, which is what we use to spin up
the secondary CPUs already. This avoids having to install a temporary
1:1 mapping.

ok mlarkin@


# 1.23 30-Jun-2021 kettenis

Simplify the way we track the FPU state, using powerpc64 as a model.
The new code still uses the clean/dirty state that the hardware reports
to optimize saving/restoring the FPU register, but no longer attempts to
keep the FPU registers alive across a context switch. Fixes panics seen
on MP kernels.

ok drahn@


# 1.22 21-Jun-2021 kettenis

Change tb_freq to uint64_t. This prevents an overflow in the riscv64
implementation of delay(9).

ok deraadt@


# 1.21 18-Jun-2021 kettenis

When we do a context switch, always set the FPU to "off" for the old proc.
Disable the optimization to mark the new proc "clean" since it causes
random failures in regress. Hopefully we can revisit this soon.

ok drahn@


# 1.20 13-Jun-2021 kettenis

Add support for sfuart(4) as a console.

ok drahn@


# 1.19 20-May-2021 drahn

Significant overhaul of the floating point save/restore code.
At this point the mechanism should closely resemble the powerpc64
save/restore points with one difference. (reload avoidance)
The previous 'aggressive' fpu save code that was (mostly) implemented before
and is present on arm32 and arm64.

There is one piece from that other design that remains, if
pcb->pcb_fpcpu == ci && ci->ci_fpuproc == p
after sleep, this will automatically re-activate the FPU state without
needing to reload it.
To enable this, the pointer pair is not changed on FPU context save
to indicate that the CPU still holds the valid content as long as both
of those pointers are pointing to each other.
Note that if another core steals the FPU conxtex (when we get to SMP)
the pcb->pcb_fpcpu will be another cpu, and from that it will know
to reload the FPU context. Also optimistically enabling this only makes
sense on riscv64 because there is the notion of FPU on and clean. Other
implimentations would need to 'fault on' the FPU enable, but could avoid
the FPU context load if no other processor has run this FPU context and no
other process has use FPU on this core.

ok kettenis@ deraadt@ Prior to a couple of fixes.


# 1.18 19-May-2021 kettenis

Get rid of the do-nothing cache setup code. The RISC-V architecture has
no architecturally defined caches (yet) so there is nothing to set up here.
Gets rid of some more useless XXX.


# 1.17 16-May-2021 kettenis

Sync memreg_add() implementation with arm64 and powerpc64.


# 1.16 14-May-2021 jsg

remove uneeded includes


# 1.15 13-May-2021 kettenis

Use intr_enable()/int_disable()/intr_restore() instead of
enable_interrupts()/disable_interrupts()/restore_interrupts() and remove
the latter interfaces.

ok mlarkin@, drahn@


# 1.14 12-May-2021 jsg

add OpenBSD rcs ids


# 1.13 11-May-2021 deraadt

more whitespace cleanups


# 1.12 11-May-2021 deraadt

whitespace cleanup


# 1.11 04-May-2021 kettenis

The clock on RISC-V is architectural, so we really don't need the
whole abstraction layer to support multiple timers. And we don't
really need a separate driver. Replace timer(4) with code based on
the powerpc64 implementation of the randomized statclock code.

Fixes hangs seen on real hardware.

ok jsg@, drahn@


# 1.10 04-May-2021 jsg

Check that fdt hart id matches boot hart id before associating an fdt
node with the primary cpu.

Prompted by the polarfire icicle where hart 0 is an mmuless e51 core.

ok drahn@ mlarkin@


# 1.9 03-May-2021 kettenis

Use the EFI memory map (if available) to determine available physical
memory. This brings the code closer to arm64 but some key differences
remain. The most notable difference is that the riscv64 currently uses
its own private direct map of physical memory. Therefore it needs to know
the RAM address range which we derive from the /memory node in the FDT.

The code also needs to work around some bugs/flaws in the firmware:

* Newer OpenSBI versions no longer add a "no-map" property to the
reserved memory block that covers the memory used by OpenSBI itself.
This makes it appear as EfiBootServicesData in the EFI memory map,
which means it is available for general use.

* The OpenSBI shipped with the beaglev prototype boards doesn't reserve
the memory used by OpenBSI at all.

The workaround for the first issue is to remove all reserved memory blocks
specified in the FDT. In its current implementation this may remove
too much memory on certain boards.

The workaround for the second issue is to remove 2MB before the memory
where the kernel lives. This workaround is fragile since it relies on
a specific memory layout. Hopefully the beaglev firmware gets fixed and
we can remove this hack.

ok jsg@


# 1.8 03-May-2021 jsg

change some commented vfp paths to riscv64 fpu equivalents

ok mlarkin@


# 1.7 02-May-2021 kettenis

Initialize the per-CPU pointer register early.

ok drahn@


# 1.6 02-May-2021 jsg

fix logic error in boot()
ok deraadt@


# 1.5 01-May-2021 kettenis

Implement early console functionality based on available SBI calls.

While these calls are part of the legacy extensions and deprecated, they
are really useful for debugging purposes.

ok jsg@


# 1.4 30-Apr-2021 jsg

reduce diff to current arm64

ok mlarkin@


# 1.3 30-Apr-2021 jsg

remove commented arm console init lines


# 1.2 23-Apr-2021 jsg

spelling


# 1.1 23-Apr-2021 drahn

Initial import of OpenBSD/riscv64

This work is based on the effort:
https://www.openbsd.org/papers/Porting_OpenBSD_to_RISCV_FinalReport.pdf
"Porting OpenBSD to RISC-V ISA"
by
Brian Bamsch <bbamsch@google.com>
Wenyan He <wenyan.he@sjsu.edu>
Mars Li <mengshi.li.mars@gmail.com>
Shivam Waghela <shivamwaghela@gmail.com>

With additional work by Dale Rahn <drahn@openbsd.org>


# 1.30 06-Dec-2022 jca

Print SBI vendor, version and implemented spec version

On my Unmatched:

SBI: OpenSBI v0.9, SBI Specification Version 0.2

ok mlarkin@


# 1.29 30-Oct-2022 guenther

Simplfity setregs() by passing it the ps_strings and switching
sys_execve() to return EJUSTRETURN.

setregs() is the MD routine used by sys_execve() to set up the
thread's trapframe and PCB such that, on 'return' to userspace, it
has the register values defined by the ABI and otherwise zero. It
had to set the syscall retval[] values previously because the normal
syscall return path overwrites a couple registers with the retval[]
values. By instead returning EJUSTRETURN that and some complexity
with program-counter handling on m88k and sparc64 goes away.

Also, give setregs() add a 'struct ps_strings *arginfo' argument
so powerpc, powerpc64, and sh can directly get argc/argv/envp
values for registers instead of copyin()ing the one in userspace.

Improvements from miod@ and millert@
Testing assistance miod@, kettenis@, and aoyama@
ok miod@ kettenis@


# 1.28 03-Oct-2022 kettenis

Reorganize the EFI code a bit. Move the efi.h header from dev/acpi to
dev/efi and rename the arm64 efi.c to efi_machdep.c, preparing the way
for MI EFI code and an amd64 implementation of EFI runtime support.

ok deraadt@, mlarkin@


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.27 22-Mar-2022 miod

Do not bother initializing a0 with a special value in setregs, that's a
FreeBSDism we have no need for.
ok jsg@


Revision tags: OPENBSD_7_0_BASE
# 1.26 14-Sep-2021 jca

Provide instruction cache invalidation through sysarch(RISCV_ICACHE_SYNC)

Modelled after the arm implementation. The first consumer would be
__builtin___clear_cache() in libcompiler_rt.

Input from kettenis@ and deraadt@, ok kettenis@


# 1.25 02-Jul-2021 kettenis

Remove a few pointless comments.


# 1.24 02-Jul-2021 kettenis

Cleanup early bootstrap code. This mostly realigns the code with the
FreeBSD code from which it was derived. In particular, it uses the same
trick to switch page tables as FreeBSD, which is what we use to spin up
the secondary CPUs already. This avoids having to install a temporary
1:1 mapping.

ok mlarkin@


# 1.23 30-Jun-2021 kettenis

Simplify the way we track the FPU state, using powerpc64 as a model.
The new code still uses the clean/dirty state that the hardware reports
to optimize saving/restoring the FPU register, but no longer attempts to
keep the FPU registers alive across a context switch. Fixes panics seen
on MP kernels.

ok drahn@


# 1.22 21-Jun-2021 kettenis

Change tb_freq to uint64_t. This prevents an overflow in the riscv64
implementation of delay(9).

ok deraadt@


# 1.21 18-Jun-2021 kettenis

When we do a context switch, always set the FPU to "off" for the old proc.
Disable the optimization to mark the new proc "clean" since it causes
random failures in regress. Hopefully we can revisit this soon.

ok drahn@


# 1.20 13-Jun-2021 kettenis

Add support for sfuart(4) as a console.

ok drahn@


# 1.19 20-May-2021 drahn

Significant overhaul of the floating point save/restore code.
At this point the mechanism should closely resemble the powerpc64
save/restore points with one difference. (reload avoidance)
The previous 'aggressive' fpu save code that was (mostly) implemented before
and is present on arm32 and arm64.

There is one piece from that other design that remains, if
pcb->pcb_fpcpu == ci && ci->ci_fpuproc == p
after sleep, this will automatically re-activate the FPU state without
needing to reload it.
To enable this, the pointer pair is not changed on FPU context save
to indicate that the CPU still holds the valid content as long as both
of those pointers are pointing to each other.
Note that if another core steals the FPU conxtex (when we get to SMP)
the pcb->pcb_fpcpu will be another cpu, and from that it will know
to reload the FPU context. Also optimistically enabling this only makes
sense on riscv64 because there is the notion of FPU on and clean. Other
implimentations would need to 'fault on' the FPU enable, but could avoid
the FPU context load if no other processor has run this FPU context and no
other process has use FPU on this core.

ok kettenis@ deraadt@ Prior to a couple of fixes.


# 1.18 19-May-2021 kettenis

Get rid of the do-nothing cache setup code. The RISC-V architecture has
no architecturally defined caches (yet) so there is nothing to set up here.
Gets rid of some more useless XXX.


# 1.17 16-May-2021 kettenis

Sync memreg_add() implementation with arm64 and powerpc64.


# 1.16 14-May-2021 jsg

remove uneeded includes


# 1.15 13-May-2021 kettenis

Use intr_enable()/int_disable()/intr_restore() instead of
enable_interrupts()/disable_interrupts()/restore_interrupts() and remove
the latter interfaces.

ok mlarkin@, drahn@


# 1.14 12-May-2021 jsg

add OpenBSD rcs ids


# 1.13 11-May-2021 deraadt

more whitespace cleanups


# 1.12 11-May-2021 deraadt

whitespace cleanup


# 1.11 04-May-2021 kettenis

The clock on RISC-V is architectural, so we really don't need the
whole abstraction layer to support multiple timers. And we don't
really need a separate driver. Replace timer(4) with code based on
the powerpc64 implementation of the randomized statclock code.

Fixes hangs seen on real hardware.

ok jsg@, drahn@


# 1.10 04-May-2021 jsg

Check that fdt hart id matches boot hart id before associating an fdt
node with the primary cpu.

Prompted by the polarfire icicle where hart 0 is an mmuless e51 core.

ok drahn@ mlarkin@


# 1.9 03-May-2021 kettenis

Use the EFI memory map (if available) to determine available physical
memory. This brings the code closer to arm64 but some key differences
remain. The most notable difference is that the riscv64 currently uses
its own private direct map of physical memory. Therefore it needs to know
the RAM address range which we derive from the /memory node in the FDT.

The code also needs to work around some bugs/flaws in the firmware:

* Newer OpenSBI versions no longer add a "no-map" property to the
reserved memory block that covers the memory used by OpenSBI itself.
This makes it appear as EfiBootServicesData in the EFI memory map,
which means it is available for general use.

* The OpenSBI shipped with the beaglev prototype boards doesn't reserve
the memory used by OpenBSI at all.

The workaround for the first issue is to remove all reserved memory blocks
specified in the FDT. In its current implementation this may remove
too much memory on certain boards.

The workaround for the second issue is to remove 2MB before the memory
where the kernel lives. This workaround is fragile since it relies on
a specific memory layout. Hopefully the beaglev firmware gets fixed and
we can remove this hack.

ok jsg@


# 1.8 03-May-2021 jsg

change some commented vfp paths to riscv64 fpu equivalents

ok mlarkin@


# 1.7 02-May-2021 kettenis

Initialize the per-CPU pointer register early.

ok drahn@


# 1.6 02-May-2021 jsg

fix logic error in boot()
ok deraadt@


# 1.5 01-May-2021 kettenis

Implement early console functionality based on available SBI calls.

While these calls are part of the legacy extensions and deprecated, they
are really useful for debugging purposes.

ok jsg@


# 1.4 30-Apr-2021 jsg

reduce diff to current arm64

ok mlarkin@


# 1.3 30-Apr-2021 jsg

remove commented arm console init lines


# 1.2 23-Apr-2021 jsg

spelling


# 1.1 23-Apr-2021 drahn

Initial import of OpenBSD/riscv64

This work is based on the effort:
https://www.openbsd.org/papers/Porting_OpenBSD_to_RISCV_FinalReport.pdf
"Porting OpenBSD to RISC-V ISA"
by
Brian Bamsch <bbamsch@google.com>
Wenyan He <wenyan.he@sjsu.edu>
Mars Li <mengshi.li.mars@gmail.com>
Shivam Waghela <shivamwaghela@gmail.com>

With additional work by Dale Rahn <drahn@openbsd.org>


# 1.29 30-Oct-2022 guenther

Simplfity setregs() by passing it the ps_strings and switching
sys_execve() to return EJUSTRETURN.

setregs() is the MD routine used by sys_execve() to set up the
thread's trapframe and PCB such that, on 'return' to userspace, it
has the register values defined by the ABI and otherwise zero. It
had to set the syscall retval[] values previously because the normal
syscall return path overwrites a couple registers with the retval[]
values. By instead returning EJUSTRETURN that and some complexity
with program-counter handling on m88k and sparc64 goes away.

Also, give setregs() add a 'struct ps_strings *arginfo' argument
so powerpc, powerpc64, and sh can directly get argc/argv/envp
values for registers instead of copyin()ing the one in userspace.

Improvements from miod@ and millert@
Testing assistance miod@, kettenis@, and aoyama@
ok miod@ kettenis@


# 1.28 03-Oct-2022 kettenis

Reorganize the EFI code a bit. Move the efi.h header from dev/acpi to
dev/efi and rename the arm64 efi.c to efi_machdep.c, preparing the way
for MI EFI code and an amd64 implementation of EFI runtime support.

ok deraadt@, mlarkin@


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.27 22-Mar-2022 miod

Do not bother initializing a0 with a special value in setregs, that's a
FreeBSDism we have no need for.
ok jsg@


Revision tags: OPENBSD_7_0_BASE
# 1.26 14-Sep-2021 jca

Provide instruction cache invalidation through sysarch(RISCV_ICACHE_SYNC)

Modelled after the arm implementation. The first consumer would be
__builtin___clear_cache() in libcompiler_rt.

Input from kettenis@ and deraadt@, ok kettenis@


# 1.25 02-Jul-2021 kettenis

Remove a few pointless comments.


# 1.24 02-Jul-2021 kettenis

Cleanup early bootstrap code. This mostly realigns the code with the
FreeBSD code from which it was derived. In particular, it uses the same
trick to switch page tables as FreeBSD, which is what we use to spin up
the secondary CPUs already. This avoids having to install a temporary
1:1 mapping.

ok mlarkin@


# 1.23 30-Jun-2021 kettenis

Simplify the way we track the FPU state, using powerpc64 as a model.
The new code still uses the clean/dirty state that the hardware reports
to optimize saving/restoring the FPU register, but no longer attempts to
keep the FPU registers alive across a context switch. Fixes panics seen
on MP kernels.

ok drahn@


# 1.22 21-Jun-2021 kettenis

Change tb_freq to uint64_t. This prevents an overflow in the riscv64
implementation of delay(9).

ok deraadt@


# 1.21 18-Jun-2021 kettenis

When we do a context switch, always set the FPU to "off" for the old proc.
Disable the optimization to mark the new proc "clean" since it causes
random failures in regress. Hopefully we can revisit this soon.

ok drahn@


# 1.20 13-Jun-2021 kettenis

Add support for sfuart(4) as a console.

ok drahn@


# 1.19 20-May-2021 drahn

Significant overhaul of the floating point save/restore code.
At this point the mechanism should closely resemble the powerpc64
save/restore points with one difference. (reload avoidance)
The previous 'aggressive' fpu save code that was (mostly) implemented before
and is present on arm32 and arm64.

There is one piece from that other design that remains, if
pcb->pcb_fpcpu == ci && ci->ci_fpuproc == p
after sleep, this will automatically re-activate the FPU state without
needing to reload it.
To enable this, the pointer pair is not changed on FPU context save
to indicate that the CPU still holds the valid content as long as both
of those pointers are pointing to each other.
Note that if another core steals the FPU conxtex (when we get to SMP)
the pcb->pcb_fpcpu will be another cpu, and from that it will know
to reload the FPU context. Also optimistically enabling this only makes
sense on riscv64 because there is the notion of FPU on and clean. Other
implimentations would need to 'fault on' the FPU enable, but could avoid
the FPU context load if no other processor has run this FPU context and no
other process has use FPU on this core.

ok kettenis@ deraadt@ Prior to a couple of fixes.


# 1.18 19-May-2021 kettenis

Get rid of the do-nothing cache setup code. The RISC-V architecture has
no architecturally defined caches (yet) so there is nothing to set up here.
Gets rid of some more useless XXX.


# 1.17 16-May-2021 kettenis

Sync memreg_add() implementation with arm64 and powerpc64.


# 1.16 14-May-2021 jsg

remove uneeded includes


# 1.15 13-May-2021 kettenis

Use intr_enable()/int_disable()/intr_restore() instead of
enable_interrupts()/disable_interrupts()/restore_interrupts() and remove
the latter interfaces.

ok mlarkin@, drahn@


# 1.14 12-May-2021 jsg

add OpenBSD rcs ids


# 1.13 11-May-2021 deraadt

more whitespace cleanups


# 1.12 11-May-2021 deraadt

whitespace cleanup


# 1.11 04-May-2021 kettenis

The clock on RISC-V is architectural, so we really don't need the
whole abstraction layer to support multiple timers. And we don't
really need a separate driver. Replace timer(4) with code based on
the powerpc64 implementation of the randomized statclock code.

Fixes hangs seen on real hardware.

ok jsg@, drahn@


# 1.10 04-May-2021 jsg

Check that fdt hart id matches boot hart id before associating an fdt
node with the primary cpu.

Prompted by the polarfire icicle where hart 0 is an mmuless e51 core.

ok drahn@ mlarkin@


# 1.9 03-May-2021 kettenis

Use the EFI memory map (if available) to determine available physical
memory. This brings the code closer to arm64 but some key differences
remain. The most notable difference is that the riscv64 currently uses
its own private direct map of physical memory. Therefore it needs to know
the RAM address range which we derive from the /memory node in the FDT.

The code also needs to work around some bugs/flaws in the firmware:

* Newer OpenSBI versions no longer add a "no-map" property to the
reserved memory block that covers the memory used by OpenSBI itself.
This makes it appear as EfiBootServicesData in the EFI memory map,
which means it is available for general use.

* The OpenSBI shipped with the beaglev prototype boards doesn't reserve
the memory used by OpenBSI at all.

The workaround for the first issue is to remove all reserved memory blocks
specified in the FDT. In its current implementation this may remove
too much memory on certain boards.

The workaround for the second issue is to remove 2MB before the memory
where the kernel lives. This workaround is fragile since it relies on
a specific memory layout. Hopefully the beaglev firmware gets fixed and
we can remove this hack.

ok jsg@


# 1.8 03-May-2021 jsg

change some commented vfp paths to riscv64 fpu equivalents

ok mlarkin@


# 1.7 02-May-2021 kettenis

Initialize the per-CPU pointer register early.

ok drahn@


# 1.6 02-May-2021 jsg

fix logic error in boot()
ok deraadt@


# 1.5 01-May-2021 kettenis

Implement early console functionality based on available SBI calls.

While these calls are part of the legacy extensions and deprecated, they
are really useful for debugging purposes.

ok jsg@


# 1.4 30-Apr-2021 jsg

reduce diff to current arm64

ok mlarkin@


# 1.3 30-Apr-2021 jsg

remove commented arm console init lines


# 1.2 23-Apr-2021 jsg

spelling


# 1.1 23-Apr-2021 drahn

Initial import of OpenBSD/riscv64

This work is based on the effort:
https://www.openbsd.org/papers/Porting_OpenBSD_to_RISCV_FinalReport.pdf
"Porting OpenBSD to RISC-V ISA"
by
Brian Bamsch <bbamsch@google.com>
Wenyan He <wenyan.he@sjsu.edu>
Mars Li <mengshi.li.mars@gmail.com>
Shivam Waghela <shivamwaghela@gmail.com>

With additional work by Dale Rahn <drahn@openbsd.org>


# 1.28 03-Oct-2022 kettenis

Reorganize the EFI code a bit. Move the efi.h header from dev/acpi to
dev/efi and rename the arm64 efi.c to efi_machdep.c, preparing the way
for MI EFI code and an amd64 implementation of EFI runtime support.

ok deraadt@, mlarkin@


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.27 22-Mar-2022 miod

Do not bother initializing a0 with a special value in setregs, that's a
FreeBSDism we have no need for.
ok jsg@


Revision tags: OPENBSD_7_0_BASE
# 1.26 14-Sep-2021 jca

Provide instruction cache invalidation through sysarch(RISCV_ICACHE_SYNC)

Modelled after the arm implementation. The first consumer would be
__builtin___clear_cache() in libcompiler_rt.

Input from kettenis@ and deraadt@, ok kettenis@


# 1.25 02-Jul-2021 kettenis

Remove a few pointless comments.


# 1.24 02-Jul-2021 kettenis

Cleanup early bootstrap code. This mostly realigns the code with the
FreeBSD code from which it was derived. In particular, it uses the same
trick to switch page tables as FreeBSD, which is what we use to spin up
the secondary CPUs already. This avoids having to install a temporary
1:1 mapping.

ok mlarkin@


# 1.23 30-Jun-2021 kettenis

Simplify the way we track the FPU state, using powerpc64 as a model.
The new code still uses the clean/dirty state that the hardware reports
to optimize saving/restoring the FPU register, but no longer attempts to
keep the FPU registers alive across a context switch. Fixes panics seen
on MP kernels.

ok drahn@


# 1.22 21-Jun-2021 kettenis

Change tb_freq to uint64_t. This prevents an overflow in the riscv64
implementation of delay(9).

ok deraadt@


# 1.21 18-Jun-2021 kettenis

When we do a context switch, always set the FPU to "off" for the old proc.
Disable the optimization to mark the new proc "clean" since it causes
random failures in regress. Hopefully we can revisit this soon.

ok drahn@


# 1.20 13-Jun-2021 kettenis

Add support for sfuart(4) as a console.

ok drahn@


# 1.19 20-May-2021 drahn

Significant overhaul of the floating point save/restore code.
At this point the mechanism should closely resemble the powerpc64
save/restore points with one difference. (reload avoidance)
The previous 'aggressive' fpu save code that was (mostly) implemented before
and is present on arm32 and arm64.

There is one piece from that other design that remains, if
pcb->pcb_fpcpu == ci && ci->ci_fpuproc == p
after sleep, this will automatically re-activate the FPU state without
needing to reload it.
To enable this, the pointer pair is not changed on FPU context save
to indicate that the CPU still holds the valid content as long as both
of those pointers are pointing to each other.
Note that if another core steals the FPU conxtex (when we get to SMP)
the pcb->pcb_fpcpu will be another cpu, and from that it will know
to reload the FPU context. Also optimistically enabling this only makes
sense on riscv64 because there is the notion of FPU on and clean. Other
implimentations would need to 'fault on' the FPU enable, but could avoid
the FPU context load if no other processor has run this FPU context and no
other process has use FPU on this core.

ok kettenis@ deraadt@ Prior to a couple of fixes.


# 1.18 19-May-2021 kettenis

Get rid of the do-nothing cache setup code. The RISC-V architecture has
no architecturally defined caches (yet) so there is nothing to set up here.
Gets rid of some more useless XXX.


# 1.17 16-May-2021 kettenis

Sync memreg_add() implementation with arm64 and powerpc64.


# 1.16 14-May-2021 jsg

remove uneeded includes


# 1.15 13-May-2021 kettenis

Use intr_enable()/int_disable()/intr_restore() instead of
enable_interrupts()/disable_interrupts()/restore_interrupts() and remove
the latter interfaces.

ok mlarkin@, drahn@


# 1.14 12-May-2021 jsg

add OpenBSD rcs ids


# 1.13 11-May-2021 deraadt

more whitespace cleanups


# 1.12 11-May-2021 deraadt

whitespace cleanup


# 1.11 04-May-2021 kettenis

The clock on RISC-V is architectural, so we really don't need the
whole abstraction layer to support multiple timers. And we don't
really need a separate driver. Replace timer(4) with code based on
the powerpc64 implementation of the randomized statclock code.

Fixes hangs seen on real hardware.

ok jsg@, drahn@


# 1.10 04-May-2021 jsg

Check that fdt hart id matches boot hart id before associating an fdt
node with the primary cpu.

Prompted by the polarfire icicle where hart 0 is an mmuless e51 core.

ok drahn@ mlarkin@


# 1.9 03-May-2021 kettenis

Use the EFI memory map (if available) to determine available physical
memory. This brings the code closer to arm64 but some key differences
remain. The most notable difference is that the riscv64 currently uses
its own private direct map of physical memory. Therefore it needs to know
the RAM address range which we derive from the /memory node in the FDT.

The code also needs to work around some bugs/flaws in the firmware:

* Newer OpenSBI versions no longer add a "no-map" property to the
reserved memory block that covers the memory used by OpenSBI itself.
This makes it appear as EfiBootServicesData in the EFI memory map,
which means it is available for general use.

* The OpenSBI shipped with the beaglev prototype boards doesn't reserve
the memory used by OpenBSI at all.

The workaround for the first issue is to remove all reserved memory blocks
specified in the FDT. In its current implementation this may remove
too much memory on certain boards.

The workaround for the second issue is to remove 2MB before the memory
where the kernel lives. This workaround is fragile since it relies on
a specific memory layout. Hopefully the beaglev firmware gets fixed and
we can remove this hack.

ok jsg@


# 1.8 03-May-2021 jsg

change some commented vfp paths to riscv64 fpu equivalents

ok mlarkin@


# 1.7 02-May-2021 kettenis

Initialize the per-CPU pointer register early.

ok drahn@


# 1.6 02-May-2021 jsg

fix logic error in boot()
ok deraadt@


# 1.5 01-May-2021 kettenis

Implement early console functionality based on available SBI calls.

While these calls are part of the legacy extensions and deprecated, they
are really useful for debugging purposes.

ok jsg@


# 1.4 30-Apr-2021 jsg

reduce diff to current arm64

ok mlarkin@


# 1.3 30-Apr-2021 jsg

remove commented arm console init lines


# 1.2 23-Apr-2021 jsg

spelling


# 1.1 23-Apr-2021 drahn

Initial import of OpenBSD/riscv64

This work is based on the effort:
https://www.openbsd.org/papers/Porting_OpenBSD_to_RISCV_FinalReport.pdf
"Porting OpenBSD to RISC-V ISA"
by
Brian Bamsch <bbamsch@google.com>
Wenyan He <wenyan.he@sjsu.edu>
Mars Li <mengshi.li.mars@gmail.com>
Shivam Waghela <shivamwaghela@gmail.com>

With additional work by Dale Rahn <drahn@openbsd.org>


# 1.27 22-Mar-2022 miod

Do not bother initializing a0 with a special value in setregs, that's a
FreeBSDism we have no need for.
ok jsg@


Revision tags: OPENBSD_7_0_BASE
# 1.26 14-Sep-2021 jca

Provide instruction cache invalidation through sysarch(RISCV_ICACHE_SYNC)

Modelled after the arm implementation. The first consumer would be
__builtin___clear_cache() in libcompiler_rt.

Input from kettenis@ and deraadt@, ok kettenis@


# 1.25 02-Jul-2021 kettenis

Remove a few pointless comments.


# 1.24 02-Jul-2021 kettenis

Cleanup early bootstrap code. This mostly realigns the code with the
FreeBSD code from which it was derived. In particular, it uses the same
trick to switch page tables as FreeBSD, which is what we use to spin up
the secondary CPUs already. This avoids having to install a temporary
1:1 mapping.

ok mlarkin@


# 1.23 30-Jun-2021 kettenis

Simplify the way we track the FPU state, using powerpc64 as a model.
The new code still uses the clean/dirty state that the hardware reports
to optimize saving/restoring the FPU register, but no longer attempts to
keep the FPU registers alive across a context switch. Fixes panics seen
on MP kernels.

ok drahn@


# 1.22 21-Jun-2021 kettenis

Change tb_freq to uint64_t. This prevents an overflow in the riscv64
implementation of delay(9).

ok deraadt@


# 1.21 18-Jun-2021 kettenis

When we do a context switch, always set the FPU to "off" for the old proc.
Disable the optimization to mark the new proc "clean" since it causes
random failures in regress. Hopefully we can revisit this soon.

ok drahn@


# 1.20 13-Jun-2021 kettenis

Add support for sfuart(4) as a console.

ok drahn@


# 1.19 20-May-2021 drahn

Significant overhaul of the floating point save/restore code.
At this point the mechanism should closely resemble the powerpc64
save/restore points with one difference. (reload avoidance)
The previous 'aggressive' fpu save code that was (mostly) implemented before
and is present on arm32 and arm64.

There is one piece from that other design that remains, if
pcb->pcb_fpcpu == ci && ci->ci_fpuproc == p
after sleep, this will automatically re-activate the FPU state without
needing to reload it.
To enable this, the pointer pair is not changed on FPU context save
to indicate that the CPU still holds the valid content as long as both
of those pointers are pointing to each other.
Note that if another core steals the FPU conxtex (when we get to SMP)
the pcb->pcb_fpcpu will be another cpu, and from that it will know
to reload the FPU context. Also optimistically enabling this only makes
sense on riscv64 because there is the notion of FPU on and clean. Other
implimentations would need to 'fault on' the FPU enable, but could avoid
the FPU context load if no other processor has run this FPU context and no
other process has use FPU on this core.

ok kettenis@ deraadt@ Prior to a couple of fixes.


# 1.18 19-May-2021 kettenis

Get rid of the do-nothing cache setup code. The RISC-V architecture has
no architecturally defined caches (yet) so there is nothing to set up here.
Gets rid of some more useless XXX.


# 1.17 16-May-2021 kettenis

Sync memreg_add() implementation with arm64 and powerpc64.


# 1.16 14-May-2021 jsg

remove uneeded includes


# 1.15 13-May-2021 kettenis

Use intr_enable()/int_disable()/intr_restore() instead of
enable_interrupts()/disable_interrupts()/restore_interrupts() and remove
the latter interfaces.

ok mlarkin@, drahn@


# 1.14 12-May-2021 jsg

add OpenBSD rcs ids


# 1.13 11-May-2021 deraadt

more whitespace cleanups


# 1.12 11-May-2021 deraadt

whitespace cleanup


# 1.11 04-May-2021 kettenis

The clock on RISC-V is architectural, so we really don't need the
whole abstraction layer to support multiple timers. And we don't
really need a separate driver. Replace timer(4) with code based on
the powerpc64 implementation of the randomized statclock code.

Fixes hangs seen on real hardware.

ok jsg@, drahn@


# 1.10 04-May-2021 jsg

Check that fdt hart id matches boot hart id before associating an fdt
node with the primary cpu.

Prompted by the polarfire icicle where hart 0 is an mmuless e51 core.

ok drahn@ mlarkin@


# 1.9 03-May-2021 kettenis

Use the EFI memory map (if available) to determine available physical
memory. This brings the code closer to arm64 but some key differences
remain. The most notable difference is that the riscv64 currently uses
its own private direct map of physical memory. Therefore it needs to know
the RAM address range which we derive from the /memory node in the FDT.

The code also needs to work around some bugs/flaws in the firmware:

* Newer OpenSBI versions no longer add a "no-map" property to the
reserved memory block that covers the memory used by OpenSBI itself.
This makes it appear as EfiBootServicesData in the EFI memory map,
which means it is available for general use.

* The OpenSBI shipped with the beaglev prototype boards doesn't reserve
the memory used by OpenBSI at all.

The workaround for the first issue is to remove all reserved memory blocks
specified in the FDT. In its current implementation this may remove
too much memory on certain boards.

The workaround for the second issue is to remove 2MB before the memory
where the kernel lives. This workaround is fragile since it relies on
a specific memory layout. Hopefully the beaglev firmware gets fixed and
we can remove this hack.

ok jsg@


# 1.8 03-May-2021 jsg

change some commented vfp paths to riscv64 fpu equivalents

ok mlarkin@


# 1.7 02-May-2021 kettenis

Initialize the per-CPU pointer register early.

ok drahn@


# 1.6 02-May-2021 jsg

fix logic error in boot()
ok deraadt@


# 1.5 01-May-2021 kettenis

Implement early console functionality based on available SBI calls.

While these calls are part of the legacy extensions and deprecated, they
are really useful for debugging purposes.

ok jsg@


# 1.4 30-Apr-2021 jsg

reduce diff to current arm64

ok mlarkin@


# 1.3 30-Apr-2021 jsg

remove commented arm console init lines


# 1.2 23-Apr-2021 jsg

spelling


# 1.1 23-Apr-2021 drahn

Initial import of OpenBSD/riscv64

This work is based on the effort:
https://www.openbsd.org/papers/Porting_OpenBSD_to_RISCV_FinalReport.pdf
"Porting OpenBSD to RISC-V ISA"
by
Brian Bamsch <bbamsch@google.com>
Wenyan He <wenyan.he@sjsu.edu>
Mars Li <mengshi.li.mars@gmail.com>
Shivam Waghela <shivamwaghela@gmail.com>

With additional work by Dale Rahn <drahn@openbsd.org>


# 1.26 14-Sep-2021 jca

Provide instruction cache invalidation through sysarch(RISCV_ICACHE_SYNC)

Modelled after the arm implementation. The first consumer would be
__builtin___clear_cache() in libcompiler_rt.

Input from kettenis@ and deraadt@, ok kettenis@


# 1.25 02-Jul-2021 kettenis

Remove a few pointless comments.


# 1.24 02-Jul-2021 kettenis

Cleanup early bootstrap code. This mostly realigns the code with the
FreeBSD code from which it was derived. In particular, it uses the same
trick to switch page tables as FreeBSD, which is what we use to spin up
the secondary CPUs already. This avoids having to install a temporary
1:1 mapping.

ok mlarkin@


# 1.23 30-Jun-2021 kettenis

Simplify the way we track the FPU state, using powerpc64 as a model.
The new code still uses the clean/dirty state that the hardware reports
to optimize saving/restoring the FPU register, but no longer attempts to
keep the FPU registers alive across a context switch. Fixes panics seen
on MP kernels.

ok drahn@


# 1.22 21-Jun-2021 kettenis

Change tb_freq to uint64_t. This prevents an overflow in the riscv64
implementation of delay(9).

ok deraadt@


# 1.21 18-Jun-2021 kettenis

When we do a context switch, always set the FPU to "off" for the old proc.
Disable the optimization to mark the new proc "clean" since it causes
random failures in regress. Hopefully we can revisit this soon.

ok drahn@


# 1.20 13-Jun-2021 kettenis

Add support for sfuart(4) as a console.

ok drahn@


# 1.19 20-May-2021 drahn

Significant overhaul of the floating point save/restore code.
At this point the mechanism should closely resemble the powerpc64
save/restore points with one difference. (reload avoidance)
The previous 'aggressive' fpu save code that was (mostly) implemented before
and is present on arm32 and arm64.

There is one piece from that other design that remains, if
pcb->pcb_fpcpu == ci && ci->ci_fpuproc == p
after sleep, this will automatically re-activate the FPU state without
needing to reload it.
To enable this, the pointer pair is not changed on FPU context save
to indicate that the CPU still holds the valid content as long as both
of those pointers are pointing to each other.
Note that if another core steals the FPU conxtex (when we get to SMP)
the pcb->pcb_fpcpu will be another cpu, and from that it will know
to reload the FPU context. Also optimistically enabling this only makes
sense on riscv64 because there is the notion of FPU on and clean. Other
implimentations would need to 'fault on' the FPU enable, but could avoid
the FPU context load if no other processor has run this FPU context and no
other process has use FPU on this core.

ok kettenis@ deraadt@ Prior to a couple of fixes.


# 1.18 19-May-2021 kettenis

Get rid of the do-nothing cache setup code. The RISC-V architecture has
no architecturally defined caches (yet) so there is nothing to set up here.
Gets rid of some more useless XXX.


# 1.17 16-May-2021 kettenis

Sync memreg_add() implementation with arm64 and powerpc64.


# 1.16 14-May-2021 jsg

remove uneeded includes


# 1.15 13-May-2021 kettenis

Use intr_enable()/int_disable()/intr_restore() instead of
enable_interrupts()/disable_interrupts()/restore_interrupts() and remove
the latter interfaces.

ok mlarkin@, drahn@


# 1.14 12-May-2021 jsg

add OpenBSD rcs ids


# 1.13 11-May-2021 deraadt

more whitespace cleanups


# 1.12 11-May-2021 deraadt

whitespace cleanup


# 1.11 04-May-2021 kettenis

The clock on RISC-V is architectural, so we really don't need the
whole abstraction layer to support multiple timers. And we don't
really need a separate driver. Replace timer(4) with code based on
the powerpc64 implementation of the randomized statclock code.

Fixes hangs seen on real hardware.

ok jsg@, drahn@


# 1.10 04-May-2021 jsg

Check that fdt hart id matches boot hart id before associating an fdt
node with the primary cpu.

Prompted by the polarfire icicle where hart 0 is an mmuless e51 core.

ok drahn@ mlarkin@


# 1.9 03-May-2021 kettenis

Use the EFI memory map (if available) to determine available physical
memory. This brings the code closer to arm64 but some key differences
remain. The most notable difference is that the riscv64 currently uses
its own private direct map of physical memory. Therefore it needs to know
the RAM address range which we derive from the /memory node in the FDT.

The code also needs to work around some bugs/flaws in the firmware:

* Newer OpenSBI versions no longer add a "no-map" property to the
reserved memory block that covers the memory used by OpenSBI itself.
This makes it appear as EfiBootServicesData in the EFI memory map,
which means it is available for general use.

* The OpenSBI shipped with the beaglev prototype boards doesn't reserve
the memory used by OpenBSI at all.

The workaround for the first issue is to remove all reserved memory blocks
specified in the FDT. In its current implementation this may remove
too much memory on certain boards.

The workaround for the second issue is to remove 2MB before the memory
where the kernel lives. This workaround is fragile since it relies on
a specific memory layout. Hopefully the beaglev firmware gets fixed and
we can remove this hack.

ok jsg@


# 1.8 03-May-2021 jsg

change some commented vfp paths to riscv64 fpu equivalents

ok mlarkin@


# 1.7 02-May-2021 kettenis

Initialize the per-CPU pointer register early.

ok drahn@


# 1.6 02-May-2021 jsg

fix logic error in boot()
ok deraadt@


# 1.5 01-May-2021 kettenis

Implement early console functionality based on available SBI calls.

While these calls are part of the legacy extensions and deprecated, they
are really useful for debugging purposes.

ok jsg@


# 1.4 30-Apr-2021 jsg

reduce diff to current arm64

ok mlarkin@


# 1.3 30-Apr-2021 jsg

remove commented arm console init lines


# 1.2 23-Apr-2021 jsg

spelling


# 1.1 23-Apr-2021 drahn

Initial import of OpenBSD/riscv64

This work is based on the effort:
https://www.openbsd.org/papers/Porting_OpenBSD_to_RISCV_FinalReport.pdf
"Porting OpenBSD to RISC-V ISA"
by
Brian Bamsch <bbamsch@google.com>
Wenyan He <wenyan.he@sjsu.edu>
Mars Li <mengshi.li.mars@gmail.com>
Shivam Waghela <shivamwaghela@gmail.com>

With additional work by Dale Rahn <drahn@openbsd.org>


# 1.25 02-Jul-2021 kettenis

Remove a few pointless comments.


# 1.24 02-Jul-2021 kettenis

Cleanup early bootstrap code. This mostly realigns the code with the
FreeBSD code from which it was derived. In particular, it uses the same
trick to switch page tables as FreeBSD, which is what we use to spin up
the secondary CPUs already. This avoids having to install a temporary
1:1 mapping.

ok mlarkin@


# 1.23 30-Jun-2021 kettenis

Simplify the way we track the FPU state, using powerpc64 as a model.
The new code still uses the clean/dirty state that the hardware reports
to optimize saving/restoring the FPU register, but no longer attempts to
keep the FPU registers alive across a context switch. Fixes panics seen
on MP kernels.

ok drahn@


# 1.22 21-Jun-2021 kettenis

Change tb_freq to uint64_t. This prevents an overflow in the riscv64
implementation of delay(9).

ok deraadt@


# 1.21 18-Jun-2021 kettenis

When we do a context switch, always set the FPU to "off" for the old proc.
Disable the optimization to mark the new proc "clean" since it causes
random failures in regress. Hopefully we can revisit this soon.

ok drahn@


# 1.20 13-Jun-2021 kettenis

Add support for sfuart(4) as a console.

ok drahn@


# 1.19 20-May-2021 drahn

Significant overhaul of the floating point save/restore code.
At this point the mechanism should closely resemble the powerpc64
save/restore points with one difference. (reload avoidance)
The previous 'aggressive' fpu save code that was (mostly) implemented before
and is present on arm32 and arm64.

There is one piece from that other design that remains, if
pcb->pcb_fpcpu == ci && ci->ci_fpuproc == p
after sleep, this will automatically re-activate the FPU state without
needing to reload it.
To enable this, the pointer pair is not changed on FPU context save
to indicate that the CPU still holds the valid content as long as both
of those pointers are pointing to each other.
Note that if another core steals the FPU conxtex (when we get to SMP)
the pcb->pcb_fpcpu will be another cpu, and from that it will know
to reload the FPU context. Also optimistically enabling this only makes
sense on riscv64 because there is the notion of FPU on and clean. Other
implimentations would need to 'fault on' the FPU enable, but could avoid
the FPU context load if no other processor has run this FPU context and no
other process has use FPU on this core.

ok kettenis@ deraadt@ Prior to a couple of fixes.


# 1.18 19-May-2021 kettenis

Get rid of the do-nothing cache setup code. The RISC-V architecture has
no architecturally defined caches (yet) so there is nothing to set up here.
Gets rid of some more useless XXX.


# 1.17 16-May-2021 kettenis

Sync memreg_add() implementation with arm64 and powerpc64.


# 1.16 14-May-2021 jsg

remove uneeded includes


# 1.15 13-May-2021 kettenis

Use intr_enable()/int_disable()/intr_restore() instead of
enable_interrupts()/disable_interrupts()/restore_interrupts() and remove
the latter interfaces.

ok mlarkin@, drahn@


# 1.14 12-May-2021 jsg

add OpenBSD rcs ids


# 1.13 11-May-2021 deraadt

more whitespace cleanups


# 1.12 11-May-2021 deraadt

whitespace cleanup


# 1.11 04-May-2021 kettenis

The clock on RISC-V is architectural, so we really don't need the
whole abstraction layer to support multiple timers. And we don't
really need a separate driver. Replace timer(4) with code based on
the powerpc64 implementation of the randomized statclock code.

Fixes hangs seen on real hardware.

ok jsg@, drahn@


# 1.10 04-May-2021 jsg

Check that fdt hart id matches boot hart id before associating an fdt
node with the primary cpu.

Prompted by the polarfire icicle where hart 0 is an mmuless e51 core.

ok drahn@ mlarkin@


# 1.9 03-May-2021 kettenis

Use the EFI memory map (if available) to determine available physical
memory. This brings the code closer to arm64 but some key differences
remain. The most notable difference is that the riscv64 currently uses
its own private direct map of physical memory. Therefore it needs to know
the RAM address range which we derive from the /memory node in the FDT.

The code also needs to work around some bugs/flaws in the firmware:

* Newer OpenSBI versions no longer add a "no-map" property to the
reserved memory block that covers the memory used by OpenSBI itself.
This makes it appear as EfiBootServicesData in the EFI memory map,
which means it is available for general use.

* The OpenSBI shipped with the beaglev prototype boards doesn't reserve
the memory used by OpenBSI at all.

The workaround for the first issue is to remove all reserved memory blocks
specified in the FDT. In its current implementation this may remove
too much memory on certain boards.

The workaround for the second issue is to remove 2MB before the memory
where the kernel lives. This workaround is fragile since it relies on
a specific memory layout. Hopefully the beaglev firmware gets fixed and
we can remove this hack.

ok jsg@


# 1.8 03-May-2021 jsg

change some commented vfp paths to riscv64 fpu equivalents

ok mlarkin@


# 1.7 02-May-2021 kettenis

Initialize the per-CPU pointer register early.

ok drahn@


# 1.6 02-May-2021 jsg

fix logic error in boot()
ok deraadt@


# 1.5 01-May-2021 kettenis

Implement early console functionality based on available SBI calls.

While these calls are part of the legacy extensions and deprecated, they
are really useful for debugging purposes.

ok jsg@


# 1.4 30-Apr-2021 jsg

reduce diff to current arm64

ok mlarkin@


# 1.3 30-Apr-2021 jsg

remove commented arm console init lines


# 1.2 23-Apr-2021 jsg

spelling


# 1.1 23-Apr-2021 drahn

Initial import of OpenBSD/riscv64

This work is based on the effort:
https://www.openbsd.org/papers/Porting_OpenBSD_to_RISCV_FinalReport.pdf
"Porting OpenBSD to RISC-V ISA"
by
Brian Bamsch <bbamsch@google.com>
Wenyan He <wenyan.he@sjsu.edu>
Mars Li <mengshi.li.mars@gmail.com>
Shivam Waghela <shivamwaghela@gmail.com>

With additional work by Dale Rahn <drahn@openbsd.org>


# 1.23 30-Jun-2021 kettenis

Simplify the way we track the FPU state, using powerpc64 as a model.
The new code still uses the clean/dirty state that the hardware reports
to optimize saving/restoring the FPU register, but no longer attempts to
keep the FPU registers alive across a context switch. Fixes panics seen
on MP kernels.

ok drahn@


# 1.22 21-Jun-2021 kettenis

Change tb_freq to uint64_t. This prevents an overflow in the riscv64
implementation of delay(9).

ok deraadt@


# 1.21 18-Jun-2021 kettenis

When we do a context switch, always set the FPU to "off" for the old proc.
Disable the optimization to mark the new proc "clean" since it causes
random failures in regress. Hopefully we can revisit this soon.

ok drahn@


# 1.20 13-Jun-2021 kettenis

Add support for sfuart(4) as a console.

ok drahn@


# 1.19 20-May-2021 drahn

Significant overhaul of the floating point save/restore code.
At this point the mechanism should closely resemble the powerpc64
save/restore points with one difference. (reload avoidance)
The previous 'aggressive' fpu save code that was (mostly) implemented before
and is present on arm32 and arm64.

There is one piece from that other design that remains, if
pcb->pcb_fpcpu == ci && ci->ci_fpuproc == p
after sleep, this will automatically re-activate the FPU state without
needing to reload it.
To enable this, the pointer pair is not changed on FPU context save
to indicate that the CPU still holds the valid content as long as both
of those pointers are pointing to each other.
Note that if another core steals the FPU conxtex (when we get to SMP)
the pcb->pcb_fpcpu will be another cpu, and from that it will know
to reload the FPU context. Also optimistically enabling this only makes
sense on riscv64 because there is the notion of FPU on and clean. Other
implimentations would need to 'fault on' the FPU enable, but could avoid
the FPU context load if no other processor has run this FPU context and no
other process has use FPU on this core.

ok kettenis@ deraadt@ Prior to a couple of fixes.


# 1.18 19-May-2021 kettenis

Get rid of the do-nothing cache setup code. The RISC-V architecture has
no architecturally defined caches (yet) so there is nothing to set up here.
Gets rid of some more useless XXX.


# 1.17 16-May-2021 kettenis

Sync memreg_add() implementation with arm64 and powerpc64.


# 1.16 14-May-2021 jsg

remove uneeded includes


# 1.15 13-May-2021 kettenis

Use intr_enable()/int_disable()/intr_restore() instead of
enable_interrupts()/disable_interrupts()/restore_interrupts() and remove
the latter interfaces.

ok mlarkin@, drahn@


# 1.14 12-May-2021 jsg

add OpenBSD rcs ids


# 1.13 11-May-2021 deraadt

more whitespace cleanups


# 1.12 11-May-2021 deraadt

whitespace cleanup


# 1.11 04-May-2021 kettenis

The clock on RISC-V is architectural, so we really don't need the
whole abstraction layer to support multiple timers. And we don't
really need a separate driver. Replace timer(4) with code based on
the powerpc64 implementation of the randomized statclock code.

Fixes hangs seen on real hardware.

ok jsg@, drahn@


# 1.10 04-May-2021 jsg

Check that fdt hart id matches boot hart id before associating an fdt
node with the primary cpu.

Prompted by the polarfire icicle where hart 0 is an mmuless e51 core.

ok drahn@ mlarkin@


# 1.9 03-May-2021 kettenis

Use the EFI memory map (if available) to determine available physical
memory. This brings the code closer to arm64 but some key differences
remain. The most notable difference is that the riscv64 currently uses
its own private direct map of physical memory. Therefore it needs to know
the RAM address range which we derive from the /memory node in the FDT.

The code also needs to work around some bugs/flaws in the firmware:

* Newer OpenSBI versions no longer add a "no-map" property to the
reserved memory block that covers the memory used by OpenSBI itself.
This makes it appear as EfiBootServicesData in the EFI memory map,
which means it is available for general use.

* The OpenSBI shipped with the beaglev prototype boards doesn't reserve
the memory used by OpenBSI at all.

The workaround for the first issue is to remove all reserved memory blocks
specified in the FDT. In its current implementation this may remove
too much memory on certain boards.

The workaround for the second issue is to remove 2MB before the memory
where the kernel lives. This workaround is fragile since it relies on
a specific memory layout. Hopefully the beaglev firmware gets fixed and
we can remove this hack.

ok jsg@


# 1.8 03-May-2021 jsg

change some commented vfp paths to riscv64 fpu equivalents

ok mlarkin@


# 1.7 02-May-2021 kettenis

Initialize the per-CPU pointer register early.

ok drahn@


# 1.6 02-May-2021 jsg

fix logic error in boot()
ok deraadt@


# 1.5 01-May-2021 kettenis

Implement early console functionality based on available SBI calls.

While these calls are part of the legacy extensions and deprecated, they
are really useful for debugging purposes.

ok jsg@


# 1.4 30-Apr-2021 jsg

reduce diff to current arm64

ok mlarkin@


# 1.3 30-Apr-2021 jsg

remove commented arm console init lines


# 1.2 23-Apr-2021 jsg

spelling


# 1.1 23-Apr-2021 drahn

Initial import of OpenBSD/riscv64

This work is based on the effort:
https://www.openbsd.org/papers/Porting_OpenBSD_to_RISCV_FinalReport.pdf
"Porting OpenBSD to RISC-V ISA"
by
Brian Bamsch <bbamsch@google.com>
Wenyan He <wenyan.he@sjsu.edu>
Mars Li <mengshi.li.mars@gmail.com>
Shivam Waghela <shivamwaghela@gmail.com>

With additional work by Dale Rahn <drahn@openbsd.org>


# 1.22 21-Jun-2021 kettenis

Change tb_freq to uint64_t. This prevents an overflow in the riscv64
implementation of delay(9).

ok deraadt@


# 1.21 18-Jun-2021 kettenis

When we do a context switch, always set the FPU to "off" for the old proc.
Disable the optimization to mark the new proc "clean" since it causes
random failures in regress. Hopefully we can revisit this soon.

ok drahn@


# 1.20 13-Jun-2021 kettenis

Add support for sfuart(4) as a console.

ok drahn@


# 1.19 20-May-2021 drahn

Significant overhaul of the floating point save/restore code.
At this point the mechanism should closely resemble the powerpc64
save/restore points with one difference. (reload avoidance)
The previous 'aggressive' fpu save code that was (mostly) implemented before
and is present on arm32 and arm64.

There is one piece from that other design that remains, if
pcb->pcb_fpcpu == ci && ci->ci_fpuproc == p
after sleep, this will automatically re-activate the FPU state without
needing to reload it.
To enable this, the pointer pair is not changed on FPU context save
to indicate that the CPU still holds the valid content as long as both
of those pointers are pointing to each other.
Note that if another core steals the FPU conxtex (when we get to SMP)
the pcb->pcb_fpcpu will be another cpu, and from that it will know
to reload the FPU context. Also optimistically enabling this only makes
sense on riscv64 because there is the notion of FPU on and clean. Other
implimentations would need to 'fault on' the FPU enable, but could avoid
the FPU context load if no other processor has run this FPU context and no
other process has use FPU on this core.

ok kettenis@ deraadt@ Prior to a couple of fixes.


# 1.18 19-May-2021 kettenis

Get rid of the do-nothing cache setup code. The RISC-V architecture has
no architecturally defined caches (yet) so there is nothing to set up here.
Gets rid of some more useless XXX.


# 1.17 16-May-2021 kettenis

Sync memreg_add() implementation with arm64 and powerpc64.


# 1.16 14-May-2021 jsg

remove uneeded includes


# 1.15 13-May-2021 kettenis

Use intr_enable()/int_disable()/intr_restore() instead of
enable_interrupts()/disable_interrupts()/restore_interrupts() and remove
the latter interfaces.

ok mlarkin@, drahn@


# 1.14 12-May-2021 jsg

add OpenBSD rcs ids


# 1.13 11-May-2021 deraadt

more whitespace cleanups


# 1.12 11-May-2021 deraadt

whitespace cleanup


# 1.11 04-May-2021 kettenis

The clock on RISC-V is architectural, so we really don't need the
whole abstraction layer to support multiple timers. And we don't
really need a separate driver. Replace timer(4) with code based on
the powerpc64 implementation of the randomized statclock code.

Fixes hangs seen on real hardware.

ok jsg@, drahn@


# 1.10 04-May-2021 jsg

Check that fdt hart id matches boot hart id before associating an fdt
node with the primary cpu.

Prompted by the polarfire icicle where hart 0 is an mmuless e51 core.

ok drahn@ mlarkin@


# 1.9 03-May-2021 kettenis

Use the EFI memory map (if available) to determine available physical
memory. This brings the code closer to arm64 but some key differences
remain. The most notable difference is that the riscv64 currently uses
its own private direct map of physical memory. Therefore it needs to know
the RAM address range which we derive from the /memory node in the FDT.

The code also needs to work around some bugs/flaws in the firmware:

* Newer OpenSBI versions no longer add a "no-map" property to the
reserved memory block that covers the memory used by OpenSBI itself.
This makes it appear as EfiBootServicesData in the EFI memory map,
which means it is available for general use.

* The OpenSBI shipped with the beaglev prototype boards doesn't reserve
the memory used by OpenBSI at all.

The workaround for the first issue is to remove all reserved memory blocks
specified in the FDT. In its current implementation this may remove
too much memory on certain boards.

The workaround for the second issue is to remove 2MB before the memory
where the kernel lives. This workaround is fragile since it relies on
a specific memory layout. Hopefully the beaglev firmware gets fixed and
we can remove this hack.

ok jsg@


# 1.8 03-May-2021 jsg

change some commented vfp paths to riscv64 fpu equivalents

ok mlarkin@


# 1.7 02-May-2021 kettenis

Initialize the per-CPU pointer register early.

ok drahn@


# 1.6 02-May-2021 jsg

fix logic error in boot()
ok deraadt@


# 1.5 01-May-2021 kettenis

Implement early console functionality based on available SBI calls.

While these calls are part of the legacy extensions and deprecated, they
are really useful for debugging purposes.

ok jsg@


# 1.4 30-Apr-2021 jsg

reduce diff to current arm64

ok mlarkin@


# 1.3 30-Apr-2021 jsg

remove commented arm console init lines


# 1.2 23-Apr-2021 jsg

spelling


# 1.1 23-Apr-2021 drahn

Initial import of OpenBSD/riscv64

This work is based on the effort:
https://www.openbsd.org/papers/Porting_OpenBSD_to_RISCV_FinalReport.pdf
"Porting OpenBSD to RISC-V ISA"
by
Brian Bamsch <bbamsch@google.com>
Wenyan He <wenyan.he@sjsu.edu>
Mars Li <mengshi.li.mars@gmail.com>
Shivam Waghela <shivamwaghela@gmail.com>

With additional work by Dale Rahn <drahn@openbsd.org>


# 1.21 18-Jun-2021 kettenis

When we do a context switch, always set the FPU to "off" for the old proc.
Disable the optimization to mark the new proc "clean" since it causes
random failures in regress. Hopefully we can revisit this soon.

ok drahn@


# 1.20 13-Jun-2021 kettenis

Add support for sfuart(4) as a console.

ok drahn@


# 1.19 20-May-2021 drahn

Significant overhaul of the floating point save/restore code.
At this point the mechanism should closely resemble the powerpc64
save/restore points with one difference. (reload avoidance)
The previous 'aggressive' fpu save code that was (mostly) implemented before
and is present on arm32 and arm64.

There is one piece from that other design that remains, if
pcb->pcb_fpcpu == ci && ci->ci_fpuproc == p
after sleep, this will automatically re-activate the FPU state without
needing to reload it.
To enable this, the pointer pair is not changed on FPU context save
to indicate that the CPU still holds the valid content as long as both
of those pointers are pointing to each other.
Note that if another core steals the FPU conxtex (when we get to SMP)
the pcb->pcb_fpcpu will be another cpu, and from that it will know
to reload the FPU context. Also optimistically enabling this only makes
sense on riscv64 because there is the notion of FPU on and clean. Other
implimentations would need to 'fault on' the FPU enable, but could avoid
the FPU context load if no other processor has run this FPU context and no
other process has use FPU on this core.

ok kettenis@ deraadt@ Prior to a couple of fixes.


# 1.18 19-May-2021 kettenis

Get rid of the do-nothing cache setup code. The RISC-V architecture has
no architecturally defined caches (yet) so there is nothing to set up here.
Gets rid of some more useless XXX.


# 1.17 16-May-2021 kettenis

Sync memreg_add() implementation with arm64 and powerpc64.


# 1.16 14-May-2021 jsg

remove uneeded includes


# 1.15 13-May-2021 kettenis

Use intr_enable()/int_disable()/intr_restore() instead of
enable_interrupts()/disable_interrupts()/restore_interrupts() and remove
the latter interfaces.

ok mlarkin@, drahn@


# 1.14 12-May-2021 jsg

add OpenBSD rcs ids


# 1.13 11-May-2021 deraadt

more whitespace cleanups


# 1.12 11-May-2021 deraadt

whitespace cleanup


# 1.11 04-May-2021 kettenis

The clock on RISC-V is architectural, so we really don't need the
whole abstraction layer to support multiple timers. And we don't
really need a separate driver. Replace timer(4) with code based on
the powerpc64 implementation of the randomized statclock code.

Fixes hangs seen on real hardware.

ok jsg@, drahn@


# 1.10 04-May-2021 jsg

Check that fdt hart id matches boot hart id before associating an fdt
node with the primary cpu.

Prompted by the polarfire icicle where hart 0 is an mmuless e51 core.

ok drahn@ mlarkin@


# 1.9 03-May-2021 kettenis

Use the EFI memory map (if available) to determine available physical
memory. This brings the code closer to arm64 but some key differences
remain. The most notable difference is that the riscv64 currently uses
its own private direct map of physical memory. Therefore it needs to know
the RAM address range which we derive from the /memory node in the FDT.

The code also needs to work around some bugs/flaws in the firmware:

* Newer OpenSBI versions no longer add a "no-map" property to the
reserved memory block that covers the memory used by OpenSBI itself.
This makes it appear as EfiBootServicesData in the EFI memory map,
which means it is available for general use.

* The OpenSBI shipped with the beaglev prototype boards doesn't reserve
the memory used by OpenBSI at all.

The workaround for the first issue is to remove all reserved memory blocks
specified in the FDT. In its current implementation this may remove
too much memory on certain boards.

The workaround for the second issue is to remove 2MB before the memory
where the kernel lives. This workaround is fragile since it relies on
a specific memory layout. Hopefully the beaglev firmware gets fixed and
we can remove this hack.

ok jsg@


# 1.8 03-May-2021 jsg

change some commented vfp paths to riscv64 fpu equivalents

ok mlarkin@


# 1.7 02-May-2021 kettenis

Initialize the per-CPU pointer register early.

ok drahn@


# 1.6 02-May-2021 jsg

fix logic error in boot()
ok deraadt@


# 1.5 01-May-2021 kettenis

Implement early console functionality based on available SBI calls.

While these calls are part of the legacy extensions and deprecated, they
are really useful for debugging purposes.

ok jsg@


# 1.4 30-Apr-2021 jsg

reduce diff to current arm64

ok mlarkin@


# 1.3 30-Apr-2021 jsg

remove commented arm console init lines


# 1.2 23-Apr-2021 jsg

spelling


# 1.1 23-Apr-2021 drahn

Initial import of OpenBSD/riscv64

This work is based on the effort:
https://www.openbsd.org/papers/Porting_OpenBSD_to_RISCV_FinalReport.pdf
"Porting OpenBSD to RISC-V ISA"
by
Brian Bamsch <bbamsch@google.com>
Wenyan He <wenyan.he@sjsu.edu>
Mars Li <mengshi.li.mars@gmail.com>
Shivam Waghela <shivamwaghela@gmail.com>

With additional work by Dale Rahn <drahn@openbsd.org>


# 1.20 13-Jun-2021 kettenis

Add support for sfuart(4) as a console.

ok drahn@


# 1.19 20-May-2021 drahn

Significant overhaul of the floating point save/restore code.
At this point the mechanism should closely resemble the powerpc64
save/restore points with one difference. (reload avoidance)
The previous 'aggressive' fpu save code that was (mostly) implemented before
and is present on arm32 and arm64.

There is one piece from that other design that remains, if
pcb->pcb_fpcpu == ci && ci->ci_fpuproc == p
after sleep, this will automatically re-activate the FPU state without
needing to reload it.
To enable this, the pointer pair is not changed on FPU context save
to indicate that the CPU still holds the valid content as long as both
of those pointers are pointing to each other.
Note that if another core steals the FPU conxtex (when we get to SMP)
the pcb->pcb_fpcpu will be another cpu, and from that it will know
to reload the FPU context. Also optimistically enabling this only makes
sense on riscv64 because there is the notion of FPU on and clean. Other
implimentations would need to 'fault on' the FPU enable, but could avoid
the FPU context load if no other processor has run this FPU context and no
other process has use FPU on this core.

ok kettenis@ deraadt@ Prior to a couple of fixes.


# 1.18 19-May-2021 kettenis

Get rid of the do-nothing cache setup code. The RISC-V architecture has
no architecturally defined caches (yet) so there is nothing to set up here.
Gets rid of some more useless XXX.


# 1.17 16-May-2021 kettenis

Sync memreg_add() implementation with arm64 and powerpc64.


# 1.16 14-May-2021 jsg

remove uneeded includes


# 1.15 13-May-2021 kettenis

Use intr_enable()/int_disable()/intr_restore() instead of
enable_interrupts()/disable_interrupts()/restore_interrupts() and remove
the latter interfaces.

ok mlarkin@, drahn@


# 1.14 12-May-2021 jsg

add OpenBSD rcs ids


# 1.13 11-May-2021 deraadt

more whitespace cleanups


# 1.12 11-May-2021 deraadt

whitespace cleanup


# 1.11 04-May-2021 kettenis

The clock on RISC-V is architectural, so we really don't need the
whole abstraction layer to support multiple timers. And we don't
really need a separate driver. Replace timer(4) with code based on
the powerpc64 implementation of the randomized statclock code.

Fixes hangs seen on real hardware.

ok jsg@, drahn@


# 1.10 04-May-2021 jsg

Check that fdt hart id matches boot hart id before associating an fdt
node with the primary cpu.

Prompted by the polarfire icicle where hart 0 is an mmuless e51 core.

ok drahn@ mlarkin@


# 1.9 03-May-2021 kettenis

Use the EFI memory map (if available) to determine available physical
memory. This brings the code closer to arm64 but some key differences
remain. The most notable difference is that the riscv64 currently uses
its own private direct map of physical memory. Therefore it needs to know
the RAM address range which we derive from the /memory node in the FDT.

The code also needs to work around some bugs/flaws in the firmware:

* Newer OpenSBI versions no longer add a "no-map" property to the
reserved memory block that covers the memory used by OpenSBI itself.
This makes it appear as EfiBootServicesData in the EFI memory map,
which means it is available for general use.

* The OpenSBI shipped with the beaglev prototype boards doesn't reserve
the memory used by OpenBSI at all.

The workaround for the first issue is to remove all reserved memory blocks
specified in the FDT. In its current implementation this may remove
too much memory on certain boards.

The workaround for the second issue is to remove 2MB before the memory
where the kernel lives. This workaround is fragile since it relies on
a specific memory layout. Hopefully the beaglev firmware gets fixed and
we can remove this hack.

ok jsg@


# 1.8 03-May-2021 jsg

change some commented vfp paths to riscv64 fpu equivalents

ok mlarkin@


# 1.7 02-May-2021 kettenis

Initialize the per-CPU pointer register early.

ok drahn@


# 1.6 02-May-2021 jsg

fix logic error in boot()
ok deraadt@


# 1.5 01-May-2021 kettenis

Implement early console functionality based on available SBI calls.

While these calls are part of the legacy extensions and deprecated, they
are really useful for debugging purposes.

ok jsg@


# 1.4 30-Apr-2021 jsg

reduce diff to current arm64

ok mlarkin@


# 1.3 30-Apr-2021 jsg

remove commented arm console init lines


# 1.2 23-Apr-2021 jsg

spelling


# 1.1 23-Apr-2021 drahn

Initial import of OpenBSD/riscv64

This work is based on the effort:
https://www.openbsd.org/papers/Porting_OpenBSD_to_RISCV_FinalReport.pdf
"Porting OpenBSD to RISC-V ISA"
by
Brian Bamsch <bbamsch@google.com>
Wenyan He <wenyan.he@sjsu.edu>
Mars Li <mengshi.li.mars@gmail.com>
Shivam Waghela <shivamwaghela@gmail.com>

With additional work by Dale Rahn <drahn@openbsd.org>


# 1.19 20-May-2021 drahn

Significant overhaul of the floating point save/restore code.
At this point the mechanism should closely resemble the powerpc64
save/restore points with one difference. (reload avoidance)
The previous 'aggressive' fpu save code that was (mostly) implemented before
and is present on arm32 and arm64.

There is one piece from that other design that remains, if
pcb->pcb_fpcpu == ci && ci->ci_fpuproc == p
after sleep, this will automatically re-activate the FPU state without
needing to reload it.
To enable this, the pointer pair is not changed on FPU context save
to indicate that the CPU still holds the valid content as long as both
of those pointers are pointing to each other.
Note that if another core steals the FPU conxtex (when we get to SMP)
the pcb->pcb_fpcpu will be another cpu, and from that it will know
to reload the FPU context. Also optimistically enabling this only makes
sense on riscv64 because there is the notion of FPU on and clean. Other
implimentations would need to 'fault on' the FPU enable, but could avoid
the FPU context load if no other processor has run this FPU context and no
other process has use FPU on this core.

ok kettenis@ deraadt@ Prior to a couple of fixes.


# 1.18 19-May-2021 kettenis

Get rid of the do-nothing cache setup code. The RISC-V architecture has
no architecturally defined caches (yet) so there is nothing to set up here.
Gets rid of some more useless XXX.


# 1.17 16-May-2021 kettenis

Sync memreg_add() implementation with arm64 and powerpc64.


# 1.16 14-May-2021 jsg

remove uneeded includes


# 1.15 13-May-2021 kettenis

Use intr_enable()/int_disable()/intr_restore() instead of
enable_interrupts()/disable_interrupts()/restore_interrupts() and remove
the latter interfaces.

ok mlarkin@, drahn@


# 1.14 12-May-2021 jsg

add OpenBSD rcs ids


# 1.13 11-May-2021 deraadt

more whitespace cleanups


# 1.12 11-May-2021 deraadt

whitespace cleanup


# 1.11 04-May-2021 kettenis

The clock on RISC-V is architectural, so we really don't need the
whole abstraction layer to support multiple timers. And we don't
really need a separate driver. Replace timer(4) with code based on
the powerpc64 implementation of the randomized statclock code.

Fixes hangs seen on real hardware.

ok jsg@, drahn@


# 1.10 04-May-2021 jsg

Check that fdt hart id matches boot hart id before associating an fdt
node with the primary cpu.

Prompted by the polarfire icicle where hart 0 is an mmuless e51 core.

ok drahn@ mlarkin@


# 1.9 03-May-2021 kettenis

Use the EFI memory map (if available) to determine available physical
memory. This brings the code closer to arm64 but some key differences
remain. The most notable difference is that the riscv64 currently uses
its own private direct map of physical memory. Therefore it needs to know
the RAM address range which we derive from the /memory node in the FDT.

The code also needs to work around some bugs/flaws in the firmware:

* Newer OpenSBI versions no longer add a "no-map" property to the
reserved memory block that covers the memory used by OpenSBI itself.
This makes it appear as EfiBootServicesData in the EFI memory map,
which means it is available for general use.

* The OpenSBI shipped with the beaglev prototype boards doesn't reserve
the memory used by OpenBSI at all.

The workaround for the first issue is to remove all reserved memory blocks
specified in the FDT. In its current implementation this may remove
too much memory on certain boards.

The workaround for the second issue is to remove 2MB before the memory
where the kernel lives. This workaround is fragile since it relies on
a specific memory layout. Hopefully the beaglev firmware gets fixed and
we can remove this hack.

ok jsg@


# 1.8 03-May-2021 jsg

change some commented vfp paths to riscv64 fpu equivalents

ok mlarkin@


# 1.7 02-May-2021 kettenis

Initialize the per-CPU pointer register early.

ok drahn@


# 1.6 02-May-2021 jsg

fix logic error in boot()
ok deraadt@


# 1.5 01-May-2021 kettenis

Implement early console functionality based on available SBI calls.

While these calls are part of the legacy extensions and deprecated, they
are really useful for debugging purposes.

ok jsg@


# 1.4 30-Apr-2021 jsg

reduce diff to current arm64

ok mlarkin@


# 1.3 30-Apr-2021 jsg

remove commented arm console init lines


# 1.2 23-Apr-2021 jsg

spelling


# 1.1 23-Apr-2021 drahn

Initial import of OpenBSD/riscv64

This work is based on the effort:
https://www.openbsd.org/papers/Porting_OpenBSD_to_RISCV_FinalReport.pdf
"Porting OpenBSD to RISC-V ISA"
by
Brian Bamsch <bbamsch@google.com>
Wenyan He <wenyan.he@sjsu.edu>
Mars Li <mengshi.li.mars@gmail.com>
Shivam Waghela <shivamwaghela@gmail.com>

With additional work by Dale Rahn <drahn@openbsd.org>


# 1.17 16-May-2021 kettenis

Sync memreg_add() implementation with arm64 and powerpc64.


# 1.16 14-May-2021 jsg

remove uneeded includes


# 1.15 13-May-2021 kettenis

Use intr_enable()/int_disable()/intr_restore() instead of
enable_interrupts()/disable_interrupts()/restore_interrupts() and remove
the latter interfaces.

ok mlarkin@, drahn@


# 1.14 12-May-2021 jsg

add OpenBSD rcs ids


# 1.13 11-May-2021 deraadt

more whitespace cleanups


# 1.12 11-May-2021 deraadt

whitespace cleanup


# 1.11 04-May-2021 kettenis

The clock on RISC-V is architectural, so we really don't need the
whole abstraction layer to support multiple timers. And we don't
really need a separate driver. Replace timer(4) with code based on
the powerpc64 implementation of the randomized statclock code.

Fixes hangs seen on real hardware.

ok jsg@, drahn@


# 1.10 04-May-2021 jsg

Check that fdt hart id matches boot hart id before associating an fdt
node with the primary cpu.

Prompted by the polarfire icicle where hart 0 is an mmuless e51 core.

ok drahn@ mlarkin@


# 1.9 03-May-2021 kettenis

Use the EFI memory map (if available) to determine available physical
memory. This brings the code closer to arm64 but some key differences
remain. The most notable difference is that the riscv64 currently uses
its own private direct map of physical memory. Therefore it needs to know
the RAM address range which we derive from the /memory node in the FDT.

The code also needs to work around some bugs/flaws in the firmware:

* Newer OpenSBI versions no longer add a "no-map" property to the
reserved memory block that covers the memory used by OpenSBI itself.
This makes it appear as EfiBootServicesData in the EFI memory map,
which means it is available for general use.

* The OpenSBI shipped with the beaglev prototype boards doesn't reserve
the memory used by OpenBSI at all.

The workaround for the first issue is to remove all reserved memory blocks
specified in the FDT. In its current implementation this may remove
too much memory on certain boards.

The workaround for the second issue is to remove 2MB before the memory
where the kernel lives. This workaround is fragile since it relies on
a specific memory layout. Hopefully the beaglev firmware gets fixed and
we can remove this hack.

ok jsg@


# 1.8 03-May-2021 jsg

change some commented vfp paths to riscv64 fpu equivalents

ok mlarkin@


# 1.7 02-May-2021 kettenis

Initialize the per-CPU pointer register early.

ok drahn@


# 1.6 02-May-2021 jsg

fix logic error in boot()
ok deraadt@


# 1.5 01-May-2021 kettenis

Implement early console functionality based on available SBI calls.

While these calls are part of the legacy extensions and deprecated, they
are really useful for debugging purposes.

ok jsg@


# 1.4 30-Apr-2021 jsg

reduce diff to current arm64

ok mlarkin@


# 1.3 30-Apr-2021 jsg

remove commented arm console init lines


# 1.2 23-Apr-2021 jsg

spelling


# 1.1 23-Apr-2021 drahn

Initial import of OpenBSD/riscv64

This work is based on the effort:
https://www.openbsd.org/papers/Porting_OpenBSD_to_RISCV_FinalReport.pdf
"Porting OpenBSD to RISC-V ISA"
by
Brian Bamsch <bbamsch@google.com>
Wenyan He <wenyan.he@sjsu.edu>
Mars Li <mengshi.li.mars@gmail.com>
Shivam Waghela <shivamwaghela@gmail.com>

With additional work by Dale Rahn <drahn@openbsd.org>


# 1.16 14-May-2021 jsg

remove uneeded includes


# 1.15 13-May-2021 kettenis

Use intr_enable()/int_disable()/intr_restore() instead of
enable_interrupts()/disable_interrupts()/restore_interrupts() and remove
the latter interfaces.

ok mlarkin@, drahn@


# 1.14 12-May-2021 jsg

add OpenBSD rcs ids


# 1.13 11-May-2021 deraadt

more whitespace cleanups


# 1.12 11-May-2021 deraadt

whitespace cleanup


# 1.11 04-May-2021 kettenis

The clock on RISC-V is architectural, so we really don't need the
whole abstraction layer to support multiple timers. And we don't
really need a separate driver. Replace timer(4) with code based on
the powerpc64 implementation of the randomized statclock code.

Fixes hangs seen on real hardware.

ok jsg@, drahn@


# 1.10 04-May-2021 jsg

Check that fdt hart id matches boot hart id before associating an fdt
node with the primary cpu.

Prompted by the polarfire icicle where hart 0 is an mmuless e51 core.

ok drahn@ mlarkin@


# 1.9 03-May-2021 kettenis

Use the EFI memory map (if available) to determine available physical
memory. This brings the code closer to arm64 but some key differences
remain. The most notable difference is that the riscv64 currently uses
its own private direct map of physical memory. Therefore it needs to know
the RAM address range which we derive from the /memory node in the FDT.

The code also needs to work around some bugs/flaws in the firmware:

* Newer OpenSBI versions no longer add a "no-map" property to the
reserved memory block that covers the memory used by OpenSBI itself.
This makes it appear as EfiBootServicesData in the EFI memory map,
which means it is available for general use.

* The OpenSBI shipped with the beaglev prototype boards doesn't reserve
the memory used by OpenBSI at all.

The workaround for the first issue is to remove all reserved memory blocks
specified in the FDT. In its current implementation this may remove
too much memory on certain boards.

The workaround for the second issue is to remove 2MB before the memory
where the kernel lives. This workaround is fragile since it relies on
a specific memory layout. Hopefully the beaglev firmware gets fixed and
we can remove this hack.

ok jsg@


# 1.8 03-May-2021 jsg

change some commented vfp paths to riscv64 fpu equivalents

ok mlarkin@


# 1.7 02-May-2021 kettenis

Initialize the per-CPU pointer register early.

ok drahn@


# 1.6 02-May-2021 jsg

fix logic error in boot()
ok deraadt@


# 1.5 01-May-2021 kettenis

Implement early console functionality based on available SBI calls.

While these calls are part of the legacy extensions and deprecated, they
are really useful for debugging purposes.

ok jsg@


# 1.4 30-Apr-2021 jsg

reduce diff to current arm64

ok mlarkin@


# 1.3 30-Apr-2021 jsg

remove commented arm console init lines


# 1.2 23-Apr-2021 jsg

spelling


# 1.1 23-Apr-2021 drahn

Initial import of OpenBSD/riscv64

This work is based on the effort:
https://www.openbsd.org/papers/Porting_OpenBSD_to_RISCV_FinalReport.pdf
"Porting OpenBSD to RISC-V ISA"
by
Brian Bamsch <bbamsch@google.com>
Wenyan He <wenyan.he@sjsu.edu>
Mars Li <mengshi.li.mars@gmail.com>
Shivam Waghela <shivamwaghela@gmail.com>

With additional work by Dale Rahn <drahn@openbsd.org>


# 1.14 12-May-2021 jsg

add OpenBSD rcs ids


# 1.13 11-May-2021 deraadt

more whitespace cleanups


# 1.12 11-May-2021 deraadt

whitespace cleanup


# 1.11 04-May-2021 kettenis

The clock on RISC-V is architectural, so we really don't need the
whole abstraction layer to support multiple timers. And we don't
really need a separate driver. Replace timer(4) with code based on
the powerpc64 implementation of the randomized statclock code.

Fixes hangs seen on real hardware.

ok jsg@, drahn@


# 1.10 04-May-2021 jsg

Check that fdt hart id matches boot hart id before associating an fdt
node with the primary cpu.

Prompted by the polarfire icicle where hart 0 is an mmuless e51 core.

ok drahn@ mlarkin@


# 1.9 03-May-2021 kettenis

Use the EFI memory map (if available) to determine available physical
memory. This brings the code closer to arm64 but some key differences
remain. The most notable difference is that the riscv64 currently uses
its own private direct map of physical memory. Therefore it needs to know
the RAM address range which we derive from the /memory node in the FDT.

The code also needs to work around some bugs/flaws in the firmware:

* Newer OpenSBI versions no longer add a "no-map" property to the
reserved memory block that covers the memory used by OpenSBI itself.
This makes it appear as EfiBootServicesData in the EFI memory map,
which means it is available for general use.

* The OpenSBI shipped with the beaglev prototype boards doesn't reserve
the memory used by OpenBSI at all.

The workaround for the first issue is to remove all reserved memory blocks
specified in the FDT. In its current implementation this may remove
too much memory on certain boards.

The workaround for the second issue is to remove 2MB before the memory
where the kernel lives. This workaround is fragile since it relies on
a specific memory layout. Hopefully the beaglev firmware gets fixed and
we can remove this hack.

ok jsg@


# 1.8 03-May-2021 jsg

change some commented vfp paths to riscv64 fpu equivalents

ok mlarkin@


# 1.7 02-May-2021 kettenis

Initialize the per-CPU pointer register early.

ok drahn@


# 1.6 02-May-2021 jsg

fix logic error in boot()
ok deraadt@


# 1.5 01-May-2021 kettenis

Implement early console functionality based on available SBI calls.

While these calls are part of the legacy extensions and deprecated, they
are really useful for debugging purposes.

ok jsg@


# 1.4 30-Apr-2021 jsg

reduce diff to current arm64

ok mlarkin@


# 1.3 30-Apr-2021 jsg

remove commented arm console init lines


# 1.2 23-Apr-2021 jsg

spelling


# 1.1 23-Apr-2021 drahn

Initial import of OpenBSD/riscv64

This work is based on the effort:
https://www.openbsd.org/papers/Porting_OpenBSD_to_RISCV_FinalReport.pdf
"Porting OpenBSD to RISC-V ISA"
by
Brian Bamsch <bbamsch@google.com>
Wenyan He <wenyan.he@sjsu.edu>
Mars Li <mengshi.li.mars@gmail.com>
Shivam Waghela <shivamwaghela@gmail.com>

With additional work by Dale Rahn <drahn@openbsd.org>


# 1.11 04-May-2021 kettenis

The clock on RISC-V is architectural, so we really don't need the
whole abstraction layer to support multiple timers. And we don't
really need a separate driver. Replace timer(4) with code based on
the powerpc64 implementation of the randomized statclock code.

Fixes hangs seen on real hardware.

ok jsg@, drahn@


# 1.10 04-May-2021 jsg

Check that fdt hart id matches boot hart id before associating an fdt
node with the primary cpu.

Prompted by the polarfire icicle where hart 0 is an mmuless e51 core.

ok drahn@ mlarkin@


# 1.9 03-May-2021 kettenis

Use the EFI memory map (if available) to determine available physical
memory. This brings the code closer to arm64 but some key differences
remain. The most notable difference is that the riscv64 currently uses
its own private direct map of physical memory. Therefore it needs to know
the RAM address range which we derive from the /memory node in the FDT.

The code also needs to work around some bugs/flaws in the firmware:

* Newer OpenSBI versions no longer add a "no-map" property to the
reserved memory block that covers the memory used by OpenSBI itself.
This makes it appear as EfiBootServicesData in the EFI memory map,
which means it is available for general use.

* The OpenSBI shipped with the beaglev prototype boards doesn't reserve
the memory used by OpenBSI at all.

The workaround for the first issue is to remove all reserved memory blocks
specified in the FDT. In its current implementation this may remove
too much memory on certain boards.

The workaround for the second issue is to remove 2MB before the memory
where the kernel lives. This workaround is fragile since it relies on
a specific memory layout. Hopefully the beaglev firmware gets fixed and
we can remove this hack.

ok jsg@


# 1.8 03-May-2021 jsg

change some commented vfp paths to riscv64 fpu equivalents

ok mlarkin@


# 1.7 02-May-2021 kettenis

Initialize the per-CPU pointer register early.

ok drahn@


# 1.6 02-May-2021 jsg

fix logic error in boot()
ok deraadt@


# 1.5 01-May-2021 kettenis

Implement early console functionality based on available SBI calls.

While these calls are part of the legacy extensions and deprecated, they
are really useful for debugging purposes.

ok jsg@


# 1.4 30-Apr-2021 jsg

reduce diff to current arm64

ok mlarkin@


# 1.3 30-Apr-2021 jsg

remove commented arm console init lines


# 1.2 23-Apr-2021 jsg

spelling


# 1.1 23-Apr-2021 drahn

Initial import of OpenBSD/riscv64

This work is based on the effort:
https://www.openbsd.org/papers/Porting_OpenBSD_to_RISCV_FinalReport.pdf
"Porting OpenBSD to RISC-V ISA"
by
Brian Bamsch <bbamsch@google.com>
Wenyan He <wenyan.he@sjsu.edu>
Mars Li <mengshi.li.mars@gmail.com>
Shivam Waghela <shivamwaghela@gmail.com>

With additional work by Dale Rahn <drahn@openbsd.org>


# 1.10 04-May-2021 jsg

Check that fdt hart id matches boot hart id before associating an fdt
node with the primary cpu.

Prompted by the polarfire icicle where hart 0 is an mmuless e51 core.

ok drahn@ mlarkin@


# 1.9 03-May-2021 kettenis

Use the EFI memory map (if available) to determine available physical
memory. This brings the code closer to arm64 but some key differences
remain. The most notable difference is that the riscv64 currently uses
its own private direct map of physical memory. Therefore it needs to know
the RAM address range which we derive from the /memory node in the FDT.

The code also needs to work around some bugs/flaws in the firmware:

* Newer OpenSBI versions no longer add a "no-map" property to the
reserved memory block that covers the memory used by OpenSBI itself.
This makes it appear as EfiBootServicesData in the EFI memory map,
which means it is available for general use.

* The OpenSBI shipped with the beaglev prototype boards doesn't reserve
the memory used by OpenBSI at all.

The workaround for the first issue is to remove all reserved memory blocks
specified in the FDT. In its current implementation this may remove
too much memory on certain boards.

The workaround for the second issue is to remove 2MB before the memory
where the kernel lives. This workaround is fragile since it relies on
a specific memory layout. Hopefully the beaglev firmware gets fixed and
we can remove this hack.

ok jsg@


# 1.8 03-May-2021 jsg

change some commented vfp paths to riscv64 fpu equivalents

ok mlarkin@


# 1.7 02-May-2021 kettenis

Initialize the per-CPU pointer register early.

ok drahn@


# 1.6 02-May-2021 jsg

fix logic error in boot()
ok deraadt@


# 1.5 01-May-2021 kettenis

Implement early console functionality based on available SBI calls.

While these calls are part of the legacy extensions and deprecated, they
are really useful for debugging purposes.

ok jsg@


# 1.4 30-Apr-2021 jsg

reduce diff to current arm64

ok mlarkin@


# 1.3 30-Apr-2021 jsg

remove commented arm console init lines


# 1.2 23-Apr-2021 jsg

spelling


# 1.1 23-Apr-2021 drahn

Initial import of OpenBSD/riscv64

This work is based on the effort:
https://www.openbsd.org/papers/Porting_OpenBSD_to_RISCV_FinalReport.pdf
"Porting OpenBSD to RISC-V ISA"
by
Brian Bamsch <bbamsch@google.com>
Wenyan He <wenyan.he@sjsu.edu>
Mars Li <mengshi.li.mars@gmail.com>
Shivam Waghela <shivamwaghela@gmail.com>

With additional work by Dale Rahn <drahn@openbsd.org>


# 1.9 03-May-2021 kettenis

Use the EFI memory map (if available) to determine available physical
memory. This brings the code closer to arm64 but some key differences
remain. The most notable difference is that the riscv64 currently uses
its own private direct map of physical memory. Therefore it needs to know
the RAM address range which we derive from the /memory node in the FDT.

The code also needs to work around some bugs/flaws in the firmware:

* Newer OpenSBI versions no longer add a "no-map" property to the
reserved memory block that covers the memory used by OpenSBI itself.
This makes it appear as EfiBootServicesData in the EFI memory map,
which means it is available for general use.

* The OpenSBI shipped with the beaglev prototype boards doesn't reserve
the memory used by OpenBSI at all.

The workaround for the first issue is to remove all reserved memory blocks
specified in the FDT. In its current implementation this may remove
too much memory on certain boards.

The workaround for the second issue is to remove 2MB before the memory
where the kernel lives. This workaround is fragile since it relies on
a specific memory layout. Hopefully the beaglev firmware gets fixed and
we can remove this hack.

ok jsg@


# 1.8 03-May-2021 jsg

change some commented vfp paths to riscv64 fpu equivalents

ok mlarkin@


# 1.7 02-May-2021 kettenis

Initialize the per-CPU pointer register early.

ok drahn@


# 1.6 02-May-2021 jsg

fix logic error in boot()
ok deraadt@


# 1.5 01-May-2021 kettenis

Implement early console functionality based on available SBI calls.

While these calls are part of the legacy extensions and deprecated, they
are really useful for debugging purposes.

ok jsg@


# 1.4 30-Apr-2021 jsg

reduce diff to current arm64

ok mlarkin@


# 1.3 30-Apr-2021 jsg

remove commented arm console init lines


# 1.2 23-Apr-2021 jsg

spelling


# 1.1 23-Apr-2021 drahn

Initial import of OpenBSD/riscv64

This work is based on the effort:
https://www.openbsd.org/papers/Porting_OpenBSD_to_RISCV_FinalReport.pdf
"Porting OpenBSD to RISC-V ISA"
by
Brian Bamsch <bbamsch@google.com>
Wenyan He <wenyan.he@sjsu.edu>
Mars Li <mengshi.li.mars@gmail.com>
Shivam Waghela <shivamwaghela@gmail.com>

With additional work by Dale Rahn <drahn@openbsd.org>


# 1.7 02-May-2021 kettenis

Initialize the per-CPU pointer register early.

ok drahn@


# 1.6 02-May-2021 jsg

fix logic error in boot()
ok deraadt@


# 1.5 01-May-2021 kettenis

Implement early console functionality based on available SBI calls.

While these calls are part of the legacy extensions and deprecated, they
are really useful for debugging purposes.

ok jsg@


# 1.4 30-Apr-2021 jsg

reduce diff to current arm64

ok mlarkin@


# 1.3 30-Apr-2021 jsg

remove commented arm console init lines


# 1.2 23-Apr-2021 jsg

spelling


# 1.1 23-Apr-2021 drahn

Initial import of OpenBSD/riscv64

This work is based on the effort:
https://www.openbsd.org/papers/Porting_OpenBSD_to_RISCV_FinalReport.pdf
"Porting OpenBSD to RISC-V ISA"
by
Brian Bamsch <bbamsch@google.com>
Wenyan He <wenyan.he@sjsu.edu>
Mars Li <mengshi.li.mars@gmail.com>
Shivam Waghela <shivamwaghela@gmail.com>

With additional work by Dale Rahn <drahn@openbsd.org>


# 1.4 30-Apr-2021 jsg

reduce diff to current arm64

ok mlarkin@


# 1.3 30-Apr-2021 jsg

remove commented arm console init lines


# 1.2 23-Apr-2021 jsg

spelling


# 1.1 23-Apr-2021 drahn

Initial import of OpenBSD/riscv64

This work is based on the effort:
https://www.openbsd.org/papers/Porting_OpenBSD_to_RISCV_FinalReport.pdf
"Porting OpenBSD to RISC-V ISA"
by
Brian Bamsch <bbamsch@google.com>
Wenyan He <wenyan.he@sjsu.edu>
Mars Li <mengshi.li.mars@gmail.com>
Shivam Waghela <shivamwaghela@gmail.com>

With additional work by Dale Rahn <drahn@openbsd.org>


# 1.2 23-Apr-2021 jsg

spelling


# 1.1 23-Apr-2021 drahn

Initial import of OpenBSD/riscv64

This work is based on the effort:
https://www.openbsd.org/papers/Porting_OpenBSD_to_RISCV_FinalReport.pdf
"Porting OpenBSD to RISC-V ISA"
by
Brian Bamsch <bbamsch@google.com>
Wenyan He <wenyan.he@sjsu.edu>
Mars Li <mengshi.li.mars@gmail.com>
Shivam Waghela <shivamwaghela@gmail.com>

With additional work by Dale Rahn <drahn@openbsd.org>