At the moment, this is my stack initialization code:
Code: Select all
// have some fun setting up the stack
stackSpace--;
*stackSpace-- = 0x0202; // EFLAGS
*stackSpace-- = 0x08; // cs for cleanup
*stackSpace-- = (unsigned int) &procret; // eip for cleanup
// *stackSpace-- = (args); // args for main function would be pushed here;
*stackSpace-- = 0x08; // cs for eip
*stackSpace-- = (unsigned int) addr; // EIP
*stackSpace-- = 0; // ebp
*stackSpace-- = 0; // esp
*stackSpace-- = 0; // edi
*stackSpace-- = 0; // esi
*stackSpace-- = 0; // edx
*stackSpace-- = 0; // ecx
*stackSpace-- = 0; // ebx
*stackSpace-- = 0; // eax
*stackSpace-- = 0x10; // ds
*stackSpace-- = 0x10; // es
*stackSpace-- = 0x10; // fs
*stackSpace = 0x10; // gs
The other thing is, often after 3 or 4 reschedules the system crashes with an Invalid Opcode error... this is really frustrating because everything looks correct. You can view my multitasker code on cvs at sourceforge (link in my sig) - it's in mt_lib.c.
Bochs log at time of crash:
Code: Select all
00059056454i[CPU0 ] LOCK prefix unallowed (op1=0x1be, attr=0x100, mod=0x40, nnn=0)
00238438000p[WGUI ] >>PANIC<< POWER button turned off.
00238438000i[SYS ] Last time is 1176168683
00238438000i[CPU0 ] protected mode
00238438000i[CPU0 ] CS.d_b = 32 bit
00238438000i[CPU0 ] SS.d_b = 32 bit
00238438000i[CPU0 ] | EAX=00105e00 EBX=0010b000 ECX=000b836c EDX=000003d5
00238438000i[CPU0 ] | ESP=0014fc6c EBP=0014fca4 ESI=0002be8f EDI=0002be94
00238438000i[CPU0 ] | IOPL=0 id vip vif ac vm rf nt of df if tf sf zf af PF cf
00238438000i[CPU0 ] | SEG selector base limit G D
00238438000i[CPU0 ] | SEG sltr(index|ti|rpl) base limit G D
00238438000i[CPU0 ] | CS:0008( 0001| 0| 0) 00000000 000fffff 1 1
00238438000i[CPU0 ] | DS:0010( 0002| 0| 0) 00000000 000fffff 1 1
00238438000i[CPU0 ] | SS:0010( 0002| 0| 0) 00000000 000fffff 1 1
00238438000i[CPU0 ] | ES:0010( 0002| 0| 0) 00000000 000fffff 1 1
00238438000i[CPU0 ] | FS:0010( 0002| 0| 0) 00000000 000fffff 1 1
00238438000i[CPU0 ] | GS:0010( 0002| 0| 0) 00000000 000fffff 1 1
00238438000i[CPU0 ] | EIP=0010600d (0010600d)
00238438000i[CPU0 ] | CR0=0x00000011 CR1=0 CR2=0x00000000
00238438000i[CPU0 ] | CR3=0x00000000 CR4=0x00000000
00238438000i[CPU0 ] >> jmp .+0xfffffffe (0x0010600d) : EBFE
00238438000i[ ] restoring default signal behavior
00238438000i[CTRL ] quit_sim called with exit code 1