Added a regs command to print register values

This commit is contained in:
2024-06-03 10:18:52 +02:00
parent 07e946221f
commit 8e004221e1
2 changed files with 43 additions and 4 deletions
+1 -2
View File
@@ -58,8 +58,7 @@ $(FONTS):
run:
qemu-system-x86_64\
-drive format=raw,file="./kern.iso",index=0,media=disk\
-m 256M\
-accel tcg\
-m 256M -accel tcg -monitor stdio\
-rtc base=localtime,clock=host,driftfix=slew\
-audiodev coreaudio,id=audio0 -machine pcspk-audiodev=audio0
+42 -2
View File
@@ -29,6 +29,7 @@
// Function declarations
void listFiles();
void printRegs();
void printPhysicalMemmap();
__attribute__ ((section("entry")))
@@ -175,6 +176,7 @@ void main() {
printf(" ls | Lists files in current directory\n");
printf(" memmap | Prints the memory map and info\n");
printf(" reboot | Reboots the system\n");
printf(" regs | Prints register values\n");
printf(" sleep | Sleeps for input number of seconds\n");
printf(" soundtest | Plays a tune :)\n");
printf(" test | Performs tests\n");
@@ -184,6 +186,8 @@ void main() {
printPhysicalMemmap();
} else if (strcmp(argv[0], "reboot") == 0) {
outb(0x64, 0xFE);
} else if (strcmp(argv[0], "regs") == 0) {
printRegs();
} else if (strcmp(argv[0], "sleep") == 0) {
if (*argv[1] == '\0') continue;
@@ -217,8 +221,8 @@ void main() {
disableSpeaker();
} else if (strcmp(argv[0], "test") == 0) {
printf("\x1b[1MError: 'test' is not available.\x1b[8M");
} else {
printf("\x1b[1MError: 'test' is not available.\x1b[8M\n");
} else { // TODO: Use new filesystem!
fileEntry_t* file = findFile(argv[0]);
if (file == NULL) {
@@ -308,6 +312,42 @@ void listFiles() {
printf("editor.bin 1280B\n");
}
void printRegs() {
uint32_t val;
// a, b, c, d
__asm__ volatile ("movl %%eax, %0" : "=r"(val));
printf("eax 0x%x\n", val);
__asm__ volatile ("movl %%ebx, %0" : "=r"(val));
printf("ebx 0x%x\n", val);
__asm__ volatile ("movl %%ecx, %0" : "=r"(val));
printf("ecx 0x%x\n", val);
__asm__ volatile ("movl %%edx, %0" : "=r"(val));
printf("edx 0x%x\n", val);
// si, di
__asm__ volatile ("movl %%esi, %0" : "=r"(val));
printf("esi 0x%x\n", val);
__asm__ volatile ("movl %%edi, %0" : "=r"(val));
printf("edi 0x%x\n", val);
// cs, ds, es, ss
__asm__ volatile ("movl %%cs, %0" : "=r"(val));
printf("cs 0x%x\n", val);
__asm__ volatile ("movl %%ds, %0" : "=r"(val));
printf("ds 0x%x\n", val);
__asm__ volatile ("movl %%es, %0" : "=r"(val));
printf("es 0x%x\n", val);
__asm__ volatile ("movl %%ss, %0" : "=r"(val));
printf("ss 0x%x\n", val);
// stack
__asm__ volatile ("movl %%esp, %0" : "=r"(val));
printf("esp 0x%x\n", val);
__asm__ volatile ("movl %%ebp, %0" : "=r"(val));
printf("ebp 0x%x\n", val);
}
void printPhysicalMemmap() {
uint32_t entryCount = *(uint32_t*)SMAP_ENTRY_COUNT;
smapEntry_t* smapEntry = (smapEntry_t*)SMAP_ENTRIES;