Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
xing1357 committed Aug 12, 2023
1 parent ccc7379 commit 74ffe25
Show file tree
Hide file tree
Showing 41 changed files with 599 additions and 133 deletions.
Binary file modified .DS_Store
Binary file not shown.
12 changes: 10 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ DEFINES=

# qemu
QEMU= qemu-system-i386
QEMU_FLAGS= -m 64 -cdrom out/SimpleOS.iso -drive file=ext2.img,format=raw
QEMU_FLAGS= -boot d -cdrom out/SimpleOS.iso -drive file=fat32.img,format=raw

# assembler flags
ASM_FLAGS = -f elf32
# compiler flags
CC_FLAGS = $(INCLUDE) $(DEFINES) -m32 -std=gnu99 -ffreestanding -Wall -Wextra
CC_FLAGS = $(INCLUDE) $(DEFINES) -m32 -std=gnu99 -ffreestanding -Wall -Wextra
# linker flags, for linker add linker.ld file too
LD_FLAGS = -m elf_i386 -T $(CONFIG)/linker.ld -nostdlib --allow-multiple-definition

Expand Down Expand Up @@ -56,6 +56,9 @@ OBJECTS=$(ASM_OBJ)/entry.o $(ASM_OBJ)/load_gdt.o\
$(OBJ)/vesa.o\
$(OBJ)/bitmap.o\
$(OBJ)/panic.o\
$(OBJ)/fat32.o\



all: $(OBJECTS)
@printf "[ linking... ]\n"
Expand Down Expand Up @@ -209,6 +212,11 @@ $(OBJ)/panic.o : $(SRC)/panic.c
$(CC) $(CC_FLAGS) -c $(SRC)/panic.c -o $(OBJ)/panic.o
@printf "\n"

$(OBJ)/fat32.o : $(SRC)/fat32.c
@printf "[ $(SRC)/fat32.c ]\n"
$(CC) $(CC_FLAGS) -c $(SRC)/fat32.c -o $(OBJ)/fat32.o
@printf "\n"

run:
$(QEMU) $(QEMU_FLAGS)

Expand Down
Binary file added fat32.img
Binary file not shown.
12 changes: 6 additions & 6 deletions include/ext2.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,17 @@ typedef struct ext2_inode
typedef struct ext2_dirent
{
uint32 inode;
uint32 dirent_size;
uint32 name_len;
uint32 type;
char* name;
uint16 dirent_size;
uint16 name_len;
uint8 type;
uint8* name;
} ext2_dirent;

ext2_superblock* sb;

void read_superblock();
ext2_superblock* read_superblock();
void ext2_init();
char* ext2_read_file(char* fpath);
char** ext2_ls(uint32 inode_num);
int ext2_ls(uint32 inode_num);
uint32 ext2_path_to_inode(char* path);
#endif
66 changes: 66 additions & 0 deletions include/fat32.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#ifndef FAT32_H
#define FAT32_H

#include "types.h"

typedef struct fat_bpb
{
unsigned char bootjmp[3];
unsigned char oem_name[8];
unsigned short bytes_per_sector;
unsigned char sectors_per_cluster;
unsigned short reserved_sector_count;
unsigned char table_count;
unsigned short root_entry_count;
unsigned short total_sectors_16;
unsigned char media_type;
unsigned short table_size_16;
unsigned short sectors_per_track;
unsigned short head_side_count;
unsigned int hidden_sector_count;
unsigned int total_sectors_32;
//Fat32 Extended BPBL
unsigned int table_size_32;
unsigned short extended_flags;
unsigned short fat_version;
unsigned int root_cluster;
unsigned short fat_info;
unsigned short backup_BS_sector;
unsigned char reserved_0[12];
unsigned char drive_number;
unsigned char reserved_1;
unsigned char boot_signature;
unsigned int volume_id;
unsigned char volume_label[11];
unsigned char fat_type_label[8];

}__attribute__((packed)) fat_bpb;

typedef struct
{
uint8 Name[11];
uint8 Attributes;
uint8 Reserved;
uint8 CreatedTimeTenths;
uint16 CreatedTime;
uint16 CreatedDate;
uint16 AccessedDate;
uint16 FirstClusterHigh;
uint16 ModifiedTime;
uint16 ModifiedDate;
uint16 FirstClusterLow;
uint32 Size;
} __attribute__((packed)) FAT_dirent;

typedef struct fat_file
{
BOOL is_dir;
uint32 position;
uint32 size;
} fat_file;

void fat_init();
char* fat_read_file(char* fpath);
uint32 fat_path_to_cluster(const char* path);
void fat_dir_ls(uint32 cluster);
#endif
28 changes: 28 additions & 0 deletions log.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
qemu: fatal: invalid tss type
EAX=00000000 EBX=0010b000 ECX=0000000f EDX=0010886e
ESI=00000000 EDI=00000000 EBP=0014385c ESP=0000080a
EIP=00001eb9 EFL=000a0002 [-------] CPL=3 II=0 A20=1 SMM=0 HLT=0
ES =0a1e 0000a1e0 0000ffff 0000f300 DPL=3 DS16 [-WA]
CS =b000 000b0000 0000ffff 0000f300 DPL=3 DS16 [-WA]
SS =7527 00075270 0000ffff 0000f300 DPL=3 DS16 [-WA]
DS =b000 000b0000 0000ffff 0000f300 DPL=3 DS16 [-WA]
FS =3908 00039080 0000ffff 0000f300 DPL=3 DS16 [-WA]
GS =01c7 00001c70 0000ffff 0000f300 DPL=3 DS16 [-WA]
LDT=0000 00000000 0000ffff 00008200 DPL=0 LDT
TR =0000 00000000 0000ffff 00008b00 DPL=0 TSS32-busy
GDT= 00127880 0000003f
IDT= 001278e0 000007ff
CR0=00000011 CR2=00000000 CR3=00000000 CR4=00000000
DR0=00000000 DR1=00000000 DR2=00000000 DR3=00000000
DR6=ffff0ff0 DR7=00000400
CCS=00000000 CCD=00143870 CCO=EFLAGS
EFER=0000000000000000
FCW=037f FSW=0000 [ST=0] FTW=00 MXCSR=00001f80
FPR0=0000000000000000 0000 FPR1=0000000000000000 0000
FPR2=0000000000000000 0000 FPR3=0000000000000000 0000
FPR4=0000000000000000 0000 FPR5=0000000000000000 0000
FPR6=0000000000000000 0000 FPR7=0000000000000000 0000
XMM00=0000000000000000 0000000000000000 XMM01=0000000000000000 0000000000000000
XMM02=0000000000000000 0000000000000000 XMM03=0000000000000000 0000000000000000
XMM04=0000000000000000 0000000000000000 XMM05=0000000000000000 0000000000000000
XMM06=0000000000000000 0000000000000000 XMM07=0000000000000000 0000000000000000
14 changes: 7 additions & 7 deletions mkdisk.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#!/bin/bash
printf "Creating Disk...\n"
dd if=/dev/zero of=ext2.img bs=1024 count=10000 > /dev/zero
mkfs -t ext2 -i 1024 -b 1024 -F ext2.img > /dev/zero
dd if=/dev/zero of=fat32.img bs=1024 count=8192 > /dev/zero
mkfs.fat -F 32 fat32.img
printf "Mounting...\n"
rm -rf /mnt/ext2
mkdir /mnt/ext2
mount ext2.img /mnt/ext2
rm -rf /mnt/fat32
mkdir /mnt/fat32
mount fat32.img /mnt/fat32
printf "MOUNTED!\n"
cp -r rootfs/* /mnt/ext2
umount ext2.img
cp -r rootfs/* /mnt/fat32
umount fat32.img
printf "Done!\n"


Expand Down
Binary file modified obj/8259_pic.o
Binary file not shown.
Binary file modified obj/bios32.o
Binary file not shown.
Binary file modified obj/bitmap.o
Binary file not shown.
Binary file modified obj/console.o
Binary file not shown.
Binary file modified obj/ext2.o
Binary file not shown.
Binary file added obj/fat32.o
Binary file not shown.
Binary file modified obj/gdt.o
Binary file not shown.
Binary file modified obj/gui.o
Binary file not shown.
Binary file modified obj/ide.o
Binary file not shown.
Binary file modified obj/idt.o
Binary file not shown.
Binary file modified obj/io_ports.o
Binary file not shown.
Binary file modified obj/isr.o
Binary file not shown.
Binary file modified obj/kernel.o
Binary file not shown.
Binary file modified obj/keyboard.o
Binary file not shown.
Binary file modified obj/kheap.o
Binary file not shown.
Binary file modified obj/mouse.o
Binary file not shown.
Binary file modified obj/panic.o
Binary file not shown.
Binary file modified obj/pmm.o
Binary file not shown.
Binary file modified obj/string.o
Binary file not shown.
Binary file added obj/task.o
Binary file not shown.
Binary file modified obj/tss.o
Binary file not shown.
Binary file modified obj/vesa.o
Binary file not shown.
Binary file modified obj/vga.o
Binary file not shown.
Binary file modified out/.DS_Store
Binary file not shown.
Binary file modified out/SimpleOS.iso
Binary file not shown.
Binary file modified out/isodir/boot/SimpleOS.bin
Binary file not shown.
43 changes: 43 additions & 0 deletions src/asm/task.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
global write_port
extern timer_handler_main

write_port:
mov edx, [esp + 4]
mov al, [esp + 4 + 4]
out dx, al
ret

global timer_handler
timer_handler:
;cli ; no more interrupts

pushad ; save all registers

push esp ; send the ESP to timer_handler_main
push ebp ; send the EBP to timer_handler_main

call timer_handler_main
;hlt ; we should not get here, halt the cpu

global switch_stack_and_jump
switch_stack_and_jump:
mov ebx, [esp + 8] ; second argument, the function pointer
mov eax, [esp + 4] ; first argument, a location to build a stack
mov esp, eax ; set the stack pointer to the location
mov ebp, esp ; by setting the EBP to the ESP, we configure a new stack
sti ; enable interrupts
jmp ebx ; jump to the function pointer

global switch_stack
switch_stack:
mov ebx, [esp + 8] ; second argument, the stack frame pointer
mov eax, [esp + 4] ; first argument, the stack pointer

mov ebp, ebx ; restore the stack frame
mov esp, eax ; restore the top of the stack

popad ; restore all registers

sti ; OK for interupts at this point
iretd ; perform a return from interrupt since the last task was interrupted

Loading

0 comments on commit 74ffe25

Please sign in to comment.