From 198a54413833171a118b952679e35a5c04000100 Mon Sep 17 00:00:00 2001 From: Brian Palmer Date: Wed, 23 Jan 2002 19:57:42 +0000 Subject: [PATCH] Removed code to save screen contents before entering freeldr Moved all architecture specific code to the arch & arch/i386 directories Renamed asmcode.* to arch.* svn path=/trunk/; revision=2545 --- freeldr/bootsect/fat.asm | 18 - freeldr/bootsect/fat32.asm | 18 - freeldr/freeldr/Makefile | 49 +- freeldr/freeldr/{asmcode.h => arch.h} | 4 - freeldr/freeldr/arch/Makefile | 33 ++ freeldr/freeldr/arch/i386/Makefile | 50 ++ .../freeldr/{asmcode.S => arch/i386/arch.S} | 486 +---------------- freeldr/freeldr/{ => arch/i386}/boot.S | 2 +- freeldr/freeldr/arch/i386/disk.S | 515 ++++++++++++++++++ freeldr/freeldr/{ => arch/i386}/mb.S | 2 +- freeldr/freeldr/{ => arch/i386}/mem.S | 2 +- freeldr/freeldr/cache/blocklist.c | 2 +- freeldr/freeldr/disk/disk.c | 2 +- freeldr/freeldr/freeldr.c | 12 +- freeldr/freeldr/freeldr.h | 4 - freeldr/freeldr/fs/fat.c | 2 +- freeldr/freeldr/fs/fs.c | 2 +- freeldr/freeldr/linux.c | 2 +- freeldr/freeldr/miscboot.c | 2 +- freeldr/freeldr/multiboot.c | 2 +- freeldr/freeldr/reactos/reactos.c | 4 +- freeldr/freeldr/rules.mk | 4 +- 22 files changed, 635 insertions(+), 582 deletions(-) rename freeldr/freeldr/{asmcode.h => arch.h} (87%) create mode 100644 freeldr/freeldr/arch/Makefile create mode 100644 freeldr/freeldr/arch/i386/Makefile rename freeldr/freeldr/{asmcode.S => arch/i386/arch.S} (52%) rename freeldr/freeldr/{ => arch/i386}/boot.S (98%) create mode 100644 freeldr/freeldr/arch/i386/disk.S rename freeldr/freeldr/{ => arch/i386}/mb.S (99%) rename freeldr/freeldr/{ => arch/i386}/mem.S (99%) diff --git a/freeldr/bootsect/fat.asm b/freeldr/bootsect/fat.asm index c541c935989..94d4ab34500 100644 --- a/freeldr/bootsect/fat.asm +++ b/freeldr/bootsect/fat.asm @@ -276,24 +276,6 @@ LoadFile: push ax ; First save AX - the start cluster of freeldr.sys - ; Lets save the contents of the screen - ; from B800:0000 to 9000:8000 - push ds - mov ax,0b800h - mov ds,ax - xor si,si - mov ax,9800h - mov es,ax - xor di,di - mov cx,2000 ; Copy 2000 characters [words] (screen is 80x25) - rep movsw ; 2 bytes a character (one is the attribute byte) - pop ds - - mov ah,03h ; AH = 03h - xor bx,bx ; BH = video page - int 10h ; BIOS Int 10h Func 3 - Read Cursor Position and Size - mov [es:di],dx ; DH = row, DL = column - ; Display "Loading FreeLoader..." message mov si,msgLoading ; Loading message call PutChars ; Display it diff --git a/freeldr/bootsect/fat32.asm b/freeldr/bootsect/fat32.asm index 61264184ee7..619f4771b66 100644 --- a/freeldr/bootsect/fat32.asm +++ b/freeldr/bootsect/fat32.asm @@ -332,24 +332,6 @@ FindFile: FoundFile: - ; Lets save the contents of the screen - ; from B800:0000 to 9000:8000 - pushad - - mov ax,0b800h - mov ds,ax - xor si,si - mov ax,9800h - mov es,ax - xor di,di - mov cx,2000 ; Copy 2000 characters (screen is 80x25) - rep movsw ; 2 bytes a character (one is the attribute byte) - - mov ah,03h ; AH = 03h - xor bx,bx ; BH = video page - int 10h ; BIOS Int 10h Func 3 - Read Cursor Position and Size - mov [es:di],dx ; DH = row, DL = column - ; Display "Loading FreeLoader..." message mov si,msgLoading ; Loading message call PutChars ; Display it diff --git a/freeldr/freeldr/Makefile b/freeldr/freeldr/Makefile index 25d1b0977e7..2b095141d58 100644 --- a/freeldr/freeldr/Makefile +++ b/freeldr/freeldr/Makefile @@ -23,47 +23,36 @@ include rules.mk #OBJS = asmcode.a asmcode.o mb.o boot.o freeldr.o rtl.o fs.a fs.o fat.o \ # reactos.o tui.o menu.o miscboot.o options.o linux.o multiboot.o arcname.o \ # mem.o memory.o debug.o parseini.o registry.o import.o -ASM_OBJS = asmcode.o mb.o boot.o mem.o +#ASM_OBJS = asmcode.o mb.o boot.o mem.o OBJS = freeldr.o miscboot.o options.o linux.o multiboot.o debug.o parseini.o oslist.o -LIBS = rtl fs ui reactos comm disk mm cache -LIB_FILES = rtl/rtl.a fs/fs.a ui/ui.a reactos/reactos.a comm/comm.a disk/disk.a mm/mm.a cache/cache.a +LIBS = arch rtl fs ui reactos comm disk mm cache +LIB_FILES = arch/arch.a rtl/rtl.a fs/fs.a ui/ui.a reactos/reactos.a +LIB_FILES2 = comm/comm.a disk/disk.a mm/mm.a cache/cache.a .PHONY : clean all: freeldr.sys -freeldr.sys: asmcode.a c_code.a - $(LD) -N -Ttext=0x8000 --oformat=binary -s -o f.sys asmcode.a c_code.a +freeldr.sys: c_code.a + $(LD) -N -Ttext=0x8000 --oformat=binary -s -o f.sys c_code.a ../bootsect/stubit ../bootsect/fatstub.bin f.sys freeldr.sys freeldr.exe: asmcode.a c_code.a $(LD) -o freeldr.exe asmcode.a c_code.a -asmcode.a: $(ASM_OBJS) - $(LD) -r -o asmcode.a $(ASM_OBJS) +c_code.a: $(LIBS) c_code1.a c_code2.a + $(LD) -r -o c_code.a $(LIB_FILES) c_code1.a c_code2.a -c_code.a: c_code1.a $(LIBS) - $(LD) -r -o c_code.a c_code1.a $(LIB_FILES) +c_code1.a: $(LIBS) + $(LD) -r -o c_code1.a $(LIB_FILES2) -c_code1.a: $(OBJS) - $(LD) -r -o c_code1.a $(OBJS) +c_code2.a: $(OBJS) + $(LD) -r -o c_code2.a $(OBJS) -asmcode.o: asmcode.S asmcode.h - $(CC) $(FLAGS) -o asmcode.o -c asmcode.S - -mb.o: mb.S asmcode.h multiboot.h - $(CC) $(FLAGS) -o mb.o -c mb.S - -boot.o: boot.S asmcode.h - $(CC) $(FLAGS) -o boot.o -c boot.S - -mem.o: mem.S asmcode.h - $(CC) $(FLAGS) -o mem.o -c mem.S - -freeldr.o: freeldr.c freeldr.h rtl.h fs.h reactos.h ui.h asmcode.h miscboot.h +freeldr.o: freeldr.c freeldr.h rtl.h fs.h reactos.h ui.h arch.h miscboot.h $(CC) $(FLAGS) -o freeldr.o -c freeldr.c -miscboot.o: miscboot.c freeldr.h asmcode.h rtl.h fs.h ui.h miscboot.h +miscboot.o: miscboot.c freeldr.h arch.h rtl.h fs.h ui.h miscboot.h $(CC) $(FLAGS) -o miscboot.o -c miscboot.c options.o: options.c freeldr.h rtl.h ui.h options.h @@ -75,15 +64,18 @@ linux.o: linux.c freeldr.h rtl.h ui.h linux.h multiboot.o: multiboot.c freeldr.h rtl.h fs.h multiboot.h ui.h $(CC) $(FLAGS) -o multiboot.o -c multiboot.c -debug.o: debug.c debug.h Makefile +debug.o: debug.c debug.h $(CC) $(FLAGS) -o debug.o -c debug.c -parseini.o: parseini.c parseini.h Makefile +parseini.o: parseini.c parseini.h $(CC) $(FLAGS) -o parseini.o -c parseini.c -oslist.o: oslist.c oslist.h Makefile +oslist.o: oslist.c oslist.h $(CC) $(FLAGS) -o oslist.o -c oslist.c +arch: + $(MAKE) -C arch + rtl: $(MAKE) -C rtl @@ -114,6 +106,7 @@ clean: - $(RM) *.o - $(RM) *.a - $(RM) *.sys + $(MAKE) -C arch clean $(MAKE) -C reactos clean $(MAKE) -C comm clean $(MAKE) -C disk clean diff --git a/freeldr/freeldr/asmcode.h b/freeldr/freeldr/arch.h similarity index 87% rename from freeldr/freeldr/asmcode.h rename to freeldr/freeldr/arch.h index 513c2d95772..368b4473f74 100644 --- a/freeldr/freeldr/asmcode.h +++ b/freeldr/freeldr/arch.h @@ -43,10 +43,6 @@ #define DISKREADBUFFER 0x90000 /* Buffer to store data read in from the disk via the BIOS */ -#define SCREENBUFFER 0x98000 /* The screen contents will be saved here */ -#define SCREENXCOORD 0x98FA0 /* Address of the byte that contains the current column of the cursor */ -#define SCREENYCOORD 0x98FA1 /* Address of the byte that contains the current row of the cursor */ - /* Makes "x" a global variable or label */ #define EXTERN(x) .global x; x: diff --git a/freeldr/freeldr/arch/Makefile b/freeldr/freeldr/arch/Makefile new file mode 100644 index 00000000000..5c4685edb65 --- /dev/null +++ b/freeldr/freeldr/arch/Makefile @@ -0,0 +1,33 @@ +# +# FreeLoader +# Copyright (C) 1998-2002 Brian Palmer +# +# 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., 675 Mass Ave, Cambridge, MA 02139, USA. +# + +include ../rules.mk + +TARGET = i386 + +.PHONY : clean + +all: arch.a + +arch.a: + $(MAKE) -C $(TARGET) + +clean: + - $(RM) *.a + $(MAKE) -C $(TARGET) clean diff --git a/freeldr/freeldr/arch/i386/Makefile b/freeldr/freeldr/arch/i386/Makefile new file mode 100644 index 00000000000..9f33c68ad0e --- /dev/null +++ b/freeldr/freeldr/arch/i386/Makefile @@ -0,0 +1,50 @@ +# +# FreeLoader +# Copyright (C) 1998-2002 Brian Palmer +# +# 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., 675 Mass Ave, Cambridge, MA 02139, USA. +# + +include ../../rules.mk + +OBJS = arch.o boot.o mb.o mem.o disk.o + +.PHONY : clean + +all: arch.a + +arch.a: $(OBJS) + $(LD) -r -o arch.a $(OBJS) + - $(RM) ..\arch.a + $(CP) arch.a ..\arch.a + +arch.o: arch.S + $(CC) $(FLAGS) -o arch.o -c arch.S + +boot.o: boot.S + $(CC) $(FLAGS) -o boot.o -c boot.S + +mb.o: mb.S + $(CC) $(FLAGS) -o mb.o -c mb.S + +mem.o: mem.S + $(CC) $(FLAGS) -o mem.o -c mem.S + +disk.o: disk.S + $(CC) $(FLAGS) -o disk.o -c disk.S + +clean: + - $(RM) *.o + - $(RM) *.a diff --git a/freeldr/freeldr/asmcode.S b/freeldr/freeldr/arch/i386/arch.S similarity index 52% rename from freeldr/freeldr/asmcode.S rename to freeldr/freeldr/arch/i386/arch.S index 29068bc0612..3d1b1db9ec6 100644 --- a/freeldr/freeldr/asmcode.S +++ b/freeldr/freeldr/arch/i386/arch.S @@ -21,7 +21,7 @@ .code16 #define ASM -#include "asmcode.h" +#include "arch.h" EXTERN(start) @@ -375,312 +375,6 @@ EXTERN(_gotoxy) pop %ebp ret -/* - * BOOL BiosInt13Read(ULONG Drive, ULONG Head, ULONG Track, ULONG Sector, ULONG SectorCount, PVOID Buffer); - */ -_biosdisk_drive: - .long 0 -_biosdisk_head: - .long 0 -_biosdisk_track: - .long 0 -_biosdisk_sector: - .long 0 -_biosdisk_nsects: - .long 0 -_biosdisk_buffer: - .long 0 -_biosdisk_retval: - .long 0 -_biosdisk_retrycount: - .byte 0 -_biosdisk_error_code: - .byte 0 -EXTERN(_BiosInt13Read) - .code32 - - push %ebp - push %esi - push %edi - push %ebx - push %ecx - push %edx - - /* Get parameters */ - movl 0x1c(%esp),%eax - movl %eax,_biosdisk_drive - movl 0x20(%esp),%eax - movl %eax,_biosdisk_head - movl 0x24(%esp),%eax - movl %eax,_biosdisk_track - movl 0x28(%esp),%eax - movl %eax,_biosdisk_sector - movl 0x2c(%esp),%eax - movl %eax,_biosdisk_nsects - movl 0x30(%esp),%eax - movl %eax,_biosdisk_buffer - - call switch_to_real - - .code16 - pushw %es // Save this just in case - movb $3,_biosdisk_retrycount // Set the retry count to 3 - -_biosdisk_read: - movl _biosdisk_buffer,%eax // Get buffer address in eax - shrl $4,%eax // Make linear address into segment - movw %ax,%es // Load ES with segment - movl _biosdisk_buffer,%ebx // and BX with offset - andl $0x0f,%ebx // so that data gets loaded to [ES:BX] - movb _biosdisk_sector,%cl // Get the sector in CL - movw _biosdisk_track,%ax // Cylinder in AX - movb %al,%ch // Now put it in CH - rorb $1,%ah // Low 8 bits of cylinder in CH, high 2 bits - rorb $1,%ah // in CL shifted to bits 6 & 7 - andb $0xc0,%ah // Clear out low six bits - orb %ah,%cl // Or with sector number - movb _biosdisk_head,%dh // Get the head - movb _biosdisk_drive,%dl // Get the drive - movb $2,%ah // BIOS int 0x13, function 2 - Read Disk Sectors - movb _biosdisk_nsects,%al // Number of sectors to read - int $0x13 // Read a sector - - // I have recently learned that not all bioses return - // the sector read count in the AL register (at least mine doesn't) - // even if the sectors were read correctly. So instead - // of checking the sector read count we will rely solely - // on the carry flag being set on error - - //jmp _biosdisk_done - //cmpb _biosdisk_nsects,%al // See how many sectors we actually read - //jne _biosdisk_error // Jump if no error - - movb $1,%al // Set the return value to be one (will be set to zero later if needed) - jc _biosdisk_error // Jump if error (CF = 1 on error) - jmp _biosdisk_done - - -_biosdisk_error: - movb %ah,_biosdisk_error_code// Save the error code - - cmpb $0x11,%ah // Check and see if it was a corrected ECC error - je _biosdisk_done // If so then the data is still good, if not fail - - movb _biosdisk_retrycount,%al// Get the current retry count - decb %al // Decrement it - movb %al,_biosdisk_retrycount// Save it - cmpb $0,%al // Is it zero? - jz _biosdisk_zero // Yes, return zero - - movb $0,%ah // BIOS int 0x13, function 0 - Reset Disk System - movb _biosdisk_drive,%dl // Get the drive - int $0x13 // Reset the disk system - jmp _biosdisk_read // Try reading again - -_biosdisk_zero: - movb $0,%al // We will return zero - -_biosdisk_done: - movzbl %al,%eax // Put the number of sectors read into EAX - movl %eax,_biosdisk_retval // Save it as the return value - - popw %es // Restore ES - call switch_to_prot - - .code32 - - movl _biosdisk_retval,%eax // Get return value - //movl $1,%eax - - pop %edx - pop %ecx - pop %ebx - pop %edi - pop %esi - pop %ebp - ret - -/* - * BOOL BiosInt13ReadExtended(ULONG Drive, ULONG Sector, ULONG SectorCount, PVOID Buffer); - */ -_disk_address_packet: -_packet_size: - .byte 0x10 -_packet_reserved: - .byte 0 -_packet_sector_count: - .word 0 -_packet_transfer_buffer_segment: - .word 0 -_packet_transfer_buffer_offset: - .word 0 -_packet_lba_sector_number: - .quad 0 -_packet_64bit_flat_address: - .quad 0 -_int13_extended_drive: - .long 0 -_int13_extended_sector_count: - .long 0 -_int13_extended_retval: - .long 0 -_int13_extended_retrycount: - .byte 0 -EXTERN(_BiosInt13ReadExtended) - .code32 - - push %ebp - push %esi - push %edi - push %ebx - push %ecx - push %edx - - /* Get parameters */ - movl 0x1c(%esp),%eax - movl %eax,_int13_extended_drive - movl 0x20(%esp),%eax - movl %eax,_packet_lba_sector_number - movl 0x24(%esp),%eax - movw %ax,_packet_sector_count - movl %eax,_int13_extended_sector_count - movl 0x28(%esp),%eax // Get buffer address in eax - shrl $4,%eax // Make linear address into segment - movw %ax,_packet_transfer_buffer_segment // Save segment - movl 0x28(%esp),%eax // Get buffer address in eax - andl $0x0f,%eax // Make linear address into offset - movw %ax,_packet_transfer_buffer_offset // Save offset - - call switch_to_real - - .code16 - pushw %es // Save this just in case - movb $3,_int13_extended_retrycount // Set the retry count to 3 - -_int13_extended_read: - movb _int13_extended_drive,%dl // Get the drive - movb $42,%ah // BIOS int 0x13, function 42h - IBM/MS INT 13 Extensions - EXTENDED READ - movw $_disk_address_packet,%si // DS:SI -> disk address packet - int $0x13 // Read sectors - - movb $1,%al // Set the return value to be one (will be set to zero later if needed) - jc _int13_extended_error // Jump if error (CF = 1 on error) - - movl _int13_extended_sector_count,%eax // Get the sector count in eax - cmpw _packet_sector_count,%ax // See how many sectors we actually read (returned in disk address packet sector count) - jne _int13_extended_error // Jump if not equal - - jmp _int13_extended_done - - -_int13_extended_error: - movb %ah,_biosdisk_error_code // Save the error code - - cmpb $0x11,%ah // Check and see if it was a corrected ECC error - je _int13_extended_done // If so then the data is still good, if not fail - - movb _int13_extended_retrycount,%al // Get the current retry count - decb %al // Decrement it - movb %al,_int13_extended_retrycount // Save it - cmpb $0,%al // Is it zero? - jz _int13_extended_zero // Yes, return zero - - movb $0,%ah // BIOS int 0x13, function 0 - Reset Disk System - movb _int13_extended_drive,%dl // Get the drive - int $0x13 // Reset the disk system - jmp _int13_extended_read // Try reading again - -_int13_extended_zero: - movb $0,%al // We will return zero - -_int13_extended_done: - movzbl %al,%eax // Put the number of sectors read into EAX - movl %eax,_int13_extended_retval // Save it as the return value - - popw %es // Restore ES - call switch_to_prot - - .code32 - - movl _int13_extended_retval,%eax // Get return value - //movl $1,%eax - - pop %edx - pop %ecx - pop %ebx - pop %edi - pop %esi - pop %ebp - ret - -/* - * BOOL BiosInt13ExtensionsSupported(ULONG Drive); - */ -_int13_extension_check_drive: - .long 0 -_int13_extension_check_retval: - .long 0 -EXTERN(_BiosInt13ExtensionsSupported) - .code32 - - push %ebp - push %esi - push %edi - push %ebx - push %ecx - push %edx - - /* Get parameters */ - movl 0x1c(%esp),%eax - movl %eax,_int13_extension_check_drive - - call switch_to_real - - .code16 - // Now make sure this computer supports extended reads - movb $0x41,%ah // AH = 41h - movw $0x55aa,%bx // BX = 55AAh - movb _int13_extension_check_drive,%dl // DL = drive (80h-FFh) - int $0x13 // IBM/MS INT 13 Extensions - INSTALLATION CHECK - jc _int13_extension_check_error // CF set on error (extensions not supported) - cmpw $0x55aa,%bx // BX = AA55h if installed - jne _int13_extension_check_error - testb $1,%cl // CX = API subset support bitmap - jz _int13_extension_check_error // Bit 0, extended disk access functions (AH=42h-44h,47h,48h) supported - - // If we get here then we passed all the int13 extension tests - movl $1,_int13_extension_check_retval // Set return value to TRUE - jmp _int13_extension_check_done - -_int13_extension_check_error: - - movl $0,_int13_extension_check_retval // The tests failed so return FALSE - -_int13_extension_check_done: - - call switch_to_prot - - .code32 - - movl _int13_extension_check_retval,%eax // Get return value - - pop %edx - pop %ecx - pop %ebx - pop %edi - pop %esi - pop %ebp - ret - -/* - * ULONG BiosInt13GetLastErrorCode(VOID); - */ -EXTERN(_BiosInt13GetLastErrorCode) - .code32 - - movzbl _biosdisk_error_code,%eax // Get return value - - ret /* * int getyear(void); @@ -1110,184 +804,6 @@ EXTERN(_wherey) pop %ebp ret -/* - * void stop_floppy(void); - * - * Stops the floppy drive from spinning, so that other software is - * jumped to with a known state. - */ -EXTERN(_stop_floppy) - .code32 - - push %eax - push %edx - - call switch_to_real - - .code16 - - movw $0x3F2, %dx - xorb %al, %al - outb %al, %dx - - call switch_to_prot - - .code32 - - pop %edx - pop %eax - ret - -/* - * int get_heads(int drive); - */ -EXTERN(_get_heads) - .code32 - - push %ebx - push %ecx - push %edx - push %edi - push %es - - /* Get drive */ - movl 0x18(%esp),%eax - movl %eax,_biosdisk_drive - - call switch_to_real - - .code16 - - movb $0x08,%ah - movb _biosdisk_drive,%dl - int $0x13 - jc _get_heads_error - - incb %dh - movzbl %dh,%edx - movl %edx,_biosdisk_retval - jmp _get_heads_done - -_get_heads_error: - movl $0xff,_biosdisk_retval - -_get_heads_done: - - call switch_to_prot - - .code32 - - movl _biosdisk_retval,%eax // Get return value - - pop %es - pop %edi - pop %edx - pop %ecx - pop %ebx - - ret - -/* - * int get_cylinders(int drive); - */ -EXTERN(_get_cylinders) - .code32 - - push %ebx - push %ecx - push %edx - push %edi - push %es - - /* Get drive */ - movl 0x18(%esp),%eax - movl %eax,_biosdisk_drive - - call switch_to_real - - .code16 - - movb $0x08,%ah - movb _biosdisk_drive,%dl - int $0x13 - jc _get_cylinders_error - - xorl %edx,%edx - andb $0xc0,%cl - shrb $0x06,%cl - movb %cl,%dh - movb %ch,%dl - incl %edx - movl %edx,_biosdisk_retval - jmp _get_cylinders_done - -_get_cylinders_error: - movl $0xff,_biosdisk_retval - -_get_cylinders_done: - - call switch_to_prot - - .code32 - - movl _biosdisk_retval,%eax // Get return value - - pop %es - pop %edi - pop %edx - pop %ecx - pop %ebx - - ret - -/* - * int get_sectors(int drive); - */ -EXTERN(_get_sectors) - .code32 - - push %ebx - push %ecx - push %edx - push %edi - push %es - - /* Get drive */ - movl 0x18(%esp),%eax - movl %eax,_biosdisk_drive - - call switch_to_real - - .code16 - - movb $0x08,%ah - movb _biosdisk_drive,%dl - int $0x13 - jc _get_sectors_error - - andb $0x3f,%cl - movzbl %cl,%ecx - movl %ecx,_biosdisk_retval - jmp _get_sectors_done - -_get_sectors_error: - movl $0xff,_biosdisk_retval - -_get_sectors_done: - - call switch_to_prot - - .code32 - - movl _biosdisk_retval,%eax // Get return value - - pop %es - pop %edi - pop %edx - pop %ecx - pop %ebx - - ret /* diff --git a/freeldr/freeldr/boot.S b/freeldr/freeldr/arch/i386/boot.S similarity index 98% rename from freeldr/freeldr/boot.S rename to freeldr/freeldr/arch/i386/boot.S index 0a72dba9f58..ea8c8c231e0 100644 --- a/freeldr/freeldr/boot.S +++ b/freeldr/freeldr/arch/i386/boot.S @@ -21,7 +21,7 @@ .code16 #define ASM -#include "asmcode.h" +#include "arch.h" #include "multiboot.h" diff --git a/freeldr/freeldr/arch/i386/disk.S b/freeldr/freeldr/arch/i386/disk.S new file mode 100644 index 00000000000..0e8cdc55945 --- /dev/null +++ b/freeldr/freeldr/arch/i386/disk.S @@ -0,0 +1,515 @@ +/* + * FreeLoader + * Copyright (C) 1998-2002 Brian Palmer + * + * 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., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + + .text + .code16 + +#define ASM +#include "arch.h" + + +/* + * BOOL BiosInt13Read(ULONG Drive, ULONG Head, ULONG Track, ULONG Sector, ULONG SectorCount, PVOID Buffer); + */ +_biosdisk_drive: + .long 0 +_biosdisk_head: + .long 0 +_biosdisk_track: + .long 0 +_biosdisk_sector: + .long 0 +_biosdisk_nsects: + .long 0 +_biosdisk_buffer: + .long 0 +_biosdisk_retval: + .long 0 +_biosdisk_retrycount: + .byte 0 +_biosdisk_error_code: + .byte 0 +EXTERN(_BiosInt13Read) + .code32 + + push %ebp + push %esi + push %edi + push %ebx + push %ecx + push %edx + + /* Get parameters */ + movl 0x1c(%esp),%eax + movl %eax,_biosdisk_drive + movl 0x20(%esp),%eax + movl %eax,_biosdisk_head + movl 0x24(%esp),%eax + movl %eax,_biosdisk_track + movl 0x28(%esp),%eax + movl %eax,_biosdisk_sector + movl 0x2c(%esp),%eax + movl %eax,_biosdisk_nsects + movl 0x30(%esp),%eax + movl %eax,_biosdisk_buffer + + call switch_to_real + + .code16 + pushw %es // Save this just in case + movb $3,_biosdisk_retrycount // Set the retry count to 3 + +_biosdisk_read: + movl _biosdisk_buffer,%eax // Get buffer address in eax + shrl $4,%eax // Make linear address into segment + movw %ax,%es // Load ES with segment + movl _biosdisk_buffer,%ebx // and BX with offset + andl $0x0f,%ebx // so that data gets loaded to [ES:BX] + movb _biosdisk_sector,%cl // Get the sector in CL + movw _biosdisk_track,%ax // Cylinder in AX + movb %al,%ch // Now put it in CH + rorb $1,%ah // Low 8 bits of cylinder in CH, high 2 bits + rorb $1,%ah // in CL shifted to bits 6 & 7 + andb $0xc0,%ah // Clear out low six bits + orb %ah,%cl // Or with sector number + movb _biosdisk_head,%dh // Get the head + movb _biosdisk_drive,%dl // Get the drive + movb $2,%ah // BIOS int 0x13, function 2 - Read Disk Sectors + movb _biosdisk_nsects,%al // Number of sectors to read + int $0x13 // Read a sector + + // I have recently learned that not all bioses return + // the sector read count in the AL register (at least mine doesn't) + // even if the sectors were read correctly. So instead + // of checking the sector read count we will rely solely + // on the carry flag being set on error + + //jmp _biosdisk_done + //cmpb _biosdisk_nsects,%al // See how many sectors we actually read + //jne _biosdisk_error // Jump if no error + + movb $1,%al // Set the return value to be one (will be set to zero later if needed) + jc _biosdisk_error // Jump if error (CF = 1 on error) + jmp _biosdisk_done + + +_biosdisk_error: + movb %ah,_biosdisk_error_code// Save the error code + + cmpb $0x11,%ah // Check and see if it was a corrected ECC error + je _biosdisk_done // If so then the data is still good, if not fail + + movb _biosdisk_retrycount,%al// Get the current retry count + decb %al // Decrement it + movb %al,_biosdisk_retrycount// Save it + cmpb $0,%al // Is it zero? + jz _biosdisk_zero // Yes, return zero + + movb $0,%ah // BIOS int 0x13, function 0 - Reset Disk System + movb _biosdisk_drive,%dl // Get the drive + int $0x13 // Reset the disk system + jmp _biosdisk_read // Try reading again + +_biosdisk_zero: + movb $0,%al // We will return zero + +_biosdisk_done: + movzbl %al,%eax // Put the number of sectors read into EAX + movl %eax,_biosdisk_retval // Save it as the return value + + popw %es // Restore ES + call switch_to_prot + + .code32 + + movl _biosdisk_retval,%eax // Get return value + //movl $1,%eax + + pop %edx + pop %ecx + pop %ebx + pop %edi + pop %esi + pop %ebp + ret + +/* + * BOOL BiosInt13ReadExtended(ULONG Drive, ULONG Sector, ULONG SectorCount, PVOID Buffer); + */ +_disk_address_packet: +_packet_size: + .byte 0x10 +_packet_reserved: + .byte 0 +_packet_sector_count: + .word 0 +_packet_transfer_buffer_segment: + .word 0 +_packet_transfer_buffer_offset: + .word 0 +_packet_lba_sector_number: + .quad 0 +_packet_64bit_flat_address: + .quad 0 +_int13_extended_drive: + .long 0 +_int13_extended_sector_count: + .long 0 +_int13_extended_retval: + .long 0 +_int13_extended_retrycount: + .byte 0 +EXTERN(_BiosInt13ReadExtended) + .code32 + + push %ebp + push %esi + push %edi + push %ebx + push %ecx + push %edx + + /* Get parameters */ + movl 0x1c(%esp),%eax + movl %eax,_int13_extended_drive + movl 0x20(%esp),%eax + movl %eax,_packet_lba_sector_number + movl 0x24(%esp),%eax + movw %ax,_packet_sector_count + movl %eax,_int13_extended_sector_count + movl 0x28(%esp),%eax // Get buffer address in eax + shrl $4,%eax // Make linear address into segment + movw %ax,_packet_transfer_buffer_segment // Save segment + movl 0x28(%esp),%eax // Get buffer address in eax + andl $0x0f,%eax // Make linear address into offset + movw %ax,_packet_transfer_buffer_offset // Save offset + + call switch_to_real + + .code16 + pushw %es // Save this just in case + movb $3,_int13_extended_retrycount // Set the retry count to 3 + +_int13_extended_read: + movb _int13_extended_drive,%dl // Get the drive + movb $42,%ah // BIOS int 0x13, function 42h - IBM/MS INT 13 Extensions - EXTENDED READ + movw $_disk_address_packet,%si // DS:SI -> disk address packet + int $0x13 // Read sectors + + movb $1,%al // Set the return value to be one (will be set to zero later if needed) + jc _int13_extended_error // Jump if error (CF = 1 on error) + + movl _int13_extended_sector_count,%eax // Get the sector count in eax + cmpw _packet_sector_count,%ax // See how many sectors we actually read (returned in disk address packet sector count) + jne _int13_extended_error // Jump if not equal + + jmp _int13_extended_done + + +_int13_extended_error: + movb %ah,_biosdisk_error_code // Save the error code + + cmpb $0x11,%ah // Check and see if it was a corrected ECC error + je _int13_extended_done // If so then the data is still good, if not fail + + movb _int13_extended_retrycount,%al // Get the current retry count + decb %al // Decrement it + movb %al,_int13_extended_retrycount // Save it + cmpb $0,%al // Is it zero? + jz _int13_extended_zero // Yes, return zero + + movb $0,%ah // BIOS int 0x13, function 0 - Reset Disk System + movb _int13_extended_drive,%dl // Get the drive + int $0x13 // Reset the disk system + jmp _int13_extended_read // Try reading again + +_int13_extended_zero: + movb $0,%al // We will return zero + +_int13_extended_done: + movzbl %al,%eax // Put the number of sectors read into EAX + movl %eax,_int13_extended_retval // Save it as the return value + + popw %es // Restore ES + call switch_to_prot + + .code32 + + movl _int13_extended_retval,%eax // Get return value + //movl $1,%eax + + pop %edx + pop %ecx + pop %ebx + pop %edi + pop %esi + pop %ebp + ret + +/* + * BOOL BiosInt13ExtensionsSupported(ULONG Drive); + */ +_int13_extension_check_drive: + .long 0 +_int13_extension_check_retval: + .long 0 +EXTERN(_BiosInt13ExtensionsSupported) + .code32 + + push %ebp + push %esi + push %edi + push %ebx + push %ecx + push %edx + + /* Get parameters */ + movl 0x1c(%esp),%eax + movl %eax,_int13_extension_check_drive + + call switch_to_real + + .code16 + // Now make sure this computer supports extended reads + movb $0x41,%ah // AH = 41h + movw $0x55aa,%bx // BX = 55AAh + movb _int13_extension_check_drive,%dl // DL = drive (80h-FFh) + int $0x13 // IBM/MS INT 13 Extensions - INSTALLATION CHECK + jc _int13_extension_check_error // CF set on error (extensions not supported) + cmpw $0x55aa,%bx // BX = AA55h if installed + jne _int13_extension_check_error + testb $1,%cl // CX = API subset support bitmap + jz _int13_extension_check_error // Bit 0, extended disk access functions (AH=42h-44h,47h,48h) supported + + // If we get here then we passed all the int13 extension tests + movl $1,_int13_extension_check_retval // Set return value to TRUE + jmp _int13_extension_check_done + +_int13_extension_check_error: + + movl $0,_int13_extension_check_retval // The tests failed so return FALSE + +_int13_extension_check_done: + + call switch_to_prot + + .code32 + + movl _int13_extension_check_retval,%eax // Get return value + + pop %edx + pop %ecx + pop %ebx + pop %edi + pop %esi + pop %ebp + ret + +/* + * ULONG BiosInt13GetLastErrorCode(VOID); + */ +EXTERN(_BiosInt13GetLastErrorCode) + .code32 + + movzbl _biosdisk_error_code,%eax // Get return value + + ret + + +/* + * void stop_floppy(void); + * + * Stops the floppy drive from spinning, so that other software is + * jumped to with a known state. + */ +EXTERN(_stop_floppy) + .code32 + + push %eax + push %edx + + call switch_to_real + + .code16 + + movw $0x3F2, %dx + xorb %al, %al + outb %al, %dx + + call switch_to_prot + + .code32 + + pop %edx + pop %eax + ret + +/* + * int get_heads(int drive); + */ +EXTERN(_get_heads) + .code32 + + push %ebx + push %ecx + push %edx + push %edi + push %es + + /* Get drive */ + movl 0x18(%esp),%eax + movl %eax,_biosdisk_drive + + call switch_to_real + + .code16 + + movb $0x08,%ah + movb _biosdisk_drive,%dl + int $0x13 + jc _get_heads_error + + incb %dh + movzbl %dh,%edx + movl %edx,_biosdisk_retval + jmp _get_heads_done + +_get_heads_error: + movl $0xff,_biosdisk_retval + +_get_heads_done: + + call switch_to_prot + + .code32 + + movl _biosdisk_retval,%eax // Get return value + + pop %es + pop %edi + pop %edx + pop %ecx + pop %ebx + + ret + +/* + * int get_cylinders(int drive); + */ +EXTERN(_get_cylinders) + .code32 + + push %ebx + push %ecx + push %edx + push %edi + push %es + + /* Get drive */ + movl 0x18(%esp),%eax + movl %eax,_biosdisk_drive + + call switch_to_real + + .code16 + + movb $0x08,%ah + movb _biosdisk_drive,%dl + int $0x13 + jc _get_cylinders_error + + xorl %edx,%edx + andb $0xc0,%cl + shrb $0x06,%cl + movb %cl,%dh + movb %ch,%dl + incl %edx + movl %edx,_biosdisk_retval + jmp _get_cylinders_done + +_get_cylinders_error: + movl $0xff,_biosdisk_retval + +_get_cylinders_done: + + call switch_to_prot + + .code32 + + movl _biosdisk_retval,%eax // Get return value + + pop %es + pop %edi + pop %edx + pop %ecx + pop %ebx + + ret + +/* + * int get_sectors(int drive); + */ +EXTERN(_get_sectors) + .code32 + + push %ebx + push %ecx + push %edx + push %edi + push %es + + /* Get drive */ + movl 0x18(%esp),%eax + movl %eax,_biosdisk_drive + + call switch_to_real + + .code16 + + movb $0x08,%ah + movb _biosdisk_drive,%dl + int $0x13 + jc _get_sectors_error + + andb $0x3f,%cl + movzbl %cl,%ecx + movl %ecx,_biosdisk_retval + jmp _get_sectors_done + +_get_sectors_error: + movl $0xff,_biosdisk_retval + +_get_sectors_done: + + call switch_to_prot + + .code32 + + movl _biosdisk_retval,%eax // Get return value + + pop %es + pop %edi + pop %edx + pop %ecx + pop %ebx + + ret + + + diff --git a/freeldr/freeldr/mb.S b/freeldr/freeldr/arch/i386/mb.S similarity index 99% rename from freeldr/freeldr/mb.S rename to freeldr/freeldr/arch/i386/mb.S index 073753de03a..54ad30c8b0d 100644 --- a/freeldr/freeldr/mb.S +++ b/freeldr/freeldr/arch/i386/mb.S @@ -21,7 +21,7 @@ .code16 #define ASM -#include "asmcode.h" +#include "arch.h" #include "multiboot.h" /* diff --git a/freeldr/freeldr/mem.S b/freeldr/freeldr/arch/i386/mem.S similarity index 99% rename from freeldr/freeldr/mem.S rename to freeldr/freeldr/arch/i386/mem.S index 3b2bc3ee3c8..326ba0489fa 100644 --- a/freeldr/freeldr/mem.S +++ b/freeldr/freeldr/arch/i386/mem.S @@ -21,7 +21,7 @@ .code16 #define ASM -#include "asmcode.h" +#include "arch.h" #include "multiboot.h" diff --git a/freeldr/freeldr/cache/blocklist.c b/freeldr/freeldr/cache/blocklist.c index cde97663775..3b899b66d36 100644 --- a/freeldr/freeldr/cache/blocklist.c +++ b/freeldr/freeldr/cache/blocklist.c @@ -24,7 +24,7 @@ #include #include #include -#include +#include // Returns a pointer to a CACHE_BLOCK structure // Adds the block to the cache manager block list diff --git a/freeldr/freeldr/disk/disk.c b/freeldr/freeldr/disk/disk.c index 8017f9520dc..9abe85108b7 100644 --- a/freeldr/freeldr/disk/disk.c +++ b/freeldr/freeldr/disk/disk.c @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include diff --git a/freeldr/freeldr/freeldr.c b/freeldr/freeldr/freeldr.c index e9642a845c8..5d388581358 100644 --- a/freeldr/freeldr/freeldr.c +++ b/freeldr/freeldr/freeldr.c @@ -22,7 +22,7 @@ #include "fs.h" #include "reactos.h" #include "ui.h" -#include "asmcode.h" +#include "arch.h" #include "miscboot.h" #include "linux.h" #include "mm.h" @@ -35,10 +35,6 @@ //ULONG BootDrive = 0; // BIOS boot drive, 0-A:, 1-B:, 0x80-C:, 0x81-D:, etc. ULONG BootPartition = 0; // Boot Partition, 1-4 -PUCHAR ScreenBuffer = (PUCHAR)(SCREENBUFFER); // Save buffer for screen contents -ULONG CursorXPos = 0; // Cursor's X Position -ULONG CursorYPos = 0; // Cursor's Y Position - ULONG GetDefaultOperatingSystem(PUCHAR OperatingSystemList[], ULONG OperatingSystemCount); LONG GetTimeOut(VOID); @@ -57,9 +53,6 @@ VOID BootMain(VOID) enable_a20(); - CursorXPos = (ULONG) *((PUCHAR)(SCREENXCOORD)); - CursorYPos = (ULONG) *((PUCHAR)(SCREENYCOORD)); - #ifdef DEBUG DebugInit(); #endif @@ -139,9 +132,8 @@ VOID BootMain(VOID) reboot: - RestoreScreen(ScreenBuffer); + clrscr(); showcursor(); - gotoxy(CursorXPos, CursorYPos); return; } diff --git a/freeldr/freeldr/freeldr.h b/freeldr/freeldr/freeldr.h index c7f0dbff6fb..d6b1759fd26 100644 --- a/freeldr/freeldr/freeldr.h +++ b/freeldr/freeldr/freeldr.h @@ -72,10 +72,6 @@ extern ULONG BootDrive; // BIOS boot drive, 0-A:, 1-B:, 0x80-C:, 0x81-D:, etc extern ULONG BootPartition; // Boot Partition, 1-4 extern BOOL UserInterfaceUp; // Tells us if the user interface is displayed -extern PUCHAR ScreenBuffer; // Save buffer for screen contents -extern ULONG CursorXPos; // Cursor's X Position -extern ULONG CursorYPos; // Cursor's Y Position - void BootMain(void); #endif // defined __FREELDR_H diff --git a/freeldr/freeldr/fs/fat.c b/freeldr/freeldr/fs/fat.c index 99149c79cd2..a4f9e26e9c3 100644 --- a/freeldr/freeldr/fs/fat.c +++ b/freeldr/freeldr/fs/fat.c @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/freeldr/freeldr/fs/fs.c b/freeldr/freeldr/fs/fs.c index 46883785782..0e0861e28f6 100644 --- a/freeldr/freeldr/fs/fs.c +++ b/freeldr/freeldr/fs/fs.c @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include diff --git a/freeldr/freeldr/linux.c b/freeldr/freeldr/linux.c index 0e46f52c876..9a99c9a6ff3 100644 --- a/freeldr/freeldr/linux.c +++ b/freeldr/freeldr/linux.c @@ -19,7 +19,7 @@ #include "freeldr.h" -#include "asmcode.h" +#include "arch.h" #include "miscboot.h" #include "rtl.h" #include "fs.h" diff --git a/freeldr/freeldr/miscboot.c b/freeldr/freeldr/miscboot.c index 7ac55ee5930..07787ad295c 100644 --- a/freeldr/freeldr/miscboot.c +++ b/freeldr/freeldr/miscboot.c @@ -19,7 +19,7 @@ #include "freeldr.h" -#include "asmcode.h" +#include "arch.h" #include "miscboot.h" #include "rtl.h" #include "fs.h" diff --git a/freeldr/freeldr/multiboot.c b/freeldr/freeldr/multiboot.c index 8f43ac6fe62..dd54d152174 100644 --- a/freeldr/freeldr/multiboot.c +++ b/freeldr/freeldr/multiboot.c @@ -19,7 +19,7 @@ #include "freeldr.h" -#include "asmcode.h" +#include "arch.h" #include "rtl.h" #include "fs.h" #include "multiboot.h" diff --git a/freeldr/freeldr/reactos/reactos.c b/freeldr/freeldr/reactos/reactos.c index baf4942bd89..4657d6e4f54 100644 --- a/freeldr/freeldr/reactos/reactos.c +++ b/freeldr/freeldr/reactos/reactos.c @@ -19,7 +19,7 @@ */ #include -#include +#include #include #include #include @@ -646,8 +646,6 @@ void LoadAndBootReactOS(PUCHAR OperatingSystemName) strcat(name, "."); //MessageBox(name); - RestoreScreen(ScreenBuffer); - /* * Now boot the kernel */ diff --git a/freeldr/freeldr/rules.mk b/freeldr/freeldr/rules.mk index c9642ebee22..904b9c83abe 100644 --- a/freeldr/freeldr/rules.mk +++ b/freeldr/freeldr/rules.mk @@ -26,7 +26,7 @@ CP = cmd /C copy MAKE = make # For a release build uncomment this line -FLAGS = -Wall -nostdlib -nostdinc -fno-builtin -I./ -I../ -O3 +FLAGS = -Wall -nostdlib -nostdinc -fno-builtin -I./ -I../ -I../../ -O3 # For a debug build uncomment this line -#FLAGS = -Wall -nostdlib -nostdinc -fno-builtin -I./ -I../ -DDEBUG -O3 +#FLAGS = -Wall -nostdlib -nostdinc -fno-builtin -I./ -I../ -I../../ -DDEBUG -O3