Skip to content

Commit

Permalink
Merging a pull from upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
evgenymartynov committed Apr 21, 2011
2 parents 0cf65fc + d3cc489 commit 6cbe576
Show file tree
Hide file tree
Showing 178 changed files with 12,925 additions and 155 deletions.
9 changes: 5 additions & 4 deletions .gitignore
@@ -1,9 +1,10 @@
*.o
build/kernel.sys
util/bin2nasm
util/inject_symbols
Make.log

*.o
*.bin
kbin/*

hdd.img
hdd.base.img.old
kbin/*
build/kernel.sys
8 changes: 5 additions & 3 deletions Makefile
Expand Up @@ -2,11 +2,12 @@ default: all

clean:
rm kbin/* ubin/* ksrc/*.o user/*.o ksrc/fs/*.o -f
make -C user/pdclib clean

CFLAGS=-m32 -std=c99 -Wall -Wextra -nostdlib -fno-builtin -nostartfiles -nodefaultlibs -fno-exceptions -fno-stack-protector -c -masm=intel
PWD=$(shell pwd)
KCFLAGS=-iquote $(PWD)/kinc $(CFLAGS)
USERCFLAGS=-I $(PWD)/uinc $(CFLAGS)
USERCFLAGS=-I $(PWD)/uinc -I $(PWD)/user/pdclib/includes -I$(PWD)/user/pdclib/internals $(CFLAGS)
LDFLAGS=-melf_i386

assembly:
Expand All @@ -17,12 +18,13 @@ assembly:
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
nasm -f elf -o user/crt.o user/crt/csos.asm
nasm -f elf -o user/crt/crt_asm.o user/crt/csos.asm

# Usermode crap
usermode:
gcc $(USERCFLAGS) user/init.c -o ubin/init.o
ld -T user_linker.ld -o build/init.bin ubin/*.o $(LDFLAGS)
gcc $(USERCFLAGS) user/crt/csos.c -o user/crt/crt_c.o
ld -T user_linker.ld -o build/init.bin ubin/*.o $(PWD)/user/pdclib/functions/stdlib/*.o $(PWD)/user/pdclib/functions/_PDCLIB/*.o $(PWD)/user/pdclib/functions/stdio/*.o $(PWD)/user/pdclib/functions/string/*.o $(PWD)/user/crt/crt_c.o $(LDFLAGS)

util:
gcc -std=c99 -o util/bin2nasm util/bin2nasm.c
Expand Down
2 changes: 1 addition & 1 deletion bochslinux.bxrc
Expand Up @@ -10,8 +10,8 @@ floppy_bootsig_check: disabled=0
# no floppya
# no floppyb
ata0: enabled=1, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14
ata0-master: type=disk, mode=flat, translation=auto, path="hdd.img", cylinders=65, heads=16, spt=63, biosdetect=auto, model="Generic 1234"
ata1: enabled=1, ioaddr1=0x170, ioaddr2=0x370, irq=15
ata1-master: type=disk, mode=flat, translation=auto, path="hdd.img", cylinders=65, heads=16, spt=63, biosdetect=auto, model="Generic 1234"
ata2: enabled=0
ata3: enabled=0
parport1: enabled=1, file=""
Expand Down
3 changes: 2 additions & 1 deletion kinc/syscall.h
Expand Up @@ -14,9 +14,10 @@ void sys_read(regs_t* registers);
void sys_open(regs_t* registers);
void sys_close(regs_t* registers);
void sys_write_ebx(regs_t* registers);
void sys_exception_handler(regs_t* registers);

void syscall_handler(regs_t* registers);

void syscall_isr();

#endif
#endif
6 changes: 5 additions & 1 deletion kinc/task.h
Expand Up @@ -5,6 +5,7 @@
#include "stdbool.h"
#include "fs/vfs.h"

#define MAX_TASKS 128
#define MAX_FDS 64

typedef struct tss
Expand Down Expand Up @@ -83,6 +84,7 @@ typedef struct task
task_state_t state;
char kernel_stack[8192];
vfs_stream_t* fds[MAX_FDS];
uint exception_handler;
}
__attribute__((__packed__)) /* so i can access the struct straight from assembly */ task_t;

Expand All @@ -103,10 +105,12 @@ typedef struct regs
}
__attribute__((__packed__)) regs_t;

task_t* task_get(uint pid);
void task_init(uint base_physical, uint high_memory);
uint alloc_page();
void free_page(uint page);
task_t* task_create(uint size, void* code, uint stack_size);
task_t* task_dup(task_t* task);
void task_kill_and_free(task_t* task);
uint task_add_page(task_t* task);
void task_del_page(task_t* task, uint virtual);
Expand All @@ -117,4 +121,4 @@ task_t* task_current();

void task_peek(task_t* task, uint virtual, uint length, void* buffer);

#endif
#endif
4 changes: 1 addition & 3 deletions kinc/util.h
Expand Up @@ -11,9 +11,7 @@ typedef struct symbol
__attribute__((__packed__)) symbol_t;

char* cpuid(char* buffer);
typedef uint(*function_pointer_t)(uint,...);
function_pointer_t function_by_name(char* name);

void sleep(uint ms);

#endif
#endif
38 changes: 30 additions & 8 deletions ksrc/ata.c
Expand Up @@ -69,15 +69,37 @@ bool ata_write_sector(uchar disk, uint lba, void* buffer)

bool ata_read_sectors(uchar disk, uint lba, uint sectors, void* buffer)
{
if(buffer == NULL)
panic("Attempt to read to a null buffer in ata_read_sectors");
// optimize later
for(uint i = 0; i < sectors; i++)
uint at_a_time = 64;
if(sectors > at_a_time)
{
if(!ata_read_sector(disk, lba + i, (char*)buffer + 512*i))
return false;
for(uint i = 0; i < sectors; i += at_a_time)
{
if(!ata_read_sectors(disk, lba + i, (sectors - i) > at_a_time ? at_a_time : sectors - i, (char*)buffer + (i * 512)))
return false;
}
return true;
}
return true;
struct lba_packet* packet = (struct lba_packet*)0x2000;
packet->size = 16;
packet->reserved = 0;
packet->sectors = sectors;
packet->dest_segment = 0x1000;
packet->dest_offset = 0x0000;
packet->lba_lo = lba;
packet->lba_hi = 0;

*(uchar*)0x2010 = disk; // disk
*(uchar*)0x2011 = 0x42; // read

real_exec(bin_ata16, bin_ata16_len);

memcpy(buffer, (void*)0x10000, 512 * sectors);

bool success = !(*(bool*)0x2000);
if(!success)
panicf("Read failed. LBA = %d, buffer = 0x%x", lba, buffer);

return success;
}

bool ata_write_sectors(uchar disk, uint lba, uint sectors, void* buffer)
Expand All @@ -89,4 +111,4 @@ bool ata_write_sectors(uchar disk, uint lba, uint sectors, void* buffer)
return false;
}
return true;
}
}
10 changes: 6 additions & 4 deletions ksrc/helper.asm
@@ -1,5 +1,6 @@
use32
extern memcpy
extern panic
global panic
global get_gdt
global gdt_reload_segment_registers
global switch_to_user_mode
Expand All @@ -9,8 +10,8 @@ get_gdt:
mov eax, .tmp
ret
.tmp dd 0
dd 0
dd 0

gdt_reload_segment_registers:
jmp 0x08:.boom
.boom:
Expand Down Expand Up @@ -45,4 +46,5 @@ switch_to_user_mode:
int 0x80
jmp $
hlt
hlt

6 changes: 5 additions & 1 deletion ksrc/isrs.asm
Expand Up @@ -12,6 +12,8 @@ extern kprintf
jmp isr_%1.fin
isr_%1:
mov [.eax], eax
mov ax, 0x10
mov ds, ax
mov eax, [esp]
mov [.err], eax
mov eax, [.eax]
Expand Down Expand Up @@ -42,6 +44,8 @@ isr_main:
.dont_send_other_clearance:
mov al, 0x20
out 0x20, al
mov ax, 0x8b
mov ds, ax
popa
sti
iret
Expand Down Expand Up @@ -108,4 +112,4 @@ asm_isr_init:
isr 0x80
ret
ret
2 changes: 1 addition & 1 deletion ksrc/loader.asm
Expand Up @@ -32,4 +32,4 @@ loader:
section .bss
align 4
kstack:
resb STACKSIZE ; reserve 16k stack on a doubleword boundary
resb STACKSIZE ; reserve 16k stack on a doubleword boundary
4 changes: 3 additions & 1 deletion ksrc/main.c
Expand Up @@ -60,7 +60,9 @@ void kmain(struct multiboot_info* mbd, unsigned int magic)
uint init_size = vfs_size("/init.bin");
char* buff = kmalloc(((init_size + PAGE_SIZE-1) / PAGE_SIZE) * PAGE_SIZE);
vfs_readfile("/init.bin", 0, init_size, buff);
task_create(init_size, buff, PAGE_SIZE);
task_create(init_size, buff, 4096);
// task_create(init_size, buff, 4096);

kfree(buff);

cli();
Expand Down
7 changes: 5 additions & 2 deletions ksrc/panic.asm
@@ -1,10 +1,13 @@
use32
global panic
global symtable
global get_symtable_addr
extern kprintf
extern panic_backtrace_step

panic:
section .text

panic:
push ss
push ds
push cs
Expand Down Expand Up @@ -48,4 +51,4 @@ symtable:
dd 0xbadf00de
dd 0xffffffff

times 65536 db 0 ; reserve 64KiB for the symbol table
times 65536 db 0 ; reserve 64KiB for the symbol table
2 changes: 1 addition & 1 deletion ksrc/panic.c
Expand Up @@ -38,4 +38,4 @@ void panic_backtrace_step(size_t address)
}

kprintf(" 0x%x: %s +%x\n", best_offset, best, address - best_offset);
}
}
2 changes: 1 addition & 1 deletion ksrc/string.c
Expand Up @@ -218,4 +218,4 @@ char* strtoupper(char* dest, char* src)
dest[i] = src[i];
}
return dest;
}
}
7 changes: 5 additions & 2 deletions ksrc/syscall.asm
Expand Up @@ -6,6 +6,8 @@ extern page_directory
syscall_isr:
cli
pusha
mov eax, 0
mov [multitasking_enabled], eax
mov eax, cr3
mov [.saved_cr3], eax
Expand Down Expand Up @@ -35,7 +37,8 @@ syscall_isr:
mov eax, [.saved_cr3]
mov cr3, eax
mov eax, 1
mov [multitasking_enabled], eax
popa
sti
iret
.saved_cr3 dd 0
.saved_cr3 dd 0

0 comments on commit 6cbe576

Please sign in to comment.