History log of /haiku/src/system/boot/platform/bios_ia32/cpu.cpp
Revision Date Author Comments
# bb2808d6 24-Oct-2023 Augustin Cavalier <waddlesplash@gmail.com>

bootloader: Implement TSC calibration via hypervisor CPUID leaf.

While debugging some problems on the HaikuPorts build VMs, mmlr
noticed their clocks had an alarming amount of drift. This prompted
an investigation into TSC calibration mechanisms, and the discovery
that there is a VM-specific one which we did not implement.

This mechanism is more accurate than counting cycles on VMs where
cycles can be "stolen" (the probable cause of the aforementioned
clock drift.)

Tested in VMware (works out of the box) and on QEMU/KVM
(may need TSC frequency specified or a host with invariant TSC.)

Change-Id: I4ccfdb2e4e2621404ec9026e7106c02bf96faf18
Reviewed-on: https://review.haiku-os.org/c/haiku/+/7063
Reviewed-by: waddlesplash <waddlesplash@gmail.com>


# 89fd39f4 01-Jul-2020 Alexander von Gluck IV <kallisti5@unixzen.com>

efi: Refactor CPU code to be arch-specific

* Migrate some platform agnostic architecture code into
boot/arch from efi/arch. This helps to avoid conflicts
between kernel and boot sources as well.
* Conflicts between arch_cpu in efi and kernel code means
bootcode really should *never* directly use kernel arch
headers. (other platforms don't, which is why they don't
have this same issue)
* We carefully thread any needed kernel headers (namely
assembly helper macros) into the bootloader headers without
mixing in the whole conflicting kernel/arch headers.
* ARM now properly get its cpu init code called, and we
progress further into the EFI bootloader.

Change-Id: If67ec9758b5ce68563ebd9eb45d5196401911c67
Reviewed-on: https://review.haiku-os.org/c/haiku/+/2975
Reviewed-by: waddlesplash <waddlesplash@gmail.com>


# 11f8b65a 20-Feb-2020 Jérôme Duval <jerome.duval@gmail.com>

boot_loader: load intel microcode update data file

Previous version of the patch was broken by the EFI refactoring.

Change-Id: I6dd125100b22b2461c531bfd8f81b3dd28e2b751
Reviewed-on: https://review.haiku-os.org/c/haiku/+/2409
Reviewed-by: Jérôme Duval <jerome.duval@gmail.com>


# 6f857fa9 23-Mar-2020 waddlesplash <waddlesplash@gmail.com>

Revert "boot_loader: load intel microcode update data file"

This reverts commit a7320593242cc0863fc909c1a32dbd255384d7dd.

It broke the build on most boot platforms (including EFI.)


# a7320593 20-Feb-2020 Jérôme Duval <jerome.duval@gmail.com>

boot_loader: load intel microcode update data file

Change-Id: I323a57cc0b1f05ad7b60b6a141d068a3e618ee4d
Reviewed-on: https://review.haiku-os.org/c/haiku/+/2263
Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>


# d2986cb6 21-Feb-2020 Alexander von Gluck IV <kallisti5@unixzen.com>

system/boot: More cleanup and shuffling

* arm efi additions
* cleanup some cpu headers which were oddly
split between efi and bios_ia32
* Move calculate_cpu_conversion_factor over to
arch_timer since it is timerish, and x86 only
* Drop some duplicated code from efi start. Move
hpet init code into efi timer/hpet code

Change-Id: Ia4264a5690ba8c09417b06788febc4f572f111ce
Reviewed-on: https://review.haiku-os.org/c/haiku/+/2259
Reviewed-by: Alex von Gluck IV <kallisti5@unixzen.com>
Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>


# 7b4d924f 04-Dec-2019 Andrej Antunovikj <tunas@cryptolab.net>

cpu: Extract shared x86 code from efi & bios_ia32

This issue was initially detected by PVS Studio (issue number V547) and fixed
as part of Google Code-in 2019.

The initial problem was the calculate_cpu_conversion_factor function
which had been copied in the BIOS and EFI versions of the boot code.
Further investigation led to more duplicated or very similar functions
being identified.

Introduce an arch_cpu.h for the x86 boot platform to group these things
in a single place, and adjust the BIOS and EFI code to call into that.
Note that the BIOS and EFI code is still a little platform specific,
ideally there should be a boot_arch_cpu_init() function for each
architecture as already done for openfirmware and u-boot.

Also remove some irrelevant comments from copypasted files for other
architectures, as that was filling my git grep with useless noise.

Change-Id: I16d815f0bf015cec0b4e03cc14f3cc447c7164c5
Reviewed-on: https://review.haiku-os.org/c/haiku/+/1985
Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>


# 4110b730 01-Oct-2013 Pawel Dziepak <pdziepak@quarnos.org>

x86[_64]: Add support for CPUID sub-leaves

Some CPUID leaves may contain one or more sub-leaves accessed by setting
ECX to an appropriate value.


# 2ae3d512 23-May-2011 Michael Lotz <mmlr@mlotz.ch>

Switch to using the PIT in mode 0 (interrupt on 0) instead of mode 2 (rate
generator). There are chipsets (namely ATI/AMD SBx00) where mode 2 doesn't seem
to work (the counter isn't reloaded after the countdown has completed). Mode 0
has the same resolution as mode 2 and, as interrupts are disabled at this point
in booting, is otherwise equivalent as well. I've tested this on 5 machines
available to me and it doesn't seem to have any negative effect.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@41683 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 7adc7269 23-May-2011 Michael Lotz <mmlr@mlotz.ch>

* Re-program the timer for each loop instead of waiting for it to wrap around.
With that we will usually start right away without having to wait for the
timer to be in the desired state, which removes roughly 116ms of spinning
around for a normal calibration run.
* Read back the value once after programming. The delay this introduces
accounts for the fact that the counter will only start counting down on the
next clock cycle.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@41680 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 2d62c17d 22-May-2011 Michael Lotz <mmlr@mlotz.ch>

* Add a limit to how often we retry the calibration. It's there as an upper
bound to prevent spinning forever if we have a very unstable TSC that we
simply can't calibrate. Shouldn't really happen though.
* Set the gate low for channel 2 on exit if we used it as the counter.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@41678 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 34d3f13c 23-May-2011 Michael Lotz <mmlr@mlotz.ch>

* Put the calibration loop into a static inline function and replace the three
copies of it with a call to that.
* Make the variable names more readable and spacing cleanup.

No functional change intended.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@41670 a95241bf-73f2-0310-859d-f6bbb57e9c96


# d6203034 23-May-2011 Michael Lotz <mmlr@mlotz.ch>

* Use macros to make the PIT programming more readable. Yes, I know that the PIT
timer code has such definitions too, but they're not quite as verbose. Will
eventually make the latter use these too.
* Prepare for possibly using other PIT channels for the calibration. Right now
everything's the same still.
* Add disabled print of the resulting factors.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@41669 a95241bf-73f2-0310-859d-f6bbb57e9c96


# db905187 07-Dec-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

Implemented a class uint128 with the basic arithmetic operations and
replaced the previous, somewhat complicated and inexact method of
computing the TSC conversion factor using it.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34542 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 1df628fe 01-Jan-2008 Michael Lotz <mmlr@mlotz.ch>

* Two more uses for the pause instruction I apparently forgot to commit
* Minor style cleanup in the conversion factor calculation

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23217 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 484c80ab 14-Dec-2005 Axel Dörfler <axeld@pinc-software.de>

* Added missing prototypes for get_eflags() and set_eflags() to arch_system_info.h
* The boot loader now checks the CPU for the cpuid and rdtsc features, which we
currently both rely on.
* Removed old and no longer used stage2_priv.h header


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15534 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 5af32e75 13-Apr-2005 Axel Dörfler <axeld@pinc-software.de>

Renamed src/kernel to src/system.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@12359 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 4110b730dbee59f5515a0bf9997b6cd167965080 01-Oct-2013 Pawel Dziepak <pdziepak@quarnos.org>

x86[_64]: Add support for CPUID sub-leaves

Some CPUID leaves may contain one or more sub-leaves accessed by setting
ECX to an appropriate value.


# 2ae3d5121c1f691cf1db3527847ac15ff33e40d1 23-May-2011 Michael Lotz <mmlr@mlotz.ch>

Switch to using the PIT in mode 0 (interrupt on 0) instead of mode 2 (rate
generator). There are chipsets (namely ATI/AMD SBx00) where mode 2 doesn't seem
to work (the counter isn't reloaded after the countdown has completed). Mode 0
has the same resolution as mode 2 and, as interrupts are disabled at this point
in booting, is otherwise equivalent as well. I've tested this on 5 machines
available to me and it doesn't seem to have any negative effect.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@41683 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 7adc7269d888ee01b7c6402944646971a774803b 23-May-2011 Michael Lotz <mmlr@mlotz.ch>

* Re-program the timer for each loop instead of waiting for it to wrap around.
With that we will usually start right away without having to wait for the
timer to be in the desired state, which removes roughly 116ms of spinning
around for a normal calibration run.
* Read back the value once after programming. The delay this introduces
accounts for the fact that the counter will only start counting down on the
next clock cycle.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@41680 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 2d62c17d268f91bca9c2093f7e127c133df44f9c 22-May-2011 Michael Lotz <mmlr@mlotz.ch>

* Add a limit to how often we retry the calibration. It's there as an upper
bound to prevent spinning forever if we have a very unstable TSC that we
simply can't calibrate. Shouldn't really happen though.
* Set the gate low for channel 2 on exit if we used it as the counter.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@41678 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 34d3f13c648d93a8f6fb5df78bf88015bdb1b89a 23-May-2011 Michael Lotz <mmlr@mlotz.ch>

* Put the calibration loop into a static inline function and replace the three
copies of it with a call to that.
* Make the variable names more readable and spacing cleanup.

No functional change intended.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@41670 a95241bf-73f2-0310-859d-f6bbb57e9c96


# d620303480adeb25846d516a74e57d2b1e52f3a4 23-May-2011 Michael Lotz <mmlr@mlotz.ch>

* Use macros to make the PIT programming more readable. Yes, I know that the PIT
timer code has such definitions too, but they're not quite as verbose. Will
eventually make the latter use these too.
* Prepare for possibly using other PIT channels for the calibration. Right now
everything's the same still.
* Add disabled print of the resulting factors.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@41669 a95241bf-73f2-0310-859d-f6bbb57e9c96


# db905187d5917eae9672bd2f14491dd565ca602c 07-Dec-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

Implemented a class uint128 with the basic arithmetic operations and
replaced the previous, somewhat complicated and inexact method of
computing the TSC conversion factor using it.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34542 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 1df628fe2f8bf6266adc7499f53d3ed3ed8a2edd 01-Jan-2008 Michael Lotz <mmlr@mlotz.ch>

* Two more uses for the pause instruction I apparently forgot to commit
* Minor style cleanup in the conversion factor calculation

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23217 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 484c80abd02ab7892be0963aad8c7d81641ed59e 14-Dec-2005 Axel Dörfler <axeld@pinc-software.de>

* Added missing prototypes for get_eflags() and set_eflags() to arch_system_info.h
* The boot loader now checks the CPU for the cpuid and rdtsc features, which we
currently both rely on.
* Removed old and no longer used stage2_priv.h header


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15534 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 5af32e752606778be5dd7379f319fe43cb3f6b8c 13-Apr-2005 Axel Dörfler <axeld@pinc-software.de>

Renamed src/kernel to src/system.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@12359 a95241bf-73f2-0310-859d-f6bbb57e9c96