small changes, part 1
This commit is contained in:
parent
4edc0cb231
commit
e520b52cd5
9 changed files with 34 additions and 24 deletions
|
@ -1,4 +0,0 @@
|
|||
allocate:
|
||||
ax in: number of pages
|
||||
dx in: process id
|
||||
ebx out: address, or 0x0000_0000 on failure
|
|
@ -13,8 +13,8 @@
|
|||
0x0001 = unavailable
|
||||
0x0002 = kernel
|
||||
other = process number
|
||||
|
||||
0x4000 - 0x6fff : not assigned
|
||||
|
||||
0x7000 - 0x7bff : bootloader scratch
|
||||
0x7000 : memory map bios buffer
|
||||
0x7c00 - 0x7fff : bootloader
|
17
makefile
17
makefile
|
@ -1,5 +1,5 @@
|
|||
floppy: out bootloader files
|
||||
mkfs.fat -C -f 1 -F 12 -n "PORTLAND OS" -R 4 -S 512 out/floppy.img 1440
|
||||
floppy: bootloader fs
|
||||
mkfs.fat -C -f 1 -F 12 -n "PORTLAND OS" -R 2 -S 512 out/floppy.img 1440
|
||||
mkdir out/floppy_mount
|
||||
mount out/floppy.img out/floppy_mount
|
||||
cp out/fs/* out/floppy_mount/
|
||||
|
@ -7,16 +7,13 @@ floppy: out bootloader files
|
|||
dd if=obj/bootloader.bin of=out/floppy.img bs=1 seek=62 conv=notrunc
|
||||
|
||||
bootloader: obj
|
||||
nasm src/bootloader.bin -o obj/bootloader.bin
|
||||
nasm src/bootloader.asm -o obj/bootloader.bin
|
||||
|
||||
kernel: obj out
|
||||
gcc -c src/kernel/main.c -o obj/kmain.o -ffreestanding
|
||||
gcc -c src/kernel/vga.c -o obj/kvga.o -ffreestanding
|
||||
ld obj/kmain.o obj/kvga.o -o out/kernel.out -nostdlib --oformat=i386-aout
|
||||
kernel: fs
|
||||
gcc src/kernel/*.c -o out/fs/kernel.sys -ffreestanding -nostdlib -m32 -T src/kernel/link.ld
|
||||
|
||||
files: kernel
|
||||
mkdir out/fs
|
||||
cp out/kernel.out out/fs/kernel.sys
|
||||
fs: out
|
||||
mkdir -p out/fs
|
||||
|
||||
obj:
|
||||
mkdir -p obj
|
||||
|
|
|
@ -24,7 +24,7 @@ fat_header:
|
|||
.oem_name equ 0x7c03;mkfs.fat - ignored
|
||||
.bytes_per_sector equ 0x7c0b;0x0200 - assumed
|
||||
.sectors_per_cluster equ 0x7c0d;0x01 - assumed
|
||||
.reserved_sectors equ 0x7c0e;0x0004 - other values handled
|
||||
.reserved_sectors equ 0x7c0e;0x0002 - handled
|
||||
.n_fats equ 0x7c10;0x01 - assumed
|
||||
.root_dir_entries equ 0x7c11; -
|
||||
.n_sectors equ 0x7c13;0x0b40 -
|
||||
|
@ -231,6 +231,12 @@ load_kernel:
|
|||
mov word [dap.offset], bx
|
||||
xor bx, bx
|
||||
shr ebx, 4
|
||||
jmp .over_sig
|
||||
|
||||
times $$ + 0x01fe - $ db 0
|
||||
dw 0xaa55
|
||||
|
||||
.over_sig:
|
||||
test ebx, 0xffff_0000
|
||||
jnz halt
|
||||
mov word [dap.segment], bx
|
||||
|
@ -269,9 +275,7 @@ load_kernel:
|
|||
|
||||
mov ebx, dword [pointers.kernel]
|
||||
|
||||
;Parse kernel executable header,
|
||||
;Go through relocation tables,
|
||||
;Get kernel_start.
|
||||
;TODO
|
||||
|
||||
cli
|
||||
|
||||
|
@ -292,7 +296,7 @@ dq 0x00c0_9200_8000_0ff7
|
|||
|
||||
dap:
|
||||
dw 0x0010
|
||||
.length dw 0x0003
|
||||
.length dw 0x0001
|
||||
.offset dw 0x7e00
|
||||
.segment dw 0x0000
|
||||
.start dd 0x0000_0001
|
||||
|
|
11
src/kernel/link.ld
Normal file
11
src/kernel/link.ld
Normal file
|
@ -0,0 +1,11 @@
|
|||
OUTPUT_FORMAT(binary)
|
||||
SECTIONS {
|
||||
. = 0x01000000;
|
||||
.text : {
|
||||
main = .;
|
||||
*(.text)
|
||||
}
|
||||
.rodata : { *(.rodata) }
|
||||
.data : { *(.data) }
|
||||
.bss : { *(.bss) }
|
||||
}
|
|
@ -24,12 +24,14 @@ OF THIS SOFTWARE.
|
|||
#include "misc.h"
|
||||
|
||||
void main(void) {
|
||||
*(uint16_t *)0x0000200e = 0x0000;
|
||||
|
||||
*(uint32_t *)0x0000050c = (uint32_t)allocate_pages(16 * sizeof(struct file_handle_info), 2);
|
||||
for (struct file_handle_info *i = FILE_HANDLES, *l = FILE_HANDLES + 65536; i < l; ++i)
|
||||
i->first_sector = 0;
|
||||
|
||||
*(uint32_t *)0x00000510 = (uint32_t)allocate_pages(16 * sizeof(struct proc_info), 2);
|
||||
for (struct proc_info *i = FILE_HANDLES, *l = FILE_HANDLES + 65536; i < l; ++i)
|
||||
for (struct proc_info *i = PROCS, *l = PROCS + 65536; i < l; ++i)
|
||||
i->memory_start = 0;
|
||||
|
||||
uint16_t pages_free = 0, pages_total = 0;
|
||||
|
|
|
@ -36,6 +36,6 @@ void *allocate_pages(uint16_t n_pages, uint16_t proc_n) {
|
|||
}
|
||||
|
||||
void deallocate_pages(void *from, uint16_t n_pages) {
|
||||
for (uint16_t *mb = MMAP + ((uint32_t)from / 0x1000), *l = mb + n_pages; mb < l; ++mb)
|
||||
for (uint16_t *mb = MMAP + (uint32_t)from / 0x1000, *l = mb + n_pages; mb < l; ++mb)
|
||||
*mb = 0;
|
||||
}
|
|
@ -22,6 +22,6 @@ OF THIS SOFTWARE.
|
|||
#ifndef MISC_H
|
||||
#define MISC_H
|
||||
|
||||
void print_32(uint32_t n);
|
||||
void put_16(uint16_t n);
|
||||
|
||||
#endif
|
|
@ -25,7 +25,7 @@ uint16_t new_proc(uint8_t *file) {
|
|||
uint16_t handle = open_file(file);
|
||||
if (handle)
|
||||
for (uint16_t id = 3; id; ++id)
|
||||
if (!(PROCS[id].memory_start)) {
|
||||
if (!PROCS[id].memory_start) {
|
||||
uint32_t size = get_size(id);
|
||||
void *mem = PROCS[id].memory_start = allocate_pages(PROCS[id].n_pages = (size - 1) / 4096 + 1, id);
|
||||
read_file(handle, size, mem);
|
||||
|
|
Reference in a new issue