more interrupt work
This commit is contained in:
parent
45c4c1d1e1
commit
d37fa101f4
7 changed files with 155 additions and 8 deletions
23
kernel/include/framebuffer.h
Normal file
23
kernel/include/framebuffer.h
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
/* Calcite, kernel/include/framebuffer.h
|
||||
* Copyright 2025 Benji Dial
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
extern uint8_t *fb_base;
|
||||
extern int fb_width;
|
||||
extern int fb_height;
|
||||
extern int fb_pitch;
|
||||
20
kernel/include/keyboard.h
Normal file
20
kernel/include/keyboard.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* Calcite, kernel/include/keyboard.h
|
||||
* Copyright 2025 Benji Dial
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
void on_keyboard_irq();
|
||||
|
|
@ -15,7 +15,9 @@
|
|||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <framebuffer.h>
|
||||
#include <interrupts.h>
|
||||
#include <keyboard.h>
|
||||
#include <utility.h>
|
||||
#include <initfs.h>
|
||||
#include <limine.h>
|
||||
|
|
@ -75,11 +77,6 @@ static void map_kernel_region(
|
|||
physical_start + i, (uint8_t *)virtual_start + i, writable, executable);
|
||||
}
|
||||
|
||||
static uint8_t *fb_base;
|
||||
static int fb_width;
|
||||
static int fb_height;
|
||||
static int fb_pitch;
|
||||
|
||||
static uint8_t *initfs_start;
|
||||
static uint64_t initfs_length;
|
||||
|
||||
|
|
@ -179,11 +176,17 @@ static uint64_t initfs_length;
|
|||
|
||||
[[noreturn]] static void with_kernel_page_tables() {
|
||||
|
||||
//further initialization
|
||||
//set initfs
|
||||
|
||||
set_initfs(initfs_start, initfs_length);
|
||||
|
||||
//set up interrupts
|
||||
|
||||
set_irq_handler(0x01, &on_keyboard_irq);
|
||||
enable_interrupts();
|
||||
|
||||
//halt repeatedly
|
||||
|
||||
while (1)
|
||||
__asm__ ("hlt");
|
||||
|
||||
|
|
|
|||
23
kernel/src/framebuffer.c
Normal file
23
kernel/src/framebuffer.c
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
/* Calcite, kernel/src/framebuffer.c
|
||||
* Copyright 2025 Benji Dial
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <framebuffer.h>
|
||||
|
||||
uint8_t *fb_base;
|
||||
int fb_width;
|
||||
int fb_height;
|
||||
int fb_pitch;
|
||||
|
|
@ -192,8 +192,8 @@ void enable_interrupts_asm(
|
|||
|
||||
void enable_interrupts() {
|
||||
|
||||
the_tss.ist1 = (uint64_t)&interrupt_stack_one;
|
||||
the_tss.ist2 = (uint64_t)&interrupt_stack_two;
|
||||
the_tss.ist1 = (uint64_t)interrupt_stack_one + INTERRUPT_STACK_SIZE;
|
||||
the_tss.ist2 = (uint64_t)interrupt_stack_two + INTERRUPT_STACK_SIZE;
|
||||
|
||||
//having the table past the end of the tss will lead to a gpf when the
|
||||
//cpu tries to access it, which is the same effect as a disabled port.
|
||||
|
|
|
|||
38
kernel/src/keyboard.asm
Normal file
38
kernel/src/keyboard.asm
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
; Calcite, kernel/src/paging.asm
|
||||
; Copyright 2025 Benji Dial
|
||||
;
|
||||
; This program is free software: you can redistribute it and/or modify
|
||||
; it under the terms of the GNU General Public License as published by
|
||||
; the Free Software Foundation, either version 3 of the License, or (at
|
||||
; your option) any later version.
|
||||
;
|
||||
; This program is distributed in the hope that it will be useful, but
|
||||
; WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
; more details.
|
||||
;
|
||||
; You should have received a copy of the GNU General Public License along with
|
||||
; this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
bits 64
|
||||
|
||||
section .text
|
||||
|
||||
;referenced in keyboard.c
|
||||
;return type is int
|
||||
;returns -1 if no byte available
|
||||
global read_keyboard_byte
|
||||
read_keyboard_byte:
|
||||
|
||||
in al, 0x64
|
||||
test al, 0x01
|
||||
jz .no_data
|
||||
|
||||
xor eax, eax
|
||||
in al, 0x60
|
||||
ret
|
||||
|
||||
.no_data:
|
||||
mov eax, -1
|
||||
ret
|
||||
40
kernel/src/keyboard.c
Normal file
40
kernel/src/keyboard.c
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/* Calcite, kernel/src/keyboard.c
|
||||
* Copyright 2025 Benji Dial
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <framebuffer.h>
|
||||
#include <keyboard.h>
|
||||
|
||||
//defined in keyboard.asm
|
||||
//returns -1 if no byte available
|
||||
int read_keyboard_byte();
|
||||
|
||||
static uint32_t color = 1;
|
||||
|
||||
void on_keyboard_irq() {
|
||||
|
||||
while (read_keyboard_byte() != -1)
|
||||
;
|
||||
|
||||
color ^= color << 13;
|
||||
color ^= color >> 17;
|
||||
color ^= color << 5;
|
||||
|
||||
for (int y = 0; y < fb_height; ++y)
|
||||
for (int x = 0; x < fb_width; ++x)
|
||||
*(uint32_t *)&fb_base[y * fb_pitch + x * 4] = color & 0x00ffffff;
|
||||
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue