From 43e902e83c36be4dab649b657af9e0886a96781d Mon Sep 17 00:00:00 2001 From: Lucia Ceionia Date: Wed, 4 Jan 2023 19:36:29 -0600 Subject: [PATCH] Fixed disk handling --- dosfs/dosfs.c | 3 +++ interrupt.h | 1 - kernel.c | 11 +++++++---- print.c | 13 +++++++++++++ print.h | 2 +- tss.h | 1 - v86.nasm | 5 +++++ 7 files changed, 29 insertions(+), 7 deletions(-) diff --git a/dosfs/dosfs.c b/dosfs/dosfs.c index 3649dfe..bcc934d 100755 --- a/dosfs/dosfs.c +++ b/dosfs/dosfs.c @@ -29,6 +29,9 @@ extern void v86DiskRead(); uint32_t DFS_ReadSector(uint8_t unit, uint8_t *buffer, uint32_t sector, uint32_t count) { v86disk_addr_packet.start_block = sector; v86disk_addr_packet.blocks = count; + v86disk_addr_packet.transfer_buffer = + (uintptr_t)buffer & 0x000F | + (((uintptr_t)buffer & 0xFFFF0) << 12); FARPTR v86_entry = i386LinearToFp(v86DiskRead); enter_v86(0x8000, 0xFF00, FP_SEG(v86_entry), FP_OFF(v86_entry)); return 0; diff --git a/interrupt.h b/interrupt.h index 69343a2..1d8656a 100644 --- a/interrupt.h +++ b/interrupt.h @@ -1,4 +1,3 @@ -#pragma once #include struct interrupt_frame { diff --git a/kernel.c b/kernel.c index f73d4c3..83a9f16 100644 --- a/kernel.c +++ b/kernel.c @@ -122,7 +122,7 @@ void TestDiskRead() { } void TestFAT() { word *vga_text = (word *)0xb8000; - uint8_t *diskReadBuf = (uint8_t *)0x23000; + uint8_t *diskReadBuf = (uint8_t *)0x22400; for (int i = 0; i < 80*25; i++) vga_text[i] = 0x0f00; VOLINFO vi; @@ -143,7 +143,7 @@ void TestFAT() { vga_text += printStr("PartType: ", vga_text); vga_text += printByte(ptype, vga_text); vga_text = (word *)((((((uintptr_t)vga_text)-0xb8000) - ((((uintptr_t)vga_text)-0xb8000) % 160)) + 160)+0xb8000); - asm ("xchgw %bx, %bx"); + //asm ("xchgw %bx, %bx"); DFS_GetVolInfo(0, diskReadBuf, pstart, &vi); vga_text += printStr("Label: ", vga_text); @@ -167,7 +167,7 @@ void TestFAT() { vga_text += printStr("ROOT@: ", vga_text); vga_text += printDword(vi.rootdir, vga_text); vga_text = (word *)((((((uintptr_t)vga_text)-0xb8000) - ((((uintptr_t)vga_text)-0xb8000) % 160)) + 160)+0xb8000); - asm ("xchgw %bx, %bx"); + //asm ("xchgw %bx, %bx"); vga_text += printStr("Files in root:", vga_text); DIRINFO di; @@ -182,9 +182,12 @@ void TestFAT() { *(uint8_t *)vga_text = de.name[i]; vga_text++; } + vga_text += printStr(" ", vga_text); + vga_text += printDec((uint32_t)de.filesize_0 + ((uint32_t)de.filesize_1 << 8) + ((uint32_t)de.filesize_2 << 16) + ((uint32_t)de.filesize_3 << 24), vga_text); + *(uint8_t*)vga_text++ = 'B'; vga_text = (word *)((((((uintptr_t)vga_text)-0xb8000) - ((((uintptr_t)vga_text)-0xb8000) % 160)) + 160)+0xb8000); } - asm ("xchgw %bx, %bx"); + //asm ("xchgw %bx, %bx"); } } diff --git a/print.c b/print.c index d57a5a3..5d87c7b 100644 --- a/print.c +++ b/print.c @@ -25,3 +25,16 @@ uintptr_t printStr(char *v, uint16_t *buff) { *(char*)buff = *s; return s - v; } + +uintptr_t printDec(uint32_t v, uint16_t *buff) { + char b[12]; + char *s = &b[11]; + if (!v) { + *(uint16_t*)&b[10] = '0'; // '0',0x00 + s = &b[10]; + } else { + *s = 0; + for (;v;v/=10) *--s = '0' + v%10; + } + return printStr(s, buff); +} diff --git a/print.h b/print.h index 5aaab79..43cdc37 100644 --- a/print.h +++ b/print.h @@ -1,7 +1,7 @@ -#pragma once #include uintptr_t printByte(uint8_t v, uint16_t *buff); uintptr_t printWord(uint16_t v, uint16_t *buff); uintptr_t printDword(uint32_t v, uint16_t *buff); uintptr_t printStr(char *v, uint16_t *buff); +uintptr_t printDec(uint32_t v, uint16_t *buff); diff --git a/tss.h b/tss.h index 42a05ab..318d263 100644 --- a/tss.h +++ b/tss.h @@ -1,2 +1 @@ -#pragma once void setup_tss(); diff --git a/v86.nasm b/v86.nasm index c005aaf..91f67be 100644 --- a/v86.nasm +++ b/v86.nasm @@ -26,6 +26,7 @@ call real_hexprint mov ax, dx call real_hexprint ret + global v86Test v86Test: mov ax, 0xb814 @@ -45,18 +46,21 @@ int 3 int 3 int 0x30 ; exit jmp $ + global v86GfxMode v86GfxMode: mov ax, 0x13 int 0x10 int 0x30 jmp $ + global v86TextMode v86TextMode: mov ax, 0x3 int 0x10 int 0x30 jmp $ + global v86DiskRead v86DiskRead: xor ax, ax ; TODO fix assuming we're in first 64k @@ -73,6 +77,7 @@ db 0x10, 0x00 ; size, reserved dw 0x1 ; blocks dd 0x23000000 ; transfer buffer 0x23000 dq 0x1 ; start block + [BITS 32] ; extern void enter_v86(uint32_t ss, uint32_t esp, uint32_t cs, uint32_t eip); global enter_v86