Commit Graph

82 Commits

Author SHA1 Message Date
Gerd Hoffmann d6728f301d add serial console support
Redirect int10 calls to serial console output.
Parse serial input and queue key events.
The serial console can work both as primary display
and in parallel to another vga display (splitmode).

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2017-09-22 11:13:22 -04:00
Kevin O'Connor b4cca861a2 stacks: Use macro wrappers for call32() and stack_hop_back()
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-15 14:15:19 -04:00
Kevin O'Connor bd5f6c7432 Add minimal support for machines without hardware interrupts
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-24 11:02:13 -04:00
Kevin O'Connor bc46ebe2ed rtc: Support disabling the RTC timer irq support
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-17 12:22:05 -04:00
Kevin O'Connor f318c0797b ps2: Support mode for polling the PS2 port instead of using irqs
Some recent hardware has trouble with routing PS2 port interrupts
while the interrupt controller is in legacy routing mode.  This patch
adds a config mechanism (via "etc/ps2-poll-only") to force the PS2
code into a polling only mode so that interrupts are not required.

It is not recommended to use this polling mode on hardware that does
properly support PS2 irqs, because some very old (DOS-era) programs
depend on the BIOS PS2 irq behavior.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2015-07-14 14:49:34 -04:00
Stefan Berger 5aa2a75463 Support for BIOS interrupt handler
This patch implements the TCG BIOS interrupt handler 1ah. It is for
example used by trusted grub.

This patch adds an implementation of SHA1 (following NIST specs., IETF RFC 3147
and Wikipedia) for speeding up measurements of code. Trusted Grub for example
makes use of this interface and measures (calculates SHA1) of the Linux kernel
and initrd. Those files can be rather large and hunting their bytes through
the TIS interface as part of the int handler commands invoked by trusted grub
does take quite some time due to the many vmexits the interface is creating
(one per byte).

There is also a threshold for the size of data to hash (100k) below which
the TPM is used and above the internal faster SHA1 algorithm is used.

This patch for example enables trusted grub to interact with the TPM
and take additional measurements.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2015-05-21 13:16:06 -04:00
Kevin O'Connor 8b7861c4d4 Rename hw/cmos.h to hw/rtc.h and copy RTC code from clock.c to hw/rtc.c.
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-28 22:05:55 -04:00
Kevin O'Connor 9fcd199861 Move PIT setup from clock.c to hw/timer.c.
Move the hardware setup to the hw/timer.c code.  This eliminates the
need for a separate hw/pit.h file with definitions.

Also, move the IRQ counting code (which is dependent on the BDA) from
hw/timer.c to clock.c.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-09-28 22:03:59 -04:00
Kevin O'Connor 135f3f676d Split disk.h into block.h and std/disk.h.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-09-18 20:48:34 -04:00
Kevin O'Connor 2d2fa31b37 Move function definitions for output.c from util.h to new file output.h.
Also, sort the order of include files in the c files.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-09-18 20:48:34 -04:00
Kevin O'Connor 3df600bbdf Move stacks.c definitions from util.h to new file stacks.h.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-09-18 20:48:34 -04:00
Kevin O'Connor fa9c66a656 Rename util.c to string.c and introduce string.h.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-09-18 20:48:34 -04:00
Kevin O'Connor 5d369d8d9e Move code centered around specific hardware devices to src/hw/
Move many C files from the src/ directory to the new src/hw/ directory.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-09-02 20:48:46 -04:00
Kevin O'Connor 018bdd77ce Rename check_tsc() (and similar) to timer_check() and use u32.
Rename the check_tsc() function to timer_check().  The CPU TSC is
often not the basis of the timer, so use a more appropriate name.

Convert all callers that were using u64 for the timers to use u32.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-07-21 14:10:15 -04:00
Kevin O'Connor b7ab1784ac Improve accuracy of internal timers.
The TICKS_PER_DAY setting is a bios standard and needs to be 1573040
for compatibility.  However, there are actually ~1573042.24 ticks in a
day.  So, only use TICKS_PER_DAY when working with the BDA
timer_counter - not when calculating any internal times.

The PIT hz is actually 143181800 / 12 (~1193181.667).  This can be
accurately encoded as PMTIMER hz / 3.  Because the PIT hz is usually
multiplied and divided by other numbers, we can use the PMTIMER hz and
defer the division by 3 to improve accuracy.

When doing division for delay time calculations, always round up the
division so the delay is never less than the requested time.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-07-20 19:30:01 -04:00
Kevin O'Connor 6901337897 Add helper functions to convert timer irqs to milliseconds.
Add ticks_to_ms() and ticks_from_ms() helpers.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-07-20 19:29:54 -04:00
Kevin O'Connor c6e8c0763d Move internal timer code from clock.c to a new file timer.c.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-07-20 19:29:07 -04:00
Kevin O'Connor aa7c234ddf PIC code cleanups.
Preface PIC functions with a pic_ to provide a more consistent
naming.

Convert the irqmask code to a more consistent
pic_irqmask_read/write/mask form.

Move code from pic.h to pic.c.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-07-14 15:10:36 -04:00
Kevin O'Connor 3e641f2ff6 Minor - improve comments and grouping of handle_08().
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-03-03 15:45:01 -05:00
Kevin O'Connor 922aa1ba0a Separate out 16bit PCI-BIOS entry point from regular int 0x1a entry point.
The PCI-BIOS entry point can be called in 16bit protected mode, so
separate its entry code from the legacy 0x1a code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-03-03 15:45:01 -05:00
Kevin O'Connor 89a2f96de4 Convert VAR16VISIBLE, VAR16EXPORT, and VAR32VISIBLE to VARFSEG.
Convert all users of the alternative variable exports to VARFSEG.
There isn't a significant distinction between the existing types of
exports, so it's simpler to just use one type going forward.

The new VARFSEG declaration is only emitting when in 32bit mode, so
update and move some variables as needed.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-02-18 23:36:03 -05:00
David Woodhouse 473013a821 Don't calibrate TSC if PMTIMER is already set up
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
2013-02-12 21:14:31 -05:00
Kevin O'Connor 0f6198a116 Determine century during init and store in VARLOW mem during runtime.
Avoid reading/writing to cmos at runtime to get the QEMU century
information.  Instead, read it at startup and cache the info.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-02-09 11:09:36 -05:00
Kevin O'Connor d83c87bb20 Normalize POST initialization function name suffixes.
The POST phase has to invoke many initialization functions, and these
functions can have complex inter-dependencies.  Try to categorize the
functions into 4 classes:

preinit - functions called very early in POST where function ordering
    is very important and the code has limited access to other
    interfaces.

init - functions that initialize internal interfaces and standard
    external interfaces.  This code is generally not dependent on
    particular hardware and typically does not communicate directly
    with any hardware devices.

setup - functions which access hardware or are dependent on particular
    hardware or platform devices.

prepboot - functions that finalize internal interfaces and that
    prepare for the boot phase.

This patch attempts to normalize the suffixes - functions that used
_init(), _setup(), _finalize(), or similar that did not follow the
above pattern were renamed.  Other than function name changes, there
should be no code impact to this patch.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-02-05 20:00:29 -05:00
Gerd Hoffmann 455a7c87e8 add acpi pmtimer support
This patch makes seabios use the acpi pmtimer instead of tsc for
timekeeping.  The pmtimer has a fixed frequency and doesn't need
calibration, thus it doesn't suffer from calibration errors due to a
loaded host machine.

[ v4: mask port ioport read ]
[ v2: add CONFIG_PMTIMER ]

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-09-10 20:35:53 -04:00
Kevin O'Connor 1297e5da56 Fix winxp boot regression introduced in ecdc655a.
The winxp boot loader does something curious - it sets an int 0x1c
handler, records the stack location, and then spins in place with irqs
enabled.  The 0x1c handler alters the memory just past the stack
pointer so that when the timer irq returns the code jumps to a new
location and stop spinning.  The winxp code relies on the fact that a
hw irq will always place 6 bytes at a specific location and that it
can alter those bytes.

The ecdc655a patch does a full backup/restore of the register state.
Unfortunately, the restore overwrites the changes made by the winxp
0x1c handler.

This patch reverts much of ecdc655a.  Hardware irqs are still handled
on the extra stack, but only the essential register state is backed up
and restored.

Also, stack_hop_back is changed to only use %sp when changing states -
this enables the entry code to store just %esp instead of both %esp
and %sp.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2012-06-02 20:30:58 -04:00
Kevin O'Connor ecdc655a86 Run all hardware irq handlers on the extra stack.
Jump into the extra stack for all hardware irq handlers.  This reduces
the overall stack requirements of SeaBIOS.

Replace all users of call16_simpint with call16_int.  Only the
hardware irq handlers used the old call, and they need to use the new
call to ensure the extra stack is properly re-entrant.

Also, pass in a 'struct bregs' to the hardware irq handlers now.  It
was not done previously to save stack space.  Now that the extra stack
is used, that is no longer an issue.

Note that should an old OS invoke a hardware irq in 16bit protected
mode, then this patch could break that OS.  However, the chances of
this causing a regression seem small as several existing hardware irq
handlers already do not work in 16bit protected mode.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2012-05-30 21:04:52 -04:00
Kevin O'Connor 94c749c34b Rename wait_irq to yield_toirq.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2012-05-28 23:21:43 -04:00
Kevin O'Connor 9d254d4614 Convert timer code EBDA variables to VARLOW variables.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2012-05-20 18:10:45 -04:00
Kevin O'Connor 745de855bd Add TSC emulation layer for 386/486 CPUs.
Original patch from Rudolf Marek.

Signed-off-by: Rudolf Marek <r.marek@assembler.cz>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2012-02-01 20:42:51 -05:00
Kevin O'Connor 4d96edc76b Cleanup - it's no longer necessary to manually reset global variables.
Now that a soft-reboot forces a hard-reboot, it is no longer necessary
to manually reset global variables.
2010-09-25 14:53:15 -04:00
Kevin O'Connor cc9e1bf433 Add FUNC16() helper macro for converting a 16bit func to a segoff_s. 2010-07-28 21:31:38 -04:00
Kevin O'Connor abf31d367a Fix integer truncating bug in calc_future_timer().
Be sure to promote to u64 before multiplication.
2010-07-26 22:33:54 -04:00
Kevin O'Connor bb68591e71 Don't use RTC to time boot menu delay.
It appears real machines sometimes have a flaky RTC, so avoid using
the RTC irq during boot.  Instead, use a delay based on the standard
timer irq.

This also optimizes CONFIG_THREAD_OPTIONROMS users as it is no longer
necessary to use preemption - the wait_irq() call handles task
switching natively.
2010-05-23 12:40:40 -04:00
Kevin O'Connor b5cc2ca5d0 Generalize timer based delay code.
Move the timer based counting code in serial.c to clock.c.

Rework the interface to make it similar to the tsc based timers.
2010-05-23 11:38:53 -04:00
Kevin O'Connor 144817be2d Rename check_time() to check_tsc(). 2010-05-23 10:46:49 -04:00
Kevin O'Connor 0e88576feb Add support for USB mice.
Initial support for USB mice that follow the "boot" protocol.
2010-05-01 22:14:40 -04:00
Kevin O'Connor 11cc662d04 Extend time for rtc to be ready.
Increase the time waiting for rtc from 3ms to 15ms - only 3ms is
needed on real hardware, but scheduling delays on qemu can make this
longer.  Extending the time prevents annoying debugging messages.
2010-03-13 23:04:41 -05:00
Kevin O'Connor 68c51390e3 Enable irqs in kbd/clock calls that caller might "spin" on.
Some old programs will spin on a clock/keyboard call with irqs
disabled.  They assume the BIOS will enable irqs and allow key events
and clock events to occur.

So, enable irqs in those functions that a caller might "spin" on.
2010-03-13 22:23:44 -05:00
Kevin O'Connor 991eaff3f6 Support USB interrupt schedules on OHCI and UHCI.
The existing code always checks for USB "interrupt in" events every
millisecond.  Although that's okay, it consumes extra bandwidth.  This
change interrupt checks to be scheduled according to their requested
interval time.
2010-02-13 21:51:47 -05:00
Kevin O'Connor 1ca05b0f39 Be sure to add "void" to all function prototypes that take no args.
Omitting "void" leads to a K&R style declaration which was not intended.
2010-01-03 17:43:37 -05:00
Kevin O'Connor dfefeb5438 Distinguish between debug reports for unimplemented vs invalid calls.
Don't use "fail" in the debug output - as this confuses users.
When reporting on an invalid parameter - use the word "invalid".
When reporting on an unimplemented call - state it is unimplemented.
Add separate debug levels for unimplemented vs invalid calls.
Also, increase the debug level of several entry points.
2009-12-13 13:04:17 -05:00
Kevin O'Connor ad90159251 Enhance experimental option rom "threading" - enable preemption.
When experimental support for parallelizing option roms and hardware
   init (default disabled) is selected, add support for checking on
   hardware init progress from the RTC irq handler.
Enable ability for RTC to be turned on for additional users.
Allow regular option roms (not just vga option roms) to run in
   parallel with hardware init.
Don't use stack in transition32 / transition16 until new mode is
   entered.
Also, cleanup leaking of data handlers in usb code.
Also, decrease frequency of iomemcpy checks (every 2K instead of 1K).
2009-12-13 11:25:25 -05:00
Kevin O'Connor 10ad799ff4 Replace irq_enable() regions with explicit calls to check for irqs.
Add new function yield() which will permit irqs to trigger.
The yield() call enables irqs to occur in 32bit mode.
Add [num]sleep calls that yield instead of just spinning.
Rename existing int 1586 usleep call to biosusleep.
Convert many calls to mdelay to msleep.
2009-10-24 11:06:08 -04:00
Kevin O'Connor 89eb6241e5 Handle tsc rollover.
Handle case where timetamp counter overflows while waiting.
2009-10-22 22:30:37 -04:00
Kevin O'Connor 1c46a548f2 Expand USB OHCI support.
Get UHCI support to point where it works with (a modified) qemu.
2009-10-17 23:53:32 -04:00
Kevin O'Connor 114592f000 Initial support for USB, UHCI, and USB Keyboards.
This adds preliminary support for USB controllers and keyboards.
Add support for UHCI controllers.
Add support for "HID" USB keyboards.
Also, fix bug in hexdump() - len need not be power of 4.
2009-09-28 21:32:08 -04:00
Kevin O'Connor 6aee52dd45 Replace clock conversion constants with defines.
Simplify and name the clock multiplier constants.
2009-09-27 20:07:40 -04:00
Kevin O'Connor ee2efa7303 Support sleeping until an irq fires, and use where applicable.
Add wait_irq() - it's more efficient than looping with cpu_relax().
Also, move kbd irq enables down - only kbd_command needs it.
Also, make some minor code layout improvements to kbd.c.
2009-09-20 15:33:08 -04:00
Kevin O'Connor 9f985427ff Replace common segment/offset pairs with struct segoff_s.
Introduce 'struct segoff_s' to more places.
2009-09-09 11:34:39 -04:00