feat(kernel): wip serial logger
This commit is contained in:
		
							parent
							
								
									031e09b3ff
								
							
						
					
					
						commit
						41676291fe
					
				
					 7 changed files with 147 additions and 24 deletions
				
			
		| 
						 | 
					@ -225,8 +225,9 @@ common32:
 | 
				
			||||||
	mov eax, STPDBOOT_MAGIC
 | 
						mov eax, STPDBOOT_MAGIC
 | 
				
			||||||
	mov ebx, boot_structure
 | 
						mov ebx, boot_structure
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	mov eax, 0xC0000000
 | 
						mov ecx, 0xC0000000
 | 
				
			||||||
	jmp eax
 | 
						jmp ecx
 | 
				
			||||||
 | 
					
 | 
				
			||||||
hang:
 | 
					hang:
 | 
				
			||||||
	hlt
 | 
						hlt
 | 
				
			||||||
	jmp $
 | 
						jmp $
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,6 +5,8 @@ INSTALL = install
 | 
				
			||||||
KERNEL	= vmstupid.sys
 | 
					KERNEL	= vmstupid.sys
 | 
				
			||||||
SRCS	= kernel.asm \
 | 
					SRCS	= kernel.asm \
 | 
				
			||||||
			const.inc \
 | 
								const.inc \
 | 
				
			||||||
 | 
								klog.inc \
 | 
				
			||||||
 | 
								dev/vga_console.inc \
 | 
				
			||||||
			mm/mm.inc
 | 
								mm/mm.inc
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.PHONY: all
 | 
					.PHONY: all
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -46,3 +46,5 @@ CR4_PKE        = 0x0400000
 | 
				
			||||||
CR4_CET        = 0x0800000
 | 
					CR4_CET        = 0x0800000
 | 
				
			||||||
CR4_PKS        = 0x1000000
 | 
					CR4_PKS        = 0x1000000
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CR   = 0x0D
 | 
				
			||||||
 | 
					LF   = 0x0A
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,16 @@
 | 
				
			||||||
struc console
 | 
					VGA_COLUMNS = 80
 | 
				
			||||||
{
 | 
					VGA_LINES = 25
 | 
				
			||||||
	.buffer db 80*25 dup (?)
 | 
					VGA_BASE = 0xC03B0000
 | 
				
			||||||
	.lineno db ?
 | 
					
 | 
				
			||||||
	.colno db ?
 | 
					vga_lineno db 0
 | 
				
			||||||
}
 | 
					vga_colno db 0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						;; Function: vga_console_clear
 | 
				
			||||||
 | 
					vga_console_clear:
 | 
				
			||||||
 | 
						mov ecx, VGA_COLUMNS*VGA_LINES
 | 
				
			||||||
 | 
						xor al, al
 | 
				
			||||||
 | 
						mov edi, VGA_BASE
 | 
				
			||||||
 | 
						rep stosb
 | 
				
			||||||
 | 
						ret
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										10
									
								
								kernel/init.inc
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								kernel/init.inc
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,10 @@
 | 
				
			||||||
 | 
					struc TSS {
 | 
				
			||||||
 | 
						.link   dw ?
 | 
				
			||||||
 | 
						.link_h dw ?
 | 
				
			||||||
 | 
						.esp0   dd ?
 | 
				
			||||||
 | 
						.ss0    dw ?
 | 
				
			||||||
 | 
						.ss0_h  dw ?
 | 
				
			||||||
 | 
						.esp1   dd ?
 | 
				
			||||||
 | 
						.ss1    dw ?
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -1,4 +1,6 @@
 | 
				
			||||||
	;; File: kernel.asm
 | 
						;; File: kernel.asm
 | 
				
			||||||
 | 
						format binary
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	include 'const.inc'
 | 
						include 'const.inc'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	org KBASE
 | 
						org KBASE
 | 
				
			||||||
| 
						 | 
					@ -9,9 +11,6 @@
 | 
				
			||||||
db 'STPDKRNL'
 | 
					db 'STPDKRNL'
 | 
				
			||||||
db 32 dup(0)
 | 
					db 32 dup(0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	include 'klog.inc'
 | 
					 | 
				
			||||||
	include 'mm/mm.inc'
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	;; Function: kmain
 | 
						;; Function: kmain
 | 
				
			||||||
	;;
 | 
						;;
 | 
				
			||||||
	;; Parameters:
 | 
						;; Parameters:
 | 
				
			||||||
| 
						 | 
					@ -20,24 +19,42 @@ db 32 dup(0)
 | 
				
			||||||
	;;     EBX - Boot structure address
 | 
						;;     EBX - Boot structure address
 | 
				
			||||||
	;;
 | 
						;;
 | 
				
			||||||
kmain:
 | 
					kmain:
 | 
				
			||||||
	xchg bx, bx
 | 
						mov esp, stack_top
 | 
				
			||||||
	mov [0xC03B0000], dword 0x08690948
 | 
						
 | 
				
			||||||
	mov [0xC03B0004], dword 0x05690648
 | 
					 | 
				
			||||||
	; TODO: interupt, vmm
 | 
					 | 
				
			||||||
	cmp eax, STPDBOOT_MAGIC
 | 
						cmp eax, STPDBOOT_MAGIC
 | 
				
			||||||
	jne .halt
 | 
						jne .halt
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						; init memory manager
 | 
				
			||||||
 | 
						; init idt, gdt
 | 
				
			||||||
 | 
						; copy boot structure 
 | 
				
			||||||
 | 
						xchg bx, bx
 | 
				
			||||||
 | 
						call vga_console_clear
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						mov [0xC03B0000], dword 0x08740953
 | 
				
			||||||
 | 
						mov [0xC03B0004], dword 0x05700675
 | 
				
			||||||
 | 
						mov [0xC03B0008], dword 0x03640469
 | 
				
			||||||
 | 
						mov [0xC03B000C], dword 0x0153024F
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	;KLOG_INIT
 | 
						;KLOG_INIT
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	;KLOG "kernel alive"
 | 
						mov esi, szMsgKernelAlive
 | 
				
			||||||
 | 
						call klog
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.halt:
 | 
					.halt:
 | 
				
			||||||
	hlt
 | 
						hlt
 | 
				
			||||||
	jmp $
 | 
						jmp $
 | 
				
			||||||
 | 
					
 | 
				
			||||||
_edata:
 | 
						include 'klog.inc'
 | 
				
			||||||
 | 
						include 'dev/vga_console.inc'
 | 
				
			||||||
 | 
						include 'mm/mm.inc'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	; BSS
 | 
					szMsgKernelAlive db "Kernel is alive", 0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						align 4
 | 
				
			||||||
 | 
					stack_bottom:
 | 
				
			||||||
	rb 0x4000
 | 
						rb 0x4000
 | 
				
			||||||
 | 
					stack_top:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
_end:
 | 
					_end:
 | 
				
			||||||
 | 
						dd 0x0
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,11 +1,92 @@
 | 
				
			||||||
 | 
					CMOS_ADDRESS = 0x70
 | 
				
			||||||
 | 
					CMOS_DATA    = 0x71
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CMOS_REG_SECOND = 0x00
 | 
				
			||||||
 | 
					CMOS_REG_MINUTE = 0x02
 | 
				
			||||||
 | 
					CMOS_REG_HOUR   = 0x04
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					COM1 = 0x3F8
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					klog_print:
 | 
				
			||||||
 | 
						mov dx, COM1
 | 
				
			||||||
 | 
					@@:
 | 
				
			||||||
 | 
						lodsb
 | 
				
			||||||
 | 
						or al, al
 | 
				
			||||||
 | 
						jz @f
 | 
				
			||||||
 | 
						out dx, al
 | 
				
			||||||
 | 
						jmp @b
 | 
				
			||||||
 | 
					@@:
 | 
				
			||||||
 | 
						ret
 | 
				
			||||||
 | 
					
 | 
				
			||||||
klog_print_date:
 | 
					klog_print_date:
 | 
				
			||||||
	clc
 | 
					@@:
 | 
				
			||||||
 | 
						mov al, 0x0A
 | 
				
			||||||
 | 
						out CMOS_ADDRESS, al
 | 
				
			||||||
 | 
						in al, CMOS_DATA
 | 
				
			||||||
 | 
						and al, 0x80
 | 
				
			||||||
 | 
						jnz @b
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						mov al, CMOS_REG_HOUR
 | 
				
			||||||
 | 
						out CMOS_ADDRESS, al
 | 
				
			||||||
 | 
						in al, CMOS_DATA
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						mov ah, al
 | 
				
			||||||
 | 
						shr ah, 4
 | 
				
			||||||
 | 
						and ah, 0xF
 | 
				
			||||||
 | 
						and al, 0xF
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						add ah, 0x30
 | 
				
			||||||
 | 
						add al, 0x30
 | 
				
			||||||
 | 
						mov [szTime + 1], ah
 | 
				
			||||||
 | 
						mov [szTime + 2], al
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						mov al, CMOS_REG_MINUTE
 | 
				
			||||||
 | 
						out CMOS_ADDRESS, al
 | 
				
			||||||
 | 
						in al, CMOS_DATA
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						mov ah, al
 | 
				
			||||||
 | 
						shr ah, 4
 | 
				
			||||||
 | 
						and ah, 0xF
 | 
				
			||||||
 | 
						and al, 0xF
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						add ah, 0x30
 | 
				
			||||||
 | 
						add al, 0x30
 | 
				
			||||||
 | 
						mov [szTime + 4], ah
 | 
				
			||||||
 | 
						mov [szTime + 5], al
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						mov al, CMOS_REG_SECOND
 | 
				
			||||||
 | 
						out CMOS_ADDRESS, al
 | 
				
			||||||
 | 
						in al, CMOS_DATA
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						mov ah, al
 | 
				
			||||||
 | 
						shr ah, 4
 | 
				
			||||||
 | 
						and ah, 0xF
 | 
				
			||||||
 | 
						and al, 0xF
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						add ah, 0x30
 | 
				
			||||||
 | 
						add al, 0x30
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						mov [szTime + 7], ah
 | 
				
			||||||
 | 
						mov [szTime + 8], al
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						push esi
 | 
				
			||||||
 | 
						mov esi, szTime
 | 
				
			||||||
 | 
						call klog_print
 | 
				
			||||||
 | 
						pop esi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ret
 | 
						ret
 | 
				
			||||||
 | 
					
 | 
				
			||||||
macro KLOG_INIT {
 | 
						;; Function: klog
 | 
				
			||||||
}
 | 
						;; Output kernel log
 | 
				
			||||||
 | 
					klog:
 | 
				
			||||||
 | 
						call klog_print_date
 | 
				
			||||||
 | 
					
 | 
				
			||||||
macro KLOG msg {
 | 
						call klog_print
 | 
				
			||||||
	out 0xe9, al
 | 
					
 | 
				
			||||||
}
 | 
						mov esi, szCRLF
 | 
				
			||||||
 | 
						call klog_print
 | 
				
			||||||
 | 
						ret
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					szTime db '[00:00:00] ', 0
 | 
				
			||||||
 | 
					szCRLF db CR, LF, 0
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue