FINALLY Added Disk support!!! f_disk.c name explanation in README.md

Disk reading only, but it works!
This commit is contained in:
2024-04-09 20:18:03 +02:00
parent eb97401ac0
commit 78367d56d6
10 changed files with 67 additions and 15 deletions
-1
View File
@@ -1 +0,0 @@
#include "disk.h"
+5 -2
View File
@@ -1,8 +1,11 @@
#ifndef DISK_H
#define DISK_H
#ifndef DRIVE_H
#define DRIVE_H
#include "stdint.h"
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);
#endif
+1 -1
View File
@@ -1,5 +1,6 @@
[bits 32]
[global _start]
[global driveNum]
[extern main]
[extern idtp]
@@ -19,7 +20,6 @@ _start:
jmp $ ;; If we used cli, hlt we wouldn't have interrupts :/
[global driveNum]
driveNum: db 0
;;
+27
View File
@@ -0,0 +1,27 @@
#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);
+11 -1
View File
@@ -52,10 +52,20 @@ void main() {
print("Available Commands:\n", 0x0f);
print(" clear | Clears the screen\n", 0x0f);
print(" echo | Prints a message to stdout\n", 0x0f);
print(" exit | Exits program\n", 0x0f);
print(" exit | Exits shell\n", 0x0f);
print(" help | Prints this message\n", 0x0f);
// TODO: print(" ls | Lists all available files\n", 0x0f);
// TODO: print(" reboot | Reboots the system\n", 0x0f);
print(" test | Tests the latest feature [DEBUG]\n", 0x0f);
} else if (strcmp(input, "test") == 0) {
char buf[512];
print("Reading from drive 0x", 0x0f);
print(itoa(driveNum, 16), 0x0f);
print("...\n", 0x0f);
diskRead(22, 1, driveNum, buf);
print(buf, 0x0f);
putc('\n', 0x0f);
} else {
print("Command not found: ", 0x0c);
print(input, 0x0c);
+12 -2
View File
@@ -3,12 +3,22 @@
uint8_t inb(uint16_t port) {
uint8_t result;
asm volatile("in %1, %0" : "=a"(result) : "Nd"(port));
asm volatile("inb %1, %0" : "=a"(result) : "Nd"(port));
return result;
}
void outb(uint16_t port, uint8_t data) {
asm volatile("out %0, %1" :: "a"(data), "Nd"(port));
asm volatile("outb %0, %1" :: "a"(data), "Nd"(port));
}
uint16_t inw(uint16_t port) {
uint16_t result;
asm volatile("inw %1, %0" : "=a"(result) : "Nd"(port));
return result;
}
void outw(uint16_t port, uint16_t data) {
asm volatile("outw %0, %1" :: "a"(data), "Nd"(port));
}
char* memcopy(char* src, char* dst, uint16_t length) {
+3
View File
@@ -7,6 +7,9 @@
uint8_t inb(uint16_t port);
void outb(uint16_t port, uint8_t data);
uint16_t inw(uint16_t port);
void outw(uint16_t port, uint16_t data);
// Memory functions
char* memcopy(char* src, char* dst, uint16_t length);
char* memset(char* dst, char data, uint16_t length);