[FREELDR] Several changes regarding chainloading and Linux boot.
[reactos.git] / boot / freeldr / freeldr / arch / i386 / entry.S
index 799764f..9e7090f 100644 (file)
@@ -27,6 +27,8 @@ EXTERN _i386Idt:DWORD
 //EXTERN _i386idtptr:FWORD
 EXTERN cmdline:DWORD
 
+EXTERN _DiskStopFloppyMotor:PROC
+
 #ifdef _USE_ML
 EXTERN __bss_start__:DWORD
 EXTERN __bss_end__:DWORD
@@ -62,11 +64,8 @@ PUBLIC ContinueAddress
 ContinueAddress:
     .long _FrldrStartup
 
-
 _FrldrStartup:
 
-ASSUME /*CS:_TEXT,*/ DS:_DATA, ES:_DATA, FS:_DATA, GS:_DATA, SS:_DATA
-
     /* Store BootDrive and BootPartition */
     mov byte ptr ds:[_FrldrBootDrive], dl
     xor eax, eax
@@ -102,6 +101,66 @@ stop:
     nop
 
 
+PUBLIC _Reboot
+_Reboot:
+    /* Stop the floppy drive motor */
+    call _DiskStopFloppyMotor
+
+    /* Set the function ID and switch to real mode (we don't return) */
+    mov bx, FNID_Reboot
+    jmp SwitchToReal
+
+
+/*
+ * VOID __cdecl Relocator16Boot(
+ *     IN REGS*  In,
+ *     IN USHORT StackSegment,
+ *     IN USHORT StackPointer,
+ *     IN USHORT CodeSegment,
+ *     IN USHORT CodePointer);
+ *
+ * RETURNS: Nothing.
+ *
+ * NOTE: The implementation of this function is similar to that of Int386(),
+ * with the proviso that no attempt is done to save the original values of
+ * the registers since we will not need them anyway, as we do not return back
+ * to the caller but instead place the machine in a permanent new CPU state.
+ */
+PUBLIC _Relocator16Boot
+_Relocator16Boot:
+
+    /* Copy input registers */
+    mov esi, dword ptr [esp + 4]
+    mov edi, BSS_RegisterSet
+    mov ecx, REGS_SIZE / 4
+    rep movsd
+
+    /* Set the stack segment/offset */
+    // Since BSS_CallbackReturn contains a ULONG, store in its high word
+    // the stack segment and in its low word the stack offset.
+    mov ax, word ptr [esp + 8]
+    shl eax, 16
+    mov ax, word ptr [esp + 12]
+    mov dword ptr ds:[BSS_CallbackReturn], eax
+
+    /*
+     * Set the code segment/offset (Copy entry point)
+     * NOTE: We permanently *ERASE* the contents of ds:[BSS_RealModeEntry]
+     * but it is not a problem since we are going to place the machine in
+     * a permanent new CPU state.
+     */
+    // Since BSS_RealModeEntry contains a ULONG, store in its high word
+    // the code segment and in its low word the code offset.
+    mov ax, word ptr [esp + 16]
+    shl eax, 16
+    mov ax, word ptr [esp + 20]
+    mov dword ptr ds:[BSS_RealModeEntry], eax
+
+    /* Set the function ID and switch to real mode (we don't return) */
+    mov bx, FNID_Relocator16Boot
+    jmp SwitchToReal
+
+
 /*
  * U16 PxeCallApi(U16 Segment, U16 Offset, U16 Service, VOID *Parameter);
  *
@@ -141,27 +200,6 @@ _PxeCallApi:
     ret
 
 
-PUBLIC _Reboot
-_Reboot:
-    /* Set the function ID */
-    mov bx, FNID_Reboot
-
-    /* Switch to real mode (we don't return) */
-    jmp SwitchToReal
-
-
-PUBLIC _ChainLoadBiosBootSectorCode
-_ChainLoadBiosBootSectorCode:
-    /* Set the boot drive */
-    mov dl, byte ptr ds:[_FrldrBootDrive]
-
-    /* Set the function ID */
-    mov bx, FNID_ChainLoadBiosBootSectorCode
-
-    /* Switch to real mode (we don't return) */
-    jmp SwitchToReal
-
-
 PUBLIC i386CallRealMode
 i386CallRealMode:
     /* Set continue address and switch to real mode */