aboutsummaryrefslogtreecommitdiff
path: root/src/stacks.c
AgeCommit message (Collapse)AuthorFilesLines
2021-06-09stacks: call check_irqs() after switch_next()Volker Rümelin1-3/+2
In function run_thread() the function check_irqs() gets called after the thread switch for atomic handoff reasons. In yield() it's the other way round. If check_irqs() is called after run_thread() and check_irqs() is called before switch_next() in yield(), it can happen in a constructed case that a background thread runs twice without a check_irqs() call in between. Call check_irqs() after switch_next() in yield() to prevent this. Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
2021-06-09stacks: call check_irqs() in run_thread()Volker Rümelin1-1/+7
The comment above the yield() function suggests that yield() allows interrupts for a short time. But yield() only briefly enables interrupts if seabios was built without CONFIG_THREADS or if yield() is called from the main thread. In order to guarantee that the interrupts were enabled once before yield() returns in a background thread, the main thread must call check_irqs() before or after every thread switch. The function run_thread() also switches threads, but the call to check_irqs() was forgotten. Add the missing check_irqs() call. This fixes PS/2 keyboard initialization failures. The code in src/hw/ps2port.c relies on yield() to briefly enable interrupts. There is a comment above the yield() function in __ps2_command(), where the author left a remark why the call to yield() is actually needed. Here is one of the call sequences leading to a PS/2 keyboard initialization failure. ps2_keyboard_setup() | ret = i8042_command(I8042_CMD_CTL_TEST, param); # This command will register an interrupt if the PS/2 device # controller raises interrupts for replies to a controller # command. | ret = ps2_kbd_command(ATKBD_CMD_RESET_BAT, param); | ps2_command(0, command, param); | ret = __ps2_command(aux, command, param); | // Flush any interrupts already pending. yield(); # yield() doesn't flush interrupts if the main thread # hasn't reached wait_threads(). | ret = ps2_sendbyte(aux, command, 1000); # Reset the PS/2 keyboard controller and wait for # PS2_RET_ACK. | ret = ps2_recvbyte(aux, 0, 4000); | for (;;) { | status = inb(PORT_PS2_STATUS); # I8042_STR_OBF isn't set because the keyboard self # test reply is still on wire. | yield(); # After a few yield()s the keyboard interrupt fires # and clears the I8042_STR_OBF status bit. If the # keyboard self test reply arrives before the # interrupt fires the keyboard reply is lost and # ps2_recvbyte() returns after the timeout. } Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
2017-06-12stacks: There is no need to disable NMI if it is already disabledKevin O'Connor1-4/+9
Don't write to the cmos index port on a mode switch if NMI is already disabled. This reduces the number of outb() calls. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-16stacks: Don't update the A20 settings if they haven't changedKevin O'Connor1-1/+3
The A20 setting is almost always enabled - only issue an outb() if the A20 is actually changing. This reduces the number of outb() calls. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-16stacks: Make sure to initialize Call16DataKevin O'Connor1-0/+1
Initialize the Call16Data at startup - otherwise some early yield() calls may check for interrupts without using the preferred A20 setting. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2015-10-15stacks: Use macro wrappers for call32() and stack_hop_back()Kevin O'Connor1-15/+10
The C code only uses _cfuncX_ prefixes for parameters to the call32(), stack_hop_back(), and call32_params() functions. It's simpler to use macro wrappers around those functions which provide the required prefix. This also changes the parameter order of stack_hop() and stack_hop_back() to use the more natural (func, params) ordering. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2015-10-09Always enable caching on transition32; backup/restore cr0 on call32Kevin O'Connor1-17/+28
Always enable caching at start of 32bit code and always make sure the paging flag is off. Because this alters the cr0 register, perform a backup and restore of it when using call32(). Also, rename get/setcr0() to cr0_read/write() to more closely match other register access functions. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2015-10-09Consolidate code16*() functionsKevin O'Connor1-34/+27
Introduce code16_override() for cases where call16() should not restore the previous 16bit state. All callers now use call16_back() to invoke 16bit code, so rename call16_back() to call16(). Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2015-09-14Use transition32_nmi_off from call32() and call16_back()Kevin O'Connor1-2/+2
The call32() and call16_back() functions will always disable NMI and enable a20 (via the call32_prep() function) so it is safe to use the _nmi_off variant of transition32. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2015-09-14Unify call32_sloppy() and call32()Kevin O'Connor1-18/+12
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2015-09-14Unify inline assembler in variants of call16 functionsKevin O'Connor1-68/+34
The assembler between call16(), call16big() and call16_sloppy() are very similar. Rework the functions so that a single version of the inline assembly can be used for all variants. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2015-09-14Rename Call32Data to Call16DataKevin O'Connor1-29/+29
The variable stores information on how and what to restore during a call to 16bit code, so Call16Data is a better name. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2015-09-14Unify smm/sloppy variants of call32_prep/post and call16_helperKevin O'Connor1-82/+50
The "smm" and "sloppy" variants of the 16bit to 32bit trampoline backup/restore code are very similar. They can be unified into a single copy of each function. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2015-09-03minor - correct spelling error in commentKevin O'Connor1-1/+1
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2015-08-24Add minimal support for machines without hardware interruptsKevin O'Connor1-1/+4
Some Chromebooks (with Baytrail CPUs) apparently do not support routing of legacy interrupts. This patch adds minimal support for running SeaBIOS in such an environment. Even with this patch, it is known that old operating systems and even some recent bootloaders will not function without real hardware interrupts. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2015-08-17rtc: Support disabling the RTC timer irq supportKevin O'Connor1-1/+1
Add a build time config option to remove support for RTC timer interrupts along with the associated bios calls requiring that support. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2015-08-17Call cpu_relax() if yielding prior to interrupts being enabledKevin O'Connor1-1/+3
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2015-08-17Move CanInterrupt check to check_irqs()Kevin O'Connor1-7/+8
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2015-07-14Don't enable interrupts prior to IVT and PIC setupKevin O'Connor1-5/+8
The machine may crash if an interrupt occurs prior to the setup of the interrupt vector table (IVT) and programmable interrupt controller (PIC). This patch makes sure that interrupts remain disabled until these components are setup. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2014-12-03Eliminate FUNCFSEG - only force portions of inline asm to f-segmentKevin O'Connor1-6/+6
The FUNCFSEG macro was introduced to force a C function into the f-segment. This was needed for some C functions that used inline assembler that contained some 16bit code. Instead of forcing the entire C function into the f-segment, just force the small subset of inline assembler into the f-segment. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2014-12-03Use macros for .code16/32 mode switches in inline asm in stacks.cKevin O'Connor1-12/+17
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2014-11-12Fix build issue on gcc34Kevin O'Connor1-1/+1
Older versions of gcc may not inline on_extra_stack() and thus cause a link error when compiling in 32bit segmented mode. Test for MODE16 explicitly in stack_hop_back() to prevent the problem. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2014-10-15Backup and restore a20 on call32_sloppy()Kevin O'Connor1-0/+7
Previously, the a20 line would always be enabled and left on after call32_sloppy(). The setting should really be backed up and restored on each call. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2014-10-15Implement call32 mechanism using SMIs.Kevin O'Connor1-0/+138
Add support for jumping into 32bit mode using a System Management Mode (SMM) handler. When available, this allows SeaBIOS to transition to 32bit mode even when called in vm86 mode. It will also prevent the clobbering of the segment registers. Currently, the SMM mode is only supported in QEMU when running in TCG mode. Also, QEMU v2.1 (or later) is needed for it to work when in vm86 mode. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2014-10-11Fully restore 16bit state during call16_sloppy()Kevin O'Connor1-30/+63
When transitioning back to 16bit mode from within call32(), restore the full state (cmos index, gdt, fs/gs) in addition to restoring the original stack. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2014-10-11Break up call32() into call32() and call32_sloppy()Kevin O'Connor1-39/+47
This separates call32() into two functions. It also moves the call16_sloppy() code next to the call32_sloppy() code. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2014-10-11Move call16() functions from romlayout.S to inline assembler in stacks.cKevin O'Connor1-12/+69
Use inline assembler in call16 type functions instead of using __call16() in romlayout.S. Since call16() and call16big() are now only called with %ss==0 they do not need to update the stack pointer. Only call16_sloppy() requires the stack manipulation code. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2014-10-11Update reset() to use call16_back()Kevin O'Connor1-2/+2
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2014-10-11Simplify farcall16 codeKevin O'Connor1-14/+12
With this change, farcall16() is only used for external API calls and is only invoked from a 32bit mode entered directly via transition32. farcall16big() is also only used for external API calls and is only invoked from a 32bit mode entered directly via transition32. call16_int() now calls _farcall16() directly, and it will use normal 16bit mode or big real mode as required. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2014-10-11Track when entering via call32() and use the same mode for stack_hop_back()Kevin O'Connor1-1/+28
If 32bit mode is entered directly via transition32, then use a simple call16() when hopping back to 16bit mode. Use only call16big() during post and when entering 32bit mode via call32(). Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2014-09-30Update stack_hop_back() to jump to 16bit mode if called in 32bit mode.Kevin O'Connor1-18/+13
Also, update callers to rely on this feature. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2014-09-30Add need_hop_back() call that determines if stack_hop_back is neededKevin O'Connor1-4/+4
Also, use need_hop_back() instead of on_extra_stack() in code that determines whether or not to call stack_hop_back(). Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2014-09-30Move stack hop code below call32/call16 code in stacks.cKevin O'Connor1-82/+82
This change is a just code movement. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2014-06-06Abstract reset call (and possible 16bit mode switch) into reset() function.Kevin O'Connor1-0/+10
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2014-06-04Don't enable thread preemption during S3 resume vga option rom execution.Kevin O'Connor1-1/+1
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2014-04-07Replace CONFIG_THREAD_OPTIONROMS with a runtime config setting.Kevin O'Connor1-5/+24
Replace the CONFIG_THREAD_OPTIONROMS option with the CBFS (or fw_cfg) file "etc/threads". This allows for the "threads during optionrom" capability to be enabled/disabled without requiring SeaBIOS to be recompiled. A value of "2" in this file will enable threads to run during option rom execution. This change also allows for all threads to be disabled via the same runtime config file. Setting the file to a value of "0" will cause SeaBIOS to perform all hardware initialization serially. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2014-01-29Add call32_params() helper function.Kevin O'Connor1-0/+27
Add helper function for calling 32bit functions with more than just one parameter. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-12-27Always perform thread cleanup on MainThread stack.Kevin O'Connor1-8/+8
The thread cleanup was being performed on whatever thread stack was next in the list. However, with high debugging this causes spurious _free() debug messages to show up in random threads which can be confusing when analyzing the debug output. So, always run __end_thread() on the MainThread stack to prevent this confusion. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-12-05Minor - move sgdt/lgdt macros from stacks.c to x86.h.Kevin O'Connor1-7/+0
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-10-14Support call16() calls after entering 32bit mode from call32().Kevin O'Connor1-6/+14
When transitioning to 32bit via call32() track the stack segment register and support restoring it on call16() requests. This permits call16() to work properly. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-10-14Update _farcall16() to pass segment of callregs explicitly.Kevin O'Connor1-7/+6
Don't use implicit passing of %es for the segment of the callregs pointer. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-10-14Make __call16 use C calling convention and support two passed parameters.Kevin O'Connor1-19/+11
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-10-14Rearrange stack_hop_back() call in wait_irq, check_irqs, and _farcall16.Kevin O'Connor1-3/+20
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-09-28Rename hw/cmos.h to hw/rtc.h and copy RTC code from clock.c to hw/rtc.c.Kevin O'Connor1-2/+3
Group the Real Time Clock code into hw/rtc.[ch]. Also, use rtc_read/write/mask function naming (instead of inb/outb_cmos) to be more consistent with other register accessors. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-09-18Move function definitions for output.c from util.h to new file output.h.Kevin O'Connor1-1/+2
Also, sort the order of include files in the c files. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-09-18Move malloc code from pmm.c to new files malloc.c and malloc.h.Kevin O'Connor1-0/+1
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-09-18Move stacks.c definitions from util.h to new file stacks.h.Kevin O'Connor1-0/+1
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-08-10Add config option to support memory allocations in 9-segment.Kevin O'Connor1-1/+2
Internal "low memory" allocations are currently placed in the UMB region (0xc0000-0xf0000). However, there have been reports of some real machines that do not support DMA to this area of memory. So, add a compile time config option (off by default) to support placing all internal low-memory allocations at the end of the 640K real-memory area (0x90000-0xa0000). Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-06-08Convert stacks.c to use standard list manipulation code.Kevin O'Connor1-17/+15
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-06-08Introduce helper function have_threads() in stacks.c.Kevin O'Connor1-10/+12
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>