Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f51426f73f | ||
|
|
4b688a3ce0 | ||
|
|
563758b1bd | ||
|
|
ae5dc7df6f | ||
|
|
d41ffbbedc | ||
|
|
5ac343a2e8 | ||
|
|
1027b8c346 | ||
|
|
08491bace9 | ||
|
|
96ba9fabb1 | ||
|
|
24485b8143 | ||
|
|
ca82cc32ac | ||
|
|
4816102139 | ||
|
|
0bc304328d | ||
|
|
dccecb054b | ||
|
|
0c78e21e14 | ||
|
|
53407d7b59 | ||
|
|
cdea1602d5 | ||
|
|
b6bebfd9b4 | ||
|
|
1be6e37961 | ||
|
|
85c5a26631 | ||
|
|
eb2dd3b1ad | ||
|
|
6cd78f195f | ||
|
|
e4701b8d96 | ||
|
|
76ac4f88a4 | ||
|
|
f6e71b9891 | ||
|
|
cf7287d368 | ||
|
|
44c6bac2af | ||
|
|
bc7064e92a | ||
|
|
2c5a5d7093 | ||
|
|
ddd8c9fd71 | ||
|
|
d7be0159c9 | ||
|
|
d352afd079 | ||
|
|
1105e6e203 | ||
|
|
339eef5976 | ||
|
|
6a75fdfc10 | ||
|
|
2f810cc2ec | ||
|
|
63289deade | ||
|
|
e70b1a5213 | ||
|
|
c21caccb1f | ||
|
|
fd02ee26e1 | ||
|
|
ecd74fe35b | ||
|
|
08af04897c | ||
|
|
1dd8250048 | ||
|
|
118021a0f6 | ||
|
|
bf9c7d74eb | ||
|
|
cf2d28f5ce | ||
|
|
594625b0fa | ||
|
|
df719b4281 | ||
|
|
0fb590a407 | ||
|
|
5b9651299e | ||
|
|
a4d497544e | ||
|
|
6a69fd06ec | ||
|
|
6a8c7431ff | ||
|
|
be17cde305 | ||
|
|
1aace858da | ||
|
|
784978b131 | ||
|
|
54b42c0226 | ||
|
|
e55f2cdfc4 | ||
|
|
edb1a6426d | ||
|
|
f07e34c849 | ||
|
|
e907902ca0 | ||
|
|
a8947f8aa3 | ||
|
|
2bddc1d428 | ||
|
|
bfb4f3bdd0 | ||
|
|
db192f6d36 | ||
|
|
2faa2cc8d6 | ||
|
|
02c2b25ded | ||
|
|
39ea3f231b | ||
|
|
981a01ba9b | ||
|
|
3eea1b4fd3 | ||
|
|
be8d6015ff | ||
|
|
6ea8fe1a27 | ||
|
|
d4f5a0b244 | ||
|
|
1548e7327a | ||
|
|
90e03d4f95 | ||
|
|
fb807847bf | ||
|
|
d8f7e731e1 | ||
|
|
a5ca4348d9 | ||
|
|
8fe8d78051 | ||
|
|
1b0da72e5a | ||
|
|
8493002072 | ||
|
|
1ba82ac77f | ||
|
|
13f467ca47 | ||
|
|
81a56c9fcf | ||
|
|
788597b6f4 | ||
|
|
09fb19df15 | ||
|
|
af529606e9 | ||
|
|
f58228c559 | ||
|
|
8f00324b30 | ||
|
|
bdf4ce8ae8 | ||
|
|
e124ac5b1b | ||
|
|
fba9e3ea54 | ||
|
|
43d1ca0e18 | ||
|
|
0aaf5db5ad | ||
|
|
89d962e33a | ||
|
|
712337c485 | ||
|
|
761e3f0483 | ||
|
|
98abfc2af0 | ||
|
|
677551fba5 | ||
|
|
7daa1c5336 | ||
|
|
79ca453f66 | ||
|
|
0521733e20 | ||
|
|
396c5f3452 | ||
|
|
9e03bfc8b6 | ||
|
|
2b67ff6f49 | ||
|
|
daa29212d0 | ||
|
|
83a5b032f8 | ||
|
|
345ef6c9f3 | ||
|
|
e1682a2fe7 | ||
|
|
2cefd9441c | ||
|
|
da90bcc164 | ||
|
|
4689c11cc8 | ||
|
|
692cf2fc08 | ||
|
|
b0132c866e | ||
|
|
14792ef954 | ||
|
|
bb8ff09e3f | ||
|
|
dfeabc39aa | ||
|
|
14148e4d80 | ||
|
|
80774c48fe | ||
|
|
862b36b37b | ||
|
|
4638656aaf | ||
|
|
3381041a8f | ||
|
|
f09ed66826 | ||
|
|
ba5906c7a3 | ||
|
|
05183a3949 | ||
|
|
d8580a9393 | ||
|
|
50285aa33b | ||
|
|
ee63a84c0e | ||
|
|
76a243d894 | ||
|
|
6bad3f2b96 | ||
|
|
51948ce081 | ||
|
|
b40a68f581 | ||
|
|
55b7429d4e | ||
|
|
7b805f2495 | ||
|
|
2445034e43 | ||
|
|
3c531f3b7b | ||
|
|
11cc0c87f3 | ||
|
|
bad7f79ed1 | ||
|
|
78272f6bc3 | ||
|
|
396d5015d2 | ||
|
|
1bf14ddefa | ||
|
|
c0dd3b529e | ||
|
|
8a8f56decb | ||
|
|
b9c77827bd | ||
|
|
cd02211b21 | ||
|
|
a50c2a1233 | ||
|
|
07e8a0f4cf | ||
|
|
6d23c76e84 | ||
|
|
11da8cb162 | ||
|
|
1063a68a21 | ||
|
|
286b5e9ae1 | ||
|
|
d4aadbea38 | ||
|
|
dfb71cc759 |
No files matched your search
@@ -1,43 +0,0 @@
|
||||
# configuration file generated by Bochs
|
||||
config_interface: textconfig
|
||||
display_library: x
|
||||
megs: 32
|
||||
romimage: file=/usr/share/bochs/BIOS-bochs-latest, address=0xf0000
|
||||
vgaromimage: /usr/share/bochs/VGABIOS-lgpl-latest
|
||||
boot: floppy
|
||||
floppya: 1_44="hos.flp", status=inserted
|
||||
# no floppyb
|
||||
ata0: enabled=1, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14
|
||||
ata1: enabled=0
|
||||
ata2: enabled=0
|
||||
ata3: enabled=0
|
||||
parport1: enabled=1, file=""
|
||||
com1: enabled=1, dev=""
|
||||
usb1: enabled=1, ioaddr=0xff80, irq=10
|
||||
# no sb16
|
||||
floppy_bootsig_check: disabled=0
|
||||
vga_update_interval: 30000
|
||||
keyboard_serial_delay: 20000
|
||||
keyboard_paste_delay: 100000
|
||||
floppy_command_delay: 50000
|
||||
ips: 500000
|
||||
text_snapshot_check: 0
|
||||
mouse: enabled=0
|
||||
private_colormap: enabled=0
|
||||
i440fxsupport: enabled=0
|
||||
clock: sync=none, time0=local
|
||||
# no ne2k
|
||||
newharddrivesupport: enabled=1
|
||||
# no loader
|
||||
log: -
|
||||
logprefix: %t%e%d
|
||||
debugger_log: -
|
||||
panic: action=ask
|
||||
error: action=report
|
||||
info: action=report
|
||||
debug: action=ignore
|
||||
pass: action=fatal
|
||||
keyboard_mapping: enabled=0, map=
|
||||
keyboard_type: mf
|
||||
user_shortcut: keys=none
|
||||
# no cmosimage
|
||||
@@ -1,48 +1,37 @@
|
||||
# Makefile for HOS
|
||||
# Josh Holtrop
|
||||
# Created: 07/09/04
|
||||
|
||||
FLOPPY=/dev/fd0
|
||||
FLOPPY_MOUNT=./mnt_flp
|
||||
FLOPPY_IMAGE=hos.flp
|
||||
GRUB_IMAGE=grub.flp
|
||||
KERNEL_FILE := hos.gz
|
||||
MKISOFS := genisoimage
|
||||
ISO := hos.iso
|
||||
QEMU := qemu-system-x86_64
|
||||
BOCHS := bochs
|
||||
|
||||
all:
|
||||
make -C kernel
|
||||
# make -C rmmod
|
||||
# default target: build the kernel and ISO image
|
||||
all: kernel iso
|
||||
|
||||
# build the kernel
|
||||
.PHONY: kernel
|
||||
kernel:
|
||||
$(MAKE) -C $@
|
||||
|
||||
# build the ISO image
|
||||
.PHONY: iso
|
||||
iso: $(ISO) kernel
|
||||
|
||||
$(ISO): kernel
|
||||
cp kernel/$(KERNEL_FILE) iso/boot
|
||||
-rm -f $(ISO)
|
||||
$(MKISOFS) -R -b boot/grub/stage2_eltorito -no-emul-boot \
|
||||
-boot-load-size 4 -boot-info-table -o $(ISO) iso
|
||||
|
||||
.PHONY: qemu
|
||||
qemu: iso
|
||||
$(QEMU) -cdrom $(ISO) -boot d -m 384 -localtime
|
||||
|
||||
.PHONY: bochs
|
||||
bochs: iso
|
||||
-$(BOCHS)
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
make -C kernel clean
|
||||
make -C include clean
|
||||
# make -C rmmod clean
|
||||
- rm *~ hos.flp
|
||||
|
||||
|
||||
grub:
|
||||
- mkdir $(FLOPPY_MOUNT)
|
||||
mke2fs $(FLOPPY)
|
||||
mount -t ext2 $(FLOPPY) $(FLOPPY_MOUNT)
|
||||
grub-install --root-directory=$(FLOPPY_MOUNT) fd0
|
||||
umount $(FLOPPY_MOUNT)
|
||||
- rmdir $(FLOPPY_MOUNT)
|
||||
|
||||
grub_image:
|
||||
dd if=$(FLOPPY) of=$(GRUB_IMAGE)
|
||||
|
||||
install:
|
||||
- mkdir $(FLOPPY_MOUNT)
|
||||
mount -t ext2 $(FLOPPY) $(FLOPPY_MOUNT)
|
||||
cp kernel/kernel.bin $(FLOPPY_MOUNT)
|
||||
cp menu.lst $(FLOPPY_MOUNT)/boot/grub
|
||||
umount $(FLOPPY_MOUNT)
|
||||
- rmdir $(FLOPPY_MOUNT)
|
||||
|
||||
install_img:
|
||||
- mkdir $(FLOPPY_MOUNT)
|
||||
cp grub.flp $(FLOPPY_IMAGE)
|
||||
mount -t ext2 -o loop $(FLOPPY_IMAGE) $(FLOPPY_MOUNT)
|
||||
cp kernel/kernel.bin $(FLOPPY_MOUNT)
|
||||
cp menu.lst $(FLOPPY_MOUNT)/boot/grub
|
||||
umount $(FLOPPY_MOUNT)
|
||||
- rmdir $(FLOPPY_MOUNT)
|
||||
|
||||
$(MAKE) -C kernel clean
|
||||
-rm -f $(ISO) iso/boot/$(KERNEL_FILE)
|
||||
@@ -0,0 +1,52 @@
|
||||
# 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: sdl
|
||||
megs: 32
|
||||
romimage: file="/usr/share/bochs/BIOS-bochs-latest"
|
||||
vgaromimage: file="/usr/share/bochs/VGABIOS-lgpl-latest"
|
||||
boot: cdrom
|
||||
floppy_bootsig_check: disabled=0
|
||||
# no floppya
|
||||
# no floppyb
|
||||
ata0: enabled=1, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14
|
||||
ata0-master: type=cdrom, path="hos.iso", status=inserted, biosdetect=auto, model="Generic 1234"
|
||||
ata1: enabled=1, ioaddr1=0x170, ioaddr2=0x370, irq=15
|
||||
ata2: enabled=0
|
||||
ata3: enabled=0
|
||||
parport1: enabled=1, file=""
|
||||
parport2: enabled=0
|
||||
com1: enabled=1, mode=null, dev=""
|
||||
com2: enabled=0
|
||||
com3: enabled=0
|
||||
com4: enabled=0
|
||||
usb_uhci: enabled=0
|
||||
usb_ohci: enabled=0
|
||||
i440fxsupport: enabled=1
|
||||
vga_update_interval: 50000
|
||||
vga: extension=vbe
|
||||
cpu: count=1, ips=4000000, reset_on_triple_fault=1, cpuid_limit_winnt=0
|
||||
print_timestamps: enabled=0
|
||||
# no gdb stub
|
||||
port_e9_hack: enabled=0
|
||||
text_snapshot_check: enabled=0
|
||||
private_colormap: enabled=0
|
||||
clock: sync=none, time0=local
|
||||
# no cmosimage
|
||||
ne2k: enabled=0
|
||||
pnic: enabled=0
|
||||
sb16: enabled=0
|
||||
# no loader
|
||||
log: -
|
||||
logprefix: %t%e%d
|
||||
panic: action=ask
|
||||
error: action=report
|
||||
info: action=report
|
||||
debug: action=ignore
|
||||
pass: action=fatal
|
||||
keyboard_type: mf
|
||||
keyboard_serial_delay: 250
|
||||
keyboard_paste_delay: 100000
|
||||
keyboard_mapping: enabled=0, map=
|
||||
user_shortcut: keys=none
|
||||
mouse: enabled=0, type=ps2
|
||||
@@ -1,2 +0,0 @@
|
||||
clean:
|
||||
- rm *~
|
||||
@@ -1,23 +0,0 @@
|
||||
|
||||
#ifndef __HOS_KERNEL_H__
|
||||
#define __HOS_KERNEL_H__ __HOS_KERNEL_H__
|
||||
|
||||
#include "multiboot.h"
|
||||
|
||||
#define VIRT_OFFSET 0xC0000000
|
||||
#define MAX_MODULES 16
|
||||
#define MAX_MMAP 16
|
||||
|
||||
typedef unsigned int u32_t;
|
||||
typedef unsigned short u16_t;
|
||||
typedef unsigned char u8_t;
|
||||
|
||||
/* returns true to callee if we should jump to a real mode module */
|
||||
int k_mbsave(mb_info_t *mbinfo, unsigned int mb_magic);
|
||||
|
||||
void k_init();
|
||||
|
||||
void isr();
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
|
||||
#ifndef __HOS_MODULE_H__
|
||||
#define __HOS_MODULE_H__ __HOS_MODULE_H__
|
||||
|
||||
#define MOD_REAL_MODE 1
|
||||
#define MOD_KERNEL 2
|
||||
|
||||
typedef struct {
|
||||
unsigned int mod_magic; // "HOSM" = 0x484F534D
|
||||
unsigned int mod_type; // module type
|
||||
void (*init) (); // address of void initialization function
|
||||
unsigned int reserved;
|
||||
} hos_module_header_t;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,144 +0,0 @@
|
||||
|
||||
#ifndef __HOS_MULTIBOOT_H__
|
||||
#define __HOS_MULTIBOOT_H__ __HOS_MULTIBOOT_H__
|
||||
|
||||
/* The magic number for the Multiboot header. */
|
||||
#define MULTIBOOT_HEADER_MAGIC 0x1BADB002
|
||||
|
||||
#define MB_HEADER_ALIGN_MODULES 0x01
|
||||
#define MB_HEADER_MEM_INFO 0x02
|
||||
#define MB_HEADER_VIDEO_INFO 0x04
|
||||
#define MB_HEADER_KLUDGE_OFFSETS 0x10000
|
||||
|
||||
|
||||
/* The magic number passed by a Multiboot-compliant boot loader. */
|
||||
#define MULTIBOOT_BOOTLOADER_MAGIC 0x2BADB002
|
||||
|
||||
#define MB_BOOTLOADER_MEM_INFO 0x01
|
||||
#define MB_BOOTLOADER_BOOT_DEVICE 0x02
|
||||
#define MB_BOOTLOADER_COMMAND_LINE 0x04
|
||||
#define MB_BOOTLOADER_MODS 0x08
|
||||
#define MB_BOOTLOADER_AOUT 0x10
|
||||
#define MB_BOOTLOADER_ELF 0x20
|
||||
#define MB_BOOTLOADER_MMAP 0x40
|
||||
#define MB_BOOTLOADER_DRIVES 0x80
|
||||
#define MB_BOOTLOADER_CONFIG 0x0100
|
||||
#define MB_BOOTLOADER_APM 0x0200
|
||||
#define MB_BOOTLOADER_GRAPHICS 0x0400
|
||||
|
||||
|
||||
#define MB_DRIVE_MODE_CHS 0
|
||||
#define MB_DRIVE_MODE_LBA 1
|
||||
|
||||
|
||||
/* The Multiboot header. */
|
||||
typedef struct
|
||||
{
|
||||
unsigned int magic;
|
||||
unsigned int flags;
|
||||
unsigned int checksum;
|
||||
unsigned int header_addr;
|
||||
unsigned int load_addr;
|
||||
unsigned int load_end_addr;
|
||||
unsigned int bss_end_addr;
|
||||
unsigned int entry_addr;
|
||||
} mb_header_t;
|
||||
|
||||
/* The symbol table for a.out. */
|
||||
typedef struct
|
||||
{
|
||||
unsigned int tabsize;
|
||||
unsigned int strsize;
|
||||
unsigned int addr;
|
||||
unsigned int reserved;
|
||||
} mb_aout_symbol_table_t;
|
||||
|
||||
/* The section header table for ELF. */
|
||||
typedef struct
|
||||
{
|
||||
unsigned int num;
|
||||
unsigned int size;
|
||||
unsigned int addr;
|
||||
unsigned int shndx;
|
||||
} mb_elf_section_header_table_t;
|
||||
|
||||
/* The Multiboot information. */
|
||||
typedef struct
|
||||
{
|
||||
unsigned int flags;
|
||||
unsigned int mem_lower; // present if flags[0] is set
|
||||
unsigned int mem_upper;
|
||||
unsigned int boot_device; // 1
|
||||
unsigned int cmdline; // 2
|
||||
unsigned int mods_count; // 3
|
||||
unsigned int mods_addr;
|
||||
union
|
||||
{
|
||||
mb_aout_symbol_table_t aout_sym; // 4
|
||||
mb_elf_section_header_table_t elf_sec; // 5
|
||||
};
|
||||
unsigned int mmap_length; // 6
|
||||
unsigned int mmap_addr;
|
||||
unsigned int drives_length; // 7
|
||||
unsigned int drives_addr;
|
||||
unsigned int config_table; // 8
|
||||
unsigned int bootloader_name; // 9
|
||||
unsigned int apm_table; // 10
|
||||
|
||||
unsigned int vbe_control_info; // 11
|
||||
unsigned int vbe_mode_info;
|
||||
unsigned short vbe_mode;
|
||||
unsigned short vbe_interface_seg;
|
||||
unsigned short vbe_interface_off;
|
||||
unsigned short vbe_interface_len;
|
||||
} mb_info_t;
|
||||
|
||||
/* The module structure. */
|
||||
typedef struct
|
||||
{
|
||||
unsigned int mod_start;
|
||||
unsigned int mod_end;
|
||||
unsigned int string;
|
||||
unsigned int reserved;
|
||||
} mb_module_t;
|
||||
|
||||
/* The memory map. Be careful that the offset 0 is base_addr_low, not size. */
|
||||
typedef struct
|
||||
{
|
||||
unsigned int size; //offset -4
|
||||
unsigned int base_addr_low; //offset 0
|
||||
unsigned int base_addr_high;
|
||||
unsigned int length_low;
|
||||
unsigned int length_high;
|
||||
unsigned int type;
|
||||
} mb_mmap_t;
|
||||
|
||||
/* The drive structure */
|
||||
typedef struct
|
||||
{
|
||||
unsigned int size;
|
||||
unsigned char drive_number;
|
||||
unsigned char drive_mode;
|
||||
unsigned char drive_cylinders;
|
||||
unsigned char drive_heads;
|
||||
unsigned char drive_sectors;
|
||||
unsigned short drive_ports[1];
|
||||
} mb_drive_t;
|
||||
|
||||
/* APM table structure */
|
||||
typedef struct
|
||||
{
|
||||
unsigned short version;
|
||||
unsigned short cseg;
|
||||
unsigned int offset;
|
||||
unsigned short cseg_16;
|
||||
unsigned short dseg;
|
||||
unsigned short flags;
|
||||
unsigned short cseg_len;
|
||||
unsigned short cseg_16_len;
|
||||
unsigned short dseg_len;
|
||||
} mb_apm_t;
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
|
||||
timeout 2
|
||||
default 0
|
||||
|
||||
title HOS
|
||||
kernel /boot/hos.gz
|
||||
Binary file not shown.
+36
-24
@@ -1,33 +1,45 @@
|
||||
# Makefile for HOS
|
||||
# Josh Holtrop
|
||||
# Created: 07/08/04
|
||||
# Modified: 07/09/04
|
||||
|
||||
# Assembler Information:
|
||||
NASM=nasm
|
||||
NASM_FLAGS=-f aout
|
||||
CROSS_COMPILE := i586-elf-
|
||||
|
||||
# C Information:
|
||||
CC=gcc
|
||||
CC_FLAGS=-fleading-underscore -fno-builtin -nostdlib -nostartfiles -nodefaultlibs -I. -I../include -Wall
|
||||
export LD := $(CROSS_COMPILE)ld
|
||||
export CC := $(CROSS_COMPILE)gcc
|
||||
export CXX := $(CROSS_COMPILE)g++
|
||||
export OBJDUMP := $(CROSS_COMPILE)objdump
|
||||
export NASM := nasm
|
||||
|
||||
# Linker Information:
|
||||
LD=ld
|
||||
LD_FLAGS=-nodefaultlibs -nostdlib --no-demangle -T link.ld
|
||||
export HOS_TOPLEVEL := $(shell pwd)
|
||||
LDSCRIPT := link.ld
|
||||
KERNEL := hos
|
||||
export CPPFLAGS := -I$(HOS_TOPLEVEL) -I$(HOS_TOPLEVEL)/include
|
||||
export CFLAGS := -Wall -O2 -g
|
||||
export CXXFLAGS := -Wall -O2 -fno-rtti -fno-exceptions -g
|
||||
export LDFLAGS := -T $(LDSCRIPT) -Map $(KERNEL).map
|
||||
export LDLIBS := `$(CC) -print-libgcc-file-name`
|
||||
|
||||
all: Asm_Kernel C_Kernel
|
||||
$(LD) $(LD_FLAGS) -Map boot.map boot.o kernel.o -o kernel.bin
|
||||
SUBDIRS := boot mm lang isr sys
|
||||
SUBDIRS_clean := $(SUBDIRS:%=%.clean)
|
||||
|
||||
Asm_Kernel:
|
||||
$(NASM) $(NASM_FLAGS) -l boot.lst boot.asm -o boot.o
|
||||
.PHONY: all
|
||||
all: $(KERNEL).gz
|
||||
|
||||
C_Kernel:
|
||||
$(CC) $(CC_FLAGS) -c kernel.c -o kernel.o
|
||||
$(KERNEL).gz: $(KERNEL)
|
||||
gzip -c $< > $@
|
||||
|
||||
#################################################
|
||||
# Clean up the source directory of any binaries #
|
||||
#################################################
|
||||
clean:
|
||||
- rm *.s *.S *.o *.bin *~ *.map *.lst
|
||||
$(KERNEL): $(KERNEL).o
|
||||
$(LD) $(LDFLAGS) -o $@ $<
|
||||
$(OBJDUMP) --disassemble --source $@ > $@.dump
|
||||
# strip $@
|
||||
|
||||
$(KERNEL).o: $(SUBDIRS)
|
||||
$(LD) -r -o $@ $(foreach subdir,$(SUBDIRS),$(subdir)/$(subdir)_all.o) $(LDLIBS)
|
||||
|
||||
.PHONY: $(SUBDIRS)
|
||||
$(SUBDIRS):
|
||||
$(MAKE) -C $@ SUBDIR=$@
|
||||
|
||||
.PHONY: clean
|
||||
clean: $(SUBDIRS_clean)
|
||||
-rm -f *~ $(KERNEL) $(KERNEL).{gz,o,elf,dump,map}
|
||||
|
||||
%.clean:
|
||||
$(MAKE) -C $* clean clean=1
|
||||
-196
@@ -1,196 +0,0 @@
|
||||
;boot.asm
|
||||
;Author: Josh Holtrop
|
||||
;Date: 07/08/04
|
||||
;Modified: 07/10/04
|
||||
|
||||
|
||||
%define MULTIBOOT_MAGIC 0x1BADB002
|
||||
%define MULTIBOOT_FLAGS 0x00010003
|
||||
|
||||
%define VIRT_OFFSET 0xC0000000 ;3gb virtual address
|
||||
%define PHYS_START 0x00100000 ;1mb physical address
|
||||
%define VIRT_STACK_TOP 0xCFFFFFFC ;3gb+256mb virtual address
|
||||
%define GDT_P PHYS_START ;1mb physical - Global Descriptor Table space
|
||||
%define GDT_V GDT_P+VIRT_OFFSET
|
||||
%define IDT_P PHYS_START+0x2000 ;1mb+8kb - Interrupt Descriptor Table space
|
||||
%define IDT_V IDT_P+VIRT_OFFSET
|
||||
%define PDBR_P PHYS_START+0x4000 ;1mb+16kb - Page Directory Base Register (first PD)
|
||||
%define PDBR_V PDBR_P+VIRT_OFFSET
|
||||
%define LOPT_P PHYS_START+0x5000 ;1mb+20kb - LOw Page Table for mapping first 4mb
|
||||
%define LOPT_V LOPT_P+VIRT_OFFSET
|
||||
%define PT_STACK_P PHYS_START+0x6000 ;1mb+24kb - page table for initial kernel stack pages (under 0xD0000000)
|
||||
%define PT_STACK_V PT_STACK_P+VIRT_OFFSET
|
||||
%define STACK_P PHYS_START+0x7000 ;1mb+28kb - initial 4kb kernel stack page
|
||||
%define STACK_V STACK_P+VIRT_OFFSET
|
||||
%define KERNEL_P PHYS_START+0x8000 ;1mb+32kb - the kernel's physical address
|
||||
%define KERNEL_V KERNEL_P+VIRT_OFFSET ;3gb+1mb+32kb, the virtual address of the kernel
|
||||
|
||||
extern _k_init, _isr, _k_mbsave, _end
|
||||
|
||||
[bits 32]
|
||||
|
||||
[global _start]
|
||||
_start:
|
||||
|
||||
multiboot_header:
|
||||
dd MULTIBOOT_MAGIC ;magic
|
||||
dd MULTIBOOT_FLAGS ;flags
|
||||
dd -(MULTIBOOT_MAGIC + MULTIBOOT_FLAGS) ;checksum
|
||||
|
||||
dd multiboot_header-VIRT_OFFSET ;header_addr
|
||||
dd _start-VIRT_OFFSET ;load_addr
|
||||
dd 0 ;load_end_addr
|
||||
dd _end-VIRT_OFFSET ;bss_end_addr
|
||||
dd multiboot_entry-VIRT_OFFSET ;entry_addr
|
||||
|
||||
; dd 1 ;mode_type
|
||||
; dd 80 ;width
|
||||
; dd 25 ;height
|
||||
; dd 0 ;depth
|
||||
|
||||
[global multiboot_entry]
|
||||
multiboot_entry:
|
||||
;This is where the kernel begins execution from the bootloader.
|
||||
;At this point, a temporary gdt is set up to "map" 0xC000_0000 to 0x0.
|
||||
cli ;should already be off...
|
||||
lgdt [gdtrbs32-VIRT_OFFSET]
|
||||
jmp KERNEL_CODE_BS32:segmented_start
|
||||
segmented_start:
|
||||
mov ax, KERNEL_DATA_BS32
|
||||
mov ss, ax
|
||||
mov ds, ax
|
||||
mov es, ax
|
||||
mov gs, ax
|
||||
mov fs, ax
|
||||
mov esp, STACK_V+0x1000 ;ok, now we can access our data
|
||||
|
||||
;aloop:
|
||||
; inc dword [0xC00B8000]
|
||||
; jmp aloop
|
||||
|
||||
|
||||
;Then the multiboot info structures are saved to local data variables.
|
||||
add ebx, VIRT_OFFSET
|
||||
push eax
|
||||
push ebx ;pointer to multiboot info structure
|
||||
call _k_mbsave ;save multiboot info structures
|
||||
add esp, 8
|
||||
|
||||
cmp eax, 0
|
||||
jz pm_return
|
||||
|
||||
;go back to real mode to initialize video mode
|
||||
mov ebx, pm_return
|
||||
|
||||
|
||||
|
||||
;Next we enable paging with the first 4mb mapped 1:1 virtual:physical
|
||||
; and with the 4mb starting at 0xC000_0000 mapped to the first 4mb physical.
|
||||
pm_return:
|
||||
xor eax, eax
|
||||
mov edi, PDBR_V
|
||||
mov ecx, 1024 ;clear the PDBR
|
||||
rep stosd
|
||||
mov edi, PT_STACK_V
|
||||
mov ecx, 1024 ;clear the PT_STACK
|
||||
rep stosd
|
||||
mov [PDBR_V], dword LOPT_P|0x03 ;store the physical address of the LOw Page Table | (read/write, present)
|
||||
mov [PDBR_V+0xC00], dword LOPT_P|0x03 ;store the physical address of the LOw Page Table | (read/write, present)
|
||||
mov [PDBR_V+0xCFC], dword PT_STACK_P|0x03 ;store the physical address of the initial stack page page table | (read/write, present)
|
||||
mov [PT_STACK_V+0xFFC], dword STACK_P|0x03 ;store the physical address of the initial stack page | (read/write, present)
|
||||
|
||||
mov edi, LOPT_V
|
||||
mov ecx, 1024
|
||||
mov eax, 0x03 ;starting physical address = 0x0 | (read/write, present flags)
|
||||
fill_lopt_loop: ;fill the page table
|
||||
stosd
|
||||
add eax, 4096 ;increment next phsyical address by 4kb
|
||||
loop fill_lopt_loop
|
||||
|
||||
mov eax, PDBR_P
|
||||
mov cr3, eax ;store the Page Directory Base Address
|
||||
mov eax, cr0
|
||||
or eax, 0x80000000 ;set Page Enable bit
|
||||
mov cr0, eax ;now paging is active!
|
||||
|
||||
|
||||
mov edi, GDT_V
|
||||
mov esi, gdt
|
||||
mov ecx, gdt_end-gdt
|
||||
rep movsb
|
||||
|
||||
mov edi, IDT_V ;destination
|
||||
mov esi, isr_0 ;address of isr0
|
||||
mov edx, isr_1-isr_0 ;distance between isr labels
|
||||
mov ecx, 50 ;number of isrlabels
|
||||
fill_idt:
|
||||
mov ebx, esi
|
||||
mov ax, si
|
||||
stosw ;0 offset 15:0
|
||||
mov ax, KERNEL_CODE
|
||||
stosw ;2 selector 15:0
|
||||
mov ax, 0x8E00
|
||||
stosw ;4 [P][DPL][0][TYPE][0][0][0][0][0][0][0][0]
|
||||
shr esi, 16
|
||||
mov ax, si
|
||||
stosw ;6 offset 31:16
|
||||
mov esi, ebx
|
||||
add esi, edx
|
||||
loop fill_idt
|
||||
mov word [IDT_V+0x30*8+4], 0xEE00 ;interrupt 0x30 has user priviledges
|
||||
|
||||
;Then we can start using our "real" gdt, then unmap the lower 4mb.
|
||||
lgdt [gdtr] ;load gdt
|
||||
jmp KERNEL_CODE:newgdtcontinue
|
||||
newgdtcontinue:
|
||||
mov ax, KERNEL_DATA
|
||||
mov es, ax
|
||||
mov ds, ax
|
||||
mov gs, ax
|
||||
mov fs, ax
|
||||
mov ss, ax
|
||||
mov esp, VIRT_STACK_TOP ;stack just under 3gb+256mb, moves downward
|
||||
lidt [idtr] ;load idt
|
||||
mov [PDBR_V], dword 0 ;unmap 0x0, we are running completely paged at 0xC000_0000
|
||||
|
||||
call _k_init ;C kernel initialization
|
||||
|
||||
idle_loop:
|
||||
; sti
|
||||
hlt
|
||||
jmp idle_loop
|
||||
|
||||
;-------------------------------------------------------
|
||||
gdtrbs32:
|
||||
dw gdt_endbs32-gdtbs32-1
|
||||
dd gdtbs32-VIRT_OFFSET
|
||||
gdtbs32: ;null descriptor
|
||||
dd 0
|
||||
dd 0
|
||||
|
||||
;a base of 0x4000_0000, when added to 0xC000_0000 will produce 0x0000_0000 physical before paging in effect
|
||||
KERNEL_CODE_BS32 equ $-gdtbs32
|
||||
db 0xff ;limit 7:0
|
||||
db 0xff ;limit 15:8
|
||||
db 0x00 ;base 7:0
|
||||
db 0x00 ;base 15:8
|
||||
db 0x00 ;base 23:16
|
||||
db 0x9a ;access
|
||||
db 0xcf ;flags / limit 19:16
|
||||
db 0x40 ;base 31:24
|
||||
|
||||
KERNEL_DATA_BS32 equ $-gdtbs32
|
||||
db 0xff ;limit 7:0
|
||||
db 0xff ;limit 15:8
|
||||
db 0x00 ;base 7:0
|
||||
db 0x00 ;base 15:8
|
||||
db 0x00 ;base 23:16
|
||||
db 0x92 ;access
|
||||
db 0xcf ;flags / limit 19:16
|
||||
db 0x40 ;base 31:24
|
||||
|
||||
gdt_endbs32:
|
||||
|
||||
%include "gdt.inc"
|
||||
%include "idt.inc"
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
|
||||
include $(HOS_TOPLEVEL)/subdir.mak
|
||||
@@ -0,0 +1,23 @@
|
||||
; boot.asm
|
||||
; Author: Josh Holtrop
|
||||
; Date: 2009-06-25
|
||||
; Adapted from HOS 0.16 source
|
||||
|
||||
%define CONSOLE_MEMORY 0xB8000
|
||||
|
||||
; Symbols from C
|
||||
extern k_bootstrap, bootstrap_stack
|
||||
|
||||
;**************************************************************************
|
||||
;* This is the entry point for the kernel. *
|
||||
;**************************************************************************
|
||||
[global start]
|
||||
start:
|
||||
mov cx, 0x0700 + 'a'
|
||||
mov [CONSOLE_MEMORY+160*8+0*2], cx
|
||||
|
||||
mov esp, bootstrap_stack+4096 ; set up temporary stack space
|
||||
|
||||
push eax ; multiboot bootloader magic value
|
||||
push ebx ; pointer to multiboot info struct
|
||||
call k_bootstrap
|
||||
@@ -0,0 +1,85 @@
|
||||
|
||||
#include "k_bootstrap.h"
|
||||
#include "k_main.h"
|
||||
#include "hos_types.h"
|
||||
#include "hos_defines.h"
|
||||
#include "multiboot.h"
|
||||
#include "sys/cpu.h"
|
||||
#include "k_early_panic.h"
|
||||
#include "mm/mm.h"
|
||||
#include "mm/stack.h"
|
||||
#include "lang/kio.h"
|
||||
#include "isr/interrupts.h"
|
||||
|
||||
#define DEBUG_LETTER(col,chr) *(u16_t *)(KERNEL_OFFSET + CONSOLE_MEMORY \
|
||||
+ 160 * 8 + (col) * 2) \
|
||||
= 0x0700 | (chr)
|
||||
extern "C" {
|
||||
|
||||
u8_t bootstrap_stack[4096];
|
||||
|
||||
/**************************************************************************
|
||||
* Multiboot header data block *
|
||||
*************************************************************************/
|
||||
u32_t mb_header[] __attribute__ ((section (".multiboot_header") )) = {
|
||||
MB_HEADER_MAGIC, /* magic */
|
||||
MB_HEADER_FLAGS, /* flags */
|
||||
-(MB_HEADER_MAGIC + MB_HEADER_FLAGS) /* checksum */
|
||||
};
|
||||
|
||||
/**************************************************************************
|
||||
* This function is invoked to bootstrap the kernel. *
|
||||
*************************************************************************/
|
||||
void k_bootstrap(mb_info_t * mb_info, u32_t mb_magic)
|
||||
{
|
||||
DEBUG_LETTER(1, 'b');
|
||||
|
||||
if (mb_magic != MB_BOOTLOADER_MAGIC)
|
||||
{
|
||||
k_early_panic("Bad multiboot magic identifier!");
|
||||
}
|
||||
|
||||
if ( ! (mb_info->flags & MB_BOOTLOADER_MMAP) )
|
||||
{
|
||||
k_early_panic("No memory map provided by bootloader!");
|
||||
}
|
||||
|
||||
for (mb_mmap_t * mmap = (mb_mmap_t *) (mb_info->mmap_addr + KERNEL_OFFSET),
|
||||
* end = (mb_mmap_t *) ((u32_t)mmap + mb_info->mmap_length);
|
||||
mmap < end;
|
||||
mmap = (mb_mmap_t *) (((u32_t)mmap) + mmap->size + 4))
|
||||
{
|
||||
// kprintf(" ** size: %d, type: %d ", mmap->size, mmap->type);
|
||||
mm_record_mmap_entry(mmap);
|
||||
}
|
||||
|
||||
DEBUG_LETTER(2, 'c');
|
||||
|
||||
/*
|
||||
* These functions could destroy the multiboot information block and
|
||||
* associated structures, so we must be finished reading those structures
|
||||
* before calling them.
|
||||
*/
|
||||
mm_bootstrap();
|
||||
DEBUG_LETTER(3, 'd');
|
||||
interrupts_bootstrap();
|
||||
DEBUG_LETTER(4, 'e');
|
||||
kio_bootstrap();
|
||||
DEBUG_LETTER(5, 'f');
|
||||
|
||||
/* begin using the permanent stack */
|
||||
write_esp(KERNEL_STACK_TOP);
|
||||
k_main();
|
||||
|
||||
idle_loop();
|
||||
}
|
||||
|
||||
void idle_loop()
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
__asm__ __volatile__ ("hlt");
|
||||
}
|
||||
}
|
||||
|
||||
} /* extern "C" */
|
||||
@@ -0,0 +1,17 @@
|
||||
|
||||
#ifndef K_BOOTSTRAP_H
|
||||
#define K_BOOTSTRAP_H
|
||||
|
||||
#include "hos_types.h"
|
||||
#include "multiboot.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
void k_bootstrap(mb_info_t * mb_info, u32_t mb_magic)
|
||||
__attribute__ ((noreturn));
|
||||
void idle_loop()
|
||||
__attribute__ ((noreturn));
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,18 @@
|
||||
|
||||
#include "hos_types.h"
|
||||
#include "hos_defines.h"
|
||||
#include "k_early_panic.h"
|
||||
|
||||
void k_early_panic(const char * msg)
|
||||
{
|
||||
char * dest = (char *) (CONSOLE_MEMORY + KERNEL_OFFSET);
|
||||
while (*msg)
|
||||
{
|
||||
*dest++ = *msg++;
|
||||
*dest++ = 0x04; /* red error message */
|
||||
}
|
||||
|
||||
/* infinite loop */
|
||||
for (;;)
|
||||
;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
#ifndef K_EARLY_PANIC_H
|
||||
#define K_EARLY_PANIC_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void k_early_panic(const char * msg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,28 @@
|
||||
|
||||
#include "k_main.h"
|
||||
#include "lang/kio.h"
|
||||
#include "mm/mm.h"
|
||||
#include "sys/timer.h"
|
||||
#include "sys/pic.h"
|
||||
#include "isr/interrupts.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
void k_main()
|
||||
{
|
||||
kprintf("Kernel load address: 0x%08x\n", KERNEL_CODE);
|
||||
kprintf("Kernel code size: %d KB (%d bytes)\n",
|
||||
(KERNEL_DATA - KERNEL_CODE) >> 10, KERNEL_DATA - KERNEL_CODE);
|
||||
kprintf("Kernel data size: %d KB (%d bytes)\n",
|
||||
(KERNEL_BSS - KERNEL_DATA) >> 10, KERNEL_BSS - KERNEL_DATA);
|
||||
kprintf("Kernel bss size: %d KB (%d bytes)\n",
|
||||
(KERNEL_END - KERNEL_BSS) >> 10, KERNEL_END - KERNEL_BSS);
|
||||
mm_print_memory_map();
|
||||
timer_init(KERNEL_TIMER_FREQ);
|
||||
pic_remap(0x20, 0x28);
|
||||
pic_mask1(0x0);
|
||||
pic_mask2(0x0);
|
||||
interrupts_enable();
|
||||
}
|
||||
|
||||
} /* extern "C" */
|
||||
@@ -0,0 +1,11 @@
|
||||
|
||||
#ifndef K_MAIN_H
|
||||
#define K_MAIN_H
|
||||
|
||||
extern "C" {
|
||||
|
||||
void k_main();
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,71 +0,0 @@
|
||||
;gdt.inc
|
||||
;Author: Josh Holtrop
|
||||
;Date: 10/30/03
|
||||
;Modified: 03/02/04
|
||||
|
||||
gdtr:
|
||||
dw gdt_end-gdt-1
|
||||
dd GDT_V
|
||||
gdt:
|
||||
dd 0
|
||||
dd 0
|
||||
KERNEL_CODE equ $-gdt
|
||||
dw 0xffff ;limit 15:0
|
||||
dw 0x0000 ;base 15:0
|
||||
db 0x00 ;base 23:16
|
||||
db 0x9A ;access ([P][DPL][1][Executable][Direction/Conforming][Writable/Readable][A])
|
||||
db 0xCF ;flags ([G][D/B][0][0]) / limit 19:16
|
||||
db 0x00 ;base 31:24
|
||||
KERNEL_DATA equ $-gdt
|
||||
dw 0xffff ;limit 15:0
|
||||
dw 0x0000 ;base 15:0
|
||||
db 0x00 ;base 23:16
|
||||
db 0x92 ;access ([P][DPL][1][Executable][Direction/Conforming][Writable/Readable][A])
|
||||
db 0xCF ;flags ([G][D/B][0][0]) / limit 19:16
|
||||
db 0x00 ;base 31:24
|
||||
USER_CODE equ $-gdt
|
||||
dw 0xffff ;limit 15:0
|
||||
dw 0x0000 ;base 15:0
|
||||
db 0x00 ;base 23:16
|
||||
db 0xFA ;access ([P][DPL][1][Executable][Direction/Conforming][Writable/Readable][A])
|
||||
db 0xCF ;flags ([G][D/B][0][0]) / limit 19:16
|
||||
db 0x00 ;base 31:24
|
||||
USER_DATA equ $-gdt
|
||||
dw 0xffff ;limit 15:0
|
||||
dw 0x0000 ;base 15:0
|
||||
db 0x00 ;base 23:16
|
||||
db 0xF2 ;access ([P][DPL][1][Executable][Direction/Conforming][Writable/Readable][A])
|
||||
db 0xCF ;flags ([G][D/B][0][0]) / limit 19:16
|
||||
db 0x00 ;base 31:24
|
||||
VESA_CODE equ $-gdt
|
||||
dw 0xffff ;limit 15:0
|
||||
dw 0x0000 ;base 15:0
|
||||
db 0x00 ;base 23:16
|
||||
db 0x9A ;access ([P][DPL][1][Executable][Direction/Conforming][Writable/Readable][A])
|
||||
db 0x40 ;flags ([G][D/B][0][0]) / limit 19:16
|
||||
db 0x00 ;base 31:24
|
||||
VESA_DATA equ $-gdt
|
||||
dw 0xffff ;limit 15:0
|
||||
dw 0x0000 ;base 15:0
|
||||
db 0x00 ;base 23:16
|
||||
db 0x92 ;access ([P][DPL][1][Executable][Direction/Conforming][Writable/Readable][A])
|
||||
db 0x40 ;flags ([G][D/B][0][0]) / limit 19:16
|
||||
db 0x00 ;base 31:24
|
||||
VIDEO_TEXT equ $-gdt
|
||||
dw 0x7FFF ;limit 15:0
|
||||
dw 0x8000 ;base 15:0
|
||||
db 0x0B ;base 23:16
|
||||
db 0x92 ;access ([P][DPL][1][Executable][Direction/Conforming][Writable/Readable][A])
|
||||
db 0x40 ;flags ([G][D/B][0][0]) / limit 19:16
|
||||
db 0x00 ;base 31:24
|
||||
VIDEO_GRAPHICS equ $-gdt
|
||||
dw 0xFFFF ;limit 15:0
|
||||
dw 0x0000 ;base 15:0
|
||||
db 0x0A ;base 23:16
|
||||
db 0x92 ;access ([P][DPL][1][Executable][Direction/Conforming][Writable/Readable][A])
|
||||
db 0x40 ;flags ([G][D/B][0][0]) / limit 19:16
|
||||
db 0x00 ;base 31:24
|
||||
gdt_end:
|
||||
|
||||
|
||||
|
||||
@@ -1,92 +0,0 @@
|
||||
;idt.inc
|
||||
;Author: Josh Holtrop
|
||||
;Date: 10/30/03
|
||||
;Modified: 07/06/04
|
||||
|
||||
idtr:
|
||||
dw 50*8-1 ;size of idt
|
||||
dd IDT_V ;address of idt
|
||||
|
||||
|
||||
%macro isr_label 1
|
||||
isr_%1:
|
||||
push eax
|
||||
mov eax, %1
|
||||
jmp isr_main
|
||||
%endmacro
|
||||
|
||||
isr_label 0
|
||||
isr_label 1
|
||||
isr_label 2
|
||||
isr_label 3
|
||||
isr_label 4
|
||||
isr_label 5
|
||||
isr_label 6
|
||||
isr_label 7
|
||||
isr_label 8
|
||||
isr_label 9
|
||||
isr_label 10
|
||||
isr_label 11
|
||||
isr_label 12
|
||||
isr_label 13
|
||||
isr_label 14
|
||||
isr_label 15
|
||||
isr_label 16
|
||||
isr_label 17
|
||||
isr_label 18
|
||||
isr_label 19
|
||||
isr_label 20
|
||||
isr_label 21
|
||||
isr_label 22
|
||||
isr_label 23
|
||||
isr_label 24
|
||||
isr_label 25
|
||||
isr_label 26
|
||||
isr_label 27
|
||||
isr_label 28
|
||||
isr_label 29
|
||||
isr_label 30
|
||||
isr_label 31
|
||||
isr_label 32
|
||||
isr_label 33
|
||||
isr_label 34
|
||||
isr_label 35
|
||||
isr_label 36
|
||||
isr_label 37
|
||||
isr_label 38
|
||||
isr_label 39
|
||||
isr_label 40
|
||||
isr_label 41
|
||||
isr_label 42
|
||||
isr_label 43
|
||||
isr_label 44
|
||||
isr_label 45
|
||||
isr_label 46
|
||||
isr_label 47
|
||||
isr_label 48
|
||||
isr_label 49
|
||||
|
||||
isr_main:
|
||||
pusha
|
||||
push ds
|
||||
push es
|
||||
|
||||
push eax ;interrupt number
|
||||
call _isr
|
||||
add esp, 4
|
||||
|
||||
pop es
|
||||
pop ds
|
||||
popa
|
||||
pop eax ;original saved eax
|
||||
|
||||
iret
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
|
||||
#ifndef HOS_DEFINES_H
|
||||
#define HOS_DEFINES_H
|
||||
|
||||
#include "hos_types.h"
|
||||
|
||||
#define KERNEL_OFFSET 0x00000000
|
||||
|
||||
#define PAGE_LOG_SIZE 12u
|
||||
#define PAGE_SIZE (1 << PAGE_LOG_SIZE)
|
||||
#define PAGE_HIGH_MASK (0xFFFFFFFFu << PAGE_LOG_SIZE)
|
||||
#define PAGE_LOW_MASK (0xFFFFFFFFu >> (32 - PAGE_LOG_SIZE))
|
||||
|
||||
#define CONSOLE_MEMORY 0xB8000
|
||||
|
||||
#define KERNEL_CODE (&_code)
|
||||
#define KERNEL_DATA (&_data)
|
||||
#define KERNEL_BSS (&_bss)
|
||||
#define KERNEL_END (&_end)
|
||||
|
||||
#define KERNEL_PHYSICAL_ADDRESS ((u32_t)(KERNEL_CODE - KERNEL_OFFSET))
|
||||
#define KERNEL_VIRTUAL_ADDRESS ((u32_t)KERNEL_CODE)
|
||||
#define KERNEL_SIZE ((u32_t)(KERNEL_END - KERNEL_CODE))
|
||||
|
||||
#define KERNEL_TIMER_FREQ 1000
|
||||
|
||||
#define BUILD_BUG_ON(condition) \
|
||||
do { \
|
||||
typedef struct { int negative_width_test : ((condition)?-1:1); } \
|
||||
BUILD_BUG_ON_DUMMY_STRUCT; \
|
||||
} \
|
||||
while(0)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern u8_t _code;
|
||||
extern u8_t _data;
|
||||
extern u8_t _bss;
|
||||
extern u8_t _end;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,55 @@
|
||||
|
||||
#ifndef HOS_TYPES_H
|
||||
#define HOS_TYPES_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef unsigned char u8_t;
|
||||
typedef signed char s8_t;
|
||||
typedef unsigned short u16_t;
|
||||
typedef signed short s16_t;
|
||||
typedef unsigned int u32_t;
|
||||
typedef signed int s32_t;
|
||||
typedef unsigned long long u64_t;
|
||||
typedef signed long long s64_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u32_t gs;
|
||||
u32_t fs;
|
||||
u32_t es;
|
||||
u32_t ds;
|
||||
|
||||
u32_t edi;
|
||||
u32_t esi;
|
||||
u32_t ebp;
|
||||
u32_t esp_junk; /* the esp value saved by 'pusha' */
|
||||
u32_t ebx;
|
||||
u32_t edx;
|
||||
u32_t ecx;
|
||||
u32_t eax;
|
||||
|
||||
u32_t error; /* valid on exceptions 8, 10-14 */
|
||||
|
||||
u32_t eip;
|
||||
u32_t cs;
|
||||
u32_t eflags;
|
||||
u32_t esp; /* present if privilege transition */
|
||||
u32_t ss;
|
||||
} int_stack_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u16_t limit;
|
||||
u32_t base;
|
||||
} __attribute__ ((packed)) gdtr_t;
|
||||
|
||||
typedef gdtr_t idtr_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,154 @@
|
||||
|
||||
#ifndef MULTIBOOT_H
|
||||
#define MULTIBOOT_H
|
||||
|
||||
#include "hos_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* The magic number for the Multiboot header. */
|
||||
#define MB_HEADER_MAGIC 0x1BADB002
|
||||
#define MB_HEADER_FLAGS 0x00000003
|
||||
|
||||
#define MB_HEADER_ALIGN_MODULES (1 << 0)
|
||||
#define MB_HEADER_MEM_INFO (1 << 1)
|
||||
#define MB_HEADER_VIDEO_INFO (1 << 2)
|
||||
#define MB_HEADER_KLUDGE_OFFSETS (1 << 16)
|
||||
|
||||
/* The magic number passed by a Multiboot-compliant boot loader. */
|
||||
#define MB_BOOTLOADER_MAGIC 0x2BADB002
|
||||
|
||||
#define MB_BOOTLOADER_MEM_INFO (1 << 0)
|
||||
#define MB_BOOTLOADER_BOOT_DEVICE (1 << 1)
|
||||
#define MB_BOOTLOADER_COMMAND_LINE (1 << 2)
|
||||
#define MB_BOOTLOADER_MODS (1 << 3)
|
||||
#define MB_BOOTLOADER_AOUT (1 << 4)
|
||||
#define MB_BOOTLOADER_ELF (1 << 5)
|
||||
#define MB_BOOTLOADER_MMAP (1 << 6)
|
||||
#define MB_BOOTLOADER_DRIVES (1 << 7)
|
||||
#define MB_BOOTLOADER_CONFIG (1 << 8)
|
||||
#define MB_BOOTLOADER_APM (1 << 9)
|
||||
#define MB_BOOTLOADER_GRAPHICS (1 << 10)
|
||||
|
||||
#define MB_DRIVE_MODE_CHS 0
|
||||
#define MB_DRIVE_MODE_LBA 1
|
||||
|
||||
#define MB_MMAP_TYPE_RAM 1
|
||||
|
||||
/* The Multiboot header. */
|
||||
typedef struct
|
||||
{
|
||||
u32_t magic;
|
||||
u32_t flags;
|
||||
u32_t checksum;
|
||||
u32_t header_addr; // if flags[16]
|
||||
u32_t load_addr; // if flags[16]
|
||||
u32_t load_end_addr; // if flags[16]
|
||||
u32_t bss_end_addr; // if flags[16]
|
||||
u32_t entry_addr; // if flags[16]
|
||||
u32_t mode_type; // if flags[2]
|
||||
u32_t width; // if flags[2]
|
||||
u32_t height; // if flags[2]
|
||||
u32_t depth; // if flags[2]
|
||||
} mb_header_t;
|
||||
|
||||
/* The symbol table for a.out. */
|
||||
typedef struct
|
||||
{
|
||||
u32_t tabsize;
|
||||
u32_t strsize;
|
||||
u32_t addr;
|
||||
u32_t reserved;
|
||||
} mb_aout_symbol_table_t;
|
||||
|
||||
/* The section header table for ELF. */
|
||||
typedef struct
|
||||
{
|
||||
u32_t num;
|
||||
u32_t size;
|
||||
u32_t addr;
|
||||
u32_t shndx;
|
||||
} mb_elf_section_header_table_t;
|
||||
|
||||
/* The Multiboot information. */
|
||||
typedef struct
|
||||
{
|
||||
u32_t flags;
|
||||
u32_t mem_lower; // present if flags[0] is set
|
||||
u32_t mem_upper;
|
||||
u32_t boot_device; // 1
|
||||
u32_t cmdline; // 2
|
||||
u32_t mods_count; // 3
|
||||
u32_t mods_addr; // 3
|
||||
union
|
||||
{
|
||||
mb_aout_symbol_table_t aout_sym; // 4
|
||||
mb_elf_section_header_table_t elf_sec; // 5
|
||||
};
|
||||
u32_t mmap_length; // 6
|
||||
u32_t mmap_addr; // 6
|
||||
u32_t drives_length; // 7
|
||||
u32_t drives_addr; // 7
|
||||
u32_t config_table; // 8
|
||||
u32_t bootloader_name; // 9
|
||||
u32_t apm_table; // 10
|
||||
|
||||
u32_t vbe_control_info; // 11
|
||||
u32_t vbe_mode_info; // 11
|
||||
u16_t vbe_mode; // 11
|
||||
u16_t vbe_interface_seg; // 11
|
||||
u16_t vbe_interface_off; // 11
|
||||
u16_t vbe_interface_len; // 11
|
||||
} mb_info_t;
|
||||
|
||||
/* The module structure. */
|
||||
typedef struct
|
||||
{
|
||||
u32_t mod_start;
|
||||
u32_t mod_end;
|
||||
u32_t string;
|
||||
u32_t reserved;
|
||||
} mb_module_t;
|
||||
|
||||
/* The memory map. Be careful that the offset 0 is base_addr_low, not size. */
|
||||
typedef struct
|
||||
{
|
||||
u32_t size; // offset -4
|
||||
u64_t base; // offset 0
|
||||
u64_t length;
|
||||
u32_t type;
|
||||
} mb_mmap_t;
|
||||
|
||||
/* The drive structure */
|
||||
typedef struct
|
||||
{
|
||||
u32_t size;
|
||||
u8_t drive_number;
|
||||
u8_t drive_mode;
|
||||
u8_t drive_cylinders;
|
||||
u8_t drive_heads;
|
||||
u8_t drive_sectors;
|
||||
u16_t drive_ports[1];
|
||||
} mb_drive_t;
|
||||
|
||||
/* APM table structure */
|
||||
typedef struct
|
||||
{
|
||||
u16_t version;
|
||||
u16_t cseg;
|
||||
u32_t offset;
|
||||
u16_t cseg_16;
|
||||
u16_t dseg;
|
||||
u16_t flags;
|
||||
u16_t cseg_len;
|
||||
u16_t cseg_16_len;
|
||||
u16_t dseg_len;
|
||||
} mb_apm_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,37 @@
|
||||
|
||||
#ifndef PORTIO_H
|
||||
#define PORTIO_H
|
||||
|
||||
#include "hos_types.h"
|
||||
|
||||
#define outportb(port, val) \
|
||||
__asm__ __volatile__ ("outb %%al, %%dx" : : "a" (val), "d" (port));
|
||||
|
||||
#define outportw(port, val) \
|
||||
__asm__ __volatile__ ("outw %%ax, %%dx" : : "a" (val), "d" (port));
|
||||
|
||||
#define outportd(port, val) \
|
||||
__asm__ __volatile__ ("outl %%eax, %%dx" : : "a" (val), "d" (port));
|
||||
|
||||
static inline u8_t inportb(u16_t port)
|
||||
{
|
||||
u8_t val;
|
||||
__asm__ __volatile__ ("inb %%dx, %%al" : "=a" (val) : "d" (port));
|
||||
return val;
|
||||
}
|
||||
|
||||
static inline u16_t inportw(u16_t port)
|
||||
{
|
||||
u16_t val;
|
||||
__asm__ __volatile__ ("inw %%dx, %%al" : "=a" (val) : "d" (port));
|
||||
return val;
|
||||
}
|
||||
|
||||
static inline u32_t inportd(u16_t port)
|
||||
{
|
||||
u32_t val;
|
||||
__asm__ __volatile__ ("inl %%dx, %%al" : "=a" (val) : "d" (port));
|
||||
return val;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,2 @@
|
||||
|
||||
include $(HOS_TOPLEVEL)/subdir.mak
|
||||
@@ -0,0 +1,110 @@
|
||||
|
||||
#include "hos_types.h"
|
||||
#include "interrupts.h"
|
||||
#include "mm/mm.h"
|
||||
#include "lang/kio.h"
|
||||
#include "sys/pic.h"
|
||||
#include "sys/cpu.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
idtr_t idtr;
|
||||
|
||||
void isr(u8_t int_num, int_stack_t * istack)
|
||||
{
|
||||
switch (int_num)
|
||||
{
|
||||
case 0x20: /* timer interrupt */
|
||||
(*(u16_t *)CONSOLE_MEMORY)++;
|
||||
pic_eoi();
|
||||
break;
|
||||
case 0x21:
|
||||
/* TODO: keyboard hook */
|
||||
pic_eoi();
|
||||
break;
|
||||
default:
|
||||
kputs("--------------------------------------------------------------------------------");
|
||||
kprintf("Unhandled Interrupt #%d\n", int_num);
|
||||
kprintf(" ds: 0x%08x es: 0x%08x fs: 0x%08x gs: 0x%08x\n",
|
||||
istack->ds, istack->es, istack->fs, istack->gs);
|
||||
kprintf(" eax: 0x%08x ebx: 0x%08x ecx: 0x%08x edx: 0x%08x\n",
|
||||
istack->eax, istack->ebx, istack->ecx, istack->edx);
|
||||
kprintf(" ebp: 0x%08x esi: 0x%08x edi: 0x%08x eflags: 0x%08x\n",
|
||||
istack->ebp, istack->esi, istack->edi, istack->eflags);
|
||||
kprintf(" cs: 0x%08x eip: 0x%08x ss: 0x%08x esp: 0x%08x\n",
|
||||
istack->cs, istack->eip, istack->ss, istack->esp);
|
||||
kprintf(" cr0: 0x%08x cr2: 0x%08x cr3: 0x%08x\n",
|
||||
read_cr0(), read_cr2(), read_cr3());
|
||||
kprintf(" Error: 0x%08x (%d)\n", istack->error, istack->error);
|
||||
kputs("--------------------------------------------------------------------------------");
|
||||
|
||||
kprintf("Halting!\n");
|
||||
for (;;)
|
||||
;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} /* extern "C" */
|
||||
|
||||
void interrupts_bootstrap()
|
||||
{
|
||||
u32_t idt_phys = mm_page_alloc();
|
||||
u32_t idt_virt = mm_early_vpage_alloc();
|
||||
mm_map(idt_virt, idt_phys, 0, 1);
|
||||
|
||||
u64_t * idt = (u64_t *) idt_virt;
|
||||
idt[0] = MAKE_IDT_DESCRIPTOR(KERNEL_CODE_SEGMENT, isr_0, 0);
|
||||
idt[1] = MAKE_IDT_DESCRIPTOR(KERNEL_CODE_SEGMENT, isr_1, 0);
|
||||
idt[2] = MAKE_IDT_DESCRIPTOR(KERNEL_CODE_SEGMENT, isr_2, 0);
|
||||
idt[3] = MAKE_IDT_DESCRIPTOR(KERNEL_CODE_SEGMENT, isr_3, 0);
|
||||
idt[4] = MAKE_IDT_DESCRIPTOR(KERNEL_CODE_SEGMENT, isr_4, 0);
|
||||
idt[5] = MAKE_IDT_DESCRIPTOR(KERNEL_CODE_SEGMENT, isr_5, 0);
|
||||
idt[6] = MAKE_IDT_DESCRIPTOR(KERNEL_CODE_SEGMENT, isr_6, 0);
|
||||
idt[7] = MAKE_IDT_DESCRIPTOR(KERNEL_CODE_SEGMENT, isr_7, 0);
|
||||
idt[8] = MAKE_IDT_DESCRIPTOR(KERNEL_CODE_SEGMENT, isr_8, 0);
|
||||
idt[9] = MAKE_IDT_DESCRIPTOR(KERNEL_CODE_SEGMENT, isr_9, 0);
|
||||
idt[10] = MAKE_IDT_DESCRIPTOR(KERNEL_CODE_SEGMENT, isr_10, 0);
|
||||
idt[11] = MAKE_IDT_DESCRIPTOR(KERNEL_CODE_SEGMENT, isr_11, 0);
|
||||
idt[12] = MAKE_IDT_DESCRIPTOR(KERNEL_CODE_SEGMENT, isr_12, 0);
|
||||
idt[13] = MAKE_IDT_DESCRIPTOR(KERNEL_CODE_SEGMENT, isr_13, 0);
|
||||
idt[14] = MAKE_IDT_DESCRIPTOR(KERNEL_CODE_SEGMENT, isr_14, 0);
|
||||
idt[15] = MAKE_IDT_DESCRIPTOR(KERNEL_CODE_SEGMENT, isr_15, 0);
|
||||
idt[16] = MAKE_IDT_DESCRIPTOR(KERNEL_CODE_SEGMENT, isr_16, 0);
|
||||
idt[17] = MAKE_IDT_DESCRIPTOR(KERNEL_CODE_SEGMENT, isr_17, 0);
|
||||
idt[18] = MAKE_IDT_DESCRIPTOR(KERNEL_CODE_SEGMENT, isr_18, 0);
|
||||
idt[19] = MAKE_IDT_DESCRIPTOR(KERNEL_CODE_SEGMENT, isr_19, 0);
|
||||
idt[20] = MAKE_IDT_DESCRIPTOR(KERNEL_CODE_SEGMENT, isr_20, 0);
|
||||
idt[21] = MAKE_IDT_DESCRIPTOR(KERNEL_CODE_SEGMENT, isr_21, 0);
|
||||
idt[22] = MAKE_IDT_DESCRIPTOR(KERNEL_CODE_SEGMENT, isr_22, 0);
|
||||
idt[23] = MAKE_IDT_DESCRIPTOR(KERNEL_CODE_SEGMENT, isr_23, 0);
|
||||
idt[24] = MAKE_IDT_DESCRIPTOR(KERNEL_CODE_SEGMENT, isr_24, 0);
|
||||
idt[25] = MAKE_IDT_DESCRIPTOR(KERNEL_CODE_SEGMENT, isr_25, 0);
|
||||
idt[26] = MAKE_IDT_DESCRIPTOR(KERNEL_CODE_SEGMENT, isr_26, 0);
|
||||
idt[27] = MAKE_IDT_DESCRIPTOR(KERNEL_CODE_SEGMENT, isr_27, 0);
|
||||
idt[28] = MAKE_IDT_DESCRIPTOR(KERNEL_CODE_SEGMENT, isr_28, 0);
|
||||
idt[29] = MAKE_IDT_DESCRIPTOR(KERNEL_CODE_SEGMENT, isr_29, 0);
|
||||
idt[30] = MAKE_IDT_DESCRIPTOR(KERNEL_CODE_SEGMENT, isr_30, 0);
|
||||
idt[31] = MAKE_IDT_DESCRIPTOR(KERNEL_CODE_SEGMENT, isr_31, 0);
|
||||
idt[32] = MAKE_IDT_DESCRIPTOR(KERNEL_CODE_SEGMENT, isr_32, 0);
|
||||
idt[33] = MAKE_IDT_DESCRIPTOR(KERNEL_CODE_SEGMENT, isr_33, 0);
|
||||
idt[34] = MAKE_IDT_DESCRIPTOR(KERNEL_CODE_SEGMENT, isr_34, 0);
|
||||
idt[35] = MAKE_IDT_DESCRIPTOR(KERNEL_CODE_SEGMENT, isr_35, 0);
|
||||
idt[36] = MAKE_IDT_DESCRIPTOR(KERNEL_CODE_SEGMENT, isr_36, 0);
|
||||
idt[37] = MAKE_IDT_DESCRIPTOR(KERNEL_CODE_SEGMENT, isr_37, 0);
|
||||
idt[38] = MAKE_IDT_DESCRIPTOR(KERNEL_CODE_SEGMENT, isr_38, 0);
|
||||
idt[39] = MAKE_IDT_DESCRIPTOR(KERNEL_CODE_SEGMENT, isr_39, 0);
|
||||
idt[40] = MAKE_IDT_DESCRIPTOR(KERNEL_CODE_SEGMENT, isr_40, 0);
|
||||
idt[41] = MAKE_IDT_DESCRIPTOR(KERNEL_CODE_SEGMENT, isr_41, 0);
|
||||
idt[42] = MAKE_IDT_DESCRIPTOR(KERNEL_CODE_SEGMENT, isr_42, 0);
|
||||
idt[43] = MAKE_IDT_DESCRIPTOR(KERNEL_CODE_SEGMENT, isr_43, 0);
|
||||
idt[44] = MAKE_IDT_DESCRIPTOR(KERNEL_CODE_SEGMENT, isr_44, 0);
|
||||
idt[45] = MAKE_IDT_DESCRIPTOR(KERNEL_CODE_SEGMENT, isr_45, 0);
|
||||
idt[46] = MAKE_IDT_DESCRIPTOR(KERNEL_CODE_SEGMENT, isr_46, 0);
|
||||
idt[47] = MAKE_IDT_DESCRIPTOR(KERNEL_CODE_SEGMENT, isr_47, 0);
|
||||
idt[48] = MAKE_IDT_DESCRIPTOR(KERNEL_CODE_SEGMENT, isr_48, 0);
|
||||
idt[49] = MAKE_IDT_DESCRIPTOR(KERNEL_CODE_SEGMENT, isr_49, 0);
|
||||
idtr.base = idt_phys;
|
||||
idtr.limit = 49 * sizeof(idt[0]) - 1;
|
||||
__asm__ __volatile__ ("lidt (idtr)" : : : "memory");
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
|
||||
#ifndef INTERRUPTS_H
|
||||
#define INTERRUPTS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void isr(u8_t int_num, int_stack_t * int_stack);
|
||||
|
||||
extern void isr_0();
|
||||
extern void isr_1();
|
||||
extern void isr_2();
|
||||
extern void isr_3();
|
||||
extern void isr_4();
|
||||
extern void isr_5();
|
||||
extern void isr_6();
|
||||
extern void isr_7();
|
||||
extern void isr_8();
|
||||
extern void isr_9();
|
||||
extern void isr_10();
|
||||
extern void isr_11();
|
||||
extern void isr_12();
|
||||
extern void isr_13();
|
||||
extern void isr_14();
|
||||
extern void isr_15();
|
||||
extern void isr_16();
|
||||
extern void isr_17();
|
||||
extern void isr_18();
|
||||
extern void isr_19();
|
||||
extern void isr_20();
|
||||
extern void isr_21();
|
||||
extern void isr_22();
|
||||
extern void isr_23();
|
||||
extern void isr_24();
|
||||
extern void isr_25();
|
||||
extern void isr_26();
|
||||
extern void isr_27();
|
||||
extern void isr_28();
|
||||
extern void isr_29();
|
||||
extern void isr_30();
|
||||
extern void isr_31();
|
||||
extern void isr_32();
|
||||
extern void isr_33();
|
||||
extern void isr_34();
|
||||
extern void isr_35();
|
||||
extern void isr_36();
|
||||
extern void isr_37();
|
||||
extern void isr_38();
|
||||
extern void isr_39();
|
||||
extern void isr_40();
|
||||
extern void isr_41();
|
||||
extern void isr_42();
|
||||
extern void isr_43();
|
||||
extern void isr_44();
|
||||
extern void isr_45();
|
||||
extern void isr_46();
|
||||
extern void isr_47();
|
||||
extern void isr_48();
|
||||
extern void isr_49();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#define MAKE_IDT_DESCRIPTOR(selector, offset, dpl) \
|
||||
(u64_t) ( ( (((u64_t) offset) & 0xFFFF0000ull) << 32 ) /* offset 31:16 */ \
|
||||
| ( ( (u64_t) 0x1ull) << 47 ) /* present */ \
|
||||
| ( (((u64_t) dpl) & 0x3) << 45 ) /* DPL */ \
|
||||
| ( ( (u64_t) 0xEull) << 40 ) /* TODO: gate? */ \
|
||||
| ( (((u64_t) selector) & 0xFFFFull) << 16 ) /* selector */ \
|
||||
| ( (((u64_t) offset) & 0x0000FFFFull) ) ) /* offset 15:0 */
|
||||
|
||||
void interrupts_bootstrap();
|
||||
|
||||
#define interrupts_enable() __asm__ __volatile__ ("sti");
|
||||
#define interrupts_disable() __asm__ __volatile__ ("cli");
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,56 @@
|
||||
|
||||
; C ISR routine
|
||||
[extern isr]
|
||||
|
||||
|
||||
; Macro for creating a single ISR label
|
||||
; We need to push a junk value on the stack first
|
||||
; if the interrupt number is not 8 or 10-14.
|
||||
; This is to properly align the stack for both exceptions
|
||||
; having and not having error codes.
|
||||
%macro isr_label 1
|
||||
[global isr_%1]
|
||||
isr_%1:
|
||||
%if ( (%1 != 8) && (%1 < 10 || %1 > 14) )
|
||||
push eax ; junk value to take error code stack space
|
||||
%endif
|
||||
pusha ; eax, ecx, edx, ebx, esp, ebp, esi, edi
|
||||
mov al, %1 ; save interrupt number in al
|
||||
%if ($ - isr_common) < 127 ; do a short jump and save 3 bytes if we can
|
||||
jmp short isr_common
|
||||
%else
|
||||
jmp isr_common
|
||||
%endif
|
||||
%endmacro
|
||||
|
||||
|
||||
; The common ISR routine
|
||||
isr_common:
|
||||
push ds
|
||||
push es
|
||||
push fs
|
||||
push gs
|
||||
|
||||
push esp ; pointer to interrupt stack
|
||||
push eax ; interrupt number
|
||||
call isr
|
||||
pop eax ; restore stack pointer (this is shorter
|
||||
pop eax ; than "add esp, 8" and "lea esp, [esp+8]")
|
||||
|
||||
pop gs
|
||||
pop fs
|
||||
pop es
|
||||
pop ds
|
||||
popa ; edi, esi, ebp, <null>, ebx, edx, ecx, eax
|
||||
lea esp, [esp+4] ; bypass error code
|
||||
|
||||
iret
|
||||
|
||||
|
||||
; Loop to create all of our ISR entry points
|
||||
%assign i 0
|
||||
%rep 50
|
||||
isr_label i
|
||||
%assign i i+1
|
||||
%endrep
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
|
||||
#include "kernel.h"
|
||||
#include "multiboot.h"
|
||||
#include "module.h"
|
||||
|
||||
mb_info_t mb_info_block;
|
||||
mb_mmap_t mb_mmap[MAX_MMAP];
|
||||
mb_module_t mb_modules[MAX_MODULES];
|
||||
mb_apm_t mb_apm_table;
|
||||
char mb_cmdline[256];
|
||||
|
||||
/* This function runs in segmented memory - 0xC000_0000 is mapped to 0x0 but 0x0
|
||||
itself is an invalid linear address. Therefore, the multiboot information addresses
|
||||
must be manually adjusted by VIRT_OFFSET to become valid linear addresses. */
|
||||
int k_mbsave(mb_info_t *mbinfo, unsigned int mb_magic)
|
||||
{
|
||||
if (mb_magic != MULTIBOOT_BOOTLOADER_MAGIC)
|
||||
{
|
||||
char *msg = "Bad multiboot magic identifier!";
|
||||
char *dest = (char *) 0xC00B8000;
|
||||
while (*msg)
|
||||
{
|
||||
*dest++ = *msg++;
|
||||
*dest++ = 0x04; //red error message
|
||||
}
|
||||
for (;;) ;
|
||||
}
|
||||
mb_info_block = *mbinfo;
|
||||
if (mb_info_block.flags & MB_BOOTLOADER_COMMAND_LINE)
|
||||
{
|
||||
mb_info_block.cmdline += VIRT_OFFSET;
|
||||
memcpy(mb_cmdline, mb_info_block.cmdline, 256);
|
||||
mb_cmdline[255] = 0;
|
||||
}
|
||||
if (mb_info_block.flags & MB_BOOTLOADER_MODS)
|
||||
{
|
||||
mb_info_block.mods_addr += VIRT_OFFSET;
|
||||
int i;
|
||||
for (i = 0; i < mb_info_block.mods_count && i < MAX_MODULES; i++)
|
||||
{
|
||||
mb_modules[i] = ((mb_module_t *)mb_info_block.mods_addr)[i];
|
||||
}
|
||||
}
|
||||
if (mb_info_block.flags & MB_BOOTLOADER_MMAP)
|
||||
{
|
||||
mb_info_block.mmap_addr += VIRT_OFFSET - 4; //-4 to get to size field, not base_addr_low field
|
||||
mb_mmap_t *mmap = (mb_mmap_t *)mb_info_block.mmap_addr;
|
||||
int i, sz = 0;
|
||||
for (i = 0; sz < mb_info_block.mmap_length && i < MAX_MMAP; i++)
|
||||
{
|
||||
sz += mmap->size;
|
||||
mb_mmap[i] = *mmap;
|
||||
mmap = (mb_mmap_t *)(((u32_t) mmap) + mmap->size);
|
||||
}
|
||||
}
|
||||
if (mb_info_block.flags & MB_BOOTLOADER_APM)
|
||||
{
|
||||
mb_info_block.apm_table += VIRT_OFFSET;
|
||||
mb_apm_table = *(mb_apm_t *)mb_info_block.apm_table;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void k_init()
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
(*(char*)0xC00B8000)++;
|
||||
}
|
||||
}
|
||||
|
||||
void isr()
|
||||
{
|
||||
for (;;) ;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
|
||||
include $(HOS_TOPLEVEL)/subdir.mak
|
||||
@@ -0,0 +1,317 @@
|
||||
|
||||
#include "hos_types.h"
|
||||
#include "hos_defines.h"
|
||||
#include "kio.h"
|
||||
#include "string.h"
|
||||
#include "portio.h"
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdarg.h> /* va_*() */
|
||||
|
||||
static void fmt_d2a(char * buf, int val);
|
||||
static void fmt_u2a(char * buf, unsigned int val);
|
||||
static void fmt_ll2a(char * buf, long long val);
|
||||
static void fmt_ull2a(char * buf, unsigned long long val);
|
||||
static void fmt_x2a(char * buf, unsigned int val);
|
||||
static void fmt_xl2a(char * buf, unsigned long long val);
|
||||
static void fmt_o2a(char * buf, unsigned int val);
|
||||
|
||||
static int cursor_x, cursor_y;
|
||||
|
||||
static void writeCursorPosition(int x, int y)
|
||||
{
|
||||
u16_t pos = 80 * y + x;
|
||||
outportb(0x3D4, 0x0E);
|
||||
outportb(0x3D5, pos >> 8);
|
||||
outportb(0x3D4, 0x0F);
|
||||
outportb(0x3D5, pos);
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
|
||||
void kio_bootstrap()
|
||||
{
|
||||
cursor_x = 0;
|
||||
cursor_y = 9;
|
||||
writeCursorPosition(cursor_x, cursor_y);
|
||||
}
|
||||
|
||||
void kprintf(const char * fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
|
||||
kvprintf(fmt, args);
|
||||
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void kvprintf(const char * fmt, va_list args)
|
||||
{
|
||||
char tmpbuf[25];
|
||||
for ( ; *fmt; fmt++)
|
||||
{
|
||||
if (*fmt == '%')
|
||||
{
|
||||
fmt++;
|
||||
if (*fmt)
|
||||
{
|
||||
int width = 0;
|
||||
char pad_char = ' ';
|
||||
bool pad_right = false;
|
||||
if (*fmt == '0')
|
||||
{
|
||||
pad_char = '0';
|
||||
fmt++;
|
||||
}
|
||||
else if (*fmt == '-')
|
||||
{
|
||||
pad_right = true;
|
||||
fmt++;
|
||||
}
|
||||
for ( ; '0' <= *fmt && *fmt <= '9'; fmt++)
|
||||
{
|
||||
if (width == 0)
|
||||
{
|
||||
width = *fmt - '0';
|
||||
}
|
||||
else
|
||||
{
|
||||
width *= 10;
|
||||
width += *fmt - '0';
|
||||
}
|
||||
}
|
||||
switch (*fmt)
|
||||
{
|
||||
case 'c':
|
||||
kputc(va_arg(args, int));
|
||||
break;
|
||||
case 'd':
|
||||
fmt_d2a(tmpbuf, va_arg(args, int));
|
||||
kputs_pad(tmpbuf, width, pad_char, pad_right);
|
||||
break;
|
||||
case 'l':
|
||||
fmt_ll2a(tmpbuf, va_arg(args, long long));
|
||||
kputs_pad(tmpbuf, width, pad_char, pad_right);
|
||||
break;
|
||||
case 'L':
|
||||
fmt_ull2a(tmpbuf, va_arg(args, unsigned long long));
|
||||
kputs_pad(tmpbuf, width, pad_char, pad_right);
|
||||
break;
|
||||
case 'o':
|
||||
fmt_o2a(tmpbuf, va_arg(args, unsigned int));
|
||||
kputs_pad(tmpbuf, width, pad_char, pad_right);
|
||||
break;
|
||||
case 's':
|
||||
kputs_pad(va_arg(args, char *),
|
||||
width, pad_char, pad_right);
|
||||
break;
|
||||
case 'u':
|
||||
fmt_u2a(tmpbuf, va_arg(args, unsigned int));
|
||||
kputs_pad(tmpbuf, width, pad_char, pad_right);
|
||||
break;
|
||||
case 'x':
|
||||
fmt_x2a(tmpbuf, va_arg(args, unsigned int));
|
||||
kputs_pad(tmpbuf, width, pad_char, pad_right);
|
||||
break;
|
||||
case 'X':
|
||||
fmt_xl2a(tmpbuf, va_arg(args, unsigned long long));
|
||||
kputs_pad(tmpbuf, width, pad_char, pad_right);
|
||||
break;
|
||||
case '%':
|
||||
kputc('%');
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
kputc(*fmt);
|
||||
}
|
||||
if (!*fmt)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void kputc(char c)
|
||||
{
|
||||
u16_t * console_memory = (u16_t *) CONSOLE_MEMORY;
|
||||
console_memory += 80 * cursor_y + cursor_x;
|
||||
switch (c)
|
||||
{
|
||||
case '\t':
|
||||
{
|
||||
int to_advance = 8 - (cursor_x & 0x3);
|
||||
while (to_advance--)
|
||||
{
|
||||
*console_memory++ = 0x0720;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case '\n':
|
||||
cursor_x = 0;
|
||||
cursor_y++;
|
||||
break;
|
||||
default:
|
||||
*console_memory = 0x0700 | (c & 0xFF);
|
||||
cursor_x++;
|
||||
break;
|
||||
}
|
||||
if (cursor_x >= 80)
|
||||
{
|
||||
cursor_x = 0;
|
||||
cursor_y++;
|
||||
}
|
||||
if (cursor_y >= 25)
|
||||
{
|
||||
memcpy((u8_t *) CONSOLE_MEMORY,
|
||||
(u8_t *) (CONSOLE_MEMORY + 80 * 2),
|
||||
2 * 80 * 24);
|
||||
memsetw((u16_t *) (CONSOLE_MEMORY + 2 * 80 * 24), 0x0720, 80);
|
||||
cursor_y = 24;
|
||||
}
|
||||
writeCursorPosition(cursor_x, cursor_y);
|
||||
}
|
||||
|
||||
void kputs(const char * s)
|
||||
{
|
||||
while (*s)
|
||||
{
|
||||
kputc(*s);
|
||||
s++;
|
||||
}
|
||||
}
|
||||
|
||||
void kputs_pad(const char * s, int width, char pad_char, bool pad_right)
|
||||
{
|
||||
int len = strlen(s);
|
||||
if (pad_right)
|
||||
{
|
||||
kputs(s);
|
||||
}
|
||||
int num_pad_chars = width - len;
|
||||
for (int i = 0; i < num_pad_chars; i++)
|
||||
{
|
||||
kputc(pad_char);
|
||||
}
|
||||
if (!pad_right)
|
||||
{
|
||||
kputs(s);
|
||||
}
|
||||
}
|
||||
|
||||
} /* extern "C" */
|
||||
|
||||
static void fmt_d2a(char * buf, int val)
|
||||
{
|
||||
if (val < 0)
|
||||
{
|
||||
*buf++ = '-';
|
||||
val = -val;
|
||||
}
|
||||
fmt_u2a(buf, (unsigned int) val);
|
||||
}
|
||||
|
||||
static void fmt_u2a(char * buf, unsigned int val)
|
||||
{
|
||||
bool printing = false;
|
||||
for (unsigned int div = 1000000000; div >= 1; div /= 10)
|
||||
{
|
||||
unsigned int n = val / div;
|
||||
if (n || div == 1)
|
||||
{
|
||||
printing = true;
|
||||
}
|
||||
if (printing)
|
||||
{
|
||||
*buf++ = '0' + n;
|
||||
}
|
||||
val -= n * div;
|
||||
}
|
||||
*buf = '\0';
|
||||
}
|
||||
|
||||
static void fmt_ll2a(char * buf, long long val)
|
||||
{
|
||||
if (val < 0)
|
||||
{
|
||||
*buf++ = '-';
|
||||
val = -val;
|
||||
}
|
||||
fmt_ull2a(buf, (unsigned long long) val);
|
||||
}
|
||||
|
||||
static void fmt_ull2a(char * buf, unsigned long long val)
|
||||
{
|
||||
bool printing = false;
|
||||
for (unsigned long long div = 10000000000000000000ull; div >= 1; div /= 10)
|
||||
{
|
||||
unsigned long long n = val / div;
|
||||
if (n || div == 1)
|
||||
{
|
||||
printing = true;
|
||||
}
|
||||
if (printing)
|
||||
{
|
||||
*buf++ = '0' + n;
|
||||
}
|
||||
val -= n * div;
|
||||
}
|
||||
*buf = '\0';
|
||||
}
|
||||
|
||||
static void fmt_x2a(char * buf, unsigned int val)
|
||||
{
|
||||
bool printing = false;
|
||||
for (int s = 28; s >= 0; s -= 4)
|
||||
{
|
||||
unsigned int n = (val >> s) & 0xF;
|
||||
if (n || s == 0)
|
||||
{
|
||||
printing = true;
|
||||
}
|
||||
if (printing)
|
||||
{
|
||||
*buf++ = "0123456789abcdef"[n];
|
||||
}
|
||||
}
|
||||
*buf = '\0';
|
||||
}
|
||||
|
||||
static void fmt_xl2a(char * buf, unsigned long long val)
|
||||
{
|
||||
bool printing = false;
|
||||
for (int s = 60; s >= 0; s -= 4)
|
||||
{
|
||||
unsigned int n = (val >> s) & 0xF;
|
||||
if (n || s == 0)
|
||||
{
|
||||
printing = true;
|
||||
}
|
||||
if (printing)
|
||||
{
|
||||
*buf++ = "0123456789abcdef"[n];
|
||||
}
|
||||
}
|
||||
*buf = '\0';
|
||||
}
|
||||
|
||||
static void fmt_o2a(char * buf, unsigned int val)
|
||||
{
|
||||
bool printing = false;
|
||||
for (int s = 30; s >= 0; s -= 3)
|
||||
{
|
||||
unsigned int n = (val >> s) & 0x7;
|
||||
if (n || s == 0)
|
||||
{
|
||||
printing = true;
|
||||
}
|
||||
if (printing)
|
||||
{
|
||||
*buf++ = "01234567"[n];
|
||||
}
|
||||
}
|
||||
*buf = '\0';
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
|
||||
#ifndef KIO_H
|
||||
#define KIO_H
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void kio_bootstrap();
|
||||
|
||||
void kprintf(const char * fmt, ...);
|
||||
|
||||
void kvprintf(const char * fmt, va_list args);
|
||||
|
||||
void kputc(char c);
|
||||
|
||||
void kputs(const char * s);
|
||||
|
||||
void kputs_pad(const char * s, int width, char pad_char, bool pad_right);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,73 @@
|
||||
|
||||
#include "string.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
void strcpy(char * dst, const char * src)
|
||||
{
|
||||
while (*src)
|
||||
{
|
||||
*dst++ = *src++;
|
||||
}
|
||||
*dst = '\0';
|
||||
}
|
||||
|
||||
u32_t strlen(const char * s)
|
||||
{
|
||||
u32_t len = 0;
|
||||
while (*s++)
|
||||
{
|
||||
len++;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
void memcpy(u8_t * dst, u8_t * src, u32_t size)
|
||||
{
|
||||
for (u32_t n = 0; n < size; n++)
|
||||
{
|
||||
*dst++ = *src++;
|
||||
}
|
||||
}
|
||||
|
||||
void memcpyw(u16_t * dst, u16_t * src, u32_t size)
|
||||
{
|
||||
for (u32_t n = 0; n < size; n++)
|
||||
{
|
||||
*dst++ = *src++;
|
||||
}
|
||||
}
|
||||
|
||||
void memcpyd(u32_t * dst, u32_t * src, u32_t size)
|
||||
{
|
||||
for (u32_t n = 0; n < size; n++)
|
||||
{
|
||||
*dst++ = *src++;
|
||||
}
|
||||
}
|
||||
|
||||
void memset(u8_t * dst, u8_t val, u32_t size)
|
||||
{
|
||||
for (u32_t n = 0; n < size; n++)
|
||||
{
|
||||
*dst++ = val;
|
||||
}
|
||||
}
|
||||
|
||||
void memsetw(u16_t * dst, u16_t val, u32_t size)
|
||||
{
|
||||
for (u32_t n = 0; n < size; n++)
|
||||
{
|
||||
*dst++ = val;
|
||||
}
|
||||
}
|
||||
|
||||
void memsetd(u32_t * dst, u32_t val, u32_t size)
|
||||
{
|
||||
for (u32_t n = 0; n < size; n++)
|
||||
{
|
||||
*dst++ = val;
|
||||
}
|
||||
}
|
||||
|
||||
} /* extern "C" */
|
||||
@@ -0,0 +1,27 @@
|
||||
|
||||
#ifndef STRING_H
|
||||
#define STRING_H
|
||||
|
||||
#include "hos_defines.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void strcpy(char * dst, const char * src);
|
||||
|
||||
u32_t strlen(const char * s);
|
||||
|
||||
void memcpy(u8_t * dst, u8_t * src, u32_t size);
|
||||
void memcpyw(u16_t * dst, u16_t * src, u32_t size);
|
||||
void memcpyd(u32_t * dst, u32_t * src, u32_t size);
|
||||
|
||||
void memset(u8_t * dst, u8_t val, u32_t size);
|
||||
void memsetw(u16_t * dst, u16_t val, u32_t size);
|
||||
void memsetd(u32_t * dst, u32_t val, u32_t size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
+34
-26
@@ -1,26 +1,34 @@
|
||||
OUTPUT_FORMAT("binary")
|
||||
ENTRY(_start)
|
||||
SECTIONS
|
||||
{
|
||||
.text 0xC0108000 : {
|
||||
code = .; _code = .; __code = .;
|
||||
*(.text)
|
||||
. = ALIGN(4096);
|
||||
}
|
||||
.data : {
|
||||
data = .; _data = .; __data = .;
|
||||
*(.data)
|
||||
/* . = ALIGN(4096); */
|
||||
}
|
||||
.rodata : {
|
||||
rodata = .; _rodata = .; __rodata = .;
|
||||
*(.rodata)
|
||||
. = ALIGN(4096);
|
||||
}
|
||||
.bss : {
|
||||
bss = .; _bss = .; __bss = .;
|
||||
*(.bss)
|
||||
. = ALIGN(4096);
|
||||
}
|
||||
end = .; _end = .; __end = .;
|
||||
}
|
||||
OUTPUT_FORMAT(elf32-i386)
|
||||
ENTRY(start)
|
||||
virt = 0x00100000;
|
||||
phys = 0x00100000;
|
||||
SECTIONS
|
||||
{
|
||||
.text virt : AT(phys) {
|
||||
code = .; _code = .; __code = .;
|
||||
*(.multiboot_header*)
|
||||
*(.text*)
|
||||
*(.gnu.linkonce*)
|
||||
. = ALIGN(4096);
|
||||
}
|
||||
.rodata : {
|
||||
*(.rodata*)
|
||||
. = ALIGN(4096);
|
||||
}
|
||||
.other : {
|
||||
*(.eh_*)
|
||||
*(.rel*)
|
||||
. = ALIGN(4096);
|
||||
}
|
||||
.data : {
|
||||
data = .; _data = .; __data = .;
|
||||
*(.data*)
|
||||
. = ALIGN(4096);
|
||||
}
|
||||
.bss : {
|
||||
bss = .; _bss = .; __bss = .;
|
||||
*(.bss*)
|
||||
. = ALIGN(4096);
|
||||
}
|
||||
end = .; _end = .; __end = .;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
|
||||
include $(HOS_TOPLEVEL)/subdir.mak
|
||||
+405
@@ -0,0 +1,405 @@
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "mm.h"
|
||||
#include "stack.h"
|
||||
#include "boot/k_early_panic.h"
|
||||
#include "lang/string.h"
|
||||
#include "lang/kio.h"
|
||||
#include "sys/cpu.h"
|
||||
|
||||
#define MM_MAX_MMAP_ENTRIES 64
|
||||
|
||||
/* mmap management */
|
||||
static mm_mem_range_t mm_mmap_entries[MM_MAX_MMAP_ENTRIES];
|
||||
static int mm_mmap_num_entries = 0;
|
||||
|
||||
/* free/total page statistics */
|
||||
static int mm_num_free_pages = 0;
|
||||
static int mm_num_total_pages = 0;
|
||||
|
||||
gdtr_t mm_gdtr;
|
||||
static u64_t * mm_gdt; /* NOT mapped into virtual address space */
|
||||
static u32_t mm_heap_base; /* virtual address of start of heap */
|
||||
static pagedirectory_t * early_page_directory_ptr;
|
||||
|
||||
/* physical addresses of page allocation pages to map in before the heap */
|
||||
static u32_t page_alloc_page_numbers[1025]; /* supports 4GB physical memory */
|
||||
static int last_page_alloc_page = -1; /* index of last valid page alloc page */
|
||||
static int page_alloc_page_index = -1;
|
||||
static mm_page_alloc_page_t * page_alloc_pages;
|
||||
static int page_alloc_pages_index = -1;
|
||||
|
||||
/**************************************************************************
|
||||
* Internal Functions *
|
||||
*************************************************************************/
|
||||
static void record_phys_page(u32_t base_address);
|
||||
|
||||
/**************************************************************************
|
||||
* Compile-time tests *
|
||||
*************************************************************************/
|
||||
static void build_tests()
|
||||
{
|
||||
/* check that a mm_page_alloc_page_t fits exactly in a page */
|
||||
BUILD_BUG_ON(sizeof(mm_page_alloc_page_t) != PAGE_SIZE);
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
* This function is run in segmented memory before paging is in effect. *
|
||||
* Record an mmap entry from the bootloader into our kernel space. *
|
||||
*************************************************************************/
|
||||
void mm_record_mmap_entry(mb_mmap_t * mmap)
|
||||
{
|
||||
if (mm_mmap_num_entries < MM_MAX_MMAP_ENTRIES)
|
||||
{
|
||||
if (mmap->type == MB_MMAP_TYPE_RAM)
|
||||
{
|
||||
mm_mmap_entries[mm_mmap_num_entries].base = mmap->base;
|
||||
mm_mmap_entries[mm_mmap_num_entries].length = mmap->length;
|
||||
mm_mmap_num_entries++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
k_early_panic("Too many mmap_entries!");
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
* This function is run in segmented memory before paging is in effect. *
|
||||
* It is run after the bootloader information has been read, so we can *
|
||||
* overwrite that memory now. *
|
||||
*************************************************************************/
|
||||
void mm_bootstrap()
|
||||
{
|
||||
u32_t max_ram_address = KERNEL_PHYSICAL_ADDRESS + KERNEL_SIZE - 1;
|
||||
|
||||
if (mm_mmap_num_entries < 1)
|
||||
{
|
||||
k_early_panic("No mmap entries read from bootloader!");
|
||||
}
|
||||
|
||||
mm_heap_base = (u32_t) KERNEL_END;
|
||||
page_alloc_pages = (mm_page_alloc_page_t *) mm_heap_base;
|
||||
|
||||
for (int mmap_idx = 0; mmap_idx < mm_mmap_num_entries; mmap_idx++)
|
||||
{
|
||||
u32_t base_address = mm_mmap_entries[mmap_idx].base;
|
||||
u32_t address_limit = base_address + mm_mmap_entries[mmap_idx].length;
|
||||
|
||||
if (base_address & PAGE_LOW_MASK)
|
||||
{
|
||||
/* start of this mmap range is not page-aligned */
|
||||
base_address = (base_address & PAGE_HIGH_MASK) + PAGE_SIZE;
|
||||
}
|
||||
if (address_limit & PAGE_LOW_MASK)
|
||||
{
|
||||
/* end of this mmap range is not page-aligned */
|
||||
address_limit &= PAGE_HIGH_MASK;
|
||||
}
|
||||
|
||||
/* record the highest RAM address found */
|
||||
if ((address_limit - 1) > max_ram_address)
|
||||
{
|
||||
max_ram_address = (address_limit - 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* loop through every page in the mmap range and add
|
||||
* pages into the free page linked list
|
||||
*/
|
||||
for (; base_address < address_limit; base_address += PAGE_SIZE)
|
||||
{
|
||||
/* check to make sure the page doesn't overlap the kernel */
|
||||
if ( base_address + PAGE_SIZE <= KERNEL_PHYSICAL_ADDRESS
|
||||
|| base_address >= KERNEL_PHYSICAL_ADDRESS + KERNEL_SIZE )
|
||||
{
|
||||
record_phys_page(base_address);
|
||||
mm_num_free_pages++;
|
||||
}
|
||||
mm_num_total_pages++;
|
||||
}
|
||||
}
|
||||
|
||||
if (mm_num_free_pages < 10)
|
||||
{
|
||||
k_early_panic("Not enough free pages of RAM!");
|
||||
}
|
||||
|
||||
/* ok, now mm_early_page_alloc() should be functional */
|
||||
|
||||
/* move the heap back to after the page allocation pages */
|
||||
mm_heap_base = (u32_t) &page_alloc_pages[last_page_alloc_page + 1];
|
||||
|
||||
/* ok, now mm_early_vpage_alloc() should be functional */
|
||||
|
||||
/* allocate the page directory */
|
||||
u32_t page_directory_phys = mm_early_page_alloc();
|
||||
early_page_directory_ptr = (pagedirectory_t *)
|
||||
(page_directory_phys + KERNEL_OFFSET);
|
||||
|
||||
/* Clear the page directory */
|
||||
for (unsigned int i = 0; i < NUM_PAGETABLE_ENTRIES; i++)
|
||||
{
|
||||
(*early_page_directory_ptr)[i] = 0;
|
||||
}
|
||||
|
||||
/* ok, now mm_early_map() should be functional */
|
||||
|
||||
/* map in the page directory itself so we can modify it once paging is on */
|
||||
(*early_page_directory_ptr)[PAGE_DIR_SELF_REF_INDEX] =
|
||||
(page_directory_phys) | (0x1 << 1) | (0x1);
|
||||
|
||||
/* map in the physical page allocator pages */
|
||||
for (int i = 0; i <= last_page_alloc_page; i++)
|
||||
{
|
||||
mm_early_map((u32_t) &page_alloc_pages[i],
|
||||
page_alloc_page_numbers[i], 0, 1);
|
||||
}
|
||||
|
||||
/* map the kernel's virtual address space into RAM */
|
||||
for (u32_t page_base = KERNEL_VIRTUAL_ADDRESS;
|
||||
page_base < KERNEL_VIRTUAL_ADDRESS + KERNEL_SIZE;
|
||||
page_base += PAGE_SIZE)
|
||||
{
|
||||
/* map page_base to page_base - KERNEL_OFFSET */
|
||||
mm_early_map(page_base, page_base - KERNEL_OFFSET, 0, 1);
|
||||
}
|
||||
|
||||
/* map console memory */
|
||||
mm_early_map(CONSOLE_MEMORY, CONSOLE_MEMORY, 0, 1);
|
||||
|
||||
/* set up the global descriptor table */
|
||||
u32_t gdt_base = mm_early_page_alloc();
|
||||
mm_gdt = (u64_t *) ((u32_t) gdt_base + (u32_t) KERNEL_OFFSET);
|
||||
mm_gdt[0] = 0x0ull;
|
||||
mm_gdt[1] = MAKE_DESCRIPTOR(0, 0xFFFFF, 1, 0, 1, 1); /* kernel code */
|
||||
mm_gdt[2] = MAKE_DESCRIPTOR(0, 0xFFFFF, 1, 0, 1, 0); /* kernel data */
|
||||
mm_gdtr.limit = 3 * sizeof(mm_gdt[0]) - 1;
|
||||
mm_gdtr.base = gdt_base;
|
||||
|
||||
__asm__ __volatile__ (
|
||||
"lgdt (mm_gdtr);\n"
|
||||
"jmp $0x08, $42f;\n"
|
||||
"42:\n"
|
||||
"mov $0x10, %%cx\n"
|
||||
"mov %%cx, %%ss\n"
|
||||
"mov %%cx, %%ds\n"
|
||||
"mov %%cx, %%es\n"
|
||||
"mov %%cx, %%fs\n"
|
||||
"mov %%cx, %%gs\n"
|
||||
: /* no outputs */
|
||||
: /* no inputs */
|
||||
: "ecx");
|
||||
|
||||
/* set the page directory base register */
|
||||
write_cr3(page_directory_phys);
|
||||
|
||||
/* set up permanent stack before enabling paging */
|
||||
stack_bootstrap();
|
||||
|
||||
/* turn on paging */
|
||||
write_cr0(read_cr0() | (1 << 31));
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
* This function is run in segmented memory before paging is in effect. *
|
||||
* Record a physical page in the page allocation pages. *
|
||||
*************************************************************************/
|
||||
static void record_phys_page(u32_t base_address)
|
||||
{
|
||||
if (page_alloc_page_index < 0)
|
||||
{
|
||||
/* allocate a new page alloc page */
|
||||
last_page_alloc_page++;
|
||||
page_alloc_pages_index++;
|
||||
page_alloc_page_numbers[last_page_alloc_page] = base_address;
|
||||
page_alloc_page_index = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
mm_page_alloc_page_t * current_page_alloc_page =
|
||||
(mm_page_alloc_page_t *)
|
||||
(page_alloc_page_numbers[page_alloc_pages_index] + KERNEL_OFFSET);
|
||||
page_alloc_page_index++;
|
||||
(*current_page_alloc_page)[page_alloc_page_index] = base_address;
|
||||
if (page_alloc_page_index == NUM_PAGETABLE_ENTRIES - 1)
|
||||
{
|
||||
page_alloc_page_index = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
* Map virtual_address to physical_address. *
|
||||
* Both addresses should be page-aligned. *
|
||||
* This 'early' version can be used during segmented bootstrapping *
|
||||
*************************************************************************/
|
||||
int mm_early_map(u32_t virtual_address, u32_t physical_address,
|
||||
u32_t user_mode, u32_t writable)
|
||||
{
|
||||
u32_t directory_index = (virtual_address >> 22) & 0x3FF;
|
||||
u32_t table_index = (virtual_address >> 12) & 0x3FF;
|
||||
|
||||
if ((*early_page_directory_ptr)[directory_index] == 0)
|
||||
{
|
||||
/* allocate a new page table */
|
||||
u32_t page_table_phys = mm_early_page_alloc();
|
||||
if (page_table_phys == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
pagedirectory_entry_t * page_table_virt = (pagedirectory_entry_t *)
|
||||
(page_table_phys + KERNEL_OFFSET);
|
||||
for (unsigned int i = 0; i < NUM_PAGETABLE_ENTRIES; i++)
|
||||
{
|
||||
page_table_virt[i] = 0;
|
||||
}
|
||||
(*early_page_directory_ptr)[directory_index] = page_table_phys
|
||||
| (0x1 << 2) /* PTs can be user mode */
|
||||
| (0x1 << 1) /* writable */
|
||||
| (0x1); /* present */
|
||||
}
|
||||
u32_t page_table_phys =
|
||||
(*early_page_directory_ptr)[directory_index] & PAGE_HIGH_MASK;
|
||||
|
||||
pagedirectory_entry_t * page_table =
|
||||
(pagedirectory_entry_t *) (page_table_phys + KERNEL_OFFSET);
|
||||
|
||||
page_table[table_index] = (physical_address & PAGE_HIGH_MASK)
|
||||
| ((user_mode & 0x1) << 2)
|
||||
| ((writable & 0x1) << 1)
|
||||
| 0x1; /* present */
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
* Map virtual_address to physical_address. *
|
||||
* Both addresses should be page-aligned. *
|
||||
*************************************************************************/
|
||||
int mm_map(u32_t virtual_address, u32_t physical_address,
|
||||
u32_t user_mode, u32_t writable)
|
||||
{
|
||||
u32_t directory_index = (virtual_address >> 22) & 0x3FF;
|
||||
u32_t table_index = (virtual_address >> 12) & 0x3FF;
|
||||
pagedirectory_entry_t * page_dir_entry = (pagedirectory_entry_t *)
|
||||
(PAGE_DIR_SELF_REF2 | (directory_index << 2));
|
||||
|
||||
if (*page_dir_entry == 0)
|
||||
{
|
||||
/* allocate a new page table */
|
||||
u32_t page_table_phys = mm_page_alloc();
|
||||
if (page_table_phys == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
*page_dir_entry = page_table_phys
|
||||
| (0x1 << 2) /* PTs can be user mode */
|
||||
| (0x1 << 1) /* writable */
|
||||
| (0x1); /* present */
|
||||
pagedirectory_entry_t * page_table = (pagedirectory_entry_t *)
|
||||
(PAGE_DIR_SELF_REF | (directory_index << 12));
|
||||
for (unsigned int i = 0; i < NUM_PAGETABLE_ENTRIES; i++)
|
||||
{
|
||||
page_table[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
pagedirectory_entry_t * page_table_entry = (pagedirectory_entry_t *)
|
||||
(PAGE_DIR_SELF_REF | (directory_index << 12) | (table_index << 2));
|
||||
|
||||
*page_table_entry = (physical_address & PAGE_HIGH_MASK)
|
||||
| ((user_mode & 0x1) << 2)
|
||||
| ((writable & 0x1) << 1)
|
||||
| 0x1; /* present */
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
* Returns the physical base address of a page in RAM *
|
||||
* or 0 if no pages were available *
|
||||
* This 'early' version can be used during segmented bootstrapping *
|
||||
*************************************************************************/
|
||||
u32_t mm_early_page_alloc()
|
||||
{
|
||||
u32_t page_address = 0;
|
||||
if (page_alloc_pages_index >= 0)
|
||||
{
|
||||
if (page_alloc_page_index >= 0)
|
||||
{
|
||||
mm_page_alloc_page_t * current_pap = (mm_page_alloc_page_t *)
|
||||
(page_alloc_page_numbers[page_alloc_pages_index]
|
||||
+ KERNEL_OFFSET);
|
||||
page_address = (*current_pap)[page_alloc_page_index];
|
||||
page_alloc_page_index--;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* return the page allocation page itself */
|
||||
page_address = page_alloc_page_numbers[page_alloc_pages_index];
|
||||
page_alloc_pages_index--;
|
||||
page_alloc_page_index = NUM_PAGETABLE_ENTRIES - 1;
|
||||
}
|
||||
mm_num_free_pages--;
|
||||
}
|
||||
return page_address;
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
* Returns the physical base address of a page in RAM *
|
||||
* or 0 if no pages were available *
|
||||
*************************************************************************/
|
||||
u32_t mm_page_alloc()
|
||||
{
|
||||
u32_t page_address = 0;
|
||||
if (page_alloc_pages_index >= 0)
|
||||
{
|
||||
if (page_alloc_page_index >= 0)
|
||||
{
|
||||
page_address =
|
||||
page_alloc_pages[page_alloc_pages_index][page_alloc_page_index];
|
||||
page_alloc_page_index--;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* return the page allocation page itself */
|
||||
page_address = page_alloc_page_numbers[page_alloc_pages_index];
|
||||
page_alloc_pages_index--;
|
||||
page_alloc_page_index = NUM_PAGETABLE_ENTRIES - 1;
|
||||
}
|
||||
mm_num_free_pages--;
|
||||
}
|
||||
return page_address;
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
* This function allocates a virtual page. It should only be called *
|
||||
* during the bootstrap process, before the kernel begins its normal *
|
||||
* operation. It adjusts the heap pointer to push it back beyond any *
|
||||
* bootstrap pages allocated. *
|
||||
*************************************************************************/
|
||||
u32_t mm_early_vpage_alloc()
|
||||
{
|
||||
u32_t vaddress = mm_heap_base;
|
||||
mm_heap_base += PAGE_SIZE;
|
||||
return vaddress;
|
||||
}
|
||||
|
||||
void mm_print_memory_map()
|
||||
{
|
||||
kprintf("Bootloader provided memory map:\n");
|
||||
kprintf(" Base Address Length\n");
|
||||
for (int i = 0; i < mm_mmap_num_entries; i++)
|
||||
{
|
||||
kprintf(" 0x%016X 0x%016X (%l bytes / %l KB / %l MB)\n",
|
||||
mm_mmap_entries[i].base,
|
||||
mm_mmap_entries[i].length,
|
||||
mm_mmap_entries[i].length,
|
||||
mm_mmap_entries[i].length >> 10,
|
||||
mm_mmap_entries[i].length >> 20);
|
||||
}
|
||||
kprintf("Used pages: %d\n", mm_num_total_pages - mm_num_free_pages);
|
||||
kprintf("Free pages: %d\n", mm_num_free_pages);
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
|
||||
#ifndef MM_H
|
||||
#define MM_H MM_H
|
||||
|
||||
#include "hos_types.h"
|
||||
#include "hos_defines.h"
|
||||
#include "multiboot.h"
|
||||
|
||||
#define KERNEL_CODE_SEGMENT 0x08
|
||||
#define KERNEL_DATA_SEGMENT 0x10
|
||||
|
||||
typedef u32_t pagedirectory_entry_t;
|
||||
|
||||
#define NUM_PAGETABLE_ENTRIES (PAGE_SIZE / sizeof(pagedirectory_entry_t))
|
||||
|
||||
#define PAGE_DIR_SELF_REF (0x20000000u - (PAGE_SIZE * NUM_PAGETABLE_ENTRIES))
|
||||
#define PAGE_DIR_SELF_REF_INDEX ((PAGE_DIR_SELF_REF >> 22) & 0x3FF)
|
||||
#define PAGE_DIR_SELF_REF2 (PAGE_DIR_SELF_REF | (PAGE_DIR_SELF_REF_INDEX << 12))
|
||||
|
||||
typedef pagedirectory_entry_t pagedirectory_t[NUM_PAGETABLE_ENTRIES];
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u64_t base;
|
||||
u64_t length;
|
||||
} mm_mem_range_t;
|
||||
|
||||
typedef u32_t mm_page_alloc_page_t[NUM_PAGETABLE_ENTRIES];
|
||||
|
||||
/* http://courses.ece.illinois.edu/ece391/references/descriptors.pdf */
|
||||
/* granularity: 0: limit in bytes; 1: limit in pages */
|
||||
/* dpl: 0: system mode; 3: user mode */
|
||||
/* normal: 0: TSS/LDT/call gate; 1: code/data segment */
|
||||
/* code_seg: 0: data segment; 1: code segment */
|
||||
#define MAKE_DESCRIPTOR(base, limit, granularity, dpl, normal, code_seg) \
|
||||
(u64_t) ( ( (((u64_t) base) & 0xFF000000ull) << 32 ) /* base 31:24 */ \
|
||||
| ( (((u64_t) granularity) & 0x1ull) << 55 ) /* granularity */ \
|
||||
| ( ( (u64_t) 0x1ull) << 54 ) /* 32-bit */ \
|
||||
| ( (((u64_t) limit) & 0xF0000ull) << 32 ) /* limit 19:16 */ \
|
||||
| ( ( (u64_t) 0x1ull) << 47 ) /* present */ \
|
||||
| ( (((u64_t) dpl) & 0x3ull) << 45 ) /* dpl */ \
|
||||
| ( (((u64_t) normal) & 0x1ull) << 44 ) /* normal */ \
|
||||
| ( (((u64_t) code_seg) & 0x1ull) << 43 ) /* code seg */ \
|
||||
| ( ( (u64_t) 0x2ull) << 40 ) /* ? */ \
|
||||
| ( (((u64_t) base) & 0x00FFFFFFull) << 16) /* base 23:00 */ \
|
||||
| ( (((u64_t) limit) & 0x0000FFFFull) ) ) /* limit 15:00 */
|
||||
|
||||
typedef u64_t descriptor_t;
|
||||
|
||||
void mm_record_mmap_entry(mb_mmap_t * mmap);
|
||||
void mm_bootstrap();
|
||||
|
||||
int mm_early_map(u32_t virtual_address, u32_t physical_address,
|
||||
u32_t user_mode, u32_t writable);
|
||||
int mm_map(u32_t virtual_address, u32_t physical_address,
|
||||
u32_t user_mode, u32_t writable);
|
||||
|
||||
u32_t mm_early_page_alloc();
|
||||
u32_t mm_page_alloc();
|
||||
u32_t mm_early_vpage_alloc();
|
||||
|
||||
void mm_print_memory_map();
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
|
||||
#include "stack.h"
|
||||
#include "mm.h"
|
||||
#include "hos_defines.h"
|
||||
|
||||
void stack_bootstrap()
|
||||
{
|
||||
/*
|
||||
* running from our temporary stack while segmentation is enabled,
|
||||
* set up the "permanent" stack for use while paging
|
||||
*/
|
||||
u32_t stack_page_virt = KERNEL_STACK_TOP - PAGE_SIZE;
|
||||
for (int i = 0; i < STACK_INITIAL_SIZE; i++)
|
||||
{
|
||||
u32_t stack_page_phys = mm_early_page_alloc();
|
||||
mm_early_map(stack_page_virt, stack_page_phys, 0, 1);
|
||||
stack_page_virt -= PAGE_SIZE;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
|
||||
#ifndef STACK_H
|
||||
#define STACK_H
|
||||
|
||||
#include "mm/mm.h"
|
||||
|
||||
#define KERNEL_STACK_TOP PAGE_DIR_SELF_REF
|
||||
|
||||
#define STACK_INITIAL_SIZE 2 /* number of initial stack pages */
|
||||
|
||||
void stack_bootstrap();
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,54 @@
|
||||
|
||||
ASMOBJS := $(patsubst %.asm,%.o,$(wildcard *.asm))
|
||||
COBJS := $(patsubst %.c,%.o,$(wildcard *.c))
|
||||
CXXOBJS := $(patsubst %.cc,%.o,$(wildcard *.cc))
|
||||
CDEPS := $(COBJS:.o=.dep)
|
||||
CXXDEPS := $(CXXOBJS:.o=.dep)
|
||||
DEPS := $(CDEPS) $(CXXDEPS)
|
||||
OUTPUT_FILE := $(SUBDIR)_all.o
|
||||
|
||||
ifdef SUBDIRS
|
||||
SUBDIRS_clean := $(SUBDIRS:%=%.clean)
|
||||
endif
|
||||
|
||||
all: $(OUTPUT_FILE)
|
||||
|
||||
$(OUTPUT_FILE): $(ASMOBJS) $(COBJS) $(CXXOBJS) $(SUBDIRS)
|
||||
$(LD) -r -o $@ $(ASMOBJS) $(COBJS) $(CXXOBJS) $(foreach subdir,$(SUBDIRS),$(subdir)/$(subdir)_all.o)
|
||||
|
||||
%.o: %.asm
|
||||
$(NASM) -f elf -o $@ -l $<.lst $<
|
||||
|
||||
%.o: %.c
|
||||
$(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $<
|
||||
|
||||
%.o: %.cc
|
||||
$(CXX) -c -o $@ $(CPPFLAGS) $(CXXFLAGS) $<
|
||||
|
||||
ifdef SUBDIRS
|
||||
.PHONY: $(SUBDIRS)
|
||||
$(SUBDIRS):
|
||||
$(MAKE) -C $@ SUBDIR=$@
|
||||
endif
|
||||
|
||||
# Make dependency files
|
||||
%.dep: %.c
|
||||
@set -e; rm -f $@; \
|
||||
$(CC) -MM $(CPPFLAGS) $< | sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' > $@
|
||||
|
||||
%.dep: %.cc
|
||||
@set -e; rm -f $@; \
|
||||
$(CXX) -MM $(CPPFLAGS) $< | sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' > $@
|
||||
|
||||
clean: $(SUBDIRS_clean)
|
||||
-rm -f *.o *.dep *.lst *~
|
||||
|
||||
ifdef SUBDIRS
|
||||
%.clean:
|
||||
$(MAKE) -C $* clean clean=1
|
||||
endif
|
||||
|
||||
# Include dependency files
|
||||
ifndef clean
|
||||
-include $(DEPS)
|
||||
endif
|
||||
@@ -0,0 +1,2 @@
|
||||
|
||||
include $(HOS_TOPLEVEL)/subdir.mak
|
||||
@@ -0,0 +1,40 @@
|
||||
|
||||
#ifndef CPU_H
|
||||
#define CPU_H
|
||||
|
||||
#include "hos_types.h"
|
||||
|
||||
static u32_t read_cr0() __attribute__ ((unused));
|
||||
static u32_t read_cr0()
|
||||
{
|
||||
u32_t val;
|
||||
__asm__ __volatile__ ("movl %%cr0, %0" : "=r" (val));
|
||||
return val;
|
||||
}
|
||||
|
||||
static u32_t read_cr2() __attribute__ ((unused));
|
||||
static u32_t read_cr2()
|
||||
{
|
||||
u32_t val;
|
||||
__asm__ __volatile__ ("movl %%cr2, %0" : "=r" (val));
|
||||
return val;
|
||||
}
|
||||
|
||||
static u32_t read_cr3() __attribute__ ((unused));
|
||||
static u32_t read_cr3()
|
||||
{
|
||||
u32_t val;
|
||||
__asm__ __volatile__ ("movl %%cr3, %0" : "=r" (val));
|
||||
return val;
|
||||
}
|
||||
|
||||
#define write_cr0(val) \
|
||||
__asm__ __volatile__ ("movl %0, %%cr0" : : "r" (val));
|
||||
|
||||
#define write_cr3(val) \
|
||||
__asm__ __volatile__ ("movl %0, %%cr3" : : "r" (val));
|
||||
|
||||
#define write_esp(val) \
|
||||
__asm__ __volatile__ ("movl %0, %%esp" : : "r" (val));
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,29 @@
|
||||
|
||||
#include "pic.h"
|
||||
#include "portio.h"
|
||||
|
||||
/*
|
||||
* Re-maps the Programmable Interrupr Controllers
|
||||
* so IRQ0->pic1 base address, IRG8->pic2 base address
|
||||
*/
|
||||
void pic_remap(u8_t base1, u8_t base2)
|
||||
{
|
||||
u8_t a1, a2;
|
||||
|
||||
a1 = inportb(PIC1_DATA); /* 0x21 */
|
||||
a2 = inportb(PIC2_DATA); /* 0xA1 */
|
||||
|
||||
outportb(PIC1_COMMAND, ICW1_INIT+ICW1_ICW4); /* 0x20, 0x10+0x01 00010001b */
|
||||
outportb(PIC2_COMMAND, ICW1_INIT+ICW1_ICW4); /* 0xA0, 0x10+0x01 00010001b */
|
||||
outportb(PIC1_DATA, base1); /* 0x21, pic1 */
|
||||
outportb(PIC2_DATA, base2); /* 0xA1, pic2 */
|
||||
outportb(PIC1_DATA, 4); /* 0x21, 0x04 00000100b */
|
||||
outportb(PIC2_DATA, 2); /* 0xA1, 0x02 00000010b */
|
||||
outportb(PIC1_DATA, ICW4_8086); /* 0x21, 0x01 00000001b */
|
||||
outportb(PIC2_DATA, ICW4_8086); /* 0xA1, 0x01 00000001b */
|
||||
|
||||
outportb(PIC1_DATA, a1); /* 0x21 */
|
||||
outportb(PIC2_DATA, a2); /* 0xA1 */
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
|
||||
#ifndef PIC_H
|
||||
#define PIC_H
|
||||
|
||||
#include "hos_types.h"
|
||||
#include "portio.h"
|
||||
|
||||
#define PIC1 0x20
|
||||
#define PIC2 0xA0
|
||||
#define PIC1_COMMAND PIC1
|
||||
#define PIC1_DATA (PIC1+1)
|
||||
#define PIC2_COMMAND PIC2
|
||||
#define PIC2_DATA (PIC2+1)
|
||||
#define PIC_EOI 0x20
|
||||
|
||||
#define ICW1_ICW4 0x01 /* ICW4 (not) needed */
|
||||
#define ICW1_SINGLE 0x02 /* Single (cascade) mode */
|
||||
#define ICW1_INTERVAL4 0x04 /* Call address interval 4 (8) */
|
||||
#define ICW1_LEVEL 0x08 /* Level triggered (edge) mode */
|
||||
#define ICW1_INIT 0x10 /* Initialization - required! */
|
||||
|
||||
#define ICW4_8086 0x01 /* 8086/88 (MCS-80/85) mode */
|
||||
#define ICW4_AUTO 0x02 /* Auto (normal) EOI */
|
||||
#define ICW4_BUF_SLAVE 0x08 /* Buffered mode/slave */
|
||||
#define ICW4_BUF_MASTER 0x0C /* Buffered mode/master */
|
||||
#define ICW4_SFNM 0x10 /* Special fully nested (not) */
|
||||
|
||||
void pic_remap(u8_t base1, u8_t base2);
|
||||
|
||||
/* Masks interrupts on first Programmable Interrupt Controller */
|
||||
#define pic_mask1(mask) outportb(PIC1_DATA, mask) /* 0x21, maskfield *OCW1* */
|
||||
|
||||
/* Masks interrupts on second Programmable Interrupt Controller */
|
||||
#define pic_mask2(mask) outportb(PIC2_DATA, mask) /* 0xA1, maskfield *OCW1* */
|
||||
|
||||
/* Signals an End Of Interrupt signal to the first PIC */
|
||||
#define pic_eoi() outportb(0x20, 0x20)
|
||||
|
||||
/* Signals an End Of Interrupt signal to both the second and first PIC unit */
|
||||
static inline void pic_eoi2()
|
||||
{
|
||||
outportb(0xA0, 0x20);
|
||||
outportb(0x20, 0x20);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,12 @@
|
||||
|
||||
#include "timer.h"
|
||||
#include "portio.h"
|
||||
|
||||
void timer_init(u32_t freq)
|
||||
{
|
||||
/* how many ticks the PIT must wait before issuing an interrupt */
|
||||
u32_t wait = 1193180 / freq;
|
||||
outportb(0x43, 0x34);
|
||||
outportb(0x40, wait); /* LSB */
|
||||
outportb(0x40, wait >> 8); /* MSB */
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
|
||||
#ifndef TIMER_H
|
||||
#define TIMER_H
|
||||
|
||||
#include "hos_types.h"
|
||||
|
||||
void timer_init(u32_t freq);
|
||||
|
||||
#endif
|
||||
@@ -1,9 +0,0 @@
|
||||
|
||||
timeout 10
|
||||
default 0
|
||||
|
||||
title HOS 0.15
|
||||
root (fd0)
|
||||
kernel /kernel.bin
|
||||
|
||||
|
||||
Whitespace-only changes.
Whitespace-only changes.
Executable
+100
@@ -0,0 +1,100 @@
|
||||
#!/bin/bash -x
|
||||
|
||||
BINUTILS_VERSION=${BINUTILS_VERSION:-"2.20"}
|
||||
GCC_VERSION=${GCC_VERSION:-"4.4.2"}
|
||||
TARGET=${TARGET:-"i586-elf"}
|
||||
PREFIX=${PREFIX:-"$HOME/local/$TARGET"}
|
||||
GNUFTP=ftp://ftp.gnu.org/gnu
|
||||
export PATH=$PREFIX/bin:$PATH
|
||||
|
||||
mkdir -p build-binutils build-gcc
|
||||
|
||||
if [ ! -f "binutils-$BINUTILS_VERSION.tar.bz2" ]; then
|
||||
wget "$GNUFTP/binutils/binutils-$BINUTILS_VERSION.tar.bz2"
|
||||
if [ $? != 0 ]; then
|
||||
echo "Error downloading binutils"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ ! -f "gcc-$GCC_VERSION.tar.bz2" ]; then
|
||||
wget "$GNUFTP/gcc/gcc-$GCC_VERSION/gcc-$GCC_VERSION.tar.bz2"
|
||||
if [ $? != 0 ]; then
|
||||
echo "Error downloading gcc"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ ! -d "binutils-$BINUTILS_VERSION" ]; then
|
||||
tar xvjf "binutils-$BINUTILS_VERSION.tar.bz2"
|
||||
if [ $? != 0 ]; then
|
||||
echo "Error extracting binutils"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ ! -d "gcc-$GCC_VERSION" ]; then
|
||||
tar xvjf "gcc-$GCC_VERSION.tar.bz2"
|
||||
if [ $? != 0 ]; then
|
||||
echo "Error extracting gcc"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
# build binutils
|
||||
dum=`which $TARGET-ar`
|
||||
if [ $? != 0 ]; then
|
||||
pushd build-binutils
|
||||
../binutils-$BINUTILS_VERSION/configure --target=$TARGET --prefix=$PREFIX --disable-nls
|
||||
if [ $? != 0 ]; then
|
||||
echo "Error configuring binutils"
|
||||
exit 1
|
||||
fi
|
||||
make all
|
||||
if [ $? != 0 ]; then
|
||||
echo "Error building binutils"
|
||||
exit 1
|
||||
fi
|
||||
make install
|
||||
if [ $? != 0 ]; then
|
||||
echo "Error installing binutils"
|
||||
exit 1
|
||||
fi
|
||||
popd
|
||||
fi
|
||||
|
||||
|
||||
# build gcc
|
||||
dum=`which $TARGET-gcc`
|
||||
if [ $? != 0 ]; then
|
||||
pushd build-gcc
|
||||
../gcc-$GCC_VERSION/configure --target=$TARGET --prefix=$PREFIX --disable-nls --enable-languages=c,c++ --without-headers
|
||||
if [ $? != 0 ]; then
|
||||
echo "Error configuring gcc"
|
||||
exit 1
|
||||
fi
|
||||
make all-gcc
|
||||
if [ $? != 0 ]; then
|
||||
echo "Error building gcc"
|
||||
exit 1
|
||||
fi
|
||||
make install-gcc
|
||||
if [ $? != 0 ]; then
|
||||
echo "Error installing gcc"
|
||||
exit 1
|
||||
fi
|
||||
make all-target-libgcc
|
||||
if [ $? != 0 ]; then
|
||||
echo "Error building libgcc"
|
||||
exit 1
|
||||
fi
|
||||
make install-target-libgcc
|
||||
if [ $? != 0 ]; then
|
||||
echo "Error installing libgcc"
|
||||
exit 1
|
||||
fi
|
||||
popd
|
||||
fi
|
||||
|
||||
exit 0
|
||||
Reference in new issue
Block a user