diff --git a/competition-osdev-08-pajadam/.gitignore b/competition-osdev-08-pajadam/.gitignore new file mode 100644 index 0000000..586e694 --- /dev/null +++ b/competition-osdev-08-pajadam/.gitignore @@ -0,0 +1,3 @@ +bin +tmp +*.pyc diff --git a/competition-osdev-08-pajadam/README.md b/competition-osdev-08-pajadam/README.md new file mode 100644 index 0000000..b663d0b --- /dev/null +++ b/competition-osdev-08-pajadam/README.md @@ -0,0 +1,16 @@ +# How to build and run project? + +You need to use simple Python script. Just run it `python manage.py` with one of following arguments: + +- `build` - generate our disk image +- `run` - run generated disk image in bochs +- `test` - `build` and `run` +- `clean` - empty temp directory + +# What is in project's directories? + +- /src - Code +- /scripts - Building scripts in python +- /conf - Bochs config +- /bin - Generated disk image +- /tmp - Directory with temporary files diff --git a/competition-osdev-08-pajadam/conf/osdev.bochsrc b/competition-osdev-08-pajadam/conf/osdev.bochsrc new file mode 100644 index 0000000..7c1fca0 --- /dev/null +++ b/competition-osdev-08-pajadam/conf/osdev.bochsrc @@ -0,0 +1,1131 @@ +# You may now use double quotes around pathnames, in case +# your pathname includes spaces. + +#======================================================================= +# PLUGIN_CTRL: +# Controls the presence of optional device plugins. These plugins are loaded +# directly with this option and some of them install a config option that is +# only available when the plugin device is loaded. The value "1" means to load +# the plugin and "0" will unload it (if loaded before). +# +# These plugins will be loaded by default (if present): 'biosdev', 'extfpuirq', +# 'gameport', 'iodebug','parallel', 'serial', 'speaker' and 'unmapped'. +# +# These plugins are also supported, but they are usually loaded directly with +# their bochsrc option: 'e1000', 'es1370', 'ne2k', 'pcidev', 'pcipnic', 'sb16', +# 'usb_ohci', 'usb_uhci' and 'usb_xhci'. +# +# This plugin currently must be loaded with plugin_ctrl: 'voodoo'. +#======================================================================= +#plugin_ctrl: unmapped=0, e1000=1 # unload 'unmapped' and load 'e1000' + +#======================================================================= +# CONFIG_INTERFACE +# +# The configuration interface is a series of menus or dialog boxes that +# allows you to change all the settings that control Bochs's behavior. +# Depending on the platform there are up to 3 choices of configuration +# interface: a text mode version called "textconfig" and two graphical versions +# called "win32config" and "wx". The text mode version uses stdin/stdout and +# is always compiled in, unless Bochs is compiled for wx only. The choice +# "win32config" is only available on win32 and it is the default there. +# The choice "wx" is only available when you use "--with-wx" on the configure +# command. If you do not write a config_interface line, Bochs will +# choose a default for you. +# +# NOTE: if you use the "wx" configuration interface, you must also use +# the "wx" display library. +#======================================================================= +#config_interface: textconfig +#config_interface: win32config +#config_interface: wx + +#======================================================================= +# DISPLAY_LIBRARY +# +# The display library is the code that displays the Bochs VGA screen. Bochs +# has a selection of about 10 different display library implementations for +# different platforms. If you run configure with multiple --with-* options, +# the display_library command lets you choose which one you want to run with. +# If you do not write a display_library line, Bochs will choose a default for +# you. +# +# The choices are: +# x use X windows interface, cross platform +# win32 use native win32 libraries +# carbon use Carbon library (for MacOS X) +# macintosh use MacOS pre-10 +# amigaos use native AmigaOS libraries +# sdl use SDL library, cross platform +# svga use SVGALIB library for Linux, allows graphics without X11 +# term text only, uses curses/ncurses library, cross platform +# rfb provides an interface to AT&T's VNC viewer, cross platform +# wx use wxWidgets library, cross platform +# nogui no display at all +# +# NOTE: if you use the "wx" configuration interface, you must also use +# the "wx" display library. +# +# Specific options: +# Some display libraries now support specific options to control their +# behaviour. These options are supported by more than one display library: +# +# "gui_debug" - use GTK debugger gui (sdl, x) / Win32 debugger gui (sdl, win32) +# "hideIPS" - disable IPS output in status bar (rfb, sdl, win32, wx, x) +# "nokeyrepeat" - turn off host keyboard repeat (sdl, win32, x) +# +# See the examples below for other currently supported options. +#======================================================================= +#display_library: amigaos +#display_library: carbon +#display_library: macintosh +#display_library: nogui +#display_library: rfb, options="timeout=60" # time to wait for client +#display_library: sdl, options="fullscreen" # startup in fullscreen mode +#display_library: term +#display_library: win32 +#display_library: wx +#display_library: x + +#======================================================================= +# ROMIMAGE: +# The ROM BIOS controls what the PC does when it first powers on. +# Normally, you can use a precompiled BIOS in the source or binary +# distribution called BIOS-bochs-latest. The ROM BIOS is usually loaded +# starting at address 0xf0000, and it is exactly 64k long. Another option +# is 128k BIOS which is loaded at address 0xe0000. +# You can also use the environment variable $BXSHARE to specify the +# location of the BIOS. +# The usage of external large BIOS images (up to 512k) at memory top is +# now supported, but we still recommend to use the BIOS distributed with +# Bochs. The start address optional, since it can be calculated from image size. +#======================================================================= +romimage: file=$BXSHARE/BIOS-bochs-latest +#romimage: file=bios/seabios-1.6.3.bin +#romimage: file=mybios.bin, address=0xfff80000 # 512k at memory top + +#======================================================================= +# CPU: +# This defines cpu-related parameters inside Bochs: +# +# MODEL: +# Selects CPU configuration to emulate from pre-defined list of all +# supported configurations. When this option is used, the CPUID option +# has no effect anymore. +# +# CPU configurations that can be selected: +# ----------------------------------------------------------------- +# pentium_mmx Intel Pentium MMX +# amd_k6_2_chomper AMD-K6(tm) 3D processor (Chomper) +# p2_klamath Intel Pentium II (Klamath) +# p3_katmai Intel Pentium III (Katmai) +# p4_willamette Intel(R) Pentium(R) 4 (Willamette) +# core_duo_t2400_yonah Intel(R) Core(TM) Duo CPU T2400 (Yonah) +# atom_n270 Intel(R) Atom(TM) CPU N270 +# athlon64_clawhammer AMD Athlon(tm) 64 Processor 2800+ (Clawhammer) +# athlon64_venice AMD Athlon(tm) 64 Processor 3000+ (Venice) +# turion64_tyler AMD Turion(tm) 64 X2 Mobile TL-60 (Tyler) +# phenom_8650_toliman AMD Phenom X3 8650 (Toliman) +# p4_prescott_celeron_336 Intel(R) Celeron(R) 336 (Prescott) +# core2_penryn_t9600 Intel Mobile Core 2 Duo T9600 (Penryn) +# corei5_lynnfield_750 Intel(R) Core(TM) i5 750 (Lynnfield) +# corei5_arrandale_m520 Intel(R) Core(TM) i5 M 520 (Arrandale) +# corei7_sandy_bridge_2600k Intel(R) Core(TM) i7-2600K (Sandy Bridge) +# corei7_ivy_bridge_3770k Intel(R) Core(TM) i7-3770K CPU (Ivy Bridge) +# +# COUNT: +# Set the number of processors:cores per processor:threads per core +# when Bochs is compiled for SMP emulation. +# Bochs currently supports up to 8 threads running simultaniosly. +# If Bochs is compiled without SMP support, it won't accept values +# different from 1. +# +# QUANTUM: +# Maximum amount of instructions allowed to execute by processor before +# returning control to another cpu. This option exists only in Bochs +# binary compiled with SMP support. +# +# RESET_ON_TRIPLE_FAULT: +# Reset the CPU when triple fault occur (highly recommended) rather than +# PANIC. Remember that if you trying to continue after triple fault the +# simulation will be completely bogus ! +# +# CPUID_LIMIT_WINNT: +# Determine whether to limit maximum CPUID function to 2. This mode is +# required to workaround WinNT installation and boot issues. +# +# MSRS: +# Define path to user CPU Model Specific Registers (MSRs) specification. +# See example in msrs.def. +# +# IGNORE_BAD_MSRS: +# Ignore MSR references that Bochs does not understand; print a warning +# message instead of generating #GP exception. This option is enabled +# by default but will not be avaiable if configurable MSRs are enabled. +# +# MWAIT_IS_NOP: +# When this option is enabled MWAIT will not put the CPU into a sleep state. +# This option exists only if Bochs compiled with --enable-monitor-mwait. +# +# IPS: +# Emulated Instructions Per Second. This is the number of IPS that bochs +# is capable of running on your machine. You can recompile Bochs with +# --enable-show-ips option enabled, to find your host's capability. +# Measured IPS value will then be logged into your log file or shown +# in the status bar (if supported by the gui). +# +# IPS is used to calibrate many time-dependent events within the bochs +# simulation. For example, changing IPS affects the frequency of VGA +# updates, the duration of time before a key starts to autorepeat, and +# the measurement of BogoMips and other benchmarks. +# +# Examples: +# +# Bochs Machine/Compiler Mips +# ______________________________________________________________________ +# 2.4.6 3.4Ghz Intel Core i7 2600 with Win7x64/g++ 4.5.2 85 to 95 Mips +# 2.3.7 3.2Ghz Intel Core 2 Q9770 with WinXP/g++ 3.4 50 to 55 Mips +# 2.3.7 2.6Ghz Intel Core 2 Duo with WinXP/g++ 3.4 38 to 43 Mips +# 2.2.6 2.6Ghz Intel Core 2 Duo with WinXP/g++ 3.4 21 to 25 Mips +# 2.2.6 2.1Ghz Athlon XP with Linux 2.6/g++ 3.4 12 to 15 Mips +#======================================================================= +cpu: model=bx_generic, count=1, ips=50000000, reset_on_triple_fault=1, ignore_bad_msrs=1, msrs="msrs.def" +cpu: cpuid_limit_winnt=0 + +#======================================================================= +# CPUID: +# +# This defines features and functionality supported by Bochs emulated CPU. +# The option has no offect if CPU model was selected in CPU option. +# +# MMX: +# Select MMX instruction set support. +# This option exists only if Bochs compiled with BX_CPU_LEVEL >= 5. +# +# APIC: +# Select APIC configuration (LEGACY/XAPIC/XAPIC_EXT/X2APIC). +# This option exists only if Bochs compiled with BX_CPU_LEVEL >= 5. +# +# SEP: +# Select SYSENTER/SYSEXIT instruction set support. +# This option exists only if Bochs compiled with BX_CPU_LEVEL >= 6. +# +# SSE: +# Select SSE instruction set support. +# Any of NONE/SSE/SSE2/SSE3/SSSE3/SSE4_1/SSE4_2 could be selected. +# This option exists only if Bochs compiled with BX_CPU_LEVEL >= 6. +# +# SSE4A: +# Select AMD SSE4A instructions support. +# This option exists only if Bochs compiled with BX_CPU_LEVEL >= 6. +# +# MISALIGNED_SSE: +# Select AMD Misaligned SSE mode support. +# This option exists only if Bochs compiled with BX_CPU_LEVEL >= 6. +# +# AES: +# Select AES instruction set support. +# This option exists only if Bochs compiled with BX_CPU_LEVEL >= 6. +# +# MOVBE: +# Select MOVBE Intel(R) Atom instruction support. +# This option exists only if Bochs compiled with BX_CPU_LEVEL >= 6. +# +# ADX: +# Select ADCX/ADOX instructions support. +# This option exists only if Bochs compiled with BX_CPU_LEVEL >= 6. +# +# XSAVE: +# Select XSAVE extensions support. +# This option exists only if Bochs compiled with BX_CPU_LEVEL >= 6. +# +# XSAVEOPT: +# Select XSAVEOPT instruction support. +# This option exists only if Bochs compiled with BX_CPU_LEVEL >= 6. +# +# AVX: +# Select AVX/AVX2 instruction set support. +# This option exists only if Bochs compiled with --enable-avx option. +# +# AVX_F16C: +# Select AVX float16 convert instructions support. +# This option exists only if Bochs compiled with --enable-avx option. +# +# AVX_FMA: +# Select AVX fused multiply add (FMA) instructions support. +# This option exists only if Bochs compiled with --enable-avx option. +# +# BMI: +# Select BMI1/BMI2 instructions support. +# This option exists only if Bochs compiled with --enable-avx option. +# +# XOP: +# Select AMD XOP instructions support. +# This option exists only if Bochs compiled with --enable-avx option. +# +# FMA4: +# Select AMD four operand FMA instructions support. +# This option exists only if Bochs compiled with --enable-avx option. +# +# TBM: +# Select AMD Trailing Bit Manipulation (TBM) instructions support. +# This option exists only if Bochs compiled with --enable-avx option. +# +# X86-64: +# Enable x86-64 and long mode support. +# This option exists only if Bochs compiled with x86-64 support. +# +# 1G_PAGES: +# Enable 1G page size support in long mode. +# This option exists only if Bochs compiled with x86-64 support. +# +# PCID: +# Enable Process-Context Identifiers (PCID) support in long mode. +# This option exists only if Bochs compiled with x86-64 support. +# +# FSGSBASE: +# Enable GS/GS BASE access instructions support in long mode. +# This option exists only if Bochs compiled with x86-64 support. +# +# SMEP: +# Enable Supervisor Mode Execution Protection (SMEP) support. +# This option exists only if Bochs compiled with BX_CPU_LEVEL >= 6. +# +# SMAP: +# Enable Supervisor Mode Access Prevention (SMAP) support. +# This option exists only if Bochs compiled with BX_CPU_LEVEL >= 6. +# +# MWAIT: +# Select MONITOR/MWAIT instructions support. +# This option exists only if Bochs compiled with --enable-monitor-mwait. +# +# VMX: +# Select VMX extensions emulation support. +# This option exists only if Bochs compiled with --enable-vmx option. +# +# SVM: +# Select AMD SVM (Secure Virtual Machine) extensions emulation support. +# This option exists only if Bochs compiled with --enable-svm option. +# +# VENDOR_STRING: +# Set the CPUID vendor string returned by CPUID(0x0). This should be a +# twelve-character ASCII string. +# +# BRAND_STRING: +# Set the CPUID vendor string returned by CPUID(0x80000002 .. 0x80000004). +# This should be at most a forty-eight-character ASCII string. +# +# LEVEL: +# Set emulated CPU level information returned by CPUID. Default value is +# determined by configure option --enable-cpu-level. Currently supported +# values are 5 (for Pentium and similar processors) and 6 (for P6 and +# later processors). +# +# FAMILY: +# Set model information returned by CPUID. Default family value determined +# by configure option --enable-cpu-level. +# +# MODEL: +# Set model information returned by CPUID. Default model value is 3. +# +# STEPPING: +# Set stepping information returned by CPUID. Default stepping value is 3. +#======================================================================= +#cpuid: x86_64=1, mmx=1, sep=1, sse=sse4_2, apic=xapic, aes=1, movbe=1, xsave=1 +#cpuid: family=6, model=0x1a, stepping=5 +cpuid: 1g_pages=1 + +#======================================================================= +# MEMORY +# Set the amount of physical memory you want to emulate. +# +# GUEST: +# Set amount of guest physical memory to emulate. The default is 32MB, +# the maximum amount limited only by physical address space limitations. +# +# HOST: +# Set amount of host memory you want to allocate for guest RAM emulation. +# It is possible to allocate less memory than you want to emulate in guest +# system. This will fake guest to see the non-existing memory. Once guest +# system touches new memory block it will be dynamically taken from the +# memory pool. You will be warned (by FATAL PANIC) in case guest already +# used all allocated host memory and wants more. +# +#======================================================================= +memory: guest=512, host=256 + +#======================================================================= +# OPTROMIMAGE[1-4]: +# You may now load up to 4 optional ROM images. Be sure to use a +# read-only area, typically between C8000 and EFFFF. These optional +# ROM images should not overwrite the rombios (located at +# F0000-FFFFF) and the videobios (located at C0000-C7FFF). +# Those ROM images will be initialized by the bios if they contain +# the right signature (0x55AA) and a valid checksum. +# It can also be a convenient way to upload some arbitrary code/data +# in the simulation, that can be retrieved by the boot loader +#======================================================================= +#optromimage1: file=optionalrom.bin, address=0xd0000 +#optromimage2: file=optionalrom.bin, address=0xd1000 +#optromimage3: file=optionalrom.bin, address=0xd2000 +#optromimage4: file=optionalrom.bin, address=0xd3000 + +#optramimage1: file=/path/file1.img, address=0x0010000 +#optramimage2: file=/path/file2.img, address=0x0020000 +#optramimage3: file=/path/file3.img, address=0x0030000 +#optramimage4: file=/path/file4.img, address=0x0040000 + +#======================================================================= +# VGAROMIMAGE +# You now need to load a VGA ROM BIOS into C0000. +#======================================================================= +#vgaromimage: file=bios/VGABIOS-elpin-2.40 +vgaromimage: file=$BXSHARE/VGABIOS-lgpl-latest +#vgaromimage: file=bios/VGABIOS-lgpl-latest-cirrus + +#======================================================================= +# VGA: +# This defines parameters related to the VGA display +# +# EXTENSION +# Here you can specify the display extension to be used. With the value +# 'none' you can use standard VGA with no extension. Other supported +# values are 'vbe' for Bochs VBE and 'cirrus' for Cirrus SVGA support. +# +# UPDATE_FREQ +# The VGA update frequency is based on the emulated clock and the default +# value is 5. Keep in mind that you must tweak the 'cpu: ips=N' directive +# to be as close to the number of emulated instructions-per-second your +# workstation can do, for this to be accurate. If the realtime sync is +# enabled with the 'clock' option, the value is based on the real time. +# This parameter can be changed at runtime. +# +# Examples: +# vga: extension=cirrus, update_freq=10 +#======================================================================= +#vga: extension=vbe, update_freq=5 + +#======================================================================= +# FLOPPYA: +# Point this to pathname of floppy image file or device +# This should be of a bootable floppy(image/device) if you're +# booting from 'a' (or 'floppy'). +# +# You can set the initial status of the media to 'ejected' or 'inserted'. +# floppya: 2_88=path, status=ejected (2.88M 3.5" media) +# floppya: 1_44=path, status=inserted (1.44M 3.5" media) +# floppya: 1_2=path, status=ejected (1.2M 5.25" media) +# floppya: 720k=path, status=inserted (720K 3.5" media) +# floppya: 360k=path, status=inserted (360K 5.25" media) +# floppya: 320k=path, status=inserted (320K 5.25" media) +# floppya: 180k=path, status=inserted (180K 5.25" media) +# floppya: 160k=path, status=inserted (160K 5.25" media) +# floppya: image=path, status=inserted (guess media type from image size) +# floppya: 1_44=vvfat:path, status=inserted (use directory as VFAT media) +# floppya: type=1_44 (1.44M 3.5" floppy drive, no media) +# +# The path should be the name of a disk image file. On Unix, you can use a raw +# device name such as /dev/fd0 on Linux. On win32 platforms, use drive letters +# such as a: or b: as the path. The parameter 'image' works with image files +# only. In that case the size must match one of the supported types. +# The parameter 'type' can be used to enable the floppy drive without media +# and status specified. Usually the drive type is set up based on the media type. +# The optional parameter 'write_protected' can be used to control the media +# write protect switch. By default it is turned off. +#======================================================================= +#floppya: 1_44=/dev/fd0, status=inserted +floppya: 1_44=../bin/floppy.bin, status=inserted +#floppya: 1_44=/dev/fd0H1440, status=inserted +#floppya: 1_2=../1_2, status=inserted +#floppya: 1_44=a:, status=inserted +#floppya: 1_44=a.img, status=inserted, write_protected=1 +#floppya: 1_44=/dev/rfd0a, status=inserted + +#======================================================================= +# FLOPPYB: +# See FLOPPYA above for syntax +#======================================================================= +#floppyb: 1_44=b:, status=inserted +#floppyb: 1_44=b.img, status=inserted + +#======================================================================= +# ATA0, ATA1, ATA2, ATA3 +# ATA controller for hard disks and cdroms +# +# ata[0-3]: enabled=[0|1], ioaddr1=addr, ioaddr2=addr, irq=number +# +# These options enables up to 4 ata channels. For each channel +# the two base io addresses and the irq must be specified. +# +# ata0 and ata1 are enabled by default with the values shown below +# +# Examples: +# ata0: enabled=1, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14 +# ata1: enabled=1, ioaddr1=0x170, ioaddr2=0x370, irq=15 +# ata2: enabled=1, ioaddr1=0x1e8, ioaddr2=0x3e0, irq=11 +# ata3: enabled=1, ioaddr1=0x168, ioaddr2=0x360, irq=9 +#======================================================================= +ata0: enabled=1, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14 +ata1: enabled=1, ioaddr1=0x170, ioaddr2=0x370, irq=15 +ata2: enabled=0, ioaddr1=0x1e8, ioaddr2=0x3e0, irq=11 +ata3: enabled=0, ioaddr1=0x168, ioaddr2=0x360, irq=9 + +#======================================================================= +# ATA[0-3]-MASTER, ATA[0-3]-SLAVE +# +# This defines the type and characteristics of all attached ata devices: +# type= type of attached device [disk|cdrom] +# mode= only valid for disks [flat|concat|external|dll|sparse|vmware3] +# [vmware4|undoable|growing|volatile|vpc|vvfat] +# path= path of the image / directory +# cylinders= only valid for disks +# heads= only valid for disks +# spt= only valid for disks +# status= only valid for cdroms [inserted|ejected] +# biosdetect= type of biosdetection [none|auto], only for disks on ata0 [cmos] +# translation=type of translation of the bios, only for disks [none|lba|large|rechs|auto] +# model= string returned by identify device command +# journal= optional filename of the redolog for undoable, volatile and vvfat disks +# +# Point this at a hard disk image file, cdrom iso file, or physical cdrom +# device. To create a hard disk image, try running bximage. It will help you +# choose the size and then suggest a line that works with it. +# +# In UNIX it may be possible to use a raw device as a Bochs hard disk, +# but WE DON'T RECOMMEND IT. In Windows there is no easy way. +# +# In windows, the drive letter + colon notation should be used for cdroms. +# Depending on versions of windows and drivers, you may only be able to +# access the "first" cdrom in the system. On MacOSX, use path="drive" +# to access the physical drive. +# +# The path is mandatory for hard disks. Disk geometry autodetection works with +# images created by bximage if CHS is set to 0/0/0 (cylinders are calculated +# using heads=16 and spt=63). For other hard disk images and modes the +# cylinders, heads, and spt are mandatory. In all cases the disk size reported +# from the image must be exactly C*H*S*512. +# +# Default values are: +# mode=flat, biosdetect=auto, translation=auto, model="Generic 1234" +# +# The biosdetect option has currently no effect on the bios +# +# Examples: +# ata0-master: type=disk, mode=flat, path=10M.sample, cylinders=306, heads=4, spt=17 +# ata0-slave: type=disk, mode=flat, path=20M.sample, cylinders=615, heads=4, spt=17 +# ata1-master: type=disk, mode=flat, path=30M.sample, cylinders=615, heads=6, spt=17 +# ata1-slave: type=disk, mode=flat, path=46M.sample, cylinders=940, heads=6, spt=17 +# ata2-master: type=disk, mode=flat, path=62M.sample, cylinders=940, heads=8, spt=17 +# ata2-slave: type=disk, mode=flat, path=112M.sample, cylinders=900, heads=15, spt=17 +# ata3-master: type=disk, mode=flat, path=483M.sample, cylinders=1024, heads=15, spt=63 +# ata3-slave: type=cdrom, path=iso.sample, status=inserted +#======================================================================= +#ata0-master: type=disk, mode=flat, path="stage4.bin" +#ata0-master: type=disk, mode=flat, path="30M.sample", cylinders=615, heads=6, spt=17 +#ata0-master: type=disk, mode=flat, path="c.img", cylinders=0 # autodetect +#ata0-slave: type=disk, mode=vvfat, path=/bochs/images/vvfat, journal=vvfat.redolog +#ata0-slave: type=cdrom, path=D:, status=inserted +#ata0-slave: type=cdrom, path=/dev/cdrom, status=inserted +#ata0-slave: type=cdrom, path="drive", status=inserted +#ata0-slave: type=cdrom, path=/dev/rcd0d, status=inserted + +#======================================================================= +# BOOT: +# This defines the boot sequence. Now you can specify up to 3 boot drives, +# which can be 'floppy', 'disk', 'cdrom' or 'network' (boot ROM). +# Legacy 'a' and 'c' are also supported. +# Examples: +# boot: floppy +# boot: cdrom, disk +# boot: network, disk +# boot: cdrom, floppy, disk +#======================================================================= +boot: floppy +#boot: disk + +#======================================================================= +# CLOCK: +# This defines the parameters of the clock inside Bochs: +# +# SYNC: +# This defines the method how to synchronize the Bochs internal time +# with realtime. With the value 'none' the Bochs time relies on the IPS +# value and no host time synchronization is used. The 'slowdown' method +# sacrifices performance to preserve reproducibility while allowing host +# time correlation. The 'realtime' method sacrifices reproducibility to +# preserve performance and host-time correlation. +# It is possible to enable both synchronization methods. +# +# RTC_SYNC: +# If this option is enabled together with the realtime synchronization, +# the RTC runs at realtime speed. This feature is disabled by default. +# +# TIME0: +# Specifies the start (boot) time of the virtual machine. Use a time +# value as returned by the time(2) system call. If no time0 value is +# set or if time0 equal to 1 (special case) or if time0 equal 'local', +# the simulation will be started at the current local host time. +# If time0 equal to 2 (special case) or if time0 equal 'utc', +# the simulation will be started at the current utc time. +# +# Syntax: +# clock: sync=[none|slowdown|realtime|both], time0=[timeValue|local|utc] +# +# Example: +# clock: sync=none, time0=local # Now (localtime) +# clock: sync=slowdown, time0=315529200 # Tue Jan 1 00:00:00 1980 +# clock: sync=none, time0=631148400 # Mon Jan 1 00:00:00 1990 +# clock: sync=realtime, time0=938581955 # Wed Sep 29 07:12:35 1999 +# clock: sync=realtime, time0=946681200 # Sat Jan 1 00:00:00 2000 +# clock: sync=none, time0=1 # Now (localtime) +# clock: sync=none, time0=utc # Now (utc/gmt) +# +# Default value are sync=none, time0=local +#======================================================================= +#clock: sync=none, time0=local + + +#======================================================================= +# FLOPPY_BOOTSIG_CHECK: disabled=[0|1] +# Enables or disables the 0xaa55 signature check on boot floppies +# Defaults to disabled=0 +# Examples: +# floppy_bootsig_check: disabled=0 +# floppy_bootsig_check: disabled=1 +#======================================================================= +floppy_bootsig_check: disabled=0 + +#======================================================================= +# LOG: +# Give the path of the log file you'd like Bochs debug and misc. verbiage +# to be written to. If you don't use this option or set the filename to +# '-' the output is written to the console. If you really don't want it, +# make it "/dev/null" (Unix) or "nul" (win32). :^( +# +# Examples: +# log: ./bochs.out +# log: /dev/tty +#======================================================================= +#log: /dev/null +log: bochsout.txt + +#======================================================================= +# LOGPREFIX: +# This handles the format of the string prepended to each log line. +# You may use those special tokens : +# %t : 11 decimal digits timer tick +# %i : 8 hexadecimal digits of cpu current eip (ignored in SMP configuration) +# %e : 1 character event type ('i'nfo, 'd'ebug, 'p'anic, 'e'rror) +# %d : 5 characters string of the device, between brackets +# +# Default : %t%e%d +# Examples: +# logprefix: %t-%e-@%i-%d +# logprefix: %i%e%d +#======================================================================= +#logprefix: %t%e%d + +#======================================================================= +# LOG CONTROLS +# +# Bochs has four severity levels for event logging. +# panic: cannot proceed. If you choose to continue after a panic, +# don't be surprised if you get strange behavior or crashes. +# error: something went wrong, but it is probably safe to continue the +# simulation. +# info: interesting or useful messages. +# debug: messages useful only when debugging the code. This may +# spit out thousands per second. +# +# For events of each level, you can choose to exit Bochs ('fatal'), 'report' +# or 'ignore'. On some guis you have the additional choice 'ask'. A gui dialog +# appears asks how to proceed. +# +# It is also possible to specify the 'action' to do for each Bochs facility +# separately (e.g. crash on panics from everything except the cdrom, and only +# report those). See the 'log function' module list in the user documentation. +# +# If you are experiencing many panics, it can be helpful to change +# the panic action to report instead of fatal. However, be aware +# that anything executed after a panic is uncharted territory and can +# cause bochs to become unstable. The panic is a "graceful exit," so +# if you disable it you may get a spectacular disaster instead. +#======================================================================= +panic: action=ask +error: action=report +info: action=report +debug: action=ignore, pci=report # report BX_DEBUG from module 'pci' + +#======================================================================= +# DEBUGGER_LOG: +# Give the path of the log file you'd like Bochs to log debugger output. +# If you really don't want it, make it /dev/null or '-'. :^( +# +# Examples: +# debugger_log: ./debugger.out +#======================================================================= +#debugger_log: /dev/null +#debugger_log: debugger.out +debugger_log: - + +#======================================================================= +# COM1, COM2, COM3, COM4: +# This defines a serial port (UART type 16550A). In the 'term' mode you can +# specify a device to use as com1. This can be a real serial line, or a pty. +# To use a pty (under X/Unix), create two windows (xterms, usually). One of +# them will run bochs, and the other will act as com1. Find out the tty the com1 +# window using the `tty' command, and use that as the `dev' parameter. +# Then do `sleep 1000000' in the com1 window to keep the shell from +# messing with things, and run bochs in the other window. Serial I/O to +# com1 (port 0x3f8) will all go to the other window. +# In socket* and pipe* (win32 only) modes Bochs becomes either socket/named pipe +# client or server. In client mode it connects to an already running server (if +# connection fails Bochs treats com port as not connected). In server mode it +# opens socket/named pipe and waits until a client application connects to it +# before starting simulation. This mode is useful for remote debugging (e.g. +# with gdb's "target remote host:port" command or windbg's command line option +# -k com:pipe,port=\\.\pipe\pipename). Socket modes use simple TCP communication, +# pipe modes use duplex byte mode pipes. +# Other serial modes are 'null' (no input/output), 'file' (output to a file +# specified as the 'dev' parameter), 'raw' (use the real serial port - under +# construction for win32), 'mouse' (standard serial mouse - requires +# mouse option setting 'type=serial', 'type=serial_wheel' or 'type=serial_msys'). +# +# Examples: +# com1: enabled=1, mode=null +# com1: enabled=1, mode=mouse +# com2: enabled=1, mode=file, dev=serial.out +# com3: enabled=1, mode=raw, dev=com1 +# com3: enabled=1, mode=socket-client, dev=localhost:8888 +# com3: enabled=1, mode=socket-server, dev=localhost:8888 +# com4: enabled=1, mode=pipe-client, dev=\\.\pipe\mypipe +# com4: enabled=1, mode=pipe-server, dev=\\.\pipe\mypipe +#======================================================================= +#com1: enabled=1, mode=term, dev=/dev/ttyp9 + + +#======================================================================= +# PARPORT1, PARPORT2: +# This defines a parallel (printer) port. When turned on and an output file is +# defined the emulated printer port sends characters printed by the guest OS +# into the output file. On some platforms a device filename can be used to +# send the data to the real parallel port (e.g. "/dev/lp0" on Linux, "lpt1" on +# win32 platforms). +# +# Examples: +# parport1: enabled=1, file="parport.out" +# parport2: enabled=1, file="/dev/lp0" +# parport1: enabled=0 +#======================================================================= +parport1: enabled=1, file="parport.out" + +#======================================================================= +# SB16: +# This defines the SB16 sound emulation. It can have several of the +# following properties. +# All properties are in the format sb16: property=value +# enabled: +# This optional property controls the presence of the SB16 emulation. +# The emulation is turned on unless this property is used and set to 0. +# midi: The filename is where the midi data is sent. This can be a +# device or just a file if you want to record the midi data. +# midimode: +# 0=no data +# 1=output to device (system dependent. midi denotes the device driver) +# 2=SMF file output, including headers +# 3=output the midi data stream to the file (no midi headers and no +# delta times, just command and data bytes) +# wave: This is the device/file where wave output is stored +# wavemode: +# 0=no data +# 1=output to device (system dependent. wave denotes the device driver) +# 2=VOC file output, incl. headers +# 3=output the raw wave stream to the file +# log: The file to write the sb16 emulator messages to. +# loglevel: +# 0=no log +# 1=resource changes, midi program and bank changes +# 2=severe errors +# 3=all errors +# 4=all errors plus all port accesses +# 5=all errors and port accesses plus a lot of extra info +# dmatimer: +# microseconds per second for a DMA cycle. Make it smaller to fix +# non-continuous sound. 750000 is usually a good value. This needs a +# reasonably correct setting for the IPS parameter of the CPU option. +# +# Examples for output devices: +# sb16: midimode=1, midi="", wavemode=1, wave="" # win32 +# sb16: midimode=1, midi=alsa:128:0, wavemode=1, wave=alsa # Linux with ALSA +# sb16: wavemode=1, wave=sdl # use SDL audio (if present) for output +#======================================================================= +#sb16: midimode=1, midi=/dev/midi00, wavemode=1, wave=/dev/dsp, loglevel=2, log=sb16.log, dmatimer=600000 + +#======================================================================= +# ES1370: +# This defines the ES1370 sound emulation. The parameter 'enabled' controls the +# presence of the device. The 'wavedev' parameter is similar to the 'wave' +# parameter of the SB16 soundcard. The emulation supports recording and playback +# (except DAC1+DAC2 output at the same time). +# +# Examples: +# es1370: enabled=1, wavedev="" # win32 +# es1370: enabled=1, wavedev=alsa # Linux with ALSA +# es1370: enabled=1, wavedev=sdl # use SDL audio (if present) for output +#======================================================================= +#es1370: enabled=1, wavedev=alsa + +#======================================================================= +# KEYBOARD: +# This defines parameters related to the emulated keyboard +# +# TYPE: +# Type of keyboard return by a "identify keyboard" command to the +# keyboard controller. It must be one of "xt", "at" or "mf". +# Defaults to "mf". It should be ok for almost everybody. A known +# exception is french macs, that do have a "at"-like keyboard. +# +# SERIAL_DELAY: +# Approximate time in microseconds that it takes one character to +# be transferred from the keyboard to controller over the serial path. +# +# PASTE_DELAY: +# Approximate time in microseconds between attempts to paste +# characters to the keyboard controller. This leaves time for the +# guest os to deal with the flow of characters. The ideal setting +# depends on how your operating system processes characters. The +# default of 100000 usec (.1 seconds) was chosen because it works +# consistently in Windows. +# If your OS is losing characters during a paste, increase the paste +# delay until it stops losing characters. +# +# KEYMAP: +# This enables a remap of a physical localized keyboard to a +# virtualized us keyboard, as the PC architecture expects. +# +# USER_SHORTCUT: +# This defines the keyboard shortcut to be sent when you press the "user" +# button in the headerbar. The shortcut string is a combination of maximum +# 3 key names (listed below) separated with a '-' character. +# Valid key names: +# "alt", "bksl", "bksp", "ctrl", "del", "down", "end", "enter", "esc", +# "f1", ... "f12", "home", "ins", "left", "menu", "minus", "pgdwn", "pgup", +# "plus", "right", "shift", "space", "tab", "up", "win", "print" and "power". + +# Examples: +# keyboard: type=mf, serial_delay=200, paste_delay=100000 +# keyboard: keymap=gui/keymaps/x11-pc-de.map +# keyboard: user_shortcut=ctrl-alt-del +#======================================================================= +#keyboard: type=mf, serial_delay=250 + +#======================================================================= +# MOUSE: +# This defines parameters for the emulated mouse type, the initial status +# of the mouse capture and the runtime method to toggle it. +# +# TYPE: +# With the mouse type option you can select the type of mouse to emulate. +# The default value is 'ps2'. The other choices are 'imps2' (wheel mouse +# on PS/2), 'serial', 'serial_wheel' and 'serial_msys' (one com port requires +# setting 'mode=mouse'). To connect a mouse to an USB port, see the 'usb_uhci', +# 'usb_ohci' or 'usb_xhci' options (requires PCI and USB support). +# +# ENABLED: +# The Bochs gui creates mouse "events" unless the 'enabled' option is +# set to 0. The hardware emulation itself is not disabled by this. +# Unless you have a particular reason for enabling the mouse by default, +# it is recommended that you leave it off. You can also toggle the mouse +# usage at runtime (RFB, SDL, Win32, wxWidgets and X11 - see below). +# +# TOGGLE: +# The default method to toggle the mouse capture at runtime is to press the +# CTRL key and the middle mouse button ('ctrl+mbutton'). This option allows +# to change the method to 'ctrl+f10' (like DOSBox), 'ctrl+alt' (like QEMU) +# or 'f12' (replaces win32 'legacyF12' option). +# +# Examples: +# mouse: enabled=1 +# mouse: type=imps2, enabled=1 +# mouse: type=serial, enabled=1 +# mouse: enabled=0, toggle=ctrl+f10 +#======================================================================= +mouse: enabled=0 + +#======================================================================= +# private_colormap: Request that the GUI create and use it's own +# non-shared colormap. This colormap will be used +# when in the bochs window. If not enabled, a +# shared colormap scheme may be used. Not implemented +# on all GUI's. +# +# Examples: +# private_colormap: enabled=1 +# private_colormap: enabled=0 +#======================================================================= +private_colormap: enabled=0 + +#======================================================================= +# fullscreen: ONLY IMPLEMENTED ON AMIGA +# Request that Bochs occupy the entire screen instead of a +# window. +# +# Examples: +# fullscreen: enabled=0 +# fullscreen: enabled=1 +#======================================================================= +#fullscreen: enabled=0 +#screenmode: name="sample" + +#======================================================================= +# ne2k: NE2000 compatible ethernet adapter +# +# Format: +# ne2k: enabled=1, ioaddr=IOADDR, irq=IRQ, mac=MACADDR, ethmod=MODULE, +# ethdev=DEVICE, script=SCRIPT, bootrom=BOOTROM +# +# IOADDR, IRQ: You probably won't need to change ioaddr and irq, unless there +# are IRQ conflicts. These arguments are ignored when assign the ne2k to a +# PCI slot. +# +# MAC: The MAC address MUST NOT match the address of any machine on the net. +# Also, the first byte must be an even number (bit 0 set means a multicast +# address), and you cannot use ff:ff:ff:ff:ff:ff because that's the broadcast +# address. For the ethertap module, you must use fe:fd:00:00:00:01. There may +# be other restrictions too. To be safe, just use the b0:c4... address. +# +# ETHDEV: The ethdev value is the name of the network interface on your host +# platform. On UNIX machines, you can get the name by running ifconfig. On +# Windows machines, you must run niclist to get the name of the ethdev. +# Niclist source code is in misc/niclist.c and it is included in Windows +# binary releases. +# +# SCRIPT: The script value is optional, and is the name of a script that +# is executed after bochs initialize the network interface. You can use +# this script to configure this network interface, or enable masquerading. +# This is mainly useful for the tun/tap devices that only exist during +# Bochs execution. The network interface name is supplied to the script +# as first parameter. +# +# BOOTROM: The bootrom value is optional, and is the name of the ROM image +# to load. Note that this feature is only implemented for the PCI version of +# the NE2000. +# +# If you don't want to make connections to any physical networks, +# you can use the following 'ethmod's to simulate a virtual network. +# null: All packets are discarded, but logged to a few files. +# vde: Virtual Distributed Ethernet +# vnet: ARP, ICMP-echo(ping), DHCP and read/write TFTP are simulated. +# The virtual host uses 192.168.10.1. +# DHCP assigns 192.168.10.2 to the guest. +# TFTP uses the 'ethdev' value for the root directory and doesn't +# overwrite files. +# +#======================================================================= +# ne2k: ioaddr=0x300, irq=9, mac=fe:fd:00:00:00:01, ethmod=fbsd, ethdev=en0 #macosx +# ne2k: ioaddr=0x300, irq=9, mac=b0:c4:20:00:00:00, ethmod=fbsd, ethdev=xl0 +# ne2k: ioaddr=0x300, irq=9, mac=b0:c4:20:00:00:00, ethmod=linux, ethdev=eth0 +# ne2k: ioaddr=0x300, irq=9, mac=b0:c4:20:00:00:01, ethmod=win32, ethdev=MYCARD +# ne2k: ioaddr=0x300, irq=9, mac=fe:fd:00:00:00:01, ethmod=tap, ethdev=tap0 +# ne2k: ioaddr=0x300, irq=9, mac=fe:fd:00:00:00:01, ethmod=tuntap, ethdev=/dev/net/tun0, script=./tunconfig +# ne2k: ioaddr=0x300, irq=9, mac=b0:c4:20:00:00:01, ethmod=null, ethdev=eth0 +# ne2k: ioaddr=0x300, irq=9, mac=b0:c4:20:00:00:01, ethmod=vde, ethdev="/tmp/vde.ctl" +# ne2k: ioaddr=0x300, irq=9, mac=b0:c4:20:00:00:01, ethmod=vnet, ethdev="c:/temp" +# ne2k: mac=b0:c4:20:00:00:01, ethmod=slirp, script=/usr/local/bin/slirp, bootrom=ne2k_pci.rom + +#======================================================================= +# pcipnic: Bochs/Etherboot pseudo-NIC +# +# Format: +# pcipnic: enabled=1, mac=MACADDR, ethmod=MODULE, ethdev=DEVICE, script=SCRIPT, +# bootrom=BOOTROM +# +# The pseudo-NIC accepts the same syntax (for mac, ethmod, ethdev, script, +# bootrom) and supports the same networking modules as the NE2000 adapter. +#======================================================================= +#pcipnic: enabled=1, mac=b0:c4:20:00:00:00, ethmod=vnet + +#======================================================================= +# e1000: Intel(R) 82540EM Gigabit Ethernet adapter +# +# Format: +# e1000: enabled=1, mac=MACADDR, ethmod=MODULE, ethdev=DEVICE, script=SCRIPT +# bootrom=BOOTROM +# +# The E1000 accepts the same syntax (for mac, ethmod, ethdev, script, bootrom) +# and supports the same networking modules as the NE2000 adapter. +#======================================================================= +#e1000: enabled=1, mac=52:54:00:12:34:56, ethmod=slirp, script=/usr/local/bin/slirp + +#======================================================================= +# PCI: +# This option controls the presence of a PCI chipset in Bochs. Currently it only +# supports the i440FX chipset. You can also specify the devices connected to +# PCI slots. Up to 5 slots are available. For these combined PCI/ISA devices +# assigning to slot is mandatory if you want to emulate the PCI model: cirrus, +# ne2k and pcivga. These PCI-only devices are also supported, but they are +# auto-assigned if you don't use the slot configuration: e1000, es1370, pcidev, +# pcipnic, usb_ohci and usb_xhci. +# +# Example: +# pci: enabled=1, chipset=i440fx, slot1=pcivga, slot2=ne2k +#======================================================================= +pci: enabled=1, chipset=i440fx + +#======================================================================= +# USB_UHCI: +# This option controls the presence of the USB root hub which is a part +# of the i440FX PCI chipset. With the portX parameter you can connect devices +# to the hub (currently supported: 'mouse', 'tablet', 'keypad', 'disk', 'cdrom' +# 'hub' and 'printer'). +# +# The optionsX parameter can be used to assign specific options to the device +# connected to the corresponding USB port. Currently this feature is only used +# to set the speed reported by device and by the 'disk' device to specify +# an alternative redolog file of some image modes. +# +# If you connect the mouse or tablet to one of the ports, Bochs forwards the +# mouse movement data to the USB device instead of the selected mouse type. +# When connecting the keypad to one of the ports, Bochs forwards the input of +# the numeric keypad to the USB device instead of the PS/2 keyboard. +# +# To connect a 'flat' mode image as an USB hardisk you can use the 'disk' device +# with the path to the image separated with a colon. To use other disk image modes +# similar to ATA disks the syntax 'disk:mode:filename' must be used (see below). +# +# To emulate an USB cdrom you can use the 'cdrom' device name and the path to +# an ISO image or raw device name also separated with a colon. An option to +# insert/eject media is available in the runtime configuration. +# +# The device name 'hub' connects an external hub with max. 8 ports (default: 4) +# to the root hub. To specify the number of ports you have to add the value +# separated with a colon. Connecting devices to the external hub ports is only +# available in the runtime configuration. +# +# The device 'printer' emulates the HP Deskjet 920C printer. The PCL data is +# sent to a file specified in bochsrc.txt. The current code appends the PCL +# code to the file if the file already existed. It would probably be nice to +# overwrite the file instead, asking user first. +#======================================================================= +#usb_uhci: enabled=1 +#usb_uhci: enabled=1, port1=mouse, port2=disk:usbstick.img +#usb_uhci: enabled=1, port1=hub:7, port2=disk:growing:usbdisk.img +#usb_uhci: enabled=1, port2=disk:undoable:usbdisk.img, options1=journal:redo.log +#usb_uhci: enabled=1, port1=printer:printdata.bin, port2=cdrom:image.iso + +#======================================================================= +# USB_OHCI: +# This option controls the presence of the USB OHCI host controller with a +# 2-port hub. The portX option accepts the same device types with the same +# syntax as the UHCI controller (see above). +#======================================================================= +#usb_ohci: enabled=1 +#usb_ohci: enabled=1, port1=printer:usbprinter.bin + +#======================================================================= +# USB_XHCI: +# This option controls the presence of the experimental USB xHCI host controller +# with a 4-port hub. The portX option accepts the same device types with the +# same syntax as the UHCI controller (see above). +#======================================================================= +#usb_xhci: enabled=1 + +#======================================================================= +# CMOSIMAGE: +# This defines image file that can be loaded into the CMOS RAM at startup. +# The rtc_init parameter controls whether initialize the RTC with values stored +# in the image. By default the time0 argument given to the clock option is used. +# With 'rtc_init=image' the image is the source for the initial time. +# +# Example: +# cmosimage: file=cmos.img, rtc_init=image +#======================================================================= +#cmosimage: file=cmos.img, rtc_init=time0 + +#======================================================================= +# MAGIC_BREAK: +# This enables the "magic breakpoint" feature when using the debugger. +# The useless cpu instruction XCHG BX, BX causes Bochs to enter the +# debugger mode. This might be useful for software development. +# +# Example: +# magic_break: enabled=1 +#======================================================================= +#magic_break: enabled=1 + +#======================================================================= +# PORT_E9_HACK: +# The 0xE9 port doesn't exists in normal ISA architecture. However, we +# define a convention here, to display on the console of the system running +# Bochs anything that is written to it. The idea is to provide debug output +# very early when writing BIOS or OS code for example, without having to +# bother with setting up a serial port or etc. Reading from port 0xE9 will +# will return 0xe9 to let you know if the feature is available. +# Leave this 0 unless you have a reason to use it. +# +# Example: +# port_e9_hack: enabled=1 +#======================================================================= +#port_e9_hack: enabled=1 + +#======================================================================= +# DEBUG_SYMBOLS: +# This loads symbols from the specified file for use in Bochs' internal +# debugger. Symbols are loaded into global context. This is equivalent to +# issuing ldsym debugger command at start up. +# +# Example: +# debug_symbols: file="kernel.sym" +# debug_symbols: file="kernel.sym", offset=0x80000000 +#======================================================================= +#debug_symbols: file="kernel.sym" + +#======================================================================= +# other stuff +#======================================================================= +#load32bitOSImage: os=nullkernel, path=../kernel.img, iolog=../vga_io.log +#load32bitOSImage: os=linux, path=../linux.img, iolog=../vga_io.log, initrd=../initrd.img +#print_timestamps: enabled=1 + +#------------------------- +# PCI host device mapping +#------------------------- +#pcidev: vendor=0x1234, device=0x5678 + +#======================================================================= +# GDBSTUB: +# Enable GDB stub. See user documentation for details. +# Default value is enabled=0. +#======================================================================= +#gdbstub: enabled=0, port=1234, text_base=0, data_base=0, bss_base=0 + +#======================================================================= +# USER_PLUGIN: +# Load user-defined plugin. This option is available only if Bochs is +# compiled with plugin support. Maximum 8 different plugins are supported. +# See the example in the Bochs sources how to write a plugin device. +#======================================================================= +#user_plugin: name=testdev + +#======================================================================= +# for Macintosh, use the style of pathnames in the following +# examples. +# +# vgaromimage: :bios:VGABIOS-elpin-2.40 +# romimage: file=:bios:BIOS-bochs-latest, address=0xf0000 +# floppya: 1_44=[fd:], status=inserted +#======================================================================= + +#======================================================================= +# MEGS +# Set the number of Megabytes of physical memory you want to emulate. +# The default is 32MB, most OS's won't need more than that. +# The maximum amount of memory supported is 2048Mb. +# The 'MEGS' option is deprecated. Use 'MEMORY' option instead. +#======================================================================= +#megs: 256 +#megs: 128 +#megs: 64 +#megs: 32 +#megs: 16 +#megs: 8 diff --git a/competition-osdev-08-pajadam/manage.py b/competition-osdev-08-pajadam/manage.py new file mode 100755 index 0000000..a1a85ed --- /dev/null +++ b/competition-osdev-08-pajadam/manage.py @@ -0,0 +1,47 @@ +from scripts import build, run +import shutil +import sys +import os + + +def main(): + + try: + # Add missing directories if needed + for directory in ("tmp", "bin",): + if not os.path.exists(directory): + os.makedirs(directory) + + # Parse console arguments + if len(sys.argv) == 2: + os.chdir("tmp/") + if sys.argv[1] == "build": + build() + elif sys.argv[1] == "run": + run() + elif sys.argv[1] == "test": + build() + run() + elif sys.argv[1] == "clean": + os.chdir("..") + shutil.rmtree("tmp") + print "Cleaned ./tmp directory." + else: + raise ValueError("Invalid argument: " + sys.argv[1]) + else: + raise ValueError("Missing arguments") + + except ValueError as exc: + print exc + print "Usage:" + print " build\t- Build project" + print " run\t- Run project" + print " test\t- Build and run project" + print " clean\t- Clean temporary directory\n" + + except Exception as exc: + print exc + + +if __name__ == "__main__": + main() diff --git a/competition-osdev-08-pajadam/scripts/__init__.py b/competition-osdev-08-pajadam/scripts/__init__.py new file mode 100644 index 0000000..0ad21a4 --- /dev/null +++ b/competition-osdev-08-pajadam/scripts/__init__.py @@ -0,0 +1,2 @@ +from .build import * +from .run import * diff --git a/competition-osdev-08-pajadam/scripts/build.py b/competition-osdev-08-pajadam/scripts/build.py new file mode 100644 index 0000000..c718cbe --- /dev/null +++ b/competition-osdev-08-pajadam/scripts/build.py @@ -0,0 +1,80 @@ +#!/usr/bin/python +import os +import sys +import subprocess +from glob import glob + + +def fix_stage1_size(): + stage2_size = os.stat("stage2").st_size + kernel_size = os.stat("kernel64").st_size + + stage2_size = (stage2_size + kernel_size + 511) / 512 + + if stage2_size >= 255: + raise Exception("stage2 & kernel are too large") + + with open("stage1", "rb+") as f: + d = f.read() + idx = d.index("\xb0\xcc\x90\x90") + d = bytearray(d) + d[idx + 1] = stage2_size + f.seek(0) + f.write(d) + + +def build(): + """ Build disk image with OS """ + cmds_to_run = [] + + cc_flags = "-std=c99 -nostdlib -c -O0 -Wall -Wextra -masm=intel -ggdb" + ld_flags = "-std=c99 -nostdlib -o kernel64 -O0 -Wall -Wextra -masm=intel -ggdb" + + objfiles = [] + + for fname in glob("../src/os/*.c"): + cmds_to_run.append("gcc %s %s" % (fname, cc_flags)) + objfiles.append("%s.o" % os.path.basename(os.path.splitext(fname)[0])) + + as_flags = "-masm=intel -ggdb -c" + + for fname in glob("../src/os/*.s"): + cmds_to_run.append("gcc %s %s" % (fname, as_flags)) + objfiles.append("%s.o" % os.path.basename(os.path.splitext(fname)[0])) + + cmds_to_run.extend([ + "gcc %s %s" % (' '.join(objfiles), ld_flags), + "strip kernel64", + "nasm ../src/boot/stage1.asm -o stage1", + "nasm ../src/boot/stage2.asm -o stage2", + fix_stage1_size + ]) + + files_to_img = [ + "stage1", + "stage2", + "kernel64" + ] + + for cmd in cmds_to_run: + if type(cmd) is str: + print "Running:", cmd + print subprocess.check_output(cmd, shell=True) + else: + print "Calling:", cmd.func_name + cmd() + + buf = [] + for fn in files_to_img: + with open(fn, "rb") as f: + d = f.read() + buf.append(d) + + if len(d) % 512 == 0: + continue + + padding_size = 512 - len(d) % 512 + buf.append("\0" * padding_size) + + with open("../bin/floppy.bin", "wb") as f: + f.write(''.join(buf)) diff --git a/competition-osdev-08-pajadam/scripts/run.py b/competition-osdev-08-pajadam/scripts/run.py new file mode 100644 index 0000000..b111a01 --- /dev/null +++ b/competition-osdev-08-pajadam/scripts/run.py @@ -0,0 +1,13 @@ +from subprocess import call +import os + + +def run(): + if not os.path.exists('../conf/osdev.bochsrc'): + raise Exception('Missing bochs config!') + + if not os.path.exists('../bin/floppy.bin'): + raise Exception("Missing disk image.\nYou should run 'python manage.py build' first.") + + print "Running bochs..." + call('bochs -f "../conf/osdev.bochsrc"', shell=True) diff --git a/competition-osdev-08-pajadam/src/boot/stage1.asm b/competition-osdev-08-pajadam/src/boot/stage1.asm new file mode 100644 index 0000000..0168aa4 --- /dev/null +++ b/competition-osdev-08-pajadam/src/boot/stage1.asm @@ -0,0 +1,54 @@ +[bits 16] +[org 0x7c00] +; 0x7c00 +; SEGMENT:OFFSET +; adres = SEGMENT * 0x10 + OFFSET +; CS 07c0 0000 +; IP 0000 7c00 +; **** + +jmp word 0x0000:start + +start: + ;mov ax, 0xb800 + ;mov es, ax + ;xor di, di + ;mov word [es:di], 0x4141 + ;jmp $ + + ; Load from floppy stage 2. + ; DL == already set by BIOS + ; AX -- 16 bits, AH AL -- 8 bits + ; EAX -- AX + + mov ax, 0x2000 ; 0x2000:0x0000 + mov es, ax + xor bx, bx ; bx == 0 + + mov ah, 2 ; read sectors into memory + mov al, 0xcc ; 1337 stage2 3 * 512 + nop + nop + mov ch, 0 + mov cl, 2 ; sectors start from 1, or so they say ;) + mov dh, 0 + + int 13h + + ; Jump to stage 2 + jmp word 0x2000:0x0000 + + ; The CPU doesn't reach here. Ever. Hopefully. + +epilogue: +%if ($ - $$) > 510 + %fatal "Bootloader code exceed 512 bytes." +%endif + +times 510 - ($ - $$) db 0 +db 0x55 +db 0xAA + + + + diff --git a/competition-osdev-08-pajadam/src/boot/stage2.asm b/competition-osdev-08-pajadam/src/boot/stage2.asm new file mode 100644 index 0000000..6c9924a --- /dev/null +++ b/competition-osdev-08-pajadam/src/boot/stage2.asm @@ -0,0 +1,264 @@ +[bits 16] +[org 0x0000] + +start: + + ; SWITCH GRAPHIC MODE - Int 10 / AH=00h + ; 320X200 + mov ax, 0x0013 + int 0x10 + + ; enabling A20 - based on http://wiki.osdev.org/A20_Line + ; note: A20 activated by Bochs by default + mov ax, 0x2401 + int 0x15 + + ; http://wiki.osdev.org/A20_Line + ; Use BIOS to turn on A20 + ; mov ax, 0x2401 + ; int 0x15 + ; Use fast A20 gate + in al, 0x92 + or al, 2 + out 0x92, al + + ; Clear (disable) interrupts. + + cli + + mov ax, 0x2000 + mov ds, ax + mov es, ax + + mov ax, 0x1f00 + mov ss, ax + xor sp, sp + + ; A20 OSDev #4 + ; 0-19 0-23 + ; ffff:ffff --> ffff0 + ffff + ; 1024 * 1024 do (1024 * 1024 * 2 - 1) + + ; remove later + ;mov ax, 0xb800 ; 0xb8000 + ;mov fs, ax + ;mov bx, 0 + ;mov ax, 0x4141 + ;mov [fs:bx], ax + + ; ds, cs, ss, es + ; fs, gs + + ; idx-w-GDT, 1 bit GDT/LDT, 2 bit (0, 3) + ; Global Descriptor Table + ; Local + lgdt [GDT_addr] + + mov eax, cr0 + or eax, 1 + mov cr0, eax + + jmp dword 0x8:(0x20000+start32) + +start32: + [bits 32]32 + mov ax, 0x10 ; GDT_idx kolejne_3_bity + mov ds, ax + mov es, ax + mov ss, ax + + ;lea eax, [0xb8000] ; mov eax, 0xb8000 + + ;mov dword [eax], 0x41414141 + +; Vol 3, 4.5 IA-32e Paging +; http://os.phil-opp.com/entering-longmode.html (reenz0h) +; http://wiki.osdev.org/Setting_Up_Long_Mode +; Vol 3. 3.4.5 Segment Descriptors + + mov eax, (PML4 - $$) + 0x20000 + mov cr3, eax + + mov eax, cr4 + or eax, 1 << 5 + mov cr4, eax + + mov ecx, 0xC0000080 ; EFER + rdmsr + or eax, 1 << 8 + wrmsr + + mov eax, cr0 + or eax, 1 << 31 + mov cr0, eax + + lgdt [GDT64_addr + 0x20000] + jmp dword 0x8:(0x20000+start64) + +start64: + [bits 64] + mov ax, 0x10 ; GDT_idx kolejne_3_bity + mov ds, ax + mov es, ax + mov ss, ax + + ; Loader ELF +loader: + mov rsi, [0x20000 + kernel + 0x20] + add rsi, 0x20000 + kernel + + movzx ecx, word [0x20000 + kernel + 0x38] + + cld + + ; Assumes that the linker always stores ELF header at + ; first p_vaddr. + xor r14, r14 ; First PT_LOAD p_vaddr. + + .ph_loop: + mov eax, [rsi + 0] + cmp eax, 1 ; If it's not PT_LOAD, ignore. + jne .next + + mov r8, [rsi + 8] ; p_offset + mov r9, [rsi + 0x10] ; p_vaddr + mov r10, [rsi + 0x20] ; p_filesz + mov r11, [rsi + 0x28] ; p_memsz + + test r14, r14 + jnz .skip + mov r14, r9 + .skip: + + ; Backup + mov rbp, rsi + mov r15, rcx + + ; Zero memory + mov rdi, r9 + mov rcx, r11 + xor al, al + rep stosb + + ; Copy segment + lea rsi, [0x20000 + kernel + r8d] + mov rdi, r9 + mov rcx, r10 + rep movsb + + ; Restore + mov rcx, r15 + mov rsi, rbp + .next: + add rsi, 0x38 + loop .ph_loop + + ; Fix stack + mov rsp, 0x30f000 + + ; Jump to EP + mov rdi, r14 + mov rax, [0x20000 + kernel + 0x18] + call rax + + +GDT_addr: +dw (GDT_end - GDT) - 1 +dd 0x20000 + GDT + +times (32 - ($ - $$) % 32) db 0xcc + +; GLOBAL DESCRIPTOR TABLE 32-BIT +GDT: + +; Null segment +dd 0, 0 + +; Code segment +dd 0xffff ; segment limit +dd (10 << 8) | (1 << 12) | (1 << 15) | (0xf << 16) | (1 << 22) | (1 << 23) + +; Data segment +dd 0xffff ; segment limit +dd (2 << 8) | (1 << 12) | (1 << 15) | (0xf << 16) | (1 << 22) | (1 << 23) + +; Null segment +dd 0, 0 + +GDT_end: + + +; 64-bit GDT here! + +GDT64_addr: +dw (GDT64_end - GDT64) - 1 +dd 0x20000 + GDT64 + +times (32 - ($ - $$) % 32) db 0xcc + +; GLOBAL DESCRIPTOR TABLE 64-BIT +GDT64: + +; Null segment +dd 0, 0 + +; Code segment +dd 0xffff ; segment limit +dd (10 << 8) | (1 << 12) | (1 << 15) | (0xf << 16) | (1 << 21) | (1 << 23) + +; Data segment +dd 0xffff ; segment limit +dd (2 << 8) | (1 << 12) | (1 << 15) | (0xf << 16) | (1 << 21) | (1 << 23) + +; Null segment +dd 0, 0 + +GDT64_end: + +times (4096 - ($ - $$) % 4096) db 0 + + +; code by reenz0h +; https://github.com/reenz0h/osdev-by-gyn/tree/master/osdev3-addons + +;PML4: +;dq 1 | (1 << 1) | (PDPTE - $$ + 0x20000) +;times 511 dq 0 + +; Assume: aligned to 4 KB + +;PDPTE: +;dq 1 | (1 << 1) | (1 << 7) +;times 511 dq 0 + +; ------------------------------------------------------------- +; Level 4 TABLE - Page-Map Level-4 Table +PML4: +dq 1 | (1 << 1) | (PDPT - $$ + 0x20000) +times 511 dq 0x0 + +; 1 GB pages - initially tried by Gyn during #OSDev3 stream +; PDPT: +;dq 1 | (1 << 1) | (1 << 7) + +; Level 3 TABLE - Page-Directory Pointer Table +PDPT: +dq 1 | (1 << 1) | (PDT - $$ + 0x20000) +times 511 dq 0x0 + +; Level 2 TABLE - Page Directory Table +PDT: +; preprocessor loop dance... - mapping first 1GB == 512 * 0x200000 bytes +; 0x83 == 0x1 + 0x2 + 0x80 ---> Present/Writeablei/2MB page +%assign i 0 +%rep 512 + dq 0x200000*i+0x83 +%assign i i+1 +%endrep +; ------------------------------------------------------------- + + + + +times (512 - ($ - $$) % 512) db 0 +kernel: diff --git a/competition-osdev-08-pajadam/src/os/common.h b/competition-osdev-08-pajadam/src/os/common.h new file mode 100644 index 0000000..210b336 --- /dev/null +++ b/competition-osdev-08-pajadam/src/os/common.h @@ -0,0 +1,4 @@ +#pragma once +#define UNUSED(a) (void)(a) + +typedef unsigned long long size_t; diff --git a/competition-osdev-08-pajadam/src/os/crt.c b/competition-osdev-08-pajadam/src/os/crt.c new file mode 100644 index 0000000..338b003 --- /dev/null +++ b/competition-osdev-08-pajadam/src/os/crt.c @@ -0,0 +1,33 @@ +#include +#include "crt.h" + +void *memset(void *dst, int c, size_t n) { + uint8_t *dst_byte = (uint8_t*)dst; + for (size_t i = 0; i < n; i++) { + dst_byte[i] = (uint8_t)c; + } + + return dst; +} + +void *memmove(void *dst, const void *src, size_t n) { + uint8_t *dst_byte = (uint8_t*)dst; + const uint8_t *src_byte = (const uint8_t*)src; + if (dst < src) { + for (size_t i = 0; i < n; i++) { + dst_byte[i] = src_byte[i]; + } + } else { + size_t i = n - 1; + for (;;) { + dst_byte[i] = src_byte[i]; + if (i == 0) { + break; + } + i--; + } + } + + return dst; +} + diff --git a/competition-osdev-08-pajadam/src/os/crt.h b/competition-osdev-08-pajadam/src/os/crt.h new file mode 100644 index 0000000..ab1da0f --- /dev/null +++ b/competition-osdev-08-pajadam/src/os/crt.h @@ -0,0 +1,5 @@ +#pragma once +#include "common.h" + +void *memset(void *dst, int c, size_t n); +void *memmove(void *dst, const void *src, size_t n); diff --git a/competition-osdev-08-pajadam/src/os/font8x8_basic.h b/competition-osdev-08-pajadam/src/os/font8x8_basic.h new file mode 100644 index 0000000..6cf7c82 --- /dev/null +++ b/competition-osdev-08-pajadam/src/os/font8x8_basic.h @@ -0,0 +1,152 @@ +/** + * 8x8 monochrome bitmap fonts for rendering + * Author: Daniel Hepper + * + * License: Public Domain + * + * Based on: + * // Summary: font8x8.h + * // 8x8 monochrome bitmap fonts for rendering + * // + * // Author: + * // Marcel Sondaar + * // International Business Machines (public domain VGA fonts) + * // + * // License: + * // Public Domain + * + * Fetched from: http://dimensionalrift.homelinux.net/combuster/mos3/?p=viewsource&file=/modules/gfx/font8_8.asm + **/ + +// Constant: font8x8_basic +// Contains an 8x8 font map for unicode points U+0000 - U+007F (basic latin) +static const unsigned char font8x8_basic[128][8] = { + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0000 (nul) + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0001 + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0002 + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0003 + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0004 + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0005 + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0006 + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0007 + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0008 + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0009 + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+000A + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+000B + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+000C + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+000D + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+000E + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+000F + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0010 + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0011 + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0012 + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0013 + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0014 + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0015 + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0016 + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0017 + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0018 + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0019 + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+001A + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+001B + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+001C + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+001D + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+001E + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+001F + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0020 (space) + { 0x18, 0x3C, 0x3C, 0x18, 0x18, 0x00, 0x18, 0x00}, // U+0021 (!) + { 0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0022 (") + { 0x36, 0x36, 0x7F, 0x36, 0x7F, 0x36, 0x36, 0x00}, // U+0023 (#) + { 0x0C, 0x3E, 0x03, 0x1E, 0x30, 0x1F, 0x0C, 0x00}, // U+0024 ($) + { 0x00, 0x63, 0x33, 0x18, 0x0C, 0x66, 0x63, 0x00}, // U+0025 (%) + { 0x1C, 0x36, 0x1C, 0x6E, 0x3B, 0x33, 0x6E, 0x00}, // U+0026 (&) + { 0x06, 0x06, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0027 (') + { 0x18, 0x0C, 0x06, 0x06, 0x06, 0x0C, 0x18, 0x00}, // U+0028 (() + { 0x06, 0x0C, 0x18, 0x18, 0x18, 0x0C, 0x06, 0x00}, // U+0029 ()) + { 0x00, 0x66, 0x3C, 0xFF, 0x3C, 0x66, 0x00, 0x00}, // U+002A (*) + { 0x00, 0x0C, 0x0C, 0x3F, 0x0C, 0x0C, 0x00, 0x00}, // U+002B (+) + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0C, 0x06}, // U+002C (,) + { 0x00, 0x00, 0x00, 0x3F, 0x00, 0x00, 0x00, 0x00}, // U+002D (-) + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0C, 0x00}, // U+002E (.) + { 0x60, 0x30, 0x18, 0x0C, 0x06, 0x03, 0x01, 0x00}, // U+002F (/) + { 0x3E, 0x63, 0x73, 0x7B, 0x6F, 0x67, 0x3E, 0x00}, // U+0030 (0) + { 0x0C, 0x0E, 0x0C, 0x0C, 0x0C, 0x0C, 0x3F, 0x00}, // U+0031 (1) + { 0x1E, 0x33, 0x30, 0x1C, 0x06, 0x33, 0x3F, 0x00}, // U+0032 (2) + { 0x1E, 0x33, 0x30, 0x1C, 0x30, 0x33, 0x1E, 0x00}, // U+0033 (3) + { 0x38, 0x3C, 0x36, 0x33, 0x7F, 0x30, 0x78, 0x00}, // U+0034 (4) + { 0x3F, 0x03, 0x1F, 0x30, 0x30, 0x33, 0x1E, 0x00}, // U+0035 (5) + { 0x1C, 0x06, 0x03, 0x1F, 0x33, 0x33, 0x1E, 0x00}, // U+0036 (6) + { 0x3F, 0x33, 0x30, 0x18, 0x0C, 0x0C, 0x0C, 0x00}, // U+0037 (7) + { 0x1E, 0x33, 0x33, 0x1E, 0x33, 0x33, 0x1E, 0x00}, // U+0038 (8) + { 0x1E, 0x33, 0x33, 0x3E, 0x30, 0x18, 0x0E, 0x00}, // U+0039 (9) + { 0x00, 0x0C, 0x0C, 0x00, 0x00, 0x0C, 0x0C, 0x00}, // U+003A (:) + { 0x00, 0x0C, 0x0C, 0x00, 0x00, 0x0C, 0x0C, 0x06}, // U+003B (//) + { 0x18, 0x0C, 0x06, 0x03, 0x06, 0x0C, 0x18, 0x00}, // U+003C (<) + { 0x00, 0x00, 0x3F, 0x00, 0x00, 0x3F, 0x00, 0x00}, // U+003D (=) + { 0x06, 0x0C, 0x18, 0x30, 0x18, 0x0C, 0x06, 0x00}, // U+003E (>) + { 0x1E, 0x33, 0x30, 0x18, 0x0C, 0x00, 0x0C, 0x00}, // U+003F (?) + { 0x3E, 0x63, 0x7B, 0x7B, 0x7B, 0x03, 0x1E, 0x00}, // U+0040 (@) + { 0x0C, 0x1E, 0x33, 0x33, 0x3F, 0x33, 0x33, 0x00}, // U+0041 (A) + { 0x3F, 0x66, 0x66, 0x3E, 0x66, 0x66, 0x3F, 0x00}, // U+0042 (B) + { 0x3C, 0x66, 0x03, 0x03, 0x03, 0x66, 0x3C, 0x00}, // U+0043 (C) + { 0x1F, 0x36, 0x66, 0x66, 0x66, 0x36, 0x1F, 0x00}, // U+0044 (D) + { 0x7F, 0x46, 0x16, 0x1E, 0x16, 0x46, 0x7F, 0x00}, // U+0045 (E) + { 0x7F, 0x46, 0x16, 0x1E, 0x16, 0x06, 0x0F, 0x00}, // U+0046 (F) + { 0x3C, 0x66, 0x03, 0x03, 0x73, 0x66, 0x7C, 0x00}, // U+0047 (G) + { 0x33, 0x33, 0x33, 0x3F, 0x33, 0x33, 0x33, 0x00}, // U+0048 (H) + { 0x1E, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x1E, 0x00}, // U+0049 (I) + { 0x78, 0x30, 0x30, 0x30, 0x33, 0x33, 0x1E, 0x00}, // U+004A (J) + { 0x67, 0x66, 0x36, 0x1E, 0x36, 0x66, 0x67, 0x00}, // U+004B (K) + { 0x0F, 0x06, 0x06, 0x06, 0x46, 0x66, 0x7F, 0x00}, // U+004C (L) + { 0x63, 0x77, 0x7F, 0x7F, 0x6B, 0x63, 0x63, 0x00}, // U+004D (M) + { 0x63, 0x67, 0x6F, 0x7B, 0x73, 0x63, 0x63, 0x00}, // U+004E (N) + { 0x1C, 0x36, 0x63, 0x63, 0x63, 0x36, 0x1C, 0x00}, // U+004F (O) + { 0x3F, 0x66, 0x66, 0x3E, 0x06, 0x06, 0x0F, 0x00}, // U+0050 (P) + { 0x1E, 0x33, 0x33, 0x33, 0x3B, 0x1E, 0x38, 0x00}, // U+0051 (Q) + { 0x3F, 0x66, 0x66, 0x3E, 0x36, 0x66, 0x67, 0x00}, // U+0052 (R) + { 0x1E, 0x33, 0x07, 0x0E, 0x38, 0x33, 0x1E, 0x00}, // U+0053 (S) + { 0x3F, 0x2D, 0x0C, 0x0C, 0x0C, 0x0C, 0x1E, 0x00}, // U+0054 (T) + { 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x3F, 0x00}, // U+0055 (U) + { 0x33, 0x33, 0x33, 0x33, 0x33, 0x1E, 0x0C, 0x00}, // U+0056 (V) + { 0x63, 0x63, 0x63, 0x6B, 0x7F, 0x77, 0x63, 0x00}, // U+0057 (W) + { 0x63, 0x63, 0x36, 0x1C, 0x1C, 0x36, 0x63, 0x00}, // U+0058 (X) + { 0x33, 0x33, 0x33, 0x1E, 0x0C, 0x0C, 0x1E, 0x00}, // U+0059 (Y) + { 0x7F, 0x63, 0x31, 0x18, 0x4C, 0x66, 0x7F, 0x00}, // U+005A (Z) + { 0x1E, 0x06, 0x06, 0x06, 0x06, 0x06, 0x1E, 0x00}, // U+005B ([) + { 0x03, 0x06, 0x0C, 0x18, 0x30, 0x60, 0x40, 0x00}, // U+005C (\) + { 0x1E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1E, 0x00}, // U+005D (]) + { 0x08, 0x1C, 0x36, 0x63, 0x00, 0x00, 0x00, 0x00}, // U+005E (^) + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF}, // U+005F (_) + { 0x0C, 0x0C, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0060 (`) + { 0x00, 0x00, 0x1E, 0x30, 0x3E, 0x33, 0x6E, 0x00}, // U+0061 (a) + { 0x07, 0x06, 0x06, 0x3E, 0x66, 0x66, 0x3B, 0x00}, // U+0062 (b) + { 0x00, 0x00, 0x1E, 0x33, 0x03, 0x33, 0x1E, 0x00}, // U+0063 (c) + { 0x38, 0x30, 0x30, 0x3e, 0x33, 0x33, 0x6E, 0x00}, // U+0064 (d) + { 0x00, 0x00, 0x1E, 0x33, 0x3f, 0x03, 0x1E, 0x00}, // U+0065 (e) + { 0x1C, 0x36, 0x06, 0x0f, 0x06, 0x06, 0x0F, 0x00}, // U+0066 (f) + { 0x00, 0x00, 0x6E, 0x33, 0x33, 0x3E, 0x30, 0x1F}, // U+0067 (g) + { 0x07, 0x06, 0x36, 0x6E, 0x66, 0x66, 0x67, 0x00}, // U+0068 (h) + { 0x0C, 0x00, 0x0E, 0x0C, 0x0C, 0x0C, 0x1E, 0x00}, // U+0069 (i) + { 0x30, 0x00, 0x30, 0x30, 0x30, 0x33, 0x33, 0x1E}, // U+006A (j) + { 0x07, 0x06, 0x66, 0x36, 0x1E, 0x36, 0x67, 0x00}, // U+006B (k) + { 0x0E, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x1E, 0x00}, // U+006C (l) + { 0x00, 0x00, 0x33, 0x7F, 0x7F, 0x6B, 0x63, 0x00}, // U+006D (m) + { 0x00, 0x00, 0x1F, 0x33, 0x33, 0x33, 0x33, 0x00}, // U+006E (n) + { 0x00, 0x00, 0x1E, 0x33, 0x33, 0x33, 0x1E, 0x00}, // U+006F (o) + { 0x00, 0x00, 0x3B, 0x66, 0x66, 0x3E, 0x06, 0x0F}, // U+0070 (p) + { 0x00, 0x00, 0x6E, 0x33, 0x33, 0x3E, 0x30, 0x78}, // U+0071 (q) + { 0x00, 0x00, 0x3B, 0x6E, 0x66, 0x06, 0x0F, 0x00}, // U+0072 (r) + { 0x00, 0x00, 0x3E, 0x03, 0x1E, 0x30, 0x1F, 0x00}, // U+0073 (s) + { 0x08, 0x0C, 0x3E, 0x0C, 0x0C, 0x2C, 0x18, 0x00}, // U+0074 (t) + { 0x00, 0x00, 0x33, 0x33, 0x33, 0x33, 0x6E, 0x00}, // U+0075 (u) + { 0x00, 0x00, 0x33, 0x33, 0x33, 0x1E, 0x0C, 0x00}, // U+0076 (v) + { 0x00, 0x00, 0x63, 0x6B, 0x7F, 0x7F, 0x36, 0x00}, // U+0077 (w) + { 0x00, 0x00, 0x63, 0x36, 0x1C, 0x36, 0x63, 0x00}, // U+0078 (x) + { 0x00, 0x00, 0x33, 0x33, 0x33, 0x3E, 0x30, 0x1F}, // U+0079 (y) + { 0x00, 0x00, 0x3F, 0x19, 0x0C, 0x26, 0x3F, 0x00}, // U+007A (z) + { 0x38, 0x0C, 0x0C, 0x07, 0x0C, 0x0C, 0x38, 0x00}, // U+007B ({) + { 0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x00}, // U+007C (|) + { 0x07, 0x0C, 0x0C, 0x38, 0x0C, 0x0C, 0x07, 0x00}, // U+007D (}) + { 0x6E, 0x3B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+007E (~) + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // U+007F +}; diff --git a/competition-osdev-08-pajadam/src/os/hal.c b/competition-osdev-08-pajadam/src/os/hal.c new file mode 100644 index 0000000..47e810e --- /dev/null +++ b/competition-osdev-08-pajadam/src/os/hal.c @@ -0,0 +1,14 @@ +#include "hal.h" + +void HAL_PortOutByte(int port, unsigned char v) { + __asm("out dx, al\n" : : "a" (v), "d" (port)); +} + +void HAL_PortOutWord(int port, unsigned short v) { + __asm("out dx, ax\n" : : "a" (v), "d" (port)); +} + +void HAL_PortOutDword(int port, unsigned int v) { + __asm("out dx, eax\n" : : "a" (v), "d" (port)); +} + diff --git a/competition-osdev-08-pajadam/src/os/hal.h b/competition-osdev-08-pajadam/src/os/hal.h new file mode 100644 index 0000000..9a1ee70 --- /dev/null +++ b/competition-osdev-08-pajadam/src/os/hal.h @@ -0,0 +1,5 @@ +#pragma once +void HAL_PortOutByte(int port, unsigned char v); +void HAL_PortOutWord(int port, unsigned short v); +void HAL_PortOutDword(int port, unsigned int v); + diff --git a/competition-osdev-08-pajadam/src/os/idt.c b/competition-osdev-08-pajadam/src/os/idt.c new file mode 100644 index 0000000..dbf05d8 --- /dev/null +++ b/competition-osdev-08-pajadam/src/os/idt.c @@ -0,0 +1,52 @@ +#include +#include "idt.h" +#include "int_handlers.h" + +struct IDTEntry { + uint16_t offset_15_0; + uint16_t seg_selector; + uint16_t flags; + uint16_t offset_31_16; + uint32_t offset_63_32; + uint32_t reserved; +} __attribute__((packed)) ; + +typedef struct IDTEntry IDTEntry; + +#define IDTFLAGS(ist, type, dpl, p) \ + (ist | (type << 8) | (dpl << 13) | (p << 15)) + +#define OFFSET_15_0(func) ((uint64_t)func & 0xffff) +#define OFFSET_31_16(func) (((uint64_t)func & 0xffff0000) >> 16) +#define OFFSET_63_32(func) ((uint64_t)func >> 32) + +#define IDTITEM(e, func, ist) { \ + e.offset_15_0 = OFFSET_15_0(func); \ + e.seg_selector = 0x8; \ + e.flags = IDTFLAGS(ist, 0xE, 0, 1); \ + e.offset_31_16 = OFFSET_31_16(func); \ + e.offset_63_32 = OFFSET_63_32(func); \ + } + + +IDTEntry IDT[256]; + +struct IDTPtr { + uint16_t limit; + uint64_t ptr; +} __attribute__((packed)) ; +typedef struct IDTPtr IDTPtr; + +extern void Int_Wrapper_DE(void); + +void SetIDTR(void) { + IDTITEM(IDT[0], Int_Wrapper_DE, 0); + + IDTPtr ptr = { + 256 * 16 - 1, + (uint64_t)&IDT + }; + + __asm("lidt %0" : : "m"(ptr)); +} + diff --git a/competition-osdev-08-pajadam/src/os/idt.h b/competition-osdev-08-pajadam/src/os/idt.h new file mode 100644 index 0000000..5c9e6ea --- /dev/null +++ b/competition-osdev-08-pajadam/src/os/idt.h @@ -0,0 +1,4 @@ +#pragma once + +void SetIDTR(void); + diff --git a/competition-osdev-08-pajadam/src/os/int_handlers.c b/competition-osdev-08-pajadam/src/os/int_handlers.c new file mode 100644 index 0000000..ad6dfd0 --- /dev/null +++ b/competition-osdev-08-pajadam/src/os/int_handlers.c @@ -0,0 +1,97 @@ +#include "common.h" +#include "terminal.h" +#include "terminal_backend_b8000.h" + +// Thanks to Karol Grzybowski +typedef struct TrapFrame +{ + uint64_t r15; + uint64_t r14; + uint64_t r13; + uint64_t r12; + uint64_t r11; + uint64_t r10; + uint64_t r9; + uint64_t r8; + uint64_t rbp; + uint64_t rdi; + uint64_t rsi; + uint64_t rdx; + uint64_t rcx; + uint64_t rbx; + uint64_t rax; + uint64_t rsp; + + /*uint64_t trap_number; + uint64_t error_code;*/ + + uint64_t rip; + uint64_t segment_cs; + /*uint64_t rflags; + uint64_t rsp; + uint64_t segment_ss;*/ + +} TrapFrame; + +void GuruPanicOfDeath(const char *reason, TrapFrame *frame) +{ + TerminalBackend *con = TerminalBackendB8000(); + T_ClearScreen(con); + + for(int y = 0; y < 200; y++) + { + for(int x = 0; x < 320; x++) + { + setpixel(x, y, ((x + 1) / (y + 1)) % 140 + 110); + } + } + + T_SetColor(con, 15); + + T_PutText(con, "\n Opsy!"); + T_SetColor(con, 80); + T_PutText(con, "\t\t\t\t GynOS\n\n"); + T_SetColor(con, 28); + T_PutText(con, " Something went wrong!\n\n\n"); + + T_SetColor(con, 90); + T_PutText(con, " State:\n\n"); + + T_SetColor(con, 67); + T_Printf(con, " RAX: %x\t\t R8: %x\n", frame->rax, frame->r8); + T_SetColor(con, 66); + T_Printf(con, " RBX: %x\t\t R9: %x\n", frame->rbx, frame->r9); + T_SetColor(con, 67); + T_Printf(con, " RCX: %x\t\t R10: %x\n", frame->rcx, frame->r10); + T_SetColor(con, 66); + T_Printf(con, " RDX: %x\t\t R11: %x\n", frame->rdx, frame->r11); + T_SetColor(con, 67); + T_Printf(con, " RSI: %x\t\t R12: %x\n", frame->rsi, frame->r12); + T_SetColor(con, 66); + T_Printf(con, " RDI: %x\t\t R13: %x\n", frame->rdi, frame->r13); + T_SetColor(con, 67); + T_Printf(con, " RBP: %x\t\t R14: %x\n", frame->rbp, frame->r14); + T_SetColor(con, 66); + T_Printf(con, " RSP: %x\t\t R15: %x\n", frame->rsp, frame->r15); + + T_SetColor(con, 64); + T_PutText(con, "\n CS:RIP: "); + T_SetColor(con, 65); + T_Printf(con, "%x:%x\n\n", frame->segment_cs, frame->rip); + + T_SetColor(con, 42); + T_PutText(con, "\n\n Reason: "); + T_SetColor(con, 43); + T_Printf(con, "%s\n\n", reason); + + // TO BE REMOVED + T_SetColor(con, 51); + T_PutText(con, "\t\t\t by pajadam"); + for (;;) + ; +} + +void Int_DE(TrapFrame *frame) +{ + GuruPanicOfDeath("DIVISION_ERROR", frame); +} diff --git a/competition-osdev-08-pajadam/src/os/int_handlers.h b/competition-osdev-08-pajadam/src/os/int_handlers.h new file mode 100644 index 0000000..454e282 --- /dev/null +++ b/competition-osdev-08-pajadam/src/os/int_handlers.h @@ -0,0 +1,3 @@ +#pragma once +void Int_DE(void); + diff --git a/competition-osdev-08-pajadam/src/os/int_wrappers.s b/competition-osdev-08-pajadam/src/os/int_wrappers.s new file mode 100644 index 0000000..c7840a9 --- /dev/null +++ b/competition-osdev-08-pajadam/src/os/int_wrappers.s @@ -0,0 +1,51 @@ +.file "int_wrappers.s" +.intel_syntax noprefix + + +# by Karol Grzybowski +# https://pastebin.com/r79HA1qT + +.global Int_Wrapper_DE +.type Int_Wrapper_DE, @function +.text +Int_Wrapper_DE: + push rsp + push rax + push rbx + push rcx + push rdx + push rsi + push rdi + push rbp + push r8 + push r9 + push r10 + push r11 + push r12 + push r13 + push r14 + push r15 + + mov rdi, rsp + + call Int_DE@PLT + + pop r15 + pop r14 + pop r13 + pop r12 + pop r11 + pop r10 + pop r9 + pop r8 + pop rbp + pop rdi + pop rsi + pop rdx + pop rcx + pop rbx + pop rax + add rsp, 8 + + iretq + diff --git a/competition-osdev-08-pajadam/src/os/kernel.c b/competition-osdev-08-pajadam/src/os/kernel.c new file mode 100644 index 0000000..fc981c2 --- /dev/null +++ b/competition-osdev-08-pajadam/src/os/kernel.c @@ -0,0 +1,38 @@ +#include "common.h" +#include "idt.h" +#include "terminal.h" +#include "terminal_backend_b8000.h" + +int div(int a, int b) { + return a/b; +} + +void _start(void* kernel_location) { + UNUSED(kernel_location); + SetIDTR(); + + TerminalBackend *con = TerminalBackendB8000(); + + T_ClearScreen(con); + T_PutText(con, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\t\tXXXX\n"); + T_Printf(con, "%p %x %i %s %c %u\n", + con, 0x41424344, -1234, "alamakota", 'X', 1234567890123LL); + + + + //unsigned long long addr = (unsigned long long)kernel_location; + //unsigned long long addr = (unsigned long long)k; + //for (int i = 0; i < 16; i++) { + // textvram[i * 2] = "0123456789ABCDEF"[(addr >> 60) & 0xf]; + // addr <<= 4; + //} + + int a = 0, b = 0; + __asm__ volatile("div %2\n" + : "=d" (a), "=a" (b) + : "r" (a), "d" (a), "a" (a)); + + T_PutText(con, "It came back!"); + + for(;;); +} diff --git a/competition-osdev-08-pajadam/src/os/terminal.c b/competition-osdev-08-pajadam/src/os/terminal.c new file mode 100644 index 0000000..d2232c4 --- /dev/null +++ b/competition-osdev-08-pajadam/src/os/terminal.c @@ -0,0 +1,206 @@ +#include +#include "common.h" +#include "terminal.h" + +void T_SetCursorPosition( + TerminalBackend *tb, uint16_t x, uint16_t y) { + tb->func_set_cursor_position(tb, x, y); +} + +void T_SetColor(TerminalBackend *tb, unsigned char color) +{ + tb->func_set_color(tb, color); +} + +void T_PutText(TerminalBackend *tb, const char *s) { + for (; *s != '\0'; s++) { + switch (*s) { + case '\n': { + uint16_t x, y; + T_GetCursorPosition(tb, &x, &y); + T_SetCursorPosition(tb, 0, y + 1); + break; + } + + case '\r': { + uint16_t x, y; + T_GetCursorPosition(tb, &x, &y); + T_SetCursorPosition(tb, 0, y); + break; + } + + case '\t': { + uint16_t x, y; + uint16_t sx, sy; + T_GetCursorPosition(tb, &sx, &sy); + x = sx; y = sy; + + uint16_t w, h; + T_GetSize(tb, &w, &h); + + x += 8 - x % 8; + + if (x >= w) { + x = 0; + y += 1; + T_SetCursorPosition(tb, x, y); + } else { + for (uint16_t i = sx; i < x; i++) { + T_PutCharacter(tb, ' '); + } + } + break; + } + + default: + T_PutCharacter(tb, (unsigned char)*s); + } + } +} + +void T_ClearScreen(TerminalBackend *tb) { + tb->func_clear_screen(tb); +} + +void T_PutCharacter(TerminalBackend *tb, uint32_t ch) { + tb->func_put_character(tb, ch); +} + +void T_GetCursorPosition( + TerminalBackend *tb, uint16_t *x, uint16_t *y) { + tb->func_get_cursor_position(tb, x, y); +} + +void T_GetSize(TerminalBackend *tb, uint16_t *w, uint16_t *h) { + tb->func_get_size(tb, w, h); +} + +void T_PrintChar(TerminalBackend *tb, char ch) { + char buf[2] = { ch, '\0' }; + T_PutText(tb, buf); +} + +void T_PrintUInt(TerminalBackend *tb, size_t n) { + if (n == 0) { + T_PutCharacter(tb, '0'); + return; + } + + char buf[24] = {0}; + char *p = &buf[24]; + while (n != 0) { + --p; + *p = (n % 10) + '0'; + n /= 10; + } + T_PutText(tb, p); +} + +void T_PrintInt(TerminalBackend *tb, long long n) { + if (n == (-9223372036854775807LL - 1LL)) { + T_PutText(tb, "-9223372036854775808"); + return; + } + + if (n < 0) { + T_PrintChar(tb, '-'); + n = -n; + } + + if (n == 0) { + T_PutCharacter(tb, '0'); + return; + } + + char buf[24] = {0}; + char *p = &buf[23]; + while (n != 0) { + --p; + *p = (n % 10) + '0'; + n /= 10; + } + T_PutText(tb, p); +} + + +void T_PrintHex(TerminalBackend *tb, size_t n, int width) { + if (n == 0) { + T_PrintChar(tb, '0'); + return; + } + + int sh = 0; + while (width < 16 - sh && (n & 0xF000000000000000ULL) == 0) { + sh ++; + n <<= 4; + } + + while (sh < 16) { + size_t idx = (n & 0xF000000000000000ULL) >> 60; + T_PrintChar(tb, "0123456789abcdef"[idx]); + sh ++; + n <<= 4; + } +} + +void T_Printf(TerminalBackend *tb, const char *fmt, ...) { + va_list args; + va_start(args, fmt); + + const char *p = fmt; + + while (*p != '\0') { + if (*p != '%') { + T_PrintChar(tb, *p); + p++; + continue; + } + + p++; + + switch(*p) { + case 'p': + T_PrintHex(tb, va_arg(args, size_t), 16); + p++; + continue; + + case 'c': + T_PrintChar(tb, va_arg(args, int)); + p++; + continue; + + case 'i': + case 'd': + T_PrintInt(tb, va_arg(args, int)); + p++; + continue; + + case 'u': + T_PrintUInt(tb, va_arg(args, size_t)); + p++; + continue; + + case 'x': + T_PrintHex(tb, va_arg(args, size_t), 0); + p++; + continue; + + case 's': + T_PutText(tb, va_arg(args, const char*)); + p++; + continue; + + case '%': + T_PrintChar(tb, *p); + p++; + continue; + + default: + break; + } + } + + va_end(args); +} + + diff --git a/competition-osdev-08-pajadam/src/os/terminal.h b/competition-osdev-08-pajadam/src/os/terminal.h new file mode 100644 index 0000000..1eec5ce --- /dev/null +++ b/competition-osdev-08-pajadam/src/os/terminal.h @@ -0,0 +1,40 @@ +#pragma once +#include + +struct TerminalBackend; +typedef struct TerminalBackend TerminalBackend; + +// XXX on creation limit size to 32000x32000 + +typedef void (*TBfunc_SetCursorPosition)( + TerminalBackend *tb, uint16_t x, uint16_t y); +typedef void (*TBfunc_GetCursorPosition)( + TerminalBackend *tb, uint16_t *x, uint16_t *y); +typedef void (*TBfunc_ClearScreen)(TerminalBackend *tb); +typedef void (*TBfunc_PutCharacter)(TerminalBackend *tb, uint32_t ch); +typedef void (*TBfunc_GetSize)(TerminalBackend *tb, + uint16_t *w, uint16_t *h); +typedef void (*TBfunc_ScrollLine)(TerminalBackend *tb); +typedef void (*TBfunc_SetColor)(TerminalBackend *tb, unsigned char color); + +struct TerminalBackend { + TBfunc_SetCursorPosition func_set_cursor_position; + TBfunc_GetCursorPosition func_get_cursor_position; + TBfunc_ClearScreen func_clear_screen; + TBfunc_PutCharacter func_put_character; + TBfunc_GetSize func_get_size; + TBfunc_ScrollLine func_scroll_line; + TBfunc_SetColor func_set_color; + void *backend_data; +}; + +void T_SetCursorPosition( + TerminalBackend *tb, uint16_t x, uint16_t y); +void T_GetCursorPosition( + TerminalBackend *tb, uint16_t *x, uint16_t *y); +void T_PutText(TerminalBackend *tb, const char *s); +void T_ClearScreen(TerminalBackend *tb); +void T_PutCharacter(TerminalBackend *tb, uint32_t ch); +void T_GetSize(TerminalBackend *tb, uint16_t *w, uint16_t *h); +void T_Printf(TerminalBackend *tb, const char *fmt, ...); +void T_ScrollLine(TerminalBackend *tb); diff --git a/competition-osdev-08-pajadam/src/os/terminal_backend_b8000.c b/competition-osdev-08-pajadam/src/os/terminal_backend_b8000.c new file mode 100644 index 0000000..ba7517c --- /dev/null +++ b/competition-osdev-08-pajadam/src/os/terminal_backend_b8000.c @@ -0,0 +1,120 @@ +#include "common.h" +#include "crt.h" +#include "hal.h" +#include "terminal.h" +#include "vga.h" + +enum +{ + kVGAControlRegisterIndex_CursorLocationHigh = 0xe, + kVGAControlRegisterIndex_CursorLocationLow = 0xf, +}; + +enum +{ + kPortVGAControlRegisterIndex = 0x3d4, + kPortVGAControlDataRegister = 0x3d5 +}; + +static struct B8000_ContextStruct +{ + unsigned short x; + unsigned short y; + unsigned char color; +} B8000_Context; + +static void B8000_ScrollLine(TerminalBackend *tb); + +static void B8000_SetColor(TerminalBackend *tb, unsigned char color) +{ + B8000_Context.color = color; +} + +static void B8000_SetCursorPosition( + TerminalBackend *tb, uint16_t x, uint16_t y) +{ + UNUSED(tb); + + B8000_Context.x = x; + B8000_Context.y = y; +} + +static void B8000_ClearScreen(TerminalBackend *tb) +{ + UNUSED(tb); + clearscreen(); + + B8000_SetCursorPosition(tb, 0, 0); +} + +static void B8000_PutCharacter(TerminalBackend *tb, uint32_t ch) +{ + UNUSED(tb); + + unsigned short x = B8000_Context.x; + unsigned short y = B8000_Context.y; + unsigned char color = B8000_Context.color; + + if (y == 25) + { + B8000_ScrollLine(tb); + x = B8000_Context.x; + y = B8000_Context.y; + } + + drawfgchar(ch, x, y, color); + + x += 1; + if (x == 40) + { + x = 0; + y += 1; + } + + B8000_SetCursorPosition(tb, x, y); +} + +static void B8000_GetCursorPosition( + TerminalBackend *tb, uint16_t *x, uint16_t *y) +{ + UNUSED(tb); + *x = B8000_Context.x; + *y = B8000_Context.y; +} + +static void B8000_GetSize(TerminalBackend *tb, + uint16_t *w, uint16_t *h) +{ + UNUSED(tb); + *w = 40; + *h = 25; +} + +static void B8000_ScrollLine(TerminalBackend *tb) +{ + unsigned char *mvram = (unsigned char *)0xA0000; + memmove(mvram, mvram + 320 * 8, 320 * (200 - 1)); + + for(int x = 0; x < 40; x++) + { + drawchar(' ', x, 25, 0, 0); + } + + B8000_SetCursorPosition(tb, 0, 25 - 1); +} + +static const TerminalBackend B8000_Functions = { + .func_set_cursor_position = B8000_SetCursorPosition, + .func_get_cursor_position = B8000_GetCursorPosition, + .func_clear_screen = B8000_ClearScreen, + .func_put_character = B8000_PutCharacter, + .func_get_size = B8000_GetSize, + .func_scroll_line = B8000_ScrollLine, + .func_set_color = B8000_SetColor}; + +TerminalBackend *TerminalBackendB8000(void) +{ + // It's just a function table, so we declared it as const. + // But we pass it as non-const to the functions. + return (TerminalBackend *)&B8000_Functions; +} diff --git a/competition-osdev-08-pajadam/src/os/terminal_backend_b8000.h b/competition-osdev-08-pajadam/src/os/terminal_backend_b8000.h new file mode 100644 index 0000000..6d5a165 --- /dev/null +++ b/competition-osdev-08-pajadam/src/os/terminal_backend_b8000.h @@ -0,0 +1,6 @@ +#pragma once +#include "terminal.h" + +TerminalBackend *TerminalBackendB8000(void); + + diff --git a/competition-osdev-08-pajadam/src/os/vga.c b/competition-osdev-08-pajadam/src/os/vga.c new file mode 100644 index 0000000..1f086d5 --- /dev/null +++ b/competition-osdev-08-pajadam/src/os/vga.c @@ -0,0 +1,74 @@ +#include "vga.h" + +unsigned char *vram = (unsigned char *)0xA0000; + +// Set pixel. +void setpixel(int x, int y, int color) +{ + //do not write memory outside the screen buffer, check parameters against the VBE mode info + if (x < 0 || x > WIDTH || y < 0 || y > HEIGHT) + return; + + if (x) + x = (x * (BITS >> 3)); + if (y) + y = (y * WIDTH); + + register char *cTemp; + cTemp = &vram[x + y]; + cTemp[0] = color & 0xff; +} + +// Fill screen with black color. +void clearscreen() +{ + for (int x = 0; x < WIDTH; x++) + for (int y = 0; y < HEIGHT; y++) + setpixel(x, y, 0); +} + +// Fill screen with given color. +void fillscreen(int color) +{ + for (int x = 0; x < WIDTH; x++) + for (int y = 0; y < HEIGHT; y++) + setpixel(x, y, color); +} + +// Draw character with FGColor and BGColor +void drawchar(unsigned char c, int x, int y, int fgcolor, int bgcolor) +{ + int cx, cy; + int mask[8] = {1, 2, 4, 8, 16, 32, 64, 128}; + + for (cx = 0; cx < 8; cx++) + { + for (cy = 0; cy < 8; cy++) + { + setpixel( + x * 8 + cx, + y * 8 + cy, + font8x8_basic[((int)c)][cy] & mask[cx] ? fgcolor : bgcolor); + } + } +} + +// Draw character with transparent background +void drawfgchar(unsigned char c, int x, int y, int fgcolor) +{ + int cx, cy; + int mask[8] = {1, 2, 4, 8, 16, 32, 64, 128}; + + for (cx = 0; cx < 8; cx++) + { + for (cy = 0; cy < 8; cy++) + { + if (font8x8_basic[((int)c)][cy] & mask[cx]) + setpixel( + x * 8 + cx, + y * 8 + cy, + fgcolor + ); + } + } +} diff --git a/competition-osdev-08-pajadam/src/os/vga.h b/competition-osdev-08-pajadam/src/os/vga.h new file mode 100644 index 0000000..0d925aa --- /dev/null +++ b/competition-osdev-08-pajadam/src/os/vga.h @@ -0,0 +1,13 @@ +#pragma once + +#include "font8x8_basic.h" + +#define WIDTH 320 +#define HEIGHT 200 +#define BITS 8 + +void setpixel(int x, int y, int color); +void clearscreen(); +void fillscreen(int color); +void drawchar(unsigned char c, int x, int y, int fgcolor, int bgcolor); +void drawfgchar(unsigned char c, int x, int y, int fgcolor); \ No newline at end of file