Permalink
Browse files

I BROKE EVERYTHING

  • Loading branch information...
charliesome committed May 14, 2011
1 parent fcb7501 commit 917a76dfa2be4730b4e3d26491d77c221f116d56
View
@@ -8,3 +8,6 @@ kbin/*
hdd.img
hdd.base.img.old
+
+.*
+._*
View
@@ -1,7 +1,7 @@
# configuration file generated by Bochs
plugin_ctrl: unmapped=1, biosdev=1, speaker=1, extfpuirq=1, gameport=1, pci_ide=1, acpi=1, ioapic=1
config_interface: textconfig
-display_library: x
+display_library: wx
memory: host=32, guest=32
romimage: file="/usr/share/bochs/BIOS-bochs-latest"
vgaromimage: file="/usr/share/bochs/VGABIOS-lgpl-latest"
@@ -25,8 +25,7 @@ usb_ohci: enabled=0
i440fxsupport: enabled=1
vga_update_interval: 50000
vga: extension=vbe
-cpu: count=1, ips=4000000, reset_on_triple_fault=1, ignore_bad_msrs=1
-cpuid: cpuid_limit_winnt=0, mmx=1, sse=sse2, xapic=1, sep=1, aes=0, xsave=0, movbe=0, 1g_pages=0
+cpu: count=1, ips=2000000, reset_on_triple_fault=0, cpuid_limit_winnt=0
print_timestamps: enabled=0
# no gdb stub
port_e9_hack: enabled=0
@@ -40,7 +39,7 @@ sb16: enabled=0
# no loader
log: -
logprefix: %t%e%d
-panic: action=ask
+panic: action=ignore
error: action=report
info: action=report
debug: action=ignore
View
102 build.sh
@@ -1 +1,101 @@
-make all -j 8
+#!/bin/bash
+
+rm kbin/*
+
+for f in $(find build | grep "/\."); do
+ rm $f
+done
+
+CFLAGS="-std=c99 -Wall -Wextra -nostdlib -fno-builtin -nostartfiles -nodefaultlibs -fno-exceptions -fno-stack-protector -c -masm=intel "
+KCFLAGS="-iquote kinc $CFLAGS $1"
+USERCFLAGS="-Iuinc $CFLAGS"
+
+nasm -f elf -o kbin/aaa_loader_asm.o ksrc/loader.asm
+nasm -f elf -o kbin/helper_asm.o ksrc/helper.asm
+nasm -f elf -o kbin/aaa_panic_asm.o ksrc/panic.asm
+nasm -f elf -o kbin/isrs_asm.o ksrc/isrs.asm
+nasm -f elf -o kbin/task_asm.o ksrc/task.asm
+nasm -f elf -o kbin/syscall_asm.o ksrc/syscall.asm
+
+#build the CRT
+
+rm ubin/* &> /dev/null
+nasm -f elf -o ubin/crt.o user/crt/csos.asm
+gcc $USERCFLAGS user/crt/stdlib.c -o ubin/stdlib.o
+gcc $USERCFLAGS user/crt/stdio.c -o ubin/stdio.o
+gcc $USERCFLAGS user/crt/string.c -o ubin/string.o
+rm user/crt.a
+ar q user/crt.a ubin/*.o
+
+#user mode crap
+ rm ubin/* &> /dev/null
+ gcc $USERCFLAGS user/init.c -o ubin/init.o
+ ld -T user_linker.ld -o build/init.bin ubin/*.o user/crt.a user/csoslua.a #user/pdclib/functions/stdlib/*.o user/pdclib/functions/_PDCLIB/*.o user/pdclib/functions/stdio/*.o user/pdclib/functions/string/*.o
+
+gcc -std=c99 -o util/bin2nasm util/bin2nasm.c
+# custom binaries to include in image!!
+
+ # realmode.bin
+ nasm -f bin -o kbin/realmode_asm.bin ksrc/realmode/realmode.asm
+ util/bin2nasm code16 < kbin/realmode_asm.bin > kbin/tmp.asm
+ nasm -f elf -o kbin/realmode_asm.o kbin/tmp.asm
+ rm kbin/tmp.asm
+
+ # ata.bin
+ nasm -f bin -o kbin/realmode_ata.bin ksrc/realmode/ata.asm
+ util/bin2nasm ata16 < kbin/realmode_ata.bin > kbin/tmp.asm
+ nasm -f elf -o kbin/realmode_ata.o kbin/tmp.asm
+ rm kbin/tmp.asm
+
+ # int.bin
+nasm -f bin -o kbin/realmode_int.bin ksrc/realmode/int.asm
+ util/bin2nasm int16 < kbin/realmode_int.bin > kbin/tmp.asm
+ nasm -f elf -o kbin/realmode_int.o kbin/tmp.asm
+ rm kbin/tmp.asm
+
+gcc $KCFLAGS ksrc/main.c -o kbin/main.o
+gcc $KCFLAGS ksrc/console.c -o kbin/console.o
+gcc $KCFLAGS ksrc/string.c -o kbin/string.o
+gcc $KCFLAGS ksrc/io.c -o kbin/io.o
+gcc $KCFLAGS ksrc/util.c -o kbin/util.o
+gcc $KCFLAGS ksrc/gdt.c -o kbin/gdt.o
+gcc $KCFLAGS ksrc/idt.c -o kbin/idt.o
+gcc $KCFLAGS ksrc/io.c -o kbin/io.o
+gcc $KCFLAGS ksrc/panic.c -o kbin/panic.o
+gcc $KCFLAGS ksrc/kmalloc.c -o kbin/kmalloc.o
+gcc $KCFLAGS ksrc/realmode.c -o kbin/realmode.o
+gcc $KCFLAGS ksrc/ata.c -o kbin/ata.o
+gcc $KCFLAGS ksrc/kb.c -o kbin/kb.o
+gcc $KCFLAGS ksrc/part.c -o kbin/part.o
+gcc $KCFLAGS ksrc/fs/fat.c -o kbin/fs_fat.o
+gcc $KCFLAGS ksrc/fs/vfs.c -o kbin/fs_vfs.o
+gcc $KCFLAGS ksrc/task.c -o kbin/task.o
+gcc $KCFLAGS ksrc/trap.c -o kbin/trap.o
+gcc $KCFLAGS ksrc/paging.c -o kbin/paging.o
+gcc $KCFLAGS ksrc/syscall.c -o kbin/syscall.o
+
+ld -T kernel_linker.ld -o build/kernel.sys kbin/*.o
+gcc -std=c99 -o util/inject_symbols util/inject_symbols.c
+perl util/find_symbols.pl build/kernel.sys | util/inject_symbols build/kernel.sys
+
+HDDIMG=hdd.img
+
+dd if=/dev/zero of=$HDDIMG bs=33546240 count=1 status=noxfer &>/dev/null
+
+parted --script $HDDIMG mklabel msdos
+parted --script $HDDIMG mkpartfs primary fat16 0 31 &> /dev/null
+parted --script $HDDIMG mkfs 1 fat16 &> /dev/null
+parted --script $HDDIMG set 1 boot on
+
+rm -rf mnt
+mkdir mnt
+sudo chmod -R 0777 mnt
+sudo mount -o loop,offset=512 $HDDIMG mnt
+sudo chmod 0777 mnt
+sudo cp -r build/* mnt
+sudo umount mnt
+sudo rm -rf mnt
+
+grub --device-map=/dev/null --batch < grubscript &> /dev/null
+
+#gzip -c -9 $HDDIMG > hdd.img.gz
View
Binary file not shown.
View
Binary file not shown.
View
@@ -1,3 +1,4 @@
device (hd0) hdd.img
root (hd0,0)
setup (hd0,0)
+
View
@@ -22,4 +22,4 @@ SECTIONS{
*(.bss)
ebss = .;
}
-}
+}
View
@@ -11,6 +11,4 @@ typedef unsigned long size_t;
#define offsetof(st, m) \
((size_t) ( (char *)&((st *)(0))->m - (char *)0 ))
-#define PAGE_SIZE 4096
-
-#endif
+#endif
View
@@ -12,9 +12,6 @@ struct fat_vfs_state
fat_volume_t volume;
};
-//#define KDEBUG(x...) { kprintf("%s:%d: ", __FILE__, __LINE__, __func__); kprintf(x); }
-#define KDEBUG(x...) {}
-
bool fat_vfs_exists(struct fat_vfs_state* state, char* path);
vfs_type_t fat_vfs_type(struct fat_vfs_state* state, char* path);
size_t fat_vfs_size(struct fat_vfs_state* state, char* path);
@@ -30,27 +27,18 @@ static void fat_read_cached(struct fat_vfs_state* state)
vfs_provider_t* fat_vfs(uchar bios_drive, partition_t* partition)
{
- KDEBUG("Entered fat_vfs\n");
-
vfs_provider_t* prov = (vfs_provider_t*)kmalloc(sizeof(vfs_provider_t));
struct fat_vfs_state* state = (struct fat_vfs_state*)kmalloc(sizeof(struct fat_vfs_state));
prov->state = state;
state->prov = prov;
partition_t* part = (partition_t*)kmalloc(sizeof(partition_t));
memcpy(part, partition, sizeof(partition_t));
-
- KDEBUG("Past malloc() calls\n");
fat_init(bios_drive, part, &state->volume);
- KDEBUG("Returned from fat_init()\n");
-
- KDEBUG("Setting state struct\n");
+
state->volume.root_entries = (fat_entry_t*)kmalloc(32 * state->volume.bpb.root_entry_count);
state->volume.fat = (short*)kmalloc(512 * state->volume.bpb.sectors_per_fat);
-
- KDEBUG("About to read\n");
fat_read_cached(state);
- KDEBUG("Setting prov struct\n");
prov->fs_name = "FAT16";
prov->exists = (bool(*)(void*,char*))fat_vfs_exists;
prov->type = (vfs_type_t(*)(void*,char*))fat_vfs_type;
View
@@ -36,14 +36,16 @@ uint isr_dispatch(uint interrupt, uint errorcode)
{
if(interrupt == 39) // spurious IRQ 7
return interrupt;
-
+
+ /*
+ // for debugging purposes
+ if(interrupt != 32)
+ kprintf("Interrupt %d, error %x\n", interrupt, errorcode);
+ */
+
if(isr_handlers[interrupt])
isr_handlers[interrupt](interrupt, errorcode);
- // for debugging purposes
-// if(interrupt != 32)
-// kprintf("Interrupt %d, error %x\n", interrupt, errorcode);
-
return interrupt; // important for the assembly handler
}
void idt_register_handler(uint interrupt, uint handler_ptr)
View
@@ -19,7 +19,6 @@ extern kprintf
mov eax, [.eax]
pusha
mov eax, [.err]
-
%2
push dword %1
jmp isr_main
View
@@ -52,9 +52,9 @@ void* _kmalloc(size_t len)
if(chunksize == len + 4)
break;
}
-
- if(chunksz == 0) { // no chunk was big enough, fail to allocate memory
- panic("Could not find a sufficiently large chunk");
+ if(chunksz == 0) // no chunk was big enough, fail to allocate memory
+ {
+ panicf("kmalloc failed. No memory to allocate.");
return NULL;
}
@@ -85,33 +85,29 @@ void _kfree(void* ptr)
size_t len = *(size_t*)begin;
char* end = begin + len;
- // first, try to insert the chunk into existing chunks
- bool chunk_returned = false;
- uint freed_chunk = 0;
+ uint free_slot = n_chunks++; // if we're going to add a chunk to the end, make sure to increment n_chunks
for(uint i = 0; i < n_chunks; i++)
{
if(!chunks[i].present)
{
- chunks[i].present = true;
- chunks[i].begin = begin;
- chunks[i].end = end;
- chunk_returned = true;
- freed_chunk = i;
+ // if it turns out we WON'T use a chunk at the end, take off that increment we put before
+ n_chunks--;
+
+ free_slot = i;
break;
}
}
- // if we failed to return the chunk, append it to the end
- if (!chunk_returned) {
- freed_chunk = n_chunks++;
- chunks[freed_chunk].present = true;
- chunks[freed_chunk].begin = begin;
- chunks[freed_chunk].end = end;
- }
+ chunks[free_slot].present = true;
+ chunks[free_slot].begin = begin;
+ chunks[free_slot].end = end;
- while(mm_fix_chunk(freed_chunk, &freed_chunk)) ;
+ uint c = free_slot;
+ while(mm_fix_chunk(c, &c)) ;
#ifdef MALLOC_PRINT_DEBUG
kprintf("freed.\n", len, file, line);
+ file = file;
+ line = line;
#endif
}
@@ -143,4 +139,4 @@ static bool mm_fix_chunk(uint chunk, uint* next_chunk)
}
return false;
-}
+}
View
@@ -20,7 +20,7 @@
void kmain(struct multiboot_info* mbd, unsigned int magic)
{
- if(magic != MULTIBOOT_BOOTLOADER_MAGIC)
+ if(magic != 0x2BADB002)
{
panic("Multiboot did not pass correct magic number");
}
@@ -45,11 +45,12 @@ void kmain(struct multiboot_info* mbd, unsigned int magic)
cli();
idt_init();
trap_init();
- sti();
kb_init();
task_init(0x00800000, mbd->mem_upper);
+ sti();
+
partition_t part;
part_read(boot_drive, 0, &part);
@@ -58,8 +59,9 @@ void kmain(struct multiboot_info* mbd, unsigned int magic)
kprint("Ok.\n");
uint init_size = vfs_size("/init.bin");
- char* buff = kmalloc(((init_size + PAGE_SIZE-1) / PAGE_SIZE) * PAGE_SIZE);
+ char* buff = kmalloc(((init_size + 4095) / 4096) * 4096);
vfs_readfile("/init.bin", 0, init_size, buff);
+
task_create(init_size, buff, 4096);
// task_create(init_size, buff, 4096);
View
@@ -13,12 +13,12 @@ void paging_init(uint mb)
memset(page_directory, 0, sizeof(uint) * 1024);
for(uint dir_i = 0; dir_i < (mb + 3) / 4; dir_i++)
{
- uint* table = (uint*)(0x00400000 + (PAGE_SIZE * dir_i));
+ uint* table = (uint*)(0x00400000 + (4096 * dir_i));
page_directory[dir_i] = ((uint)table & 0xfffff000) | 1;
for(uint tbl_i = 0; tbl_i < 1024; tbl_i++)
{
- table[tbl_i] = ((dir_i * 1024 + tbl_i) * PAGE_SIZE) | 1;
+ table[tbl_i] = ((dir_i * 1024 + tbl_i) * 4096) | 1;
}
}
@@ -36,15 +36,15 @@ void paging_map(uint virtual, uint physical, bool user)
if(physical & 0xff)
panic("Physical address not page-aligned");
- virtual /= PAGE_SIZE;
+ virtual /= 4096;
uint dir_i = virtual / 1024;
uint tbl_i = virtual % 1024;
uint* table = (uint*)(page_directory[dir_i] & 0xfffff000);
if(table[tbl_i] & 1)
panic("Tried to map already mapped page table entry");
-
+
table[tbl_i] = (physical & 0xfffff000) | 1 | 2 | (user ? 4 : 0);
__asm__ volatile("mov cr3, eax" :: "a"(page_directory)); // invalidate TLB cache
@@ -55,7 +55,7 @@ void paging_unmap(uint virtual)
if(virtual & 0xfff)
panic("Virtual address not page-aligned");
- virtual /= PAGE_SIZE;
+ virtual /= 4096;
uint dir_i = virtual / 1024;
uint tbl_i = virtual % 1024;
@@ -71,7 +71,7 @@ void paging_unmap(uint virtual)
uint paging_virtual_to_physical(uint* page_directory, uint virtual)
{
- uint* table = (uint*)(page_directory[(virtual / PAGE_SIZE) / 1024] & 0xfffff000);
- uint phys = table[(virtual / PAGE_SIZE) % 1024] & 0xfffff000;
+ uint* table = (uint*)(page_directory[(virtual / 4096) / 1024] & 0xfffff000);
+ uint phys = table[(virtual / 4096) % 1024] & 0xfffff000;
return phys | (virtual & 0xfff);
-}
+}
View
@@ -26,9 +26,8 @@ syscall_isr:
mov fs, ax
mov es, ax
- push dword [.saved_esp]
+ ;push dword [.saved_esp]
push esp
-
call syscall_handler
add esp, 4
Oops, something went wrong.

0 comments on commit 917a76d

Please sign in to comment.