Skip to content

Commit c93b465

Browse files
committed
update makefile
1 parent 6e105a0 commit c93b465

File tree

7 files changed

+30
-19
lines changed

7 files changed

+30
-19
lines changed

Makefile

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
CC = gcc
22
ASM = nasm
3+
LD = ld
34

45
all: os-image
56

67
run: all
7-
qemu-system-x86_64 os-image
8+
qemu-system-x86_64 -fda os-image
89

910
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 $@
1115

1216
bootstrap.bin: bootstrap.asm
1317
$(ASM) $< -f bin -o $@
1418

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
1721

1822
os-image: bootstrap.bin kernel.bin
1923
cat $^ > $@

b

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
floppya: 1_44=os-image , status=inserted
2+
boot: a

bootstrap.asm

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[org 0x7C00]
1+
org 0x7C00
22

33
KERNEL_OFFSET equ 0x1000 ; offset to reach main func in kernel.c
44

@@ -29,20 +29,18 @@ load_kernel:
2929
call print_string
3030

3131
mov bx, KERNEL_OFFSET ; destination
32-
mov dh, 6 ; 6 sectors of drive
32+
mov dh, 2 ; 2 sectors of drive
3333
mov dl, [BOOT_DRIVE]
3434
call disk_load
3535

3636
ret
3737

3838
[bits 32]
39-
;extern main
4039

4140
BEGIN_PM:
4241
mov ebx, MSG_PROT_MODE
4342
call print_string_pm
4443

45-
;call main
4644
jmp KERNEL_OFFSET
4745

4846
jmp $

gdt.asm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ gdt_code:
88
; 1st flags: (present)1 (privilege)00 (descr type)1 -> 1001b
99
; type flags: (code)1 (conforming)0 (readable)1 (accessed)0 -> 1010b
1010
; 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
1212
dw 0x0 ; Base 0-15
1313
db 0x0 ; Base 16-23
1414
db 10011010b ; 1st flag, type flag
@@ -17,7 +17,7 @@ gdt_code:
1717

1818
gdt_data:
1919
;type flags: (code)0 (expand down)0 (writable)1 (accessed)0 -> 0010b
20-
dw 0xfffff
20+
dw 0xffff
2121
dw 0x0
2222
dw 0x0
2323
db 10010010b

kernel.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
void main() {
2-
char* video_memory = (char*) 0xB8000;
1+
void kernel() {
2+
char* video_memory = (char*) 0xb8000;
33
*video_memory = 'X';
44
}

kernel_entry.asm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[bits 32]
2+
[extern kernel]
3+
call kernel
4+
jmp $

switch_to_32.asm

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,19 @@ switch_to_32:
88
or eax, 0x1
99
mov cr0, eax
1010

11-
jmp init_pm
11+
jmp CODE_SEG:init_pm
1212

1313
[bits 32]
1414
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
2124

2225
mov ebp, 0x90000
2326
mov esp, ebp

0 commit comments

Comments
 (0)