ncloader  0.1
 모두 데이타 구조 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 매크로 그룹들 페이지들
Stage 2 Boot Loader

시스템을 초기화 하고 커널을 로딩한다. 더 자세히 ...

+ Stage 2 Boot Loader에 대한 협력 다이어그램:

모듈

 x86
 Stage 2 for x86.
 
 Executable File Format
 
 Filesystem
 파일 시스템
 
 프로세스(쓰레드)
 NCLoader 는 커널 쓰레드만 지원한다.
 
 메모리
 
 Device
 외부 장치로의 입출력을 위한 공통된 디바이스 인터페이스를 정의한다.
 
 Test functions
 
 Configuration manager
 
 이중 연결 리스트
 Linux kenrel 에서 가져온 List 관리 함수들의 구현체
 

함수

void ncloader_entry (void)
 두번째 스테이지 Loader 의 시작 함수 더 자세히 ...
 

상세한 설명

시스템을 초기화 하고 커널을 로딩한다.

; Stage2 의 진입 함수 ; ; Dummy GDT 를 준비한 후 Protected Mode 를 Toggle On 시킨다. ; 0xe820 service 를 이용해 MRD 를 읽어 둔다. ; ; Memory Range Descriptors ; ;

; ; ;

;
bits 16
SECTION .init
; This label is not for exporting, Just I want to get rid of warnings of ld.
GLOBAL entry
entry:
;
; Set the keyboard repeat rate to the max
mov ax, 0x0305
xor bx, bx
int 0x16
;
; Get the memory from the ACPI (E820h) services
mov dword [KERNEL_ARGUMENT], 0
xor ebx, ebx ; Continuation
mov es, ebx ; ES
mov edi, KERNEL_ARGUMENT + 4 ; DI (ES:DI) location of storing data
mov ecx, 20 ; Buffer size, 20 bytes
mov edx, 0x534d4150 ; Signature
e820_get_desc:
mov eax, 0x0000E820 ; function ID
clc ; Clear carry flag
int 0x15 ; Invoke interrupt 0x15
jc e820_error ; Check the carry flag
cmp eax, 0x534d4150 ; Check the signature
jne e820_error
cmp ecx, 20 ; Check the minimum size of descriptor
jl no_e820
add edi, ecx ; Move pointer to next
cmp edi, E820_BOUND ; Compare the boundary of memory for descriptors
jge e820_overflow
inc dword [KERNEL_ARGUMENT]
cmp ebx, 0 ; Check the continuation value
jne e820_get_desc
;
;
; Load global descriptor table
cli
lgdt [gdt_ptr]
; Change the CPU mode to protected
mov eax, cr0
or al, 1 ; Toggle PE bit
mov cr0, eax
;
;
; Now we got the code descripor and its selector,
; so we use it now through FAR jump
;
e820_error:
push e820_error_msg
call print
add sp, 2
jmp $
e820_overflow:
push e820_overflow_msg
call print
add sp, 2
jmp $
no_e820:
push no_e820_msg
call print
add sp, 2
jmp $
print:
push bp
mov bp, sp
pusha
mov si, [bp+4] ; si : address of string
cld ; direction forward
print_loop:
lodsb ; next character - ds:si
cmp al, 0
je print_done
mov ah, 0x0E
mov bx, 0x0007
int 0x10
jmp print_loop
print_done:
popa
pop bp
ret
e820_error_msg db 'E820-Error',0x0
e820_overflow_msg db 'E820-Overflow',0x0
e820_read_msg db 'E820-Read', 0x0
no_e820_msg db 'No E820', 0x0
;
bits 32
SECTION .data
; GDT Pointer
GLOBAL gdt_ptr
gdt_ptr equ $
dw end_gdt - begin_gdt - 1
dd begin_gdt
; Start of GDT
; GLOBAL begin_gdt
begin_gdt equ $
dd 0x00000000
dd 0x00000000 ; NULL Descriptor
; GLOBAL kernel_cs
kernel_cs equ $-begin_gdt
dw 0xFFFF
dw 0x0000
db 0x00
db 0x9A
db 0xCF
db 0x00
; GLOBAL kernel_ds
kernel_ds equ $-begin_gdt
dw 0xFFFF
dw 0x0000
db 0x00
db 0x92
db 0xCF
db 0x00
; GLOBAL kernel_ss
kernel_ss equ $-begin_gdt
dw 0xFFFF
dw 0x0000
db 0x00
db 0x92
db 0xCF
db 0x00
end_gdt equ $
; End of GDT
;
;
SECTION .text
GLOBAL entry32
entry32:
mov eax, kernel_ds
mov ds, eax
mov es, eax
mov fs, eax
mov gs, eax
mov eax, kernel_ss
mov ss, eax
mov esp, KTHREAD_MAIN_ESP ; I have to initialize the stack pointer
mov ebp, esp ; Base stack pointer
;
;

;

작성자
Sung-jae Park nices.nosp@m.j@ni.nosp@m.cesj..nosp@m.com
날짜
2011-8-1

NC Kernel 을 로딩하기 위해 설계 아키텍쳐 독립적인 boot loader 의 인터페이스를 정의하고, 정의된 인터페이스에 맞추어 x86 용을 구현된다.

함수 문서화

__NORET void ncloader_entry ( void  )

두번째 스테이지 Loader 의 시작 함수

이 함수는 첫번째 스테이지 Loader 에 의해 호출된다. 새로운 Main 쓰레드를 생성한 후, Main 쓰레드로 Context switching 을 한다. 이 함수는 Return 되지 않는다.

반환값
void return 되지 않음
주의
아키텍쳐 의존적인 것들을 초기화 한다. (특히 CPU)
arch_switch_to_thread 함수는 인터럽트를 활성화 시킨다.
이 부분은 실행되지 않는다.

+ 이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.: