video/palette.c
video/video.c)
+list(APPEND FREELDR_BASE_ASM_SOURCE)
+
if(ARCH STREQUAL "i386")
+ list(APPEND FREELDR_BASE_ASM_SOURCE
+ arch/i386/multiboot.S)
+
list(APPEND FREELDR_COMMON_ASM_SOURCE
+ arch/i386/drvmap.S
arch/i386/entry.S
arch/i386/int386.S
arch/i386/pnpbios.S
arch/i386/i386trap.S
- arch/i386/linux.S
- arch/i386/mb.S)
+ arch/i386/linux.S)
list(APPEND FREELDR_NTLDR_SOURCE
ntldr/arch/i386/winldr.c
arch/i386/xboxrtc.c
arch/i386/xboxvideo.c
disk/scsiport.c)
- if(NOT MSVC)
- list(APPEND FREELDR_COMMON_ASM_SOURCE arch/i386/drvmap.S)
- endif()
elseif(ARCH STREQUAL "amd64")
list(APPEND FREELDR_COMMON_ASM_SOURCE
add_pch(freeldr_common include/freeldr.h PCH_SOURCE)
add_dependencies(freeldr_common bugcodes asm xdk)
-if(ARCH STREQUAL "i386" AND NOT MSVC)
- list(APPEND FREELDR_BASE_SOURCE arch/i386/multiboot.S)
## GCC builds need this extra thing for some reason...
+if(ARCH STREQUAL "i386" AND NOT MSVC)
target_link_libraries(freeldr_common mini_hal)
endif()
+add_asm_files(freeldr_base_asm ${FREELDR_BASE_ASM_SOURCE})
+
list(APPEND FREELDR_BASE_SOURCE
+ ${freeldr_base_asm}
bootmgr.c # This file is compiled with custom definitions
freeldr.c
ntldr/setupldr.c ## Strangely enough this file is needed in GCC builds
#include <freeldr.h>
#include <debug.h>
-DBG_DEFAULT_CHANNEL(WARNING);
+DBG_DEFAULT_CHANNEL(DISK);
BOOLEAN DriveMapInstalled = FALSE; // Tells us if we have already installed our drive map int 13h handler code
ULONG OldInt13HandlerAddress = 0; // Address of BIOS int 13h handler
ULONG DriveMapHandlerAddress = 0; // Linear address of our drive map handler
ULONG DriveMapHandlerSegOff = 0; // Segment:offset style address of our drive map handler
-#ifndef _MSC_VER
VOID DriveMapMapDrivesInSection(PCSTR SectionName)
{
CHAR SettingName[80];
CHAR SettingValue[80];
CHAR Drive1[80];
CHAR Drive2[80];
- ULONG SectionId;
+ ULONG_PTR SectionId;
ULONG SectionItemCount;
ULONG Index;
ULONG Index2;
return TRUE;
}
-#endif
UCHAR DriveMapGetBiosDriveNumber(PCSTR DeviceName)
{
return BiosDriveNumber;
}
-#ifndef _MSC_VER
VOID DriveMapInstallInt13Handler(PDRIVE_MAP_LIST DriveMap)
{
ULONG* RealModeIVT = (ULONG*)0x00000000;
DriveMapInstalled = FALSE;
}
}
-#endif
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-
#include <asm.inc>
#include <arch/pc/x86common.h>
PUBLIC _DriveMapInt13HandlerStart
_DriveMapInt13HandlerStart:
-Int13Handler:
+Int13Handler:
push bp
mov bp, sp
push ax
mov word ptr cs:[CallersFlags - Int13Handler], ax
/* Save the drive number they passed in */
- mov cs:[PassedInDriveNumber - Int13Handler], dl
+ mov byte ptr cs:[PassedInDriveNumber - Int13Handler], dl
/* Now we need to perform the mapping */
xor cx, cx
mov si, offset Int13HandlerMapCount - Int13Handler
/* Get the count of drives in the map list */
- mov cl, cs:[si]
+ mov cl, byte ptr cs:[si]
inc si
/* If the map list is empty then just call the old int 13h handler */
GetMappedDriveNumberLoop:
- /* Get the next drive number in the list */
- lods ax, cs:[si]
+ /* Get the next drive number in the list (store it in AX) */
+ lods word ptr cs:[si]
/* Check to see if it's the one they are calling int 13h for */
cmp dl, al
/* Put flags onto stack */
push word ptr cs:[CallersFlags - Int13Handler]
-
/* Call old int 13h handler with new drive number */
.byte HEX(9a) /* lcall */
PUBLIC _DriveMapOldInt13HandlerAddress
pop ax
/* Restore the callers drive number */
- mov dl, cs:[PassedInDriveNumber - Int13Handler]
+ mov dl, byte ptr cs:[PassedInDriveNumber - Int13Handler]
pop bp
PassedInDriveNumber:
.byte 0
+/* See the DRIVE_MAP_LIST structure in include/arch/i386/drivemap.h */
PUBLIC _DriveMapInt13HandlerMapList
_DriveMapInt13HandlerMapList:
Int13HandlerMapCount:
PUBLIC _DriveMapInt13HandlerEnd
_DriveMapInt13HandlerEnd:
+
+.endcode16
+
+END
EXTERN _InitIdt:PROC
EXTERN _i386Idt:DWORD
//EXTERN _i386idtptr:FWORD
-// EXTERN cmdline:DWORD
+EXTERN cmdline:DWORD
#ifdef _USE_ML
EXTERN __bss_start__:DWORD
call _InitIdt
/* Pass the command line to BootMain */
- // mov eax, offset cmdline
- xor eax, eax
+ mov eax, offset cmdline
/* GO! */
push eax
+++ /dev/null
-/*
- * FreeLoader
- * Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#include <asm.inc>
-#include <arch/pc/x86common.h>
-#include <multiboot.h>
-
-.code32
-PUBLIC _PageDirectoryStart
-
-PUBLIC _startup_pagedirectory
-PUBLIC _lowmem_pagetable
-PUBLIC _kernel_pagetable
-PUBLIC _apic_pagetable
-PUBLIC _PageDirectoryEnd
-
-#ifndef _USE_ML
-.bss
-#endif
-_PageDirectoryStart:
-_startup_pagedirectory:
- .fill 4096, 1, 0
-
-_lowmem_pagetable:
- .fill 4096, 1, 0
-
-_kernel_pagetable:
- .fill 2*4096, 1, 0
-
-_apic_pagetable:
- .fill 4096, 1, 0
-
-_PageDirectoryEnd:
-
-END
*/
#define INITIAL_BASE HEX(200000)
+
+#ifdef _USE_ML
+EXTERN __bss_start__:DWORD
+EXTERN __bss_end__:DWORD
+#endif
+
+
+#ifdef _USE_ML
+.MBDATA SEGMENT PUBLIC 'DATA'
+ASSUME nothing
+#endif
+
/* Align to 32 bits boundary */
.align 4
/* checksum */
.long -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
/* header_addr */
- .long INITIAL_BASE + MultibootHeader - FREELDR_BASE
+ .long MultibootHeader + INITIAL_BASE - FREELDR_BASE
/* load_addr */
.long INITIAL_BASE
/* load_end_addr */
/* bss_end_addr */
.long 0
/* entry_addr */
- .long INITIAL_BASE + MultibootEntry - FREELDR_BASE
+ .long MultibootEntry + INITIAL_BASE - FREELDR_BASE
+
+#ifdef _USE_ML
+.MBDATA ENDS
+#endif
+
+
+.code32
+ASSUME ES:NOTHING, FS:NOTHING, GS:NOTHING
MultibootEntry:
cld
+ /* Check for valid multiboot signature */
+ cmp eax, MULTIBOOT_BOOTLOADER_MAGIC
+ jne mbfail
+
/* Save command line */
- test dword ptr [ebx + MB_INFO_FLAGS_OFFSET], MB_INFO_FLAG_COMMAND_LINE
+ test dword ptr ds:[ebx + MB_INFO_FLAGS_OFFSET], MB_INFO_FLAG_COMMAND_LINE
jz mb2
- mov esi, [ebx + MB_INFO_COMMAND_LINE_OFFSET]
+ mov esi, dword ptr ds:[ebx + MB_INFO_COMMAND_LINE_OFFSET]
mov edi, offset cmdline + INITIAL_BASE - FREELDR_BASE
mov ecx, CMDLINE_SIZE - 1
mb1:
mb2:
/* See if the boot device was passed in */
- test dword ptr [ebx + MB_INFO_FLAGS_OFFSET], MB_INFO_FLAG_BOOT_DEVICE
+ test dword ptr ds:[ebx + MB_INFO_FLAGS_OFFSET], MB_INFO_FLAG_BOOT_DEVICE
/* If no boot device known, assume first partition of first harddisk */
mov dx, HEX(0180)
jz mb3
/* Load boot drive into DL, boot partition into DH */
- mov edx, [ebx + MB_INFO_BOOT_DEVICE_OFFSET]
+ mov edx, dword ptr ds:[ebx + MB_INFO_BOOT_DEVICE_OFFSET]
bswap edx
inc dh
rep movsd
/* Load segment registers for real-address mode */
- lgdt gdtptr
+#ifdef _USE_ML
+ lgdt fword ptr ds:[gdtptr]
+#else
+ lgdt ds:[gdtptr]
+#endif
mov ax, HEX(10)
mov ds, ax
mov es, ax
/* Jump to relocated code */
ljmp HEX(08), mb4
+mbfail:
+ int 3
+mbstop:
+ jmp short mbstop /* We should never get here */
+
.code16
mb4:
/* Disable protected mode */
/* Jump to real entry point */
ljmp16 0, FREELDR_BASE
+.endcode16
+
/* Force 8-byte alignment */
.align 8
gdt:
- /* 16-bit flat CS (!) */
- .word HEX(FFFF)
- .word HEX(0000)
- .word HEX(9B00)
- .word HEX(008F)
-
- /* 16-bit real mode DS */
- .word HEX(FFFF)
- .word HEX(0000)
- .word HEX(9300)
- .word HEX(0000)
-
- /* GDT pointer */
+ .word HEX(0000), HEX(0000), HEX(0000), HEX(0000) /* 00: NULL descriptor */
+ .word HEX(FFFF), HEX(0000), HEX(9B00), HEX(008F) /* 08: 16-bit flat CS (!) */
+ .word HEX(FFFF), HEX(0000), HEX(9300), HEX(0000) /* 10: 16-bit real mode DS */
+
+/* GDT table pointer */
gdtptr:
- .word HEX(17) /* Limit */
- .long gdt - 8 /* Base Address */
+ .word HEX(17) /* Limit */
+ .long gdt /* Base Address */
PUBLIC cmdline
cmdline:
}
}
+#if defined(_M_IX86)
/* Install the drive mapper according to this section drive mappings */
-#if defined(_M_IX86) && !defined(_MSC_VER)
DriveMapMapDrivesInSection(SectionName);
#endif
* Otherwise they are kept separated, unless an explicit /MERGE is used.
*/
-#pragma comment(linker, "/SECTION:.text,ERW /SECTION:.data,RW /MERGE:INIT=.text /MERGE:.edata=.rdata")
+#pragma comment(linker, "/SECTION:.text,ERW /SECTION:.data,RW /MERGE:.MBDATA=.text /MERGE:INIT=.text /MERGE:.edata=.rdata")
#endif
#define LMODE_DS HEX(18)
#define CMODE_CS HEX(30)
//#endif
-
-/* Makes "x" a global variable or label */
-#define EXTERN(x) .global x; x: