Commit Graph

18 Commits

Author SHA1 Message Date
Martin Whitaker
f16be176ed Fix triple-fault when starting APs with program loaded above 16MB (issue #63).
In a .code16 section, the default coding for the lgdt instruction only loads
a 24 bit base address from the GDT descriptor. When loaded above 16MB, we
need it to load the full 32 bits.
2022-05-15 12:18:07 +01:00
Martin Whitaker
4078b7760e Faster barrier implementation.
The old barrier implementation was very slow when running on a multi-socket
machine (pcmemtest issue 16).

The new implementation provides two options:

  - when blocked, spin on a thread-local flag
  - when blocked, execute a HLT instruction and wait for a NMI

The first option might be faster, but we need to measure it to find out. A
new boot command line option is provided to select between the two, with a
third setting that uses a mixture of the two.
2022-02-28 22:05:21 +00:00
Martin Whitaker
99e258457b Use je/jne instead of jz/jnz when testing boolean variables in startup code.
Just for readability - they are aliases for the same instructions.
2022-02-12 09:39:18 +00:00
Martin Whitaker
39d5715224 Fix interrupt handling when long mode is enabled in a 32-bit binary (part 2).
Handle passing the processor state to the application interrupt handler.
Update the 64-bit code to match the new trap state structure definition.
2022-02-12 09:39:09 +00:00
Martin Whitaker
e96fd7b99f Fix a few minor issues in the 64-bit startup code...
- the calculation of the RSP value when an interrupt occurred was
  out by 8 bytes
- in a few places a 32-bit pointer was used instead of a 64-bit one
- incorrect tabulation (white space)
2022-02-08 23:29:24 +00:00
Martin Whitaker
9769990679 Extend the use of the startup mutex to cover the entire startup code.
There is more in the startup code that isn't thread safe than just
the use of the temporary stack. So take the mutex for the whole time.
The code isn't that long, so it's not worth trying to cover just the
critical sections.
2022-02-05 18:03:32 +00:00
Martin Whitaker
e37fbbd429 Set stack alignment to 16 bytes.
This needs to be done in the ldscripts.
2022-02-02 18:23:23 +00:00
Martin Whitaker
7acb81e302 Fix assembler warning about unsized bts instruction. 2022-02-02 12:52:44 +00:00
Martin Whitaker
dcac527068 Don't make assumptions about usable memory.
When using a legacy BIOS, the memory regions used by the BIOS are well
defined. This is not the case when using a UEFI BIOS. So include the
stack area in the BSS so the loader knows how much memory to allocate,
and check we have space to relocate the program to either low or high
memory.

There are still some assumptions in the USB driver code that need to
be fixed.
2022-02-02 12:20:39 +00:00
Martin Whitaker
16d55b7dad Remove distinction between physical and virtual CPUs.
This is no longer needed, now we can display as many CPUs as we can
physically handle.
2022-01-31 22:59:14 +00:00
Martin Whitaker
4100a44b12 Properly protect the startup stack with a mutex.
Because we start the APs sequentially, it is unlikely they will coincide
for the brief period that they use the temporary startup stack, but we
should guard against it. This allows us to remove the mutex around the
restart of each AP when relocating, which should improve test times.
2022-01-31 21:54:24 +00:00
Martin Whitaker
fe4374e818 Allocate the main program stacks after the loaded program.
After we relocate the program, we restart it. So there is no need to copy
over the old stack contents. This allows us to increase the maximum number
of APs without a run time overhead. The maximum number of APs will still
be limited by the size of low memory.
2022-01-29 15:17:00 +00:00
Martin Whitaker
0aa1b1fa97 Rearrange stack space to reduce memory footprint.
The BSP only needs extra stack space during program initialisation. The APs
aren't running at that point, so by positioning the BSP stack above the AP
stacks, it can extend down into the AP stack space without causing any
problems.
2022-01-09 21:25:16 +00:00
Martin Whitaker
a454174f3f Fis startup stack address calculations. 2022-01-09 19:26:56 +00:00
Martin Whitaker
c089a81ed1 Add support for 32-bit EFI boot. 2020-07-08 11:07:32 +01:00
Martin Whitaker
c505472939 Support direct 64-bit EFI boot. 2020-07-03 22:42:45 +01:00
Martin Whitaker
a2110cb97f Add support for 64-bit EFI handover boot protocol. 2020-06-30 13:54:58 +01:00
Martin Whitaker
fbd3376668 Initial commit. 2020-05-24 21:30:55 +01:00