aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt2
-rwxr-xr-xrun7
-rw-r--r--src/entry.asm7
-rw-r--r--src/link.ld28
-rw-r--r--src/main.c34
5 files changed, 12 insertions, 66 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f56ef51..524c679 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -32,7 +32,7 @@ file(GLOB_RECURSE apps_sources apps/*.c)
# MELVIX
add_executable(melvix ${sources})
-set_target_properties(melvix PROPERTIES OUTPUT_NAME "${CMAKE_CURRENT_SOURCE_DIR}/build/melvix.bin")
+set_target_properties(melvix PROPERTIES OUTPUT_NAME "${CMAKE_CURRENT_SOURCE_DIR}/build/melvix.o")
target_link_libraries(melvix PRIVATE "-Ttext 0x0050000")
# APPS
diff --git a/run b/run
index 2cd64c1..8a53630 100755
--- a/run
+++ b/run
@@ -89,7 +89,7 @@ make_cross() {
}
make_build() {
- rm -rf ./disk/bin/ ./disk/
+ rm -rf disk/bin/ disk/
mkdir -p build/ disk/bin/ disk/
echo "Building..."
@@ -98,8 +98,11 @@ make_build() {
make
cd ..
- # Copy files
+ # Assemble bootloader
nasm src/entry.asm -f bin -o disk/boot.bin
+
+ # Make kernel binary
+ objcopy -O binary build/melvix.o build/melvix.bin
cp build/melvix.bin disk/
# Create disk image
diff --git a/src/entry.asm b/src/entry.asm
index 7f5ed5b..596a042 100644
--- a/src/entry.asm
+++ b/src/entry.asm
@@ -212,7 +212,6 @@ stage_two:
and ax, EXT2_REG ; AND with regular file
cmp ax, EXT2_REG ; Check if it's a regular file
jne disk_error ; Not a regular file!
- jmp $
; Read first block
mov ax, [bx + EXT2_POINTER_OFFSET] ; Address of first block pointer
shl ax, 1 ; Multiply by 2
@@ -273,6 +272,7 @@ protected_mode_enter:
lgdt [gdt_desc] ; Load GDT
+ ; Set protected mode via cr0
mov eax, cr0
or eax, 1 ; Set bit 0
mov cr0, eax
@@ -289,10 +289,12 @@ protected_mode:
mov fs, ax
mov gs, ax
mov ss, ax ; Stack segment
+
mov esp, 0x00900000 ; Move stack pointer
mov edx, 0x00050000
lea eax, [edx]
+ jmp $
call eax
; GDT
@@ -313,7 +315,7 @@ gdt_data:
dw 0
db 0
db 0x92
- db 0xcF
+ db 0xCF
db 0
gdt_end:
gdt_desc:
@@ -322,4 +324,5 @@ gdt_desc:
times 1024 - ($ - $$) db 0
+; Start at LBA 2
superblock:
diff --git a/src/link.ld b/src/link.ld
deleted file mode 100644
index d5aa082..0000000
--- a/src/link.ld
+++ /dev/null
@@ -1,28 +0,0 @@
-ENTRY(boot)
-
-SECTIONS
-{
- . = 1M;
-
- .text BLOCK(4K) : ALIGN(4K)
- {
- text_start = .;
- *(.text)
- *(.rodata)
- }
-
- .data BLOCK(4K) : ALIGN(4K)
- {
- data_start = .;
- *(.data)
- }
-
- .bss BLOCK(4K) : ALIGN(4K)
- {
- bss_start = .;
- *(.COMMON)
- *(.bss)
- }
-
- kernel_end = .;
-}
diff --git a/src/main.c b/src/main.c
index 21ad290..82f6961 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,37 +1,5 @@
-unsigned char inb(unsigned short port)
+int main()
{
- unsigned char value;
- __asm__ volatile("inb %1, %0" : "=a"(value) : "Nd"(port));
- return value;
-}
-
-void outb(unsigned short port, unsigned char data)
-{
- __asm__ volatile("outb %0, %1" ::"a"(data), "Nd"(port));
-}
-
-int is_transmit_empty()
-{
- return inb(0x3f8 + 5) & 0x20;
-}
-
-void serial_put(char ch)
-{
- while (is_transmit_empty() == 0)
- ;
- outb(0x3f8, (unsigned char)ch);
-}
-
-int main(int argc, char *argv[])
-{
- outb(0x3f8 + 1, 0x00);
- outb(0x3f8 + 3, 0x80);
- outb(0x3f8 + 0, 0x03);
- outb(0x3f8 + 1, 0x00);
- outb(0x3f8 + 3, 0x03);
- outb(0x3f8 + 2, 0xC7);
- outb(0x3f8 + 4, 0x0B);
- serial_put('a');
while (1) {
};
return 0;