#include "stacks.h" // struct mutex_s
#include "util.h" // useRTC
+#define MAIN_STACK_MAX (1024*1024)
+
/****************************************************************
* Extra 16bit stack
asm("lgdtl %0" : : "m"(*desc) : "memory");
}
+u16 StackSeg VARLOW;
+
// Call a 32bit SeaBIOS function from a 16bit SeaBIOS function.
u32 VISIBLE16
call32(void *func, u32 eax, u32 errret)
struct descloc_s gdt;
sgdt(&gdt);
+ u16 oldstackseg = GET_LOW(StackSeg);
+ SET_LOW(StackSeg, GET_SEG(SS));
u32 bkup_ss, bkup_esp;
asm volatile(
// Backup ss/esp / set esp to flat stack location
: "r" (func)
: "ecx", "edx", "cc", "memory");
+ SET_LOW(StackSeg, oldstackseg);
+
// Restore gdt and fs/gs
lgdt(&gdt);
SET_SEG(FS, fs);
call16(u32 eax, u32 edx, void *func)
{
ASSERT32FLAT();
- if (getesp() > BUILD_STACK_ADDR)
+ if (getesp() > MAIN_STACK_MAX)
panic("call16 with invalid stack\n");
extern u32 __call16(u32 eax, u32 edx, void *func);
return __call16(eax, edx, func - BUILD_BIOS_ADDR);
call16big(u32 eax, u32 edx, void *func)
{
ASSERT32FLAT();
- if (getesp() > BUILD_STACK_ADDR)
+ if (getesp() > MAIN_STACK_MAX)
panic("call16big with invalid stack\n");
extern u32 __call16big(u32 eax, u32 edx, void *func);
return __call16big(eax, edx, func - BUILD_BIOS_ADDR);
return;
}
extern void _cfunc16__farcall16(void);
- call16((u32)callregs, 0, _cfunc16__farcall16);
+ call16((u32)callregs - StackSeg * 16, StackSeg, _cfunc16__farcall16);
}
inline void
farcall16big(struct bregs *callregs)
{
extern void _cfunc16__farcall16(void);
- call16big((u32)callregs, 0, _cfunc16__farcall16);
+ call16big((u32)callregs - StackSeg * 16, StackSeg, _cfunc16__farcall16);
}
// Invoke a 16bit software interrupt.
getCurThread(void)
{
u32 esp = getesp();
- if (esp <= BUILD_STACK_ADDR)
+ if (esp <= MAIN_STACK_MAX)
return &MainThread;
return (void*)ALIGN_DOWN(esp, THREADSTACKSIZE);
}
wait_preempt(void)
{
if (MODESEGMENT || !CONFIG_THREAD_OPTIONROMS || !CanPreempt
- || getesp() < 1024*1024)
+ || getesp() < MAIN_STACK_MAX)
return 0;
while (CanPreempt)
yield();