feat(kernel): pic initialize and remap
This commit is contained in:
parent
649b68ee39
commit
bd7468e69c
|
@ -16,3 +16,7 @@ vga_console_clear:
|
|||
rep stosb
|
||||
ret
|
||||
|
||||
vga_console_putc:
|
||||
|
||||
ret
|
||||
|
||||
|
|
1
kernel/fs/fat.inc
Normal file
1
kernel/fs/fat.inc
Normal file
|
@ -0,0 +1 @@
|
|||
;; File: fat.inc
|
5
kernel/fs/stpdfs.inc
Normal file
5
kernel/fs/stpdfs.inc
Normal file
|
@ -0,0 +1,5 @@
|
|||
;; File: stpdfs.inc
|
||||
|
||||
STPDFS_SB_MAGIC = 0x44505453
|
||||
STPDFS_SB_REV = 1
|
||||
|
|
@ -21,9 +21,9 @@ gdt:
|
|||
db 0x00, 0xF2, 0xCF, 0x00
|
||||
|
||||
; Tss
|
||||
;.tss:
|
||||
; dw ?
|
||||
; dd ?
|
||||
.tss:
|
||||
dw ?
|
||||
dd ?
|
||||
|
||||
.end:
|
||||
|
||||
|
|
3
kernel/irq.inc
Normal file
3
kernel/irq.inc
Normal file
|
@ -0,0 +1,3 @@
|
|||
irq_timer:
|
||||
iret
|
||||
|
|
@ -26,6 +26,15 @@ idt_setup:
|
|||
cmp ecx, 32
|
||||
jb @b
|
||||
|
||||
mov ecx, 0x42
|
||||
mov eax, isr_syscall
|
||||
mov [aInterruptGate + (ecx * 8)], ax
|
||||
mov [aInterruptGate + (ecx * 8) + 2], word 0x08
|
||||
|
||||
mov [aInterruptGate + (ecx * 8) + 5], word 0x8E
|
||||
shr eax, 16
|
||||
mov [aInterruptGate + (ecx * 8) + 6], ax
|
||||
|
||||
lidt [pIDT]
|
||||
sti
|
||||
ret
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
format binary
|
||||
|
||||
include 'const.inc'
|
||||
include 'sys/bootinfo.inc'
|
||||
include 'sys/cpu.inc'
|
||||
|
||||
org KBASE
|
||||
use32
|
||||
|
@ -52,15 +54,16 @@ kmain:
|
|||
add ebx, KERNEL_VIRT_BASE
|
||||
call pmm_free_range
|
||||
|
||||
call pic_init
|
||||
|
||||
; load kernel gdt
|
||||
lgdt [pGDT]
|
||||
; I don't think i need to reload segment cuz their value are already correct
|
||||
|
||||
xchg bx, bx
|
||||
call pic_disable
|
||||
|
||||
call idt_setup
|
||||
|
||||
int 0x42
|
||||
|
||||
.halt:
|
||||
hlt
|
||||
|
@ -71,20 +74,23 @@ kmain:
|
|||
call klog
|
||||
jmp .halt
|
||||
|
||||
include 'sys/bootinfo.inc'
|
||||
include 'klog.inc'
|
||||
include 'dev/vga_console.inc'
|
||||
include 'mm/mm.inc'
|
||||
include 'lock.inc'
|
||||
include 'gdt.inc'
|
||||
include 'syscall.inc'
|
||||
include 'isr.inc'
|
||||
include 'pic.inc'
|
||||
|
||||
|
||||
szMsgKernelAlive db "Kernel is alive", 0
|
||||
szErrorBootProtocol db "Error: wrong magic number", 0
|
||||
|
||||
boot_structure BootInfo
|
||||
|
||||
kTSS TSS
|
||||
|
||||
align 4096
|
||||
stack_bottom:
|
||||
rb 0x4000
|
||||
|
|
|
@ -6,10 +6,47 @@ PIC1_DATA = 0x21
|
|||
PIC2_COMMAND = 0xA0
|
||||
PIC2_DATA = 0xA1
|
||||
|
||||
PIC_ICW1 = 0x10
|
||||
PIC_ICW1_IC4 = 0x01
|
||||
PIC_ICW1_SNGL = 0x02
|
||||
PIC_ICW1_ADI = 0x04
|
||||
PIC_ICW1_LTIM = 0x08
|
||||
|
||||
PIC_ICW4_8086 = 0x01
|
||||
PIC_ICW4_AEOI = 0x02
|
||||
PIC_ICW4_MSTR = 0x04
|
||||
PIC_ICW4_BUF = 0x08
|
||||
PIC_ICW4_SFNM = 0x10
|
||||
|
||||
PIC_EOI = 0x20
|
||||
|
||||
|
||||
pic_init:
|
||||
; ICW 1
|
||||
mov al, PIC_ICW1 or PIC_ICW1_IC4
|
||||
out PIC1_COMMAND, al
|
||||
out PIC2_COMMAND, al
|
||||
|
||||
; ICW 2
|
||||
mov al, 0x20
|
||||
out PIC1_DATA, al
|
||||
mov al, 0x28
|
||||
out PIC2_DATA, al
|
||||
|
||||
; ICW 3
|
||||
mov al, 0x4
|
||||
out PIC1_DATA, al
|
||||
mov al, 0x2
|
||||
out PIC2_DATA, al
|
||||
|
||||
; ICW 4
|
||||
mov al, PIC_ICW4_8086
|
||||
out PIC1_DATA, al
|
||||
out PIC2_DATA, al
|
||||
|
||||
xor al, al
|
||||
out PIC1_DATA, al
|
||||
out PIC2_DATA, al
|
||||
|
||||
ret
|
||||
|
||||
|
|
|
@ -88,21 +88,24 @@ struc TSS {
|
|||
.iomap dw ?
|
||||
}
|
||||
|
||||
;; Structure: idt_gate
|
||||
struc GDTGate {
|
||||
|
||||
}
|
||||
|
||||
;; Structure: IDTGate
|
||||
;; .offset_low - TODO
|
||||
;; .selector - TODO
|
||||
;; .zero - TODO
|
||||
;; .attributes - TODO
|
||||
;; .offset_high - TODO
|
||||
;;
|
||||
struc idt_gate
|
||||
.offset_low: resw 1
|
||||
.selector: resw 1
|
||||
.zero: resb 1
|
||||
.attributes: resb 1
|
||||
.offset_high: resw 1
|
||||
endstruc
|
||||
defn idt_gate
|
||||
struc IDTGate {
|
||||
.offset_low dw ?
|
||||
.selector dw ?
|
||||
.zero db 0
|
||||
.attributes db ?
|
||||
.offset_high dw ?
|
||||
}
|
||||
|
||||
;; About: Gates
|
||||
;; - Task Gate
|
||||
|
@ -130,31 +133,31 @@ defn idt_gate
|
|||
;; > +--------------- |----------------+-----------------|-----------------+
|
||||
|
||||
|
||||
struc intframe
|
||||
struc intframe {
|
||||
;; registers
|
||||
.edi: resd 1
|
||||
.esi: resd 1
|
||||
.ebp: resd 1
|
||||
.esp: resd 1
|
||||
.ebx: resd 1
|
||||
.edx: resd 1
|
||||
.ecx: resd 1
|
||||
.eax: resd 1
|
||||
.edi dd ?
|
||||
.esi dd ?
|
||||
.ebp dd ?
|
||||
.esp dd ?
|
||||
.ebx dd ?
|
||||
.edx dd ?
|
||||
.ecx dd ?
|
||||
.eax dd ?
|
||||
|
||||
;;
|
||||
.gs: resd 1
|
||||
.fs: resd 1
|
||||
.es: resd 1
|
||||
.ds: resd 1
|
||||
.intno: resd 1
|
||||
.gs dd ?
|
||||
.fs dd ?
|
||||
.es dd ?
|
||||
.ds dd ?
|
||||
.intno dd ?
|
||||
|
||||
;; by x86 hardware
|
||||
.err: resd 1
|
||||
.eip: resd 1
|
||||
.cs: resd 1
|
||||
.eflags: resd 1
|
||||
.err dd ?
|
||||
.eip dd ?
|
||||
.cs dd ?
|
||||
.eflags dd ?
|
||||
|
||||
;; crossring
|
||||
.useresp: resd 1
|
||||
.ss: resd 1
|
||||
endstruc
|
||||
.useresp dd ?
|
||||
.ss dd ?
|
||||
}
|
||||
|
|
10
kernel/syscall.inc
Normal file
10
kernel/syscall.inc
Normal file
|
@ -0,0 +1,10 @@
|
|||
SYSCALL_EXIT = 0x01
|
||||
SYSCALL_FORK = 0x02
|
||||
|
||||
isr_syscall:
|
||||
push eax
|
||||
mov esi, szMsgSyscall
|
||||
call klog
|
||||
iret
|
||||
|
||||
szMsgSyscall db "syscall %x", 0
|
Loading…
Reference in a new issue