summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorthe lemons <citrons@mondecitronne.com>2021-04-01 11:39:33 -0500
committerthe lemons <citrons@mondecitronne.com>2021-04-01 11:39:33 -0500
commitffb3780b5031cafc8ce9335c5413c74a10a94599 (patch)
tree23ca367441163169b2cb403300c0ec7334b8eb22
parentb75e39a2e30ed1cd88e7ac456dc83053158250d7 (diff)
provide multiboot structure to kernel_main
-rw-r--r--asm_obj/boot.obin18332 -> 18332 bytes
-rw-r--r--asm_obj/interrupt_stub.obin1620 -> 1628 bytes
-rwxr-xr-xisodir/boot/kernel.binbin86616 -> 87888 bytes
-rwxr-xr-xkernel.binbin86616 -> 87888 bytes
-rw-r--r--obj/interrupt.obin8668 -> 8848 bytes
-rw-r--r--obj/keyboard.obin6180 -> 6348 bytes
-rw-r--r--obj/main.obin6720 -> 8076 bytes
-rw-r--r--os.isobin19890176 -> 19890176 bytes
-rw-r--r--src/boot.s1
-rw-r--r--src/interrupt.c6
-rw-r--r--src/interrupt_stub.s3
-rw-r--r--src/keyboard.c9
-rw-r--r--src/keyboard.h2
-rw-r--r--src/main.c4
-rw-r--r--src/multiboot.h223
15 files changed, 241 insertions, 7 deletions
diff --git a/asm_obj/boot.o b/asm_obj/boot.o
index 91d113a..fd87394 100644
--- a/asm_obj/boot.o
+++ b/asm_obj/boot.o
Binary files differ
diff --git a/asm_obj/interrupt_stub.o b/asm_obj/interrupt_stub.o
index 669b218..1c091af 100644
--- a/asm_obj/interrupt_stub.o
+++ b/asm_obj/interrupt_stub.o
Binary files differ
diff --git a/isodir/boot/kernel.bin b/isodir/boot/kernel.bin
index 8102ba9..a3d698f 100755
--- a/isodir/boot/kernel.bin
+++ b/isodir/boot/kernel.bin
Binary files differ
diff --git a/kernel.bin b/kernel.bin
index 8102ba9..a3d698f 100755
--- a/kernel.bin
+++ b/kernel.bin
Binary files differ
diff --git a/obj/interrupt.o b/obj/interrupt.o
index 62fa47b..2dc07e0 100644
--- a/obj/interrupt.o
+++ b/obj/interrupt.o
Binary files differ
diff --git a/obj/keyboard.o b/obj/keyboard.o
index f8457ab..d34dd97 100644
--- a/obj/keyboard.o
+++ b/obj/keyboard.o
Binary files differ
diff --git a/obj/main.o b/obj/main.o
index 4e314ac..8a77e8e 100644
--- a/obj/main.o
+++ b/obj/main.o
Binary files differ
diff --git a/os.iso b/os.iso
index f78bfdd..9c9759f 100644
--- a/os.iso
+++ b/os.iso
Binary files differ
diff --git a/src/boot.s b/src/boot.s
index dd43460..569663f 100644
--- a/src/boot.s
+++ b/src/boot.s
@@ -66,6 +66,7 @@ _start:
ljmp $0x08,$continue
continue:
+ push %ebx /* pointer to multiboot structure */
call kernel_main
cli
diff --git a/src/interrupt.c b/src/interrupt.c
index e588353..c417117 100644
--- a/src/interrupt.c
+++ b/src/interrupt.c
@@ -23,6 +23,10 @@ void irq_end(uint8_t int_number) {
port_write(pic_master_command, PIC_EOI);
}
+uint8_t ps2_read() {
+ return port_read(ps2_port);
+}
+
uint32_t handle_int(uint8_t int_number, uint32_t idk, uint32_t esp) {
switch (int_number) {
case 0x0D:
@@ -30,7 +34,7 @@ uint32_t handle_int(uint8_t int_number, uint32_t idk, uint32_t esp) {
bees("general protection fault");
break;
case 0x21:
- process_scancode(port_read(ps2_port));
+ keyboard_event(&ps2_read);
irq_end(int_number);
break;
}
diff --git a/src/interrupt_stub.s b/src/interrupt_stub.s
index 618c982..3d2ba53 100644
--- a/src/interrupt_stub.s
+++ b/src/interrupt_stub.s
@@ -46,7 +46,10 @@ int_bottom:
popl %ds
popa
+ iret
+
int_ignore:
+ pop %eax
iret
diff --git a/src/keyboard.c b/src/keyboard.c
index 30dc5b7..f3919ac 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -61,15 +61,16 @@ void keyup(char c) {
}
-void process_scancode(uint8_t c) {
+void keyboard_event(uint8_t (*get_bytes)()) {
+ uint8_t data = get_bytes();
uint8_t code;
int release;
- if (c > 0x80 && c <= 0xD8) {
+ if (data > 0x80 && data <= 0xD8) {
release = 1;
- code = c - 0x80;
+ code = data - 0x80;
} else {
release = 0;
- code = c;
+ code = data;
}
switch (code) {
default:
diff --git a/src/keyboard.h b/src/keyboard.h
index c867e07..5642eb5 100644
--- a/src/keyboard.h
+++ b/src/keyboard.h
@@ -3,7 +3,7 @@
#include <stdint.h>
-void process_scancode(uint8_t c);
+void keyboard_event(uint8_t (*get_bytes)());
struct {
int shift;
diff --git a/src/main.c b/src/main.c
index 725f438..0022a4c 100644
--- a/src/main.c
+++ b/src/main.c
@@ -4,6 +4,8 @@
#include "vga.h"
#include "interrupt.h"
#include "string.h"
+#include "multiboot.h"
+#include "printf.h"
extern void *gdt;
@@ -27,7 +29,7 @@ const char *pope =
"by means of its diplomatic relations and political accords with many \n"
"independent states.\n";
-void kernel_main(void) {
+void kernel_main(multiboot_info_t *mbd) {
vsetcolor(vga_color(vga_black, vga_white));
vclear();
interrupt_init();
diff --git a/src/multiboot.h b/src/multiboot.h
new file mode 100644
index 0000000..587f508
--- /dev/null
+++ b/src/multiboot.h
@@ -0,0 +1,223 @@
+/* multiboot.h - Multiboot header file. */
+/* Copyright (C) 1999,2003,2007,2008,2009 Free Software Foundation, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ANY
+ * DEVELOPER OR DISTRIBUTOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
+ * IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef MULTIBOOT_HEADER
+#define MULTIBOOT_HEADER 1
+
+/* How many bytes from the start of the file we search for the header. */
+#define MULTIBOOT_SEARCH 8192
+
+/* The magic field should contain this. */
+#define MULTIBOOT_HEADER_MAGIC 0x1BADB002
+
+/* This should be in %eax. */
+#define MULTIBOOT_BOOTLOADER_MAGIC 0x2BADB002
+
+/* The bits in the required part of flags field we don't support. */
+#define MULTIBOOT_UNSUPPORTED 0x0000fffc
+
+/* Alignment of multiboot modules. */
+#define MULTIBOOT_MOD_ALIGN 0x00001000
+
+/* Alignment of the multiboot info structure. */
+#define MULTIBOOT_INFO_ALIGN 0x00000004
+
+/* Flags set in the 'flags' member of the multiboot header. */
+
+/* Align all boot modules on i386 page (4KB) boundaries. */
+#define MULTIBOOT_PAGE_ALIGN 0x00000001
+
+/* Must pass memory information to OS. */
+#define MULTIBOOT_MEMORY_INFO 0x00000002
+
+/* Must pass video information to OS. */
+#define MULTIBOOT_VIDEO_MODE 0x00000004
+
+/* This flag indicates the use of the address fields in the header. */
+#define MULTIBOOT_AOUT_KLUDGE 0x00010000
+
+/* Flags to be set in the 'flags' member of the multiboot info structure. */
+
+/* is there basic lower/upper memory information? */
+#define MULTIBOOT_INFO_MEMORY 0x00000001
+/* is there a boot device set? */
+#define MULTIBOOT_INFO_BOOTDEV 0x00000002
+/* is the command-line defined? */
+#define MULTIBOOT_INFO_CMDLINE 0x00000004
+/* are there modules to do something with? */
+#define MULTIBOOT_INFO_MODS 0x00000008
+
+/* These next two are mutually exclusive */
+
+/* is there a symbol table loaded? */
+#define MULTIBOOT_INFO_AOUT_SYMS 0x00000010
+/* is there an ELF section header table? */
+#define MULTIBOOT_INFO_ELF_SHDR 0X00000020
+
+/* is there a full memory map? */
+#define MULTIBOOT_INFO_MEM_MAP 0x00000040
+
+/* Is there drive info? */
+#define MULTIBOOT_INFO_DRIVE_INFO 0x00000080
+
+/* Is there a config table? */
+#define MULTIBOOT_INFO_CONFIG_TABLE 0x00000100
+
+/* Is there a boot loader name? */
+#define MULTIBOOT_INFO_BOOT_LOADER_NAME 0x00000200
+
+/* Is there a APM table? */
+#define MULTIBOOT_INFO_APM_TABLE 0x00000400
+
+/* Is there video information? */
+#define MULTIBOOT_INFO_VIDEO_INFO 0x00000800
+
+#ifndef ASM_FILE
+
+typedef unsigned short multiboot_uint16_t;
+typedef unsigned int multiboot_uint32_t;
+typedef unsigned long long multiboot_uint64_t;
+
+struct multiboot_header
+{
+ /* Must be MULTIBOOT_MAGIC - see above. */
+ multiboot_uint32_t magic;
+
+ /* Feature flags. */
+ multiboot_uint32_t flags;
+
+ /* The above fields plus this one must equal 0 mod 2^32. */
+ multiboot_uint32_t checksum;
+
+ /* These are only valid if MULTIBOOT_AOUT_KLUDGE is set. */
+ multiboot_uint32_t header_addr;
+ multiboot_uint32_t load_addr;
+ multiboot_uint32_t load_end_addr;
+ multiboot_uint32_t bss_end_addr;
+ multiboot_uint32_t entry_addr;
+
+ /* These are only valid if MULTIBOOT_VIDEO_MODE is set. */
+ multiboot_uint32_t mode_type;
+ multiboot_uint32_t width;
+ multiboot_uint32_t height;
+ multiboot_uint32_t depth;
+};
+
+/* The symbol table for a.out. */
+struct multiboot_aout_symbol_table
+{
+ multiboot_uint32_t tabsize;
+ multiboot_uint32_t strsize;
+ multiboot_uint32_t addr;
+ multiboot_uint32_t reserved;
+};
+typedef struct multiboot_aout_symbol_table multiboot_aout_symbol_table_t;
+
+/* The section header table for ELF. */
+struct multiboot_elf_section_header_table
+{
+ multiboot_uint32_t num;
+ multiboot_uint32_t size;
+ multiboot_uint32_t addr;
+ multiboot_uint32_t shndx;
+};
+typedef struct multiboot_elf_section_header_table multiboot_elf_section_header_table_t;
+
+struct multiboot_info
+{
+ /* Multiboot info version number */
+ multiboot_uint32_t flags;
+
+ /* Available memory from BIOS */
+ multiboot_uint32_t mem_lower;
+ multiboot_uint32_t mem_upper;
+
+ /* "root" partition */
+ multiboot_uint32_t boot_device;
+
+ /* Kernel command line */
+ multiboot_uint32_t cmdline;
+
+ /* Boot-Module list */
+ multiboot_uint32_t mods_count;
+ multiboot_uint32_t mods_addr;
+
+ union
+ {
+ multiboot_aout_symbol_table_t aout_sym;
+ multiboot_elf_section_header_table_t elf_sec;
+ } u;
+
+ /* Memory Mapping buffer */
+ multiboot_uint32_t mmap_length;
+ multiboot_uint32_t mmap_addr;
+
+ /* Drive Info buffer */
+ multiboot_uint32_t drives_length;
+ multiboot_uint32_t drives_addr;
+
+ /* ROM configuration table */
+ multiboot_uint32_t config_table;
+
+ /* Boot Loader Name */
+ multiboot_uint32_t boot_loader_name;
+
+ /* APM table */
+ multiboot_uint32_t apm_table;
+
+ /* Video */
+ multiboot_uint32_t vbe_control_info;
+ multiboot_uint32_t vbe_mode_info;
+ multiboot_uint16_t vbe_mode;
+ multiboot_uint16_t vbe_interface_seg;
+ multiboot_uint16_t vbe_interface_off;
+ multiboot_uint16_t vbe_interface_len;
+};
+typedef struct multiboot_info multiboot_info_t;
+
+struct multiboot_mmap_entry
+{
+ multiboot_uint32_t size;
+ multiboot_uint64_t addr;
+ multiboot_uint64_t len;
+#define MULTIBOOT_MEMORY_AVAILABLE 1
+#define MULTIBOOT_MEMORY_RESERVED 2
+ multiboot_uint32_t type;
+} __attribute__((packed));
+typedef struct multiboot_mmap_entry multiboot_memory_map_t;
+
+struct multiboot_mod_list
+{
+ /* the memory used goes from bytes 'mod_start' to 'mod_end-1' inclusive */
+ multiboot_uint32_t mod_start;
+ multiboot_uint32_t mod_end;
+
+ /* Module command line */
+ multiboot_uint32_t cmdline;
+
+ /* padding to take it to 16 bytes (must be zero) */
+ multiboot_uint32_t pad;
+};
+typedef struct multiboot_mod_list multiboot_module_t;
+
+#endif /* ! ASM_FILE */
+
+#endif /* ! MULTIBOOT_HEADER */