Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

I BROKE EVERYTHING

  • Loading branch information...
commit 917a76dfa2be4730b4e3d26491d77c221f116d56 1 parent fcb7501
@charliesome authored
View
3  .gitignore
@@ -8,3 +8,6 @@ kbin/*
hdd.img
hdd.base.img.old
+
+.*
+._*
View
7 bochslinux.bxrc
@@ -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
BIN  build/init.bin
Binary file not shown
View
BIN  build/kernel.sys
Binary file not shown
View
1  grubscript
@@ -1,3 +1,4 @@
device (hd0) hdd.img
root (hd0,0)
setup (hd0,0)
+
View
2  kernel_linker.ld
@@ -22,4 +22,4 @@ SECTIONS{
*(.bss)
ebss = .;
}
-}
+}
View
4 kinc/stddef.h
@@ -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
14 ksrc/fs/fat.c
@@ -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
12 ksrc/idt.c
@@ -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
1  ksrc/isrs.asm
@@ -19,7 +19,6 @@ extern kprintf
mov eax, [.eax]
pusha
mov eax, [.err]
-
%2
push dword %1
jmp isr_main
View
36 ksrc/kmalloc.c
@@ -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
8 ksrc/main.c
@@ -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
16 ksrc/paging.c
@@ -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,7 +36,7 @@ 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;
@@ -44,7 +44,7 @@ void paging_map(uint virtual, uint physical, bool user)
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
3  ksrc/syscall.asm
@@ -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
View
2  ksrc/task.asm
@@ -121,7 +121,7 @@ task_switch:
; EIP:
mov eax, [ebx + 0x20]
push eax
-
+
mov ebp, [ebx + 0x3c]
mov esi, [ebx + 0x40]
mov edi, [ebx + 0x44]
View
44 ksrc/task.c
@@ -36,11 +36,11 @@ task_t* task_get(uint pid)
void task_init(uint base_physical, uint high_memory)
{
user_base = base_physical;
- page_base = base_physical / PAGE_SIZE;
- total_pages = (high_memory * 1024 - base_physical) / PAGE_SIZE;
+ page_base = base_physical / 4096;
+ total_pages = ((high_memory * 1024) - base_physical) / 4096;
kprintf("Total pages: %d\n", total_pages);
- pagemap = (uchar*)kmalloc(total_pages / 8);
- memset(pagemap, 0, total_pages / 8);
+ pagemap = (uchar*)kmalloc((total_pages + 7) / 8);
+ memset(pagemap, 0, (total_pages + 7) / 8);
// setup GDT entries for tasks
gdt_entry_t task_seg;
@@ -71,7 +71,7 @@ uint alloc_page()
continue;
pagemap[i] |= 1 << j;
- return (i * 8 + j + page_base) * PAGE_SIZE;
+ return (i * 8 + j + page_base) << 12;
}
}
panic("No free pages");
@@ -79,9 +79,8 @@ uint alloc_page()
}
void free_page(uint page)
{
- page /= PAGE_SIZE;
- uint pdiv = page/8, pmod = page%8;
-
+ page >>= 12;
+
if(page < page_base || page >= total_pages + page_base)
panic("Freeing non-existent page");
@@ -90,18 +89,17 @@ void free_page(uint page)
if(((pagemap[page / 8] >> (page % 8)) & 1) == 0)
panicf("Freeing freed page: %x (%x), pagemap %x", page, page << 12, pagemap[page / 8] & 0xff);
- pagemap[pdiv] &= ~(1 << pmod);
+ pagemap[page / 8] &= ~(1 << (page % 8));
}
-
task_t* task_create(uint size, void* code, uint stack_size)
{
- if(num_tasks == MAX_TASKS) {
- kprintf("Failed to create a task");
+ if(num_tasks == MAX_TASKS)
return NULL;
- }
- uint stack_pages = (stack_size + PAGE_SIZE-1) / PAGE_SIZE;
- uint codedata_pages = (size + PAGE_SIZE-1) / PAGE_SIZE;
+ uint stack_pages = (stack_size + 4095) / 4096;
+ uint codedata_pages = (size + 4095) / 4096;
+
+ kprintf("Allocating %d pages for task, plus %d stack pages\n", codedata_pages, stack_pages);
task_t* task = (task_t*)kmalloc(sizeof(task_t));
memset(task, 0, sizeof(task_t));
@@ -109,20 +107,20 @@ task_t* task_create(uint size, void* code, uint stack_size)
uint total_pages = stack_pages + codedata_pages;
uint total_dir_entries = (total_pages + 1023) / 1024;
task->tss.cr3 = (uint)(task->page_directory = (uint*)alloc_page());
- memset(task->page_directory, 0, PAGE_SIZE);
+ memset(task->page_directory, 0, 4096);
memcpy(task->page_directory, page_directory, 4 /* copy only first page directory (4MB) of ram. this is what the kernel will be using */);
for(uint i = 0; i < total_dir_entries; i++)
{
- task->page_directory[((0x10000000 / PAGE_SIZE) / 1024) + i] = alloc_page() | 1 | 2 | 4;
+ task->page_directory[((0x10000000 / 4096) / 1024) + i] = alloc_page() | 1 | 2 | 4;
}
for(uint i = 0; i < total_pages; i++)
{
uint dir = i / 1024;
- uint* table = (uint*)(task->page_directory[dir + ((0x10000000 / PAGE_SIZE) / 1024)] & 0xfffff000);
+ uint* table = (uint*)(task->page_directory[dir + ((0x10000000 / 4096) / 1024)] & 0xfffff000);
uint phys = alloc_page();
table[i % 1024] = phys | 1 | 2 | 4;
- if(i * PAGE_SIZE < size)
- memcpy((void*)phys, (char*)code + (PAGE_SIZE * i), PAGE_SIZE);
+ if(i * 4096 < size)
+ memcpy((void*)phys, (char*)code + (4096 * i), (i+1) * 4096 > size ? size % 4096 : 4096);
}
task->state = RUNNING;
@@ -136,7 +134,7 @@ task_t* task_create(uint size, void* code, uint stack_size)
task->tss.eflags |= 0x200; // interrupts enabled
task->tss.eip = 0x10000000;
- task->tss.esp = 0x10000000 + total_pages * PAGE_SIZE - 4;
+ task->tss.esp = 0x10000000 + total_pages * 4096 - 4;
// find free pid
uint pid = 0;
@@ -151,7 +149,6 @@ task_t* task_create(uint size, void* code, uint stack_size)
return task;
}
-
task_t* task_dup(task_t* task)
{
if(num_tasks == MAX_TASKS)
@@ -208,7 +205,6 @@ task_t* task_dup(task_t* task)
return copy;
}
-
void task_kill_and_free(task_t* task)
{
if(task->state == KILLED)
@@ -225,7 +221,7 @@ void task_kill_and_free(task_t* task)
__asm__("mov cr3, eax" :: "a"(&page_directory));
}
// work through page directory starting at 0x10000000 freeing pages
- for(uint dir_i = 0x10000000 / PAGE_SIZE / 1024; dir_i < 1024; dir_i++)
+ for(uint dir_i = 0x10000000 / 4096 / 1024; dir_i < 1024; dir_i++)
{
if(!(task->page_directory[dir_i] & 1))
{
View
6 ksrc/trap.c
@@ -39,13 +39,13 @@ static char* traps[] = {
"Security Exception"
};
-static void trap_handler(uint interrupt, uint error, interrupt_stack_t* int_stack)
+static void trap_handler(uint interrupt, uint error/*, interrupt_stack_t* int_stack*/)
{
uint cr2;
__asm__("mov eax, cr2" : "=a"(cr2));
- if(interrupt == 13)
+ if(/*interrupt == 13*/ true)
{
- kprintf("[#%d] %s. Killed.\n", task_current()->pid, traps[interrupt]);
+ kprintf("[#%d] %s (%d) at 0x%x. Killed.\n", task_current()->pid, traps[interrupt], interrupt, ((uint*)(task_current()->tss.esp0))[-5]);
task_kill_and_free(task_current());
current_task = 0xffffffff;
sti();
View
27 uinc/csos.h
@@ -1,27 +1,20 @@
#ifndef CSOS_H
#define CSOS_H
-#include <_PDCLIB_glue.h>
-
typedef unsigned int uint;
-//extern uint stdin;
-//extern uint stdout;
-//extern uint stderr;
-
-void* alloc_page();
-void* alloc_pages(uint n);
-void free_page(void* page);
+void* sys_alloc_page();
+void sys_free_page(void* page);
-void exit(int status);
+void sys_exit(int status);
-void kill(uint pid);
-uint get_pid();
-uint fork();
+void sys_kill(uint pid);
+uint sys_get_pid();
+uint sys_fork();
-uint write(uint fd, void* buff, uint len);
-uint read(uint fd, void* buff, uint len);
-uint open(char* path);
-void close(uint fd);
+uint sys_write(uint fd, void* buff, uint len);
+uint sys_read(uint fd, void* buff, uint len);
+uint sys_open(char* path);
+void sys_close(uint fd);
#endif
View
BIN  user/crt.a
Binary file not shown
View
BIN  user/crt/crt_asm.o
Binary file not shown
View
BIN  user/crt/crt_c.o
Binary file not shown
View
64 user/crt/csos.asm
@@ -2,20 +2,21 @@ extern main
;;;; syscalls
-global alloc_page ; vec 0x01
-global free_page ; vec 0x02
+global sys_alloc_page ; vec 0x01
+global sys_free_page ; vec 0x02
+global sys_exit
global _PDCLIB_Exit ; vec 0x03
-global kill ; vec 0x04
+global sys_kill ; vec 0x04
-global get_pid ; vec 0x05
-global fork ; vec 0x06
-global write ; vec 0x07
-global read ; vec 0x08
+global sys_get_pid ; vec 0x05
+global sys_fork ; vec 0x06
+global sys_write ; vec 0x07
+global sys_read ; vec 0x08
-global open ; vec 0x09
-global close ; vec 0x0a
+global sys_open ; vec 0x09
+global sys_close ; vec 0x0a
-global exception_handler ; vec 0x0c
+global sys_exception_handler ; vec 0x0c
;;;; support for pdclib
global stdin
@@ -25,18 +26,18 @@ global __divdi3
global errno
global __errno_location
-push __raw_exception_handler
-call exception_handler
-add esp, 4
+;push __raw_exception_handler
+;call exception_handler
+;add esp, 4
call main
-push eax
-call _PDCLIB_Exit
+;push eax
+;call _PDCLIB_Exit
jmp $
-stdin dd 0
-stdout dd 1
-stderr dd 1 ; @TODO fix this to have stderr be its own fd
+;stdin dd 0
+;stdout dd 1
+;stderr dd 1 ; @TODO fix this to have stderr be its own fd
errno dd 0
__errno_location dd 0
@@ -53,11 +54,11 @@ __c_exception_handler:
push dword 21
push .msg
push dword 1
- call write
+ call sys_write
add esp, 12
push dword 1
- call _PDCLIB_Exit
+ call sys_exit
section .data
align 16
@@ -65,26 +66,27 @@ section .data
section .text
-alloc_page:
+sys_alloc_page:
mov eax, 0x01
int 0x80
ret
-free_page:
+sys_free_page:
push ebx
mov eax, 0x02
mov ebx, [esp+8]
int 0x80
pop ebx
ret
-
+
+sys_exit:
_PDCLIB_Exit:
mov ebx, [esp+4]
mov eax, 0x03
int 0x80
ret
-kill:
+sys_kill:
push ebx
mov eax, 0x04
mov ebx, [esp+8]
@@ -92,17 +94,17 @@ kill:
pop ebx
ret
-get_pid:
+sys_get_pid:
mov eax, 0x05
int 0x80
ret
-fork:
+sys_fork:
mov eax, 0x06
int 0x80
ret
-write:
+sys_write:
push ebx
mov eax, 0x07
mov ebx, [esp+8]
@@ -112,7 +114,7 @@ write:
pop ebx
ret
-read:
+sys_read:
push ebx
mov eax, 0x08
mov ebx, [esp+8]
@@ -122,7 +124,7 @@ read:
pop ebx
ret
-open:
+sys_open:
push ebx
mov eax, 0x09
mov ebx, [esp+8]
@@ -130,7 +132,7 @@ open:
pop ebx
ret
-close:
+sys_close:
push ebx
mov eax, 0x0a
mov ebx, [esp+8]
@@ -138,7 +140,7 @@ close:
pop ebx
ret
-exception_handler:
+sys_exception_handler:
push ebx
mov eax, 0x0c
mov ebx, [esp+8]
View
27 user/init.c
@@ -1,30 +1,9 @@
#include <csos.h>
+#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main()
-{
- /*
- char* msg = "Hello world from init! I am process number: ";
- write(stdout, msg, strlen(msg));
-
- uint pid = get_pid();
- char buff[16];
- char* bptr = (char*)buff + 16;
- uint len = 0;
- do
- {
- *--bptr = (pid % 10) + '0';
- pid /= 10;
- len++;
- }
- while(pid != 0);
- write(stdout, bptr, len);
-
- write(stdout, "\n", 1);
-
-// write(stdout, &pid, 1);
- */
-
- printf("Hello world from init! I am process number: %d\n", get_pid());
+{
+ printf("Hello world from init! I am process number: %d\n", sys_get_pid());
}
View
BIN  util/bin2nasm
Binary file not shown
View
BIN  util/inject_symbols
Binary file not shown
Please sign in to comment.
Something went wrong with that request. Please try again.