Multiboot fixes
authorDavid Welch <welch@cwcom.net>
Wed, 17 Jan 2001 15:38:03 +0000 (15:38 +0000)
committerDavid Welch <welch@cwcom.net>
Wed, 17 Jan 2001 15:38:03 +0000 (15:38 +0000)
svn path=/trunk/; revision=1529

reactos/install.bochs
reactos/loaders/dos/loadros.asm
reactos/ntoskrnl/ke/apc.c
reactos/ntoskrnl/ke/main.c
reactos/ntoskrnl/ke/multiboot.S
reactos/ntoskrnl/mm/mminit.c
reactos/ntoskrnl/ps/kill.c

index 3f69e2b..cdec20b 100644 (file)
@@ -1,8 +1,8 @@
 #!/bin/sh
-echo "Installing to floppy."
-mount -t vfat /bochs/1.44a /mnt/floppy -o loop,rw
-./install-system.sh /mnt/floppy
-umount /mnt/floppy
+#echo "Installing to floppy."
+#mount -t vfat /bochs/1.44a /mnt/floppy -o loop,rw
+#./install-system.sh /mnt/floppy
+#umount /mnt/floppy
 echo "Installing to disk."
 mount -t vfat /bochs/10M.vga.dos /mnt/floppy -o loop,offset=8704,rw
 ./install.sh /mnt/floppy
index d23e139..0753717 100644 (file)
@@ -266,51 +266,57 @@ entry:
        mov     [_multiboot_cmdline], eax
        add     dword [_multiboot_cmdline], _multiboot_kernel_cmdline
        
+       ;;
+       ;; Hide the kernel's entry in the list of modules
+       ;; 
        mov     [_multiboot_mods_addr], eax
-       add     dword [_multiboot_mods_addr], _multiboot_modules
-       
+       mov     ebx, _multiboot_modules
+       add     ebx, multiboot_module_size
+       add     dword [_multiboot_mods_addr], ebx
+       dec     dword [_multiboot_mods_count]
+               
        ;;
        ;; get extended memory size in KB
        ;;
-
-       push ebx
-       xor ebx,ebx
-       mov [_multiboot_mem_lower],ebx
-        mov ax, 0xe801
-        int 015h
-       cmp ebx,ebx
-       jz .oldstylemem
-
-        and ebx, 0xffff
-       shl ebx,6
-       mov [_multiboot_mem_lower],ebx
-        and eax,0xffff
-        add dword [_multiboot_mem_lower],eax
-       jmp .done_mem
+       push    ebx
+       xor     ebx,ebx
+       mov     [_multiboot_mem_upper],ebx
+       mov     [_multiboot_mem_lower],ebx
+        mov    ax, 0xe801
+        int    015h
+       cmp     ebx,ebx
+       jz      .oldstylemem
+
+        and    ebx, 0xffff
+       shl      ebx,6
+       mov     [_multiboot_mem_upper],ebx
+        and    eax,0xffff
+        add    dword [_multiboot_mem_upper],eax
+       jmp     .done_mem
 
 .oldstylemem:
        ;; int 15h opt e801 don't work , try int 15h, option 88h
-        mov ah, 088h
-        int 015h
-       cmp ax,ax
-       jz .cmosmem
-       mov [_multiboot_mem_lower],ax
-       jmp .done_mem
+        mov    ah, 088h
+        int    015h
+       cmp     ax,ax
+       jz      .cmosmem
+       mov     [_multiboot_mem_upper],ax
+       jmp     .done_mem
 .cmosmem:
        ;; int 15h opt 88h don't work , try read cmos
-       xor eax,eax
-       mov  al, 0x31
-       out 0x70, al
-       in  al, 0x71
-        and eax, 0xffff        ; clear carry
-       shl eax,8
-       mov [_multiboot_mem_lower],eax
-;;     xor eax,eax
-;;     mov  al, 0x30
-;;     out 0x70, al
-;;     in  al, 0x71
-;;     and eax, 0xffff ; clear carry
-;;     add [_multiboot_mem_lower],eax
+       xor     eax,eax
+       mov     al, 0x31
+       out     0x70, al
+       in      al, 0x71
+        and    eax, 0xffff     ; clear carry
+       shl     eax,8
+       mov     [_multiboot_mem_upper],eax
+;;     xor     eax,eax
+;;     mov     al, 0x30
+;;     out     0x70, al
+;;     in      al, 0x71
+;;     and     eax, 0xffff     ; clear carry
+;;     add     [_multiboot_mem_lower],eax
 
 .done_mem:
        pop ebx
index 5d7065d..d02dd40 100644 (file)
@@ -89,11 +89,28 @@ BOOLEAN KiDeliverUserApc(PKTRAP_FRAME TrapFrame)
    PCONTEXT Context;
    KIRQL oldlvl;
    PKTHREAD Thread;
-   
+   PETHREAD EThread;
+
    DPRINT("KiDeliverUserApc(TrapFrame %x/%x)\n", TrapFrame,
          KeGetCurrentThread()->TrapFrame);
    Thread = KeGetCurrentThread();
    KeAcquireSpinLock(&PiApcLock, &oldlvl);
+
+   /*
+    * Check for thread termination
+    */
+   KeAcquireSpinLock(&PiThreadListLock, &oldlvl);
+   EThread = CONTAINING_RECORD(Thread, ETHREAD, Tcb);
+   if (EThread->DeadThread)
+     {
+       KeReleaseSpinLock(&PiThreadListLock, oldlvl);
+       PsTerminateCurrentThread(EThread->ExitStatus);
+     }
+   else
+     {
+       KeReleaseSpinLock(&PiThreadListLock, oldlvl);
+     }
+
    current_entry = Thread->ApcState.ApcListHead[1].Flink;
    
    /*
@@ -174,20 +191,6 @@ BOOLEAN KiDeliverUserApc(PKTRAP_FRAME TrapFrame)
                      (PVOID*)&Esp[3],
                      (PVOID*)&Esp[4]);
 
-#if 0   
-   KeAcquireSpinLock(&PiThreadListLock, &oldlvl);
-   EThread = CONTAINING_RECORD(Thread, ETHREAD, Tcb);
-   if (EThread->DeadThread)
-     {
-       KeReleaseSpinLock(&PiThreadListLock, oldlvl);
-       PsTerminateCurrentThread(EThread->ExitStatus);
-     }
-   else
-     {
-       KeReleaseSpinLock(&PiThreadListLock, oldlvl);
-     }
-   return ret;
-#endif
    return(TRUE);
 }
 
@@ -231,10 +234,11 @@ VOID STDCALL KiDeliverApc(ULONG Unknown1,
 //   Thread->Tcb.WaitStatus = STATUS_KERNEL_APC;
 }
 
-VOID STDCALL KeInsertQueueApc (PKAPC   Apc,
-                              PVOID    SystemArgument1,
-                              PVOID    SystemArgument2,
-                              UCHAR    Mode)
+VOID STDCALL 
+KeInsertQueueApc (PKAPC        Apc,
+                 PVOID SystemArgument1,
+                 PVOID SystemArgument2,
+                 UCHAR Mode)
 /*
  * FUNCTION: Queues an APC for execution
  * ARGUMENTS:
index 8d45875..613370e 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: main.c,v 1.73 2001/01/14 15:30:47 ekohl Exp $
+/* $Id: main.c,v 1.74 2001/01/17 15:38:02 dwelch Exp $
  *
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS kernel
@@ -84,13 +84,13 @@ CreateSystemRootLink (PCSZ ParameterLine)
                RtlCreateUnicodeStringFromAsciiz (&BootPath, "\\");
        }
        DPRINT("Arc name: %s\n", ParamBuffer);
-
+       
        /* Only arc name left - build full arc name */
        ArcNameBuffer = ExAllocatePool (PagedPool, 256 * sizeof(WCHAR));
        swprintf (ArcNameBuffer,
                  L"\\ArcName\\%S", ParamBuffer);
        RtlInitUnicodeString (&ArcName, ArcNameBuffer);
-       DPRINT("Arc name: %wZ\n", &ArcName);
+       DPRINT1("Arc name: %wZ\n", &ArcName);
 
        /* free ParamBuffer */
        ExFreePool (ParamBuffer);
@@ -435,25 +435,31 @@ _main (ULONG MultiBootMagic, PLOADER_PARAMETER_BLOCK _LoaderBlock)
    ULONG last_kernel_address;
    ULONG start;
    PCHAR name;
-   
+   extern ULONG _bss_end__;
+
    /*
     * Copy the parameters to a local buffer because lowmem will go away
     */
    memcpy (&KeLoaderBlock, _LoaderBlock, sizeof(LOADER_PARAMETER_BLOCK));
-   memcpy (&KeLoaderModules, (PVOID)KeLoaderBlock.ModsAddr,
+   memcpy (&KeLoaderModules[1], (PVOID)KeLoaderBlock.ModsAddr,
           sizeof(LOADER_MODULE) * KeLoaderBlock.ModsCount);
+   KeLoaderBlock.ModsCount++;
    KeLoaderBlock.ModsAddr = (ULONG)&KeLoaderModules;
-
+   
    /*
     * FIXME: Preliminary hack!!!! Add boot device to beginning of command line.
     * This should be done by the boot loader.
     */
    strcpy (KeLoaderCommandLine,
           "multi(0)disk(0)rdisk(0)partition(1)\\reactos ");
-   strcat (KeLoaderCommandLine, (PUCHAR)KeLoaderBlock.CommandLine);
+   strcat (KeLoaderCommandLine, (PUCHAR)KeLoaderBlock.CommandLine);   
 
    KeLoaderBlock.CommandLine = (ULONG)KeLoaderCommandLine;
-   for (i = 0; i < KeLoaderBlock.ModsCount; i++)
+   strcpy(KeLoaderModuleStrings[0], "ntoskrnl.exe");
+   KeLoaderModules[0].String = (ULONG)KeLoaderModuleStrings[0];
+   KeLoaderModules[0].ModStart = 0xC0000000;
+   KeLoaderModules[0].ModEnd = PAGE_ROUND_UP((ULONG)&_bss_end__);
+   for (i = 1; i < KeLoaderBlock.ModsCount; i++)
      {
        strcpy(KeLoaderModuleStrings[i], (PUCHAR)KeLoaderModules[i].String);
        KeLoaderModules[i].ModStart -= 0x200000;
@@ -469,11 +475,12 @@ _main (ULONG MultiBootMagic, PLOADER_PARAMETER_BLOCK _LoaderBlock)
    HalInitSystem (0, (PLOADER_PARAMETER_BLOCK)&KeLoaderBlock);
    KeInit1();
    KeLowerIrql(DISPATCH_LEVEL);
-
+   
    {
      char tmpbuf[80];
-     sprintf(tmpbuf,"system with %d MB extended memory\n",
-            (unsigned int)(KeLoaderBlock.MemLower)/1024);
+     sprintf(tmpbuf,"system with %d/%d MB memory\n",
+            (unsigned int)(KeLoaderBlock.MemLower)/1024,
+            (unsigned int)(KeLoaderBlock.MemHigher)/1024);
      HalDisplayString(tmpbuf);
    }
 
@@ -564,6 +571,7 @@ _main (ULONG MultiBootMagic, PLOADER_PARAMETER_BLOCK _LoaderBlock)
      }
    
    /* Create the SystemRoot symbolic link */
+   DbgPrint("CommandLine: %s\n", (PUCHAR)KeLoaderBlock.CommandLine);
    CreateSystemRootLink ((PUCHAR)KeLoaderBlock.CommandLine);
    
    CmInitializeRegistry2();
index 98b23e1..c341339 100644 (file)
@@ -103,6 +103,7 @@ l2:
        movl    $0, %eax
        movl    $__bss_end__, %ecx
        subl    $__bss_start__, %ecx
+       shr     $2, %ecx
        movl    $__bss_start__, %edi
        rep
        stosl
index 444c756..913f0eb 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: mminit.c,v 1.12 2000/12/28 03:38:07 dwelch Exp $
+/* $Id: mminit.c,v 1.13 2001/01/17 15:38:03 dwelch Exp $
  *
  * COPYRIGHT:   See COPYING in the top directory
  * PROJECT:     ReactOS kernel 
@@ -217,19 +217,23 @@ VOID MmInit1(ULONG FirstKrnlPhysAddr,
    /*
     * Free physical memory not used by the kernel
     */
-   MmStats.NrTotalPages = KeLoaderBlock.MemLower/4;
-   if ( !MmStats.NrTotalPages )
-   {
-      DbgPrint("Memory not detected, default to 8 MB\n");
+   MmStats.NrTotalPages = KeLoaderBlock.MemHigher/4;
+   if (!MmStats.NrTotalPages)
+     {
+       DbgPrint("Memory not detected, default to 8 MB\n");
        MmStats.NrTotalPages = 2048;
-   }
+     }
    else
-       MmStats.NrTotalPages += 256;// add 1MB for standard memory (not extended)
+     {
+       /* add 1MB for standard memory (not extended) */
+       MmStats.NrTotalPages += 256;
+     }
+   DbgPrint("Used memory %d\n", MmStats.NrTotalPages * PAGESIZE);
+   
    LastKernelAddress = (ULONG)MmInitializePageList(
                                           (PVOID)FirstKrnlPhysAddr,
                                           (PVOID)LastKrnlPhysAddr,
-//                                        1024,
-                       MmStats.NrTotalPages ,
+                                          MmStats.NrTotalPages,
                                           PAGE_ROUND_UP(LastKernelAddress));
    kernel_len = LastKrnlPhysAddr - FirstKrnlPhysAddr;
    
index 8c61d9e..9caae0c 100644 (file)
@@ -149,8 +149,15 @@ PsTerminateOtherThread(PETHREAD Thread, NTSTATUS ExitStatus)
    DPRINT("PsTerminateOtherThread(Thread %x, ExitStatus %x)\n",
          Thread, ExitStatus);
    
+   /*
+    * We must synchronize the termination of a thread with its execution
+    * so all this routine does is to mark the thread as terminated and
+    * wake it if possible. The thread will then kill itself when it
+    * next exits kernel mode.
+    */
    Thread->DeadThread = 1;
    Thread->ExitStatus = ExitStatus;
+   Thread->Tcb.ApcState.UserApcPending++;
    if (Thread->Tcb.State == THREAD_STATE_FROZEN && 
        (Thread->Tcb.Alertable || Thread->Tcb.WaitMode == UserMode))
      {
@@ -254,7 +261,8 @@ NTSTATUS STDCALL PsTerminateSystemThread(NTSTATUS ExitStatus)
    return(STATUS_SUCCESS);
 }
 
-NTSTATUS STDCALL NtCallTerminatePorts(PETHREAD Thread)
+NTSTATUS STDCALL 
+NtCallTerminatePorts(PETHREAD Thread)
 {
    KIRQL oldIrql;
    PLIST_ENTRY current_entry;
@@ -276,7 +284,8 @@ NTSTATUS STDCALL NtCallTerminatePorts(PETHREAD Thread)
    return(STATUS_SUCCESS);
 }
 
-NTSTATUS STDCALL NtRegisterThreadTerminatePort(HANDLE TerminationPortHandle)
+NTSTATUS STDCALL 
+NtRegisterThreadTerminatePort(HANDLE TerminationPortHandle)
 {
    NTSTATUS Status;
    PEPORT_TERMINATION_REQUEST Request;