Skip to content

Commit

Permalink
fc
Browse files Browse the repository at this point in the history
  • Loading branch information
Billibilli committed Aug 22, 2015
0 parents commit dab25b3
Show file tree
Hide file tree
Showing 62 changed files with 5,389 additions and 0 deletions.
7 changes: 7 additions & 0 deletions DEBUG
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
DEBUGGING MP3
===============

The only steps that need to be taken on the virtual machine for debugging
using qemu is to perform a "sudo make debug" (after "make dep"). This will build the disk image needed for QEMU and gdb.

Refer to the handout for instructions on starting QEMU and gdb.
17 changes: 17 additions & 0 deletions INSTALL
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
ECE391 MP3 - Operating System Project
=====================================

To get this skeleton OS running on QEMU, you must do the following steps:

"make dep"
"sudo make"

to build the OS (it is called bootimg) and the QEMU disk image (mp3.img)

You can then follow the instructions in Appendix G to setup your
debug.bat batch script.

If you would like to run MP3 without having to connect gdb (When you are done
and have removed all your bugs for example), you can duplicate the debug.bat
batch script and remove the -s and -S options in the QEMU command. This is
will stop QEMU from waiting for GDB to connect.
42 changes: 42 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

# Makefile for OS project
# To build, first `make dep`, them `make`. Everything should be automatic.
# Will compile all *.c and *.S files in the current directory.


# Flags to use when compiling, preprocessing, assembling, and linking
CFLAGS += -Wall -fno-builtin -fno-stack-protector -nostdlib
ASFLAGS +=
LDFLAGS += -nostdlib -static
CC=gcc

#If you have any .h files in another directory, add -I<dir> to this line
CPPFLAGS +=-nostdinc -g

# This generates the list of source files
SRC = $(wildcard *.S) $(wildcard *.c)

# This generates the list of .o files. The order matters, boot.o must be first
OBJS = boot.o
OBJS += $(filter-out boot.o,$(patsubst %.S,%.o,$(filter %.S,$(SRC))))
OBJS += $(patsubst %.c,%.o,$(filter %.c,$(SRC)))


bootimg: Makefile $(OBJS)
$(CC) $(LDFLAGS) $(OBJS) -Ttext=0x400000 -o bootimg
./debug.sh

dep: Makefile.dep

Makefile.dep: $(SRC)
$(CC) -MM $(CPPFLAGS) $(SRC) > $@

.PHONY: clean
clean:
rm -f *.o Makefile.dep bootimg

ifneq ($(MAKECMDGOALS),dep)
ifneq ($(MAKECMDGOALS),clean)
include Makefile.dep
endif
endif
25 changes: 25 additions & 0 deletions Makefile.dep
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
boot.o: boot.S multiboot.h x86_desc.h types.h
page.o: page.S
stub_handler.o: stub_handler.S
x86_desc.o: x86_desc.S x86_desc.h types.h
file_system.o: file_system.c file_system.h types.h lib.h task.h \
file_desc.h
i8259.o: i8259.c i8259.h types.h lib.h task.h file_desc.h
idt_handler.o: idt_handler.c lib.h types.h task.h file_desc.h \
idt_handler.h i8259.h terminal.h rtc.h
irq0.o: irq0.c irq0.h lib.h types.h task.h file_desc.h i8259.h
kernel.o: kernel.c multiboot.h types.h x86_desc.h lib.h task.h \
file_desc.h i8259.h debug.h idt_handler.h sys_call.h stub_handler.h \
page.h rtc.h terminal.h file_system.h test.h
lib.o: lib.c lib.h types.h task.h file_desc.h
rtc.o: rtc.c rtc.h lib.h types.h task.h file_desc.h
sys_call.o: sys_call.c sys_call.h types.h file_op_table.h lib.h task.h \
file_desc.h idt_handler.h rtc.h file_system.h terminal.h page.h
table.o: table.c task.h types.h file_desc.h lib.h table.h
task.o: task.c task.h types.h file_desc.h page.h x86_desc.h file_system.h \
lib.h i8259.h irq0.h
terminal.o: terminal.c terminal.h types.h lib.h task.h file_desc.h \
table.h
test.o: test.c test.h types.h lib.h task.h file_desc.h multiboot.h \
x86_desc.h i8259.h debug.h idt_handler.h page.h rtc.h terminal.h \
file_system.h
56 changes: 56 additions & 0 deletions boot.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# boot.S - start point for the kernel after GRUB gives us control
# vim:ts=4 noexpandtab

#define ASM 1

#include "multiboot.h"
#include "x86_desc.h"

.text

# Multiboot header (required for GRUB to boot us)
.long MULTIBOOT_HEADER_MAGIC
.long MULTIBOOT_HEADER_FLAGS
.long -(MULTIBOOT_HEADER_MAGIC+MULTIBOOT_HEADER_FLAGS)

# Entrypoint to the kernel
.globl start, _start

.align 4
start:
_start:
# Make sure interrupts are off
cli
jmp continue

continue:
# Load the GDT
lgdt gdt_desc
# Load CS with the new descriptor value
ljmp $KERNEL_CS, $keep_going

keep_going:
# Set up ESP so we can have an initial stack
movl $0x800000, %esp

# Set up the rest of the segment selector registers
movw $KERNEL_DS, %cx
movw %cx, %ss
movw %cx, %ds
movw %cx, %es
movw %cx, %fs
movw %cx, %gs

# Push the parameters that entry() expects (see kernel.c):
# eax = multiboot magic
# ebx = address of multiboot info struct
pushl %ebx
pushl %eax

# Jump to the C entrypoint to the kernel.
call entry

# We'll never get back here, but we put in a hlt anyway.
halt:
hlt
jmp halt
Binary file added boot.o
Binary file not shown.
Binary file added bootimg
Binary file not shown.
Binary file added debug-gdb.lnk
Binary file not shown.
33 changes: 33 additions & 0 deletions debug.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* debug.h - Useful macros for debugging
* vim:ts=4 noexpandtab
*/

#ifndef _DEBUG_H
#define _DEBUG_H

#ifndef ASM

#ifdef DEBUG

#define ASSERT(EXP) \
do { \
if(!(EXP)) { \
printf(__FILE__ ":%u: Assertion `" #EXP "\' failed.\n", __LINE__); \
} \
} while(0)

#define debugf(...) \
do { \
printf(__FILE__ ":%u: ", __LINE__); \
printf(__VA_ARGS__); \
} while(0)

#else
#define ASSERT(EXP) \
while(0)
#define debugf(...) \
while(0)
#endif

#endif
#endif /* _DEBUG_H */
Binary file added debug.lnk
Binary file not shown.
23 changes: 23 additions & 0 deletions debug.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/sh

if [ -d /mnt/tmpmp3 ]; then
rmdir /mnt/tmpmp3
fi

if [ -d /tmp/mp3 ]; then
rm -rf /tmp/mp3
fi

mkdir /mnt/tmpmp3
mkdir /tmp/mp3
cp ./bootimg /tmp/mp3/
cp ./filesys_img /tmp/mp3/
cp ./mp3.img /tmp/mp3/
mount -o loop,offset=32256 /tmp/mp3/mp3.img /mnt/tmpmp3
cp -f /tmp/mp3/bootimg /mnt/tmpmp3/
cp -f /tmp/mp3/filesys_img /mnt/tmpmp3/
umount /mnt/tmpmp3
cp -f /tmp/mp3/mp3.img ./
rm -rf /tmp/mp3
rmdir /mnt/tmpmp3

Binary file added devel machine.lnk
Binary file not shown.
21 changes: 21 additions & 0 deletions file_desc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef _FILE_DESC_H
#define _FILE_DESC_H

typedef struct filedescriptor{
void* file_operations_pointer;
uint32_t inode_pointer;
uint32_t file_position;
uint32_t flags;
}filedescriptor_t;


typedef struct file_type_op_action{
int32_t (*open)(filedescriptor_t*,void*);
int32_t (*read)(filedescriptor_t* , void*, uint32_t);
int32_t (*write)(filedescriptor_t* , const void*, uint32_t);
}file_type_op_action_t;


#endif


155 changes: 155 additions & 0 deletions file_op_table.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
#ifndef _FILE_OP_TABLE_H
#define _FILE_OP_TABLE_H
#include "lib.h"
#include "idt_handler.h"
#include "rtc.h"
#include "file_system.h"
#include "terminal.h"
#include "file_desc.h"
#define debug_fread_f_d 0
#define debug_fread_f_d_freq 51
#if debug_fread_f_d
static int32_t debug_fread_f_d_k=debug_fread_f_d_freq;
#endif

static int32_t fopen_f_d(filedescriptor_t* fdstruct,void* buf)
{
return -1;
}

static int32_t fread_f_d(filedescriptor_t* fdstruct, void* buf, uint32_t n_bytes)
{


//char buff[n_bytes];
//char * pointer =(char *) buf;
//int32_t h;
uint32_t temp;
//uint32_t temp2;
//uint32_t inode = fdstruct->inode_pointer;
//uint32_t n_bytes1 = n_bytes;
//printf("indoe %d",fdstruct->inode_pointer);
//printf("fb %x",(uint32_t)*(uint32_t*)(fdstruct->inode_pointer));
if(fdstruct->inode_pointer == 0)
{
//printf( "directory: %d",fdstruct->file_position);
temp = read_data(fdstruct->inode_pointer, fdstruct->file_position, (uint8_t*) buf, n_bytes);
fdstruct->file_position += n_bytes;

}
else
{
temp = read_data(fdstruct->inode_pointer, fdstruct->file_position, (uint8_t*) buf, n_bytes);
fdstruct->file_position += temp;
if(temp == 0)
{
//printf( "cao ni ma quan jia ");

}

}
// don grep excutebe file
if(*(uint32_t*) buf == 0x464c457f )
return 0;
//temp2 = fdstruct->file_position;
// if(temp == -1)
// fdstruct->file_position = 0;
// for(h = temp; h < strlen((uint8_t*)buf); h++)
// pointer[h]=0;
//printf( "%c",*pointer);
#if debug_fread_f_d
debug_fread_f_d_k--;
if (debug_fread_f_d_k==0) {
printf("Buf is %s\n",buf);
printf("return data byte read:%d\n",temp);
while(1);
}
#endif
//printf( "\n %s ",buf);
return temp;

}

static int32_t fwrite_f_d(filedescriptor_t* fdstruct, const void* buf, uint32_t n_bytes)
{
return -1;
}

static int32_t fopen_rtc(filedescriptor_t* fdstruct,void* buf)
{
return 0;
}

static int32_t fread_rtc(filedescriptor_t* fdstruct, void* buf, uint32_t n_bytes)
{
sti();
read_rtc();
cli();
return 0;
}

static int32_t fwrite_rtc(filedescriptor_t* fdstruct, const void* buf, uint32_t n_bytes)
{

// printf( "fwrite_rtc %d",(int)*(int*)buf);
// char *type = NULL;
// char temp =*type;
cli();
write_rtc((int)*(int*)buf);
sti();
return 0;
}

static int32_t termin_read(filedescriptor_t* fdstruct, void* buf, uint32_t n_bytes)
{
sti();
return r_terminal(0x00,(uint8_t*) buf, n_bytes);


}

static int32_t termin_open(filedescriptor_t* fdstruct,void* buf)
{
open_terminal(0x00);
return 0;
}

static int32_t termin_write(filedescriptor_t* fdstruct, const void* buf, uint32_t n_bytes)
{

printf( "%s",buf);
return 0;
}


//no
file_type_op_action_t RTC_type_op = {
.open =&fopen_rtc,
.write= &fwrite_rtc,
.read= &fread_rtc};



//DIRECTORY
file_type_op_action_t directry_type_op = {
.open = &fopen_f_d,
.write= &fwrite_f_d,
.read = &fread_f_d};



//REGULER FILE
file_type_op_action_t file_type_op = {
.open = &fopen_f_d,
.write= &fwrite_f_d,
.read = &fread_f_d};

file_type_op_action_t terminal_type_op = {
.open = &termin_open,
.write= &termin_write,
.read = &termin_read};


#endif


Loading

0 comments on commit dab25b3

Please sign in to comment.