Skip to content

Improve build images #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,18 @@ jobs:

- uses: actions/upload-artifact@v2
with:
name: OS Image
path: build/image.vmdk
name: Raw Image
path: build/FuzzyOS.raw

- uses: actions/upload-artifact@v2
with:
name: Virtual Box Image
path: build/FuzzyOS.vdi

- uses: actions/upload-artifact@v2
with:
name: VMWare Image
path: build/FuzzyOS.vmdk

- name: make test
run: make test
Expand Down
28 changes: 23 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ jobs:
utcOffset: "+00:00"

- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -39,13 +38,32 @@ jobs:
prerelease: false
commitish: ${{ github.sha }}

- name: Upload Release Image
- name: Upload Raw Image
uses: actions/upload-release-asset@v1
id: upload-release-image
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: build/image.vmdk
asset_name: image.vmdk
asset_path: build/FuzzyOS.raw
asset_name: FuzzyOS.raw
asset_content_type: application/octet-stream

- name: Upload Virtual Box Image
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: build/FuzzyOS.vdi
asset_name: FuzzyOS.vdi
asset_content_type: application/x-virtualbox-vdi

- name: Upload VMWare Image
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: build/FuzzyOS.vmdk
asset_name: FuzzyOS.vmdk
asset_content_type: application/x-vmdk
23 changes: 18 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,15 @@ BUILD_REALMODE = $(BUILD_DIR)/real_mode
# Files
bt_stage1 = $(BUILD_BOOTLOADER)/stage1
bt_stage2 = $(BUILD_BOOTLOADER)/stage2
image_vmdk = $(BUILD_DIR)/image.vmdk
app_entry = $(BUILD_LIB)/app/entry.out
rm_static = $(BUILD_REALMODE)/static_library

# OS images
image_raw = $(BUILD_DIR)/FuzzyOS.raw
image_vmdk = $(BUILD_DIR)/FuzzyOS.vmdk
image_vdi = $(BUILD_DIR)/FuzzyOS.vdi
ALL_IMAGES = $(image_raw) $(image_vmdk) $(image_vdi)

# Kernel
kernel_core = $(BUILD_DIR)/kernel/core

Expand Down Expand Up @@ -90,10 +95,10 @@ FLAT_FROM_ELF=objcopy -O binary
# Targets
all_artifacts: images binaries external

test: $(image_vmdk) $(wildcard tests/**/*)
test: images $(wildcard tests/**/*)
bash tests/run.sh

images: $(image_vmdk)
images: $(ALL_IMAGES)

binaries: $(bt_stage1) $(bt_stage2) $(kernel_core) $(rm_static)

Expand All @@ -102,22 +107,29 @@ binaries: $(bt_stage1) $(bt_stage2) $(kernel_core) $(rm_static)
SECTOR_COUNT_BT_STAGE1 = 1
SECTOR_COUNT_SHARED_LIBRARY = 1
SECTOR_COUNT_BT_STAGE2 = 12
SECTOR_COUNT_KERNEL = 70
SECTOR_COUNT_KERNEL = 75

SECTOR_START_BT_STAGE1 = 0
SECTOR_START_SHARED_LIBRARY = $(shell expr $(SECTOR_START_BT_STAGE1) + $(SECTOR_COUNT_BT_STAGE1) )
SECTOR_START_BT_STAGE2 = $(shell expr $(SECTOR_START_SHARED_LIBRARY) + $(SECTOR_COUNT_SHARED_LIBRARY) )
SECTOR_START_KERNEL = $(shell expr $(SECTOR_START_BT_STAGE2) + $(SECTOR_COUNT_BT_STAGE2) )

$(image_vmdk): $(bt_stage1) $(rm_static) $(bt_stage2) $(kernel_core) $(BUILD_DIR)/external/bin/mbr_builder $(MINIMAL_DISK)
$(image_raw): $(bt_stage1) $(rm_static) $(bt_stage2) $(kernel_core) $(BUILD_DIR)/external/bin/mbr_builder $(MINIMAL_DISK)
bash scripts/build_image.sh $(BUILD_DIR)/temp_vmdk \
$(bt_stage1) $(SECTOR_COUNT_BT_STAGE1) \
$(rm_static) $(SECTOR_COUNT_SHARED_LIBRARY) \
$(bt_stage2) $(SECTOR_COUNT_BT_STAGE2) \
$(kernel_core) $(SECTOR_COUNT_KERNEL)
./$(BUILD_DIR)/external/bin/mbr_builder $@ $(BUILD_DIR)/temp_vmdk $(MINIMAL_DISK)
truncate --size=128M $@ # sparse file
@echo "Image Size : $$(stat -c %s $@) byte(s)"

$(image_vmdk): $(image_raw)
qemu-img convert -O vmdk $< $@

$(image_vdi): $(image_raw)
qemu-img convert -O vdi $< $@

clean:
rm -r $(BUILD_DIR)/ || echo "Build directory is clean."

Expand All @@ -137,6 +149,7 @@ include $(SRC_KERNEL)/syscall/Makefile.mk
include $(SRC_DRIVERS)/disk/Makefile.mk
include $(SRC_DRIVERS)/keyboard/Makefile.mk
include $(SRC_DRIVERS)/pic/Makefile.mk
include $(SRC_DRIVERS)/ps2/Makefile.mk
include $(SRC_DRIVERS)/display/Makefile.mk
include $(SRC_DRIVERS)/display/vga/Makefile.mk

Expand Down
18 changes: 6 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,25 @@ fork() | TicTacToe game
----------------|---------------
![image](https://user-images.githubusercontent.com/9819066/132112808-72ba7691-5f18-4631-b95d-fa52a63d2f38.png) | ![image](https://user-images.githubusercontent.com/9819066/129463802-d9a0bc77-74eb-4438-b553-e1439ada95a1.png)

| pingpong game |
| pingpong game |
| ------------- |
| ![image](https://user-images.githubusercontent.com/9819066/132931019-eee2deca-ed31-4f7a-88ac-1d7754e7683e.png) |


### Boot OS

#### How to get boot image?
- Download image from one of the [Release](#Release).
- Or directly build image using `make images` after cloning the repository.

#### Boot on VirtualBox
- Create VM with `FuzzyOS.vdi` as storage.

#### Boot on VMware
- Create *Virtual Machine Disk* with fixed size of *4MB*.
- Burn `image.vmdk` to `new-disk-flat.vmdk`
- `bash scripts/burn.sh /path/to/image.vmdk /path/to/build/new-disk-flat.vmdk`
- Or simply replace `new-disk-flat.vmdk` with a sym-link to `build/image.vmdk` (for rapid development :grin:)
- Create VM with `FuzzyOS.vmdk` as storage.

##### Boot on a real machine
- Use `dd` or `scripts/burn.sh` to burn image into the disk (potentially destructive).
- `bash scripts/burn.sh build/image.vmdk /path/to/devicefile`

###### If boot from Flash Drive doesn't work
- Try formatting device MBR with a FAT partition.
- And then burn the image again.

- `bash scripts/burn.sh build/FuzzyOS.raw /path/to/devicefile`

### Development

Expand Down
8 changes: 4 additions & 4 deletions emulator/Makefile.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ QEMU_GDB_PORT=9000
QEMU_MONITOR_PORT=55555
GDB_EX=echo Use GDB_EX="<command>" to execute command on connect.\n

qemu: $(image_vmdk)
qemu: $(image_raw)
qemu-system-x86_64 -smp 1 -m 128M -hda $< $(QEMU_SHUT_FLAGS) $(QEMU_EXTRA_FLAGS)

qemu_vvv: $(image_vmdk)
qemu_vvv: $(image_raw)
qemu-system-x86_64 -smp 1 -m 128M -hda $< $(QEMU_SHUT_FLAGS) $(QEMU_EXTRA_FLAGS) -d cpu,exec,in_asm

qemu_monitor: $(image_vmdk)
qemu_monitor: $(image_raw)
qemu-system-x86_64 -smp 1 -m 128M -hda $< $(QEMU_SHUT_FLAGS) $(QEMU_EXTRA_FLAGS) -monitor telnet:127.0.0.1:$(QEMU_MONITOR_PORT),server,nowait

qemu_debug: $(image_vmdk)
qemu_debug: $(image_raw)
qemu-system-x86_64 -S -gdb tcp::$(QEMU_GDB_PORT) -smp 1 -m 128M -hda $< $(QEMU_SHUT_FLAGS) -d cpu,exec,in_asm

qemu_debug_connect:
Expand Down
5 changes: 5 additions & 0 deletions include/fuzzy/drivers/port.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
#define PORT_PIT_DATA2 0x42
#define PORT_PIT_CMD 0x43

#define PORT_PS2_DATA 0x60
#define PORT_PS2_CMD 0x64
#define PORT_PS2_STATUS 0x64


static inline void outb(uint16_t port, uint8_t data) {
__asm__ volatile(
"outb %0, %1 \n"
Expand Down
8 changes: 8 additions & 0 deletions include/fuzzy/drivers/ps2/keyboard.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once


void ps2_keyboard_init();

char ps2_keyboard_get_key_pressed_blocking();
char ps2_keyboard_get_key_pressed_poll();
int ps2_keyboard_get_kbhit();
15 changes: 15 additions & 0 deletions include/fuzzy/drivers/ps2/ps2.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

#include <stddef.h>

void ps2_init();

uint8_t ps2_read_data();
void ps2_write_port1(uint8_t byte);
void ps2_controller_wait_for_empty_input();
void ps2_controller_wait_for_full_output();

void interrupt_register_0x21_0x2C_irq1_ir12_keyboard_mouse();
void irq1_handler();
void irq12_handler();

4 changes: 3 additions & 1 deletion include/fuzzy/kernel/interrupts/interrupts.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
#define IDT_IRQ_OFFSET 0x20

// Used by /usr/lib/process.c
#define IDT_IRQ0_PIC (IDT_IRQ_OFFSET+0)
#define IDT_IRQ0_PIC (IDT_IRQ_OFFSET+0)
#define IDT_IRQ1_KEYBOARD (IDT_IRQ_OFFSET+1)
#define IDT_IRQ12_MOUSE (IDT_IRQ_OFFSET+12)
// Used by /usr/lib/sys/syscall.asm
#define IDT_SYSCALL 0x32

Expand Down
8 changes: 5 additions & 3 deletions include/fuzzy/memmgr/tables/gdt.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ struct GDTEntry {
};
#pragma pack(pop)

#define GDT_ENTRY_FLAG_32_BIT_SELECTOR 1

#define GDT_NULL_CS (GDT_STD_SELECTOR_NULL*sizeof(struct GDTEntry))
#define GDT_KERNEL_CS (GDT_STD_SELECTOR_KERNEL_CS*sizeof(struct GDTEntry))
#define GDT_KERNEL_DS (GDT_STD_SELECTOR_KERNEL_DS*sizeof(struct GDTEntry))
Expand All @@ -41,7 +43,7 @@ int get_gdt_baseaddress(struct GDTEntry gdt_table[], unsigned int table_size, in

void populate_gdt_entry(struct GDTEntry *entry,
unsigned int base,
unsigned int limit, // 20 bits
unsigned char flags, // 4 bits
unsigned char access_byte
unsigned int limit, // 32 bit with 4k granularity
unsigned char access_byte,
int is_32_bit_selector
);
4 changes: 2 additions & 2 deletions src/drivers/disk/disk.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ static int load_sector_via_reallibrary_data(
unsigned int lba,
unsigned char count) {
// assumes count <= 128
int es = (MEMORY_REALLIBRARY_DATA_ADDRESS&0xF0000)>>4;
int es_address = MEMORY_REALLIBRARY_DATA_ADDRESS&0xFFFF;
int es = (MEMORY_REALLIBRARY_DATA_ADDRESS&0xFFFF0)>>4;
int es_address = MEMORY_REALLIBRARY_DATA_ADDRESS&0x000F;
int cylinder_head = (lba/63);
int sector_index = lba%63 + 1;
// https://en.wikipedia.org/wiki/INT_13H#INT_13h_AH=02h:_Read_Sectors_From_Drive
Expand Down
4 changes: 2 additions & 2 deletions src/drivers/disk/disk_16.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ int load_sectors(unsigned int full_address,
unsigned int count) {
// we don't expect disk_16 (used by bootloader) to load more than 255 sectors.

int es = (full_address&0xF0000)>>4;
int es_address = full_address&0xFFFF;
int es = (full_address&0xFFFF0)>>4;
int es_address = full_address&0x000F;
int cylinder_head = (lba/63);
int sector_index = lba%63 + 1;
// https://en.wikipedia.org/wiki/INT_13H#INT_13h_AH=02h:_Read_Sectors_From_Drive
Expand Down
Loading