Include ACPI related code, add PCI wrapper.

This commit is contained in:
Ivan Baravy 2020-05-02 01:09:42 +03:00
parent 26fd52621d
commit e481975a89
6 changed files with 100 additions and 3 deletions

View File

@ -242,12 +242,18 @@ void xfs_user_functions(void);
void ext_user_functions(void);
void fat_user_functions(void);
void ntfs_user_functions(void);
void kos_enable_acpi(void);
void coverage_begin(void);
void coverage_end(void);
extern uint32_t *kos_lfb_base;
extern uint16_t *kos_win_stack;
extern uint16_t *kos_win_pos;
extern uint32_t kos_acpi_ssdt_cnt;
extern uint8_t **kos_acpi_ssdt_base;
extern size_t *kos_acpi_ssdt_size;
extern disk_t disk_list;
#endif

View File

@ -11,15 +11,18 @@ all: umka_shell umka_fuse umka.sym umka.prp umka.lst tags tools/mkdirrange tools
covpreproc: covpreproc.c
$(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@
umka_shell: umka_shell.o umka.o trace.o trace_lbr.o vdisk.o lodepng.o
umka_shell: umka_shell.o umka.o trace.o trace_lbr.o vdisk.o lodepng.o pci.o
$(CC) $(LDFLAGS_32) $^ -o $@ -static
umka_fuse: umka_fuse.o umka.o trace.o trace_lbr.o vdisk.o
umka_fuse: umka_fuse.o umka.o trace.o trace_lbr.o vdisk.o pci.o
$(CC) $(LDFLAGS_32) $^ -o $@ `pkg-config fuse3 --libs`
umka.o umka.fas: umka.asm
INCLUDE="$(KOLIBRI)/kernel/trunk;$(KOLIBRI)/programs/develop/libraries/libcrash/trunk" $(FASM) $< umka.o -s umka.fas -m 1234567
pci.o: pci.c
$(CC) $(CFLAGS_32) -c $<
lodepng.o: lodepng.c lodepng.h
$(CC) $(CFLAGS_32) -c $<

17
pci.c Normal file
View File

@ -0,0 +1,17 @@
#include <stdio.h>
#include <inttypes.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
__attribute__((stdcall)) uint32_t pci_read(uint32_t bus, uint32_t dev, uint32_t fun, uint32_t offset, size_t len) {
char path[128];
uint32_t value = 0;
sprintf(path, "/sys/bus/pci/devices/%4.4u:%2.2u:%2.2u.%u/config", 0, bus, dev, fun);
int fd = open(path, O_RDONLY);
lseek(fd, offset, SEEK_SET);
read(fd, &value, len);
close(fd);
return value;
}

8
test/020_#acpi_all.t Normal file
View File

@ -0,0 +1,8 @@
acpi_preload_table ../../acpi/tables/2020hp_pavilion/DSDT
acpi_preload_table ../../acpi/tables/2020hp_pavilion/SSDT1
acpi_preload_table ../../acpi/tables/2020hp_pavilion/SSDT2
acpi_preload_table ../../acpi/tables/2020hp_pavilion/SSDT3
acpi_preload_table ../../acpi/tables/2020hp_pavilion/SSDT4
acpi_preload_table ../../acpi/tables/2020hp_pavilion/SSDT5
acpi_preload_table ../../acpi/tables/2020hp_pavilion/SSDT6
acpi_enable

View File

@ -26,6 +26,11 @@ public win_stack_addr as 'kos_win_stack'
public win_pos_addr as 'kos_win_pos'
public lfb_base_addr as 'kos_lfb_base'
public enable_acpi as 'kos_enable_acpi'
public acpi_ssdt_cnt as 'kos_acpi_ssdt_cnt'
public kos_acpi_ssdt_base
public kos_acpi_ssdt_size
cli equ nop
iretd equ retd
@ -105,6 +110,7 @@ include 'blkdev/disk_cache.inc'
include 'fs/fs_lfn.inc'
include 'crc.inc'
include 'unicode.inc'
include 'acpi/acpi.inc'
include 'core/string.inc'
include 'core/malloc.inc'
include 'core/heap.inc'
@ -247,6 +253,31 @@ proc kos_init c uses ebx esi edi ebp
ret
endp
extrn pci_read
;uint32_t pci_read(uint32_t bus, uint32_t dev, uint32_t fun, uint32_t offset, size_t len) {
; IN: ah=bus,device+func=bh,register address=bl
; number of bytes to read (1,2,4) coded into AL, bits 0-1
; (0 - byte, 1 - word, 2 - dword)
proc pci_read_reg uses ebx esi edi
mov ecx, eax
and ecx, 3
movi edx, 1
shl edx, cl
push edx ; len
movzx edx, bl
push edx ; offset
movzx edx, bh
and edx, 7
push edx ; fun
movzx edx, bh
shr edx, 3
push edx ; dev
movzx edx, ah
push edx ; bus
call pci_read
ret
endp
proc sys_msg_board
cmp cl, 0x0d
jz @f
@ -263,6 +294,11 @@ proc sys_msg_board
ret
endp
proc map_io_mem _base, _size, _flags
mov eax, [_base]
ret
endp
change_task:
mov [REDRAW_BACKGROUND], 0
ret
@ -315,7 +351,6 @@ scheduler_add_thread:
build_interrupt_table:
init_fpu:
init_mtrr:
map_io_mem:
create_trampoline_pgmap:
alloc_page:
@ -385,6 +420,9 @@ win_stack_addr dd WIN_STACK
win_pos_addr dd WIN_POS
lfb_base_addr dd lfb_base
kos_acpi_ssdt_base dd acpi_ssdt_base
kos_acpi_ssdt_size dd acpi_ssdt_size
uglobal
context_counter dd ?
LAPIC_BASE dd ?

View File

@ -994,6 +994,29 @@ void shell_read80(int argc, char **argv) {
shell_read(argc, argv, F80);
}
void shell_acpi_preload_table(int argc, char **argv) {
(void)argc;
FILE *f = fopen(argv[1], "r");
fseek(f, 0, SEEK_END);
size_t fsize = ftell(f);
rewind(f);
uint8_t *table = (uint8_t*)malloc(fsize);
fread(table, fsize, 1, f);
fclose(f);
fprintf(stderr, "# %zu\n", kos_acpi_ssdt_cnt);
kos_acpi_ssdt_base[kos_acpi_ssdt_cnt] = table;
kos_acpi_ssdt_size[kos_acpi_ssdt_cnt] = fsize;
kos_acpi_ssdt_cnt++;
}
void shell_acpi_enable(int argc, char **argv) {
(void)argc;
(void)argv;
COVERAGE_ON();
kos_enable_acpi();
COVERAGE_OFF();
}
typedef struct {
char *name;
void (*func) (int, char **);
@ -1041,6 +1064,8 @@ func_table_t funcs[] = {
{ "scrot", shell_scrot },
{ "dump_win_stack", shell_dump_win_stack },
{ "dump_win_pos", shell_dump_win_pos },
{ "acpi_enable", shell_acpi_enable },
{ "acpi_preload_table", shell_acpi_preload_table },
{ NULL, NULL },
};