static inline void setcr0(u32 cr0) {
asm("movl %0, %%cr0" : : "r"(cr0));
}
+static inline u16 getcr0_vm86(void) {
+ u16 cr0;
+ asm("smsww %0" : "=r"(cr0));
+ return cr0;
+}
static inline u64 rdmsr(u32 index)
{
SET_BDA(video_mode, 0xff);
SET_BDA_EXT(vbe_mode, mode | (flags & MF_VBEFLAGS));
SET_BDA_EXT(vgamode_offset, (u32)vmode_g);
+ if (CONFIG_VGA_ALLOCATE_EXTRA_STACK && !(getcr0_vm86() & CR0_PE))
+ // Disable extra stack if it appears a modern OS is in use.
+ // This works around bugs in some versions of Windows (Vista
+ // and possibly later) when the stack is in the e-segment.
+ MASK_BDA_EXT(flags, BF_EXTRA_STACK
+ , (flags & MF_LEGACY) ? BF_EXTRA_STACK : 0);
if (memmodel == MM_TEXT) {
SET_BDA(video_cols, width);
SET_BDA(video_rows, height-1);
#define GO_MEMSET 3
#define GO_MEMMOVE 4
-// Custom internal storage in BDA
+// Custom internal storage in BDA (don't change here without also
+// updating vgaentry.S)
#define VGA_CUSTOM_BDA 0xb9
struct vga_bda_s {
#define BF_PM_MASK 0x0f
#define BF_EMULATE_TEXT 0x10
#define BF_SWCURSOR 0x20
+#define BF_EXTRA_STACK 0x40
#define GET_BDA_EXT(var) \
GET_FARVAR(SEG_BDA, ((struct vga_bda_s *)VGA_CUSTOM_BDA)->var)
ENTRY_ARG_VGA handle_10
iretw
+#define VGA_CUSTOM_BDA_FLAGS 0xb9
+#define BF_EXTRA_STACK 0x40
+
// Entry point using extra stack
DECLFUNC entry_10_extrastack
entry_10_extrastack:
cli
cld
- pushw %ds // Set %ds:%eax to space on ExtraStack
+ pushw %ds
pushl %eax
- movw %cs:ExtraStackSeg, %ds
+
+ movw $SEG_BDA, %ax // Check if extra stack is enabled
+ movw %ax, %ds
+ testb $BF_EXTRA_STACK, VGA_CUSTOM_BDA_FLAGS
+ jz 1f
+
+ movw %cs:ExtraStackSeg, %ds // Set %ds:%eax to space on ExtraStack
movl $(CONFIG_VGA_EXTRA_STACK_SIZE-PUSHBREGS_size-16), %eax
SAVEBREGS_POP_DSEAX // Save registers on extra stack
movl %esp, PUSHBREGS_size+8(%eax)
RESTOREBREGS_DSEAX
iretw
+1: // Use regular entry point if the extra stack is disabled
+ popl %eax
+ popw %ds
+ jmp entry_10
+
// Timer irq handling
DECLFUNC entry_timer_hook
entry_timer_hook: