forked from PoliEcho-holding-org/kern
FINALLY Added Disk support!!! f_disk.c name explanation in README.md
Disk reading only, but it works!
This commit is contained in:
@@ -29,19 +29,17 @@ If you don't know how to do something, try the 'help' command!
|
||||
|
||||
## Some images
|
||||
|
||||
Interactive Shell: \
|
||||

|
||||
|
||||
Text editor **concept**: \
|
||||

|
||||
|
||||
Available character set: \
|
||||

|
||||
|
||||
Available colors: \
|
||||

|
||||
|
||||
_These images may be outdated, Idk_
|
||||
|
||||
## Known issues
|
||||
- If you run the kernel.bin, loading files sorta breaks, because the program is running at 0x8000, but it thinks that it's at 0x2000 (i think)
|
||||
- If you run anything in the code editor and return to the kernel, you won't be able to load any files
|
||||
- For some unknown reason, i cannot name the f\_disk.c file just disk.c. It breaks the OS. No idea why. In fact, anything starting with a character that is before f doesn't work. Help me
|
||||
|
||||
## [Old Version](https://github.com/Tom-on64/old-kern)
|
||||
|
||||
+3
-2
@@ -7,15 +7,16 @@ Well, 32-bit means that it can access $2^{32}$ different memory addresses.
|
||||
x86 is the processor architecture it is built upon.
|
||||
|
||||
## Command Line
|
||||
Kern uses a command line (for now), so you'll have to type commands to do stuff.
|
||||
Kern uses a shell (for now), so you'll have to type commands to do stuff.
|
||||
It is currently quite simple. It supports these commands:
|
||||
|
||||
- clear: Clears the screen
|
||||
- echo <msg>: Prints msg to the screen
|
||||
- exit: Shuts down the OS ***(QEMU only!)***
|
||||
- exit: Exits the shell
|
||||
- help: Prints all available commands
|
||||
- ls: Prints all files
|
||||
- reboot: Reboots the system
|
||||
- test: Tests the newest feature _Debug_
|
||||
|
||||
You can also print/run files by typing their filename (More in **Filesystem**)
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
Hello, World!
|
||||
@@ -1 +0,0 @@
|
||||
#include "disk.h"
|
||||
+5
-2
@@ -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,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
|
||||
|
||||
;;
|
||||
|
||||
@@ -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
@@ -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
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user