Index: /trunk/abdev/BasicCompiler64/BasicCompiler.vcproj
===================================================================
--- /trunk/abdev/BasicCompiler64/BasicCompiler.vcproj	(revision 308)
+++ /trunk/abdev/BasicCompiler64/BasicCompiler.vcproj	(revision 309)
@@ -412,12 +412,4 @@
 					</File>
 				</Filter>
-				<Filter
-					Name="Low Level Classes"
-					>
-					<File
-						RelativePath="..\BasicCompiler_Common\include\StackFrame.h"
-						>
-					</File>
-				</Filter>
 			</Filter>
 		</Filter>
Index: /trunk/abdev/BasicCompiler64/Compile_ProcOp.cpp
===================================================================
--- /trunk/abdev/BasicCompiler64/Compile_ProcOp.cpp	(revision 308)
+++ /trunk/abdev/BasicCompiler64/Compile_ProcOp.cpp	(revision 309)
@@ -146,4 +146,37 @@
 
 			Compile_AddGlobalRootsForGc();
+	}
+	else if( userProc.GetName() == compiler.globalAreaProcName ){
+		////////////////////////////////////////
+		// グローバル領域をコンパイル
+		////////////////////////////////////////
+
+		const UserProc *pBackUserProc = &UserProc::CompilingUserProc();
+		UserProc::CompileStartForGlobalArea();
+
+		int BackCp = cp;
+		cp=-1;
+
+		//クラスに属する静的メンバを定義
+		compiler.GetObjectModule().meta.GetClasses().InitStaticMember();
+
+		//グローバル実行領域をコンパイル開始
+		CompileBuffer(0,0);
+
+		//Goto未知ラベルスケジュールが存在したらエラーにする
+		BOOST_FOREACH( const GotoLabelSchedule *pGotoLabelSchedule, compiler.codeGenerator.gotoLabelSchedules )
+		{
+			if(pGotoLabelSchedule->GetName().size()>0){
+				SetError(6,pGotoLabelSchedule->GetName(),pGotoLabelSchedule->GetSourceCodePos());
+			}
+			else{
+				char temporary[255];
+				sprintf(temporary,"%d",pGotoLabelSchedule->GetLineNum());
+				SetError(6,temporary,pGotoLabelSchedule->GetSourceCodePos());
+			}
+		}
+
+		UserProc::CompileStartForUserProc( pBackUserProc );
+		cp=BackCp;
 	}
 	else{
@@ -691,4 +724,10 @@
 		else SetError(300,NULL,cp);
 	}
+	else
+	{
+		// グローバル領域を一番初めにコンパイルする
+		extern const UserProc *pSub_System_GlobalArea;
+		CompileBufferInProcedure( *pSub_System_GlobalArea );
+	}
 
 	//_System_TypeBase_InitializeUserTypesは一番最後にコンパイル
Index: /trunk/abdev/BasicCompiler64/MakePeHdr.cpp
===================================================================
--- /trunk/abdev/BasicCompiler64/MakePeHdr.cpp	(revision 308)
+++ /trunk/abdev/BasicCompiler64/MakePeHdr.cpp	(revision 309)
@@ -24,4 +24,5 @@
 const UserProc
 	*pSub_System_StartupProgram,
+	*pSub_System_GlobalArea,
 	*pSub_DebugSys_StartProc,
 	*pSub_DebugSys_EndProc,
@@ -224,4 +225,10 @@
 		pSub_System_StartupProgram->Using();
 
+	if(pSub_System_GlobalArea=GetSubHash(compiler.globalAreaProcName.c_str(),1))
+	{
+		pSub_System_GlobalArea->Using();
+		pSub_System_GlobalArea->ThisIsAutoGenerationProc();
+	}
+
 	if(pSub_DebugSys_StartProc=GetSubHash("_DebugSys_StartProc",1))
 		pSub_DebugSys_StartProc->Using();
@@ -344,5 +351,5 @@
 
 		//スタックフレーム管理用クラスを選択
-		pobj_sf = &compiler.GetObjectModule().globalStackFrame;
+		pobj_sf=new StackFrame();
 
 		// コード生成対象を選択
@@ -358,5 +365,5 @@
 		{
 			//sub rsp,スタックフレームサイズ
-			const PertialSchedule *pStackFramePertialSchedule = compiler.codeGenerator.op_sub_rsp( 0, true );
+			compiler.codeGenerator.op_sub_RV( sizeof(_int64), REG_RSP, 0x100 );
 
 			if(bDebugCompile){
@@ -372,21 +379,6 @@
 		}
 
-		//クラスに属する静的メンバを定義
-		compiler.GetObjectModule().meta.GetClasses().InitStaticMember();
-
-		//グローバル実行領域をコンパイル開始
-		CompileBuffer(0,0);
-
-		//Goto未知ラベルスケジュールが存在したらエラーにする
-		BOOST_FOREACH( const GotoLabelSchedule *pGotoLabelSchedule, compiler.codeGenerator.gotoLabelSchedules )
-		{
-			if(pGotoLabelSchedule->GetName().size()>0){
-				SetError(6,pGotoLabelSchedule->GetName(),pGotoLabelSchedule->GetSourceCodePos());
-			}
-			else{
-				sprintf(temporary,"%d",pGotoLabelSchedule->GetLineNum());
-				SetError(6,temporary,pGotoLabelSchedule->GetSourceCodePos());
-			}
-		}
+		// _System_GlobalArea の呼び出し
+		compiler.codeGenerator.op_call( pSub_System_GlobalArea );
 
 
@@ -403,6 +395,5 @@
 
 			//add rsp,スタックフレームサイズ
-			int stackFrameSize = pobj_sf->GetFrameSize(0);
-			compiler.codeGenerator.op_add_RV( REG_RSP, stackFrameSize );
+			compiler.codeGenerator.op_add_RV( REG_RSP, 0x100 );
 
 			//xor rax,rax（raxを0に初期化する）
@@ -411,12 +402,10 @@
 			//ret
 			compiler.codeGenerator.op_ret();
-
-			//スタックフレームスケジュール（subコマンドに渡す値）
-			compiler.codeGenerator.opfix( pStackFramePertialSchedule, stackFrameSize );
-
-			//スタックフレームスケジュールを実行
-			pobj_sf->RunningSchedule( stackFrameSize );
-			pobj_sf=0;
-		}
+		}
+
+		//スタックフレームスケジュールを実行
+		pobj_sf->RunningSchedule( 0x100 );
+		delete pobj_sf;
+		pobj_sf=0;
 
 		//グローバル実行領域のコードサイズ
Index: /trunk/abdev/BasicCompiler64/Opcode.h
===================================================================
--- /trunk/abdev/BasicCompiler64/Opcode.h	(revision 308)
+++ /trunk/abdev/BasicCompiler64/Opcode.h	(revision 309)
@@ -43,4 +43,38 @@
 
 
+class StackFrame
+{
+	///////////////////////////
+	// スタックフレーム管理
+	///////////////////////////
+
+	PertialSchedules pertialSchedules;
+
+	int lowest_sp;			//スタックポインタの最下位位置
+	int now_sp;				//スタックポインタ
+	int max_parm_size;		//パラメータの最大サイズ
+
+public:
+	//コンストラクタ
+	StackFrame();
+
+	//デストラクタ
+	~StackFrame();
+
+	int GetFrameSize( int localParamSize );
+	int GetNowSp();
+	void mov_sp( int reg );
+	int push(int reg);
+	void push(int xmm_reg,int varSize);
+	void ref_offset_data( int reg, int sp_offset );
+	void ref(int reg);
+	void ref(int xmm_reg,int varSize);
+	void pop(int reg = REG_NON);
+	void pop(int xmm_reg,int varSize);
+	void parameter_allocate(int size);
+	void RunningSchedule( int stackFrameSize );
+
+	void error_check(void);
+};
 extern StackFrame *pobj_sf;
 
