210 Commits
Author SHA1 Message Date
josh f51426f73f fixed memory barrier bug in IDT initialization -- kernel still crashing when interrupts enabled but i think the memory management initialization is correct
git-svn-id: svn://anubis/hos/trunk@102 5b3e749e-e535-0410-8002-a9bb6afbdfca
2010-02-01 05:24:40 +00:00
josh 4b688a3ce0 fixed bug that mapping PAGE_DIR_SELF_REF would incorrectly allocate a new physical page
git-svn-id: svn://anubis/hos/trunk@101 5b3e749e-e535-0410-8002-a9bb6afbdfca
2010-02-01 05:04:39 +00:00
josh 563758b1bd added PAGE_DIR_SELF_REF2 to fix bug in page directory self-referencing
git-svn-id: svn://anubis/hos/trunk@100 5b3e749e-e535-0410-8002-a9bb6afbdfca
2010-02-01 04:21:29 +00:00
josh ae5dc7df6f in the middle of clearing page tables allocated during mm_map() and mm_early_map()
git-svn-id: svn://anubis/hos/trunk@99 5b3e749e-e535-0410-8002-a9bb6afbdfca
2010-02-01 01:47:19 +00:00
josh d41ffbbedc added mm_early_vpage_alloc(); kernel still crashing...
git-svn-id: svn://anubis/hos/trunk@98 5b3e749e-e535-0410-8002-a9bb6afbdfca
2010-01-28 04:22:02 +00:00
josh 5ac343a2e8 fixed mm bug, now crashing because IDT isn't mapped via paging
git-svn-id: svn://anubis/hos/trunk@97 5b3e749e-e535-0410-8002-a9bb6afbdfca
2010-01-27 05:25:05 +00:00
josh 1027b8c346 compiling again after updating mm_early_map() and mm_map() for new page allocation scheme
git-svn-id: svn://anubis/hos/trunk@96 5b3e749e-e535-0410-8002-a9bb6afbdfca
2010-01-27 05:06:12 +00:00
josh 08491bace9 still reworking physical page allocator
git-svn-id: svn://anubis/hos/trunk@95 5b3e749e-e535-0410-8002-a9bb6afbdfca
2010-01-26 05:25:46 +00:00
josh 96ba9fabb1 reworking memory management... again
git-svn-id: svn://anubis/hos/trunk@94 5b3e749e-e535-0410-8002-a9bb6afbdfca
2010-01-25 23:03:23 +00:00
josh 24485b8143 fixed line endings on text files
git-svn-id: svn://anubis/hos/trunk@93 5b3e749e-e535-0410-8002-a9bb6afbdfca
2010-01-25 16:04:08 +00:00
josh ca82cc32ac cleaned up a few page allocation page issues, still crashing
git-svn-id: svn://anubis/hos/trunk@92 5b3e749e-e535-0410-8002-a9bb6afbdfca
2010-01-25 15:59:27 +00:00
josh 4816102139 kernel compiling with new page allocation mechanism but crashing
git-svn-id: svn://anubis/hos/trunk@91 5b3e749e-e535-0410-8002-a9bb6afbdfca
2010-01-25 05:56:40 +00:00
josh 0bc304328d kernel now keeping track of total/free number of physical pages instead of free/used
git-svn-id: svn://anubis/hos/trunk@90 5b3e749e-e535-0410-8002-a9bb6afbdfca
2010-01-22 20:51:34 +00:00
josh dccecb054b fixed BUILD_BUG_ON() to work in C++
git-svn-id: svn://anubis/hos/trunk@89 5b3e749e-e535-0410-8002-a9bb6afbdfca
2010-01-22 20:48:41 +00:00
josh 0c78e21e14 added STACK_INITIAL_SIZE to control the number of initial stack pages; added BUILD_BUG_ON() macro to catch compile-time errors
git-svn-id: svn://anubis/hos/trunk@88 5b3e749e-e535-0410-8002-a9bb6afbdfca
2010-01-22 19:35:43 +00:00
josh 53407d7b59 rearranged slightly
git-svn-id: svn://anubis/hos/trunk@87 5b3e749e-e535-0410-8002-a9bb6afbdfca
2010-01-22 18:19:20 +00:00
josh cdea1602d5 added bochs target to Makefile
git-svn-id: svn://anubis/hos/trunk@86 5b3e749e-e535-0410-8002-a9bb6afbdfca
2010-01-22 18:19:17 +00:00
josh b6bebfd9b4 removed debug print
git-svn-id: svn://anubis/hos/trunk@85 5b3e749e-e535-0410-8002-a9bb6afbdfca
2010-01-14 15:54:16 +00:00
josh 1be6e37961 thanks to bug found by Nick - fixed mmap traversal and size calculation
git-svn-id: svn://anubis/hos/trunk@84 5b3e749e-e535-0410-8002-a9bb6afbdfca
2010-01-14 15:43:49 +00:00
josh 85c5a26631 removed erroneous offset by four when calculating address of mmap structure from bootloader
git-svn-id: svn://anubis/hos/trunk@83 5b3e749e-e535-0410-8002-a9bb6afbdfca
2010-01-14 04:23:26 +00:00
josh eb2dd3b1ad updated start symbol comment
git-svn-id: svn://anubis/hos/trunk@82 5b3e749e-e535-0410-8002-a9bb6afbdfca
2010-01-07 19:14:34 +00:00
josh 6cd78f195f changed kernel stack top to 0x40000000 (1GB) virtual
git-svn-id: svn://anubis/hos/trunk@81 5b3e749e-e535-0410-8002-a9bb6afbdfca
2010-01-07 15:56:53 +00:00
josh e4701b8d96 merged in removing-assembly branch to do more in C
git-svn-id: svn://anubis/hos/trunk@80 5b3e749e-e535-0410-8002-a9bb6afbdfca
2010-01-07 15:38:15 +00:00
josh 76ac4f88a4 set virtual offset to 0x0, kernel now runs in qemu / VirtualBox
git-svn-id: svn://anubis/hos/trunk@73 5b3e749e-e535-0410-8002-a9bb6afbdfca
2010-01-06 05:37:04 +00:00
josh f6e71b9891 minor Makefile improvements
git-svn-id: svn://anubis/hos/trunk@72 5b3e749e-e535-0410-8002-a9bb6afbdfca
2010-01-06 05:04:59 +00:00
josh cf7287d368 removed multiboot kludge; using ELF kernel with different virtual and load addresses
git-svn-id: svn://anubis/hos/trunk@71 5b3e749e-e535-0410-8002-a9bb6afbdfca
2010-01-06 05:02:32 +00:00
josh 44c6bac2af added util folder with build script for i586-elf target cross-compiler
git-svn-id: svn://anubis/hos/trunk@70 5b3e749e-e535-0410-8002-a9bb6afbdfca
2010-01-02 02:10:20 +00:00
josh bc7064e92a got interrupts working, added sys/{pic,timer,cpu} modules, ready to work on multitasking
git-svn-id: svn://anubis/hos/trunk@69 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-07-29 22:30:52 +00:00
josh 2c5a5d7093 moved gdtr_t definition from mm.h to hos_types.h
git-svn-id: svn://anubis/hos/trunk@68 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-07-24 17:05:11 +00:00
josh ddd8c9fd71 split mm_map() and mm_page_alloc() into regular and "early" versions (mm_early_map() and mm_early_page_alloc()); removed mm_use_virtual_offset flag
git-svn-id: svn://anubis/hos/trunk@67 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-07-24 14:51:23 +00:00
josh d7be0159c9 created /kernel/isr subdir, moved isr.asm from boot to isr module, added interrupts.cc for isr() main function and isr_bootstrap() routine
git-svn-id: svn://anubis/hos/trunk@66 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-07-24 14:19:31 +00:00
josh d352afd079 added int_stack_t type in hos_types.h for interrupt stack access
git-svn-id: svn://anubis/hos/trunk@65 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-07-24 14:02:11 +00:00
josh 1105e6e203 optimized isr.asm a bit
git-svn-id: svn://anubis/hos/trunk@64 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-07-24 13:50:29 +00:00
josh 339eef5976 build process generating assembly list files for .asm sources; ignoring .lst files in /kernel/boot
git-svn-id: svn://anubis/hos/trunk@63 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-07-23 22:03:57 +00:00
josh 6a75fdfc10 Added isr.asm with 50 isr_%d labels defined, ready to call isr()
git-svn-id: svn://anubis/hos/trunk@62 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-07-23 22:02:11 +00:00
josh 2f810cc2ec Reduced grub timeout in menu.lst
git-svn-id: svn://anubis/hos/trunk@61 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-07-22 21:00:18 +00:00
josh 63289deade updated include/portio.h to not use gcc-specific "statement blocks" but instead have inportX() be static inline functions. Verified that the compiler does in fact inline them
git-svn-id: svn://anubis/hos/trunk@60 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-07-20 19:21:20 +00:00
josh e70b1a5213 removed special cases for formatting of lowest signed values due to Corrin' rationale; fixed formatting routines to handle formatting "0" values
git-svn-id: svn://anubis/hos/trunk@59 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-07-20 19:10:54 +00:00
josh c21caccb1f printing memory map, used pages, and free pages on boot
git-svn-id: svn://anubis/hos/trunk@58 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-07-16 00:05:44 +00:00
josh fd02ee26e1 added kputs_pad(); implemented padding in kprintf(); put some padding tests in k_main()
git-svn-id: svn://anubis/hos/trunk@57 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-07-15 14:53:58 +00:00
josh ecd74fe35b starting kio change
git-svn-id: svn://anubis/hos/trunk@56 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-07-15 02:47:46 +00:00
josh 08af04897c added include/portio.h; using it to update cursor position in kputc()
git-svn-id: svn://anubis/hos/trunk@55 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-07-14 20:37:10 +00:00
josh 1dd8250048 moved call to stack_bootstrap() into mm_bootstrap() since stack_bootstrap() relies on calling mm_map() and mm_use_virtual_offset was getting unset at the end of mm_bootstrap(); calling k_main() now works!
git-svn-id: svn://anubis/hos/trunk@54 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-07-14 16:08:06 +00:00
josh 118021a0f6 added Makefile commands to build a binary and an ELF kernel and do disassemble the ELF version
git-svn-id: svn://anubis/hos/trunk@53 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-07-14 13:50:29 +00:00
josh bf9c7d74eb added mm/stack module; initializing "permanent" stack for kernel use while paging, crashing when calling k_main() though...
git-svn-id: svn://anubis/hos/trunk@52 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-07-14 13:31:08 +00:00
josh cf2d28f5ce added k_main.cc, need to set up a stack before calling k_main()
git-svn-id: svn://anubis/hos/trunk@51 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-07-14 03:34:16 +00:00
josh 594625b0fa changed lgdt instruction to load from linear address instead of physical address for [mm_gdtr]
git-svn-id: svn://anubis/hos/trunk@50 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-07-14 00:26:40 +00:00
josh df719b4281 added code to reset segmentation and enable paging; added fmt_xl2a() in kio; added debug prints in k_bootstrap() since kernel is crashing when trying to enable paging
git-svn-id: svn://anubis/hos/trunk@49 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-07-13 22:58:48 +00:00
josh 0fb590a407 changed kio routines to accept const char *; added MAKE_DESCRIPTOR() macro to mm
git-svn-id: svn://anubis/hos/trunk@48 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-07-13 22:38:53 +00:00
josh 5b9651299e fixed a few formatting and string bugs, kprintf() working when called during bootstrapping!
git-svn-id: svn://anubis/hos/trunk@47 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-07-13 21:54:27 +00:00
josh a4d497544e added memcpy{,w,d}(), memset{,w,d}(); filled in kputc()
git-svn-id: svn://anubis/hos/trunk@46 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-07-13 21:42:18 +00:00
josh 6a69fd06ec filled in a few more formatting routines; linking with libgcc.a to work with 64-bit unsigned integer division/modulus
git-svn-id: svn://anubis/hos/trunk@45 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-07-13 20:08:16 +00:00
josh 6a8c7431ff hos_defines.h should include hos_types.h first
git-svn-id: svn://anubis/hos/trunk@44 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-07-13 17:15:39 +00:00
josh be17cde305 added devices and lang directories, added skeleton kio and string modules
git-svn-id: svn://anubis/hos/trunk@43 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-07-13 15:34:39 +00:00
josh 1aace858da Moved page_directory from an allocated object to a pointer to a run-time allocated page of RAM
git-svn-id: svn://anubis/hos/trunk@42 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-07-06 21:48:04 +00:00
josh 784978b131 boot.asm comments
git-svn-id: svn://anubis/hos/trunk@41 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-07-05 16:38:47 +00:00
josh 54b42c0226 added set_cr3() macro and called it to set the PDBR
git-svn-id: svn://anubis/hos/trunk@40 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-07-04 00:22:18 +00:00
josh e55f2cdfc4 mapping in kernel virtual address space
git-svn-id: svn://anubis/hos/trunk@39 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-07-03 20:48:51 +00:00
josh edb1a6426d minor mm.cc comment changes
git-svn-id: svn://anubis/hos/trunk@38 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-07-02 19:26:52 +00:00
josh f07e34c849 updated link script to pack things better
git-svn-id: svn://anubis/hos/trunk@37 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-07-02 03:43:44 +00:00
josh e907902ca0 changed mm functions to C++ linkage
git-svn-id: svn://anubis/hos/trunk@36 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-07-02 03:35:24 +00:00
josh a8947f8aa3 added mm_map() to map addresses and mm_page_alloc() to allocate physical pages
git-svn-id: svn://anubis/hos/trunk@35 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-07-02 03:28:25 +00:00
josh 2bddc1d428 filled out more of mm_bootstrap() including initializing the free page linked list
git-svn-id: svn://anubis/hos/trunk@34 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-07-02 01:09:09 +00:00
josh bfb4f3bdd0 changed k_bootstrap from C to C++ source file
git-svn-id: svn://anubis/hos/trunk@33 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-07-01 21:17:24 +00:00
josh db192f6d36 added CXXFLAGS to disable rtti and exceptions; added C++ support to header files; moved mm.c to mm.cc to use C++ functionality
git-svn-id: svn://anubis/hos/trunk@32 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-07-01 19:52:18 +00:00
josh 2faa2cc8d6 added mm_bootstrap() skeleton function
git-svn-id: svn://anubis/hos/trunk@31 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-07-01 17:34:52 +00:00
josh 02c2b25ded added DEPS definition in subdir.mak so dependency files are automatically generated again
git-svn-id: svn://anubis/hos/trunk@30 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-07-01 12:39:43 +00:00
josh 39ea3f231b added bootstrap_stack so the temporary stack is not in the same place as the page directory
git-svn-id: svn://anubis/hos/trunk@29 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-07-01 01:53:43 +00:00
josh 981a01ba9b added linker script symbols and address macros to hos_defines.h
git-svn-id: svn://anubis/hos/trunk@28 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-07-01 01:51:02 +00:00
josh 3eea1b4fd3 building in linux with i586-elf cross-compiler as well
git-svn-id: svn://anubis/hos/trunk@27 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-06-30 23:31:30 +00:00
josh be8d6015ff Added mm_record_mmap_entry() and calls to it in k_bootstrap().
git-svn-id: svn://anubis/hos/trunk@26 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-06-30 21:29:44 +00:00
josh 6ea8fe1a27 Added k_bootstrap.c, k_early_panic.[ch]
Calling k_bootstrap() from boot.asm in segmented mode

git-svn-id: svn://anubis/hos/trunk@25 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-06-30 20:12:39 +00:00
josh d4f5a0b244 Added multiboot.h
git-svn-id: svn://anubis/hos/trunk@24 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-06-30 18:17:20 +00:00
josh 1548e7327a added SUBDIRS support to subdir.mak for recursive building
git-svn-id: svn://anubis/hos/trunk@23 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-06-30 17:54:09 +00:00
josh 90e03d4f95 Added include folder with hos_types.h and hos_defines.h
Added mm build subdir with mm.c
Updated subdir.mak to build $(subdir)_all.o instead of $(subdir).o
Updated main Makefile to pass SUBDIR in to subdirectory builds, add $(HOS_TOPLEVEL)/include to compiler include path, and made the linker write a map file
Updated boot.asm to use the page_directory symbol from the .bss section defined in mm.o as its temporary stack area

git-svn-id: svn://anubis/hos/trunk@22 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-06-29 19:55:50 +00:00
josh fb807847bf fixed SUBDIRS_clean definition in Makefile
git-svn-id: svn://anubis/hos/trunk@21 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-06-29 13:40:33 +00:00
josh d8f7e731e1 moved boot.asm into kernel/boot, added kernel/boot/Makefile using new subdir.mak
git-svn-id: svn://anubis/hos/trunk@20 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-06-25 21:57:50 +00:00
josh a5ca4348d9 changing Makefile system a bit, again
git-svn-id: svn://anubis/hos/trunk@19 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-06-25 19:46:49 +00:00
josh 8fe8d78051 realigned assembly a bit
git-svn-id: svn://anubis/hos/trunk@18 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-06-25 19:12:25 +00:00
josh 1b0da72e5a moved PLATFORM and associated definitions from Makefile to kernel/Makefile so the kernel can be built by itself
git-svn-id: svn://anubis/hos/trunk@17 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-06-25 18:03:39 +00:00
josh 8493002072 removed jump at start symbol since the bootloader starts after the multiboot header anyway; added diagnostic characters "a", "b"
git-svn-id: svn://anubis/hos/trunk@16 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-06-25 15:16:01 +00:00
josh 1ba82ac77f added svn:ignore to a few directories; kernel linked to virtual address 0xE000_0000 and running there in segmented mode
git-svn-id: svn://anubis/hos/trunk@15 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-06-25 15:02:46 +00:00
josh 13f467ca47 i guess genisoimage likes to modify iso/boot/grub/stage2_eltorito
git-svn-id: svn://anubis/hos/trunk@14 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-06-25 13:17:48 +00:00
josh 81a56c9fcf build system works using i586-elf cross-compiler in cygwin
git-svn-id: svn://anubis/hos/trunk@13 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-06-25 13:16:22 +00:00
josh 788597b6f4 added linker script
git-svn-id: svn://anubis/hos/trunk@12 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-06-24 21:53:32 +00:00
josh 09fb19df15 little Makefile change
git-svn-id: svn://anubis/hos/trunk@11 5b3e749e-e535-0410-8002-a9bb6afbdfca
2009-06-24 18:30:57 +00:00
josh af529606e9 load address changed to 1MB
git-svn-id: svn://anubis/hos/trunk@7 5b3e749e-e535-0410-8002-a9bb6afbdfca
2007-07-25 03:30:16 +00:00
josh f58228c559 fixed sample boot.asm, changed Makefile target to $(ISO)
git-svn-id: svn://anubis/hos/trunk@6 5b3e749e-e535-0410-8002-a9bb6afbdfca
2007-07-25 03:16:59 +00:00
josh 8f00324b30 bootable with small multiboot kernel
git-svn-id: svn://anubis/hos/trunk@5 5b3e749e-e535-0410-8002-a9bb6afbdfca
2007-07-25 03:00:58 +00:00
josh bdf4ce8ae8 added clean target
git-svn-id: svn://anubis/hos/trunk@4 5b3e749e-e535-0410-8002-a9bb6afbdfca
2007-07-25 01:18:24 +00:00
josh e124ac5b1b Makefiles created, added initial iso directory
git-svn-id: svn://anubis/hos/trunk@3 5b3e749e-e535-0410-8002-a9bb6afbdfca
2007-07-25 01:08:19 +00:00
josh fba9e3ea54 created kernel directory
git-svn-id: svn://anubis/hos/trunk@2 5b3e749e-e535-0410-8002-a9bb6afbdfca
2007-07-23 03:32:19 +00:00
josh 43d1ca0e18 initial creation of trunk directory
git-svn-id: svn://anubis/hos/trunk@1 5b3e749e-e535-0410-8002-a9bb6afbdfca
2007-07-23 03:11:24 +00:00
josh 0aaf5db5ad Import backup from 2006-01-02 2017-07-25 22:23:52 -04:00
josh 89d962e33a Import backup from 2005-12-31 2017-07-25 22:23:52 -04:00
josh 712337c485 Import backup from 2005-12-30 2017-07-25 22:23:52 -04:00
josh 761e3f0483 Import backup from 2005-12-26 2017-07-25 22:23:51 -04:00
josh 98abfc2af0 Import backup from 2005-12-19 2017-07-25 22:23:51 -04:00
josh 677551fba5 Import backup from 2005-11-03 2017-07-25 22:23:51 -04:00
josh 7daa1c5336 Import backup from 2005-11-01 2017-07-25 22:23:51 -04:00
josh 79ca453f66 Import backup from 2005-09-13 2017-07-25 22:23:51 -04:00
josh 0521733e20 Import backup from 2005-09-11 2017-07-25 22:23:51 -04:00
josh 396c5f3452 Import backup from 2005-09-01 2017-07-25 22:23:51 -04:00
josh 9e03bfc8b6 Import backup from 2005-08-30 2017-07-25 22:23:51 -04:00
josh 2b67ff6f49 Import backup from 2005-08-29 2017-07-25 22:23:51 -04:00
josh daa29212d0 Import backup from 2005-08-27 2017-07-25 22:23:50 -04:00
josh 83a5b032f8 Import backup from 2005-08-25 2017-07-25 22:23:50 -04:00
josh 345ef6c9f3 Import backup from 2005-08-18 2017-07-25 22:23:50 -04:00
josh e1682a2fe7 Import backup from 2005-08-17 2017-07-25 22:23:50 -04:00
josh 2cefd9441c Import backup from 2005-06-21 2017-07-25 22:23:50 -04:00
josh da90bcc164 Import backup from 2005-06-20 2017-07-25 22:23:50 -04:00
josh 4689c11cc8 Import backup from 2005-06-13 2017-07-25 22:23:50 -04:00
josh 692cf2fc08 Import backup from 2005-06-02 2017-07-25 22:23:50 -04:00
josh b0132c866e Import backup from 2005-05-12 2017-07-25 22:23:50 -04:00
josh 14792ef954 Import backup from 2005-03-21 2017-07-25 22:23:50 -04:00
josh bb8ff09e3f Import backup from 2005-03-11 2017-07-25 22:23:50 -04:00
josh dfeabc39aa Import backup from 2005-02-23 2017-07-25 22:23:50 -04:00
josh 14148e4d80 Import backup from 2005-02-15 2017-07-25 22:23:49 -04:00
josh 80774c48fe Import backup from 2005-02-07 2017-07-25 22:23:49 -04:00
josh 862b36b37b Import backup from 2005-02-01 2017-07-25 22:23:49 -04:00
josh 4638656aaf Import backup from 2005-01-31 2017-07-25 22:23:49 -04:00
josh 3381041a8f Import backup from 2005-01-26 2017-07-25 22:23:49 -04:00
josh f09ed66826 Import backup from 2005-01-18 2017-07-25 22:23:49 -04:00
josh ba5906c7a3 Import backup from 2005-01-14 2017-07-25 22:23:49 -04:00
josh 05183a3949 Import backup from 2005-01-05 2017-07-25 22:23:49 -04:00
josh d8580a9393 Import backup from 2005-01-04 2017-07-25 22:23:49 -04:00
josh 50285aa33b Import backup from 2005-01-01 2017-07-25 22:23:49 -04:00
josh ee63a84c0e Import backup from 2004-12-31 2017-07-25 22:23:49 -04:00
josh 76a243d894 Import backup from 2004-12-30 2017-07-25 22:23:49 -04:00
josh 6bad3f2b96 Import backup from 2004-12-29 2017-07-25 22:23:49 -04:00
josh 51948ce081 Import backup from 2004-12-24 2017-07-25 22:23:49 -04:00
josh b40a68f581 Import backup from 2004-12-23 2017-07-25 22:23:49 -04:00
josh 55b7429d4e Import backup from 2004-12-22 2017-07-25 22:23:49 -04:00
josh 7b805f2495 Import backup from 2004-12-21 2017-07-25 22:23:48 -04:00
josh 2445034e43 Import backup from 2004-12-20 2017-07-25 22:23:48 -04:00
josh 3c531f3b7b Import backup from 2004-12-17 2017-07-25 22:23:48 -04:00
josh 11cc0c87f3 Import backup from 2004-12-16 2017-07-25 22:23:48 -04:00
josh bad7f79ed1 Import backup from 2004-09-21 2017-07-25 22:23:48 -04:00
josh 78272f6bc3 Import backup from 2004-08-20 2017-07-25 22:23:48 -04:00
josh 396d5015d2 Import backup from 2004-08-19 2017-07-25 22:23:48 -04:00
josh 1bf14ddefa Import backup from 2004-08-17 2017-07-25 22:23:48 -04:00
josh c0dd3b529e Import backup from 2004-08-16 2017-07-25 22:23:48 -04:00
josh 8a8f56decb Import backup from 2004-08-15 2017-07-25 22:23:48 -04:00
josh b9c77827bd Import backup from 2004-08-06 2017-07-25 22:23:48 -04:00
josh cd02211b21 Import backup from 2004-08-03 2017-07-25 22:23:48 -04:00
josh a50c2a1233 Import backup from 2004-08-02 2017-07-25 22:23:48 -04:00
josh 07e8a0f4cf Import backup from 2004-07-31 2017-07-25 22:23:48 -04:00
josh 6d23c76e84 Import backup from 2004-07-29 2017-07-25 22:23:48 -04:00
josh 11da8cb162 Import backup from 2004-07-25 2017-07-25 22:23:48 -04:00
josh 1063a68a21 Import backup from 2004-07-20 2017-07-25 22:23:47 -04:00
josh 286b5e9ae1 Import backup from 2004-07-17 2017-07-25 22:23:47 -04:00
josh d4aadbea38 Import backup from 2004-07-15 2017-07-25 22:23:47 -04:00
josh dfb71cc759 Import backup from 2004-07-12 2017-07-25 22:23:47 -04:00
josh 872d562d6a Import backup from 2004-07-10 2017-07-25 22:23:47 -04:00
josh 0729754659 Import backup from 2004-07-09 2017-07-25 22:23:47 -04:00
josh f3fe4ef3b8 Import backup from 2004-06-16 2017-07-25 22:23:47 -04:00
josh c76725eac3 Import backup from 2004-06-12 2017-07-25 22:23:47 -04:00
josh 9a8d2c29cb Import backup from 2004-06-10 2017-07-25 22:23:47 -04:00
josh b54b8191c4 Import backup from 2004-06-09 2017-07-25 22:23:47 -04:00
josh fdf6b71a91 Import backup from 2004-06-08 2017-07-25 22:23:47 -04:00
josh 802a07ebfe Import backup from 2004-06-07 2017-07-25 22:23:46 -04:00
josh b5ba5b63fe Import backup from 2004-06-03 2017-07-25 22:23:46 -04:00
josh b4aca026d4 Import backup from 2004-06-01 2017-07-25 22:23:46 -04:00
josh 6d941b7b16 Import backup from 2004-05-23 2017-07-25 22:23:46 -04:00
josh a982312d2c Import backup from 2004-05-22 2017-07-25 22:23:46 -04:00
josh 6b6e19effd Import backup from 2004-05-21 2017-07-25 22:23:46 -04:00
josh 38f009f2ca Import backup from 2004-04-05 2017-07-25 22:23:46 -04:00
josh 6236c341dd Import backup from 2004-04-03 2017-07-25 22:23:46 -04:00
josh 7110307896 Import backup from 2004-03-15 2017-07-25 22:23:46 -04:00
josh ab576bf18f Import backup from 2004-03-12 2017-07-25 22:23:46 -04:00
josh 302538b8ff Import backup from 2004-03-10 2017-07-25 22:23:46 -04:00
josh 7f886e44e1 Import backup from 2004-03-09 2017-07-25 22:23:46 -04:00
josh 8d0e6de040 Import backup from 2004-03-08 2017-07-25 22:23:46 -04:00
josh 0b9d7fde22 Import backup from 2004-03-02 2017-07-25 22:23:46 -04:00
josh 48f4046e79 Import backup from 2004-02-13 2017-07-25 22:23:46 -04:00
josh 2cd08dee70 Import backup from 2004-02-11 2017-07-25 22:23:46 -04:00
josh 311b8afc83 Import backup from 2004-01-26 2017-07-25 22:23:46 -04:00
josh 21e3943b5e Import backup from 2004-01-20 2017-07-25 22:23:46 -04:00
josh 10fd7102ca Import backup from 2004-01-18 2017-07-25 22:23:46 -04:00
josh 7de4f94423 Import backup from 2004-01-15 2017-07-25 22:23:46 -04:00
josh 0a546f1467 Import backup from 2004-01-07 2017-07-25 22:23:45 -04:00
josh af6087ecec Import backup from 2004-01-04 2017-07-25 22:23:45 -04:00
josh c613002307 Import backup from 2003-12-31 2017-07-25 22:23:45 -04:00
josh 76398df125 Import backup from 2003-12-30 2017-07-25 22:23:45 -04:00
josh e83408ce83 Import backup from 2003-12-29 2017-07-25 22:23:45 -04:00
josh 715bb9341a Import backup from 2003-12-28 2017-07-25 22:23:45 -04:00
josh e82bf2ecdf Import backup from 2003-12-25 2017-07-25 22:23:45 -04:00
josh 528527a7ed Import backup from 2003-12-23_2 2017-07-25 22:23:45 -04:00
josh 71aaa7a598 Import backup from 2003-12-23 2017-07-25 22:23:45 -04:00
josh 9070a76b18 Import backup from 2003-12-22_2 2017-07-25 22:23:45 -04:00
josh 5048a93ff7 Import backup from 2003-12-22 2017-07-25 22:23:45 -04:00
josh 282b856e24 Import backup from 2003-12-21 2017-07-25 22:23:45 -04:00
josh 3bb1e5fffc Import backup from 2003-12-20 2017-07-25 22:23:45 -04:00
josh 5ccfd0fc74 Import backup from 2003-11-13 2017-07-25 22:23:45 -04:00
josh 70d6bb1eb3 Import backup from 2003-11-12 2017-07-25 22:23:45 -04:00
josh 294b4b0e27 Import backup from 2003-11-11 2017-07-25 22:23:45 -04:00
josh 57980293e6 Import backup from 2003-11-03 2017-07-25 22:23:45 -04:00
josh ba97e8a7f0 Import backup from 2003-10-30 2017-07-25 22:23:45 -04:00
josh 36b025ccb4 Import backup from 2003-10-27 2017-07-25 22:23:45 -04:00
josh aab5ff3c90 Import backup from 2003-10-23 2017-07-25 22:23:45 -04:00
josh 8bf6e65a95 Import backup from 2003-10-16 2017-07-25 22:23:45 -04:00
josh 5da602b162 Import backup from 2003-10-06 2017-07-25 22:23:45 -04:00
josh 7a0351e123 Import backup from 2003-10-03 2017-07-25 22:23:45 -04:00
josh 3dc0fe5e2b Import backup from 2003-09-30 2017-07-25 22:23:45 -04:00
josh 82da40c9f0 Import backup from 2003-09-29 2017-07-25 22:23:45 -04:00
josh 8d5b28f823 Import backup from 2003-09-28 2017-07-25 22:23:45 -04:00
josh 68fd6cad70 Import backup from 2003-09-26 2017-07-25 22:23:45 -04:00
josh c3309d4e5d Import backup from 2003-09-23 2017-07-25 22:23:45 -04:00
josh 06d7cbef47 Import backup from 2003-09-13 2017-07-25 22:23:44 -04:00
josh e8b1abb265 Import backup from 2003-09-12 2017-07-25 22:23:44 -04:00
64 changed files with 2155 additions and 3008 deletions

No files matched your search

-74
View File
@@ -1,74 +0,0 @@
//Functions.c
//05/07/03 Josh Holtrop
//for HOS
inline void outportb(unsigned int port, unsigned char value) // Output a byte to a port
{
asm volatile ("outb %%al,%%dx"::"d" (port), "a" (value));
};
inline void outportw(unsigned int port, unsigned int value) // Output a word to a port
{
asm volatile ("outw %%ax,%%dx"::"d" (port), "a" (value));
};
inline byte inportb(unsigned short port)
{
unsigned char ret_val;
asm volatile("inb %w1,%b0"
: "=a"(ret_val)
: "d"(port));
return ret_val;
};
void enable_ints()
{
asm("sti");
};
void disable_ints()
{
asm("cli");
};
void remap_pics(int pic1, int pic2)
{
byte a1, a2;
a1 = inportb(PIC1_DATA);
a2 = inportb(PIC2_DATA);
outportb(PIC1_COMMAND, ICW1_INIT+ICW1_ICW4);
outportb(PIC2_COMMAND, ICW1_INIT+ICW1_ICW4);
outportb(PIC1_DATA, pic1);
outportb(PIC2_DATA, pic2);
outportb(PIC1_DATA, 4);
outportb(PIC2_DATA, 2);
outportb(PIC1_DATA, ICW4_8086);
outportb(PIC2_DATA, ICW4_8086);
outportb(PIC1_DATA, a1);
outportb(PIC2_DATA, a2);
};
inline void restart()
{
outportb (0x64, 0xfe);
for (;;)
{
}
}
inline void eoi()
{
outportb(0x20, 0x20); //EOI
}
+37
View File
@@ -0,0 +1,37 @@
KERNEL_FILE := hos.gz
MKISOFS := genisoimage
ISO := hos.iso
QEMU := qemu-system-x86_64
BOCHS := bochs
# 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
-rm -f $(ISO) iso/boot/$(KERNEL_FILE)
+52
View 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
-26
View File
@@ -1,26 +0,0 @@
%define VERSION "0.1.2" ;HOS version
%define BOOT_FAT_SEG 0x07E0 ;right after boot sector
%define BOOT_ROOT_SEG 0x0900 ;right after FAT
%define BOOT_KERNEL_SEG 0x0AC0 ;right after ROOT_DIR
%define BOOT_STAGE2_SEG 0x0B00 ;right after KERNEL_SEG
%define BOOT_STAGE2_ADD 0xB000 ;address of stage2 to jump to, org at
%define BOOT_KERNEL_ADD 0x100000 ;final pmode kernel destination - physical
%define BOOT_RD_ADD 0x200000 ;2mb for ram disk
%define BOOT_DATA_SEG 0x9000 ;data gathered by stage2 loader goes here
%define BOOT_HASRD 0x0000 ;1
%define BOOT_VESA 0x0002 ;2 - 0 for console, otherwise VESA mode
%define BOOT_VESA_OEM 0x0004 ;258 - null-terminated OEM identification string
%define BOOT_VESA_VBE 0x0106 ;512 - copy of VESA VBEInfoBlock
%define BOOT_VESA_INFO 0x0306 ;256 - copy of VESA ModeInfoBlock for selected mode
%define BOOT_MEMENTRIES 0x040A ;4 - dword = number of memmap entries
%define BOOT_MEMMAP 0x2000 ;? - memory map information
%define BOOT_DRIVE 0x7C24 ;1 - boot drive
-7
View File
@@ -1,7 +0,0 @@
typedef unsigned int dword;
typedef unsigned short word;
typedef unsigned char byte;
-21
View File
@@ -1,21 +0,0 @@
//functions.h
//05/07/03 Josh Holtrop
//for HOS
inline void outportb(unsigned int port, unsigned char value);
inline void outportw(unsigned int port, unsigned int value);
inline byte inportb(unsigned short port);
void enable_ints();
void disable_ints();
inline void restart();
void remap_pics(int pic1, int pic2);
inline void eoi();
-68
View File
@@ -1,68 +0,0 @@
gdtr:
dw gdt_end-gdt-1
dd GDT
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
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
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
gdt_end:
-86
View File
@@ -1,86 +0,0 @@
idtr:
dw 50*8-1 ;size of idt
dd IDT ;address of idt
%macro isr_label 1
isr_%1:
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
call _isr
pop eax
pop es
pop ds
popa
iret
-530
View File
@@ -1,530 +0,0 @@
%macro jzfar 1
jnz %%skip
jmp %1
%%skip:
%endmacro
[global _writeCursorPosition]
[global _getCursorPosition]
[global _putc]
[global _puts]
[global _printf]
[global _console_scroll]
[global _console_cls]
[global _putHex]
[global _putDec]
[global _putDecu]
;
;void writeCursorPosition(word pos)
;
_writeCursorPosition:
push ebp
mov ebp, esp
push ebx
push edx
mov eax, [ebp+8] ;cursor position in ax
mov bl, al
mov dx, 0x03D4
mov al, 0x0E
out dx, al
inc dx
mov al, ah
out dx, al
dec dx
mov al, 0x0F
out dx, al
inc dx
mov al, bl
out dx, al
pop edx
pop ebx
pop ebp
ret
;
;word getCursorPosition()
;
_getCursorPosition:
push ebx
push edx
xor eax, eax
mov dx, 0x03D4
mov al, 0x0E
out dx, al
inc dx
in al, dx
mov bl, al
dec dx
mov al, 0x0F
out dx, al
inc dx
in al, dx
mov ah, bl
pop edx
pop ebx
ret
;
;int putc(int chr)
;
_putc:
push ebp
mov ebp, esp
push ebx
push ecx
push edx
call _getCursorPosition
mov ebx, eax
mov ecx, ebx
mov eax, [ebp+8] ;al=character
cmp al, 10 ;newline
jz putc_newline
cmp al, 9 ;tab
jz putc_tab
shl ebx, 1
add ebx, 0xb8000
mov ah, 0x07
mov [ebx], ax
mov eax, ecx
inc eax
cmp eax, 2000
jnz putc_writeit2
call _console_scroll
mov eax, 2000-80
putc_writeit2:
push eax
call _writeCursorPosition
add esp, 4
jmp putc_done
putc_newline:
mov eax, ebx ;eax = cursor position
mov ebx, 80
xor edx, edx
div bx ;ax=dx:ax/bx, dx=remainder
mov bx, 80
sub bx, dx
mov eax, ecx
add eax, ebx ;eax = new cursor position
cmp eax, 2000
jnz putc_newline_writeit2
call _console_scroll
mov eax, 2000-80 ;beginning of last row
putc_newline_writeit2:
push eax
call _writeCursorPosition
add esp, 4
jmp putc_done
putc_tab:
mov eax, ebx ;eax = cursor position
mov ebx, 8
div bl ;al=ax/bl, ah=remainder
xor edx, edx
mov dl, ah
mov bx, 8
sub bx, dx
mov eax, ecx
add eax, ebx ;eax = new cursor position
cmp eax, 2000
jnz putc_tab_writeit2
call _console_scroll
mov eax, 2000-80 ;beginning of last row
putc_tab_writeit2:
push eax
call _writeCursorPosition
add esp, 4
putc_done:
pop edx
pop ecx
pop ebx
pop ebp
ret
;
;void printf(char *fmt, ... )
;
_printf:
push ebp
mov ebp, esp
pusha
mov ebx, [ebp+8] ;ebx = in format string
mov esi, ebp
add esi, 12 ;esi = to next variable arg
xor ecx, ecx ;ecx used if we encounter a '%'
printf_loop:
mov al, [ebx]
inc ebx
cmp al, 0
jzfar printf_done
cmp al, '%'
jzfar printf_percent
cmp ecx, 1
jz printf_special
push eax
call _putc
add esp, 4
jmp printf_loop
printf_special:
xor ecx, ecx
cmp al, 'd'
jz printf_decimal
cmp al, 'u'
jz printf_decimalu
cmp al, 'x'
jz printf_hex
cmp al, '%'
jz printf_ppercent
cmp al, 's'
jz printf_string
cmp al, 'c'
jz printf_char
jmp printf_special_done
printf_decimal:
mov eax, [esi]
push eax
call _putDec
add esp, 4
jmp printf_special_done
printf_decimalu:
mov eax, [esi]
push eax
call _putDecu
add esp, 4
jmp printf_special_done
printf_hex:
mov eax, [esi]
push eax
call _putHex
add esp, 4
jmp printf_special_done
printf_ppercent:
push eax
call _putc
add esp, 4
jmp printf_special_done
printf_string:
mov eax, [esi]
push eax
call _puts
add esp, 4
jmp printf_special_done
printf_char:
mov eax, [esi]
push eax
call _putc
add esp, 4
jmp printf_special_done
printf_special_done
add esi, 4 ;point to next extra argument
jmp printf_loop
printf_percent:
mov ecx, 1
jmp printf_loop
printf_done:
popa
pop ebp
ret
;
;void console_scroll()
;
_console_scroll:
pusha
mov esi, 0xb8000+160
mov edi, 0xb8000
mov ecx, 960 ;(2000-80)/2
console_scroll_loop:
lodsd
stosd
loop console_scroll_loop
mov ax, 0x0720
mov ecx, 80
console_scroll_loop2:
stosw
loop console_scroll_loop2
popa
ret
;
;void console_cls()
;
_console_cls:
pusha
mov edi, 0xb8000
mov ax, 0x0720
mov ecx, 2000
console_cls_loop:
stosw
loop console_cls_loop
push dword 0
call _writeCursorPosition
add esp, 4
popa
ret
;
;int putHex(dword number)
;
_putHex:
push ebp
mov ebp, esp
pusha
mov eax, [ebp+8] ;eax = number to print
xor ebx, ebx ;we have not printed a character yet
mov ecx, 8 ;counter for number of characters
putHex_loop:
push eax
push ecx
dec ecx
shl ecx, 2 ;edx=counter*4 (amount to shift by)
shr eax, cl
and eax, 0x0F
cmp cl, 0
jz putHex_notzero ;if number is 0
cmp al, 0
jnz putHex_notzero
cmp bl, 0
jz putHex_loop_end
putHex_notzero:
mov bl, 1
add eax, '0'
cmp eax, '9'
jbe putHex_dontadjust
add eax, 'A'-'9'-1
putHex_dontadjust:
push eax
call _putc
add esp, 4
putHex_loop_end:
pop ecx
pop eax
loop putHex_loop
popa
pop ebp
ret
;
;int puts(char *str)
;
_puts:
push ebp
mov ebp, esp
push esi
push eax
mov esi, [ebp+8] ;esi = to string
puts_loop:
lodsb
cmp al, 0
jz puts_done
push eax
call _putc
add esp, 4
jmp puts_loop
puts_done:
pop eax
pop esi
pop ebp
ret
_putDecu:
push ebp
mov ebp, esp
sub esp, 24
mov DWORD [ebp-4], 1
mov BYTE [ebp-5], 0
L2:
mov edx, DWORD [ebp+8]
mov eax, -858993459
mul edx
mov eax, edx
shr eax, 3
cmp eax, DWORD [ebp-4]
jae L4
jmp L3
L4:
mov eax, DWORD [ebp-4]
mov edx, eax
sal edx, 2
add edx, eax
lea eax, [edx+edx]
mov DWORD [ebp-4], eax
jmp L2
L3:
nop
L5:
cmp DWORD [ebp-4], 1
ja L7
jmp L6
L7:
mov edx, DWORD [ebp+8]
mov eax, edx
mov edx, 0
div DWORD [ebp-4]
mov DWORD [ebp-12], eax
mov al, BYTE [ebp-12]
mov BYTE [ebp-5], al
mov eax, 0
mov al, BYTE [ebp-5]
imul eax, DWORD [ebp-4]
sub DWORD [ebp+8], eax
mov edx, DWORD [ebp-4]
mov eax, -858993459
mul edx
mov eax, edx
shr eax, 3
mov DWORD [ebp-4], eax
lea eax, [ebp-5]
add BYTE [eax], 48
sub esp, 12
mov eax, 0
mov al, BYTE [ebp-5]
push eax
call _putc
add esp, 16
jmp L5
L6:
sub esp, 12
mov al, BYTE [ebp+8]
add eax, 48
and eax, 255
push eax
call _putc
add esp, 16
leave
ret
_putDec:
push ebp
mov ebp, esp
sub esp, 24
cmp DWORD [ebp+8], 0
jns L9
sub esp, 12
push 45
call _putc
add esp, 16
neg DWORD [ebp+8]
L9:
mov DWORD [ebp-4], 1
mov BYTE [ebp-5], 0
L10:
mov eax, DWORD [ebp+8]
cmp eax, DWORD [ebp-4]
jae L12
jmp L11
L12:
mov eax, DWORD [ebp-4]
mov edx, eax
sal edx, 2
add edx, eax
lea eax, [edx+edx]
mov DWORD [ebp-4], eax
jmp L10
L11:
mov edx, DWORD [ebp-4]
mov eax, -858993459
mul edx
mov eax, edx
shr eax, 3
mov DWORD [ebp-4], eax
L13:
cmp DWORD [ebp-4], 1
ja L15
jmp L14
L15:
mov edx, DWORD [ebp+8]
mov eax, edx
mov edx, 0
div DWORD [ebp-4]
mov DWORD [ebp-12], eax
mov al, BYTE [ebp-12]
mov BYTE [ebp-5], al
mov eax, 0
mov al, BYTE [ebp-5]
imul eax, DWORD [ebp-4]
sub DWORD [ebp+8], eax
mov edx, DWORD [ebp-4]
mov eax, -858993459
mul edx
mov eax, edx
shr eax, 3
mov DWORD [ebp-4], eax
lea eax, [ebp-5]
add BYTE [eax], 48
sub esp, 12
mov eax, 0
mov al, BYTE [ebp-5]
push eax
call _putc
add esp, 16
jmp L13
L14:
sub esp, 12
mov al, BYTE [ebp+8]
add eax, 48
and eax, 255
push eax
call _putc
add esp, 16
leave
ret
-18
View File
@@ -1,18 +0,0 @@
#ifndef __HIO_H__
#define __HIO_H__ __HIO_H__
void writeCursorPosition(word pos);
word getCursorPosition();
int putc(byte chr);
int printf(char *fmt, ...);
int puts(char *str);
int putDec(int number);
int putDecu(dword number);
int putHex(dword number);
void console_cls();
void console_scroll();
#endif
+6
View File
@@ -0,0 +1,6 @@
timeout 2
default 0
title HOS
kernel /boot/hos.gz
Binary file not shown.
-45
View File
@@ -1,45 +0,0 @@
//k_defines.h
//03/17/03 Josh Holtrop
#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) */
#define BLUE_TXT 0x01
#define RED_TXT 0x04
#define WHITE_TXT 0x07
#define CYAN_TXT 0x0B
#define YELLOW_TXT 0x0E
#define BRWHITE_TXT 0x0F
#define FREERAM_START 0x268000
typedef unsigned char byte;
typedef unsigned short word;
typedef unsigned int dword;
typedef struct {
dword lowdword;
dword highdword;
} __attribute__((packed)) qword;
-62
View File
@@ -1,62 +0,0 @@
%include "bootdef.inc"
%define GDT 0x140000
%define IDT 0x150000
[global start]
[extern _isr]
[extern _k_init]
bits 32
start:
cli ;if they weren't already off
mov edi, GDT
mov esi, gdt
mov ecx, gdt_end-gdt
copy_gdt:
lodsb
stosb
loop copy_gdt
mov edi, IDT ;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
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, 0x1ffffc ;stack just under 2mb, moves downward
lidt [idtr] ;load idt
call _k_init
hlt ;halt processor when k_init is done
jmp $ ;shouldn't get here...
%include "gdt.inc"
%include "idt.inc"
-96
View File
@@ -1,96 +0,0 @@
//kernel.c
//08/13/03 Josh Holtrop
//Holtrop's Operating System
#define VXR video_mode.XResolution
#define VYR video_mode.YResolution
#include "k_defines.h"
#include "lib/string.h"
#include "lib/io.h"
#include "functions.h"
#include "video.h"
#include "mm.h"
#include "keyboard.h"
void isr(dword num);
void k_init();
#include "keyboard.c"
#include "mm.c"
#include "functions.c"
#include "video.c"
dword timer = 0;
void k_init()
{
remap_pics(0x20, 0x28);
//set timer : 2e9c = 100hz
outportb(0x43, 0x34);
outportb(0x40, 0x9c); //lsb
outportb(0x40, 0x2e); //msb
video_init((ModeInfoBlock *) 0x90306);
mm_init();
enable_ints();
console_cls();
printf("Memory available to OS: %d MB\n (Bytes: %d)", mm_totalmem/0x100000, mm_totalmem);
for (;;)
printf("%c ", kbdWaitKey());
/* pageblock *pb = first_pageblock;
for (;;)
{
if (pb->flags == MM_PB_NP)
break;
printf("\nBase: 0x%x; Limit: 0x%x; Flags: 0x%x, Link: 0x%x", pb->base, pb->length, pb->flags, pb->link);
pb = (pageblock *) pb->link;
} */
}
void isr(dword num)
{
switch(num)
{
case 0x20:
timer++;
(*(byte *)0xb8000)++;
switch(timer)
{
case 150:
video_rectf(VXR*3/11, 0, VXR*4/11, VYR-1, 0x00000088);
break;
case 200:
video_rectf(VXR*7/11, 0, VXR*8/11, VYR-1, 0x00000088);
break;
case 250:
video_rectf(VXR/11, 0, VXR*2/11, VYR*2/5, 0x00000088);
break;
case 300:
video_rectf(VXR/11, VYR*3/5, VXR*2/11, VYR-1, 0x00000088);
break;
case 350:
video_rectf(VXR*5/11, VYR/5, VXR*6/11, VYR*4/5, 0x00000088);
break;
case 400:
video_rectf(VXR*9/11, VYR/5, VXR-1, VYR*2/5, 0x00000088);
break;
case 450:
video_rectf(VXR*8/11, VYR*3/5, VXR*10/11, VYR*4/5, 0x00000088);
break;
}
eoi();
break;
case 0x21:
printf("------------------KEYBOARD ISR--------------------------\n");
isr_keyboard();
break;
}
}
+45
View File
@@ -0,0 +1,45 @@
CROSS_COMPILE := i586-elf-
export LD := $(CROSS_COMPILE)ld
export CC := $(CROSS_COMPILE)gcc
export CXX := $(CROSS_COMPILE)g++
export OBJDUMP := $(CROSS_COMPILE)objdump
export NASM := nasm
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`
SUBDIRS := boot mm lang isr sys
SUBDIRS_clean := $(SUBDIRS:%=%.clean)
.PHONY: all
all: $(KERNEL).gz
$(KERNEL).gz: $(KERNEL)
gzip -c $< > $@
$(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
+2
View File
@@ -0,0 +1,2 @@
include $(HOS_TOPLEVEL)/subdir.mak
+23
View File
@@ -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
+85
View File
@@ -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" */
+17
View File
@@ -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
+18
View File
@@ -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 (;;)
;
}
+15
View File
@@ -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
+28
View File
@@ -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" */
+11
View File
@@ -0,0 +1,11 @@
#ifndef K_MAIN_H
#define K_MAIN_H
extern "C" {
void k_main();
}
#endif
+47
View File
@@ -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
+55
View File
@@ -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
+154
View File
@@ -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
+37
View File
@@ -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
+2
View File
@@ -0,0 +1,2 @@
include $(HOS_TOPLEVEL)/subdir.mak
+110
View File
@@ -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");
}
+79
View File
@@ -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
+56
View File
@@ -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
+2
View File
@@ -0,0 +1,2 @@
include $(HOS_TOPLEVEL)/subdir.mak
+317
View File
@@ -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';
}
+27
View File
@@ -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
+73
View File
@@ -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" */
+27
View File
@@ -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
View File
@@ -0,0 +1,34 @@
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 = .;
}
+2
View File
@@ -0,0 +1,2 @@
include $(HOS_TOPLEVEL)/subdir.mak
+405
View File
@@ -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);
}
+65
View File
@@ -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
+19
View File
@@ -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;
}
}
+13
View File
@@ -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
+54
View File
@@ -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
+2
View File
@@ -0,0 +1,2 @@
include $(HOS_TOPLEVEL)/subdir.mak
+40
View File
@@ -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
+29
View File
@@ -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 */
}
+46
View File
@@ -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
+12
View File
@@ -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 */
}
+9
View File
@@ -0,0 +1,9 @@
#ifndef TIMER_H
#define TIMER_H
#include "hos_types.h"
void timer_init(u32_t freq);
#endif
-249
View File
@@ -1,249 +0,0 @@
//Keyboard.c
// Created: 04/17/03 Josh Holtrop
// Modified: 09/09/03
//for HOS
#define KBD_BUFFER_LENGTH 64
byte kbdFlags = 0;
byte kbdAscii = 0;
byte kbdScan = 0;
dword kbdBuffer[KBD_BUFFER_LENGTH];
byte kbdBufferStart = 0;
byte kbdBufferLen = 0;
byte kbdExt = 0;
byte kbdExt2 = 0;
byte ackReason = 0; //used to record the reason why we would get an acknowledge byte (0xFA)
//nul esc bksp tab lctl lsft rsft lalt caps F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 numScrlNumPad------- unknown---- F11 F12 unknown....
const byte SCAN2ASCII[128] = "\000\0331234567890-=\010\011qwertyuiop[]\n\001asdfghjkl;'`\001\\zxcvbnm,./\001*\001 \001\001\001\001\001\001\001\001\001\001\001\001\001\001\001\001-\001\001\001+\001\001\001\001\001\002\002\002\001\001\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002";
const byte SCAN2ASCIISHIFT[128] = "\000\033!@#$%^&*()_+\010\011QWERTYUIOP{}\n\001ASDFGHJKL:\"~\001|ZXCVBNM<>?\001*\001 \001\001\001\001\001\001\001\001\001\001\001\001\001789-456+1230.\002\002\002\001\001\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002";
//====FUNCTIONS:
void isr_keyboard()
{
kbdScan = inportb(0x60);
byte inState = inportb(0x61);
outportb(0x61, inState|0x80);
outportb(0x61, inState);
printf("IRQ 1: %x\n", kbdScan);
if (kbdScan == 0xFA) //250 //ACKnowledge
{
if (ackReason == 0xED) //reset LEDs
{
outportb(0x64, (kbdFlags & 0x07));
printf("KBD_ACK!");
}
ackReason = 0;
}
if (kbdScan == 224) //extended key
{
kbdExt = 1;
eoi();
return;
}
if (kbdScan == 225)
{
kbdExt2 = 2;
eoi();
return;
}
//====handle control keys::
kbdAscii = 2;
switch (kbdScan) //control keys
{
case KBD_SCAN_LSHIFT:
kbdFlags |= KBD_SHIFT;
kbdAscii = 1;
break;
case KBD_SCAN_RSHIFT:
kbdFlags |= KBD_SHIFT;
kbdAscii = 1;
break;
case KBD_SCAN_LCTRL:
kbdFlags |= KBD_CTRL;
kbdAscii = 1;
break;
case KBD_SCAN_LALT:
kbdFlags |= KBD_ALT;
kbdAscii = 1;
break;
case KBD_SCAN_LSHIFT + KBD_SCAN_RELEASED:
kbdFlags &= (KBD_SHIFT ^ 0xFF);
kbdAscii = 1;
break;
case KBD_SCAN_RSHIFT + KBD_SCAN_RELEASED:
kbdFlags &= (KBD_SHIFT ^ 0xFF);
kbdAscii = 1;
break;
case KBD_SCAN_LCTRL + KBD_SCAN_RELEASED:
kbdFlags &= (KBD_CTRL ^ 0xFF);
kbdAscii = 1;
break;
case KBD_SCAN_LALT + KBD_SCAN_RELEASED:
kbdFlags &= (KBD_ALT ^ 0xFF);
kbdAscii = 1;
break;
case KBD_SCAN_CAPS+KBD_SCAN_RELEASED:
kbdFlags ^= KBD_CAPS;
kbdAscii = 1;
kbd_resetLEDs(); //update LEDs
break;
case KBD_SCAN_SCROLL+KBD_SCAN_RELEASED:
kbdFlags ^= KBD_SCROLL;
kbdAscii = 1;
kbd_resetLEDs(); //update LEDs
break;
case KBD_SCAN_NUM+KBD_SCAN_RELEASED:
kbdFlags ^= KBD_NUM;
kbdAscii = 1;
kbd_resetLEDs(); //update LEDs
break;
}
if (kbdAscii == 1)
{
if (kbdExt > 0)
kbdExt--;
eoi();
return;
}
//====determine ASCII value of key::
if (kbdExt > 0) //extended key, kbdScan holds extended key
{
kbdExt--;
kbdAscii = 1;
switch (kbdScan)
{
case KBD_SCANE_ENTER:
kbdAscii = '\n'; break;
case 53: // '/' character (divide on numpad)
kbdAscii = '/'; break;
}
}
else if (kbdExt2 > 0) //extended key 2
{
kbdExt2--;
// if (kbdScan == 69) // (pause|break)
// kbdAscii = 2; //flag ascii value of 1 means control character (pausebreak)
// else
kbdAscii = 2; //flag ascii value of 2 means ignore key (or unknown value)
}
else //not an extended key
{
// if letter key
if (((kbdScan >= 16) && (kbdScan <= 25)) || ((kbdScan >= 30) && (kbdScan <= 38)) || ((kbdScan >= 44) && (kbdScan <= 50)))
{
// if caps and shift are different (either one pressed, not both)
if (((kbdFlags & KBD_SHIFT) != 0) & ((kbdFlags & KBD_CAPS) != 0))
kbdAscii = SCAN2ASCII[kbdScan & 0x7F];
else if (((kbdFlags & KBD_SHIFT) == 0) & ((kbdFlags & KBD_CAPS) == 0))
kbdAscii = SCAN2ASCII[kbdScan & 0x7F];
else
kbdAscii = SCAN2ASCIISHIFT[kbdScan & 0x7F];
}
// if numpad key
else if ((kbdScan >= 71) && (kbdScan <= 83))
{
// if numlock on
if (kbdFlags & KBD_NUM)
kbdAscii = SCAN2ASCIISHIFT[kbdScan & 0x7F];
else
kbdAscii = SCAN2ASCII[kbdScan & 0x7F];
}
// other key
else
{
if ((kbdFlags & KBD_SHIFT) != 0)
kbdAscii = SCAN2ASCIISHIFT[kbdScan & 0x7F];
else
kbdAscii = SCAN2ASCII[kbdScan & 0x7F];
}
}
//====do something with key::
if ((kbdScan == 83) & ((kbdFlags & KBD_CTRL) != 0) & ((kbdFlags & KBD_ALT) != 0))
{
printf("Initiating reboot.");
restart();
}
if (kbdAscii == 2) //unknown key / ignore key
{
eoi();
return;
}
if (kbdScan < KBD_SCAN_RELEASED) //a key was pressed, save it
{
if (kbdBufferLen >= KBD_BUFFER_LENGTH) //no key slots available
{
eoi();
return;
}
else
{
kbdBuffer[(kbdBufferStart+kbdBufferLen)%KBD_BUFFER_LENGTH] = (dword) ((kbdFlags << 16) | (kbdScan << 8) | kbdAscii);
kbdBufferLen++;
}
}
eoi();
// if (key == 0xFA) //ACKnowledge
// outportb(0x60, 0x3);
};
inline byte switchCase(byte asciiCode)
{
if ((asciiCode >= 'A') & (asciiCode <= 'Z'))
return (asciiCode + ('a' - 'A'));
if ((asciiCode >= 'a') & (asciiCode <= 'z'))
return (asciiCode - ('a' - 'A'));
return asciiCode;
}
dword kbdGetKey()
{
if (kbdBufferLen == 0) //buffer empty
return 0;
dword retVal = kbdBuffer[kbdBufferStart];
printf("S:%d\tE:%d\tR:%x\n", kbdBufferStart, kbdBufferLen, retVal);
kbdBufferStart++;
kbdBufferLen--;
if (kbdBufferStart == KBD_BUFFER_LENGTH)
kbdBufferStart = 0;
return retVal;
}
dword kbdWaitKey()
{
dword retVal = 0;
for (;;)
{
retVal = kbdGetKey();
if (retVal != 0)
{
printf("S:%d\tE:%d\tR:%x\n", kbdBufferStart, kbdBufferLen, retVal);
return retVal;
}
}
}
inline void kbd_resetLEDs()
{
outportb(0x64, 0xED);
//outportb(0x64, (kbdFlags & 0x07));
ackReason = 0xED;
}
-47
View File
@@ -1,47 +0,0 @@
//Keyboard.h
// Created: 04/17/03 Josh Holtrop
// Modified: 05/07/03
//for HOS
#define KBD_SCROLL 0x01
#define KBD_NUM 0x02
#define KBD_CAPS 0x04
#define KBD_SHIFT 0x10
#define KBD_CTRL 0x20
#define KBD_ALT 0x40
#define KBD_SCAN_RELEASED 128
#define KBD_SCAN_LCTRL 29
#define KBD_SCAN_LSHIFT 42
#define KBD_SCAN_RSHIFT 54
#define KBD_SCAN_LALT 56
#define KBD_SCAN_SCROLL 70
#define KBD_SCAN_CAPS 58
#define KBD_SCAN_NUM 69
#define KBD_SCANE_PRINTSCREEN 55
#define KBD_SCANE_INS 82
#define KBD_SCANE_HOME 71
#define KBD_SCANE_PGUP 73
#define KBD_SCANE_DEL 83
#define KBD_SCANE_END 79
#define KBD_SCANE_PGDN 81
#define KBD_SCANE_ENTER 28
#define KBD_SCANE_NULL 42
//====PROTOTYPES:
void isr_keyboard();
inline void kbd_resetLEDs();
inline byte kbd_ascii(dword keycode);
inline byte kbd_scancode(dword keycode);
inline byte kbd_flags(dword keycode);
inline byte switchCase(byte asciiCode);
dword kbdGetKey();
dword kbdWaitKey();
-22
View File
@@ -1,22 +0,0 @@
OUTPUT_FORMAT("binary")
ENTRY(start)
SECTIONS
{
.text 0x100000 : {
code = .; _code = .; __code = .;
*(.text)
. = ALIGN(4096);
}
.data : {
data = .; _data = .; __data = .;
*(.data)
. = ALIGN(4096);
}
.bss :
{
bss = .; _bss = .; __bss = .;
*(.bss)
. = ALIGN(4096);
}
end = .; _end = .; __end = .;
}
-242
View File
@@ -1,242 +0,0 @@
// mm.c
// 09/01/03 Josh Holtrop
// 0x368000 is first available byte (this is right after the kernel @ 1mb and the initrd @ 2mb, 1440kb.
pageblock *first_pageblock = (pageblock *) 0;
dword mm_totalmem = 0x100000; //assume 1mb
void mm_init()
{
dword *memmap_entries = (dword *) 0x9040A;
memmap_entry *maps = (memmap_entry *) 0x92000;
dword a;
for (a=0;a<(*memmap_entries);a++)
{
if (maps[a].attributes == 1) // (1) mem free to OS
{
mm_totalmem += maps[a].limit.lowdword;
if ((maps[a].base.lowdword + maps[a].limit.lowdword) > (FREERAM_START+8192)) //goes past where we start freeram
{
if (maps[a].base.lowdword < FREERAM_START)
{
maps[a].limit.lowdword = maps[a].limit.lowdword - (FREERAM_START - maps[a].base.lowdword);
maps[a].base.lowdword = FREERAM_START; //block at least 4kb, starts >= FREERAM_START
}
if (first_pageblock == 0) //no pageblock page set up yet, so set it up here
{
first_pageblock = (pageblock *) maps[a].base.lowdword ;
maps[a].base.lowdword += 4096;
maps[a].limit.lowdword -= 4096;
mm_init_pageblockpage(first_pageblock);
first_pageblock->base = maps[a].base.lowdword;
first_pageblock->length = maps[a].limit.lowdword / 4096;
first_pageblock->flags = MM_PB_AVAIL;
}
else //first_pageblock already set up, add on segment
{
pageblock *pb = first_pageblock;
for (;;)
{
if (pb->flags == MM_PB_NP)
break;
else
pb++;
}
pb->base = maps[a].base.lowdword;
pb->length = maps[a].limit.lowdword / 4096;
pb->flags = MM_PB_AVAIL;
}
}
}
}
if (first_pageblock == 0)
{
printf("ERROR! NO INITIAL PAGE BLOCK COULD BE CREATED.");
asm("cli");
asm("hlt");
}
}
void mm_init_pageblockpage(pageblock *pbp)
{
pageblock *pb = pbp;
int a;
for (a=0; a<512; a++)
{
pb->base = 0;
pb->length = 0;
pb->flags = MM_PB_NP;
if (a<511)
pb->link = (dword)pb + sizeof(pageblock);
else
pb->link = 0;
pb++;
}
}
void *mm_palloc(dword numpages)
{
pageblock *pb = first_pageblock;
dword freeentries = mm_freeentries();
if (freeentries < 2)
{
if(mm_new_pageblock_page() == 0)
return 0;
}
pageblock *newentry = mm_nextpageblockentry();
for (;;)
{
if ((pb->flags == MM_PB_AVAIL) && (pb->length >= numpages))
break;
if (pb->link == 0)
return 0;
pb = (pageblock *)pb->link;
}
if (pb->length == numpages) //dont need a new entry, just mark this one as used :)
{
pb->flags = MM_PB_USED;
return pb;
}
else //subtract out allocated number of pages from length
{
newentry->base = pb->base;
newentry->length = numpages;
newentry->flags = MM_PB_USED;
pb->base += (numpages * 4096);
pb->length -= numpages;
return (void *)newentry->base;
}
}
dword mm_freeentries()
{
pageblock *pb = first_pageblock;
dword counter = 0;
for (;;)
{
if (pb->flags == MM_PB_NP)
counter++;
if (pb->link == 0)
return counter;
pb = (pageblock *) pb->link;
}
}
pageblock *mm_new_pageblock_page()
{
pageblock *pb = first_pageblock;
for (;;)
{
if ((pb->flags == MM_PB_AVAIL) && (pb->length > 1))
{
pageblock *retval = (pageblock *)pb->base;
pb->base += 4096;
pb->length--;
mm_init_pageblockpage(retval); //zeros out, links new pageblock page
mm_lastpageblockentry()->link = (dword)retval; //set up link to new pageblock page
return retval;
}
pb = (pageblock *) pb->link;
if (pb == 0)
return 0;
}
}
int mm_pfree(void *ptr)
{
pageblock *pb = first_pageblock;
dword tofree = (dword) ptr;
for (;;)
{
if ((pb->base == tofree) && (pb->flags == MM_PB_USED))
{
pb->flags = MM_PB_AVAIL; //found block, mark available / coalesce it
pageblock *pbc = first_pageblock;
for (;;)
{
if (pbc->flags == MM_PB_AVAIL)
{
if ((pbc->base + (pbc->length * 4096)) == pb->base) //pbc ends where pb starts
{
pbc->length += pb->length; //extend pbc's length by pb's length
pb->flags = MM_PB_NP; //mark pb as an unused entry
return 0;
}
if ((pb->base + (pb->length * 4096)) == pbc->base) //pb ends where pb starts
{
pb->length += pbc->length;
pbc->flags = MM_PB_NP;
return 0;
}
}
if (pbc->link == 0) //no entry found to consolidate...
return 0;
pbc = (pageblock *) pbc->link; //next entry to test
}
}
if (pb->link == 0)
return 1;
pb = (pageblock *) pb->link;
}
}
pageblock *mm_lastpageblockentry()
{
pageblock *pb = first_pageblock;
for (;;)
{
if (pb->link == 0)
return pb;
pb = (pageblock *)pb->link;
}
}
pageblock *mm_nextpageblockentry()
{
pageblock *pb = first_pageblock;
for (;;)
{
if (pb->flags == MM_PB_NP)
return pb;
if (pb->link == 0)
return 0;
pb = (pageblock *)pb->link;
}
}
dword mm_freemem()
{
dword amount = 0;
pageblock *pb = first_pageblock;
for (;;)
{
if (pb->flags == MM_PB_AVAIL)
amount += (pb->length)*4096;
if (pb->link == 0)
return amount;
pb = (pageblock *) pb->link;
}
}
-36
View File
@@ -1,36 +0,0 @@
typedef struct {
qword base;
qword limit;
dword attributes;
} __attribute__((packed)) memmap_entry;
typedef struct {
dword base;
dword length; //in pages
dword flags;
dword link;
} __attribute__ ((packed)) pageblock; //16 byte pageblock entry - 512 entries = 1 page
void mm_init();
void mm_init_pageblockpage(pageblock *pbp);
void *mm_palloc(dword numpages);
int mm_pfree(void *ptr);
dword mm_freeentries();
pageblock *mm_new_pageblock_page();
pageblock *mm_lastpageblockentry();
pageblock *mm_nextpageblockentry();
dword mm_freemem();
#define MM_PB_FLAGMASK 0x03 //00000011
#define MM_PB_NP 0x00 //00000000
#define MM_PB_AVAIL 0x01 //00000001
#define MM_PB_USED 0x02 //00000010
-228
View File
@@ -1,228 +0,0 @@
%include "bootdef.inc"
[bits 16]
org 0x7c00
jmp short start
; --------------------------------------------------
; data portion of the "DOS BOOT RECORD"
; ----------------------------------------------------------------------
brINT13Flag DB 90H ; 0002h - 0EH for INT13 AH=42 READ
brOEM DB 'MSDOS5.0' ; 0003h - OEM ID - Windows 95B
brBPS DW 512 ; 000Bh - Bytes per sector
brSPC DB 1 ; 000Dh - Sector per cluster
brSc_b4_fat DW 1 ; 000Eh - Reserved sectors
brFATs DB 2 ; 0010h - FAT copies
brRootEntries DW 0E0H ; 0011h - Root directory entries
brSectorCount DW 2880 ; 0013h - Sectors in volume, < 32MB
brMedia DB 240 ; 0015h - Media descriptor
brSPF DW 9 ; 0016h - Sectors per FAT
brSc_p_trk DW 18 ; 0018h - Sectors per head/track
brHPC DW 2 ; 001Ah - Heads per cylinder
brSc_b4_prt DD 0 ; 001Ch - Hidden sectors
brSectors DD 0 ; 0020h - Total number of sectors
brDrive DB 0 ; 0024h - Physical drive no.
DB 0 ; 0025h - Reserved (FAT32)
DB 29H ; 0026h - Extended boot record sig (FAT32)
brSerialNum DD 404418EAH ; 0027h - Volume serial number
brLabel DB 'HOS 0.1.1 ' ; 002Bh - Volume label
brFSID DB 'FAT12 ' ; 0036h - File System ID
;------------------------------------------------------------------------
start:
jmp 0:jmphere ;ensure that cs=0 and ip=0x7c...
jmphere:
;dl=drive number, save it!
xor ax, ax
mov ds, ax
mov [brDrive], dl
cli
mov ss, ax
mov sp, 0x7Bfe ;right under boot sector
sti
mov ax, 0xb800
mov ds, ax
mov es, ax
xor di, di
mov ax, 0x0700
mov cx, 2000
cls:
stosw
loop cls
enable_a20:
in al, 0x64
test al, 2
jnz enable_a20
mov al, 0xD1
out 0x64, al
ea20_2: in al, 0x64
and ax, byte 2
jnz ea20_2
mov al, 0xDF
out 0x60, al
unreal:
xor ax, ax
mov es, ax
mov ds, ax
lgdt [gdtr] ;load gdt
cli
push es
push ds ;save segment values
mov ebx, cr0
inc bl
mov cr0, ebx ;pmode!
mov ax, KERNEL_DATA
mov es, ax
mov ds, ax ;load segment limits
dec bl
mov cr0, ebx ;back to real mode!
pop ds
pop es ;segments back, with 4gb limits!
sti
;now lets read in the FAT and root directory so we can search for the kernel file...
mov ax, 0x0209 ;FAT1
mov cx, 0x0002
xor dh, dh
mov dl, [brDrive]
mov bx, BOOT_FAT_SEG
mov es, bx
xor bx, bx
int 0x13
mov ax, 0x020E ;root directory
mov cx, 0x0002 ;cyl/sect
mov dh, 0x01 ;head
mov dl, [brDrive] ;drive
mov bx, BOOT_ROOT_SEG
mov es, bx
xor bx, bx
int 0x13
;k now read root directory
mov bx, BOOT_ROOT_SEG
mov ds, bx
xor si, si ;k now ds:si points to beginning of root directory
mov es, si
mov cx, 224 ;max root entries
loop_compare:
mov di, stage2
push cx
push si ;save pointer to root dir entry
mov cx, 11
loop_name:
cmpsb
loopz loop_name
jnz goon ;cx didn't get to zero, bad file
pop si
pop cx
jmp found_file ;good file, ds:si points to start of root directory entry
goon:
pop si
pop cx
add si, 32
loop loop_compare
error:
jmp $ ;halt! no kernel file found!
found_file: ;ds:si points to root dir entry
xor ax, ax
mov gs, ax
mov ax, BOOT_STAGE2_SEG
mov es, ax
mov ax, [ds:si+26]
mov bx, BOOT_FAT_SEG
mov ds, bx ;ds points to beginning of FAT
xor di, di
readstage2_loop:
cmp ax, 0xff7
jg readstage2_done
inc di
push ax
call getCHSfromCluster
mov ax, 0x0201
mov dl, [gs:BOOT_DRIVE]
xor bx, bx
int 0x13
mov bx, es
add bx, 0x0020
mov es, bx
pop ax ;current logical cluster #
mov cx, ax ;cx=logical cluster
mov dx, 3
mul dx
shr ax, 1 ;ax=logical cluster * 3 / 2
mov si, ax
test cl, 1 ;is bit0 set?
jnz odd_cluster
even_cluster:
lodsw
and ax, 0x0fff
jmp got_cluster
odd_cluster:
lodsw
shr ax, 4
got_cluster:
jmp readstage2_loop
readstage2_done:
jmp 0:BOOT_STAGE2_ADD
;------------------------------------------------------
getCHSfromCluster:
;input: ax=lba of sector on floppy (0-2879)
add ax, 31 ;convert logical cluster# to lba#
xor dx, dx ;lba->chs
mov bx, 18
div bx
inc dx
mov cl, dl ;sector# (1-18)
xor dx, dx
mov bx, 2
div bx
mov ch, al ;cylinder# (0-79)
mov dh, dl ;head# (0-1)
ret
;-------------------------------------------------------
gdtr:
dw gdt_end-gdt-1
dd gdt
gdt:
dd 0
dd 0
KERNEL_DATA equ $-gdt
db 0xff ;segment 16 = 4gb data
db 0xff
db 0x00
db 0x00
db 0x00
db 0x92
db 0xcf ;cf
db 0x00
gdt_end:
stage2: db "STAGE2 BIN"
times 510-($-$$) db 0
db 0x55, 0xaa
-920
View File
@@ -1,920 +0,0 @@
%include "bootdef.inc"
%define VESA_MODEINFO_SEG 0x0120
%define VESA_MODELIST_SEG 0x0140
%define GOOD_MODELIST_SEG 0x0160
[bits 16]
org BOOT_STAGE2_ADD
;k now read root directory
mov bx, BOOT_ROOT_SEG
mov ds, bx
xor si, si ;k now ds:si points to beginning of root directory
mov es, si
mov cx, 224 ;max root entries
loop_compare:
mov di, kernel
push cx
push si ;save pointer to root dir entry
mov cx, 11
loop_name:
cmpsb
loopz loop_name
jnz goon ;cx didn't get to zero, bad file
pop si
pop cx
jmp found_file ;good file, ds:si points to start of root directory entry
goon:
pop si
pop cx
loop loop_compare
error:
jmp $ ;halt! no kernel file found!
found_file: ;ds:si points to root dir entry of kernel file
xor ax, ax
mov gs, ax
mov ax, [ds:si+26]
mov bx, BOOT_FAT_SEG
mov ds, bx ;ds points to beginning of FAT
mov edi, BOOT_KERNEL_ADD
readkernel_loop:
cmp ax, 0xff7
jg readkernel_done
push ax
call getCHSfromCluster
mov ax, 0x0201
mov dl, [gs:BOOT_DRIVE]
mov bx, BOOT_KERNEL_SEG
mov es, bx
xor bx, bx
int 0x13
mov cx, 256
xor ax, ax
mov es, ax
mov esi, BOOT_KERNEL_SEG*16
copykernel_loop:
mov ax, [es:esi]
mov [es:edi], ax
inc esi
inc esi
inc edi
inc edi
loop copykernel_loop
pop ax ;current logical cluster #
mov cx, ax ;cx=logical cluster
mov dx, 3
mul dx
shr ax, 1 ;ax=logical cluster * 3 / 2
mov si, ax
test cl, 1 ;is bit0 set?
jnz odd_cluster
even_cluster:
lodsw
and ax, 0x0fff
jmp got_cluster
odd_cluster:
lodsw
shr ax, 4
got_cluster:
jmp readkernel_loop
;------------------------------------------------------
readkernel_done: ;-------------put more real mode init stuff here!
;----ask to load RD from floppy
mov ax, 0xb800
mov es, ax
xor ax, ax
mov ds, ax
xor di, di
mov cx, 2000
mov ax, 0x0700
cls_loop:
stosw
loop cls_loop
mov dx, 0x3d4 ;move cursor off screen...
mov al, 0x0e
out dx, al
inc dx
mov al, 0xff
out dx, al
dec dx
mov al, 0x0f
out dx, al
inc dx
out dx, al
xor di, di
mov si, txt_welcome
mov ah, 0x1f
call puts
mov di, 160
mov si, txt_rd1
mov ah, 7
call puts
mov si, txt_rd2
mov di, 160*2
call puts
mov di, 160*3
mov si, txt_input
call puts
get_rd:
xor ax, ax
int 0x16
cmp al, '1'
jz got_rd
cmp al, '2'
jnz get_rd
got_rd:
stosb
sub al, '1'
push ds
mov bx, BOOT_DATA_SEG ;segment for data to send kernel
mov ds, bx
mov [ds:BOOT_HASRD], al
pop ds ;ds=0
cmp al, 0 ;dont load rd
jz no_rd
mov cx, 80
mov edi, 0xb8000+160*4
filler_loop:
mov word [ds:edi], 0x0400+177
inc edi
inc edi
loop filler_loop
mov cx, 80 ;80 cylinders to read
xor si, si
mov edi, BOOT_RD_ADD ;ram disk address
read_cylinder:
push cx
mov bx, 0x0100
mov es, bx
xor bx, bx
mov ax, 0x0224
mov cx, si
mov ch, cl
mov cl, 1
xor dx, dx
mov dl, [gs:BOOT_DRIVE]
int 0x13
mov ebx, 0xb8000
add bx, si
shl bl, 1
mov word [ds:ebx+160*4], 0x0200+219
push si
mov esi, 0x1000
mov cx, 0x2400
copydisk_loop:
mov ax, [ds:esi]
inc esi
inc esi
mov [ds:edi], ax
inc edi
inc edi
loop copydisk_loop
pop si ;what cylinder# we are on...
inc si
pop cx
loop read_cylinder
;------------------------------------------------------
no_rd:
mov ax, BOOT_DATA_SEG
mov es, ax
mov di, BOOT_MEMMAP ;store memmap info in es:di for kernel
xor edx, edx
mov ax, 0x0100
mov ds, ax
xor ebx, ebx
getmemmap_loop:
push es
push di
push edx
mov ax, 0x0100 ;get memory map
mov es, ax
xor di, di
mov eax, 0x0000E820
mov ecx, 0x00000014
;mov ebx, 0x00000000
mov edx, 0x534D4150 ;'SMAP'
int 0x15
jc getmemmap_carry
cmp eax, 0x534D4150 ;eax should be 'SMAP' on return...
jnz getmemmap_error
cmp ebx, 0
jz getmemmap_done
pop edx ;now, copy memmap entry to es:di on the stack
pop di
pop es
xor si, si
mov cx, 20
getmemmap_copymem_loop:
lodsb
stosb
loop getmemmap_copymem_loop
inc edx
jmp getmemmap_loop
getmemmap_error:
mov ax, 0xb800
mov es, ax
mov di, 160*24
xor ax, ax
mov ds, ax
mov si, txt_memerror
mov ah, 0x04
call puts
hlt
jmp $
getmemmap_carry:
dec edx
getmemmap_done:
pop edx
pop di
pop es
xor si, si
mov cx, 20
getmemmap_done_copymem_loop:
lodsb
stosb
loop getmemmap_done_copymem_loop
inc edx
mov di, BOOT_MEMENTRIES
mov [es:di], edx ;save # of memmap entries for kernel
;on to vesa info...
xor ax, ax
mov gs, ax
mov ds, ax
mov ax, 0xb800
mov es, ax
mov di, 160
mov cx, 2000-80
mov ax, 0x0700
cls_vesa_loop:
stosw
loop cls_vesa_loop
mov si, txt_vesa
mov di, 160*1
mov ah, 7
call puts
push di
mov ax, 0x0100
mov es, ax
xor di, di
mov dword [es:di], "2EBV"
mov ax, 0x4F00
int 0x10
pop di
cmp ax, 0x004F
jz vesa_good
mov si, txt_novesa
mov ax, 0xb800
mov es, ax
mov ah, 7
call puts
mov ax, BOOT_DATA_SEG
mov ds, ax
mov word [ds:BOOT_VESA], 0
jmp vesa_done
vesa_good:
mov ax, 0xb800
mov es, ax
mov ax, 0x0100
mov ds, ax
xor si, si
mov bx, [4]
mov al, bh
call puthex
mov al, '.'
stosb
mov al, 7
stosb
mov al, bl
call puthex
add di, 4
cmp bh, 2
jge vesa_good2
xor ax, ax
mov ds, ax
mov si, txt_vesaold
mov ah, 7
call puts
mov ax, BOOT_DATA_SEG
mov ds, ax
mov word [ds:BOOT_VESA], 0
jmp vesa_done
vesa_good2:
mov ebx, [6] ;something like 0x00000E60
mov edx, [14]
mov si, bx
shr ebx, 16
mov ds, bx ;ds:si points to null-terminated OEM identification string
mov ah, 2
push si
call puts
pop si
mov ax, BOOT_DATA_SEG
mov es, ax
mov di, BOOT_VESA_OEM
vesa_copyoem:
lodsb
stosb
or al, al
jnz vesa_copyoem
mov ax, 0x0100
mov ds, ax
xor si, si
mov di, BOOT_VESA_VBE
mov cx, 512
vesa_copyvbe:
lodsb
stosb
loop vesa_copyvbe
mov si, dx
shr edx, 16
mov ds, dx ;ds:si points to video mode list
mov ax, VESA_MODELIST_SEG
mov es, ax
xor di, di
vesa_copymodes:
lodsw
stosw
cmp ax, 0xffff
jnz vesa_copymodes
mov ax, GOOD_MODELIST_SEG
mov es, ax
xor di, di
mov cx, 256
mov ax, 0xffff
clear_good_mode_list_loop:
stosw
loop clear_good_mode_list_loop
mov ax, VESA_MODELIST_SEG
mov ds, ax
xor si, si ;ds:si points to video mode list where we can edit it :)
mov ax, GOOD_MODELIST_SEG
mov es, ax
xor di, di
xor dx, dx ;dx=what good mode # we are on
vesa_readmodeinfo_loop:
lodsw
cmp ax, 0xffff
jz vesa_endofmodes
push ax ;save mode#
call checkmode
cmp ax, 0
jz vesa_readmodeinfo_good
pop ax
jmp vesa_readmodeinfo_loop
vesa_readmodeinfo_good:
pop ax ;restore mode#
stosw
call vesa_showmodeinfo
inc dx
jmp vesa_readmodeinfo_loop
vesa_endofmodes: ;here we have a list of good modes at GOOD_MODELIST_SEG:0
xor ax, ax
mov ds, ax
mov si, txt_consolemode
mov ax, 0xb800
mov es, ax
mov di, 160*2
mov ah, 7
call puts
mov di, 160*3
mov cx, dx
mov al, 'b'
vesa_displaylabels:
stosb
push ax
mov al, 7
stosb
mov al, '.'
stosb
mov al, 7
stosb
pop ax
inc al
add di, 160-4
loop vesa_displaylabels ;done drawing screen of VESA choices, now ask for one
;valid options are 'a' through (al-1)
mov bl, al
xor ax, ax
mov ds, ax
mov di, 160*24
mov si, txt_input
mov ah, 14
call puts
vesa_getchoice:
xor ax, ax
int 0x16
cmp al, 'a'
jl vesa_getchoice
cmp al, bl
jge vesa_getchoice
stosb
push ax
mov al, 14
stosb
pop ax
xor ah, ah
sub ax, 'a'
cmp ax, 0
jz vesa_consolemode_only
mov cx, ax ;cx holds good mode# (1=first good vesa mode)
dec cx
mov ax, GOOD_MODELIST_SEG
mov ds, ax
shl cx, 1
mov si, cx ;ds:si points to word containing selected mode#
lodsw
mov cx, ax
mov dx, ax ;cx and dx hold mode#
mov ax, VESA_MODEINFO_SEG
mov es, ax
xor di, di
mov ax, 0x4F01
int 0x10
call checkvesa
mov ax, VESA_MODEINFO_SEG
mov ds, ax
xor si, si
mov ax, BOOT_DATA_SEG
mov es, ax
mov di, BOOT_VESA_INFO
mov cx, 256
vesa_copymodeinfo_loop:
lodsb
stosb
loop vesa_copymodeinfo_loop ;store ModeInfoBlock for current
mov [es:BOOT_VESA], dx ;store mode# for kernel
; mov ax, 0xb800
; mov es, ax
; xor di, di
; mov al, dh
; call puthex2
; mov al, dl
; call puthex2
mov bx, dx
or bx, 0x4000 ;set "use LFB" bit of mode#
mov ax, 0x4F02
int 0x10 ;switch to graphics mode!!!
call checkvesa
jmp vesa_done
vesa_consolemode_only:
mov ax, BOOT_DATA_SEG
mov es, ax
mov word [es:BOOT_VESA], 0
jmp vesa_done
;------------------------------------------------------
vesa_showmodeinfo:
pusha
push es
push ds
mov ax, VESA_MODEINFO_SEG
mov ds, ax
xor si, si
mov ax, 0xb800
mov es, ax
mov cx, dx
mov ax, 160
mul dx ;ax=160*mod#
add ax, 160*3+6 ;offset first line of modes and room on left for label
mov di, ax
mov ax, [ds:18]
call console_putDec
add di, 10
mov al, 'x'
call console_putChar
inc di
inc di
mov ax, [ds:20]
call console_putDec
add di, 10
mov al, 'x'
call console_putChar
inc di
inc di
xor ah, ah
mov al, [ds:25]
call console_putDec
add di, 8
mov al, [ds:0]
test al, 0x80
jz vesa_showmodeinfo_done
mov al, 'L'
call console_putChar
mov al, 'F'
call console_putChar
mov al, 'B'
call console_putChar
inc di
inc di
mov ebx, [ds:40]
mov eax, ebx
shr eax, 24
call puthex2
mov eax, ebx
shr eax, 16
call puthex2
mov al, bh
call puthex2
mov al, bl
call puthex2
vesa_showmodeinfo_done:
pop ds
pop es
popa
ret
;------------------------------------------------------
checkmode:
push bx
push cx
push dx
push es
push ds
push di
push si
mov cx, ax ;cx=modenumber
mov ax, VESA_MODEINFO_SEG
mov es, ax
xor di, di
mov ax, 0x4F01
int 0x10
call checkvesa
xor di, di ;es:di -> ModeInfoBlock struc
mov ax, [es:di] ;ModeAttributes
test al, 1 ;mode supported
jz vesa_modenogood
test al, 8 ;color mode
jz vesa_modenogood
test al, 0x10 ;graphics mode
jz vesa_modenogood
test al, 0x80 ;Linear Frame Buffer supported
jz vesa_modenogood
mov al, [es:di+25] ;BitsPerPixel
cmp al, 16
jz vesa_bppok
cmp al, 24
jz vesa_bppok
cmp al, 32
jnz vesa_modenogood
vesa_bppok:
mov ax, [es:di+18] ;XResolution
mov bx, [es:di+20] ;YResolution
cmp ax, 640 ;640x480
jnz res_goon1
cmp bx, 480
jnz vesa_modenogood
jmp vesa_modegood
res_goon1:
cmp ax, 800
jnz res_goon2
cmp bx, 600
jnz vesa_modenogood
jmp vesa_modegood
res_goon2:
cmp ax, 1024
jnz res_goon3
cmp bx, 768
jnz vesa_modenogood
jmp vesa_modegood
res_goon3:
cmp ax, 1280
jnz res_goon4
cmp bx, 1024
jz vesa_modegood
cmp bx, 960
jz vesa_modegood
jmp vesa_modenogood
res_goon4:
cmp ax, 1600
jnz vesa_modenogood
cmp bx, 1200
jnz vesa_modenogood
vesa_modegood:
pop si
pop di
pop ds
pop es
pop dx
pop cx
pop bx
xor ax, ax
ret
vesa_modenogood:
pop si
pop di
pop ds
pop es
pop dx
pop cx
pop bx
mov ax, 0xffff
ret
;------------------------------------------------------
vesa_done:
; xor ax, ax ;wait for keypress...
; int 0x16
jmp go_pm
;------------------------------------------------------
puts:
lodsb
or al, al
jz puts_done
stosb
mov al, ah
stosb
jmp puts
puts_done:
ret
;------------------------------------------------------
checkvesa:
cmp ax, 0x004F
jnz vesaerror
ret
vesaerror:
mov ax, 0xb800
mov es, ax
xor ax, ax
mov ds, ax
mov si, txt_vesaerror
mov di, 160*24
mov ah, 4
call puts
cli
hlt
;-------Function console_putDec
;input:
; AX = number to display
;output:
; number written in decimal to es:di
console_putDec:
pusha
xor dx, dx
xor bh, bh ;no characters written yet
mov cx, 10000
div cx ;ax=quotiont, dx=remainder
add ax, '0'
cmp ax, '0'
je .goon1
call console_putChar
mov bh, 1
.goon1:
mov ax, dx ;load remainder to ax
xor dx, dx
mov cx, 1000
div cx ;ax=quotiont, dx=remainder
add ax, '0'
cmp ax, '0'
je .goon11
call console_putChar
mov bh, 1
jmp .goon2
.goon11:
cmp bh, 0
je .goon2
call console_putChar
.goon2:
mov ax, dx ;load remainder to ax
xor dx, dx
mov cx, 100
div cx ;ax=quotiont, dx=remainder
add ax, '0'
cmp ax, '0'
je .goon21
call console_putChar
mov bh, 1
jmp .goon3
.goon21:
cmp bh, 0
je .goon3
call console_putChar
.goon3:
mov ax, dx ;load remainder to ax
xor dx, dx
mov cx, 10
div cx ;ax=quotiont, dx=remainder
add ax, '0'
cmp ax, '0'
je .goon31
call console_putChar
mov bh, 1
jmp .goon4
.goon31:
cmp bh, 0
je .goon4
call console_putChar
.goon4: ;here dx contains last remainder
mov ax, dx
add ax, '0'
call console_putChar
popa
ret
;------------------------------------------------------
console_putChar:
stosb
mov al, 7
stosb
ret
;------------------------------------------------------
puthex:
;es:di points to video memory
;al holds hex value
push ax
mov ah, al
shr ax, 4
and al, 0x0F
add al, '0'
cmp al, '9'
jle puthex_goon1
add al, 'A'-'9'-1
puthex_goon1:
cmp al, '0'
jz puthex_skipzero
stosb
mov al, 7
stosb
puthex_skipzero:
pop ax
push ax
and al, 0x0F
add al, '0'
cmp al, '9'
jle puthex_goon2
add al, 'A'-'9'-1
puthex_goon2:
stosb
mov al, 7
stosb
pop ax
ret
;------------------------------------------------------
puthex2:
;es:di points to video memory, always displays 2 characters!
;al holds hex value
push ax
mov ah, al
shr ax, 4
and al, 0x0F
add al, '0'
cmp al, '9'
jle puthex2_goon1
add al, 'A'-'9'-1
puthex2_goon1:
stosb
mov al, 7
stosb
pop ax
push ax
and al, 0x0F
add al, '0'
cmp al, '9'
jle puthex2_goon2
add al, 'A'-'9'-1
puthex2_goon2:
stosb
mov al, 7
stosb
pop ax
ret
;------------------------------------------------------
txt_welcome: db " Welcome to HOS v", VERSION, "! ", 0
txt_rd1: db "1. Do not load an initial ram disk", 0
txt_rd2: db "2. Load initial ram disk from floppy", 0
txt_input: db "Enter your selection: ", 0
txt_vesa: db "VESA version: ", 0
txt_vesaerror: db "VESA function call error! Halting system!", 0
txt_novesa: db "VESA not found. Starting in console mode...", 0
txt_vesaold: db "VESA version 2.0 required. Starting in console mode...", 0
txt_consolemode: db "a. Console mode only.", 0
txt_memerror: db "Extended Memory Map information unavailable! Halting system...", 0
;------------------------------------------------------
getCHSfromCluster:
;input: ax=lba of sector on floppy (0-2879)
add ax, 31 ;convert logical cluster# to lba#
xor dx, dx ;lba->chs
mov bx, 18
div bx
inc dx
mov cl, dl ;sector# (1-18)
xor dx, dx
mov bx, 2
div bx
mov ch, al ;cylinder# (0-79)
mov dh, dl ;head# (0-1)
ret
;-------------------------------------------------------
gdtr:
dw gdt_end-gdt-1
dd gdt
gdt:
dd 0
dd 0
KERNEL_CODE equ $-gdt
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 0x00 ;base 31:24
KERNEL_DATA equ $-gdt
db 0xff ;segment 16 = 4gb data
db 0xff
db 0x00
db 0x00
db 0x00
db 0x92
db 0xcf ;cf
db 0x00
gdt_end:
;------------------------------------------------------
go_pm:
xor ax, ax
mov ds, ax
lgdt [gdtr]
cli
mov eax, cr0
inc eax
mov cr0, eax
jmp KERNEL_CODE:pmode
bits 32
pmode:
mov ax, KERNEL_DATA
mov es, ax
mov ds, ax
mov fs, ax
mov gs, ax
jmp KERNEL_CODE:BOOT_KERNEL_ADD
kernel: db "KERNEL BIN", 0
-13
View File
@@ -1,13 +0,0 @@
#include "string.h"
int strlen(char *str)
{
int retn = 0;
while (*str++ != 0)
retn++;
return retn;
}
-8
View File
@@ -1,8 +0,0 @@
#ifndef __HSTRING_H__
#define __HSTRING_H__ __HSTRING_H__
int strlen(char *str);
#endif
+100
View File
@@ -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
View File
Whitespace-only changes.
View File
Whitespace-only changes.
-151
View File
@@ -1,151 +0,0 @@
//video.c
// 08/13/03 Josh Holtrop
ModeInfoBlock video_mode;
byte *vid_ptr24;
word *vid_ptr16;
dword *vid_ptr32;
void video_init(ModeInfoBlock *mib)
{
video_mode = *mib;
switch(video_mode.BitsPerPixel)
{
case 16:
vid_ptr16 = (word *) video_mode.PhysBasePtr;
break;
case 24:
vid_ptr24 = (byte *) video_mode.PhysBasePtr;
break;
case 32:
vid_ptr32 = (dword *) video_mode.PhysBasePtr;
}
dword tot = ((video_mode.XResolution) * (video_mode.YResolution));
int a;
for (a = 0; a < tot; a++)
{
if (a < (tot / 4))
video_psetp(a, 0x00FF0000);
else if (a < (tot / 2))
video_psetp(a, 0x0000FF00);
else if (a < ((tot * 3) / 4))
video_psetp(a, 0x000000FF);
else
video_psetp(a, 0x00FFFFFF);
}
}
void video_horiz(int y, int x1, int x2, dword color)
{
checkBoundsy(y);
checkBoundsx(x1);
checkBoundsx(x2);
if (x1 > x2)
{
int tmp = x2;
x2 = x1;
x1 = tmp;
}
int pixel = y*video_mode.XResolution+x1;
int a;
for (a = 0; a <= (x2-x1); a++)
{
video_psetp(pixel, color);
pixel++;
}
}
void video_vert(int x, int y1, int y2, dword color)
{
checkBoundsx(x);
checkBoundsy(y1);
checkBoundsy(y2);
if (y1 > y2)
{
int tmp = y2;
y2 = y1;
y1 = tmp;
}
int pixel = y1*video_mode.XResolution+x;
int a;
for (a = 0; a <= (y2-y1); a++)
{
video_psetp(pixel, color);
pixel+=video_mode.XResolution;
}
}
void video_rect(int x1, int y1, int x2, int y2, dword color)
{
checkBoundsx(x1);
checkBoundsx(x2);
checkBoundsy(y1);
checkBoundsy(y2);
if (x2 < x1)
{
int tmp = x2;
x2 = x1;
x1 = tmp;
}
if (y2 < y1)
{
int tmp = y2;
y2 = y1;
y1 = tmp;
}
video_horiz(y1, x1, x2, color);
video_horiz(y2, x1, x2, color);
video_vert(x1, y1, y2, color);
video_vert(x2, y1, y2, color);
}
void video_rectf(int x1, int y1, int x2, int y2, dword color)
{
checkBoundsx(x1);
checkBoundsx(x2);
checkBoundsy(y1);
checkBoundsy(y2);
if (x2 < x1)
{
int tmp = x2;
x2 = x1;
x1 = tmp;
}
if (y2 < y1)
{
int tmp = y2;
y2 = y1;
y1 = tmp;
}
int a;
for (a = 0; a <= (y2-y1); a++)
video_horiz(y1+a, x1, x2, color);
}
inline void video_pset(int x, int y, dword color)
{
video_psetp(y*video_mode.XResolution+x, color);
}
void video_psetp(int pixel, dword color)
{
switch(video_mode.BitsPerPixel)
{
case 16:
vid_ptr16[pixel] = ((color&0xFF)>>3) | ((((color>>8)&0xFF)>>2)<<6) | ((((color>>16)&0xFF)>>3)<<11);
//vid_ptr16[pixel] = ((color&0xFF)>>3) | ((((color>>8)&0xFF)>>3)<<5) | ((((color>>16)&0xFF)>>3)<<10);
break;
case 24:
vid_ptr24[pixel*3] = color & 0xFF;
vid_ptr24[pixel*3+1] = (color>>8) & 0xFF;
vid_ptr24[pixel*3+2] = (color>>16) & 0xFF;
break;
case 32:
vid_ptr32[pixel] = color;
}
}
-59
View File
@@ -1,59 +0,0 @@
//video.h
// 08/18/03 Josh Holtrop
void video_init();
void video_horiz(int y, int x1, int x2, dword color);
void video_vert(int x, int y1, int y2, dword color);
void video_rect(int x1, int y1, int x2, int y2, dword color);
void video_rectf(int x1, int y1, int x2, int y2, dword color);
inline void video_pset(int x, int y, dword color);
void video_psetp(int pixel, dword color);
#define checkBoundsx(x) (x<0 ? x=0 : (x>=video_mode.XResolution ? x=video_mode.XResolution-1 : 0))
#define checkBoundsy(x) (x<0 ? x=0 : (x>=video_mode.YResolution ? x=video_mode.YResolution-1 : 0))
typedef struct{
word ModeAttributes;
byte WinAAttributes;
byte WinBAttributes;
word WinGranularity;
word WinSize;
word WinASegment;
word WinBSegment;
dword WinFuncPtr;
word BytesPerScanLine;
word XResolution;
word YResolution;
byte XCharSize;
byte YCharSize;
byte NumberOfPlanes;
byte BitsPerPixel;
byte NumberOfBanks;
byte MemoryModel;
byte BankSize;
byte NumberOfImagePages;
byte Reserved1;
byte RedMaskSize;
byte RedFieldPosition;
byte GreenMaskSize;
byte GreenFieldPosition;
byte BlueMaskSize;
byte BlueFieldPosition;
byte RsvdMaskSize;
byte RsvdFieldPosition;
byte DirectColorModeInfo;
dword PhysBasePtr;
dword OffScreenMemOffset;
word OffScreenMemSize;
byte Reserved[206];
} ModeInfoBlock;