feat(kernel): setup idt
This commit is contained in:
		
							parent
							
								
									8081e804a5
								
							
						
					
					
						commit
						90e1d2818d
					
				
					 5 changed files with 43 additions and 2 deletions
				
			
		|  | @ -9,7 +9,9 @@ SRCS	= kernel.asm \ | ||||||
| 			dev/vga_console.inc \
 | 			dev/vga_console.inc \
 | ||||||
| 			mm/mm.inc \
 | 			mm/mm.inc \
 | ||||||
| 			mm/pmm.inc \
 | 			mm/pmm.inc \
 | ||||||
| 			lock.inc  | 			lock.inc \
 | ||||||
|  | 			gdt.inc \
 | ||||||
|  | 			isr.inc | ||||||
| 
 | 
 | ||||||
| .PHONY: all | .PHONY: all | ||||||
| all: $(KERNEL) | all: $(KERNEL) | ||||||
|  |  | ||||||
|  | @ -1,5 +1,4 @@ | ||||||
| macro ISR [name,error] { | macro ISR [name,error] { | ||||||
| isr_table: |  | ||||||
| forward | forward | ||||||
| 	dd isr_#name
 | 	dd isr_#name
 | ||||||
| forward | forward | ||||||
|  | @ -13,6 +12,34 @@ forward | ||||||
| 				  | 				  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | idt_setup: | ||||||
|  | 	xor ecx, ecx | ||||||
|  | @@: | ||||||
|  | 	mov eax, [aISRTable + (ecx * 4)] | ||||||
|  | 	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 | ||||||
|  | 	inc ecx | ||||||
|  | 	cmp ecx, 32 | ||||||
|  | 	jb @b | ||||||
|  | 
 | ||||||
|  | 	lidt [pIDT] | ||||||
|  | 	sti | ||||||
|  | 	ret | ||||||
|  | 
 | ||||||
|  | pIDT: | ||||||
|  | 	dw aInterruptGate.end-aInterruptGate-1 | ||||||
|  | 	dd aInterruptGate | ||||||
|  | 
 | ||||||
|  | ; variable: idt_entries | ||||||
|  | aInterruptGate: | ||||||
|  | 	dd 256*2 dup(0) | ||||||
|  | .end: | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| isr_common: | isr_common: | ||||||
| 	pusha | 	pusha | ||||||
| 
 | 
 | ||||||
|  | @ -25,6 +52,9 @@ isr_common: | ||||||
| 	mov fs, ax | 	mov fs, ax | ||||||
| 	mov gs, ax | 	mov gs, ax | ||||||
| 
 | 
 | ||||||
|  | 	mov esi, szMsgInterrupt | ||||||
|  | 	call klog  | ||||||
|  | 
 | ||||||
| 	pop eax | 	pop eax | ||||||
| 	mov ds, ax | 	mov ds, ax | ||||||
| 	mov es, ax | 	mov es, ax | ||||||
|  | @ -36,6 +66,7 @@ isr_common: | ||||||
| 	sti | 	sti | ||||||
| 	iret | 	iret | ||||||
| 
 | 
 | ||||||
|  | aISRTable: | ||||||
| ISR \ | ISR \ | ||||||
| 	division_by_zero, 0, \ | 	division_by_zero, 0, \ | ||||||
| 	debug, 0, \ | 	debug, 0, \ | ||||||
|  | @ -69,3 +100,5 @@ ISR \ | ||||||
| 	reserved29, 0, \ | 	reserved29, 0, \ | ||||||
| 	security_exception, 0, \ | 	security_exception, 0, \ | ||||||
| 	reserved31, 0 | 	reserved31, 0 | ||||||
|  | 
 | ||||||
|  | szMsgInterrupt db "Interrupt", 0 | ||||||
|  |  | ||||||
|  | @ -56,6 +56,7 @@ kmain: | ||||||
| 	lgdt [pGDT] | 	lgdt [pGDT] | ||||||
| 	; I don't think i need to reload segment cuz their value are already correct | 	; I don't think i need to reload segment cuz their value are already correct | ||||||
| 
 | 
 | ||||||
|  | 	call idt_setup | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| .halt: | .halt: | ||||||
|  | @ -73,6 +74,7 @@ kmain: | ||||||
| 	include 'mm/mm.inc' | 	include 'mm/mm.inc' | ||||||
| 	include 'lock.inc' | 	include 'lock.inc' | ||||||
| 	include 'gdt.inc' | 	include 'gdt.inc' | ||||||
|  | 	include 'isr.inc' | ||||||
| 
 | 
 | ||||||
| szMsgKernelAlive db "Kernel is alive", 0 | szMsgKernelAlive db "Kernel is alive", 0 | ||||||
| szErrorBootProtocol db "Error: wrong magic number", 0 | szErrorBootProtocol db "Error: wrong magic number", 0 | ||||||
|  |  | ||||||
|  | @ -1,3 +1,6 @@ | ||||||
|  | 	;; File: pic.inc | ||||||
|  | 	;;  <Datasheet at https://pdos.csail.mit.edu/6.828/2005/readings/hardware/8259A.pdf> | ||||||
|  | 
 | ||||||
| PIC1_COMMAND = 0x20 | PIC1_COMMAND = 0x20 | ||||||
| PIC1_DATA    = 0x21 | PIC1_DATA    = 0x21 | ||||||
| PIC2_COMMAND = 0xA0 | PIC2_COMMAND = 0xA0 | ||||||
|  |  | ||||||
|  | @ -102,6 +102,7 @@ struc idt_gate | ||||||
| 	.attributes:  resb 1 | 	.attributes:  resb 1 | ||||||
| 	.offset_high: resw 1 | 	.offset_high: resw 1 | ||||||
| endstruc | endstruc | ||||||
|  | defn idt_gate | ||||||
| 
 | 
 | ||||||
| 	;; About: Gates | 	;; About: Gates | ||||||
| 	;; - Task Gate | 	;; - Task Gate | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue