mirror of
https://github.com/gbowne1/ClassicOS.git
synced 2024-11-22 06:06:52 -08:00
Fixing a bunch of broken stuff including the looping bootloader boot.asm
This commit is contained in:
parent
4b0bd4d133
commit
ad28352c29
@ -1,5 +1,6 @@
|
|||||||
---
|
---
|
||||||
Language: Cpp
|
Language: C
|
||||||
|
Standard: C11 (or C17)
|
||||||
BasedOnStyle: LLVM
|
BasedOnStyle: LLVM
|
||||||
IndentWidth: 4
|
IndentWidth: 4
|
||||||
UseTab: Never
|
UseTab: Never
|
||||||
|
52
.clang-tidy
52
.clang-tidy
@ -1,12 +1,48 @@
|
|||||||
Checks: "clang-diagnostic-*,clang-analyzer-*,cppcoreguidelines-*,modernize-*,-modernize-use-trailing-return-type"
|
Checks: "clang-diagnostic-*,clang-analyzer-*,modernize-*,-modernize-use-trailing-return-type"
|
||||||
WarningsAsErrors: true
|
WarningsAsErrors: true
|
||||||
HeaderFilterRegex: ""
|
HeaderFilterRegex: ""
|
||||||
AnalyzeTemporaryDtors: false
|
AnalyzeTemporaryDtors: false
|
||||||
FormatStyle: google
|
FormatStyle: llvm
|
||||||
CheckOptions:
|
CheckOptions:
|
||||||
- key: cert-dcl16-c.NewSuffixes
|
- key: modernize-use-trailing-return-type.Enabled
|
||||||
value: "L;LL;LU;LLU"
|
value: false
|
||||||
- key: cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField
|
- key: readability-identifier-naming.NamespaceCase
|
||||||
value: "0"
|
value: CamelCase
|
||||||
- key: cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors
|
- key: readability-identifier-naming.ClassCase
|
||||||
value: "1"
|
value: CamelCase
|
||||||
|
- key: readability-identifier-naming.StructCase
|
||||||
|
value: CamelCase
|
||||||
|
- key: readability-identifier-naming.FunctionCase
|
||||||
|
value: CamelCase
|
||||||
|
- key: readability-identifier-naming.VariableCase
|
||||||
|
value: camelBack
|
||||||
|
- key: readability-identifier-naming.ConstantCase
|
||||||
|
value: UPPER_CASE
|
||||||
|
- key: readability-identifier-naming.EnumCase
|
||||||
|
value: CamelCase
|
||||||
|
- key: readability-identifier-naming.EnumConstantCase
|
||||||
|
value: UPPER_CASE
|
||||||
|
- key: readability-identifier-naming.GlobalConstantCase
|
||||||
|
value: UPPER_CASE
|
||||||
|
- key: readability-identifier-naming.GlobalVariableCase
|
||||||
|
value: camelBack
|
||||||
|
- key: readability-identifier-naming.LocalConstantCase
|
||||||
|
value: camelBack
|
||||||
|
- key: readability-identifier-naming.LocalVariableCase
|
||||||
|
value: camelBack
|
||||||
|
- key: readability-identifier-naming.MemberConstantCase
|
||||||
|
value: camelBack
|
||||||
|
- key: readability-identifier-naming.MemberVariableCase
|
||||||
|
value: camelBack
|
||||||
|
- key: readability-identifier-naming.ParameterCase
|
||||||
|
value: camelBack
|
||||||
|
- key: readability-identifier-naming.TemplateParameterCase
|
||||||
|
value: camelBack
|
||||||
|
- key: readability-identifier-naming.TypedefCase
|
||||||
|
value: CamelCase
|
||||||
|
- key: readability-identifier-naming.TypeAliasCase
|
||||||
|
value: CamelCase
|
||||||
|
- key: readability-identifier-naming.TypeTemplateParameterCase
|
||||||
|
value: CamelCase
|
||||||
|
- key: readability-identifier-naming.VariableTemplateCase
|
||||||
|
value: camelBack
|
||||||
|
14
.gdbinit
14
.gdbinit
@ -4,6 +4,16 @@ set architecture i386
|
|||||||
# Set the disassembly flavor
|
# Set the disassembly flavor
|
||||||
set disassembly-flavor intel
|
set disassembly-flavor intel
|
||||||
|
|
||||||
|
set disassemble-next-line
|
||||||
|
|
||||||
|
set pagination enable
|
||||||
|
|
||||||
|
set print address
|
||||||
|
|
||||||
|
set logging enable
|
||||||
|
|
||||||
|
set logging file gdb.log
|
||||||
|
|
||||||
# Set the prompt
|
# Set the prompt
|
||||||
set prompt (gdb)
|
set prompt (gdb)
|
||||||
|
|
||||||
@ -16,10 +26,10 @@ set history size 1000
|
|||||||
set solib-search-path .
|
set solib-search-path .
|
||||||
|
|
||||||
# Set the default directory
|
# Set the default directory
|
||||||
cd /path/to/project
|
d /home/user/Documents/ClassicOS
|
||||||
|
|
||||||
# Set the default target
|
# Set the default target
|
||||||
file kernel
|
file ClassicOS/build/kernel
|
||||||
|
|
||||||
# Set the symbol file
|
# Set the symbol file
|
||||||
symbol-file kernel
|
symbol-file kernel
|
||||||
|
@ -71,7 +71,10 @@ set(CMAKE_EXE_LINKER_FLAGS "-g -s")
|
|||||||
set(CMAKE_LINK_FLAGS "${CMAKE_LINK_FLAGS} -e kernel_main")
|
set(CMAKE_LINK_FLAGS "${CMAKE_LINK_FLAGS} -e kernel_main")
|
||||||
set(CMAKE_CXX_FLAGS "-g -Wall")
|
set(CMAKE_CXX_FLAGS "-g -Wall")
|
||||||
set(CMAKE_C_FLAGS "-g -Wall -m32")
|
set(CMAKE_C_FLAGS "-g -Wall -m32")
|
||||||
|
set(CMAKE_C_FLAGS_DEBUG "-g")
|
||||||
set(CMAKE_BUILD_TYPE Debug)
|
set(CMAKE_BUILD_TYPE Debug)
|
||||||
|
set(CMAKE_GDB_COMMAND gdb)
|
||||||
|
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0")
|
||||||
set(CMAKE_CXX_COMPILER g++)
|
set(CMAKE_CXX_COMPILER g++)
|
||||||
set(CMAKE_ASM_COMPILER nasm)
|
set(CMAKE_ASM_COMPILER nasm)
|
||||||
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} --32")
|
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} --32")
|
||||||
|
13
ask.txt
13
ask.txt
@ -147,16 +147,23 @@ target_link_libraries(ClassicOS PRIVATE)
|
|||||||
|
|
||||||
set(CMAKE_C_COMPILER gcc)
|
set(CMAKE_C_COMPILER gcc)
|
||||||
set(CMAKE_LINKER ld)
|
set(CMAKE_LINKER ld)
|
||||||
set(CMAKE_EXE_LINKER_FLAGS "-g")
|
set(CMAKE_EXE_LINKER_FLAGS "-g -s")
|
||||||
|
set(CMAKE_LINK_FLAGS "${CMAKE_LINK_FLAGS} -e kernel_main")
|
||||||
set(CMAKE_CXX_FLAGS "-g -Wall")
|
set(CMAKE_CXX_FLAGS "-g -Wall")
|
||||||
set(CMAKE_C_FLAGS "-g -Wall")
|
set(CMAKE_C_FLAGS "-g -Wall -m32")
|
||||||
|
set(CMAKE_C_FLAGS_DEBUG "-g")
|
||||||
set(CMAKE_BUILD_TYPE Debug)
|
set(CMAKE_BUILD_TYPE Debug)
|
||||||
|
set(CMAKE_GDB_COMMAND gdb)
|
||||||
|
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0")
|
||||||
set(CMAKE_CXX_COMPILER g++)
|
set(CMAKE_CXX_COMPILER g++)
|
||||||
set(CMAKE_ASM_COMPILER nasm)
|
set(CMAKE_ASM_COMPILER nasm)
|
||||||
|
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} --32")
|
||||||
set(CMAKE_SYSTEM_PROCESSOR i386)
|
set(CMAKE_SYSTEM_PROCESSOR i386)
|
||||||
|
set(CMAKE_SYSTEM_NAME None)
|
||||||
set(CMAKE_ASM_NASM_COMPILER nasm)
|
set(CMAKE_ASM_NASM_COMPILER nasm)
|
||||||
set(CMAKE_C_STANDARD 17)
|
set(CMAKE_C_STANDARD 17)
|
||||||
set(CMAKE_CXX_STANDARD 20)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
set(CMAKE_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
|
set(CMAKE_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
|
||||||
set(CMAKE_BINARY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/build)
|
set(CMAKE_BINARY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/build)
|
||||||
set_target_properties(ClassicOS PROPERTIES LINK_FLAGS "-T ${CMAKE_CURRENT_SOURCE_DIR}/linker.ld")
|
set_target_properties(ClassicOS PROPERTIES LINK_FLAGS "-T ${CMAKE_CURRENT_SOURCE_DIR}/linker.ld")
|
||||||
|
|
||||||
|
@ -1,28 +1,28 @@
|
|||||||
; Set up the segment registers
|
; Set up the segment registers
|
||||||
xor ax, ax
|
xor ax, ax
|
||||||
mov ds, ax
|
mov ds, ax
|
||||||
mov es, ax
|
mov es, ax
|
||||||
|
|
||||||
; Set up stack and jump to main
|
; Set up stack and jump to main
|
||||||
mov ss, ax
|
mov ss, ax
|
||||||
mov sp, 0x7c00
|
mov sp, 0x7c00
|
||||||
jmp main
|
jmp main
|
||||||
|
|
||||||
; Print 'Booting ClassicOS!' to the screen
|
; Print 'Booting ClassicOS!' to the screen
|
||||||
print:
|
print:
|
||||||
mov si, message
|
mov si, message
|
||||||
mov ah, 0x0e
|
mov ah, 0x0e
|
||||||
.loop:
|
.loop:
|
||||||
lodsb
|
lodsb
|
||||||
test al, al
|
test al, al
|
||||||
jz .done
|
jz .done
|
||||||
int 0x10
|
int 0x10
|
||||||
jmp .loop
|
jmp .loop
|
||||||
.done:
|
.done:
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; Set the video mode to a 40 column text mode
|
; Set the video mode to a 40 column text mode
|
||||||
set_video_mode:
|
set_video_mode:
|
||||||
mov ax, 0x0003 ; Set up a 80x25 text mode
|
mov ax, 0x0003 ; Set up a 80x25 text mode
|
||||||
int 0x10
|
int 0x10
|
||||||
|
|
||||||
@ -33,8 +33,44 @@
|
|||||||
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; Bootloader entry point
|
; Detect floppy disk drive
|
||||||
main:
|
detect_disk:
|
||||||
|
mov ah, 0x08
|
||||||
|
int 0x13
|
||||||
|
cmp ah, 0
|
||||||
|
jne .error
|
||||||
|
ret
|
||||||
|
|
||||||
|
.error:
|
||||||
|
; Handle disk detection error
|
||||||
|
; Display error message or take appropriate action
|
||||||
|
ret
|
||||||
|
|
||||||
|
; Read sectors from floppy disk
|
||||||
|
read_sectors:
|
||||||
|
mov ah, 0x02
|
||||||
|
mov al, 1 ; Number of sectors to read
|
||||||
|
mov ch, 0 ; Cylinder/Track number
|
||||||
|
mov cl, 2 ; Sector number (starting from 1)
|
||||||
|
mov dh, 0 ; Head number
|
||||||
|
mov dl, 0 ; Drive number (0 for floppy disk)
|
||||||
|
|
||||||
|
mov bx, buffer ; Destination buffer
|
||||||
|
mov es, bx
|
||||||
|
xor bx, bx
|
||||||
|
|
||||||
|
int 0x13
|
||||||
|
|
||||||
|
jc .error ; Check carry flag for error
|
||||||
|
ret
|
||||||
|
|
||||||
|
.error:
|
||||||
|
; Handle read error
|
||||||
|
; Display error message or take appropriate action
|
||||||
|
ret
|
||||||
|
|
||||||
|
; Bootloader entry point
|
||||||
|
main:
|
||||||
; Call the set_video_mode function
|
; Call the set_video_mode function
|
||||||
call set_video_mode
|
call set_video_mode
|
||||||
|
|
||||||
@ -50,12 +86,25 @@
|
|||||||
; Call the print function
|
; Call the print function
|
||||||
call print
|
call print
|
||||||
|
|
||||||
|
; Wait for a key press to exit the loop
|
||||||
|
mov ah, 0x00
|
||||||
|
int 0x16
|
||||||
|
|
||||||
|
; Call the detect_disk function
|
||||||
|
call detect_disk
|
||||||
|
|
||||||
|
; Call the read_sectors function
|
||||||
|
call read_sectors
|
||||||
|
|
||||||
; Infinite loop
|
; Infinite loop
|
||||||
.loop:
|
.loop:
|
||||||
jmp .loop
|
jmp .loop
|
||||||
|
|
||||||
; Message to print
|
; Message to print
|
||||||
message db 'Booting ClassicOS!', 0
|
message db 'Booting ClassicOS!', 0
|
||||||
|
|
||||||
times 510-($-$$) db 0
|
; Buffer to store read sectors
|
||||||
dw 0xaa55
|
buffer times 512 db 0
|
||||||
|
|
||||||
|
times 510-($-$$) db 0
|
||||||
|
dw 0xaa55
|
@ -1,8 +1,34 @@
|
|||||||
ENTRY(boot)
|
ENTRY(start)
|
||||||
SECTIONS {
|
SECTIONS {
|
||||||
. = 0x7c00;
|
. = 0x7c00;
|
||||||
|
|
||||||
.text : {
|
.text : {
|
||||||
*(.text)
|
*(.text)
|
||||||
}
|
}
|
||||||
/* Add other sections as needed */
|
|
||||||
|
.data : {
|
||||||
|
*(.data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.bss : {
|
||||||
|
*(.bss)
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Define the bootloader signature at the end of the bootloader */
|
||||||
|
bootloader_signature : {
|
||||||
|
*(.bootloader_signature)
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Define the bootloader magic number at the end of the bootloader */
|
||||||
|
bootloader_magic : {
|
||||||
|
*(.bootloader_magic)
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Define the bootloader padding to fill up the remaining space */
|
||||||
|
bootloader_padding : {
|
||||||
|
*(.bootloader_padding)
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set the bootloader size to 512 bytes */
|
||||||
|
= 512;
|
||||||
|
}
|
@ -80,7 +80,7 @@ void gdt_init()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Exception handlers
|
// Exception handlers
|
||||||
extern void divide_error();
|
extern void divide_error(struct idt_regs *regs);
|
||||||
extern void page_fault(struct idt_regs *regs);
|
extern void page_fault(struct idt_regs *regs);
|
||||||
extern void general_protection_fault();
|
extern void general_protection_fault();
|
||||||
extern void double_fault();
|
extern void double_fault();
|
||||||
@ -92,20 +92,20 @@ extern void keyboard();
|
|||||||
extern void device();
|
extern void device();
|
||||||
|
|
||||||
// Register an ISR
|
// Register an ISR
|
||||||
void isr_register(uint8_t num, void (*handler)(struct idt_regs *))
|
void isr_register(uint8_t num, void (*handler)(struct isr_regs *))
|
||||||
{
|
{
|
||||||
isr_table[num] = handler;
|
isr_table[num] = handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void divide_error(struct idt_regs *regs)
|
||||||
|
{
|
||||||
|
printf("Divide by zero error!\n");
|
||||||
|
// Additional actions can be taken as needed
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize the ISR
|
// Initialize the ISR
|
||||||
void isr_init()
|
void isr_init()
|
||||||
{
|
{
|
||||||
// Initialize ISR table
|
|
||||||
for (int i = 0; i < ISR_TABLE_SIZE; i++)
|
|
||||||
{
|
|
||||||
isr_table[i] = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Register exception handlers
|
// Register exception handlers
|
||||||
isr_register(0, divide_error);
|
isr_register(0, divide_error);
|
||||||
isr_register(PAGE_FAULT, page_fault);
|
isr_register(PAGE_FAULT, page_fault);
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#define IDT_H
|
#define IDT_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include "isr.h"
|
||||||
// IDT entry structure
|
// IDT entry structure
|
||||||
struct idt_entry
|
struct idt_entry
|
||||||
{
|
{
|
||||||
@ -21,7 +21,7 @@ struct idt_ptr
|
|||||||
} __attribute__((packed));
|
} __attribute__((packed));
|
||||||
|
|
||||||
// Exception handlers
|
// Exception handlers
|
||||||
void divide_error();
|
void divide_error(struct idt_regs *regs);
|
||||||
void double_fault();
|
void double_fault();
|
||||||
|
|
||||||
// Interrupt handlers
|
// Interrupt handlers
|
||||||
|
@ -18,7 +18,7 @@ void dummy_isr(struct isr_regs *regs)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ISR table
|
// ISR table
|
||||||
extern void (*isr_table[256])(struct isr_regs *regs);
|
void (*isr_table[256])(struct isr_regs *regs) = {0};
|
||||||
|
|
||||||
// Register an ISR
|
// Register an ISR
|
||||||
extern void isr_register(uint8_t num, void (*handler)(struct isr_regs *regs))
|
extern void isr_register(uint8_t num, void (*handler)(struct isr_regs *regs))
|
||||||
@ -32,7 +32,7 @@ void isr_handler(struct idt_regs *regs)
|
|||||||
switch (regs->int_no)
|
switch (regs->int_no)
|
||||||
{
|
{
|
||||||
case 0x00:
|
case 0x00:
|
||||||
divide_error();
|
divide_error(regs);
|
||||||
break;
|
break;
|
||||||
case 0x06:
|
case 0x06:
|
||||||
invalid_opcode();
|
invalid_opcode();
|
||||||
@ -74,7 +74,7 @@ void isr_handler(struct idt_regs *regs)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Exception handlers
|
// Exception handlers
|
||||||
void divide_error()
|
void divide_error(struct idt_regs *regs)
|
||||||
{
|
{
|
||||||
printf("Divide by zero error!\n");
|
printf("Divide by zero error!\n");
|
||||||
// Additional actions can be taken as needed
|
// Additional actions can be taken as needed
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
extern void (*isr_table[256])(struct isr_regs *regs);
|
||||||
|
|
||||||
struct isr_regs
|
struct isr_regs
|
||||||
{
|
{
|
||||||
uint32_t gs, fs, es, ds; // Segment selectors
|
uint32_t gs, fs, es, ds; // Segment selectors
|
||||||
|
Loading…
Reference in New Issue
Block a user