mirror of
https://github.com/Tom-on64/kern.git
synced 2026-11-03 18:22:22 +00:00
Fixed diskRead() function and made it follow the defined standards. \nAlso made a temp fix to the disk.c issue (it's something about the disk.o obj file idk
This commit is contained in:
@@ -12,14 +12,15 @@ nasm -fbin ./src/boot.asm -o ./build/boot.bin
|
||||
echo "Assembling ./src/kernel/entry.asm..."
|
||||
nasm -felf32 ./src/kernel/entry.asm -o ./build/entry.o
|
||||
|
||||
for file in ./src/kernel/**.c; do
|
||||
for file in ./src/kernel/*.c; do
|
||||
filename=$(basename "$file" .c)
|
||||
echo "Compiling $file..."
|
||||
i386-elf-gcc -ffreestanding -Wall -Wextra -m32 -c $file -o ./build/$filename.o
|
||||
i386-elf-gcc -ffreestanding -Wall -Wextra -m32 -c "$file" -o "./build/$filename.o"
|
||||
done
|
||||
|
||||
echo "Linking kernel object files..."
|
||||
i386-elf-ld -o ./build/kernel.bin -Ttext 0x1000 --oformat binary ./build/**.o
|
||||
mv ./build/disk.o ./build/f_disk.o # Very temporary fix to issue with disk.o not linking or something weird
|
||||
i386-elf-ld -o ./build/kernel.bin -Ttext 0x1000 --oformat binary ./build/*.o
|
||||
|
||||
# OS Image
|
||||
echo "Creating kern.iso disk image..."
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
#include "disk.h"
|
||||
#include "stdint.h"
|
||||
#include "system.h"
|
||||
|
||||
#define PIO_PORT 0x1f0
|
||||
#define READ_COMMAND 0x20
|
||||
#define WRITE_COMMAND 0x30
|
||||
|
||||
void diskRead(uint32_t lbaAddress, uint8_t sectorCount, char* dst) {
|
||||
outb(PIO_PORT + 6, ((lbaAddress >> 24) & 0x0f) | 0xe0); // 6 - Use LBA; 4 - Drive number; 3-0 - Highest lba address nibble
|
||||
outb(PIO_PORT + 2, sectorCount); // Sector count register
|
||||
outb(PIO_PORT + 3, (uint8_t)(lbaAddress)); // Lowest lba address byte
|
||||
outb(PIO_PORT + 4, (uint8_t)(lbaAddress >> 8)); // Middle lba address byte
|
||||
outb(PIO_PORT + 5, (uint8_t)(lbaAddress >> 16)); // High lba address byte
|
||||
outb(PIO_PORT + 7, READ_COMMAND); // Command register
|
||||
|
||||
uint16_t* address = (uint16_t*)dst;
|
||||
|
||||
for (uint8_t i = sectorCount; i > 0; i--) {
|
||||
while (inb(PIO_PORT + 7) & (1 << 7)); // Poll status register untill BSY bit is clear
|
||||
|
||||
for (size_t j = 0; j < 256; j++) {
|
||||
*address++ = inw(PIO_PORT); // Read 256 words (512 Bytes = 1 Sector)
|
||||
}
|
||||
|
||||
for (uint8_t delay = 0; delay < 4; delay++) { // 400ns delay
|
||||
inb(0x3f6); // Alternate status register
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -5,7 +5,7 @@
|
||||
|
||||
extern uint8_t driveNum;
|
||||
|
||||
void diskRead(uint8_t sector, uint8_t sectorCount, uint8_t drive, char* dst);
|
||||
void diskWrite(uint8_t sector, uint8_t sectorCount, uint8_t drive, const char* src);
|
||||
void diskRead(uint32_t lbaAddress, uint8_t sectorCount, char* dst);
|
||||
// TODO: void diskWrite(uint8_t sector, uint8_t sectorCount, uint8_t drive, const char* src);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
#include "disk.h"
|
||||
#include "stdint.h"
|
||||
#include "system.h"
|
||||
|
||||
#define PIO_PORT 0x1f0
|
||||
|
||||
void diskRead(uint8_t sector, uint8_t sectorCount, uint8_t drive, char* dst) {
|
||||
outb(PIO_PORT + 6, (drive & 0x0f) | 0xa0); // Head and drive number port
|
||||
outb(PIO_PORT + 2, sectorCount); // Sector count
|
||||
outb(PIO_PORT + 3, sector); // Sector to start reading at
|
||||
outb(PIO_PORT + 4, 0); // Cylinder number low
|
||||
outb(PIO_PORT + 5, 0); // Cylinder number high
|
||||
outb(PIO_PORT + 7, 0x20); // Command register, 0x20 - Read with retry
|
||||
|
||||
while (inb(PIO_PORT + 7) == 8); // Status register, wait until ready
|
||||
|
||||
uint32_t i = 512 * sectorCount;
|
||||
while (i > 0) {
|
||||
uint16_t data = inw(PIO_PORT); // Data port
|
||||
*dst++ = (uint8_t)(data);
|
||||
*dst++ = (uint8_t)(data >> 8);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
|
||||
void diskWrite(uint8_t sector, uint8_t sectorCount, uint8_t drive, const char* src);
|
||||
|
||||
Reference in New Issue
Block a user