kernel: relocate to HMA if available
This commit is contained in:
		
							parent
							
								
									fa6e624604
								
							
						
					
					
						commit
						517c156c3d
					
				
					 3 changed files with 45 additions and 41 deletions
				
			
		
							
								
								
									
										32
									
								
								kernel/hma.asm
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								kernel/hma.asm
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,32 @@ | |||
| ; Code related to memory segment from 0xFFFF0 - 0x10FFEF | ||||
| 
 | ||||
| ; Check if 0000:0000 and FFFF:0010 point to the same memory | ||||
| ; ZF=1 when A20 disabled and HMA unusable | ||||
| ; ZF=0 when A20 enabled | ||||
| a20_enabled: | ||||
|   mov ax, 0x0000 | ||||
|   mov ds, ax | ||||
|   mov si, ax | ||||
|   mov ax, 0xFFFF | ||||
|   mov di, 0x0010 | ||||
|   mov cx, 0x0200 | ||||
|   repe cmpsw | ||||
|   ret | ||||
| 
 | ||||
| ; Relocate kernel code to HMA | ||||
| hma_relocate: | ||||
|   call a20_enabled | ||||
|   ; TODO: talk to hw to enable a20 | ||||
|   jz .end | ||||
|   mov ax, cs | ||||
|   mov ds, ax | ||||
|   mov si, 0x0010 | ||||
|   mov ax, 0xFFFF | ||||
|   mov es, ax ; new code segment | ||||
|   mov ss, ax ; new stack segment | ||||
|   mov di, 0x0010 | ||||
|   mov cx, 0x7FF8 ; 0xFFF0 divided by 2 | ||||
|   repe movsw | ||||
|   jmp 0xFFFF:.end | ||||
| .end: | ||||
|   ret | ||||
|  | @ -14,10 +14,10 @@ ivt_backup: | |||
| 
 | ||||
| ; set item in interrupt vector table | ||||
| ; in:	bx	interrupt number | ||||
| ;	ds:dx	new handler address | ||||
| ;	cs:dx	new handler address | ||||
| ivt_set: | ||||
|   push es | ||||
|   push ax | ||||
|   push es | ||||
| 
 | ||||
|   xor ax,ax | ||||
|   mov es,ax | ||||
|  | @ -28,6 +28,6 @@ ivt_set: | |||
|   mov [es:bx], dx | ||||
|   mov [es:bx+2], cs | ||||
| 
 | ||||
|   pop ax | ||||
|   pop es | ||||
|   pop ax | ||||
|   ret | ||||
|  |  | |||
|  | @ -4,55 +4,27 @@ org 0x0000 | |||
| 
 | ||||
| _startup: | ||||
|   mov ax, cs | ||||
|   mov ds, ax | ||||
|   mov es, ax | ||||
|   mov ss, ax | ||||
|   mov sp, 0x0000 | ||||
|   ; <0x0010 is BIOS segment when relocated to HMA | ||||
|   ; so we need a nop sled | ||||
|   times (0x10 - ($-$$)) nop | ||||
| main: | ||||
|   xor ax, ax | ||||
|   mov ds, ax | ||||
|   mov si, ax | ||||
|   mov cx, ax | ||||
| 
 | ||||
|   call debug_init | ||||
|   int 0x2E | ||||
| 
 | ||||
|   call hma_relocate | ||||
|   call ivt_backup | ||||
|   call debug_init | ||||
| 
 | ||||
|   xor ax, ax | ||||
|   mov ds, ax | ||||
|   mov es, ax | ||||
|   xor cx, cx | ||||
|   mov si, ax | ||||
| .loop: | ||||
|   mov ax, cx | ||||
|   call kprint8 | ||||
|   mov al, '=' | ||||
|   call kputc | ||||
|   lodsw | ||||
|   xchg ax, dx | ||||
|   lodsw | ||||
|   int 0x2E | ||||
|   mov ax,0x1234 | ||||
|   int 0x2E | ||||
|   call kprint16 | ||||
|   mov al, ':' | ||||
|   call kputc | ||||
|   xchg ax, dx | ||||
|   call kprint16 | ||||
|   mov al, ' ' | ||||
|   call kputc | ||||
|   inc cx | ||||
|   test cx, 0x0003 | ||||
|   jnz .loop | ||||
|   mov al, 0x0A | ||||
|   call kputc | ||||
|   mov al, 0x0D | ||||
|   call kputc | ||||
|   cmp cx, 0x0060 | ||||
|   jl .loop | ||||
| 
 | ||||
| .halt: | ||||
|   hlt | ||||
|   jmp .halt | ||||
| 
 | ||||
| %include "hma.asm" | ||||
| 
 | ||||
| %include "heap.asm" | ||||
| %include "intr.asm" | ||||
| %include "debug.asm" | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue