Skip to content

Commit 92ff191

Browse files
committed
lesson 23, steps 1 and 2
1 parent 0134c56 commit 92ff191

File tree

4 files changed

+54
-6
lines changed

4 files changed

+54
-6
lines changed

23-fixes/Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ OBJ = ${C_SOURCES:.c=.o cpu/interrupt.o}
77
CC = /usr/local/i386elfgcc/bin/i386-elf-gcc
88
GDB = /usr/local/i386elfgcc/bin/i386-elf-gdb
99
# -g: Use debugging symbols in gcc
10-
CFLAGS = -g -m32 -nostdlib -nostdinc -fno-builtin -fno-stack-protector -nostartfiles -nodefaultlibs \
11-
-Wall -Wextra -Werror
10+
CFLAGS = -g -ffreestanding -Wall -Wextra -fno-exceptions
1211

1312
# First rule is run by default
1413
os-image.bin: boot/bootsect.bin kernel.bin

23-fixes/README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,50 @@ JamesM's tutorial](http://wiki.osdev.org/James_Molloy%27s_Tutorial_Known_Bugs).
77
Since we followed his tutorial for lessons 18-22 (interrupts through malloc), we'll
88
need to make sure we fix any of the issues before moving on.
99

10+
1. Wrong CFLAGS
11+
---------------
12+
13+
We add `-ffreestanding` when compiling `.o` files, which includes `kernel_entry.o` and thus
14+
`kernel.bin` and `os-image.bin`.
15+
16+
Before, we disabled libgcc (not libc) through the use of `-nostdlib` and we didn't re-enable
17+
it for linking. Since this is tricky, we'll delete `-nostdlib`
18+
19+
20+
2. Not setting a stack
21+
----------------------
22+
23+
24+
25+
3. kernel.c `main()` function
26+
-----------------------------
27+
28+
Modify `kernel/kernel.c` and change `main()` to `kernel_main()` since gcc recognizes "main" as
29+
a special keyword and we don't want to mess with that.
30+
31+
Change `boot/kernel_entry.asm` to point to the new name accordingly.
32+
33+
To fix the `i386-elf-ld: warning: cannot find entry symbol _start; defaulting to 0000000000001000`
34+
warning message, add a `global _start;` and define the `_start:` label in `boot/kernel_entry.asm`.
35+
36+
4. Reinvented datatypes
37+
-----------------------
38+
<stddef.h> to provide size\_t
39+
40+
41+
42+
5. Missing functions
43+
--------------------
44+
45+
6. Interrupt handlers
46+
---------------------
47+
- also cli, sti in interrupt handlers
48+
49+
50+
7. Structs and attributes
51+
-------------------------
52+
53+
8. Improperly aligned `kmalloc`
54+
-------------------------------
55+
1056

23-fixes/boot/kernel_entry.asm

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
global _start;
12
[bits 32]
2-
[extern main] ; Define calling point. Must have same name as kernel.c 'main' function
3-
call main ; Calls the C function. The linker will know where it is placed in memory
4-
jmp $
3+
4+
_start:
5+
[extern kernel_main] ; Define calling point. Must have same name as kernel.c 'main' function
6+
call kernel_main ; Calls the C function. The linker will know where it is placed in memory
7+
jmp $

23-fixes/kernel/kernel.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "../libc/string.h"
55
#include "../libc/mem.h"
66

7-
void main() {
7+
void kernel_main() {
88
isr_install();
99
irq_install();
1010

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy