Some tests on ATA driver

This commit is contained in:
Adrien Bourmault 2019-05-23 14:50:05 +02:00
parent f3b7b85da8
commit 4ff65f57d0
8 changed files with 89 additions and 57 deletions

View File

@ -108,7 +108,7 @@ KernSources = kernel/ke/cpuid.c kernel/mm/paging.c \
kernel/ke/rtc.c kernel/io/keyb.c \ kernel/ke/rtc.c kernel/io/keyb.c \
kernel/io/spkr.c kernel/po/shtdwn.c \ kernel/io/spkr.c kernel/po/shtdwn.c \
kernel/sh/shell.c kernel/sh/shcmds.c \ kernel/sh/shell.c kernel/sh/shcmds.c \
kernel/sh/musage.c kernel/sh/musage.c kernel/io/ata.c
KernObj=$(patsubst %.c,$(KOBJDIR)/%.o,$(KernSources)) KernObj=$(patsubst %.c,$(KOBJDIR)/%.o,$(KernSources))
KernDep=$(patsubst %.c,$(KOBJDIR)/%.d,$(KernSources)) KernDep=$(patsubst %.c,$(KOBJDIR)/%.d,$(KernSources))
@ -168,6 +168,15 @@ $(KOBJDIR)/kernel/ke/idt.o: $(KALEIDDIR)/kernel/ke/idt.c \
@rm -f $@.1 $@.2 @rm -f $@.1 $@.2
@echo ${CL2}[$@] ${CL}Compiled.${CL3} @echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/kernel/ke/cpuid.o: $(KALEIDDIR)/kernel/ke/cpuid.c \
$(KALEIDDIR)/kernel/ke/cpuf.asm | $(KOBJDIR)
@mkdir -p $(shell dirname $@)
@$(ASM) $(ASMFLAGS) $(KALEIDDIR)/kernel/ke/cpuf.asm -o $@.1
@$(KCC_MATHS) $< -o $@.2
@$(LD) $(LDFLAGS) -r $@.1 $@.2 -o $@
@rm -f $@.1 $@.2
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/kernel/mm/paging.o: $(KALEIDDIR)/kernel/mm/paging.c \ $(KOBJDIR)/kernel/mm/paging.o: $(KALEIDDIR)/kernel/mm/paging.c \
$(KALEIDDIR)/kernel/mm/paging.asm | $(KOBJDIR) $(KALEIDDIR)/kernel/mm/paging.asm | $(KOBJDIR)
@mkdir -p $(shell dirname $@) @mkdir -p $(shell dirname $@)
@ -186,11 +195,11 @@ $(KOBJDIR)/kernel/mm/gdt.o: $(KALEIDDIR)/kernel/mm/gdt.c \
@rm -f $@.1 $@.2 @rm -f $@.1 $@.2
@echo ${CL2}[$@] ${CL}Compiled.${CL3} @echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/kernel/ke/cpuid.o: $(KALEIDDIR)/kernel/ke/cpuid.c \ $(KOBJDIR)/kernel/io/ata.o: $(KALEIDDIR)/kernel/io/ata.c \
$(KALEIDDIR)/kernel/ke/cpuf.asm | $(KOBJDIR) $(KALEIDDIR)/kernel/io/ata.asm | $(KOBJDIR)
@mkdir -p $(shell dirname $@) @mkdir -p $(shell dirname $@)
@$(ASM) $(ASMFLAGS) $(KALEIDDIR)/kernel/ke/cpuf.asm -o $@.1 @$(ASM) $(ASMFLAGS) $(KALEIDDIR)/kernel/io/ata.asm -o $@.1
@$(KCC_MATHS) $< -o $@.2 @$(KCC) $< -o $@.2
@$(LD) $(LDFLAGS) -r $@.1 $@.2 -o $@ @$(LD) $(LDFLAGS) -r $@.1 $@.2 -o $@
@rm -f $@.1 $@.2 @rm -f $@.1 $@.2
@echo ${CL2}[$@] ${CL}Compiled.${CL3} @echo ${CL2}[$@] ${CL}Compiled.${CL3}

View File

@ -158,6 +158,12 @@ extern void MmLoadGdt(GdtPtr_t *gdtPtr, ushort tssOffset);
// //
extern void MmStoreGdt(void); extern void MmStoreGdt(void);
void MmInitPaging(void);
void MmReloadPaging(void);
void MmActivatePageHandler(void);
// //
// Returns the address of the stack guard pages // Returns the address of the stack guard pages
// //

View File

@ -24,9 +24,6 @@
#include "init.h" #include "init.h"
void MmInitPaging(void);
void MmActivatePageHandler(void);
// //
// Entry point of the Kaleid kernel // Entry point of the Kaleid kernel
// //

View File

@ -34,6 +34,7 @@
#include <mm/mm.h> #include <mm/mm.h>
#include <io/vga.h> #include <io/vga.h>
#include <ke/cpuid.h> #include <ke/cpuid.h>
#include <io/ata.h>
// info.c // info.c
extern void BtDoSanityChecks(uint mbMagic); extern void BtDoSanityChecks(uint mbMagic);

View File

@ -23,6 +23,9 @@
; along with OS/K. If not, see <https://www.gnu.org/licenses/>. ; ; along with OS/K. If not, see <https://www.gnu.org/licenses/>. ;
;=----------------------------------------------------------------------------=; ;=----------------------------------------------------------------------------=;
global IoReadATA
extern KernLog
[BITS 64] [BITS 64]
;; BPB ;; BPB
@ -47,18 +50,14 @@
%define fatTypeLabel bp+0x36 ; File system type %define fatTypeLabel bp+0x36 ; File system type
;; GLOBAL DATA ;; GLOBAL DATA
Bootdrv db 0 Bootdrv db 0
ended db "[End of Sector]", 0x0A, 0x0A, 0x0D, 0x0
buffer: times 513 db "_", 0
;; TEXT ;; TEXT
IoReadATA:
ata_read:
;-----------------------------------------------------------------------; ;-----------------------------------------------------------------------;
; x64/LM ATA Reading function ; ; x64/LM ATA Reading function ;
; bl : number of sectors to read XXX ; ; rsi : number of sectors to read XXX ;
; bh : the first sector to read ; ; rdx : the first sector to read ;
;-----------------------------------------------------------------------; ;-----------------------------------------------------------------------;
; Technical infos about the ports (Intel Doc): ; Technical infos about the ports (Intel Doc):
@ -99,11 +98,10 @@ ata_read:
; 32h write long with retry ; 32h write long with retry
; 33h write long without retry ; 33h write long without retry
; ;
push rax
push rbx push rbx
push rcx mov bh, dl
push rdx mov dx, si
push rdi mov bl, dl
mov dx, 0x1f6 ; Drive and head port mov dx, 0x1f6 ; Drive and head port
mov al, 0x0a0 ; Drive 0, head 0 mov al, 0x0a0 ; Drive 0, head 0
out dx,al out dx,al
@ -135,18 +133,7 @@ still_going:
;is ready. ;is ready.
mov cx, 512/2 ; One sector /2 because it copies words mov cx, 512/2 ; One sector /2 because it copies words
mov rdi, QWORD buffer
mov dx, 0x1f0 ; Data port - data comes in and out of here. mov dx, 0x1f0 ; Data port - data comes in and out of here.
rep insw rep insw
pop rdi
mov bl, 0x0F
mov rdi, QWORD buffer
call KernLog
mov bl, 0x0A
mov rdi, ended
call KernLog
pop rdx
pop rcx
pop rbx pop rbx
pop rax
ret ret

View File

@ -24,6 +24,17 @@
#include "shell.h" #include "shell.h"
int ShAtoi(char* str)
{
int res = 0;
for (int i = 0; str[i] != 0; ++i)
res = res * 10 + str[i] - '0';
return res;
}
error_t CmdArgs(int argc, char **argv, char *cmdline) error_t CmdArgs(int argc, char **argv, char *cmdline)
{ {
int i; int i;
@ -114,6 +125,31 @@ error_t CmdDie(int argc, char **argv, char *cmdline)
return EOK; return EOK;
} }
error_t CmdDumpATASect(int argc, char **argv, char *cmdline)
{
char sector[513] = {0};
int sectNumber = ShAtoi(argv[1]);
if (!sectNumber) {
KernLog("Bad argument\n\n");
return EINVAL;
}
KernLog("Sector number: %d\n", sectNumber);
IoReadATA(sector, 1, sectNumber);
for (int i = 0; i < 513; i++) {
if (isprint(sector[i]))
KernLog("%c", sector[i]);
else
KernLog(" ");
}
KernLog("\n\n");
return EOK;
}
error_t CmdHelp(int argc, char **argv, char *cmdline) error_t CmdHelp(int argc, char **argv, char *cmdline)
{ {
uint i, count = 0; uint i, count = 0;
@ -235,28 +271,28 @@ error_t CmdVersion(int argc, char **argv, char *cmdline)
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
Command_t cmdtable[] = Command_t cmdtable[] =
{ {
{ "args", CmdArgs, "Print command line" }, { "args", CmdArgs, "Print command line" },
{ "beep", CmdBeep, "Make a beep" }, { "beep", CmdBeep, "Make a beep" },
{ "cls", CmdClear, "Clears standard output" }, { "cls", CmdClear, "Clears standard output" },
{ "color", CmdColor, "Change shell text color" }, { "color", CmdColor, "Change shell text color" },
{ "cpuid", CmdCpuid, "Request a cpuid info." }, { "cpuid", CmdCpuid, "Request a cpuid info." },
{ "date", CmdDate, "Print date" }, { "date", CmdDate, "Print date" },
{ "die", CmdDie, "Die painfully" }, { "die", CmdDie, "Die painfully" },
{ "help", CmdHelp, "Show this message" }, { "dmpsec", CmdDumpATASect, "Dump an ATA sector on screen" },
{ "mmap", CmdMemMap, "Show memory map" }, { "help", CmdHelp, "Show this message" },
{ "musage", CmdMemUsage, "Show memory statistics" }, { "mmap", CmdMemMap, "Show memory map" },
{ "pfault", CmdPF, "Provoke a PF. Usage : pfault <address>" }, { "musage", CmdMemUsage, "Show memory statistics" },
{ "pstest", CmdPsTest, "Scheduler test routine" }, { "pfault", CmdPF, "Provoke a PF. Usage: pfault <address>"},
{ "exit", CmdQuit, "Initiate shutdown" }, { "pstest", CmdPsTest, "Scheduler test routine" },
{ "quit", CmdQuit, "Alias for 'exit'" }, { "exit", CmdQuit, "Initiate shutdown" },
{ "rpag", CmdReloadPage, "Reload the pages directory" }, { "quit", CmdQuit, "Alias for 'exit'" },
{ "shell", CmdShell, "Start a new shell (nested)", }, { "rpag", CmdReloadPage, "Reload the pages directory" },
{ "stkov", CmdStackOverflow, "Provoke a stack overflow" }, { "shell", CmdShell, "Start a new shell (nested)", },
{ "stkun", CmdStackUnderflow, "Provoke a stack underflow" }, { "stkov", CmdStackOverflow, "Provoke a stack overflow" },
{ "march", CmdStarWars, "Play the Imperial March"}, { "stkun", CmdStackUnderflow, "Provoke a stack underflow" },
{ "time", CmdTime, "Print time" }, { "march", CmdStarWars, "Play the Imperial March" },
{ "test", CmdTime, "Undocumented (various tests)" }, { "time", CmdTime, "Print time" },
{ "ver", CmdVersion, "Version and legal infos" }, { "ver", CmdVersion, "Version and legal infos" },
{ NULL, NULL, NULL } { NULL, NULL, NULL }
}; };

View File

@ -35,13 +35,10 @@
#include <io/vga.h> #include <io/vga.h>
#include <po/shtdwn.h> #include <po/shtdwn.h>
#include <ke/cpuid.h> #include <ke/cpuid.h>
#include <io/ata.h>
void IoScrollDown(void);
void IoScrollUp(void);
void KeStartShell(void); void KeStartShell(void);
void pstest(void); void pstest(void);
void MmInitPaging(void);
void MmReloadPaging(void);
extern int shcol; extern int shcol;
extern int shargc; extern int shargc;

View File

@ -45,4 +45,3 @@ _ATOI_IMPL(atoul, ulong, strtoul)
#else #else
#error "What am I supposed to declare?" #error "What am I supposed to declare?"
#endif #endif