Browse Source

Preprare for the release

tags/0.0.1
Tu Do 3 years ago
commit
f981dbace9

+ 12203
- 0
Operating_System_From_0_to_1.pdf
File diff suppressed because it is too large
View File


+ 12
- 0
code/chapter7/os/.gdbinit View File

@@ -0,0 +1,12 @@
define hook-stop
# Translate the segment:offset into a physical address
printf "[%4x:%4x] ", $cs, $eip
end
set architecture i8086
layout asm
layout reg
set disassembly-flavor intel
target remote localhost:26000
symbol-file build/os/os
b *0x7c00
b main

+ 26
- 0
code/chapter7/os/Makefile View File

@@ -0,0 +1,26 @@
BUILD_DIR=build
BOOTLOADER=$(BUILD_DIR)/bootloader/bootloader.o
OS=$(BUILD_DIR)/os/sample.o
DISK_IMG=disk.img

all: bootdisk

.PHONY: bootdisk bootloader os

bootloader:
make -C bootloader

os:
make -C os

bootdisk: bootloader os
dd if=/dev/zero of=$(DISK_IMG) bs=512 count=2880
dd conv=notrunc if=$(BOOTLOADER) of=$(DISK_IMG) bs=512 count=1 seek=0
dd conv=notrunc if=$(OS) of=$(DISK_IMG) bs=512 count=1 seek=1

qemu:
qemu-system-i386 -machine q35 -fda $(DISK_IMG) -gdb tcp::26000 -S

clean:
make -C bootloader clean
make -C os clean

+ 12
- 0
code/chapter7/os/bootloader/Makefile View File

@@ -0,0 +1,12 @@
BUILD_DIR=../build/bootloader

BOOTLOADER_SRCS := $(wildcard *.asm)
BOOTLOADER_OBJS := $(patsubst %.asm, $(BUILD_DIR)/%.o, $(BOOTLOADER_SRCS))

all: $(BOOTLOADER_OBJS)

$(BUILD_DIR)/%.o: %.asm
nasm -f bin $< -o $@

clean:
rm $(BUILD_DIR)/*

+ 35
- 0
code/chapter7/os/bootloader/bootloader.asm View File

@@ -0,0 +1,35 @@
;******************************************
; Bootloader.asm
; A Simple Bootloader
;******************************************
bits 16
start: jmp boot

;; constant and variable definitions
msg db "Welcome to My Operating System!", 0ah, 0dh, 0h

boot:
cli ; no interrupts
cld ; all that we need to init

mov ax, 50h

; ;; set the buffer
mov es, ax
xor bx, bx

mov al, 2 ; read 2 sector
mov ch, 0 ; we are reading the second sector past us, so its still on track 0
mov cl, 2 ; sector to read (The second sector)
mov dh, 0 ; head number
mov dl, 0 ; drive number. Remember Drive 0 is floppy drive.

mov ah, 0x02 ; read floppy sector function
int 0x13 ; call BIOS - Read the sector
jmp 0x50:0x0 ; jump and execute the sector!

hlt ; halt the system

; We have to be 512 bytes. Clear the rest of the bytes with 0
times 510 - ($-$$) db 0
dw 0xAA55 ; Boot Signiture

BIN
code/chapter7/os/bootloader/debug.elf View File


BIN
code/chapter7/os/build/bootloader/bootloader.o View File


BIN
code/chapter7/os/build/os/sample.o View File


BIN
code/chapter7/os/disk.img View File


+ 12
- 0
code/chapter7/os/os/Makefile View File

@@ -0,0 +1,12 @@
BUILD_DIR=../build/os

OS_SRCS := $(wildcard *.asm)
OS_OBJS := $(patsubst %.asm, $(BUILD_DIR)/%.o, $(OS_SRCS))

all: $(OS_OBJS)

$(BUILD_DIR)/%.o: %.asm
nasm -f bin $< -o $@

clean:
rm $(BUILD_DIR)/*

+ 6
- 0
code/chapter7/os/os/sample.asm View File

@@ -0,0 +1,6 @@
;******************************************
; sample.asm
; A Sample Program
;******************************************
mov eax, 1
add eax, 1

+ 12
- 0
code/chapter8/os/.gdbinit View File

@@ -0,0 +1,12 @@
define hook-stop
# Translate the segment:offset into a physical address
printf "[%4x:%4x] ", $cs, $eip
end
set architecture i8086
layout asm
layout reg
set disassembly-flavor intel
target remote localhost:26000
symbol-file build/os/os
b *0x7c00
b main

+ 29
- 0
code/chapter8/os/Makefile View File

@@ -0,0 +1,29 @@
BUILD_DIR=build
BOOTLOADER=$(BUILD_DIR)/bootloader/bootloader.o
OS=$(BUILD_DIR)/os/os
DISK_IMG=disk.img

all: bootdisk

.PHONY: bootloader os

bootloader:
make -C bootloader

os:
make -C os

bootdisk: bootloader os
# @echo "size is $(size)"
# @echo "count is $(count)"
dd if=/dev/zero of=$(DISK_IMG) bs=512 count=2880
dd conv=notrunc if=$(BOOTLOADER) of=$(DISK_IMG) bs=512 count=1 seek=0
# dd conv=notrunc if=$(OS) of=$(DISK_IMG) bs=512 count=1 seek=1
dd conv=notrunc if=$(OS) of=$(DISK_IMG) bs=512 count=$$(($(shell stat --printf="%s" $(OS))/512)) seek=1

qemu:
qemu-system-i386 -machine q35 -fda $(DISK_IMG) -gdb tcp::26000 -S

clean:
make -C bootloader clean
make -C os clean

+ 14
- 0
code/chapter8/os/bootloader/Makefile View File

@@ -0,0 +1,14 @@
BUILD_DIR=../build/bootloader

BOOTLOADER_SRCS := $(wildcard *.asm)
BOOTLOADER_OBJS := $(patsubst %.asm, $(BUILD_DIR)/%.o, $(BOOTLOADER_SRCS))

all: $(BOOTLOADER_OBJS)

$(BUILD_DIR)/%.o: %.asm
nasm -f elf $< -F dwarf -g -o $@
ld -m elf_i386 -T bootloader.lds $@ -o $@.elf
objcopy -O binary $(BUILD_DIR)/bootloader.o.elf $@

clean:
rm $(BUILD_DIR)/*

+ 35
- 0
code/chapter8/os/bootloader/bootloader.asm View File

@@ -0,0 +1,35 @@
;******************************************
; Bootloader.asm
; A Simple Bootloader
;******************************************
bits 16
start: jmp boot

;; constant and variable definitions
msg db "Welcome to My Operating System!", 0ah, 0dh, 0h

boot:
cli ; no interrupts
cld ; all that we need to init

mov ax, 50h

; ;; set the buffer
mov es, ax
xor bx, bx

mov al, 17 ; read 2 sector
mov ch, 0 ; we are reading the second sector past us, so its still on track 0
mov cl, 2 ; sector to read (The second sector)
mov dh, 0 ; head number
mov dl, 0 ; drive number. Remember Drive 0 is floppy drive.

mov ah, 0x02 ; read floppy sector function
int 0x13 ; call BIOS - Read the sector
jmp [500h + 0x18] ; jump and execute the sector!

hlt ; halt the system

; We have to be 512 bytes. Clear the rest of the bytes with 0
times 510 - ($-$$) db 0
dw 0xAA55 ; Boot Signiture

BIN
code/chapter8/os/bootloader/bootloader.dbg View File


+ 16
- 0
code/chapter8/os/bootloader/bootloader.lds View File

@@ -0,0 +1,16 @@
OUTPUT(bootloader);

PHDRS
{
headers PT_NULL;
text PT_LOAD FILEHDR PHDRS ;
data PT_LOAD ;
}


SECTIONS
{
. = SIZEOF_HEADERS;
.text 0x7c00: { *(.text) } :text
.data : { *(.data) } :data
}

BIN
code/chapter8/os/build/bootloader/bootloader.elf View File


BIN
code/chapter8/os/build/bootloader/bootloader.o View File


BIN
code/chapter8/os/build/bootloader/bootloader.o.elf View File


BIN
code/chapter8/os/build/disk.img View File


BIN
code/chapter8/os/build/main.o View File


BIN
code/chapter8/os/build/os/main.o View File


BIN
code/chapter8/os/build/os/os View File


BIN
code/chapter8/os/build/os/os.debug View File


BIN
code/chapter8/os/build/os/sample.o View File


BIN
code/chapter8/os/disk.img View File


+ 1
- 0
code/chapter8/os/os/.#os View File

@@ -0,0 +1 @@
tuhdo@vbuntu.1872:1486050267

+ 20
- 0
code/chapter8/os/os/Makefile View File

@@ -0,0 +1,20 @@
BUILD_DIR=../build/os
OS=$(BUILD_DIR)/os

CFLAGS+=-ffreestanding -nostdlib -m32 -gdwarf-4 -ggdb3

OS_SRCS := $(wildcard *.c)
OS_OBJS := $(patsubst %.c, $(BUILD_DIR)/%.o, $(OS_SRCS))

all: $(OS)

$(BUILD_DIR)/%.o: %.c
gcc $(CFLAGS) -m32 -c $< -o $@

$(OS): $(OS_OBJS)
ld -m elf_i386 -nmagic -Tos.lds $(OS_OBJS) -o $@
# objcopy --only-keep-debug $(OS) $(OS).dbg
# strip -g $(OS)

clean:
rm $(BUILD_DIR)/*

BIN
code/chapter8/os/os/main View File


+ 1
- 0
code/chapter8/os/os/main.c View File

@@ -0,0 +1 @@
void main(){}

BIN
code/chapter8/os/os/os View File


+ 15
- 0
code/chapter8/os/os/os.lds View File

@@ -0,0 +1,15 @@
ENTRY(main);

PHDRS
{
headers PT_PHDR FILEHDR PHDRS;
code PT_LOAD;
}

SECTIONS
{
.text 0x600: ALIGN(0x100) { *(.text) } :code
.data : { *(.data) }
.bss : { *(.bss) }
/DISCARD/ : { *(.eh_frame) }
}

+ 6
- 0
code/chapter8/os/os/sample.asm View File

@@ -0,0 +1,6 @@
;******************************************
; sample.asm
; A Sample Program
;******************************************
mov eax, 1
add eax, 1

Loading…
Cancel
Save