Skip to content
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
8 changes: 8 additions & 0 deletions .github/workflows/c-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,11 @@ jobs:
run: make
- name: run and test
run: make clean && make && make test
- name: Versions
run: |
make -v
gcc -v
clang-format --version
xorriso --version
qemu-system-x86_64 -version
grub-mkrescue --version
8 changes: 8 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ jobs:
make clean
make
make test
- name: Versions
run: |
make -v
gcc -v
clang-format --version
xorriso --version
qemu-system-x86_64 -version
grub-mkrescue --version

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
Expand Down
51 changes: 51 additions & 0 deletions kernel/arch/amd64/sections.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include "khal.h"
#include "kstring.h"
#include <stdint.h>

extern uint64_t kernel_section_text_start;
extern uint64_t kernel_section_text_end;
extern uint64_t kernel_section_rodata_start;
extern uint64_t kernel_section_rodata_end;
extern uint64_t kernel_section_data_start;
extern uint64_t kernel_section_data_end;
extern uint64_t kernel_section_bss_start;
extern uint64_t kernel_section_bss_end;

typedef struct {
uint64_t start;
uint64_t end;
} sections_t;

sections_t kernel_sections[4];

sections_t *sectons_init() {
// Why this halts cpu?
//memset(&kernel_section_bss_start, 0,
// (uint64_t)&kernel_section_bss_end -
// (uint64_t)&kernel_section_bss_start);
serial_printf("\t.text 0x%x-0x%x(%u)\n", &kernel_section_text_start,

Check failure

Code scanning / CodeQL

Wrong type of arguments to formatting function High

This format specifier for type 'unsigned int' does not match the argument type 'unsigned long *'.
&kernel_section_text_end,

Check failure

Code scanning / CodeQL

Wrong type of arguments to formatting function High

This format specifier for type 'unsigned int' does not match the argument type 'unsigned long *'.
&kernel_section_text_end - &kernel_section_text_start);

Check failure

Code scanning / CodeQL

Wrong type of arguments to formatting function High

This format specifier for type 'unsigned int' does not match the argument type 'long'.
kernel_sections[0] =
(sections_t){ kernel_section_text_start, kernel_section_text_end };

serial_printf("\t.rodata 0x%x-0x%x(%u)\n", &kernel_section_rodata_start,

Check failure

Code scanning / CodeQL

Wrong type of arguments to formatting function High

This format specifier for type 'unsigned int' does not match the argument type 'unsigned long *'.
&kernel_section_rodata_end,

Check failure

Code scanning / CodeQL

Wrong type of arguments to formatting function High

This format specifier for type 'unsigned int' does not match the argument type 'unsigned long *'.
&kernel_section_rodata_end - &kernel_section_rodata_start);

Check failure

Code scanning / CodeQL

Wrong type of arguments to formatting function High

This format specifier for type 'unsigned int' does not match the argument type 'long'.
kernel_sections[1] =
(sections_t){ kernel_section_rodata_start, kernel_section_rodata_end };

serial_printf("\t.data 0x%x-0x%x(%u)\n", &kernel_section_data_start,

Check failure

Code scanning / CodeQL

Wrong type of arguments to formatting function High

This format specifier for type 'unsigned int' does not match the argument type 'unsigned long *'.
&kernel_section_data_end,

Check failure

Code scanning / CodeQL

Wrong type of arguments to formatting function High

This format specifier for type 'unsigned int' does not match the argument type 'unsigned long *'.
&kernel_section_data_end - &kernel_section_data_start);

Check failure

Code scanning / CodeQL

Wrong type of arguments to formatting function High

This format specifier for type 'unsigned int' does not match the argument type 'long'.
kernel_sections[2] =
(sections_t){ kernel_section_data_start, kernel_section_data_end };

serial_printf("\t.bss 0x%x-0x%x(%u)\n", &kernel_section_bss_start,

Check failure

Code scanning / CodeQL

Wrong type of arguments to formatting function High

This format specifier for type 'unsigned int' does not match the argument type 'unsigned long *'.
&kernel_section_bss_end,

Check failure

Code scanning / CodeQL

Wrong type of arguments to formatting function High

This format specifier for type 'unsigned int' does not match the argument type 'unsigned long *'.
&kernel_section_bss_end - &kernel_section_bss_start);

Check failure

Code scanning / CodeQL

Wrong type of arguments to formatting function High

This format specifier for type 'unsigned int' does not match the argument type 'long'.
kernel_sections[3] =
(sections_t){ kernel_section_bss_start, kernel_section_bss_end };

return (sections_t *)&kernel_sections;
}
3 changes: 2 additions & 1 deletion kernel/arch/amd64/serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

void serial_write_byte(uint8_t byte) {
// Wait until the transmit holding register is empty
while ((inb(0x3f8 + 5) & 0x20) == 0);
while ((inb(0x3f8 + 5) & 0x20) == 0)
;
outb(0x3f8, byte);
}

Expand Down
4 changes: 2 additions & 2 deletions kernel/include/sys/panic.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include <stdint.h>

void __attribute__((noreturn)) panic_int(uint8_t int_no, const char *msg);
void __attribute__((noreturn)) panic(const char *msg, const char *func,
const int line);
void __attribute__((noreturn))
panic(const char *msg, const char *func, const int line);

#define PANIC(msg) panic(msg, __func__, __LINE__)

Expand Down
2 changes: 2 additions & 0 deletions kernel/kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
#include <stdint.h>

int multiboot2_init(uint64_t *addr, uint32_t magic);
int sectons_init();

void kernel_main64(uint64_t *multiboot2, uint32_t magic, void *esp,
uint64_t base) {
sectons_init();
serial_init();
serial_printf(":D\n");

Expand Down
3 changes: 2 additions & 1 deletion kernel/klibc/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ int memcmp(const void *ptr1, const void *ptr2, size_t count) {

size_t __attribute__((pure)) strlen(const char *s) {
int i;
for (i = 0; s[i] != '\0'; i++);
for (i = 0; s[i] != '\0'; i++)
;
return i;
}

Expand Down
2 changes: 2 additions & 0 deletions kernel/multiboot2.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ void handle_basic_load_base_addr(struct multiboot_tag *tag) {
(struct multiboot_tag_load_base_addr *)tag;
serial_printf("load_base_size: %u\n", base_addr->size);
serial_printf("load_base_addr: 0x%x\n", base_addr->load_base_addr);
serial_printf("Kernel: 0x%x-0x%x\n", base_addr->load_base_addr,
base_addr->load_base_addr + base_addr->size);
}

void handle_mmap_tag(struct multiboot_tag *tag) {
Expand Down
4 changes: 2 additions & 2 deletions kernel/sys/panic.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ void __attribute__((noreturn)) panic_int(uint8_t int_no, const char *msg) {
for (;;) cpu_halt();
}

void __attribute__((noreturn)) panic(const char *msg, const char *func,
const int line) {
void __attribute__((noreturn))
panic(const char *msg, const char *func, const int line) {
cpu_interrupt_lock_acquire();

serial_printf("\n\rKernel panic - %s in %s:%d\n", msg, func, line);
Expand Down
8 changes: 8 additions & 0 deletions scripts/linker.ld
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,38 @@ SECTIONS{
phys = .;

.text BLOCK(4K) : ALIGN(4K) {
PROVIDE(kernel_section_text_start = .);
*(.multiboot)
*(.bootstrap)
code = .;
*(.text)
PROVIDE(kernel_section_text_end = .);
}

.rodata BLOCK(4K) : ALIGN(4K) {
PROVIDE(kernel_section_rodata_start = .);
*(.rodata)
PROVIDE(kernel_section_rodata_end = .);
}

.data BLOCK(4K) : ALIGN(4K) {
PROVIDE(kernel_section_data_start = .);
data = .;
*(.data)
*(.symbols)
PROVIDE(kernel_symbols_start = .);
PROVIDE(kernel_symbols_end = .);
PROVIDE(kernel_section_data_end = .);
}

.bss BLOCK(4K) : ALIGN(4K) {
PROVIDE(kernel_section_bss_start = .);
PROVIDE(bss_start = .);
bss = .;
*(COMMON)
*(.bss)
*(.stack)
PROVIDE(kernel_section_bss_end = .);
}

end = .;
Expand Down
Loading