diff --git a/Makefile b/Makefile index 12e21f8..697dbd0 100644 --- a/Makefile +++ b/Makefile @@ -108,7 +108,7 @@ KernSources = kernel/ke/cpuid.c kernel/mm/paging.c \ kernel/ke/rtc.c kernel/io/keyb.c \ kernel/io/spkr.c kernel/po/shtdwn.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)) KernDep=$(patsubst %.c,$(KOBJDIR)/%.d,$(KernSources)) @@ -168,6 +168,15 @@ $(KOBJDIR)/kernel/ke/idt.o: $(KALEIDDIR)/kernel/ke/idt.c \ @rm -f $@.1 $@.2 @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 \ $(KALEIDDIR)/kernel/mm/paging.asm | $(KOBJDIR) @mkdir -p $(shell dirname $@) @@ -186,11 +195,11 @@ $(KOBJDIR)/kernel/mm/gdt.o: $(KALEIDDIR)/kernel/mm/gdt.c \ @rm -f $@.1 $@.2 @echo ${CL2}[$@] ${CL}Compiled.${CL3} -$(KOBJDIR)/kernel/ke/cpuid.o: $(KALEIDDIR)/kernel/ke/cpuid.c \ - $(KALEIDDIR)/kernel/ke/cpuf.asm | $(KOBJDIR) +$(KOBJDIR)/kernel/io/ata.o: $(KALEIDDIR)/kernel/io/ata.c \ + $(KALEIDDIR)/kernel/io/ata.asm | $(KOBJDIR) @mkdir -p $(shell dirname $@) - @$(ASM) $(ASMFLAGS) $(KALEIDDIR)/kernel/ke/cpuf.asm -o $@.1 - @$(KCC_MATHS) $< -o $@.2 + @$(ASM) $(ASMFLAGS) $(KALEIDDIR)/kernel/io/ata.asm -o $@.1 + @$(KCC) $< -o $@.2 @$(LD) $(LDFLAGS) -r $@.1 $@.2 -o $@ @rm -f $@.1 $@.2 @echo ${CL2}[$@] ${CL}Compiled.${CL3} diff --git a/include/mm/mm.h b/include/mm/mm.h index f0c7707..2ef7185 100644 --- a/include/mm/mm.h +++ b/include/mm/mm.h @@ -158,6 +158,12 @@ extern void MmLoadGdt(GdtPtr_t *gdtPtr, ushort tssOffset); // extern void MmStoreGdt(void); +void MmInitPaging(void); + +void MmReloadPaging(void); + +void MmActivatePageHandler(void); + // // Returns the address of the stack guard pages // diff --git a/kaleid/kernel/init/init.c b/kaleid/kernel/init/init.c index 5fd564e..217f6bf 100644 --- a/kaleid/kernel/init/init.c +++ b/kaleid/kernel/init/init.c @@ -24,9 +24,6 @@ #include "init.h" -void MmInitPaging(void); -void MmActivatePageHandler(void); - // // Entry point of the Kaleid kernel // diff --git a/kaleid/kernel/init/init.h b/kaleid/kernel/init/init.h index 82df973..4f9accf 100644 --- a/kaleid/kernel/init/init.h +++ b/kaleid/kernel/init/init.h @@ -34,6 +34,7 @@ #include #include #include +#include // info.c extern void BtDoSanityChecks(uint mbMagic); diff --git a/kaleid/kernel/io/ata.asm b/kaleid/kernel/io/ata.asm index 40805c9..6c07fb3 100644 --- a/kaleid/kernel/io/ata.asm +++ b/kaleid/kernel/io/ata.asm @@ -23,6 +23,9 @@ ; along with OS/K. If not, see . ; ;=----------------------------------------------------------------------------=; +global IoReadATA +extern KernLog + [BITS 64] ;; BPB @@ -47,18 +50,14 @@ %define fatTypeLabel bp+0x36 ; File system type ;; GLOBAL DATA - Bootdrv db 0 -ended db "[End of Sector]", 0x0A, 0x0A, 0x0D, 0x0 -buffer: times 513 db "_", 0 ;; TEXT - -ata_read: +IoReadATA: ;-----------------------------------------------------------------------; ; x64/LM ATA Reading function ; -; bl : number of sectors to read XXX ; -; bh : the first sector to read ; +; rsi : number of sectors to read XXX ; +; rdx : the first sector to read ; ;-----------------------------------------------------------------------; ; Technical infos about the ports (Intel Doc): @@ -99,11 +98,10 @@ ata_read: ; 32h write long with retry ; 33h write long without retry ; - push rax push rbx - push rcx - push rdx - push rdi + mov bh, dl + mov dx, si + mov bl, dl mov dx, 0x1f6 ; Drive and head port mov al, 0x0a0 ; Drive 0, head 0 out dx,al @@ -135,18 +133,7 @@ still_going: ;is ready. 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. 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 rax ret diff --git a/kaleid/kernel/sh/shcmds.c b/kaleid/kernel/sh/shcmds.c index 26a8666..ab3214a 100644 --- a/kaleid/kernel/sh/shcmds.c +++ b/kaleid/kernel/sh/shcmds.c @@ -24,6 +24,17 @@ #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) { int i; @@ -114,6 +125,31 @@ error_t CmdDie(int argc, char **argv, char *cmdline) 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) { uint i, count = 0; @@ -235,28 +271,28 @@ error_t CmdVersion(int argc, char **argv, char *cmdline) //----------------------------------------------------------------------------// Command_t cmdtable[] = { - { "args", CmdArgs, "Print command line" }, - { "beep", CmdBeep, "Make a beep" }, - { "cls", CmdClear, "Clears standard output" }, - { "color", CmdColor, "Change shell text color" }, - { "cpuid", CmdCpuid, "Request a cpuid info." }, - { "date", CmdDate, "Print date" }, - { "die", CmdDie, "Die painfully" }, - { "help", CmdHelp, "Show this message" }, - { "mmap", CmdMemMap, "Show memory map" }, - { "musage", CmdMemUsage, "Show memory statistics" }, - { "pfault", CmdPF, "Provoke a PF. Usage : pfault
" }, - { "pstest", CmdPsTest, "Scheduler test routine" }, - { "exit", CmdQuit, "Initiate shutdown" }, - { "quit", CmdQuit, "Alias for 'exit'" }, - { "rpag", CmdReloadPage, "Reload the pages directory" }, - { "shell", CmdShell, "Start a new shell (nested)", }, - { "stkov", CmdStackOverflow, "Provoke a stack overflow" }, - { "stkun", CmdStackUnderflow, "Provoke a stack underflow" }, - { "march", CmdStarWars, "Play the Imperial March"}, - { "time", CmdTime, "Print time" }, - { "test", CmdTime, "Undocumented (various tests)" }, - { "ver", CmdVersion, "Version and legal infos" }, + { "args", CmdArgs, "Print command line" }, + { "beep", CmdBeep, "Make a beep" }, + { "cls", CmdClear, "Clears standard output" }, + { "color", CmdColor, "Change shell text color" }, + { "cpuid", CmdCpuid, "Request a cpuid info." }, + { "date", CmdDate, "Print date" }, + { "die", CmdDie, "Die painfully" }, + { "dmpsec", CmdDumpATASect, "Dump an ATA sector on screen" }, + { "help", CmdHelp, "Show this message" }, + { "mmap", CmdMemMap, "Show memory map" }, + { "musage", CmdMemUsage, "Show memory statistics" }, + { "pfault", CmdPF, "Provoke a PF. Usage: pfault
"}, + { "pstest", CmdPsTest, "Scheduler test routine" }, + { "exit", CmdQuit, "Initiate shutdown" }, + { "quit", CmdQuit, "Alias for 'exit'" }, + { "rpag", CmdReloadPage, "Reload the pages directory" }, + { "shell", CmdShell, "Start a new shell (nested)", }, + { "stkov", CmdStackOverflow, "Provoke a stack overflow" }, + { "stkun", CmdStackUnderflow, "Provoke a stack underflow" }, + { "march", CmdStarWars, "Play the Imperial March" }, + { "time", CmdTime, "Print time" }, + { "ver", CmdVersion, "Version and legal infos" }, { NULL, NULL, NULL } }; diff --git a/kaleid/kernel/sh/shell.h b/kaleid/kernel/sh/shell.h index 215855c..0edc933 100644 --- a/kaleid/kernel/sh/shell.h +++ b/kaleid/kernel/sh/shell.h @@ -35,13 +35,10 @@ #include #include #include +#include -void IoScrollDown(void); -void IoScrollUp(void); void KeStartShell(void); void pstest(void); -void MmInitPaging(void); -void MmReloadPaging(void); extern int shcol; extern int shargc; diff --git a/kaleid/libc/atoi.c b/kaleid/libc/atoi.c index 1455d2e..79b19ff 100644 --- a/kaleid/libc/atoi.c +++ b/kaleid/libc/atoi.c @@ -45,4 +45,3 @@ _ATOI_IMPL(atoul, ulong, strtoul) #else #error "What am I supposed to declare?" #endif -