File tree Expand file tree Collapse file tree 7 files changed +30
-19
lines changed Expand file tree Collapse file tree 7 files changed +30
-19
lines changed Original file line number Diff line number Diff line change 1
1
CC = gcc
2
2
ASM = nasm
3
+ LD = ld
3
4
4
5
all : os-image
5
6
6
7
run : all
7
- qemu-system-x86_64 os-image
8
+ qemu-system-x86_64 -fda os-image
8
9
9
10
kernel.o : kernel.c
10
- $(CC ) -ffreestanding -c $< -o $@
11
+ $(CC ) -fno-pie -m32 -ffreestanding -c $< -o $@
12
+
13
+ kernel_entry.o : kernel_entry.asm
14
+ $(ASM ) $< -f elf -o $@
11
15
12
16
bootstrap.bin : bootstrap.asm
13
17
$(ASM ) $< -f bin -o $@
14
18
15
- kernel.bin : kernel.o
16
- $(LD ) -o $@ -Ttext 0x1000 $^ --oformat binary
19
+ kernel.bin : kernel_entry.o kernel.o
20
+ $(LD ) -m elf_i386 - o $@ -Ttext 0x1000 $^ --oformat binary
17
21
18
22
os-image : bootstrap.bin kernel.bin
19
23
cat $^ > $@
Original file line number Diff line number Diff line change
1
+ floppya: 1_44=os-image , status=inserted
2
+ boot: a
Original file line number Diff line number Diff line change 1
- [ org 0x7C00]
1
+ org 0x7C00
2
2
3
3
KERNEL_OFFSET equ 0x1000 ; offset to reach main func in kernel.c
4
4
@@ -29,20 +29,18 @@ load_kernel:
29
29
call print_string
30
30
31
31
mov bx , KERNEL_OFFSET ; destination
32
- mov dh , 6 ; 6 sectors of drive
32
+ mov dh , 2 ; 2 sectors of drive
33
33
mov dl , [ BOOT_DRIVE ]
34
34
call disk_load
35
35
36
36
ret
37
37
38
38
[bits 32]
39
- ;extern main
40
39
41
40
BEGIN_PM:
42
41
mov ebx , MSG_PROT_MODE
43
42
call print_string_pm
44
43
45
- ;call main
46
44
jmp KERNEL_OFFSET
47
45
48
46
jmp $
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ gdt_code:
8
8
; 1st flags: (present)1 (privilege)00 (descr type)1 -> 1001b
9
9
; type flags: (code)1 (conforming)0 (readable)1 (accessed)0 -> 1010b
10
10
; 2nd flags: (granularity)1 (32-bit default)1 (64-bit seg)0 (AVL)0 -> 1100b
11
- dw 0xfffff ; Limit 0-15
11
+ dw 0xffff ; Limit 0-15
12
12
dw 0x0 ; Base 0-15
13
13
db 0x0 ; Base 16-23
14
14
db 10011010b ; 1st flag, type flag
@@ -17,7 +17,7 @@ gdt_code:
17
17
18
18
gdt_data:
19
19
;type flags: (code)0 (expand down)0 (writable)1 (accessed)0 -> 0010b
20
- dw 0xfffff
20
+ dw 0xffff
21
21
dw 0x0
22
22
dw 0x0
23
23
db 10010010b
Original file line number Diff line number Diff line change 1
- void main () {
2
- char * video_memory = (char * ) 0xB8000 ;
1
+ void kernel () {
2
+ char * video_memory = (char * ) 0xb8000 ;
3
3
* video_memory = 'X' ;
4
4
}
Original file line number Diff line number Diff line change
1
+ [bits 32]
2
+ [extern kernel]
3
+ call kernel
4
+ jmp $
Original file line number Diff line number Diff line change @@ -8,16 +8,19 @@ switch_to_32:
8
8
or eax , 0x1
9
9
mov cr0 , eax
10
10
11
- jmp init_pm
11
+ jmp CODE_SEG: init_pm
12
12
13
13
[bits 32]
14
14
init_pm:
15
- mov ax , DATA_SEG
16
- mov ds , ax
17
- mov ss , ax
18
- mov es , ax
19
- mov fs , ax
20
- mov gs , ax
15
+ ;inc eax
16
+ ;jmp $
17
+ mov ecx , DATA_SEG
18
+ ;jmp $
19
+ mov ds , ecx
20
+ mov ss , ecx
21
+ mov es , ecx
22
+ mov fs , ecx
23
+ mov gs , ecx
21
24
22
25
mov ebp , 0x90000
23
26
mov esp , ebp
You can’t perform that action at this time.
0 commit comments