CTAOS v3
This commit is contained in:
20
SysCore/compile.bat
Normal file
20
SysCore/compile.bat
Normal file
@ -0,0 +1,20 @@
|
||||
@echo off
|
||||
rem The name of the loader assembly file (without extension, must be .asm):
|
||||
set loader_name=loader
|
||||
|
||||
rem NASM and DJGPP executable paths:
|
||||
set nasm_path=C:\nasm
|
||||
set djgpp_path=C:\DJGPP\bin
|
||||
|
||||
rem Compile loader
|
||||
@echo on
|
||||
%nasm_path%\nasm.exe -f aout -o ./objects/%loader_name%.o %loader_name%.asm
|
||||
@echo off
|
||||
@echo.
|
||||
rem Compile main Kernel
|
||||
@echo on
|
||||
%djgpp_path%\gcc.exe -Wall -O -fstrength-reduce -fomit-frame-pointer -nostdinc -fno-builtin -I./include -c -o ./objects/main.o main.c
|
||||
@echo off
|
||||
rem OTHER GCC/NASM SOURCES GO HERE
|
||||
|
||||
@pause
|
BIN
SysCore/debug/BIOS-bochs-latest
Normal file
BIN
SysCore/debug/BIOS-bochs-latest
Normal file
Binary file not shown.
292
SysCore/debug/OSDev.log
Normal file
292
SysCore/debug/OSDev.log
Normal file
@ -0,0 +1,292 @@
|
||||
00000000000i[ ] Bochs x86 Emulator 2.4.5
|
||||
00000000000i[ ] Build from CVS snapshot, on April 25, 2010
|
||||
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[ ] MWAIT 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 cirrus
|
||||
00000000000i[MEM0 ] allocated memory at 027B0020. after alignment, vector=027B1000
|
||||
00000000000i[MEM0 ] 32.00MB
|
||||
00000000000i[MEM0 ] mem block size = 0x00100000, blocks=32
|
||||
00000000000i[MEM0 ] rom at 0xe0000/131072 ('BIOS-bochs-latest')
|
||||
00000000000i[MEM0 ] rom at 0xc0000/40448 ('VGABIOS-lgpl-latest')
|
||||
00000000000i[CMOS ] Using local time for initial clock
|
||||
00000000000i[CMOS ] Setting initial clock to: Sat Jul 03 09:26:48 2010 (time0=1278138408)
|
||||
00000000000i[DMA ] channel 4 used by cascade
|
||||
00000000000i[DMA ] channel 2 used by Floppy Drive
|
||||
00000000000i[FDD ] fd0: 'ctaos.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[MEM0 ] Register memory access handlers: 0x000a0000 - 0x000bffff
|
||||
00000000000i[WGUI ] Desktop Window dimensions: 1366 x 768
|
||||
00000000000i[WGUI ] Number of Mouse Buttons = 5
|
||||
00000000000i[WGUI ] IME disabled
|
||||
00000000000i[MEM0 ] Register memory access handlers: 0xe0000000 - 0xe0ffffff
|
||||
00000000000i[CLVGA] VBE Bochs Display Extension Enabled
|
||||
00000000000i[CLVGA] interval=50000
|
||||
00000000000i[ ] init_dev of 'unmapped' plugin device by virtual method
|
||||
00000000000i[ ] init_dev of 'biosdev' plugin device by virtual method
|
||||
00000000000i[ ] init_dev of 'speaker' plugin device by virtual method
|
||||
00000000000i[ ] init_dev of 'extfpuirq' plugin device by virtual method
|
||||
00000000000i[ ] init_dev of 'gameport' plugin device by virtual method
|
||||
00000000000i[ ] init_dev of 'pci_ide' plugin device by virtual method
|
||||
00000000000i[PCI ] PIIX3 PCI IDE controller present at device 1, function 1
|
||||
00000000000i[ ] init_dev of 'acpi' plugin device by virtual method
|
||||
00000000000i[PCI ] ACPI Controller present at device 1, function 3
|
||||
00000000000i[ ] init_dev of 'ioapic' plugin device by virtual method
|
||||
00000000000i[IOAP ] initializing I/O APIC
|
||||
00000000000i[MEM0 ] Register memory access handlers: 0xfec00000 - 0xfec00fff
|
||||
00000000000i[ ] init_dev of 'keyboard' plugin device by virtual method
|
||||
00000000000i[KBD ] will paste characters every 1000 keyboard ticks
|
||||
00000000000i[ ] 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[ ] init_dev of 'serial' plugin device by virtual method
|
||||
00000000000i[SER ] com1 at 0x03f8 irq 4
|
||||
00000000000i[ ] init_dev of 'parallel' plugin device by virtual method
|
||||
00000000000i[PAR ] parallel port 1 at 0x0378 irq 7
|
||||
00000000000i[ ] register state of 'unmapped' plugin device by virtual method
|
||||
00000000000i[ ] register state of 'biosdev' plugin device by virtual method
|
||||
00000000000i[ ] register state of 'speaker' plugin device by virtual method
|
||||
00000000000i[ ] register state of 'extfpuirq' plugin device by virtual method
|
||||
00000000000i[ ] register state of 'gameport' plugin device by virtual method
|
||||
00000000000i[ ] register state of 'pci_ide' plugin device by virtual method
|
||||
00000000000i[ ] register state of 'acpi' plugin device by virtual method
|
||||
00000000000i[ ] register state of 'ioapic' plugin device by virtual method
|
||||
00000000000i[ ] register state of 'keyboard' plugin device by virtual method
|
||||
00000000000i[ ] register state of 'harddrv' plugin device by virtual method
|
||||
00000000000i[ ] register state of 'serial' plugin device by virtual method
|
||||
00000000000i[ ] 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 0xfee00000
|
||||
00000000000i[CPU0 ] CPUID[0x00000000]: 00000003 756e6547 6c65746e 49656e69
|
||||
00000000000i[CPU0 ] CPUID[0x00000001]: 00000f20 00000800 00002000 078bfbff
|
||||
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[0x80000000]: 80000008 00000000 00000000 00000000
|
||||
00000000000i[CPU0 ] CPUID[0x80000001]: 00000000 00000000 00000101 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]: 00003020 00000000 00000000 00000000
|
||||
00000000000i[ ] reset of 'unmapped' plugin device by virtual method
|
||||
00000000000i[ ] reset of 'biosdev' plugin device by virtual method
|
||||
00000000000i[ ] reset of 'speaker' plugin device by virtual method
|
||||
00000000000i[ ] reset of 'extfpuirq' plugin device by virtual method
|
||||
00000000000i[ ] reset of 'gameport' plugin device by virtual method
|
||||
00000000000i[ ] reset of 'pci_ide' plugin device by virtual method
|
||||
00000000000i[ ] reset of 'acpi' plugin device by virtual method
|
||||
00000000000i[ ] reset of 'ioapic' plugin device by virtual method
|
||||
00000000000i[ ] reset of 'keyboard' plugin device by virtual method
|
||||
00000000000i[ ] reset of 'harddrv' plugin device by virtual method
|
||||
00000000000i[ ] reset of 'serial' plugin device by virtual method
|
||||
00000000000i[ ] reset of 'parallel' plugin device by virtual method
|
||||
00000003305i[BIOS ] $Revision: 1.247 $ $Date: 2010/04/04 19:33:50 $
|
||||
00000200000i[WGUI ] dimension update x=720 y=400 fontheight=16 fontwidth=9 bpp=8
|
||||
00000318042i[KBD ] reset-disable command received
|
||||
00000444800i[VBIOS] VGABios $Id: vgabios.c,v 1.69 2009/04/07 18:18:20 vruppert Exp $
|
||||
|
||||
00000444871i[CLVGA] VBE known Display Interface b0c0
|
||||
00000444903i[CLVGA] VBE known Display Interface b0c5
|
||||
00000447828i[VBIOS] VBE Bios $Id: vbe.c,v 1.62 2009/01/25 15:46:25 vruppert Exp $
|
||||
00000760517i[BIOS ] Starting rombios32
|
||||
00000761014i[BIOS ] Shutdown flag 0
|
||||
00000761695i[BIOS ] ram_size=0x02000000
|
||||
00000762173i[BIOS ] ram_end=32MB
|
||||
00000802745i[BIOS ] Found 1 cpu(s)
|
||||
00000822014i[BIOS ] bios_table_addr: 0x000fbc18 end=0x000fcc00
|
||||
00000822117i[PCI ] 440FX PMC write to PAM register 59 (TLB Flush)
|
||||
00001149814i[PCI ] 440FX PMC write to PAM register 59 (TLB Flush)
|
||||
00001477742i[P2I ] PCI IRQ routing: PIRQA# set to 0x0b
|
||||
00001477763i[P2I ] PCI IRQ routing: PIRQB# set to 0x09
|
||||
00001477784i[P2I ] PCI IRQ routing: PIRQC# set to 0x0b
|
||||
00001477805i[P2I ] PCI IRQ routing: PIRQD# set to 0x09
|
||||
00001477815i[P2I ] write: ELCR2 = 0x0a
|
||||
00001478700i[BIOS ] PIIX3/PIIX4 init: elcr=00 0a
|
||||
00001486658i[BIOS ] PCI: bus=0 devfn=0x00: vendor_id=0x8086 device_id=0x1237 class=0x0600
|
||||
00001489220i[BIOS ] PCI: bus=0 devfn=0x08: vendor_id=0x8086 device_id=0x7000 class=0x0601
|
||||
00001491621i[BIOS ] PCI: bus=0 devfn=0x09: vendor_id=0x8086 device_id=0x7010 class=0x0101
|
||||
00001491851i[PIDE ] new BM-DMA address: 0xc000
|
||||
00001492555i[BIOS ] region 4: 0x0000c000
|
||||
00001494865i[BIOS ] PCI: bus=0 devfn=0x0b: vendor_id=0x8086 device_id=0x7113 class=0x0680
|
||||
00001495103i[ACPI ] new irq line = 11
|
||||
00001495117i[ACPI ] new irq line = 9
|
||||
00001495147i[ACPI ] new PM base address: 0xb000
|
||||
00001495161i[ACPI ] new SM base address: 0xb100
|
||||
00001495189i[PCI ] setting SMRAM control register to 0x4a
|
||||
00001659283i[CPU0 ] Enter to System Management Mode
|
||||
00001659293i[CPU0 ] RSM: Resuming from System Management Mode
|
||||
00001823313i[PCI ] setting SMRAM control register to 0x0a
|
||||
00001832484i[BIOS ] MP table addr=0x000fbcf0 MPC table addr=0x000fbc20 size=0xd0
|
||||
00001834543i[BIOS ] SMBIOS table addr=0x000fbd00
|
||||
00001836931i[BIOS ] ACPI tables: RSDP addr=0x000fbe20 ACPI DATA addr=0x01ff0000 size=0x988
|
||||
00001840169i[BIOS ] Firmware waking vector 0x1ff00cc
|
||||
00001851282i[PCI ] 440FX PMC write to PAM register 59 (TLB Flush)
|
||||
00001852126i[BIOS ] bios_table_cur_addr: 0x000fbe44
|
||||
00014041543i[BIOS ] Booting from 0000:7c00
|
||||
00019105039i[KBD ] setting typematic info
|
||||
00019105052i[KBD ] setting delay to 500 mS (unused)
|
||||
00019105052i[KBD ] setting repeat rate to 10.9 cps (unused)
|
||||
00019105085i[KBD ] Switched to scancode set 2
|
||||
00019105160i[KBD ] keyboard: scan convert turned off
|
||||
00019184168e[CPU0 ] interrupt(): gate.type(1) != {5,6,7,14,15}
|
||||
00019184168e[CPU0 ] interrupt(): gate descriptor is not valid sys seg (vector=0x0d)
|
||||
00019184168e[CPU0 ] interrupt(): gate.type(1) != {5,6,7,14,15}
|
||||
00019184168i[CPU0 ] CPU is in protected mode (active)
|
||||
00019184168i[CPU0 ] CS.d_b = 32 bit
|
||||
00019184168i[CPU0 ] SS.d_b = 32 bit
|
||||
00019184168i[CPU0 ] EFER = 0x00000000
|
||||
00019184168i[CPU0 ] | RAX=00000000000011a5 RBX=0000000000001116
|
||||
00019184168i[CPU0 ] | RCX=000000000010a977 RDX=0000000000000eea
|
||||
00019184168i[CPU0 ] | RSP=000000000008ffc8 RBP=0000000000003000
|
||||
00019184168i[CPU0 ] | RSI=00000000000000ff RDI=0000000000105001
|
||||
00019184168i[CPU0 ] | R8=0000000000000000 R9=0000000000000000
|
||||
00019184168i[CPU0 ] | R10=0000000000000000 R11=0000000000000000
|
||||
00019184168i[CPU0 ] | R12=0000000000000000 R13=0000000000000000
|
||||
00019184168i[CPU0 ] | R14=0000000000000000 R15=0000000000000000
|
||||
00019184168i[CPU0 ] | IOPL=0 id vip vif ac vm RF nt of df IF tf sf zf AF PF cf
|
||||
00019184168i[CPU0 ] | SEG selector base limit G D
|
||||
00019184168i[CPU0 ] | SEG sltr(index|ti|rpl) base limit G D
|
||||
00019184168i[CPU0 ] | CS:0008( 0001| 0| 0) 00000000 ffffffff 1 1
|
||||
00019184168i[CPU0 ] | DS:0010( 0002| 0| 0) 00000000 ffffffff 1 1
|
||||
00019184168i[CPU0 ] | SS:0010( 0002| 0| 0) 00000000 ffffffff 1 1
|
||||
00019184168i[CPU0 ] | ES:0010( 0002| 0| 0) 00000000 ffffffff 1 1
|
||||
00019184168i[CPU0 ] | FS:0010( 0002| 0| 0) 00000000 ffffffff 1 1
|
||||
00019184168i[CPU0 ] | GS:0010( 0002| 0| 0) 00000000 ffffffff 1 1
|
||||
00019184168i[CPU0 ] | MSR_FS_BASE:0000000000000000
|
||||
00019184168i[CPU0 ] | MSR_GS_BASE:0000000000000000
|
||||
00019184168i[CPU0 ] | RIP=00000000001030d7 (00000000001030d7)
|
||||
00019184168i[CPU0 ] | CR0=0x60000011 CR2=0x0000000000000000
|
||||
00019184168i[CPU0 ] | CR3=0x00000000 CR4=0x00000000
|
||||
00019184168i[CPU0 ] 0x00000000001030d7>> jnz .-25 (0x001030c0) : 75E7
|
||||
00019184168e[CPU0 ] exception(): 3rd (13) exception with no resolution, shutdown status is 00h, resetting
|
||||
00019184168i[SYS ] bx_pc_system_c::Reset(HARDWARE) called
|
||||
00019184168i[CPU0 ] cpu hardware reset
|
||||
00019184168i[APIC0] allocate APIC id=0 (MMIO enabled) to 0xfee00000
|
||||
00019184168i[CPU0 ] CPUID[0x00000000]: 00000003 756e6547 6c65746e 49656e69
|
||||
00019184168i[CPU0 ] CPUID[0x00000001]: 00000f20 00000800 00002000 078bfbff
|
||||
00019184168i[CPU0 ] CPUID[0x00000002]: 00410601 00000000 00000000 00000000
|
||||
00019184168i[CPU0 ] CPUID[0x00000003]: 00000000 00000000 00000000 00000000
|
||||
00019184168i[CPU0 ] CPUID[0x00000004]: 00000000 00000000 00000000 00000000
|
||||
00019184168i[CPU0 ] CPUID[0x80000000]: 80000008 00000000 00000000 00000000
|
||||
00019184168i[CPU0 ] CPUID[0x80000001]: 00000000 00000000 00000101 2a100800
|
||||
00019184168i[CPU0 ] CPUID[0x80000002]: 20202020 20202020 20202020 6e492020
|
||||
00019184168i[CPU0 ] CPUID[0x80000003]: 286c6574 50202952 69746e65 52286d75
|
||||
00019184168i[CPU0 ] CPUID[0x80000004]: 20342029 20555043 20202020 00202020
|
||||
00019184168i[CPU0 ] CPUID[0x80000006]: 00000000 42004200 02008140 00000000
|
||||
00019184168i[CPU0 ] CPUID[0x80000007]: 00000000 00000000 00000000 00000000
|
||||
00019184168i[CPU0 ] CPUID[0x80000008]: 00003020 00000000 00000000 00000000
|
||||
00019184168i[ ] reset of 'unmapped' plugin device by virtual method
|
||||
00019184168i[ ] reset of 'biosdev' plugin device by virtual method
|
||||
00019184168i[ ] reset of 'speaker' plugin device by virtual method
|
||||
00019184168i[ ] reset of 'extfpuirq' plugin device by virtual method
|
||||
00019184168i[ ] reset of 'gameport' plugin device by virtual method
|
||||
00019184168i[ ] reset of 'pci_ide' plugin device by virtual method
|
||||
00019184168i[ ] reset of 'acpi' plugin device by virtual method
|
||||
00019184168i[ ] reset of 'ioapic' plugin device by virtual method
|
||||
00019184168i[ ] reset of 'keyboard' plugin device by virtual method
|
||||
00019184168i[ ] reset of 'harddrv' plugin device by virtual method
|
||||
00019184168i[ ] reset of 'serial' plugin device by virtual method
|
||||
00019184168i[ ] reset of 'parallel' plugin device by virtual method
|
||||
00019187474i[BIOS ] $Revision: 1.247 $ $Date: 2010/04/04 19:33:50 $
|
||||
00019502059i[KBD ] reset-disable command received
|
||||
00019628817i[VBIOS]
|
||||
VGABios $Id: vgabios.c,v 1.69 2009/04/07 18:18:20 vruppert Exp $
|
||||
|
||||
00019628888i[CLVGA] VBE known Display Interface b0c0
|
||||
00019628920i[CLVGA] VBE known Display Interface b0c5
|
||||
00019631845i[VBIOS] VBE Bios $Id: vbe.c,v 1.62 2009/01/25 15:46:25 vruppert Exp $
|
||||
00019944534i[BIOS ] Starting rombios32
|
||||
00019945031i[BIOS ] Shutdown flag 0
|
||||
00019945712i[BIOS ] ram_size=0x02000000
|
||||
00019946190i[BIOS ] ram_end=32MB
|
||||
00019986786i[BIOS ] Found 1 cpu(s)
|
||||
00020006055i[BIOS ] bios_table_addr: 0x000fbc18 end=0x000fcc00
|
||||
00020006158i[PCI ] 440FX PMC write to PAM register 59 (TLB Flush)
|
||||
00020333855i[PCI ] 440FX PMC write to PAM register 59 (TLB Flush)
|
||||
00020661783i[P2I ] PCI IRQ routing: PIRQA# set to 0x0b
|
||||
00020661804i[P2I ] PCI IRQ routing: PIRQB# set to 0x09
|
||||
00020661825i[P2I ] PCI IRQ routing: PIRQC# set to 0x0b
|
||||
00020661846i[P2I ] PCI IRQ routing: PIRQD# set to 0x09
|
||||
00020661856i[P2I ] write: ELCR2 = 0x0a
|
||||
00020662741i[BIOS ] PIIX3/PIIX4 init: elcr=00 0a
|
||||
00020670699i[BIOS ] PCI: bus=0 devfn=0x00: vendor_id=0x8086 device_id=0x1237 class=0x0600
|
||||
00020673261i[BIOS ] PCI: bus=0 devfn=0x08: vendor_id=0x8086 device_id=0x7000 class=0x0601
|
||||
00020675662i[BIOS ] PCI: bus=0 devfn=0x09: vendor_id=0x8086 device_id=0x7010 class=0x0101
|
||||
00020676596i[BIOS ] region 4: 0x0000c000
|
||||
00020678906i[BIOS ] PCI: bus=0 devfn=0x0b: vendor_id=0x8086 device_id=0x7113 class=0x0680
|
||||
00020679144i[ACPI ] new irq line = 11
|
||||
00020679158i[ACPI ] new irq line = 9
|
||||
00020679230i[PCI ] setting SMRAM control register to 0x4a
|
||||
00020843324i[CPU0 ] Enter to System Management Mode
|
||||
00020843334i[CPU0 ] RSM: Resuming from System Management Mode
|
||||
00021007354i[PCI ] setting SMRAM control register to 0x0a
|
||||
00021016525i[BIOS ] MP table addr=0x000fbcf0 MPC table addr=0x000fbc20 size=0xd0
|
||||
00021018584i[BIOS ] SMBIOS table addr=0x000fbd00
|
||||
00021020972i[BIOS ] ACPI tables: RSDP addr=0x000fbe20 ACPI DATA addr=0x01ff0000 size=0x988
|
||||
00021024210i[BIOS ] Firmware waking vector 0x1ff00cc
|
||||
00021035323i[PCI ] 440FX PMC write to PAM register 59 (TLB Flush)
|
||||
00021036167i[BIOS ] bios_table_cur_addr: 0x000fbe44
|
||||
00033225716i[BIOS ] Booting from 0000:7c00
|
||||
00038289036i[KBD ] setting typematic info
|
||||
00038289049i[KBD ] setting delay to 500 mS (unused)
|
||||
00038289049i[KBD ] setting repeat rate to 10.9 cps (unused)
|
||||
00038289082i[KBD ] Switched to scancode set 2
|
||||
00038289157i[KBD ] keyboard: scan convert turned off
|
||||
00220440000p[WGUI ] >>PANIC<< POWER button turned off.
|
||||
00220440000i[CPU0 ] CPU is in protected mode (active)
|
||||
00220440000i[CPU0 ] CS.d_b = 32 bit
|
||||
00220440000i[CPU0 ] SS.d_b = 32 bit
|
||||
00220440000i[CPU0 ] EFER = 0x00000000
|
||||
00220440000i[CPU0 ] | RAX=0000000000000700 RBX=000000000008ffa0
|
||||
00220440000i[CPU0 ] | RCX=00000000000b8000 RDX=00000000000bf01c
|
||||
00220440000i[CPU0 ] | RSP=000000000008ff20 RBP=0000000000003000
|
||||
00220440000i[CPU0 ] | RSI=0000000000008000 RDI=0000000000000028
|
||||
00220440000i[CPU0 ] | R8=0000000000000000 R9=0000000000000000
|
||||
00220440000i[CPU0 ] | R10=0000000000000000 R11=0000000000000000
|
||||
00220440000i[CPU0 ] | R12=0000000000000000 R13=0000000000000000
|
||||
00220440000i[CPU0 ] | R14=0000000000000000 R15=0000000000000000
|
||||
00220440000i[CPU0 ] | IOPL=0 id vip vif ac vm rf nt of df if tf sf zf af pf cf
|
||||
00220440000i[CPU0 ] | SEG selector base limit G D
|
||||
00220440000i[CPU0 ] | SEG sltr(index|ti|rpl) base limit G D
|
||||
00220440000i[CPU0 ] | CS:0008( 0001| 0| 0) 00000000 ffffffff 1 1
|
||||
00220440000i[CPU0 ] | DS:0010( 0002| 0| 0) 00000000 ffffffff 1 1
|
||||
00220440000i[CPU0 ] | SS:0010( 0002| 0| 0) 00000000 ffffffff 1 1
|
||||
00220440000i[CPU0 ] | ES:0010( 0002| 0| 0) 00000000 ffffffff 1 1
|
||||
00220440000i[CPU0 ] | FS:0010( 0002| 0| 0) 00000000 ffffffff 1 1
|
||||
00220440000i[CPU0 ] | GS:0010( 0002| 0| 0) 00000000 ffffffff 1 1
|
||||
00220440000i[CPU0 ] | MSR_FS_BASE:0000000000000000
|
||||
00220440000i[CPU0 ] | MSR_GS_BASE:0000000000000000
|
||||
00220440000i[CPU0 ] | RIP=0000000000102a49 (0000000000102a49)
|
||||
00220440000i[CPU0 ] | CR0=0x60000011 CR2=0x0000000000000000
|
||||
00220440000i[CPU0 ] | CR3=0x00000000 CR4=0x00000000
|
||||
00220440000i[CPU0 ] 0x0000000000102a49>> jmp .-2 (0x00102a49) : EBFE
|
BIN
SysCore/debug/VGABIOS-lgpl-latest
Normal file
BIN
SysCore/debug/VGABIOS-lgpl-latest
Normal file
Binary file not shown.
14
SysCore/debug/bochs_config.bxrc
Normal file
14
SysCore/debug/bochs_config.bxrc
Normal file
@ -0,0 +1,14 @@
|
||||
# ROM and VGA BIOS images ---------------------------------------------
|
||||
|
||||
romimage: file=BIOS-bochs-latest, address=0xe0000
|
||||
vgaromimage: file=VGABIOS-lgpl-latest
|
||||
|
||||
# boot from floppy using our disk image -------------------------------
|
||||
|
||||
floppya: 1_44=ctaos.img, status=inserted
|
||||
|
||||
# logging and reporting -----------------------------------------------
|
||||
|
||||
log: OSDev.log # All errors and info logs will output to OSDev.log
|
||||
error: action=report
|
||||
info: action=report
|
BIN
SysCore/debug/ctaos.img
Normal file
BIN
SysCore/debug/ctaos.img
Normal file
Binary file not shown.
92
SysCore/hal/cmos/cmos.c
Normal file
92
SysCore/hal/cmos/cmos.c
Normal file
@ -0,0 +1,92 @@
|
||||
#include <system.h>
|
||||
#include <time.h>
|
||||
#include "cmos.h"
|
||||
|
||||
volatile byte i86_cmos_data[128];
|
||||
|
||||
void i86_cmos_write ()
|
||||
{
|
||||
byte i;
|
||||
for (i = 0; i < 128; i++) {
|
||||
//asm volatile ("cli");
|
||||
outportb(0x70, i);
|
||||
iowait();
|
||||
outportb(0x71, i86_cmos_data[i]);
|
||||
//asm volatile ("sti");
|
||||
}
|
||||
}
|
||||
|
||||
void i86_cmos_read ()
|
||||
{
|
||||
byte i;
|
||||
for (i = 0; i < 128; i++) {
|
||||
//asm volatile ("cli");
|
||||
outportb(0x70, i);
|
||||
iowait();
|
||||
i86_cmos_data[i] = inportb(0x71);
|
||||
//asm volatile ("sti");
|
||||
}
|
||||
}
|
||||
|
||||
void i86_cmos_read_clock(TIME* tim)
|
||||
{
|
||||
i86_cmos_read();
|
||||
|
||||
if ((i86_cmos_data[0x0b]&4)==0) // BCD = true;
|
||||
{
|
||||
tim->seconds = (i86_cmos_data[0x00]%16) + 10*(i86_cmos_data[0x00]/16);
|
||||
tim->minutes = (i86_cmos_data[0x02]%16) + 10*(i86_cmos_data[0x02]/16);
|
||||
if ((i86_cmos_data[0x0b]&2)==0) { // AM/PM
|
||||
if (i86_cmos_data[0x04]&80) { // pm
|
||||
tim->hours = ((i86_cmos_data[0x04]-0x80)%16) + 10*((i86_cmos_data[0x04]-0x80)/16);
|
||||
tim->am_pm = 1;
|
||||
}
|
||||
else { // am
|
||||
tim->hours = (i86_cmos_data[0x04]%16) + 10*(i86_cmos_data[0x04]/16);
|
||||
tim->am_pm = 0;
|
||||
}
|
||||
}
|
||||
else { // 24 hours
|
||||
tim->hours = (i86_cmos_data[0x04]%16) + 10*(i86_cmos_data[0x04]/16);
|
||||
if (tim->hours > 12) {
|
||||
tim->am_pm = 1;
|
||||
tim->hours -= 12;
|
||||
}
|
||||
else tim->am_pm = 0;
|
||||
}
|
||||
|
||||
tim->weekday = (i86_cmos_data[0x06]%16) + 10*(i86_cmos_data[0x06]/16);
|
||||
tim->day = (i86_cmos_data[0x07]%16) + 10*(i86_cmos_data[0x07]/16);
|
||||
tim->month = (i86_cmos_data[0x08]%16) + 10*(i86_cmos_data[0x08]/16);
|
||||
tim->year = (i86_cmos_data[0x09]%16) + 10*(i86_cmos_data[0x09]/16);
|
||||
tim->century = (i86_cmos_data[0x32]%16) + 10*(i86_cmos_data[0x32]/16);
|
||||
}
|
||||
|
||||
else {//BCD = false;
|
||||
tim->seconds = i86_cmos_data[0x00];
|
||||
tim->minutes = i86_cmos_data[0x02];
|
||||
if ((i86_cmos_data[0x0b]&2)==0) { // AM/PM
|
||||
if (i86_cmos_data[0x04]&80) { // pm
|
||||
tim->hours = i86_cmos_data[0x04]-0x80;
|
||||
tim->am_pm = 1;
|
||||
}
|
||||
else { // am
|
||||
tim->hours = i86_cmos_data[0x04];
|
||||
tim->am_pm = 0;
|
||||
}
|
||||
}
|
||||
else { // 24 hours
|
||||
tim->hours = i86_cmos_data[0x02];
|
||||
if (tim->hours > 12) {
|
||||
tim->am_pm = 1;
|
||||
tim->hours -= 12;
|
||||
}
|
||||
else tim->am_pm = 0;
|
||||
}
|
||||
tim->weekday = i86_cmos_data[0x06];
|
||||
tim->day = i86_cmos_data[0x07];
|
||||
tim->month = i86_cmos_data[0x08];
|
||||
tim->year = i86_cmos_data[0x09];
|
||||
tim->century = i86_cmos_data[0x32];
|
||||
}
|
||||
}
|
10
SysCore/hal/cmos/cmos.h
Normal file
10
SysCore/hal/cmos/cmos.h
Normal file
@ -0,0 +1,10 @@
|
||||
#ifndef __CMOS_H
|
||||
#define __CMOS_H
|
||||
|
||||
extern volatile byte i86_cmos_data[128];
|
||||
|
||||
extern void i86_cmos_write ();
|
||||
extern void i86_cmos_read ();
|
||||
extern void i86_cmos_read_clock (TIME *tim);
|
||||
|
||||
#endif
|
18
SysCore/hal/cmos/compile.bat
Normal file
18
SysCore/hal/cmos/compile.bat
Normal file
@ -0,0 +1,18 @@
|
||||
@echo off
|
||||
rem The name of the loader assembly file (without extension, must be .asm):
|
||||
set loader_name=loader
|
||||
|
||||
rem NASM and DJGPP executable paths:
|
||||
set nasm_path=C:\nasm
|
||||
set djgpp_path=C:\DJGPP\bin
|
||||
set objpath=../../objects
|
||||
set incpath=../../include
|
||||
|
||||
@echo on
|
||||
%djgpp_path%\gcc.exe -Wall -O -fstrength-reduce -fomit-frame-pointer -nostdinc -fno-builtin -I%incpath% -c -o %objpath%/cmos.o cmos.c
|
||||
|
||||
@echo off
|
||||
@echo .
|
||||
@echo Done!
|
||||
|
||||
@pause
|
43
SysCore/hal/compile.bat
Normal file
43
SysCore/hal/compile.bat
Normal file
@ -0,0 +1,43 @@
|
||||
@echo off
|
||||
|
||||
set loader_name=loader
|
||||
set nasm_path=C:\nasm
|
||||
set djgpp_path=C:\DJGPP\bin
|
||||
|
||||
|
||||
@echo ***************** CTA KERNEL *****************
|
||||
|
||||
:KernelEntry
|
||||
@echo.
|
||||
@echo Building Kernel entry...
|
||||
@echo * Compiling kernel loader...
|
||||
%nasm_path%\nasm.exe -f aout -o ./objects/%loader_name%.o %loader_name%.asm
|
||||
|
||||
@echo * Compiling kernel main...
|
||||
%djgpp_path%\gcc.exe -Wall -O -fstrength-reduce -fomit-frame-pointer -nostdinc -fno-builtin -I./include -c -o ./objects/main.o main.c
|
||||
|
||||
|
||||
:KernelSTDLIB
|
||||
cd lib
|
||||
call compile.bat
|
||||
cd..
|
||||
|
||||
:KernelMemoryManager
|
||||
cd memory
|
||||
call compile.bat
|
||||
cd..
|
||||
|
||||
|
||||
rem here go other sources:
|
||||
|
||||
rem here go other sources ^
|
||||
|
||||
:Finish
|
||||
cd objects
|
||||
@echo Linking...
|
||||
%djgpp_path%\ld -T link.ld
|
||||
@echo.
|
||||
|
||||
echo Copying to floppy drive...
|
||||
copy KERNEL.BIN A:\KERNEL.CTA
|
||||
cd..
|
18
SysCore/hal/cpu/compile.bat
Normal file
18
SysCore/hal/cpu/compile.bat
Normal file
@ -0,0 +1,18 @@
|
||||
@echo off
|
||||
rem The name of the loader assembly file (without extension, must be .asm):
|
||||
set loader_name=loader
|
||||
|
||||
rem NASM and DJGPP executable paths:
|
||||
set nasm_path=C:\nasm
|
||||
set djgpp_path=C:\DJGPP\bin
|
||||
set objpath=../../objects
|
||||
set incpath=../../include
|
||||
|
||||
@echo on
|
||||
%djgpp_path%\gcc.exe -Wall -O -fstrength-reduce -fomit-frame-pointer -nostdinc -fno-builtin -I%incpath% -c -o %objpath%/cpu.o cpu.c
|
||||
|
||||
@echo off
|
||||
@echo .
|
||||
@echo Done!
|
||||
|
||||
@pause
|
35
SysCore/hal/cpu/cpu.c
Normal file
35
SysCore/hal/cpu/cpu.c
Normal file
@ -0,0 +1,35 @@
|
||||
#include <system.h>
|
||||
#include "cpu.h"
|
||||
#include "../gdt/gdt.h"
|
||||
#include "../idt/idt.h"
|
||||
#define cpuid(in, a, b, c, d) __asm__("cpuid": "=a" (a), "=b" (b), "=c" (c), "=d" (d) : "a" (in));
|
||||
|
||||
|
||||
|
||||
// initializes cpu resources
|
||||
void i86_cpu_initialize()
|
||||
{
|
||||
// initialize processor tables
|
||||
i86_gdt_install();
|
||||
i86_idt_install();
|
||||
}
|
||||
|
||||
void i86_cpu_shutdown()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
char* i86_cpu_get_vender()
|
||||
{
|
||||
static char vender[13];
|
||||
dword unused, arr[3];
|
||||
int i;
|
||||
|
||||
cpuid(0, unused, arr[0], arr[2], arr[1]);
|
||||
|
||||
for (i=0; i<12; i++)
|
||||
vender[i] = (arr[i/4]>>(i%4*8)) && 0xFF;
|
||||
|
||||
vender[12] = 0;
|
||||
return vender;
|
||||
}
|
29
SysCore/hal/cpu/cpu.h
Normal file
29
SysCore/hal/cpu/cpu.h
Normal file
@ -0,0 +1,29 @@
|
||||
#ifndef _CPU_H_INCLUDED
|
||||
#define _CPU_H_INCLUDED
|
||||
//****************************************************************************
|
||||
//**
|
||||
//** cpu.h
|
||||
//**
|
||||
//** This is the processor interface. Everything outside of this module
|
||||
//** must use this interface when working on processor data.
|
||||
//**
|
||||
//** A processor is a module that manages the very basic data structures
|
||||
//** and data within the system. The processor interface provides the interface
|
||||
//** for managing processors, processor cores, accessing processor structures,
|
||||
//** and more
|
||||
//**
|
||||
//****************************************************************************
|
||||
|
||||
#include <stdint.h>
|
||||
#include <regs.h>
|
||||
|
||||
//! initialize the processors
|
||||
extern void i86_cpu_initialize ();
|
||||
|
||||
//! shutdown the processors
|
||||
extern void i86_cpu_shutdown ();
|
||||
|
||||
//! get cpu vender
|
||||
extern char* i86_cpu_get_vender ();
|
||||
|
||||
#endif
|
19
SysCore/hal/gdt/compile.bat
Normal file
19
SysCore/hal/gdt/compile.bat
Normal file
@ -0,0 +1,19 @@
|
||||
@echo off
|
||||
rem The name of the loader assembly file (without extension, must be .asm):
|
||||
set loader_name=loader
|
||||
|
||||
rem NASM and DJGPP executable paths:
|
||||
set nasm_path=C:\nasm
|
||||
set djgpp_path=C:\DJGPP\bin
|
||||
set objpath=../../objects
|
||||
set incpath=../../include
|
||||
|
||||
@echo on
|
||||
%nasm_path%\nasm.exe -f aout -o %objpath%/gdt_asm.o gdt.asm
|
||||
%djgpp_path%\gcc.exe -Wall -O -fstrength-reduce -fomit-frame-pointer -nostdinc -fno-builtin -I%incpath% -c -o %objpath%/gdt.o gdt.c
|
||||
|
||||
@echo off
|
||||
@echo .
|
||||
@echo Done!
|
||||
|
||||
@pause
|
20
SysCore/hal/gdt/gdt.asm
Normal file
20
SysCore/hal/gdt/gdt.asm
Normal file
@ -0,0 +1,20 @@
|
||||
bits 32
|
||||
; !!! GDT !!!
|
||||
; This will set up our new segment registers. We need to do
|
||||
; something special in order to set CS. We do what is called a
|
||||
; far jump. A jump that includes a segment as well as an offset.
|
||||
; This is declared in C as 'extern void gdt_flush();'
|
||||
|
||||
global _i86_gdt_flush ; Allows the C code to link to this
|
||||
extern _gp ; Says that '_gp' is in another file
|
||||
_i86_gdt_flush:
|
||||
lgdt [_gp] ; Load the GDT with our '_gp' which is a special pointer
|
||||
mov ax, 0x10 ; 0x10 is the offset in the GDT to our data segment
|
||||
mov ds, ax
|
||||
mov es, ax
|
||||
mov fs, ax
|
||||
mov gs, ax
|
||||
mov ss, ax
|
||||
jmp 0x08:flush2 ; 0x08 is the offset to our code segment: Far jump!
|
||||
flush2:
|
||||
ret ; Returns back to the C code!
|
65
SysCore/hal/gdt/gdt.c
Normal file
65
SysCore/hal/gdt/gdt.c
Normal file
@ -0,0 +1,65 @@
|
||||
/******************************************************************
|
||||
* gdt.c - GLOBAL DESCRIPTOR TABLE *
|
||||
* Contains function prototypes for setting up the GDT *
|
||||
******************************************************************/
|
||||
#define MAX_DESCRIPTORS 3
|
||||
#include "gdt.h"
|
||||
|
||||
/* Our GDT, with 3 entries, and finally our special GDT pointer */
|
||||
struct gdt_entry gdt[3];
|
||||
struct gdt_ptr gp;
|
||||
|
||||
|
||||
/* Setup a descriptor in the Global Descriptor Table */
|
||||
void i86_gdt_set_gate(int num, unsigned long base, unsigned long limit, unsigned char access, unsigned char gran)
|
||||
{
|
||||
/* Setup the descriptor base address */
|
||||
gdt[num].base_low = (base & 0xFFFF);
|
||||
gdt[num].base_middle = (base >> 16) & 0xFF;
|
||||
gdt[num].base_high = (base >> 24) & 0xFF;
|
||||
|
||||
/* Setup the descriptor limits */
|
||||
gdt[num].limit_low = (limit & 0xFFFF);
|
||||
gdt[num].granularity = ((limit >> 16) & 0x0F);
|
||||
|
||||
/* Finally, set up the granularity and access flags */
|
||||
gdt[num].granularity |= (gran & 0xF0);
|
||||
gdt[num].access = access;
|
||||
}
|
||||
|
||||
struct gdt_entry* i86_gdt_get_gate(int num)
|
||||
{
|
||||
if (num>MAX_DESCRIPTORS) return 0;
|
||||
return &gdt[num];
|
||||
}
|
||||
|
||||
/* Should be called by main. This will setup the special GDT
|
||||
* pointer, set up the first 3 entries in our GDT, and then
|
||||
* finally call gdt_flush() in our assembler file in order
|
||||
* to tell the processor where the new GDT is and update the
|
||||
* new segment registers */
|
||||
void i86_gdt_install()
|
||||
{
|
||||
/* Setup the GDT pointer and limit */
|
||||
gp.limit = (sizeof(struct gdt_entry) * 3) - 1;
|
||||
gp.base = (unsigned int)&gdt;
|
||||
|
||||
/* Our NULL descriptor */
|
||||
i86_gdt_set_gate(0, 0, 0, 0, 0);
|
||||
|
||||
/* The second entry is our Code Segment. The base address
|
||||
* is 0, the limit is 4GBytes, it uses 4KByte granularity,
|
||||
* uses 32-bit opcodes, and is a Code Segment descriptor.
|
||||
* Please check the table above in the tutorial in order
|
||||
* to see exactly what each value means */
|
||||
i86_gdt_set_gate(1, 0, 0xFFFFFFFF, 0x9A, 0xCF);
|
||||
|
||||
/* The third entry is our Data Segment. It's EXACTLY the
|
||||
* same as our code segment, but the descriptor type in
|
||||
* this entry's access byte says it's a Data Segment */
|
||||
i86_gdt_set_gate(2, 0, 0xFFFFFFFF, 0x92, 0xCF);
|
||||
|
||||
/* Flush out the old GDT and install the new changes! */
|
||||
i86_gdt_flush();
|
||||
}
|
||||
|
39
SysCore/hal/gdt/gdt.h
Normal file
39
SysCore/hal/gdt/gdt.h
Normal file
@ -0,0 +1,39 @@
|
||||
/******************************************************************
|
||||
* gdt.h - GLOBAL DESCRIPTOR TABLE *
|
||||
* Contains structures and function declarations for GDT *
|
||||
******************************************************************/
|
||||
|
||||
#ifndef __GDT_H
|
||||
#define __GDT_H
|
||||
|
||||
/* Defines a GDT entry. We say packed, because it prevents the
|
||||
* compiler from doing things that it thinks is best: Prevent
|
||||
* compiler "optimization" by packing */
|
||||
struct gdt_entry
|
||||
{
|
||||
unsigned short limit_low;
|
||||
unsigned short base_low;
|
||||
unsigned char base_middle;
|
||||
unsigned char access;
|
||||
unsigned char granularity;
|
||||
unsigned char base_high;
|
||||
} __attribute__((packed));
|
||||
|
||||
/* Special pointer which includes the limit: The max bytes
|
||||
* taken up by the GDT, minus 1. Again, this NEEDS to be packed */
|
||||
struct gdt_ptr
|
||||
{
|
||||
unsigned short limit;
|
||||
unsigned int base;
|
||||
} __attribute__((packed));
|
||||
|
||||
|
||||
/* This will be a function in start.asm. We use this to properly
|
||||
* reload the new segment registers */
|
||||
extern void i86_gdt_flush();
|
||||
extern void i86_gdt_set_gate(int num, unsigned long base, unsigned long limit, unsigned char access, unsigned char gran);
|
||||
extern struct gdt_entry* i86_gdt_get_gate(int num);
|
||||
|
||||
extern void i86_gdt_install();
|
||||
|
||||
#endif
|
184
SysCore/hal/hal.c
Normal file
184
SysCore/hal/hal.c
Normal file
@ -0,0 +1,184 @@
|
||||
#include <system.h>
|
||||
#include <time.h>
|
||||
#include <hal.h>
|
||||
#include "cpu/cpu.h"
|
||||
#include "gdt/gdt.h"
|
||||
#include "idt/idt.h"
|
||||
#include "pic/pic.h"
|
||||
#include "pit/pit.h"
|
||||
#include "cmos/cmos.h"
|
||||
#include "irq/irq.h"
|
||||
#include "isrs/isrs.h"
|
||||
#include "keyboard/keyus.h"
|
||||
|
||||
// initialize hardware devices
|
||||
void i86_hal_initialize () {
|
||||
|
||||
// initialize motherboard controllers and system timer
|
||||
i86_cpu_initialize (); // (install GDT, IDT)
|
||||
i86_isrs_install(); // (install ISR handler)
|
||||
i86_irq_install(); // (install IRQ handler)
|
||||
|
||||
// install PIT and system clock; pit at 100 Hz
|
||||
i86_kb_install_partone();
|
||||
i86_cmos_read_clock((TIME*)&_internal_clock);
|
||||
i86_pit_install (100);
|
||||
i86_kb_install_parttwo();
|
||||
|
||||
// enable interrupts
|
||||
i86_start_interrupts();
|
||||
|
||||
}
|
||||
|
||||
// shutdown hardware devices
|
||||
int i86_hal_shutdown () {
|
||||
|
||||
i86_cpu_shutdown ();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void reboot()
|
||||
{
|
||||
unsigned char good = 0x02;
|
||||
while ((good & 0x02) != 0)
|
||||
good = inportb(0x64);
|
||||
outportb(0x64, 0xFE);
|
||||
__asm__ __volatile__ ("hlt");
|
||||
}
|
||||
|
||||
//! notifies hal interrupt is done
|
||||
/*inline void interruptdone (unsigned int intno) {
|
||||
|
||||
//! insure its a valid hardware irq
|
||||
if (intno > 16)
|
||||
return;
|
||||
|
||||
//! test if we need to send end-of-interrupt to second pic
|
||||
if (intno >= 8)
|
||||
i86_pic_send_command (0x20, 0xA1);
|
||||
|
||||
//! always send end-of-interrupt to primary pic
|
||||
i86_pic_send_command (0x20, 0x21);
|
||||
}
|
||||
*/
|
||||
|
||||
//! output sound to speaker
|
||||
void sound (unsigned frequency) {
|
||||
|
||||
//! sets frequency for speaker. frequency of 0 disables speaker
|
||||
outportb (0x61, 3 | (byte)(frequency<<2) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//! sets new interrupt vector
|
||||
/*void _cdecl setvect (int intno, void (_cdecl far &vect) ( ) ) {
|
||||
|
||||
//! install interrupt handler! This overwrites prev interrupt descriptor
|
||||
i86_install_ir (intno, I86_IDT_DESC_PRESENT | I86_IDT_DESC_BIT32,
|
||||
0x8, vect);
|
||||
}
|
||||
|
||||
|
||||
//! returns current interrupt vector
|
||||
void (_cdecl far * _cdecl getvect (int intno)) ( ) {
|
||||
|
||||
//! get the descriptor from the idt
|
||||
idt_descriptor* desc = i86_get_ir (intno);
|
||||
if (!desc)
|
||||
return 0;
|
||||
|
||||
//! get address of interrupt handler
|
||||
uint32_t addr = desc->baseLo | (desc->baseHi << 16);
|
||||
|
||||
//! return interrupt handler
|
||||
I86_IRQ_HANDLER irq = (I86_IRQ_HANDLER)addr;
|
||||
return irq;
|
||||
}
|
||||
|
||||
*/
|
||||
//! returns cpu vender
|
||||
const char* get_cpu_vender () {
|
||||
|
||||
return i86_cpu_get_vender();
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************************
|
||||
* Keyboard Routines *
|
||||
***************************************************************************************/
|
||||
char getch()
|
||||
{
|
||||
kb_key alpha = getkey();
|
||||
return alpha.character;
|
||||
}
|
||||
|
||||
char scancode_to_ascii(byte scancode, byte status)
|
||||
{
|
||||
if ((status&1) || (status&2)) return kbdus_map_shift[scancode];
|
||||
else return kbdus_map[scancode];
|
||||
}
|
||||
|
||||
byte get_key_status (byte scancode)
|
||||
{
|
||||
if (scancode&0xF0) return kb_lights_status&0x0F;
|
||||
else if (scancode&0x80) return kb_modifier_status&0x7F;
|
||||
|
||||
return i86_kb_get_key(scancode);
|
||||
}
|
||||
|
||||
/***************************************
|
||||
* Set repeat rate/delay *
|
||||
***************************************
|
||||
Values for inter-character delay (bits 4-0)
|
||||
(characters per second; default is 10.9)
|
||||
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7
|
||||
----+----+----+----+----+----+----+----+----
|
||||
0 |30.0|26.7|24.0|21.8|20.0|18.5|17.1|16.0
|
||||
8 |15.0|13.3|12.0|10.9|10.0|9.2 |8.6 |8.0
|
||||
16 |7.5 |6.7 |6.0 |5.5 |5.0 |4.6 |4.3 |4.0
|
||||
24 |3.7 |3.3 |3.0 |2.7 |2.5 |2.3 |2.1 |2.0
|
||||
|
||||
Values for delay:
|
||||
(miliseconds; default is 500)
|
||||
0 | 1 | 2 | 3
|
||||
-----+-----+-----+-----
|
||||
250 | 500 | 750 | 1000
|
||||
|
||||
***************************************/
|
||||
void kb_set_repeat(float rate, int delay){
|
||||
float rates[] = {30.0, 26.7, 24.0, 21.8, 20.0, 18.5, 17.1, 16.0, 15.0, 13.3, 12.0,
|
||||
10.9, 10.0, 9.2, 8.6, 8.0, 7.5, 6.7, 6.0, 5.5, 5.0, 4.6, 4.3, 4.0,
|
||||
3.7, 3.3, 3.0, 2.7, 2.5, 2.3, 2.1, 2.0} ;
|
||||
|
||||
|
||||
byte r,d;
|
||||
|
||||
for (r = 0; rate != rates[r] && r < 32; r++)
|
||||
if (rate==32) return;
|
||||
|
||||
switch(delay) {
|
||||
case 250: d = 0; break;
|
||||
case 500: d = 1; break;
|
||||
case 750: d = 2; break;
|
||||
case 1000: d = 3; break;
|
||||
default: return;
|
||||
}
|
||||
|
||||
i86_kb_set_repeat(r,d);
|
||||
}
|
||||
|
||||
|
||||
/***************************************
|
||||
* Set keyboard LEDs *
|
||||
***************************************
|
||||
+-----------+-------+-------+--------+
|
||||
| Bits 7-3 | Bit 2 | Bit 1 | Bit 0 |
|
||||
| 0 | Caps | Num | Scroll |
|
||||
|(reserved) | lock | lock | lock |
|
||||
+-----------+-------+-------+--------+
|
||||
***************************************/
|
||||
void kb_set_LEDs(byte status) {
|
||||
i86_kb_set_LEDs(status);
|
||||
}
|
19
SysCore/hal/idt/compile.bat
Normal file
19
SysCore/hal/idt/compile.bat
Normal file
@ -0,0 +1,19 @@
|
||||
@echo off
|
||||
rem The name of the loader assembly file (without extension, must be .asm):
|
||||
set loader_name=loader
|
||||
|
||||
rem NASM and DJGPP executable paths:
|
||||
set nasm_path=C:\nasm
|
||||
set djgpp_path=C:\DJGPP\bin
|
||||
set objpath=../../objects
|
||||
set incpath=../../include
|
||||
|
||||
@echo on
|
||||
%nasm_path%\nasm.exe -f aout -o %objpath%/idt_asm.o idt.asm
|
||||
%djgpp_path%\gcc.exe -Wall -O -fstrength-reduce -fomit-frame-pointer -nostdinc -fno-builtin -I%incpath% -c -o %objpath%/idt.o idt.c
|
||||
|
||||
@echo off
|
||||
@echo .
|
||||
@echo Done!
|
||||
|
||||
@pause
|
9
SysCore/hal/idt/idt.asm
Normal file
9
SysCore/hal/idt/idt.asm
Normal file
@ -0,0 +1,9 @@
|
||||
bits 32
|
||||
|
||||
; !!! IDT !!!
|
||||
; Loads the IDT defined in '_idtp'
|
||||
global _i86_idt_load
|
||||
extern _idtp
|
||||
_i86_idt_load:
|
||||
lidt [_idtp]
|
||||
ret
|
49
SysCore/hal/idt/idt.c
Normal file
49
SysCore/hal/idt/idt.c
Normal file
@ -0,0 +1,49 @@
|
||||
/******************************************************************
|
||||
* idt.h - INTERRUPT DESCRIPTOR TABLE *
|
||||
* Contains structures and function declarations for IDT *
|
||||
******************************************************************/
|
||||
#include <system.h>
|
||||
#include "idt.h"
|
||||
|
||||
/* Declare an IDT of 256 entries. Although we will only use the
|
||||
* first 32 entries in this tutorial, the rest exists as a bit
|
||||
* of a trap. If any undefined IDT entry is hit, it normally
|
||||
* will cause an "Unhandled Interrupt" exception. Any descriptor
|
||||
* for which the 'presence' bit is cleared (0) will generate an
|
||||
* "Unhandled Interrupt" exception */
|
||||
struct idt_entry idt[256];
|
||||
struct idt_ptr idtp;
|
||||
|
||||
/* Use this function to set an entry in the IDT. Alot simpler
|
||||
* than twiddling with the GDT ;) */
|
||||
void i86_idt_set_gate(unsigned char num, unsigned long base, unsigned short sel, unsigned char flags)
|
||||
{
|
||||
/* The interrupt routine's base address */
|
||||
idt[num].base_lo = (base & 0xFFFF);
|
||||
idt[num].base_hi = (base >> 16) & 0xFFFF;
|
||||
|
||||
/* The segment or 'selector' that this IDT entry will use
|
||||
* is set here, along with any access flags */
|
||||
idt[num].sel = sel;
|
||||
idt[num].always0 = 0;
|
||||
idt[num].flags = flags;
|
||||
}
|
||||
|
||||
struct idt_entry* i86_idt_get_gate(unsigned char num)
|
||||
{
|
||||
return &idt[num];
|
||||
}
|
||||
|
||||
/* Installs the IDT */
|
||||
void i86_idt_install()
|
||||
{
|
||||
/* Sets the special IDT pointer up, just like in 'gdt.c' */
|
||||
idtp.limit = (sizeof (struct idt_entry) * 256) - 1;
|
||||
idtp.base = (unsigned int)&idt;
|
||||
|
||||
/* Clear out the entire IDT, initializing it to zeros */
|
||||
memset (&idt, 0, sizeof(struct idt_entry) * 256);
|
||||
|
||||
/* Points the processor's internal register to the new IDT */
|
||||
i86_idt_load();
|
||||
}
|
32
SysCore/hal/idt/idt.h
Normal file
32
SysCore/hal/idt/idt.h
Normal file
@ -0,0 +1,32 @@
|
||||
/******************************************************************
|
||||
* idt.h - INTERRUPT DESCRIPTOR TABLE *
|
||||
* Contains structures and function declarations for IDT *
|
||||
******************************************************************/
|
||||
|
||||
#ifndef __IDT_H
|
||||
#define __IDT_H
|
||||
|
||||
/* Defines an IDT entry */
|
||||
struct idt_entry
|
||||
{
|
||||
unsigned short base_lo;
|
||||
unsigned short sel;
|
||||
unsigned char always0;
|
||||
unsigned char flags;
|
||||
unsigned short base_hi;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct idt_ptr
|
||||
{
|
||||
unsigned short limit;
|
||||
unsigned int base;
|
||||
} __attribute__((packed));
|
||||
|
||||
|
||||
/* This exists in 'start.asm', and is used to load our IDT */
|
||||
extern void i86_idt_load();
|
||||
extern void i86_idt_set_gate(unsigned char num, unsigned long base, unsigned short sel, unsigned char flags);
|
||||
extern struct idt_entry* i86_idt_get_gate(unsigned char num);
|
||||
extern void i86_idt_install();
|
||||
|
||||
#endif
|
19
SysCore/hal/irq/compile.bat
Normal file
19
SysCore/hal/irq/compile.bat
Normal file
@ -0,0 +1,19 @@
|
||||
@echo off
|
||||
rem The name of the loader assembly file (without extension, must be .asm):
|
||||
set loader_name=loader
|
||||
|
||||
rem NASM and DJGPP executable paths:
|
||||
set nasm_path=C:\nasm
|
||||
set djgpp_path=C:\DJGPP\bin
|
||||
set objpath=../../objects
|
||||
set incpath=../../include
|
||||
|
||||
@echo on
|
||||
%nasm_path%\nasm.exe -f aout -o %objpath%/irq_asm.o irq.asm
|
||||
%djgpp_path%\gcc.exe -Wall -O -fstrength-reduce -fomit-frame-pointer -nostdinc -fno-builtin -I%incpath% -c -o %objpath%/irq.o irq.c
|
||||
|
||||
@echo off
|
||||
@echo .
|
||||
@echo Done!
|
||||
|
||||
@pause
|
159
SysCore/hal/irq/irq.asm
Normal file
159
SysCore/hal/irq/irq.asm
Normal file
@ -0,0 +1,159 @@
|
||||
bits 32
|
||||
|
||||
; !!! IRQ !!!
|
||||
global _i86_irq0
|
||||
global _i86_irq1
|
||||
global _i86_irq2
|
||||
global _i86_irq3
|
||||
global _i86_irq4
|
||||
global _i86_irq5
|
||||
global _i86_irq6
|
||||
global _i86_irq7
|
||||
global _i86_irq8
|
||||
global _i86_irq9
|
||||
global _i86_irq10
|
||||
global _i86_irq11
|
||||
global _i86_irq12
|
||||
global _i86_irq13
|
||||
global _i86_irq14
|
||||
global _i86_irq15
|
||||
|
||||
; 32: IRQ0
|
||||
_i86_irq0:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 32; Note that these don't push an error code on the stack:
|
||||
; We need to push a dummy error code
|
||||
jmp irq_common_stub
|
||||
|
||||
; 33: IRQ1
|
||||
_i86_irq1:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 33
|
||||
jmp irq_common_stub
|
||||
|
||||
; 34: IRQ2
|
||||
_i86_irq2:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 34
|
||||
jmp irq_common_stub
|
||||
|
||||
; 35: IRQ3
|
||||
_i86_irq3:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 35
|
||||
jmp irq_common_stub
|
||||
|
||||
; 36: IRQ4
|
||||
_i86_irq4:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 36
|
||||
jmp irq_common_stub
|
||||
|
||||
; 37: IRQ5
|
||||
_i86_irq5:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 37
|
||||
jmp irq_common_stub
|
||||
|
||||
; 38: IRQ6
|
||||
_i86_irq6:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 38
|
||||
jmp irq_common_stub
|
||||
|
||||
; 39: IRQ7
|
||||
_i86_irq7:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 39
|
||||
jmp irq_common_stub
|
||||
|
||||
; 40: IRQ8
|
||||
_i86_irq8:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 40
|
||||
jmp irq_common_stub
|
||||
; 41: IRQ9
|
||||
_i86_irq9:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 41
|
||||
jmp irq_common_stub
|
||||
|
||||
; 42: IRQ10
|
||||
_i86_irq10:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 42
|
||||
jmp irq_common_stub
|
||||
|
||||
; 43: IRQ11
|
||||
_i86_irq11:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 43
|
||||
jmp irq_common_stub
|
||||
|
||||
; 44: IRQ12
|
||||
_i86_irq12:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 44
|
||||
jmp irq_common_stub
|
||||
|
||||
; 45: IRQ13
|
||||
_i86_irq13:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 45
|
||||
jmp irq_common_stub
|
||||
|
||||
; 46: IRQ14
|
||||
_i86_irq14:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 46
|
||||
jmp irq_common_stub
|
||||
|
||||
; 47: IRQ15
|
||||
_i86_irq15:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 47
|
||||
jmp irq_common_stub
|
||||
|
||||
extern _i86_irq_handler
|
||||
|
||||
; This is a stub that we have created for IRQ based ISRs. This calls
|
||||
; '_i86_irq_handler' in our C code. We need to create this in an 'irq.c'
|
||||
irq_common_stub:
|
||||
pusha
|
||||
push ds
|
||||
push es
|
||||
push fs
|
||||
push gs
|
||||
mov ax, 0x10
|
||||
mov ds, ax
|
||||
mov es, ax
|
||||
mov fs, ax
|
||||
mov gs, ax
|
||||
mov eax, esp
|
||||
push eax
|
||||
mov eax, _i86_irq_handler
|
||||
call eax
|
||||
pop eax
|
||||
pop gs
|
||||
pop fs
|
||||
pop es
|
||||
pop ds
|
||||
popa
|
||||
add esp, 8
|
||||
iret
|
79
SysCore/hal/irq/irq.c
Normal file
79
SysCore/hal/irq/irq.c
Normal file
@ -0,0 +1,79 @@
|
||||
#include <system.h>
|
||||
#include "../idt/idt.h"
|
||||
#include "../pic/pic.h"
|
||||
#include "irq.h"
|
||||
/* This array is actually an array of function pointers. We use
|
||||
* this to handle custom IRQ handlers for a given IRQ */
|
||||
void *irq_routines[16] =
|
||||
{
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
/* This installs a custom IRQ handler for the given IRQ */
|
||||
void i86_irq_install_handler (int irq, void (*handler)(ISR_stack_regs *r))
|
||||
{
|
||||
irq_routines[irq] = handler;
|
||||
}
|
||||
|
||||
void i86_irq_uninstall_handler (int irq)
|
||||
{
|
||||
irq_routines[irq] = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* We first remap the interrupt controllers, and then we install
|
||||
* the appropriate ISRs to the correct entries in the IDT. This
|
||||
* is just like installing the exception handlers */
|
||||
void i86_irq_install()
|
||||
{
|
||||
i86_pic_remap(32,40);
|
||||
|
||||
i86_idt_set_gate(32, (unsigned)i86_irq0, 0x08, 0x8E);
|
||||
i86_idt_set_gate(33, (unsigned)i86_irq1, 0x08, 0x8E);
|
||||
i86_idt_set_gate(34, (unsigned)i86_irq2, 0x08, 0x8E);
|
||||
i86_idt_set_gate(35, (unsigned)i86_irq3, 0x08, 0x8E);
|
||||
i86_idt_set_gate(36, (unsigned)i86_irq4, 0x08, 0x8E);
|
||||
i86_idt_set_gate(37, (unsigned)i86_irq5, 0x08, 0x8E);
|
||||
i86_idt_set_gate(38, (unsigned)i86_irq6, 0x08, 0x8E);
|
||||
i86_idt_set_gate(39, (unsigned)i86_irq7, 0x08, 0x8E);
|
||||
i86_idt_set_gate(40, (unsigned)i86_irq8, 0x08, 0x8E);
|
||||
i86_idt_set_gate(41, (unsigned)i86_irq9, 0x08, 0x8E);
|
||||
i86_idt_set_gate(42, (unsigned)i86_irq10, 0x08, 0x8E);
|
||||
i86_idt_set_gate(43, (unsigned)i86_irq11, 0x08, 0x8E);
|
||||
i86_idt_set_gate(44, (unsigned)i86_irq12, 0x08, 0x8E);
|
||||
i86_idt_set_gate(45, (unsigned)i86_irq13, 0x08, 0x8E);
|
||||
i86_idt_set_gate(46, (unsigned)i86_irq14, 0x08, 0x8E);
|
||||
i86_idt_set_gate(47, (unsigned)i86_irq15, 0x08, 0x8E);
|
||||
}
|
||||
|
||||
/* Each of the IRQ ISRs point to this function, rather than
|
||||
* the 'fault_handler' in 'isrs.c'. The IRQ Controllers need
|
||||
* to be told when you are done servicing them, so you need
|
||||
* to send them an "End of Interrupt" command (0x20). There
|
||||
* are two 8259 chips: The first exists at 0x20, the second
|
||||
* exists at 0xA0. If the second controller (an IRQ from 8 to
|
||||
* 15) gets an interrupt, you need to acknowledge the
|
||||
* interrupt at BOTH controllers, otherwise, you only send
|
||||
* an EOI command to the first controller. If you don't send
|
||||
* an EOI, you won't raise any more IRQs */
|
||||
void i86_irq_handler (ISR_stack_regs *r)
|
||||
{
|
||||
/* This is a blank function pointer */
|
||||
void (*handler)(ISR_stack_regs *r);
|
||||
|
||||
/* Find out if we have a custom handler to run for this
|
||||
* IRQ, and then finally, run it */
|
||||
handler = irq_routines[r->int_no - 32];
|
||||
if (handler) handler(r);
|
||||
|
||||
/* If the IDT entry that was invoked was greater than 40
|
||||
* (meaning IRQ8 - 15), then we need to send an EOI to
|
||||
* the slave controller */
|
||||
if (r->int_no >=40) outportb(0x0A, 0x20);
|
||||
|
||||
/* In either case, we need to send an EOI to the master
|
||||
* interrupt controller too */
|
||||
outportb(0x20, 0x20);
|
||||
}
|
29
SysCore/hal/irq/irq.h
Normal file
29
SysCore/hal/irq/irq.h
Normal file
@ -0,0 +1,29 @@
|
||||
#ifndef __IRQ_H
|
||||
#define __IRQ_H
|
||||
|
||||
/* These are own ISRs that point to our special IRQ handler
|
||||
* instead of the regular 'fault_handler' function */
|
||||
|
||||
extern void i86_irq0();
|
||||
extern void i86_irq1();
|
||||
extern void i86_irq2();
|
||||
extern void i86_irq3();
|
||||
extern void i86_irq4();
|
||||
extern void i86_irq5();
|
||||
extern void i86_irq6();
|
||||
extern void i86_irq7();
|
||||
extern void i86_irq8();
|
||||
extern void i86_irq9();
|
||||
extern void i86_irq10();
|
||||
extern void i86_irq11();
|
||||
extern void i86_irq12();
|
||||
extern void i86_irq13();
|
||||
extern void i86_irq14();
|
||||
extern void i86_irq15();
|
||||
|
||||
extern void i86_irq_install_handler (int irq, void (*handler)(ISR_stack_regs *r));
|
||||
extern void i86_irq_uninstall_handler (int irq);
|
||||
extern void i86_irq_install();
|
||||
extern void i86_irq_handler (ISR_stack_regs *r);
|
||||
|
||||
#endif
|
79
SysCore/hal/isrs/BSOD.c
Normal file
79
SysCore/hal/isrs/BSOD.c
Normal file
@ -0,0 +1,79 @@
|
||||
#include <system.h>
|
||||
#include <conio.h>
|
||||
|
||||
char *exception_messages[] = {
|
||||
"Division By Zero Exception",
|
||||
"Debug Exception",
|
||||
"Non Maskable Interrupt Exception",
|
||||
"Breakpoint Exception",
|
||||
"Into Detected Overflow Exception",
|
||||
"Out of Bounds Exception",
|
||||
"Invalid Opcode Exception",
|
||||
"No Coprocessor",
|
||||
"Double Fault Exception",
|
||||
"Coprocessor Segment Overrun Exception",
|
||||
"Bad TSS Exception",
|
||||
"Segment Not Present Exception",
|
||||
"Stack Fault Exception",
|
||||
"General Protection Fault Exception",
|
||||
"Page Fault Exception",
|
||||
"Unknown Interrupt Exception",
|
||||
"Coprocessor Fault Exception",
|
||||
"Alignment Check Exception",
|
||||
"Machine Check Exception",
|
||||
"Reserved Exception",
|
||||
"Reserved Exception",
|
||||
"Reserved Exception",
|
||||
"Reserved Exception",
|
||||
"Reserved Exception",
|
||||
"Reserved Exception",
|
||||
"Reserved Exception",
|
||||
"Reserved Exception",
|
||||
"Reserved Exception",
|
||||
"Reserved Exception",
|
||||
"Reserved Exception",
|
||||
"Reserved Exception"
|
||||
};
|
||||
|
||||
|
||||
void _STOP_ERROR_SCREEN (ISR_stack_regs *r)
|
||||
{
|
||||
set_default_colors (0x01, 0x0F); clrscr();
|
||||
puts (" Blue Screen Of Death\n");
|
||||
int i; for (i = 79; i>=0; i--) putc('=');
|
||||
puts_pos_font (15, 2, "A fatal error has occured, CTA OS has been halted.", 0x01, 0x0C);
|
||||
puts_pos_font (10, 4, "gs", 0x01, 0x0B); put_hex_pos(15, 4, r->gs);
|
||||
puts_pos_font (10, 5, "fs", 0x01, 0x0B); put_hex_pos(15, 5, r->fs);
|
||||
puts_pos_font (10, 6, "es", 0x01, 0x0B); put_hex_pos(15, 6, r->es);
|
||||
puts_pos_font (10, 7, "ds", 0x01, 0x0B); put_hex_pos(15, 7, r->ds);
|
||||
|
||||
puts_pos_font (40, 4, "edi", 0x01, 0x0B); put_hex_pos(45, 4, r->edi);
|
||||
puts_pos_font (40, 5, "esi", 0x01, 0x0B); put_hex_pos(45, 5, r->esi);
|
||||
puts_pos_font (40, 6, "ebp", 0x01, 0x0B); put_hex_pos(45, 6, r->ebp);
|
||||
puts_pos_font (40, 7, "esp", 0x01, 0x0B); put_hex_pos(45, 7, r->esp);
|
||||
|
||||
puts_pos_font (10, 9, "eax", 0x01, 0x0B); put_hex_pos(15, 9, r->eax);
|
||||
puts_pos_font (10, 10, "ebx", 0x01, 0x0B); put_hex_pos(15, 10, r->ebx);
|
||||
puts_pos_font (40, 9, "ecx", 0x01, 0x0B); put_hex_pos(45, 9, r->ecx);
|
||||
puts_pos_font (40, 10, "edx", 0x01, 0x0B); put_hex_pos(45, 10, r->edx);
|
||||
|
||||
puts_pos_font (10, 12, "int_no", 0x01, 0x0B); put_hex_pos(17, 12, r->int_no);
|
||||
puts_pos_font (10, 14, "Error code:", 0x01, 0x0B); put_hex_pos(24, 14, r->err_code);
|
||||
puts_pos_font (10, 15, "Error msg: ", 0x01, 0x0B); puts_pos(24, 15, exception_messages[r->int_no]);
|
||||
|
||||
puts_pos_font (10, 17, "eip", 0x01, 0x0B); put_hex_pos(17, 17, r->eip);
|
||||
puts_pos_font (10, 18, "cs", 0x01, 0x0B); put_hex_pos(17, 18, r->cs);
|
||||
puts_pos_font (10, 19, "eflags", 0x01, 0x0B); put_hex_pos(17, 19, r->eflags);
|
||||
puts_pos_font (10, 20, "useresp", 0x01, 0x0B); put_hex_pos(17, 20, r->useresp);
|
||||
puts_pos_font (10, 21, "ss", 0x01, 0x0B); put_hex_pos(17, 21, r->ss);
|
||||
|
||||
puts_pos_font (29, 24, "!!! System Halted !!!", 0x01, 0x0C);
|
||||
}
|
||||
|
||||
/*void _STOP_ERROR_SCREEN (ISR_stack_regs *r)
|
||||
{
|
||||
puts_pos_font (30, 24, "Stop error 0x", 0x01, 0x0B); put_hex_pos(37, 24, r->int_no);
|
||||
puts_pos(50, 24, exception_messages[r->int_no]);
|
||||
|
||||
puts_pos_font (5, 24, "!!! System Halted !!!", 0x01, 0x0C);
|
||||
}*/
|
20
SysCore/hal/isrs/compile.bat
Normal file
20
SysCore/hal/isrs/compile.bat
Normal file
@ -0,0 +1,20 @@
|
||||
@echo off
|
||||
rem The name of the loader assembly file (without extension, must be .asm):
|
||||
set loader_name=loader
|
||||
|
||||
rem NASM and DJGPP executable paths:
|
||||
set nasm_path=C:\nasm
|
||||
set djgpp_path=C:\DJGPP\bin
|
||||
set objpath=../../objects
|
||||
set incpath=../../include
|
||||
|
||||
@echo on
|
||||
%nasm_path%\nasm.exe -f aout -o %objpath%/isrs_asm.o isrs.asm
|
||||
%djgpp_path%\gcc.exe -Wall -O -fstrength-reduce -fomit-frame-pointer -nostdinc -fno-builtin -I%incpath% -c -o %objpath%/isrs.o isrs.c
|
||||
%djgpp_path%\gcc.exe -Wall -O -fstrength-reduce -fomit-frame-pointer -nostdinc -fno-builtin -I%incpath% -c -o %objpath%/BSOD.o BSOD.c
|
||||
|
||||
@echo off
|
||||
@echo .
|
||||
@echo Done!
|
||||
|
||||
@pause
|
217
SysCore/hal/isrs/isrs.asm
Normal file
217
SysCore/hal/isrs/isrs.asm
Normal file
@ -0,0 +1,217 @@
|
||||
bits 32
|
||||
|
||||
; !!! ISRs !!!
|
||||
global _i86_isr0
|
||||
global _i86_isr1
|
||||
global _i86_isr2
|
||||
global _i86_isr3
|
||||
global _i86_isr4
|
||||
global _i86_isr5
|
||||
global _i86_isr6
|
||||
global _i86_isr7
|
||||
global _i86_isr8
|
||||
global _i86_isr9
|
||||
global _i86_isr10
|
||||
global _i86_isr11
|
||||
global _i86_isr12
|
||||
global _i86_isr13
|
||||
global _i86_isr14
|
||||
global _i86_isr15
|
||||
global _i86_isr16
|
||||
global _i86_isr17
|
||||
global _i86_isr18
|
||||
global _i86_isr19
|
||||
global _i86_isr20
|
||||
global _i86_isr21
|
||||
global _i86_isr22
|
||||
global _i86_isr23
|
||||
global _i86_isr24
|
||||
global _i86_isr25
|
||||
global _i86_isr26
|
||||
global _i86_isr27
|
||||
global _i86_isr28
|
||||
global _i86_isr29
|
||||
global _i86_isr30
|
||||
global _i86_isr31
|
||||
|
||||
_i86_isr0:
|
||||
cli
|
||||
push byte 0; A normal ISR stub that pops a dummy error code to keep a
|
||||
; uniform stack frame
|
||||
push byte 0
|
||||
jmp isr_common_stub
|
||||
_i86_isr1:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 1
|
||||
jmp isr_common_stub
|
||||
_i86_isr2:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 2
|
||||
jmp isr_common_stub
|
||||
_i86_isr3:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 3
|
||||
jmp isr_common_stub
|
||||
_i86_isr4:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 4
|
||||
jmp isr_common_stub
|
||||
_i86_isr5:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 5
|
||||
jmp isr_common_stub
|
||||
_i86_isr6:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 6
|
||||
jmp isr_common_stub
|
||||
_i86_isr7:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 7
|
||||
jmp isr_common_stub
|
||||
_i86_isr8:
|
||||
cli
|
||||
push byte 8
|
||||
jmp isr_common_stub
|
||||
_i86_isr9:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 9
|
||||
jmp isr_common_stub
|
||||
_i86_isr10:
|
||||
cli
|
||||
push byte 10
|
||||
jmp isr_common_stub
|
||||
_i86_isr11:
|
||||
cli
|
||||
push byte 11
|
||||
jmp isr_common_stub
|
||||
_i86_isr12:
|
||||
cli
|
||||
push byte 12
|
||||
jmp isr_common_stub
|
||||
_i86_isr13:
|
||||
cli
|
||||
push byte 13
|
||||
jmp isr_common_stub
|
||||
_i86_isr14:
|
||||
cli
|
||||
push byte 14
|
||||
jmp isr_common_stub
|
||||
_i86_isr15:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 15
|
||||
jmp isr_common_stub
|
||||
_i86_isr16:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 16
|
||||
jmp isr_common_stub
|
||||
_i86_isr17:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 17
|
||||
jmp isr_common_stub
|
||||
_i86_isr18:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 18
|
||||
jmp isr_common_stub
|
||||
_i86_isr19:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 19
|
||||
jmp isr_common_stub
|
||||
_i86_isr20:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 20
|
||||
jmp isr_common_stub
|
||||
_i86_isr21:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 21
|
||||
jmp isr_common_stub
|
||||
_i86_isr22:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 22
|
||||
jmp isr_common_stub
|
||||
_i86_isr23:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 23
|
||||
jmp isr_common_stub
|
||||
_i86_isr24:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 24
|
||||
jmp isr_common_stub
|
||||
_i86_isr25:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 25
|
||||
jmp isr_common_stub
|
||||
_i86_isr26:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 26
|
||||
jmp isr_common_stub
|
||||
_i86_isr27:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 27
|
||||
jmp isr_common_stub
|
||||
_i86_isr28:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 28
|
||||
jmp isr_common_stub
|
||||
_i86_isr29:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 29
|
||||
jmp isr_common_stub
|
||||
_i86_isr30:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 30
|
||||
jmp isr_common_stub
|
||||
_i86_isr31:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 31
|
||||
jmp isr_common_stub
|
||||
|
||||
extern _i86_fault_handler
|
||||
|
||||
isr_common_stub:
|
||||
pusha
|
||||
push ds
|
||||
push es
|
||||
push fs
|
||||
push gs
|
||||
mov ax, 0x10 ; Load the Kernel Data Segment descriptor!
|
||||
mov ds, ax
|
||||
mov es, ax
|
||||
mov fs, ax
|
||||
mov gs, ax
|
||||
mov eax, esp ; Push us the stack
|
||||
push eax
|
||||
mov eax, _i86_fault_handler
|
||||
call eax ; A special call, preserves the 'eip' register
|
||||
pop eax
|
||||
pop gs
|
||||
pop fs
|
||||
pop es
|
||||
pop ds
|
||||
popa
|
||||
add esp, 8 ; Cleans up the pushed error code and pushed ISR number
|
||||
iret ; pops 5 things at once: CS, EIP, EFLAGS, SS, and ESP!
|
70
SysCore/hal/isrs/isrs.c
Normal file
70
SysCore/hal/isrs/isrs.c
Normal file
@ -0,0 +1,70 @@
|
||||
#include <system.h>
|
||||
#include "isrs.h"
|
||||
#include "../idt/idt.h"
|
||||
|
||||
extern void _STOP_ERROR_SCREEN(ISR_stack_regs *);
|
||||
/* This is a very repetitive function... it's not hard, it's
|
||||
* just annoying. As you can see, we set the first 32 entries
|
||||
* in the IDT to the first 32 ISRs. We can't use a for loop
|
||||
* for this, because there is no way to get the function names
|
||||
* that correspond to that given entry. We set the access
|
||||
* flags to 0x8E. This means that the entry is present, is
|
||||
* running in ring 0 (kernel level), and has the lower 5 bits
|
||||
* set to the required '14', which is represented by 'E' in
|
||||
* hex. */
|
||||
void i86_isrs_install()
|
||||
{
|
||||
i86_idt_set_gate(0, (unsigned)i86_isr0, 0x08, 0x8E);
|
||||
i86_idt_set_gate(1, (unsigned)i86_isr1, 0x08, 0x8E);
|
||||
i86_idt_set_gate(2, (unsigned)i86_isr2, 0x08, 0x8E);
|
||||
i86_idt_set_gate(3, (unsigned)i86_isr3, 0x08, 0x8E);
|
||||
i86_idt_set_gate(4, (unsigned)i86_isr4, 0x08, 0x8E);
|
||||
i86_idt_set_gate(5, (unsigned)i86_isr5, 0x08, 0x8E);
|
||||
i86_idt_set_gate(6, (unsigned)i86_isr6, 0x08, 0x8E);
|
||||
i86_idt_set_gate(7, (unsigned)i86_isr7, 0x08, 0x8E);
|
||||
i86_idt_set_gate(8, (unsigned)i86_isr8, 0x08, 0x8E);
|
||||
i86_idt_set_gate(9, (unsigned)i86_isr9, 0x08, 0x8E);
|
||||
i86_idt_set_gate(10, (unsigned)i86_isr10, 0x08, 0x8E);
|
||||
i86_idt_set_gate(11, (unsigned)i86_isr11, 0x08, 0x8E);
|
||||
i86_idt_set_gate(12, (unsigned)i86_isr12, 0x08, 0x8E);
|
||||
i86_idt_set_gate(13, (unsigned)i86_isr13, 0x08, 0x8E);
|
||||
i86_idt_set_gate(14, (unsigned)i86_isr14, 0x08, 0x8E);
|
||||
i86_idt_set_gate(15, (unsigned)i86_isr15, 0x08, 0x8E);
|
||||
i86_idt_set_gate(16, (unsigned)i86_isr16, 0x08, 0x8E);
|
||||
i86_idt_set_gate(17, (unsigned)i86_isr17, 0x08, 0x8E);
|
||||
i86_idt_set_gate(18, (unsigned)i86_isr18, 0x08, 0x8E);
|
||||
i86_idt_set_gate(19, (unsigned)i86_isr19, 0x08, 0x8E);
|
||||
i86_idt_set_gate(20, (unsigned)i86_isr20, 0x08, 0x8E);
|
||||
i86_idt_set_gate(21, (unsigned)i86_isr21, 0x08, 0x8E);
|
||||
i86_idt_set_gate(22, (unsigned)i86_isr22, 0x08, 0x8E);
|
||||
i86_idt_set_gate(23, (unsigned)i86_isr23, 0x08, 0x8E);
|
||||
i86_idt_set_gate(24, (unsigned)i86_isr24, 0x08, 0x8E);
|
||||
i86_idt_set_gate(25, (unsigned)i86_isr25, 0x08, 0x8E);
|
||||
i86_idt_set_gate(26, (unsigned)i86_isr26, 0x08, 0x8E);
|
||||
i86_idt_set_gate(27, (unsigned)i86_isr27, 0x08, 0x8E);
|
||||
i86_idt_set_gate(28, (unsigned)i86_isr28, 0x08, 0x8E);
|
||||
i86_idt_set_gate(29, (unsigned)i86_isr29, 0x08, 0x8E);
|
||||
i86_idt_set_gate(30, (unsigned)i86_isr30, 0x08, 0x8E);
|
||||
i86_idt_set_gate(31, (unsigned)i86_isr31, 0x08, 0x8E);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* All of our Exception handling Interrupt Service Routines will
|
||||
* point to this function. This will tell us what exception has
|
||||
* happened! Right now, we simply halt the system by hitting an
|
||||
* endless loop. All ISRs disable interrupts while they are being
|
||||
* serviced as a 'locking' mechanism to prevent an IRQ from
|
||||
* happening and messing up kernel data structures */
|
||||
void i86_fault_handler(ISR_stack_regs *r)
|
||||
{
|
||||
/* Is this a fault whose number is from 0 to 31? */
|
||||
if (r->int_no < 32)
|
||||
{
|
||||
_STOP_ERROR_SCREEN(r);
|
||||
/* Display the description for the Exception that occurred.*/
|
||||
|
||||
/* Put on the BSOD screen*/
|
||||
for (;;);
|
||||
}
|
||||
}
|
40
SysCore/hal/isrs/isrs.h
Normal file
40
SysCore/hal/isrs/isrs.h
Normal file
@ -0,0 +1,40 @@
|
||||
#ifndef __ISRS_H
|
||||
#define __ISRS_H
|
||||
|
||||
extern void i86_isr0();
|
||||
extern void i86_isr1();
|
||||
extern void i86_isr2();
|
||||
extern void i86_isr3();
|
||||
extern void i86_isr4();
|
||||
extern void i86_isr5();
|
||||
extern void i86_isr6();
|
||||
extern void i86_isr7();
|
||||
extern void i86_isr8();
|
||||
extern void i86_isr9();
|
||||
extern void i86_isr10();
|
||||
extern void i86_isr11();
|
||||
extern void i86_isr12();
|
||||
extern void i86_isr13();
|
||||
extern void i86_isr14();
|
||||
extern void i86_isr15();
|
||||
extern void i86_isr16();
|
||||
extern void i86_isr17();
|
||||
extern void i86_isr18();
|
||||
extern void i86_isr19();
|
||||
extern void i86_isr20();
|
||||
extern void i86_isr21();
|
||||
extern void i86_isr22();
|
||||
extern void i86_isr23();
|
||||
extern void i86_isr24();
|
||||
extern void i86_isr25();
|
||||
extern void i86_isr26();
|
||||
extern void i86_isr27();
|
||||
extern void i86_isr28();
|
||||
extern void i86_isr29();
|
||||
extern void i86_isr30();
|
||||
extern void i86_isr31();
|
||||
|
||||
extern void i86_isrs_install();
|
||||
extern void i86_fault_handler(ISR_stack_regs *r);
|
||||
|
||||
#endif
|
18
SysCore/hal/keyboard/compile.bat
Normal file
18
SysCore/hal/keyboard/compile.bat
Normal file
@ -0,0 +1,18 @@
|
||||
@echo off
|
||||
rem The name of the loader assembly file (without extension, must be .asm):
|
||||
set loader_name=loader
|
||||
|
||||
rem NASM and DJGPP executable paths:
|
||||
set nasm_path=C:\nasm
|
||||
set djgpp_path=C:\DJGPP\bin
|
||||
set objpath=../../objects
|
||||
set incpath=../../include
|
||||
|
||||
@echo on
|
||||
%djgpp_path%\gcc.exe -Wall -O -fstrength-reduce -fomit-frame-pointer -nostdinc -fno-builtin -I%incpath% -c -o %objpath%/keyus.o keyus.c
|
||||
|
||||
@echo off
|
||||
@echo .
|
||||
@echo Done!
|
||||
|
||||
@pause
|
135
SysCore/hal/keyboard/key_list.txt
Normal file
135
SysCore/hal/keyboard/key_list.txt
Normal file
@ -0,0 +1,135 @@
|
||||
*0x00 Pause/Break
|
||||
0x01 F9
|
||||
0x02 F7
|
||||
0x03 F5
|
||||
0x04 F3
|
||||
0x05 F1
|
||||
0x06 F2
|
||||
0x07 F12
|
||||
0x08 Print Screen
|
||||
0x09 F10
|
||||
0x0A F8
|
||||
0x0B F6
|
||||
0x0C F4
|
||||
0x0D Tab
|
||||
0x0E `~
|
||||
0x0F
|
||||
|
||||
0x10
|
||||
0x11
|
||||
0x12
|
||||
0x13
|
||||
0x14
|
||||
0x15 Q
|
||||
0x16 1!
|
||||
0x17
|
||||
0x18
|
||||
0x19
|
||||
0x1A Z
|
||||
0x1B S
|
||||
0x1C A
|
||||
0x1D W
|
||||
0x1E 2@
|
||||
0x1F LeftWin
|
||||
|
||||
0x20
|
||||
0x21 C
|
||||
0x22 X
|
||||
0x23 D
|
||||
0x24 E
|
||||
0x25 4$
|
||||
0x26 3#
|
||||
0x27 RightWin
|
||||
0x28
|
||||
0x29 Space
|
||||
0x2A V
|
||||
0x2B F
|
||||
0x2C T
|
||||
0x2D R
|
||||
0x2E 5%
|
||||
0x2F Menu
|
||||
|
||||
0x30
|
||||
0x31 N
|
||||
0x32 B
|
||||
0x33 H
|
||||
0x34 G
|
||||
0x35 Y
|
||||
0x36 6^
|
||||
0x37
|
||||
0x38
|
||||
0x39
|
||||
0x3A M
|
||||
0x3B J
|
||||
0x3C U
|
||||
0x3D 7&
|
||||
0x3E 8*
|
||||
0x3F
|
||||
|
||||
0x40
|
||||
0x41 ,<
|
||||
0x42 K
|
||||
0x43 I
|
||||
0x44 O
|
||||
0x45 0)
|
||||
0x46 9(
|
||||
0x47
|
||||
0x48
|
||||
0x49 .>
|
||||
0x4A /?
|
||||
0x4B L
|
||||
0x4C ;:
|
||||
0x4D P
|
||||
0x4E -_
|
||||
0x4F
|
||||
|
||||
0x50
|
||||
0x51
|
||||
0x52 '"
|
||||
0x53
|
||||
0x54 [{
|
||||
0x55 =+
|
||||
0x56
|
||||
0x57
|
||||
0x58
|
||||
0x59 Numpad Enter
|
||||
0x5A Enter
|
||||
0x5B ]}
|
||||
0x5C
|
||||
0x5D \|
|
||||
0x5E End
|
||||
0x5F Left
|
||||
|
||||
0x60 Home
|
||||
0x61 Insert
|
||||
0x62 Delete
|
||||
0x63 Down
|
||||
0x64 Right
|
||||
0x65 Up
|
||||
0x66 Backspace
|
||||
0x67 PageDown
|
||||
0x68 PageUp
|
||||
0x69 Numpad 1 (end)
|
||||
0x6A Numpad /
|
||||
0x6B Numpad 4 (left)
|
||||
0x6C Numpad 7 (Home)
|
||||
0x6D
|
||||
0x6E
|
||||
0x6F
|
||||
|
||||
0x70 Numpad 0 (insert)
|
||||
0x71 Numpad . (del)
|
||||
0x72 Numpad 2 (down)
|
||||
0x73 Numpad 5
|
||||
0x74 Numpad 6 (right)
|
||||
0x75 Numpad 8 (up)
|
||||
0x76 Esc
|
||||
0x77
|
||||
0x78 F11
|
||||
0x79 Numpad +
|
||||
0x7A Numpad 3 (pgdwn)
|
||||
0x7B Numpad -
|
||||
0x7C Numpad *
|
||||
0x7D Numpad 9 (pgup)
|
||||
0x7E
|
||||
0x7F
|
133
SysCore/hal/keyboard/keyboard.h
Normal file
133
SysCore/hal/keyboard/keyboard.h
Normal file
@ -0,0 +1,133 @@
|
||||
|
||||
#define KB_KEY_LSHIFT 0x81 // 1000 0001
|
||||
#define KB_KEY_RSHIFT 0X82 // 1000 0010
|
||||
#define KB_KEY_LALT 0X84 // 1000 0100
|
||||
#define KB_KEY_RALT 0x88 // 1000 1000
|
||||
#define KB_KEY_LCTRL 0x90 // 1001 0000
|
||||
#define KB_KEY_RCTRL 0xA0 // 1010 0000
|
||||
#define KB_KEY_FSHIFT 0xC0 // 1100 0000
|
||||
extern volatile byte kb_modifier_status;
|
||||
|
||||
#define KB_PREFIX_GRAY 0x01 // Gray
|
||||
#define KB_PREFIX_BREAK 0x02 // Break code
|
||||
#define KB_PREFIX_PAUSE 0x04 // Pause/break key
|
||||
#define KB_PREFIX_PAUSE1 0x08 // Recieved first byte from pause/break
|
||||
extern volatile byte kb_prefix;
|
||||
|
||||
#define KB_KEY_SCROLL 0xF1 // 1111 0001
|
||||
#define KB_KEY_NUM 0xF2 // 1111 0010
|
||||
#define KB_KEY_CAPS 0xF4 // 1111 0100
|
||||
extern volatile byte kb_lights_status;
|
||||
|
||||
extern byte kb_scancode_set;
|
||||
#define KB_KEY_PAUSE 0x00
|
||||
#define KB_KEY_F9 0x01
|
||||
#define KB_KEY_F7 0x02
|
||||
#define KB_KEY_F5 0X03
|
||||
#define KB_KEY_F3 0x04
|
||||
#define KB_KEY_F1 0x05
|
||||
#define KB_KEY_F2 0x06
|
||||
#define KB_KEY_F12 0x07
|
||||
#define KB_KEY_PRINTSCRN 0x08
|
||||
#define KB_KEY_F10 0x09
|
||||
#define KB_KEY_F8 0x0A
|
||||
#define KB_KEY_F6 0x0B
|
||||
#define KB_KEY_F4 0x0C
|
||||
#define KB_KEY_TAB 0x0D
|
||||
#define KB_KEY_TILDA 0x0E
|
||||
#define KB_KEY_Q 0x15
|
||||
#define KB_KEY_1 0x16
|
||||
#define KB_KEY_Z 0x1A
|
||||
#define KB_KEY_S 0x1B
|
||||
#define KB_KEY_A 0x1C
|
||||
#define KB_KEY_W 0x1D
|
||||
#define KB_KEY_2 0x1E
|
||||
#define KB_KEY_LWIN 0x1F
|
||||
#define KB_KEY_C 0x21
|
||||
#define KB_KEY_X 0x22
|
||||
#define KB_KEY_D 0x23
|
||||
#define KB_KEY_E 0x24
|
||||
#define KB_KEY_4 0x25
|
||||
#define KB_KEY_3 0x26
|
||||
#define KB_KEY_RWIN 0x27
|
||||
#define KB_KEY_SPACE 0x29
|
||||
#define KB_KEY_V 0x2A
|
||||
#define KB_KEY_F 0x2B
|
||||
#define KB_KEY_T 0x2C
|
||||
#define KB_KEY_R 0x2D
|
||||
#define KB_KEY_5 0x2E
|
||||
#define KB_KEY_MENU 0x2F
|
||||
#define KB_KEY_N 0x31
|
||||
#define KB_KEY_B 0x32
|
||||
#define KB_KEY_H 0x33
|
||||
#define KB_KEY_G 0x34
|
||||
#define KB_KEY_Y 0x35
|
||||
#define KB_KEY_6 0x36
|
||||
#define KB_KEY_M 0x3A
|
||||
#define KB_KEY_J 0x3B
|
||||
#define KB_KEY_U 0x3C
|
||||
#define KB_KEY_7 0x3D
|
||||
#define KB_KEY_8 0x3E
|
||||
#define KB_KEY_COMMA 0x41
|
||||
#define KB_KEY_K 0x42
|
||||
#define KB_KEY_I 0x43
|
||||
#define KB_KEY_O 0x44
|
||||
#define KB_KEY_0 0x45
|
||||
#define KB_KEY_9 0x46
|
||||
#define KB_KEY_PERIOD 0x49
|
||||
#define KB_KEY_SLASH 0x4A
|
||||
#define KB_KEY_L 0x4B
|
||||
#define KB_KEY_SEMICOLON 0x4C
|
||||
#define KB_KEY_P 0x4D
|
||||
#define KB_KEY_DASH 0x4E
|
||||
#define KB_KEY_APOSTROPHE 0x52
|
||||
#define KB_KEY_LBRACKET 0x54
|
||||
#define KB_KEY_EQUAL 0x55
|
||||
#define KB_KEY_NUMPAD_ENTER 0x59
|
||||
#define KB_KEY_ENTER 0x5A
|
||||
#define KB_KEY_RBRACKET 0x5B
|
||||
#define KB_KEY_BACKSLASH 0x5D
|
||||
#define KB_KEY_END 0x5E
|
||||
#define KB_KEY_LEFT 0x5F
|
||||
#define KB_KEY_HOME 0x60
|
||||
#define KB_KEY_INSERT 0x61
|
||||
#define KB_KEY_DELETE 0x62
|
||||
#define KB_KEY_DOWN 0x63
|
||||
#define KB_KEY_RIGHT 0x64
|
||||
#define KB_KEY_UP 0x65
|
||||
#define KB_KEY_BACKSPACE 0x66
|
||||
#define KB_KEY_PGDOWN 0x67
|
||||
#define KB_KEY_PGUP 0x68
|
||||
#define KB_KEY_NUMPAD_1 0x69
|
||||
#define KB_KEY_NUMPAD_SLASH 0x6A
|
||||
#define KB_KEY_NUMPAD_4 0x6B
|
||||
#define KB_KEY_NUMPAD_7 0x6C
|
||||
#define KB_KEY_NUMPAD_0 0x70
|
||||
#define KB_KEY_NUMPAD_COLON 0x71
|
||||
#define KB_KEY_NUMPAD_2 0x72
|
||||
#define KB_KEY_NUMPAD_5 0x73
|
||||
#define KB_KEY_NUMPAD_6 0x74
|
||||
#define KB_KEY_NUMPAD_8 0x75
|
||||
#define KB_KEY_ESC 0x76
|
||||
#define KB_KEY_F11 0x78
|
||||
#define KB_KEY_NUMPAD_PLUS 0x79
|
||||
#define KB_KEY_NUMPAD_3 0x7A
|
||||
#define KB_KEY_NUMPAD_MINUS 0x7B
|
||||
#define KB_KEY_NUMPAD_ASTERISK 0x7C
|
||||
#define KB_KEY_NUMPAD_9 0x7D
|
||||
|
||||
|
||||
typedef struct {
|
||||
byte status;
|
||||
byte lights;
|
||||
byte scancode;
|
||||
byte character;
|
||||
} kb_key;
|
||||
|
||||
|
||||
extern char getch();
|
||||
extern kb_key get_key();
|
||||
extern scancode_to_ascii(byte scancode);
|
||||
extern byte get_key_status(byte scancode);
|
||||
extern void kb_set_repeat(float rate, int delay);
|
||||
extern void kb_set_LEDs(byte status);
|
326
SysCore/hal/keyboard/keyus.c
Normal file
326
SysCore/hal/keyboard/keyus.c
Normal file
@ -0,0 +1,326 @@
|
||||
#include <system.h>
|
||||
#include <hal.h>
|
||||
#include "keyus.h"
|
||||
#include "../irq/irq.h"
|
||||
|
||||
extern void reboot();
|
||||
|
||||
const char kbdus_map[] = {
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '\t', '`', 0,
|
||||
0, 0, 0, 0, 0, 'q', '1', 0, 0, 0, 'z', 's', 'a', 'w', '2', 0,
|
||||
0, 'c', 'x', 'd', 'e', '4', '3', 0, 0, ' ', 'v', 'f', 't', 'r', '5', 0,
|
||||
0, 'n', 'b', 'h', 'g', 'y', '6', 0, 0, 0, 'm', 'j', 'u', '7', '8', 0,
|
||||
0, ',', 'k', 'i', 'o', '0', '9', 0, 0, '.', '/', 'l', ';', 'p', '-', 0,
|
||||
0, 0, '\'', 0, '[', '=', 0, 0, 0, '\n', '\n', ']', 0, '\\', 0, 0,
|
||||
0, 0, 0x7F, 0, 0, 0, '\b', 0, 0, '1', '/', '4', '7', 0, 0, 0,
|
||||
'0', '.', '2', '5', '6', '8', 0, 0, 0, '+', '3', '-', '*', '9', 0, 0
|
||||
};
|
||||
|
||||
const char kbdus_map_shift[] = {
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '\t', '~', 0,
|
||||
0, 0, 0, 0, 0, 'Q', '!', 0, 0, 0, 'Z', 'S', 'A', 'W', '@', 0,
|
||||
0, 'C', 'X', 'D', 'E', '$', '#', 0, 0, ' ', 'V', 'F', 'T', 'R', '%', 0,
|
||||
0, 'N', 'B', 'H', 'G', 'Y', '^', 0, 0, 0, 'M', 'J', 'U', '&', '*', 0,
|
||||
0, '<', 'K', 'I', 'O', ')', '(', 0, 0, '>', '?', 'L', ':', 'P', '_', 0,
|
||||
0, 0, '\"', 0, '{', '+', 0, 0, 0, '\n', '\n', '}', 0, '|', 0, 0,
|
||||
0, 0, 0x7F, 0, 0, 0, '\b', 0, 0, '1', '/', '4', '7', 0, 0, 0,
|
||||
'0', '.', '2', '5', '6', '8', 0, 0, 0, '+', '3', '-', '*', '9', 0, 0
|
||||
};
|
||||
|
||||
|
||||
volatile byte kb_array[16];
|
||||
volatile byte kb_newdata;
|
||||
volatile byte kb_modifier_status;
|
||||
volatile byte kb_prefix;
|
||||
volatile byte kb_lights_status;
|
||||
byte kb_scancode_set;
|
||||
|
||||
|
||||
void i86_kb_set_key(byte scancode, byte val)
|
||||
{
|
||||
byte pos = scancode/8;
|
||||
byte offset = scancode%8;
|
||||
|
||||
if (val) {
|
||||
kb_array[pos] |= 1<<offset;
|
||||
kb_newdata = scancode;
|
||||
}
|
||||
else kb_array[pos] &= 0xFF - (1<<offset);
|
||||
}
|
||||
|
||||
byte i86_kb_get_key(byte scancode)
|
||||
{
|
||||
byte pos = scancode/8;
|
||||
byte offset = scancode%8;
|
||||
return (kb_array[pos]&(1<<offset));
|
||||
}
|
||||
|
||||
|
||||
void i86_kb_handler(ISR_stack_regs *r) {
|
||||
byte scancode = inportb(0x60);
|
||||
|
||||
switch (scancode) {
|
||||
case 0x00: // Error 0x00
|
||||
case 0xFC: // Diagnostics failed (MF kb)
|
||||
case 0xFD: // Diagnostics failed (AT kb)
|
||||
case 0xFF: i86_kb_waitin(); outportb(0x60, 0xF4); // Error 0xFF
|
||||
break;
|
||||
case 0xAA: // BAT test successful.
|
||||
case 0xFA: // ACKnowledge
|
||||
case 0xFE: // Last command invalid or parity error
|
||||
case 0xEE: break; // Echo response
|
||||
// Gray or break
|
||||
case 0xE0: kb_prefix |= 1; break;
|
||||
case 0xE1: kb_prefix |= 4; break;
|
||||
case 0xF0: kb_prefix |= 2; break;
|
||||
|
||||
// Alt, ctrl...
|
||||
case 0x11: if ((kb_prefix&1) == 0) { // Left alt
|
||||
if ((kb_prefix&2) == 0) kb_modifier_status |= 1<<2;
|
||||
else kb_modifier_status &= 0xFF - (1<<2);
|
||||
}
|
||||
else { // Right alt
|
||||
if ((kb_prefix&2) == 0) kb_modifier_status |= 1<<3;
|
||||
else kb_modifier_status &= 0xFF - (1<<3);
|
||||
}
|
||||
kb_prefix = 0; break;
|
||||
|
||||
case 0x12: if ((kb_prefix&1) == 0) { // Left shift
|
||||
if ((kb_prefix&2) == 0) kb_modifier_status |= 1<<0;
|
||||
else kb_modifier_status &= 0xFF - (1<<0);
|
||||
}
|
||||
else { // Fake shift
|
||||
if ((kb_prefix&2) == 0) kb_modifier_status |= 1<<6;
|
||||
else kb_modifier_status &= 0xFF - (1<<6);
|
||||
}
|
||||
kb_prefix = 0; break;
|
||||
|
||||
case 0x14: if (kb_prefix&4) {
|
||||
if ((kb_prefix&2) == 0) i86_kb_set_key (0, 1);
|
||||
else i86_kb_set_key (0, 0);
|
||||
kb_prefix |= 8; break;
|
||||
}
|
||||
|
||||
else if ((kb_prefix&1) == 0) { // Left ctrl
|
||||
if ((kb_prefix&2) == 0) kb_modifier_status |= 1<<4;
|
||||
else kb_modifier_status &= 0xFF - (1<<4);
|
||||
}
|
||||
else { // Right ctrl
|
||||
if ((kb_prefix&2) == 0) kb_modifier_status |= 1<<5;
|
||||
else kb_modifier_status &= 0xFF - (1<<5);
|
||||
}
|
||||
kb_prefix = 0; break;
|
||||
|
||||
case 0x59: // Right shift
|
||||
if ((kb_prefix&2) == 0) kb_modifier_status |= 1<<1;
|
||||
else kb_modifier_status &= 0xFF - (1<<1);
|
||||
|
||||
kb_prefix = 0; break;
|
||||
|
||||
// LEDs
|
||||
case 0x58: if ((kb_prefix&2) == 0) {
|
||||
kb_lights_status ^= 4; i86_kb_set_LEDs(kb_lights_status);
|
||||
} kb_prefix = 0; break; // Caps
|
||||
|
||||
//TO ADD BELOW: pause/break byte2
|
||||
case 0x77:
|
||||
if ((kb_prefix&4) && (kb_prefix&8)) kb_prefix=0;
|
||||
else if ((kb_prefix&2) == 0) {
|
||||
kb_lights_status ^= 2; i86_kb_set_LEDs(kb_lights_status);
|
||||
} kb_prefix = 0; break; // Num
|
||||
case 0x7E: if ((kb_prefix&2) == 0) {
|
||||
kb_lights_status ^= 1; i86_kb_set_LEDs(kb_lights_status);
|
||||
} kb_prefix = 0; break; // Scroll
|
||||
|
||||
case 0x83: scancode = 0x02; // Put F7 under the 0x80 (128bit) barrier
|
||||
|
||||
default:
|
||||
// Remap gray keys
|
||||
if (kb_prefix&1) switch (scancode) {
|
||||
case 0x7C: scancode=0x08; break; // PrintScreen
|
||||
case 0x4A: scancode=0x6A; break; // Numpad /
|
||||
case 0x5A: scancode=0x59; break; // Numpad Enter
|
||||
case 0x69: scancode=0x5E; break; // End
|
||||
case 0x6B: scancode=0x5F; break; // Left
|
||||
case 0x6C: scancode=0x60; break; // Home
|
||||
case 0x70: scancode=0x61; break; // Insert
|
||||
case 0x71: scancode=0x62; break; // Delete
|
||||
case 0x72: scancode=0x63; break; // Down
|
||||
case 0x74: scancode=0x64; break; // Right
|
||||
case 0x75: scancode=0x65; break; // Up
|
||||
case 0x7A: scancode=0x67; break; // PageDown
|
||||
case 0x7D: scancode=0x68; break; // PageUp
|
||||
}
|
||||
if ((kb_prefix&2) == 0) i86_kb_set_key(scancode, 1);
|
||||
else i86_kb_set_key(scancode, 0);
|
||||
|
||||
kb_prefix = 0; break;
|
||||
}
|
||||
|
||||
// Alt+ctrl+del = reset
|
||||
if (scancode==0x62) {
|
||||
int ok=0;
|
||||
if ((kb_modifier_status&4) || (kb_modifier_status&8)) ok++;
|
||||
if ((kb_modifier_status&16) || (kb_modifier_status&32)) ok++;
|
||||
if (ok==2) reboot();
|
||||
}
|
||||
|
||||
outportb(0x20, 0x20);
|
||||
}
|
||||
|
||||
|
||||
|
||||
kb_key getkey()
|
||||
{
|
||||
kb_key ret;
|
||||
|
||||
kb_newdata = 0xFF;
|
||||
while (kb_newdata==0xFF); // wait for keypress
|
||||
|
||||
ret.scancode = kb_newdata; // Send scancode for non-chars
|
||||
ret.status = kb_modifier_status; // Shift, ctrl... state
|
||||
ret.lights = kb_lights_status; // Num, caps.... state
|
||||
|
||||
if ((ret.status & 1) || (ret.status & 2)) // Shift is on
|
||||
ret.character = kbdus_map_shift[ret.scancode];
|
||||
else ret.character = kbdus_map[ret.scancode]; // Shift is off
|
||||
|
||||
return ret; // And send it.
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/***************************************
|
||||
* Set repeat rate/delay *
|
||||
***************************************
|
||||
Values for inter-character delay (bits 4-0)
|
||||
(characters per second; default is 10.9)
|
||||
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7
|
||||
----+----+----+----+----+----+----+----+----
|
||||
0 |30.0|26.7|24.0|21.8|20.0|18.5|17.1|16.0
|
||||
8 |15.0|13.3|12.0|10.9|10.0|9.2 |8.6 |8.0
|
||||
16 |7.5 |6.7 |6.0 |5.5 |5.0 |4.6 |4.3 |4.0
|
||||
24 |3.7 |3.3 |3.0 |2.7 |2.5 |2.3 |2.1 |2.0
|
||||
|
||||
Values for delay:
|
||||
(miliseconds; default is 500)
|
||||
0 | 1 | 2 | 3
|
||||
-----+-----+-----+-----
|
||||
250 | 500 | 750 | 1000
|
||||
|
||||
***************************************/
|
||||
void i86_kb_set_repeat(byte rate, byte delay)
|
||||
{
|
||||
if (rate>3 || delay>31) return;
|
||||
|
||||
byte out = rate<<5 | delay;
|
||||
while ((inportb(0x64)&2) != 0);
|
||||
outportb(0x60, 0xF3);
|
||||
while ((inportb(0x64)&2) != 0);
|
||||
outportb(0x60, out);
|
||||
}
|
||||
|
||||
|
||||
/***************************************
|
||||
* Set keyboard LEDs *
|
||||
***************************************
|
||||
+-----------+-------+-------+--------+
|
||||
| Bits 7-3 | Bit 2 | Bit 1 | Bit 0 |
|
||||
| 0 | Caps | Num | Scroll |
|
||||
|(reserved) | lock | lock | lock |
|
||||
+-----------+-------+-------+--------+
|
||||
***************************************/
|
||||
void i86_kb_set_LEDs(byte status)
|
||||
{
|
||||
while ((inportb (0x64)&2)!=0);
|
||||
outportb (0x60, 0xED);
|
||||
|
||||
while ((inportb (0x64)&2)!=0);
|
||||
outportb (0x60, status);
|
||||
}
|
||||
|
||||
/***************************************
|
||||
* Set scancode set *
|
||||
***************************************
|
||||
0 Get current scancode set
|
||||
1 Set to scancode set 1
|
||||
2 Set to scancode set 2
|
||||
3 Set to scancode set 3
|
||||
***************************************/
|
||||
void i86_kb_set_scancodeset(byte set)
|
||||
{
|
||||
if (set>3) return;
|
||||
|
||||
while ((inportb (0x64)&2)!=0);
|
||||
outportb (0x60, 0xF0);
|
||||
|
||||
while ((inportb (0x64)&2)!=0);
|
||||
outportb (0x60, set);
|
||||
|
||||
kb_scancode_set = set;
|
||||
}
|
||||
|
||||
byte i86_kb_get_scancodeset() {
|
||||
return kb_scancode_set;
|
||||
}
|
||||
|
||||
void i86_kb_waitin()
|
||||
{
|
||||
int fail_safe=200000;
|
||||
while ((inportb(0x64)&2)!=0 && fail_safe>0) fail_safe--;
|
||||
}
|
||||
|
||||
void i86_kb_waitout()
|
||||
{
|
||||
int fail_safe=200000;
|
||||
while ((inportb(0x64)&1)==0 && fail_safe>0) fail_safe--;
|
||||
}
|
||||
|
||||
|
||||
void i86_kb_install_partone()
|
||||
{
|
||||
i86_irq_install_handler(1, i86_kb_handler);// instali handler
|
||||
i86_kb_waitin(); outportb(0x60, 0xFF); // Reset kb
|
||||
|
||||
// Initialize variables
|
||||
kb_newdata = 0;
|
||||
kb_modifier_status = 0;
|
||||
kb_prefix = 0;
|
||||
kb_lights_status = 0;
|
||||
kb_scancode_set = 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
int i86_kb_install_parttwo()
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
// Wait for BAT test results
|
||||
byte temp;
|
||||
do temp = inportb(0x60);
|
||||
while (temp!=0xAA && temp!=0xFC);
|
||||
|
||||
if (temp == 0xFC) ret = -1;
|
||||
|
||||
// Set new repeat rate
|
||||
i86_kb_set_repeat(1, 11);
|
||||
|
||||
// Set scancode set 2
|
||||
i86_kb_set_scancodeset(2); // Set new scancode set
|
||||
|
||||
i86_kb_waitin();
|
||||
outportb(0x64, 0x20); // Get "Command byte"
|
||||
|
||||
do { temp = inportb(0x60);
|
||||
} while (temp==0xFA || temp==0xAA);
|
||||
|
||||
temp &= 0xFF - (1<<6); // Set bit6 to 0: disable conversion
|
||||
i86_kb_waitin(); outportb(0x64, 0x60); // Function to write cmd byte
|
||||
i86_kb_waitin(); outportb(0x60, temp); // Send it
|
||||
memset((void*)kb_array, 0, 16);
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
28
SysCore/hal/keyboard/keyus.h
Normal file
28
SysCore/hal/keyboard/keyus.h
Normal file
@ -0,0 +1,28 @@
|
||||
#ifndef __KEYUS_H
|
||||
#define __KEYUS_H
|
||||
|
||||
extern const char kbdus_map[0x80];
|
||||
extern const char kbdus_map_shift[0x80];
|
||||
|
||||
extern volatile byte kb_modifier_status;
|
||||
extern volatile byte kb_prefix;
|
||||
extern volatile byte kb_lights_status;
|
||||
extern byte kb_scancode_set;
|
||||
|
||||
extern void i86_kb_set_key(byte scancode, byte val);
|
||||
extern void i86_kb_set_LEDs(byte status);
|
||||
extern void i86_kb_set_repeat(byte rate, byte delay);
|
||||
extern void i86_kb_set_scancodeset(byte set);
|
||||
extern byte i86_kb_get_key(byte scancode);
|
||||
extern void i86_kb_handler(ISR_stack_regs *r);
|
||||
extern kb_key getkey();
|
||||
extern void i86_kb_set_repeat(byte rate, byte delay);
|
||||
extern void i86_kb_set_LEDs(byte status);
|
||||
extern void i86_kb_set_scancodeset(byte set);
|
||||
extern byte i86_kb_get_scancodeset();
|
||||
extern void i86_kb_waitin();
|
||||
extern void i86_kb_waitout();
|
||||
extern void i86_kb_install_partone();
|
||||
extern int i86_kb_install_parttwo();
|
||||
|
||||
#endif
|
109
SysCore/hal/makeall.bat
Normal file
109
SysCore/hal/makeall.bat
Normal file
@ -0,0 +1,109 @@
|
||||
@echo off
|
||||
set nasm_path=C:\nasm
|
||||
set djgpp_path=C:\DJGPP\bin
|
||||
|
||||
@echo Building Hardware Abstraction Layer...
|
||||
set objpath=..\objects
|
||||
set incpath=../include
|
||||
del %objpath%\hal.o
|
||||
%djgpp_path%\gcc.exe -Wall -O -fstrength-reduce -fomit-frame-pointer -nostdinc -fno-builtin -I%incpath% -c -o %objpath%/hal.o hal.c
|
||||
if not exist %objpath%\hal.o goto error
|
||||
|
||||
set objpath=..\..\objects
|
||||
set incpath=../../include
|
||||
|
||||
goto cmos
|
||||
|
||||
:error
|
||||
@echo.
|
||||
@echo There have been build errors. Building halted.
|
||||
@pause
|
||||
exit
|
||||
|
||||
:cmos
|
||||
cd cmos
|
||||
@echo * Compiling CMOS...
|
||||
del %objpath%\cmos.o
|
||||
%djgpp_path%\gcc.exe -Wall -O -fstrength-reduce -fomit-frame-pointer -nostdinc -fno-builtin -I%incpath% -c -o %objpath%/cmos.o cmos.c
|
||||
if not exist %objpath%\cmos.o goto error
|
||||
cd..
|
||||
|
||||
:cpu
|
||||
cd cpu
|
||||
@echo * Compiling Central Processing Unit...
|
||||
del %objpath%\cpu.o
|
||||
%djgpp_path%\gcc.exe -Wall -O -fstrength-reduce -fomit-frame-pointer -nostdinc -fno-builtin -I%incpath% -c -o %objpath%/cpu.o cpu.c
|
||||
if not exist %objpath%\cpu.o goto error
|
||||
|
||||
cd..
|
||||
|
||||
:gdt
|
||||
cd gdt
|
||||
@echo * Compiling Global Descriptor Table...
|
||||
del %objpath%\gdt.o
|
||||
del %objpath%\gdt_asm.o
|
||||
%nasm_path%\nasm.exe -f aout -o %objpath%/gdt_asm.o gdt.asm
|
||||
%djgpp_path%\gcc.exe -Wall -O -fstrength-reduce -fomit-frame-pointer -nostdinc -fno-builtin -I%incpath% -c -o %objpath%/gdt.o gdt.c
|
||||
if not exist %objpath%\gdt.o goto error
|
||||
if not exist %objpath%\gdt_asm.o goto error
|
||||
cd..
|
||||
|
||||
:idt
|
||||
cd idt
|
||||
@echo * Compiling Interrupt Descriptor Table...
|
||||
del %objpath%\idt.o
|
||||
del %objpath%\idt_asm.o
|
||||
%nasm_path%\nasm.exe -f aout -o %objpath%/idt_asm.o idt.asm
|
||||
%djgpp_path%\gcc.exe -Wall -O -fstrength-reduce -fomit-frame-pointer -nostdinc -fno-builtin -I%incpath% -c -o %objpath%/idt.o idt.c
|
||||
if not exist %objpath%\idt.o goto error
|
||||
if not exist %objpath%\idt_asm.o goto error
|
||||
cd..
|
||||
|
||||
:irq
|
||||
cd irq
|
||||
@echo * Compiling Interrupt ReQuests...
|
||||
del %objpath%\irq.o
|
||||
del %objpath%\irq_asm.o
|
||||
%nasm_path%\nasm.exe -f aout -o %objpath%/irq_asm.o irq.asm
|
||||
%djgpp_path%\gcc.exe -Wall -O -fstrength-reduce -fomit-frame-pointer -nostdinc -fno-builtin -I%incpath% -c -o %objpath%/irq.o irq.c
|
||||
if not exist %objpath%\irq.o goto error
|
||||
if not exist %objpath%\irq_asm.o goto error
|
||||
cd..
|
||||
|
||||
:isrs
|
||||
cd isrs
|
||||
@echo * Compiling Interrupt Service Routines...
|
||||
del %objpath%\isrs_asm.o
|
||||
del %objpath%\isrs.o
|
||||
del %objpath%\BSOD.o
|
||||
%nasm_path%\nasm.exe -f aout -o %objpath%/isrs_asm.o isrs.asm
|
||||
%djgpp_path%\gcc.exe -Wall -O -fstrength-reduce -fomit-frame-pointer -nostdinc -fno-builtin -I%incpath% -c -o %objpath%/isrs.o isrs.c
|
||||
%djgpp_path%\gcc.exe -Wall -O -fstrength-reduce -fomit-frame-pointer -nostdinc -fno-builtin -I%incpath% -c -o %objpath%/BSOD.o BSOD.c
|
||||
if not exist %objpath%\isrs_asm.o goto error
|
||||
if not exist %objpath%\isrs.o goto error
|
||||
if not exist %objpath%\BSOD.o goto error
|
||||
cd..
|
||||
|
||||
:keyboard
|
||||
cd keyboard
|
||||
@echo * Compiling KEYBOARD...
|
||||
del %objpath%\keyus.o
|
||||
%djgpp_path%\gcc.exe -Wall -O -fstrength-reduce -fomit-frame-pointer -nostdinc -fno-builtin -I%incpath% -c -o %objpath%/keyus.o keyus.c
|
||||
if not exist %objpath%\keyus.o goto error
|
||||
cd..
|
||||
|
||||
:pic
|
||||
cd pic
|
||||
@echo * Compiling Programmable Interrupt Controller...
|
||||
del %objpath%\pic.o
|
||||
%djgpp_path%\gcc.exe -Wall -O -fstrength-reduce -fomit-frame-pointer -nostdinc -fno-builtin -I%incpath% -c -o %objpath%/pic.o pic.c
|
||||
if not exist %objpath%\pic.o goto error
|
||||
cd..
|
||||
|
||||
:pit
|
||||
cd pit
|
||||
@echo * Compiling Programmable Interval Timer...
|
||||
del %objpath%\pit.o
|
||||
%djgpp_path%\gcc.exe -Wall -O -fstrength-reduce -fomit-frame-pointer -nostdinc -fno-builtin -I%incpath% -c -o %objpath%/pit.o pit.c
|
||||
if not exist %objpath%\pit.o goto error
|
||||
cd..
|
18
SysCore/hal/pic/compile.bat
Normal file
18
SysCore/hal/pic/compile.bat
Normal file
@ -0,0 +1,18 @@
|
||||
@echo off
|
||||
rem The name of the loader assembly file (without extension, must be .asm):
|
||||
set loader_name=loader
|
||||
|
||||
rem NASM and DJGPP executable paths:
|
||||
set nasm_path=C:\nasm
|
||||
set djgpp_path=C:\DJGPP\bin
|
||||
set objpath=../../objects
|
||||
set incpath=../../include
|
||||
|
||||
@echo on
|
||||
%djgpp_path%\gcc.exe -Wall -O -fstrength-reduce -fomit-frame-pointer -nostdinc -fno-builtin -I%incpath% -c -o %objpath%/pic.o pic.c
|
||||
|
||||
@echo off
|
||||
@echo .
|
||||
@echo Done!
|
||||
|
||||
@pause
|
23
SysCore/hal/pic/pic.c
Normal file
23
SysCore/hal/pic/pic.c
Normal file
@ -0,0 +1,23 @@
|
||||
#include <system.h>
|
||||
#include "pic.h"
|
||||
|
||||
void i86_pic_remap(int pic1, int pic2)
|
||||
{
|
||||
// Send ICW1
|
||||
outportb(0x20, 0x11);
|
||||
outportb(0xA0, 0x11);
|
||||
|
||||
// send ICW2
|
||||
outportb(0x21, pic1); // remap pics
|
||||
outportb(0xA1, pic2);
|
||||
|
||||
// send ICW3
|
||||
outportb(0x21, 4);
|
||||
outportb(0xA1, 2);
|
||||
|
||||
// Send ICW4
|
||||
outportb(0x21, 0x01);
|
||||
outportb(0xA1, 0x01);
|
||||
|
||||
outportb(0x21, 0x00);
|
||||
}
|
6
SysCore/hal/pic/pic.h
Normal file
6
SysCore/hal/pic/pic.h
Normal file
@ -0,0 +1,6 @@
|
||||
#ifndef _PIC_H
|
||||
#define _PIC_H
|
||||
|
||||
extern void i86_pic_remap(int pic1, int pic2);
|
||||
|
||||
#endif
|
18
SysCore/hal/pit/compile.bat
Normal file
18
SysCore/hal/pit/compile.bat
Normal file
@ -0,0 +1,18 @@
|
||||
@echo off
|
||||
rem The name of the loader assembly file (without extension, must be .asm):
|
||||
set loader_name=loader
|
||||
|
||||
rem NASM and DJGPP executable paths:
|
||||
set nasm_path=C:\nasm
|
||||
set djgpp_path=C:\DJGPP\bin
|
||||
set objpath=../../objects
|
||||
set incpath=../../include
|
||||
|
||||
@echo on
|
||||
%djgpp_path%\gcc.exe -Wall -O -fstrength-reduce -fomit-frame-pointer -nostdinc -fno-builtin -I%incpath% -c -o %objpath%/pit.o pit.c
|
||||
|
||||
@echo off
|
||||
@echo .
|
||||
@echo Done!
|
||||
|
||||
@pause
|
56
SysCore/hal/pit/pit.c
Normal file
56
SysCore/hal/pit/pit.c
Normal file
@ -0,0 +1,56 @@
|
||||
#include <system.h>
|
||||
#include <time.h>
|
||||
#include "../irq/irq.h"
|
||||
#include "pit.h"
|
||||
|
||||
volatile unsigned int _pit_ticks = 0;
|
||||
volatile unsigned int _pit_frequency = 0;
|
||||
unsigned char _pit_init = 0;
|
||||
volatile TIME _internal_clock;
|
||||
|
||||
|
||||
void i86_pit_set_frequency(int frequency)
|
||||
{
|
||||
int divisor = 1193180/frequency; // Calculate the divisor
|
||||
outportb(0x43, 0x36); // Set our command byte 0x36
|
||||
outportb(0x40, divisor&0xFF); // Set low byte
|
||||
outportb(0x40, divisor>>8); // Set high byte
|
||||
_pit_frequency = frequency;
|
||||
}
|
||||
|
||||
void i86_pit_handler(ISR_stack_regs *r)
|
||||
{
|
||||
_pit_ticks++; // count tick
|
||||
if (_pit_ticks % _pit_frequency == 0)
|
||||
_CLOCK_INC((TIME*)&_internal_clock); // update internal clock
|
||||
}
|
||||
|
||||
unsigned int i86_pit_set_tick_count(unsigned int i)
|
||||
{
|
||||
unsigned int r = _pit_ticks;
|
||||
_pit_ticks = i;
|
||||
return r;
|
||||
}
|
||||
|
||||
unsigned int i86_pit_get_tick_count()
|
||||
{
|
||||
return _pit_ticks;
|
||||
}
|
||||
unsigned int i86_pit_get_frequency()
|
||||
{
|
||||
return _pit_frequency;
|
||||
}
|
||||
|
||||
void i86_pit_install(int freq)
|
||||
{
|
||||
i86_irq_install_handler(0, i86_pit_handler);
|
||||
i86_pit_set_frequency(freq);
|
||||
_pit_ticks = 0;
|
||||
_pit_init = 1;
|
||||
|
||||
}
|
||||
|
||||
unsigned char i86_pit_is_initialized()
|
||||
{
|
||||
return _pit_init;
|
||||
}
|
17
SysCore/hal/pit/pit.h
Normal file
17
SysCore/hal/pit/pit.h
Normal file
@ -0,0 +1,17 @@
|
||||
#ifndef __PIT_H
|
||||
#define __PIT_H
|
||||
|
||||
#include<regs.h>
|
||||
extern volatile unsigned int _pit_ticks;
|
||||
extern volatile unsigned int _pit_frequency;
|
||||
extern volatile TIME _internal_clock;
|
||||
|
||||
extern void i86_pit_handler(ISR_stack_regs *r);
|
||||
extern void i86_pit_set_frequency(int frequency);
|
||||
extern unsigned int i86_pit_set_tick_count(unsigned int i);
|
||||
extern unsigned int i86_pit_get_tick_count();
|
||||
extern unsigned int i86_pit_get_frequency();
|
||||
extern void i86_pit_install(int freq);
|
||||
extern unsigned char i86_pit_is_initialized();
|
||||
|
||||
#endif
|
30
SysCore/include/_null.h
Normal file
30
SysCore/include/_null.h
Normal file
@ -0,0 +1,30 @@
|
||||
|
||||
#ifndef __NULL_H
|
||||
#define __NULL_H
|
||||
|
||||
/******************************
|
||||
* _null.h *
|
||||
* - NULL declaration *
|
||||
******************************/
|
||||
|
||||
#if defined (_MSC_VER) && (_MSC_VER >= 1020)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
#ifdef NULL
|
||||
#undef NULL
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
/* standard NULL declaration */
|
||||
#define NULL 0
|
||||
}
|
||||
#else
|
||||
/* standard NULL declaration */
|
||||
#define NULL (void*)0
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
39
SysCore/include/bootinfo.h
Normal file
39
SysCore/include/bootinfo.h
Normal file
@ -0,0 +1,39 @@
|
||||
#ifndef _BOOTINFO_H
|
||||
#define _BOOTINFO_H
|
||||
//****************************************************************************
|
||||
//** bootinfo.h
|
||||
//****************************************************************************
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
//! multiboot info structure passed from boot loader
|
||||
|
||||
typedef struct {
|
||||
|
||||
uint32_t m_flags;
|
||||
uint32_t m_memoryLo;
|
||||
uint32_t m_memoryHi;
|
||||
uint32_t m_bootDevice;
|
||||
uint32_t m_cmdLine;
|
||||
uint32_t m_modsCount;
|
||||
uint32_t m_modsAddr;
|
||||
uint32_t m_syms0;
|
||||
uint32_t m_syms1;
|
||||
uint32_t m_syms2;
|
||||
uint32_t m_mmap_length;
|
||||
uint32_t m_mmap_addr;
|
||||
uint32_t m_drives_length;
|
||||
uint32_t m_drives_addr;
|
||||
uint32_t m_config_table;
|
||||
uint32_t m_bootloader_name;
|
||||
uint32_t m_apm_table;
|
||||
uint32_t m_vbe_control_info;
|
||||
uint32_t m_vbe_mode_info;
|
||||
uint16_t m_vbe_mode;
|
||||
uint32_t m_vbe_interface_addr;
|
||||
uint16_t m_vbe_interface_len;
|
||||
} multiboot_info ;
|
||||
|
||||
|
||||
#endif
|
||||
|
9
SysCore/include/cctype
Normal file
9
SysCore/include/cctype
Normal file
@ -0,0 +1,9 @@
|
||||
// cerrno standard header
|
||||
|
||||
#ifndef _CSTDCTYPE_
|
||||
#define _CSTDCTYPE_
|
||||
#include <ctype.h>
|
||||
|
||||
#endif /* _CSTDCTYPE_ */
|
||||
|
||||
|
30
SysCore/include/conio.h
Normal file
30
SysCore/include/conio.h
Normal file
@ -0,0 +1,30 @@
|
||||
#ifndef __CONIO_H
|
||||
#define __CONIO_H
|
||||
#define _ATTRIB 0x0F
|
||||
|
||||
extern byte default_background, default_foreground;
|
||||
extern char hex[16];
|
||||
|
||||
extern void itoa (int value, char *string, unsigned int radix);
|
||||
extern int printf(const char* str, ...);
|
||||
extern int abs(int x);
|
||||
extern void graphics_init();
|
||||
extern void text_mode_cursor(int x, int y);
|
||||
extern void set_default_colors(byte back, byte fore);
|
||||
extern void clrscr();
|
||||
extern void scroll(int n);
|
||||
extern void prev_line();
|
||||
extern void next_line();
|
||||
extern void putc_pos_font(int x, int y, char c, byte back, byte fore);
|
||||
extern void putc_pos(int x, int y, char c);
|
||||
extern void putc_font(char c, byte back, byte fore);
|
||||
extern void putc(char c);
|
||||
extern void puts_pos_font(int x, int y, const char *str, byte back, byte fore);
|
||||
extern void puts_pos(int x, int y, const char *str);
|
||||
extern void puts(const char *str);
|
||||
extern void puts_font(const char *str, byte back, byte fore);
|
||||
extern void put_hex(unsigned int alpha);
|
||||
extern void put_hex_pos(int x, int y, unsigned int alpha);
|
||||
extern void put_bin (int x, int y, byte xz);
|
||||
|
||||
#endif
|
50
SysCore/include/crtdefs.h
Normal file
50
SysCore/include/crtdefs.h
Normal file
@ -0,0 +1,50 @@
|
||||
#ifndef _CRTDEFS_H
|
||||
#define _CRTDEFS_H
|
||||
|
||||
/******************************
|
||||
* crtdefs.h *
|
||||
* - basic definitions *
|
||||
******************************/
|
||||
|
||||
#if !defined (CRT_EXPORTS) && !defined (CRT_IMPORTS)
|
||||
#define CRT_EXPORTS
|
||||
#endif
|
||||
|
||||
#undef far
|
||||
#undef near
|
||||
#undef pascal
|
||||
|
||||
#define far
|
||||
#define near
|
||||
|
||||
#ifdef _WIN32
|
||||
#if (!defined(_MAC)) && ((_MSC_VER >= 800) || defined(_STDCALL_SUPPORTED))
|
||||
#define pascal __stdcall
|
||||
#else
|
||||
#define pascal
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef _MAC
|
||||
#ifndef _CRTLIB
|
||||
#define _CRTLIB __cdecl
|
||||
#endif
|
||||
#ifdef _68K_
|
||||
#ifndef __pascal
|
||||
#define __pascal
|
||||
#endif
|
||||
#endif
|
||||
#elif defined( _WIN32)
|
||||
#if (_MSC_VER >= 800) || defined(_STDCALL_SUPPORTED)
|
||||
#ifndef _CRTLIB
|
||||
#define _CRTLIB __stdcall
|
||||
#endif
|
||||
#else
|
||||
#ifndef _CRTLIB
|
||||
#define _CRTLIB
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
7
SysCore/include/cstdarg
Normal file
7
SysCore/include/cstdarg
Normal file
@ -0,0 +1,7 @@
|
||||
// cerrno standard header
|
||||
|
||||
#ifndef _CSTDARG_
|
||||
#define _CSTDARG_
|
||||
#include <stdarg.h>
|
||||
|
||||
#endif /* _CSTDARG_ */
|
9
SysCore/include/cstdint
Normal file
9
SysCore/include/cstdint
Normal file
@ -0,0 +1,9 @@
|
||||
// cerrno standard header
|
||||
|
||||
#ifndef _CSTDINT_
|
||||
#define _CSTDINT_
|
||||
#include <stdint.h>
|
||||
|
||||
#endif /* _CSTDINT_ */
|
||||
|
||||
|
9
SysCore/include/cstring
Normal file
9
SysCore/include/cstring
Normal file
@ -0,0 +1,9 @@
|
||||
// cstring standard header
|
||||
|
||||
#ifndef _CSTDSTRING_
|
||||
#define _CSTDSTRING_
|
||||
#include <string.h>
|
||||
|
||||
#endif /* _CSTDINT_ */
|
||||
|
||||
|
55
SysCore/include/ctype.h
Normal file
55
SysCore/include/ctype.h
Normal file
@ -0,0 +1,55 @@
|
||||
#ifndef __CTYPE_H
|
||||
#define __CTYPE_H
|
||||
|
||||
/******************************
|
||||
* ctype.h *
|
||||
* - character macros *
|
||||
******************************/
|
||||
|
||||
#ifdef _MSC_VER
|
||||
// Get rid of conversion warnings
|
||||
#pragma warning (disable:4244)
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern char _ctype[];
|
||||
|
||||
/* Constants */
|
||||
|
||||
#define CT_UP 0x01 /* upper case */
|
||||
#define CT_LOW 0x02 /* lower case */
|
||||
#define CT_DIG 0x04 /* digit */
|
||||
#define CT_CTL 0x08 /* control */
|
||||
#define CT_PUN 0x10 /* punctuation */
|
||||
#define CT_WHT 0x20 /* white space (space/cr/lf/tab) */
|
||||
#define CT_HEX 0x40 /* hex digit */
|
||||
#define CT_SP 0x80 /* hard space (0x20) */
|
||||
|
||||
/* Basic macros */
|
||||
|
||||
#define isalnum(c) ((_ctype + 1)[(unsigned)(c)] & (CT_UP | CT_LOW | CT_DIG))
|
||||
#define isalpha(c) ((_ctype + 1)[(unsigned)(c)] & (CT_UP | CT_LOW))
|
||||
#define iscntrl(c) ((_ctype + 1)[(unsigned)(c)] & (CT_CTL))
|
||||
#define isdigit(c) ((_ctype + 1)[(unsigned)(c)] & (CT_DIG))
|
||||
#define isgraph(c) ((_ctype + 1)[(unsigned)(c)] & (CT_PUN | CT_UP | CT_LOW | CT_DIG))
|
||||
#define islower(c) ((_ctype + 1)[(unsigned)(c)] & (CT_LOW))
|
||||
#define isprint(c) ((_ctype + 1)[(unsigned)(c)] & (CT_PUN | CT_UP | CT_LOW | CT_DIG | CT_SP))
|
||||
#define ispunct(c) ((_ctype + 1)[(unsigned)(c)] & (CT_PUN))
|
||||
#define isspace(c) ((_ctype + 1)[(unsigned)(c)] & (CT_WHT))
|
||||
#define isupper(c) ((_ctype + 1)[(unsigned)(c)] & (CT_UP))
|
||||
#define isxdigit(c) ((_ctype + 1)[(unsigned)(c)] & (CT_DIG | CT_HEX))
|
||||
#define isascii(c) ((unsigned)(c) <= 0x7F)
|
||||
#define toascii(c) ((unsigned)(c) & 0x7F)
|
||||
#define tolower(c) (isupper(c) ? c + 'a' - 'A' : c)
|
||||
#define toupper(c) (islower(c) ? c + 'A' - 'a' : c)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
180
SysCore/include/hal.h
Normal file
180
SysCore/include/hal.h
Normal file
@ -0,0 +1,180 @@
|
||||
#ifndef _HAL_H
|
||||
#define _HAL_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
#define far
|
||||
#define near
|
||||
|
||||
#define i86_start_interrupts() __asm__ __volatile__ ("sti");
|
||||
#define i86_clear_interrupts() __asm__ __volatile__ ("cli");
|
||||
|
||||
extern volatile TIME _internal_clock;
|
||||
|
||||
// initialize hardware abstraction layer
|
||||
extern void i86_hal_initialize ();
|
||||
|
||||
// shutdown hardware abstraction layer
|
||||
extern int i86_hal_shutdown ();
|
||||
|
||||
//! notifies hal interrupt is done
|
||||
//extern void interruptdone (unsigned int intno);
|
||||
|
||||
//! output sound to speaker
|
||||
extern void sound (unsigned frequency);
|
||||
|
||||
//! read byte from device using port mapped io
|
||||
//extern unsigned char inportb (unsigned short _port);
|
||||
|
||||
//! write byte to device through port mapped io
|
||||
//extern void outportb (unsigned short _port, unsigned char _data);
|
||||
|
||||
//! sets new interrupt vector
|
||||
//extern void setvect (int intno, void ( far &vect) ( ) );
|
||||
|
||||
//! returns current interrupt vector
|
||||
//extern void ( far * getvect (int intno)) ( );
|
||||
|
||||
//! returns cpu vender
|
||||
extern const char* get_cpu_vender ();
|
||||
|
||||
extern void reboot();
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
* KEYBOARD STUFF *
|
||||
**********************************************************************/
|
||||
#define KB_KEY_LSHIFT 0x81 // 1000 0001
|
||||
#define KB_KEY_RSHIFT 0X82 // 1000 0010
|
||||
#define KB_KEY_LALT 0X84 // 1000 0100
|
||||
#define KB_KEY_RALT 0x88 // 1000 1000
|
||||
#define KB_KEY_LCTRL 0x90 // 1001 0000
|
||||
#define KB_KEY_RCTRL 0xA0 // 1010 0000
|
||||
#define KB_KEY_FSHIFT 0xC0 // 1100 0000
|
||||
extern volatile byte kb_modifier_status;
|
||||
|
||||
#define KB_PREFIX_GRAY 0x01 // Gray
|
||||
#define KB_PREFIX_BREAK 0x02 // Break code
|
||||
#define KB_PREFIX_PAUSE 0x04 // Pause/break key
|
||||
#define KB_PREFIX_PAUSE1 0x08 // Recieved first byte from pause/break
|
||||
extern volatile byte kb_prefix;
|
||||
|
||||
#define KB_KEY_SCROLL 0xF1 // 1111 0001
|
||||
#define KB_KEY_NUM 0xF2 // 1111 0010
|
||||
#define KB_KEY_CAPS 0xF4 // 1111 0100
|
||||
extern volatile byte kb_lights_status;
|
||||
|
||||
extern byte kb_scancode_set;
|
||||
#define KB_KEY_PAUSE 0x00
|
||||
#define KB_KEY_F9 0x01
|
||||
#define KB_KEY_F7 0x02
|
||||
#define KB_KEY_F5 0X03
|
||||
#define KB_KEY_F3 0x04
|
||||
#define KB_KEY_F1 0x05
|
||||
#define KB_KEY_F2 0x06
|
||||
#define KB_KEY_F12 0x07
|
||||
#define KB_KEY_PRINTSCRN 0x08
|
||||
#define KB_KEY_F10 0x09
|
||||
#define KB_KEY_F8 0x0A
|
||||
#define KB_KEY_F6 0x0B
|
||||
#define KB_KEY_F4 0x0C
|
||||
#define KB_KEY_TAB 0x0D
|
||||
#define KB_KEY_TILDA 0x0E
|
||||
#define KB_KEY_Q 0x15
|
||||
#define KB_KEY_1 0x16
|
||||
#define KB_KEY_Z 0x1A
|
||||
#define KB_KEY_S 0x1B
|
||||
#define KB_KEY_A 0x1C
|
||||
#define KB_KEY_W 0x1D
|
||||
#define KB_KEY_2 0x1E
|
||||
#define KB_KEY_LWIN 0x1F
|
||||
#define KB_KEY_C 0x21
|
||||
#define KB_KEY_X 0x22
|
||||
#define KB_KEY_D 0x23
|
||||
#define KB_KEY_E 0x24
|
||||
#define KB_KEY_4 0x25
|
||||
#define KB_KEY_3 0x26
|
||||
#define KB_KEY_RWIN 0x27
|
||||
#define KB_KEY_SPACE 0x29
|
||||
#define KB_KEY_V 0x2A
|
||||
#define KB_KEY_F 0x2B
|
||||
#define KB_KEY_T 0x2C
|
||||
#define KB_KEY_R 0x2D
|
||||
#define KB_KEY_5 0x2E
|
||||
#define KB_KEY_MENU 0x2F
|
||||
#define KB_KEY_N 0x31
|
||||
#define KB_KEY_B 0x32
|
||||
#define KB_KEY_H 0x33
|
||||
#define KB_KEY_G 0x34
|
||||
#define KB_KEY_Y 0x35
|
||||
#define KB_KEY_6 0x36
|
||||
#define KB_KEY_M 0x3A
|
||||
#define KB_KEY_J 0x3B
|
||||
#define KB_KEY_U 0x3C
|
||||
#define KB_KEY_7 0x3D
|
||||
#define KB_KEY_8 0x3E
|
||||
#define KB_KEY_COMMA 0x41
|
||||
#define KB_KEY_K 0x42
|
||||
#define KB_KEY_I 0x43
|
||||
#define KB_KEY_O 0x44
|
||||
#define KB_KEY_0 0x45
|
||||
#define KB_KEY_9 0x46
|
||||
#define KB_KEY_PERIOD 0x49
|
||||
#define KB_KEY_SLASH 0x4A
|
||||
#define KB_KEY_L 0x4B
|
||||
#define KB_KEY_SEMICOLON 0x4C
|
||||
#define KB_KEY_P 0x4D
|
||||
#define KB_KEY_DASH 0x4E
|
||||
#define KB_KEY_APOSTROPHE 0x52
|
||||
#define KB_KEY_LBRACKET 0x54
|
||||
#define KB_KEY_EQUAL 0x55
|
||||
#define KB_KEY_NUMPAD_ENTER 0x59
|
||||
#define KB_KEY_ENTER 0x5A
|
||||
#define KB_KEY_RBRACKET 0x5B
|
||||
#define KB_KEY_BACKSLASH 0x5D
|
||||
#define KB_KEY_END 0x5E
|
||||
#define KB_KEY_LEFT 0x5F
|
||||
#define KB_KEY_HOME 0x60
|
||||
#define KB_KEY_INSERT 0x61
|
||||
#define KB_KEY_DELETE 0x62
|
||||
#define KB_KEY_DOWN 0x63
|
||||
#define KB_KEY_RIGHT 0x64
|
||||
#define KB_KEY_UP 0x65
|
||||
#define KB_KEY_BACKSPACE 0x66
|
||||
#define KB_KEY_PGDOWN 0x67
|
||||
#define KB_KEY_PGUP 0x68
|
||||
#define KB_KEY_NUMPAD_1 0x69
|
||||
#define KB_KEY_NUMPAD_SLASH 0x6A
|
||||
#define KB_KEY_NUMPAD_4 0x6B
|
||||
#define KB_KEY_NUMPAD_7 0x6C
|
||||
#define KB_KEY_NUMPAD_0 0x70
|
||||
#define KB_KEY_NUMPAD_COLON 0x71
|
||||
#define KB_KEY_NUMPAD_2 0x72
|
||||
#define KB_KEY_NUMPAD_5 0x73
|
||||
#define KB_KEY_NUMPAD_6 0x74
|
||||
#define KB_KEY_NUMPAD_8 0x75
|
||||
#define KB_KEY_ESC 0x76
|
||||
#define KB_KEY_F11 0x78
|
||||
#define KB_KEY_NUMPAD_PLUS 0x79
|
||||
#define KB_KEY_NUMPAD_3 0x7A
|
||||
#define KB_KEY_NUMPAD_MINUS 0x7B
|
||||
#define KB_KEY_NUMPAD_ASTERISK 0x7C
|
||||
#define KB_KEY_NUMPAD_9 0x7D
|
||||
|
||||
|
||||
typedef struct {
|
||||
byte status;
|
||||
byte lights;
|
||||
byte scancode;
|
||||
byte character;
|
||||
} kb_key;
|
||||
|
||||
|
||||
extern char getch();
|
||||
extern kb_key getkey();
|
||||
extern char scancode_to_ascii(byte scancode, byte status);
|
||||
extern byte get_key_status(byte scancode);
|
||||
extern void kb_set_repeat(float rate, int delay);
|
||||
extern void kb_set_LEDs(byte status);
|
||||
|
||||
#endif
|
100
SysCore/include/regs.h
Normal file
100
SysCore/include/regs.h
Normal file
@ -0,0 +1,100 @@
|
||||
#ifndef _REGS_H_INCLUDED
|
||||
#define _REGS_H_INCLUDED
|
||||
//****************************************************************************
|
||||
//**
|
||||
//** regs.h
|
||||
//**
|
||||
//** processor register structures and declarations. This interface abstracts
|
||||
//** register names behind a common, portable interface
|
||||
//**
|
||||
//****************************************************************************
|
||||
|
||||
//============================================================================
|
||||
// INTERFACE REQUIRED HEADERS
|
||||
//============================================================================
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
//============================================================================
|
||||
// INTERFACE DEFINITIONS / ENUMERATIONS / SIMPLE TYPEDEFS
|
||||
//============================================================================
|
||||
//============================================================================
|
||||
// INTERFACE CLASS PROTOTYPES / EXTERNAL CLASS REFERENCES
|
||||
//============================================================================
|
||||
//============================================================================
|
||||
// INTERFACE STRUCTURES / UTILITY CLASSES
|
||||
//============================================================================
|
||||
|
||||
//! 32 bit registers
|
||||
typedef struct {
|
||||
uint32_t eax, ebx, ecx, edx, esi, edi, ebp, esp, eflags;
|
||||
uint8_t cflag;
|
||||
} _R32BIT;
|
||||
|
||||
//! 16 bit registers
|
||||
typedef struct {
|
||||
uint16_t ax, bx, cx, dx, si, di, bp, sp, es, cs, ss, ds, flags;
|
||||
uint8_t cflag;
|
||||
} _R16BIT ;
|
||||
|
||||
//! 16 bit registers expressed in 32 bit registers
|
||||
typedef struct {
|
||||
uint16_t ax, axh, bx, bxh, cx, cxh, dx, dxh;
|
||||
uint16_t si, di, bp, sp, es, cs, ss, ds, flags;
|
||||
uint8_t cflags;
|
||||
} _R16BIT32 ;
|
||||
|
||||
//! 8 bit registers
|
||||
typedef struct {
|
||||
uint8_t al, ah, bl, bh, cl, ch, dl, dh;
|
||||
} _R8BIT;
|
||||
|
||||
//! 8 bit registers expressed in 32 bit registers
|
||||
typedef struct {
|
||||
uint8_t al, ah; uint16_t axh;
|
||||
uint8_t bl, bh; uint16_t bxh;
|
||||
uint8_t cl, ch; uint16_t cxh;
|
||||
uint8_t dl, dh; uint16_t dxh;
|
||||
} _R8BIT32;
|
||||
|
||||
//! 8 and 16 bit registers union
|
||||
typedef union {
|
||||
_R16BIT x;
|
||||
_R8BIT h;
|
||||
}_INTR16;
|
||||
|
||||
//! 32 bit, 16 bit and 8 bit registers union
|
||||
typedef union {
|
||||
_R32BIT x;
|
||||
_R16BIT32 l;
|
||||
_R8BIT32 h;
|
||||
} _INTR32;
|
||||
|
||||
/* This defines what the stack looks like after an ISR was running */
|
||||
typedef struct
|
||||
{
|
||||
unsigned int gs, fs, es, ds; /* pushed the segs last */
|
||||
unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; /* pushed by 'pusha' */
|
||||
unsigned int int_no, err_code; /* our 'push byte #' and ecodes do this */
|
||||
unsigned int eip, cs, eflags, useresp, ss; /* pushed by the processor automatically */
|
||||
} ISR_stack_regs;
|
||||
|
||||
|
||||
//============================================================================
|
||||
// INTERFACE DATA DECLARATIONS
|
||||
//============================================================================
|
||||
//============================================================================
|
||||
// INTERFACE FUNCTION PROTOTYPES
|
||||
//============================================================================
|
||||
//============================================================================
|
||||
// INTERFACE OBJECT CLASS DEFINITIONS
|
||||
//============================================================================
|
||||
//============================================================================
|
||||
// INTERFACE TRAILING HEADERS
|
||||
//============================================================================
|
||||
//****************************************************************************
|
||||
//**
|
||||
//** END regs.h
|
||||
//**
|
||||
//****************************************************************************
|
||||
#endif
|
23
SysCore/include/size_t.h
Normal file
23
SysCore/include/size_t.h
Normal file
@ -0,0 +1,23 @@
|
||||
#ifndef __SIZE_T_H
|
||||
#define __SIZE_T_H
|
||||
|
||||
/************************************
|
||||
* size_t.h *
|
||||
* - Standard C/C++ size_t type *
|
||||
************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/* standard size_t type */
|
||||
typedef unsigned size_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif
|
46
SysCore/include/stdarg.h
Normal file
46
SysCore/include/stdarg.h
Normal file
@ -0,0 +1,46 @@
|
||||
#ifndef __STDARG_H
|
||||
#define __STDARG_H
|
||||
|
||||
|
||||
/******************************
|
||||
* [filename] *
|
||||
* - [description] *
|
||||
******************************/
|
||||
|
||||
// INTERFACE REQUIRED HEADERS
|
||||
#include <va_list.h>
|
||||
|
||||
|
||||
// INTERFACE DEFINITIONS / ENUMERATIONS / SIMPLE TYPEDEFS
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/* width of stack == width of int */
|
||||
#define STACKITEM int
|
||||
|
||||
/* round up width of objects pushed on stack. The expression before the
|
||||
& ensures that we get 0 for objects of size 0. */
|
||||
#define VA_SIZE(TYPE) \
|
||||
((sizeof(TYPE) + sizeof(STACKITEM) - 1) \
|
||||
& ~(sizeof(STACKITEM) - 1))
|
||||
|
||||
/* &(LASTARG) points to the LEFTMOST argument of the function call
|
||||
(before the ...) */
|
||||
#define va_start(AP, LASTARG) \
|
||||
(AP=((va_list)&(LASTARG) + VA_SIZE(LASTARG)))
|
||||
|
||||
/* nothing for va_end */
|
||||
#define va_end(AP)
|
||||
|
||||
#define va_arg(AP, TYPE) \
|
||||
(AP += VA_SIZE(TYPE), *((TYPE *)(AP - VA_SIZE(TYPE))))
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif
|
163
SysCore/include/stdint.h
Normal file
163
SysCore/include/stdint.h
Normal file
@ -0,0 +1,163 @@
|
||||
|
||||
#ifndef _STDINT_H
|
||||
#define _STDINT_H
|
||||
|
||||
#define __need_wint_t
|
||||
#define __need_wchar_t
|
||||
|
||||
|
||||
/***************************************
|
||||
* stdint.h *
|
||||
* - Standard C++ integral types *
|
||||
***************************************/
|
||||
|
||||
/* 7.18.1.1 Exact-width integer types */
|
||||
typedef signed char int8_t;
|
||||
typedef unsigned char uint8_t;
|
||||
typedef short int16_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef int int32_t;
|
||||
typedef unsigned uint32_t;
|
||||
typedef long long int64_t;
|
||||
typedef unsigned long long uint64_t;
|
||||
|
||||
/* 7.18.1.2 Minimum-width integer types */
|
||||
typedef signed char int_least8_t;
|
||||
typedef unsigned char uint_least8_t;
|
||||
typedef short int_least16_t;
|
||||
typedef unsigned short uint_least16_t;
|
||||
typedef int int_least32_t;
|
||||
typedef unsigned uint_least32_t;
|
||||
typedef long long int_least64_t;
|
||||
typedef unsigned long long uint_least64_t;
|
||||
|
||||
/* 7.18.1.3 Fastest minimum-width integer types
|
||||
* Not actually guaranteed to be fastest for all purposes
|
||||
* Here we use the exact-width types for 8 and 16-bit ints.
|
||||
*/
|
||||
typedef char int_fast8_t;
|
||||
typedef unsigned char uint_fast8_t;
|
||||
typedef short int_fast16_t;
|
||||
typedef unsigned short uint_fast16_t;
|
||||
typedef int int_fast32_t;
|
||||
typedef unsigned int uint_fast32_t;
|
||||
typedef long long int_fast64_t;
|
||||
typedef unsigned long long uint_fast64_t;
|
||||
|
||||
/* 7.18.1.4 Integer types capable of holding object pointers */
|
||||
typedef int intptr_t;
|
||||
typedef unsigned uintptr_t;
|
||||
|
||||
/* 7.18.1.5 Greatest-width integer types */
|
||||
typedef long long intmax_t;
|
||||
typedef unsigned long long uintmax_t;
|
||||
|
||||
/* 7.18.2 Limits of specified-width integer types */
|
||||
#if !defined ( __cplusplus) || defined (__STDC_LIMIT_MACROS)
|
||||
|
||||
/* 7.18.2.1 Limits of exact-width integer types */
|
||||
#define INT8_MIN (-128)
|
||||
#define INT16_MIN (-32768)
|
||||
#define INT32_MIN (-2147483647 - 1)
|
||||
#define INT64_MIN (-9223372036854775807LL - 1)
|
||||
|
||||
#define INT8_MAX 127
|
||||
#define INT16_MAX 32767
|
||||
#define INT32_MAX 2147483647
|
||||
#define INT64_MAX 9223372036854775807LL
|
||||
|
||||
#define UINT8_MAX 0xff /* 255U */
|
||||
#define UINT16_MAX 0xffff /* 65535U */
|
||||
#define UINT32_MAX 0xffffffff /* 4294967295U */
|
||||
#define UINT64_MAX 0xffffffffffffffffULL /* 18446744073709551615ULL */
|
||||
|
||||
/* 7.18.2.2 Limits of minimum-width integer types */
|
||||
#define INT_LEAST8_MIN INT8_MIN
|
||||
#define INT_LEAST16_MIN INT16_MIN
|
||||
#define INT_LEAST32_MIN INT32_MIN
|
||||
#define INT_LEAST64_MIN INT64_MIN
|
||||
|
||||
#define INT_LEAST8_MAX INT8_MAX
|
||||
#define INT_LEAST16_MAX INT16_MAX
|
||||
#define INT_LEAST32_MAX INT32_MAX
|
||||
#define INT_LEAST64_MAX INT64_MAX
|
||||
|
||||
#define UINT_LEAST8_MAX UINT8_MAX
|
||||
#define UINT_LEAST16_MAX UINT16_MAX
|
||||
#define UINT_LEAST32_MAX UINT32_MAX
|
||||
#define UINT_LEAST64_MAX UINT64_MAX
|
||||
|
||||
/* 7.18.2.3 Limits of fastest minimum-width integer types */
|
||||
#define INT_FAST8_MIN INT8_MIN
|
||||
#define INT_FAST16_MIN INT16_MIN
|
||||
#define INT_FAST32_MIN INT32_MIN
|
||||
#define INT_FAST64_MIN INT64_MIN
|
||||
|
||||
#define INT_FAST8_MAX INT8_MAX
|
||||
#define INT_FAST16_MAX INT16_MAX
|
||||
#define INT_FAST32_MAX INT32_MAX
|
||||
#define INT_FAST64_MAX INT64_MAX
|
||||
|
||||
#define UINT_FAST8_MAX UINT8_MAX
|
||||
#define UINT_FAST16_MAX UINT16_MAX
|
||||
#define UINT_FAST32_MAX UINT32_MAX
|
||||
#define UINT_FAST64_MAX UINT64_MAX
|
||||
|
||||
/* 7.18.2.4 Limits of integer types capable of holding
|
||||
object pointers */
|
||||
#define INTPTR_MIN INT32_MIN
|
||||
#define INTPTR_MAX INT32_MAX
|
||||
#define UINTPTR_MAX UINT32_MAX
|
||||
|
||||
/* 7.18.2.5 Limits of greatest-width integer types */
|
||||
#define INTMAX_MIN INT64_MIN
|
||||
#define INTMAX_MAX INT64_MAX
|
||||
#define UINTMAX_MAX UINT64_MAX
|
||||
|
||||
/* 7.18.3 Limits of other integer types */
|
||||
#define PTRDIFF_MIN INT32_MIN
|
||||
#define PTRDIFF_MAX INT32_MAX
|
||||
|
||||
#define SIG_ATOMIC_MIN INT32_MIN
|
||||
#define SIG_ATOMIC_MAX INT32_MAX
|
||||
|
||||
#define SIZE_MAX UINT32_MAX
|
||||
|
||||
#ifndef WCHAR_MIN /* also in wchar.h */
|
||||
#define WCHAR_MIN 0
|
||||
#define WCHAR_MAX ((wchar_t)-1) /* UINT16_MAX */
|
||||
#endif
|
||||
|
||||
/*
|
||||
* wint_t is unsigned short for compatibility with MS runtime
|
||||
*/
|
||||
#define WINT_MIN 0
|
||||
#define WINT_MAX ((wint_t)-1) /* UINT16_MAX */
|
||||
|
||||
#endif /* !defined ( __cplusplus) || defined __STDC_LIMIT_MACROS */
|
||||
|
||||
|
||||
/* 7.18.4 Macros for integer constants */
|
||||
#if !defined ( __cplusplus) || defined (__STDC_CONSTANT_MACROS)
|
||||
|
||||
/* 7.18.4.1 Macros for minimum-width integer constants */
|
||||
|
||||
#define INT8_C(val) ((int8_t) + (val))
|
||||
#define UINT8_C(val) ((uint8_t) + (val##U))
|
||||
#define INT16_C(val) ((int16_t) + (val))
|
||||
#define UINT16_C(val) ((uint16_t) + (val##U))
|
||||
|
||||
#define INT32_C(val) val##L
|
||||
#define UINT32_C(val) val##UL
|
||||
#define INT64_C(val) val##LL
|
||||
#define UINT64_C(val) val##ULL
|
||||
|
||||
/* 7.18.4.2 Macros for greatest-width integer constants */
|
||||
#define INTMAX_C(val) INT64_C(val)
|
||||
#define UINTMAX_C(val) UINT64_C(val)
|
||||
|
||||
#endif /* !defined ( __cplusplus) || defined __STDC_CONSTANT_MACROS */
|
||||
|
||||
|
||||
|
||||
#endif
|
46
SysCore/include/string.h
Normal file
46
SysCore/include/string.h
Normal file
@ -0,0 +1,46 @@
|
||||
#ifndef _STRING_H
|
||||
#define _STRING_H
|
||||
//****************************************************************************
|
||||
//**
|
||||
//** [string.h]
|
||||
//** - Standard C String routines
|
||||
//**
|
||||
//****************************************************************************
|
||||
//============================================================================
|
||||
// INTERFACE REQUIRED HEADERS
|
||||
//============================================================================
|
||||
|
||||
#include <size_t.h>
|
||||
|
||||
//============================================================================
|
||||
// INTERFACE DEFINITIONS / ENUMERATIONS / SIMPLE TYPEDEFS
|
||||
//============================================================================
|
||||
//============================================================================
|
||||
// INTERFACE CLASS PROTOTYPES / EXTERNAL CLASS REFERENCES
|
||||
//============================================================================
|
||||
//============================================================================
|
||||
// INTERFACE STRUCTURES / UTILITY CLASSES
|
||||
//============================================================================
|
||||
//============================================================================
|
||||
// INTERFACE DATA DECLARATIONS
|
||||
//============================================================================
|
||||
//============================================================================
|
||||
// INTERFACE FUNCTION PROTOTYPES
|
||||
//============================================================================
|
||||
|
||||
extern size_t strlen (const char *str);
|
||||
extern int strcmp(const char *pStr1, const char *pStr2);
|
||||
|
||||
//============================================================================
|
||||
// INTERFACE OBJECT CLASS DEFINITIONS
|
||||
//============================================================================
|
||||
//============================================================================
|
||||
// INTERFACE TRAILING HEADERS
|
||||
//============================================================================
|
||||
//****************************************************************************
|
||||
//**
|
||||
//** END [string.h]
|
||||
//**
|
||||
//****************************************************************************
|
||||
|
||||
#endif
|
21
SysCore/include/sys/declarat.h
Normal file
21
SysCore/include/sys/declarat.h
Normal file
@ -0,0 +1,21 @@
|
||||
#ifndef __DECLARAT_H
|
||||
#define __DECLARAT_H
|
||||
|
||||
// Data type declarations
|
||||
typedef unsigned char byte;
|
||||
typedef unsigned short word;
|
||||
typedef unsigned int dword;
|
||||
|
||||
// Functions
|
||||
void system_init();
|
||||
|
||||
void isrs_install();
|
||||
|
||||
void irq_install_handler(int irq, void (*handler)(ISR_stack_regs *r));
|
||||
void irq_uninstall_handler(int irq);
|
||||
void irq_install();
|
||||
void kb_handler(ISR_stack_regs *r);
|
||||
void reboot();
|
||||
void kb_waitin();
|
||||
|
||||
#endif
|
40
SysCore/include/system.h
Normal file
40
SysCore/include/system.h
Normal file
@ -0,0 +1,40 @@
|
||||
/*******************************************************************
|
||||
* system.c - Basic system functions and variables declaration *
|
||||
*******************************************************************/
|
||||
#ifndef __SYSTEM_H
|
||||
#define __SYSTEM_H
|
||||
#include <regs.h>
|
||||
|
||||
#define true 1
|
||||
#define false 0
|
||||
|
||||
// Data type declarations
|
||||
typedef unsigned char byte;
|
||||
typedef unsigned short word;
|
||||
typedef unsigned int dword;
|
||||
|
||||
extern byte *TextVideoRam;
|
||||
extern volatile int cursor_x, cursor_y;
|
||||
extern int current_mode_width;
|
||||
extern int current_mode_height;
|
||||
|
||||
extern void *memcpy(void *dest, const void *src, int count);
|
||||
extern void *memset(void *dest, char val, int count);
|
||||
extern unsigned short *memsetw(unsigned short *dest, unsigned short val, int count);
|
||||
|
||||
extern byte inportb (word _port);
|
||||
extern byte inb (word _port);
|
||||
|
||||
static inline void outportb (word _port, byte _data) {
|
||||
__asm__ __volatile__ ("outb %1, %0" : : "dN" (_port), "a" (_data));
|
||||
}
|
||||
static inline void outb (word _port, byte _data) {
|
||||
__asm__ __volatile__ ("outb %1, %0" : : "dN" (_port), "a" (_data));
|
||||
}
|
||||
|
||||
static inline void iowait() {
|
||||
asm volatile ("outb %al, $0x80");
|
||||
}
|
||||
|
||||
|
||||
#endif
|
25
SysCore/include/time.h
Normal file
25
SysCore/include/time.h
Normal file
@ -0,0 +1,25 @@
|
||||
#ifndef __TIME_C
|
||||
#define __TIME_C
|
||||
|
||||
extern const char* clock_months[13];
|
||||
extern const char* clock_weekdays[8];
|
||||
extern byte clock_months_len[13];
|
||||
|
||||
typedef struct {
|
||||
byte seconds;
|
||||
byte minutes;
|
||||
byte hours;
|
||||
byte weekday;
|
||||
byte day;
|
||||
byte month;
|
||||
byte year;
|
||||
byte century;
|
||||
byte am_pm;
|
||||
|
||||
} TIME;
|
||||
|
||||
extern void _CLOCK_INC(TIME *tim);
|
||||
|
||||
//extern char* asctime (TIME time);
|
||||
|
||||
#endif
|
52
SysCore/include/va_list.h
Normal file
52
SysCore/include/va_list.h
Normal file
@ -0,0 +1,52 @@
|
||||
#ifndef __VA_LIST_H
|
||||
#define __VA_LIST_H
|
||||
//****************************************************************************
|
||||
//**
|
||||
//** va_list.h
|
||||
//** - varable length parameter definition
|
||||
//**
|
||||
//****************************************************************************
|
||||
//============================================================================
|
||||
// INTERFACE REQUIRED HEADERS
|
||||
//============================================================================
|
||||
//============================================================================
|
||||
// INTERFACE DEFINITIONS / ENUMERATIONS / SIMPLE TYPEDEFS
|
||||
//============================================================================
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/* va list parameter list */
|
||||
typedef unsigned char *va_list;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
//============================================================================
|
||||
// INTERFACE CLASS PROTOTYPES / EXTERNAL CLASS REFERENCES
|
||||
//============================================================================
|
||||
//============================================================================
|
||||
// INTERFACE STRUCTURES / UTILITY CLASSES
|
||||
//============================================================================
|
||||
//============================================================================
|
||||
// INTERFACE DATA DECLARATIONS
|
||||
//============================================================================
|
||||
//============================================================================
|
||||
// INTERFACE FUNCTION PROTOTYPES
|
||||
//============================================================================
|
||||
//============================================================================
|
||||
// INTERFACE OBJECT CLASS DEFINITIONS
|
||||
//============================================================================
|
||||
//============================================================================
|
||||
// INTERFACE TRAILING HEADERS
|
||||
//============================================================================
|
||||
//****************************************************************************
|
||||
//**
|
||||
//** END va_list.h
|
||||
//**
|
||||
//****************************************************************************
|
||||
|
||||
#endif
|
40
SysCore/lib/compile.bat
Normal file
40
SysCore/lib/compile.bat
Normal file
@ -0,0 +1,40 @@
|
||||
@echo off
|
||||
|
||||
rem NASM and DJGPP executable paths:
|
||||
set nasm_path=C:\nasm
|
||||
set djgpp_path=C:\DJGPP\bin
|
||||
set objpath=..\objects
|
||||
set incpath=../include
|
||||
|
||||
@echo Building Kernel Standard Libraries...
|
||||
|
||||
del %objpath%\system.o
|
||||
del %objpath%\string.o
|
||||
del %objpath%\conio.o
|
||||
del %objpath%\time.o
|
||||
|
||||
goto build
|
||||
:error
|
||||
@echo.
|
||||
@echo There have been build errors. Building halted.
|
||||
@pause
|
||||
exit
|
||||
|
||||
:build
|
||||
@echo * Compiling SYSTEM.C ...
|
||||
%djgpp_path%\gcc.exe -Wall -O -fstrength-reduce -fomit-frame-pointer -nostdinc -fno-builtin -I%incpath% -c -o %objpath%/system.o system.c
|
||||
|
||||
@echo * Compiling STRING.C ...
|
||||
%djgpp_path%\gcc.exe -Wall -O -fstrength-reduce -fomit-frame-pointer -nostdinc -fno-builtin -I%incpath% -c -o %objpath%/string.o string.c
|
||||
|
||||
@echo * Compiling CONIO.C ...
|
||||
%djgpp_path%\gcc.exe -Wall -O -fstrength-reduce -fomit-frame-pointer -nostdinc -fno-builtin -I%incpath% -c -o %objpath%/conio.o conio.c
|
||||
|
||||
@echo * Compiling TIME.C ...
|
||||
%djgpp_path%\gcc.exe -Wall -O -fstrength-reduce -fomit-frame-pointer -nostdinc -fno-builtin -I%incpath% -c -o %objpath%/time.o time.c
|
||||
|
||||
:check
|
||||
if not exist %objpath%\system.o goto error
|
||||
if not exist %objpath%\string.o goto error
|
||||
if not exist %objpath%\conio.o goto error
|
||||
if not exist %objpath%\time.o goto error
|
284
SysCore/lib/conio.c
Normal file
284
SysCore/lib/conio.c
Normal file
@ -0,0 +1,284 @@
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <system.h>
|
||||
#include <conio.h>
|
||||
|
||||
byte default_background, default_foreground;
|
||||
|
||||
char hex[] = "0123456789ABCDEF";
|
||||
const static char base_chars[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
|
||||
int abs(int x)
|
||||
{
|
||||
return (x>0) ? (x) : (x*-1);
|
||||
}
|
||||
|
||||
void graphics_init()
|
||||
{
|
||||
// Detect if color/monochrome screen
|
||||
char c = (*(volatile unsigned short*)0x410)&0x30;
|
||||
if (c==0x30) TextVideoRam = (byte *)0xb0000;
|
||||
else TextVideoRam = (byte *)0xb8000;
|
||||
|
||||
// Reset cursor, use 80x25 text video mode
|
||||
current_mode_width = 80;
|
||||
current_mode_height = 25;
|
||||
cursor_x = cursor_y = 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Change cursor position
|
||||
void text_mode_cursor(int x, int y)
|
||||
{
|
||||
unsigned temp = y*current_mode_width + x;
|
||||
|
||||
outportb (0x3D4, 14);
|
||||
outportb (0x3D5, temp >> 8);
|
||||
outportb (0x3D4, 15);
|
||||
outportb (0x3D5, temp);
|
||||
}
|
||||
|
||||
// Set the default colors; max is 0x0F
|
||||
void set_default_colors(byte back, byte fore)
|
||||
{
|
||||
if (back < 0x10) default_background = back;
|
||||
if (fore < 0x10) default_foreground = fore;
|
||||
}
|
||||
|
||||
|
||||
// Clear screen, and set font to default font
|
||||
void clrscr()
|
||||
{
|
||||
byte font = default_foreground | (default_background<<4);
|
||||
int i = 0;
|
||||
for (i = 0; i < current_mode_width*current_mode_height; i++)
|
||||
{ TextVideoRam[2*i] = 0;
|
||||
TextVideoRam[2*i+1] = font;
|
||||
}
|
||||
cursor_x = 0; cursor_y = 0;
|
||||
}
|
||||
|
||||
void scroll(int n)
|
||||
{
|
||||
memcpy(TextVideoRam,
|
||||
TextVideoRam+(current_mode_width*n*2),
|
||||
2*current_mode_width*(current_mode_height - n));
|
||||
|
||||
byte blank = default_foreground | (default_background<<4);
|
||||
|
||||
int i;
|
||||
for (i = current_mode_width*(current_mode_height-n);
|
||||
i < current_mode_width*current_mode_height; i++){
|
||||
TextVideoRam[2*i] = 0;
|
||||
TextVideoRam[2*i+1] = blank;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void prev_line()
|
||||
{
|
||||
cursor_x = 79;
|
||||
if (--cursor_y < 0) {
|
||||
cursor_y = 0; cursor_x=0;
|
||||
}
|
||||
}
|
||||
|
||||
void next_line()
|
||||
{
|
||||
cursor_x = 0;
|
||||
if (++cursor_y >=25) {
|
||||
cursor_y = 24; scroll(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Put character on screen in specified position; can use different font colors
|
||||
void putc_pos_font(int x, int y, char c, byte back, byte fore)
|
||||
{
|
||||
TextVideoRam[2*(y*current_mode_width+x)] = c;
|
||||
TextVideoRam[2*(y*current_mode_width+x)+1] = fore|(back<<4);
|
||||
}
|
||||
// Put character on screen in specified position; use default font colors
|
||||
void putc_pos(int x, int y, char c)
|
||||
{
|
||||
TextVideoRam[2*(y*current_mode_width+x)] = c;
|
||||
}
|
||||
// Put character on screen in the current cursor position; different font colors
|
||||
void putc_font(char c, byte back, byte fore)
|
||||
{
|
||||
if (cursor_x >= current_mode_width) next_line();
|
||||
|
||||
if (c == '\n') {next_line(); return;};
|
||||
TextVideoRam[2*(cursor_y*current_mode_width+cursor_x)] = c;
|
||||
TextVideoRam[2*(cursor_y*current_mode_width+cursor_x)+1] = fore|(back<<4);
|
||||
cursor_x++;
|
||||
}
|
||||
// Put character on screen in the current cursor position; default font colors
|
||||
void putc(char c)
|
||||
{
|
||||
if (cursor_x >= current_mode_width) next_line();
|
||||
|
||||
if (c == '\n') {next_line(); return;};
|
||||
if (c == '\r') {cursor_x = 0; return; };
|
||||
TextVideoRam[2*(cursor_y*current_mode_width+cursor_x)] = c;
|
||||
cursor_x++;
|
||||
}
|
||||
|
||||
// Unsigned INT to ASCII
|
||||
void uitoa (unsigned int value, char *string, int radix)
|
||||
{
|
||||
if (radix == 1 || radix>36) return;
|
||||
|
||||
// Calculate how much space needed for number
|
||||
int len, temp = abs(value);
|
||||
for (len = 0; temp > 0; len++) temp/=radix;
|
||||
if (len == 0) len = 1;
|
||||
|
||||
string[len] = 0;
|
||||
for (len--; len >=0; len-- ) {
|
||||
string[len] = base_chars[value%radix];
|
||||
value/=radix;
|
||||
}
|
||||
}
|
||||
|
||||
// Signed INT to ASCII
|
||||
void itoa (int value, char *string, unsigned int radix)
|
||||
{
|
||||
if (radix < 2 || radix>36) return;
|
||||
|
||||
// Calculate how much space needed for number
|
||||
int len, temp = abs(value);
|
||||
for (len = 0; temp > 0; len++) temp/=radix;
|
||||
if (len == 0) len = 1;
|
||||
|
||||
//Add a space for '-'
|
||||
if (value<0) {
|
||||
len++; string[0] = '-';
|
||||
value = abs(value);
|
||||
}
|
||||
|
||||
string[len] = 0;
|
||||
for (len--; len >0; len-- ) {
|
||||
string[len] = base_chars[value%radix];
|
||||
value/=radix;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Put string on screen in specified position; can use different font colors
|
||||
void puts_pos_font(int x, int y, const char *str, byte back, byte fore)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; str[i] != 0; i++)
|
||||
putc_pos_font(x+i, y, str[i], back, fore);
|
||||
|
||||
}
|
||||
|
||||
// Put string on screen in specified position; use default font colors
|
||||
void puts_pos(int x, int y, const char *str)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; str[i] != 0; i++)
|
||||
putc_pos(x+i, y, str[i]);
|
||||
}
|
||||
void puts(const char *str)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; str[i] != 0; i++)
|
||||
putc(str[i]);
|
||||
}
|
||||
|
||||
void puts_font(const char *str, byte back, byte fore)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; str[i] != 0; i++)
|
||||
putc_font(str[i], back, fore);
|
||||
}
|
||||
|
||||
void put_hex(unsigned int alpha)
|
||||
{
|
||||
char nr[9];
|
||||
int i;
|
||||
for (i = 7; i >= 0; i--) {
|
||||
nr[i] = hex[alpha%16];
|
||||
alpha /= 16;
|
||||
}
|
||||
nr[8] = 0;
|
||||
puts(nr);
|
||||
}
|
||||
void put_hex_pos(int x, int y, unsigned int alpha)
|
||||
{
|
||||
char nr[9];
|
||||
int i;
|
||||
for (i = 7; i >= 0; i--) {
|
||||
nr[i] = hex[alpha%16];
|
||||
alpha /= 16;
|
||||
}
|
||||
nr[8] = 0;
|
||||
puts_pos(x,y,nr);
|
||||
}
|
||||
|
||||
void put_bin (int x, int y, byte xz)
|
||||
{
|
||||
int i;
|
||||
char arr[9] = {0,0,0,0,0,0,0,0,0};
|
||||
for(i=7; i>=0; i--) {
|
||||
arr[i] = (xz%2) + '0'; xz/=2;
|
||||
}
|
||||
puts_pos (x, y, arr);
|
||||
}
|
||||
|
||||
|
||||
int printf(const char* str, ...)
|
||||
{
|
||||
if (!str) return 0;
|
||||
|
||||
va_list args;
|
||||
va_start (args, str);
|
||||
size_t i, len = strlen(str);
|
||||
for (i = 0; i < len; i++)
|
||||
switch (str[i]) {
|
||||
case '%':
|
||||
switch (str[i+1]) {
|
||||
// Character
|
||||
case 'c': {char c = va_arg (args, char);
|
||||
putc(c); i++; break;}
|
||||
// String
|
||||
case 's': {int* c = (int*) va_arg (args, char*);
|
||||
puts((const char*)c); i++; break;}
|
||||
// Integers
|
||||
case 'd':
|
||||
case 'i': {int c = va_arg(args, int);
|
||||
char temp[32];
|
||||
itoa(c, temp, 10);
|
||||
puts(temp);
|
||||
i++; break;}
|
||||
// Integers - hex
|
||||
case 'X':
|
||||
case 'x': {int c = va_arg(args, int);
|
||||
char temp[32];
|
||||
uitoa(c, temp, 16);
|
||||
puts(temp);
|
||||
i++; break;}
|
||||
|
||||
// Integers - unsigned
|
||||
case 'u': { int c = va_arg(args, unsigned int);
|
||||
char temp[32];
|
||||
uitoa(c, temp, 10);
|
||||
puts(temp);
|
||||
i++; break;
|
||||
}
|
||||
|
||||
default: va_end(args); return 1;
|
||||
};
|
||||
break;
|
||||
default: putc(str[i]); break;
|
||||
}
|
||||
|
||||
va_end(args);
|
||||
return i;
|
||||
}
|
||||
|
23
SysCore/lib/string.c
Normal file
23
SysCore/lib/string.c
Normal file
@ -0,0 +1,23 @@
|
||||
#include <string.h>
|
||||
|
||||
size_t strlen (const char *str)
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; *str!=0; str++) i++;
|
||||
return i;
|
||||
}
|
||||
|
||||
int strcmp(const char *pStr1, const char *pStr2)
|
||||
{
|
||||
char c1, c2;
|
||||
int v;
|
||||
|
||||
do {
|
||||
c1 = *pStr1++;
|
||||
c2 = *pStr2++;
|
||||
/* the casts are necessary when pStr1 is shorter & char is signed */
|
||||
v = (unsigned int)c1 - (unsigned int)c2;
|
||||
} while ((v == 0) && (c1 != '\0'));
|
||||
|
||||
return v;
|
||||
}
|
44
SysCore/lib/system.c
Normal file
44
SysCore/lib/system.c
Normal file
@ -0,0 +1,44 @@
|
||||
/******************************************************************
|
||||
* system.c - Basic system functions *
|
||||
******************************************************************/
|
||||
|
||||
#include <system.h>
|
||||
|
||||
byte *TextVideoRam;
|
||||
volatile int cursor_x, cursor_y;
|
||||
int current_mode_width;
|
||||
int current_mode_height;
|
||||
|
||||
void *memcpy(void *dest, const void *src, int count)
|
||||
{
|
||||
const char *sp = (const char *)src;
|
||||
char *dp = (char *)dest;
|
||||
for(; count != 0; count--) *dp++ = *sp++;
|
||||
return dest;
|
||||
}
|
||||
|
||||
void *memset(void *dest, char val, int count)
|
||||
{
|
||||
char *temp = (char *)dest;
|
||||
for( ; count != 0; count--) *temp++ = val;
|
||||
return dest;
|
||||
}
|
||||
|
||||
unsigned short *memsetw(unsigned short *dest, unsigned short val, int count)
|
||||
{
|
||||
unsigned short *temp = (unsigned short *)dest;
|
||||
for( ; count != 0; count--) *temp++ = val;
|
||||
return dest;
|
||||
}
|
||||
|
||||
|
||||
byte inportb (word _port) {
|
||||
byte rv;
|
||||
__asm__ __volatile__ ("inb %1, %0" : "=a" (rv) : "dN" (_port));
|
||||
return rv;
|
||||
}
|
||||
byte inb (word _port) {
|
||||
byte rv;
|
||||
__asm__ __volatile__ ("inb %1, %0" : "=a" (rv) : "dN" (_port));
|
||||
return rv;
|
||||
}
|
80
SysCore/lib/time.c
Normal file
80
SysCore/lib/time.c
Normal file
@ -0,0 +1,80 @@
|
||||
#include <system.h>
|
||||
#include <time.h>
|
||||
|
||||
const char* clock_months[] = {0,
|
||||
"January", "February", "March", "April", "May", "June",
|
||||
"July", "August", "September", "October", "November", "December"};
|
||||
const char* clock_weekdays[] = {0,
|
||||
"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
|
||||
|
||||
byte clock_months_len[] = {
|
||||
0,
|
||||
31, // January
|
||||
28, // February
|
||||
31, // March
|
||||
30, // April
|
||||
31, // May
|
||||
30, // June
|
||||
31, // July
|
||||
31, // August
|
||||
30, // September
|
||||
31, // October
|
||||
30, // November
|
||||
31 // December
|
||||
};
|
||||
|
||||
void _CLOCK_INC(TIME *tim)
|
||||
{
|
||||
// New minute
|
||||
if (++tim->seconds > 59) {
|
||||
tim->seconds = 0;
|
||||
// New hour
|
||||
if (++tim->minutes > 59) {
|
||||
tim->minutes = 0;
|
||||
tim->hours++;
|
||||
if (tim->hours == 12 && tim->am_pm == 1) { // 11:59pm -> 0:00am
|
||||
tim->hours = 0; tim->am_pm = 0;
|
||||
// New day
|
||||
tim->weekday = 1+(tim->weekday%7);
|
||||
// Leap years
|
||||
if ((tim->day==28) && (tim->month==2)) { tim->day++; return; }
|
||||
// New month
|
||||
if (++tim->day > clock_months_len[tim->month]) {
|
||||
tim->day = 1;
|
||||
// New year
|
||||
if (++tim->month>12) {
|
||||
tim->month = 1;
|
||||
// New century
|
||||
if (++tim->year > 99) { tim->year = 0; tim->century++;}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (tim->hours == 12 && tim->am_pm == 0) tim->am_pm = 1; // 11:59am -> 12:00pm
|
||||
else if (tim->hours == 13 && tim->am_pm == 1) tim->hours = 1; // 12:59pm -> 1:59pm
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* ASCTIME Formats: ****************************************************************
|
||||
* 1 W = weekday, M = month, D = day, H = Hour, M = Minute, S = Second, Y = year) *
|
||||
* A = AM/PM *
|
||||
* 2 Use capital letter for one letter/digit; else, use lower *
|
||||
* *
|
||||
* Example: asctime (time, "Today is: %W3 %D2 %m") *
|
||||
* Result: Today is: Mon 22 June *
|
||||
************************************************************************************/
|
||||
|
||||
/*char* asctime (TIME time, char* format)
|
||||
{
|
||||
char str[100];
|
||||
int l = strlen(format), i;
|
||||
byte special = 0;
|
||||
|
||||
for (i=0; i<l-1 && i<100; i++) {
|
||||
if (format[i] == '%') switch (format[i+1]) {
|
||||
case 'W':
|
||||
|
||||
|
||||
|
||||
}*/
|
26
SysCore/loader.asm
Normal file
26
SysCore/loader.asm
Normal file
@ -0,0 +1,26 @@
|
||||
bits 32
|
||||
|
||||
global start
|
||||
start: jmp stub
|
||||
|
||||
|
||||
stub: cmp eax, 0x2badb002
|
||||
jne .bad
|
||||
|
||||
mov ax, 10h
|
||||
mov ds, ax
|
||||
mov es, ax
|
||||
mov fs, ax
|
||||
mov gs, ax
|
||||
|
||||
extern _k_main
|
||||
call _k_main
|
||||
|
||||
.bad:
|
||||
cli
|
||||
hlt
|
||||
|
||||
|
||||
|
||||
SECTION .bss
|
||||
resb 8192 ; This reserves 8KBytes of memory here
|
71
SysCore/main.c
Normal file
71
SysCore/main.c
Normal file
@ -0,0 +1,71 @@
|
||||
#include <string.h>
|
||||
#include <system.h>
|
||||
#include <conio.h>
|
||||
#include <hal.h>
|
||||
#include <time.h>
|
||||
#include <bootinfo.h>
|
||||
#include "memory/mmngr_ph.h"
|
||||
#include "shell/shell.c"
|
||||
|
||||
//! format of a memory region
|
||||
typedef struct {
|
||||
|
||||
uint32_t startLo;
|
||||
uint32_t startHi;
|
||||
uint32_t sizeLo;
|
||||
uint32_t sizeHi;
|
||||
uint32_t type;
|
||||
uint32_t acpi_3_0;
|
||||
} memory_region ;
|
||||
|
||||
//! different memory regions (in memory_region.type)
|
||||
char* strMemoryTypes[] = {
|
||||
"",
|
||||
"Available", //memory_region.type==0
|
||||
"Reserved", //memory_region.type==1
|
||||
"ACPI Reclaim", //memory_region.type==2
|
||||
"ACPI NVS Memory" //memory_region.type==3
|
||||
};
|
||||
|
||||
extern dword _code;
|
||||
extern dword _data;
|
||||
extern dword _bss;
|
||||
extern dword _end;
|
||||
|
||||
void k_init(multiboot_info* bootinfo)
|
||||
{
|
||||
// Start by zero-ing the bss
|
||||
memset(&_bss, 0, &_end - &_bss);
|
||||
|
||||
// Initialize HAL
|
||||
i86_hal_initialize();
|
||||
|
||||
// Initialize Graphics
|
||||
graphics_init();
|
||||
|
||||
// cleanup the console screen
|
||||
set_default_colors (0x07, 0x04);
|
||||
clrscr();
|
||||
|
||||
|
||||
// Start memory manager
|
||||
uint32_t memSize = 1024 + bootinfo->m_memoryLo + bootinfo->m_memoryHi*64;
|
||||
memory_region* memMap = (memory_region*)0x1000;
|
||||
pmmngr_init (memSize, (uint32_t)&_end);
|
||||
|
||||
unsigned int i;
|
||||
|
||||
for (i=0; (memMap[i].sizeHi != 0 || memMap[i].sizeLo != 0) && i<3; ++i)
|
||||
if (memMap[i].type==1) pmmngr_init_region (memMap[i].startLo, memMap[i].sizeLo);
|
||||
|
||||
}
|
||||
|
||||
void k_main(uint32_t kernel_size, multiboot_info* bootinfo)
|
||||
{
|
||||
k_init(bootinfo);
|
||||
apps_osver();
|
||||
|
||||
shell();
|
||||
|
||||
for(;;);
|
||||
}
|
59
SysCore/makeall.bat
Normal file
59
SysCore/makeall.bat
Normal file
@ -0,0 +1,59 @@
|
||||
@echo off
|
||||
|
||||
set loader_name=loader
|
||||
set nasm_path=C:\nasm
|
||||
set djgpp_path=C:\DJGPP\bin
|
||||
|
||||
|
||||
@echo ***************** CTA KERNEL *****************
|
||||
|
||||
goto KernelEntry
|
||||
|
||||
:error
|
||||
@echo.
|
||||
@echo There have been build errors. Building halted.
|
||||
@pause
|
||||
exit
|
||||
|
||||
:KernelEntry
|
||||
del objects\%loader_name%.o
|
||||
del objects\main.o
|
||||
|
||||
@echo.
|
||||
@echo Building Kernel entry...
|
||||
@echo * Compiling kernel loader...
|
||||
%nasm_path%\nasm.exe -f aout -o ./objects/%loader_name%.o %loader_name%.asm
|
||||
|
||||
@echo * Compiling kernel main...
|
||||
%djgpp_path%\gcc.exe -Wall -O -fstrength-reduce -fomit-frame-pointer -nostdinc -fno-builtin -I./include -c -o ./objects/main.o main.c
|
||||
if not exist objects\%loader_name%.o goto error
|
||||
if not exist objects\main.o goto error
|
||||
|
||||
@echo.
|
||||
|
||||
:KernelSTDLIB
|
||||
cd lib
|
||||
rem call compile.bat
|
||||
cd..
|
||||
|
||||
:KernelMemoryManager
|
||||
cd memory
|
||||
call compile.bat
|
||||
cd..
|
||||
|
||||
rem here go other sources:
|
||||
|
||||
rem here go other sources ^
|
||||
|
||||
:Finish
|
||||
cd objects
|
||||
@echo Linking...
|
||||
del kernel.bin
|
||||
%djgpp_path%\ld -T link.ld
|
||||
if not exist kernel.bin goto error
|
||||
|
||||
@echo.
|
||||
|
||||
echo Copying to floppy drive...
|
||||
copy KERNEL.BIN A:\KERNEL.CTA >nul
|
||||
cd..
|
66
SysCore/makeallh.bat
Normal file
66
SysCore/makeallh.bat
Normal file
@ -0,0 +1,66 @@
|
||||
@echo off
|
||||
|
||||
set loader_name=loader
|
||||
set nasm_path=C:\nasm
|
||||
set djgpp_path=C:\DJGPP\bin
|
||||
|
||||
|
||||
@echo ***************** CTA KERNEL *****************
|
||||
|
||||
goto KernelEntry
|
||||
|
||||
:error
|
||||
@echo.
|
||||
@echo There have been build errors. Building halted.
|
||||
@pause
|
||||
exit
|
||||
|
||||
:KernelEntry
|
||||
del objects\%loader_name%.o
|
||||
del objects\main.o
|
||||
|
||||
@echo.
|
||||
@echo Building Kernel entry...
|
||||
@echo * Compiling kernel loader...
|
||||
%nasm_path%\nasm.exe -f aout -o ./objects/%loader_name%.o %loader_name%.asm
|
||||
|
||||
@echo * Compiling kernel main...
|
||||
%djgpp_path%\gcc.exe -Wall -O -fstrength-reduce -fomit-frame-pointer -nostdinc -fno-builtin -I./include -c -o ./objects/main.o main.c
|
||||
if not exist objects\%loader_name%.o goto error
|
||||
if not exist objects\main.o goto error
|
||||
|
||||
@echo.
|
||||
|
||||
:KernelSTDLIB
|
||||
cd lib
|
||||
call compile.bat
|
||||
@echo.
|
||||
cd..
|
||||
|
||||
:KernelMemoryManager
|
||||
cd memory
|
||||
call compile.bat
|
||||
@echo.
|
||||
cd..
|
||||
|
||||
:KernelHAL
|
||||
cd hal
|
||||
call makeall.bat
|
||||
cd..
|
||||
|
||||
rem here go other sources:
|
||||
|
||||
rem here go other sources ^
|
||||
|
||||
:Finish
|
||||
cd objects
|
||||
@echo Linking...
|
||||
del kernel.bin
|
||||
%djgpp_path%\ld -T link.ld
|
||||
if not exist kernel.bin goto error
|
||||
|
||||
@echo.
|
||||
|
||||
echo Copying to floppy drive...
|
||||
copy KERNEL.BIN A:\KERNEL.CTA >nul
|
||||
cd..
|
28
SysCore/memory/compile.bat
Normal file
28
SysCore/memory/compile.bat
Normal file
@ -0,0 +1,28 @@
|
||||
@echo off
|
||||
|
||||
rem NASM and DJGPP executable paths:
|
||||
set nasm_path=C:\nasm
|
||||
set djgpp_path=C:\DJGPP\bin
|
||||
set objpath=..\objects
|
||||
set incpath=../include
|
||||
goto build
|
||||
|
||||
:error
|
||||
@echo.
|
||||
@echo There have been build errors. Building halted.
|
||||
@pause
|
||||
exit
|
||||
|
||||
:build
|
||||
@echo Building Memory Manager...
|
||||
|
||||
del %objpath%\mmngr_cr.o
|
||||
del %objpath%\mmngr_ph.o
|
||||
|
||||
@echo * Compiling Physical Memory Manager...
|
||||
%nasm_path%\nasm.exe -f aout -o %objpath%/mmngr_cr.o mmngr_cr.asm
|
||||
%djgpp_path%\gcc.exe -Wall -O -fstrength-reduce -fomit-frame-pointer -nostdinc -fno-builtin -I%incpath% -c -o %objpath%/mmngr_ph.o mmngr_ph.c
|
||||
|
||||
:check
|
||||
if not exist %objpath%\mmngr_cr.o goto error
|
||||
if not exist %objpath%\mmngr_ph.o goto error
|
29
SysCore/memory/mmngr_cr.asm
Normal file
29
SysCore/memory/mmngr_cr.asm
Normal file
@ -0,0 +1,29 @@
|
||||
bits 32
|
||||
|
||||
global _read_cr0
|
||||
_read_cr0:
|
||||
mov eax, cr0
|
||||
retn
|
||||
|
||||
global _write_cr0
|
||||
_write_cr0:
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
mov eax, [ebp+8]
|
||||
mov cr0, eax
|
||||
pop ebp
|
||||
retn
|
||||
|
||||
global _read_cr3
|
||||
_read_cr3:
|
||||
mov eax, cr3
|
||||
retn
|
||||
|
||||
global _write_cr3
|
||||
_write_cr3:
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
mov eax, [ebp+8]
|
||||
mov cr3, eax
|
||||
pop ebp
|
||||
retn
|
204
SysCore/memory/mmngr_ph.c
Normal file
204
SysCore/memory/mmngr_ph.c
Normal file
@ -0,0 +1,204 @@
|
||||
/******************************************************
|
||||
* Physical Memory Manager *
|
||||
******************************************************/
|
||||
#include <system.h>
|
||||
#include <string.h>
|
||||
#include "mmngr_ph.h"
|
||||
|
||||
#define PMMNGR_BLOCK_SIZE 4096 // block size (4k)
|
||||
#define PMMNGR_BLOCK_ALIGN PMMNGR_BLOCK_SIZE // block alignment
|
||||
|
||||
struct memory_stack_entry{
|
||||
word low;
|
||||
byte high;
|
||||
} __attribute__ ((__packed__));
|
||||
typedef struct memory_stack_entry mstack;
|
||||
|
||||
static uint32_t _mmngr_memory_size=0; // size of physical memory
|
||||
static uint32_t _mmngr_used_blocks=0; // number of blocks currently in use
|
||||
static uint32_t _mmngr_max_blocks=0; // maximum number of available memory blocks
|
||||
static uint32_t _mmngr_index = 0;
|
||||
|
||||
static mstack* _mmngr_memory_stack= 0; // memory stack
|
||||
|
||||
inline mstack mstack_pop ()
|
||||
{
|
||||
mstack temp;
|
||||
temp.low = _mmngr_memory_stack[--_mmngr_index].low;
|
||||
temp.high = _mmngr_memory_stack[_mmngr_index].high;
|
||||
_mmngr_used_blocks++;
|
||||
|
||||
_mmngr_memory_stack[_mmngr_index].low = 0xFFFF;
|
||||
_mmngr_memory_stack[_mmngr_index].high = 0xFF;
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
||||
|
||||
inline void mstack_push (const mstack *block)
|
||||
{
|
||||
if (block->low == 0 && block-> high == 0) return;
|
||||
|
||||
_mmngr_memory_stack[_mmngr_index].low = block->low;
|
||||
_mmngr_memory_stack[_mmngr_index].high = block->high;
|
||||
|
||||
_mmngr_index++;
|
||||
_mmngr_used_blocks--;
|
||||
}
|
||||
|
||||
|
||||
inline byte mstack_test (const mstack *block)
|
||||
{
|
||||
uint32_t i;
|
||||
for (i = 0; i < _mmngr_index; i++)
|
||||
if (_mmngr_memory_stack[i].low == block->low && _mmngr_memory_stack[i].high == block->high) return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
byte pmmngr_test_block (uint32_t block)
|
||||
{
|
||||
mstack temp;
|
||||
temp.low = block & 0xFFFF;
|
||||
temp.high = (block>>16) & 0xFF;
|
||||
|
||||
return mstack_test(&temp);
|
||||
}
|
||||
|
||||
void pmmngr_free_block(void* address)
|
||||
{
|
||||
// Calculate block
|
||||
mstack block;
|
||||
uint32_t temp = (uint32_t)address / PMMNGR_BLOCK_SIZE;
|
||||
block.low = temp & 0xFFFF;
|
||||
block.high = (temp>>16) & 0xFF;
|
||||
|
||||
// Push it
|
||||
mstack_push (&block);
|
||||
}
|
||||
|
||||
|
||||
void* pmmngr_alloc_block()
|
||||
{
|
||||
if (_mmngr_index == 0) return 0;// Out of memory
|
||||
// pop a block
|
||||
mstack block = mstack_pop();
|
||||
|
||||
// Calculate and return address;
|
||||
void* address;
|
||||
uint32_t temp = block.low | (block.high<<16);
|
||||
address = (void *)(temp * PMMNGR_BLOCK_SIZE);
|
||||
|
||||
return address;
|
||||
}
|
||||
|
||||
|
||||
void pmmngr_init (size_t memSize, uint32_t stack) {
|
||||
|
||||
_mmngr_memory_size = memSize;
|
||||
_mmngr_memory_stack = (mstack*) stack;
|
||||
_mmngr_max_blocks = (_mmngr_memory_size*1024) / PMMNGR_BLOCK_SIZE;
|
||||
_mmngr_used_blocks = _mmngr_max_blocks;
|
||||
_mmngr_index = 0;
|
||||
|
||||
// By default, all of memory is in use
|
||||
}
|
||||
|
||||
void pmmngr_init_region (physical_addr base, size_t size) {
|
||||
|
||||
mstack block;
|
||||
|
||||
|
||||
unsigned int count = size / PMMNGR_BLOCK_SIZE;
|
||||
unsigned int start = base / PMMNGR_BLOCK_SIZE;
|
||||
|
||||
for (; count!=0; count--) {
|
||||
block.low = (start + count) & 0xFFFF;
|
||||
block.high = ((start + count) << 16) & 0xFF;
|
||||
mstack_push(&block);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void pmmngr_deinit_region (physical_addr base, size_t size) {
|
||||
unsigned int start = base / PMMNGR_BLOCK_SIZE;
|
||||
unsigned int count = size / PMMNGR_BLOCK_SIZE;
|
||||
int temp;
|
||||
|
||||
unsigned int i;
|
||||
unsigned int j;
|
||||
|
||||
// Find free blocks in the area and zero them
|
||||
for (i = 0; i < _mmngr_index; i++) {
|
||||
temp = (_mmngr_memory_stack[i].high << 16) | _mmngr_memory_stack[i].low;
|
||||
if (temp >=start && temp < start+count)
|
||||
{ _mmngr_memory_stack[i].high = 0;
|
||||
_mmngr_memory_stack[i].low = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Eliminate zero blocks
|
||||
for (i = 0; i<_mmngr_index; i++)
|
||||
if (_mmngr_memory_stack[i].high == 0 && _mmngr_memory_stack[i].low == 0)
|
||||
{
|
||||
// Find next non-zero
|
||||
for (j = i; _mmngr_memory_stack[j].high == 0 && _mmngr_memory_stack[j].low == 0; j++)
|
||||
if (j == _mmngr_index-1) {
|
||||
j = 0; break; }
|
||||
|
||||
if (j == 0) {
|
||||
_mmngr_index = i;
|
||||
break;
|
||||
}
|
||||
|
||||
_mmngr_memory_stack[i].high = _mmngr_memory_stack[j].high;
|
||||
_mmngr_memory_stack[i].low = _mmngr_memory_stack[j].low;
|
||||
_mmngr_memory_stack[j].high = 0;
|
||||
_mmngr_memory_stack[j].low = 0;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
size_t pmmngr_get_memory_size () {
|
||||
return _mmngr_memory_size;
|
||||
}
|
||||
|
||||
uint32_t pmmngr_get_block_count () {
|
||||
return _mmngr_max_blocks;
|
||||
}
|
||||
|
||||
uint32_t pmmngr_get_use_block_count () {
|
||||
return _mmngr_used_blocks;
|
||||
}
|
||||
|
||||
uint32_t pmmngr_get_free_block_count () {
|
||||
return _mmngr_index;
|
||||
}
|
||||
|
||||
uint32_t pmmngr_get_block_size () {
|
||||
return PMMNGR_BLOCK_SIZE;
|
||||
}
|
||||
|
||||
void pmmngr_paging_enable (byte b) {
|
||||
uint32_t temp;
|
||||
|
||||
temp = read_cr0();
|
||||
// Enable
|
||||
if (b) temp |= 0x80000000;
|
||||
else temp &= ~0x80000000;
|
||||
|
||||
write_cr0(temp);
|
||||
}
|
||||
|
||||
|
||||
byte pmmngr_is_paging () {
|
||||
uint32_t temp = read_cr0();
|
||||
return ((temp&0x80000000)>0);
|
||||
}
|
||||
|
||||
mstack* pmmngr_get_stack_addr()
|
||||
{
|
||||
return _mmngr_memory_stack;
|
||||
}
|
33
SysCore/memory/mmngr_ph.h
Normal file
33
SysCore/memory/mmngr_ph.h
Normal file
@ -0,0 +1,33 @@
|
||||
|
||||
#ifndef _MMNGR_PHYS_H
|
||||
#define _MMNGR_PHYS_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <system.h>
|
||||
|
||||
|
||||
#define pmmngr_load_PDBR(addr) write_cr3(addr)
|
||||
#define pmmngr_get_PDBR() read_cr3()
|
||||
|
||||
// physical address
|
||||
typedef unsigned physical_addr;
|
||||
|
||||
extern uint32_t read_cr0();
|
||||
extern uint32_t read_cr3();
|
||||
extern void write_cr0(uint32_t data);
|
||||
extern void write_cr3(uint32_t data);
|
||||
extern void pmmngr_free_block(void* address); // releases a memory block
|
||||
extern void* pmmngr_alloc_block (); // allocates a single memory block
|
||||
extern void pmmngr_init (size_t memSize, uint32_t stack); // initialize the physical memory manager
|
||||
extern void pmmngr_init_region (physical_addr base, size_t size); // enables a physical memory region for use
|
||||
extern void pmmngr_deinit_region (physical_addr base, size_t size); // disables a physical memory region as in use (unuseable)
|
||||
extern size_t pmmngr_get_memory_size (); // returns amount of physical memory the manager is set to use
|
||||
extern uint32_t pmmngr_get_use_block_count (); // returns number of blocks currently in use
|
||||
extern uint32_t pmmngr_get_free_block_count (); // returns number of blocks not in use
|
||||
extern uint32_t pmmngr_get_block_count (); // returns number of memory blocks
|
||||
extern uint32_t pmmngr_get_block_size (); // returns default memory block size in bytes
|
||||
extern void pmmngr_paging_enable (byte b); // enable or disable paging
|
||||
extern byte pmmngr_is_paging (); // test if paging is enabled
|
||||
|
||||
extern byte pmmngr_test_block (uint32_t block);
|
||||
#endif
|
26
SysCore/memory/pde.c
Normal file
26
SysCore/memory/pde.c
Normal file
@ -0,0 +1,26 @@
|
||||
#include <pde.h>
|
||||
|
||||
void pt_entry_add_attrib (pt_entry* entry, unsigned mask) {
|
||||
*entry |= mask;
|
||||
}
|
||||
|
||||
void pt_entry_del_attrib (pt_entry* entry, unsigned mask) {
|
||||
*entry &= ~mask;
|
||||
}
|
||||
|
||||
void pt_entry_set_frame (pt_entry* entry, unsigned address) {
|
||||
*entry &= ~_I86_PTE_FRAME;
|
||||
*entry |= address & _I86_PTE_FRAME;
|
||||
}
|
||||
|
||||
unsigned pt_entry_get_frame (pt_entry entry) {
|
||||
return entry&_I86_PTE_FRAME;
|
||||
}
|
||||
|
||||
unsigned char pt_entry_is_present (pt_entry entry) {
|
||||
return ( (entry & _I86_PTE_PRESENT) > 0 );
|
||||
}
|
||||
|
||||
unsigned char pt_entry_is_writable (pt_entry entry) {
|
||||
return ( (entry & _I86_PTE_WRITABLE) > 0 );
|
||||
}
|
27
SysCore/memory/pde.h
Normal file
27
SysCore/memory/pde.h
Normal file
@ -0,0 +1,27 @@
|
||||
#ifndef __PAGE_DIRECTORY_ENTRY_
|
||||
#define __PAGE_DIRECTORY_ENTRY_
|
||||
|
||||
enum __PAGE_FLAGS {
|
||||
_I86_PTE_PRESENT = 1,
|
||||
_I86_PTE_WRITABLE = 2,
|
||||
_I86_PTE_USER = 4,
|
||||
_I86_PTE_WRITETHROUGH = 8,
|
||||
_I86_PTE_NOT_CACHEABLE = 0x10,
|
||||
_I86_PTE_ACCESSED = 0x20,
|
||||
_I86_PTE_DIRTY = 0x40,
|
||||
_I86_PTE_PAT = 0x80,
|
||||
_I86_PTE_CPU_GLOBAL = 0x100,
|
||||
_I86_PTE_LV4_GLOBAL = 0x200,
|
||||
_I86_PTE_FRAME = 0x7FFFF000
|
||||
};
|
||||
|
||||
typedef unsigned pt_entry;
|
||||
|
||||
extern void pt_entry_add_attrib (pt_entry* entry, unsigned mask);
|
||||
extern void pt_entry_del_attrib (pt_entry* entry, unsigned mask);
|
||||
extern void pt_entry_set_frame (pt_entry* entry, unsigned address);
|
||||
extern unsigned pt_entry_get_frame (pt_entry entry);
|
||||
|
||||
extern unsigned char pt_entry_is_present (pt_entry entry);
|
||||
extern unsigned char pt_entry_is_writable (pt_entry entry);
|
||||
#endif
|
26
SysCore/memory/pte.c
Normal file
26
SysCore/memory/pte.c
Normal file
@ -0,0 +1,26 @@
|
||||
#include <pte.h>
|
||||
|
||||
void pt_entry_add_attrib (pt_entry* entry, unsigned mask) {
|
||||
*entry |= mask;
|
||||
}
|
||||
|
||||
void pt_entry_del_attrib (pt_entry* entry, unsigned mask) {
|
||||
*entry &= ~mask;
|
||||
}
|
||||
|
||||
void pt_entry_set_frame (pt_entry* entry, unsigned address) {
|
||||
*entry &= ~_I86_PTE_FRAME;
|
||||
*entry |= address & _I86_PTE_FRAME;
|
||||
}
|
||||
|
||||
unsigned pt_entry_get_frame (pt_entry entry) {
|
||||
return entry&_I86_PTE_FRAME;
|
||||
}
|
||||
|
||||
unsigned char pt_entry_is_present (pt_entry entry) {
|
||||
return ( (entry & _I86_PTE_PRESENT) > 0 );
|
||||
}
|
||||
|
||||
unsigned char pt_entry_is_writable (pt_entry entry) {
|
||||
return ( (entry & _I86_PTE_WRITABLE) > 0 );
|
||||
}
|
27
SysCore/memory/pte.h
Normal file
27
SysCore/memory/pte.h
Normal file
@ -0,0 +1,27 @@
|
||||
#ifndef __PAGE_TABLE_ENTRY_
|
||||
#define __PAGE_TABLE_ENTRY_
|
||||
|
||||
enum __PAGE_FLAGS {
|
||||
_I86_PTE_PRESENT = 1,
|
||||
_I86_PTE_WRITABLE = 2,
|
||||
_I86_PTE_USER = 4,
|
||||
_I86_PTE_WRITETHROUGH = 8,
|
||||
_I86_PTE_NOT_CACHEABLE = 0x10,
|
||||
_I86_PTE_ACCESSED = 0x20,
|
||||
_I86_PTE_DIRTY = 0x40,
|
||||
_I86_PTE_PAT = 0x80,
|
||||
_I86_PTE_CPU_GLOBAL = 0x100,
|
||||
_I86_PTE_LV4_GLOBAL = 0x200,
|
||||
_I86_PTE_FRAME = 0x7FFFF000
|
||||
};
|
||||
|
||||
typedef unsigned pt_entry;
|
||||
|
||||
extern void pt_entry_add_attrib (pt_entry* entry, unsigned mask);
|
||||
extern void pt_entry_del_attrib (pt_entry* entry, unsigned mask);
|
||||
extern void pt_entry_set_frame (pt_entry* entry, unsigned address);
|
||||
extern unsigned pt_entry_get_frame (pt_entry entry);
|
||||
|
||||
extern unsigned char pt_entry_is_present (pt_entry entry);
|
||||
extern unsigned char pt_entry_is_writable (pt_entry entry);
|
||||
#endif
|
BIN
SysCore/objects/BSOD.O
Normal file
BIN
SysCore/objects/BSOD.O
Normal file
Binary file not shown.
BIN
SysCore/objects/CMOS.O
Normal file
BIN
SysCore/objects/CMOS.O
Normal file
Binary file not shown.
BIN
SysCore/objects/CONIO.O
Normal file
BIN
SysCore/objects/CONIO.O
Normal file
Binary file not shown.
BIN
SysCore/objects/CPU.O
Normal file
BIN
SysCore/objects/CPU.O
Normal file
Binary file not shown.
BIN
SysCore/objects/GDT.O
Normal file
BIN
SysCore/objects/GDT.O
Normal file
Binary file not shown.
BIN
SysCore/objects/GDT_ASM.O
Normal file
BIN
SysCore/objects/GDT_ASM.O
Normal file
Binary file not shown.
BIN
SysCore/objects/HAL.O
Normal file
BIN
SysCore/objects/HAL.O
Normal file
Binary file not shown.
BIN
SysCore/objects/IDT.O
Normal file
BIN
SysCore/objects/IDT.O
Normal file
Binary file not shown.
BIN
SysCore/objects/IDT_ASM.O
Normal file
BIN
SysCore/objects/IDT_ASM.O
Normal file
Binary file not shown.
BIN
SysCore/objects/IRQ.O
Normal file
BIN
SysCore/objects/IRQ.O
Normal file
Binary file not shown.
BIN
SysCore/objects/IRQ_ASM.O
Normal file
BIN
SysCore/objects/IRQ_ASM.O
Normal file
Binary file not shown.
BIN
SysCore/objects/ISRS.O
Normal file
BIN
SysCore/objects/ISRS.O
Normal file
Binary file not shown.
BIN
SysCore/objects/ISRS_ASM.O
Normal file
BIN
SysCore/objects/ISRS_ASM.O
Normal file
Binary file not shown.
BIN
SysCore/objects/KERNEL.BIN
Normal file
BIN
SysCore/objects/KERNEL.BIN
Normal file
Binary file not shown.
BIN
SysCore/objects/KEYUS.O
Normal file
BIN
SysCore/objects/KEYUS.O
Normal file
Binary file not shown.
BIN
SysCore/objects/LOADER.O
Normal file
BIN
SysCore/objects/LOADER.O
Normal file
Binary file not shown.
BIN
SysCore/objects/MAIN.O
Normal file
BIN
SysCore/objects/MAIN.O
Normal file
Binary file not shown.
BIN
SysCore/objects/MMNGR_CR.O
Normal file
BIN
SysCore/objects/MMNGR_CR.O
Normal file
Binary file not shown.
BIN
SysCore/objects/MMNGR_PH.O
Normal file
BIN
SysCore/objects/MMNGR_PH.O
Normal file
Binary file not shown.
BIN
SysCore/objects/PIC.O
Normal file
BIN
SysCore/objects/PIC.O
Normal file
Binary file not shown.
BIN
SysCore/objects/PIT.O
Normal file
BIN
SysCore/objects/PIT.O
Normal file
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user