File: bootsect.asm

package info (click to toggle)
libcaca 0.99.beta20-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,540 kB
  • sloc: ansic: 25,091; php: 2,763; python: 2,637; cs: 1,213; cpp: 1,127; java: 916; objc: 836; makefile: 545; perl: 505; sh: 472; asm: 297; ruby: 215; xml: 33
file content (123 lines) | stat: -rw-r--r-- 2,202 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
; Boot sector, freely inspired by http://jojo.ouvaton.org/dossiers/boot_sector/tutorial02.html
; Sets a GDT and protected mode
; Copy the kernel (or stage2) to 0x1000 (linear)
; Max kernel size is 25600 bytes (50 sectors)


%define	BASE	0x100	; 0x0100:0x0 = 0x1000
%define KSIZE	50

[BITS 16]
[ORG 0x0]

; Code starts here, jump to our real entry point, skipping print
jmp start

; print string using BIOS
print:
		push ax
		push bx
	.start:
		lodsb		; ds:si -> al
		cmp al,0
		jz .fin
		mov ah,0x0E	; 0x0e function of BIOS 0x10 interruption
		mov bx,0x07	; bx -> attribute, al -> ascii
		int 0x10
        jmp .start
	
	.fin:
		pop bx
		pop ax
		ret
        
; Entry point
start:
	mov [bootdrv],dl	; boot drive

; Stack and section initialization at 0x07C0
	mov ax,0x07C0
	mov ds,ax
	mov es,ax
	mov ax,0x8000	; stack at 0xFFFF
	mov ss,ax
	mov sp, 0xf000

; print 'Loading kernel ...'
	mov si, ldKernel
	call print

; Load kernel
	xor ax,ax
	int 0x13

	push es
	mov ax,BASE
	mov es,ax
	mov bx,0
	mov ah,2
	mov al,KSIZE
	mov ch,0
	mov cl,2
	mov dh,0
	mov dl,[bootdrv]
	int 0x13
	pop es

; GDT pointer
	mov ax,gdtend	; GDT limit
	mov bx,gdt
	sub ax,bx
	mov word [gdtptr],ax

	xor eax,eax		; GDT linear address
	xor ebx,ebx
	mov ax,ds
	mov ecx,eax
	shl ecx,4
	mov bx,gdt
	add ecx,ebx
	mov dword [gdtptr+2],ecx

; pmode
	cli
	lgdt [gdtptr]	; load GDT
	mov eax, cr0
	or ax,1
	mov cr0,eax		; enter Protected Mode

	jmp next
next:
	mov ax,0x10		; data segment
	mov ds,ax
	mov fs,ax
	mov gs,ax
	mov es,ax
	mov ss,ax
	mov esp,0x9F000	

	jmp dword 0x8:0x1000    ; jump to kernel _start at 0x1000 of 'second' selector (*8)


;--------------------------------------------------------------------
bootdrv: db 0
ldKernel	db	"Loading kernel ...",13,10,0
;--------------------------------------------------------------------
gdt:
	db 0,0,0,0,0,0,0,0
gdt_cs:
	db 0xFF,0xFF,0x0,0x0,0x0,10011011b,11011111b,0x0
gdt_ds:
	db 0xFF,0xFF,0x0,0x0,0x0,10010011b,11011111b,0x0
gdtend:

;--------------------------------------------------------------------
gdtptr:
	dw	0	; limit
	dd	0	; base


;--------------------------------------------------------------------
;; fill remaining space with NOPs
times 510-($-$$) db 144
dw 0xAA55