Compare commits

..

No commits in common. "6bafcf1afa767691846f5288af301943b8017362" and "3d9b2dcfc601b3f035020b1bf61cc9c60592add4" have entirely different histories.

25 changed files with 3781 additions and 5 deletions

2
.gitignore vendored
View file

@ -1,2 +0,0 @@
obj
.gdbinit

View file

@ -47,7 +47,7 @@ CFLAGS := $(CFLAGS) $(DEFS) $(LABDEFS) -O1 -fno-builtin -I$(TOP) -MD
CFLAGS += -fno-omit-frame-pointer CFLAGS += -fno-omit-frame-pointer
CFLAGS += -std=gnu99 CFLAGS += -std=gnu99
CFLAGS += -static CFLAGS += -static
CFLAGS += -Wall -Wno-format -Wno-unused -Werror -m32 CFLAGS += -Wall -Wno-format -Wno-unused -Werror -gstabs -m32
# -fno-tree-ch prevented gcc from sometimes reordering read_ebp() before # -fno-tree-ch prevented gcc from sometimes reordering read_ebp() before
# mon_backtrace()'s function prologue on gcc version: (Debian 4.7.2-5) 4.7.2 # mon_backtrace()'s function prologue on gcc version: (Debian 4.7.2-5) 4.7.2
CFLAGS += -fno-tree-ch CFLAGS += -fno-tree-ch
@ -85,8 +85,8 @@ all:
$(OBJDIR)/lib/%.o $(OBJDIR)/fs/%.o $(OBJDIR)/net/%.o \ $(OBJDIR)/lib/%.o $(OBJDIR)/fs/%.o $(OBJDIR)/net/%.o \
$(OBJDIR)/user/%.o $(OBJDIR)/user/%.o
KERN_CFLAGS := $(CFLAGS) -DJOS_KERNEL KERN_CFLAGS := $(CFLAGS) -DJOS_KERNEL -gstabs
USER_CFLAGS := $(CFLAGS) -DJOS_USER USER_CFLAGS := $(CFLAGS) -DJOS_USER -gstabs
# Update .vars.X if variable X has changed since the last make run. # Update .vars.X if variable X has changed since the last make run.
# #

21
obj/.deps Normal file
View file

@ -0,0 +1,21 @@
obj/kern/init.o: kern/init.c inc/stdio.h inc/stdarg.h inc/string.h \
inc/types.h inc/assert.h kern/monitor.h kern/console.h
obj/kern/entry.o: kern/entry.S inc/mmu.h inc/memlayout.h
obj/kern/readline.o: lib/readline.c inc/stdio.h inc/stdarg.h inc/error.h
obj/boot/main.o: boot/main.c inc/x86.h inc/types.h inc/elf.h
obj/kern/string.o: lib/string.c inc/string.h inc/types.h
obj/kern/printfmt.o: lib/printfmt.c inc/types.h inc/stdio.h inc/stdarg.h \
inc/string.h inc/error.h
obj/boot/boot.o: boot/boot.S inc/mmu.h
obj/kern/console.o: kern/console.c inc/x86.h inc/types.h inc/memlayout.h \
inc/mmu.h inc/kbdreg.h inc/string.h inc/assert.h inc/stdio.h \
inc/stdarg.h kern/console.h
obj/kern/printf.o: kern/printf.c inc/types.h inc/stdio.h inc/stdarg.h
obj/kern/kdebug.o: kern/kdebug.c inc/stab.h inc/types.h inc/string.h \
inc/memlayout.h inc/mmu.h inc/assert.h inc/stdio.h inc/stdarg.h \
kern/kdebug.h
obj/kern/monitor.o: kern/monitor.c inc/stdio.h inc/stdarg.h inc/string.h \
inc/types.h inc/memlayout.h inc/mmu.h inc/assert.h inc/x86.h \
kern/console.h kern/monitor.h kern/kdebug.h
obj/kern/entrypgdir.o: kern/entrypgdir.c inc/mmu.h inc/types.h \
inc/memlayout.h

1
obj/.vars.INIT_CFLAGS Normal file
View file

@ -0,0 +1 @@

1
obj/.vars.KERN_CFLAGS Normal file
View file

@ -0,0 +1 @@
-O1 -fno-builtin -I. -MD -fno-omit-frame-pointer -std=gnu99 -static -Wall -Wno-format -Wno-unused -Werror -gstabs -m32 -fno-tree-ch -fno-pic -fno-pie -fno-stack-protector -DJOS_KERNEL -gstabs

1
obj/.vars.KERN_LDFLAGS Normal file
View file

@ -0,0 +1 @@
-m elf_i386 -T kern/kernel.ld -nostdlib

BIN
obj/boot/boot Executable file

Binary file not shown.

325
obj/boot/boot.asm Normal file
View file

@ -0,0 +1,325 @@
obj/boot/boot.out: file format elf32-i386
Disassembly of section .text:
00007c00 <start>:
.set CR0_PE_ON, 0x1 # protected mode enable flag
.globl start
start:
.code16 # Assemble for 16-bit mode
cli # Disable interrupts
7c00: fa cli
cld # String operations increment
7c01: fc cld
# Set up the important data segment registers (DS, ES, SS).
xorw %ax,%ax # Segment number zero
7c02: 31 c0 xor %eax,%eax
movw %ax,%ds # -> Data Segment
7c04: 8e d8 mov %eax,%ds
movw %ax,%es # -> Extra Segment
7c06: 8e c0 mov %eax,%es
movw %ax,%ss # -> Stack Segment
7c08: 8e d0 mov %eax,%ss
00007c0a <seta20.1>:
# Enable A20:
# For backwards compatibility with the earliest PCs, physical
# address line 20 is tied low, so that addresses higher than
# 1MB wrap around to zero by default. This code undoes this.
seta20.1:
inb $0x64,%al # Wait for not busy
7c0a: e4 64 in $0x64,%al
testb $0x2,%al
7c0c: a8 02 test $0x2,%al
jnz seta20.1
7c0e: 75 fa jne 7c0a <seta20.1>
movb $0xd1,%al # 0xd1 -> port 0x64
7c10: b0 d1 mov $0xd1,%al
outb %al,$0x64
7c12: e6 64 out %al,$0x64
00007c14 <seta20.2>:
seta20.2:
inb $0x64,%al # Wait for not busy
7c14: e4 64 in $0x64,%al
testb $0x2,%al
7c16: a8 02 test $0x2,%al
jnz seta20.2
7c18: 75 fa jne 7c14 <seta20.2>
movb $0xdf,%al # 0xdf -> port 0x60
7c1a: b0 df mov $0xdf,%al
outb %al,$0x60
7c1c: e6 60 out %al,$0x60
# Switch from real to protected mode, using a bootstrap GDT
# and segment translation that makes virtual addresses
# identical to their physical addresses, so that the
# effective memory map does not change during the switch.
lgdt gdtdesc
7c1e: 0f 01 16 lgdtl (%esi)
7c21: 64 7c 0f fs jl 7c33 <protcseg+0x1>
movl %cr0, %eax
7c24: 20 c0 and %al,%al
orl $CR0_PE_ON, %eax
7c26: 66 83 c8 01 or $0x1,%ax
movl %eax, %cr0
7c2a: 0f 22 c0 mov %eax,%cr0
# Jump to next instruction, but in 32-bit code segment.
# Switches processor into 32-bit mode.
ljmp $PROT_MODE_CSEG, $protcseg
7c2d: ea .byte 0xea
7c2e: 32 7c 08 00 xor 0x0(%eax,%ecx,1),%bh
00007c32 <protcseg>:
.code32 # Assemble for 32-bit mode
protcseg:
# Set up the protected-mode data segment registers
movw $PROT_MODE_DSEG, %ax # Our data segment selector
7c32: 66 b8 10 00 mov $0x10,%ax
movw %ax, %ds # -> DS: Data Segment
7c36: 8e d8 mov %eax,%ds
movw %ax, %es # -> ES: Extra Segment
7c38: 8e c0 mov %eax,%es
movw %ax, %fs # -> FS
7c3a: 8e e0 mov %eax,%fs
movw %ax, %gs # -> GS
7c3c: 8e e8 mov %eax,%gs
movw %ax, %ss # -> SS: Stack Segment
7c3e: 8e d0 mov %eax,%ss
# Set up the stack pointer and call into C.
movl $start, %esp
7c40: bc 00 7c 00 00 mov $0x7c00,%esp
call bootmain
7c45: e8 db 00 00 00 call 7d25 <bootmain>
00007c4a <spin>:
# If bootmain returns (it shouldn't), loop.
spin:
jmp spin
7c4a: eb fe jmp 7c4a <spin>
00007c4c <gdt>:
...
7c54: ff (bad)
7c55: ff 00 incl (%eax)
7c57: 00 00 add %al,(%eax)
7c59: 9a cf 00 ff ff 00 00 lcall $0x0,$0xffff00cf
7c60: 00 .byte 0x0
7c61: 92 xchg %eax,%edx
7c62: cf iret
...
00007c64 <gdtdesc>:
7c64: 17 pop %ss
7c65: 00 4c 7c 00 add %cl,0x0(%esp,%edi,2)
...
00007c6a <waitdisk>:
}
}
void
waitdisk(void)
{
7c6a: f3 0f 1e fb endbr32
static inline uint8_t
inb(int port)
{
uint8_t data;
asm volatile("inb %w1,%0" : "=a" (data) : "d" (port));
7c6e: ba f7 01 00 00 mov $0x1f7,%edx
7c73: ec in (%dx),%al
// wait for disk reaady
while ((inb(0x1F7) & 0xC0) != 0x40)
7c74: 83 e0 c0 and $0xffffffc0,%eax
7c77: 3c 40 cmp $0x40,%al
7c79: 75 f8 jne 7c73 <waitdisk+0x9>
/* do nothing */;
}
7c7b: c3 ret
00007c7c <readsect>:
void
readsect(void *dst, uint32_t offset)
{
7c7c: f3 0f 1e fb endbr32
7c80: 55 push %ebp
7c81: 89 e5 mov %esp,%ebp
7c83: 57 push %edi
7c84: 50 push %eax
7c85: 8b 4d 0c mov 0xc(%ebp),%ecx
// wait for disk to be ready
waitdisk();
7c88: e8 dd ff ff ff call 7c6a <waitdisk>
}
static inline void
outb(int port, uint8_t data)
{
asm volatile("outb %0,%w1" : : "a" (data), "d" (port));
7c8d: b0 01 mov $0x1,%al
7c8f: ba f2 01 00 00 mov $0x1f2,%edx
7c94: ee out %al,(%dx)
7c95: ba f3 01 00 00 mov $0x1f3,%edx
7c9a: 89 c8 mov %ecx,%eax
7c9c: ee out %al,(%dx)
outb(0x1F2, 1); // count = 1
outb(0x1F3, offset);
outb(0x1F4, offset >> 8);
7c9d: 89 c8 mov %ecx,%eax
7c9f: ba f4 01 00 00 mov $0x1f4,%edx
7ca4: c1 e8 08 shr $0x8,%eax
7ca7: ee out %al,(%dx)
outb(0x1F5, offset >> 16);
7ca8: 89 c8 mov %ecx,%eax
7caa: ba f5 01 00 00 mov $0x1f5,%edx
7caf: c1 e8 10 shr $0x10,%eax
7cb2: ee out %al,(%dx)
outb(0x1F6, (offset >> 24) | 0xE0);
7cb3: 89 c8 mov %ecx,%eax
7cb5: ba f6 01 00 00 mov $0x1f6,%edx
7cba: c1 e8 18 shr $0x18,%eax
7cbd: 83 c8 e0 or $0xffffffe0,%eax
7cc0: ee out %al,(%dx)
7cc1: b0 20 mov $0x20,%al
7cc3: ba f7 01 00 00 mov $0x1f7,%edx
7cc8: ee out %al,(%dx)
outb(0x1F7, 0x20); // cmd 0x20 - read sectors
// wait for disk to be ready
waitdisk();
7cc9: e8 9c ff ff ff call 7c6a <waitdisk>
asm volatile("cld\n\trepne\n\tinsl"
7cce: 8b 7d 08 mov 0x8(%ebp),%edi
7cd1: b9 80 00 00 00 mov $0x80,%ecx
7cd6: ba f0 01 00 00 mov $0x1f0,%edx
7cdb: fc cld
7cdc: f2 6d repnz insl (%dx),%es:(%edi)
// read a sector
insl(0x1F0, dst, SECTSIZE/4);
}
7cde: 5a pop %edx
7cdf: 5f pop %edi
7ce0: 5d pop %ebp
7ce1: c3 ret
00007ce2 <readseg>:
{
7ce2: f3 0f 1e fb endbr32
7ce6: 55 push %ebp
7ce7: 89 e5 mov %esp,%ebp
7ce9: 57 push %edi
7cea: 56 push %esi
7ceb: 53 push %ebx
7cec: 83 ec 0c sub $0xc,%esp
offset = (offset / SECTSIZE) + 1;
7cef: 8b 7d 10 mov 0x10(%ebp),%edi
{
7cf2: 8b 5d 08 mov 0x8(%ebp),%ebx
end_pa = pa + count;
7cf5: 8b 75 0c mov 0xc(%ebp),%esi
offset = (offset / SECTSIZE) + 1;
7cf8: c1 ef 09 shr $0x9,%edi
end_pa = pa + count;
7cfb: 01 de add %ebx,%esi
offset = (offset / SECTSIZE) + 1;
7cfd: 47 inc %edi
pa &= ~(SECTSIZE - 1);
7cfe: 81 e3 00 fe ff ff and $0xfffffe00,%ebx
while (pa < end_pa) {
7d04: 39 f3 cmp %esi,%ebx
7d06: 73 15 jae 7d1d <readseg+0x3b>
readsect((uint8_t*) pa, offset);
7d08: 50 push %eax
7d09: 50 push %eax
7d0a: 57 push %edi
offset++;
7d0b: 47 inc %edi
readsect((uint8_t*) pa, offset);
7d0c: 53 push %ebx
pa += SECTSIZE;
7d0d: 81 c3 00 02 00 00 add $0x200,%ebx
readsect((uint8_t*) pa, offset);
7d13: e8 64 ff ff ff call 7c7c <readsect>
offset++;
7d18: 83 c4 10 add $0x10,%esp
7d1b: eb e7 jmp 7d04 <readseg+0x22>
}
7d1d: 8d 65 f4 lea -0xc(%ebp),%esp
7d20: 5b pop %ebx
7d21: 5e pop %esi
7d22: 5f pop %edi
7d23: 5d pop %ebp
7d24: c3 ret
00007d25 <bootmain>:
{
7d25: f3 0f 1e fb endbr32
7d29: 55 push %ebp
7d2a: 89 e5 mov %esp,%ebp
7d2c: 56 push %esi
7d2d: 53 push %ebx
readseg((uint32_t) ELFHDR, SECTSIZE*8, 0);
7d2e: 52 push %edx
7d2f: 6a 00 push $0x0
7d31: 68 00 10 00 00 push $0x1000
7d36: 68 00 00 01 00 push $0x10000
7d3b: e8 a2 ff ff ff call 7ce2 <readseg>
if (ELFHDR->e_magic != ELF_MAGIC)
7d40: 83 c4 10 add $0x10,%esp
7d43: 81 3d 00 00 01 00 7f cmpl $0x464c457f,0x10000
7d4a: 45 4c 46
7d4d: 75 38 jne 7d87 <bootmain+0x62>
ph = (struct Proghdr *) ((uint8_t *) ELFHDR + ELFHDR->e_phoff);
7d4f: a1 1c 00 01 00 mov 0x1001c,%eax
eph = ph + ELFHDR->e_phnum;
7d54: 0f b7 35 2c 00 01 00 movzwl 0x1002c,%esi
ph = (struct Proghdr *) ((uint8_t *) ELFHDR + ELFHDR->e_phoff);
7d5b: 8d 98 00 00 01 00 lea 0x10000(%eax),%ebx
eph = ph + ELFHDR->e_phnum;
7d61: c1 e6 05 shl $0x5,%esi
7d64: 01 de add %ebx,%esi
for (; ph < eph; ph++)
7d66: 39 f3 cmp %esi,%ebx
7d68: 73 17 jae 7d81 <bootmain+0x5c>
readseg(ph->p_pa, ph->p_memsz, ph->p_offset);
7d6a: 50 push %eax
for (; ph < eph; ph++)
7d6b: 83 c3 20 add $0x20,%ebx
readseg(ph->p_pa, ph->p_memsz, ph->p_offset);
7d6e: ff 73 e4 pushl -0x1c(%ebx)
7d71: ff 73 f4 pushl -0xc(%ebx)
7d74: ff 73 ec pushl -0x14(%ebx)
7d77: e8 66 ff ff ff call 7ce2 <readseg>
for (; ph < eph; ph++)
7d7c: 83 c4 10 add $0x10,%esp
7d7f: eb e5 jmp 7d66 <bootmain+0x41>
((void (*)(void)) (ELFHDR->e_entry))();
7d81: ff 15 18 00 01 00 call *0x10018
}
static inline void
outw(int port, uint16_t data)
{
asm volatile("outw %0,%w1" : : "a" (data), "d" (port));
7d87: ba 00 8a 00 00 mov $0x8a00,%edx
7d8c: b8 00 8a ff ff mov $0xffff8a00,%eax
7d91: 66 ef out %ax,(%dx)
7d93: b8 00 8e ff ff mov $0xffff8e00,%eax
7d98: 66 ef out %ax,(%dx)
7d9a: eb fe jmp 7d9a <bootmain+0x75>

BIN
obj/boot/boot.o Normal file

Binary file not shown.

BIN
obj/boot/boot.out Executable file

Binary file not shown.

BIN
obj/boot/main.o Normal file

Binary file not shown.

BIN
obj/kern/console.o Normal file

Binary file not shown.

BIN
obj/kern/entry.o Normal file

Binary file not shown.

BIN
obj/kern/entrypgdir.o Normal file

Binary file not shown.

BIN
obj/kern/init.o Normal file

Binary file not shown.

BIN
obj/kern/kdebug.o Normal file

Binary file not shown.

BIN
obj/kern/kernel Executable file

Binary file not shown.

3349
obj/kern/kernel.asm Normal file

File diff suppressed because it is too large Load diff

BIN
obj/kern/kernel.img Normal file

Binary file not shown.

80
obj/kern/kernel.sym Normal file
View file

@ -0,0 +1,80 @@
0010000c T _start
f010000c T entry
f010002f t relocated
f010003e t spin
f0100040 T test_backtrace
f0100098 T i386_init
f01000ee T _panic
f010014b T _warn
f0100189 t serial_proc_data
f01001a7 t cons_intr
f01001e6 t kbd_proc_data
f01002ff t cons_putc
f01004f1 T serial_intr
f0100511 T kbd_intr
f0100527 T cons_getc
f010056d T cons_init
f010067f T cputchar
f0100693 T getchar
f01006a8 T iscons
f01006b2 T mon_help
f01006ee T mon_kerninfo
f0100792 T mon_backtrace
f010079c T monitor
f01008e6 t putch
f01008fd T vcprintf
f0100927 T cprintf
f010093f t stab_binsearch
f0100a34 T debuginfo_eip
f0100c0a t printnum
f0100cb3 t sprintputch
f0100cd4 T printfmt
f0100cf5 T vprintfmt
f0101118 T vsnprintf
f010116a T snprintf
f0101188 T readline
f010126e T strlen
f010128a T strnlen
f01012b1 T strcpy
f01012d7 T strcat
f0101300 T strncpy
f0101331 T strlcpy
f0101370 T strcmp
f010139a T strncmp
f01013d6 T strchr
f01013fb T strfind
f010141b T memset
f0101467 T memmove
f01014cd T memcpy
f01014e7 T memcmp
f0101524 T memfind
f0101545 T strtol
f0101630 T __udivdi3
f0101740 T __umoddi3
f010188d T etext
f0101960 r charcode
f0101980 r togglecode
f0101a80 r shiftcode
f0101d64 r commands
f0101f88 r error_string
f0101fb4 R __STAB_BEGIN__
f010622c R __STAB_END__
f010622d R __STABSTR_BEGIN__
f0107bd7 R __STABSTR_END__
f0108000 D bootstack
f0110000 D bootstacktop
f0110000 D entry_pgdir
f0111000 D entry_pgtable
f0112000 d ctlmap
f0112100 d shiftmap
f0112200 d normalmap
f0112300 B edata
f0112300 b shift.1385
f0112320 b cons
f0112528 b crt_pos
f011252c b crt_buf
f0112530 b addr_6845
f0112534 b serial_exists
f0112540 b buf
f0112940 B end
f0112944 B panicstr

BIN
obj/kern/monitor.o Normal file

Binary file not shown.

BIN
obj/kern/printf.o Normal file

Binary file not shown.

BIN
obj/kern/printfmt.o Normal file

Binary file not shown.

BIN
obj/kern/readline.o Normal file

Binary file not shown.

BIN
obj/kern/string.o Normal file

Binary file not shown.