Browse Source

BIOS loader fixups, should kinda work in vmware?

K. Lange 2 years ago
parent
commit
e6f8d0fae1
3 changed files with 18 additions and 14 deletions
  1. 12 13
      boot/atapi_imp.h
  2. 5 0
      boot/boot.s
  3. 1 1
      boot/moremultiboot.h

+ 12 - 13
boot/atapi_imp.h

@@ -197,25 +197,24 @@ _try_again:
 		outports(bus, command.command_words[i]);
 	}
 
+	uint16_t size_to_read = dev->atapi_sector_size;
 
 	for (int i = 0; i < sectors; ++i) {
-	while (1) {
-		uint8_t status = inportb(dev->io_base + ATA_REG_STATUS);
-		if ((status & ATA_SR_ERR)) goto atapi_error_on_read_setup_cmd;
-		if (!(status & ATA_SR_BSY) && (status & ATA_SR_DRQ)) break;
-	}
-		uint16_t size_to_read = inportb(bus + ATA_REG_LBA2) << 8;
-		size_to_read = size_to_read | inportb(bus + ATA_REG_LBA1);
+		while (1) {
+			uint8_t status = inportb(dev->io_base + ATA_REG_STATUS);
+			if ((status & ATA_SR_ERR)) goto atapi_error_on_read_setup_cmd;
+			if (!(status & ATA_SR_BSY) && (status & ATA_SR_DRQ)) break;
+		}
 
 		inportsm(bus,buf,size_to_read/2);
 
-		buf += 2048;
+		buf += size_to_read;
 
-	while (1) {
-		uint8_t status = inportb(dev->io_base + ATA_REG_STATUS);
-		if ((status & ATA_SR_ERR)) goto atapi_error_on_read_setup;
-		if (!(status & ATA_SR_BSY) && (status & ATA_SR_DRDY)) break;
-	}
+		while (1) {
+			uint8_t status = inportb(dev->io_base + ATA_REG_STATUS);
+			if ((status & ATA_SR_ERR)) goto atapi_error_on_read_setup;
+			if (!(status & ATA_SR_BSY) && (status & ATA_SR_DRDY)) break;
+		}
 	}
 
 	return;

+ 5 - 0
boot/boot.s

@@ -1,7 +1,12 @@
 [bits 16]
 main:
+	jmp far 0x000:0x7c05
+main2:
 	mov ax, 0x0000
 	mov ds, ax
+	mov ss, ax
+	mov ax, 0x7b00
+	mov sp, ax
 	mov ax, 0x0500
 	mov es, ax
 

+ 1 - 1
boot/moremultiboot.h

@@ -487,7 +487,7 @@ done:
 
 				int i = dir_entry->extent_start_LSB;
 				int sectors = dir_entry->extent_length_LSB / 2048 + 1;
-#define SECTORS 65536
+#define SECTORS 512
 				while (sectors >= SECTORS) {
 					print_(".");
 					ata_device_read_sectors_atapi(device, i, (uint8_t *)KERNEL_LOAD_START + offset, SECTORS);