Skip to content

Commit

Permalink
add mini_kernel4 to demo the keyboard driver
Browse files Browse the repository at this point in the history
  • Loading branch information
foxsen committed Jun 19, 2022
1 parent 9735612 commit 11c3962
Show file tree
Hide file tree
Showing 18 changed files with 1,065 additions and 0 deletions.
151 changes: 151 additions & 0 deletions mini_kernel4/.gdb_history
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
target remote :1234
b kernel_entry
c
quit
target remote :1234
b kernel_entry
c
disass
quit
target remote :1234
b kernel_entry
c
disass
si
c
disass
info reg
si
p/x addr
info reg
quit
b kernel_entry
target remote :1234
c
disas
s
s
quit
target remote :1234
c
x
target remote :1234
c
b kernel_entry
quit
target remote :1234
b kernel_entry
c
p str
s
disas
si
si
info reg
si
info reg
quit
target remote :1234
b kernel_entry
c
s
disass
si
info reg
quit
target remote :1234
b kernel_entry
c
s
s
s
disass
si
info reg
si
c
quit
target remote :1234
b kernel_entry
c
s
quit
target remote :1234
b kernel_entry
c
s
disass
si
info reg
si
quit
target remote :1234
b kernel_entry
c
quit
target remote :1234
b kernel_entry
c
disass
quit
target remote :1234
b kernel_entry
c
disas
disas
x 0x100000
quit
target remote :1234
b kernel_entry
c
x 0x100000
x 0x101fe0
quit
target remote :1234
b kernel_entry
c
c
target remote :1234
c
c
target remote :1234
c
c
quit
target remote :1234
b kernel_entry
c
disass
quit
target remote :1234
b kernel_entry
c
disass
quit
target remote :1234
b kernel_entry
c
disass
quit
target remote :1234
b kernel_entry
c
s
s
x/s str
p/s str
s
p str
s
s
s
l
s
s
s
s
s
quit
target remote :1234
c
quit
22 changes: 22 additions & 0 deletions mini_kernel4/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
OBJS := serial.o printf.o hello_kernel.o trap.o trap_entry.o extioi.o ls7a_intc.o pckbd.o
TOOLPREFIX = loongarch64-unknown-linux-gnu-

CC = $(TOOLPREFIX)gcc
LD = $(TOOLPREFIX)ld

CFLAGS = -Wall -Wno-warn -O2 -g3 -march=loongarch64 -mabi=lp64s -ffreestanding -fno-common -nostdlib -I. -fno-stack-protector -fno-pie -no-pie
LDFLAGS = -z max-page-size=4096

kernel: $(OBJS) ld.script
$(LD) $(LDFLAGS) -T ld.script -o kernel $(OBJS)

%.o : %.c
$(CC) $(CFLAGS) -c -o $@ $<

%.o : %.S
$(CC) $(CFLAGS) -c -o $@ $<

all: kernel

clean:
rm -f *.o ./kernel
57 changes: 57 additions & 0 deletions mini_kernel4/README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# mini kernel

在mini kernel3的基础上,展示键盘中断处理。

## 注意1: 要使用本测试,模拟器需要更新到以下commit之后的版本。

commit ac069a8ffb8f41fcbc7ed0aa5d420a71fff36581 (HEAD -> loongarch, origin/loongarch)
Author: Zhang Fuxin <fxzhang@ict.ac.cn>
Date: Sun Jun 19 17:10:49 2022 +0800

add pc keyboard support.
The pc PS2 keyboard controller is added at 0x1fe00060, with
keyboard interrupt connected to ls7a irq 3/4.

## 注意2: 为了方便观察输出,启动命令行可以设为:

./qemu-system-loongarch64 -m 4G -smp 1 -bios ./loongarch_bios_0310.bin -kernel ./mini_kernel4/kernel -vga virtio -serial stdio

其中-vga选项使能图形选项,键盘输入只有在有图形界面的情况下起作用。-serial stdio在命令行界面实现一个模拟串口,用于观察内核的输出。


## 预期界面

在图形界面试图输入一些键,每输入一个键,应该有两次键盘中断,内核打印出其扫描码。

命令行输出:

There is 2 args for kernel:
cmd arg 0: a0
cmd arg 1: root=/dev/ram console=ttyS0,115200 rdinit=/init
efi system table at 0x00000000fffd0018
efi extend list at 0x00000000fffda430
keyboard reponse 55
test result 0
reset result fa

estat 4, ecfg bfc
era=0x00000000001005d8 eentry=0x0000000000101000
irq=1c
aa key done
mouse interrupt

estat 800, ecfg bfc
era=0x000000000010036c eentry=0x0000000000101000
timer interrupt

estat 4, ecfg bfc
era=0x000000000010036c eentry=0x0000000000101000
irq=8
29 key done

estat 4, ecfg bfc
era=0x000000000010036c eentry=0x0000000000101000
irq=8
f0 29 key done

98 changes: 98 additions & 0 deletions mini_kernel4/boot_param.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/* SPDX-License-Identifier: GPL-2.0 */
/* copied from linux source */
#ifndef __ASM_BOOT_PARAM_H_
#define __ASM_BOOT_PARAM_H_

#ifdef CONFIG_VT
#include <linux/screen_info.h>
#endif

/* add necessary defines */
typedef unsigned char u8;
typedef unsigned int u32;
typedef unsigned long u64;
#define __packed __attribute__((__packed__))

#define ADDRESS_TYPE_SYSRAM 1
#define ADDRESS_TYPE_RESERVED 2
#define ADDRESS_TYPE_ACPI 3
#define ADDRESS_TYPE_NVS 4
#define ADDRESS_TYPE_PMEM 5

#define LOONGSON3_BOOT_MEM_MAP_MAX 128

#define LOONGSON_EFIBOOT_SIGNATURE "BPI"
#define LOONGSON_MEM_LINKLIST "MEM"
#define LOONGSON_VBIOS_LINKLIST "VBIOS"
#define LOONGSON_SCREENINFO_LINKLIST "SINFO"

/* Values for Version BPI */
enum bpi_version {
BPI_VERSION_V1 = 1000, /* Signature="BPI01000" */
BPI_VERSION_V2 = 1001, /* Signature="BPI01001" */
};

/* Flags in bootparamsinterface */
#define BPI_FLAGS_UEFI_SUPPORTED BIT(0)

struct _extention_list_hdr {
u64 signature;
u32 length;
u8 revision;
u8 checksum;
struct _extention_list_hdr *next;
} __packed;

struct bootparamsinterface {
u64 signature; /* {"B", "P", "I", "0", "1", ... } */
void *systemtable;
struct _extention_list_hdr *extlist;
u64 flags;
} __packed;

struct loongsonlist_mem_map {
struct _extention_list_hdr header; /* {"M", "E", "M"} */
u8 map_count;
struct loongson_mem_map {
u32 mem_type;
u64 mem_start;
u64 mem_size;
} __packed map[LOONGSON3_BOOT_MEM_MAP_MAX];
} __packed;

struct loongsonlist_vbios {
struct _extention_list_hdr header; /* {"V", "B", "I", "O", "S"} */
u64 vbios_addr;
} __packed;

struct loongsonlist_screeninfo {
struct _extention_list_hdr header; /* {"S", "I", "N", "F", "O"} */
//struct screen_info si;
} __packed;

struct loongson_board_info {
int bios_size;
char *bios_vendor;
char *bios_version;
char *bios_release_date;
char *board_name;
char *board_vendor;
};

struct loongson_system_configuration {
int bpi_ver;
int nr_cpus;
int nr_nodes;
int nr_io_pics;
int boot_cpu_id;
int cores_per_node;
int cores_per_package;
char *cpuname;
u64 vgabios_addr;
};

extern struct loongson_board_info b_info;
extern struct bootparamsinterface *efi_bp;
extern struct loongsonlist_mem_map *loongson_mem_map;
extern struct loongson_system_configuration loongson_sysconf;
#endif
28 changes: 28 additions & 0 deletions mini_kernel4/extioi.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "loongarch.h"
#include "ls7a.h"

void extioi_init(void)
{
iocsr_writeq((0x1UL << UART0_IRQ) | (0x1UL << KEYBOARD_IRQ) |
(0x1UL << MOUSE_IRQ), LOONGARCH_IOCSR_EXTIOI_EN_BASE);

/* extioi[31:0] map to cpu irq pin INT1, other to INT0 */
iocsr_writeq(0x01UL,LOONGARCH_IOCSR_EXTIOI_MAP_BASE);

/* extioi IRQ 0-7 route to core 0, use node type 0 */
iocsr_writeq(0x0UL,LOONGARCH_IOCSR_EXTIOI_ROUTE_BASE);

/* nodetype0 set to 1, always trigger at node 0 */
iocsr_writeq(0x1,LOONGARCH_IOCSR_EXRIOI_NODETYPE_BASE);
}

// ask the extioi what interrupt we should serve.
unsigned long extioi_claim(void)
{
return iocsr_readq(LOONGARCH_IOCSR_EXTIOI_ISR_BASE);
}

void extioi_complete(unsigned long irq)
{
iocsr_writeq(irq, LOONGARCH_IOCSR_EXTIOI_ISR_BASE);
}
28 changes: 28 additions & 0 deletions mini_kernel4/hello_kernel.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* minimal kernel for loongarch64
* it print out information passed by BIOS
*/
#include "lib.h"
#include "boot_param.h"

extern void trap_init(void);

void kernel_entry(int a0, char **args, struct bootparamsinterface *a2)
{
int i;

printf("There is %d args for kernel:\n", a0);
for (i=0; i < a0; i++) {
printf("cmd arg %d: %s\n", i, args[i]);
}

printf("efi system table at %p\n", a2->systemtable);
printf("efi extend list at %p\n", a2->extlist);

/* ... read the linux kernel source for how to decode these data */

trap_init();

while(1);
}


Loading

0 comments on commit 11c3962

Please sign in to comment.