Initial Commit.
This commit is contained in:
commit
9a811106f3
36 changed files with 1109 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
Abraham Silberschatz-Operating System Concepts (9th,2012.12).pdf
|
||||
DevEnv/
|
BIN
MP1/MP1_Sources.zip
Normal file
BIN
MP1/MP1_Sources.zip
Normal file
Binary file not shown.
BIN
MP1/MP1_Sources/.DS_Store
vendored
Normal file
BIN
MP1/MP1_Sources/.DS_Store
vendored
Normal file
Binary file not shown.
BIN
MP1/MP1_Sources/BIOS-bochs-latest
Normal file
BIN
MP1/MP1_Sources/BIOS-bochs-latest
Normal file
Binary file not shown.
54
MP1/MP1_Sources/README.TXT
Normal file
54
MP1/MP1_Sources/README.TXT
Normal file
|
@ -0,0 +1,54 @@
|
|||
CSCE 410/611/613: MP1 -- README.TXT
|
||||
|
||||
This file describes the content of this directory.
|
||||
A file marked with (*) may be of some interest to the
|
||||
student, and he/she may want to have a look at it.
|
||||
A file marked with (**) is important for this MP, and the
|
||||
student is strongly encouraged to study the contents of this file.
|
||||
|
||||
BOCH Environment:
|
||||
=================
|
||||
|
||||
FILE: DESCRIPTION:
|
||||
|
||||
BIOS-bochs-latest BIOS file.
|
||||
VGABIOS-lgpl-latest BIOS file for the graphics system.
|
||||
dev_kernel_grub.img Image file of the boot floopy.
|
||||
bochsrc.bxrc Description file for the system.
|
||||
(windows) doube-click this file to start emulation.
|
||||
(linux) type 'bochs -f bochsrc.bxrc' to
|
||||
start emulation.
|
||||
|
||||
COMPILATION:
|
||||
===========
|
||||
|
||||
FILE: DESCRIPTION:
|
||||
|
||||
makefile Makefile for Linux 64-bit
|
||||
environment. Works with the provided
|
||||
linux image.
|
||||
linker.ld the linker script.
|
||||
|
||||
OS COMPONENTS:
|
||||
=============
|
||||
|
||||
FILE: DESCRIPTION:
|
||||
|
||||
start.asm (*) The bootloader starts code in this file, which in turn
|
||||
jumps to the main entry in File "kernel.C".
|
||||
kernel.C (**) Main file, where the OS components are set up, and the
|
||||
system gets going.
|
||||
utils.H/C Various utilities (e.g. memcpy, strlen, etc..)
|
||||
console.H/C Routines to print to the screen.
|
||||
|
||||
UTILITIES:
|
||||
==========
|
||||
|
||||
FILE: DESCRIPTION:
|
||||
|
||||
copykernel.sh (**) (linux) Simple script to copy the kernel onto
|
||||
the floppy image on linux.
|
||||
The script mounts the floppy image, copies the kernel
|
||||
image onto it, and then unmounts the floppy image again.
|
||||
The paths in the file may need to be edited to make them
|
||||
reflect the student's environment.
|
BIN
MP1/MP1_Sources/VGABIOS-lgpl-latest
Normal file
BIN
MP1/MP1_Sources/VGABIOS-lgpl-latest
Normal file
Binary file not shown.
235
MP1/MP1_Sources/bochsout.txt
Normal file
235
MP1/MP1_Sources/bochsout.txt
Normal file
|
@ -0,0 +1,235 @@
|
|||
00000000000i[ ] Bochs x86 Emulator 2.4.6
|
||||
00000000000i[ ] Build from CVS snapshot, on February 22, 2011
|
||||
00000000000i[ ] Compiled at Nov 11 2011, 09:31:18
|
||||
00000000000i[ ] System configuration
|
||||
00000000000i[ ] processors: 1 (cores=1, HT threads=1)
|
||||
00000000000i[ ] A20 line support: yes
|
||||
00000000000i[ ] CPU configuration
|
||||
00000000000i[ ] level: 6
|
||||
00000000000i[ ] SMP support: no
|
||||
00000000000i[ ] APIC support: yes
|
||||
00000000000i[ ] FPU support: yes
|
||||
00000000000i[ ] MMX support: yes
|
||||
00000000000i[ ] 3dnow! support: no
|
||||
00000000000i[ ] SEP support: yes
|
||||
00000000000i[ ] SSE support: sse2
|
||||
00000000000i[ ] XSAVE support: no
|
||||
00000000000i[ ] AES support: no
|
||||
00000000000i[ ] MOVBE support: no
|
||||
00000000000i[ ] x86-64 support: yes
|
||||
00000000000i[ ] 1G paging support: no
|
||||
00000000000i[ ] VMX support: no
|
||||
00000000000i[ ] Optimization configuration
|
||||
00000000000i[ ] RepeatSpeedups support: yes
|
||||
00000000000i[ ] Trace cache support: yes
|
||||
00000000000i[ ] Fast function calls: yes
|
||||
00000000000i[ ] Devices configuration
|
||||
00000000000i[ ] ACPI support: yes
|
||||
00000000000i[ ] NE2000 support: yes
|
||||
00000000000i[ ] PCI support: yes, enabled=yes
|
||||
00000000000i[ ] SB16 support: yes
|
||||
00000000000i[ ] USB support: yes
|
||||
00000000000i[ ] VGA extension support: vbe
|
||||
00000000000i[MEM0 ] allocated memory at 0x7f59a881c010. after alignment, vector=0x7f59a881d000
|
||||
00000000000i[MEM0 ] 32.00MB
|
||||
00000000000i[MEM0 ] mem block size = 0x00100000, blocks=32
|
||||
00000000000i[MEM0 ] rom at 0xfffe0000/131072 ('BIOS-bochs-latest')
|
||||
00000000000i[MEM0 ] rom at 0xc0000/38400 ('VGABIOS-lgpl-latest')
|
||||
00000000000i[ ] lt_dlhandle is 0x2b1e550
|
||||
00000000000i[PLGIN] loaded plugin libbx_cmos.so
|
||||
00000000000i[ ] lt_dlhandle is 0x2b1ef70
|
||||
00000000000i[PLGIN] loaded plugin libbx_dma.so
|
||||
00000000000i[ ] lt_dlhandle is 0x2b1f9d0
|
||||
00000000000i[PLGIN] loaded plugin libbx_pic.so
|
||||
00000000000i[ ] lt_dlhandle is 0x2b20210
|
||||
00000000000i[PLGIN] loaded plugin libbx_pit.so
|
||||
00000000000i[ ] lt_dlhandle is 0x2b20b80
|
||||
00000000000i[PLGIN] loaded plugin libbx_vga.so
|
||||
00000000000i[ ] lt_dlhandle is 0x2b212b0
|
||||
00000000000i[PLGIN] loaded plugin libbx_hdimage.so
|
||||
00000000000i[ ] lt_dlhandle is 0x2b21b70
|
||||
00000000000i[PLGIN] loaded plugin libbx_floppy.so
|
||||
00000000000i[ ] lt_dlhandle is 0x2b22760
|
||||
00000000000i[PLGIN] loaded plugin libbx_soundmod.so
|
||||
00000000000i[ ] lt_dlhandle is 0x2b23db0
|
||||
00000000000i[PLGIN] loaded plugin libbx_pci.so
|
||||
00000000000i[ ] lt_dlhandle is 0x2b249e0
|
||||
00000000000i[PLGIN] loaded plugin libbx_pci2isa.so
|
||||
00000000000i[ ] lt_dlhandle is 0x2b252c0
|
||||
00000000000i[PLGIN] loaded plugin libbx_usb_common.so
|
||||
00000000000i[ ] lt_dlhandle is 0x2b25b20
|
||||
00000000000i[PLGIN] loaded plugin libbx_unmapped.so
|
||||
00000000000i[ ] lt_dlhandle is 0x2b26390
|
||||
00000000000i[PLGIN] loaded plugin libbx_biosdev.so
|
||||
00000000000i[ ] lt_dlhandle is 0x2b26cc0
|
||||
00000000000i[PLGIN] loaded plugin libbx_speaker.so
|
||||
00000000000i[ ] lt_dlhandle is 0x2b274f0
|
||||
00000000000i[PLGIN] loaded plugin libbx_extfpuirq.so
|
||||
00000000000i[ ] lt_dlhandle is 0x2b27d60
|
||||
00000000000i[PLGIN] loaded plugin libbx_gameport.so
|
||||
00000000000i[ ] lt_dlhandle is 0x2b286d0
|
||||
00000000000i[PLGIN] loaded plugin libbx_pci_ide.so
|
||||
00000000000i[ ] lt_dlhandle is 0x2b290a0
|
||||
00000000000i[PLGIN] loaded plugin libbx_acpi.so
|
||||
00000000000i[ ] lt_dlhandle is 0x2b299e0
|
||||
00000000000i[PLGIN] loaded plugin libbx_ioapic.so
|
||||
00000000000i[ ] lt_dlhandle is 0x2b2a390
|
||||
00000000000i[PLGIN] loaded plugin libbx_keyboard.so
|
||||
00000000000i[ ] lt_dlhandle is 0x2b2ab90
|
||||
00000000000i[PLGIN] loaded plugin libbx_harddrv.so
|
||||
00000000000i[ ] lt_dlhandle is 0x2b3cc60
|
||||
00000000000i[PLGIN] loaded plugin libbx_serial.so
|
||||
00000000000i[ ] lt_dlhandle is 0x2b3dad0
|
||||
00000000000i[PLGIN] loaded plugin libbx_parallel.so
|
||||
00000000000i[CMOS ] Using local time for initial clock
|
||||
00000000000i[CMOS ] Setting initial clock to: Mon May 29 17:37:28 2017 (time0=1496097448)
|
||||
00000000000i[DMA ] channel 4 used by cascade
|
||||
00000000000i[DMA ] channel 2 used by Floppy Drive
|
||||
00000000000i[FDD ] fd0: 'dev_kernel_grub.img' ro=0, h=2,t=80,spt=18
|
||||
00000000000i[PCI ] 440FX Host bridge present at device 0, function 0
|
||||
00000000000i[PCI ] PIIX3 PCI-to-ISA bridge present at device 1, function 0
|
||||
00000000000i[VGA ] interval=50000
|
||||
00000000000i[MEM0 ] Register memory access handlers: 0x00000000000a0000 - 0x00000000000bffff
|
||||
00000000000i[XGUI ] test_alloc_colors: 16 colors available out of 16 colors tried
|
||||
00000000000i[XGUI ] font 8 wide x 16 high, display depth = 24
|
||||
00000000000i[MEM0 ] Register memory access handlers: 0x00000000e0000000 - 0x00000000e0ffffff
|
||||
00000000000i[VGA ] VBE Bochs Display Extension Enabled
|
||||
00000000000i[PLGIN] init_dev of 'unmapped' plugin device by virtual method
|
||||
00000000000i[PLGIN] init_dev of 'biosdev' plugin device by virtual method
|
||||
00000000000i[PLGIN] init_dev of 'speaker' plugin device by virtual method
|
||||
00000000000i[SPEAK] Failed to open /dev/console: Resource temporarily unavailable
|
||||
00000000000i[SPEAK] Deactivating beep on console
|
||||
00000000000i[PLGIN] init_dev of 'extfpuirq' plugin device by virtual method
|
||||
00000000000i[PLGIN] init_dev of 'gameport' plugin device by virtual method
|
||||
00000000000i[PLGIN] init_dev of 'pci_ide' plugin device by virtual method
|
||||
00000000000i[PCI ] PIIX3 PCI IDE controller present at device 1, function 1
|
||||
00000000000i[PLGIN] init_dev of 'acpi' plugin device by virtual method
|
||||
00000000000i[PCI ] ACPI Controller present at device 1, function 3
|
||||
00000000000i[PLGIN] init_dev of 'ioapic' plugin device by virtual method
|
||||
00000000000i[IOAP ] initializing I/O APIC
|
||||
00000000000i[MEM0 ] Register memory access handlers: 0x00000000fec00000 - 0x00000000fec00fff
|
||||
00000000000i[PLGIN] init_dev of 'keyboard' plugin device by virtual method
|
||||
00000000000i[KBD ] will paste characters every 1000 keyboard ticks
|
||||
00000000000i[PLGIN] init_dev of 'harddrv' plugin device by virtual method
|
||||
00000000000i[HD ] Using boot sequence floppy, none, none
|
||||
00000000000i[HD ] Floppy boot signature check is enabled
|
||||
00000000000i[PLGIN] init_dev of 'serial' plugin device by virtual method
|
||||
00000000000i[SER ] com1 at 0x03f8 irq 4
|
||||
00000000000i[PLGIN] init_dev of 'parallel' plugin device by virtual method
|
||||
00000000000i[PAR ] parallel port 1 at 0x0378 irq 7
|
||||
00000000000i[PLGIN] register state of 'unmapped' plugin device by virtual method
|
||||
00000000000i[PLGIN] register state of 'biosdev' plugin device by virtual method
|
||||
00000000000i[PLGIN] register state of 'speaker' plugin device by virtual method
|
||||
00000000000i[PLGIN] register state of 'extfpuirq' plugin device by virtual method
|
||||
00000000000i[PLGIN] register state of 'gameport' plugin device by virtual method
|
||||
00000000000i[PLGIN] register state of 'pci_ide' plugin device by virtual method
|
||||
00000000000i[PLGIN] register state of 'acpi' plugin device by virtual method
|
||||
00000000000i[PLGIN] register state of 'ioapic' plugin device by virtual method
|
||||
00000000000i[PLGIN] register state of 'keyboard' plugin device by virtual method
|
||||
00000000000i[PLGIN] register state of 'harddrv' plugin device by virtual method
|
||||
00000000000i[PLGIN] register state of 'serial' plugin device by virtual method
|
||||
00000000000i[PLGIN] register state of 'parallel' plugin device by virtual method
|
||||
00000000000i[SYS ] bx_pc_system_c::Reset(HARDWARE) called
|
||||
00000000000i[CPU0 ] cpu hardware reset
|
||||
00000000000i[APIC0] allocate APIC id=0 (MMIO enabled) to 0x00000000fee00000
|
||||
00000000000i[CPU0 ] CPUID[0x00000000]: 00000003 756e6547 6c65746e 49656e69
|
||||
00000000000i[CPU0 ] CPUID[0x00000001]: 00000f23 00000800 00002000 07cbfbff
|
||||
00000000000i[CPU0 ] CPUID[0x00000002]: 00410601 00000000 00000000 00000000
|
||||
00000000000i[CPU0 ] CPUID[0x00000003]: 00000000 00000000 00000000 00000000
|
||||
00000000000i[CPU0 ] CPUID[0x00000004]: 00000000 00000000 00000000 00000000
|
||||
00000000000i[CPU0 ] CPUID[0x00000007]: 00000000 00000000 00000000 00000000
|
||||
00000000000i[CPU0 ] CPUID[0x80000000]: 80000008 00000000 00000000 00000000
|
||||
00000000000i[CPU0 ] CPUID[0x80000001]: 00000000 00000000 00000001 2a100800
|
||||
00000000000i[CPU0 ] CPUID[0x80000002]: 20202020 20202020 20202020 6e492020
|
||||
00000000000i[CPU0 ] CPUID[0x80000003]: 286c6574 50202952 69746e65 52286d75
|
||||
00000000000i[CPU0 ] CPUID[0x80000004]: 20342029 20555043 20202020 00202020
|
||||
00000000000i[CPU0 ] CPUID[0x80000006]: 00000000 42004200 02008140 00000000
|
||||
00000000000i[CPU0 ] CPUID[0x80000007]: 00000000 00000000 00000000 00000000
|
||||
00000000000i[CPU0 ] CPUID[0x80000008]: 00003028 00000000 00000000 00000000
|
||||
00000000000i[PLGIN] reset of 'unmapped' plugin device by virtual method
|
||||
00000000000i[PLGIN] reset of 'biosdev' plugin device by virtual method
|
||||
00000000000i[PLGIN] reset of 'speaker' plugin device by virtual method
|
||||
00000000000i[PLGIN] reset of 'extfpuirq' plugin device by virtual method
|
||||
00000000000i[PLGIN] reset of 'gameport' plugin device by virtual method
|
||||
00000000000i[PLGIN] reset of 'pci_ide' plugin device by virtual method
|
||||
00000000000i[PLGIN] reset of 'acpi' plugin device by virtual method
|
||||
00000000000i[PLGIN] reset of 'ioapic' plugin device by virtual method
|
||||
00000000000i[PLGIN] reset of 'keyboard' plugin device by virtual method
|
||||
00000000000i[PLGIN] reset of 'harddrv' plugin device by virtual method
|
||||
00000000000i[PLGIN] reset of 'serial' plugin device by virtual method
|
||||
00000000000i[PLGIN] reset of 'parallel' plugin device by virtual method
|
||||
00000000000i[XGUI ] [x] Mouse off
|
||||
00000003302i[BIOS ] $Revision: 1.209 $ $Date: 2008/06/02 20:08:10 $
|
||||
00000318057i[KBD ] reset-disable command received
|
||||
00000438667i[VBIOS] VGABios $Id: vgabios.c,v 1.67 2008/01/27 09:44:12 vruppert Exp $
|
||||
00000438738i[VGA ] VBE known Display Interface b0c0
|
||||
00000438770i[VGA ] VBE known Display Interface b0c4
|
||||
00000441695i[VBIOS] VBE Bios $Id: vbe.c,v 1.60 2008/03/02 07:47:21 vruppert Exp $
|
||||
00000600000i[XGUI ] charmap update. Font Height is 16
|
||||
00000764696i[BIOS ] Starting rombios32
|
||||
00000765523i[BIOS ] ram_size=0x02000000
|
||||
00000805868i[BIOS ] Found 1 cpu(s)
|
||||
00000822169i[BIOS ] bios_table_addr: 0x000fb778 end=0x000fcc00
|
||||
00000822236i[PCI ] 440FX PMC write to PAM register 59 (TLB Flush)
|
||||
00001281043i[PCI ] 440FX PMC write to PAM register 59 (TLB Flush)
|
||||
00001740530i[P2I ] PCI IRQ routing: PIRQA# set to 0x0b
|
||||
00001740577i[P2I ] PCI IRQ routing: PIRQB# set to 0x09
|
||||
00001740624i[P2I ] PCI IRQ routing: PIRQC# set to 0x0b
|
||||
00001740671i[P2I ] PCI IRQ routing: PIRQD# set to 0x09
|
||||
00001740687i[P2I ] write: ELCR2 = 0x0a
|
||||
00001741624i[BIOS ] PIIX3 init: elcr=00 0a
|
||||
00001761879i[BIOS ] PCI: bus=0 devfn=0x00: vendor_id=0x8086 device_id=0x1237
|
||||
00001765116i[BIOS ] PCI: bus=0 devfn=0x08: vendor_id=0x8086 device_id=0x7000
|
||||
00001767849i[BIOS ] PCI: bus=0 devfn=0x09: vendor_id=0x8086 device_id=0x7010
|
||||
00001768310i[PIDE ] new BM-DMA address: 0xc000
|
||||
00001769193i[BIOS ] region 4: 0x0000c000
|
||||
00001771769i[BIOS ] PCI: bus=0 devfn=0x0b: vendor_id=0x8086 device_id=0x7113
|
||||
00001772269i[ACPI ] new irq line = 11
|
||||
00001772306i[ACPI ] new PM base address: 0xb000
|
||||
00001772368i[ACPI ] new SM base address: 0xb100
|
||||
00001772836i[CPU0 ] Enter to System Management Mode
|
||||
00001772846i[CPU0 ] RSM: Resuming from System Management Mode
|
||||
00001772880i[PCI ] setting SMRAM control register to 0x4a
|
||||
00001773162i[PCI ] setting SMRAM control register to 0x0a
|
||||
00001796443i[BIOS ] MP table addr=0x000fb850 MPC table addr=0x000fb780 size=0xd0
|
||||
00001798646i[BIOS ] SMBIOS table addr=0x000fb860
|
||||
00001801690i[BIOS ] ACPI tables: RSDP addr=0x000fb970 ACPI DATA addr=0x01ff0000 size=0x9d8
|
||||
00001821223i[PCI ] 440FX PMC write to PAM register 59 (TLB Flush)
|
||||
00001822235i[BIOS ] bios_table_cur_addr: 0x000fb994
|
||||
00014041530i[BIOS ] Booting from 0000:7c00
|
||||
00023800000i[XGUI ] charmap update. Font Height is 16
|
||||
00024000000i[XGUI ] charmap update. Font Height is 16
|
||||
00051600000i[XGUI ] charmap update. Font Height is 16
|
||||
00059200000i[XGUI ] charmap update. Font Height is 16
|
||||
00163492000p[XGUI ] >>PANIC<< POWER button turned off.
|
||||
00163492000i[CPU0 ] CPU is in protected mode (active)
|
||||
00163492000i[CPU0 ] CS.d_b = 32 bit
|
||||
00163492000i[CPU0 ] SS.d_b = 32 bit
|
||||
00163492000i[CPU0 ] EFER = 0x00000000
|
||||
00163492000i[CPU0 ] | RAX=0000000000000000 RBX=0000000000101000
|
||||
00163492000i[CPU0 ] | RCX=00000000000b8000 RDX=00000000000003d4
|
||||
00163492000i[CPU0 ] | RSP=0000000000102fe0 RBP=0000000000102ff8
|
||||
00163492000i[CPU0 ] | RSI=00000000000263d3 RDI=00000000000263df
|
||||
00163492000i[CPU0 ] | R8=0000000000000000 R9=0000000000000000
|
||||
00163492000i[CPU0 ] | R10=0000000000000000 R11=0000000000000000
|
||||
00163492000i[CPU0 ] | R12=0000000000000000 R13=0000000000000000
|
||||
00163492000i[CPU0 ] | R14=0000000000000000 R15=0000000000000000
|
||||
00163492000i[CPU0 ] | IOPL=0 id vip vif ac vm rf nt of df if tf sf ZF af PF cf
|
||||
00163492000i[CPU0 ] | SEG selector base limit G D
|
||||
00163492000i[CPU0 ] | SEG sltr(index|ti|rpl) base limit G D
|
||||
00163492000i[CPU0 ] | CS:0008( 0001| 0| 0) 00000000 ffffffff 1 1
|
||||
00163492000i[CPU0 ] | DS:0010( 0002| 0| 0) 00000000 ffffffff 1 1
|
||||
00163492000i[CPU0 ] | SS:0010( 0002| 0| 0) 00000000 ffffffff 1 1
|
||||
00163492000i[CPU0 ] | ES:0010( 0002| 0| 0) 00000000 ffffffff 1 1
|
||||
00163492000i[CPU0 ] | FS:0010( 0002| 0| 0) 00000000 ffffffff 1 1
|
||||
00163492000i[CPU0 ] | GS:0010( 0002| 0| 0) 00000000 ffffffff 1 1
|
||||
00163492000i[CPU0 ] | MSR_FS_BASE:0000000000000000
|
||||
00163492000i[CPU0 ] | MSR_GS_BASE:0000000000000000
|
||||
00163492000i[CPU0 ] | RIP=00000000001000e9 (00000000001000e9)
|
||||
00163492000i[CPU0 ] | CR0=0x60000011 CR2=0x0000000000000000
|
||||
00163492000i[CPU0 ] | CR3=0x00000000 CR4=0x00000000
|
||||
00163492000i[CPU0 ] 0x00000000001000e9>> jmp .-2 (0x001000e9) : EBFE
|
||||
00163492000i[CMOS ] Last time is 1496097488 (Mon May 29 17:38:08 2017)
|
||||
00163492000i[XGUI ] Exit
|
||||
00163492000i[ ] restoring default signal behavior
|
||||
00163492000i[CTRL ] quit_sim called with exit code 1
|
45
MP1/MP1_Sources/bochsrc.bxrc
Normal file
45
MP1/MP1_Sources/bochsrc.bxrc
Normal file
|
@ -0,0 +1,45 @@
|
|||
###############################################################
|
||||
# bochsrc.txt file for DLX Linux disk image.
|
||||
###############################################################
|
||||
|
||||
# how much memory the emulated machine will have
|
||||
megs: 32
|
||||
|
||||
# filename of ROM images
|
||||
romimage: file=BIOS-bochs-latest
|
||||
vgaromimage: file=VGABIOS-lgpl-latest
|
||||
|
||||
# what disk images will be used
|
||||
floppya: 1_44=dev_kernel_grub.img, status=inserted
|
||||
#floppyb: 1_44=floppyb.img, status=inserted
|
||||
|
||||
# hard disk
|
||||
#ata0: enabled=1, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14
|
||||
#ata0-master: type=disk, path="c.img", mode=flat, cylinders=20, heads=16, spt=63
|
||||
# choose the boot disk.
|
||||
#boot: floppy
|
||||
|
||||
# default config interface is textconfig.
|
||||
#config_interface: textconfig
|
||||
#config_interface: wx
|
||||
|
||||
#display_library: x
|
||||
# other choices: win32 sdl wx carbon amigaos beos macintosh nogui rfb term svga
|
||||
|
||||
# where do we send log messages?
|
||||
log: bochsout.txt
|
||||
|
||||
# disable the mouse
|
||||
mouse: enabled=0
|
||||
|
||||
# enable key mapping, using US layout as default.
|
||||
#
|
||||
# NOTE: In Bochs 1.4, keyboard mapping is only 100% implemented on X windows.
|
||||
# However, the key mapping tables are used in the paste function, so
|
||||
# in the DLX Linux example I'm enabling keyboard_mapping so that paste
|
||||
# will work. Cut&Paste is currently implemented on win32 and X windows only.
|
||||
|
||||
#keyboard_mapping: enabled=1, map=$BXSHARE/keymaps/x11-pc-us.map
|
||||
#keyboard_mapping: enabled=1, map=$BXSHARE/keymaps/x11-pc-fr.map
|
||||
#keyboard_mapping: enabled=1, map=$BXSHARE/keymaps/x11-pc-de.map
|
||||
#keyboard_mapping: enabled=1, map=$BXSHARE/keymaps/x11-pc-es.map
|
212
MP1/MP1_Sources/console.C
Normal file
212
MP1/MP1_Sources/console.C
Normal file
|
@ -0,0 +1,212 @@
|
|||
/*
|
||||
File: Console.C
|
||||
|
||||
Author: R. Bettati
|
||||
Department of Computer Science
|
||||
Texas A&M University
|
||||
Date : 09/02/2009
|
||||
|
||||
*/
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
/* DEFINES */
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
#define CONSOLE_START_ADDRESS (unsigned short *)0xB8000
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
/* INCLUDES */
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
#include "console.H"
|
||||
|
||||
#include "utils.H"
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
/* DATA STRUCTURES */
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
/* -- (none) -- */
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
/* CONSTANTS */
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
/* -- (none) -- */
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
/* FORWARDS */
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
/* -- (none) -- */
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
/* METHODS FOR CLASS C o n s o l e */
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
/* -- GLOBAL VARIABLES -- */
|
||||
|
||||
int Console::attrib; /* background and foreground color */
|
||||
int Console::csr_x; /* position of cursor */
|
||||
int Console::csr_y;
|
||||
unsigned short * Console::textmemptr; /* text pointer */
|
||||
|
||||
/* -- CONSTRUCTOR -- */
|
||||
|
||||
void Console::init(unsigned char _fore_color,
|
||||
unsigned char _back_color) {
|
||||
set_TextColor(_fore_color, _back_color);
|
||||
csr_x = 0;
|
||||
csr_y = 0;
|
||||
textmemptr = CONSOLE_START_ADDRESS;
|
||||
cls();
|
||||
}
|
||||
|
||||
|
||||
void Console::scroll() {
|
||||
|
||||
/* A blank is defined as a space... we need to give it
|
||||
* backcolor too */
|
||||
unsigned blank = 0x20 | (attrib << 8);
|
||||
|
||||
/* Row 25 is the end, this means we need to scroll up */
|
||||
if(csr_y >= 25)
|
||||
{
|
||||
/* Move the current text chunk that makes up the screen
|
||||
* back in the buffer by a line */
|
||||
unsigned temp = csr_y - 25 + 1;
|
||||
memcpy ((char*)textmemptr, (char*)textmemptr + temp * 80, (25 - temp) * 80 * 2);
|
||||
|
||||
/* Finally, we set the chunk of memory that occupies
|
||||
* the last line of text to our 'blank' character */
|
||||
memsetw (textmemptr + (25 - temp) * 80, blank, 80);
|
||||
csr_y = 25 - 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Console::move_cursor() {
|
||||
|
||||
/* The equation for finding the index in a linear
|
||||
* chunk of memory can be represented by:
|
||||
* Index = [(y * width) + x] */
|
||||
unsigned temp = csr_y * 80 + csr_x;
|
||||
|
||||
/* This sends a command to indicies 14 and 15 in the
|
||||
* Console Control Register of the VGA controller. These
|
||||
* are the high and low bytes of the index that show
|
||||
* where the hardware cursor is to be 'blinking'. To
|
||||
* learn more, you should look up some VGA specific
|
||||
* programming documents. A great start to graphics:
|
||||
* http://www.brackeen.com/home/vga */
|
||||
outportb(0x3D4, (char)14);
|
||||
//outportb(0x3D5, temp >> 8);
|
||||
outportb(0x3D4, 15);
|
||||
//outportb(0x3D5, (char)temp);
|
||||
}
|
||||
|
||||
/* Clear the screen */
|
||||
void Console::cls() {
|
||||
|
||||
/* Again, we need the 'short' that will be used to
|
||||
* represent a space with color */
|
||||
unsigned blank = 0x20 | (attrib << 8);
|
||||
|
||||
/* Sets the entire screen to spaces in our current
|
||||
* color */
|
||||
for(int i = 0; i < 25; i++)
|
||||
memsetw (textmemptr + i * 80, blank, 80);
|
||||
|
||||
/* Update out virtual cursor, and then move the
|
||||
* hardware cursor */
|
||||
csr_x = 0;
|
||||
csr_y = 0;
|
||||
move_cursor();
|
||||
}
|
||||
|
||||
/* Puts a single character on the screen */
|
||||
void Console::putch(const char _c){
|
||||
|
||||
|
||||
/* Handle a backspace, by moving the cursor back one space */
|
||||
if(_c == 0x08)
|
||||
{
|
||||
if(csr_x != 0) csr_x--;
|
||||
}
|
||||
/* Handles a tab by incrementing the cursor's x, but only
|
||||
* to a point that will make it divisible by 8 */
|
||||
else if(_c == 0x09)
|
||||
{
|
||||
csr_x = (csr_x + 8) & ~(8 - 1);
|
||||
}
|
||||
/* Handles a 'Carriage Return', which simply brings the
|
||||
* cursor back to the margin */
|
||||
else if(_c == '\r')
|
||||
{
|
||||
csr_x = 0;
|
||||
}
|
||||
/* We handle our newlines the way DOS and the BIOS do: we
|
||||
* treat it as if a 'CR' was also there, so we bring the
|
||||
* cursor to the margin and we increment the 'y' value */
|
||||
else if(_c == '\n')
|
||||
{
|
||||
csr_x = 0;
|
||||
csr_y++;
|
||||
}
|
||||
/* Any character greater than and including a space, is a
|
||||
* printable character. The equation for finding the index
|
||||
* in a linear chunk of memory can be represented by:
|
||||
* Index = [(y * width) + x] */
|
||||
else if(_c >= ' ')
|
||||
{
|
||||
unsigned short * where = textmemptr + (csr_y * 80 + csr_x);
|
||||
*where = _c | (attrib << 8); /* Character AND attributes: color */
|
||||
csr_x++;
|
||||
}
|
||||
|
||||
/* If the cursor has reached the edge of the screen's width, we
|
||||
* insert a new line in there */
|
||||
if(csr_x >= 80)
|
||||
{
|
||||
csr_x = 0;
|
||||
csr_y++;
|
||||
}
|
||||
|
||||
/* Scroll the screen if needed, and finally move the cursor */
|
||||
scroll();
|
||||
move_cursor();
|
||||
}
|
||||
|
||||
/* Uses the above routine to output a string... */
|
||||
void Console::puts(const char * _s) {
|
||||
|
||||
for (int i = 0; i < strlen(_s); i++) {
|
||||
putch(_s[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void Console::puti(const int _n) {
|
||||
char foostr[15];
|
||||
|
||||
int2str(_n, foostr);
|
||||
puts(foostr);
|
||||
}
|
||||
|
||||
void Console::putui(const unsigned int _n) {
|
||||
char foostr[15];
|
||||
|
||||
uint2str(_n, foostr);
|
||||
putch('<');
|
||||
puts(foostr);
|
||||
putch('>');
|
||||
}
|
||||
|
||||
|
||||
/* -- COLOR CONTROL -- */
|
||||
void Console::set_TextColor(const unsigned char _forecolor,
|
||||
const unsigned char _backcolor) {
|
||||
/* Top 4 bytes are the background, bottom 4 bytes
|
||||
* are the foreground color */
|
||||
attrib = (_backcolor << 4) | (_forecolor & 0x0F);
|
||||
}
|
||||
|
113
MP1/MP1_Sources/console.H
Normal file
113
MP1/MP1_Sources/console.H
Normal file
|
@ -0,0 +1,113 @@
|
|||
/*
|
||||
File: Console.H
|
||||
|
||||
Author : R. Bettati
|
||||
Department of Computer Science
|
||||
Texas A&M University
|
||||
Date : 09/02/12
|
||||
|
||||
The class Console encapsulates the output operations ot the console
|
||||
screen. Since the console is initialized at the very beginning of the
|
||||
boot-up of the operating system, when no memory management is available
|
||||
yet, all functions and storage for the console are static.
|
||||
|
||||
The console is initialized with an "init" function instead of a
|
||||
constructor. (We don't want to deal with constructors that are called
|
||||
before the "main()" function.)
|
||||
|
||||
By making all functions static, we can access them across all object
|
||||
files without having to declare a global Console object or pass pointers
|
||||
to a locally declared object.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef _Console_H_ // include file only once
|
||||
#define _Console_H_
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
/* DEFINES */
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
/* -- (none) -- */
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
/* INCLUDES */
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
/* -- (none -- */
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
/* DATA STRUCTURES */
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
typedef enum {
|
||||
BLACK = 0,
|
||||
BLUE = 1,
|
||||
GREEN = 2,
|
||||
CYAN = 3,
|
||||
RED = 4,
|
||||
MAGENTA = 5,
|
||||
BROWN = 6,
|
||||
LIGHT_GREY = 7,
|
||||
DARK_GREY = 8,
|
||||
LIGHT_BLUE = 9,
|
||||
LIGHT_GREEN = 10,
|
||||
LIGHT_CYAN = 11,
|
||||
LIGHT_RED = 12,
|
||||
LIGHT_MAGENTA = 13,
|
||||
LIGHT_BROWN = 14,
|
||||
WHITE = 15
|
||||
} COLOR_CODE;
|
||||
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
/* FORWARDS */
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
/* -- (none) -- */
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
/* CLASS C o n s o l e */
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
class Console {
|
||||
private:
|
||||
static int attrib; /* background and foreground color */
|
||||
static int csr_x; /* position of cursor */
|
||||
static int csr_y;
|
||||
static unsigned short * textmemptr; /* text pointer */
|
||||
public:
|
||||
|
||||
/* -- INITIALIZER (we have no constructor, there is no memory mgmt yet.) */
|
||||
static void init(unsigned char _fore_color = WHITE,
|
||||
unsigned char _back_color = BLACK);
|
||||
|
||||
static void scroll();
|
||||
|
||||
static void move_cursor();
|
||||
/* Update the hardware cursor. */
|
||||
|
||||
static void cls();
|
||||
/* Clear the screen. */
|
||||
|
||||
static void putch(const char _c);
|
||||
/* Put a single character on the screen. */
|
||||
|
||||
static void puts(const char * _s);
|
||||
/* Display a NULL-terminated string on the screen.*/
|
||||
|
||||
static void puti(const int _i);
|
||||
/* Display a integer on the screen.*/
|
||||
|
||||
static void putui(const unsigned int _u);
|
||||
/* Display a unsigned integer on the screen.*/
|
||||
|
||||
static void set_TextColor(unsigned char _fore_color, unsigned char _back_color);
|
||||
/* Set the color of the foreground and background. */
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
4
MP1/MP1_Sources/copykernel.sh
Executable file
4
MP1/MP1_Sources/copykernel.sh
Executable file
|
@ -0,0 +1,4 @@
|
|||
sudo mount -o loop dev_kernel_grub.img /mnt/floppy
|
||||
sudo cp kernel.bin /mnt/floppy/
|
||||
sleep 1s
|
||||
sudo umount /mnt/floppy/
|
BIN
MP1/MP1_Sources/dev_kernel_grub.img
Normal file
BIN
MP1/MP1_Sources/dev_kernel_grub.img
Normal file
Binary file not shown.
47
MP1/MP1_Sources/kernel.C
Normal file
47
MP1/MP1_Sources/kernel.C
Normal file
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
File: kernel.C
|
||||
|
||||
Author: R. Bettati
|
||||
Department of Computer Science
|
||||
Texas A&M University
|
||||
|
||||
Date : 2017/05/25
|
||||
|
||||
The "main()" function is the entry point for the kernel.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
/* INCLUDES */
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
#include "console.H"
|
||||
|
||||
using namespace std;
|
||||
|
||||
/* ======================================================================= */
|
||||
/* MAIN -- THIS IS WHERE THE OS KERNEL WILL BE STARTED UP */
|
||||
/* ======================================================================= */
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
/* -- INITIALIZE CONSOLE */
|
||||
Console::init();
|
||||
Console::puts("Initialized console.\n");
|
||||
Console::puts("\n");
|
||||
|
||||
Console::puts("Replace the following <NAME> field with your name.\n");
|
||||
Console::puts("After your are done admiring your output, you can shutdown this 'machine'.\n");
|
||||
Console::puts("\n");
|
||||
Console::puts("WELCOME TO MY KERNEL!\n");
|
||||
Console::puts(" ");
|
||||
Console::set_TextColor(GREEN, RED);
|
||||
Console::puts("<NAME>\n");
|
||||
|
||||
/* -- LOOP FOREVER! */
|
||||
for(;;);
|
||||
|
||||
}
|
36
MP1/MP1_Sources/linker.ld
Normal file
36
MP1/MP1_Sources/linker.ld
Normal file
|
@ -0,0 +1,36 @@
|
|||
OUTPUT_FORMAT("binary")
|
||||
ENTRY(start)
|
||||
phys = 0x00100000;
|
||||
SECTIONS
|
||||
{
|
||||
.text phys : AT(phys) {
|
||||
code = .;
|
||||
*(.text)
|
||||
*(.gnu.linkonce.t.*)
|
||||
*(.gnu.linkonce.r.*)
|
||||
*(.rodata)
|
||||
. = ALIGN(4096);
|
||||
}
|
||||
.data : AT(phys + (data - code))
|
||||
{
|
||||
data = .;
|
||||
*(.data)
|
||||
start_ctors = .;
|
||||
*(.ctor*)
|
||||
end_ctors = .;
|
||||
start_dtors = .;
|
||||
*(.dtor*)
|
||||
end_dtors = .;
|
||||
*(.gnu.linkonce.d.*)
|
||||
. = ALIGN(4096);
|
||||
}
|
||||
.bss : AT(phys + (bss - code))
|
||||
{
|
||||
bss = .;
|
||||
*(.bss)
|
||||
*(.gnu.linkonce.b.*)
|
||||
. = ALIGN(4096);
|
||||
}
|
||||
end = .;
|
||||
}
|
||||
|
31
MP1/MP1_Sources/makefile
Normal file
31
MP1/MP1_Sources/makefile
Normal file
|
@ -0,0 +1,31 @@
|
|||
GCC_OPTIONS = -m32 -nostdlib -fno-builtin -nostartfiles -nodefaultlibs -fno-exceptions -fno-rtti -fno-stack-protector -fleading-underscore -fno-asynchronous-unwind-tables
|
||||
|
||||
all: kernel.bin
|
||||
|
||||
clean:
|
||||
rm -f *.o *.bin
|
||||
|
||||
# ==== KERNEL ENTRY POINT ====
|
||||
|
||||
start.o: start.asm
|
||||
nasm -f aout -o start.o start.asm
|
||||
|
||||
# ==== UTILITIES ====
|
||||
|
||||
utils.o: utils.H utils.C
|
||||
gcc $(GCC_OPTIONS) -c -o utils.o utils.C
|
||||
|
||||
# ==== DEVICES ====
|
||||
|
||||
console.o: console.H console.C
|
||||
gcc $(GCC_OPTIONS) -c -o console.o console.C
|
||||
|
||||
# ==== KERNEL MAIN FILE ====
|
||||
|
||||
kernel.o: kernel.C
|
||||
gcc $(GCC_OPTIONS) -c -o kernel.o kernel.C
|
||||
|
||||
|
||||
kernel.bin: start.o kernel.o console.o utils.o linker.ld
|
||||
ld -melf_i386 -T linker.ld -o kernel.bin start.o kernel.o console.o utils.o
|
||||
|
103
MP1/MP1_Sources/start.asm
Normal file
103
MP1/MP1_Sources/start.asm
Normal file
|
@ -0,0 +1,103 @@
|
|||
; This is the kernel's entry point. We could either call main here,
|
||||
; or we can use this to setup the stack or other nice stuff, like
|
||||
; perhaps setting up the GDT and segments. Please note that interrupts
|
||||
; are disabled at this point: More on interrupts later!
|
||||
[BITS 32]
|
||||
global start
|
||||
start:
|
||||
mov esp, _sys_stack ; Points stack pointer to our new stack area
|
||||
jmp stublet
|
||||
|
||||
; This part MUST be 4-byte aligned, so we solve that issue using 'ALIGN 4'
|
||||
ALIGN 4
|
||||
; Start of the multiboot header
|
||||
mboot:
|
||||
; Multiboot macros to make a few lines later more readable
|
||||
; Align all boot modulees on i386 page (4kB) boundaries
|
||||
MULTIBOOT_PAGE_ALIGN equ 1<<0
|
||||
; must pass memory information to OS
|
||||
MULTIBOOT_MEMORY_INFO equ 1<<1
|
||||
; flag below indicates the use of the address fields in the header
|
||||
; (used for a.out)
|
||||
MULTIBOOT_AOUT_KLUDGE equ 1<<16
|
||||
; magic marker identifying the multiboot header
|
||||
MULTIBOOT_HEADER_MAGIC equ 0x1BADB002
|
||||
; combine flags together
|
||||
MULTIBOOT_HEADER_FLAGS equ MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO | MULTIBOOT_AOUT_KLUDGE
|
||||
MULTIBOOT_CHECKSUM equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
|
||||
EXTERN code, bss, end
|
||||
|
||||
; This is the GRUB Multiboot header. A boot signature
|
||||
dd MULTIBOOT_HEADER_MAGIC
|
||||
dd MULTIBOOT_HEADER_FLAGS
|
||||
dd MULTIBOOT_CHECKSUM
|
||||
|
||||
; AOUT kludge - must be physical addresses. Make a note of these:
|
||||
; The linker script fills in the data for these ones!
|
||||
dd mboot ; header_addr:
|
||||
; address corresponding to the multiboot header
|
||||
dd code ; load_addr:
|
||||
; physical address of the beginning of the text segment
|
||||
dd bss ; load_end_addr:
|
||||
; physical address of the end of the data segment
|
||||
; (load_end_addr - load_addr) specifies how much data to load.
|
||||
dd end ; bss_end_addr:
|
||||
; pysical address of end of bss segment.
|
||||
; boot loader initializes this area to zero,
|
||||
; and reserves the memory
|
||||
dd start ; entry_addr:
|
||||
; physical address to which the boot loader should jump
|
||||
; to start running the OS
|
||||
|
||||
|
||||
stublet:
|
||||
; Initilization of static global objects. This goes through each object
|
||||
; in the ctors section of the object file, where the global constructors
|
||||
; created by C++ are put, and calls it. Normally C++ compilers add some code
|
||||
; to do this, but that code is in the standard library - which we do not
|
||||
; include
|
||||
; See linker.ld to see where we tell the linker to put them.
|
||||
extern start_ctors, end_ctors, start_dtors, end_dtors
|
||||
|
||||
static_ctors_loop:
|
||||
mov ebx, start_ctors
|
||||
jmp .test
|
||||
.body:
|
||||
call [ebx]
|
||||
add ebx,4
|
||||
.test:
|
||||
cmp ebx, end_ctors
|
||||
jb .body
|
||||
|
||||
; Entering the kernel proper.
|
||||
extern _main
|
||||
call _main
|
||||
|
||||
; Deinitialization of static global objects. This goes through each object
|
||||
; in the dtors section of the object file, where the global destructors
|
||||
; created by C++ are put, and calls it. Normally C++ compilers add some code
|
||||
; to do this, but that code is in the standard library - which we do not
|
||||
; include.
|
||||
; See linker.ld to see where we tell the linker to put them.
|
||||
static_dtors_loop:
|
||||
mov ebx, start_dtors
|
||||
jmp .test
|
||||
.body:
|
||||
call [ebx]
|
||||
add ebx,4
|
||||
.test:
|
||||
cmp ebx, end_dtors
|
||||
jb .body
|
||||
|
||||
; Enter an endless loop here in order to stop.
|
||||
jmp $
|
||||
|
||||
|
||||
; Here is the definition of our BSS section. Right now, we'll use
|
||||
; it just to store the stack. Remember that a stack actually grows
|
||||
; downwards, so we declare the size of the data before declaring
|
||||
; the identifier '_sys_stack'
|
||||
SECTION .bss
|
||||
resb 8192 ; This reserves 8KBytes of memory here
|
||||
_sys_stack:
|
||||
|
157
MP1/MP1_Sources/utils.C
Normal file
157
MP1/MP1_Sources/utils.C
Normal file
|
@ -0,0 +1,157 @@
|
|||
/*
|
||||
File: utils.C
|
||||
|
||||
Author: R. Bettati
|
||||
Department of Computer Science
|
||||
Texas A&M University
|
||||
|
||||
Date : 09/02/12
|
||||
|
||||
*/
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
/* DEFINES */
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
/* -- (none ) -- */
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
/* INCLUDES */
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
#include "utils.H"
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
/* DATA STRUCTURES */
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
/* -- (none) -- */
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
/* CONSTANTS */
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
/* -- (none) -- */
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
/* ABORT (USED e.g. IN _ASSERT() */
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
void abort() {
|
||||
for(;;);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
/* MEMORY OPERATIONS */
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
char * memcpy(char * _dest, const char * _src, const int _count) {
|
||||
for (int i = 0; i < _count; i++) {
|
||||
*_dest = *_src;
|
||||
_dest++;
|
||||
_src++;
|
||||
}
|
||||
|
||||
return _dest-1;
|
||||
}
|
||||
|
||||
char *memset(char * _dest, const char _val, const int _count) {
|
||||
for (int i = 0; i < _count; i++) {
|
||||
*_dest = _val;
|
||||
_dest++;
|
||||
}
|
||||
return _dest-1;
|
||||
}
|
||||
|
||||
unsigned short *memsetw( unsigned short * _dest,
|
||||
const unsigned short _val,
|
||||
const int _count) {
|
||||
for (int i = 0; i < _count; i++) {
|
||||
*_dest = _val;
|
||||
_dest++;
|
||||
}
|
||||
return _dest-1;
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
/* STRING OPERATIONS */
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
int strlen(const char *_str) {
|
||||
/* This loops through character array 'str', returning how
|
||||
* many characters it needs to check before it finds a 0.
|
||||
* In simple words, it returns the length in bytes of a string */
|
||||
int len = 0;
|
||||
while (*_str != 0) {
|
||||
_str++;
|
||||
len++;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
void strcpy(char* _dst, char* _src) {
|
||||
while (*_src != 0) {
|
||||
*_dst = *_src;
|
||||
_dst++;
|
||||
_src++;
|
||||
}
|
||||
*_dst = 0; // put terminating 0 at end.
|
||||
}
|
||||
|
||||
void int2str(int _num, char * _str) {
|
||||
/* -- THIS IMPLEMENTATION IS ONE PRETTY BAD HACK. */
|
||||
int i;
|
||||
char c, temp[11];
|
||||
|
||||
temp[0] = '\0';
|
||||
for(i = 1; i <= 10; i++) {
|
||||
temp[i] = _num % 10 + '0';
|
||||
_num /= 10;
|
||||
}
|
||||
for(i = 10; temp[i] == '0'; i--);
|
||||
if( i == 0 )
|
||||
i++;
|
||||
while( i >= 0 )
|
||||
*_str++ = temp[i--];
|
||||
}
|
||||
|
||||
|
||||
void uint2str(unsigned int _num, char * _str) {
|
||||
/* -- THIS IS A BAD HACK AS WELL. */
|
||||
int i;
|
||||
char c, temp[11];
|
||||
|
||||
temp[0] = '\0';
|
||||
for(i = 1; i <= 10; i++) {
|
||||
temp[i] = _num % 10 + '0';
|
||||
_num /= 10;
|
||||
}
|
||||
for(i = 10; temp[i] == '0'; i--);
|
||||
if( i == 0 )
|
||||
i++;
|
||||
while( i >= 0 )
|
||||
*_str++ = temp[i--];
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
/* POERT I/O OPERATIONS */
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
/* We will use this later on for reading from the I/O ports to get data
|
||||
* from devices such as the keyboard. We are using what is called
|
||||
* 'inline assembly' in these routines to actually do the work */
|
||||
char inportb (unsigned short _port) {
|
||||
unsigned char rv;
|
||||
__asm__ __volatile__ ("inb %1, %0" : "=a" (rv) : "dN" (_port));
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* We will use this to write to I/O ports to send bytes to devices. This
|
||||
* will be used in the next tutorial for changing the textmode cursor
|
||||
* position. Again, we use some inline assembly for the stuff that simply
|
||||
* cannot be done in C */
|
||||
void outportb (unsigned short _port, char _data) {
|
||||
__asm__ __volatile__ ("outb %1, %0" : : "dN" (_port), "a" (_data));
|
||||
}
|
||||
|
70
MP1/MP1_Sources/utils.H
Normal file
70
MP1/MP1_Sources/utils.H
Normal file
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
File : utils.H
|
||||
|
||||
Author : Riccardo Bettati
|
||||
Modified : 2017/05/02
|
||||
|
||||
Description : Various definitions (NULL) and
|
||||
utility functions (e.g. abort, memory and
|
||||
string functions).
|
||||
*/
|
||||
|
||||
#ifndef _utils_H_
|
||||
#define _utils_H_
|
||||
|
||||
/*---------------------------------------------------------------*/
|
||||
/* GENERAL CONSTANTS */
|
||||
|
||||
#ifndef NULL
|
||||
# define NULL 0
|
||||
#endif
|
||||
|
||||
/*---------------------------------------------------------------*/
|
||||
/* ABORT */
|
||||
|
||||
void abort();
|
||||
/* Stop execution. */
|
||||
|
||||
/*---------------------------------------------------------------*/
|
||||
/* SIMPLE MEMORY OPERATIONS */
|
||||
|
||||
char * memcpy(char * _dest, const char * _src, const int _count);
|
||||
/* Copy _count bytes from _src to _dest. (No check for uverlapping) */
|
||||
|
||||
char *memset(char * _dest, char _val, const int _count);
|
||||
/* Set _count bytes to value _val, starting from location _dest. */
|
||||
|
||||
unsigned short *memsetw( unsigned short * _dest,
|
||||
const unsigned short _val,
|
||||
const int _count);
|
||||
/* Same as above, but operations are 16-bit wide. */
|
||||
|
||||
/*---------------------------------------------------------------*/
|
||||
/* SIMPLE STRING OPERATIONS (STRINGS ARE NULL-TERMINATED) */
|
||||
|
||||
int strlen(const char * _str);
|
||||
/* Determine the length of null-terminated string. */
|
||||
|
||||
void strcpy(char * _dst, char * _src);
|
||||
/* Copy null-terminated string from _src to _dst. */
|
||||
|
||||
void int2str(int _num, char * _str);
|
||||
/* Convert int to null-terminated string. */
|
||||
|
||||
void uint2str(unsigned int _num, char * _str);
|
||||
/* Convert unsigned int to null-terminated string. */
|
||||
|
||||
/*---------------------------------------------------------------*/
|
||||
/* PORT I/O OPERATIONS */
|
||||
|
||||
char inportb (unsigned short _port);
|
||||
/* Read data from input port _port.*/
|
||||
|
||||
void outportb (unsigned short _port, char _data);
|
||||
/* Write _data to output port _port.*/
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
BIN
MP1/__MACOSX/._MP1_Sources
Normal file
BIN
MP1/__MACOSX/._MP1_Sources
Normal file
Binary file not shown.
BIN
MP1/__MACOSX/MP1_Sources/._.DS_Store
Normal file
BIN
MP1/__MACOSX/MP1_Sources/._.DS_Store
Normal file
Binary file not shown.
BIN
MP1/__MACOSX/MP1_Sources/._BIOS-bochs-latest
Normal file
BIN
MP1/__MACOSX/MP1_Sources/._BIOS-bochs-latest
Normal file
Binary file not shown.
BIN
MP1/__MACOSX/MP1_Sources/._README.TXT
Normal file
BIN
MP1/__MACOSX/MP1_Sources/._README.TXT
Normal file
Binary file not shown.
BIN
MP1/__MACOSX/MP1_Sources/._VGABIOS-lgpl-latest
Normal file
BIN
MP1/__MACOSX/MP1_Sources/._VGABIOS-lgpl-latest
Normal file
Binary file not shown.
BIN
MP1/__MACOSX/MP1_Sources/._bochsout.txt
Normal file
BIN
MP1/__MACOSX/MP1_Sources/._bochsout.txt
Normal file
Binary file not shown.
BIN
MP1/__MACOSX/MP1_Sources/._bochsrc.bxrc
Normal file
BIN
MP1/__MACOSX/MP1_Sources/._bochsrc.bxrc
Normal file
Binary file not shown.
BIN
MP1/__MACOSX/MP1_Sources/._console.C
Normal file
BIN
MP1/__MACOSX/MP1_Sources/._console.C
Normal file
Binary file not shown.
BIN
MP1/__MACOSX/MP1_Sources/._console.H
Normal file
BIN
MP1/__MACOSX/MP1_Sources/._console.H
Normal file
Binary file not shown.
BIN
MP1/__MACOSX/MP1_Sources/._copykernel.sh
Normal file
BIN
MP1/__MACOSX/MP1_Sources/._copykernel.sh
Normal file
Binary file not shown.
BIN
MP1/__MACOSX/MP1_Sources/._dev_kernel_grub.img
Normal file
BIN
MP1/__MACOSX/MP1_Sources/._dev_kernel_grub.img
Normal file
Binary file not shown.
BIN
MP1/__MACOSX/MP1_Sources/._kernel.C
Normal file
BIN
MP1/__MACOSX/MP1_Sources/._kernel.C
Normal file
Binary file not shown.
BIN
MP1/__MACOSX/MP1_Sources/._linker.ld
Normal file
BIN
MP1/__MACOSX/MP1_Sources/._linker.ld
Normal file
Binary file not shown.
BIN
MP1/__MACOSX/MP1_Sources/._makefile
Normal file
BIN
MP1/__MACOSX/MP1_Sources/._makefile
Normal file
Binary file not shown.
BIN
MP1/__MACOSX/MP1_Sources/._start.asm
Normal file
BIN
MP1/__MACOSX/MP1_Sources/._start.asm
Normal file
Binary file not shown.
BIN
MP1/__MACOSX/MP1_Sources/._utils.C
Normal file
BIN
MP1/__MACOSX/MP1_Sources/._utils.C
Normal file
Binary file not shown.
BIN
MP1/__MACOSX/MP1_Sources/._utils.H
Normal file
BIN
MP1/__MACOSX/MP1_Sources/._utils.H
Normal file
Binary file not shown.
BIN
MP1/handout_mp1.pdf
Normal file
BIN
MP1/handout_mp1.pdf
Normal file
Binary file not shown.
Reference in a new issue