Skip to content

Commit 96736c7

Browse files
author
Hanna Skairipa
authored
saving progress couldn't get fat32 fs on main drive someone else please help: issue right now is the jumping to the load32 to jump to kernel
saving progress couldn't get fat32 fs on main drive someone else please help: issue right now is the jumping to the load32 to jump to kernel
2 parents 4694580 + 7c69267 commit 96736c7

16 files changed

Lines changed: 927 additions & 452 deletions

.gitignore

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,4 @@ mnt/
2222
**/bin/
2323
**/build/
2424
.venv/
25-
external/
26-
27-
pushTags.sh
25+
external/

Makefile

Lines changed: 61 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
2-
3-
# Object files grouped by functionality
41
FILES = \
52
./build/kernel.asm.o \
63
./build/kernel.o \
@@ -72,7 +69,7 @@ prepare_dirs:
7269

7370
all: build install
7471

75-
build: prepare_dirs fonts ./bin/boot_with_size.bin user_programs ./bin/os.bin
72+
build: prepare_dirs fonts ./bin/boot_with_size.bin ./bin/kernel.bin user_programs ./bin/os.bin
7673
@echo "Build complete! User programs built but not installed to disk image."
7774
@echo "To install user programs to disk image, run: make install"
7875

@@ -82,82 +79,75 @@ fonts:
8279
install: ./bin/os.bin
8380
ifeq ($(UNAME_S),Linux)
8481
@echo "Installing user programs and assets to disk image (Linux)..."
85-
@# Create mount point if it doesn't exist
8682
@sudo mkdir -p /mnt/d
87-
@# Unmount if already mounted
8883
@sudo umount /mnt/d 2>/dev/null || true
89-
@# Mount the disk image
90-
@sudo mount -t vfat ./bin/os.bin /mnt/d
91-
@# Copy all assets recursively
92-
@sudo cp -r ./assets/* /mnt/d/ 2>/dev/null || true
93-
@# Find and copy all .elf files from programs directory
94-
@find ./assets/etc/default/user/programs -name '*.elf' -exec sudo cp {} /mnt/d/ \;
95-
@# Unmount the disk image
84+
@sudo mount -t vfat ./bin/os.bin /mnt/d || { echo "Failed to mount disk image"; exit 1; }
85+
@if [ -d "./assets" ]; then sudo cp -r ./assets/* /mnt/d/ || { echo "Failed to copy assets"; sudo umount /mnt/d; exit 1; }; fi
86+
@if [ -d "./assets/etc/default/user/programs" ]; then find ./assets/etc/default/user/programs -name '*.elf' -exec sudo cp {} /mnt/d/ \; || { echo "Failed to copy .elf files"; sudo umount /mnt/d; exit 1; }; fi
9687
@sudo umount /mnt/d
9788
@echo "User programs and assets installed to disk image!"
9889
else ifeq ($(UNAME_S),Darwin)
99-
@echo "Attaching disk image (macOS)..."
100-
@bash -c '\
101-
DISK_ID=$$(hdiutil attach -imagekey diskimage-class=CRawDiskImage -nomount ./bin/os.bin | awk "/\\/dev\\// {print \$$1}"); \
102-
echo "diskutil list output for $$DISK_ID:"; \
103-
diskutil list $$DISK_ID; \
104-
PART_DEV=$$(ls /dev/$$(basename $$DISK_ID)s1); \
105-
echo "Partition device: $$PART_DEV"; \
106-
sudo mkdir -p /Volumes/viosmnt; \
107-
sudo mount -t msdos $$PART_DEV /Volumes/viosmnt || { echo "Failed to mount $$PART_DEV"; hdiutil detach $$DISK_ID; exit 1; }; \
108-
echo "Copying files..."; \
109-
sudo cp -r ./assets/* /Volumes/viosmnt/ 2>/dev/null || true; \
110-
find ./assets/etc/default/user/programs -name "*.elf" -exec sudo cp {} /Volumes/viosmnt/ \; ; \
90+
@echo "Preparing disk image for macOS..."
91+
@bash -c "\
92+
set -e; \
93+
echo 'Attaching disk image...'; \
94+
ATTACH_OUTPUT=\$$(hdiutil attach -imagekey diskimage-class=CRawDiskImage -nomount ./bin/os.bin 2>/dev/null); \
95+
DISK_ID=\$$(echo \"\$$ATTACH_OUTPUT\" | grep -o '/dev/disk[0-9]*' | head -1); \
96+
PARTITION_ID=\"\$${DISK_ID}s1\"; \
97+
if [ -z \"\$$DISK_ID\" ]; then echo 'Failed to attach disk image'; exit 1; fi; \
98+
echo \"Attached as \$$DISK_ID, partition \$$PARTITION_ID\"; \
99+
echo 'Formatting partition as FAT32...'; \
100+
diskutil eraseVolume MS-DOS VIOSFAT32 \"\$$PARTITION_ID\" >/dev/null 2>&1 || { echo 'Failed to format partition'; hdiutil detach \"\$$DISK_ID\" 2>/dev/null; exit 1; }; \
101+
echo 'Copying files...'; \
102+
if [ -d './assets' ]; then \
103+
echo 'Copying assets...'; \
104+
cp -r ./assets/* /Volumes/VIOSFAT32/ || { echo 'Failed to copy assets'; diskutil unmount \"\$$PARTITION_ID\"; hdiutil detach \"\$$DISK_ID\" 2>/dev/null; exit 1; }; \
105+
else \
106+
echo 'No assets directory found, skipping...'; \
107+
fi; \
108+
if [ -d './assets/etc/default/user/programs' ]; then \
109+
echo 'Copying .elf files...'; \
110+
find ./assets/etc/default/user/programs -name '*.elf' -exec cp {} /Volumes/VIOSFAT32/ \; || { echo 'Failed to copy .elf files'; diskutil unmount \"\$$PARTITION_ID\"; hdiutil detach \"\$$DISK_ID\" 2>/dev/null; exit 1; }; \
111+
else \
112+
echo 'No programs directory found, skipping...'; \
113+
fi; \
111114
sync; \
112-
echo "Unmounting..."; \
113-
sudo umount /Volumes/viosmnt; \
114-
hdiutil detach $$DISK_ID; \
115-
echo "User programs and assets installed to disk image!"; \
116-
'
115+
echo 'Unmounting for boot sector update...'; \
116+
diskutil unmount \"\$$PARTITION_ID\" >/dev/null 2>&1 || echo 'Unmount failed, continuing...'; \
117+
echo 'Installing custom boot sector...'; \
118+
dd if=./bin/vbr.bin of=\"\$$PARTITION_ID\" bs=512 count=1 conv=notrunc 2>/dev/null || echo 'Warning: Failed to install custom boot sector'; \
119+
hdiutil detach \"\$$DISK_ID\" >/dev/null 2>&1 || echo 'Detach failed, continuing...'; \
120+
echo 'User programs and assets installed to disk image!'; \
121+
"
117122
endif
118123

124+
119125
./bin/kernel.bin: prepare_dirs $(FILES)
120126
i686-elf-gcc $(FLAGS) -T ./src/linker.ld -o ./bin/kernel.bin -ffreestanding -O0 -nostdlib $(FILES)
121127

122-
./bin/mbr.bin: prepare_dirs ./src/boot/mbr.asm
128+
./bin/boot.bin: prepare_dirs ./src/boot/mbr.asm ./src/boot/vbrEntry.asm ./src/boot/vbrMain.asm ./src/boot/fsinfo.asm
123129
nasm -f bin ./src/boot/mbr.asm -o ./bin/mbr.bin
124-
125-
./bin/vbr.bin: prepare_dirs ./src/boot/vbr.asm
126-
nasm -f bin ./src/boot/vbr.asm -o ./bin/vbr.bin
130+
nasm -f bin ./src/boot/vbrEntry.asm -o ./bin/vbrEntry.bin
131+
nasm -f bin ./src/boot/vbrMain.asm -o ./bin/vbrMain.bin
132+
nasm -f bin ./src/boot/fsinfo.asm -o ./bin/fsinfo.bin
133+
dd if=./bin/vbrEntry.bin of=./bin/vbr.bin bs=512 count=1 conv=notrunc status=none
134+
dd if=./bin/vbrMain.bin of=./bin/vbr.bin bs=512 seek=1 count=2 conv=notrunc status=none
135+
dd if=./bin/mbr.bin of=$@ bs=512 count=1 conv=notrunc status=none
136+
dd if=./bin/vbr.bin of=$@ bs=512 seek=2050 count=3 conv=notrunc status=none
137+
dd if=./bin/fsinfo.bin of=$@ bs=512 seek=2060 count=1 conv=notrunc status=none
127138

128139
# Calculate kernel size and update boot sector
129-
./bin/boot_with_size.bin: ./bin/mbr.bin ./bin/vbr.bin ./bin/kernel.bin
130-
@echo "Calculating kernel size and updating VBR..."
131-
# ./updateBoot.sh ./bin/vbr.bin ./bin/kernel.bin
132-
@echo "Combining MBR + VBR into boot image..."
133-
dd if=./bin/mbr.bin of=./bin/boot_with_size.bin bs=512 count=1 conv=notrunc
134-
dd if=./bin/vbr.bin of=./bin/boot_with_size.bin bs=512 seek=2048 conv=notrunc
135-
136-
./bin/os.bin:
137-
python3 utilities/make_mbr_partition.py ./bin/os.bin --size 128 --start 2048 --type 0x0C
138-
@bash -c " \
139-
set -e; \
140-
ATTACH_OUTPUT=$$(hdiutil attach -imagekey diskimage-class=CRawDiskImage -nomount ./bin/os.bin); \
141-
echo 'hdiutil attach output:'; \
142-
echo "$$ATTACH_OUTPUT"; \
143-
DISK_ID=$$(echo "$$ATTACH_OUTPUT" | awk '/\/dev\// {print $$1; exit}'); \
144-
if [ -z "$$DISK_ID" ]; then \
145-
echo 'ERROR: No device found. hdiutil did not recognize the image as a disk.'; \
146-
exit 1; \
147-
fi; \
148-
echo "DISK_ID is $$DISK_ID"; \
149-
PART_DEV=$$(ls /dev/$$(basename $$DISK_ID)s1 2>/dev/null || true); \
150-
if [ -z "$$PART_DEV" ]; then \
151-
echo 'ERROR: Partition device not found. Check the image partition table.'; \
152-
hdiutil detach $$DISK_ID; \
153-
exit 1; \
154-
fi; \
155-
echo "Formatting partition $$PART_DEV as FAT32..."; \
156-
sudo newfs_msdos -F 32 -v VIOS_BOOT $$PART_DEV; \
157-
hdiutil detach $$DISK_ID; \
158-
"
159-
@sudo dd if=./bin/vbr.bin of=./bin/os.bin bs=512 seek=2048 conv=notrunc
160-
140+
./bin/boot_with_size.bin: ./bin/boot.bin ./bin/kernel.bin
141+
@echo "Calculating kernel size and updating boot sector..."
142+
cp ./bin/boot.bin ./bin/boot_with_size.bin
143+
144+
145+
./bin/os.bin: ./bin/boot_with_size.bin
146+
rm -rf ./bin/os.bin
147+
dd if=./bin/boot_with_size.bin of=./bin/os.bin bs=512 conv=notrunc
148+
dd if=./bin/kernel.bin of=./bin/os.bin bs=512 seek=2070 conv=notrunc
149+
dd if=/dev/zero bs=1048576 count=128 >> ./bin/os.bin
150+
161151
# Generic C and ASM file rules
162152
./build/%.o: ./src/%.c
163153
mkdir -p $(dir $@)
@@ -168,12 +158,14 @@ endif
168158
nasm -f elf -g $< -o $@
169159

170160
user_programs:
171-
@{ \
172-
for dir in $(shell find ./assets/etc/default/user/programs -mindepth 1 -maxdepth 1 -type d); do \
161+
@if [ -d "./assets/etc/default/user/programs" ]; then \
162+
for dir in $$(find ./assets/etc/default/user/programs -mindepth 1 -maxdepth 1 -type d 2>/dev/null); do \
173163
echo "Building user program $$dir..."; \
174164
$(MAKE) -C $$dir all || exit 1; \
175165
done; \
176-
}
166+
else \
167+
echo "No user programs directory found (./assets/etc/default/user/programs), skipping..."; \
168+
fi
177169

178170
user_programs_clean:
179171
@for dir in ./assets/etc/default/user/programs/*/ ; do \

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ ___________
155155
│   └── .keep
156156
├── build.sh
157157
├── buildExternal.sh
158+
├── debug.log
158159
├── docs
159160
│   └── api
160161
│   ├── copy_string_from_task.md
@@ -200,8 +201,11 @@ ___________
200201
│   │   ├── sb16.c
201202
│   │   └── sb16.h
202203
│   ├── boot
204+
│   │   ├── fsinfo.asm
203205
│   │   ├── mbr.asm
204-
│   │   └── vbr.asm
206+
│   │   ├── vbrEntry.asm
207+
│   │   ├── vbrMain.asm
208+
│   │   └── vbrOld.asm
205209
│   ├── config.h
206210
│   ├── debug
207211
│   │   ├── simple_serial.c
@@ -316,7 +320,6 @@ ___________
316320
│   └── utils
317321
│   ├── utils.c
318322
│   └── utils.h
319-
├── updateBoot.sh
320323
├── updateREADME.sh
321324
├── utilities
322325
│   ├── fonts
@@ -325,11 +328,10 @@ ___________
325328
│   │   ├── Brightly.otf
326329
│   │   ├── Cheri.ttf
327330
│   │   └── RobotoThin.ttf
328-
│   ├── generateFonts.py
329-
│   └── make_mbr_partition.py
331+
│   └── generateFonts.py
330332
└── ViOS_LOGO_PNG.png
331333
332-
53 directories, 165 files
334+
53 directories, 167 files
333335
```
334336

335337
___________

debug.log

9 Bytes
Binary file not shown.

src/boot/fsinfo.asm

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
; FAT32 FSInfo Sector
2+
; This sector provides information about the filesystem state
3+
4+
ORG 0x0000
5+
BITS 16
6+
7+
; FSInfo sector structure
8+
FSInfo_LeadSig dd 0x41615252 ; Lead signature "RRaA"
9+
FSInfo_Reserved1 times 480 db 0 ; Reserved bytes
10+
FSInfo_StrucSig dd 0x61417272 ; Structure signature "rrAa"
11+
FSInfo_Free_Count dd 0xFFFFFFFF ; Free cluster count (unknown)
12+
FSInfo_Nxt_Free dd 0xFFFFFFFF ; Next free cluster (unknown)
13+
FSInfo_Reserved2 times 12 db 0 ; Reserved bytes
14+
FSInfo_TrailSig dd 0xAA550000 ; Trail signature
15+
16+
; Pad to 512 bytes
17+
times 512-($-$$) db 0

src/boot/mbr.asm

Lines changed: 45 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,61 @@
1-
; MBR FAT32 Bootloader - loads first cluster of BOOT file
2-
BITS 16
31
ORG 0x7C00
2+
BITS 16
43

54
start:
65
cli
76
xor ax, ax
87
mov ds, ax
98
mov es, ax
10-
mov ss, ax
11-
mov sp, 0x7C00
12-
sti
13-
14-
; Save boot drive
15-
mov [boot_drive], dl
16-
17-
; Set text mode
18-
mov ax, 0x03
19-
int 0x10
209

21-
; Load first sector of partition at LBA 2048
22-
mov eax, 2048 ; Sector number to load
23-
mov [dap_lba], eax
24-
mov [dap_mem], word 0x8000 ; Destination segment:offset
25-
mov [dap_mem + 2], word 0x0000
10+
mov si, load_msg
11+
call print
2612

27-
; INT 13h Extended Read (0x42)
28-
mov si, disk_address_packet
29-
mov dl, [boot_drive]
13+
; Setup Disk Address Packet (DAP) for partition start (LBA 2048)
14+
mov si, dap
3015
mov ah, 0x42
16+
mov dl, 0x80 ; First hard disk
3117
int 0x13
3218
jc disk_error
33-
34-
; Jump to loaded VBR/Stage2
35-
jmp 0:0x8000
19+
; Far jump to loaded VBR at 0x0000:0x7E00
20+
jmp 0x0000:0x7E00
3621

3722
disk_error:
38-
mov si, err_msg
39-
.print_err:
40-
lodsb
41-
or al, al
42-
jz $
23+
mov si, error_msg
24+
call print
25+
jmp $
26+
27+
print:
4328
mov ah, 0x0E
29+
.next_char:
30+
lodsb
31+
cmp al, 0
32+
je .done
4433
int 0x10
45-
jmp .print_err
46-
47-
; --- Disk Address Packet ---
48-
disk_address_packet:
49-
db 0x10 ; Size
50-
db 0x00 ; Reserved
51-
dw 1 ; Sectors to read
52-
dap_mem:
53-
dw 0x8000 ; Offset
54-
dw 0x0000 ; Segment
55-
dap_lba:
56-
dd 0x00000800 ; LBA = 2048
57-
dd 0x00000000 ; LBA high dword
58-
59-
boot_drive: db 0
60-
err_msg db "Disk Error", 0
61-
62-
times 510 - ($ - $$) db 0
63-
dw 0xAA55
34+
jmp .next_char
35+
.done:
36+
ret
37+
38+
load_msg db "MBR: Loading VBR...", 0
39+
error_msg db "MBR: Disk read error!", 0
40+
41+
; --- Disk Address Packet (DAP) ---
42+
dap:
43+
db 0x10 ; size of DAP
44+
db 0x00 ; reserved
45+
dw 0x0003 ; number of sectors to read
46+
dw 0x7E00 ; offset
47+
dw 0x0000 ; segment
48+
dq 2050 ; LBA - VBR location
49+
50+
times 446 - ($ - $$) db 0 ; Pad to partition table
51+
52+
; === Partition Table ===
53+
db 0x80 ; Bootable
54+
db 0x01, 0x01, 0x00 ; CHS start — dummy
55+
db 0x0C ; FAT32 (LBA)
56+
db 0xFE, 0xFF, 0xFF ; CHS end — dummy
57+
dd 3000 ; LBA of first sector of partition
58+
dd 260096 ; Number of sectors in partition (262144 - 2048)
59+
60+
times 3*16 db 0 ; Empty partitions
61+
dw 0xAA55 ; Boot signature

0 commit comments

Comments
 (0)